@pgpmjs/export 0.26.8 → 0.28.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.
@@ -4,6 +4,7 @@ import { toSnakeCase } from 'inflekt';
4
4
  import path from 'path';
5
5
  import { PgpmPackage, getMissingInstallableModules, parseAuthor } from '@pgpmjs/core';
6
6
  import { lookupByPgUdt } from './type-map';
7
+ import metaExportTables from './meta-export-tables.json';
7
8
  // =============================================================================
8
9
  // Shared constants
9
10
  // =============================================================================
@@ -81,206 +82,17 @@ $LQLMIGRATION$;`;
81
82
  export const META_COMMON_FOOTER = `
82
83
  SET session_replication_role TO DEFAULT;`;
83
84
  /**
84
- * Ordered list of meta tables for export.
85
- * Tables are processed in this order to satisfy foreign key dependencies.
85
+ * Hand-authored per-table overrides layered on top of the generated
86
+ * table manifest. Only exceptional exporter behavior lives here:
87
+ * conflict handling, special field types (image, upload, url) that
88
+ * cannot be inferred, GraphQL type name overrides, and columns whose
89
+ * values must come from DDL defaults at deploy time.
86
90
  */
87
- export const META_TABLE_ORDER = [
88
- 'database',
89
- 'schema',
90
- 'function',
91
- 'table',
92
- 'field',
93
- 'spatial_relation',
94
- 'policy',
95
- 'index',
96
- 'trigger',
97
- 'trigger_function',
98
- 'rls_function',
99
- 'foreign_key_constraint',
100
- 'primary_key_constraint',
101
- 'unique_constraint',
102
- 'check_constraint',
103
- 'full_text_search',
104
- 'schema_grant',
105
- 'table_grant',
106
- 'default_privilege',
107
- 'domains',
108
- 'sites',
109
- 'apis',
110
- 'apps',
111
- 'site_modules',
112
- 'site_themes',
113
- 'site_metadata',
114
- 'api_modules',
115
- 'api_extensions',
116
- 'api_schemas',
117
- 'database_settings',
118
- 'api_settings',
119
- 'rls_settings',
120
- 'cors_settings',
121
- 'pubkey_settings',
122
- 'webauthn_settings',
123
- 'rls_module',
124
- 'user_auth_module',
125
- 'memberships_module',
126
- 'permissions_module',
127
- 'limits_module',
128
- 'levels_module',
129
- 'events_module',
130
- 'users_module',
131
- 'hierarchy_module',
132
- 'membership_types_module',
133
- 'invites_module',
134
- 'emails_module',
135
- 'sessions_module',
136
- 'user_state_module',
137
- 'profiles_module',
138
- 'config_secrets_user_module',
139
- 'user_credentials_module',
140
- 'user_settings_module',
141
- 'connected_accounts_module',
142
- 'phone_numbers_module',
143
- 'crypto_addresses_module',
144
- 'crypto_auth_module',
145
- 'field_module',
146
- 'table_module',
147
- 'secure_table_provision',
148
- 'uuid_module',
149
- 'default_ids_module',
150
- 'denormalized_table_field',
151
- // NOTE: blueprint_template, blueprint, and blueprint_construction are intentionally
152
- // excluded from the export flow — they are runtime-only tables not exported as metadata.
153
- 'relation_provision',
154
- 'entity_type_provision',
155
- 'rate_limits_module',
156
- 'storage_module',
157
- 'billing_module',
158
- 'billing_provider_module',
159
- 'devices_module',
160
- 'identity_providers_module',
161
- 'notifications_module',
162
- 'plans_module',
163
- 'realtime_module',
164
- 'session_secrets_module',
165
- 'infra_secrets_module',
166
- 'infra_config_module',
167
- 'internal_secrets_module',
168
- 'i18n_module',
169
- 'agent_module',
170
- 'function_module',
171
- 'namespace_module',
172
- 'merkle_store_module',
173
- 'graph_module',
174
- 'graph_execution_module',
175
- 'function_deployment_module',
176
- 'function_invocation_module',
177
- 'compute_log_module',
178
- 'db_usage_module',
179
- 'storage_log_module',
180
- 'transfer_log_module',
181
- 'webauthn_auth_module',
182
- 'webauthn_credentials_module',
183
- 'inference_log_module',
184
- 'rate_limit_meters_module'
185
- ];
186
- /**
187
- * Shared metadata table configuration.
188
- *
189
- * Fields are discovered dynamically at runtime via introspection:
190
- * - SQL flow: uses information_schema.columns + mapPgTypeToFieldType()
191
- * - GraphQL flow: uses __type introspection + mapGraphQLTypeToFieldType()
192
- *
193
- * Only `typeOverrides` are hardcoded for special types (image, upload, url)
194
- * that cannot be inferred from database/GraphQL types alone.
195
- *
196
- */
197
- export const META_TABLE_CONFIG = {
198
- // =============================================================================
199
- // metaschema_public tables
200
- // =============================================================================
201
- database: {
202
- schema: 'metaschema_public',
203
- table: 'database'
204
- },
205
- schema: {
206
- schema: 'metaschema_public',
207
- table: 'schema'
208
- },
209
- function: {
210
- schema: 'metaschema_public',
211
- table: 'function'
212
- },
213
- table: {
214
- schema: 'metaschema_public',
215
- table: 'table'
216
- },
91
+ export const META_TABLE_OVERRIDES = {
217
92
  field: {
218
- schema: 'metaschema_public',
219
- table: 'field',
220
93
  conflictDoNothing: true
221
94
  },
222
- policy: {
223
- schema: 'metaschema_public',
224
- table: 'policy'
225
- },
226
- index: {
227
- schema: 'metaschema_public',
228
- table: 'index'
229
- },
230
- trigger: {
231
- schema: 'metaschema_public',
232
- table: 'trigger'
233
- },
234
- trigger_function: {
235
- schema: 'metaschema_public',
236
- table: 'trigger_function'
237
- },
238
- rls_function: {
239
- schema: 'metaschema_public',
240
- table: 'rls_function'
241
- },
242
- foreign_key_constraint: {
243
- schema: 'metaschema_public',
244
- table: 'foreign_key_constraint'
245
- },
246
- primary_key_constraint: {
247
- schema: 'metaschema_public',
248
- table: 'primary_key_constraint'
249
- },
250
- unique_constraint: {
251
- schema: 'metaschema_public',
252
- table: 'unique_constraint'
253
- },
254
- check_constraint: {
255
- schema: 'metaschema_public',
256
- table: 'check_constraint'
257
- },
258
- full_text_search: {
259
- schema: 'metaschema_public',
260
- table: 'full_text_search'
261
- },
262
- schema_grant: {
263
- schema: 'metaschema_public',
264
- table: 'schema_grant'
265
- },
266
- table_grant: {
267
- schema: 'metaschema_public',
268
- table: 'table_grant'
269
- },
270
- default_privilege: {
271
- schema: 'metaschema_public',
272
- table: 'default_privilege'
273
- },
274
- // =============================================================================
275
- // services_public tables
276
- // =============================================================================
277
- domains: {
278
- schema: 'services_public',
279
- table: 'domains'
280
- },
281
95
  sites: {
282
- schema: 'services_public',
283
- table: 'sites',
284
96
  typeOverrides: {
285
97
  og_image: 'image',
286
98
  favicon: 'upload',
@@ -292,322 +104,47 @@ export const META_TABLE_CONFIG = {
292
104
  }
293
105
  },
294
106
  apis: {
295
- schema: 'services_public',
296
- table: 'apis',
297
107
  columnDefaults: {
298
108
  dbname: 'current_database()'
299
109
  }
300
110
  },
301
111
  apps: {
302
- schema: 'services_public',
303
- table: 'apps',
304
112
  typeOverrides: {
305
113
  app_image: 'image',
306
114
  app_store_link: 'url',
307
115
  play_store_link: 'url'
308
116
  }
309
117
  },
310
- site_modules: {
311
- schema: 'services_public',
312
- table: 'site_modules'
313
- },
314
- site_themes: {
315
- schema: 'services_public',
316
- table: 'site_themes'
317
- },
318
118
  site_metadata: {
319
- schema: 'services_public',
320
- table: 'site_metadata',
321
119
  typeOverrides: {
322
120
  og_image: 'image'
323
121
  }
324
122
  },
325
- api_modules: {
326
- schema: 'services_public',
327
- table: 'api_modules'
328
- },
329
- api_extensions: {
330
- schema: 'services_public',
331
- table: 'api_extensions'
332
- },
333
- api_schemas: {
334
- schema: 'services_public',
335
- table: 'api_schemas'
336
- },
337
- database_settings: {
338
- schema: 'services_public',
339
- table: 'database_settings'
340
- },
341
- api_settings: {
342
- schema: 'services_public',
343
- table: 'api_settings'
344
- },
345
- rls_settings: {
346
- schema: 'services_public',
347
- table: 'rls_settings'
348
- },
349
- cors_settings: {
350
- schema: 'services_public',
351
- table: 'cors_settings'
352
- },
353
- pubkey_settings: {
354
- schema: 'services_public',
355
- table: 'pubkey_settings'
356
- },
357
- webauthn_settings: {
358
- schema: 'services_public',
359
- table: 'webauthn_settings'
360
- },
361
- // =============================================================================
362
- // metaschema_modules_public tables
363
- // =============================================================================
364
- rls_module: {
365
- schema: 'metaschema_modules_public',
366
- table: 'rls_module'
367
- },
368
- user_auth_module: {
369
- schema: 'metaschema_modules_public',
370
- table: 'user_auth_module'
371
- },
372
- memberships_module: {
373
- schema: 'metaschema_modules_public',
374
- table: 'memberships_module'
375
- },
376
- permissions_module: {
377
- schema: 'metaschema_modules_public',
378
- table: 'permissions_module'
379
- },
380
- limits_module: {
381
- schema: 'metaschema_modules_public',
382
- table: 'limits_module'
383
- },
384
- levels_module: {
385
- schema: 'metaschema_modules_public',
386
- table: 'levels_module'
387
- },
388
- events_module: {
389
- schema: 'metaschema_modules_public',
390
- table: 'events_module'
391
- },
392
- users_module: {
393
- schema: 'metaschema_modules_public',
394
- table: 'users_module'
395
- },
396
- hierarchy_module: {
397
- schema: 'metaschema_modules_public',
398
- table: 'hierarchy_module'
399
- },
400
- membership_types_module: {
401
- schema: 'metaschema_modules_public',
402
- table: 'membership_types_module'
403
- },
404
- invites_module: {
405
- schema: 'metaschema_modules_public',
406
- table: 'invites_module'
407
- },
408
- emails_module: {
409
- schema: 'metaschema_modules_public',
410
- table: 'emails_module'
411
- },
412
- sessions_module: {
413
- schema: 'metaschema_modules_public',
414
- table: 'sessions_module'
415
- },
416
- user_state_module: {
417
- schema: 'metaschema_modules_public',
418
- table: 'user_state_module'
419
- },
420
- profiles_module: {
421
- schema: 'metaschema_modules_public',
422
- table: 'profiles_module'
423
- },
424
- config_secrets_user_module: {
425
- schema: 'metaschema_modules_public',
426
- table: 'config_secrets_user_module'
427
- },
428
- user_credentials_module: {
429
- schema: 'metaschema_modules_public',
430
- table: 'user_credentials_module'
431
- },
432
- user_settings_module: {
433
- schema: 'metaschema_modules_public',
434
- table: 'user_settings_module'
435
- },
436
- connected_accounts_module: {
437
- schema: 'metaschema_modules_public',
438
- table: 'connected_accounts_module'
439
- },
440
- phone_numbers_module: {
441
- schema: 'metaschema_modules_public',
442
- table: 'phone_numbers_module'
443
- },
444
- crypto_addresses_module: {
445
- schema: 'metaschema_modules_public',
446
- table: 'crypto_addresses_module'
447
- },
448
- crypto_auth_module: {
449
- schema: 'metaschema_modules_public',
450
- table: 'crypto_auth_module'
451
- },
452
- field_module: {
453
- schema: 'metaschema_modules_public',
454
- table: 'field_module'
455
- },
456
- table_module: {
457
- schema: 'metaschema_modules_public',
458
- table: 'table_module'
459
- },
460
- // NOTE: table_template_module has been removed from pgpm-modules (superseded by blueprints)
461
- secure_table_provision: {
462
- schema: 'metaschema_modules_public',
463
- table: 'secure_table_provision'
464
- },
465
- uuid_module: {
466
- schema: 'metaschema_modules_public',
467
- table: 'uuid_module'
468
- },
469
- default_ids_module: {
470
- schema: 'metaschema_modules_public',
471
- table: 'default_ids_module'
472
- },
473
- denormalized_table_field: {
474
- schema: 'metaschema_modules_public',
475
- table: 'denormalized_table_field'
476
- },
477
- relation_provision: {
478
- schema: 'metaschema_modules_public',
479
- table: 'relation_provision'
480
- },
481
- entity_type_provision: {
482
- schema: 'metaschema_modules_public',
483
- table: 'entity_type_provision'
484
- },
485
- rate_limits_module: {
486
- schema: 'metaschema_modules_public',
487
- table: 'rate_limits_module'
488
- },
489
- storage_module: {
490
- schema: 'metaschema_modules_public',
491
- table: 'storage_module'
492
- },
493
- billing_module: {
494
- schema: 'metaschema_modules_public',
495
- table: 'billing_module'
496
- },
497
- billing_provider_module: {
498
- schema: 'metaschema_modules_public',
499
- table: 'billing_provider_module'
500
- },
501
- devices_module: {
502
- schema: 'metaschema_modules_public',
503
- table: 'devices_module'
504
- },
505
- identity_providers_module: {
506
- schema: 'metaschema_modules_public',
507
- table: 'identity_providers_module'
508
- },
509
- notifications_module: {
510
- schema: 'metaschema_modules_public',
511
- table: 'notifications_module'
512
- },
513
- plans_module: {
514
- schema: 'metaschema_modules_public',
515
- table: 'plans_module'
516
- },
517
- realtime_module: {
518
- schema: 'metaschema_modules_public',
519
- table: 'realtime_module'
520
- },
521
- session_secrets_module: {
522
- schema: 'metaschema_modules_public',
523
- table: 'session_secrets_module'
524
- },
525
- infra_secrets_module: {
526
- schema: 'metaschema_modules_public',
527
- table: 'infra_secrets_module'
528
- },
529
- infra_config_module: {
530
- schema: 'metaschema_modules_public',
531
- table: 'infra_config_module'
532
- },
533
- internal_secrets_module: {
534
- schema: 'metaschema_modules_public',
535
- table: 'internal_secrets_module'
536
- },
537
123
  i18n_module: {
538
- schema: 'metaschema_modules_public',
539
- table: 'i18n_module',
540
124
  gqlTypeName: 'I18NModule' // i18n is a well-known abbreviation; PostGraphile inflector capitalizes the N
541
- },
542
- agent_module: {
543
- schema: 'metaschema_modules_public',
544
- table: 'agent_module'
545
- },
546
- function_module: {
547
- schema: 'metaschema_modules_public',
548
- table: 'function_module'
549
- },
550
- namespace_module: {
551
- schema: 'metaschema_modules_public',
552
- table: 'namespace_module'
553
- },
554
- merkle_store_module: {
555
- schema: 'metaschema_modules_public',
556
- table: 'merkle_store_module'
557
- },
558
- graph_module: {
559
- schema: 'metaschema_modules_public',
560
- table: 'graph_module'
561
- },
562
- graph_execution_module: {
563
- schema: 'metaschema_modules_public',
564
- table: 'graph_execution_module'
565
- },
566
- function_deployment_module: {
567
- schema: 'metaschema_modules_public',
568
- table: 'function_deployment_module'
569
- },
570
- function_invocation_module: {
571
- schema: 'metaschema_modules_public',
572
- table: 'function_invocation_module'
573
- },
574
- compute_log_module: {
575
- schema: 'metaschema_modules_public',
576
- table: 'compute_log_module'
577
- },
578
- db_usage_module: {
579
- schema: 'metaschema_modules_public',
580
- table: 'db_usage_module'
581
- },
582
- storage_log_module: {
583
- schema: 'metaschema_modules_public',
584
- table: 'storage_log_module'
585
- },
586
- transfer_log_module: {
587
- schema: 'metaschema_modules_public',
588
- table: 'transfer_log_module'
589
- },
590
- webauthn_auth_module: {
591
- schema: 'metaschema_modules_public',
592
- table: 'webauthn_auth_module'
593
- },
594
- webauthn_credentials_module: {
595
- schema: 'metaschema_modules_public',
596
- table: 'webauthn_credentials_module'
597
- },
598
- inference_log_module: {
599
- schema: 'metaschema_modules_public',
600
- table: 'inference_log_module',
601
- },
602
- rate_limit_meters_module: {
603
- schema: 'metaschema_modules_public',
604
- table: 'rate_limit_meters_module',
605
- },
606
- spatial_relation: {
607
- schema: 'metaschema_public',
608
- table: 'spatial_relation'
609
125
  }
610
126
  };
127
+ /**
128
+ * Ordered list of meta tables for export, derived from the generated
129
+ * manifest. Tables are already topologically sorted by foreign key
130
+ * dependencies at generation time.
131
+ */
132
+ export const META_TABLE_ORDER = metaExportTables.tables.map(t => t.key);
133
+ /**
134
+ * Shared metadata table configuration, built from the generated manifest
135
+ * plus META_TABLE_OVERRIDES.
136
+ *
137
+ * Fields are discovered dynamically at runtime via introspection:
138
+ * - SQL flow: uses information_schema.columns + mapPgTypeToFieldType()
139
+ * - GraphQL flow: uses __type introspection + mapGraphQLTypeToFieldType()
140
+ *
141
+ * Only `typeOverrides` are hardcoded for special types (image, upload, url)
142
+ * that cannot be inferred from database/GraphQL types alone.
143
+ */
144
+ export const META_TABLE_CONFIG = Object.fromEntries(metaExportTables.tables.map(t => [
145
+ t.key,
146
+ { schema: t.schema, table: t.table, ...META_TABLE_OVERRIDES[t.key] }
147
+ ]));
611
148
  // =============================================================================
612
149
  // Shared functions
613
150
  // =============================================================================
package/esm/index.js CHANGED
@@ -4,6 +4,6 @@ export * from './export-graphql';
4
4
  export * from './export-graphql-meta';
5
5
  export { GraphQLClient } from './graphql-client';
6
6
  export { getGraphQLQueryName, getGraphQLTypeName, graphqlRowToPostgresRow, buildFieldsFragment, mapGraphQLTypeToFieldType, unwrapGraphQLType } from './graphql-naming';
7
- export { DB_REQUIRED_EXTENSIONS, SERVICE_REQUIRED_EXTENSIONS, META_COMMON_HEADER, META_COMMON_FOOTER, META_TABLE_ORDER, META_TABLE_CONFIG, mapPgTypeToFieldType, makeReplacer, preparePackage, normalizeOutdir, detectMissingModules, installMissingModules } from './export-utils';
7
+ export { DB_REQUIRED_EXTENSIONS, SERVICE_REQUIRED_EXTENSIONS, META_COMMON_HEADER, META_COMMON_FOOTER, META_TABLE_ORDER, META_TABLE_CONFIG, META_TABLE_OVERRIDES, mapPgTypeToFieldType, makeReplacer, preparePackage, normalizeOutdir, detectMissingModules, installMissingModules } from './export-utils';
8
8
  export { PG_TYPE_MAP, lookupByPgUdt, lookupByGqlType } from './type-map';
9
9
  export { intervalToPostgres, parsePgInterval } from './interval-utils';