@pgpmjs/core 3.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 (140) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +99 -0
  3. package/core/boilerplate-scanner.d.ts +41 -0
  4. package/core/boilerplate-scanner.js +106 -0
  5. package/core/boilerplate-types.d.ts +52 -0
  6. package/core/boilerplate-types.js +6 -0
  7. package/core/class/pgpm.d.ts +150 -0
  8. package/core/class/pgpm.js +1470 -0
  9. package/core/template-scaffold.d.ts +29 -0
  10. package/core/template-scaffold.js +168 -0
  11. package/esm/core/boilerplate-scanner.js +96 -0
  12. package/esm/core/boilerplate-types.js +5 -0
  13. package/esm/core/class/pgpm.js +1430 -0
  14. package/esm/core/template-scaffold.js +161 -0
  15. package/esm/export/export-meta.js +240 -0
  16. package/esm/export/export-migrations.js +180 -0
  17. package/esm/extensions/extensions.js +31 -0
  18. package/esm/files/extension/index.js +3 -0
  19. package/esm/files/extension/reader.js +79 -0
  20. package/esm/files/extension/writer.js +63 -0
  21. package/esm/files/index.js +6 -0
  22. package/esm/files/plan/generator.js +49 -0
  23. package/esm/files/plan/index.js +5 -0
  24. package/esm/files/plan/parser.js +296 -0
  25. package/esm/files/plan/validators.js +181 -0
  26. package/esm/files/plan/writer.js +114 -0
  27. package/esm/files/sql/index.js +1 -0
  28. package/esm/files/sql/writer.js +107 -0
  29. package/esm/files/sql-scripts/index.js +2 -0
  30. package/esm/files/sql-scripts/reader.js +19 -0
  31. package/esm/files/types/index.js +1 -0
  32. package/esm/files/types/package.js +1 -0
  33. package/esm/index.js +21 -0
  34. package/esm/init/client.js +144 -0
  35. package/esm/init/sql/bootstrap-roles.sql +55 -0
  36. package/esm/init/sql/bootstrap-test-roles.sql +72 -0
  37. package/esm/migrate/clean.js +23 -0
  38. package/esm/migrate/client.js +551 -0
  39. package/esm/migrate/index.js +5 -0
  40. package/esm/migrate/sql/procedures.sql +258 -0
  41. package/esm/migrate/sql/schema.sql +37 -0
  42. package/esm/migrate/types.js +1 -0
  43. package/esm/migrate/utils/event-logger.js +28 -0
  44. package/esm/migrate/utils/hash.js +27 -0
  45. package/esm/migrate/utils/transaction.js +125 -0
  46. package/esm/modules/modules.js +49 -0
  47. package/esm/packaging/package.js +96 -0
  48. package/esm/packaging/transform.js +70 -0
  49. package/esm/projects/deploy.js +123 -0
  50. package/esm/projects/revert.js +75 -0
  51. package/esm/projects/verify.js +61 -0
  52. package/esm/resolution/deps.js +526 -0
  53. package/esm/resolution/resolve.js +101 -0
  54. package/esm/utils/debug.js +147 -0
  55. package/esm/utils/target-utils.js +37 -0
  56. package/esm/workspace/paths.js +43 -0
  57. package/esm/workspace/utils.js +31 -0
  58. package/export/export-meta.d.ts +8 -0
  59. package/export/export-meta.js +244 -0
  60. package/export/export-migrations.d.ts +17 -0
  61. package/export/export-migrations.js +187 -0
  62. package/extensions/extensions.d.ts +5 -0
  63. package/extensions/extensions.js +35 -0
  64. package/files/extension/index.d.ts +2 -0
  65. package/files/extension/index.js +19 -0
  66. package/files/extension/reader.d.ts +24 -0
  67. package/files/extension/reader.js +86 -0
  68. package/files/extension/writer.d.ts +39 -0
  69. package/files/extension/writer.js +70 -0
  70. package/files/index.d.ts +5 -0
  71. package/files/index.js +22 -0
  72. package/files/plan/generator.d.ts +22 -0
  73. package/files/plan/generator.js +57 -0
  74. package/files/plan/index.d.ts +4 -0
  75. package/files/plan/index.js +21 -0
  76. package/files/plan/parser.d.ts +27 -0
  77. package/files/plan/parser.js +303 -0
  78. package/files/plan/validators.d.ts +52 -0
  79. package/files/plan/validators.js +187 -0
  80. package/files/plan/writer.d.ts +27 -0
  81. package/files/plan/writer.js +124 -0
  82. package/files/sql/index.d.ts +1 -0
  83. package/files/sql/index.js +17 -0
  84. package/files/sql/writer.d.ts +12 -0
  85. package/files/sql/writer.js +114 -0
  86. package/files/sql-scripts/index.d.ts +1 -0
  87. package/files/sql-scripts/index.js +18 -0
  88. package/files/sql-scripts/reader.d.ts +8 -0
  89. package/files/sql-scripts/reader.js +23 -0
  90. package/files/types/index.d.ts +46 -0
  91. package/files/types/index.js +17 -0
  92. package/files/types/package.d.ts +20 -0
  93. package/files/types/package.js +2 -0
  94. package/index.d.ts +21 -0
  95. package/index.js +45 -0
  96. package/init/client.d.ts +26 -0
  97. package/init/client.js +148 -0
  98. package/init/sql/bootstrap-roles.sql +55 -0
  99. package/init/sql/bootstrap-test-roles.sql +72 -0
  100. package/migrate/clean.d.ts +1 -0
  101. package/migrate/clean.js +27 -0
  102. package/migrate/client.d.ts +80 -0
  103. package/migrate/client.js +555 -0
  104. package/migrate/index.d.ts +5 -0
  105. package/migrate/index.js +21 -0
  106. package/migrate/sql/procedures.sql +258 -0
  107. package/migrate/sql/schema.sql +37 -0
  108. package/migrate/types.d.ts +67 -0
  109. package/migrate/types.js +2 -0
  110. package/migrate/utils/event-logger.d.ts +13 -0
  111. package/migrate/utils/event-logger.js +32 -0
  112. package/migrate/utils/hash.d.ts +12 -0
  113. package/migrate/utils/hash.js +32 -0
  114. package/migrate/utils/transaction.d.ts +27 -0
  115. package/migrate/utils/transaction.js +129 -0
  116. package/modules/modules.d.ts +31 -0
  117. package/modules/modules.js +56 -0
  118. package/package.json +70 -0
  119. package/packaging/package.d.ts +19 -0
  120. package/packaging/package.js +102 -0
  121. package/packaging/transform.d.ts +22 -0
  122. package/packaging/transform.js +75 -0
  123. package/projects/deploy.d.ts +8 -0
  124. package/projects/deploy.js +160 -0
  125. package/projects/revert.d.ts +15 -0
  126. package/projects/revert.js +112 -0
  127. package/projects/verify.d.ts +8 -0
  128. package/projects/verify.js +98 -0
  129. package/resolution/deps.d.ts +57 -0
  130. package/resolution/deps.js +531 -0
  131. package/resolution/resolve.d.ts +37 -0
  132. package/resolution/resolve.js +107 -0
  133. package/utils/debug.d.ts +21 -0
  134. package/utils/debug.js +153 -0
  135. package/utils/target-utils.d.ts +5 -0
  136. package/utils/target-utils.js +40 -0
  137. package/workspace/paths.d.ts +14 -0
  138. package/workspace/paths.js +50 -0
  139. package/workspace/utils.d.ts +8 -0
  140. package/workspace/utils.js +36 -0
@@ -0,0 +1,147 @@
1
+ import { Logger } from '@pgpmjs/logger';
2
+ const log = new Logger('debug');
3
+ export class DebugHelper {
4
+ options;
5
+ constructor(options = { enabled: false }) {
6
+ this.options = {
7
+ logLevel: 'debug',
8
+ showStackTrace: true,
9
+ showQueryParams: true,
10
+ showFullSQL: true,
11
+ ...options
12
+ };
13
+ }
14
+ isEnabled() {
15
+ return this.options.enabled;
16
+ }
17
+ logError(message, error, context) {
18
+ if (!this.options.enabled)
19
+ return;
20
+ log.error(message);
21
+ if (context) {
22
+ log.error('Context:', JSON.stringify(context, null, 2));
23
+ }
24
+ if (error) {
25
+ log.error('Error Details:', {
26
+ code: error.code,
27
+ message: error.message,
28
+ severity: error.severity,
29
+ detail: error.detail,
30
+ hint: error.hint,
31
+ position: error.position,
32
+ where: error.where,
33
+ schema: error.schema,
34
+ table: error.table,
35
+ column: error.column,
36
+ dataType: error.dataType,
37
+ constraint: error.constraint,
38
+ file: error.file,
39
+ line: error.line,
40
+ routine: error.routine
41
+ });
42
+ if (this.options.showStackTrace && error.stack) {
43
+ log.error('Stack Trace:', error.stack);
44
+ }
45
+ }
46
+ }
47
+ logQuery(query, params, duration) {
48
+ if (!this.options.enabled)
49
+ return;
50
+ log.debug(`Query executed in ${duration || 0}ms:`);
51
+ if (this.options.showFullSQL) {
52
+ log.debug('Full SQL:', query);
53
+ }
54
+ else {
55
+ log.debug('SQL Preview:', query.split('\n')[0].trim());
56
+ }
57
+ if (this.options.showQueryParams && params && params.length > 0) {
58
+ log.debug('Parameters:', JSON.stringify(params, null, 2));
59
+ }
60
+ }
61
+ logTransactionStart() {
62
+ if (!this.options.enabled)
63
+ return;
64
+ log.debug('🔄 Transaction started');
65
+ }
66
+ logTransactionCommit(duration) {
67
+ if (!this.options.enabled)
68
+ return;
69
+ log.debug(`✅ Transaction committed in ${duration || 0}ms`);
70
+ }
71
+ logTransactionRollback(duration) {
72
+ if (!this.options.enabled)
73
+ return;
74
+ log.debug(`❌ Transaction rolled back after ${duration || 0}ms`);
75
+ }
76
+ static fromEnvironment() {
77
+ const enabled = process.env.LAUNCHQL_DEBUG === 'true' || process.env.DEBUG === 'launchql*';
78
+ const logLevel = process.env.LAUNCHQL_DEBUG_LEVEL || 'debug';
79
+ const showStackTrace = process.env.LAUNCHQL_DEBUG_STACK !== 'false';
80
+ const showQueryParams = process.env.LAUNCHQL_DEBUG_PARAMS !== 'false';
81
+ const showFullSQL = process.env.LAUNCHQL_DEBUG_SQL !== 'false';
82
+ return new DebugHelper({
83
+ enabled,
84
+ logLevel,
85
+ showStackTrace,
86
+ showQueryParams,
87
+ showFullSQL
88
+ });
89
+ }
90
+ }
91
+ // Global debug instance
92
+ export const debugHelper = DebugHelper.fromEnvironment();
93
+ // Utility functions
94
+ export function enableDebugMode() {
95
+ process.env.LAUNCHQL_DEBUG = 'true';
96
+ process.env.LOG_LEVEL = 'debug';
97
+ log.info('🔍 Debug mode enabled');
98
+ log.info(' Set LAUNCHQL_DEBUG=false to disable');
99
+ log.info(' Set LAUNCHQL_DEBUG_LEVEL=info|warn|error|debug to change log level');
100
+ log.info(' Set LAUNCHQL_DEBUG_STACK=false to hide stack traces');
101
+ log.info(' Set LAUNCHQL_DEBUG_PARAMS=false to hide query parameters');
102
+ log.info(' Set LAUNCHQL_DEBUG_SQL=false to hide full SQL scripts');
103
+ }
104
+ export function createDebugSummary(error, context) {
105
+ const summary = [];
106
+ summary.push('=== LaunchQL Debug Summary ===');
107
+ summary.push('');
108
+ if (error) {
109
+ summary.push('Error Information:');
110
+ summary.push(` Code: ${error.code || 'N/A'}`);
111
+ summary.push(` Message: ${error.message || 'N/A'}`);
112
+ summary.push(` Severity: ${error.severity || 'N/A'}`);
113
+ if (error.detail)
114
+ summary.push(` Detail: ${error.detail}`);
115
+ if (error.hint)
116
+ summary.push(` Hint: ${error.hint}`);
117
+ if (error.position)
118
+ summary.push(` Position: ${error.position}`);
119
+ if (error.where)
120
+ summary.push(` Where: ${error.where}`);
121
+ if (error.schema)
122
+ summary.push(` Schema: ${error.schema}`);
123
+ if (error.table)
124
+ summary.push(` Table: ${error.table}`);
125
+ if (error.column)
126
+ summary.push(` Column: ${error.column}`);
127
+ if (error.constraint)
128
+ summary.push(` Constraint: ${error.constraint}`);
129
+ summary.push('');
130
+ }
131
+ if (context) {
132
+ summary.push('Context:');
133
+ Object.entries(context).forEach(([key, value]) => {
134
+ summary.push(` ${key}: ${JSON.stringify(value)}`);
135
+ });
136
+ summary.push('');
137
+ }
138
+ summary.push('Debugging Tips:');
139
+ summary.push(' 1. Run with LAUNCHQL_DEBUG=true for more details');
140
+ summary.push(' 2. Check the transaction query history above');
141
+ summary.push(' 3. Verify your SQL scripts for syntax errors');
142
+ summary.push(' 4. Ensure dependencies are applied in correct order');
143
+ summary.push(' 5. Check database permissions and schema existence');
144
+ summary.push('');
145
+ summary.push('=== End Debug Summary ===');
146
+ return summary.join('\n');
147
+ }
@@ -0,0 +1,37 @@
1
+ import { errors } from '@pgpmjs/types';
2
+ export function parseTarget(target) {
3
+ if (!target) {
4
+ throw new Error('Target parameter is required');
5
+ }
6
+ if (target.includes(':@')) {
7
+ const atIndex = target.indexOf(':@');
8
+ const beforeAt = target.substring(0, atIndex);
9
+ const afterAt = target.substring(atIndex + 2);
10
+ if (!afterAt) {
11
+ throw errors.INVALID_NAME({ name: target, type: 'tag', rules: 'Expected format: package:@tagName' });
12
+ }
13
+ // Check if this is a simple package:@tag format
14
+ if (!beforeAt.includes(':')) {
15
+ if (!beforeAt) {
16
+ throw errors.INVALID_NAME({ name: target, type: 'tag', rules: 'Expected format: package:@tagName' });
17
+ }
18
+ return { packageName: beforeAt, toChange: `@${afterAt}` };
19
+ }
20
+ throw errors.INVALID_NAME({ name: target, type: 'change', rules: 'Expected formats: package, package:changeName, or package:@tagName' });
21
+ }
22
+ if (target.includes(':') && !target.includes('@')) {
23
+ const parts = target.split(':');
24
+ if (parts.length > 2) {
25
+ throw errors.INVALID_NAME({ name: target, type: 'change', rules: 'Expected formats: package, package:changeName, or package:@tagName' });
26
+ }
27
+ const [packageName, changeName] = parts;
28
+ if (!packageName || !changeName) {
29
+ throw errors.INVALID_NAME({ name: target, type: 'change', rules: 'Expected format: package:changeName' });
30
+ }
31
+ return { packageName, toChange: changeName };
32
+ }
33
+ if (!target.includes(':')) {
34
+ return { packageName: target, toChange: undefined };
35
+ }
36
+ throw errors.INVALID_NAME({ name: target, type: 'change', rules: 'Expected formats: package, package:changeName, or package:@tagName' });
37
+ }
@@ -0,0 +1,43 @@
1
+ import { walkUp } from './utils';
2
+ const PROJECT_FILES = {
3
+ PLAN: 'pgpm.plan',
4
+ LAUNCHQL: 'pgpm.json',
5
+ };
6
+ /**
7
+ * Finds the module path by looking for pgpm.plan.
8
+ * @param cwd - Current working directory.
9
+ * @returns A promise that resolves to the directory path containing `pgpm.plan`.
10
+ */
11
+ export const modulePath = (cwd = process.cwd()) => {
12
+ return walkUp(cwd, PROJECT_FILES.PLAN);
13
+ };
14
+ /**
15
+ * Finds the LaunchQL project path.
16
+ * @param cwd - Current working directory.
17
+ * @returns A promise that resolves to the directory path containing `pgpm.json`.
18
+ */
19
+ export const launchqlPath = (cwd = process.cwd()) => {
20
+ return walkUp(cwd, PROJECT_FILES.LAUNCHQL);
21
+ };
22
+ export const getWorkspacePath = (cwd) => {
23
+ let workspacePath;
24
+ try {
25
+ workspacePath = launchqlPath(cwd);
26
+ }
27
+ catch (err) {
28
+ console.error('Error: You must be in a LaunchQL workspace. You can initialize one with `lql init workspace` (or `pgpm init workspace`).');
29
+ process.exit(1);
30
+ }
31
+ return workspacePath;
32
+ };
33
+ export const getModulePath = (cwd) => {
34
+ let pkgPath;
35
+ try {
36
+ pkgPath = modulePath(cwd);
37
+ }
38
+ catch (err) {
39
+ console.error('Error: You must be in a LaunchQL module. You can initialize one with the `init` command.');
40
+ process.exit(1);
41
+ }
42
+ return pkgPath;
43
+ };
@@ -0,0 +1,31 @@
1
+ import { existsSync } from 'fs';
2
+ import { dirname, resolve } from 'path';
3
+ import { errors } from '@pgpmjs/types';
4
+ /**
5
+ * Recursively walks up directories to find a specific file (sync version).
6
+ * @param startDir - Starting directory.
7
+ * @param filename - The target file to search for.
8
+ * @returns The directory path containing the file.
9
+ */
10
+ export const walkUp = (startDir, filename) => {
11
+ let currentDir = resolve(startDir);
12
+ while (currentDir) {
13
+ const targetPath = resolve(currentDir, filename);
14
+ if (existsSync(targetPath)) {
15
+ return currentDir;
16
+ }
17
+ const parentDir = dirname(currentDir);
18
+ if (parentDir === currentDir) {
19
+ break;
20
+ }
21
+ currentDir = parentDir;
22
+ }
23
+ throw errors.FILE_NOT_FOUND({ filePath: filename, type: 'configuration' });
24
+ };
25
+ export const sluggify = (text) => {
26
+ return text.toString().toLowerCase().trim()
27
+ .replace(/\s+/g, '-') // Replace spaces with -
28
+ .replace(/&/g, '-and-') // Replace & with 'and'
29
+ .replace(/[^\w\-]+/g, '') // Remove all non-word chars
30
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
31
+ };
@@ -0,0 +1,8 @@
1
+ import { PgpmOptions } from '@pgpmjs/types';
2
+ interface ExportMetaParams {
3
+ opts: PgpmOptions;
4
+ dbname: string;
5
+ database_id: string;
6
+ }
7
+ export declare const exportMeta: ({ opts, dbname, database_id }: ExportMetaParams) => Promise<string>;
8
+ export {};
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportMeta = void 0;
4
+ const csv_to_pg_1 = require("csv-to-pg");
5
+ const pg_cache_1 = require("pg-cache");
6
+ const config = {
7
+ database: {
8
+ schema: 'collections_public',
9
+ table: 'database',
10
+ fields: {
11
+ id: 'uuid',
12
+ owner_id: 'uuid',
13
+ name: 'text',
14
+ hash: 'uuid'
15
+ }
16
+ },
17
+ database_extension: {
18
+ schema: 'collections_public',
19
+ table: 'database_extensions',
20
+ fields: {
21
+ name: 'text',
22
+ database_id: 'uuid'
23
+ }
24
+ },
25
+ schema: {
26
+ schema: 'collections_public',
27
+ table: 'schema',
28
+ fields: {
29
+ id: 'uuid',
30
+ database_id: 'uuid',
31
+ name: 'text',
32
+ schema_name: 'text',
33
+ description: 'text'
34
+ }
35
+ },
36
+ table: {
37
+ schema: 'collections_public',
38
+ table: 'table',
39
+ fields: {
40
+ id: 'uuid',
41
+ database_id: 'uuid',
42
+ schema_id: 'uuid',
43
+ name: 'text',
44
+ description: 'text'
45
+ }
46
+ },
47
+ field: {
48
+ schema: 'collections_public',
49
+ table: 'field',
50
+ fields: {
51
+ id: 'uuid',
52
+ database_id: 'uuid',
53
+ table_id: 'uuid',
54
+ name: 'text',
55
+ type: 'text',
56
+ description: 'text'
57
+ }
58
+ },
59
+ domains: {
60
+ schema: 'meta_public',
61
+ table: 'domains',
62
+ fields: {
63
+ id: 'uuid',
64
+ database_id: 'uuid',
65
+ site_id: 'uuid',
66
+ api_id: 'uuid',
67
+ domain: 'text',
68
+ subdomain: 'text'
69
+ }
70
+ },
71
+ sites: {
72
+ schema: 'meta_public',
73
+ table: 'sites',
74
+ fields: {
75
+ id: 'uuid',
76
+ database_id: 'uuid',
77
+ title: 'text',
78
+ description: 'text',
79
+ og_image: 'image',
80
+ favicon: 'upload',
81
+ apple_touch_icon: 'image',
82
+ logo: 'image',
83
+ dbname: 'text'
84
+ }
85
+ },
86
+ apis: {
87
+ schema: 'meta_public',
88
+ table: 'apis',
89
+ fields: {
90
+ id: 'uuid',
91
+ database_id: 'uuid',
92
+ name: 'text',
93
+ dbname: 'text',
94
+ is_public: 'boolean',
95
+ role_name: 'text',
96
+ anon_role: 'text'
97
+ }
98
+ },
99
+ apps: {
100
+ schema: 'meta_public',
101
+ table: 'apps',
102
+ fields: {
103
+ id: 'uuid',
104
+ database_id: 'uuid',
105
+ site_id: 'uuid',
106
+ name: 'text',
107
+ app_image: 'image',
108
+ app_store_link: 'url',
109
+ app_store_id: 'text',
110
+ app_id_prefix: 'text',
111
+ play_store_link: 'url'
112
+ }
113
+ },
114
+ site_modules: {
115
+ schema: 'meta_public',
116
+ table: 'site_modules',
117
+ fields: {
118
+ id: 'uuid',
119
+ database_id: 'uuid',
120
+ site_id: 'uuid',
121
+ name: 'text',
122
+ data: 'jsonb'
123
+ }
124
+ },
125
+ site_themes: {
126
+ schema: 'meta_public',
127
+ table: 'site_themes',
128
+ fields: {
129
+ id: 'uuid',
130
+ database_id: 'uuid',
131
+ site_id: 'uuid',
132
+ theme: 'jsonb'
133
+ }
134
+ },
135
+ api_modules: {
136
+ schema: 'meta_public',
137
+ table: 'api_modules',
138
+ fields: {
139
+ id: 'uuid',
140
+ database_id: 'uuid',
141
+ api_id: 'uuid',
142
+ name: 'text',
143
+ data: 'jsonb'
144
+ }
145
+ },
146
+ api_extensions: {
147
+ schema: 'meta_public',
148
+ table: 'api_extensions',
149
+ fields: {
150
+ id: 'uuid',
151
+ database_id: 'uuid',
152
+ api_id: 'uuid',
153
+ schema_name: 'text'
154
+ }
155
+ },
156
+ api_schemata: {
157
+ schema: 'meta_public',
158
+ table: 'api_schemata',
159
+ fields: {
160
+ id: 'uuid',
161
+ database_id: 'uuid',
162
+ schema_id: 'uuid',
163
+ api_id: 'uuid'
164
+ }
165
+ },
166
+ rls_module: {
167
+ schema: 'meta_public',
168
+ table: 'rls_module',
169
+ fields: {
170
+ id: 'uuid',
171
+ database_id: 'uuid',
172
+ api_id: 'uuid',
173
+ schema_id: 'uuid',
174
+ private_schema_id: 'uuid',
175
+ tokens_table_id: 'uuid',
176
+ users_table_id: 'uuid',
177
+ authenticate: 'text',
178
+ authenticate_strict: 'text',
179
+ current_role: 'text',
180
+ current_role_id: 'text'
181
+ }
182
+ },
183
+ user_auth_module: {
184
+ schema: 'meta_public',
185
+ table: 'user_auth_module',
186
+ fields: {
187
+ id: 'uuid',
188
+ database_id: 'uuid',
189
+ schema_id: 'uuid',
190
+ emails_table_id: 'uuid',
191
+ users_table_id: 'uuid',
192
+ secrets_table_id: 'uuid',
193
+ encrypted_table_id: 'uuid',
194
+ tokens_table_id: 'uuid',
195
+ sign_in_function: 'text',
196
+ sign_up_function: 'text',
197
+ sign_out_function: 'text',
198
+ sign_in_one_time_token_function: 'text',
199
+ one_time_token_function: 'text',
200
+ extend_token_expires: 'text',
201
+ send_account_deletion_email_function: 'text',
202
+ delete_account_function: 'text',
203
+ set_password_function: 'text',
204
+ reset_password_function: 'text',
205
+ forgot_password_function: 'text',
206
+ send_verification_email_function: 'text',
207
+ verify_email_function: 'text'
208
+ }
209
+ }
210
+ };
211
+ const exportMeta = async ({ opts, dbname, database_id }) => {
212
+ const pool = (0, pg_cache_1.getPgPool)({
213
+ ...opts.pg,
214
+ database: dbname
215
+ });
216
+ const sql = {};
217
+ const parsers = Object.entries(config).reduce((m, [name, config]) => {
218
+ m[name] = new csv_to_pg_1.Parser(config);
219
+ return m;
220
+ }, {});
221
+ const queryAndParse = async (key, query) => {
222
+ const result = await pool.query(query, [database_id]);
223
+ if (result.rows.length) {
224
+ sql[key] = await parsers[key].parse(result.rows);
225
+ }
226
+ };
227
+ await queryAndParse('database', `SELECT * FROM collections_public.database WHERE id = $1`);
228
+ await queryAndParse('schema', `SELECT * FROM collections_public.schema WHERE database_id = $1`);
229
+ await queryAndParse('table', `SELECT * FROM collections_public.table WHERE database_id = $1`);
230
+ await queryAndParse('domains', `SELECT * FROM meta_public.domains WHERE database_id = $1`);
231
+ await queryAndParse('apis', `SELECT * FROM meta_public.apis WHERE database_id = $1`);
232
+ await queryAndParse('sites', `SELECT * FROM meta_public.sites WHERE database_id = $1`);
233
+ await queryAndParse('api_modules', `SELECT * FROM meta_public.api_modules WHERE database_id = $1`);
234
+ await queryAndParse('site_modules', `SELECT * FROM meta_public.site_modules WHERE database_id = $1`);
235
+ await queryAndParse('site_themes', `SELECT * FROM meta_public.site_themes WHERE database_id = $1`);
236
+ await queryAndParse('apps', `SELECT * FROM meta_public.apps WHERE database_id = $1`);
237
+ await queryAndParse('database_extension', `SELECT * FROM collections_public.database_extension WHERE database_id = $1`);
238
+ await queryAndParse('api_extensions', `SELECT * FROM meta_public.api_extensions WHERE database_id = $1`);
239
+ await queryAndParse('api_schemata', `SELECT * FROM meta_public.api_schemata WHERE database_id = $1`);
240
+ await queryAndParse('rls_module', `SELECT * FROM meta_public.rls_module WHERE database_id = $1`);
241
+ await queryAndParse('user_auth_module', `SELECT * FROM meta_public.user_auth_module WHERE database_id = $1`);
242
+ return Object.entries(sql).reduce((m, [_, v]) => m + '\n\n' + v, '');
243
+ };
244
+ exports.exportMeta = exportMeta;
@@ -0,0 +1,17 @@
1
+ import { PgpmOptions } from '@pgpmjs/types';
2
+ import { PgpmPackage } from '../core/class/pgpm';
3
+ interface ExportOptions {
4
+ project: PgpmPackage;
5
+ options: PgpmOptions;
6
+ dbInfo: {
7
+ dbname: string;
8
+ database_ids: string[];
9
+ };
10
+ author: string;
11
+ outdir: string;
12
+ schema_names: string[];
13
+ extensionName?: string;
14
+ metaExtensionName: string;
15
+ }
16
+ export declare const exportMigrations: ({ project, options, dbInfo, author, outdir, schema_names, extensionName, metaExtensionName }: ExportOptions) => Promise<void>;
17
+ export {};