@event-driven-io/pongo 0.17.0-beta.4 → 0.17.0-beta.40

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