@substrat-run/kernel 0.106.0 → 0.107.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/dist/ulid.d.ts +19 -1
- package/dist/ulid.d.ts.map +1 -1
- package/dist/ulid.js +36 -6
- package/dist/ulid.js.map +1 -1
- package/package.json +2 -2
package/dist/ulid.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/** A monotonic ULID mint. `now` is epoch milliseconds; it defaults to the wall clock. */
|
|
2
|
-
export
|
|
2
|
+
export interface UlidMint {
|
|
3
|
+
(now?: number): string;
|
|
4
|
+
/**
|
|
5
|
+
* Raise the floor to an id this writer has already persisted (#1335), so the next
|
|
6
|
+
* mint is strictly greater than it whatever the clock now says.
|
|
7
|
+
*
|
|
8
|
+
* The floor only ever goes UP: seeding with an id below where the mint already
|
|
9
|
+
* stands is a no-op, so a seed racing an in-flight mint cannot undo it, and seeding
|
|
10
|
+
* twice is harmless. Both halves of the state are taken — the timestamp AND the
|
|
11
|
+
* random digits — because an id minted in the same millisecond has to beat the
|
|
12
|
+
* seed's random half too, and re-randomizing could land below it.
|
|
13
|
+
*
|
|
14
|
+
* Refuses anything that is not a ULID, for `ulidTime`'s reason: a floor decoded
|
|
15
|
+
* from a prefix is a plausible-looking number and would silently sit in the wrong
|
|
16
|
+
* place. Callers read the id back out of their own storage, where the only writer
|
|
17
|
+
* is a mint like this one.
|
|
18
|
+
*/
|
|
19
|
+
seedFrom(id: string): void;
|
|
20
|
+
}
|
|
3
21
|
/**
|
|
4
22
|
* A ULID mint with its OWN monotonic state — one writer's floor, not the process's.
|
|
5
23
|
*
|
package/dist/ulid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../src/ulid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../src/ulid.ts"],"names":[],"mappings":"AA0CA,yFAAyF;AACzF,MAAM,WAAW,QAAQ;IACvB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,QAAQ,CAmFrC;AAKD,wBAAgB,IAAI,CAAC,GAAG,GAAE,MAAmB,GAAG,MAAM,CAErD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAO3C"}
|
package/dist/ulid.js
CHANGED
|
@@ -16,11 +16,14 @@
|
|
|
16
16
|
// go backwards against ITS OWN rows, which is the invariant `ORDER BY id` needs.
|
|
17
17
|
//
|
|
18
18
|
// The floor lives in MEMORY, so it is only as old as the mint. A host that closes and
|
|
19
|
-
// reopens — or a Durable Object that is evicted and revived —
|
|
20
|
-
// clock alone, and if that clock now
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
19
|
+
// reopens — or a Durable Object that is evicted and revived — would start again from the
|
|
20
|
+
// clock alone, and if that clock now read behind the last id it persisted, the next id
|
|
21
|
+
// would sort underneath rows that are already stored. `seedFrom()` (#1335) is how a
|
|
22
|
+
// writer closes that gap: it hands the mint an id it has ALREADY persisted, and the
|
|
23
|
+
// floor is raised to it before the first mint of the new life. The mint cannot read
|
|
24
|
+
// storage itself — it has no idea what its writer's rows live in — so the durability
|
|
25
|
+
// half is the caller's, and each adapter seeds from `SELECT MAX(id) FROM
|
|
26
|
+
// _substrat_outbox` for the scope it is about to mint into.
|
|
24
27
|
const B32 = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
25
28
|
/** The largest instant 48 bits can hold — `7ZZZZZZZZZ`, some time in 10889 AD. */
|
|
26
29
|
const MAX_ULID_TIME = 2 ** 48 - 1;
|
|
@@ -55,7 +58,7 @@ export function createUlid() {
|
|
|
55
58
|
}
|
|
56
59
|
return false; // all digits were 31 — overflowed (astronomically rare)
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
const mint = ((now = Date.now()) => {
|
|
59
62
|
// Not a clock reading at all. `NaN` (an unparseable timestamp) is the one that
|
|
60
63
|
// matters: every comparison below is false for it, so it would sail through the
|
|
61
64
|
// floor untouched and encode as a run of `undefined`s.
|
|
@@ -92,7 +95,34 @@ export function createUlid() {
|
|
|
92
95
|
for (const d of lastRand)
|
|
93
96
|
r += B32[d];
|
|
94
97
|
return ts + r;
|
|
98
|
+
});
|
|
99
|
+
mint.seedFrom = (id) => {
|
|
100
|
+
const time = ulidTime(id); // refuses anything that is not a ULID
|
|
101
|
+
if (time < lastTime)
|
|
102
|
+
return;
|
|
103
|
+
// The random half, as the same 16 base32 digits the mint holds. Past `ulidTime`'s
|
|
104
|
+
// alphabet gate every digit is in `B32`, so `indexOf` cannot miss.
|
|
105
|
+
const rand = [];
|
|
106
|
+
for (const ch of id.slice(10))
|
|
107
|
+
rand.push(B32.indexOf(ch));
|
|
108
|
+
if (time === lastTime) {
|
|
109
|
+
// Same millisecond: only adopt the seed's random half if it is the higher one,
|
|
110
|
+
// or the next `incrementRandom()` would step from below where this mint stands.
|
|
111
|
+
let ahead = false;
|
|
112
|
+
for (let i = 0; i < 16; i++) {
|
|
113
|
+
if (rand[i] !== lastRand[i]) {
|
|
114
|
+
ahead = rand[i] > lastRand[i];
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!ahead)
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
lastTime = time;
|
|
122
|
+
for (let i = 0; i < 16; i++)
|
|
123
|
+
lastRand[i] = rand[i];
|
|
95
124
|
};
|
|
125
|
+
return mint;
|
|
96
126
|
}
|
|
97
127
|
/** The process-wide mint every id in the platform has always come from. */
|
|
98
128
|
const processUlid = createUlid();
|
package/dist/ulid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ulid.js","sourceRoot":"","sources":["../src/ulid.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,gEAAgE;AAChE,EAAE;AACF,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAC9E,iFAAiF;AACjF,mEAAmE;AACnE,EAAE;AACF,kFAAkF;AAClF,qFAAqF;AACrF,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,EAAE;AACF,sFAAsF;AACtF,oFAAoF;AACpF,qFAAqF;AACrF
|
|
1
|
+
{"version":3,"file":"ulid.js","sourceRoot":"","sources":["../src/ulid.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,gEAAgE;AAChE,EAAE;AACF,iFAAiF;AACjF,gFAAgF;AAChF,8EAA8E;AAC9E,iFAAiF;AACjF,mEAAmE;AACnE,EAAE;AACF,kFAAkF;AAClF,qFAAqF;AACrF,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,EAAE;AACF,sFAAsF;AACtF,yFAAyF;AACzF,uFAAuF;AACvF,oFAAoF;AACpF,oFAAoF;AACpF,oFAAoF;AACpF,qFAAqF;AACrF,yEAAyE;AACzE,4DAA4D;AAM5D,MAAM,GAAG,GAAG,kCAAkC,CAAC;AAE/C,kFAAkF;AAClF,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAElC,iFAAiF;AACjF,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,MAAM,WAAW,GAAG,CAAC,CAAS,EAAU,EAAE,CACxC,kCAAkC,CAAC,aAAa,aAAa,GAAG,CAAC;AAuBnE;;;;;;GAMG;AACH,MAAM,UAAU,UAAU;IACxB,iFAAiF;IACjF,iEAAiE;IACjE,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClB,MAAM,QAAQ,GAAa,IAAI,KAAK,CAAS,EAAE,C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,EAAE,EAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@substrat-run/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.107.0",
|
|
4
4
|
"description": "Substrat kernel contracts and services — pure TypeScript, no platform imports (D-14)",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@substrat-run/contracts": "^0.
|
|
25
|
+
"@substrat-run/contracts": "^0.107.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^22.0.0",
|