@mnmal-ai/substrate 1.0.0-alpha.16 → 1.0.0-alpha.18
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/README.md +5 -4
- package/dist/{boot-store-HxCgbvNl.js → boot-store-C8KrACZ5.js} +51 -72
- package/dist/{bridge-CvZGzNIO.d.ts → bridge-5VHZiH9o.d.ts} +1 -1
- package/dist/{cli-6mjAWiEZ.js → cli-zZ7nHhY5.js} +235 -16
- package/dist/client.d.ts +8 -3
- package/dist/client.js +4 -4
- package/dist/{errors-BXxm9eZF.d.ts → errors-DHgT7Fa8.d.ts} +8 -2
- package/dist/{index-EN-nQsX8.d.ts → index-DKJXQ031.d.ts} +1 -1
- package/dist/{node-version-C5FSmwJX.js → node-version-CxqcqECU.js} +1 -1
- package/dist/pack.d.ts +18 -2
- package/dist/pack.js +2 -2
- package/dist/{pg-edges-store-De5F1tUf.js → pg-edges-store-D7etFxNK.js} +1 -1
- package/dist/{plugin-Dpa_Y7Ep.js → plugin-DcoJGEMM.js} +2 -2
- package/dist/proposals-bootstrap.js +2 -2
- package/dist/proposals.d.ts +5 -3
- package/dist/proposals.js +1 -1
- package/dist/recall-bootstrap.js +2 -2
- package/dist/recall.d.ts +1 -1
- package/dist/recall.js +2 -2
- package/dist/{repl-2WfRPUb0.js → repl-SY8cLOZl.js} +1 -1
- package/dist/{row-Dh57ShWL.d.ts → row-DHxnCnhA.d.ts} +10 -8
- package/dist/{run-ChcHBIN3.js → run-Cr-53N3F.js} +142 -106
- package/dist/{schema-B--_bHjn.d.ts → schema-B5WBO8yh.d.ts} +79 -19
- package/dist/{script-C6DSa_Na.js → script-B-32wZGY.js} +11 -1
- package/dist/script-runner.js +78 -0
- package/dist/sdk.d.ts +51 -8
- package/dist/sdk.js +4 -4
- package/dist/{src-B4sqnLRy.js → src-B4dTiEWw.js} +77 -28
- package/dist/{src-DHLw3eCn.js → src-BcuotITf.js} +1016 -231
- package/dist/{src-DWqzrm3O.js → src-CdbUzLhB.js} +209 -36
- package/dist/{src-BMHI_rTJ.js → src-D55T3ZcP.js} +2203 -499
- package/dist/{src-Bi3NhEsT.js → src-DR_hUj2p.js} +1 -1
- package/dist/{src-CHND7-Pm.js → src-DV6PcXym.js} +2 -2
- package/dist/{src--uyAqssS.js → src-DZfgQ2gR.js} +3 -3
- package/dist/substrate-admin.js +2 -2
- package/dist/substrate.js +2 -2
- package/dist/testing.d.ts +5 -3
- package/dist/testing.js +4 -4
- package/dist/{ws-CpHWxwp9.d.ts → ws-BL9nSELO.d.ts} +2 -2
- package/package.json +21 -21
|
@@ -18,6 +18,140 @@ const DEFAULT_FILTER_WRITE_LIMITS = Object.freeze({
|
|
|
18
18
|
idsCap: 1e3
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region ../../packages/substrate-types/src/expression.ts
|
|
23
|
+
const sig = (name, args, returns, description) => ({
|
|
24
|
+
name,
|
|
25
|
+
args,
|
|
26
|
+
returns,
|
|
27
|
+
description
|
|
28
|
+
});
|
|
29
|
+
const CMP = "both sides the same type; int64 and number compare as number.";
|
|
30
|
+
const EXPR_FUNCTIONS = [
|
|
31
|
+
sig("add", ["number", "number"], "any", "Sum; int64 when both are int64 (or a safe-integer literal), else number. Errors on overflow."),
|
|
32
|
+
sig("sub", ["number", "number"], "any", "Difference; int64 when both are int64, else number. Errors on overflow."),
|
|
33
|
+
sig("mul", ["number", "number"], "any", "Product; int64 when both are int64, else number. Errors on overflow, and on a nonzero product that underflows to zero."),
|
|
34
|
+
sig("div", ["number", "number"], "number", "Quotient as a number; null when the divisor is zero. Errors on overflow, and on a nonzero quotient that underflows to zero."),
|
|
35
|
+
sig("mod", ["int64", "int64"], "int64", "Remainder of int64 arguments (a safe-integer literal counts); null when the divisor is zero."),
|
|
36
|
+
sig("neg", ["number"], "any", "Arithmetic negation; keeps int64."),
|
|
37
|
+
sig("eq", ["any", "any"], "boolean", `Equal; ${CMP}`),
|
|
38
|
+
sig("neq", ["any", "any"], "boolean", `Not equal; ${CMP}`),
|
|
39
|
+
sig("gt", ["any", "any"], "boolean", `Greater than; ${CMP}`),
|
|
40
|
+
sig("gte", ["any", "any"], "boolean", `Greater than or equal; ${CMP}`),
|
|
41
|
+
sig("lt", ["any", "any"], "boolean", `Less than; ${CMP}`),
|
|
42
|
+
sig("lte", ["any", "any"], "boolean", `Less than or equal; ${CMP}`),
|
|
43
|
+
sig("and", "variadic", "boolean", "True when every boolean argument (one or more) is true."),
|
|
44
|
+
sig("or", "variadic", "boolean", "True when any boolean argument (one or more) is true."),
|
|
45
|
+
sig("not", ["boolean"], "boolean", "Boolean negation."),
|
|
46
|
+
sig("isNull", ["any"], "boolean", "True when its one argument is null; any type."),
|
|
47
|
+
sig("in", "variadic", "boolean", "True when the first argument equals any later one (two or more arguments share a type)."),
|
|
48
|
+
sig("length", ["string"], "number", "Length in characters."),
|
|
49
|
+
sig("lower", ["string"], "string", "Lower-cased text; ASCII letters only, every other character is unchanged."),
|
|
50
|
+
sig("upper", ["string"], "string", "Upper-cased text; ASCII letters only, every other character is unchanged."),
|
|
51
|
+
sig("substring", [
|
|
52
|
+
"string",
|
|
53
|
+
"number",
|
|
54
|
+
"number"
|
|
55
|
+
], "string", "Substring from a 1-based start for a length."),
|
|
56
|
+
sig("concat", "variadic", "string", "Concatenation of one or more string arguments."),
|
|
57
|
+
sig("like", ["string", "likePattern"], "boolean", "SQL LIKE, case-sensitive: % and _ wildcards, backslash escape. The pattern is a lit that does not end in an unescaped backslash."),
|
|
58
|
+
sig("notLike", ["string", "likePattern"], "boolean", "Negated SQL LIKE, case-sensitive."),
|
|
59
|
+
sig("regexpMatch", ["string", "pattern"], "boolean", "True when the portable-subset regex (a lit) matches anywhere."),
|
|
60
|
+
sig("regexpReplace", [
|
|
61
|
+
"string",
|
|
62
|
+
"pattern",
|
|
63
|
+
"string"
|
|
64
|
+
], "string", "Replace the leftmost-longest regex (a lit) match; the replacement may use \\1 to \\9. The pattern may use capturing groups or |, not both."),
|
|
65
|
+
sig("dateTrunc", ["unit", "date"], "date", "Truncate a date (UTC) to a unit given as a lit."),
|
|
66
|
+
sig("extract", ["unit", "date"], "number", "A date part (UTC) as a number; the unit is a lit."),
|
|
67
|
+
sig("case", "variadic", "any", "Pairs [cond, then] then a final else; branches share a type."),
|
|
68
|
+
sig("coalesce", "variadic", "any", "First non-null of one or more arguments sharing a type.")
|
|
69
|
+
];
|
|
70
|
+
const EXPR_LIMITS = {
|
|
71
|
+
maxDepth: 16,
|
|
72
|
+
maxNodesPerExpr: 64,
|
|
73
|
+
maxNodesPerFrame: 1024
|
|
74
|
+
};
|
|
75
|
+
/** The aggregate names `_agg`, `having` and grouped reads accept. */
|
|
76
|
+
const EXPR_AGGREGATES = [
|
|
77
|
+
"count",
|
|
78
|
+
"countDistinct",
|
|
79
|
+
"sum",
|
|
80
|
+
"avg",
|
|
81
|
+
"min",
|
|
82
|
+
"max"
|
|
83
|
+
];
|
|
84
|
+
const DATE_UNITS = [
|
|
85
|
+
"second",
|
|
86
|
+
"minute",
|
|
87
|
+
"hour",
|
|
88
|
+
"day",
|
|
89
|
+
"week",
|
|
90
|
+
"month",
|
|
91
|
+
"year"
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../../packages/substrate-types/src/int64.ts
|
|
96
|
+
const MIN_INT64 = -(2n ** 63n);
|
|
97
|
+
const MAX_INT64 = 2n ** 63n - 1n;
|
|
98
|
+
const MIN_INT16 = -(2 ** 15);
|
|
99
|
+
const MAX_INT16 = 2 ** 15 - 1;
|
|
100
|
+
const MIN_INT32 = -(2 ** 31);
|
|
101
|
+
const MAX_INT32 = 2 ** 31 - 1;
|
|
102
|
+
const CANONICAL_INT = /^-?(0|[1-9]\d*)$/;
|
|
103
|
+
/**
|
|
104
|
+
* An `int64` operand or write value as a bigint: a bigint, a safe-integer
|
|
105
|
+
* number, or a canonical decimal string, within the int64 range. Anything else
|
|
106
|
+
* (a float, a number past 2^53, `'007'`, `'1e3'`, an out-of-range value) is
|
|
107
|
+
* `undefined`.
|
|
108
|
+
*/
|
|
109
|
+
function parseInt64(v) {
|
|
110
|
+
let n;
|
|
111
|
+
if (typeof v === "bigint") n = v;
|
|
112
|
+
else if (typeof v === "number") {
|
|
113
|
+
if (!Number.isSafeInteger(v)) return void 0;
|
|
114
|
+
n = BigInt(v);
|
|
115
|
+
} else if (typeof v === "string" && CANONICAL_INT.test(v)) n = BigInt(v);
|
|
116
|
+
else return void 0;
|
|
117
|
+
return n >= MIN_INT64 && n <= MAX_INT64 ? n : void 0;
|
|
118
|
+
}
|
|
119
|
+
/** Whether `v` is an `int16` value: an integer number within the int16 range. */
|
|
120
|
+
function isInt16(v) {
|
|
121
|
+
return Number.isInteger(v) && v >= MIN_INT16 && v <= MAX_INT16;
|
|
122
|
+
}
|
|
123
|
+
/** Whether `v` is an `int32` value: an integer number within the int32 range. */
|
|
124
|
+
function isInt32(v) {
|
|
125
|
+
return Number.isInteger(v) && v >= MIN_INT32 && v <= MAX_INT32;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* `JSON.stringify` that writes a bigint as a decimal string, so an `int64`
|
|
129
|
+
* keeps every digit on the JSON wire. The plain call runs first, so a value
|
|
130
|
+
* with no bigint pays nothing for the replacer.
|
|
131
|
+
*/
|
|
132
|
+
function stringifyJson(value) {
|
|
133
|
+
try {
|
|
134
|
+
return JSON.stringify(value);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
if (!(e instanceof TypeError) || !/BigInt/.test(e.message)) throw e;
|
|
137
|
+
return JSON.stringify(value, (_k, v) => typeof v === "bigint" ? v.toString() : v);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Like {@link stringifyJson}, but a bigint is written as an exact JSON number
|
|
142
|
+
* (`9223372036854775807`, not a string), for a jsonb body that `substrate_num`
|
|
143
|
+
* reads back as the number it is.
|
|
144
|
+
*/
|
|
145
|
+
function stringifyJsonExact(value) {
|
|
146
|
+
try {
|
|
147
|
+
return JSON.stringify(value);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
if (!(e instanceof TypeError) || !/BigInt/.test(e.message)) throw e;
|
|
150
|
+
const raw = JSON.rawJSON;
|
|
151
|
+
return JSON.stringify(value, (_k, v) => typeof v === "bigint" ? raw(v.toString()) : v);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
21
155
|
//#endregion
|
|
22
156
|
//#region ../../packages/substrate-types/src/qualified-key.ts
|
|
23
157
|
function parseQualifiedKey(key) {
|
|
@@ -229,46 +363,44 @@ function encodePositionalFromFieldDef(value, def, schema, ctx, path = []) {
|
|
|
229
363
|
return encodeFieldDef(value, def, schema, path, ctx);
|
|
230
364
|
}
|
|
231
365
|
function encodeEnvelope(envelope, ctx) {
|
|
232
|
-
const
|
|
233
|
-
for (const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
rewritten[key] = encodePositionalForShape(value, returns, schema, envelope.shapes[key], {
|
|
247
|
-
schemas: ctx.schemas,
|
|
248
|
-
currentNs
|
|
249
|
-
});
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
const fields = ctx.fieldsByKey[key];
|
|
253
|
-
const typeName = ctx.typeByKey[key];
|
|
366
|
+
const data = {};
|
|
367
|
+
for (const key of Object.keys(envelope.data)) data[key] = positionValue(envelope, ctx, key);
|
|
368
|
+
return Buffer.from(pack(withData(envelope, data)));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* The wire form of `envelope.data[key]`, or of `value` in its place: rows as
|
|
372
|
+
* positional tuples, or the value as-is when nothing positions it. A `list`
|
|
373
|
+
* value's rows encode one by one, so a slice of its rows gives that slice of
|
|
374
|
+
* the whole value's wire form.
|
|
375
|
+
*/
|
|
376
|
+
function positionValue(envelope, ctx, key, value = envelope.data[key]) {
|
|
377
|
+
if (isAggShape(envelope.shapes[key])) return value;
|
|
378
|
+
const returns = ctx.returnsByKey?.[key];
|
|
379
|
+
if (returns !== void 0) {
|
|
254
380
|
const currentNs = ctx.currentNsByKey[key];
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
const schema = ctx.schemas[currentNs];
|
|
260
|
-
if (schema === void 0) {
|
|
261
|
-
rewritten[key] = value;
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
rewritten[key] = encodePositional(value, fields, schema, typeName, {
|
|
381
|
+
const schema = currentNs !== void 0 ? ctx.schemas[currentNs] : void 0;
|
|
382
|
+
if (currentNs === void 0 || schema === void 0) return value;
|
|
383
|
+
return encodePositionalForShape(value, returns, schema, envelope.shapes[key], {
|
|
265
384
|
schemas: ctx.schemas,
|
|
266
385
|
currentNs
|
|
267
386
|
});
|
|
268
387
|
}
|
|
388
|
+
const fields = ctx.fieldsByKey[key];
|
|
389
|
+
const typeName = ctx.typeByKey[key];
|
|
390
|
+
const currentNs = ctx.currentNsByKey[key];
|
|
391
|
+
if (fields === void 0 || typeName === void 0 || currentNs === void 0) return value;
|
|
392
|
+
const schema = ctx.schemas[currentNs];
|
|
393
|
+
if (schema === void 0) return value;
|
|
394
|
+
return encodePositional(value, fields, schema, typeName, {
|
|
395
|
+
schemas: ctx.schemas,
|
|
396
|
+
currentNs
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/** `envelope` with `data` replaced by its wire form; `pack` of it is the response body. */
|
|
400
|
+
function withData(envelope, data) {
|
|
269
401
|
const out = {
|
|
270
402
|
schemaVersion: envelope.schemaVersion,
|
|
271
|
-
data
|
|
403
|
+
data,
|
|
272
404
|
shapes: envelope.shapes
|
|
273
405
|
};
|
|
274
406
|
if (envelope._meta !== void 0) out._meta = envelope._meta;
|
|
@@ -276,7 +408,48 @@ function encodeEnvelope(envelope, ctx) {
|
|
|
276
408
|
if (envelope._completeness !== void 0) out._completeness = envelope._completeness;
|
|
277
409
|
if (envelope._diagnostics !== void 0) out._diagnostics = envelope._diagnostics;
|
|
278
410
|
if (envelope.errors !== void 0) out.errors = envelope.errors;
|
|
279
|
-
return
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* `pack(wire)` in pieces, a long row list `rowsPerPart` rows per piece, for a
|
|
415
|
+
* `wire` envelope from `withData`. msgpackr's default `pack` writes every
|
|
416
|
+
* object as a map16 (`de`) and records no shared state between values, so
|
|
417
|
+
* the pieces concatenate to the same bytes.
|
|
418
|
+
*/
|
|
419
|
+
function* packEnvelopeParts(wire, rowsPerPart) {
|
|
420
|
+
const packed = (v) => Buffer.from(pack(v));
|
|
421
|
+
const keys = Object.keys(wire);
|
|
422
|
+
yield mapHeader(keys.length);
|
|
423
|
+
for (const key of keys) {
|
|
424
|
+
yield packed(key);
|
|
425
|
+
if (key !== "data") {
|
|
426
|
+
yield packed(wire[key]);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
const entries = Object.entries(wire.data);
|
|
430
|
+
yield mapHeader(entries.length);
|
|
431
|
+
for (const [k, v] of entries) {
|
|
432
|
+
yield packed(k);
|
|
433
|
+
if (!Array.isArray(v) || v.length <= rowsPerPart) {
|
|
434
|
+
yield packed(v);
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
yield arrayHeader(v.length);
|
|
438
|
+
for (let i = 0; i < v.length; i += rowsPerPart) {
|
|
439
|
+
const rows = v.slice(i, i + rowsPerPart);
|
|
440
|
+
yield packed(rows).subarray(arrayHeader(rows.length).length);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function mapHeader(n) {
|
|
446
|
+
if (n > 65535) throw new PackEncodeError(`map of ${n} keys`, []);
|
|
447
|
+
return Uint8Array.of(222, n >> 8, n & 255);
|
|
448
|
+
}
|
|
449
|
+
function arrayHeader(n) {
|
|
450
|
+
if (n < 16) return Uint8Array.of(144 | n);
|
|
451
|
+
if (n <= 65535) return Uint8Array.of(220, n >> 8, n & 255);
|
|
452
|
+
return Uint8Array.of(221, n >>> 24, n >> 16 & 255, n >> 8 & 255, n & 255);
|
|
280
453
|
}
|
|
281
454
|
/** A shape whose value is a `{ count }` or `{ groups }` map, not rows. */
|
|
282
455
|
function isAggShape(shape) {
|
|
@@ -845,7 +1018,7 @@ function decodeStreamChunk(bytes, input) {
|
|
|
845
1018
|
* a typed `typeof wire === 'string'` branch.
|
|
846
1019
|
*/
|
|
847
1020
|
function encodeWsFrame(value, mode) {
|
|
848
|
-
return mode === "pack" ? pack(value) :
|
|
1021
|
+
return mode === "pack" ? pack(value) : stringifyJson(value);
|
|
849
1022
|
}
|
|
850
1023
|
/**
|
|
851
1024
|
* Decode an inbound WS message envelope (the outer `{ id, kind, data?, ... }`
|
|
@@ -961,4 +1134,4 @@ function applyDecodePlanInPlace(envelope, plan) {
|
|
|
961
1134
|
const WS_SUBPROTOCOL_SUBSTRATE_PACK = "substrate-pack";
|
|
962
1135
|
|
|
963
1136
|
//#endregion
|
|
964
|
-
export {
|
|
1137
|
+
export { parseInt64 as A, DEFAULT_ORDERED_BY as C, parseQualifiedKey as D, formatQualifiedKey as E, EXPR_FUNCTIONS as F, EXPR_LIMITS as I, DEFAULT_FILTER_WRITE_LIMITS as L, stringifyJsonExact as M, DATE_UNITS as N, isInt16 as O, EXPR_AGGREGATES as P, assertNever as R, withData as S, naturalOrderOf as T, encodeEnvelope as _, buildDecodePlan as a, packEnvelopeParts as b, isPlainRequestData as c, PackDecodeError as d, SchemaDriftError as f, PackEncodeError as g, decodePositionalFromFieldDef as h, applyDecodePlanInPlace as i, stringifyJson as j, isInt32 as k, decodeStreamChunk as l, decodePositional as m, packFrame as n, decodeWsEnvelope as o, decodeEnvelope as p, unpackFrame as r, encodeWsFrame as s, WS_SUBPROTOCOL_SUBSTRATE_PACK as t, encodeStreamChunk as u, encodePositional as v, isColumnField as w, positionValue as x, encodePositionalFromFieldDef as y };
|