@sequenceholdings/orm 0.1.3 → 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.
package/README.md CHANGED
@@ -1,47 +1,62 @@
1
1
  # @sequenceholdings/orm
2
2
 
3
- Sequence ORM — the OpCo data layer. V2 namespaces define managed tables and
4
- read-only views in TypeScript, compile named GraphQL operations to persisted
5
- IR, and execute them through the governed Atlas Data API. Legacy v1 YAML
6
- namespaces remain supported during migration.
7
-
8
- Design source of truth: the "Sequence ORM: OpCo Data Layer" Notion page.
9
-
10
- This package is the pure core — no Atlas imports, no database access:
11
-
12
- - `authoring/` — TypeScript `defineTable` / `defineView` DSL. View queries use
13
- Drizzle through `@sequenceholdings/orm/drizzle`; only normalized SQL and
14
- dependencies enter canonical JSON.
15
- - `canonical/` — validated v2 table/view wire contract shared by CLI and Atlas.
16
- - `compiler-gql/`, `sdl/`, and `ir/` — read/write table operations plus
17
- read-only keyed or keyless view queries compiled to persisted operation IR.
18
-
19
- - `schema/` — zod schemas for the YAML definition surface (tables, columns, links, indexes, policies, actions)
20
- - `migrations/` — the committed migration workspace (`orm diff`, offline `--check` verification, destructive-statement classification)
21
- - `predicate/` — the policy expression grammar (`claim('…')`, `capability('…')`, comparisons, `and`/`or`/`not`)
22
- - `compiler/` — predicate AST and identifier/literal helpers → SQL fragments for policies and claims
23
- - `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.
24
- - `loader.ts` — a namespace directory of `*.yaml` files → validated `NamespaceDefinition`
25
- - `hash.ts` — canonical content hash (key-order-insensitive) used for content-addressed registry versions
26
- - `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".
27
- - `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)
28
-
29
- Deploy with `seq-studio orm …` (see `@sequenceholdings/studio-cli`):
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.
30
7
 
8
+ ## Install
9
+
10
+ Install the CLI and SDK together:
11
+
12
+ ```bash
13
+ pnpm add -g @sequenceholdings/studio-cli@0.1.27 @sequenceholdings/orm@2.0.0
14
+ ```
15
+
16
+ Create a namespace project:
17
+
18
+ ```bash
19
+ seq-studio orm init lending
20
+ cd lending
21
+ pnpm install
31
22
  ```
32
- seq-studio orm apply [dir] -e <env> # the everyday loop: author the migration, register, apply, refresh types
33
- 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)
34
- seq-studio orm plan [dir] -e <env> # offline dry run — compiled SQL + registry status (no database, no writes)
35
- seq-studio orm diff [dir] [--check] # write / verify the committed migration (--check is the offline CI gate)
36
- 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>
37
32
  ```
38
33
 
39
- `--dry-run` registers the version and rehearses its plan on a throwaway
40
- copy-on-write fork of the environment's live data — proving the migration
41
- survives real rows (a `NOT NULL` onto populated data, a constraint existing
42
- 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:
43
46
 
44
47
  ```bash
45
- pnpm --filter @sequenceholdings/orm build
46
- pnpm --filter @sequenceholdings/orm test
48
+ seq-studio orm execute GetOpenDeals . \
49
+ --variables-file variables.json \
50
+ -e <environment-name>
47
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
@@ -1685,7 +1685,12 @@ async function loadNamespaceFromDir(dir, options = {}) {
1685
1685
  const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('authoring.cjs', document.baseURI).href)), {
1686
1686
  interopDefault: true,
1687
1687
  fsCache: false,
1688
- ...options.ormModulePath !== void 0 ? { alias: { "@sequenceholdings/orm": options.ormModulePath } } : {}
1688
+ ...options.ormModulePath !== void 0 ? {
1689
+ alias: {
1690
+ "@sequenceholdings/orm": options.ormModulePath,
1691
+ "@sequenceholdings/orm/authoring": options.ormModulePath
1692
+ }
1693
+ } : {}
1689
1694
  });
1690
1695
  const context = beginAuthoringContext();
1691
1696
  try {