@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
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ const { createRequire } = require('node:module');
4
+ const path = require('node:path');
5
+
6
+ const apolloHooksPlugin = require('./apollo-hooks.cjs');
7
+ const serverFnsPlugin = require('./server-fns.cjs');
8
+
9
+ const CLIENT_PLUGIN = '@sequenceholdings/orm/codegen/apollo-hooks';
10
+ const SERVER_PLUGIN = '@sequenceholdings/orm/codegen/server-fns';
11
+
12
+ function outputPlugins({ plugin, config }) {
13
+ return [
14
+ { typescript: {} },
15
+ { 'typescript-operations': {} },
16
+ { 'typed-document-node': {} },
17
+ { [plugin]: config },
18
+ ];
19
+ }
20
+
21
+ function consumerRequireFrom(options) {
22
+ const cwd = options?.config?.cwd ?? process.cwd();
23
+ return createRequire(path.join(cwd, 'package.json'));
24
+ }
25
+
26
+ function createPreset({ loadPlugin } = {}) {
27
+ return {
28
+ buildGeneratesSection: async (options) => {
29
+ const resolvePlugin = loadPlugin ?? ((name) => consumerRequireFrom(options)(name));
30
+ const pluginMap = {
31
+ ...options.pluginMap,
32
+ typescript: resolvePlugin('@graphql-codegen/typescript'),
33
+ 'typescript-operations': resolvePlugin('@graphql-codegen/typescript-operations'),
34
+ 'typed-document-node': resolvePlugin('@graphql-codegen/typed-document-node'),
35
+ [CLIENT_PLUGIN]: apolloHooksPlugin,
36
+ [SERVER_PLUGIN]: serverFnsPlugin,
37
+ };
38
+
39
+ return [
40
+ {
41
+ filename: `${options.baseOutputDir}client.ts`,
42
+ plugins: outputPlugins({ plugin: CLIENT_PLUGIN, config: {} }),
43
+ pluginMap,
44
+ schema: options.schema,
45
+ config: options.config,
46
+ documents: options.documents,
47
+ documentTransforms: options.documentTransforms,
48
+ },
49
+ {
50
+ filename: `${options.baseOutputDir}server.ts`,
51
+ plugins: outputPlugins({ plugin: SERVER_PLUGIN, config: { typesImportPath: false } }),
52
+ pluginMap,
53
+ schema: options.schema,
54
+ config: options.config,
55
+ documents: options.documents,
56
+ documentTransforms: options.documentTransforms,
57
+ },
58
+ ];
59
+ },
60
+ };
61
+ }
62
+
63
+ module.exports = createPreset();
64
+ module.exports.createPreset = createPreset;
@@ -16,7 +16,8 @@
16
16
  * config:
17
17
  * typesImportPath — module the `<Name><Kind>Variables` types are imported
18
18
  * from (default './types.gen'). Point it at the file the `typescript` +
19
- * `typescript-operations` plugins write.
19
+ * `typescript-operations` plugins write. Set false when those plugins run
20
+ * in the same output file.
20
21
  */
21
22
 
22
23
  function getResultFieldName(operation) {
@@ -60,7 +61,9 @@ function capitalize(str) {
60
61
 
61
62
  module.exports = {
62
63
  plugin: (_schema, documents, config) => {
63
- const typesImportPath = (config && config.typesImportPath) || './types.gen';
64
+ const typesImportPath = config?.typesImportPath === false
65
+ ? false
66
+ : (config?.typesImportPath || './types.gen');
64
67
  const imports = new Set();
65
68
  const functions = documents
66
69
  .flatMap(({ document }) => {
@@ -90,10 +93,12 @@ module.exports = {
90
93
  .filter(Boolean);
91
94
 
92
95
  if (functions.length) {
93
- const importStatements = [
94
- `import { executeOperation } from '@sequenceholdings/orm/client';`,
95
- `import { ${Array.from(imports).join(', ')} } from '${typesImportPath}';`,
96
- ];
96
+ const importStatements = [`import { executeOperation } from '@sequenceholdings/orm/client';`];
97
+ if (typesImportPath) {
98
+ importStatements.push(
99
+ `import { ${Array.from(imports).join(', ')} } from '${typesImportPath}';`,
100
+ );
101
+ }
97
102
  return [...importStatements, ...functions].join('\n\n');
98
103
  }
99
104
  return '';
@@ -29,11 +29,12 @@ applies it. Your app never talks to Postgres — it calls the data plane with
29
29
  GraphQL document in `graphql/`, compiled at push time. For genuinely exotic
30
30
  multi-statement writes, declare a table `action` — parameterized, gated,
31
31
  audited.
32
- - **Every table needs `read` and `write` policies.** Policies are the row
33
- security boundary and are compiled into every operation touching the table.
34
- There is no "no policy" fallback — an unrestricted table must say so
35
- explicitly (`allow: true` variant or a `true` policy) so the decision is
36
- reviewable.
32
+ - **Every table needs row policies.** At minimum declare `read` plus either a
33
+ legacy `write` policy or split `insert` / `update` policies when create and
34
+ resolve are different actors. Policies are the row security boundary and are
35
+ compiled into every operation touching the table. There is no "no policy"
36
+ fallback — an unrestricted table must say so explicitly (`allow: true`
37
+ variant or a `true` policy) so the decision is reviewable.
37
38
  - **Exactly one `defineNamespace`** (in `sequence.config.ts`), and every
38
39
  table module must call `defineTable` at import time — the CLI collects
39
40
  registrations by importing your files.
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const { createRequire } = require('node:module');
4
+ const path = require('node:path');
5
+
6
+ /**
7
+ * Consumer-local graphql-codegen preset shim. The ORM package ships the preset
8
+ * implementation, but graphql-codegen plugins must resolve from the scaffold's
9
+ * devDependencies (pnpm's strict layout does not hoist them into the ORM pkg).
10
+ */
11
+ const consumerRequire = createRequire(path.join(__dirname, 'package.json'));
12
+ const ormCodegenDir = path.dirname(
13
+ consumerRequire.resolve('@sequenceholdings/orm/codegen/apollo-hooks'),
14
+ );
15
+ const { createPreset } = require(path.join(ormCodegenDir, 'preset.cjs'));
16
+
17
+ module.exports = createPreset();
@@ -14,7 +14,7 @@ const config: CodegenConfig = {
14
14
  documents: ['graphql/**/*.ts'],
15
15
  generates: {
16
16
  './generated/': {
17
- preset: '@sequenceholdings/orm/codegen',
17
+ preset: './codegen.preset.cjs',
18
18
  },
19
19
  },
20
20
  }
@@ -16,6 +16,9 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@graphql-codegen/cli": "^5.0.7",
19
+ "@graphql-codegen/typed-document-node": "^5.1.1",
20
+ "@graphql-codegen/typescript": "^4.1.6",
21
+ "@graphql-codegen/typescript-operations": "^4.6.1",
19
22
  "typescript": "^5.6.0"
20
23
  },
21
24
  "engines": {
@@ -1,4 +1,4 @@
1
- import { defineEnum, defineTable, t, toMany, toOne, toPlatformUser } from '@sequenceholdings/orm'
1
+ import { defineEnum, defineTable, t, toMany, toOne, toPlatformUser } from '@sequenceholdings/orm/authoring'
2
2
 
3
3
  /**
4
4
  * Tables are TypeScript, but they SERIALIZE to data — the server never runs
@@ -1,4 +1,4 @@
1
- import { defineNamespace } from '@sequenceholdings/orm'
1
+ import { defineNamespace } from '@sequenceholdings/orm/authoring'
2
2
 
3
3
  /**
4
4
  * The namespace config — exactly one per directory.