node-type-registry 0.3.1 → 0.4.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.
@@ -5,10 +5,16 @@
5
5
  * suitable for use as separate pgpm migration files.
6
6
  *
7
7
  * Usage:
8
- * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single]
8
+ * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single] [--pgpm <dir>]
9
9
  *
10
10
  * --outdir <dir> Directory to write individual SQL files (default: stdout)
11
11
  * --single Emit a single combined seed.sql instead of per-node files
12
+ * --pgpm <dir> Generate deploy/revert/verify files in pgpm package layout.
13
+ * <dir> is the pgpm package root (e.g. packages/metaschema).
14
+ * Files are written relative to this root at:
15
+ * deploy/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
16
+ * revert/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
17
+ * verify/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
12
18
  *
13
19
  * Examples:
14
20
  * # Print all INSERT statements to stdout
@@ -19,5 +25,8 @@
19
25
  *
20
26
  * # Generate a single combined seed file
21
27
  * npx ts-node src/codegen/generate-seed.ts --single --outdir ./deploy
28
+ *
29
+ * # Generate pgpm deploy/revert/verify files
30
+ * npx ts-node src/codegen/generate-seed.ts --pgpm ../../constructive-db/packages/metaschema
22
31
  */
23
32
  export {};
@@ -6,10 +6,16 @@
6
6
  * suitable for use as separate pgpm migration files.
7
7
  *
8
8
  * Usage:
9
- * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single]
9
+ * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single] [--pgpm <dir>]
10
10
  *
11
11
  * --outdir <dir> Directory to write individual SQL files (default: stdout)
12
12
  * --single Emit a single combined seed.sql instead of per-node files
13
+ * --pgpm <dir> Generate deploy/revert/verify files in pgpm package layout.
14
+ * <dir> is the pgpm package root (e.g. packages/metaschema).
15
+ * Files are written relative to this root at:
16
+ * deploy/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
17
+ * revert/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
18
+ * verify/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
13
19
  *
14
20
  * Examples:
15
21
  * # Print all INSERT statements to stdout
@@ -20,6 +26,9 @@
20
26
  *
21
27
  * # Generate a single combined seed file
22
28
  * npx ts-node src/codegen/generate-seed.ts --single --outdir ./deploy
29
+ *
30
+ * # Generate pgpm deploy/revert/verify files
31
+ * npx ts-node src/codegen/generate-seed.ts --pgpm ../../constructive-db/packages/metaschema
23
32
  */
24
33
  Object.defineProperty(exports, "__esModule", { value: true });
25
34
  const fs_1 = require("fs");
@@ -28,6 +37,10 @@ const pgsql_deparser_1 = require("pgsql-deparser");
28
37
  const utils_1 = require("@pgsql/utils");
29
38
  const index_1 = require("../index");
30
39
  // ---------------------------------------------------------------------------
40
+ // Constants
41
+ // ---------------------------------------------------------------------------
42
+ const MIGRATION_PATH = 'schemas/metaschema_public/tables/node_type_registry/data/seed';
43
+ // ---------------------------------------------------------------------------
31
44
  // AST helpers
32
45
  // ---------------------------------------------------------------------------
33
46
  const astr = (val) => utils_1.nodes.aConst({ sval: utils_1.ast.string({ sval: val }) });
@@ -109,17 +122,101 @@ function buildInsertStmt(nt) {
109
122
  };
110
123
  }
111
124
  // ---------------------------------------------------------------------------
125
+ // pgpm file generators
126
+ // ---------------------------------------------------------------------------
127
+ const GENERATED_HEADER = [
128
+ '-- GENERATED FILE — DO NOT EDIT',
129
+ '--',
130
+ '-- Regenerate with:',
131
+ '-- cd graphile/node-type-registry && pnpm generate:seed --pgpm ../../constructive-db/packages/metaschema',
132
+ '--',
133
+ '',
134
+ ].join('\n');
135
+ async function buildDeploySql() {
136
+ const header = [
137
+ `-- Deploy ${MIGRATION_PATH} to pg`,
138
+ '',
139
+ GENERATED_HEADER,
140
+ '-- requires: schemas/metaschema_public/tables/node_type_registry/table',
141
+ '',
142
+ ].join('\n');
143
+ const stmts = index_1.allNodeTypes.map(buildInsertStmt);
144
+ const body = await (0, pgsql_deparser_1.deparse)(stmts);
145
+ return header + body + '\n';
146
+ }
147
+ function buildRevertSql() {
148
+ const names = index_1.allNodeTypes.map((nt) => ` '${nt.name}'`);
149
+ // Wrap names at ~4 per line for readability
150
+ const chunks = [];
151
+ for (let i = 0; i < names.length; i += 4) {
152
+ chunks.push(names.slice(i, i + 4).join(', '));
153
+ }
154
+ return [
155
+ `-- Revert ${MIGRATION_PATH} from pg`,
156
+ '',
157
+ GENERATED_HEADER,
158
+ 'DELETE FROM metaschema_public.node_type_registry',
159
+ 'WHERE name IN (',
160
+ chunks.join(',\n'),
161
+ ');',
162
+ '',
163
+ ].join('\n');
164
+ }
165
+ function buildVerifySql() {
166
+ // Pick one representative from each category
167
+ const categories = new Map();
168
+ for (const nt of index_1.allNodeTypes) {
169
+ if (!categories.has(nt.category)) {
170
+ categories.set(nt.category, nt);
171
+ }
172
+ }
173
+ const checks = Array.from(categories.values()).map((nt) => `SELECT 1 FROM metaschema_public.node_type_registry WHERE name = '${nt.name}';`);
174
+ return [
175
+ `-- Verify ${MIGRATION_PATH} on pg`,
176
+ '',
177
+ GENERATED_HEADER,
178
+ ...checks,
179
+ '',
180
+ ].join('\n');
181
+ }
182
+ // ---------------------------------------------------------------------------
183
+ // File writer helper
184
+ // ---------------------------------------------------------------------------
185
+ function writeFile(filePath, content) {
186
+ const dir = (0, path_1.join)(filePath, '..');
187
+ if (!(0, fs_1.existsSync)(dir))
188
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
189
+ (0, fs_1.writeFileSync)(filePath, content);
190
+ }
191
+ // ---------------------------------------------------------------------------
112
192
  // CLI
113
193
  // ---------------------------------------------------------------------------
114
- function main() {
194
+ async function main() {
115
195
  const args = process.argv.slice(2);
116
196
  const outdirIdx = args.indexOf('--outdir');
117
197
  const outdir = outdirIdx !== -1 ? args[outdirIdx + 1] : undefined;
118
198
  const single = args.includes('--single');
199
+ const pgpmIdx = args.indexOf('--pgpm');
200
+ const pgpmRoot = pgpmIdx !== -1 ? args[pgpmIdx + 1] : undefined;
201
+ // --pgpm mode: generate deploy/revert/verify in pgpm package layout
202
+ if (pgpmRoot) {
203
+ const relPath = 'schemas/metaschema_public/tables/node_type_registry/data/seed.sql';
204
+ const deployPath = (0, path_1.join)(pgpmRoot, 'deploy', relPath);
205
+ const revertPath = (0, path_1.join)(pgpmRoot, 'revert', relPath);
206
+ const verifyPath = (0, path_1.join)(pgpmRoot, 'verify', relPath);
207
+ writeFile(deployPath, await buildDeploySql());
208
+ writeFile(revertPath, buildRevertSql());
209
+ writeFile(verifyPath, buildVerifySql());
210
+ console.log(`Wrote ${index_1.allNodeTypes.length} node types to pgpm layout:`);
211
+ console.log(` deploy: ${deployPath}`);
212
+ console.log(` revert: ${revertPath}`);
213
+ console.log(` verify: ${verifyPath}`);
214
+ return;
215
+ }
119
216
  if (single) {
120
217
  // Emit all INSERT statements as a single SQL string
121
218
  const stmts = index_1.allNodeTypes.map(buildInsertStmt);
122
- const sql = (0, pgsql_deparser_1.deparse)(stmts);
219
+ const sql = await (0, pgsql_deparser_1.deparse)(stmts);
123
220
  if (outdir) {
124
221
  if (!(0, fs_1.existsSync)(outdir))
125
222
  (0, fs_1.mkdirSync)(outdir, { recursive: true });
@@ -132,10 +229,10 @@ function main() {
132
229
  return;
133
230
  }
134
231
  // Emit individual SQL files per node type
135
- const stmts = index_1.allNodeTypes.map((nt) => ({
232
+ const stmts = await Promise.all(index_1.allNodeTypes.map(async (nt) => ({
136
233
  nt,
137
- sql: (0, pgsql_deparser_1.deparse)([buildInsertStmt(nt)]),
138
- }));
234
+ sql: await (0, pgsql_deparser_1.deparse)([buildInsertStmt(nt)]),
235
+ })));
139
236
  if (outdir) {
140
237
  if (!(0, fs_1.existsSync)(outdir))
141
238
  (0, fs_1.mkdirSync)(outdir, { recursive: true });
@@ -5,10 +5,16 @@
5
5
  * suitable for use as separate pgpm migration files.
6
6
  *
7
7
  * Usage:
8
- * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single]
8
+ * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single] [--pgpm <dir>]
9
9
  *
10
10
  * --outdir <dir> Directory to write individual SQL files (default: stdout)
11
11
  * --single Emit a single combined seed.sql instead of per-node files
12
+ * --pgpm <dir> Generate deploy/revert/verify files in pgpm package layout.
13
+ * <dir> is the pgpm package root (e.g. packages/metaschema).
14
+ * Files are written relative to this root at:
15
+ * deploy/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
16
+ * revert/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
17
+ * verify/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
12
18
  *
13
19
  * Examples:
14
20
  * # Print all INSERT statements to stdout
@@ -19,5 +25,8 @@
19
25
  *
20
26
  * # Generate a single combined seed file
21
27
  * npx ts-node src/codegen/generate-seed.ts --single --outdir ./deploy
28
+ *
29
+ * # Generate pgpm deploy/revert/verify files
30
+ * npx ts-node src/codegen/generate-seed.ts --pgpm ../../constructive-db/packages/metaschema
22
31
  */
23
32
  export {};
@@ -5,10 +5,16 @@
5
5
  * suitable for use as separate pgpm migration files.
6
6
  *
7
7
  * Usage:
8
- * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single]
8
+ * npx ts-node src/codegen/generate-seed.ts [--outdir <dir>] [--single] [--pgpm <dir>]
9
9
  *
10
10
  * --outdir <dir> Directory to write individual SQL files (default: stdout)
11
11
  * --single Emit a single combined seed.sql instead of per-node files
12
+ * --pgpm <dir> Generate deploy/revert/verify files in pgpm package layout.
13
+ * <dir> is the pgpm package root (e.g. packages/metaschema).
14
+ * Files are written relative to this root at:
15
+ * deploy/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
16
+ * revert/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
17
+ * verify/schemas/metaschema_public/tables/node_type_registry/data/seed.sql
12
18
  *
13
19
  * Examples:
14
20
  * # Print all INSERT statements to stdout
@@ -19,6 +25,9 @@
19
25
  *
20
26
  * # Generate a single combined seed file
21
27
  * npx ts-node src/codegen/generate-seed.ts --single --outdir ./deploy
28
+ *
29
+ * # Generate pgpm deploy/revert/verify files
30
+ * npx ts-node src/codegen/generate-seed.ts --pgpm ../../constructive-db/packages/metaschema
22
31
  */
23
32
  import { writeFileSync, mkdirSync, existsSync } from 'fs';
24
33
  import { join } from 'path';
@@ -26,6 +35,10 @@ import { deparse } from 'pgsql-deparser';
26
35
  import { ast, nodes } from '@pgsql/utils';
27
36
  import { allNodeTypes } from '../index';
28
37
  // ---------------------------------------------------------------------------
38
+ // Constants
39
+ // ---------------------------------------------------------------------------
40
+ const MIGRATION_PATH = 'schemas/metaschema_public/tables/node_type_registry/data/seed';
41
+ // ---------------------------------------------------------------------------
29
42
  // AST helpers
30
43
  // ---------------------------------------------------------------------------
31
44
  const astr = (val) => nodes.aConst({ sval: ast.string({ sval: val }) });
@@ -107,17 +120,101 @@ function buildInsertStmt(nt) {
107
120
  };
108
121
  }
109
122
  // ---------------------------------------------------------------------------
123
+ // pgpm file generators
124
+ // ---------------------------------------------------------------------------
125
+ const GENERATED_HEADER = [
126
+ '-- GENERATED FILE — DO NOT EDIT',
127
+ '--',
128
+ '-- Regenerate with:',
129
+ '-- cd graphile/node-type-registry && pnpm generate:seed --pgpm ../../constructive-db/packages/metaschema',
130
+ '--',
131
+ '',
132
+ ].join('\n');
133
+ async function buildDeploySql() {
134
+ const header = [
135
+ `-- Deploy ${MIGRATION_PATH} to pg`,
136
+ '',
137
+ GENERATED_HEADER,
138
+ '-- requires: schemas/metaschema_public/tables/node_type_registry/table',
139
+ '',
140
+ ].join('\n');
141
+ const stmts = allNodeTypes.map(buildInsertStmt);
142
+ const body = await deparse(stmts);
143
+ return header + body + '\n';
144
+ }
145
+ function buildRevertSql() {
146
+ const names = allNodeTypes.map((nt) => ` '${nt.name}'`);
147
+ // Wrap names at ~4 per line for readability
148
+ const chunks = [];
149
+ for (let i = 0; i < names.length; i += 4) {
150
+ chunks.push(names.slice(i, i + 4).join(', '));
151
+ }
152
+ return [
153
+ `-- Revert ${MIGRATION_PATH} from pg`,
154
+ '',
155
+ GENERATED_HEADER,
156
+ 'DELETE FROM metaschema_public.node_type_registry',
157
+ 'WHERE name IN (',
158
+ chunks.join(',\n'),
159
+ ');',
160
+ '',
161
+ ].join('\n');
162
+ }
163
+ function buildVerifySql() {
164
+ // Pick one representative from each category
165
+ const categories = new Map();
166
+ for (const nt of allNodeTypes) {
167
+ if (!categories.has(nt.category)) {
168
+ categories.set(nt.category, nt);
169
+ }
170
+ }
171
+ const checks = Array.from(categories.values()).map((nt) => `SELECT 1 FROM metaschema_public.node_type_registry WHERE name = '${nt.name}';`);
172
+ return [
173
+ `-- Verify ${MIGRATION_PATH} on pg`,
174
+ '',
175
+ GENERATED_HEADER,
176
+ ...checks,
177
+ '',
178
+ ].join('\n');
179
+ }
180
+ // ---------------------------------------------------------------------------
181
+ // File writer helper
182
+ // ---------------------------------------------------------------------------
183
+ function writeFile(filePath, content) {
184
+ const dir = join(filePath, '..');
185
+ if (!existsSync(dir))
186
+ mkdirSync(dir, { recursive: true });
187
+ writeFileSync(filePath, content);
188
+ }
189
+ // ---------------------------------------------------------------------------
110
190
  // CLI
111
191
  // ---------------------------------------------------------------------------
112
- function main() {
192
+ async function main() {
113
193
  const args = process.argv.slice(2);
114
194
  const outdirIdx = args.indexOf('--outdir');
115
195
  const outdir = outdirIdx !== -1 ? args[outdirIdx + 1] : undefined;
116
196
  const single = args.includes('--single');
197
+ const pgpmIdx = args.indexOf('--pgpm');
198
+ const pgpmRoot = pgpmIdx !== -1 ? args[pgpmIdx + 1] : undefined;
199
+ // --pgpm mode: generate deploy/revert/verify in pgpm package layout
200
+ if (pgpmRoot) {
201
+ const relPath = 'schemas/metaschema_public/tables/node_type_registry/data/seed.sql';
202
+ const deployPath = join(pgpmRoot, 'deploy', relPath);
203
+ const revertPath = join(pgpmRoot, 'revert', relPath);
204
+ const verifyPath = join(pgpmRoot, 'verify', relPath);
205
+ writeFile(deployPath, await buildDeploySql());
206
+ writeFile(revertPath, buildRevertSql());
207
+ writeFile(verifyPath, buildVerifySql());
208
+ console.log(`Wrote ${allNodeTypes.length} node types to pgpm layout:`);
209
+ console.log(` deploy: ${deployPath}`);
210
+ console.log(` revert: ${revertPath}`);
211
+ console.log(` verify: ${verifyPath}`);
212
+ return;
213
+ }
117
214
  if (single) {
118
215
  // Emit all INSERT statements as a single SQL string
119
216
  const stmts = allNodeTypes.map(buildInsertStmt);
120
- const sql = deparse(stmts);
217
+ const sql = await deparse(stmts);
121
218
  if (outdir) {
122
219
  if (!existsSync(outdir))
123
220
  mkdirSync(outdir, { recursive: true });
@@ -130,10 +227,10 @@ function main() {
130
227
  return;
131
228
  }
132
229
  // Emit individual SQL files per node type
133
- const stmts = allNodeTypes.map((nt) => ({
230
+ const stmts = await Promise.all(allNodeTypes.map(async (nt) => ({
134
231
  nt,
135
- sql: deparse([buildInsertStmt(nt)]),
136
- }));
232
+ sql: await deparse([buildInsertStmt(nt)]),
233
+ })));
137
234
  if (outdir) {
138
235
  if (!existsSync(outdir))
139
236
  mkdirSync(outdir, { recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-type-registry",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Node type definitions for the Constructive blueprint system. Single source of truth for all Authz*, Data*, Relation*, and View* node types.",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "main": "index.js",
@@ -26,7 +26,8 @@
26
26
  "build:dev": "makage build --dev",
27
27
  "lint": "eslint . --fix",
28
28
  "test": "jest",
29
- "test:watch": "jest --watch"
29
+ "test:watch": "jest --watch",
30
+ "generate:seed": "ts-node src/codegen/generate-seed.ts"
30
31
  },
31
32
  "dependencies": {
32
33
  "@pgsql/types": "^17.6.2",
@@ -45,5 +46,5 @@
45
46
  "registry",
46
47
  "graphile"
47
48
  ],
48
- "gitHead": "e86099de99284e17b6e99ccbe8bb1997f808cec5"
49
+ "gitHead": "531237d67de94cbe88bbbbdcecc56ceea120b623"
49
50
  }