@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/orm",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Sequence ORM v2 — TypeScript-defined governed tables and persisted GraphQL operations",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -28,9 +28,14 @@
28
28
  "require": "./dist/cli.cjs"
29
29
  },
30
30
  "./client": {
31
- "types": "./dist/client.d.ts",
32
- "import": "./dist/client.js",
33
- "require": "./dist/client.cjs"
31
+ "import": {
32
+ "types": "./dist/client.d.ts",
33
+ "default": "./dist/client.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/client.d.cts",
37
+ "default": "./dist/client.cjs"
38
+ }
34
39
  },
35
40
  "./ir": {
36
41
  "types": "./dist/ir.d.ts",
@@ -89,7 +94,7 @@
89
94
  "jiti": "^2.4.2",
90
95
  "drizzle-kit": "^0.31.9",
91
96
  "drizzle-orm": "^0.45.2",
92
- "js-yaml": "^4.3.1",
97
+ "js-yaml": "^4.3.2",
93
98
  "zod": "^4.1.13",
94
99
  "@sequenceholdings/custom-roles-manifest": "0.1.0"
95
100
  },
@@ -98,7 +103,7 @@
98
103
  "@types/node": "^22.0.0",
99
104
  "tsup": "^8.3.0",
100
105
  "typescript": "^5.3.3",
101
- "vitest": "^4.1.5"
106
+ "vitest": "^4.1.11"
102
107
  },
103
108
  "engines": {
104
109
  "node": ">=20"
@@ -42,7 +42,9 @@ applies it. Your app never talks to Postgres — it calls the data plane with
42
42
  `.renamedFrom('old_name')` (column) / `renamedFrom` (table config) is a
43
43
  DROP + CREATE — data loss. The diff will refuse ambiguous renames; add the
44
44
  hint instead of forcing.
45
- - **Capabilities/roles are declared here, granted in the Permissions UI.**
45
+ - **Capabilities are code, roles are data.** Capabilities are declared here; roles that bundle them are
46
+ created in Atlas and granted in the Permissions UI. Don't add role `definitions`
47
+ (a deprecated one-time seed) or check `role('…')` — check capabilities.
46
48
  Never hardcode user identities in policies; use `claim('sub')` /
47
49
  `claim('org')` and grants.
48
50
 
@@ -53,7 +55,6 @@ author_sub = claim('sub') -- row value vs caller claim
53
55
  org = claim('org') and status = 'open' -- boolean algebra
54
56
  exists(deal, org = claim('org')) -- traverse a declared link
55
57
  capability('deals-read') -- boolean grant check
56
- role('deal-manager') -- boolean role check
57
58
  ```
58
59
 
59
60
  Variants widen access per grant (permissive union):
@@ -64,7 +65,7 @@ policies: {
64
65
  default: "author_sub = claim('sub')",
65
66
  variants: [
66
67
  { when: "capability('deals-read')", policy: "org = claim('org')" },
67
- { when: "role('deal-manager')", allow: true },
68
+ { when: "capability('deals-admin')", allow: true },
68
69
  ],
69
70
  },
70
71
  }
@@ -73,7 +74,8 @@ policies: {
73
74
  ## GraphQL operations
74
75
 
75
76
  - Named operations only; one export per document; gate with
76
- `@requires(capability: "…")` / `@requires(role: "…")`.
77
+ `@requires(capability: "…")`. Check capabilities, not roles — roles are
78
+ created in Atlas and can change there.
77
79
  - Dynamic filters are policy-bounded: `$where: <Table>BoolExp` /
78
80
  `$orderBy` / whole-input write objects are validated against a
79
81
  schema-derived whitelist and AND-ed with the table policy at runtime —
@@ -0,0 +1,7 @@
1
+ import type { CodegenConfig } from '@graphql-codegen/cli'
2
+
3
+ // The runtime shim loads the package's preset object. Derive its type from the
4
+ // installed CLI so this declaration follows the consumer's codegen contract.
5
+ type ConfiguredOutput = Exclude<CodegenConfig['generates'][string], unknown[]>
6
+ declare const preset: Exclude<ConfiguredOutput['preset'], string | undefined>
7
+ export = preset
@@ -1,4 +1,5 @@
1
1
  import type { CodegenConfig } from '@graphql-codegen/cli'
2
+ import preset from './codegen.preset.cjs'
2
3
 
3
4
  /**
4
5
  * graphql-codegen config. `seq-studio orm generate` writes ./schema.graphql
@@ -14,7 +15,7 @@ const config: CodegenConfig = {
14
15
  documents: ['graphql/**/*.ts'],
15
16
  generates: {
16
17
  './generated/': {
17
- preset: './codegen.preset.cjs',
18
+ preset,
18
19
  },
19
20
  },
20
21
  }
@@ -4,9 +4,10 @@
4
4
  * variables }` — never query text, never SQL. Type names come from the
5
5
  * generated `schema.graphql` (`seq-studio orm generate`).
6
6
  *
7
- * Gate an operation with `@requires(capability: "…")` or
8
- * `@requires(role: "…")` — checked before execution, on top of the
9
- * table policies that are always compiled in.
7
+ * Gate an operation with `@requires(capability: "…")` — checked before
8
+ * execution, on top of the table policies that are always compiled in.
9
+ * Check capabilities, not roles: roles are created in Atlas and can change
10
+ * there.
10
11
  */
11
12
 
12
13
  export const GetOpenDeals = /* GraphQL */ `
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@apollo/client": "^3.11.0",
14
- "@sequenceholdings/orm": "^2.0.0",
14
+ "@graphql-typed-document-node/core": "^3.2.0",
15
+ "@sequenceholdings/orm": "^2.1.1",
15
16
  "graphql": "^16.11.0"
16
17
  },
17
18
  "devDependencies": {
@@ -8,7 +8,8 @@ import { defineEnum, defineTable, t, toMany, toOne, toPlatformUser } from '@sequ
8
8
  *
9
9
  * Every table carries its own row-level policies. The policy DSL:
10
10
  * - `claim('sub')` / `claim('org')` — the caller's identity claims
11
- * - `capability('x')` / `role('y')` — boolean grants, resolved per caller
11
+ * - `capability('x')` — boolean grant, resolved per caller (check
12
+ * capabilities, not roles: roles are created in Atlas and can change)
12
13
  * - `exists(link, <predicate>)` — traverse a declared link
13
14
  * - variants: `default` applies to everyone; each variant WIDENS access
14
15
  * when its `when` guard matches (permissive union — grants only ever
@@ -39,7 +40,7 @@ export const deals = defineTable(
39
40
  default: "author_sub = claim('sub')",
40
41
  variants: [
41
42
  { when: "capability('deals-read')", policy: "org = claim('org')" },
42
- { when: "role('deal-manager')", allow: true },
43
+ { when: "capability('deals-admin')", allow: true },
43
44
  ],
44
45
  },
45
46
  write: "author_sub = claim('sub')",
@@ -3,9 +3,10 @@ import { defineNamespace } from '@sequenceholdings/orm/authoring'
3
3
  /**
4
4
  * The namespace config — exactly one per directory.
5
5
  *
6
- * Capabilities and roles are DECLARED here (verbatim custom-roles grammar);
7
- * who HOLDS them is granted later in the Permissions UI (FGA), never in code.
8
- * Table policies reference them with `capability('…')` / `role('…')`.
6
+ * Capabilities are DECLARED here (verbatim custom-roles grammar) — the
7
+ * contract your policies check with `capability('…')`. Roles that bundle
8
+ * them are created in Atlas (the namespace's Roles tab), and who HOLDS them
9
+ * is granted there too, never in code.
9
10
  */
10
11
  export default defineNamespace({
11
12
  // Rename me: the namespace becomes your Postgres schema (orm_<namespace>).
@@ -13,18 +14,13 @@ export default defineNamespace({
13
14
  description: 'Describe what this namespace stores and who uses it.',
14
15
  capabilities: {
15
16
  roles: {
16
- definitions: {
17
- 'deal-manager': {
18
- description: 'Full access to every deal in the namespace',
19
- default: false,
20
- inherits: [],
21
- grants: ['deals-read'],
22
- },
23
- },
24
17
  capabilities: {
25
18
  'deals-read': {
26
19
  description: 'Read all deals in the caller org (instead of author-only)',
27
20
  },
21
+ 'deals-admin': {
22
+ description: 'Read every deal in the namespace, in any org',
23
+ },
28
24
  },
29
25
  },
30
26
  uses: [],