@sequenceholdings/orm 0.1.2 → 2.0.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.
Files changed (72) hide show
  1. package/README.md +49 -24
  2. package/dist/authoring.cjs +1072 -60
  3. package/dist/authoring.cjs.map +1 -1
  4. package/dist/authoring.d.cts +291 -26
  5. package/dist/authoring.d.ts +291 -26
  6. package/dist/authoring.js +1062 -61
  7. package/dist/authoring.js.map +1 -1
  8. package/dist/canonical.cjs +415 -9
  9. package/dist/canonical.cjs.map +1 -1
  10. package/dist/canonical.d.cts +235 -1
  11. package/dist/canonical.d.ts +235 -1
  12. package/dist/canonical.js +411 -10
  13. package/dist/canonical.js.map +1 -1
  14. package/dist/cli.cjs +1860 -228
  15. package/dist/cli.cjs.map +1 -1
  16. package/dist/cli.js +1861 -229
  17. package/dist/cli.js.map +1 -1
  18. package/dist/client.cjs.map +1 -1
  19. package/dist/client.d.cts +1 -1
  20. package/dist/client.d.ts +1 -1
  21. package/dist/client.js.map +1 -1
  22. package/dist/compiler.cjs +512 -54
  23. package/dist/compiler.cjs.map +1 -1
  24. package/dist/compiler.d.cts +39 -231
  25. package/dist/compiler.d.ts +39 -231
  26. package/dist/compiler.js +510 -55
  27. package/dist/compiler.js.map +1 -1
  28. package/dist/drizzle.cjs +14 -0
  29. package/dist/drizzle.cjs.map +1 -0
  30. package/dist/drizzle.d.cts +1 -0
  31. package/dist/drizzle.d.ts +1 -0
  32. package/dist/drizzle.js +3 -0
  33. package/dist/drizzle.js.map +1 -0
  34. package/dist/dynamic-input.cjs +391 -0
  35. package/dist/dynamic-input.cjs.map +1 -0
  36. package/dist/dynamic-input.d.cts +111 -0
  37. package/dist/dynamic-input.d.ts +111 -0
  38. package/dist/dynamic-input.js +380 -0
  39. package/dist/dynamic-input.js.map +1 -0
  40. package/dist/index.cjs +2229 -220
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +125 -9
  43. package/dist/index.d.ts +125 -9
  44. package/dist/index.js +2205 -221
  45. package/dist/index.js.map +1 -1
  46. package/dist/ir.cjs +249 -14
  47. package/dist/ir.cjs.map +1 -1
  48. package/dist/ir.d.cts +20 -80
  49. package/dist/ir.d.ts +20 -80
  50. package/dist/ir.js +249 -14
  51. package/dist/ir.js.map +1 -1
  52. package/dist/predicate-v2.cjs +1099 -0
  53. package/dist/predicate-v2.cjs.map +1 -0
  54. package/dist/predicate-v2.d.cts +142 -0
  55. package/dist/predicate-v2.d.ts +142 -0
  56. package/dist/predicate-v2.js +1089 -0
  57. package/dist/predicate-v2.js.map +1 -0
  58. package/dist/sdl.cjs +344 -55
  59. package/dist/sdl.cjs.map +1 -1
  60. package/dist/sdl.d.cts +1 -3
  61. package/dist/sdl.d.ts +1 -3
  62. package/dist/sdl.js +344 -55
  63. package/dist/sdl.js.map +1 -1
  64. package/package.json +20 -3
  65. package/src/codegen-gql/preset.cjs +64 -0
  66. package/src/codegen-gql/server-fns.cjs +11 -6
  67. package/templates/orm-namespace/CLAUDE.md +6 -5
  68. package/templates/orm-namespace/codegen.preset.cjs +17 -0
  69. package/templates/orm-namespace/codegen.ts +1 -1
  70. package/templates/orm-namespace/package.json +3 -0
  71. package/templates/orm-namespace/schema/tables.ts +1 -1
  72. package/templates/orm-namespace/sequence.config.ts +1 -1
package/README.md CHANGED
@@ -1,37 +1,62 @@
1
1
  # @sequenceholdings/orm
2
2
 
3
- Sequence ORM — the OpCo data layer. Tables, links, row policies, and actions are defined in YAML per namespace; the platform compiles them into Postgres tables with forced row-level security in the OpCo's Lakebase, serves them through the Atlas Data API, and generates a typed client.
3
+ Sequence ORM v2 is a Preview SDK for TypeScript-defined governed data
4
+ namespaces. You define tables, policies, and named GraphQL operations in source
5
+ control; the platform compiles them into persisted operations and enforces the
6
+ caller's access on every execution.
4
7
 
5
- Design source of truth: the "Sequence ORM: OpCo Data Layer" Notion page.
8
+ ## Install
6
9
 
7
- This package is the pure core — no Atlas imports, no database access:
10
+ Install the CLI and SDK together:
8
11
 
9
- - `schema/` — zod schemas for the YAML definition surface (tables, columns, links, indexes, policies, actions)
10
- - `migrations/` — the committed migration workspace (`orm diff`, offline `--check` verification, destructive-statement classification)
11
- - `predicate/` — the policy expression grammar (`claim('…')`, `capability('…')`, comparisons, `and`/`or`/`not`)
12
- - `compiler/` — predicate AST and identifier/literal helpers → SQL fragments for policies and claims
13
- - `engine/` — namespace definitions → ordered migration plans (`hint` / `ddl` / `security` / `function`) plus drizzle-kit snapshots for the registry. Each declared action compiles to a `SECURITY INVOKER` Postgres function (`orm_<ns>.action_<name>`) created at apply, so the invoke path is a single `SELECT`; writes never run as client-rewritten statements. Apply also `PREPARE`s each executes statement so Postgres validates its columns/types (plpgsql function bodies defer that to first invoke), failing the apply on a bad reference. `executes` may be one statement or an ordered list (run atomically); `returns:` makes the function `RETURNS TABLE(...)` and hands back the RETURNING rows.
14
- - `loader.ts` — a namespace directory of `*.yaml` files → validated `NamespaceDefinition`
15
- - `hash.ts` — canonical content hash (key-order-insensitive) used for content-addressed registry versions
16
- - `client/` (`@sequenceholdings/orm/client`) — typed Data API client; fetch-only, no node builtins. `createOrmClient` acts as the caller (session bearer, or a managed function's delegated user token — the default); `createServiceOrmClient` is the loudly-named escalation that acts as the platform service account attached to the function (its manifest's top-level `service_account`). See the `sequence-orm` skill → "two consumer modes".
17
- - `codegen/` — derives the client's wire types from the definitions; `apply` refreshes `types.gen.ts` on every successful run (there is no separate `generate` command — one verb owns the loop)
12
+ ```bash
13
+ pnpm add -g @sequenceholdings/studio-cli@0.1.27 @sequenceholdings/orm@2.0.0
14
+ ```
18
15
 
19
- Deploy with `seq-studio orm …` (see `@sequenceholdings/studio-cli`):
16
+ Create a namespace project:
20
17
 
18
+ ```bash
19
+ seq-studio orm init lending
20
+ cd lending
21
+ pnpm install
21
22
  ```
22
- seq-studio orm apply [dir] -e <env> # the everyday loop: author the migration, register, apply, refresh types
23
- seq-studio orm apply [dir] --dry-run -e <env> # rehearse the migration on a copy of the env's real data, then discard it (no real apply)
24
- seq-studio orm plan [dir] -e <env> # offline dry run — compiled SQL + registry status (no database, no writes)
25
- seq-studio orm diff [dir] [--check] # write / verify the committed migration (--check is the offline CI gate)
26
- seq-studio orm validate [dir] # parse + content hash + the offline migration gate
23
+
24
+ ## Everyday workflow
25
+
26
+ ```bash
27
+ # Edit sequence.config.ts, schema/*.ts, and graphql/**/*.ts.
28
+ seq-studio orm generate .
29
+ seq-studio orm validate .
30
+ seq-studio orm plan . -e <environment-name>
31
+ seq-studio orm apply . -e <environment-name>
27
32
  ```
28
33
 
29
- `--dry-run` registers the version and rehearses its plan on a throwaway
30
- copy-on-write fork of the environment's live data — proving the migration
31
- survives real rows (a `NOT NULL` onto populated data, a constraint existing
32
- rows violate) — then discards the fork without applying for real.
34
+ `generate` writes `schema.graphql`, `operations.manifest.json`, cache policies,
35
+ and typed consumer modules. Commit generated outputs and migrations with the
36
+ source that produced them.
37
+
38
+ Use `apply --dry-run` to rehearse a migration against a disposable copy of the
39
+ target environment's data. `apply --no-create` refuses to provision a missing
40
+ namespace, which is useful for deployment checks.
41
+
42
+ ## Execute persisted operations
43
+
44
+ Operations execute by their generated manifest name, never by sending GraphQL
45
+ text or SQL:
33
46
 
34
47
  ```bash
35
- pnpm --filter @sequenceholdings/orm build
36
- pnpm --filter @sequenceholdings/orm test
48
+ seq-studio orm execute GetOpenDeals . \
49
+ --variables-file variables.json \
50
+ -e <environment-name>
37
51
  ```
52
+
53
+ `variables.json` must contain a JSON object. The platform validates variables,
54
+ operation requirements, and row policies as the signed-in caller.
55
+
56
+ ## Public exports
57
+
58
+ - `@sequenceholdings/orm/authoring` — namespace, table, policy, and view DSL
59
+ - `@sequenceholdings/orm/client` — persisted-operation client utilities
60
+ - `@sequenceholdings/orm/drizzle` — supported Drizzle helpers for views
61
+ - `@sequenceholdings/orm/codegen` — GraphQL Code Generator preset used by a
62
+ scaffolded namespace