@sequenceholdings/orm 0.1.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 ADDED
@@ -0,0 +1,37 @@
1
+ # @sequenceholdings/orm
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.
4
+
5
+ Design source of truth: the "Sequence ORM: OpCo Data Layer" Notion page.
6
+
7
+ This package is the pure core — no Atlas imports, no database access:
8
+
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 a function's own per-function 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)
18
+
19
+ Deploy with `seq-studio orm …` (see `@sequenceholdings/studio-cli`):
20
+
21
+ ```
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
27
+ ```
28
+
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.
33
+
34
+ ```bash
35
+ pnpm --filter @sequenceholdings/orm build
36
+ pnpm --filter @sequenceholdings/orm test
37
+ ```