@cogenta/schema 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cogenta/schema",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Content schema in code: collections, field types, generated types and migrations.",
5
5
  "license": "MPL-2.0",
6
6
  "type": "module",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "zod": "^4.4.3",
31
- "@cogenta/core": "0.1.1"
31
+ "@cogenta/core": "0.2.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "typescript": "^7.0.2",
@@ -1,18 +0,0 @@
1
- /**
2
- * UUIDv7, generated by the application (ADR-0015).
3
- *
4
- * `node:crypto` ships `randomUUID` for v4 only, and v4 is exactly what ADR-0015
5
- * rules out: random keys fragment a B-tree on insert, which degrades writes as
6
- * the table grows. v7 puts a 48-bit millisecond timestamp first, so new rows
7
- * land at the end of the index.
8
- *
9
- * Layout, per RFC 9562 §5.7:
10
- *
11
- * 0 1 2 3
12
- * | unix_ts_ms (48 bits) | ver | rand_a | var | rand_b |
13
- *
14
- * Same-millisecond ordering is not guaranteed and is not needed: nothing here
15
- * sorts by identifier for correctness, only for index locality.
16
- */
17
- export declare function uuidv7(): string;
18
- //# sourceMappingURL=ids.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/routing/ids.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,IAAI,MAAM,CA0B/B"}
@@ -1,41 +0,0 @@
1
- import { randomFillSync } from 'node:crypto';
2
- /**
3
- * UUIDv7, generated by the application (ADR-0015).
4
- *
5
- * `node:crypto` ships `randomUUID` for v4 only, and v4 is exactly what ADR-0015
6
- * rules out: random keys fragment a B-tree on insert, which degrades writes as
7
- * the table grows. v7 puts a 48-bit millisecond timestamp first, so new rows
8
- * land at the end of the index.
9
- *
10
- * Layout, per RFC 9562 §5.7:
11
- *
12
- * 0 1 2 3
13
- * | unix_ts_ms (48 bits) | ver | rand_a | var | rand_b |
14
- *
15
- * Same-millisecond ordering is not guaranteed and is not needed: nothing here
16
- * sorts by identifier for correctness, only for index locality.
17
- */
18
- export function uuidv7() {
19
- const bytes = new Uint8Array(16);
20
- randomFillSync(bytes);
21
- const milliseconds = Date.now();
22
- // Big-endian 48-bit timestamp. `Math.floor(ms / 2 ** 32)` rather than a shift:
23
- // bitwise operators in JavaScript truncate to 32 bits and would drop the top.
24
- bytes[0] = Math.floor(milliseconds / 2 ** 40) & 0xff;
25
- bytes[1] = Math.floor(milliseconds / 2 ** 32) & 0xff;
26
- bytes[2] = Math.floor(milliseconds / 2 ** 24) & 0xff;
27
- bytes[3] = Math.floor(milliseconds / 2 ** 16) & 0xff;
28
- bytes[4] = Math.floor(milliseconds / 2 ** 8) & 0xff;
29
- bytes[5] = milliseconds & 0xff;
30
- bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70; // version 7
31
- bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80; // variant 10
32
- const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
33
- return [
34
- hex.slice(0, 8),
35
- hex.slice(8, 12),
36
- hex.slice(12, 16),
37
- hex.slice(16, 20),
38
- hex.slice(20, 32),
39
- ].join('-');
40
- }
41
- //# sourceMappingURL=ids.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/routing/ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM;IACpB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;IAChC,cAAc,CAAC,KAAK,CAAC,CAAA;IAErB,MAAM,YAAY,G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CAAC,EAAE,CAAC,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QAChB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;KAClB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACb,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare function uuidv7(): string;
2
- /** True for a syntactically valid UUID. `version` narrows it to one layout. */
3
- export declare function isUuid(value: string, version?: number): boolean;
4
- /** The millisecond timestamp a v7 was minted at. Null for any other layout. */
5
- export declare function uuidv7Timestamp(value: string): number | null;
6
- //# sourceMappingURL=uuid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/store/uuid.ts"],"names":[],"mappings":"AAqBA,wBAAgB,MAAM,IAAI,MAAM,CAiC/B;AAID,+EAA+E;AAC/E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAI/D;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG5D"}
@@ -1,64 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- /**
3
- * UUIDv7, generated by the application (ADR-0015).
4
- *
5
- * Node ships `randomUUID()`, but that is a v4: random, and therefore a B-tree
6
- * index that fragments a little more with every insert. A v7 carries its
7
- * millisecond timestamp in the high bits, so ids sort in creation order and rows
8
- * written together land together on disk.
9
- *
10
- * There is no dependency here on purpose (rule R9): the layout is 48 bits of
11
- * Unix milliseconds, 4 bits of version, 12 bits of counter, 2 bits of variant
12
- * and 62 bits of randomness — small enough to write than to justify a package.
13
- */
14
- /** The counter occupies 12 bits, so it wraps after 4096 ids in one millisecond. */
15
- const MAX_COUNTER = 0xfff;
16
- let lastTimestamp = 0;
17
- let counter = 0;
18
- export function uuidv7() {
19
- const now = Date.now();
20
- if (now > lastTimestamp) {
21
- lastTimestamp = now;
22
- // Seeded low, and randomly: low so a burst inside a single millisecond
23
- // cannot overflow the twelve bits, random so one id does not give away the
24
- // next. A fixed zero would make consecutive ids guessable.
25
- counter = randomBytes(1).readUInt8(0);
26
- }
27
- else {
28
- counter += 1;
29
- if (counter > MAX_COUNTER) {
30
- // Borrow from the next millisecond rather than emit a duplicate. Ordering
31
- // survives, and the id is at most a few milliseconds ahead of the clock.
32
- lastTimestamp += 1;
33
- counter = 0;
34
- }
35
- }
36
- const time = lastTimestamp.toString(16).padStart(12, '0');
37
- const random = randomBytes(8).toString('hex');
38
- // RFC 9562 variant: the top two bits of octet 8 must be `10`.
39
- const variant = ((Number.parseInt(random.slice(0, 2), 16) & 0x3f) | 0x80)
40
- .toString(16)
41
- .padStart(2, '0');
42
- return [
43
- time.slice(0, 8),
44
- time.slice(8, 12),
45
- `7${counter.toString(16).padStart(3, '0')}`,
46
- `${variant}${random.slice(2, 4)}`,
47
- random.slice(4, 16),
48
- ].join('-');
49
- }
50
- const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-([0-9a-f])[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
51
- /** True for a syntactically valid UUID. `version` narrows it to one layout. */
52
- export function isUuid(value, version) {
53
- const match = UUID.exec(value);
54
- if (match === null)
55
- return false;
56
- return version === undefined || match[1] === version.toString(16);
57
- }
58
- /** The millisecond timestamp a v7 was minted at. Null for any other layout. */
59
- export function uuidv7Timestamp(value) {
60
- if (!isUuid(value, 7))
61
- return null;
62
- return Number.parseInt(value.slice(0, 8) + value.slice(9, 13), 16);
63
- }
64
- //# sourceMappingURL=uuid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/store/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EA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