@mnmal-ai/substrate 1.0.0-alpha.1 → 1.0.0-alpha.11
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 +48 -6
- package/dist/boot-store-C5vNZJ3i.js +4065 -0
- package/dist/{runtime-metrics-DwpDJ8vz.d.ts → bridge-COu0Tg_h.d.ts} +2 -87
- package/dist/cli-BrwW4tjO.js +3144 -0
- package/dist/client.d.ts +129 -8
- package/dist/client.js +6 -5
- package/dist/{agent-token-BIboWOU0.js → env-utils-CGNazUNt.js} +31 -2
- package/dist/{errors-D4vKuwz8.d.ts → errors-BOllGhVx.d.ts} +15 -2
- package/dist/{index-D7mSOFlM.d.ts → index-Cp74OcmS.d.ts} +1 -1
- package/dist/node-version-C5FSmwJX.js +26 -0
- package/dist/pack.d.ts +2 -2
- package/dist/pack.js +1 -1
- package/dist/pg-edges-store-BLsbcXkk.js +381 -0
- package/dist/{plugin-BuQQEzL-.js → plugin-DIYm2cZE.js} +171 -18
- package/dist/proposals-bootstrap.js +6 -4
- package/dist/proposals.config.schema.json +5 -0
- package/dist/proposals.d.ts +14 -4
- package/dist/proposals.default-config.json +2 -1
- package/dist/proposals.js +2 -2
- package/dist/recall-bootstrap.js +13 -4
- package/dist/recall.config.schema.json +12 -0
- package/dist/recall.d.ts +53 -9
- package/dist/recall.js +2 -2
- package/dist/{repl-C52wyfMs.js → repl-B8gy0YM7.js} +63 -30
- package/dist/{row-ByLFE2Wx.d.ts → row-DwaDU4b-.d.ts} +58 -9
- package/dist/run-B18qtGKc.js +2012 -0
- package/dist/{plugin-t2g2wX0b.d.ts → schema-CijHRfuk.d.ts} +957 -16
- package/dist/script-C6DSa_Na.js +134 -0
- package/dist/sdk.d.ts +104 -16
- package/dist/sdk.js +5 -110
- package/dist/{src-DuopV8u7.js → src-Br6aDUti.js} +153 -20
- package/dist/{src-5hVbeiAu.js → src-D041j6GS.js} +697 -57
- package/dist/{src-YXlv_RyL.js → src-DK7VEQT6.js} +4099 -1040
- package/dist/{src-C4DzaIQZ.js → src-Dbvuel6w.js} +392 -282
- package/dist/{row-DK7lPZVe.js → src-DpPdw2oL.js} +11 -11
- package/dist/{src-zcyUofMJ.js → src-DptNGNYQ.js} +39 -15
- package/dist/src-gz4I1F29.js +5097 -0
- package/dist/substrate-admin.js +17 -781
- package/dist/substrate.js +4 -5476
- package/dist/testing.d.ts +582 -9
- package/dist/testing.js +39 -3
- package/dist/{ws-C72iVS5T.d.ts → ws-DC8OhMaV.d.ts} +2 -3
- package/package.json +22 -20
- package/dist/dataset-DOXGRz50.js +0 -1535
- package/dist/env-utils-B7SGmoeJ.js +0 -21
- package/dist/schema-g4FQLr0V.d.ts +0 -433
- package/dist/src-CjEwiKXw.js +0 -2327
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
+
//#region ../../packages/substrate-client/src/script.ts
|
|
3
|
+
const DEFAULT_MAX_WRITES = 50;
|
|
4
|
+
const DEFAULT_MAX_PAGES = 200;
|
|
5
|
+
/** Counts the frames in a mutate payload: an array under an op-key is one frame per element. */
|
|
6
|
+
function frameCount(frame) {
|
|
7
|
+
return Object.values(frame).reduce((n, v) => n + (Array.isArray(v) ? v.length : 1), 0);
|
|
8
|
+
}
|
|
9
|
+
function assertKeys(frame, env, verb) {
|
|
10
|
+
const missing = Object.keys(frame).filter((k) => !(k in env.data));
|
|
11
|
+
if (missing.length > 0 || verb === "mutate" && (env.errors?.length ?? 0) > 0) {
|
|
12
|
+
const errs = (env.errors ?? []).map((e) => `${e.code ?? "error"}: ${e.message}`).join("; ");
|
|
13
|
+
throw new Error(`${verb} refused${missing.length > 0 ? ` for ${missing.join(", ")}` : ""}${errs !== "" ? ` (${errs})` : ""}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Runs `script` against a guarded context and reports everything it did,
|
|
18
|
+
* including the mutations applied before any failure.
|
|
19
|
+
*/
|
|
20
|
+
async function runScript(script, opts) {
|
|
21
|
+
const { client, kid, mode = "read", args = {}, maxWrites = 50, maxPages = DEFAULT_MAX_PAGES } = opts;
|
|
22
|
+
const log = opts.log ?? ((line) => process.stderr.write(`${line}\n`));
|
|
23
|
+
const mutations = [];
|
|
24
|
+
const warnings = [];
|
|
25
|
+
const stats = {
|
|
26
|
+
queries: 0,
|
|
27
|
+
writes: 0,
|
|
28
|
+
ms: 0
|
|
29
|
+
};
|
|
30
|
+
const started = Date.now();
|
|
31
|
+
const query = async (frame) => {
|
|
32
|
+
stats.queries++;
|
|
33
|
+
const env = await client.query(frame);
|
|
34
|
+
assertKeys(frame, env, "query");
|
|
35
|
+
for (const [key, page] of Object.entries(env._pagination ?? {})) if (page.hasMore) warnings.push(`${key}: result truncated (hasMore); use queryAll for a complete read`);
|
|
36
|
+
return env;
|
|
37
|
+
};
|
|
38
|
+
const ctx = {
|
|
39
|
+
kid,
|
|
40
|
+
mode,
|
|
41
|
+
args: Object.freeze({ ...args }),
|
|
42
|
+
query,
|
|
43
|
+
async queryAll(key, frame) {
|
|
44
|
+
const rows = [];
|
|
45
|
+
let cursor;
|
|
46
|
+
for (let page = 0; page < maxPages; page++) {
|
|
47
|
+
const params = {
|
|
48
|
+
...frame.params,
|
|
49
|
+
...cursor !== void 0 ? { cursor } : {}
|
|
50
|
+
};
|
|
51
|
+
stats.queries++;
|
|
52
|
+
const env = await client.query({ [key]: {
|
|
53
|
+
...frame,
|
|
54
|
+
params
|
|
55
|
+
} });
|
|
56
|
+
assertKeys({ [key]: frame }, env, "query");
|
|
57
|
+
const data = env.data[key];
|
|
58
|
+
rows.push(...Array.isArray(data) ? data : [data]);
|
|
59
|
+
const p = env._pagination?.[key];
|
|
60
|
+
if (p?.hasMore !== true) return rows;
|
|
61
|
+
if (p.nextCursor === void 0) throw new Error(`${key}: hasMore with no nextCursor`);
|
|
62
|
+
cursor = p.nextCursor;
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`${key}: still hasMore after ${maxPages} pages`);
|
|
65
|
+
},
|
|
66
|
+
async recall({ query: to, row, ...params }) {
|
|
67
|
+
const fields = row === void 0 ? {} : { fields: {
|
|
68
|
+
id: true,
|
|
69
|
+
namespace: true,
|
|
70
|
+
type: true,
|
|
71
|
+
score: true,
|
|
72
|
+
kind: true,
|
|
73
|
+
expandedFrom: true,
|
|
74
|
+
row
|
|
75
|
+
} };
|
|
76
|
+
return (await query({ "recall/Hit": {
|
|
77
|
+
params: {
|
|
78
|
+
to,
|
|
79
|
+
...params
|
|
80
|
+
},
|
|
81
|
+
...fields
|
|
82
|
+
} })).data["recall/Hit"];
|
|
83
|
+
},
|
|
84
|
+
async mutate(frame) {
|
|
85
|
+
if (mode === "read") throw new Error("mutate refused: read mode (pass --dry-run or --write)");
|
|
86
|
+
if (mode === "dry-run") {
|
|
87
|
+
mutations.push({
|
|
88
|
+
frame,
|
|
89
|
+
applied: false
|
|
90
|
+
});
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const n = frameCount(frame);
|
|
94
|
+
if (stats.writes + n > maxWrites) throw new Error(`mutate refused: ${stats.writes + n} frames would exceed --max-writes ${maxWrites}`);
|
|
95
|
+
const env = await client.mutate(frame);
|
|
96
|
+
const applied = Object.keys(frame).some((k) => k in env.data);
|
|
97
|
+
if (applied) stats.writes += n;
|
|
98
|
+
mutations.push({
|
|
99
|
+
frame,
|
|
100
|
+
applied,
|
|
101
|
+
...env.errors !== void 0 ? { errors: env.errors } : {}
|
|
102
|
+
});
|
|
103
|
+
assertKeys(frame, env, "mutate");
|
|
104
|
+
return env;
|
|
105
|
+
},
|
|
106
|
+
log: (...args) => log(args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" "))
|
|
107
|
+
};
|
|
108
|
+
const report = (extra) => {
|
|
109
|
+
stats.ms = Date.now() - started;
|
|
110
|
+
return {
|
|
111
|
+
...extra,
|
|
112
|
+
kid,
|
|
113
|
+
mode,
|
|
114
|
+
args,
|
|
115
|
+
mutations,
|
|
116
|
+
warnings,
|
|
117
|
+
stats
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
return report({
|
|
122
|
+
ok: true,
|
|
123
|
+
result: await script(ctx)
|
|
124
|
+
});
|
|
125
|
+
} catch (err) {
|
|
126
|
+
return report({
|
|
127
|
+
ok: false,
|
|
128
|
+
error: err instanceof Error ? err.message : String(err)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { runScript as n, DEFAULT_MAX_WRITES as t };
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
import { $ as NlJudgeStep, A as and, B as SYSTEM_NAMESPACE, C as flattenGrant, D as parseGrantEntries, E as intersectGrants, F as TokenProviderOpts, G as resolveAdminCredential, H as isActiveAdminKeyRow, I as adminClaimCapabilities, J as NlAskRequest, K as resolveDefaultKeyPath, L as isEncryptedKey, M as or, N as ADMIN_CAPABILITIES, O as decodeList, P as DEFAULT_CAPABILITIES, Q as NlJudgeChoice, R as makeAuthorizationProvider, S as expandFlat, T as grantIsUniform, U as AdminCredential, V as describeGrant, W as AdminEnv, X as NlEvidence, Y as NlAskResult, Z as NlJudgeAction, _ as newlyGrantedPairs, a as denyAll, at as NlPackType, b as capabilitiesFor, c as requireIdentity, ct as NlParsedData, d as KeyUpdateRefusal, dt as NlValueAlias, et as NlJudgedStatus, f as checkRevocable, ft as NlWireEvent, g as newlyGranted, gt as Query, h as grantEntriesConfer, ht as NLVocabularyHint, i as allowVerbs, it as NlPackField, j as not, k as encodeList, l as requireNamespace, lt as NlServedPack, m as grantCovers, mt as NLResult, n as row, nt as NlNamespaceRulings, o as denyVerbs, ot as NlPackValueRef, p as checkUpdatable, pt as NLBase, q as resolveDefaultKidPath, r as allowAll, rt as NlOutcome, s as requireCapability, st as NlParseStatus, t as applyRowFilters, tt as NlNamespacePack, u as KeyMutationRefusal, ut as NlTrailEvent, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-ByLFE2Wx.js";
|
|
1
|
+
import { $ as PluginRouter, $t as WriteOptions, A as KernelPlugin, At as DeriveSpec, B as QualifiedFrame, Bt as ReadResult, C as FilterOperatorDef, Cn as Row, Ct as WriteEvent, D as KernelMigration, Dn as assertNoRepeatedIds, Dt as Dataset, E as KernelLifecycleContext, En as WriteRow, Et as ConditionalUpdateResult, F as NamespaceInstallContext, Ft as FrameAgg, G as RegistryEntryKind, Gt as TypeStorageReport, H as RegistryBase, Ht as StorageReport, I as NamespaceTypeDef, It as IndexPlan, J as ScheduledTaskContext, Jt as WalkAggOperand, K as RegistryEntryResolver, Kt as UpdateFieldRef, L as PluginLifecycleContext, Lt as NestedSelection, M as McpToolRegistration, Mt as FieldKind, N as NamespaceConfig, Nt as FieldPredicate, O as KernelMigrationContext, Ot as DatasetRegistry, P as NamespaceDefinition, Pt as FilterCapabilities, Q as HttpMethod, Qt as WhereClause, R as PluginRouteContext, Rt as OrderByClause, S as EngineInput, Sn as ROW_METADATA_FIELDS, St as TypedResolver, T as IndexDecl, Tn as RowMetadataField, Tt as BucketSpec, U as RegistryEntry, Ut as TxScopeHandles, V as Registry, Vt as RefOperand, W as RegistryEntryInput, Wt as TypeIndexState, X as VirtualTypeDef, Xt as WalkNode, Y as VirtualMutationDef, Yt as WalkAggPredicate, Z as HttpHandler, Zt as WalkPick, _ as CoordinatorPlugin, _n as ActorIdentity, _t as RequestContext, a as FieldDefCrossRef, an as RuntimeErrors, at as SubstrateResponse, b as EncodeContext, bn as Id, bt as ResolverReturn, c as FieldDefStruct, cn as TypeStats, ct as WsConnection, d as OrderedBy, dn as EdgePatch, dt as AutoCrudVerb, en as WriteResult, et as RequestObservation, f as PackEnvelope, fn as EdgeRef, ft as Identity, g as naturalOrderOf, gn as OnMissing, gt as PolicyProbeContext, h as TypeSchema, hn as OnDelete, ht as PolicyDecision, i as FieldDef, in as RuntimeErrorEntry, it as SubstrateRequest, j as KernelRouteClaim, jt as DropResult, k as KernelNamespaceContribution, kt as DeleteResult, l as FieldInput, ln as CanDeleteResult, lt as WsHandler, m as Schema, mn as EdgesStore, mt as Policy, n as Dropped, nn as ResolveObservation, nt as RuntimeOp, o as FieldDefList, on as RuntimeMetrics, ot as SubstrateServer, p as PlanClause, pn as EdgeWriteInput, pt as Obligation, q as ScheduledTask, qt as WalkAgg, r as EnvelopeShape, rn as ResolverStat, rt as StartOpts, s as FieldDefScalar, sn as SlowRequest, st as TlsConfig, t as DEFAULT_ORDERED_BY, tn as ProcessStat, tt as RequestObserver, u as MutationSchema, un as Edge, ut as AfterTxWork, v as DropParticipant, vn as CLIENT_SUPPLIED_SERVER_FIELD, vt as Resolver, w as FrameEntry, wn as RowMetadata, wt as AggFn, x as EngineHandle, xn as IdentityKind, xt as RowFilterObligation, y as EmbedSourceContext, yn as ClientSuppliedServerFieldError, yt as ResolverArgs, z as PostWriteHook, zt as ReadParams } from "./schema-CijHRfuk.js";
|
|
2
|
+
import { i as BridgeFrame, n as BridgeCredential, r as BridgeCredentialStore, t as BridgeClient } from "./bridge-COu0Tg_h.js";
|
|
3
|
+
import { _ as isRestrictViolation, a as ReservedField, c as UnsupportedFilterError, d as WALKS_NEED_PARTITIONED, f as WALKS_UNSUPPORTED_STORE, g as isResolverFrameError, h as isAuthCause, i as ROW_POLICY_BLOCKS_WALK, l as WALKS_IN_MUTATION, m as WALK_UNSUPPORTED_REF, n as MissingReferentError, o as ResolverFrameError, p as WALK_BUDGET_EXCEEDED, r as NamespaceMismatch, s as RestrictViolation, t as BridgeUnreachableError, u as WALKS_IN_SUBSCRIPTION } from "./errors-BOllGhVx.js";
|
|
4
|
+
import { a as WsResponseFrame, c as ResolveTarget, d as TargetState, f as IdempotencyStore, i as WsRequestFrame, l as SweepDeps, n as WS_REASON_SERVER_RESTART, o as WsResponseKind, r as WS_REASON_SUBSCRIPTION_OVERLOADED, s as BridgeRegistry, t as WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, u as SweepState } from "./ws-DC8OhMaV.js";
|
|
5
|
+
import { $ as NlJudgeChoice, A as and, B as SYSTEM_NAMESPACE, C as flattenGrant, D as parseGrantEntries, E as intersectGrants, F as TokenProviderOpts, G as resolveAdminCredential, H as isActiveAdminKeyRow, I as adminClaimCapabilities, J as NlAskRequest, K as resolveDefaultKeyPath, L as isEncryptedKey, M as or, N as ADMIN_CAPABILITIES, O as decodeList, P as DEFAULT_CAPABILITIES, Q as NlJudgeAction, R as makeAuthorizationProvider, S as expandFlat, T as grantIsUniform, U as AdminCredential, V as describeGrant, W as AdminEnv, X as NlEvidence, Y as NlAskResult, Z as NlFieldPhrase, _ as newlyGrantedPairs, _t as Query, a as denyAll, at as NlPackField, b as capabilitiesFor, c as requireIdentity, ct as NlParseStatus, d as KeyUpdateRefusal, dt as NlTrailEvent, et as NlJudgeStep, f as checkRevocable, ft as NlValueAlias, g as newlyGranted, gt as NLVocabularyHint, h as grantEntriesConfer, ht as NLResult, i as allowVerbs, it as NlOutcome, j as not, k as encodeList, l as requireNamespace, lt as NlParsedData, m as grantCovers, mt as NLBase, n as row, nt as NlNamespacePack, o as denyVerbs, ot as NlPackType, p as checkUpdatable, pt as NlWireEvent, q as resolveDefaultKidPath, r as allowAll, rt as NlNamespaceRulings, s as requireCapability, st as NlPackValueRef, t as applyRowFilters, tt as NlJudgedStatus, u as KeyMutationRefusal, ut as NlServedPack, v as revokedAtIso, w as grantEntryError, x as encodeGrant, y as Grant, z as makeTokenProvider } from "./row-DwaDU4b-.js";
|
|
7
6
|
//#region ../../packages/substrate-types/src/assert-never.d.ts
|
|
8
7
|
/**
|
|
9
8
|
* Exhaustiveness guard for the `default:` arm of a `switch` over a
|
|
@@ -32,6 +31,12 @@ export declare function canonicalize(value: unknown): unknown;
|
|
|
32
31
|
* a config typo fails at boot.
|
|
33
32
|
*/
|
|
34
33
|
export declare function parsePositiveInt(raw: string | undefined, envVar: string, fallback: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* `url` with its trailing slashes removed, for joining a configured base URL
|
|
36
|
+
* to a path. A loop rather than `/\/+$/`, which backtracks quadratically on a
|
|
37
|
+
* long run of slashes that does not end the string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function trimTrailingSlashes(url: string): string;
|
|
35
40
|
//#endregion
|
|
36
41
|
//#region ../../packages/substrate-types/src/hard-delete-gate.d.ts
|
|
37
42
|
/**
|
|
@@ -98,6 +103,18 @@ export declare function confersAnywhere(resolved: IdentityGrant | null, capabili
|
|
|
98
103
|
/** Every capability conferred anywhere — the union, for error messages only. */
|
|
99
104
|
export declare function allCapabilities(resolved: IdentityGrant | null): string[];
|
|
100
105
|
//#endregion
|
|
106
|
+
//#region ../../packages/substrate-types/src/iso-timestamp.d.ts
|
|
107
|
+
/**
|
|
108
|
+
* `v` as `YYYY-MM-DDTHH:MM:SS[.ffffff](Z|±HH:MM)`, or `undefined` when it is
|
|
109
|
+
* outside the grammar or names a day that does not exist (Feb 30, year 0000).
|
|
110
|
+
* No offset is read as UTC, and a date alone as its midnight UTC.
|
|
111
|
+
*/
|
|
112
|
+
export declare function normalizeIsoTimestamp(v: string): string | undefined;
|
|
113
|
+
/** Is `v` a timestamp every dataset reads to the same instant? */
|
|
114
|
+
export declare function isIsoTimestamp(v: string): boolean;
|
|
115
|
+
/** Does `v` have the grammar's shape but name a day that does not exist (Feb 30, month 13, year 0000)? */
|
|
116
|
+
export declare function isImpossibleIsoTimestamp(v: string): boolean;
|
|
117
|
+
//#endregion
|
|
101
118
|
//#region ../../packages/substrate-types/src/keyed-mutex.d.ts
|
|
102
119
|
/**
|
|
103
120
|
* A process-local mutual-exclusion lock per string key.
|
|
@@ -132,13 +149,24 @@ export declare const METADATA_AUTHOR_FIELDS: {
|
|
|
132
149
|
readonly kind: 'updatedByKind';
|
|
133
150
|
};
|
|
134
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* The far side of a walk hop (`{ in }` / `{ out }`): its fields and its own
|
|
154
|
+
* hops, or undefined when the hop does not resolve (the validator refuses it).
|
|
155
|
+
*/
|
|
156
|
+
export type MetadataHop = (node: Record<string, unknown>) => {
|
|
157
|
+
fields: Record<string, FieldDef>;
|
|
158
|
+
hop: MetadataHop;
|
|
159
|
+
} | undefined;
|
|
160
|
+
/** A `_walk` / `_agg` node with its `where` rewritten against the far type. */
|
|
161
|
+
export declare function normaliseWalkNode(node: unknown, hop: MetadataHop | undefined): unknown;
|
|
135
162
|
/**
|
|
136
163
|
* Rewrites every metadata spelling in a `where` clause onto the canonical
|
|
137
|
-
* columns, through AND / OR / NOT
|
|
138
|
-
*
|
|
139
|
-
*
|
|
164
|
+
* columns, through AND / OR / NOT and, given `hop`, into each `_walk` / `_agg`
|
|
165
|
+
* against its far type. A name the type declares as a field of its own is
|
|
166
|
+
* left alone, and so is anything that is not a metadata spelling, for the
|
|
167
|
+
* validator to judge.
|
|
140
168
|
*/
|
|
141
|
-
export declare function normaliseMetadataWhere(where: unknown, fieldDefs: Record<string, FieldDef
|
|
169
|
+
export declare function normaliseMetadataWhere(where: unknown, fieldDefs: Record<string, FieldDef>, hop?: MetadataHop): unknown;
|
|
142
170
|
/** Rewrites metadata spellings in an `orderBy` list; an author name sorts by its id. */
|
|
143
171
|
export declare function normaliseMetadataOrderBy(orderBy: unknown, fieldDefs: Record<string, FieldDef>): unknown;
|
|
144
172
|
//#endregion
|
|
@@ -331,6 +359,43 @@ interface TypeInput {
|
|
|
331
359
|
lexical?: {
|
|
332
360
|
source: (row: Row) => string | null | undefined | Promise<string | null | undefined>;
|
|
333
361
|
};
|
|
362
|
+
/**
|
|
363
|
+
* Composite and unique indexes, built by the engine with the filter
|
|
364
|
+
* compiler's own expressions. Keys and predicate fields must be declared
|
|
365
|
+
* scalar (not json) or crossRef fields. See `IndexDecl`.
|
|
366
|
+
*/
|
|
367
|
+
indexes?: IndexDecl[];
|
|
368
|
+
/**
|
|
369
|
+
* The type's natural order: what a read with no `orderBy` returns. Exactly
|
|
370
|
+
* one key, a declared date or number field or a metadata column
|
|
371
|
+
* (`createdAt`, `updatedAt`, or `seq` on a visible-order type). Absent
|
|
372
|
+
* means newest first by `createdAt`.
|
|
373
|
+
*/
|
|
374
|
+
orderedBy?: OrderedBy;
|
|
375
|
+
/**
|
|
376
|
+
* `'visible'`: each inserted row gets `_metadata.seq`, strictly increasing
|
|
377
|
+
* per type in commit order, so a reader paging by `seq` never sees a higher
|
|
378
|
+
* seq before a lower one becomes visible. An upsert of an existing row keeps
|
|
379
|
+
* its seq. `seq` is filterable, sortable, and valid in `orderedBy`.
|
|
380
|
+
*
|
|
381
|
+
* Cost: writes to the type are serialised. Each insert holds a per-type
|
|
382
|
+
* transaction lock from seq assignment to commit, so one writer's open
|
|
383
|
+
* transaction blocks every other writer of the type until it ends. Other
|
|
384
|
+
* types are unaffected and pay nothing.
|
|
385
|
+
*
|
|
386
|
+
* Two transactions that write two visible-order types in opposite orders
|
|
387
|
+
* can deadlock; Postgres aborts one with 40P01. Write them in a consistent
|
|
388
|
+
* order.
|
|
389
|
+
*
|
|
390
|
+
* Making an existing type visible assigns no seq to its old rows: they keep
|
|
391
|
+
* a null seq and sort after every new row.
|
|
392
|
+
*/
|
|
393
|
+
ordering?: 'visible';
|
|
394
|
+
/**
|
|
395
|
+
* Expected size. `large` lets the index advisor recommend for this type
|
|
396
|
+
* from its profile's lower `minRowsLargeHint` rather than `minRows`.
|
|
397
|
+
*/
|
|
398
|
+
expectedSize?: 'small' | 'large';
|
|
334
399
|
}
|
|
335
400
|
interface DefineNamespaceOptions {
|
|
336
401
|
/**
|
|
@@ -347,6 +412,13 @@ interface DefineNamespaceOptions {
|
|
|
347
412
|
promotedColumns?: NamespaceDefinition['promotedColumns'];
|
|
348
413
|
}
|
|
349
414
|
export declare function defineNamespace(namespace: string, types: Record<string, TypeInput>, opts?: DefineNamespaceOptions): NamespaceDefinition;
|
|
415
|
+
/** Throws unless every key is a btree-indexable declared field or `createdAt`/`updatedAt`, and every predicate field a declared one. */
|
|
416
|
+
export declare function assertIndexDecl(typeName: string, fields: Record<string, FieldDef>, decl: IndexDecl): void;
|
|
417
|
+
/**
|
|
418
|
+
* Throws unless `orderedBy` is one key, on a date or number field or a metadata
|
|
419
|
+
* column; `seq` only on a type declared `ordering: 'visible'`.
|
|
420
|
+
*/
|
|
421
|
+
export declare function assertOrderedBy(typeName: string, def: Pick<TypeInput, 'fields' | 'orderedBy' | 'ordering'>): void;
|
|
350
422
|
//#endregion
|
|
351
423
|
//#region ../../packages/substrate-sdk/src/autocrud/autocrud-create.d.ts
|
|
352
424
|
interface CreateResolverOptions {
|
|
@@ -418,6 +490,9 @@ export interface AutoCrudRegistry {
|
|
|
418
490
|
kind?: 'type' | 'mutation';
|
|
419
491
|
params?: Record<string, FieldDef>;
|
|
420
492
|
returns?: FieldDef;
|
|
493
|
+
orderedBy?: OrderedBy;
|
|
494
|
+
indexes?: IndexDecl[];
|
|
495
|
+
expectedSize?: 'small' | 'large';
|
|
421
496
|
/** Semantic autoCRUD verb threaded to policies via ctx.verb. */
|
|
422
497
|
verb?: AutoCrudVerb;
|
|
423
498
|
}): void;
|
|
@@ -446,6 +521,12 @@ export interface InstallAutoCrudOptions {
|
|
|
446
521
|
* Delete resolver does NOT invoke this hook.
|
|
447
522
|
*/
|
|
448
523
|
postWrite?: PostWriteHook;
|
|
524
|
+
/** The type's natural order — published on the type entry's schema. */
|
|
525
|
+
orderedBy?: OrderedBy;
|
|
526
|
+
/** Declared indexes, kept on the type entry for storage to build (proposed types). */
|
|
527
|
+
indexes?: IndexDecl[];
|
|
528
|
+
/** Size hint, kept on the type entry for the index advisor (proposed types). */
|
|
529
|
+
expectedSize?: 'small' | 'large';
|
|
449
530
|
}
|
|
450
531
|
export interface CreateResolverWithEdgesOptions {
|
|
451
532
|
/** Field definitions for the type — crossRef entries drive edge emission. */
|
|
@@ -478,6 +559,8 @@ export declare function installAutoCrud(registry: AutoCrudRegistry, typeName: st
|
|
|
478
559
|
//#endregion
|
|
479
560
|
//#region ../../packages/substrate-sdk/src/autocrud/reserved.d.ts
|
|
480
561
|
export declare const RESERVED_AUTOCRUD_FIELDS: Record<string, FieldDef>;
|
|
562
|
+
/** Is `def` a descriptor autoCRUD injected, rather than a body field of the same name? */
|
|
563
|
+
export declare function isReservedAutoCrudField(def: FieldDef): boolean;
|
|
481
564
|
/** Reserved field names — useful for validation loops. */
|
|
482
565
|
export declare const RESERVED_AUTOCRUD_FIELD_NAMES: string[];
|
|
483
566
|
//#endregion
|
|
@@ -569,6 +652,12 @@ export declare function queryOne<T>(engine: EngineHandle, namespace: string, typ
|
|
|
569
652
|
//#endregion
|
|
570
653
|
//#region ../../packages/substrate-sdk/src/field.d.ts
|
|
571
654
|
interface ScalarFieldOptions {
|
|
655
|
+
/**
|
|
656
|
+
* `true` builds a btree for this field. Leave it unset for no index: the
|
|
657
|
+
* field still filters and sorts, by scanning. `false` also means no index,
|
|
658
|
+
* and marks the field as not a search handle (long-form prose), so NL
|
|
659
|
+
* leaves it out.
|
|
660
|
+
*/
|
|
572
661
|
indexed?: boolean;
|
|
573
662
|
nullable?: boolean;
|
|
574
663
|
/**
|
|
@@ -626,9 +715,9 @@ interface StructFieldOptions {
|
|
|
626
715
|
}
|
|
627
716
|
interface ListFieldOptions {
|
|
628
717
|
/**
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
718
|
+
* Back the list field's `has` (element-membership) filter with a GIN, which
|
|
719
|
+
* the substrate binary derives as a tracked migration at boot — no per-field
|
|
720
|
+
* migration to author. Without it `has` still works, by scanning.
|
|
632
721
|
* Default false. See `FieldDefList.indexed`.
|
|
633
722
|
*/
|
|
634
723
|
indexed?: boolean;
|
|
@@ -673,8 +762,7 @@ export declare const field: {
|
|
|
673
762
|
* JSON body. Value round-trips unchanged. Filter a value INSIDE it with a
|
|
674
763
|
* path predicate — `{ values: { path: ['year'], gt: 1990 } }` — which is
|
|
675
764
|
* type-strict. `eq` / `in` / `has` are index-served only with
|
|
676
|
-
* `{ indexed: true }`; everything else scans the type's rows
|
|
677
|
-
* `_allowTableScan`. No ordering. When inner keys are known at schema time,
|
|
765
|
+
* `{ indexed: true }`; everything else scans the type's rows. No ordering. When inner keys are known at schema time,
|
|
678
766
|
* `field.struct` is still the better fit: declared, indexed, orderable.
|
|
679
767
|
*/
|
|
680
768
|
json(opts?: JsonFieldOptions): FieldDefScalar;
|
|
@@ -691,4 +779,4 @@ export declare function resolveEntityId(dataset: Dataset, type: string, input: I
|
|
|
691
779
|
*/
|
|
692
780
|
export declare function resolveEntityRow(dataset: Dataset, type: string, input: Id): Promise<Row | null>;
|
|
693
781
|
//#endregion
|
|
694
|
-
export { ADMIN_CAPABILITIES, ActorIdentity, type AdminCredential, type AdminEnv, AfterTxWork, AutoCrudVerb, BridgeClient, BridgeCredential, BridgeCredentialStore, BridgeFrame, BridgeRegistry, BridgeUnreachableError, CLIENT_SUPPLIED_SERVER_FIELD, CanDeleteResult, ClientSuppliedServerFieldError, ConditionalUpdateResult, CoordinatorPlugin, type CrossRefFieldOptions, DEFAULT_CAPABILITIES, Dataset, DatasetRegistry, type DateFieldOptions, type DefineNamespaceOptions, DeleteResult, type DeleteRowArgs, type DeleteRowResult, DropParticipant, DropResult, Edge, EdgePatch, EdgeRef, EdgeWriteInput, EdgesStore, EmbedSourceContext, EncodeContext, EngineHandle, EngineInput, EnvelopeShape, FieldDef, FieldDefCrossRef, FieldDefList, FieldDefScalar, FieldDefStruct, FieldInput, FieldKind, FieldPredicate, FilterCapabilities, FilterOperatorDef, FrameEntry, type Grant, HttpHandler, HttpMethod, Id, IdempotencyStore, Identity, IdentityKind, type JsonFieldOptions, KernelLifecycleContext, KernelMigration, KernelMigrationContext, KernelNamespaceContribution, KernelPlugin, KernelRouteClaim, type KeyMutationRefusal, type KeyUpdateRefusal, type ListFieldOptions, McpToolRegistration, MissingReferentError, MutationSchema, NLBase, NLResult, NLVocabularyHint, NamespaceConfig, NamespaceDefinition, NamespaceInstallContext, NamespaceMismatch, NamespaceTypeDef, NlAskRequest, NlAskResult, NlEvidence, NlJudgeAction, NlJudgeChoice, NlJudgeStep, NlJudgedStatus, NlNamespacePack, NlNamespaceRulings, NlOutcome, NlPackField, NlPackType, NlPackValueRef, NlParseStatus, NlParsedData, NlServedPack, NlTrailEvent, NlValueAlias, NlWireEvent, Obligation, OnDelete, OnMissing, OrderByClause, PackEnvelope, PluginLifecycleContext, PluginRouteContext, PluginRouter, Policy, PolicyDecision, PolicyProbeContext, PostWriteHook, ProcessStat, QualifiedFrame, Query, ROW_METADATA_FIELDS, ReadParams, ReadResult, Registry, RegistryBase, RegistryEntry, RegistryEntryInput, RegistryEntryKind, RegistryEntryResolver, RequestContext, RequestObservation, RequestObserver, ReservedField, ResolveObservation, ResolveTarget, Resolver, ResolverArgs, ResolverFrameError, ResolverReturn, ResolverStat, RestrictViolation, Row, RowFilterObligation, RowMetadata, RowMetadataField, RuntimeErrorEntry, RuntimeErrors, RuntimeMetrics, RuntimeOp, SYSTEM_NAMESPACE, type ScalarFieldOptions, ScheduledTask, ScheduledTaskContext, Schema, SlowRequest, StartOpts, type StructFieldOptions, SubstrateRequest, SubstrateResponse, SubstrateServer, SweepDeps, SweepState, TargetState, TlsConfig, type TokenProviderOpts, TxScopeHandles, type TypeInput, TypeSchema, TypedResolver, UnsupportedFilterError, UpdateFieldRef, type UpdateResolverOptions, VirtualMutationDef, VirtualTypeDef, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, WS_REASON_SERVER_RESTART, WS_REASON_SUBSCRIPTION_OVERLOADED, WhereClause, WriteEvent, WriteOptions, WriteResult, WsConnection, WsHandler, WsRequestFrame, WsResponseFrame, WsResponseKind, adminClaimCapabilities, allowAll, allowVerbs, and, applyRowFilters, capabilitiesFor, checkRevocable, checkUpdatable, decodeList, denyAll, denyVerbs, describeGrant, encodeGrant, encodeList, expandFlat, flattenGrant, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, intersectGrants, isActiveAdminKeyRow, isAuthCause, isEncryptedKey, isResolverFrameError, isRestrictViolation, makeAuthorizationProvider, makeTokenProvider, newlyGranted, newlyGrantedPairs, not, or, parseGrantEntries, requireCapability, requireIdentity, requireNamespace, resolveAdminCredential, resolveDefaultKeyPath, resolveDefaultKidPath, revokedAtIso, row };
|
|
782
|
+
export { ADMIN_CAPABILITIES, ActorIdentity, type AdminCredential, type AdminEnv, AfterTxWork, AggFn, AutoCrudVerb, BridgeClient, BridgeCredential, BridgeCredentialStore, BridgeFrame, BridgeRegistry, BridgeUnreachableError, BucketSpec, CLIENT_SUPPLIED_SERVER_FIELD, CanDeleteResult, ClientSuppliedServerFieldError, ConditionalUpdateResult, CoordinatorPlugin, type CrossRefFieldOptions, DEFAULT_CAPABILITIES, DEFAULT_ORDERED_BY, Dataset, DatasetRegistry, type DateFieldOptions, type DefineNamespaceOptions, DeleteResult, type DeleteRowArgs, type DeleteRowResult, DeriveSpec, DropParticipant, DropResult, Dropped, Edge, EdgePatch, EdgeRef, EdgeWriteInput, EdgesStore, EmbedSourceContext, EncodeContext, EngineHandle, EngineInput, EnvelopeShape, FieldDef, FieldDefCrossRef, FieldDefList, FieldDefScalar, FieldDefStruct, FieldInput, FieldKind, FieldPredicate, FilterCapabilities, FilterOperatorDef, FrameAgg, FrameEntry, type Grant, HttpHandler, HttpMethod, Id, IdempotencyStore, Identity, IdentityKind, IndexDecl, IndexPlan, type JsonFieldOptions, KernelLifecycleContext, KernelMigration, KernelMigrationContext, KernelNamespaceContribution, KernelPlugin, KernelRouteClaim, type KeyMutationRefusal, type KeyUpdateRefusal, type ListFieldOptions, McpToolRegistration, MissingReferentError, MutationSchema, NLBase, NLResult, NLVocabularyHint, NamespaceConfig, NamespaceDefinition, NamespaceInstallContext, NamespaceMismatch, NamespaceTypeDef, NestedSelection, NlAskRequest, NlAskResult, NlEvidence, NlFieldPhrase, NlJudgeAction, NlJudgeChoice, NlJudgeStep, NlJudgedStatus, NlNamespacePack, NlNamespaceRulings, NlOutcome, NlPackField, NlPackType, NlPackValueRef, NlParseStatus, NlParsedData, NlServedPack, NlTrailEvent, NlValueAlias, NlWireEvent, Obligation, OnDelete, OnMissing, OrderByClause, OrderedBy, PackEnvelope, PlanClause, PluginLifecycleContext, PluginRouteContext, PluginRouter, Policy, PolicyDecision, PolicyProbeContext, PostWriteHook, ProcessStat, QualifiedFrame, Query, ROW_METADATA_FIELDS, ROW_POLICY_BLOCKS_WALK, ReadParams, ReadResult, RefOperand, Registry, RegistryBase, RegistryEntry, RegistryEntryInput, RegistryEntryKind, RegistryEntryResolver, RequestContext, RequestObservation, RequestObserver, ReservedField, ResolveObservation, ResolveTarget, Resolver, ResolverArgs, ResolverFrameError, ResolverReturn, ResolverStat, RestrictViolation, Row, RowFilterObligation, RowMetadata, RowMetadataField, RuntimeErrorEntry, RuntimeErrors, RuntimeMetrics, RuntimeOp, SYSTEM_NAMESPACE, type ScalarFieldOptions, ScheduledTask, ScheduledTaskContext, Schema, SlowRequest, StartOpts, StorageReport, type StructFieldOptions, SubstrateRequest, SubstrateResponse, SubstrateServer, SweepDeps, SweepState, TargetState, TlsConfig, type TokenProviderOpts, TxScopeHandles, TypeIndexState, type TypeInput, TypeSchema, TypeStats, TypeStorageReport, TypedResolver, UnsupportedFilterError, UpdateFieldRef, type UpdateResolverOptions, VirtualMutationDef, VirtualTypeDef, WALKS_IN_MUTATION, WALKS_IN_SUBSCRIPTION, WALKS_NEED_PARTITIONED, WALKS_UNSUPPORTED_STORE, WALK_BUDGET_EXCEEDED, WALK_UNSUPPORTED_REF, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, WS_REASON_SERVER_RESTART, WS_REASON_SUBSCRIPTION_OVERLOADED, WalkAgg, WalkAggOperand, WalkAggPredicate, WalkNode, WalkPick, WhereClause, WriteEvent, WriteOptions, WriteResult, WriteRow, WsConnection, WsHandler, WsRequestFrame, WsResponseFrame, WsResponseKind, adminClaimCapabilities, allowAll, allowVerbs, and, applyRowFilters, assertNoRepeatedIds, capabilitiesFor, checkRevocable, checkUpdatable, decodeList, denyAll, denyVerbs, describeGrant, encodeGrant, encodeList, expandFlat, flattenGrant, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, intersectGrants, isActiveAdminKeyRow, isAuthCause, isEncryptedKey, isResolverFrameError, isRestrictViolation, makeAuthorizationProvider, makeTokenProvider, naturalOrderOf, newlyGranted, newlyGrantedPairs, not, or, parseGrantEntries, requireCapability, requireIdentity, requireNamespace, resolveAdminCredential, resolveDefaultKeyPath, resolveDefaultKidPath, revokedAtIso, row };
|
package/dist/sdk.js
CHANGED
|
@@ -1,112 +1,7 @@
|
|
|
1
1
|
import { createRequire as __binCreateRequire } from 'node:module'; const require = __binCreateRequire(import.meta.url);
|
|
2
|
-
import { $ as
|
|
3
|
-
import { a as
|
|
4
|
-
import { A as expandFlat, C as not, D as isActiveAdminKeyRow, E as describeGrant, F as parseGrantEntries, I as decodeList, L as encodeList, M as grantEntryError, N as grantIsUniform, O as capabilitiesFor, P as intersectGrants, S as and, T as SYSTEM_NAMESPACE, _ as grantCovers, a as denyAll, b as newlyGrantedPairs, c as requireIdentity, d as confersAnywhere, f as coversNamespace, g as checkUpdatable, h as checkRevocable, i as allowVerbs, j as flattenGrant, k as encodeGrant, l as requireNamespace, m as grantedIn, n as row, o as denyVerbs, p as grantOf, r as allowAll, s as requireCapability, t as applyRowFilters, u as allCapabilities, v as grantEntriesConfer, w as or, x as revokedAtIso, y as newlyGranted } from "./
|
|
5
|
-
import { S as
|
|
6
|
-
import { t as parsePositiveInt } from "./env-utils-B7SGmoeJ.js";
|
|
2
|
+
import { $t as WALKS_IN_SUBSCRIPTION, A as createResolverWithEdges, At as storedVocabSpellings, B as UnattributedWriteError, Bt as isIsoTimestamp, C as queryOne, D as isReservedAutoCrudField, Dt as canonicalVocabValue, E as RESERVED_AUTOCRUD_FIELD_NAMES, Et as WS_REASON_SUBSCRIPTION_OVERLOADED, F as listResolver, Ft as normaliseMetadataOrderBy, Gt as MissingReferentError, H as resolveEntityId, Ht as assertHardDeleteAllowed, I as getResolver, It as normaliseMetadataWhere, Jt as ReservedField, Kt as NamespaceMismatch, L as deleteResolver, Lt as normaliseWalkNode, M as applyUpdatePatch, Mt as RegistryBase, N as updateResolver, Nt as METADATA_AUTHOR_FIELDS, O as field, Ot as normaliseVocabValues, P as purgeResolver, Pt as METADATA_FILTER_FIELDS, Qt as WALKS_IN_MUTATION, R as deleteRow, Rt as createKeyedMutex, S as queryAll, T as RESERVED_AUTOCRUD_FIELDS, Tt as WS_REASON_SERVER_RESTART, U as resolveEntityRow, Ut as validateHardDeleteEnv, V as resolveIdentity, Vt as normalizeIsoTimestamp, Wt as BridgeUnreachableError, Xt as RestrictViolation, Yt as ResolverFrameError, Zt as UnsupportedFilterError, _ as assertIndexDecl, _t as JSON_HEADERS, an as isResolverFrameError, b as EngineQueryError, bt as jsonResponse, cn as ROW_METADATA_FIELDS, dn as BootstrapConfigError, en as WALKS_NEED_PARTITIONED, fn as defineBootstrap, in as isAuthCause, j as installAutoCrud, jt as vocabImplication, k as autoCrudOptionsOf, kt as normaliseVocabWhere, ln as assertNoRepeatedIds, nn as WALK_BUDGET_EXCEEDED, on as isRestrictViolation, qt as ROW_POLICY_BLOCKS_WALK, rn as WALK_UNSUPPORTED_REF, sn as CLIENT_SUPPLIED_SERVER_FIELD, tn as WALKS_UNSUPPORTED_STORE, un as canonicalize, v as assertOrderedBy, w as selectAll, wt as WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, x as makeCtx, xt as parseJsonBody, y as defineNamespace, yt as error400, z as createResolver, zt as isImpossibleIsoTimestamp } from "./src-DK7VEQT6.js";
|
|
3
|
+
import { a as adminClaimCapabilities, c as makeTokenProvider, d as resolveDefaultKidPath, i as DEFAULT_CAPABILITIES, l as resolveAdminCredential, n as trimTrailingSlashes, o as isEncryptedKey, r as ADMIN_CAPABILITIES, s as makeAuthorizationProvider, t as parsePositiveInt, u as resolveDefaultKeyPath } from "./env-utils-CGNazUNt.js";
|
|
4
|
+
import { A as expandFlat, C as not, D as isActiveAdminKeyRow, E as describeGrant, F as parseGrantEntries, I as decodeList, L as encodeList, M as grantEntryError, N as grantIsUniform, O as capabilitiesFor, P as intersectGrants, S as and, T as SYSTEM_NAMESPACE, _ as grantCovers, a as denyAll, b as newlyGrantedPairs, c as requireIdentity, d as confersAnywhere, f as coversNamespace, g as checkUpdatable, h as checkRevocable, i as allowVerbs, j as flattenGrant, k as encodeGrant, l as requireNamespace, m as grantedIn, n as row, o as denyVerbs, p as grantOf, r as allowAll, s as requireCapability, t as applyRowFilters, u as allCapabilities, v as grantEntriesConfer, w as or, x as revokedAtIso, y as newlyGranted } from "./src-DpPdw2oL.js";
|
|
5
|
+
import { C as parseQualifiedKey, S as formatQualifiedKey, b as DEFAULT_ORDERED_BY, w as assertNever, x as naturalOrderOf } from "./src-Dbvuel6w.js";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Engine-call helpers for coordinator/plugin authors.
|
|
11
|
-
*
|
|
12
|
-
* Run an internal engine query or build a request context from inside a
|
|
13
|
-
* plugin route or scheduled task, so coordinators share one implementation.
|
|
14
|
-
*
|
|
15
|
-
* Depends only on `@mnmal-ai/substrate-types`; this package must not take a
|
|
16
|
-
* runtime dependency on `substrate-core`.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Build a minimal `Partial<RequestContext>` for a plugin's engine call.
|
|
20
|
-
*
|
|
21
|
-
* PASS THE CALLER'S IDENTITY WHENEVER THERE IS ONE. Omitting it yields the
|
|
22
|
-
* SYSTEM ACTOR (`identity: null`), which the engine's per-frame namespace gate
|
|
23
|
-
* waves through unconditionally — correct for genuinely system-initiated work
|
|
24
|
-
* (a scheduled sweep, a liveness probe), and a privilege escalation for
|
|
25
|
-
* anything a caller asked for. A plugin route that omits it lets a caller reach
|
|
26
|
-
* namespaces their grant does not cover, because the route gate checks a
|
|
27
|
-
* capability without a namespace and the engine gate then checks a namespace
|
|
28
|
-
* without an identity.
|
|
29
|
-
*
|
|
30
|
-
* The distinction is WHO ASKED, not which plugin.
|
|
31
|
-
*/
|
|
32
|
-
function makeCtx(namespace, operation, identity = null) {
|
|
33
|
-
return {
|
|
34
|
-
identity,
|
|
35
|
-
namespace,
|
|
36
|
-
operation,
|
|
37
|
-
now: /* @__PURE__ */ new Date(),
|
|
38
|
-
headers: {},
|
|
39
|
-
meta: {}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A frame the engine REFUSED, surfaced as a throw rather than as an empty result.
|
|
44
|
-
*
|
|
45
|
-
* Substrate returns a partial-success envelope: a rejected frame comes back with its
|
|
46
|
-
* key ABSENT from `data` and the reason in `errors`. Without this, `queryOne` /
|
|
47
|
-
* `queryAll` would render a refusal as `null` / `[]`, indistinguishable from a
|
|
48
|
-
* query that matched nothing.
|
|
49
|
-
*/
|
|
50
|
-
var EngineQueryError = class extends Error {
|
|
51
|
-
name = "EngineQueryError";
|
|
52
|
-
code;
|
|
53
|
-
constructor(code, message) {
|
|
54
|
-
super(message);
|
|
55
|
-
this.code = code;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
/** Throw when the envelope carries an error, so a refusal cannot read as absence. */
|
|
59
|
-
function assertNoFrameError(env, key) {
|
|
60
|
-
const err = env.errors?.[0];
|
|
61
|
-
if (err !== void 0) throw new EngineQueryError(err.code ?? "query_failed", err.message ?? `${key} was refused`);
|
|
62
|
-
}
|
|
63
|
-
/** Expand a list of field names into the `{ field: true }` selection map. */
|
|
64
|
-
function selectAll(fields) {
|
|
65
|
-
const out = {};
|
|
66
|
-
for (const f of fields) out[f] = true;
|
|
67
|
-
return out;
|
|
68
|
-
}
|
|
69
|
-
/** Accept either a field-name list or an already-built selection map. */
|
|
70
|
-
function toSelection(fields) {
|
|
71
|
-
return Array.isArray(fields) ? selectAll(fields) : fields;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Run an internal engine query and return the row list (empty when the frame
|
|
75
|
-
* resolves to nothing). `fields` may be a name list or a prebuilt selection map.
|
|
76
|
-
*/
|
|
77
|
-
async function queryAll(engine, namespace, typeName, params, fields, identity = null) {
|
|
78
|
-
const key = formatQualifiedKey(namespace, typeName);
|
|
79
|
-
const env = await engine.query({
|
|
80
|
-
frame: { [key]: {
|
|
81
|
-
params,
|
|
82
|
-
fields: toSelection(fields)
|
|
83
|
-
} },
|
|
84
|
-
ctx: makeCtx(namespace, "query", identity)
|
|
85
|
-
});
|
|
86
|
-
assertNoFrameError(env, key);
|
|
87
|
-
const rows = env.data[key];
|
|
88
|
-
if (rows === void 0 || rows === null) return [];
|
|
89
|
-
return rows;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Run an internal engine query expecting at most one row; returns the first
|
|
93
|
-
* row or null. `fields` may be a name list or a prebuilt selection map.
|
|
94
|
-
*/
|
|
95
|
-
async function queryOne(engine, namespace, typeName, params, fields, identity = null) {
|
|
96
|
-
const key = formatQualifiedKey(namespace, typeName);
|
|
97
|
-
const env = await engine.query({
|
|
98
|
-
frame: { [key]: {
|
|
99
|
-
params,
|
|
100
|
-
fields: toSelection(fields)
|
|
101
|
-
} },
|
|
102
|
-
ctx: makeCtx(namespace, "query", identity)
|
|
103
|
-
});
|
|
104
|
-
assertNoFrameError(env, key);
|
|
105
|
-
const rows = env.data[key];
|
|
106
|
-
if (rows === void 0 || rows === null) return null;
|
|
107
|
-
if (Array.isArray(rows)) return rows[0] ?? null;
|
|
108
|
-
return rows;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
//#endregion
|
|
112
|
-
export { ADMIN_CAPABILITIES, BootstrapConfigError, BridgeUnreachableError, CLIENT_SUPPLIED_SERVER_FIELD, DEFAULT_CAPABILITIES, EngineQueryError, JSON_HEADERS, METADATA_AUTHOR_FIELDS, METADATA_FILTER_FIELDS, MissingReferentError, NamespaceMismatch, RESERVED_AUTOCRUD_FIELDS, RESERVED_AUTOCRUD_FIELD_NAMES, ROW_METADATA_FIELDS, RegistryBase, ReservedField, ResolverFrameError, RestrictViolation, SYSTEM_NAMESPACE, UnattributedWriteError, UnsupportedFilterError, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, WS_REASON_SERVER_RESTART, WS_REASON_SUBSCRIPTION_OVERLOADED, adminClaimCapabilities, allCapabilities, allowAll, allowVerbs, and, applyRowFilters, applyUpdatePatch, assertHardDeleteAllowed, assertNever, autoCrudOptionsOf, canonicalVocabValue, canonicalize, capabilitiesFor, checkRevocable, checkUpdatable, confersAnywhere, coversNamespace, createKeyedMutex, createResolver, createResolverWithEdges, decodeList, defineBootstrap, defineNamespace, deleteResolver, deleteRow, denyAll, denyVerbs, describeGrant, encodeGrant, encodeList, error400, expandFlat, field, flattenGrant, formatQualifiedKey, getResolver, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, grantOf, grantedIn, installAutoCrud, intersectGrants, isActiveAdminKeyRow, isAuthCause, isEncryptedKey, isResolverFrameError, isRestrictViolation, jsonResponse, listResolver, makeAuthorizationProvider, makeCtx, makeTokenProvider, newlyGranted, newlyGrantedPairs, normaliseMetadataOrderBy, normaliseMetadataWhere, normaliseVocabValues, normaliseVocabWhere, not, or, parseGrantEntries, parseJsonBody, parsePositiveInt, parseQualifiedKey, purgeResolver, queryAll, queryOne, requireCapability, requireIdentity, requireNamespace, resolveAdminCredential, resolveDefaultKeyPath, resolveDefaultKidPath, resolveEntityId, resolveEntityRow, resolveIdentity, revokedAtIso, row, selectAll, storedVocabSpellings, updateResolver, validateHardDeleteEnv, vocabImplication };
|
|
7
|
+
export { ADMIN_CAPABILITIES, BootstrapConfigError, BridgeUnreachableError, CLIENT_SUPPLIED_SERVER_FIELD, DEFAULT_CAPABILITIES, DEFAULT_ORDERED_BY, EngineQueryError, JSON_HEADERS, METADATA_AUTHOR_FIELDS, METADATA_FILTER_FIELDS, MissingReferentError, NamespaceMismatch, RESERVED_AUTOCRUD_FIELDS, RESERVED_AUTOCRUD_FIELD_NAMES, ROW_METADATA_FIELDS, ROW_POLICY_BLOCKS_WALK, RegistryBase, ReservedField, ResolverFrameError, RestrictViolation, SYSTEM_NAMESPACE, UnattributedWriteError, UnsupportedFilterError, WALKS_IN_MUTATION, WALKS_IN_SUBSCRIPTION, WALKS_NEED_PARTITIONED, WALKS_UNSUPPORTED_STORE, WALK_BUDGET_EXCEEDED, WALK_UNSUPPORTED_REF, WS_CODE_SUBSCRIPTION_UNSUPPORTED_FRAME, WS_REASON_SERVER_RESTART, WS_REASON_SUBSCRIPTION_OVERLOADED, adminClaimCapabilities, allCapabilities, allowAll, allowVerbs, and, applyRowFilters, applyUpdatePatch, assertHardDeleteAllowed, assertIndexDecl, assertNever, assertNoRepeatedIds, assertOrderedBy, autoCrudOptionsOf, canonicalVocabValue, canonicalize, capabilitiesFor, checkRevocable, checkUpdatable, confersAnywhere, coversNamespace, createKeyedMutex, createResolver, createResolverWithEdges, decodeList, defineBootstrap, defineNamespace, deleteResolver, deleteRow, denyAll, denyVerbs, describeGrant, encodeGrant, encodeList, error400, expandFlat, field, flattenGrant, formatQualifiedKey, getResolver, grantCovers, grantEntriesConfer, grantEntryError, grantIsUniform, grantOf, grantedIn, installAutoCrud, intersectGrants, isActiveAdminKeyRow, isAuthCause, isEncryptedKey, isImpossibleIsoTimestamp, isIsoTimestamp, isReservedAutoCrudField, isResolverFrameError, isRestrictViolation, jsonResponse, listResolver, makeAuthorizationProvider, makeCtx, makeTokenProvider, naturalOrderOf, newlyGranted, newlyGrantedPairs, normaliseMetadataOrderBy, normaliseMetadataWhere, normaliseVocabValues, normaliseVocabWhere, normaliseWalkNode, normalizeIsoTimestamp, not, or, parseGrantEntries, parseJsonBody, parsePositiveInt, parseQualifiedKey, purgeResolver, queryAll, queryOne, requireCapability, requireIdentity, requireNamespace, resolveAdminCredential, resolveDefaultKeyPath, resolveDefaultKidPath, resolveEntityId, resolveEntityRow, resolveIdentity, revokedAtIso, row, selectAll, storedVocabSpellings, trimTrailingSlashes, updateResolver, validateHardDeleteEnv, vocabImplication };
|