@mnmal-ai/substrate 0.0.0 → 1.0.0-alpha.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/LICENSE +202 -0
- package/README.md +118 -1
- package/dist/agent-token-BIboWOU0.js +200 -0
- package/dist/client.d.ts +782 -0
- package/dist/client.js +7 -0
- package/dist/cluster-worker.js +35 -0
- package/dist/content-type-C7T28xNb.js +25 -0
- package/dist/dataset-BXkus75W.js +1527 -0
- package/dist/env-utils-B7SGmoeJ.js +21 -0
- package/dist/errors-D4vKuwz8.d.ts +130 -0
- package/dist/fake-DUVtKVSE.js +36 -0
- package/dist/index-D7mSOFlM.d.ts +69 -0
- package/dist/pack.d.ts +192 -0
- package/dist/pack.js +5 -0
- package/dist/plugin-j1jt1l3n.js +3844 -0
- package/dist/plugin-t2g2wX0b.d.ts +1568 -0
- package/dist/proposals-bootstrap.js +37 -0
- package/dist/proposals.config.schema.json +20 -0
- package/dist/proposals.d.ts +118 -0
- package/dist/proposals.default-config.json +4 -0
- package/dist/proposals.js +4 -0
- package/dist/recall-bootstrap.js +451 -0
- package/dist/recall.config.schema.json +232 -0
- package/dist/recall.d.ts +1981 -0
- package/dist/recall.default-config.json +4 -0
- package/dist/recall.js +5 -0
- package/dist/repl-C52wyfMs.js +2213 -0
- package/dist/row-ByLFE2Wx.d.ts +719 -0
- package/dist/row-DK7lPZVe.js +732 -0
- package/dist/runtime-metrics-DwpDJ8vz.d.ts +159 -0
- package/dist/schema-g4FQLr0V.d.ts +433 -0
- package/dist/sdk.d.ts +694 -0
- package/dist/sdk.js +112 -0
- package/dist/src-C4DzaIQZ.js +837 -0
- package/dist/src-CrEgiMJQ.js +1015 -0
- package/dist/src-CzxvmhFn.js +2327 -0
- package/dist/src-D88LvCX8.js +1797 -0
- package/dist/src-D91yij6C.js +13523 -0
- package/dist/src-DuopV8u7.js +2408 -0
- package/dist/substrate-admin.js +808 -0
- package/dist/substrate.js +5477 -0
- package/dist/testing.d.ts +1240 -0
- package/dist/testing.js +702 -0
- package/dist/types-8c0gtnd2.d.ts +35 -0
- package/dist/ws-C72iVS5T.d.ts +143 -0
- package/package.json +117 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
+
//#region ../../packages/substrate-types/src/env-utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Pure env-string parsing helpers shared by plugins and deployment helpers
|
|
5
|
+
* (e.g. `substrate-sentinel-client`) without a substrate-sdk runtime dep.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Strict positive-integer env parsing. Returns `fallback` when `raw` is
|
|
9
|
+
* undefined (env var unset). Throws with `envVar` in the message when `raw`
|
|
10
|
+
* is set but not a positive integer — never falls back on invalid input, so
|
|
11
|
+
* a config typo fails at boot.
|
|
12
|
+
*/
|
|
13
|
+
function parsePositiveInt(raw, envVar, fallback) {
|
|
14
|
+
if (raw === void 0) return fallback;
|
|
15
|
+
const n = Number(raw);
|
|
16
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) throw new Error(`${envVar} must be a positive integer (got '${raw}')`);
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { parsePositiveInt as t };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { h as EdgeRef, p as Edge } from "./schema-g4FQLr0V.js";
|
|
2
|
+
//#region ../../packages/substrate-types/src/errors.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Throwable by a resolver to surface a structured per-frame error with a
|
|
5
|
+
* caller-chosen `code` instead of the generic `resolver_error`. The engine's
|
|
6
|
+
* mutate / query / subscribe / stream paths all catch this class alongside
|
|
7
|
+
* `RestrictViolation` and translate it into an envelope error
|
|
8
|
+
* `{ message, code, path: [key] }`.
|
|
9
|
+
*
|
|
10
|
+
* Use it when a resolver needs to refuse a frame with policy-style semantics
|
|
11
|
+
* but the decision depends on runtime state that a `Policy` can't cleanly
|
|
12
|
+
* express, or when the rejection has a distinct code the client should be
|
|
13
|
+
* able to branch on.
|
|
14
|
+
*/
|
|
15
|
+
declare class ResolverFrameError extends Error {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** Cross-realm brand: stays true on every subclass even when `name` is
|
|
18
|
+
* overridden (e.g. MissingReferentError). isResolverFrameError checks this
|
|
19
|
+
* rather than `name`, which a subclass may re-tag. */
|
|
20
|
+
readonly __substrateResolverFrameError = true;
|
|
21
|
+
readonly code: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional structured payload carried alongside `code` + `message` for
|
|
24
|
+
* programmatic discrimination (NL agents, MCP clients, test assertions).
|
|
25
|
+
* Common shape: `{ field: '<rejected-field-name>' }` for field-rejection
|
|
26
|
+
* codes. The engine projects this verbatim onto the envelope error's
|
|
27
|
+
* `details` slot when present; absent → no `details` key in the envelope.
|
|
28
|
+
*/
|
|
29
|
+
readonly details?: Record<string, unknown>;
|
|
30
|
+
constructor(code: string, message: string, details?: Record<string, unknown>);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown by a write-path resolver when a crossRef declaring `onMissing: 'reject'`
|
|
34
|
+
* references a target that does not exist (or has been tombstoned). Extends
|
|
35
|
+
* ResolverFrameError so the engine's existing catch branch surfaces it as a
|
|
36
|
+
* clean `missing_referent` envelope error with structured `details`.
|
|
37
|
+
*/
|
|
38
|
+
declare class MissingReferentError extends ResolverFrameError {
|
|
39
|
+
readonly name = "MissingReferentError";
|
|
40
|
+
constructor(field: string, target: {
|
|
41
|
+
ns: string;
|
|
42
|
+
type: string;
|
|
43
|
+
id: string | number;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Thrown by a substrate when a where-clause predicate cannot be honoured —
|
|
48
|
+
* an operator the compiler has no case for, or an operand whose shape the
|
|
49
|
+
* operator cannot use (`in` given a string, `between` given one element).
|
|
50
|
+
*
|
|
51
|
+
* Not redundant with the upstream filter validator: it only runs for entries
|
|
52
|
+
* with a schema to walk, so virtual, custom-resolver and dataset-less entries
|
|
53
|
+
* reach the substrate unvalidated. Without this throw a substrate silently
|
|
54
|
+
* drops the predicate (matching everything) or matches nothing.
|
|
55
|
+
*/
|
|
56
|
+
declare class UnsupportedFilterError extends ResolverFrameError {
|
|
57
|
+
readonly name = "UnsupportedFilterError";
|
|
58
|
+
constructor(field: string, operator: string, reason: string);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Thrown by `deleteRow` when a target's incoming edges include at least one
|
|
62
|
+
* live edge with `policy: 'restrict'`. The engine catches and surfaces a
|
|
63
|
+
* structured `restrict` envelope error rather than rolling back. Spec §6.2.
|
|
64
|
+
*/
|
|
65
|
+
declare class RestrictViolation extends Error {
|
|
66
|
+
readonly name = "RestrictViolation";
|
|
67
|
+
readonly blockedBy: Edge[];
|
|
68
|
+
constructor(ref: EdgeRef, blockedBy: Edge[]);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Thrown by `Dataset` implementations when a caller-supplied namespace
|
|
72
|
+
* doesn't match the dataset's bound namespace. Spec §4.5. Shared here so
|
|
73
|
+
* `instanceof` works across dataset impls.
|
|
74
|
+
*/
|
|
75
|
+
declare class NamespaceMismatch extends Error {
|
|
76
|
+
readonly name = "NamespaceMismatch";
|
|
77
|
+
constructor(expected: string, actual: string);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Thrown by `Dataset.updateField` when the caller targets a reserved
|
|
81
|
+
* field name (e.g. `_deletedAt`). Spec §4.5.
|
|
82
|
+
*/
|
|
83
|
+
declare class ReservedField extends Error {
|
|
84
|
+
readonly name = "ReservedField";
|
|
85
|
+
constructor(field: string);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The `(auth)` tag `HttpBridgeClient` appends to a 401/403 cause. Single
|
|
89
|
+
* source of truth for the convention: the error message wording and the
|
|
90
|
+
* engine's `bridge_auth_failed` metric both key off it, and they must agree.
|
|
91
|
+
*/
|
|
92
|
+
declare function isAuthCause(cause: unknown): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Thrown by `BridgeClient` implementations when the remote can't be reached,
|
|
95
|
+
* or refuses the credential. Spec §5.8 ("Reads are timeout-bound. On
|
|
96
|
+
* unreachable target → surface as `{ __orphan: true, reason:
|
|
97
|
+
* 'bridge_unreachable' }`") + §6.5 ("Reads never fail"). Caught by the engine
|
|
98
|
+
* + sweep via instanceof to translate into the sentinel envelope without
|
|
99
|
+
* rolling back the surrounding tx.
|
|
100
|
+
*/
|
|
101
|
+
declare class BridgeUnreachableError extends Error {
|
|
102
|
+
readonly name = "BridgeUnreachableError";
|
|
103
|
+
readonly bridgeName: string;
|
|
104
|
+
readonly baseUrl: string;
|
|
105
|
+
readonly cause: unknown;
|
|
106
|
+
constructor(bridgeName: string, baseUrl: string, cause: unknown);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Recognise a {@link ResolverFrameError} across module-realm boundaries.
|
|
110
|
+
*
|
|
111
|
+
* Plain `instanceof` is realm-fragile whenever this class exists twice in one
|
|
112
|
+
* process: an error thrown by a plugin resolver is then NOT `instanceof` the
|
|
113
|
+
* engine's class even though it is structurally the same type. Two copies
|
|
114
|
+
* arise from version skew between host and plugin installs, or from a
|
|
115
|
+
* consumer that bundles this package.
|
|
116
|
+
*
|
|
117
|
+
* Accepts the dedicated
|
|
118
|
+
* `__substrateResolverFrameError` brand (which survives on subclasses even when
|
|
119
|
+
* `name` is overridden, e.g. `MissingReferentError`) OR the legacy
|
|
120
|
+
* `name === 'ResolverFrameError'` tag, in both cases gated on a string `code`.
|
|
121
|
+
*/
|
|
122
|
+
declare function isResolverFrameError(err: unknown): err is ResolverFrameError;
|
|
123
|
+
/**
|
|
124
|
+
* Recognise a {@link RestrictViolation} across module-realm boundaries — same
|
|
125
|
+
* realm-fragility rationale as {@link isResolverFrameError}. Brands on `name`
|
|
126
|
+
* plus the discriminating `blockedBy` array.
|
|
127
|
+
*/
|
|
128
|
+
declare function isRestrictViolation(err: unknown): err is RestrictViolation;
|
|
129
|
+
//#endregion
|
|
130
|
+
export { ResolverFrameError as a, isAuthCause as c, ReservedField as i, isResolverFrameError as l, MissingReferentError as n, RestrictViolation as o, NamespaceMismatch as r, UnsupportedFilterError as s, BridgeUnreachableError as t, isRestrictViolation as u };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/substrate-embedder/src/fake.ts
|
|
5
|
+
/**
|
|
6
|
+
* FakeEmbedder — deterministic hash-based embeddings for tests. Produces
|
|
7
|
+
* a repeatable Float32Array of the configured dimension from any input
|
|
8
|
+
* string. Never calls out to a real embedder. modelId = `fake:v1:<dim>`
|
|
9
|
+
* so test vectors never collide with real-model vectors when both land
|
|
10
|
+
* in the same dev database.
|
|
11
|
+
*/
|
|
12
|
+
var FakeEmbedder = class {
|
|
13
|
+
modelId;
|
|
14
|
+
dimension;
|
|
15
|
+
constructor(opts = {}) {
|
|
16
|
+
this.dimension = opts.dimension ?? 384;
|
|
17
|
+
this.modelId = `fake:v1:${this.dimension}`;
|
|
18
|
+
}
|
|
19
|
+
async embed(text) {
|
|
20
|
+
const out = new Float32Array(this.dimension);
|
|
21
|
+
let counter = 0;
|
|
22
|
+
let filled = 0;
|
|
23
|
+
while (filled < this.dimension) {
|
|
24
|
+
const hash = createHash("sha256").update(`${counter}:${text}`).digest();
|
|
25
|
+
for (let offset = 0; offset < hash.length && filled < this.dimension; offset += 4) {
|
|
26
|
+
const int = hash.readInt32BE(offset);
|
|
27
|
+
out[filled++] = int / 2147483648;
|
|
28
|
+
}
|
|
29
|
+
counter++;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { FakeEmbedder as t };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { l as PackEnvelope, n as FieldDef, s as FieldInput, u as Schema } from "./schema-g4FQLr0V.js";
|
|
2
|
+
import { pack as packFrame, unpack as unpackFrame } from "msgpackr";
|
|
3
|
+
//#region ../../packages/substrate-pack/src/decoder.d.ts
|
|
4
|
+
interface DecodeContext {
|
|
5
|
+
schemas?: Record<string, Schema>;
|
|
6
|
+
currentNs: string;
|
|
7
|
+
}
|
|
8
|
+
interface DecodeEnvelopeCtx {
|
|
9
|
+
fieldsByKey: Record<string, FieldInput>;
|
|
10
|
+
/**
|
|
11
|
+
* Mutation-path return-shape map — symmetric to `EncodeEnvelopeCtx.returnsByKey`.
|
|
12
|
+
* A key listed here is decoded using `decodePositionalFromFieldDef` instead
|
|
13
|
+
* of the client-sent FieldInput.
|
|
14
|
+
*/
|
|
15
|
+
returnsByKey?: Record<string, FieldDef>;
|
|
16
|
+
typeByKey: Record<string, string>;
|
|
17
|
+
schemas: Record<string, Schema>;
|
|
18
|
+
currentNsByKey: Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Expected schema version — §7.1 drift check. When set, the decoder
|
|
21
|
+
* compares `envelope.schemaVersion` before decoding any data value; a
|
|
22
|
+
* mismatch throws `SchemaDriftError`. When undefined the drift check is
|
|
23
|
+
* skipped (callers without a cached version, e.g. server self-roundtrip,
|
|
24
|
+
* shouldn't fail on their own envelopes).
|
|
25
|
+
*/
|
|
26
|
+
expectedSchemaVersion?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @internal — error thrown by the positional decoder on malformed input.
|
|
30
|
+
* Exported, but treat as package-private; signature may change without a
|
|
31
|
+
* major bump.
|
|
32
|
+
*/
|
|
33
|
+
declare class PackDecodeError extends Error {
|
|
34
|
+
readonly name = "PackDecodeError";
|
|
35
|
+
readonly path: string[];
|
|
36
|
+
constructor(message: string, path: string[]);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* §7.1 loud-failure. Thrown by `decodeEnvelope` when the caller supplied an
|
|
40
|
+
* `expectedSchemaVersion` that disagrees with the envelope's declared version.
|
|
41
|
+
* Carries both sides of the mismatch so the caller can decide whether to
|
|
42
|
+
* refetch the federated schema and retry or surface the error.
|
|
43
|
+
*/
|
|
44
|
+
declare class SchemaDriftError extends Error {
|
|
45
|
+
readonly envelopeSchemaVersion: string;
|
|
46
|
+
readonly expectedSchemaVersion: string;
|
|
47
|
+
readonly name = "SchemaDriftError";
|
|
48
|
+
constructor(envelopeSchemaVersion: string, expectedSchemaVersion: string);
|
|
49
|
+
}
|
|
50
|
+
declare function decodePositional<T = unknown>(encoded: unknown, fields: FieldInput, schema: Schema, typeName: string, ctx: DecodeContext): T;
|
|
51
|
+
/**
|
|
52
|
+
* Decode a mutation response against its declared `FieldDef`. Symmetric to
|
|
53
|
+
* `encodePositionalFromFieldDef`.
|
|
54
|
+
*
|
|
55
|
+
* @internal — used by `decodeEnvelope` for mutation returns. Treat as
|
|
56
|
+
* package-private.
|
|
57
|
+
*/
|
|
58
|
+
declare function decodePositionalFromFieldDef<T = unknown>(encoded: unknown, def: FieldDef, schema: Schema, ctx: DecodeContext, path?: string[]): T;
|
|
59
|
+
declare function decodeEnvelope(bytes: Buffer | Uint8Array, ctx: DecodeEnvelopeCtx): PackEnvelope;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../../packages/substrate-pack/src/index.d.ts
|
|
62
|
+
/**
|
|
63
|
+
* WebSocket subprotocol advertised in `Sec-WebSocket-Protocol` at handshake
|
|
64
|
+
* time. Connections negotiating this subprotocol receive msgpack frames with
|
|
65
|
+
* positionally-encoded `data`; anything else falls back to JSON.
|
|
66
|
+
*/
|
|
67
|
+
declare const WS_SUBPROTOCOL_SUBSTRATE_PACK = "substrate-pack";
|
|
68
|
+
//#endregion
|
|
69
|
+
export { DecodeEnvelopeCtx as a, decodeEnvelope as c, DecodeContext as i, decodePositional as l, packFrame as n, PackDecodeError as o, unpackFrame as r, SchemaDriftError as s, WS_SUBPROTOCOL_SUBSTRATE_PACK as t, decodePositionalFromFieldDef as u };
|
package/dist/pack.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { l as PackEnvelope, n as FieldDef, s as FieldInput, u as Schema } from "./schema-g4FQLr0V.js";
|
|
2
|
+
import { a as DecodeEnvelopeCtx, c as decodeEnvelope, i as DecodeContext, l as decodePositional, n as packFrame, o as PackDecodeError, r as unpackFrame, s as SchemaDriftError, t as WS_SUBPROTOCOL_SUBSTRATE_PACK, u as decodePositionalFromFieldDef } from "./index-D7mSOFlM.js";
|
|
3
|
+
//#region ../../packages/substrate-pack/src/content-type.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Content-type negotiation. Spec: §7.0.
|
|
6
|
+
*
|
|
7
|
+
* A request that advertises `Accept: application/vnd.substrate.pack` gets the binary
|
|
8
|
+
* envelope; anything else falls back to JSON. We deliberately skip RFC 7231
|
|
9
|
+
* q-value ranking — the useful scenarios are exact match, the `; q=…` form,
|
|
10
|
+
* and comma-separated clauses. A real parser is overkill for a single-mime
|
|
11
|
+
* negotiation.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PACK_MIME = "application/vnd.substrate.pack";
|
|
14
|
+
export declare function acceptsPack(acceptHeader: string | undefined): boolean;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region ../../packages/substrate-pack/src/encoder.d.ts
|
|
17
|
+
interface EncodeContext {
|
|
18
|
+
/** Federated schema map — required when the type has any crossRef fields selected. */
|
|
19
|
+
schemas?: Record<string, Schema>;
|
|
20
|
+
/** Namespace owning the current type. Used to detect crossRef boundary crossings. */
|
|
21
|
+
currentNs: string;
|
|
22
|
+
}
|
|
23
|
+
interface EncodeEnvelopeCtx {
|
|
24
|
+
/** Query-path selection map — keyed by envelope key. */
|
|
25
|
+
fieldsByKey: Record<string, FieldInput>;
|
|
26
|
+
/**
|
|
27
|
+
* Mutation-path return-shape map — keyed by envelope key. Mutation responses
|
|
28
|
+
* don't carry a client-sent FieldInput; their shape is declared at registry
|
|
29
|
+
* time as `MutationSchema.returns` and wired through here.
|
|
30
|
+
*/
|
|
31
|
+
returnsByKey?: Record<string, FieldDef>;
|
|
32
|
+
/** Query-path type-name map — keyed by envelope key. */
|
|
33
|
+
typeByKey: Record<string, string>;
|
|
34
|
+
schemas: Record<string, Schema>;
|
|
35
|
+
/** Namespace owning each envelope key's type or mutation. */
|
|
36
|
+
currentNsByKey: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @internal — error thrown by the positional encoder on malformed input.
|
|
40
|
+
* Exported, but treat as package-private.
|
|
41
|
+
*/
|
|
42
|
+
export declare class PackEncodeError extends Error {
|
|
43
|
+
readonly name = "PackEncodeError";
|
|
44
|
+
readonly path: string[];
|
|
45
|
+
constructor(message: string, path: string[]);
|
|
46
|
+
}
|
|
47
|
+
export declare function encodePositional(value: unknown, fields: FieldInput, schema: Schema, typeName: string, ctx: EncodeContext): unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Encode a mutation response against its declared `FieldDef` (no client-sent
|
|
50
|
+
* FieldInput). Symmetric to `encodePositional` but driven entirely by the
|
|
51
|
+
* schema descriptor.
|
|
52
|
+
*
|
|
53
|
+
* - `scalar` → value passes through (nullable tolerated)
|
|
54
|
+
* - `struct` → positional tuple over `def.fields` iteration order
|
|
55
|
+
* - `list` → value is an array; each element encoded against `def.of`
|
|
56
|
+
* - `crossRef` → value is expected to be an id scalar (eq-on-id; we don't
|
|
57
|
+
* recurse into the target type — mutation returns don't embed sub-rows)
|
|
58
|
+
*
|
|
59
|
+
* @internal — used by `encodeEnvelope` for mutation returns. Treat as
|
|
60
|
+
* package-private.
|
|
61
|
+
*/
|
|
62
|
+
export declare function encodePositionalFromFieldDef(value: unknown, def: FieldDef, schema: Schema, ctx: EncodeContext, path?: string[]): unknown;
|
|
63
|
+
export declare function encodeEnvelope(envelope: PackEnvelope, ctx: EncodeEnvelopeCtx): Buffer;
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region ../../packages/substrate-pack/src/stream-chunk.d.ts
|
|
66
|
+
/**
|
|
67
|
+
* Per §7.4. `shape` is fixed to `'single'`; chunks never carry a list.
|
|
68
|
+
*/
|
|
69
|
+
interface PackStreamChunk {
|
|
70
|
+
schemaVersion: string;
|
|
71
|
+
streamId: string;
|
|
72
|
+
sequence: number;
|
|
73
|
+
shape: 'single';
|
|
74
|
+
data: unknown;
|
|
75
|
+
final?: boolean;
|
|
76
|
+
_meta?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
interface EncodeStreamChunkInput {
|
|
79
|
+
schemaVersion: string;
|
|
80
|
+
streamId: string;
|
|
81
|
+
sequence: number;
|
|
82
|
+
/** Named-object row (the shape resolvers yield). */
|
|
83
|
+
row: unknown;
|
|
84
|
+
/** Selection tree as sent by the client; drives positional field ordering. */
|
|
85
|
+
fields: FieldInput;
|
|
86
|
+
/** Schema of the stream's owning namespace — matches `schemas[currentNs]`. */
|
|
87
|
+
schema: Schema;
|
|
88
|
+
/** Type name the stream resolver targets (e.g. `'Todo'`). */
|
|
89
|
+
typeName: string;
|
|
90
|
+
/** Owning namespace. Used for crossRef boundary detection in the encoder. */
|
|
91
|
+
currentNs: string;
|
|
92
|
+
/** Optional full federated schema map — required if the type has crossRefs. */
|
|
93
|
+
schemas?: Record<string, Schema>;
|
|
94
|
+
final?: boolean;
|
|
95
|
+
meta?: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
interface DecodeStreamChunkInput {
|
|
98
|
+
/** Selection tree used to encode — drives the same iteration order on decode. */
|
|
99
|
+
fields: FieldInput;
|
|
100
|
+
schema: Schema;
|
|
101
|
+
typeName: string;
|
|
102
|
+
currentNs: string;
|
|
103
|
+
schemas?: Record<string, Schema>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Pack a chunk into a msgpack buffer. The row is positionally encoded first,
|
|
107
|
+
* then the whole sub-envelope is serialised in one pass.
|
|
108
|
+
*/
|
|
109
|
+
export declare function encodeStreamChunk(input: EncodeStreamChunkInput): Buffer;
|
|
110
|
+
/**
|
|
111
|
+
* Unpack a chunk and reconstruct the named-object row using the same selection
|
|
112
|
+
* tree + schema the encoder saw. `schemaVersion`, `sequence`, `final`, and
|
|
113
|
+
* `_meta` round-trip unchanged.
|
|
114
|
+
*/
|
|
115
|
+
export declare function decodeStreamChunk<T = unknown>(bytes: Buffer | Uint8Array, input: DecodeStreamChunkInput): PackStreamChunk & {
|
|
116
|
+
data: T;
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region ../../packages/substrate-pack/src/wire.d.ts
|
|
120
|
+
type WireMode = 'json' | 'pack';
|
|
121
|
+
/**
|
|
122
|
+
* Encode an outbound WS frame. Pack mode returns msgpack bytes; JSON mode
|
|
123
|
+
* returns stringified text. The `mode` argument is the wire-format discriminant
|
|
124
|
+
* — call sites can route the result to the right `WebSocket.send` overload via
|
|
125
|
+
* a typed `typeof wire === 'string'` branch.
|
|
126
|
+
*/
|
|
127
|
+
export declare function encodeWsFrame(value: unknown, mode: WireMode): string | Uint8Array;
|
|
128
|
+
/**
|
|
129
|
+
* Decode an inbound WS message envelope (the outer `{ id, kind, data?, ... }`
|
|
130
|
+
* shape — positional `data` reconstruction is a separate concern handled by
|
|
131
|
+
* `applyDecodePlanInPlace`).
|
|
132
|
+
*
|
|
133
|
+
* The `mode` discriminant determines how `raw` is interpreted: pack-mode
|
|
134
|
+
* messages arrive as `ArrayBuffer | Uint8Array | Buffer` and are msgpack-
|
|
135
|
+
* decoded; JSON-mode messages arrive as `string` (or, when node-ws hands the
|
|
136
|
+
* payload across as binary, as bytes that we coerce back to text before
|
|
137
|
+
* `JSON.parse`).
|
|
138
|
+
*
|
|
139
|
+
* The runtime narrowing is centralized here so callers don't reach for
|
|
140
|
+
* `raw as string` casts at every call site.
|
|
141
|
+
*/
|
|
142
|
+
export declare function decodeWsEnvelope<T = unknown>(raw: unknown, mode: WireMode): T;
|
|
143
|
+
/**
|
|
144
|
+
* Whether a decoded request holds only JSON-shaped data (plus `Date`, which
|
|
145
|
+
* msgpack timestamps decode to), no deeper than 64 levels. A server refuses
|
|
146
|
+
* anything else: RegExp, Set, Map, BigInt, typed arrays and the like.
|
|
147
|
+
*/
|
|
148
|
+
export declare function isPlainRequestData(value: unknown, depth?: number): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* A single precomputed entry in a WS pack-decode plan. All per-key lookups
|
|
151
|
+
* (parseQualifiedKey, schema probe, fields narrow) happen once at plan-build
|
|
152
|
+
* time; per-frame decoding then iterates the plan directly.
|
|
153
|
+
*
|
|
154
|
+
* `opts` is captured at plan-build time and shared across every frame for the
|
|
155
|
+
* same qkey — the `{ schemas, currentNs }` pair is invariant for the
|
|
156
|
+
* subscription lifetime.
|
|
157
|
+
*/
|
|
158
|
+
type DecodePlanEntry = {
|
|
159
|
+
qkey: string;
|
|
160
|
+
name: string;
|
|
161
|
+
schema: Schema;
|
|
162
|
+
fields: FieldInput;
|
|
163
|
+
opts: {
|
|
164
|
+
schemas: Record<string, Schema>;
|
|
165
|
+
currentNs: string;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
/** Frame-spec input shape — duck-typed so multiple call-site frame types fit. */
|
|
169
|
+
interface FrameSpecEntry {
|
|
170
|
+
params?: unknown;
|
|
171
|
+
fields?: unknown;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Build the decode plan from a frame spec map + federated schemas. Called
|
|
175
|
+
* once per subscription, before the first frame arrives. Keys that are
|
|
176
|
+
* unqualified, have no matching schema, or have no field selection are
|
|
177
|
+
* skipped.
|
|
178
|
+
*/
|
|
179
|
+
export declare function buildDecodePlan(frameSpec: Record<string, FrameSpecEntry>, schemas: Record<string, Schema>): DecodePlanEntry[];
|
|
180
|
+
/**
|
|
181
|
+
* Apply a precomputed decode plan to an envelope's `data` map in place.
|
|
182
|
+
* Mutates `envelope.data[qkey]` from positional tuple to named object/list
|
|
183
|
+
* for each plan entry whose qkey is present.
|
|
184
|
+
*
|
|
185
|
+
* Accepts `unknown` so both `WsResponseFrame` and the data-bearing
|
|
186
|
+
* `SubscribeEvent` variants flow through without a parameter-type cast at the
|
|
187
|
+
* call site; remove/end/error frames lack a `data` property and short-circuit
|
|
188
|
+
* here.
|
|
189
|
+
*/
|
|
190
|
+
export declare function applyDecodePlanInPlace(envelope: unknown, plan: DecodePlanEntry[]): void;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { type DecodeContext, type DecodeEnvelopeCtx, type DecodePlanEntry, type DecodeStreamChunkInput, type EncodeContext, type EncodeEnvelopeCtx, type EncodeStreamChunkInput, type FrameSpecEntry, PackDecodeError, type PackStreamChunk, SchemaDriftError, WS_SUBPROTOCOL_SUBSTRATE_PACK, type WireMode, decodeEnvelope, decodePositional, decodePositionalFromFieldDef, packFrame, unpackFrame };
|
package/dist/pack.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
+
import { _ as decodeEnvelope, a as buildDecodePlan, c as isPlainRequestData, d as PackEncodeError, f as encodeEnvelope, g as SchemaDriftError, h as PackDecodeError, i as applyDecodePlanInPlace, l as decodeStreamChunk, m as encodePositionalFromFieldDef, n as packFrame, o as decodeWsEnvelope, p as encodePositional, r as unpackFrame, s as encodeWsFrame, t as WS_SUBPROTOCOL_SUBSTRATE_PACK, u as encodeStreamChunk, v as decodePositional, y as decodePositionalFromFieldDef } from "./src-C4DzaIQZ.js";
|
|
3
|
+
import { n as acceptsPack, t as PACK_MIME } from "./content-type-C7T28xNb.js";
|
|
4
|
+
|
|
5
|
+
export { PACK_MIME, PackDecodeError, PackEncodeError, SchemaDriftError, WS_SUBPROTOCOL_SUBSTRATE_PACK, acceptsPack, applyDecodePlanInPlace, buildDecodePlan, decodeEnvelope, decodePositional, decodePositionalFromFieldDef, decodeStreamChunk, decodeWsEnvelope, encodeEnvelope, encodePositional, encodePositionalFromFieldDef, encodeStreamChunk, encodeWsFrame, isPlainRequestData, packFrame, unpackFrame };
|