@sequenceholdings/orm 2.0.0 → 2.1.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 (69) hide show
  1. package/README.md +94 -2
  2. package/dist/authoring.cjs +1474 -54
  3. package/dist/authoring.cjs.map +1 -1
  4. package/dist/authoring.d.cts +242 -4
  5. package/dist/authoring.d.ts +242 -4
  6. package/dist/authoring.js +1465 -56
  7. package/dist/authoring.js.map +1 -1
  8. package/dist/canonical.cjs +740 -42
  9. package/dist/canonical.cjs.map +1 -1
  10. package/dist/canonical.d.cts +742 -53
  11. package/dist/canonical.d.ts +742 -53
  12. package/dist/canonical.js +724 -43
  13. package/dist/canonical.js.map +1 -1
  14. package/dist/cli.cjs +2478 -328
  15. package/dist/cli.cjs.map +1 -1
  16. package/dist/cli.js +2480 -330
  17. package/dist/cli.js.map +1 -1
  18. package/dist/client.cjs +90 -25
  19. package/dist/client.cjs.map +1 -1
  20. package/dist/client.d.cts +39 -22
  21. package/dist/client.d.ts +39 -22
  22. package/dist/client.js +87 -26
  23. package/dist/client.js.map +1 -1
  24. package/dist/compiler.cjs +1755 -329
  25. package/dist/compiler.cjs.map +1 -1
  26. package/dist/compiler.d.cts +56 -3
  27. package/dist/compiler.d.ts +56 -3
  28. package/dist/compiler.js +1756 -330
  29. package/dist/compiler.js.map +1 -1
  30. package/dist/constants-YoFGjIBM.d.cts +99 -0
  31. package/dist/constants-YoFGjIBM.d.ts +99 -0
  32. package/dist/dynamic-input.d.cts +1 -0
  33. package/dist/dynamic-input.d.ts +1 -0
  34. package/dist/index.cjs +1973 -164
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +474 -100
  37. package/dist/index.d.ts +474 -100
  38. package/dist/index.js +1940 -167
  39. package/dist/index.js.map +1 -1
  40. package/dist/ir.cjs +869 -46
  41. package/dist/ir.cjs.map +1 -1
  42. package/dist/ir.d.cts +699 -25
  43. package/dist/ir.d.ts +699 -25
  44. package/dist/ir.js +861 -47
  45. package/dist/ir.js.map +1 -1
  46. package/dist/{naming-CTvWSRTf.d.ts → naming-CPfx7EfF.d.ts} +28 -1
  47. package/dist/{naming-DRyinU4u.d.cts → naming-CU9ThP_E.d.cts} +28 -1
  48. package/dist/policy-1iZbGnZZ.d.cts +24 -0
  49. package/dist/policy-1iZbGnZZ.d.ts +24 -0
  50. package/dist/predicate-v2.cjs +852 -49
  51. package/dist/predicate-v2.cjs.map +1 -1
  52. package/dist/predicate-v2.d.cts +2 -1
  53. package/dist/predicate-v2.d.ts +2 -1
  54. package/dist/predicate-v2.js +852 -49
  55. package/dist/predicate-v2.js.map +1 -1
  56. package/dist/sdl.cjs +1309 -58
  57. package/dist/sdl.cjs.map +1 -1
  58. package/dist/sdl.d.cts +7 -3
  59. package/dist/sdl.d.ts +7 -3
  60. package/dist/sdl.js +1305 -59
  61. package/dist/sdl.js.map +1 -1
  62. package/package.json +11 -6
  63. package/templates/orm-namespace/CLAUDE.md +6 -4
  64. package/templates/orm-namespace/codegen.preset.d.cts +7 -0
  65. package/templates/orm-namespace/codegen.ts +2 -1
  66. package/templates/orm-namespace/graphql/example/queries.ts +4 -3
  67. package/templates/orm-namespace/package.json +2 -1
  68. package/templates/orm-namespace/schema/tables.ts +3 -2
  69. package/templates/orm-namespace/sequence.config.ts +7 -11
package/README.md CHANGED
@@ -5,12 +5,18 @@ namespaces. You define tables, policies, and named GraphQL operations in source
5
5
  control; the platform compiles them into persisted operations and enforces the
6
6
  caller's access on every execution.
7
7
 
8
+ Sequence ORM is a workflow-agnostic platform primitive. The compiler and
9
+ runtime own generic schema, policy, migration, and execution contracts;
10
+ deployed namespaces own domain tables and operations. Primitive code must not
11
+ branch on a namespace or product identity. See
12
+ [Platform primitive boundaries](../../../docs/platform/platform-primitives.md).
13
+
8
14
  ## Install
9
15
 
10
16
  Install the CLI and SDK together:
11
17
 
12
18
  ```bash
13
- pnpm add -g @sequenceholdings/studio-cli@0.1.27 @sequenceholdings/orm@2.0.0
19
+ pnpm add -g @sequenceholdings/studio-cli@0.3.0 @sequenceholdings/orm@2.1.1
14
20
  ```
15
21
 
16
22
  Create a namespace project:
@@ -32,15 +38,83 @@ seq-studio orm apply . -e <environment-name>
32
38
  ```
33
39
 
34
40
  `generate` writes `schema.graphql`, `operations.manifest.json`, cache policies,
35
- and typed consumer modules. Commit generated outputs and migrations with the
41
+ and typed consumer modules. Generated SDL may contain up to 16 MiB of UTF-8
42
+ text for the complete namespace; individual authored files retain a 1 MiB cap.
43
+ Registration and reviewed migration exports are bounded to 64 MiB including
44
+ canonical metadata, snapshots, documents, and migration statements.
45
+
46
+ Commit generated outputs and migrations with the
36
47
  source that produced them.
37
48
 
49
+ Owned `defineTable` contracts support named `checks` and referential actions
50
+ on enforced `toOne` links or composite `foreignKeys`:
51
+
52
+ ```ts
53
+ const reports = defineTable('reports', {
54
+ id: t.uuid().primaryKey(),
55
+ status: t.text().notNull(),
56
+ }, {
57
+ checks: [{ name: 'reports_status_check', expression: "status IN ('draft', 'active')" }],
58
+ })
59
+
60
+ const runs = defineTable('runs', {
61
+ id: t.uuid().primaryKey(),
62
+ reportId: t.uuid().notNull(),
63
+ }, {
64
+ links: { report: toOne(reports, { on: 'reportId', enforce: true, onDelete: 'cascade' }) },
65
+ })
66
+ ```
67
+
68
+ Check expressions use a validated subset of PostgreSQL predicates. See
69
+ [database constraints](../../../docs/platform/orm-v2.md#database-integrity-constraints)
70
+ for the supported operators, actions, migration behavior, and limitations.
71
+
38
72
  Use `apply --dry-run` to rehearse a migration against a disposable copy of the
39
73
  target environment's data. `apply --no-create` refuses to provision a missing
40
74
  namespace, which is useful for deployment checks.
41
75
 
42
76
  ## Execute persisted operations
43
77
 
78
+ ### Guard dependent writes
79
+
80
+ Mutation roots run in one transaction. To require a conditional write to
81
+ succeed before committing dependent roots, add a fixed row-count assertion:
82
+
83
+ ```graphql
84
+ mutation SaveDeal($id: uuid!, $revision: Int!, $title: String!) {
85
+ updateDeals(
86
+ where: { id: { _eq: $id }, revision: { _eq: $revision } }
87
+ _set: { title: $title }
88
+ _inc: { revision: 1 }
89
+ ) @assertAffectedRows(exactly: 1) {
90
+ returning { id revision }
91
+ }
92
+ }
93
+ ```
94
+
95
+ This example assumes a `deals` table with `id`, `title`, and integer `revision`
96
+ columns and suitable write policies. The assertion uses the actual SQL write
97
+ count even when `affectedRows` is not selected. A mismatch rolls back **all**
98
+ roots and the operation journal with HTTP 409 `MUTATION_PRECONDITION_FAILED`.
99
+ Missing, policy-hidden, and stale matches receive the same generic error.
100
+ Ordinary mutations without this directive keep zero-match success semantics.
101
+
102
+ `exactly` must be a literal integer from 0 through 2147483647. It cannot be a
103
+ caller variable. Only mutation root fields may carry the directive, and a
104
+ guarded root cannot also use `@include` or `@skip`. Policy and constraint
105
+ failures retain their existing errors. This does not add automatic retries:
106
+ when the domain permits retry, reread authorized state and recompute the write.
107
+ Every writer affecting the invariant must participate in the revision protocol.
108
+
109
+ Guarded operations use **IR v2**; older runtimes reject them. Upgrade the host
110
+ compiler and executor together before registering guarded documents, regenerate
111
+ SDL with the matching SDK, and only then activate consumers. Existing unguarded
112
+ operations keep their IR v1 and operation hashes. This source addition requires
113
+ a matching SDK release and host rollout; it is not a claim that the published
114
+ Preview version already supports it.
115
+
116
+ ### Execute by name
117
+
44
118
  Operations execute by their generated manifest name, never by sending GraphQL
45
119
  text or SQL:
46
120
 
@@ -53,6 +127,10 @@ seq-studio orm execute GetOpenDeals . \
53
127
  `variables.json` must contain a JSON object. The platform validates variables,
54
128
  operation requirements, and row policies as the signed-in caller.
55
129
 
130
+ Execute uses the `/_data/v2` endpoint by default. Set
131
+ `SEQUENCE_ORM_ATLAS_EXECUTE_V2=1` to opt into Atlas's `/api/data/v2` endpoint.
132
+ This client rollout switch does not bypass server feature flags or authorization.
133
+
56
134
  ## Public exports
57
135
 
58
136
  - `@sequenceholdings/orm/authoring` — namespace, table, policy, and view DSL
@@ -60,3 +138,17 @@ operation requirements, and row policies as the signed-in caller.
60
138
  - `@sequenceholdings/orm/drizzle` — supported Drizzle helpers for views
61
139
  - `@sequenceholdings/orm/codegen` — GraphQL Code Generator preset used by a
62
140
  scaffolded namespace
141
+
142
+ The `@sequenceholdings/orm/client` entry point contains the persisted-operation
143
+ executor and error types without importing compiler, migration, Node builtins,
144
+ or third-party runtime dependencies. It is safe to bundle into browser and
145
+ function applications. The Managed Functions SDK bundles this entry point so
146
+ deployed functions do not install ORM's authoring dependencies.
147
+
148
+ Use `createArtifactOrmExecutor` from `@sequenceholdings/artifact-studio` inside
149
+ an authenticated Artifact, and `createFunctionOrmExecutor` from
150
+ `@sequenceholdings/managed-functions/orm` inside a Managed Function. Both accept
151
+ the generated JSON manifest and preserve the caller's governed data access.
152
+ The host adapters supply authentication; they do not grant namespace access or
153
+ register operations. Do not extract CLI credentials or invent a browser token
154
+ provider to wire a generated client.