@peerbit/blocks-interface 2.1.7 → 2.1.8

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.
@@ -17,7 +17,47 @@ export type CrashSafeBlockDurability = {
17
17
  readonly crashSafe: true;
18
18
  barrier(): MaybePromise<void>;
19
19
  };
20
+ /**
21
+ * Scope across which local references to a content-addressed block may alias.
22
+ *
23
+ * `block-service` is the scope of Peerbit's built-in stores: the backing
24
+ * namespace belongs to one blocks service, but every program using that
25
+ * service shares it. `caller-exclusive` is an explicit assertion that the
26
+ * declaring caller controls the entire physical namespace and every reference
27
+ * in it. `shared` means references may exist outside this block service;
28
+ * `unknown` makes no reliable scope assertion. Neither persistence nor a
29
+ * backend class implies any scope.
30
+ */
31
+ export type BlockStoreReferenceDomain = "block-service" | "caller-exclusive" | "shared" | "unknown";
32
+ /**
33
+ * Immutable facts needed before a caller considers physical block deletion.
34
+ *
35
+ * `enforcedReclamation: "none"` means the store exposes no reference-safe
36
+ * lease, fencing, atomic delete-if-unreferenced, or isolated-namespace
37
+ * primitive. A raw `rm` is therefore safe only for an authority that controls
38
+ * the complete reference domain. This field is deliberately separate from
39
+ * `persisted()`.
40
+ */
41
+ export type BlockStoreSafety = Readonly<{
42
+ referenceDomain: BlockStoreReferenceDomain;
43
+ enforcedReclamation: "none";
44
+ }>;
45
+ export declare const UNKNOWN_BLOCK_STORE_SAFETY: BlockStoreSafety;
46
+ export declare const BLOCK_SERVICE_BLOCK_STORE_SAFETY: BlockStoreSafety;
47
+ /**
48
+ * Validate, defensively copy, and freeze block-store safety metadata.
49
+ *
50
+ * The input is intentionally `unknown`: declarations can cross JavaScript and
51
+ * configuration boundaries where TypeScript's static shape is unavailable.
52
+ */
53
+ export declare const normalizeBlockStoreSafety: (value: unknown) => BlockStoreSafety;
20
54
  export interface Blocks extends WaitForPeer {
55
+ /**
56
+ * Safety metadata for this service's local physical block namespace.
57
+ * Absence is equivalent to {@link UNKNOWN_BLOCK_STORE_SAFETY} so older and
58
+ * custom implementations fail closed.
59
+ */
60
+ readonly localStoreSafety?: BlockStoreSafety;
21
61
  put(data: Uint8Array | {
22
62
  block: Block<any, any, any, any>;
23
63
  cid: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,CAAC,EACJ;QACA,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACjB,GACD,OAAO,CAAC;CACX,CAAC;AACF,MAAM,MAAM,UAAU,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACtC,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,WAAW,MAAO,SAAQ,WAAW;IAC1C,GAAG,CACF,IAAI,EAAE,UAAU,GAAG;QAAE,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAClE,YAAY,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,CACP,IAAI,EAAE,KAAK,CAAC,UAAU,GAAG;QAAE,KAAK,EAAE,KAAK,CAAC,GAAG,EAA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,EAAE,UAAU,GAAG,YAAY,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IAC7E,OAAO,CAAC,CACP,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,UAAU,GAClB,YAAY,CAAC,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/C;;;;OAIG;IACH,aAAa,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACvD,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACpC,QAAQ,IAAI,cAAc,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7D,IAAI,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7B,SAAS,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACnC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,wBAAwB,CAAC;CACxD;AAED,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,QAAQ,GACR,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,4 +1,39 @@
1
1
  import {} from "@peerbit/stream-interface";
2
2
  import {} from "multiformats/block";
3
+ export const UNKNOWN_BLOCK_STORE_SAFETY = Object.freeze({
4
+ referenceDomain: "unknown",
5
+ enforcedReclamation: "none",
6
+ });
7
+ export const BLOCK_SERVICE_BLOCK_STORE_SAFETY = Object.freeze({
8
+ referenceDomain: "block-service",
9
+ enforcedReclamation: "none",
10
+ });
11
+ /**
12
+ * Validate, defensively copy, and freeze block-store safety metadata.
13
+ *
14
+ * The input is intentionally `unknown`: declarations can cross JavaScript and
15
+ * configuration boundaries where TypeScript's static shape is unavailable.
16
+ */
17
+ export const normalizeBlockStoreSafety = (value) => {
18
+ if (value === undefined)
19
+ return UNKNOWN_BLOCK_STORE_SAFETY;
20
+ if (value === null || typeof value !== "object") {
21
+ throw new TypeError("Invalid block-store safety metadata");
22
+ }
23
+ const referenceDomain = value
24
+ .referenceDomain;
25
+ const enforcedReclamation = value
26
+ .enforcedReclamation;
27
+ if (referenceDomain !== "block-service" &&
28
+ referenceDomain !== "caller-exclusive" &&
29
+ referenceDomain !== "shared" &&
30
+ referenceDomain !== "unknown") {
31
+ throw new TypeError("Invalid block-store reference domain");
32
+ }
33
+ if (enforcedReclamation !== "none") {
34
+ throw new TypeError("Unsupported block-store reclamation capability");
35
+ }
36
+ return Object.freeze({ referenceDomain, enforcedReclamation });
37
+ };
3
38
  export { cidifyString, stringifyCid, createBlock, getBlockValue, calculateRawCid, checkDecodeBlock, verifyBlockBytes, codecCodes, defaultHasher, codecMap, } from "./block.js";
4
39
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAc,MAAM,oBAAoB,CAAC;AAgEhD,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,QAAQ,GACR,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAc,MAAM,oBAAoB,CAAC;AAsDhD,MAAM,CAAC,MAAM,0BAA0B,GAAqB,MAAM,CAAC,MAAM,CAAC;IACzE,eAAe,EAAE,SAAS;IAC1B,mBAAmB,EAAE,MAAM;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAqB,MAAM,CAAC,MAAM,CAC9E;IACC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,MAAM;CAC3B,CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACxC,KAAc,EACK,EAAE;IACrB,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,0BAA0B,CAAC;IAC3D,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACjD,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,eAAe,GAAI,KAAuC;SAC9D,eAAe,CAAC;IAClB,MAAM,mBAAmB,GAAI,KAA2C;SACtE,mBAAmB,CAAC;IACtB,IACC,eAAe,KAAK,eAAe;QACnC,eAAe,KAAK,kBAAkB;QACtC,eAAe,KAAK,QAAQ;QAC5B,eAAe,KAAK,SAAS,EAC5B,CAAC;QACF,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,mBAAmB,KAAK,MAAM,EAAE,CAAC;QACpC,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC,CAAC;AAChE,CAAC,CAAC;AAiDF,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,QAAQ,GACR,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/blocks-interface",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "Block store streaming",
5
5
  "type": "module",
6
6
  "sideEffects": false,
package/src/index.ts CHANGED
@@ -22,7 +22,87 @@ export type CrashSafeBlockDurability = {
22
22
  barrier(): MaybePromise<void>;
23
23
  };
24
24
 
25
+ /**
26
+ * Scope across which local references to a content-addressed block may alias.
27
+ *
28
+ * `block-service` is the scope of Peerbit's built-in stores: the backing
29
+ * namespace belongs to one blocks service, but every program using that
30
+ * service shares it. `caller-exclusive` is an explicit assertion that the
31
+ * declaring caller controls the entire physical namespace and every reference
32
+ * in it. `shared` means references may exist outside this block service;
33
+ * `unknown` makes no reliable scope assertion. Neither persistence nor a
34
+ * backend class implies any scope.
35
+ */
36
+ export type BlockStoreReferenceDomain =
37
+ | "block-service"
38
+ | "caller-exclusive"
39
+ | "shared"
40
+ | "unknown";
41
+
42
+ /**
43
+ * Immutable facts needed before a caller considers physical block deletion.
44
+ *
45
+ * `enforcedReclamation: "none"` means the store exposes no reference-safe
46
+ * lease, fencing, atomic delete-if-unreferenced, or isolated-namespace
47
+ * primitive. A raw `rm` is therefore safe only for an authority that controls
48
+ * the complete reference domain. This field is deliberately separate from
49
+ * `persisted()`.
50
+ */
51
+ export type BlockStoreSafety = Readonly<{
52
+ referenceDomain: BlockStoreReferenceDomain;
53
+ enforcedReclamation: "none";
54
+ }>;
55
+
56
+ export const UNKNOWN_BLOCK_STORE_SAFETY: BlockStoreSafety = Object.freeze({
57
+ referenceDomain: "unknown",
58
+ enforcedReclamation: "none",
59
+ });
60
+
61
+ export const BLOCK_SERVICE_BLOCK_STORE_SAFETY: BlockStoreSafety = Object.freeze(
62
+ {
63
+ referenceDomain: "block-service",
64
+ enforcedReclamation: "none",
65
+ },
66
+ );
67
+
68
+ /**
69
+ * Validate, defensively copy, and freeze block-store safety metadata.
70
+ *
71
+ * The input is intentionally `unknown`: declarations can cross JavaScript and
72
+ * configuration boundaries where TypeScript's static shape is unavailable.
73
+ */
74
+ export const normalizeBlockStoreSafety = (
75
+ value: unknown,
76
+ ): BlockStoreSafety => {
77
+ if (value === undefined) return UNKNOWN_BLOCK_STORE_SAFETY;
78
+ if (value === null || typeof value !== "object") {
79
+ throw new TypeError("Invalid block-store safety metadata");
80
+ }
81
+ const referenceDomain = (value as { referenceDomain?: unknown })
82
+ .referenceDomain;
83
+ const enforcedReclamation = (value as { enforcedReclamation?: unknown })
84
+ .enforcedReclamation;
85
+ if (
86
+ referenceDomain !== "block-service" &&
87
+ referenceDomain !== "caller-exclusive" &&
88
+ referenceDomain !== "shared" &&
89
+ referenceDomain !== "unknown"
90
+ ) {
91
+ throw new TypeError("Invalid block-store reference domain");
92
+ }
93
+ if (enforcedReclamation !== "none") {
94
+ throw new TypeError("Unsupported block-store reclamation capability");
95
+ }
96
+ return Object.freeze({ referenceDomain, enforcedReclamation });
97
+ };
98
+
25
99
  export interface Blocks extends WaitForPeer {
100
+ /**
101
+ * Safety metadata for this service's local physical block namespace.
102
+ * Absence is equivalent to {@link UNKNOWN_BLOCK_STORE_SAFETY} so older and
103
+ * custom implementations fail closed.
104
+ */
105
+ readonly localStoreSafety?: BlockStoreSafety;
26
106
  put(
27
107
  data: Uint8Array | { block: Block<any, any, any, any>; cid: string },
28
108
  ): MaybePromise<string>;