@bjornpagen/bumbledb-log 0.20.1 → 0.20.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/dist/braids.d.ts +28 -0
- package/dist/braids.d.ts.map +1 -0
- package/{src/braids.ts → dist/braids.js} +22 -29
- package/dist/braids.js.map +1 -0
- package/dist/bytes.d.ts +26 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +86 -0
- package/dist/bytes.js.map +1 -0
- package/dist/chain.d.ts +56 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +137 -0
- package/dist/chain.js.map +1 -0
- package/dist/codec.d.ts +71 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +179 -0
- package/dist/codec.js.map +1 -0
- package/dist/descriptor.d.ts +61 -0
- package/dist/descriptor.d.ts.map +1 -0
- package/dist/descriptor.js +160 -0
- package/dist/descriptor.js.map +1 -0
- package/dist/errors.d.ts +202 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +122 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +52 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +166 -0
- package/dist/keys.js.map +1 -0
- package/dist/manifest.d.ts +42 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +116 -0
- package/dist/manifest.js.map +1 -0
- package/dist/replica.d.ts +154 -0
- package/dist/replica.d.ts.map +1 -0
- package/dist/replica.js +820 -0
- package/dist/replica.js.map +1 -0
- package/dist/store-s3.d.ts +31 -0
- package/dist/store-s3.d.ts.map +1 -0
- package/dist/store-s3.js +299 -0
- package/dist/store-s3.js.map +1 -0
- package/dist/store.d.ts +129 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +577 -0
- package/dist/store.js.map +1 -0
- package/dist/tenants.d.ts +56 -0
- package/dist/tenants.d.ts.map +1 -0
- package/dist/tenants.js +333 -0
- package/dist/tenants.js.map +1 -0
- package/dist/vector.d.ts +31 -0
- package/dist/vector.d.ts.map +1 -0
- package/dist/vector.js +87 -0
- package/dist/vector.js.map +1 -0
- package/dist/writer.d.ts +106 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +677 -0
- package/dist/writer.js.map +1 -0
- package/package.json +12 -7
- package/src/bytes.ts +0 -115
- package/src/chain.ts +0 -181
- package/src/codec.ts +0 -252
- package/src/descriptor.ts +0 -240
- package/src/errors.ts +0 -309
- package/src/index.ts +0 -57
- package/src/keys.ts +0 -224
- package/src/manifest.ts +0 -161
- package/src/replica.ts +0 -1061
- package/src/store-s3.ts +0 -377
- package/src/store.ts +0 -727
- package/src/tenants.ts +0 -414
- package/src/vector.ts +0 -103
- package/src/writer.ts +0 -977
- /package/{src → dist}/tilde-family.json +0 -0
package/dist/braids.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Braid derivation as data (10/20): connected components of the
|
|
3
|
+
* statement graph over ordinary relations, the braid id the smallest
|
|
4
|
+
* RelationId in the component rendered `c{id:08x}`. The one derivation
|
|
5
|
+
* lives in `crates/bumbledb-log` and reaches the descriptor parse
|
|
6
|
+
* through the engine bridge (`internalLogBraidsOf`); this façade names
|
|
7
|
+
* that derivation in the driver's vocabulary.
|
|
8
|
+
*/
|
|
9
|
+
import type { Braid, SerialStatement, Theory } from "./descriptor.js";
|
|
10
|
+
import { braid } from "./descriptor.js";
|
|
11
|
+
/** The schema's own shard map: ordinary relation name → braid id. */
|
|
12
|
+
declare function braidsOf(theory: Theory): ReadonlyMap<string, Braid>;
|
|
13
|
+
/**
|
|
14
|
+
* The degenerate-serial roster (15): key or capacity statements whose
|
|
15
|
+
* determinant projection is empty name one global group, so their braid
|
|
16
|
+
* serializes at that statement. The statement ids are the log core's
|
|
17
|
+
* own roster, read off the descriptor's derivation.
|
|
18
|
+
*/
|
|
19
|
+
declare function serialAtStatementsOf(theory: Theory): readonly SerialStatement[];
|
|
20
|
+
/**
|
|
21
|
+
* Parses a wire u32 into a braid id: valid only when the relation it
|
|
22
|
+
* names is the smallest in its own component. An unknown, closed, or
|
|
23
|
+
* non-head id is not a braid — the caller refuses, it is not ignored.
|
|
24
|
+
*/
|
|
25
|
+
declare function parse(theory: Theory, raw: number): Braid | undefined;
|
|
26
|
+
export type { Braid };
|
|
27
|
+
export { braid, braidsOf, parse, serialAtStatementsOf };
|
|
28
|
+
//# sourceMappingURL=braids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"braids.d.ts","sourceRoot":"","sources":["../src/braids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,KAAK,EAA0B,MAAM,gBAAgB,CAAA;AAI9D,qEAAqE;AACrE,iBAAS,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAU5D;AAED;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,CAExE;AAED;;;;GAIG;AACH,iBAAS,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAM7D;AAED,YAAY,EAAE,KAAK,EAAE,CAAA;AACrB,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -6,47 +6,40 @@
|
|
|
6
6
|
* through the engine bridge (`internalLogBraidsOf`); this façade names
|
|
7
7
|
* that derivation in the driver's vocabulary.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { braid, braidHex, descriptorOf } from "#descriptor.ts"
|
|
12
|
-
|
|
13
|
-
const U32_MAX = 0xffffffff
|
|
14
|
-
|
|
9
|
+
import { braid, braidHex, descriptorOf } from "#descriptor.ts";
|
|
10
|
+
const U32_MAX = 0xffffffff;
|
|
15
11
|
/** The schema's own shard map: ordinary relation name → braid id. */
|
|
16
|
-
function braidsOf(theory
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
function braidsOf(theory) {
|
|
13
|
+
const descriptor = descriptorOf(theory);
|
|
14
|
+
const out = new Map();
|
|
15
|
+
for (const relation of descriptor.relations) {
|
|
16
|
+
const braid = descriptor.braidOfRelation.get(relation.id);
|
|
17
|
+
if (braid !== undefined) {
|
|
18
|
+
out.set(relation.name, braid);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
/**
|
|
29
24
|
* The degenerate-serial roster (15): key or capacity statements whose
|
|
30
25
|
* determinant projection is empty name one global group, so their braid
|
|
31
26
|
* serializes at that statement. The statement ids are the log core's
|
|
32
27
|
* own roster, read off the descriptor's derivation.
|
|
33
28
|
*/
|
|
34
|
-
function serialAtStatementsOf(theory
|
|
35
|
-
|
|
29
|
+
function serialAtStatementsOf(theory) {
|
|
30
|
+
return descriptorOf(theory).serialAtStatements;
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
/**
|
|
39
33
|
* Parses a wire u32 into a braid id: valid only when the relation it
|
|
40
34
|
* names is the smallest in its own component. An unknown, closed, or
|
|
41
35
|
* non-head id is not a braid — the caller refuses, it is not ignored.
|
|
42
36
|
*/
|
|
43
|
-
function parse(theory
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
function parse(theory, raw) {
|
|
38
|
+
if (!Number.isInteger(raw) || raw < 0 || raw > U32_MAX) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const name = braidHex(raw);
|
|
42
|
+
return descriptorOf(theory).braidMembers.has(name) ? name : undefined;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export { braid, braidsOf, parse, serialAtStatementsOf }
|
|
44
|
+
export { braid, braidsOf, parse, serialAtStatementsOf };
|
|
45
|
+
//# sourceMappingURL=braids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"braids.js","sourceRoot":"","sources":["../src/braids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE9D,MAAM,OAAO,GAAG,UAAU,CAAA;AAE1B,qEAAqE;AACrE,SAAS,QAAQ,CAAC,MAAc;IAC/B,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;IACvC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAiB,CAAA;IACpC,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACzD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAC9B,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAc;IAC3C,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAA;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAS,KAAK,CAAC,MAAc,EAAE,GAAW;IACzC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,OAAO,EAAE,CAAC;QACxD,OAAO,SAAS,CAAA;IACjB,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC1B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACtE,CAAC;AAGD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAA"}
|
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte primitives beside the one grammar: the hex spelling every
|
|
3
|
+
* document digest walks (32 bytes, 64 lowercase hex characters), the
|
|
4
|
+
* `Digest32` brand, byte equality, and the u64 arithmetic the vector
|
|
5
|
+
* and lease algebras share. The wire's own cursors live in
|
|
6
|
+
* `crates/bumbledb-log`; nothing here reads or writes protocol bytes.
|
|
7
|
+
*/
|
|
8
|
+
declare const U64_MAX = 18446744073709551615n;
|
|
9
|
+
declare const utf8Encoder: import("node:util").TextEncoder;
|
|
10
|
+
/** Fatal UTF-8. ignoreBOM is true: a leading U+FEFF is a character, not a stripped BOM. */
|
|
11
|
+
declare const utf8StrictDecoder: import("node:util").TextDecoder;
|
|
12
|
+
declare const digest32Brand: unique symbol;
|
|
13
|
+
type Digest32 = Uint8Array & {
|
|
14
|
+
readonly [digest32Brand]: typeof digest32Brand;
|
|
15
|
+
};
|
|
16
|
+
declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
17
|
+
declare function toHex(bytes: Uint8Array): string;
|
|
18
|
+
declare function fromHex(hex: string): Uint8Array;
|
|
19
|
+
declare function digest32(bytes: Uint8Array): Digest32;
|
|
20
|
+
declare function digest32FromHex(hex: string): Digest32;
|
|
21
|
+
declare function hex32(bytes: Digest32): string;
|
|
22
|
+
declare function saturatingAddU64(a: bigint, b: bigint): bigint;
|
|
23
|
+
declare function checkedAddU64(a: bigint, b: bigint): bigint | undefined;
|
|
24
|
+
export type { Digest32 };
|
|
25
|
+
export { bytesEqual, checkedAddU64, digest32, digest32FromHex, fromHex, hex32, saturatingAddU64, toHex, U64_MAX, utf8Encoder, utf8StrictDecoder };
|
|
26
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,QAAA,MAAM,OAAO,wBAAsB,CAAA;AAEnC,QAAA,MAAM,WAAW,iCAAoB,CAAA;AACrC,2FAA2F;AAC3F,QAAA,MAAM,iBAAiB,iCAA6D,CAAA;AAEpF,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAA;AAC1C,KAAK,QAAQ,GAAG,UAAU,GAAG;IAAE,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,aAAa,CAAA;CAAE,CAAA;AAE/E,iBAAS,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAUzD;AAcD,iBAAS,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAOxC;AAED,iBAAS,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAoBxC;AAED,iBAAS,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAO7C;AAED,iBAAS,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAE9C;AAED,iBAAS,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAEtC;AAED,iBAAS,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,iBAAS,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG/D;AAED,YAAY,EAAE,QAAQ,EAAE,CAAA;AACxB,OAAO,EACN,UAAU,EACV,aAAa,EACb,QAAQ,EACR,eAAe,EACf,OAAO,EACP,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,CAAA"}
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte primitives beside the one grammar: the hex spelling every
|
|
3
|
+
* document digest walks (32 bytes, 64 lowercase hex characters), the
|
|
4
|
+
* `Digest32` brand, byte equality, and the u64 arithmetic the vector
|
|
5
|
+
* and lease algebras share. The wire's own cursors live in
|
|
6
|
+
* `crates/bumbledb-log`; nothing here reads or writes protocol bytes.
|
|
7
|
+
*/
|
|
8
|
+
import * as errors from "@superbuilders/errors";
|
|
9
|
+
const U64_MAX = 0xffffffffffffffffn;
|
|
10
|
+
const utf8Encoder = new TextEncoder();
|
|
11
|
+
/** Fatal UTF-8. ignoreBOM is true: a leading U+FEFF is a character, not a stripped BOM. */
|
|
12
|
+
const utf8StrictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
13
|
+
function bytesEqual(a, b) {
|
|
14
|
+
if (a.length !== b.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
for (let i = 0; i < a.length; i++) {
|
|
18
|
+
if (a[i] !== b[i]) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const HEX_DIGITS = "0123456789abcdef";
|
|
25
|
+
function hexNibble(byte) {
|
|
26
|
+
if (byte >= 0x30 && byte <= 0x39) {
|
|
27
|
+
return byte - 0x30;
|
|
28
|
+
}
|
|
29
|
+
if (byte >= 0x61 && byte <= 0x66) {
|
|
30
|
+
return byte - 0x61 + 10;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
function toHex(bytes) {
|
|
35
|
+
let out = "";
|
|
36
|
+
for (const byte of bytes) {
|
|
37
|
+
out += HEX_DIGITS[byte >>> 4];
|
|
38
|
+
out += HEX_DIGITS[byte & 0xf];
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
function fromHex(hex) {
|
|
43
|
+
const raw = utf8Encoder.encode(hex);
|
|
44
|
+
if (raw.length % 2 !== 0) {
|
|
45
|
+
throw errors.new(`not lowercase hex: ${hex}`);
|
|
46
|
+
}
|
|
47
|
+
const out = new Uint8Array(raw.length / 2);
|
|
48
|
+
for (let i = 0, j = 0; i < raw.length; i += 2, j++) {
|
|
49
|
+
const hiByte = raw[i];
|
|
50
|
+
const loByte = raw[i + 1];
|
|
51
|
+
if (hiByte === undefined || loByte === undefined) {
|
|
52
|
+
throw errors.new(`not lowercase hex: ${hex}`);
|
|
53
|
+
}
|
|
54
|
+
const hi = hexNibble(hiByte);
|
|
55
|
+
const lo = hexNibble(loByte);
|
|
56
|
+
if (hi === undefined || lo === undefined) {
|
|
57
|
+
throw errors.new(`not lowercase hex: ${hex}`);
|
|
58
|
+
}
|
|
59
|
+
out[j] = (hi << 4) | lo;
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
function digest32(bytes) {
|
|
64
|
+
if (bytes.length !== 32) {
|
|
65
|
+
throw errors.new(`digest is not 32 bytes: ${bytes.length}`);
|
|
66
|
+
}
|
|
67
|
+
const out = new Uint8Array(32);
|
|
68
|
+
out.set(bytes);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function digest32FromHex(hex) {
|
|
72
|
+
return digest32(fromHex(hex));
|
|
73
|
+
}
|
|
74
|
+
function hex32(bytes) {
|
|
75
|
+
return toHex(bytes);
|
|
76
|
+
}
|
|
77
|
+
function saturatingAddU64(a, b) {
|
|
78
|
+
const sum = a + b;
|
|
79
|
+
return sum > U64_MAX ? U64_MAX : sum;
|
|
80
|
+
}
|
|
81
|
+
function checkedAddU64(a, b) {
|
|
82
|
+
const sum = a + b;
|
|
83
|
+
return sum > U64_MAX ? undefined : sum;
|
|
84
|
+
}
|
|
85
|
+
export { bytesEqual, checkedAddU64, digest32, digest32FromHex, fromHex, hex32, saturatingAddU64, toHex, U64_MAX, utf8Encoder, utf8StrictDecoder };
|
|
86
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,MAAM,OAAO,GAAG,mBAAmB,CAAA;AAEnC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AACrC,2FAA2F;AAC3F,MAAM,iBAAiB,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;AAKpF,SAAS,UAAU,CAAC,CAAa,EAAE,CAAa;IAC/C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAA;IACb,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACnB,OAAO,KAAK,CAAA;QACb,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,GAAG,kBAAkB,CAAA;AAErC,SAAS,SAAS,CAAC,IAAY;IAC9B,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QAClC,OAAO,IAAI,GAAG,IAAI,CAAA;IACnB,CAAC;IACD,IAAI,IAAI,IAAI,IAAI,IAA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Aa,EACb,QAAQ,EACR,eAAe,EACf,OAAO,EACP,KAAK,EACL,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,CAAA"}
|
package/dist/chain.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chain sidecar in `dir/chain`: a floor cache of chain position,
|
|
3
|
+
* written atomically (temp + rename, fsync). The chain is Settled or
|
|
4
|
+
* Pending — generation is the vector sum, plus one exactly when the
|
|
5
|
+
* value is Pending. The byte grammar has one implementation —
|
|
6
|
+
* `crates/bumbledb-log` behind the napi bridge — so parse and render
|
|
7
|
+
* are marshal walks over the sealed codec handle; the file IO half
|
|
8
|
+
* lives here. The content address is blake3 of the rendered bytes.
|
|
9
|
+
*/
|
|
10
|
+
import type { LogCodecHandle } from "@bjornpagen/bumbledb";
|
|
11
|
+
import type { Digest32 } from "./bytes.js";
|
|
12
|
+
import type { Braid } from "./descriptor.js";
|
|
13
|
+
import type { Generation } from "./keys.js";
|
|
14
|
+
/** The sidecar's file name inside a replica directory. */
|
|
15
|
+
declare const CHAIN_FILE = "chain";
|
|
16
|
+
/** One braid's chain coordinate: the applied count, the applied
|
|
17
|
+
* batch's content address, its timestamp. */
|
|
18
|
+
interface ChainEntry {
|
|
19
|
+
readonly g: Generation;
|
|
20
|
+
readonly prev: Digest32;
|
|
21
|
+
readonly ts: bigint;
|
|
22
|
+
}
|
|
23
|
+
interface Pending {
|
|
24
|
+
readonly braid: Braid;
|
|
25
|
+
readonly slot: Generation;
|
|
26
|
+
readonly bytes: Uint8Array;
|
|
27
|
+
}
|
|
28
|
+
type Chain = {
|
|
29
|
+
readonly tag: "settled";
|
|
30
|
+
readonly entries: ReadonlyMap<Braid, ChainEntry>;
|
|
31
|
+
} | {
|
|
32
|
+
readonly tag: "pending";
|
|
33
|
+
readonly entries: ReadonlyMap<Braid, ChainEntry>;
|
|
34
|
+
readonly batch: Pending;
|
|
35
|
+
};
|
|
36
|
+
type SidecarRead = {
|
|
37
|
+
readonly tag: "absent";
|
|
38
|
+
} | {
|
|
39
|
+
readonly tag: "fault";
|
|
40
|
+
readonly io: Error;
|
|
41
|
+
} | {
|
|
42
|
+
readonly tag: "corrupt";
|
|
43
|
+
readonly parse: Error;
|
|
44
|
+
} | {
|
|
45
|
+
readonly tag: "read";
|
|
46
|
+
readonly chain: Chain;
|
|
47
|
+
};
|
|
48
|
+
declare function chainSum(chain: Chain): bigint;
|
|
49
|
+
declare function chainGeneration(chain: Chain): bigint;
|
|
50
|
+
declare function renderSidecar(codec: LogCodecHandle, chain: Chain): Uint8Array;
|
|
51
|
+
declare function parseSidecar(codec: LogCodecHandle, bytes: Uint8Array): Chain;
|
|
52
|
+
declare function readSidecar(codec: LogCodecHandle, file: string): Promise<SidecarRead>;
|
|
53
|
+
declare function writeSidecar(codec: LogCodecHandle, file: string, chain: Chain): Promise<void>;
|
|
54
|
+
export type { Chain, ChainEntry, Pending };
|
|
55
|
+
export { CHAIN_FILE, chainGeneration, chainSum, parseSidecar, readSidecar, renderSidecar, writeSidecar };
|
|
56
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAY,cAAc,EAAkB,MAAM,sBAAsB,CAAA;AAGpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAI1C,0DAA0D;AAC1D,QAAA,MAAM,UAAU,UAAU,CAAA;AAE1B;8CAC8C;AAC9C,UAAU,UAAU;IACnB,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA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C,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAepF;AAED,iBAAe,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB5F;AAED,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chain sidecar in `dir/chain`: a floor cache of chain position,
|
|
3
|
+
* written atomically (temp + rename, fsync). The chain is Settled or
|
|
4
|
+
* Pending — generation is the vector sum, plus one exactly when the
|
|
5
|
+
* value is Pending. The byte grammar has one implementation —
|
|
6
|
+
* `crates/bumbledb-log` behind the napi bridge — so parse and render
|
|
7
|
+
* are marshal walks over the sealed codec handle; the file IO half
|
|
8
|
+
* lives here. The content address is blake3 of the rendered bytes.
|
|
9
|
+
*/
|
|
10
|
+
import * as crypto from "node:crypto";
|
|
11
|
+
import * as fs from "node:fs/promises";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import { internalLogParseSidecar, internalLogRenderSidecar } from "@bjornpagen/bumbledb";
|
|
14
|
+
import * as errors from "@superbuilders/errors";
|
|
15
|
+
import { digest32, saturatingAddU64, U64_MAX } from "#bytes.ts";
|
|
16
|
+
import { braidHex } from "#descriptor.ts";
|
|
17
|
+
import { refuse } from "#errors.ts";
|
|
18
|
+
import { generation } from "#keys.ts";
|
|
19
|
+
import { Vector } from "#vector.ts";
|
|
20
|
+
/** The sidecar's file name inside a replica directory. */
|
|
21
|
+
const CHAIN_FILE = "chain";
|
|
22
|
+
function codeOf(error) {
|
|
23
|
+
return error.code;
|
|
24
|
+
}
|
|
25
|
+
function braidIdOf(id) {
|
|
26
|
+
return Number.parseInt(id.slice(1), 16);
|
|
27
|
+
}
|
|
28
|
+
function vectorOf(entries) {
|
|
29
|
+
const counts = new Map();
|
|
30
|
+
for (const [braid, entry] of entries) {
|
|
31
|
+
counts.set(braid, entry.g);
|
|
32
|
+
}
|
|
33
|
+
return Vector.from(counts);
|
|
34
|
+
}
|
|
35
|
+
function chainSum(chain) {
|
|
36
|
+
const sum = vectorOf(chain.entries).sum();
|
|
37
|
+
return typeof sum === "bigint" ? sum : U64_MAX;
|
|
38
|
+
}
|
|
39
|
+
function chainGeneration(chain) {
|
|
40
|
+
const sum = chainSum(chain);
|
|
41
|
+
return chain.tag === "settled" ? sum : saturatingAddU64(sum, 1n);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Remints a bridge refusal row as the driver's typed refusal. The
|
|
45
|
+
* boundary carries `{ kind, message }` only: the kind is the log
|
|
46
|
+
* core's own identity string, so the cause payload holds the data this
|
|
47
|
+
* side owns — the document's length, its version byte (byte 0 of every
|
|
48
|
+
* v:3 document). The raw braid id of an `UnknownBraid` rides the
|
|
49
|
+
* message.
|
|
50
|
+
*/
|
|
51
|
+
function refuseBridged(kind, message, bytes) {
|
|
52
|
+
switch (kind) {
|
|
53
|
+
case "Version":
|
|
54
|
+
return refuse({ kind: "Version", version: bytes[0] ?? 0 }, message);
|
|
55
|
+
case "Overflow":
|
|
56
|
+
return refuse({ kind: "Overflow" }, message);
|
|
57
|
+
case "UnknownBraid":
|
|
58
|
+
return refuse({ kind: "UnknownBraid" }, message);
|
|
59
|
+
case "Malformed":
|
|
60
|
+
return refuse({ kind: "Malformed", at: bytes.length }, message);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function renderSidecar(codec, chain) {
|
|
64
|
+
const entries = [...chain.entries.entries()]
|
|
65
|
+
.sort(function ascending(a, b) {
|
|
66
|
+
return braidIdOf(a[0]) - braidIdOf(b[0]);
|
|
67
|
+
})
|
|
68
|
+
.map(function entryOf([id, entry]) {
|
|
69
|
+
return { braid: braidIdOf(id), g: entry.g, prev: entry.prev, ts: entry.ts };
|
|
70
|
+
});
|
|
71
|
+
const doc = chain.tag === "settled"
|
|
72
|
+
? { entries }
|
|
73
|
+
: {
|
|
74
|
+
entries,
|
|
75
|
+
pending: { braid: braidIdOf(chain.batch.braid), slot: chain.batch.slot, bytes: chain.batch.bytes }
|
|
76
|
+
};
|
|
77
|
+
return internalLogRenderSidecar(codec, doc);
|
|
78
|
+
}
|
|
79
|
+
function parseSidecar(codec, bytes) {
|
|
80
|
+
const parsed = internalLogParseSidecar(codec, bytes);
|
|
81
|
+
if (!parsed.ok) {
|
|
82
|
+
refuseBridged(parsed.kind, parsed.message, bytes);
|
|
83
|
+
}
|
|
84
|
+
const entries = new Map();
|
|
85
|
+
for (const entry of parsed.value.entries) {
|
|
86
|
+
entries.set(braidHex(entry.braid), { g: generation(entry.g), prev: digest32(entry.prev), ts: entry.ts });
|
|
87
|
+
}
|
|
88
|
+
const pending = parsed.value.pending;
|
|
89
|
+
if (pending === undefined) {
|
|
90
|
+
return { tag: "settled", entries };
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
tag: "pending",
|
|
94
|
+
entries,
|
|
95
|
+
batch: { braid: braidHex(pending.braid), slot: generation(pending.slot), bytes: pending.bytes }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function readSidecar(codec, file) {
|
|
99
|
+
const read = await errors.try(fs.readFile(file));
|
|
100
|
+
if (read.error) {
|
|
101
|
+
if (codeOf(read.error) === "ENOENT") {
|
|
102
|
+
return { tag: "absent" };
|
|
103
|
+
}
|
|
104
|
+
return { tag: "fault", io: read.error };
|
|
105
|
+
}
|
|
106
|
+
const parsed = errors.trySync(function parse() {
|
|
107
|
+
return parseSidecar(codec, read.data);
|
|
108
|
+
});
|
|
109
|
+
if (parsed.error) {
|
|
110
|
+
return { tag: "corrupt", parse: parsed.error };
|
|
111
|
+
}
|
|
112
|
+
return { tag: "read", chain: parsed.data };
|
|
113
|
+
}
|
|
114
|
+
async function writeSidecar(codec, file, chain) {
|
|
115
|
+
const dir = path.dirname(file);
|
|
116
|
+
await fs.mkdir(dir, { recursive: true });
|
|
117
|
+
const temp = path.join(dir, `.chain-${process.pid}-${crypto.randomBytes(4).toString("hex")}`);
|
|
118
|
+
const handle = await fs.open(temp, "wx");
|
|
119
|
+
const written = await errors.try((async function writeAll() {
|
|
120
|
+
await handle.writeFile(renderSidecar(codec, chain));
|
|
121
|
+
await handle.sync();
|
|
122
|
+
})());
|
|
123
|
+
await handle.close();
|
|
124
|
+
if (written.error) {
|
|
125
|
+
await fs.rm(temp, { force: true });
|
|
126
|
+
throw errors.wrap(written.error, `write sidecar ${file}`);
|
|
127
|
+
}
|
|
128
|
+
await fs.rename(temp, file);
|
|
129
|
+
const dirHandle = await fs.open(dir, "r");
|
|
130
|
+
const synced = await errors.try(dirHandle.sync());
|
|
131
|
+
await dirHandle.close();
|
|
132
|
+
if (synced.error) {
|
|
133
|
+
throw errors.wrap(synced.error, `fsync sidecar directory ${dir}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export { CHAIN_FILE, chainGeneration, chainSum, parseSidecar, readSidecar, renderSidecar, writeSidecar };
|
|
137
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AACxF,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAE/C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,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AE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/codec.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command codec seat (20): one implementation reads and writes the
|
|
3
|
+
* batch wire — `crates/bumbledb-log`, reached through the sealed
|
|
4
|
+
* per-theory `LogCodec` handle the descriptor parse mints
|
|
5
|
+
* (`descriptor.codec`). This module is typed payload construction only:
|
|
6
|
+
* raw rows tag by the descriptor's layout on the way in, decoded rows
|
|
7
|
+
* cross exactly as the engine's `ValueOut` walk, and every grammar
|
|
8
|
+
* refusal carries the log core's own identity kind, minted through the
|
|
9
|
+
* bridge's `log-identities.json` table. The chain discipline
|
|
10
|
+
* (`verifyChain`) is pure slot algebra over decoded headers and stays
|
|
11
|
+
* host-side; no byte grammar lives here.
|
|
12
|
+
*/
|
|
13
|
+
import type { FactValue } from "@bjornpagen/bumbledb";
|
|
14
|
+
import type { Digest32 } from "./bytes.js";
|
|
15
|
+
import type { ChainEntry } from "./chain.js";
|
|
16
|
+
import type { Braid, Theory } from "./descriptor.js";
|
|
17
|
+
import type { Generation } from "./keys.js";
|
|
18
|
+
interface Op {
|
|
19
|
+
readonly op: "insert" | "delete";
|
|
20
|
+
readonly relation: string;
|
|
21
|
+
readonly rows: ReadonlyArray<readonly FactValue[]>;
|
|
22
|
+
}
|
|
23
|
+
interface BatchHeader {
|
|
24
|
+
readonly fingerprint: Digest32;
|
|
25
|
+
readonly braid: Braid;
|
|
26
|
+
readonly braidGen: Generation;
|
|
27
|
+
readonly prev: Digest32;
|
|
28
|
+
readonly writer: bigint;
|
|
29
|
+
readonly timestamp: bigint;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Encode input. The handle is the fingerprint authority, so no
|
|
33
|
+
* fingerprint field exists here — encode fills the wire's from the
|
|
34
|
+
* sealed codec. `prev` is raw bytes so a short digest reaches the named
|
|
35
|
+
* `DigestWidth` refuse at this gate instead of dying at `Digest32`
|
|
36
|
+
* construction. Decode still produces a branded `BatchHeader`.
|
|
37
|
+
*/
|
|
38
|
+
interface EncodeHeader {
|
|
39
|
+
readonly braid: Braid;
|
|
40
|
+
readonly braidGen: Generation;
|
|
41
|
+
readonly prev: Uint8Array;
|
|
42
|
+
readonly writer: bigint;
|
|
43
|
+
readonly timestamp: bigint;
|
|
44
|
+
}
|
|
45
|
+
interface DecodedBatch {
|
|
46
|
+
readonly header: BatchHeader;
|
|
47
|
+
readonly ops: readonly Op[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Encodes one batch through the sealed codec. The handle is the
|
|
51
|
+
* fingerprint authority: encode fills the wire's fingerprint from the
|
|
52
|
+
* sealed codec, so none rides the bridge (a short `prev` is
|
|
53
|
+
* `DigestWidth` at this gate). Braid membership, closedness, arity, and
|
|
54
|
+
* value validity are the core's refusals, crossing with their identity
|
|
55
|
+
* kinds.
|
|
56
|
+
*/
|
|
57
|
+
declare function encodeBatch(theory: Theory, header: EncodeHeader, ops: readonly Op[]): Uint8Array;
|
|
58
|
+
/** Full parse of a batch object by the one grammar; refusals cross typed, never partial reads. */
|
|
59
|
+
declare function decodeBatch(theory: Theory, bytes: Uint8Array): DecodedBatch;
|
|
60
|
+
/**
|
|
61
|
+
* The chain discipline (20 apply, step 1): one identity, three proved
|
|
62
|
+
* causes — the header's slot identity (braid and generation, both
|
|
63
|
+
* halves of the key the object was fetched from), its `prev` vs the
|
|
64
|
+
* chain head, its timestamp vs the head's. Corruption-class; the header
|
|
65
|
+
* names the misbehaving writer, and the refusal data names the fetched
|
|
66
|
+
* braid.
|
|
67
|
+
*/
|
|
68
|
+
declare function verifyChain(header: BatchHeader, braid: Braid, slot: Generation, chain: ChainEntry): void;
|
|
69
|
+
export type { BatchHeader, ChainEntry, DecodedBatch, EncodeHeader, Op };
|
|
70
|
+
export { decodeBatch, encodeBatch, verifyChain };
|
|
71
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
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