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:
1 parent
27b243b121
commit
fa22562bb1
17 files changed
+30
-18
No files matched your search
@@ -5,7 +5,7 @@ Vue 3 frontends.
|
|||||||
|
|
||||||
## Planned Layout
|
## 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/infra`: Prisma/Redis connectors and other runtime infra
|
||||||
- `/packages/logic`: pure game logic with DI and interfaces
|
- `/packages/logic`: pure game logic with DI and interfaces
|
||||||
- `/app/gateway-frontend`: gateway UI
|
- `/app/gateway-frontend`: gateway UI
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
"lint": "node -e \"console.log('lint not configured')\"",
|
"lint": "node -e \"console.log('lint not configured')\"",
|
||||||
"test": "node -e \"console.log('test not configured')\""
|
"test": "node -e \"console.log('test not configured')\""
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"js-sha512": "^0.9.0"
|
||||||
|
},
|
||||||
"devDependencies": {}
|
"devDependencies": {}
|
||||||
}
|
}
|
||||||
@@ -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';
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -18,7 +18,7 @@
|
|||||||
"test": "vitest run --config vitest.config.ts"
|
"test": "vitest run --config vitest.config.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-sha512": "^0.9.0"
|
"@sammo-ts/common": "workspace:*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vitest": "^4.0.16"
|
"vitest": "^4.0.16"
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
export * from './domain/entities.js';
|
export * from './domain/entities.js';
|
||||||
export * from './ports/rng.js';
|
export type { RandomGenerator } from '@sammo-ts/common';
|
||||||
export * from './ports/world.js';
|
export * from './ports/world.js';
|
||||||
export * from './triggers/index.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,5 +1,5 @@
|
|||||||
import type { General, GeneralTriggerState } from '../domain/entities.js';
|
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 type { WorldStateRepository } from '../ports/world.js';
|
||||||
import { TriggerCaller, type Trigger } from './core.js';
|
import { TriggerCaller, type Trigger } from './core.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { bufferByteSize, LiteHashDRBG } from '../src/util/LiteHashDRBG.js';
|
import {
|
||||||
import { RandUtil } from '../src/util/RandUtil.js';
|
bufferByteSize,
|
||||||
import { convertBytesLikeToArrayBuffer } from '../src/util/convertBytesLikeToArrayBuffer.js';
|
convertBytesLikeToArrayBuffer,
|
||||||
import { convertBytesLikeToUint8Array as toBytes } from '../src/util/convertBytesLikeToUint8Array.js';
|
convertBytesLikeToUint8Array as toBytes,
|
||||||
|
LiteHashDRBG,
|
||||||
|
RandUtil,
|
||||||
|
} from '@sammo-ts/common';
|
||||||
|
|
||||||
type Bytes = ArrayBuffer | DataView<ArrayBuffer> | Uint8Array<ArrayBuffer>;
|
type Bytes = ArrayBuffer | DataView<ArrayBuffer> | Uint8Array<ArrayBuffer>;
|
||||||
type MaybeBytes = Bytes | string;
|
type MaybeBytes = Bytes | string;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
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);
|
const toArray = (bytes: Uint8Array): number[] => Array.from(bytes);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@sammo-ts/common': path.resolve(__dirname, '../common/src/index.ts'),
|
||||||
|
},
|
||||||
|
},
|
||||||
test: {
|
test: {
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
globals: true,
|
globals: true,
|
||||||
|
|||||||
Reference in new issue
Block a user