@event-driven-io/pongo 0.17.0-beta.35 → 0.17.0-beta.36
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.
- package/dist/cli.cjs +311 -494
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +4 -4
- package/dist/cli.d.ts +4 -3
- package/dist/cli.js +279 -494
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare.cjs +36 -48
- package/dist/cloudflare.cjs.map +1 -1
- package/dist/cloudflare.d.cts +7 -7
- package/dist/cloudflare.d.ts +7 -7
- package/dist/cloudflare.js +29 -47
- package/dist/cloudflare.js.map +1 -1
- package/dist/core-CwxxuUAn.cjs +1590 -0
- package/dist/core-CwxxuUAn.cjs.map +1 -0
- package/dist/core-D_iZiiYe.js +1308 -0
- package/dist/core-D_iZiiYe.js.map +1 -0
- package/dist/core-DwoTLYbR.cjs +319 -0
- package/dist/core-DwoTLYbR.cjs.map +1 -0
- package/dist/core-fsJmsQDa.js +307 -0
- package/dist/core-fsJmsQDa.js.map +1 -0
- package/dist/index-DMq6F3x9.d.ts +705 -0
- package/dist/index-Du_IHXAj.d.ts +10 -0
- package/dist/index-ZKOB86ub.d.cts +10 -0
- package/dist/index-qeC-p0Tq.d.cts +705 -0
- package/dist/index.cjs +61 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -130
- package/dist/index.d.ts +11 -130
- package/dist/index.js +14 -119
- package/dist/index.js.map +1 -1
- package/dist/pg.cjs +214 -320
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +24 -22
- package/dist/pg.d.ts +24 -22
- package/dist/pg.js +209 -321
- package/dist/pg.js.map +1 -1
- package/dist/shim.cjs +281 -367
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +140 -137
- package/dist/shim.d.ts +140 -137
- package/dist/shim.js +275 -366
- package/dist/shim.js.map +1 -1
- package/dist/sqlite3.cjs +41 -56
- package/dist/sqlite3.cjs.map +1 -1
- package/dist/sqlite3.d.cts +9 -9
- package/dist/sqlite3.d.ts +9 -9
- package/dist/sqlite3.js +35 -56
- package/dist/sqlite3.js.map +1 -1
- package/package.json +15 -15
- package/dist/chunk-EQ3T4XHT.cjs +0 -1583
- package/dist/chunk-EQ3T4XHT.cjs.map +0 -1
- package/dist/chunk-H6YIW5C5.js +0 -399
- package/dist/chunk-H6YIW5C5.js.map +0 -1
- package/dist/chunk-NTHMSHNG.cjs +0 -399
- package/dist/chunk-NTHMSHNG.cjs.map +0 -1
- package/dist/chunk-NWYI26VT.js +0 -1583
- package/dist/chunk-NWYI26VT.js.map +0 -1
- package/dist/index-BfBszcG4.d.ts +0 -8
- package/dist/index-a-fxODW1.d.cts +0 -8
- package/dist/pongoTransactionCache-CRuPGag3.d.cts +0 -556
- package/dist/pongoTransactionCache-CRuPGag3.d.ts +0 -556
package/dist/cli.cjs
CHANGED
|
@@ -1,532 +1,349 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return formatted;
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
15
|
+
__defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
25
23
|
};
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
const require_core = require('./core-CwxxuUAn.cjs');
|
|
31
|
+
let _event_driven_io_dumbo = require("@event-driven-io/dumbo");
|
|
32
|
+
let commander = require("commander");
|
|
33
|
+
let node_fs = require("node:fs");
|
|
34
|
+
node_fs = __toESM(node_fs, 1);
|
|
35
|
+
let _event_driven_io_dumbo_pg = require("@event-driven-io/dumbo/pg");
|
|
36
|
+
let cli_table3 = require("cli-table3");
|
|
37
|
+
cli_table3 = __toESM(cli_table3, 1);
|
|
38
|
+
let node_repl = require("node:repl");
|
|
39
|
+
node_repl = __toESM(node_repl, 1);
|
|
40
|
+
|
|
41
|
+
//#region src/commandLine/configFile.ts
|
|
42
|
+
const formatTypeName = (input) => {
|
|
43
|
+
if (input.length === 0) return input;
|
|
44
|
+
let formatted = input.charAt(0).toUpperCase() + input.slice(1);
|
|
45
|
+
if (formatted.endsWith("s")) formatted = formatted.slice(0, -1);
|
|
46
|
+
return formatted;
|
|
47
|
+
};
|
|
48
|
+
const sampleConfig = (collectionNames = ["users"]) => {
|
|
49
|
+
return `import { pongoSchema } from '@event-driven-io/pongo';
|
|
34
50
|
|
|
35
|
-
${
|
|
51
|
+
${collectionNames.map((name) => `export type ${formatTypeName(name)} = { name: string; description: string; date: Date }`).join("\n")}
|
|
36
52
|
|
|
37
53
|
export default {
|
|
38
54
|
schema: pongoSchema.client({
|
|
39
55
|
database: pongoSchema.db({
|
|
40
|
-
${
|
|
56
|
+
${collectionNames.map((name) => ` ${name}: pongoSchema.collection<${formatTypeName(name)}>('${name}'),`).join("\n")}
|
|
41
57
|
}),
|
|
42
58
|
}),
|
|
43
59
|
};`;
|
|
44
60
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
${sampleConfig()}`;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const imported = await Promise.resolve().then(() => _interopRequireWildcard(require(configUrl.href)));
|
|
64
|
-
const parsed = parseDefaultDbSchema(imported);
|
|
65
|
-
if (typeof parsed === "string") {
|
|
66
|
-
console.error(parsed);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
return parsed;
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.error(`Error: Couldn't load file: ${configUrl.href}`);
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
61
|
+
const missingDefaultExport = `Error: Config should contain default export, e.g.\n\n${sampleConfig()}`;
|
|
62
|
+
const missingSchema = `Error: Config should contain schema property, e.g.\n\n${sampleConfig()}`;
|
|
63
|
+
const missingDbs = `Error: Config should have at least a single database defined, e.g.\n\n${sampleConfig()}`;
|
|
64
|
+
const missingDefaultDb = `Error: Config should have a default database defined (without name or or with default database name), e.g.\n\n${sampleConfig()}`;
|
|
65
|
+
const missingCollections = `Error: Database should have defined at least one collection, e.g.\n\n${sampleConfig()}`;
|
|
66
|
+
const loadConfigFile = async (configPath) => {
|
|
67
|
+
const configUrl = new URL(configPath, `file://${process.cwd()}/`);
|
|
68
|
+
try {
|
|
69
|
+
const parsed = parseDefaultDbSchema(await import(configUrl.href));
|
|
70
|
+
if (typeof parsed === "string") {
|
|
71
|
+
console.error(parsed);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
return parsed;
|
|
75
|
+
} catch {
|
|
76
|
+
console.error(`Error: Couldn't load file: ${configUrl.href}`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
74
79
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
const generateConfigFile = (configPath, collectionNames) => {
|
|
81
|
+
try {
|
|
82
|
+
node_fs.default.writeFileSync(configPath, sampleConfig(collectionNames), "utf8");
|
|
83
|
+
console.log(`Configuration file stored at: ${configPath}`);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(`Error: Couldn't store config file: ${configPath}!`);
|
|
86
|
+
console.error(error);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
84
89
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
const dbs = _chunkEQ3T4XHTcjs.objectEntries.call(void 0, imported.default.schema.dbs).map((db) => db[1]);
|
|
96
|
-
const defaultDb = dbs.find((db) => db.name === void 0);
|
|
97
|
-
if (!defaultDb) {
|
|
98
|
-
return missingDefaultDb;
|
|
99
|
-
}
|
|
100
|
-
if (!defaultDb.collections) {
|
|
101
|
-
return missingCollections;
|
|
102
|
-
}
|
|
103
|
-
const collections = _chunkEQ3T4XHTcjs.objectEntries.call(void 0, defaultDb.collections).map((col) => col[1]);
|
|
104
|
-
if (collections.length === 0) {
|
|
105
|
-
return missingCollections;
|
|
106
|
-
}
|
|
107
|
-
return _chunkEQ3T4XHTcjs.toDbSchemaMetadata.call(void 0, defaultDb);
|
|
90
|
+
const parseDefaultDbSchema = (imported) => {
|
|
91
|
+
if (!imported.default) return missingDefaultExport;
|
|
92
|
+
if (!imported.default.schema) return missingSchema;
|
|
93
|
+
if (!imported.default.schema.dbs) return missingDbs;
|
|
94
|
+
const defaultDb = require_core.objectEntries(imported.default.schema.dbs).map((db) => db[1]).find((db) => db.name === void 0);
|
|
95
|
+
if (!defaultDb) return missingDefaultDb;
|
|
96
|
+
if (!defaultDb.collections) return missingCollections;
|
|
97
|
+
if (require_core.objectEntries(defaultDb.collections).map((col) => col[1]).length === 0) return missingCollections;
|
|
98
|
+
return require_core.toDbSchemaMetadata(defaultDb);
|
|
108
99
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"Error: Please provide either:\n--print param to print sample config or\n--generate to generate sample config file"
|
|
127
|
-
);
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|
|
130
|
-
if ("print" in options) {
|
|
131
|
-
console.log(`${sampleConfig(collectionNames)}`);
|
|
132
|
-
} else if ("generate" in options) {
|
|
133
|
-
if (!options.file) {
|
|
134
|
-
console.error(
|
|
135
|
-
"Error: You need to provide a config file through a --file"
|
|
136
|
-
);
|
|
137
|
-
process.exit(1);
|
|
138
|
-
}
|
|
139
|
-
generateConfigFile(options.file, collectionNames);
|
|
140
|
-
}
|
|
100
|
+
const configCommand = new commander.Command("config").description("Manage Pongo configuration");
|
|
101
|
+
configCommand.command("sample").description("Generate or print sample configuration").option("--col, --collection <name>", "Specify the collection name", (value, previous) => {
|
|
102
|
+
return previous.concat([value]);
|
|
103
|
+
}, []).option("-f, --file <path>", "Path to configuration file with collection list").option("-g, --generate", "Generate sample config file").option("-p, --print", "Print sample config file").action((options) => {
|
|
104
|
+
const collectionNames = options.collection.length > 0 ? options.collection : ["users"];
|
|
105
|
+
if (!("print" in options) && !("generate" in options)) {
|
|
106
|
+
console.error("Error: Please provide either:\n--print param to print sample config or\n--generate to generate sample config file");
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
if ("print" in options) console.log(`${sampleConfig(collectionNames)}`);
|
|
110
|
+
else if ("generate" in options) {
|
|
111
|
+
if (!options.file) {
|
|
112
|
+
console.error("Error: You need to provide a config file through a --file");
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
generateConfigFile(options.file, collectionNames);
|
|
116
|
+
}
|
|
141
117
|
});
|
|
142
118
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
)
|
|
177
|
-
"--t, --timeout <ms>",
|
|
178
|
-
"Set the migration timeout in milliseconds",
|
|
179
|
-
parseInt
|
|
180
|
-
).action(async (options) => {
|
|
181
|
-
const { collection, dryRun, databaseName, databaseDriver, timeoutMs } = options;
|
|
182
|
-
const connectionString = _nullishCoalesce(options.connectionString, () => ( process.env.DB_CONNECTION_STRING));
|
|
183
|
-
const databaseType = _nullishCoalesce(options.databaseType, () => ( _dumbo.parseConnectionString.call(void 0, connectionString).databaseType));
|
|
184
|
-
let collectionNames;
|
|
185
|
-
if (!connectionString) {
|
|
186
|
-
console.error(
|
|
187
|
-
'Error: Connection string is required. Provide it either as a "--connection-string" parameter or through the DB_CONNECTION_STRING environment variable.\nFor instance: --connection-string postgresql://postgres:postgres@localhost:5432/postgres'
|
|
188
|
-
);
|
|
189
|
-
process.exit(1);
|
|
190
|
-
}
|
|
191
|
-
if (options.config) {
|
|
192
|
-
const config = await loadConfigFile(options.config);
|
|
193
|
-
collectionNames = config.collections.map((c) => c.name);
|
|
194
|
-
} else if (collection) {
|
|
195
|
-
collectionNames = collection;
|
|
196
|
-
} else {
|
|
197
|
-
console.error(
|
|
198
|
-
'Error: You need to provide at least one collection name. Provide it either through "--config" file or as a "--collection" parameter.'
|
|
199
|
-
);
|
|
200
|
-
process.exit(1);
|
|
201
|
-
}
|
|
202
|
-
const driverType = `${databaseType}:${databaseDriver}`;
|
|
203
|
-
const migrations = getMigrations({
|
|
204
|
-
driverType,
|
|
205
|
-
connectionString,
|
|
206
|
-
databaseName,
|
|
207
|
-
collectionNames
|
|
208
|
-
});
|
|
209
|
-
const pool = _dumbo.dumbo.call(void 0, { connectionString, driverType });
|
|
210
|
-
await _dumbo.runSQLMigrations.call(void 0, pool, migrations, {
|
|
211
|
-
dryRun,
|
|
212
|
-
migrationTimeoutMs: timeoutMs
|
|
213
|
-
});
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/commandLine/migrate.ts
|
|
121
|
+
const migrateCommand = new commander.Command("migrate").description("Manage database migrations");
|
|
122
|
+
migrateCommand.command("run").description("Run database migrations").option("--dbt, --database-type <string>", "Database type that should be used for connection (e.g., PostgreSQL or SQLite)", void 0).option("--drv, --database-driver <string>", "Database driver that should be used for connection (e.g., \"pg\" for PostgreSQL, \"sqlite3\" for SQLite)").option("--dbn, --database-name <string>", "Database name to connect to", void 0).option("--cs, --connection-string <string>", "Connection string for the database").option("--col, --collection <name>", "Specify the collection name", (value, previous) => {
|
|
123
|
+
return previous.concat([value]);
|
|
124
|
+
}, []).option("-f, --config <path>", "Path to configuration file with Pongo config").option("--dr, --dryRun", "Perform dry run without commiting changes", false).option("--t, --timeout <ms>", "Set the migration timeout in milliseconds", parseInt).action(async (options) => {
|
|
125
|
+
const { collection, dryRun, databaseName, databaseDriver, timeoutMs } = options;
|
|
126
|
+
const connectionString = options.connectionString ?? process.env.DB_CONNECTION_STRING;
|
|
127
|
+
const databaseType = options.databaseType ?? (0, _event_driven_io_dumbo.parseConnectionString)(connectionString).databaseType;
|
|
128
|
+
let collectionNames;
|
|
129
|
+
if (!connectionString) {
|
|
130
|
+
console.error("Error: Connection string is required. Provide it either as a \"--connection-string\" parameter or through the DB_CONNECTION_STRING environment variable.\nFor instance: --connection-string postgresql://postgres:postgres@localhost:5432/postgres");
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
if (options.config) collectionNames = (await loadConfigFile(options.config)).collections.map((c) => c.name);
|
|
134
|
+
else if (collection) collectionNames = collection;
|
|
135
|
+
else {
|
|
136
|
+
console.error("Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.");
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const driverType = `${databaseType}:${databaseDriver}`;
|
|
140
|
+
const migrations = getMigrations({
|
|
141
|
+
driverType,
|
|
142
|
+
connectionString,
|
|
143
|
+
databaseName,
|
|
144
|
+
collectionNames
|
|
145
|
+
});
|
|
146
|
+
await (0, _event_driven_io_dumbo.runSQLMigrations)((0, _event_driven_io_dumbo.dumbo)({
|
|
147
|
+
connectionString,
|
|
148
|
+
driverType
|
|
149
|
+
}), migrations, {
|
|
150
|
+
dryRun,
|
|
151
|
+
migrationTimeoutMs: timeoutMs
|
|
152
|
+
});
|
|
214
153
|
});
|
|
215
|
-
migrateCommand.command("sql").description("Generate SQL for database migration").option(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
let collectionNames;
|
|
235
|
-
if (options.config) {
|
|
236
|
-
const config = await loadConfigFile(options.config);
|
|
237
|
-
collectionNames = config.collections.map((c) => c.name);
|
|
238
|
-
} else if (collection) {
|
|
239
|
-
collectionNames = collection;
|
|
240
|
-
} else {
|
|
241
|
-
console.error(
|
|
242
|
-
'Error: You need to provide at least one collection name. Provide it either through "--config" file or as a "--collection" parameter.'
|
|
243
|
-
);
|
|
244
|
-
process.exit(1);
|
|
245
|
-
}
|
|
246
|
-
const driverType = `${databaseType}:${databaseDriver}`;
|
|
247
|
-
const migrations = getMigrations({
|
|
248
|
-
driverType,
|
|
249
|
-
connectionString: void 0,
|
|
250
|
-
databaseName,
|
|
251
|
-
collectionNames
|
|
252
|
-
});
|
|
253
|
-
console.log("Printing SQL:");
|
|
254
|
-
console.log(_dumbo.combineMigrations.call(void 0, ...migrations));
|
|
154
|
+
migrateCommand.command("sql").description("Generate SQL for database migration").option("--dbt, --database-type <string>", "Database type that should be used for connection (e.g., PostgreSQL or SQLite)").option("--drv, --database-driver <string>", "Database driver that should be used for connection (e.g., \"pg\" for PostgreSQL, \"sqlite3\" for SQLite)").option("--dbn, --database-name <string>", "Database name to connect to", void 0).option("--col, --collection <name>", "Specify the collection name", (value, previous) => {
|
|
155
|
+
return previous.concat([value]);
|
|
156
|
+
}, []).option("-f, --config <path>", "Path to configuration file with Pongo config").option("--print", "Print the SQL to the console (default)", true).action(async (options) => {
|
|
157
|
+
const { collection, databaseName, databaseType, databaseDriver } = options;
|
|
158
|
+
let collectionNames;
|
|
159
|
+
if (options.config) collectionNames = (await loadConfigFile(options.config)).collections.map((c) => c.name);
|
|
160
|
+
else if (collection) collectionNames = collection;
|
|
161
|
+
else {
|
|
162
|
+
console.error("Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.");
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
const migrations = getMigrations({
|
|
166
|
+
driverType: `${databaseType}:${databaseDriver}`,
|
|
167
|
+
connectionString: void 0,
|
|
168
|
+
databaseName,
|
|
169
|
+
collectionNames
|
|
170
|
+
});
|
|
171
|
+
console.log("Printing SQL:");
|
|
172
|
+
console.log((0, _event_driven_io_dumbo.combineMigrations)(...migrations));
|
|
255
173
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const customOptions = {
|
|
275
|
-
connectionString,
|
|
276
|
-
databaseName
|
|
277
|
-
};
|
|
278
|
-
const db = driver.databaseFactory({ ...driverOptions, ...customOptions });
|
|
279
|
-
return db.schema.component.migrations;
|
|
174
|
+
const getMigrations = ({ driverType, connectionString, databaseName, collectionNames }) => {
|
|
175
|
+
const driver = require_core.pongoDriverRegistry.tryGet(driverType);
|
|
176
|
+
if (driver === null) {
|
|
177
|
+
console.error(`Error: No database driver found for driver type "${driverType}". Make sure the driver is registered and the connection string is correct.`);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
const driverOptions = {
|
|
181
|
+
schema: { definition: require_core.pongoSchema.db.from(databaseName, collectionNames) },
|
|
182
|
+
serializer: _event_driven_io_dumbo.JSONSerializer
|
|
183
|
+
};
|
|
184
|
+
const customOptions = {
|
|
185
|
+
connectionString,
|
|
186
|
+
databaseName
|
|
187
|
+
};
|
|
188
|
+
return driver.databaseFactory({
|
|
189
|
+
...driverOptions,
|
|
190
|
+
...customOptions
|
|
191
|
+
}).schema.component.migrations;
|
|
280
192
|
};
|
|
281
193
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var _pg = require('@event-driven-io/dumbo/pg');
|
|
292
|
-
var _clitable3 = require('cli-table3'); var _clitable32 = _interopRequireDefault(_clitable3);
|
|
293
|
-
|
|
294
|
-
var _repl = require('repl'); var _repl2 = _interopRequireDefault(_repl);
|
|
295
|
-
var pongo;
|
|
296
|
-
var calculateColumnWidths = (results, columnNames) => {
|
|
297
|
-
const columnWidths = columnNames.map((col) => {
|
|
298
|
-
const maxWidth = Math.max(
|
|
299
|
-
col.length,
|
|
300
|
-
...results.map(
|
|
301
|
-
(result) => (
|
|
302
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
303
|
-
result[col] ? String(result[col]).length : 0
|
|
304
|
-
)
|
|
305
|
-
)
|
|
306
|
-
);
|
|
307
|
-
return maxWidth + 2;
|
|
308
|
-
});
|
|
309
|
-
return columnWidths;
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/commandLine/shell.ts
|
|
196
|
+
let pongo;
|
|
197
|
+
const calculateColumnWidths = (results, columnNames) => {
|
|
198
|
+
return columnNames.map((col) => {
|
|
199
|
+
return Math.max(col.length, ...results.map((result) => result[col] ? String(result[col]).length : 0)) + 2;
|
|
200
|
+
});
|
|
310
201
|
};
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
head: columnNames.map((col) => _dumbo.color.cyan(col)),
|
|
327
|
-
colWidths: columnWidths
|
|
328
|
-
});
|
|
329
|
-
results.forEach((result) => {
|
|
330
|
-
table.push(
|
|
331
|
-
columnNames.map(
|
|
332
|
-
(col) => (
|
|
333
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
334
|
-
result[col] !== void 0 ? (
|
|
335
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
336
|
-
Array.isArray(result[col]) ? (
|
|
337
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
338
|
-
displayResultsAsTable(result[col])
|
|
339
|
-
) : (
|
|
340
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
341
|
-
_dumbo.prettyJson.call(void 0, result[col])
|
|
342
|
-
)
|
|
343
|
-
) : typeof result === "object" ? "" : result != void 0 && result != void 0 ? _dumbo.prettyJson.call(void 0, result) : ""
|
|
344
|
-
)
|
|
345
|
-
)
|
|
346
|
-
);
|
|
347
|
-
});
|
|
348
|
-
return table.toString();
|
|
202
|
+
let shouldDisplayResultsAsTable = false;
|
|
203
|
+
const printResultsAsTable = (print) => shouldDisplayResultsAsTable = print === void 0 || print === true;
|
|
204
|
+
const printOutput = (obj) => Array.isArray(obj) && shouldDisplayResultsAsTable ? displayResultsAsTable(obj) : (0, _event_driven_io_dumbo.prettyJson)(obj);
|
|
205
|
+
const displayResultsAsTable = (results) => {
|
|
206
|
+
if (results.length === 0) return _event_driven_io_dumbo.color.yellow("No documents found.");
|
|
207
|
+
const columnNames = results.flatMap((result) => typeof result === "object" ? Object.keys(result) : typeof result).filter((value, index, array) => array.indexOf(value) === index);
|
|
208
|
+
const columnWidths = calculateColumnWidths(results, columnNames);
|
|
209
|
+
const table = new cli_table3.default({
|
|
210
|
+
head: columnNames.map((col) => _event_driven_io_dumbo.color.cyan(col)),
|
|
211
|
+
colWidths: columnWidths
|
|
212
|
+
});
|
|
213
|
+
results.forEach((result) => {
|
|
214
|
+
table.push(columnNames.map((col) => result[col] !== void 0 ? Array.isArray(result[col]) ? displayResultsAsTable(result[col]) : (0, _event_driven_io_dumbo.prettyJson)(result[col]) : typeof result === "object" ? "" : result != void 0 && result != void 0 ? (0, _event_driven_io_dumbo.prettyJson)(result) : ""));
|
|
215
|
+
});
|
|
216
|
+
return table.toString();
|
|
349
217
|
};
|
|
350
|
-
|
|
351
|
-
|
|
218
|
+
const setLogLevel = (logLevel) => {
|
|
219
|
+
process.env.DUMBO_LOG_LEVEL = logLevel;
|
|
352
220
|
};
|
|
353
|
-
|
|
354
|
-
|
|
221
|
+
const setLogStyle = (logLevel) => {
|
|
222
|
+
process.env.DUMBO_LOG_STYLE = logLevel;
|
|
355
223
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
224
|
+
const prettifyLogs = (logLevel) => {
|
|
225
|
+
if (logLevel !== void 0) setLogLevel(logLevel);
|
|
226
|
+
setLogStyle(_event_driven_io_dumbo.LogStyle.PRETTY);
|
|
359
227
|
};
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
} else {
|
|
442
|
-
const driverOptions = {
|
|
443
|
-
driver,
|
|
444
|
-
schema: {
|
|
445
|
-
autoMigration: options.schema.autoMigration
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
const customOptions = {
|
|
449
|
-
connectionString
|
|
450
|
-
};
|
|
451
|
-
pongo = _chunkEQ3T4XHTcjs.pongoClient.call(void 0, {
|
|
452
|
-
...driverOptions,
|
|
453
|
-
...customOptions
|
|
454
|
-
});
|
|
455
|
-
db = pongo.db(options.schema.database);
|
|
456
|
-
}
|
|
457
|
-
shell.context.pongo = pongo;
|
|
458
|
-
shell.context.db = db;
|
|
459
|
-
shell.context.SQL = _dumbo.SQL;
|
|
460
|
-
shell.context.setLogLevel = setLogLevel;
|
|
461
|
-
shell.context.setLogStyle = setLogStyle;
|
|
462
|
-
shell.context.prettifyLogs = prettifyLogs;
|
|
463
|
-
shell.context.printResultsAsTable = printResultsAsTable;
|
|
464
|
-
shell.context.LogStyle = _dumbo.LogStyle;
|
|
465
|
-
shell.context.LogLevel = _dumbo.LogLevel;
|
|
466
|
-
shell.on("exit", async () => {
|
|
467
|
-
await teardown();
|
|
468
|
-
process.exit();
|
|
469
|
-
});
|
|
470
|
-
shell.on("SIGINT", async () => {
|
|
471
|
-
await teardown();
|
|
472
|
-
process.exit();
|
|
473
|
-
});
|
|
228
|
+
const startRepl = async (options) => {
|
|
229
|
+
setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);
|
|
230
|
+
setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);
|
|
231
|
+
console.log(_event_driven_io_dumbo.color.green("Starting Pongo Shell (version: 0.17.0-beta.36)"));
|
|
232
|
+
if (options.logging.printOptions) {
|
|
233
|
+
console.log(_event_driven_io_dumbo.color.green("With Options:"));
|
|
234
|
+
console.log((0, _event_driven_io_dumbo.prettyJson)(options));
|
|
235
|
+
}
|
|
236
|
+
const connectionString = options.connectionString ?? process.env.DB_CONNECTION_STRING ?? "postgresql://postgres:postgres@localhost:5432/postgres";
|
|
237
|
+
if (!(options.connectionString ?? process.env.DB_CONNECTION_STRING)) console.log(_event_driven_io_dumbo.color.yellow(`No connection string provided, using: 'postgresql://postgres:postgres@localhost:5432/postgres'`));
|
|
238
|
+
const { databaseType } = (0, _event_driven_io_dumbo.parseConnectionString)(connectionString);
|
|
239
|
+
const driverType = `${databaseType}:${options.databaseDriver}`;
|
|
240
|
+
const driver = require_core.pongoDriverRegistry.tryGet(driverType);
|
|
241
|
+
if (driver === null) {
|
|
242
|
+
console.error(`Error: No database driver found for driver type "${driverType}". Make sure the driver is installed and the connection string is correct.`);
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
const connectionCheck = await (0, _event_driven_io_dumbo_pg.checkConnection)(connectionString);
|
|
246
|
+
if (!connectionCheck.successful) {
|
|
247
|
+
if (connectionCheck.errorType === "ConnectionRefused") console.error(_event_driven_io_dumbo.color.red(`Connection was refused. Check if the PostgreSQL server is running and accessible.`));
|
|
248
|
+
else if (connectionCheck.errorType === "Authentication") console.error(_event_driven_io_dumbo.color.red(`Authentication failed. Check the username and password in the connection string.`));
|
|
249
|
+
else console.error(_event_driven_io_dumbo.color.red("Error connecting to PostgreSQL server"));
|
|
250
|
+
console.log(_event_driven_io_dumbo.color.red("Exiting Pongo Shell..."));
|
|
251
|
+
process.exit();
|
|
252
|
+
}
|
|
253
|
+
console.log(_event_driven_io_dumbo.color.green(`Successfully connected`));
|
|
254
|
+
console.log(_event_driven_io_dumbo.color.green("Use db.<collection>.<method>() to query."));
|
|
255
|
+
const shell = node_repl.default.start({
|
|
256
|
+
prompt: _event_driven_io_dumbo.color.green("pongo> "),
|
|
257
|
+
useGlobal: true,
|
|
258
|
+
breakEvalOnSigint: true,
|
|
259
|
+
writer: printOutput
|
|
260
|
+
});
|
|
261
|
+
let db;
|
|
262
|
+
if (options.schema.collections.length > 0) {
|
|
263
|
+
const collectionsSchema = {};
|
|
264
|
+
for (const collectionName of options.schema.collections) collectionsSchema[collectionName] = require_core.pongoSchema.collection(collectionName);
|
|
265
|
+
const driverOptions = {
|
|
266
|
+
driver,
|
|
267
|
+
schema: {
|
|
268
|
+
definition: require_core.pongoSchema.client({ database: require_core.pongoSchema.db(options.schema.database, collectionsSchema) }),
|
|
269
|
+
autoMigration: options.schema.autoMigration
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const customOptions = { connectionString };
|
|
273
|
+
const typedClient = require_core.pongoClient({
|
|
274
|
+
...driverOptions,
|
|
275
|
+
...customOptions
|
|
276
|
+
});
|
|
277
|
+
db = typedClient.database;
|
|
278
|
+
for (const collectionName of options.schema.collections) shell.context[collectionName] = typedClient.database[collectionName];
|
|
279
|
+
pongo = typedClient;
|
|
280
|
+
} else {
|
|
281
|
+
const driverOptions = {
|
|
282
|
+
driver,
|
|
283
|
+
schema: { autoMigration: options.schema.autoMigration }
|
|
284
|
+
};
|
|
285
|
+
const customOptions = { connectionString };
|
|
286
|
+
pongo = require_core.pongoClient({
|
|
287
|
+
...driverOptions,
|
|
288
|
+
...customOptions
|
|
289
|
+
});
|
|
290
|
+
db = pongo.db(options.schema.database);
|
|
291
|
+
}
|
|
292
|
+
shell.context.pongo = pongo;
|
|
293
|
+
shell.context.db = db;
|
|
294
|
+
shell.context.SQL = _event_driven_io_dumbo.SQL;
|
|
295
|
+
shell.context.setLogLevel = setLogLevel;
|
|
296
|
+
shell.context.setLogStyle = setLogStyle;
|
|
297
|
+
shell.context.prettifyLogs = prettifyLogs;
|
|
298
|
+
shell.context.printResultsAsTable = printResultsAsTable;
|
|
299
|
+
shell.context.LogStyle = _event_driven_io_dumbo.LogStyle;
|
|
300
|
+
shell.context.LogLevel = _event_driven_io_dumbo.LogLevel;
|
|
301
|
+
shell.on("exit", async () => {
|
|
302
|
+
await teardown();
|
|
303
|
+
process.exit();
|
|
304
|
+
});
|
|
305
|
+
shell.on("SIGINT", async () => {
|
|
306
|
+
await teardown();
|
|
307
|
+
process.exit();
|
|
308
|
+
});
|
|
474
309
|
};
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
310
|
+
const teardown = async () => {
|
|
311
|
+
console.log(_event_driven_io_dumbo.color.yellow("Exiting Pongo Shell..."));
|
|
312
|
+
await pongo.close();
|
|
478
313
|
};
|
|
479
314
|
process.on("uncaughtException", teardown);
|
|
480
315
|
process.on("SIGINT", teardown);
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
"Log level: DISABLED, INFO, LOG, WARN, ERROR",
|
|
501
|
-
"DISABLED"
|
|
502
|
-
).option("--ls, --log-style", "Log style: RAW, PRETTY", "RAW").option("-p, --pretty-log", "Turn on logging with prettified output").action(async (options) => {
|
|
503
|
-
const { collection, database } = options;
|
|
504
|
-
const connectionString = options.connectionString;
|
|
505
|
-
await startRepl({
|
|
506
|
-
logging: {
|
|
507
|
-
printOptions: options.printOptions === true,
|
|
508
|
-
logStyle: options.prettyLog ? _dumbo.LogStyle.PRETTY : _nullishCoalesce(options.logStyle, () => ( _dumbo.LogStyle.RAW)),
|
|
509
|
-
logLevel: options.logLevel ? options.logLevel : options.prettyLog ? _dumbo.LogLevel.INFO : _dumbo.LogLevel.DISABLED
|
|
510
|
-
},
|
|
511
|
-
schema: {
|
|
512
|
-
collections: collection,
|
|
513
|
-
database,
|
|
514
|
-
autoMigration: options.disableAutoMigrations ? "None" : "CreateOrUpdate"
|
|
515
|
-
},
|
|
516
|
-
connectionString,
|
|
517
|
-
databaseDriver: options.databaseDriver
|
|
518
|
-
});
|
|
316
|
+
const shellCommand = new commander.Command("shell").description("Start an interactive Pongo shell").option("--drv, --database-driver <string>", "Database driver that should be used for connection (e.g., \"pg\" for PostgreSQL, \"sqlite3\" for SQLite)", "pg").option("--cs, --connectionString <string>", "Connection string for the database").option("--db, --database <string>", "Database name to connect", "postgres").option("--col, --collection <name>", "Specify the collection name", (value, previous) => {
|
|
317
|
+
return previous.concat([value]);
|
|
318
|
+
}, []).option("--no-migrations, --disable-auto-migrations", "Disable automatic migrations").option("-o, --print-options", "Print shell options").option("--ll, --log-level <logLevel>", "Log level: DISABLED, INFO, LOG, WARN, ERROR", "DISABLED").option("--ls, --log-style", "Log style: RAW, PRETTY", "RAW").option("-p, --pretty-log", "Turn on logging with prettified output").action(async (options) => {
|
|
319
|
+
const { collection, database } = options;
|
|
320
|
+
const connectionString = options.connectionString;
|
|
321
|
+
await startRepl({
|
|
322
|
+
logging: {
|
|
323
|
+
printOptions: options.printOptions === true,
|
|
324
|
+
logStyle: options.prettyLog ? _event_driven_io_dumbo.LogStyle.PRETTY : options.logStyle ?? _event_driven_io_dumbo.LogStyle.RAW,
|
|
325
|
+
logLevel: options.logLevel ? options.logLevel : options.prettyLog ? _event_driven_io_dumbo.LogLevel.INFO : _event_driven_io_dumbo.LogLevel.DISABLED
|
|
326
|
+
},
|
|
327
|
+
schema: {
|
|
328
|
+
collections: collection,
|
|
329
|
+
database,
|
|
330
|
+
autoMigration: options.disableAutoMigrations ? "None" : "CreateOrUpdate"
|
|
331
|
+
},
|
|
332
|
+
connectionString,
|
|
333
|
+
databaseDriver: options.databaseDriver
|
|
334
|
+
});
|
|
519
335
|
});
|
|
520
336
|
|
|
521
|
-
|
|
522
|
-
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/cli.ts
|
|
339
|
+
const program = new commander.Command();
|
|
523
340
|
program.name("pongo").description("CLI tool for Pongo");
|
|
524
341
|
program.addCommand(configCommand);
|
|
525
342
|
program.addCommand(migrateCommand);
|
|
526
343
|
program.addCommand(shellCommand);
|
|
527
344
|
program.parse(process.argv);
|
|
528
|
-
var cli_default = program;
|
|
529
|
-
|
|
530
345
|
|
|
531
|
-
|
|
346
|
+
//#endregion
|
|
347
|
+
exports.__toESM = __toESM;
|
|
348
|
+
exports.default = program;
|
|
532
349
|
//# sourceMappingURL=cli.cjs.map
|