koota-kit 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +3 -1
- package/dist/cjs/index.cjs +3 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/index.d.cts.map +1 -1
- package/dist/cjs/rng.cjs +29 -0
- package/dist/cjs/rng.d.cts +13 -0
- package/dist/cjs/rng.d.cts.map +1 -1
- package/dist/cjs/traits/index.cjs +2 -4
- package/dist/cjs/traits/index.d.cts +2 -4
- package/dist/cjs/traits/index.d.cts.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/rng.d.ts +13 -0
- package/dist/esm/rng.d.ts.map +1 -1
- package/dist/esm/rng.js +27 -0
- package/dist/esm/traits/index.d.ts +2 -4
- package/dist/esm/traits/index.d.ts.map +1 -1
- package/dist/esm/traits/index.js +2 -4
- package/docs/API.md +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0](https://github.com/jbcom/koota-kit/compare/v0.3.1...v0.4.0) (2026-10-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **rng:** pick and shuffle over a stream ([167eb1c](https://github.com/jbcom/koota-kit/commit/167eb1c75fdb7aa2b78f9d9d4e2533c81e0b5230))
|
|
9
|
+
|
|
10
|
+
## [0.3.1](https://github.com/jbcom/koota-kit/compare/v0.3.0...v0.3.1) (2026-10-07)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* declare maintained Node support and align OSS protection gates ([20f6aa3](https://github.com/jbcom/koota-kit/commit/20f6aa37b971138d3d7fbca54152f44b99d1f2d8))
|
|
16
|
+
* declare the supported Node lines and test each in CI ([94ed880](https://github.com/jbcom/koota-kit/commit/94ed8803242a43c055a9ae9333327b0856109bb5))
|
|
17
|
+
|
|
3
18
|
## [0.3.0](https://github.com/jbcom/koota-kit/compare/v0.2.1...v0.3.0) (2026-10-06)
|
|
4
19
|
|
|
5
20
|
|
package/CONTRIBUTING.md
CHANGED
|
@@ -5,7 +5,7 @@ Thanks for taking the time to contribute.
|
|
|
5
5
|
## Getting set up
|
|
6
6
|
|
|
7
7
|
With [mise](https://mise.jdx.dev) (recommended — installs the Node and pnpm
|
|
8
|
-
|
|
8
|
+
toolchain selected in `mise.toml`; Node selects a major, not an exact patch):
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
11
|
mise install
|
package/README.md
CHANGED
|
@@ -34,7 +34,9 @@ pnpm add koota-kit koota
|
|
|
34
34
|
|
|
35
35
|
Requirements:
|
|
36
36
|
|
|
37
|
-
- Node.js 22
|
|
37
|
+
- Node.js 22, 24 and 26 (CI covers each on Linux and Node 24 on Windows).
|
|
38
|
+
The package declares `>=22`; support follows maintained Node lines rather
|
|
39
|
+
than requiring one exact patch release.
|
|
38
40
|
- Koota `^0.6.6`, installed by the application as a peer dependency
|
|
39
41
|
|
|
40
42
|
The package ships native ESM and CommonJS entry points with format-correct
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// ./eventLog — scratch-backed publish/drain event logs with a peek seam for
|
|
13
13
|
// observers (harnesses, tests, HUDs)
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.defineTrait = exports.defineEventLog = exports.MASTER_SEED_BYTES = exports.isMasterSeed = exports.deriveSeed = exports.createMasterSeed = exports.substream = exports.snapshotSubstreams = exports.snapshotStream = exports.snapshotLayers = exports.restoreSubstreams = exports.restoreStream = exports.restoreLayers = exports.nextU32 = exports.nextInt = exports.nextFloat = exports.getSubstream = exports.createSubstreams = exports.createRng = exports.chance = exports.trait = exports.snapshotWorld = exports.restoreWorldHeader = exports.relation = exports.destroySimWorld = exports.createSimWorld = exports.createActions = exports.advanceClock = void 0;
|
|
15
|
+
exports.defineTrait = exports.defineEventLog = exports.MASTER_SEED_BYTES = exports.isMasterSeed = exports.deriveSeed = exports.createMasterSeed = exports.substream = exports.snapshotSubstreams = exports.snapshotStream = exports.snapshotLayers = exports.shuffle = exports.restoreSubstreams = exports.restoreStream = exports.restoreLayers = exports.pick = exports.nextU32 = exports.nextInt = exports.nextFloat = exports.getSubstream = exports.createSubstreams = exports.createRng = exports.chance = exports.trait = exports.snapshotWorld = exports.restoreWorldHeader = exports.relation = exports.destroySimWorld = exports.createSimWorld = exports.createActions = exports.advanceClock = void 0;
|
|
16
16
|
var world_js_1 = require("./world.cjs");
|
|
17
17
|
Object.defineProperty(exports, "advanceClock", { enumerable: true, get: function () { return world_js_1.advanceClock; } });
|
|
18
18
|
Object.defineProperty(exports, "createActions", { enumerable: true, get: function () { return world_js_1.createActions; } });
|
|
@@ -30,9 +30,11 @@ Object.defineProperty(exports, "getSubstream", { enumerable: true, get: function
|
|
|
30
30
|
Object.defineProperty(exports, "nextFloat", { enumerable: true, get: function () { return rng_js_1.nextFloat; } });
|
|
31
31
|
Object.defineProperty(exports, "nextInt", { enumerable: true, get: function () { return rng_js_1.nextInt; } });
|
|
32
32
|
Object.defineProperty(exports, "nextU32", { enumerable: true, get: function () { return rng_js_1.nextU32; } });
|
|
33
|
+
Object.defineProperty(exports, "pick", { enumerable: true, get: function () { return rng_js_1.pick; } });
|
|
33
34
|
Object.defineProperty(exports, "restoreLayers", { enumerable: true, get: function () { return rng_js_1.restoreLayers; } });
|
|
34
35
|
Object.defineProperty(exports, "restoreStream", { enumerable: true, get: function () { return rng_js_1.restoreStream; } });
|
|
35
36
|
Object.defineProperty(exports, "restoreSubstreams", { enumerable: true, get: function () { return rng_js_1.restoreSubstreams; } });
|
|
37
|
+
Object.defineProperty(exports, "shuffle", { enumerable: true, get: function () { return rng_js_1.shuffle; } });
|
|
36
38
|
Object.defineProperty(exports, "snapshotLayers", { enumerable: true, get: function () { return rng_js_1.snapshotLayers; } });
|
|
37
39
|
Object.defineProperty(exports, "snapshotStream", { enumerable: true, get: function () { return rng_js_1.snapshotStream; } });
|
|
38
40
|
Object.defineProperty(exports, "snapshotSubstreams", { enumerable: true, get: function () { return rng_js_1.snapshotSubstreams; } });
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { advanceClock, createActions, createSimWorld, destroySimWorld, relation, restoreWorldHeader, snapshotWorld, trait, } from "./world.cjs";
|
|
2
2
|
export type { Entity, World, WorldHandle, WorldSnapshot } from "./world.cjs";
|
|
3
|
-
export { chance, createRng, createSubstreams, getSubstream, nextFloat, nextInt, nextU32, restoreLayers, restoreStream, restoreSubstreams, snapshotLayers, snapshotStream, snapshotSubstreams, substream, } from "./rng.cjs";
|
|
3
|
+
export { chance, createRng, createSubstreams, getSubstream, nextFloat, nextInt, nextU32, pick, restoreLayers, restoreStream, restoreSubstreams, shuffle, snapshotLayers, snapshotStream, snapshotSubstreams, substream, } from "./rng.cjs";
|
|
4
4
|
export type { RngLayers, RngLayersSnapshot, RngSeeds, RngStream, RngStreamSnapshot, Substreams, SubstreamsSnapshot, } from "./rng.cjs";
|
|
5
5
|
export { createMasterSeed, deriveSeed, isMasterSeed, MASTER_SEED_BYTES } from "./seed.cjs";
|
|
6
6
|
export type { EntropySource, SeedPart } from "./seed.cjs";
|
package/dist/cjs/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,KAAK,GACN,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,MAAM,EAAE,KAAK,E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;AAClB,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1F,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/cjs/rng.cjs
CHANGED
|
@@ -28,6 +28,8 @@ exports.nextU32 = nextU32;
|
|
|
28
28
|
exports.nextFloat = nextFloat;
|
|
29
29
|
exports.nextInt = nextInt;
|
|
30
30
|
exports.chance = chance;
|
|
31
|
+
exports.pick = pick;
|
|
32
|
+
exports.shuffle = shuffle;
|
|
31
33
|
exports.snapshotStream = snapshotStream;
|
|
32
34
|
exports.snapshotLayers = snapshotLayers;
|
|
33
35
|
exports.restoreStream = restoreStream;
|
|
@@ -118,6 +120,33 @@ function chance(stream, p) {
|
|
|
118
120
|
}
|
|
119
121
|
return nextFloat(stream) < p;
|
|
120
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Pick one element of `items` uniformly. Valid calls consume exactly one
|
|
125
|
+
* `nextInt` draw; an empty array is rejected without consuming the stream,
|
|
126
|
+
* so a caller can never silently skip a draw it meant to make.
|
|
127
|
+
*/
|
|
128
|
+
function pick(stream, items) {
|
|
129
|
+
if (items.length === 0) {
|
|
130
|
+
throw new RangeError("pick: items must not be empty.");
|
|
131
|
+
}
|
|
132
|
+
return items[nextInt(stream, 0, items.length)];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Return a uniformly shuffled copy of `items` (Fisher–Yates, from the last
|
|
136
|
+
* index down). The input is never mutated. Valid calls consume exactly
|
|
137
|
+
* `items.length - 1` draws (none for zero or one element), so the draw count
|
|
138
|
+
* depends only on the length — replay stays aligned whatever the contents.
|
|
139
|
+
*/
|
|
140
|
+
function shuffle(stream, items) {
|
|
141
|
+
const out = [...items];
|
|
142
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
143
|
+
const j = nextInt(stream, 0, i + 1);
|
|
144
|
+
const swap = out[i];
|
|
145
|
+
out[i] = out[j];
|
|
146
|
+
out[j] = swap;
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
121
150
|
/**
|
|
122
151
|
* Capture `stream`'s internal seedrandom state as a plain, JSON-serializable
|
|
123
152
|
* object (deep-cloned, so later draws on `stream` cannot mutate the
|
package/dist/cjs/rng.d.cts
CHANGED
|
@@ -50,6 +50,19 @@ export declare function nextInt(stream: RngStream, minInclusive: number, maxExcl
|
|
|
50
50
|
* deterministic across codepaths that must replay identically.
|
|
51
51
|
*/
|
|
52
52
|
export declare function chance(stream: RngStream, p: number): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Pick one element of `items` uniformly. Valid calls consume exactly one
|
|
55
|
+
* `nextInt` draw; an empty array is rejected without consuming the stream,
|
|
56
|
+
* so a caller can never silently skip a draw it meant to make.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pick<T>(stream: RngStream, items: readonly T[]): T;
|
|
59
|
+
/**
|
|
60
|
+
* Return a uniformly shuffled copy of `items` (Fisher–Yates, from the last
|
|
61
|
+
* index down). The input is never mutated. Valid calls consume exactly
|
|
62
|
+
* `items.length - 1` draws (none for zero or one element), so the draw count
|
|
63
|
+
* depends only on the length — replay stays aligned whatever the contents.
|
|
64
|
+
*/
|
|
65
|
+
export declare function shuffle<T>(stream: RngStream, items: readonly T[]): T[];
|
|
53
66
|
export type RngStreamSnapshot = {
|
|
54
67
|
state: State;
|
|
55
68
|
};
|
package/dist/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S,CAO5E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,kBAAkB,CAW7E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,UAAU,CAiB1E"}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* `src/traits/` — trait-authoring conventions, kept in a LEAF sub-package.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
5
|
+
* Trait declarations live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
7
6
|
* only `koota` (the npm dep) and pure types, never runtime values from
|
|
8
7
|
* sibling modules like ./world or ./rng. That is what prevents the
|
|
9
8
|
* koota ↔ world-facade ↔ game-scenario top-level evaluation cycle that a
|
|
@@ -12,8 +11,7 @@
|
|
|
12
11
|
* from exactly one location so trait reference-identity holds regardless of
|
|
13
12
|
* which subpath a consumer imports from.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
* documented convention): object-valued fields in a SoA schema must use the
|
|
14
|
+
* Object-valued fields in a SoA schema must use the
|
|
17
15
|
* AoS-factory pattern (`() => ({...})`) so each entity gets its own object
|
|
18
16
|
* instance — koota's SoA pattern would otherwise alias state across
|
|
19
17
|
* entities (one shared object literal mutated by every entity that has the
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `src/traits/` — trait-authoring conventions, kept in a LEAF sub-package.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
4
|
+
* Trait declarations live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
6
5
|
* only `koota` (the npm dep) and pure types, never runtime values from
|
|
7
6
|
* sibling modules like ./world or ./rng. That is what prevents the
|
|
8
7
|
* koota ↔ world-facade ↔ game-scenario top-level evaluation cycle that a
|
|
@@ -11,8 +10,7 @@
|
|
|
11
10
|
* from exactly one location so trait reference-identity holds regardless of
|
|
12
11
|
* which subpath a consumer imports from.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
* documented convention): object-valued fields in a SoA schema must use the
|
|
13
|
+
* Object-valued fields in a SoA schema must use the
|
|
16
14
|
* AoS-factory pattern (`() => ({...})`) so each entity gets its own object
|
|
17
15
|
* instance — koota's SoA pattern would otherwise alias state across
|
|
18
16
|
* entities (one shared object literal mutated by every entity that has the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/traits/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/traits/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAGjD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GAC/D,CAAC,GACD;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GACtD,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACjB,KAAK,GACL,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEN;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAgBvF"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { advanceClock, createActions, createSimWorld, destroySimWorld, relation, restoreWorldHeader, snapshotWorld, trait, } from "./world.js";
|
|
2
2
|
export type { Entity, World, WorldHandle, WorldSnapshot } from "./world.js";
|
|
3
|
-
export { chance, createRng, createSubstreams, getSubstream, nextFloat, nextInt, nextU32, restoreLayers, restoreStream, restoreSubstreams, snapshotLayers, snapshotStream, snapshotSubstreams, substream, } from "./rng.js";
|
|
3
|
+
export { chance, createRng, createSubstreams, getSubstream, nextFloat, nextInt, nextU32, pick, restoreLayers, restoreStream, restoreSubstreams, shuffle, snapshotLayers, snapshotStream, snapshotSubstreams, substream, } from "./rng.js";
|
|
4
4
|
export type { RngLayers, RngLayersSnapshot, RngSeeds, RngStream, RngStreamSnapshot, Substreams, SubstreamsSnapshot, } from "./rng.js";
|
|
5
5
|
export { createMasterSeed, deriveSeed, isMasterSeed, MASTER_SEED_BYTES } from "./seed.js";
|
|
6
6
|
export type { EntropySource, SeedPart } from "./seed.js";
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,KAAK,GACN,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE5E,OAAO,EACL,MAAM,EACN,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,OAAO,EACP,OAAO,EACP,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,kBAAkB,GACnB,MAAM,UAA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M,eAAe,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// ./eventLog — scratch-backed publish/drain event logs with a peek seam for
|
|
12
12
|
// observers (harnesses, tests, HUDs)
|
|
13
13
|
export { advanceClock, createActions, createSimWorld, destroySimWorld, relation, restoreWorldHeader, snapshotWorld, trait, } from "./world.js";
|
|
14
|
-
export { chance, createRng, createSubstreams, getSubstream, nextFloat, nextInt, nextU32, restoreLayers, restoreStream, restoreSubstreams, snapshotLayers, snapshotStream, snapshotSubstreams, substream, } from "./rng.js";
|
|
14
|
+
export { chance, createRng, createSubstreams, getSubstream, nextFloat, nextInt, nextU32, pick, restoreLayers, restoreStream, restoreSubstreams, shuffle, snapshotLayers, snapshotStream, snapshotSubstreams, substream, } from "./rng.js";
|
|
15
15
|
export { createMasterSeed, deriveSeed, isMasterSeed, MASTER_SEED_BYTES } from "./seed.js";
|
|
16
16
|
export { defineEventLog } from "./eventLog.js";
|
|
17
17
|
export { defineTrait } from "./traits/index.js";
|
package/dist/esm/rng.d.ts
CHANGED
|
@@ -50,6 +50,19 @@ export declare function nextInt(stream: RngStream, minInclusive: number, maxExcl
|
|
|
50
50
|
* deterministic across codepaths that must replay identically.
|
|
51
51
|
*/
|
|
52
52
|
export declare function chance(stream: RngStream, p: number): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Pick one element of `items` uniformly. Valid calls consume exactly one
|
|
55
|
+
* `nextInt` draw; an empty array is rejected without consuming the stream,
|
|
56
|
+
* so a caller can never silently skip a draw it meant to make.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pick<T>(stream: RngStream, items: readonly T[]): T;
|
|
59
|
+
/**
|
|
60
|
+
* Return a uniformly shuffled copy of `items` (Fisher–Yates, from the last
|
|
61
|
+
* index down). The input is never mutated. Valid calls consume exactly
|
|
62
|
+
* `items.length - 1` draws (none for zero or one element), so the draw count
|
|
63
|
+
* depends only on the length — replay stays aligned whatever the contents.
|
|
64
|
+
*/
|
|
65
|
+
export declare function shuffle<T>(stream: RngStream, items: readonly T[]): T[];
|
|
53
66
|
export type RngStreamSnapshot = {
|
|
54
67
|
state: State;
|
|
55
68
|
};
|
package/dist/esm/rng.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rng.d.ts","sourceRoot":"","sources":["../../src/rng.ts"],"names":[],"mappings":"AAqBA,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,KAAK,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;AACnC,KAAK,QAAQ,GAAG,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,SAAS,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,uEAAuE;IACvE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAUpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEnD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAc7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AE,IAAI,EAAE,MAAM,GAAG,SAAS,CAGxE;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAGlE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAO5E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,kBAAkB,CAW7E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,UAAU,CAiB1E"}
|
package/dist/esm/rng.js
CHANGED
|
@@ -99,6 +99,33 @@ export function chance(stream, p) {
|
|
|
99
99
|
}
|
|
100
100
|
return nextFloat(stream) < p;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Pick one element of `items` uniformly. Valid calls consume exactly one
|
|
104
|
+
* `nextInt` draw; an empty array is rejected without consuming the stream,
|
|
105
|
+
* so a caller can never silently skip a draw it meant to make.
|
|
106
|
+
*/
|
|
107
|
+
export function pick(stream, items) {
|
|
108
|
+
if (items.length === 0) {
|
|
109
|
+
throw new RangeError("pick: items must not be empty.");
|
|
110
|
+
}
|
|
111
|
+
return items[nextInt(stream, 0, items.length)];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Return a uniformly shuffled copy of `items` (Fisher–Yates, from the last
|
|
115
|
+
* index down). The input is never mutated. Valid calls consume exactly
|
|
116
|
+
* `items.length - 1` draws (none for zero or one element), so the draw count
|
|
117
|
+
* depends only on the length — replay stays aligned whatever the contents.
|
|
118
|
+
*/
|
|
119
|
+
export function shuffle(stream, items) {
|
|
120
|
+
const out = [...items];
|
|
121
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
122
|
+
const j = nextInt(stream, 0, i + 1);
|
|
123
|
+
const swap = out[i];
|
|
124
|
+
out[i] = out[j];
|
|
125
|
+
out[j] = swap;
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
102
129
|
/**
|
|
103
130
|
* Capture `stream`'s internal seedrandom state as a plain, JSON-serializable
|
|
104
131
|
* object (deep-cloned, so later draws on `stream` cannot mutate the
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `src/traits/` — trait-authoring conventions, kept in a LEAF sub-package.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
4
|
+
* Trait declarations live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
6
5
|
* only `koota` (the npm dep) and pure types, never runtime values from
|
|
7
6
|
* sibling modules like ./world or ./rng. That is what prevents the
|
|
8
7
|
* koota ↔ world-facade ↔ game-scenario top-level evaluation cycle that a
|
|
@@ -11,8 +10,7 @@
|
|
|
11
10
|
* from exactly one location so trait reference-identity holds regardless of
|
|
12
11
|
* which subpath a consumer imports from.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
* documented convention): object-valued fields in a SoA schema must use the
|
|
13
|
+
* Object-valued fields in a SoA schema must use the
|
|
16
14
|
* AoS-factory pattern (`() => ({...})`) so each entity gets its own object
|
|
17
15
|
* instance — koota's SoA pattern would otherwise alias state across
|
|
18
16
|
* entities (one shared object literal mutated by every entity that has the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/traits/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/traits/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAGjD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GAC/D,CAAC,GACD;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,GACtD,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACjB,KAAK,GACL,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AAEN;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAgBvF"}
|
package/dist/esm/traits/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `src/traits/` — trait-authoring conventions, kept in a LEAF sub-package.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
4
|
+
* Trait declarations live in a leaf sub-package with ZERO sibling imports — this file imports
|
|
6
5
|
* only `koota` (the npm dep) and pure types, never runtime values from
|
|
7
6
|
* sibling modules like ./world or ./rng. That is what prevents the
|
|
8
7
|
* koota ↔ world-facade ↔ game-scenario top-level evaluation cycle that a
|
|
@@ -11,8 +10,7 @@
|
|
|
11
10
|
* from exactly one location so trait reference-identity holds regardless of
|
|
12
11
|
* which subpath a consumer imports from.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
* documented convention): object-valued fields in a SoA schema must use the
|
|
13
|
+
* Object-valued fields in a SoA schema must use the
|
|
16
14
|
* AoS-factory pattern (`() => ({...})`) so each entity gets its own object
|
|
17
15
|
* instance — koota's SoA pattern would otherwise alias state across
|
|
18
16
|
* entities (one shared object literal mutated by every entity that has the
|
package/docs/API.md
CHANGED
|
@@ -68,6 +68,8 @@ function nextU32(stream: RngStream): number;
|
|
|
68
68
|
function nextFloat(stream: RngStream): number;
|
|
69
69
|
function nextInt(stream: RngStream, minInclusive: number, maxExclusive: number): number;
|
|
70
70
|
function chance(stream: RngStream, probability: number): boolean;
|
|
71
|
+
function pick<T>(stream: RngStream, items: readonly T[]): T;
|
|
72
|
+
function shuffle<T>(stream: RngStream, items: readonly T[]): T[];
|
|
71
73
|
function snapshotStream(stream: RngStream): RngStreamSnapshot;
|
|
72
74
|
function restoreStream(snapshot: RngStreamSnapshot): RngStream;
|
|
73
75
|
function snapshotLayers(layers: RngLayers): RngLayersSnapshot;
|
|
@@ -79,6 +81,11 @@ function restoreLayers(snapshot: RngLayersSnapshot): RngLayers;
|
|
|
79
81
|
- `nextInt` uses half-open bounds and exactly one float draw after validation.
|
|
80
82
|
- `chance` consumes one draw for every valid probability, including `0` and
|
|
81
83
|
`1`, keeping later draw positions predictable.
|
|
84
|
+
- `pick` returns one element uniformly with exactly one `nextInt` draw and
|
|
85
|
+
rejects an empty array without drawing.
|
|
86
|
+
- `shuffle` returns a Fisher–Yates shuffled copy (the input is never mutated)
|
|
87
|
+
and consumes exactly `length - 1` draws, so the draw count depends only on
|
|
88
|
+
the length, never on the contents.
|
|
82
89
|
- Restore functions reject malformed ARC4 state and clone accepted state so a
|
|
83
90
|
snapshot can seed multiple independent replays.
|
|
84
91
|
|
package/package.json
CHANGED