refactor: migrate RNG and utility functions to common package

- Removed RNG interface and related utility classes from logic package.
- Added RNG interface and utility classes in common package.
- Implemented various RNG classes (ConstantRNG, MidpointRNG, SineRNG, SequenceRNG) in common package.
- Updated conversion utilities for BytesLike to ArrayBuffer and Uint8Array in common package.
- Adjusted tests to import RNG utilities from the new common package.
- Updated vitest configuration to resolve common package imports.
This commit is contained in:
2025-12-28 12:27:47 +00:00
parent 27b243b121
commit fa22562bb1
17 changed files with 30 additions and 18 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ Vue 3 frontends.
## Planned Layout
- `/packages/common`: shared utilities and type definitions (no infra)
- `/packages/common`: shared utilities and type definitions (RNG/bytes/테스트 RNG 포함, no infra)
- `/packages/infra`: Prisma/Redis connectors and other runtime infra
- `/packages/logic`: pure game logic with DI and interfaces
- `/app/gateway-frontend`: gateway UI
+3 -1
View File
@@ -11,6 +11,8 @@
"lint": "node -e \"console.log('lint not configured')\"",
"test": "node -e \"console.log('test not configured')\""
},
"dependencies": {},
"dependencies": {
"js-sha512": "^0.9.0"
},
"devDependencies": {}
}
+8 -1
View File
@@ -1 +1,8 @@
export {};
export * from './rng.js';
export * from './util/BytesLike.js';
export * from './util/convertBytesLikeToArrayBuffer.js';
export * from './util/convertBytesLikeToUint8Array.js';
export * from './util/LiteHashDRBG.js';
export * from './util/RNG.js';
export * from './util/RandUtil.js';
export * from './util/TestRNG.js';
+1 -1
View File
@@ -18,7 +18,7 @@
"test": "vitest run --config vitest.config.ts"
},
"dependencies": {
"js-sha512": "^0.9.0"
"@sammo-ts/common": "workspace:*"
},
"devDependencies": {
"vitest": "^4.0.16"
+1 -8
View File
@@ -1,11 +1,4 @@
export * from './domain/entities.js';
export * from './ports/rng.js';
export type { RandomGenerator } from '@sammo-ts/common';
export * from './ports/world.js';
export * from './triggers/index.js';
export * from './util/BytesLike.js';
export * from './util/convertBytesLikeToArrayBuffer.js';
export * from './util/convertBytesLikeToUint8Array.js';
export * from './util/LiteHashDRBG.js';
export * from './util/RNG.js';
export * from './util/RandUtil.js';
export * from './util/TestRNG.js';
+1 -1
View File
@@ -1,5 +1,5 @@
import type { General, GeneralTriggerState } from '../domain/entities.js';
import type { RandomGenerator } from '../ports/rng.js';
import type { RandomGenerator } from '@sammo-ts/common';
import type { WorldStateRepository } from '../ports/world.js';
import { TriggerCaller, type Trigger } from './core.js';
+7 -4
View File
@@ -1,8 +1,11 @@
import { describe, expect, it } from 'vitest';
import { bufferByteSize, LiteHashDRBG } from '../src/util/LiteHashDRBG.js';
import { RandUtil } from '../src/util/RandUtil.js';
import { convertBytesLikeToArrayBuffer } from '../src/util/convertBytesLikeToArrayBuffer.js';
import { convertBytesLikeToUint8Array as toBytes } from '../src/util/convertBytesLikeToUint8Array.js';
import {
bufferByteSize,
convertBytesLikeToArrayBuffer,
convertBytesLikeToUint8Array as toBytes,
LiteHashDRBG,
RandUtil,
} from '@sammo-ts/common';
type Bytes = ArrayBuffer | DataView<ArrayBuffer> | Uint8Array<ArrayBuffer>;
type MaybeBytes = Bytes | string;
+1 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { ConstantRNG, MidpointRNG, SequenceRNG, SineRNG } from '../src/util/TestRNG.js';
import { ConstantRNG, MidpointRNG, SequenceRNG, SineRNG } from '@sammo-ts/common';
const toArray = (bytes: Uint8Array): number[] => Array.from(bytes);
+7
View File
@@ -1,6 +1,13 @@
import path from 'node:path';
import { defineConfig } from 'vitest/config';
export default defineConfig({
resolve: {
alias: {
'@sammo-ts/common': path.resolve(__dirname, '../common/src/index.ts'),
},
},
test: {
environment: 'node',
globals: true,