graphddb 0.7.10 → 0.8.1

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.
Files changed (46) hide show
  1. package/README.md +6 -6
  2. package/dist/cdc/index.d.ts +389 -5
  3. package/dist/cdc/index.js +4 -4
  4. package/dist/{chunk-AD6ZQTTE.js → chunk-GS4C5VGO.js} +2 -6
  5. package/dist/{chunk-DFUKGU2Q.js → chunk-HNY2EJPV.js} +216 -229
  6. package/dist/{chunk-3ZU2VW3L.js → chunk-L2NEDS7U.js} +582 -781
  7. package/dist/chunk-L4QRCHRQ.js +278 -0
  8. package/dist/chunk-LAT64YCZ.js +1987 -0
  9. package/dist/chunk-S2NI4PBW.js +187 -0
  10. package/dist/{chunk-EOJDN3SA.js → chunk-T44OB5GU.js} +3757 -6138
  11. package/dist/{chunk-PDUVTYC5.js → chunk-XTWXMOHD.js} +0 -1
  12. package/dist/cli.js +63 -254
  13. package/dist/index.d.ts +23 -1550
  14. package/dist/index.js +94 -1850
  15. package/dist/internal/index.d.ts +84 -0
  16. package/dist/internal/index.js +701 -0
  17. package/dist/{maintenance-view-adapter-BAZ9uBGe.d.ts → key-DZtjAQDh.d.ts} +573 -1817
  18. package/dist/linter/index.d.ts +39 -7
  19. package/dist/linter/index.js +22 -4
  20. package/dist/{registry-LWE54Sdc.d.ts → linter-DQY7gUEk.d.ts} +22 -22
  21. package/dist/prepared-artifact-HFealr1q.d.ts +281 -0
  22. package/dist/spec/index.d.ts +506 -5
  23. package/dist/spec/index.js +22 -18
  24. package/dist/testing/index.d.ts +2 -3
  25. package/dist/testing/index.js +4 -4
  26. package/dist/transform/index.d.ts +1 -1
  27. package/dist/transform/index.js +4 -4
  28. package/dist/{types-BQLzTEqh.d.ts → types-2PMXEn5x.d.ts} +8 -10
  29. package/dist/types-DW__-Icc.d.ts +450 -0
  30. package/docs/cdc-projection.md +5 -5
  31. package/docs/class-hydration.md +1 -1
  32. package/docs/cqrs-contract.md +79 -20
  33. package/docs/design-patterns.md +5 -5
  34. package/docs/docs-generation.md +6 -6
  35. package/docs/middleware.md +15 -15
  36. package/docs/mutation-command-derivation.md +52 -42
  37. package/docs/prepared-statements.md +14 -14
  38. package/docs/python-bridge.md +96 -65
  39. package/docs/spec.md +153 -124
  40. package/docs/testing.md +9 -8
  41. package/package.json +14 -4
  42. package/dist/chunk-3UD3XIF2.js +0 -860
  43. package/dist/chunk-MMVHOUM4.js +0 -24
  44. package/dist/from-change-Ty95KA8C.d.ts +0 -327
  45. package/dist/index-Dc7d8mWI.d.ts +0 -1089
  46. package/dist/relation-depth-BRS513Tq.d.ts +0 -36
@@ -33,7 +33,7 @@ access patterns that TypeScript has already defined and validated.
33
33
  ```text
34
34
  TypeScript (design-time / build-time SSoT)
35
35
  ├─ Entity / Key / GSI / Relation models
36
- ├─ Parameterized query / command definitions (param + define*)
36
+ ├─ Parameterized query / command contracts (param + graphddb.publish*)
37
37
  ├─ Static parameterized planner (symbolic key evaluation)
38
38
  ├─ Bridge guard (reject non-declarative / non-serializable specs)
39
39
  └─ Bridge bundle: manifest.json + operations.json
@@ -51,7 +51,7 @@ boto3 DynamoDB client
51
51
  | Layer | Responsibility |
52
52
  |---|---|
53
53
  | TypeScript model | Entity / key / GSI / relation definitions |
54
- | Definition DSL (`param`, `define*`) | The permitted, parameterized queries and commands |
54
+ | Contract DSL (`param`, `graphddb.publish*`) | The permitted, parameterized queries and commands |
55
55
  | Static planner (`src/spec/*`) | Symbolic key evaluation → `manifest.json` / `operations.json` |
56
56
  | Generator (`src/codegen/python.ts`, `src/cli/*`) | Python repositories, result types, package exports |
57
57
  | Python repository | Stable application-facing interface |
@@ -69,68 +69,96 @@ runtime descriptor (`kind`, optional `literals`, optional element shape) that
69
69
  the planner and generator read. `param.literal('active', 'disabled')` has value
70
70
  type `'active' | 'disabled'`; the literal set is preserved in the spec.
71
71
 
72
- Parameters are legal only inside the structures passed to the `define*` entry
73
- points — never to the live `Model.query` / `Model.putItem` runtime API, whose types
74
- remain free of parameter placeholders.
72
+ Parameters are legal only inside the structures passed to the contract authoring
73
+ entry points (`graphddb.publishQuery` / `graphddb.publishCommand`) never to the
74
+ live `Model.query` / `Model.putItem` runtime API, whose types remain free of
75
+ parameter placeholders.
75
76
 
76
- ### 3.2 Definition Entry Points
77
+ ### 3.2 Contract Authoring Entry Points
77
78
 
78
- Definitions are built with dedicated entry points, each accepting `param`
79
+ Public reads and writes are authored through the CQRS contract layer, the sole
80
+ read/write authoring surface. Import the `graphddb` namespace and publish keyed
81
+ contracts whose methods are declarative descriptors, each accepting `param`
79
82
  placeholders at scalar leaves while checking field names, value types, the key
80
83
  boundary, and the strict select against the model:
81
84
 
82
- - `defineQuery(Model, key, select)` — single-item read (unique key).
83
- - `defineList(Model, key, select)` partition read (partial / partition key).
84
- - `definePut(Model, item, options?)` — put.
85
- - `defineUpdate(Model, key, changes, options?)` — update.
86
- - `defineDelete(Model, key, options?)` — delete.
85
+ ```ts
86
+ import { graphddb, param } from 'graphddb';
87
+ ```
87
88
 
88
- Write entry points accept an optional `{ condition }` (see §6.2). Each entry
89
- point collects its placeholders into a `name → ParamDescriptor` map; a parameter
90
- name used twice with conflicting types is rejected at definition time.
89
+ - `graphddb.publishQuery({ name: { get: { query: Model, key, select } } })`
90
+ single-item read (unique key).
91
+ - `graphddb.publishQuery({ name: { list: { list: Model, key, select } } })` —
92
+ partition read (partial / partition key).
93
+ - `graphddb.publishCommand({ name: { create: Model, key, input } })` — put.
94
+ - `graphddb.publishCommand({ name: { update: Model, key, input } })` — update.
95
+ - `graphddb.publishCommand({ name: { remove: Model, key } })` — delete.
91
96
 
92
- > Design note: the entry points are dedicated functions (not `Model.query(...)`
93
- > overloads) so that the live runtime model API is never widened to accept
94
- > parameter placeholders.
97
+ A command method descriptor accepts an optional `condition` (see §6.2) and an
98
+ optional `result: { select }` read-back projection. Each published contract
99
+ collects its placeholders into a `name → ParamDescriptor` map; a parameter name
100
+ used twice with conflicting types is rejected at definition time.
101
+
102
+ > Design note: the authoring surface is `graphddb.publishQuery` /
103
+ > `graphddb.publishCommand` (not `Model.query(...)` overloads), so the live
104
+ > runtime model API is never widened to accept parameter placeholders.
95
105
 
96
106
  ### 3.3 Grouping
97
107
 
98
- `defineQueries({ ... })` groups read definitions (`defineQuery` / `defineList`);
99
- `defineCommands({ ... })` groups write definitions (`definePut` / `defineUpdate`
100
- / `defineDelete`). Each validates that every entry is the correct operation kind
101
- and returns the typed record that the planner consumes. `defineTransactions({
102
- ... })` groups declarative transactions (see §6.3).
108
+ `graphddb.publishQuery({ ... })` publishes a keyed read contract whose methods
109
+ resolve to `get` / `list` descriptors; `graphddb.publishCommand({ ... })`
110
+ publishes a keyed write contract whose methods resolve to `create` / `update` /
111
+ `remove` descriptors. Each validates that every method is the correct operation
112
+ kind and returns the typed contract that the planner consumes. Atomic multi-op
113
+ writes are declared with a `mode: 'transaction'` descriptor and compile to a
114
+ declarative `TransactionSpec` (see §6.3).
103
115
 
104
116
  ```ts
105
- export const queries = defineQueries({
106
- getUserByEmail: defineQuery(
107
- User,
108
- { email: param.string() },
109
- { userId: true, name: true, email: true, status: true },
110
- ),
111
- listGroupMembers: defineList(
112
- GroupMembership,
113
- { groupId: param.string() },
114
- { userId: true, role: true, joinedAt: true },
115
- ),
117
+ import { graphddb, param } from 'graphddb';
118
+
119
+ export const UserByEmail = graphddb.publishQuery({
120
+ get: {
121
+ query: User,
122
+ key: { email: param.string() },
123
+ select: { userId: true, name: true, email: true, status: true },
124
+ },
125
+ });
126
+
127
+ export const MembersByGroup = graphddb.publishQuery({
128
+ list: {
129
+ list: GroupMembership,
130
+ key: { groupId: param.string() },
131
+ select: { userId: true, role: true, joinedAt: true },
132
+ },
133
+ });
134
+
135
+ export const MembershipCommands = graphddb.publishCommand({
136
+ addGroupMember: {
137
+ create: GroupMembership,
138
+ key: { groupId: param.string(), userId: param.string() },
139
+ input: { role: param.string() },
140
+ },
141
+ deleteGroupMember: {
142
+ remove: GroupMembership,
143
+ key: { groupId: param.string(), userId: param.string() },
144
+ },
116
145
  });
117
146
 
118
- export const commands = defineCommands({
119
- addGroupMember: definePut(GroupMembership, {
120
- groupId: param.string(),
121
- userId: param.string(),
122
- role: param.string(),
123
- }),
124
- disableUser: defineUpdate(
125
- User,
126
- { userId: param.string() },
127
- { status: param.literal('disabled') },
128
- ),
129
- deleteGroupMember: defineDelete(GroupMembership, {
130
- groupId: param.string(),
131
- userId: param.string(),
132
- }),
147
+ export const UserCommands = graphddb.publishCommand({
148
+ disableUser: {
149
+ update: User,
150
+ key: { userId: param.string() },
151
+ input: { status: param.literal('disabled') },
152
+ },
133
153
  });
154
+
155
+ // The `contracts` map the generator consumes (see §5).
156
+ export const contracts = {
157
+ UserByEmail,
158
+ MembersByGroup,
159
+ MembershipCommands,
160
+ UserCommands,
161
+ };
134
162
  ```
135
163
 
136
164
  ## 4. The Bridge Bundle
@@ -330,20 +358,17 @@ GSI-keyed write is rejected by the planner.
330
358
  ```bash
331
359
  graphddb generate python \
332
360
  --entry src/models/index.ts \
333
- --queries src/models/queries.ts \
334
- --commands src/models/commands.ts \
361
+ --contracts src/models/contracts.ts \
335
362
  --out generated/graphddb
336
363
  ```
337
364
 
338
365
  | Flag | Required | Default | Meaning |
339
366
  |---|---|---|---|
340
- | `--entry`, `-e` | yes | — | Module that registers entity models (imported for side effects); may also export the definition maps. |
367
+ | `--entry`, `-e` | yes | — | Module that registers entity models (imported for side effects); may also export `contracts` / `contexts` / `transactions`. |
341
368
  | `--out`, `-o` | yes | — | Output directory (created if absent). |
342
- | `--queries`, `-q` | no | `--entry` | Module exporting `queries`. |
343
- | `--commands`, `-c` | no | `--entry` | Module exporting `commands`. |
344
- | `--transactions`, `-t` | no | `--commands` then `--entry` | Module exporting `transactions`. |
345
- | `--contracts` | no | `--entry` | Module exporting CQRS `contracts`. |
369
+ | `--contracts` | no | `--entry` | Module exporting the CQRS `contracts` map (`graphddb.publishQuery` / `graphddb.publishCommand` results). |
346
370
  | `--contexts` | no | `--contracts` then `--entry` | Module exporting context ownership. |
371
+ | `--transactions`, `-t` | no | `--entry` | Module exporting `transactions`. |
347
372
  | `--dataclass` | no | `false` | Emit `@dataclass` result types instead of `TypedDict`. |
348
373
 
349
374
  TypeScript definition modules are transpiled on the fly (via tsx/esbuild — the
@@ -455,15 +480,21 @@ the serialized `expr` tree). (Per-item conditions are not available on
455
480
 
456
481
  ### 6.3 Transactions (declarative subset)
457
482
 
458
- `defineTransaction` records a declarative transaction whose body may only call
459
- `tx.put` / `tx.update` / `tx.delete` with field references or literals at scalar
460
- leaves, iterate an array parameter with `tx.forEach(p.<arrayParam>, ...)`, and
461
- attach a declarative `when` comparison (`eq` / `ne`) and/or a supported
462
- `condition`. The planner emits a `TransactionSpec` whose `items` carry rendered
463
- templates (`{param}`, `{item.field}` for `forEach` elements), optional
464
- `condition`, optional `when`, and optional `forEach: { source }`. A transaction
465
- with no `forEach` is rejected at build time if it exceeds 25 items; with
466
- `forEach`, the 25-item limit is enforced by the runtime after expansion.
483
+ An atomic multi-op write — a `mode: 'transaction'` command descriptor, or the
484
+ derived effects of any command (edges, counters, uniqueness guards, outbox,
485
+ idempotency, maintenance writes) compiles to a declarative `TransactionSpec`.
486
+ Its `items` write with field references or literals at scalar leaves; a bulk
487
+ `key: K[]` command lowers to a single `forEach`-over-keys item; and each item may
488
+ carry a declarative `when` comparison (`eq` / `ne`) and/or a supported
489
+ `condition`. The `TransactionSpec` `items` carry rendered templates (`{param}`,
490
+ `{item.field}` for `forEach` elements), optional `condition`, optional `when`, and
491
+ optional `forEach: { source }`. A transaction with no `forEach` is rejected at
492
+ build time if it exceeds 25 items; with `forEach`, the 25-item limit is enforced
493
+ by the runtime after expansion.
494
+
495
+ (The internal declarative-transaction recorder that produces this IR is the
496
+ `publishCommand` / `mutate` compile backend and the `graphddb transform`
497
+ lowering target — it is not a public authoring verb.)
467
498
 
468
499
  ## 7. The Python Runtime (`graphddb_runtime`)
469
500