pgflow 0.1.9 → 0.1.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/compile/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;kCAkChB,OAAO;AAAhC,wBA4EE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/compile/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;kCAkChB,OAAO;AAAhC,wBAoHE"}
@@ -35,6 +35,7 @@ export default (program) => {
35
35
  .description('Compiles a TypeScript-defined flow into SQL migration')
36
36
  .argument('<flowPath>', 'Path to the flow TypeScript file')
37
37
  .option('--deno-json <denoJsonPath>', 'Path to deno.json with valid importMap')
38
+ .option('--supabase-path <supabasePath>', 'Path to the Supabase folder')
38
39
  .action(async (flowPath, options) => {
39
40
  intro('pgflow - Compile Flow to SQL');
40
41
  try {
@@ -55,17 +56,43 @@ export default (program) => {
55
56
  log.error(`Flow file not found: ${resolvedFlowPath}`);
56
57
  process.exit(1);
57
58
  }
59
+ // Validate Supabase path
60
+ let supabasePath;
61
+ if (options.supabasePath) {
62
+ supabasePath = path.resolve(process.cwd(), options.supabasePath);
63
+ }
64
+ else {
65
+ // Default to ./supabase/ if not provided
66
+ supabasePath = path.resolve(process.cwd(), 'supabase');
67
+ }
68
+ // Check if Supabase path exists
69
+ if (!fs.existsSync(supabasePath)) {
70
+ log.error(`Supabase directory not found: ${supabasePath}\n` +
71
+ `Please provide a valid Supabase path using --supabase-path option or ensure ./supabase/ directory exists.`);
72
+ process.exit(1);
73
+ }
58
74
  // Find the internal_compile.js script
59
- const internalCompileScript = path.resolve(__dirname, '../../../deno/internal_compile.js');
75
+ const internalCompileScript = path.resolve(__dirname, '../../deno/internal_compile.js');
60
76
  // Create migrations directory if it doesn't exist
61
- const migrationsDir = path.resolve(process.cwd(), 'migrations');
77
+ const migrationsDir = path.resolve(supabasePath, 'migrations');
62
78
  if (!fs.existsSync(migrationsDir)) {
63
79
  fs.mkdirSync(migrationsDir, { recursive: true });
64
80
  log.info(`Created migrations directory: ${migrationsDir}`);
65
81
  }
66
- // Generate timestamp for migration file
67
- const timestamp = new Date().toISOString().replace(/[:.]/g, '_');
68
- const migrationFileName = `pgflow_${timestamp}.sql`;
82
+ // Generate timestamp for migration file in format YYYYMMDDHHMMSS
83
+ const now = new Date();
84
+ const timestamp = [
85
+ now.getFullYear(),
86
+ String(now.getMonth() + 1).padStart(2, '0'),
87
+ String(now.getDate()).padStart(2, '0'),
88
+ String(now.getHours()).padStart(2, '0'),
89
+ String(now.getMinutes()).padStart(2, '0'),
90
+ String(now.getSeconds()).padStart(2, '0'),
91
+ ].join('');
92
+ // Extract the base filename without extension from the flow path
93
+ const flowBasename = path.basename(resolvedFlowPath, path.extname(resolvedFlowPath));
94
+ // Create migration filename in the format: <timestamp>_create_<flow_file_basename>_flow.sql
95
+ const migrationFileName = `${timestamp}_create_${flowBasename}_flow.sql`;
69
96
  const migrationFilePath = path.join(migrationsDir, migrationFileName);
70
97
  // Run the compilation
71
98
  const s = spinner();
@@ -74,7 +101,9 @@ export default (program) => {
74
101
  // Write the SQL to a migration file
75
102
  fs.writeFileSync(migrationFilePath, compiledSql);
76
103
  s.stop(`Successfully compiled flow to SQL`);
77
- log.success(`Migration file created: ${migrationFilePath}`);
104
+ // Show the migration file path relative to the current directory
105
+ const relativeFilePath = path.relative(process.cwd(), migrationFilePath);
106
+ log.success(`Migration file created: ${relativeFilePath}`);
78
107
  }
79
108
  catch (error) {
80
109
  log.error(`Compilation failed: ${error instanceof Error ? error.message : String(error)}`);
@@ -6,6 +6,10 @@
6
6
  * and passes it to compileFlow() from the DSL package.
7
7
  */
8
8
 
9
+ // Import the compileFlow function directly from @pgflow/dsl
10
+ // The import map in deno.json will resolve this import
11
+ import { compileFlow } from '@pgflow/dsl';
12
+
9
13
  // Get the flow file path from command line arguments
10
14
  const flowFilePath = Deno.args[0];
11
15
 
@@ -24,82 +28,28 @@ try {
24
28
  Deno.exit(1);
25
29
  }
26
30
 
27
- // Import the DSL module
28
- // The import map in deno.json will resolve this import
29
- const dslModule = await import('npm:@pgflow/dsl');
30
-
31
- // Debug available exports
32
- console.error('Available exports from @pgflow/dsl:', Object.keys(dslModule));
33
-
34
31
  // Get the flow instance
35
32
  const flow = flowModule.default;
36
33
 
37
- let compileFlow;
38
- let sqlStatements;
39
-
40
- // Try different ways to access the compileFlow function
41
- if (typeof dslModule.compileFlow === 'function') {
42
- // Direct export
43
- compileFlow = dslModule.compileFlow;
44
- } else if (
45
- dslModule.default &&
46
- typeof dslModule.default.compileFlow === 'function'
47
- ) {
48
- // Default export with compileFlow as a property
49
- compileFlow = dslModule.default.compileFlow;
50
- } else {
51
- // Try to import the compile-flow module directly
52
- try {
53
- const compileFlowModule = await import(
54
- 'npm:@pgflow/dsl/dist/compile-flow.js'
55
- );
56
- if (typeof compileFlowModule.compileFlow === 'function') {
57
- compileFlow = compileFlowModule.compileFlow;
58
- } else if (
59
- compileFlowModule.default &&
60
- typeof compileFlowModule.default === 'function'
61
- ) {
62
- compileFlow = compileFlowModule.default;
63
- }
64
- } catch (importError) {
65
- console.error(
66
- 'Failed to import compile-flow module:',
67
- importError.message
68
- );
69
-
70
- // Try another path
71
- try {
72
- const altModule = await import('npm:@pgflow/dsl/src/compile-flow.js');
73
- if (typeof altModule.compileFlow === 'function') {
74
- compileFlow = altModule.compileFlow;
75
- } else if (
76
- altModule.default &&
77
- typeof altModule.default === 'function'
78
- ) {
79
- compileFlow = altModule.default;
80
- }
81
- } catch (altError) {
82
- console.error(
83
- 'Failed to import alternative compile-flow module:',
84
- altError.message
85
- );
86
- }
87
- }
88
- }
89
-
90
- // Check if we found a valid compileFlow function
91
- if (typeof compileFlow !== 'function') {
92
- console.error('Error: compileFlow function not found in @pgflow/dsl');
93
- console.error('Available exports:', Object.keys(dslModule));
94
- Deno.exit(1);
95
- }
96
-
97
34
  // Compile the flow to SQL
98
- sqlStatements = compileFlow(flow);
35
+ const sqlStatements = compileFlow(flow);
99
36
 
100
37
  // Output the SQL statements to stdout
101
38
  console.log(sqlStatements.join('\n'));
102
39
  } catch (error) {
103
40
  console.error(`Error compiling flow: ${error.message}`);
41
+
42
+ // If the error is related to importing compileFlow, provide more detailed error
43
+ if (error.message.includes('@pgflow/dsl')) {
44
+ console.error(
45
+ 'Failed to import compileFlow from @pgflow/dsl. This might be due to:'
46
+ );
47
+ console.error(
48
+ '1. The function not being exported correctly from the package'
49
+ );
50
+ console.error('2. A version mismatch between the CLI and DSL packages');
51
+ console.error('3. Issues with the Deno import map configuration');
52
+ }
53
+
104
54
  Deno.exit(1);
105
55
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgflow",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -27,8 +27,7 @@
27
27
  "toml-patch": "^0.2.3"
28
28
  },
29
29
  "publishConfig": {
30
- "access": "public",
31
- "directory": "."
30
+ "access": "public"
32
31
  },
33
32
  "files": [
34
33
  "dist"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgflow",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -24,11 +24,10 @@
24
24
  "chalk": "^5.4.1",
25
25
  "commander": "^13.1.0",
26
26
  "toml-patch": "^0.2.3",
27
- "@pgflow/core": "0.1.9"
27
+ "@pgflow/core": "0.1.11"
28
28
  },
29
29
  "publishConfig": {
30
- "access": "public",
31
- "directory": "."
30
+ "access": "public"
32
31
  },
33
32
  "files": [
34
33
  "dist"
@@ -1,105 +0,0 @@
1
- /**
2
- * internal_compile.ts
3
- *
4
- * This script is executed by Deno to compile a Flow into SQL statements.
5
- * It takes a path to a flow file as an argument, imports the default export,
6
- * and passes it to compileFlow() from the DSL package.
7
- */
8
-
9
- // Get the flow file path from command line arguments
10
- const flowFilePath = Deno.args[0];
11
-
12
- if (!flowFilePath) {
13
- console.error('Error: No flow file path provided');
14
- Deno.exit(1);
15
- }
16
-
17
- try {
18
- // Dynamically import the flow file
19
- const flowModule = await import(`file://${flowFilePath}`);
20
-
21
- // Check if there's a default export
22
- if (!flowModule.default) {
23
- console.error(`Error: No default export found in ${flowFilePath}`);
24
- Deno.exit(1);
25
- }
26
-
27
- // Import the DSL module
28
- // The import map in deno.json will resolve this import
29
- const dslModule = await import('npm:@pgflow/dsl');
30
-
31
- // Debug available exports
32
- console.error('Available exports from @pgflow/dsl:', Object.keys(dslModule));
33
-
34
- // Get the flow instance
35
- const flow = flowModule.default;
36
-
37
- let compileFlow;
38
- const sqlStatements;
39
-
40
- // Try different ways to access the compileFlow function
41
- if (typeof dslModule.compileFlow === 'function') {
42
- // Direct export
43
- compileFlow = dslModule.compileFlow;
44
- } else if (
45
- dslModule.default &&
46
- typeof dslModule.default.compileFlow === 'function'
47
- ) {
48
- // Default export with compileFlow as a property
49
- compileFlow = dslModule.default.compileFlow;
50
- } else {
51
- // Try to import the compile-flow module directly
52
- try {
53
- const compileFlowModule = await import(
54
- 'npm:@pgflow/dsl/dist/compile-flow.js'
55
- );
56
- if (typeof compileFlowModule.compileFlow === 'function') {
57
- compileFlow = compileFlowModule.compileFlow;
58
- } else if (
59
- compileFlowModule.default &&
60
- typeof compileFlowModule.default === 'function'
61
- ) {
62
- compileFlow = compileFlowModule.default;
63
- }
64
- } catch (importError) {
65
- console.error(
66
- 'Failed to import compile-flow module:',
67
- importError.message
68
- );
69
-
70
- // Try another path
71
- try {
72
- const altModule = await import('npm:@pgflow/dsl/src/compile-flow.js');
73
- if (typeof altModule.compileFlow === 'function') {
74
- compileFlow = altModule.compileFlow;
75
- } else if (
76
- altModule.default &&
77
- typeof altModule.default === 'function'
78
- ) {
79
- compileFlow = altModule.default;
80
- }
81
- } catch (altError) {
82
- console.error(
83
- 'Failed to import alternative compile-flow module:',
84
- altError.message
85
- );
86
- }
87
- }
88
- }
89
-
90
- // Check if we found a valid compileFlow function
91
- if (typeof compileFlow !== 'function') {
92
- console.error('Error: compileFlow function not found in @pgflow/dsl');
93
- console.error('Available exports:', Object.keys(dslModule));
94
- Deno.exit(1);
95
- }
96
-
97
- // Compile the flow to SQL
98
- sqlStatements = compileFlow(flow);
99
-
100
- // Output the SQL statements to stdout
101
- console.log(sqlStatements.join('\n'));
102
- } catch (error) {
103
- console.error(`Error compiling flow: ${error.message}`);
104
- Deno.exit(1);
105
- }