graphddb 0.7.9 → 0.8.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/README.md +6 -6
- package/dist/cdc/index.d.ts +389 -4
- package/dist/cdc/index.js +4 -3
- package/dist/{chunk-ZPNRLOKA.js → chunk-GS4C5VGO.js} +4 -6
- package/dist/chunk-HNY2EJPV.js +1184 -0
- package/dist/{chunk-NYM7K2ST.js → chunk-I4LEJ4TF.js} +3812 -6724
- package/dist/{chunk-PFFPLD4B.js → chunk-L2NEDS7U.js} +725 -2112
- package/dist/chunk-L4QRCHRQ.js +278 -0
- package/dist/chunk-LGHSZIEE.js +187 -0
- package/dist/chunk-N4NWYNGZ.js +1987 -0
- package/dist/{chunk-PDUVTYC5.js → chunk-XTWXMOHD.js} +0 -1
- package/dist/cli.js +63 -252
- package/dist/index.d.ts +23 -1548
- package/dist/index.js +100 -1778
- package/dist/internal/index.d.ts +84 -0
- package/dist/internal/index.js +701 -0
- package/dist/{maintenance-view-adapter-BATUh_I8.d.ts → key-DR7_lpyk.d.ts} +538 -2975
- package/dist/linter/index.d.ts +39 -6
- package/dist/linter/index.js +22 -4
- package/dist/{registry-CXhP4TaE.d.ts → linter-C-vypgut.d.ts} +22 -22
- package/dist/prepared-artifact-BpPgkXEo.d.ts +281 -0
- package/dist/spec/index.d.ts +506 -4
- package/dist/spec/index.js +36 -17
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +4 -3
- package/dist/transform/index.d.ts +460 -1
- package/dist/transform/index.js +2085 -2
- package/dist/types-2PMXEn5x.d.ts +1205 -0
- package/dist/types-BXLzIcQD.d.ts +450 -0
- package/docs/cdc-projection.md +5 -5
- package/docs/class-hydration.md +1 -1
- package/docs/cqrs-contract.md +28 -20
- package/docs/design-patterns.md +5 -5
- package/docs/docs-generation.md +6 -6
- package/docs/middleware.md +15 -15
- package/docs/mutation-command-derivation.md +52 -42
- package/docs/prepared-statements.md +14 -14
- package/docs/python-bridge.md +113 -66
- package/docs/spec.md +153 -124
- package/docs/testing.md +9 -8
- package/package.json +20 -5
- package/dist/chunk-MMVHOUM4.js +0 -24
- package/dist/from-change-DanwjE5b.d.ts +0 -327
- package/dist/index-CtPJSMrc.d.ts +0 -934
- package/dist/relation-depth-Dg3yhl7S.d.ts +0 -36
package/dist/index-CtPJSMrc.d.ts
DELETED
|
@@ -1,934 +0,0 @@
|
|
|
1
|
-
import { Q as QueryModelContract, x as QueryMethodSpec, y as CommandModelContract, z as CommandMethodSpec, A as ContractSpec, G as QuerySpec, H as CommandSpec, I as TransactionSpec, J as ContextSpec, K as SPEC_VERSION, L as ParamSpec, m as EntityMetadata, N as ParamDescriptor, O as EntityRef, X as ConditionInput, Y as Param, M as ModelStatic, w as DDBModel, Z as DefinitionMap, _ as OperationsDocument, $ as AnyOperationDefinition, a0 as Manifest, a1 as BridgeBundle, a2 as ConditionSpec, a3 as PreparedBody } from './maintenance-view-adapter-BATUh_I8.js';
|
|
2
|
-
import { M as MetadataRegistry } from './registry-CXhP4TaE.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Contract-layer serialization (issue #59, CQRS Contract layer, Epic #57;
|
|
6
|
-
* spec `docs/cqrs-contract.md`, "SSoT Schema").
|
|
7
|
-
*
|
|
8
|
-
* The Contract IR (#58, `src/define/contract.ts`) holds, per contract method, a
|
|
9
|
-
* resolved declarative {@link ContractMethodOp} plus the **decided facts** the
|
|
10
|
-
* planner derived (`resolution` / `inputArity` / `result`). This module
|
|
11
|
-
* **serializes** those facts into the JSON SSoT — it does **not** re-derive them:
|
|
12
|
-
*
|
|
13
|
-
* - The `contracts` map (contract name → {@link ContractSpec}) is layered **on
|
|
14
|
-
* top of** the existing `queries` / `commands` / `transactions`. Each method
|
|
15
|
-
* references one of them by name (`ContractName__methodName`), so the existing
|
|
16
|
-
* operation-spec shapes are unchanged and the current runtime keeps working.
|
|
17
|
-
* - The referenced operation spec is produced by **reusing** the proven
|
|
18
|
-
* {@link buildQuerySpec} / {@link buildCommandSpec} planners: a
|
|
19
|
-
* {@link ContractMethodOp} is translated back into the {@link AnyOperationDefinition}
|
|
20
|
-
* shape those planners consume (the contract's sentinel references become the
|
|
21
|
-
* `Param` placeholders the planner already understands), so the symbolic key
|
|
22
|
-
* evaluation, projection, relation chaining, and condition handling are shared
|
|
23
|
-
* — never re-implemented, never drifting.
|
|
24
|
-
*
|
|
25
|
-
* Everything emitted is **JSON-serializable** by construction (only strings /
|
|
26
|
-
* numbers / booleans / arrays / plain objects). A contract-free input emits no
|
|
27
|
-
* `contracts` / `contexts` keys, so the pre-#59 operations document is reproduced
|
|
28
|
-
* byte-for-byte (backward compatibility).
|
|
29
|
-
*
|
|
30
|
-
* ## What this issue serializes vs. defers
|
|
31
|
-
*
|
|
32
|
-
* The #58 IR captures a single declarative op per method with a boolean `select`
|
|
33
|
-
* projection; it does **not** model External Query / Query Composition (no
|
|
34
|
-
* `query(Contract.method, { from(...) })` primitive exists yet). So no #58
|
|
35
|
-
* contract produces a `compose`. The serializer nonetheless **supports** it: when
|
|
36
|
-
* a method op carries composition (a forward-compatible {@link ContractMethodOp}
|
|
37
|
-
* extension), it is emitted per the proposal's `compose` shape. The N+1 checker
|
|
38
|
-
* (#60), boundary lint (#61), and runtime execution (#62) are out of scope here —
|
|
39
|
-
* this is serialization + generator only.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A contract as accepted by the serializer: either a resolved
|
|
44
|
-
* {@link QueryModelContract} or a {@link CommandModelContract} (the #58 factory
|
|
45
|
-
* output). The Key type is erased — the serializer reads the key **fields** off
|
|
46
|
-
* the resolved op / model metadata, not the phantom type.
|
|
47
|
-
*/
|
|
48
|
-
type AnyModelContract = QueryModelContract<unknown, Record<string, QueryMethodSpec<unknown, unknown, unknown>>> | CommandModelContract<unknown, Record<string, CommandMethodSpec<unknown, unknown, unknown>>>;
|
|
49
|
-
/** A map of contract name → resolved contract IR (as passed to the generator). */
|
|
50
|
-
type ContractMap = Record<string, AnyModelContract>;
|
|
51
|
-
/**
|
|
52
|
-
* A context-ownership declaration as authored by the producer: context name →
|
|
53
|
-
* the Model (entity) and Contract names that belong to it. The serializer sorts
|
|
54
|
-
* the member lists deterministically; see {@link ContextSpec}.
|
|
55
|
-
*/
|
|
56
|
-
interface ContextOwnership {
|
|
57
|
-
readonly models?: readonly string[];
|
|
58
|
-
readonly contracts?: readonly string[];
|
|
59
|
-
}
|
|
60
|
-
/** A map of context name → its membership (as passed to the generator). */
|
|
61
|
-
type ContextOwnershipMap = Record<string, ContextOwnership>;
|
|
62
|
-
/**
|
|
63
|
-
* The output of {@link buildContracts}: the `contracts` map and the
|
|
64
|
-
* **synthesized** operation specs each method references. The caller merges the
|
|
65
|
-
* synthesized `queries` / `commands` / `transactions` into the document's
|
|
66
|
-
* existing maps (a contract method's referenced op lives alongside hand-written
|
|
67
|
-
* definitions, addressed by name).
|
|
68
|
-
*/
|
|
69
|
-
interface BuiltContracts {
|
|
70
|
-
readonly contracts: Record<string, ContractSpec>;
|
|
71
|
-
/** Synthesized read ops referenced by query contract methods. */
|
|
72
|
-
readonly queries: Record<string, QuerySpec>;
|
|
73
|
-
/** Synthesized write ops referenced by command contract methods (single form). */
|
|
74
|
-
readonly commands: Record<string, CommandSpec>;
|
|
75
|
-
/**
|
|
76
|
-
* Synthesized transactions referenced by command contract methods whose array
|
|
77
|
-
* form resolves to a `'transact'` batched write (issue #64). One transaction per
|
|
78
|
-
* such method, named `<Contract>__<method>__batch`: a single `forEach`-over-keys
|
|
79
|
-
* write item that the runtime expands once per key (≤25, atomic), reusing the
|
|
80
|
-
* proven declarative-transaction machinery (#46). Empty when no command method
|
|
81
|
-
* declares a `'transact'` batch.
|
|
82
|
-
*/
|
|
83
|
-
readonly transactions: Record<string, TransactionSpec>;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* The derived-effect family of one serialized prepared-write transaction item
|
|
87
|
-
* (issue #208). Index-aligned to `TransactionSpec.items`; the AOT loader groups
|
|
88
|
-
* rendered items by category ACROSS the plan's ops so the composed
|
|
89
|
-
* `TransactWriteItems` matches the in-process execution core's order
|
|
90
|
-
* (writes, then all edges, then all derived updates, …) byte-for-byte.
|
|
91
|
-
*/
|
|
92
|
-
type PreparedWriteItemCategory = 'base' | 'edge' | 'derive' | 'unique' | 'outbox' | 'idempotency' | 'maintain' | 'maintainOutbox' | 'check';
|
|
93
|
-
/**
|
|
94
|
-
* Serialize a map of resolved contracts into the `contracts` SSoT map plus the
|
|
95
|
-
* synthesized operation specs each method references. Deterministic: contracts
|
|
96
|
-
* and methods are emitted in sorted-key order.
|
|
97
|
-
*
|
|
98
|
-
* @param contracts Contract name → resolved {@link QueryModelContract} /
|
|
99
|
-
* {@link CommandModelContract} (the #58 factory output). Empty → empty output.
|
|
100
|
-
* @throws if a contract method op cannot be serialized (a non-boolean projection
|
|
101
|
-
* slot, an unsupported write condition); or if a contract violates an N+1
|
|
102
|
-
* safety rule (#60, {@link assertContractN1Safe}) — an array into a `range`
|
|
103
|
-
* method, a "list under a list", or a `range` composed child.
|
|
104
|
-
*/
|
|
105
|
-
declare function buildContracts(contracts?: ContractMap): BuiltContracts;
|
|
106
|
-
/**
|
|
107
|
-
* Serialize the context-ownership declarations into the SSoT `contexts` map.
|
|
108
|
-
* Member lists are sorted for determinism. An empty input yields an empty map
|
|
109
|
-
* (the caller then omits the key for backward compatibility).
|
|
110
|
-
*/
|
|
111
|
-
declare function buildContexts(contexts?: ContextOwnershipMap): Record<string, ContextSpec>;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Static prepared-plan artifact — the SHARED, dependency-minimal half of the
|
|
115
|
-
* AOT pipeline (issue #208; layering fixed by #223).
|
|
116
|
-
*
|
|
117
|
-
* This module carries everything BOTH sides of the pipeline need:
|
|
118
|
-
*
|
|
119
|
-
* - the artifact shapes ({@link PreparedPlanDocument} and friends),
|
|
120
|
-
* - the format version ({@link PREPARED_FORMAT_VERSION}),
|
|
121
|
-
* - canonical JSON ({@link canonicalJson}) and the drift-detection
|
|
122
|
-
* fingerprints ({@link entityFingerprint} / {@link planFingerprint}).
|
|
123
|
-
*
|
|
124
|
-
* ## Layering (#223)
|
|
125
|
-
*
|
|
126
|
-
* The dependency direction is strictly one-way:
|
|
127
|
-
*
|
|
128
|
-
* ```
|
|
129
|
-
* emitter (src/spec/prepared.ts, build-time) ──▶ THIS MODULE
|
|
130
|
-
* loader (src/runtime/prepared-loader.ts) ──▶ THIS MODULE
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* The loader must NEVER import the emitter: the emitter drags the whole
|
|
134
|
-
* build-time spec machinery into the runtime bundle (`dist/index.js`), which
|
|
135
|
-
* is exactly the leak the size-limit CI gate caught in #223. This module's
|
|
136
|
-
* only value-level dependencies are ones the loader already carries
|
|
137
|
-
* (`buildManifestEntity` / spec types).
|
|
138
|
-
*
|
|
139
|
-
* ## Fingerprints are checksums, not cryptography
|
|
140
|
-
*
|
|
141
|
-
* The fingerprint exists to detect DRIFT (model declarations changed since
|
|
142
|
-
* the artifact was generated). It is not a security boundary, so it uses a
|
|
143
|
-
* pure-TypeScript FNV-1a 64-bit hash — no `node:crypto`, no platform builtin,
|
|
144
|
-
* bundles everywhere. Switching the algorithm (sha-256 → FNV-1a) is what
|
|
145
|
-
* bumped {@link PREPARED_FORMAT_VERSION} '1' → '2': a format-'1' artifact's
|
|
146
|
-
* fingerprints can never match, so the loader rejects the version loudly
|
|
147
|
-
* instead of failing the comparison confusingly.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* The prepared-plan artifact format version (independent of {@link SPEC_VERSION}).
|
|
152
|
-
*
|
|
153
|
-
* '2' (#223): fingerprints are FNV-1a 64-bit over canonical JSON (16 hex
|
|
154
|
-
* chars). '1' (#208, graphddb ≤ 0.7.2) used sha-256 via `node:crypto`; the
|
|
155
|
-
* loader rejects '1' artifacts with a regeneration instruction.
|
|
156
|
-
*/
|
|
157
|
-
declare const PREPARED_FORMAT_VERSION: "2";
|
|
158
|
-
/**
|
|
159
|
-
* One serialized value bind: a `$`-param slot (bound from the caller's
|
|
160
|
-
* `execute(params)` by name) or a static literal recorded at build time. `Date`
|
|
161
|
-
* and `bigint` literals — which JSON cannot carry natively — are encoded
|
|
162
|
-
* explicitly and revived by the loader, so the bound value is the SAME typed
|
|
163
|
-
* value the runtime `prepare` would have captured.
|
|
164
|
-
*/
|
|
165
|
-
type PreparedBindSpec = {
|
|
166
|
-
readonly param: string;
|
|
167
|
-
} | {
|
|
168
|
-
readonly literal: string | number | boolean | null;
|
|
169
|
-
} | {
|
|
170
|
-
readonly literalDate: string;
|
|
171
|
-
} | {
|
|
172
|
-
readonly literalBigInt: string;
|
|
173
|
-
};
|
|
174
|
-
/** A `{ field: bind }` map (a serialized slot map). */
|
|
175
|
-
type PreparedBindMap = Readonly<Record<string, PreparedBindSpec>>;
|
|
176
|
-
/** One serialized read route of a prepared READ plan. */
|
|
177
|
-
interface PreparedReadRouteSpec {
|
|
178
|
-
readonly alias: string;
|
|
179
|
-
readonly op: 'query' | 'list';
|
|
180
|
-
/** The target entity name (re-bound via the registry at load). */
|
|
181
|
-
readonly entity: string;
|
|
182
|
-
/** The static, params-independent select template (JSON-safe by the #206 lint). */
|
|
183
|
-
readonly select: Record<string, unknown>;
|
|
184
|
-
/** Key-field binds (`{ field: { param | literal } }`). */
|
|
185
|
-
readonly key: PreparedBindMap;
|
|
186
|
-
/** Static option literals decided at build time. */
|
|
187
|
-
readonly maxDepth?: number;
|
|
188
|
-
readonly order?: 'ASC' | 'DESC';
|
|
189
|
-
readonly filter?: Record<string, unknown>;
|
|
190
|
-
/** Dynamic option binds (a `$` param or a literal, decided per call). */
|
|
191
|
-
readonly consistentRead?: PreparedBindSpec;
|
|
192
|
-
readonly limit?: PreparedBindSpec;
|
|
193
|
-
readonly after?: PreparedBindSpec;
|
|
194
|
-
/**
|
|
195
|
-
* The spec-IR read plan (`operations.json` vocabulary: physical ops, templated
|
|
196
|
-
* `{<field>}` key conditions, relation fan-outs, execution plan) derived from
|
|
197
|
-
* this route at build time. Key-condition tokens are the entity's key FIELD
|
|
198
|
-
* names; the per-call param→field mapping is {@link key}. Deriving it at build
|
|
199
|
-
* time surfaces a broken route as a BUILD failure and freezes the physical
|
|
200
|
-
* plan for drift comparison.
|
|
201
|
-
*/
|
|
202
|
-
readonly query: QuerySpec;
|
|
203
|
-
}
|
|
204
|
-
/** One serialized write op of a prepared WRITE plan. */
|
|
205
|
-
interface PreparedWriteOpSpec {
|
|
206
|
-
readonly alias: string;
|
|
207
|
-
readonly entity: string;
|
|
208
|
-
readonly intent: 'create' | 'update' | 'remove';
|
|
209
|
-
/** The target model's primary-key input fields (W1 key/changes split + read-back key). */
|
|
210
|
-
readonly keyFields: readonly string[];
|
|
211
|
-
/** Key-field binds. */
|
|
212
|
-
readonly key: PreparedBindMap;
|
|
213
|
-
/** Input-field binds. */
|
|
214
|
-
readonly input: PreparedBindMap;
|
|
215
|
-
/** In-process write-gate binds (flat equality / existence template), if declared. */
|
|
216
|
-
readonly condition?: PreparedBindMap;
|
|
217
|
-
/** The read-back projection + options, verbatim (JSON-safe by the #206 lint). */
|
|
218
|
-
readonly result?: {
|
|
219
|
-
readonly select?: Record<string, unknown>;
|
|
220
|
-
readonly options?: {
|
|
221
|
-
readonly consistentRead?: boolean;
|
|
222
|
-
readonly maxDepth?: number;
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
/**
|
|
226
|
-
* The consistent read-back's spec-IR plan (derived from `result.select` at
|
|
227
|
-
* build time — a broken read-back projection fails the BUILD). Present iff
|
|
228
|
-
* {@link result} declares a non-empty select.
|
|
229
|
-
*/
|
|
230
|
-
readonly readback?: QuerySpec;
|
|
231
|
-
/**
|
|
232
|
-
* The op's full declarative {@link TransactionSpec}: `items[0]` is the base
|
|
233
|
-
* write, followed by every derived effect the mutation compiler resolved at
|
|
234
|
-
* build time. Templates bind `{<field>}` tokens — the op's key/input FIELD
|
|
235
|
-
* names — which the loader renders from the per-call bound field values.
|
|
236
|
-
*/
|
|
237
|
-
readonly transaction: TransactionSpec;
|
|
238
|
-
/** Per-item derived-effect categories, index-aligned to `transaction.items`. */
|
|
239
|
-
readonly categories: readonly PreparedWriteItemCategory[];
|
|
240
|
-
}
|
|
241
|
-
/** One compiled prepared plan (all routes of one `DDBModel.prepare` body). */
|
|
242
|
-
interface PreparedPlanSpec {
|
|
243
|
-
readonly kind: 'read' | 'write';
|
|
244
|
-
/**
|
|
245
|
-
* The `$` params the plan binds (union across routes), with kinds recovered
|
|
246
|
-
* from the bound entity fields where determinable.
|
|
247
|
-
*/
|
|
248
|
-
readonly params: Readonly<Record<string, ParamSpec>>;
|
|
249
|
-
/**
|
|
250
|
-
* Entity name → fingerprint of its canonical manifest entry at build time.
|
|
251
|
-
* The loader recomputes these from the live registry and LOUDLY rejects a
|
|
252
|
-
* mismatch (stale plan / model drift).
|
|
253
|
-
*/
|
|
254
|
-
readonly entities: Readonly<Record<string, string>>;
|
|
255
|
-
/** Read routes, in body declaration order (read plans only). */
|
|
256
|
-
readonly reads?: readonly PreparedReadRouteSpec[];
|
|
257
|
-
/** Write ops, in body declaration order (write plans only). */
|
|
258
|
-
readonly writes?: readonly PreparedWriteOpSpec[];
|
|
259
|
-
}
|
|
260
|
-
/** The full static prepared-plan artifact. */
|
|
261
|
-
interface PreparedPlanDocument {
|
|
262
|
-
readonly formatVersion: typeof PREPARED_FORMAT_VERSION;
|
|
263
|
-
/** The shared operation-IR version the plans were compiled against. */
|
|
264
|
-
readonly specVersion: typeof SPEC_VERSION;
|
|
265
|
-
/** Plan id (the transform's stable call-site id) → compiled plan. */
|
|
266
|
-
readonly plans: Readonly<Record<string, PreparedPlanSpec>>;
|
|
267
|
-
}
|
|
268
|
-
/** Deterministic JSON: object keys sorted at every level (arrays keep order). */
|
|
269
|
-
declare function canonicalJson(value: unknown): string;
|
|
270
|
-
/**
|
|
271
|
-
* The fingerprint of one entity's canonical manifest entry — every plan-relevant
|
|
272
|
-
* declaration fact (table, physical name, prefix, fields + formats, key / GSI
|
|
273
|
-
* templates, relations incl. `refs` bindings, TTL). Computed identically at
|
|
274
|
-
* build (emit) and at load (live registry), so any drift is caught.
|
|
275
|
-
*/
|
|
276
|
-
declare function entityFingerprint(metadata: EntityMetadata): string;
|
|
277
|
-
/** Stable content hash of a compiled plan (drift-check convenience). */
|
|
278
|
-
declare function planFingerprint(plan: PreparedPlanSpec): string;
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Declarative transaction definition DSL (issue #46, Python-bridge Phase 4).
|
|
282
|
-
*
|
|
283
|
-
* `defineTransaction(params, (tx, p) => { … })` captures a **single source of
|
|
284
|
-
* truth** for a `TransactWriteItems` batch: a parameter map plus a declarative
|
|
285
|
-
* instruction list (`tx.put` / `tx.update` / `tx.delete`, plus `tx.forEach` over
|
|
286
|
-
* an array param). The callback is evaluated at definition time with sentinel
|
|
287
|
-
* proxies in place of params / loop elements, so the recorded instructions carry
|
|
288
|
-
* **field-reference templates** (`{groupId}`, `{item.userId}`) rather than
|
|
289
|
-
* concrete values — exactly the shape the static planner (#42) turns into a
|
|
290
|
-
* serializable `transaction` op the TS and Python runtimes expand identically.
|
|
291
|
-
*
|
|
292
|
-
* ## Declarativity boundary (enforced — same soundness as #42 keys)
|
|
293
|
-
*
|
|
294
|
-
* The callback body may only:
|
|
295
|
-
* - call `tx.put/update/delete(Model, …)` with **field references** (from `p`
|
|
296
|
-
* or a `forEach` element) or **concrete literals** at scalar leaves;
|
|
297
|
-
* - call `tx.forEach(p.<arrayParam>, (el) => { … }, { when? })` whose body is
|
|
298
|
-
* itself only `tx.*` writes;
|
|
299
|
-
* - attach a declarative `when` (a small comparison over field refs) and/or a
|
|
300
|
-
* `condition` (the `{ notExists } | equality` subset, as for single writes).
|
|
301
|
-
*
|
|
302
|
-
* The same hardening that protects **key** positions (#42 `src/spec/symbolic.ts`)
|
|
303
|
-
* is applied to **value** positions (item / changes / condition values, `when`
|
|
304
|
-
* right-hand side). Value positions are in fact held to a *stricter* boundary
|
|
305
|
-
* than keys: a key may legitimately interpolate a field (`` `USER#${id}` ``), so
|
|
306
|
-
* coercion is allowed there and the differential template check is the boundary;
|
|
307
|
-
* a value leaf may **only** be a *direct* field reference or a concrete literal,
|
|
308
|
-
* so at a value position a faithful reference is **never coerced**. That single
|
|
309
|
-
* fact is the soundness boundary:
|
|
310
|
-
*
|
|
311
|
-
* 1. **Throwing sentinel Proxy.** Each param / element placeholder is a Proxy
|
|
312
|
-
* whose `get` trap whitelists only primitive coercion
|
|
313
|
-
* (`Symbol.toPrimitive` / `toString` / `valueOf`) and the brand / `token` /
|
|
314
|
-
* `origin` reads the planner needs, and **throws on every other property or
|
|
315
|
-
* method access**. So a *direct* transform on a value placeholder —
|
|
316
|
-
* `p.role.length`, `p.role[0]`, `p.role.toUpperCase()` — fails at the access
|
|
317
|
-
* site, exactly like a key sentinel. (Same first-line defense as #42.)
|
|
318
|
-
* 2. **Per-access coercion ledger (primary boundary).** Every minted field ref
|
|
319
|
-
* records each time it is coerced to a primitive (`Symbol.toPrimitive` /
|
|
320
|
-
* `toString` / `valueOf`). Because a faithful value reference is stored as
|
|
321
|
-
* the Proxy *object* and never coerced, **any** coercion of a value ref is
|
|
322
|
-
* positive proof the callback consumed the parameter into a transform, a
|
|
323
|
-
* branch, an interpolation, or a comparison — and the build is rejected. This
|
|
324
|
-
* is *access-site* accurate: it fires even when the same field is *also*
|
|
325
|
-
* referenced faithfully elsewhere in the item (so its token still surfaces),
|
|
326
|
-
* and it catches transforms that **converge to a constant or a shared marker
|
|
327
|
-
* fragment** — `String(p.role).slice(0,0)` → `''`, `.slice(0,3)` → a shared
|
|
328
|
-
* prefix, `[0]` / `.charAt(0)`, `.includes('Tx')` → a constant boolean, any
|
|
329
|
-
* `… + 'CONST'` built atop them — which a purely output-comparing check could
|
|
330
|
-
* not (the dropped field is masked by its faithful sibling, and the converged
|
|
331
|
-
* value is byte-identical across passes).
|
|
332
|
-
* 3. **Differential evaluation (secondary).** The callback is evaluated **twice**,
|
|
333
|
-
* each run delivering placeholders that coerce to a *different* per-field
|
|
334
|
-
* marker (the two markers share no common prefix and no common substring of
|
|
335
|
-
* length ≥ 2, and differ in length). Every recorded value leaf must be either
|
|
336
|
-
* (a) a faithful field reference (the Proxy object survived intact in *both*
|
|
337
|
-
* runs) or (b) a concrete literal byte-identical across both runs. This is a
|
|
338
|
-
* defense-in-depth layer behind the coercion ledger.
|
|
339
|
-
* 4. **Consumed-field check.** A placeholder field that the callback *accessed*
|
|
340
|
-
* but that never reached the recorded output — e.g. `(p.role === 'admin') ?
|
|
341
|
-
* 'A' : 'B'`, where `===` does **not** coerce (so the ledger does not fire),
|
|
342
|
-
* the comparison is `false`, and only a literal is emitted — is rejected: the
|
|
343
|
-
* param was silently dropped and a branch burned into the spec. (Same
|
|
344
|
-
* consumed-field accounting #42 uses for `kind === 'admin' ? … : …`.)
|
|
345
|
-
*
|
|
346
|
-
* Arbitrary JS, reads, value branching, arithmetic, coercion, or string
|
|
347
|
-
* transforms on a param / element placeholder are therefore rejected at build
|
|
348
|
-
* time, in **both** key and value positions — **never silently emitted as a
|
|
349
|
-
* wrong spec**. Unlike key positions, value positions have **no residual class**:
|
|
350
|
-
* because a faithful value ref is never coerced, even an identity-shaped
|
|
351
|
-
* transform (`String(p.x).slice(0)`, `.normalize()`, `.trim()`, `.replace('§',…)`
|
|
352
|
-
* on an absent substring) is rejected (it coerced the ref). The only operations
|
|
353
|
-
* that *do not* coerce a ref are (a) storing it directly and (b) the brand read;
|
|
354
|
-
* (a) is the supported faithful reference and (b) is internal — so the ledger has
|
|
355
|
-
* no false positives and no escape.
|
|
356
|
-
*/
|
|
357
|
-
|
|
358
|
-
declare const TX_REF_BRAND: unique symbol;
|
|
359
|
-
/**
|
|
360
|
-
* A captured reference to a parameter (`{name}`) or a `forEach` element field
|
|
361
|
-
* (`{item.<field>}`). Branded so the planner can distinguish a reference from a
|
|
362
|
-
* concrete literal, and so a stray reference cannot be silently coerced.
|
|
363
|
-
*/
|
|
364
|
-
interface TransactionRef {
|
|
365
|
-
readonly [TX_REF_BRAND]: true;
|
|
366
|
-
/** The template token this reference renders to, e.g. `{groupId}`. */
|
|
367
|
-
readonly token: string;
|
|
368
|
-
/** Human-readable origin (for error messages), e.g. `param 'groupId'`. */
|
|
369
|
-
readonly origin: string;
|
|
370
|
-
}
|
|
371
|
-
/** Runtime guard: is `value` a {@link TransactionRef}? */
|
|
372
|
-
declare function isTransactionRef(value: unknown): value is TransactionRef;
|
|
373
|
-
/** A declarative comparison used by `when` (the only branching allowed). */
|
|
374
|
-
type WhenComparison = {
|
|
375
|
-
readonly op: 'eq';
|
|
376
|
-
readonly left: TransactionRef;
|
|
377
|
-
readonly right: unknown;
|
|
378
|
-
} | {
|
|
379
|
-
readonly op: 'ne';
|
|
380
|
-
readonly left: TransactionRef;
|
|
381
|
-
readonly right: unknown;
|
|
382
|
-
};
|
|
383
|
-
/**
|
|
384
|
-
* A single captured instruction inside a transaction. The three write operations
|
|
385
|
-
* (`put` / `update` / `delete`) mutate an item; `conditionCheck` (issue #81) is a
|
|
386
|
-
* **read-only assertion** on another keyed item — it carries a `key` and a
|
|
387
|
-
* **required** `condition` and never mutates, but its failure rolls the whole
|
|
388
|
-
* transaction back. It is the foundation for referential-integrity derivation
|
|
389
|
-
* (`requires <Entity> exists` → a `conditionCheck` with `attributeExists`).
|
|
390
|
-
*/
|
|
391
|
-
interface TxWriteInstruction {
|
|
392
|
-
readonly kind: 'write';
|
|
393
|
-
readonly operation: 'put' | 'update' | 'delete' | 'conditionCheck';
|
|
394
|
-
readonly entity: EntityRef;
|
|
395
|
-
/** Put: the item structure (field → ref / literal). */
|
|
396
|
-
readonly item?: Record<string, unknown>;
|
|
397
|
-
/** Update / delete / conditionCheck: the key structure. */
|
|
398
|
-
readonly key?: Record<string, unknown>;
|
|
399
|
-
/** Update: the changes structure. */
|
|
400
|
-
readonly changes?: Record<string, unknown>;
|
|
401
|
-
/**
|
|
402
|
-
* The write / assertion condition (subset). Optional on `put` / `update` /
|
|
403
|
-
* `delete`; **required** on a `conditionCheck` (the assertion it makes).
|
|
404
|
-
*
|
|
405
|
-
* A tx condition operand may be a `p.*` field reference ({@link
|
|
406
|
-
* TransactionRef}) — the serializer renders it to a `{ $param }` marker — so
|
|
407
|
-
* the recorded leaf type is widened with `TransactionRef` in the tx context
|
|
408
|
-
* (#246), matching what the recorder captures from {@link TxWriteOptions}.
|
|
409
|
-
*/
|
|
410
|
-
readonly condition?: ConditionInput<TransactionRef>;
|
|
411
|
-
/** Optional declarative guard (skip this item when it does not hold). */
|
|
412
|
-
readonly when?: WhenComparison;
|
|
413
|
-
}
|
|
414
|
-
/** A `forEach` block expanding `body` once per element of an array param. */
|
|
415
|
-
interface TxForEachInstruction {
|
|
416
|
-
readonly kind: 'forEach';
|
|
417
|
-
/** The array-param name iterated. */
|
|
418
|
-
readonly source: string;
|
|
419
|
-
/** Optional per-element declarative guard. */
|
|
420
|
-
readonly when?: WhenComparison;
|
|
421
|
-
/** The (write-only) instructions emitted per element. */
|
|
422
|
-
readonly body: TxWriteInstruction[];
|
|
423
|
-
}
|
|
424
|
-
type TxInstruction = TxWriteInstruction | TxForEachInstruction;
|
|
425
|
-
/** Options accepted by `tx.put/update/delete`. */
|
|
426
|
-
interface TxWriteOptions {
|
|
427
|
-
readonly condition?: ConditionInput<TransactionRef>;
|
|
428
|
-
readonly when?: WhenComparison;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Options accepted by `tx.conditionCheck` (issue #81). The `condition` is the
|
|
432
|
-
* read-only assertion the check makes against the keyed item and is **required**
|
|
433
|
-
* — a ConditionCheck with no condition is meaningless. An optional `when` skips
|
|
434
|
-
* the check entirely when the guard does not hold.
|
|
435
|
-
*/
|
|
436
|
-
interface TxConditionCheckOptions {
|
|
437
|
-
readonly condition: ConditionInput<TransactionRef>;
|
|
438
|
-
readonly when?: WhenComparison;
|
|
439
|
-
}
|
|
440
|
-
/** Options accepted by `tx.forEach`. */
|
|
441
|
-
interface TxForEachOptions {
|
|
442
|
-
readonly when?: WhenComparison;
|
|
443
|
-
}
|
|
444
|
-
/** A small comparison helper: `when.eq(ref, value)` / `when.ne(ref, value)`. */
|
|
445
|
-
declare const when: {
|
|
446
|
-
readonly eq: (left: TransactionRef, right: unknown) => WhenComparison;
|
|
447
|
-
readonly ne: (left: TransactionRef, right: unknown) => WhenComparison;
|
|
448
|
-
};
|
|
449
|
-
/** The transaction recorder handed to the callback as `tx`. */
|
|
450
|
-
interface TxRecorder {
|
|
451
|
-
put(model: ModelStatic<DDBModel>, item: Record<string, unknown>, options?: TxWriteOptions): void;
|
|
452
|
-
update(model: ModelStatic<DDBModel>, key: Record<string, unknown>, changes: Record<string, unknown>, options?: TxWriteOptions): void;
|
|
453
|
-
delete(model: ModelStatic<DDBModel>, key: Record<string, unknown>, options?: TxWriteOptions): void;
|
|
454
|
-
/**
|
|
455
|
-
* Record a **read-only** `ConditionCheck` assertion on a keyed item (issue
|
|
456
|
-
* #81): the item is not mutated, but `options.condition` must hold or the whole
|
|
457
|
-
* transaction is cancelled atomically. The foundation for referential-integrity
|
|
458
|
-
* derivation (`requires <Entity> exists` → `conditionCheck(Model, key, {
|
|
459
|
-
* condition: { attributeExists: 'PK' } })`).
|
|
460
|
-
*/
|
|
461
|
-
conditionCheck(model: ModelStatic<DDBModel>, key: Record<string, unknown>, options: TxConditionCheckOptions): void;
|
|
462
|
-
forEach<E>(source: E, body: (element: ElementProxy<E>) => void, options?: TxForEachOptions): void;
|
|
463
|
-
}
|
|
464
|
-
/** The element proxy type inside a `forEach` body (fields → refs). */
|
|
465
|
-
type ElementProxy<E> = E extends Param<infer T> ? T extends (infer Item)[] ? {
|
|
466
|
-
readonly [K in keyof Item]: TransactionRef;
|
|
467
|
-
} : never : never;
|
|
468
|
-
/** The typed IR node produced by {@link defineTransaction}. */
|
|
469
|
-
interface TransactionDefinition {
|
|
470
|
-
/** @internal Marks this object as a transaction definition IR node. */
|
|
471
|
-
readonly __isTransactionDefinition: true;
|
|
472
|
-
/** Collected parameters: name → descriptor (array params carry `element`). */
|
|
473
|
-
readonly params: Readonly<Record<string, ParamDescriptor>>;
|
|
474
|
-
/** The captured, declarative instruction list. */
|
|
475
|
-
readonly instructions: readonly TxInstruction[];
|
|
476
|
-
}
|
|
477
|
-
/** A param map accepted by {@link defineTransaction}. */
|
|
478
|
-
type TransactionParamShape = Record<string, Param<unknown>>;
|
|
479
|
-
/** The `p` proxy type: each scalar param → ref; each array param → itself. */
|
|
480
|
-
type ParamProxy<P extends TransactionParamShape> = {
|
|
481
|
-
readonly [K in keyof P]: P[K] extends {
|
|
482
|
-
readonly kind: 'array';
|
|
483
|
-
} ? P[K] : TransactionRef;
|
|
484
|
-
};
|
|
485
|
-
/**
|
|
486
|
-
* Define a declarative transaction. The callback is evaluated **twice** with
|
|
487
|
-
* throwing value sentinels (one differential marker set per pass); its `tx.*`
|
|
488
|
-
* calls are recorded and the two passes are checked against each other so any
|
|
489
|
-
* non-declarative value (a transform, a value branch, a coercion escape) is
|
|
490
|
-
* rejected at build time — the same soundness #42 enforces for key positions.
|
|
491
|
-
*
|
|
492
|
-
* @param params A record of `param.*` placeholders (scalars and/or `param.array`).
|
|
493
|
-
* @param build `(tx, p) => void` — records the write instructions.
|
|
494
|
-
*/
|
|
495
|
-
declare function defineTransaction<const P extends TransactionParamShape>(params: P, build: (tx: TxRecorder, p: ParamProxy<P>) => void): TransactionDefinition;
|
|
496
|
-
/**
|
|
497
|
-
* Group a record of transaction definitions into the IR consumed by the static
|
|
498
|
-
* planner (#42/#46). Validates each entry is a transaction definition.
|
|
499
|
-
*/
|
|
500
|
-
declare function defineTransactions<const D extends Record<string, TransactionDefinition>>(definitions: D): D;
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Static parameterized operation-spec generation (issue #42, Phase 0b).
|
|
504
|
-
*
|
|
505
|
-
* Turns the parameterized definition IR (#41) into JSON-serializable
|
|
506
|
-
* {@link OperationSpec} / {@link CommandSpec} via **symbolic evaluation** of the
|
|
507
|
-
* key / GSI mapping functions. The result is deterministic and contains only
|
|
508
|
-
* `{param}` / `{result.field}` template placeholders, never concrete values.
|
|
509
|
-
*
|
|
510
|
-
* Relation chains in a read `select` become **multiple operations** wired with
|
|
511
|
-
* `resultPath` and `{result.*}` key templates, mirroring the runtime
|
|
512
|
-
* `relation-planner` policy: `hasMany` → `Query` + `begins_with`, `belongsTo` /
|
|
513
|
-
* `hasOne` → `BatchGetItem`.
|
|
514
|
-
*/
|
|
515
|
-
|
|
516
|
-
/** Build the {@link QuerySpec} for a single read definition. */
|
|
517
|
-
declare function buildQuerySpec(def: AnyOperationDefinition): QuerySpec;
|
|
518
|
-
/**
|
|
519
|
-
* Optional contract-layer inputs to {@link buildOperations} (issue #59). Both are
|
|
520
|
-
* absent on a pre-#59 (contract-free) build, in which case the produced document
|
|
521
|
-
* is byte-identical to the pre-#59 shape (no `contracts` / `contexts` keys).
|
|
522
|
-
*/
|
|
523
|
-
interface ContractInputs {
|
|
524
|
-
/** Resolved contracts (publicQueryModel / publicCommandModel output). */
|
|
525
|
-
readonly contracts?: ContractMap;
|
|
526
|
-
/** Context-ownership declarations (context → member models / contracts). */
|
|
527
|
-
readonly contexts?: ContextOwnershipMap;
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Build the operations document from grouped read (`queries`) and write
|
|
531
|
-
* (`commands`) definition maps, plus the optional CQRS contract layer (#59).
|
|
532
|
-
* All inputs are optional. Output is deterministic (definitions emitted in
|
|
533
|
-
* sorted-key order; the runtime resolves by name).
|
|
534
|
-
*
|
|
535
|
-
* The contract layer (#59) is layered **on top of** the existing specs: each
|
|
536
|
-
* contract method's underlying op is synthesized into `queries` / `commands` and
|
|
537
|
-
* referenced by name, and the `contracts` / `contexts` maps are emitted. A
|
|
538
|
-
* contract-free input (`contractInputs` empty / absent) reproduces the pre-#59
|
|
539
|
-
* document byte-for-byte — no `contracts` / `contexts` keys appear.
|
|
540
|
-
*
|
|
541
|
-
* @throws if a command carries a write condition outside the supported subset
|
|
542
|
-
* (`{ notExists }` or pure equality) — the bridge guard; or if a contract op
|
|
543
|
-
* name collides with a hand-written definition.
|
|
544
|
-
*/
|
|
545
|
-
declare function buildOperations(queries?: DefinitionMap, commands?: DefinitionMap, transactions?: Record<string, TransactionDefinition>, contractInputs?: ContractInputs): OperationsDocument;
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Manifest generation (issue #42, Python-bridge Phase 0b).
|
|
549
|
-
*
|
|
550
|
-
* Produces the JSON-serializable {@link Manifest} from a {@link MetadataRegistry}
|
|
551
|
-
* snapshot: entity → table / physicalName / prefix / field types / key & GSI
|
|
552
|
-
* templates / relation metadata. Generation is **deterministic** — entities,
|
|
553
|
-
* fields, GSIs, and relations are emitted in a stable (sorted) order so the same
|
|
554
|
-
* registry always yields byte-identical JSON.
|
|
555
|
-
*/
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Build the full {@link Manifest} from the {@link MetadataRegistry}.
|
|
559
|
-
*
|
|
560
|
-
* Every registered entity is included. Output ordering is deterministic
|
|
561
|
-
* (entities / fields / relations sorted by name, GSIs by index name).
|
|
562
|
-
*/
|
|
563
|
-
declare function buildManifest(registry?: typeof MetadataRegistry): Manifest;
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* N+1 static checker for the CQRS Contract layer (issue #60, Epic #57; proposal
|
|
567
|
-
* `docs/cqrs-contract.md`, "N+1 Safety (Static Restriction)").
|
|
568
|
-
*
|
|
569
|
-
* Whether a resolution is N+1-safe depends on **two** facts the planner already
|
|
570
|
-
* decided in #58 and #59 serialized into the SSoT — the checker **honors** them,
|
|
571
|
-
* it does **not** re-derive policy ("decide once, declare in the SSoT"):
|
|
572
|
-
*
|
|
573
|
-
* - `resolution` — `'point'` (target keys known → `BatchGetItem` / another
|
|
574
|
-
* contract's `get(keys[])`; coalesces) or `'range'` (target key set unknown →
|
|
575
|
-
* partition `Query`; one request per partition key).
|
|
576
|
-
* - `inputArity` / parent `cardinality` — how many keys are fed in. A `range`
|
|
577
|
-
* method is one query for one key but N queries for N keys.
|
|
578
|
-
*
|
|
579
|
-
* The rule (absolute, no opt-in escape hatch): **a `range` resolution is allowed
|
|
580
|
-
* only with single-key input.** Three forms are build-time errors:
|
|
581
|
-
*
|
|
582
|
-
* (a) **array into a `range` method** — a `range` method whose `inputArity` is
|
|
583
|
-
* not `'single'` (`'array'` / `'either'`). A `range` method must be
|
|
584
|
-
* `'single'`; anything else is an N partition-`Query` fan-out.
|
|
585
|
-
* (a′) **array into a unique-GSI `point` method** (issue #71) — a `point` method
|
|
586
|
-
* whose Key resolves via a **unique GSI** (a per-key `Query`, since
|
|
587
|
-
* `BatchGetItem` cannot read a GSI) but whose `inputArity` is not `'single'`.
|
|
588
|
-
* A base-table `point` coalesces a key array into one `BatchGetItem`, but a
|
|
589
|
-
* unique-GSI `point` would issue N `Query`s — an N+1 fan-out, the same shape
|
|
590
|
-
* as (a). graphddb's official spec does not include N+1-producing queries, so
|
|
591
|
-
* it is rejected at build time; the application-side loop is the escape (same
|
|
592
|
-
* philosophy as `range`).
|
|
593
|
-
* (b) **"list under a list"** — a `range` child nested under a parent step whose
|
|
594
|
-
* output cardinality is `'many'`. The composition's parent yields N records,
|
|
595
|
-
* so a `range` child fans out to N partition `Query`s.
|
|
596
|
-
* (c) **`compose` child that is `range`** — the cross-contract / composition form
|
|
597
|
-
* of (b): a composed (External Query) child declared `range` under a parent
|
|
598
|
-
* that can yield many. (Rule (b) and (c) are the same axis — a `range` child
|
|
599
|
-
* under a many-yielding parent — surfaced through nested model relations vs.
|
|
600
|
-
* cross-contract composition respectively.)
|
|
601
|
-
*
|
|
602
|
-
* `point` resolutions are always allowed (they coalesce). If a caller genuinely
|
|
603
|
-
* needs "just these few", it loops in its own application code (the proposal's
|
|
604
|
-
* `Promise.all(ids.map(...))`), keeping the N visible at the call site —
|
|
605
|
-
* the contract surface never hides a fan-out.
|
|
606
|
-
*
|
|
607
|
-
* ## Placement — build path, not the model `LintRule` framework
|
|
608
|
-
*
|
|
609
|
-
* This checker runs on the **contract build path** ({@link buildContracts} in
|
|
610
|
-
* `src/spec/contracts.ts`), where every other contract validation surfaces
|
|
611
|
-
* (#59's projection audit, write-condition guard, and the original inline
|
|
612
|
-
* `compose` rule all `throw` there). It operates on the serialized
|
|
613
|
-
* {@link ContractSpec} facts, not on {@link EntityMetadata}: the existing
|
|
614
|
-
* `src/linter/` `LintRule` framework is keyed on a single model's `EntityMetadata`
|
|
615
|
-
* (model relations / GSIs), which carries none of the contract `resolution` /
|
|
616
|
-
* `inputArity` / `compose` facts the N+1 rule needs. Surfacing the violation as a
|
|
617
|
-
* thrown build error — exactly as `relation/traversal.ts` `validateDepth` and the
|
|
618
|
-
* #59 contract validations do — fails the build the same way `inputArity`
|
|
619
|
-
* mismatches and `range` composed children already failed it.
|
|
620
|
-
*
|
|
621
|
-
* The cross-contract `range`-child form (c) and the nested-relation form (b) are
|
|
622
|
-
* only fully reachable once the composition DSL primitive
|
|
623
|
-
* (`query(Contract.method, { from() })`, owned by #63) lands; until then no #58
|
|
624
|
-
* DSL produces a `compose` node. The checker implements the full logic now so it
|
|
625
|
-
* is ready, and the forward forms are exercised by feeding synthesized SSoT nodes
|
|
626
|
-
* (exactly as #59's serializer tests do).
|
|
627
|
-
*/
|
|
628
|
-
|
|
629
|
-
/** A single N+1 rule violation, carrying the rule label and a clear message. */
|
|
630
|
-
interface ContractN1Violation {
|
|
631
|
-
/** Which of the N+1 forms was violated. */
|
|
632
|
-
readonly rule: 'array-into-range' | 'array-into-gsi-point' | 'list-under-list' | 'compose-range-under-many';
|
|
633
|
-
/** The offending contract name. */
|
|
634
|
-
readonly contract: string;
|
|
635
|
-
/** The offending method name. */
|
|
636
|
-
readonly method: string;
|
|
637
|
-
/** A clear, actionable error message (the same text the thrown error carries). */
|
|
638
|
-
readonly message: string;
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* Tells, for a query contract method name, whether its `point` read resolves via
|
|
642
|
-
* a **unique GSI** (a per-key `Query`) rather than the base-table primary key (a
|
|
643
|
-
* coalescible `GetItem` / `BatchGetItem`). Supplied by the serializer (issue #71),
|
|
644
|
-
* which recovers the fact from the method's synthesized read op (a root `Query`
|
|
645
|
-
* carrying an `indexName`). Absent → no method is treated as a GSI point (the
|
|
646
|
-
* pre-#71 default; e.g. synthesized-SSoT checker tests that exercise only the
|
|
647
|
-
* `range` / `compose` rules).
|
|
648
|
-
*/
|
|
649
|
-
type IsGsiPointMethod = (methodName: string) => boolean;
|
|
650
|
-
/**
|
|
651
|
-
* Collect every N+1 violation in a single serialized {@link ContractSpec}.
|
|
652
|
-
* Command contracts carry no `resolution` / `compose` and are always N+1-safe
|
|
653
|
-
* (writes resolve to known keys), so only query contracts are inspected.
|
|
654
|
-
*
|
|
655
|
-
* @param isGsiPoint Optional predicate (issue #71): does the named method's
|
|
656
|
-
* `point` read resolve via a unique GSI? Used to reject array-into-GSI-point
|
|
657
|
-
* (rule a′). Defaults to "never" when not supplied.
|
|
658
|
-
*/
|
|
659
|
-
declare function collectContractN1Violations(contractName: string, spec: ContractSpec, isGsiPoint?: IsGsiPointMethod): ContractN1Violation[];
|
|
660
|
-
/**
|
|
661
|
-
* Assert a single serialized contract is N+1-safe, throwing the first violation
|
|
662
|
-
* as a build error (mirroring `relation/traversal.ts` `validateDepth` and the
|
|
663
|
-
* #59 contract validations, which `throw` on the build path). Multiple violations
|
|
664
|
-
* are summarized in the thrown message so the build surfaces them all at once.
|
|
665
|
-
*
|
|
666
|
-
* @throws if any of the N+1 forms is present.
|
|
667
|
-
*
|
|
668
|
-
* @param isGsiPoint Optional predicate (issue #71) identifying unique-GSI `point`
|
|
669
|
-
* methods, so rule (a′) (array into a GSI point) can be enforced.
|
|
670
|
-
*/
|
|
671
|
-
declare function assertContractN1Safe(contractName: string, spec: ContractSpec, isGsiPoint?: IsGsiPointMethod): void;
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Bounded-context boundary checker for the CQRS Contract layer (issue #61, Epic
|
|
675
|
-
* #57; spec `docs/cqrs-contract.md`, External Query section "Why it
|
|
676
|
-
* exists: boundary enforcement").
|
|
677
|
-
*
|
|
678
|
-
* The rule, stated in the proposal and the issue: a **Model is a private
|
|
679
|
-
* implementation detail of its bounded context; a Contract is the published
|
|
680
|
-
* interface**. Within its own context a contract resolves its own Models directly
|
|
681
|
-
* (internal `query` / `list` / `put` / `update` / `delete`). Across a context
|
|
682
|
-
* boundary it may depend on another context **only through that context's
|
|
683
|
-
* published Contract** (an External Query / Command). Reaching directly into a
|
|
684
|
-
* **foreign** Model is a **build-time error** — it couples one context to
|
|
685
|
-
* another's private storage shape and silently defeats the boundary the contexts
|
|
686
|
-
* declaration is meant to enforce.
|
|
687
|
-
*
|
|
688
|
-
* ## What "own" vs. "foreign" means here
|
|
689
|
-
*
|
|
690
|
-
* The decision is made entirely from the **context-ownership declaration** (#59,
|
|
691
|
-
* the `contexts` map: context name → `{ models, contracts }`). For each contract:
|
|
692
|
-
*
|
|
693
|
-
* - its **owning context** is the (unique) context whose `contracts` list names
|
|
694
|
-
* it; and
|
|
695
|
-
* - for every Model its method ops touch (the recorded {@link ContractMethodOp}
|
|
696
|
-
* `entity` refs, #58), that Model's **owning context** is the context whose
|
|
697
|
-
* `models` list names it.
|
|
698
|
-
*
|
|
699
|
-
* A method op against a Model owned by a **different** context than the contract's
|
|
700
|
-
* own is the violation. Three cases are deliberately **allowed**, never flagged:
|
|
701
|
-
*
|
|
702
|
-
* - the Model and the contract are in the **same** context (the normal internal
|
|
703
|
-
* case);
|
|
704
|
-
* - the **contract is in no declared context** — there is no boundary to enforce
|
|
705
|
-
* *from*, so the contract is unconstrained (a partial / incremental adoption of
|
|
706
|
-
* the contexts declaration must not turn unrelated contracts into errors);
|
|
707
|
-
* - the touched **Model is in no declared context** — an undeclared Model has no
|
|
708
|
-
* owner to protect, so it is not "foreign" to anyone. (Declaring the Model into
|
|
709
|
-
* a context is what opts it into boundary protection.)
|
|
710
|
-
*
|
|
711
|
-
* In short: the check fires **only** when both the contract *and* the foreign
|
|
712
|
-
* Model have declared, *different* owners. This is the least-surprising reading of
|
|
713
|
-
* a *partial* contexts declaration and keeps the rule purely additive — declaring
|
|
714
|
-
* more ownership can only ever surface *more* violations, never fewer.
|
|
715
|
-
*
|
|
716
|
-
* ## Placement — build path, not the model `LintRule` framework (decision B)
|
|
717
|
-
*
|
|
718
|
-
* This checker runs in **{@link buildOperations}** (`src/spec/operations.ts`),
|
|
719
|
-
* immediately before the {@link buildContracts} call — the seam where both the
|
|
720
|
-
* raw contract IR (the recorded op `entity` refs) and the `contexts` map are
|
|
721
|
-
* still available, alongside #59's projection audit, the write-condition guard,
|
|
722
|
-
* and #60's N+1 checker — every contract validation surfaces there as a thrown
|
|
723
|
-
* build error. It is **not** added to the `src/linter/` `LintRule`
|
|
724
|
-
* framework, even though the issue text suggests a `context-boundary` rule there,
|
|
725
|
-
* because that framework's contract — `check(metadata: EntityMetadata, registry)`
|
|
726
|
-
* — is keyed on a **single model's** {@link EntityMetadata} and carries **none** of
|
|
727
|
-
* the facts this rule needs:
|
|
728
|
-
*
|
|
729
|
-
* - which context a *contract* belongs to (a contract is not an `EntityMetadata`);
|
|
730
|
-
* - which Models a contract's *methods* touch (these live on the unserialized
|
|
731
|
-
* {@link ContractMethodOp} `entity` refs, not on any model's metadata);
|
|
732
|
-
* - the cross-cutting `contexts` map relating the two.
|
|
733
|
-
*
|
|
734
|
-
* A `LintRule` sees one model at a time and no contract facts at all, so a naive
|
|
735
|
-
* rule physically cannot observe a contract→foreign-Model reference. Bending the
|
|
736
|
-
* framework to carry contracts + contexts would be an invasive, parallel
|
|
737
|
-
* "rule kind" that no other rule uses — exactly the ugly refactor the brief warns
|
|
738
|
-
* against. Placing the check here is consistent with how #60 already resolved the
|
|
739
|
-
* identical tension (`src/spec/contract-n1-check.ts`, "Placement"), and it reads
|
|
740
|
-
* the **same facts the rule actually depends on** at the one point where contracts
|
|
741
|
-
* and contexts are both in hand. The boundary violation fails the build the same
|
|
742
|
-
* way an `inputArity` mismatch or a `range` composed child already does.
|
|
743
|
-
*/
|
|
744
|
-
|
|
745
|
-
/** A single context-boundary violation, carrying the offending facts + message. */
|
|
746
|
-
interface ContractBoundaryViolation {
|
|
747
|
-
/** The offending contract name. */
|
|
748
|
-
readonly contract: string;
|
|
749
|
-
/** The context that owns the offending contract. */
|
|
750
|
-
readonly contractContext: string;
|
|
751
|
-
/** The contract method whose op touched the foreign Model. */
|
|
752
|
-
readonly method: string;
|
|
753
|
-
/** The foreign Model (entity / model-class name) referenced directly. */
|
|
754
|
-
readonly foreignModel: string;
|
|
755
|
-
/** The context that owns the foreign Model. */
|
|
756
|
-
readonly foreignContext: string;
|
|
757
|
-
/** A clear, actionable error message (the same text the thrown error carries). */
|
|
758
|
-
readonly message: string;
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Collect every context-boundary violation across a map of resolved contracts,
|
|
762
|
-
* given the context-ownership declaration. A violation is a contract method whose
|
|
763
|
-
* recorded op touches a Model owned by a **different** context than the contract's
|
|
764
|
-
* own (see the module doc for the precise own / foreign / undeclared rule).
|
|
765
|
-
*
|
|
766
|
-
* @param contracts Contract name → resolved {@link QueryModelContract} /
|
|
767
|
-
* {@link CommandModelContract} (the #58 factory output).
|
|
768
|
-
* @param contexts The context-ownership declaration (#59). When empty, no
|
|
769
|
-
* contract has a declared owner, so there are no boundaries to enforce → no
|
|
770
|
-
* violations.
|
|
771
|
-
* @throws if the contexts declaration claims a Model / Contract in two contexts
|
|
772
|
-
* (an ambiguous, self-contradictory declaration).
|
|
773
|
-
*/
|
|
774
|
-
declare function collectContractBoundaryViolations(contracts: ContractMap, contexts: ContextOwnershipMap): ContractBoundaryViolation[];
|
|
775
|
-
/**
|
|
776
|
-
* Assert a map of resolved contracts respects bounded-context boundaries, throwing
|
|
777
|
-
* the first violation as a build error (mirroring #60's {@link assertContractN1Safe}
|
|
778
|
-
* and the other #59 contract validations, which `throw` on the build path).
|
|
779
|
-
* Multiple violations are summarized in the thrown message so the build surfaces
|
|
780
|
-
* them all at once.
|
|
781
|
-
*
|
|
782
|
-
* @param contracts Contract name → resolved contract IR.
|
|
783
|
-
* @param contexts The context-ownership declaration (#59).
|
|
784
|
-
* @throws if any contract directly references a foreign context's Model, or if the
|
|
785
|
-
* contexts declaration is ambiguous (a Model / Contract claimed twice).
|
|
786
|
-
*/
|
|
787
|
-
declare function assertContractBoundaries(contracts: ContractMap, contexts: ContextOwnershipMap): void;
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* Static planning for declarative transactions (issue #46, Phase 4).
|
|
791
|
-
*
|
|
792
|
-
* Turns a {@link TransactionDefinition} (captured by `defineTransaction`) into a
|
|
793
|
-
* serializable {@link TransactionSpec}. Each `tx.put/update/delete` becomes a
|
|
794
|
-
* templated {@link TransactionItemSpec}; a `tx.forEach` block marks its items
|
|
795
|
-
* with a `forEach` binding so the runtime expands them once per array-param
|
|
796
|
-
* element. Key templates are derived with the **same** symbolic key-mapping
|
|
797
|
-
* evaluator (#42 `evaluateKey`) the single-write planner uses — the
|
|
798
|
-
* declarativity of the field references is what lets that reuse work: every
|
|
799
|
-
* key / item / changes leaf is either a field reference (whose token the planner
|
|
800
|
-
* substitutes) or a concrete literal.
|
|
801
|
-
*/
|
|
802
|
-
|
|
803
|
-
/** Build the {@link TransactionSpec} for one transaction definition. */
|
|
804
|
-
declare function buildTransactionSpec(txName: string, def: TransactionDefinition): TransactionSpec;
|
|
805
|
-
/** Build the transactions map from a record of transaction definitions. */
|
|
806
|
-
declare function buildTransactions(transactions?: Record<string, TransactionDefinition>): Record<string, TransactionSpec>;
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Bridge guard (issue #42, Phase 0b).
|
|
810
|
-
*
|
|
811
|
-
* The Python bridge can only carry a **declarative, serializable subset** of
|
|
812
|
-
* graphddb. This module enforces that subset at build time:
|
|
813
|
-
*
|
|
814
|
-
* 1. **Write conditions** must be `{ notExists }`, an existence primitive
|
|
815
|
-
* (`{ attributeExists }` / `{ attributeNotExists }` on any field, issue #81),
|
|
816
|
-
* *or* pure field equality (mirroring `expression/condition-expression.ts`,
|
|
817
|
-
* which only emits `attribute_(not_)exists(...)` or `#f = :v` clauses). Any
|
|
818
|
-
* other condition shape is rejected — there is no serializable representation
|
|
819
|
-
* for it. {@link conditionInputToSpec} is the single place the IR-shaped input
|
|
820
|
-
* is mapped to the {@link ConditionSpec} subset.
|
|
821
|
-
* 2. The produced bundle must be **JSON-serializable** — no functions, classes,
|
|
822
|
-
* `Date`, `Set`, `Map`, `Symbol`, or non-finite numbers may leak into the
|
|
823
|
-
* spec. {@link assertJsonSerializable} walks the value and throws on any.
|
|
824
|
-
*
|
|
825
|
-
* (Note: the post-load TS predicate `refine` was removed in #49, so no guard for
|
|
826
|
-
* it is needed; see `docs/python-bridge.md`.)
|
|
827
|
-
*/
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Assert a write {@link ConditionSpec} is within the supported subset. The spec
|
|
831
|
-
* type already constrains it to `notExists` | `attributeExists` |
|
|
832
|
-
* `attributeNotExists` | `equals`, so this defends against a malformed `equals`
|
|
833
|
-
* (empty / non-template values) or a blank existence field and gives a clear,
|
|
834
|
-
* single-source build-time error message for any future widening.
|
|
835
|
-
*/
|
|
836
|
-
declare function assertSupportedCondition(commandName: string, condition: ConditionSpec): void;
|
|
837
|
-
/**
|
|
838
|
-
* Walk an arbitrary value and throw if it contains anything that does not
|
|
839
|
-
* survive `JSON.stringify` round-tripping as itself (functions, symbols,
|
|
840
|
-
* `undefined`, `Date`, `Map`, `Set`, class instances, non-finite numbers).
|
|
841
|
-
*/
|
|
842
|
-
declare function assertJsonSerializable(value: unknown, path?: string): void;
|
|
843
|
-
/** Convenience: assert an entire {@link BridgeBundle} is JSON-serializable. */
|
|
844
|
-
declare function assertBundleSerializable(bundle: BridgeBundle): void;
|
|
845
|
-
|
|
846
|
-
/**
|
|
847
|
-
* Static prepared-plan artifact — the **build-time** (AOT) compilation of
|
|
848
|
-
* `DDBModel.prepare` bodies (issue #208; design #203 phase 4, on top of the #205
|
|
849
|
-
* runtime and the #206 compile-time hoist).
|
|
850
|
-
*
|
|
851
|
-
* `graphddb transform prepared --aot` evaluates each no-capture-verified prepare
|
|
852
|
-
* body at BUILD time (the #206 lint proves build-time evaluability) and this
|
|
853
|
-
* module compiles the evaluated routes into a JSON-serializable
|
|
854
|
-
* {@link PreparedPlanDocument}:
|
|
855
|
-
*
|
|
856
|
-
* - a **write** plan runs the SAME mutation compiler the runtime `prepare` uses
|
|
857
|
-
* (`compileWriteFragment` → lifecycle resolution → derived-effect derivation)
|
|
858
|
-
* and serializes the result through the SAME contract-SSoT path a
|
|
859
|
-
* `.plan(mutation)` command method uses
|
|
860
|
-
* ({@link serializePreparedWriteFragment} → one declarative
|
|
861
|
-
* {@link TransactionSpec} per op: base write + edges / counters / uniqueness
|
|
862
|
-
* guards / outbox / idempotency / maintenance / ConditionChecks) — so the
|
|
863
|
-
* runtime never invokes the mutation compiler again, **including the first
|
|
864
|
-
* call** (the #206 audit's cold-start gap);
|
|
865
|
-
* - a **read** plan serializes the analyzed route products (entity name, select
|
|
866
|
-
* template, per-field param binds, static/dynamic options) plus the
|
|
867
|
-
* {@link QuerySpec} the spec planner derives for it — the same
|
|
868
|
-
* `operations.json` vocabulary the Python runtime consumes (templated
|
|
869
|
-
* `{param}` key conditions, physical ops, execution plan), so a broken read
|
|
870
|
-
* plan fails the BUILD, not the first request.
|
|
871
|
-
*
|
|
872
|
-
* ## Model references are entity NAMES
|
|
873
|
-
*
|
|
874
|
-
* The artifact never carries a class: each plan records the entity names it
|
|
875
|
-
* touches plus a **fingerprint** of each entity's canonical manifest entry
|
|
876
|
-
* ({@link entityFingerprint}). The TS loader (`src/runtime/prepared-loader.ts`)
|
|
877
|
-
* re-binds names against the live {@link MetadataRegistry} and recomputes the
|
|
878
|
-
* fingerprints — a mismatch (model declaration / TableMapping drift since the
|
|
879
|
-
* artifact was generated) is a LOUD reject, never a stale-plan execution.
|
|
880
|
-
*
|
|
881
|
-
* Everything emitted is JSON-serializable by construction (the #206 no-capture
|
|
882
|
-
* lint guarantees the body's templates are static data; the only non-JSON
|
|
883
|
-
* scalars a template may carry — `Date` / `bigint` literals — are encoded
|
|
884
|
-
* explicitly in {@link PreparedBindSpec}).
|
|
885
|
-
*
|
|
886
|
-
* ## Layering (#223)
|
|
887
|
-
*
|
|
888
|
-
* This module is BUILD-TIME ONLY. The artifact shapes, the format version, and
|
|
889
|
-
* the fingerprint/canonical-JSON helpers the runtime loader also needs live in
|
|
890
|
-
* the shared, dependency-minimal `./prepared-artifact.ts` — both this emitter
|
|
891
|
-
* and the loader (`src/runtime/prepared-loader.ts`) depend on that module, and
|
|
892
|
-
* the loader NEVER imports this one (a loader→emitter import leaks the whole
|
|
893
|
-
* build-time spec machinery into the runtime bundle — the #223 size-limit
|
|
894
|
-
* failure). The shared symbols are re-exported here for API continuity.
|
|
895
|
-
*/
|
|
896
|
-
|
|
897
|
-
/**
|
|
898
|
-
* Compile ONE `DDBModel.prepare` body into its static {@link PreparedPlanSpec}
|
|
899
|
-
* (build-time). The body is evaluated once with the recording `$` proxy — the
|
|
900
|
-
* #206 no-capture lint has already proven this is side-effect-free and
|
|
901
|
-
* params-independent — then each route is analyzed and serialized.
|
|
902
|
-
*
|
|
903
|
-
* @param body The prepare body function (as extracted by the transform).
|
|
904
|
-
* @param planLabel A human-readable label woven into build errors (the plan id).
|
|
905
|
-
*/
|
|
906
|
-
declare function compilePreparedPlan(body: PreparedBody, planLabel?: string): PreparedPlanSpec;
|
|
907
|
-
/** Assemble the full artifact document from compiled plans. */
|
|
908
|
-
declare function buildPreparedPlanDocument(plans: Readonly<Record<string, PreparedPlanSpec>>): PreparedPlanDocument;
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* Static parameterized planner: serializable OperationSpec + manifest + bridge
|
|
912
|
-
* guard (issue #42, Python-bridge Phase 0b). Public surface.
|
|
913
|
-
*
|
|
914
|
-
* The CLI / file output is #43's responsibility; this module stops at the
|
|
915
|
-
* **generation functions** producing the typed, JSON-serializable
|
|
916
|
-
* `{ manifest, operations }` bundle.
|
|
917
|
-
*/
|
|
918
|
-
|
|
919
|
-
/**
|
|
920
|
-
* Build the full `{ manifest, operations }` bridge bundle from grouped query /
|
|
921
|
-
* command definition maps. The bundle is typed and JSON-serializable; the bridge
|
|
922
|
-
* guard runs (unsupported write conditions throw during `buildOperations`, and
|
|
923
|
-
* the whole bundle is asserted JSON-serializable here).
|
|
924
|
-
*
|
|
925
|
-
* @param queries Read definitions (`defineQueries(...)` output). Optional.
|
|
926
|
-
* @param commands Write definitions (`defineCommands(...)` output). Optional.
|
|
927
|
-
* @param registry Metadata source (defaults to the global registry).
|
|
928
|
-
* @param transactions Declarative transactions (`defineTransactions(...)`). Optional.
|
|
929
|
-
* @param contractInputs The CQRS contract layer (#59): resolved contracts +
|
|
930
|
-
* context-ownership. Optional — absent reproduces the pre-#59 document.
|
|
931
|
-
*/
|
|
932
|
-
declare function buildBridgeBundle(queries?: DefinitionMap, commands?: DefinitionMap, registry?: typeof MetadataRegistry, transactions?: Record<string, TransactionDefinition>, contractInputs?: ContractInputs): BridgeBundle;
|
|
933
|
-
|
|
934
|
-
export { type AnyModelContract as A, type BuiltContracts as B, type ContextOwnership as C, buildManifest as D, buildOperations as E, buildQuerySpec as F, buildTransactionSpec as G, buildTransactions as H, collectContractBoundaryViolations as I, collectContractN1Violations as J, defineTransaction as K, defineTransactions as L, isTransactionRef as M, when as N, PREPARED_FORMAT_VERSION as O, type PreparedWriteOpSpec as P, type PreparedBindMap as Q, buildPreparedPlanDocument as R, canonicalJson as S, type TransactionDefinition as T, compilePreparedPlan as U, entityFingerprint as V, type WhenComparison as W, planFingerprint as X, type PreparedPlanDocument as a, type ContextOwnershipMap as b, type ContractBoundaryViolation as c, type ContractInputs as d, type ContractMap as e, type ContractN1Violation as f, type PreparedBindSpec as g, type PreparedPlanSpec as h, type PreparedReadRouteSpec as i, type TransactionParamShape as j, type TransactionRef as k, type TxConditionCheckOptions as l, type TxForEachInstruction as m, type TxForEachOptions as n, type TxInstruction as o, type TxRecorder as p, type TxWriteInstruction as q, type TxWriteOptions as r, assertBundleSerializable as s, assertContractBoundaries as t, assertContractN1Safe as u, assertJsonSerializable as v, assertSupportedCondition as w, buildBridgeBundle as x, buildContexts as y, buildContracts as z };
|