@event-driven-io/pongo 0.17.0-alpha.4 → 0.17.0-alpha.5
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/README.md +1 -1
- package/dist/{chunk-ATI5CCCT.cjs → chunk-AV4SHJQB.cjs} +16 -4
- package/dist/chunk-AV4SHJQB.cjs.map +1 -0
- package/dist/{chunk-DRVOAVHN.js → chunk-OO7GMTMP.js} +16 -4
- package/dist/chunk-OO7GMTMP.js.map +1 -0
- package/dist/cli.cjs +12 -12
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/{pg-BTgRFIL2.d.ts → pg-BfTNWLV9.d.ts} +2 -2
- package/dist/{pg-CO6kw3rY.d.cts → pg-C9NmCQe7.d.cts} +2 -2
- package/dist/pg.cjs +2 -2
- package/dist/pg.d.cts +2 -2
- package/dist/pg.d.ts +2 -2
- package/dist/pg.js +1 -1
- package/dist/{pongoClient-BpQPqFEh.d.cts → pongoClient-D8jPedlZ.d.cts} +6 -2
- package/dist/{pongoClient-BpQPqFEh.d.ts → pongoClient-D8jPedlZ.d.ts} +6 -2
- package/dist/shim.cjs +21 -8
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +1 -1
- package/dist/shim.d.ts +1 -1
- package/dist/shim.js +18 -5
- package/dist/shim.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-ATI5CCCT.cjs.map +0 -1
- package/dist/chunk-DRVOAVHN.js.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkAV4SHJQBcjs = require('./chunk-AV4SHJQB.cjs');
|
|
9
9
|
|
|
10
10
|
// src/cli.ts
|
|
11
11
|
var _commander = require('commander');
|
|
@@ -92,7 +92,7 @@ var parseDefaultDbSchema = (imported) => {
|
|
|
92
92
|
if (!imported.default.schema.dbs) {
|
|
93
93
|
return missingDbs;
|
|
94
94
|
}
|
|
95
|
-
const dbs =
|
|
95
|
+
const dbs = _chunkAV4SHJQBcjs.objectEntries.call(void 0, imported.default.schema.dbs).map((db) => db[1]);
|
|
96
96
|
const defaultDb = dbs.find((db) => db.name === void 0);
|
|
97
97
|
if (!defaultDb) {
|
|
98
98
|
return missingDefaultDb;
|
|
@@ -100,11 +100,11 @@ var parseDefaultDbSchema = (imported) => {
|
|
|
100
100
|
if (!defaultDb.collections) {
|
|
101
101
|
return missingCollections;
|
|
102
102
|
}
|
|
103
|
-
const collections =
|
|
103
|
+
const collections = _chunkAV4SHJQBcjs.objectEntries.call(void 0, defaultDb.collections).map((col) => col[1]);
|
|
104
104
|
if (collections.length === 0) {
|
|
105
105
|
return missingCollections;
|
|
106
106
|
}
|
|
107
|
-
return
|
|
107
|
+
return _chunkAV4SHJQBcjs.toDbSchemaMetadata.call(void 0, defaultDb);
|
|
108
108
|
};
|
|
109
109
|
var configCommand = new (0, _commander.Command)("config").description(
|
|
110
110
|
"Manage Pongo configuration"
|
|
@@ -184,7 +184,7 @@ migrateCommand.command("run").description("Run database migrations").option(
|
|
|
184
184
|
}
|
|
185
185
|
const pool = _pg.dumbo.call(void 0, { connectionString });
|
|
186
186
|
const migrations = collectionNames.flatMap(
|
|
187
|
-
(collectionsName) =>
|
|
187
|
+
(collectionsName) => _chunkAV4SHJQBcjs.pongoCollectionSchemaComponent.call(void 0, collectionsName).migrations({
|
|
188
188
|
connector: "PostgreSQL:pg"
|
|
189
189
|
// TODO: Provide connector here
|
|
190
190
|
})
|
|
@@ -220,7 +220,7 @@ migrateCommand.command("sql").description("Generate SQL for database migration")
|
|
|
220
220
|
const migrations = [
|
|
221
221
|
...coreMigrations,
|
|
222
222
|
...collectionNames.flatMap(
|
|
223
|
-
(collectionName) =>
|
|
223
|
+
(collectionName) => _chunkAV4SHJQBcjs.pongoCollectionSchemaComponent.call(void 0, collectionName).migrations({
|
|
224
224
|
connector: "PostgreSQL:pg"
|
|
225
225
|
// TODO: Provide connector here
|
|
226
226
|
})
|
|
@@ -310,7 +310,7 @@ var prettifyLogs = (logLevel) => {
|
|
|
310
310
|
var startRepl = async (options) => {
|
|
311
311
|
setLogLevel(_nullishCoalesce(process.env.DUMBO_LOG_LEVEL, () => ( options.logging.logLevel)));
|
|
312
312
|
setLogStyle(_nullishCoalesce(process.env.DUMBO_LOG_STYLE, () => ( options.logging.logStyle)));
|
|
313
|
-
console.log(_dumbo.color.green("Starting Pongo Shell (version: 0.17.0-alpha.
|
|
313
|
+
console.log(_dumbo.color.green("Starting Pongo Shell (version: 0.17.0-alpha.5)"));
|
|
314
314
|
if (options.logging.printOptions) {
|
|
315
315
|
console.log(_dumbo.color.green("With Options:"));
|
|
316
316
|
console.log(_dumbo.prettyJson.call(void 0, options));
|
|
@@ -355,12 +355,12 @@ var startRepl = async (options) => {
|
|
|
355
355
|
if (options.schema.collections.length > 0) {
|
|
356
356
|
const collectionsSchema = {};
|
|
357
357
|
for (const collectionName of options.schema.collections) {
|
|
358
|
-
collectionsSchema[collectionName] =
|
|
358
|
+
collectionsSchema[collectionName] = _chunkAV4SHJQBcjs.pongoSchema.collection(collectionName);
|
|
359
359
|
}
|
|
360
|
-
const schema =
|
|
361
|
-
database:
|
|
360
|
+
const schema = _chunkAV4SHJQBcjs.pongoSchema.client({
|
|
361
|
+
database: _chunkAV4SHJQBcjs.pongoSchema.db(options.schema.database, collectionsSchema)
|
|
362
362
|
});
|
|
363
|
-
const typedClient =
|
|
363
|
+
const typedClient = _chunkAV4SHJQBcjs.pongoClient.call(void 0, connectionString, {
|
|
364
364
|
schema: {
|
|
365
365
|
definition: schema,
|
|
366
366
|
autoMigration: options.schema.autoMigration
|
|
@@ -372,7 +372,7 @@ var startRepl = async (options) => {
|
|
|
372
372
|
}
|
|
373
373
|
pongo = typedClient;
|
|
374
374
|
} else {
|
|
375
|
-
pongo =
|
|
375
|
+
pongo = _chunkAV4SHJQBcjs.pongoClient.call(void 0, connectionString, {
|
|
376
376
|
schema: { autoMigration: options.schema.autoMigration }
|
|
377
377
|
});
|
|
378
378
|
db = pongo.db(options.schema.database);
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/cli.cjs","../src/cli.ts","../src/commandLine/configFile.ts","../src/commandLine/migrate.ts","../src/commandLine/shell.ts"],"names":[],"mappings":"AAAA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACRA,sCAAwB;ADUxB;AACA;AEZA;AACA,gEAAe;AAQf,IAAM,eAAA,EAAiB,CAAC,KAAA,EAAA,GAA0B;AAChD,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,IAAW,CAAA,EAAG;AACtB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI,UAAA,EAAY,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,CAAY,EAAA,EAAI,KAAA,CAAM,KAAA,CAAM,CAAC,CAAA;AAE7D,EAAA,GAAA,CAAI,SAAA,CAAU,QAAA,CAAS,GAAG,CAAA,EAAG;AAC3B,IAAA,UAAA,EAAY,SAAA,CAAU,KAAA,CAAM,CAAA,EAAG,CAAA,CAAE,CAAA;AAAA,EACnC;AAEA,EAAA,OAAO,SAAA;AACT,CAAA;AAEA,IAAM,aAAA,EAAe,CAAC,gBAAA,EAA4B,CAAC,OAAO,CAAA,EAAA,GAAM;AAC9D,EAAA,MAAM,MAAA,EAAQ,eAAA,CACX,GAAA;AAAA,IACC,CAAC,IAAA,EAAA,GACC,CAAA,YAAA,EAAe,cAAA,CAAe,IAAI,CAAC,CAAA,oDAAA;AAAA,EACvC,CAAA,CACC,IAAA,CAAK,IAAI,CAAA;AAEZ,EAAA,M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M,IAAA;AACH,MAAA;AACR,IAAA;AAEQ,IAAA;AACH,EAAA;AACG,IAAA;AACI,MAAA;AACX,IAAA;AAEU,IAAA;AACb,EAAA;AAEc,EAAA;AACA,EAAA;AAGA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAGL,EAAA;AACD,IAAA;AACO,IAAA;AACd,EAAA;AAEQ,EAAA;AACD,IAAA;AACO,IAAA;AACd,EAAA;AACH;AAEiB;AACH,EAAA;AACA,EAAA;AACd;AAEW;AACA;AAaL;AAGF,EAAA;AACA,EAAA;AAEM;AAEN,EAAA;AACA,EAAA;AACgB,EAAA;AAEP,IAAA;AACT,EAAA;AACC,EAAA;AAEF;AACC,EAAA;AACA,EAAA;AAEM;AAEN,EAAA;AACA,EAAA;AACA,EAAA;AAEM;AAGE,EAAA;AACF,EAAA;AAEA,EAAA;AACK,IAAA;AACP,MAAA;AACU,MAAA;AAGA,MAAA;AAKZ,IAAA;AACQ,IAAA;AACN,MAAA;AACA,MAAA;AACA,MAAA;AAGF,IAAA;AACA,IAAA;AACD,EAAA;AACF;AJ+Hc;AACA;AClbD;AAEH;AAEL;AACA;AACA;AAEM;AAEP;ADgbU;AACA;AACA","file":"/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/cli.cjs","sourcesContent":[null,"#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { configCommand, migrateCommand, shellCommand } from './commandLine';\n\nconst program = new Command();\n\nprogram.name('pongo').description('CLI tool for Pongo');\n\nprogram.addCommand(configCommand);\nprogram.addCommand(migrateCommand);\nprogram.addCommand(shellCommand);\n\nprogram.parse(process.argv);\n\nexport default program;\n","import { Command } from 'commander';\nimport fs from 'node:fs';\nimport {\n objectEntries,\n toDbSchemaMetadata,\n type PongoDbSchemaMetadata,\n type PongoSchemaConfig,\n} from '../core';\n\nconst formatTypeName = (input: string): string => {\n if (input.length === 0) {\n return input;\n }\n\n let formatted = input.charAt(0).toUpperCase() + input.slice(1);\n\n if (formatted.endsWith('s')) {\n formatted = formatted.slice(0, -1);\n }\n\n return formatted;\n};\n\nconst sampleConfig = (collectionNames: string[] = ['users']) => {\n const types = collectionNames\n .map(\n (name) =>\n `export type ${formatTypeName(name)} = { name: string; description: string; date: Date }`,\n )\n .join('\\n');\n\n const collections = collectionNames\n .map(\n (name) =>\n ` ${name}: pongoSchema.collection<${formatTypeName(name)}>('${name}'),`,\n )\n .join('\\n');\n\n return `import { pongoSchema } from '@event-driven-io/pongo';\n\n${types}\n\nexport default {\n schema: pongoSchema.client({\n database: pongoSchema.db({\n${collections}\n }),\n }),\n};`;\n};\n\nconst missingDefaultExport = `Error: Config should contain default export, e.g.\\n\\n${sampleConfig()}`;\nconst missingSchema = `Error: Config should contain schema property, e.g.\\n\\n${sampleConfig()}`;\nconst missingDbs = `Error: Config should have at least a single database defined, e.g.\\n\\n${sampleConfig()}`;\nconst missingDefaultDb = `Error: Config should have a default database defined (without name or or with default database name), e.g.\\n\\n${sampleConfig()}`;\nconst missingCollections = `Error: Database should have defined at least one collection, e.g.\\n\\n${sampleConfig()}`;\n\nexport const loadConfigFile = async (\n configPath: string,\n): Promise<PongoDbSchemaMetadata> => {\n const configUrl = new URL(configPath, `file://${process.cwd()}/`);\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const imported: Partial<{ default: PongoSchemaConfig }> = await import(\n configUrl.href\n );\n\n const parsed = parseDefaultDbSchema(imported);\n\n if (typeof parsed === 'string') {\n console.error(parsed);\n process.exit(1);\n }\n\n return parsed;\n } catch {\n console.error(`Error: Couldn't load file: ${configUrl.href}`);\n process.exit(1);\n }\n};\n\nexport const generateConfigFile = (\n configPath: string,\n collectionNames: string[],\n): void => {\n try {\n fs.writeFileSync(configPath, sampleConfig(collectionNames), 'utf8');\n console.log(`Configuration file stored at: ${configPath}`);\n } catch (error) {\n console.error(`Error: Couldn't store config file: ${configPath}!`);\n console.error(error);\n process.exit(1);\n }\n};\n\nexport const parseDefaultDbSchema = (\n imported: Partial<{ default: PongoSchemaConfig }>,\n): PongoDbSchemaMetadata | string => {\n if (!imported.default) {\n return missingDefaultExport;\n }\n\n if (!imported.default.schema) {\n return missingSchema;\n }\n\n if (!imported.default.schema.dbs) {\n return missingDbs;\n }\n\n const dbs = objectEntries(imported.default.schema.dbs).map((db) => db[1]);\n\n const defaultDb = dbs.find((db) => db.name === undefined);\n\n if (!defaultDb) {\n return missingDefaultDb;\n }\n\n if (!defaultDb.collections) {\n return missingCollections;\n }\n\n const collections = objectEntries(defaultDb.collections).map((col) => col[1]);\n\n if (collections.length === 0) {\n return missingCollections;\n }\n\n return toDbSchemaMetadata(defaultDb);\n};\n\ntype SampleConfigOptions =\n | {\n collection: string[];\n print?: boolean;\n }\n | {\n collection: string[];\n generate?: boolean;\n file?: string;\n };\n\nexport const configCommand = new Command('config').description(\n 'Manage Pongo configuration',\n);\n\nconfigCommand\n .command('sample')\n .description('Generate or print sample configuration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-f, --file <path>',\n 'Path to configuration file with collection list',\n )\n .option('-g, --generate', 'Generate sample config file')\n .option('-p, --print', 'Print sample config file')\n .action((options: SampleConfigOptions) => {\n const collectionNames =\n options.collection.length > 0 ? options.collection : ['users'];\n\n if (!('print' in options) && !('generate' in options)) {\n console.error(\n 'Error: Please provide either:\\n--print param to print sample config or\\n--generate to generate sample config file',\n );\n process.exit(1);\n }\n\n if ('print' in options) {\n console.log(`${sampleConfig(collectionNames)}`);\n } else if ('generate' in options) {\n if (!options.file) {\n console.error(\n 'Error: You need to provide a config file through a --file',\n );\n process.exit(1);\n }\n\n generateConfigFile(options.file, collectionNames);\n }\n });\n","import { combineMigrations } from '@event-driven-io/dumbo';\nimport {\n dumbo,\n migrationTableSchemaComponent,\n runPostgreSQLMigrations,\n} from '@event-driven-io/dumbo/pg';\nimport { Command } from 'commander';\nimport { pongoCollectionSchemaComponent } from '../core';\nimport { loadConfigFile } from './configFile';\n\ninterface MigrateRunOptions {\n collection: string[];\n connectionString: string;\n config?: string;\n dryRun?: boolean;\n}\n\ninterface MigrateSqlOptions {\n print?: boolean;\n write?: string;\n config?: string;\n collection: string[];\n}\n\nexport const migrateCommand = new Command('migrate').description(\n 'Manage database migrations',\n);\n\nmigrateCommand\n .command('run')\n .description('Run database migrations')\n .option(\n '-cs, --connection-string <string>',\n 'Connection string for the database',\n )\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('-dr, --dryRun', 'Perform dry run without commiting changes', false)\n .action(async (options: MigrateRunOptions) => {\n const { collection, dryRun } = options;\n const connectionString =\n options.connectionString ?? process.env.DB_CONNECTION_STRING;\n let collectionNames: string[];\n\n if (!connectionString) {\n console.error(\n 'Error: Connection string is required. Provide it either as a \"--connection-string\" parameter or through the DB_CONNECTION_STRING environment variable.' +\n '\\nFor instance: --connection-string postgresql://postgres:postgres@localhost:5432/postgres',\n );\n process.exit(1);\n }\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const pool = dumbo({ connectionString });\n\n const migrations = collectionNames.flatMap((collectionsName) =>\n pongoCollectionSchemaComponent(collectionsName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n );\n\n await runPostgreSQLMigrations(pool, migrations, {\n dryRun,\n });\n });\n\nmigrateCommand\n .command('sql')\n .description('Generate SQL for database migration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('--print', 'Print the SQL to the console (default)', true)\n //.option('--write <filename>', 'Write the SQL to a specified file')\n .action(async (options: MigrateSqlOptions) => {\n const { collection } = options;\n\n let collectionNames: string[];\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const coreMigrations = migrationTableSchemaComponent.migrations({\n connector: 'PostgreSQL:pg',\n });\n const migrations = [\n ...coreMigrations,\n ...collectionNames.flatMap((collectionName) =>\n pongoCollectionSchemaComponent(collectionName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n ),\n ];\n\n console.log('Printing SQL:');\n console.log(combineMigrations(...migrations));\n });\n","import {\n color,\n LogLevel,\n LogStyle,\n prettyJson,\n SQL,\n type MigrationStyle,\n} from '@event-driven-io/dumbo';\nimport { checkConnection } from '@event-driven-io/dumbo/pg';\nimport Table from 'cli-table3';\nimport { Command } from 'commander';\nimport repl from 'node:repl';\nimport {\n pongoClient,\n pongoSchema,\n type PongoClient,\n type PongoCollectionSchema,\n type PongoDb,\n} from '../core';\n\nlet pongo: PongoClient;\n\nconst calculateColumnWidths = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n results: any[],\n columnNames: string[],\n): number[] => {\n const columnWidths = columnNames.map((col) => {\n const maxWidth = Math.max(\n col.length, // Header size\n ...results.map((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] ? String(result[col]).length : 0,\n ),\n );\n return maxWidth + 2; // Add padding\n });\n return columnWidths;\n};\n\nlet shouldDisplayResultsAsTable = false;\n\nconst printResultsAsTable = (print?: boolean) =>\n (shouldDisplayResultsAsTable = print === undefined || print === true);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst printOutput = (obj: any): string =>\n Array.isArray(obj) && shouldDisplayResultsAsTable\n ? displayResultsAsTable(obj)\n : prettyJson(obj);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst displayResultsAsTable = (results: any[]): string => {\n if (results.length === 0) {\n return color.yellow('No documents found.');\n }\n\n const columnNames = results\n\n .flatMap((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n typeof result === 'object' ? Object.keys(result) : typeof result,\n )\n .filter((value, index, array) => array.indexOf(value) === index);\n\n const columnWidths = calculateColumnWidths(results, columnNames);\n\n const table = new Table({\n head: columnNames.map((col) => color.cyan(col)),\n colWidths: columnWidths,\n });\n\n results.forEach((result) => {\n table.push(\n columnNames.map((col) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] !== undefined\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Array.isArray(result[col])\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n displayResultsAsTable(result[col])\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n prettyJson(result[col])\n : typeof result === 'object'\n ? ''\n : result != undefined && result != undefined\n ? prettyJson(result)\n : '',\n ),\n );\n });\n\n return table.toString();\n};\n\nconst setLogLevel = (logLevel: string) => {\n process.env.DUMBO_LOG_LEVEL = logLevel;\n};\n\nconst setLogStyle = (logLevel: string) => {\n process.env.DUMBO_LOG_STYLE = logLevel;\n};\n\nconst prettifyLogs = (logLevel?: string) => {\n if (logLevel !== undefined) setLogLevel(logLevel);\n setLogStyle(LogStyle.PRETTY);\n};\n\nconst startRepl = async (options: {\n logging: {\n printOptions: boolean;\n logLevel: LogLevel;\n logStyle: LogStyle;\n };\n schema: {\n database: string;\n collections: string[];\n autoMigration: MigrationStyle;\n };\n connectionString: string | undefined;\n}) => {\n // TODO: This will change when we have proper tracing and logging config\n // For now, that's enough\n setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);\n setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);\n\n console.log(color.green('Starting Pongo Shell (version: 0.17.0-alpha.4)'));\n\n if (options.logging.printOptions) {\n console.log(color.green('With Options:'));\n console.log(prettyJson(options));\n }\n\n const connectionString =\n options.connectionString ??\n process.env.DB_CONNECTION_STRING ??\n 'postgresql://postgres:postgres@localhost:5432/postgres';\n\n if (!(options.connectionString ?? process.env.DB_CONNECTION_STRING)) {\n console.log(\n color.yellow(\n `No connection string provided, using: 'postgresql://postgres:postgres@localhost:5432/postgres'`,\n ),\n );\n }\n\n const connectionCheck = await checkConnection(connectionString);\n\n if (!connectionCheck.successful) {\n if (connectionCheck.errorType === 'ConnectionRefused') {\n console.error(\n color.red(\n `Connection was refused. Check if the PostgreSQL server is running and accessible.`,\n ),\n );\n } else if (connectionCheck.errorType === 'Authentication') {\n console.error(\n color.red(\n `Authentication failed. Check the username and password in the connection string.`,\n ),\n );\n } else {\n console.error(color.red('Error connecting to PostgreSQL server'));\n }\n console.log(color.red('Exiting Pongo Shell...'));\n process.exit();\n }\n\n console.log(color.green(`Successfully connected`));\n console.log(color.green('Use db.<collection>.<method>() to query.'));\n\n const shell = repl.start({\n prompt: color.green('pongo> '),\n useGlobal: true,\n breakEvalOnSigint: true,\n writer: printOutput,\n });\n\n let db: PongoDb;\n\n if (options.schema.collections.length > 0) {\n const collectionsSchema: Record<string, PongoCollectionSchema> = {};\n\n for (const collectionName of options.schema.collections) {\n collectionsSchema[collectionName] =\n pongoSchema.collection(collectionName);\n }\n\n const schema = pongoSchema.client({\n database: pongoSchema.db(options.schema.database, collectionsSchema),\n });\n\n const typedClient = pongoClient(connectionString, {\n schema: {\n definition: schema,\n autoMigration: options.schema.autoMigration,\n },\n });\n\n db = typedClient.database;\n\n for (const collectionName of options.schema.collections) {\n shell.context[collectionName] = typedClient.database[collectionName];\n }\n\n pongo = typedClient;\n } else {\n pongo = pongoClient(connectionString, {\n schema: { autoMigration: options.schema.autoMigration },\n });\n\n db = pongo.db(options.schema.database);\n }\n\n shell.context.pongo = pongo;\n shell.context.db = db;\n\n // helpers\n shell.context.SQL = SQL;\n shell.context.setLogLevel = setLogLevel;\n shell.context.setLogStyle = setLogStyle;\n shell.context.prettifyLogs = prettifyLogs;\n shell.context.printResultsAsTable = printResultsAsTable;\n shell.context.LogStyle = LogStyle;\n shell.context.LogLevel = LogLevel;\n\n // Intercept REPL output to display results as a table if they are arrays\n shell.on('exit', async () => {\n await teardown();\n process.exit();\n });\n\n shell.on('SIGINT', async () => {\n await teardown();\n process.exit();\n });\n};\n\nconst teardown = async () => {\n console.log(color.yellow('Exiting Pongo Shell...'));\n await pongo.close();\n};\n\nprocess.on('uncaughtException', teardown);\nprocess.on('SIGINT', teardown);\n\ninterface ShellOptions {\n database: string;\n collection: string[];\n connectionString?: string;\n disableAutoMigrations: boolean;\n logStyle?: string;\n logLevel?: string;\n prettyLog?: boolean;\n printOptions?: boolean;\n}\n\nconst shellCommand = new Command('shell')\n .description('Start an interactive Pongo shell')\n .option(\n '-cs, --connectionString <string>',\n 'Connection string for the database',\n )\n .option('-db, --database <string>', 'Database name to connect', 'postgres')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-no-migrations, --disable-auto-migrations',\n 'Disable automatic migrations',\n )\n .option('-o, --print-options', 'Print shell options')\n .option(\n '-ll, --log-level <logLevel>',\n 'Log level: DISABLED, INFO, LOG, WARN, ERROR',\n 'DISABLED',\n )\n .option('-ls, --log-style', 'Log style: RAW, PRETTY', 'RAW')\n .option('-p, --pretty-log', 'Turn on logging with prettified output')\n .action(async (options: ShellOptions) => {\n const { collection, database } = options;\n const connectionString = options.connectionString;\n\n await startRepl({\n logging: {\n printOptions: options.printOptions === true,\n logStyle: options.prettyLog\n ? LogStyle.PRETTY\n : ((options.logStyle as LogStyle | undefined) ?? LogStyle.RAW),\n logLevel: options.logLevel\n ? (options.logLevel as LogLevel)\n : options.prettyLog\n ? LogLevel.INFO\n : LogLevel.DISABLED,\n },\n schema: {\n collections: collection,\n database,\n autoMigration: options.disableAutoMigrations\n ? 'None'\n : 'CreateOrUpdate',\n },\n connectionString,\n });\n });\n\nexport { shellCommand };\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/cli.cjs","../src/cli.ts","../src/commandLine/configFile.ts","../src/commandLine/migrate.ts","../src/commandLine/shell.ts"],"names":[],"mappings":"AAAA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACRA,sCAAwB;ADUxB;AACA;AEZA;AACA,gEAAe;AAQf,IAAM,eAAA,EAAiB,CAAC,KAAA,EAAA,GAA0B;AAChD,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,IAAW,CAAA,EAAG;AACtB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI,UAAA,EAAY,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,CAAY,EAAA,EAAI,KAAA,CAAM,KAAA,CAAM,CAAC,CAAA;AAE7D,EAAA,GAAA,CAAI,SAAA,CAAU,QAAA,CAAS,GAAG,CAAA,EAAG;AAC3B,IAAA,UAAA,EAAY,SAAA,CAAU,KAAA,CAAM,CAAA,EAAG,CAAA,CAAE,CAAA;AAAA,EACnC;AAEA,EAAA,OAAO,SAAA;AACT,CAAA;AAEA,IAAM,aAAA,EAAe,CAAC,gBAAA,EAA4B,CAAC,OAAO,CAAA,EAAA,GAAM;AAC9D,EAAA,MAAM,MAAA,EAAQ,eAAA,CACX,GAAA;AAAA,IACC,CAAC,IAAA,EAAA,GACC,CAAA,YAAA,EAAe,cAAA,CAAe,IAAI,CAAC,CAAA,oDAAA;AAAA,EACvC,CAAA,CACC,IAAA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,MAAA;AACD,IAAA;AAEI,IAAA;AAEM,IAAA;AACH,MAAA;AACR,IAAA;AAEQ,IAAA;AACH,EAAA;AACG,IAAA;AACI,MAAA;AACX,IAAA;AAEU,IAAA;AACb,EAAA;AAEc,EAAA;AACA,EAAA;AAGA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAGL,EAAA;AACD,IAAA;AACO,IAAA;AACd,EAAA;AAEQ,EAAA;AACD,IAAA;AACO,IAAA;AACd,EAAA;AACH;AAEiB;AACH,EAAA;AACA,EAAA;AACd;AAEW;AACA;AAaL;AAGF,EAAA;AACA,EAAA;AAEM;AAEN,EAAA;AACA,EAAA;AACgB,EAAA;AAEP,IAAA;AACT,EAAA;AACC,EAAA;AAEF;AACC,EAAA;AACA,EAAA;AAEM;AAEN,EAAA;AACA,EAAA;AACA,EAAA;AAEM;AAGE,EAAA;AACF,EAAA;AAEA,EAAA;AACK,IAAA;AACP,MAAA;AACU,MAAA;AAGA,MAAA;AAKZ,IAAA;AACQ,IAAA;AACN,MAAA;AACA,MAAA;AACA,MAAA;AAGF,IAAA;AACA,IAAA;AACD,EAAA;AACF;AJ+Hc;AACA;AClbD;AAEH;AAEL;AACA;AACA;AAEM;AAEP;ADgbU;AACA;AACA","file":"/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/cli.cjs","sourcesContent":[null,"#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { configCommand, migrateCommand, shellCommand } from './commandLine';\n\nconst program = new Command();\n\nprogram.name('pongo').description('CLI tool for Pongo');\n\nprogram.addCommand(configCommand);\nprogram.addCommand(migrateCommand);\nprogram.addCommand(shellCommand);\n\nprogram.parse(process.argv);\n\nexport default program;\n","import { Command } from 'commander';\nimport fs from 'node:fs';\nimport {\n objectEntries,\n toDbSchemaMetadata,\n type PongoDbSchemaMetadata,\n type PongoSchemaConfig,\n} from '../core';\n\nconst formatTypeName = (input: string): string => {\n if (input.length === 0) {\n return input;\n }\n\n let formatted = input.charAt(0).toUpperCase() + input.slice(1);\n\n if (formatted.endsWith('s')) {\n formatted = formatted.slice(0, -1);\n }\n\n return formatted;\n};\n\nconst sampleConfig = (collectionNames: string[] = ['users']) => {\n const types = collectionNames\n .map(\n (name) =>\n `export type ${formatTypeName(name)} = { name: string; description: string; date: Date }`,\n )\n .join('\\n');\n\n const collections = collectionNames\n .map(\n (name) =>\n ` ${name}: pongoSchema.collection<${formatTypeName(name)}>('${name}'),`,\n )\n .join('\\n');\n\n return `import { pongoSchema } from '@event-driven-io/pongo';\n\n${types}\n\nexport default {\n schema: pongoSchema.client({\n database: pongoSchema.db({\n${collections}\n }),\n }),\n};`;\n};\n\nconst missingDefaultExport = `Error: Config should contain default export, e.g.\\n\\n${sampleConfig()}`;\nconst missingSchema = `Error: Config should contain schema property, e.g.\\n\\n${sampleConfig()}`;\nconst missingDbs = `Error: Config should have at least a single database defined, e.g.\\n\\n${sampleConfig()}`;\nconst missingDefaultDb = `Error: Config should have a default database defined (without name or or with default database name), e.g.\\n\\n${sampleConfig()}`;\nconst missingCollections = `Error: Database should have defined at least one collection, e.g.\\n\\n${sampleConfig()}`;\n\nexport const loadConfigFile = async (\n configPath: string,\n): Promise<PongoDbSchemaMetadata> => {\n const configUrl = new URL(configPath, `file://${process.cwd()}/`);\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const imported: Partial<{ default: PongoSchemaConfig }> = await import(\n configUrl.href\n );\n\n const parsed = parseDefaultDbSchema(imported);\n\n if (typeof parsed === 'string') {\n console.error(parsed);\n process.exit(1);\n }\n\n return parsed;\n } catch {\n console.error(`Error: Couldn't load file: ${configUrl.href}`);\n process.exit(1);\n }\n};\n\nexport const generateConfigFile = (\n configPath: string,\n collectionNames: string[],\n): void => {\n try {\n fs.writeFileSync(configPath, sampleConfig(collectionNames), 'utf8');\n console.log(`Configuration file stored at: ${configPath}`);\n } catch (error) {\n console.error(`Error: Couldn't store config file: ${configPath}!`);\n console.error(error);\n process.exit(1);\n }\n};\n\nexport const parseDefaultDbSchema = (\n imported: Partial<{ default: PongoSchemaConfig }>,\n): PongoDbSchemaMetadata | string => {\n if (!imported.default) {\n return missingDefaultExport;\n }\n\n if (!imported.default.schema) {\n return missingSchema;\n }\n\n if (!imported.default.schema.dbs) {\n return missingDbs;\n }\n\n const dbs = objectEntries(imported.default.schema.dbs).map((db) => db[1]);\n\n const defaultDb = dbs.find((db) => db.name === undefined);\n\n if (!defaultDb) {\n return missingDefaultDb;\n }\n\n if (!defaultDb.collections) {\n return missingCollections;\n }\n\n const collections = objectEntries(defaultDb.collections).map((col) => col[1]);\n\n if (collections.length === 0) {\n return missingCollections;\n }\n\n return toDbSchemaMetadata(defaultDb);\n};\n\ntype SampleConfigOptions =\n | {\n collection: string[];\n print?: boolean;\n }\n | {\n collection: string[];\n generate?: boolean;\n file?: string;\n };\n\nexport const configCommand = new Command('config').description(\n 'Manage Pongo configuration',\n);\n\nconfigCommand\n .command('sample')\n .description('Generate or print sample configuration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-f, --file <path>',\n 'Path to configuration file with collection list',\n )\n .option('-g, --generate', 'Generate sample config file')\n .option('-p, --print', 'Print sample config file')\n .action((options: SampleConfigOptions) => {\n const collectionNames =\n options.collection.length > 0 ? options.collection : ['users'];\n\n if (!('print' in options) && !('generate' in options)) {\n console.error(\n 'Error: Please provide either:\\n--print param to print sample config or\\n--generate to generate sample config file',\n );\n process.exit(1);\n }\n\n if ('print' in options) {\n console.log(`${sampleConfig(collectionNames)}`);\n } else if ('generate' in options) {\n if (!options.file) {\n console.error(\n 'Error: You need to provide a config file through a --file',\n );\n process.exit(1);\n }\n\n generateConfigFile(options.file, collectionNames);\n }\n });\n","import { combineMigrations } from '@event-driven-io/dumbo';\nimport {\n dumbo,\n migrationTableSchemaComponent,\n runPostgreSQLMigrations,\n} from '@event-driven-io/dumbo/pg';\nimport { Command } from 'commander';\nimport { pongoCollectionSchemaComponent } from '../core';\nimport { loadConfigFile } from './configFile';\n\ninterface MigrateRunOptions {\n collection: string[];\n connectionString: string;\n config?: string;\n dryRun?: boolean;\n}\n\ninterface MigrateSqlOptions {\n print?: boolean;\n write?: string;\n config?: string;\n collection: string[];\n}\n\nexport const migrateCommand = new Command('migrate').description(\n 'Manage database migrations',\n);\n\nmigrateCommand\n .command('run')\n .description('Run database migrations')\n .option(\n '-cs, --connection-string <string>',\n 'Connection string for the database',\n )\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('-dr, --dryRun', 'Perform dry run without commiting changes', false)\n .action(async (options: MigrateRunOptions) => {\n const { collection, dryRun } = options;\n const connectionString =\n options.connectionString ?? process.env.DB_CONNECTION_STRING;\n let collectionNames: string[];\n\n if (!connectionString) {\n console.error(\n 'Error: Connection string is required. Provide it either as a \"--connection-string\" parameter or through the DB_CONNECTION_STRING environment variable.' +\n '\\nFor instance: --connection-string postgresql://postgres:postgres@localhost:5432/postgres',\n );\n process.exit(1);\n }\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const pool = dumbo({ connectionString });\n\n const migrations = collectionNames.flatMap((collectionsName) =>\n pongoCollectionSchemaComponent(collectionsName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n );\n\n await runPostgreSQLMigrations(pool, migrations, {\n dryRun,\n });\n });\n\nmigrateCommand\n .command('sql')\n .description('Generate SQL for database migration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('--print', 'Print the SQL to the console (default)', true)\n //.option('--write <filename>', 'Write the SQL to a specified file')\n .action(async (options: MigrateSqlOptions) => {\n const { collection } = options;\n\n let collectionNames: string[];\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const coreMigrations = migrationTableSchemaComponent.migrations({\n connector: 'PostgreSQL:pg',\n });\n const migrations = [\n ...coreMigrations,\n ...collectionNames.flatMap((collectionName) =>\n pongoCollectionSchemaComponent(collectionName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n ),\n ];\n\n console.log('Printing SQL:');\n console.log(combineMigrations(...migrations));\n });\n","import {\n color,\n LogLevel,\n LogStyle,\n prettyJson,\n SQL,\n type MigrationStyle,\n} from '@event-driven-io/dumbo';\nimport { checkConnection } from '@event-driven-io/dumbo/pg';\nimport Table from 'cli-table3';\nimport { Command } from 'commander';\nimport repl from 'node:repl';\nimport {\n pongoClient,\n pongoSchema,\n type PongoClient,\n type PongoCollectionSchema,\n type PongoDb,\n} from '../core';\n\nlet pongo: PongoClient;\n\nconst calculateColumnWidths = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n results: any[],\n columnNames: string[],\n): number[] => {\n const columnWidths = columnNames.map((col) => {\n const maxWidth = Math.max(\n col.length, // Header size\n ...results.map((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] ? String(result[col]).length : 0,\n ),\n );\n return maxWidth + 2; // Add padding\n });\n return columnWidths;\n};\n\nlet shouldDisplayResultsAsTable = false;\n\nconst printResultsAsTable = (print?: boolean) =>\n (shouldDisplayResultsAsTable = print === undefined || print === true);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst printOutput = (obj: any): string =>\n Array.isArray(obj) && shouldDisplayResultsAsTable\n ? displayResultsAsTable(obj)\n : prettyJson(obj);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst displayResultsAsTable = (results: any[]): string => {\n if (results.length === 0) {\n return color.yellow('No documents found.');\n }\n\n const columnNames = results\n\n .flatMap((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n typeof result === 'object' ? Object.keys(result) : typeof result,\n )\n .filter((value, index, array) => array.indexOf(value) === index);\n\n const columnWidths = calculateColumnWidths(results, columnNames);\n\n const table = new Table({\n head: columnNames.map((col) => color.cyan(col)),\n colWidths: columnWidths,\n });\n\n results.forEach((result) => {\n table.push(\n columnNames.map((col) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] !== undefined\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Array.isArray(result[col])\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n displayResultsAsTable(result[col])\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n prettyJson(result[col])\n : typeof result === 'object'\n ? ''\n : result != undefined && result != undefined\n ? prettyJson(result)\n : '',\n ),\n );\n });\n\n return table.toString();\n};\n\nconst setLogLevel = (logLevel: string) => {\n process.env.DUMBO_LOG_LEVEL = logLevel;\n};\n\nconst setLogStyle = (logLevel: string) => {\n process.env.DUMBO_LOG_STYLE = logLevel;\n};\n\nconst prettifyLogs = (logLevel?: string) => {\n if (logLevel !== undefined) setLogLevel(logLevel);\n setLogStyle(LogStyle.PRETTY);\n};\n\nconst startRepl = async (options: {\n logging: {\n printOptions: boolean;\n logLevel: LogLevel;\n logStyle: LogStyle;\n };\n schema: {\n database: string;\n collections: string[];\n autoMigration: MigrationStyle;\n };\n connectionString: string | undefined;\n}) => {\n // TODO: This will change when we have proper tracing and logging config\n // For now, that's enough\n setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);\n setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);\n\n console.log(color.green('Starting Pongo Shell (version: 0.17.0-alpha.5)'));\n\n if (options.logging.printOptions) {\n console.log(color.green('With Options:'));\n console.log(prettyJson(options));\n }\n\n const connectionString =\n options.connectionString ??\n process.env.DB_CONNECTION_STRING ??\n 'postgresql://postgres:postgres@localhost:5432/postgres';\n\n if (!(options.connectionString ?? process.env.DB_CONNECTION_STRING)) {\n console.log(\n color.yellow(\n `No connection string provided, using: 'postgresql://postgres:postgres@localhost:5432/postgres'`,\n ),\n );\n }\n\n const connectionCheck = await checkConnection(connectionString);\n\n if (!connectionCheck.successful) {\n if (connectionCheck.errorType === 'ConnectionRefused') {\n console.error(\n color.red(\n `Connection was refused. Check if the PostgreSQL server is running and accessible.`,\n ),\n );\n } else if (connectionCheck.errorType === 'Authentication') {\n console.error(\n color.red(\n `Authentication failed. Check the username and password in the connection string.`,\n ),\n );\n } else {\n console.error(color.red('Error connecting to PostgreSQL server'));\n }\n console.log(color.red('Exiting Pongo Shell...'));\n process.exit();\n }\n\n console.log(color.green(`Successfully connected`));\n console.log(color.green('Use db.<collection>.<method>() to query.'));\n\n const shell = repl.start({\n prompt: color.green('pongo> '),\n useGlobal: true,\n breakEvalOnSigint: true,\n writer: printOutput,\n });\n\n let db: PongoDb;\n\n if (options.schema.collections.length > 0) {\n const collectionsSchema: Record<string, PongoCollectionSchema> = {};\n\n for (const collectionName of options.schema.collections) {\n collectionsSchema[collectionName] =\n pongoSchema.collection(collectionName);\n }\n\n const schema = pongoSchema.client({\n database: pongoSchema.db(options.schema.database, collectionsSchema),\n });\n\n const typedClient = pongoClient(connectionString, {\n schema: {\n definition: schema,\n autoMigration: options.schema.autoMigration,\n },\n });\n\n db = typedClient.database;\n\n for (const collectionName of options.schema.collections) {\n shell.context[collectionName] = typedClient.database[collectionName];\n }\n\n pongo = typedClient;\n } else {\n pongo = pongoClient(connectionString, {\n schema: { autoMigration: options.schema.autoMigration },\n });\n\n db = pongo.db(options.schema.database);\n }\n\n shell.context.pongo = pongo;\n shell.context.db = db;\n\n // helpers\n shell.context.SQL = SQL;\n shell.context.setLogLevel = setLogLevel;\n shell.context.setLogStyle = setLogStyle;\n shell.context.prettifyLogs = prettifyLogs;\n shell.context.printResultsAsTable = printResultsAsTable;\n shell.context.LogStyle = LogStyle;\n shell.context.LogLevel = LogLevel;\n\n // Intercept REPL output to display results as a table if they are arrays\n shell.on('exit', async () => {\n await teardown();\n process.exit();\n });\n\n shell.on('SIGINT', async () => {\n await teardown();\n process.exit();\n });\n};\n\nconst teardown = async () => {\n console.log(color.yellow('Exiting Pongo Shell...'));\n await pongo.close();\n};\n\nprocess.on('uncaughtException', teardown);\nprocess.on('SIGINT', teardown);\n\ninterface ShellOptions {\n database: string;\n collection: string[];\n connectionString?: string;\n disableAutoMigrations: boolean;\n logStyle?: string;\n logLevel?: string;\n prettyLog?: boolean;\n printOptions?: boolean;\n}\n\nconst shellCommand = new Command('shell')\n .description('Start an interactive Pongo shell')\n .option(\n '-cs, --connectionString <string>',\n 'Connection string for the database',\n )\n .option('-db, --database <string>', 'Database name to connect', 'postgres')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-no-migrations, --disable-auto-migrations',\n 'Disable automatic migrations',\n )\n .option('-o, --print-options', 'Print shell options')\n .option(\n '-ll, --log-level <logLevel>',\n 'Log level: DISABLED, INFO, LOG, WARN, ERROR',\n 'DISABLED',\n )\n .option('-ls, --log-style', 'Log style: RAW, PRETTY', 'RAW')\n .option('-p, --pretty-log', 'Turn on logging with prettified output')\n .action(async (options: ShellOptions) => {\n const { collection, database } = options;\n const connectionString = options.connectionString;\n\n await startRepl({\n logging: {\n printOptions: options.printOptions === true,\n logStyle: options.prettyLog\n ? LogStyle.PRETTY\n : ((options.logStyle as LogStyle | undefined) ?? LogStyle.RAW),\n logLevel: options.logLevel\n ? (options.logLevel as LogLevel)\n : options.prettyLog\n ? LogLevel.INFO\n : LogLevel.DISABLED,\n },\n schema: {\n collections: collection,\n database,\n autoMigration: options.disableAutoMigrations\n ? 'None'\n : 'CreateOrUpdate',\n },\n connectionString,\n });\n });\n\nexport { shellCommand };\n"]}
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
pongoCollectionSchemaComponent,
|
|
6
6
|
pongoSchema,
|
|
7
7
|
toDbSchemaMetadata
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OO7GMTMP.js";
|
|
9
9
|
|
|
10
10
|
// src/cli.ts
|
|
11
11
|
import { Command as Command4 } from "commander";
|
|
@@ -310,7 +310,7 @@ var prettifyLogs = (logLevel) => {
|
|
|
310
310
|
var startRepl = async (options) => {
|
|
311
311
|
setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);
|
|
312
312
|
setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);
|
|
313
|
-
console.log(color.green("Starting Pongo Shell (version: 0.17.0-alpha.
|
|
313
|
+
console.log(color.green("Starting Pongo Shell (version: 0.17.0-alpha.5)"));
|
|
314
314
|
if (options.logging.printOptions) {
|
|
315
315
|
console.log(color.green("With Options:"));
|
|
316
316
|
console.log(prettyJson(options));
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/commandLine/configFile.ts","../src/commandLine/migrate.ts","../src/commandLine/shell.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { configCommand, migrateCommand, shellCommand } from './commandLine';\n\nconst program = new Command();\n\nprogram.name('pongo').description('CLI tool for Pongo');\n\nprogram.addCommand(configCommand);\nprogram.addCommand(migrateCommand);\nprogram.addCommand(shellCommand);\n\nprogram.parse(process.argv);\n\nexport default program;\n","import { Command } from 'commander';\nimport fs from 'node:fs';\nimport {\n objectEntries,\n toDbSchemaMetadata,\n type PongoDbSchemaMetadata,\n type PongoSchemaConfig,\n} from '../core';\n\nconst formatTypeName = (input: string): string => {\n if (input.length === 0) {\n return input;\n }\n\n let formatted = input.charAt(0).toUpperCase() + input.slice(1);\n\n if (formatted.endsWith('s')) {\n formatted = formatted.slice(0, -1);\n }\n\n return formatted;\n};\n\nconst sampleConfig = (collectionNames: string[] = ['users']) => {\n const types = collectionNames\n .map(\n (name) =>\n `export type ${formatTypeName(name)} = { name: string; description: string; date: Date }`,\n )\n .join('\\n');\n\n const collections = collectionNames\n .map(\n (name) =>\n ` ${name}: pongoSchema.collection<${formatTypeName(name)}>('${name}'),`,\n )\n .join('\\n');\n\n return `import { pongoSchema } from '@event-driven-io/pongo';\n\n${types}\n\nexport default {\n schema: pongoSchema.client({\n database: pongoSchema.db({\n${collections}\n }),\n }),\n};`;\n};\n\nconst missingDefaultExport = `Error: Config should contain default export, e.g.\\n\\n${sampleConfig()}`;\nconst missingSchema = `Error: Config should contain schema property, e.g.\\n\\n${sampleConfig()}`;\nconst missingDbs = `Error: Config should have at least a single database defined, e.g.\\n\\n${sampleConfig()}`;\nconst missingDefaultDb = `Error: Config should have a default database defined (without name or or with default database name), e.g.\\n\\n${sampleConfig()}`;\nconst missingCollections = `Error: Database should have defined at least one collection, e.g.\\n\\n${sampleConfig()}`;\n\nexport const loadConfigFile = async (\n configPath: string,\n): Promise<PongoDbSchemaMetadata> => {\n const configUrl = new URL(configPath, `file://${process.cwd()}/`);\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const imported: Partial<{ default: PongoSchemaConfig }> = await import(\n configUrl.href\n );\n\n const parsed = parseDefaultDbSchema(imported);\n\n if (typeof parsed === 'string') {\n console.error(parsed);\n process.exit(1);\n }\n\n return parsed;\n } catch {\n console.error(`Error: Couldn't load file: ${configUrl.href}`);\n process.exit(1);\n }\n};\n\nexport const generateConfigFile = (\n configPath: string,\n collectionNames: string[],\n): void => {\n try {\n fs.writeFileSync(configPath, sampleConfig(collectionNames), 'utf8');\n console.log(`Configuration file stored at: ${configPath}`);\n } catch (error) {\n console.error(`Error: Couldn't store config file: ${configPath}!`);\n console.error(error);\n process.exit(1);\n }\n};\n\nexport const parseDefaultDbSchema = (\n imported: Partial<{ default: PongoSchemaConfig }>,\n): PongoDbSchemaMetadata | string => {\n if (!imported.default) {\n return missingDefaultExport;\n }\n\n if (!imported.default.schema) {\n return missingSchema;\n }\n\n if (!imported.default.schema.dbs) {\n return missingDbs;\n }\n\n const dbs = objectEntries(imported.default.schema.dbs).map((db) => db[1]);\n\n const defaultDb = dbs.find((db) => db.name === undefined);\n\n if (!defaultDb) {\n return missingDefaultDb;\n }\n\n if (!defaultDb.collections) {\n return missingCollections;\n }\n\n const collections = objectEntries(defaultDb.collections).map((col) => col[1]);\n\n if (collections.length === 0) {\n return missingCollections;\n }\n\n return toDbSchemaMetadata(defaultDb);\n};\n\ntype SampleConfigOptions =\n | {\n collection: string[];\n print?: boolean;\n }\n | {\n collection: string[];\n generate?: boolean;\n file?: string;\n };\n\nexport const configCommand = new Command('config').description(\n 'Manage Pongo configuration',\n);\n\nconfigCommand\n .command('sample')\n .description('Generate or print sample configuration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-f, --file <path>',\n 'Path to configuration file with collection list',\n )\n .option('-g, --generate', 'Generate sample config file')\n .option('-p, --print', 'Print sample config file')\n .action((options: SampleConfigOptions) => {\n const collectionNames =\n options.collection.length > 0 ? options.collection : ['users'];\n\n if (!('print' in options) && !('generate' in options)) {\n console.error(\n 'Error: Please provide either:\\n--print param to print sample config or\\n--generate to generate sample config file',\n );\n process.exit(1);\n }\n\n if ('print' in options) {\n console.log(`${sampleConfig(collectionNames)}`);\n } else if ('generate' in options) {\n if (!options.file) {\n console.error(\n 'Error: You need to provide a config file through a --file',\n );\n process.exit(1);\n }\n\n generateConfigFile(options.file, collectionNames);\n }\n });\n","import { combineMigrations } from '@event-driven-io/dumbo';\nimport {\n dumbo,\n migrationTableSchemaComponent,\n runPostgreSQLMigrations,\n} from '@event-driven-io/dumbo/pg';\nimport { Command } from 'commander';\nimport { pongoCollectionSchemaComponent } from '../core';\nimport { loadConfigFile } from './configFile';\n\ninterface MigrateRunOptions {\n collection: string[];\n connectionString: string;\n config?: string;\n dryRun?: boolean;\n}\n\ninterface MigrateSqlOptions {\n print?: boolean;\n write?: string;\n config?: string;\n collection: string[];\n}\n\nexport const migrateCommand = new Command('migrate').description(\n 'Manage database migrations',\n);\n\nmigrateCommand\n .command('run')\n .description('Run database migrations')\n .option(\n '-cs, --connection-string <string>',\n 'Connection string for the database',\n )\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('-dr, --dryRun', 'Perform dry run without commiting changes', false)\n .action(async (options: MigrateRunOptions) => {\n const { collection, dryRun } = options;\n const connectionString =\n options.connectionString ?? process.env.DB_CONNECTION_STRING;\n let collectionNames: string[];\n\n if (!connectionString) {\n console.error(\n 'Error: Connection string is required. Provide it either as a \"--connection-string\" parameter or through the DB_CONNECTION_STRING environment variable.' +\n '\\nFor instance: --connection-string postgresql://postgres:postgres@localhost:5432/postgres',\n );\n process.exit(1);\n }\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const pool = dumbo({ connectionString });\n\n const migrations = collectionNames.flatMap((collectionsName) =>\n pongoCollectionSchemaComponent(collectionsName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n );\n\n await runPostgreSQLMigrations(pool, migrations, {\n dryRun,\n });\n });\n\nmigrateCommand\n .command('sql')\n .description('Generate SQL for database migration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('--print', 'Print the SQL to the console (default)', true)\n //.option('--write <filename>', 'Write the SQL to a specified file')\n .action(async (options: MigrateSqlOptions) => {\n const { collection } = options;\n\n let collectionNames: string[];\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const coreMigrations = migrationTableSchemaComponent.migrations({\n connector: 'PostgreSQL:pg',\n });\n const migrations = [\n ...coreMigrations,\n ...collectionNames.flatMap((collectionName) =>\n pongoCollectionSchemaComponent(collectionName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n ),\n ];\n\n console.log('Printing SQL:');\n console.log(combineMigrations(...migrations));\n });\n","import {\n color,\n LogLevel,\n LogStyle,\n prettyJson,\n SQL,\n type MigrationStyle,\n} from '@event-driven-io/dumbo';\nimport { checkConnection } from '@event-driven-io/dumbo/pg';\nimport Table from 'cli-table3';\nimport { Command } from 'commander';\nimport repl from 'node:repl';\nimport {\n pongoClient,\n pongoSchema,\n type PongoClient,\n type PongoCollectionSchema,\n type PongoDb,\n} from '../core';\n\nlet pongo: PongoClient;\n\nconst calculateColumnWidths = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n results: any[],\n columnNames: string[],\n): number[] => {\n const columnWidths = columnNames.map((col) => {\n const maxWidth = Math.max(\n col.length, // Header size\n ...results.map((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] ? String(result[col]).length : 0,\n ),\n );\n return maxWidth + 2; // Add padding\n });\n return columnWidths;\n};\n\nlet shouldDisplayResultsAsTable = false;\n\nconst printResultsAsTable = (print?: boolean) =>\n (shouldDisplayResultsAsTable = print === undefined || print === true);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst printOutput = (obj: any): string =>\n Array.isArray(obj) && shouldDisplayResultsAsTable\n ? displayResultsAsTable(obj)\n : prettyJson(obj);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst displayResultsAsTable = (results: any[]): string => {\n if (results.length === 0) {\n return color.yellow('No documents found.');\n }\n\n const columnNames = results\n\n .flatMap((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n typeof result === 'object' ? Object.keys(result) : typeof result,\n )\n .filter((value, index, array) => array.indexOf(value) === index);\n\n const columnWidths = calculateColumnWidths(results, columnNames);\n\n const table = new Table({\n head: columnNames.map((col) => color.cyan(col)),\n colWidths: columnWidths,\n });\n\n results.forEach((result) => {\n table.push(\n columnNames.map((col) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] !== undefined\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Array.isArray(result[col])\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n displayResultsAsTable(result[col])\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n prettyJson(result[col])\n : typeof result === 'object'\n ? ''\n : result != undefined && result != undefined\n ? prettyJson(result)\n : '',\n ),\n );\n });\n\n return table.toString();\n};\n\nconst setLogLevel = (logLevel: string) => {\n process.env.DUMBO_LOG_LEVEL = logLevel;\n};\n\nconst setLogStyle = (logLevel: string) => {\n process.env.DUMBO_LOG_STYLE = logLevel;\n};\n\nconst prettifyLogs = (logLevel?: string) => {\n if (logLevel !== undefined) setLogLevel(logLevel);\n setLogStyle(LogStyle.PRETTY);\n};\n\nconst startRepl = async (options: {\n logging: {\n printOptions: boolean;\n logLevel: LogLevel;\n logStyle: LogStyle;\n };\n schema: {\n database: string;\n collections: string[];\n autoMigration: MigrationStyle;\n };\n connectionString: string | undefined;\n}) => {\n // TODO: This will change when we have proper tracing and logging config\n // For now, that's enough\n setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);\n setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);\n\n console.log(color.green('Starting Pongo Shell (version: 0.17.0-alpha.4)'));\n\n if (options.logging.printOptions) {\n console.log(color.green('With Options:'));\n console.log(prettyJson(options));\n }\n\n const connectionString =\n options.connectionString ??\n process.env.DB_CONNECTION_STRING ??\n 'postgresql://postgres:postgres@localhost:5432/postgres';\n\n if (!(options.connectionString ?? process.env.DB_CONNECTION_STRING)) {\n console.log(\n color.yellow(\n `No connection string provided, using: 'postgresql://postgres:postgres@localhost:5432/postgres'`,\n ),\n );\n }\n\n const connectionCheck = await checkConnection(connectionString);\n\n if (!connectionCheck.successful) {\n if (connectionCheck.errorType === 'ConnectionRefused') {\n console.error(\n color.red(\n `Connection was refused. Check if the PostgreSQL server is running and accessible.`,\n ),\n );\n } else if (connectionCheck.errorType === 'Authentication') {\n console.error(\n color.red(\n `Authentication failed. Check the username and password in the connection string.`,\n ),\n );\n } else {\n console.error(color.red('Error connecting to PostgreSQL server'));\n }\n console.log(color.red('Exiting Pongo Shell...'));\n process.exit();\n }\n\n console.log(color.green(`Successfully connected`));\n console.log(color.green('Use db.<collection>.<method>() to query.'));\n\n const shell = repl.start({\n prompt: color.green('pongo> '),\n useGlobal: true,\n breakEvalOnSigint: true,\n writer: printOutput,\n });\n\n let db: PongoDb;\n\n if (options.schema.collections.length > 0) {\n const collectionsSchema: Record<string, PongoCollectionSchema> = {};\n\n for (const collectionName of options.schema.collections) {\n collectionsSchema[collectionName] =\n pongoSchema.collection(collectionName);\n }\n\n const schema = pongoSchema.client({\n database: pongoSchema.db(options.schema.database, collectionsSchema),\n });\n\n const typedClient = pongoClient(connectionString, {\n schema: {\n definition: schema,\n autoMigration: options.schema.autoMigration,\n },\n });\n\n db = typedClient.database;\n\n for (const collectionName of options.schema.collections) {\n shell.context[collectionName] = typedClient.database[collectionName];\n }\n\n pongo = typedClient;\n } else {\n pongo = pongoClient(connectionString, {\n schema: { autoMigration: options.schema.autoMigration },\n });\n\n db = pongo.db(options.schema.database);\n }\n\n shell.context.pongo = pongo;\n shell.context.db = db;\n\n // helpers\n shell.context.SQL = SQL;\n shell.context.setLogLevel = setLogLevel;\n shell.context.setLogStyle = setLogStyle;\n shell.context.prettifyLogs = prettifyLogs;\n shell.context.printResultsAsTable = printResultsAsTable;\n shell.context.LogStyle = LogStyle;\n shell.context.LogLevel = LogLevel;\n\n // Intercept REPL output to display results as a table if they are arrays\n shell.on('exit', async () => {\n await teardown();\n process.exit();\n });\n\n shell.on('SIGINT', async () => {\n await teardown();\n process.exit();\n });\n};\n\nconst teardown = async () => {\n console.log(color.yellow('Exiting Pongo Shell...'));\n await pongo.close();\n};\n\nprocess.on('uncaughtException', teardown);\nprocess.on('SIGINT', teardown);\n\ninterface ShellOptions {\n database: string;\n collection: string[];\n connectionString?: string;\n disableAutoMigrations: boolean;\n logStyle?: string;\n logLevel?: string;\n prettyLog?: boolean;\n printOptions?: boolean;\n}\n\nconst shellCommand = new Command('shell')\n .description('Start an interactive Pongo shell')\n .option(\n '-cs, --connectionString <string>',\n 'Connection string for the database',\n )\n .option('-db, --database <string>', 'Database name to connect', 'postgres')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-no-migrations, --disable-auto-migrations',\n 'Disable automatic migrations',\n )\n .option('-o, --print-options', 'Print shell options')\n .option(\n '-ll, --log-level <logLevel>',\n 'Log level: DISABLED, INFO, LOG, WARN, ERROR',\n 'DISABLED',\n )\n .option('-ls, --log-style', 'Log style: RAW, PRETTY', 'RAW')\n .option('-p, --pretty-log', 'Turn on logging with prettified output')\n .action(async (options: ShellOptions) => {\n const { collection, database } = options;\n const connectionString = options.connectionString;\n\n await startRepl({\n logging: {\n printOptions: options.printOptions === true,\n logStyle: options.prettyLog\n ? LogStyle.PRETTY\n : ((options.logStyle as LogStyle | undefined) ?? LogStyle.RAW),\n logLevel: options.logLevel\n ? (options.logLevel as LogLevel)\n : options.prettyLog\n ? LogLevel.INFO\n : LogLevel.DISABLED,\n },\n schema: {\n collections: collection,\n database,\n autoMigration: options.disableAutoMigrations\n ? 'None'\n : 'CreateOrUpdate',\n },\n connectionString,\n });\n });\n\nexport { shellCommand };\n"],"mappings":";;;;;;;;;;AACA,SAAS,WAAAA,gBAAe;;;ACDxB,SAAS,eAAe;AACxB,OAAO,QAAQ;AAQf,IAAM,iBAAiB,CAAC,UAA0B;AAChD,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,MAAM,OAAO,CAAC,EAAE,YAAY,IAAI,MAAM,MAAM,CAAC;AAE7D,MAAI,UAAU,SAAS,GAAG,GAAG;AAC3B,gBAAY,UAAU,MAAM,GAAG,EAAE;AAAA,EACnC;AAEA,SAAO;AACT;AAEA,IAAM,eAAe,CAAC,kBAA4B,CAAC,OAAO,MAAM;AAC9D,QAAM,QAAQ,gBACX;AAAA,IACC,CAAC,SACC,eAAe,eAAe,IAAI,CAAC;AAAA,EACvC,EACC,KAAK,IAAI;AAEZ,QAAM,cAAc,gBACjB;AAAA,IACC,CAAC,SACC,SAAS,IAAI,4BAA4B,eAAe,IAAI,CAAC,MAAM,IAAI;AAAA,EAC3E,EACC,KAAK,IAAI;AAEZ,SAAO;AAAA;AAAA,EAEP,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA,EAKL,WAAW;AAAA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,MAAM;AACpB;AAEA,QAAQ,GAAG,qBAAqB,QAAQ;AACxC,QAAQ,GAAG,UAAU,QAAQ;AAa7B,IAAM,eAAe,IAAIC,SAAQ,OAAO,EACrC,YAAY,kCAAkC,EAC9C;AAAA,EACC;AAAA,EACA;AACF,EACC,OAAO,4BAA4B,4BAA4B,UAAU,EACzE;AAAA,EACC;AAAA,EACA;AAAA,EACA,CAAC,OAAe,aAAuB;AAErC,WAAO,SAAS,OAAO,CAAC,KAAK,CAAC;AAAA,EAChC;AAAA,EACA,CAAC;AACH,EACC;AAAA,EACC;AAAA,EACA;AACF,EACC,OAAO,uBAAuB,qBAAqB,EACnD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACF,EACC,OAAO,oBAAoB,0BAA0B,KAAK,EAC1D,OAAO,oBAAoB,wCAAwC,EACnE,OAAO,OAAO,YAA0B;AACvC,QAAM,EAAE,YAAY,SAAS,IAAI;AACjC,QAAM,mBAAmB,QAAQ;AAEjC,QAAM,UAAU;AAAA,IACd,SAAS;AAAA,MACP,cAAc,QAAQ,iBAAiB;AAAA,MACvC,UAAU,QAAQ,YACd,SAAS,SACP,QAAQ,YAAqC,SAAS;AAAA,MAC5D,UAAU,QAAQ,WACb,QAAQ,WACT,QAAQ,YACN,SAAS,OACT,SAAS;AAAA,IACjB;AAAA,IACA,QAAQ;AAAA,MACN,aAAa;AAAA,MACb;AAAA,MACA,eAAe,QAAQ,wBACnB,SACA;AAAA,IACN;AAAA,IACA;AAAA,EACF,CAAC;AACH,CAAC;;;AHlTH,IAAM,UAAU,IAAIC,SAAQ;AAE5B,QAAQ,KAAK,OAAO,EAAE,YAAY,oBAAoB;AAEtD,QAAQ,WAAW,aAAa;AAChC,QAAQ,WAAW,cAAc;AACjC,QAAQ,WAAW,YAAY;AAE/B,QAAQ,MAAM,QAAQ,IAAI;AAE1B,IAAO,cAAQ;","names":["Command","Command","Command","Command","Command","Command"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/commandLine/configFile.ts","../src/commandLine/migrate.ts","../src/commandLine/shell.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { configCommand, migrateCommand, shellCommand } from './commandLine';\n\nconst program = new Command();\n\nprogram.name('pongo').description('CLI tool for Pongo');\n\nprogram.addCommand(configCommand);\nprogram.addCommand(migrateCommand);\nprogram.addCommand(shellCommand);\n\nprogram.parse(process.argv);\n\nexport default program;\n","import { Command } from 'commander';\nimport fs from 'node:fs';\nimport {\n objectEntries,\n toDbSchemaMetadata,\n type PongoDbSchemaMetadata,\n type PongoSchemaConfig,\n} from '../core';\n\nconst formatTypeName = (input: string): string => {\n if (input.length === 0) {\n return input;\n }\n\n let formatted = input.charAt(0).toUpperCase() + input.slice(1);\n\n if (formatted.endsWith('s')) {\n formatted = formatted.slice(0, -1);\n }\n\n return formatted;\n};\n\nconst sampleConfig = (collectionNames: string[] = ['users']) => {\n const types = collectionNames\n .map(\n (name) =>\n `export type ${formatTypeName(name)} = { name: string; description: string; date: Date }`,\n )\n .join('\\n');\n\n const collections = collectionNames\n .map(\n (name) =>\n ` ${name}: pongoSchema.collection<${formatTypeName(name)}>('${name}'),`,\n )\n .join('\\n');\n\n return `import { pongoSchema } from '@event-driven-io/pongo';\n\n${types}\n\nexport default {\n schema: pongoSchema.client({\n database: pongoSchema.db({\n${collections}\n }),\n }),\n};`;\n};\n\nconst missingDefaultExport = `Error: Config should contain default export, e.g.\\n\\n${sampleConfig()}`;\nconst missingSchema = `Error: Config should contain schema property, e.g.\\n\\n${sampleConfig()}`;\nconst missingDbs = `Error: Config should have at least a single database defined, e.g.\\n\\n${sampleConfig()}`;\nconst missingDefaultDb = `Error: Config should have a default database defined (without name or or with default database name), e.g.\\n\\n${sampleConfig()}`;\nconst missingCollections = `Error: Database should have defined at least one collection, e.g.\\n\\n${sampleConfig()}`;\n\nexport const loadConfigFile = async (\n configPath: string,\n): Promise<PongoDbSchemaMetadata> => {\n const configUrl = new URL(configPath, `file://${process.cwd()}/`);\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const imported: Partial<{ default: PongoSchemaConfig }> = await import(\n configUrl.href\n );\n\n const parsed = parseDefaultDbSchema(imported);\n\n if (typeof parsed === 'string') {\n console.error(parsed);\n process.exit(1);\n }\n\n return parsed;\n } catch {\n console.error(`Error: Couldn't load file: ${configUrl.href}`);\n process.exit(1);\n }\n};\n\nexport const generateConfigFile = (\n configPath: string,\n collectionNames: string[],\n): void => {\n try {\n fs.writeFileSync(configPath, sampleConfig(collectionNames), 'utf8');\n console.log(`Configuration file stored at: ${configPath}`);\n } catch (error) {\n console.error(`Error: Couldn't store config file: ${configPath}!`);\n console.error(error);\n process.exit(1);\n }\n};\n\nexport const parseDefaultDbSchema = (\n imported: Partial<{ default: PongoSchemaConfig }>,\n): PongoDbSchemaMetadata | string => {\n if (!imported.default) {\n return missingDefaultExport;\n }\n\n if (!imported.default.schema) {\n return missingSchema;\n }\n\n if (!imported.default.schema.dbs) {\n return missingDbs;\n }\n\n const dbs = objectEntries(imported.default.schema.dbs).map((db) => db[1]);\n\n const defaultDb = dbs.find((db) => db.name === undefined);\n\n if (!defaultDb) {\n return missingDefaultDb;\n }\n\n if (!defaultDb.collections) {\n return missingCollections;\n }\n\n const collections = objectEntries(defaultDb.collections).map((col) => col[1]);\n\n if (collections.length === 0) {\n return missingCollections;\n }\n\n return toDbSchemaMetadata(defaultDb);\n};\n\ntype SampleConfigOptions =\n | {\n collection: string[];\n print?: boolean;\n }\n | {\n collection: string[];\n generate?: boolean;\n file?: string;\n };\n\nexport const configCommand = new Command('config').description(\n 'Manage Pongo configuration',\n);\n\nconfigCommand\n .command('sample')\n .description('Generate or print sample configuration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-f, --file <path>',\n 'Path to configuration file with collection list',\n )\n .option('-g, --generate', 'Generate sample config file')\n .option('-p, --print', 'Print sample config file')\n .action((options: SampleConfigOptions) => {\n const collectionNames =\n options.collection.length > 0 ? options.collection : ['users'];\n\n if (!('print' in options) && !('generate' in options)) {\n console.error(\n 'Error: Please provide either:\\n--print param to print sample config or\\n--generate to generate sample config file',\n );\n process.exit(1);\n }\n\n if ('print' in options) {\n console.log(`${sampleConfig(collectionNames)}`);\n } else if ('generate' in options) {\n if (!options.file) {\n console.error(\n 'Error: You need to provide a config file through a --file',\n );\n process.exit(1);\n }\n\n generateConfigFile(options.file, collectionNames);\n }\n });\n","import { combineMigrations } from '@event-driven-io/dumbo';\nimport {\n dumbo,\n migrationTableSchemaComponent,\n runPostgreSQLMigrations,\n} from '@event-driven-io/dumbo/pg';\nimport { Command } from 'commander';\nimport { pongoCollectionSchemaComponent } from '../core';\nimport { loadConfigFile } from './configFile';\n\ninterface MigrateRunOptions {\n collection: string[];\n connectionString: string;\n config?: string;\n dryRun?: boolean;\n}\n\ninterface MigrateSqlOptions {\n print?: boolean;\n write?: string;\n config?: string;\n collection: string[];\n}\n\nexport const migrateCommand = new Command('migrate').description(\n 'Manage database migrations',\n);\n\nmigrateCommand\n .command('run')\n .description('Run database migrations')\n .option(\n '-cs, --connection-string <string>',\n 'Connection string for the database',\n )\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('-dr, --dryRun', 'Perform dry run without commiting changes', false)\n .action(async (options: MigrateRunOptions) => {\n const { collection, dryRun } = options;\n const connectionString =\n options.connectionString ?? process.env.DB_CONNECTION_STRING;\n let collectionNames: string[];\n\n if (!connectionString) {\n console.error(\n 'Error: Connection string is required. Provide it either as a \"--connection-string\" parameter or through the DB_CONNECTION_STRING environment variable.' +\n '\\nFor instance: --connection-string postgresql://postgres:postgres@localhost:5432/postgres',\n );\n process.exit(1);\n }\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const pool = dumbo({ connectionString });\n\n const migrations = collectionNames.flatMap((collectionsName) =>\n pongoCollectionSchemaComponent(collectionsName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n );\n\n await runPostgreSQLMigrations(pool, migrations, {\n dryRun,\n });\n });\n\nmigrateCommand\n .command('sql')\n .description('Generate SQL for database migration')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option('-f, --config <path>', 'Path to configuration file with Pongo config')\n .option('--print', 'Print the SQL to the console (default)', true)\n //.option('--write <filename>', 'Write the SQL to a specified file')\n .action(async (options: MigrateSqlOptions) => {\n const { collection } = options;\n\n let collectionNames: string[];\n\n if (options.config) {\n const config = await loadConfigFile(options.config);\n\n collectionNames = config.collections.map((c) => c.name);\n } else if (collection) {\n collectionNames = collection;\n } else {\n console.error(\n 'Error: You need to provide at least one collection name. Provide it either through \"--config\" file or as a \"--collection\" parameter.',\n );\n process.exit(1);\n }\n\n const coreMigrations = migrationTableSchemaComponent.migrations({\n connector: 'PostgreSQL:pg',\n });\n const migrations = [\n ...coreMigrations,\n ...collectionNames.flatMap((collectionName) =>\n pongoCollectionSchemaComponent(collectionName).migrations({\n connector: 'PostgreSQL:pg', // TODO: Provide connector here\n }),\n ),\n ];\n\n console.log('Printing SQL:');\n console.log(combineMigrations(...migrations));\n });\n","import {\n color,\n LogLevel,\n LogStyle,\n prettyJson,\n SQL,\n type MigrationStyle,\n} from '@event-driven-io/dumbo';\nimport { checkConnection } from '@event-driven-io/dumbo/pg';\nimport Table from 'cli-table3';\nimport { Command } from 'commander';\nimport repl from 'node:repl';\nimport {\n pongoClient,\n pongoSchema,\n type PongoClient,\n type PongoCollectionSchema,\n type PongoDb,\n} from '../core';\n\nlet pongo: PongoClient;\n\nconst calculateColumnWidths = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n results: any[],\n columnNames: string[],\n): number[] => {\n const columnWidths = columnNames.map((col) => {\n const maxWidth = Math.max(\n col.length, // Header size\n ...results.map((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] ? String(result[col]).length : 0,\n ),\n );\n return maxWidth + 2; // Add padding\n });\n return columnWidths;\n};\n\nlet shouldDisplayResultsAsTable = false;\n\nconst printResultsAsTable = (print?: boolean) =>\n (shouldDisplayResultsAsTable = print === undefined || print === true);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst printOutput = (obj: any): string =>\n Array.isArray(obj) && shouldDisplayResultsAsTable\n ? displayResultsAsTable(obj)\n : prettyJson(obj);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst displayResultsAsTable = (results: any[]): string => {\n if (results.length === 0) {\n return color.yellow('No documents found.');\n }\n\n const columnNames = results\n\n .flatMap((result) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n typeof result === 'object' ? Object.keys(result) : typeof result,\n )\n .filter((value, index, array) => array.indexOf(value) === index);\n\n const columnWidths = calculateColumnWidths(results, columnNames);\n\n const table = new Table({\n head: columnNames.map((col) => color.cyan(col)),\n colWidths: columnWidths,\n });\n\n results.forEach((result) => {\n table.push(\n columnNames.map((col) =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n result[col] !== undefined\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Array.isArray(result[col])\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n displayResultsAsTable(result[col])\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n prettyJson(result[col])\n : typeof result === 'object'\n ? ''\n : result != undefined && result != undefined\n ? prettyJson(result)\n : '',\n ),\n );\n });\n\n return table.toString();\n};\n\nconst setLogLevel = (logLevel: string) => {\n process.env.DUMBO_LOG_LEVEL = logLevel;\n};\n\nconst setLogStyle = (logLevel: string) => {\n process.env.DUMBO_LOG_STYLE = logLevel;\n};\n\nconst prettifyLogs = (logLevel?: string) => {\n if (logLevel !== undefined) setLogLevel(logLevel);\n setLogStyle(LogStyle.PRETTY);\n};\n\nconst startRepl = async (options: {\n logging: {\n printOptions: boolean;\n logLevel: LogLevel;\n logStyle: LogStyle;\n };\n schema: {\n database: string;\n collections: string[];\n autoMigration: MigrationStyle;\n };\n connectionString: string | undefined;\n}) => {\n // TODO: This will change when we have proper tracing and logging config\n // For now, that's enough\n setLogLevel(process.env.DUMBO_LOG_LEVEL ?? options.logging.logLevel);\n setLogStyle(process.env.DUMBO_LOG_STYLE ?? options.logging.logStyle);\n\n console.log(color.green('Starting Pongo Shell (version: 0.17.0-alpha.5)'));\n\n if (options.logging.printOptions) {\n console.log(color.green('With Options:'));\n console.log(prettyJson(options));\n }\n\n const connectionString =\n options.connectionString ??\n process.env.DB_CONNECTION_STRING ??\n 'postgresql://postgres:postgres@localhost:5432/postgres';\n\n if (!(options.connectionString ?? process.env.DB_CONNECTION_STRING)) {\n console.log(\n color.yellow(\n `No connection string provided, using: 'postgresql://postgres:postgres@localhost:5432/postgres'`,\n ),\n );\n }\n\n const connectionCheck = await checkConnection(connectionString);\n\n if (!connectionCheck.successful) {\n if (connectionCheck.errorType === 'ConnectionRefused') {\n console.error(\n color.red(\n `Connection was refused. Check if the PostgreSQL server is running and accessible.`,\n ),\n );\n } else if (connectionCheck.errorType === 'Authentication') {\n console.error(\n color.red(\n `Authentication failed. Check the username and password in the connection string.`,\n ),\n );\n } else {\n console.error(color.red('Error connecting to PostgreSQL server'));\n }\n console.log(color.red('Exiting Pongo Shell...'));\n process.exit();\n }\n\n console.log(color.green(`Successfully connected`));\n console.log(color.green('Use db.<collection>.<method>() to query.'));\n\n const shell = repl.start({\n prompt: color.green('pongo> '),\n useGlobal: true,\n breakEvalOnSigint: true,\n writer: printOutput,\n });\n\n let db: PongoDb;\n\n if (options.schema.collections.length > 0) {\n const collectionsSchema: Record<string, PongoCollectionSchema> = {};\n\n for (const collectionName of options.schema.collections) {\n collectionsSchema[collectionName] =\n pongoSchema.collection(collectionName);\n }\n\n const schema = pongoSchema.client({\n database: pongoSchema.db(options.schema.database, collectionsSchema),\n });\n\n const typedClient = pongoClient(connectionString, {\n schema: {\n definition: schema,\n autoMigration: options.schema.autoMigration,\n },\n });\n\n db = typedClient.database;\n\n for (const collectionName of options.schema.collections) {\n shell.context[collectionName] = typedClient.database[collectionName];\n }\n\n pongo = typedClient;\n } else {\n pongo = pongoClient(connectionString, {\n schema: { autoMigration: options.schema.autoMigration },\n });\n\n db = pongo.db(options.schema.database);\n }\n\n shell.context.pongo = pongo;\n shell.context.db = db;\n\n // helpers\n shell.context.SQL = SQL;\n shell.context.setLogLevel = setLogLevel;\n shell.context.setLogStyle = setLogStyle;\n shell.context.prettifyLogs = prettifyLogs;\n shell.context.printResultsAsTable = printResultsAsTable;\n shell.context.LogStyle = LogStyle;\n shell.context.LogLevel = LogLevel;\n\n // Intercept REPL output to display results as a table if they are arrays\n shell.on('exit', async () => {\n await teardown();\n process.exit();\n });\n\n shell.on('SIGINT', async () => {\n await teardown();\n process.exit();\n });\n};\n\nconst teardown = async () => {\n console.log(color.yellow('Exiting Pongo Shell...'));\n await pongo.close();\n};\n\nprocess.on('uncaughtException', teardown);\nprocess.on('SIGINT', teardown);\n\ninterface ShellOptions {\n database: string;\n collection: string[];\n connectionString?: string;\n disableAutoMigrations: boolean;\n logStyle?: string;\n logLevel?: string;\n prettyLog?: boolean;\n printOptions?: boolean;\n}\n\nconst shellCommand = new Command('shell')\n .description('Start an interactive Pongo shell')\n .option(\n '-cs, --connectionString <string>',\n 'Connection string for the database',\n )\n .option('-db, --database <string>', 'Database name to connect', 'postgres')\n .option(\n '-col, --collection <name>',\n 'Specify the collection name',\n (value: string, previous: string[]) => {\n // Accumulate collection names into an array (explicitly typing `previous` as `string[]`)\n return previous.concat([value]);\n },\n [] as string[],\n )\n .option(\n '-no-migrations, --disable-auto-migrations',\n 'Disable automatic migrations',\n )\n .option('-o, --print-options', 'Print shell options')\n .option(\n '-ll, --log-level <logLevel>',\n 'Log level: DISABLED, INFO, LOG, WARN, ERROR',\n 'DISABLED',\n )\n .option('-ls, --log-style', 'Log style: RAW, PRETTY', 'RAW')\n .option('-p, --pretty-log', 'Turn on logging with prettified output')\n .action(async (options: ShellOptions) => {\n const { collection, database } = options;\n const connectionString = options.connectionString;\n\n await startRepl({\n logging: {\n printOptions: options.printOptions === true,\n logStyle: options.prettyLog\n ? LogStyle.PRETTY\n : ((options.logStyle as LogStyle | undefined) ?? LogStyle.RAW),\n logLevel: options.logLevel\n ? (options.logLevel as LogLevel)\n : options.prettyLog\n ? LogLevel.INFO\n : LogLevel.DISABLED,\n },\n schema: {\n collections: collection,\n database,\n autoMigration: options.disableAutoMigrations\n ? 'None'\n : 'CreateOrUpdate',\n },\n connectionString,\n });\n });\n\nexport { shellCommand };\n"],"mappings":";;;;;;;;;;AACA,SAAS,WAAAA,gBAAe;;;ACDxB,SAAS,eAAe;AACxB,OAAO,QAAQ;AAQf,IAAM,iBAAiB,CAAC,UAA0B;AAChD,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,MAAM,OAAO,CAAC,EAAE,YAAY,IAAI,MAAM,MAAM,CAAC;AAE7D,MAAI,UAAU,SAAS,GAAG,GAAG;AAC3B,gBAAY,UAAU,MAAM,GAAG,EAAE;AAAA,EACnC;AAEA,SAAO;AACT;AAEA,IAAM,eAAe,CAAC,kBAA4B,CAAC,OAAO,MAAM;AAC9D,QAAM,QAAQ,gBACX;AAAA,IACC,CAAC,SACC,eAAe,eAAe,IAAI,CAAC;AAAA,EACvC,EACC,KAAK,IAAI;AAEZ,QAAM,c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AAQ,WAAW,aAAa;AAChC,QAAQ,WAAW,cAAc;AACjC,QAAQ,WAAW,YAAY;AAE/B,QAAQ,MAAM,QAAQ,IAAI;AAE1B,IAAO,cAAQ;","names":["Command","Command","Command","Command","Command","Command"]}
|
package/dist/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var _chunkAV4SHJQBcjs = require('./chunk-AV4SHJQB.cjs');
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
@@ -75,5 +75,5 @@ var _chunkATI5CCCTcjs = require('./chunk-ATI5CCCT.cjs');
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
exports.ConcurrencyError =
|
|
78
|
+
exports.ConcurrencyError = _chunkAV4SHJQBcjs.ConcurrencyError; exports.DOCUMENT_DOES_NOT_EXIST = _chunkAV4SHJQBcjs.DOCUMENT_DOES_NOT_EXIST; exports.DOCUMENT_EXISTS = _chunkAV4SHJQBcjs.DOCUMENT_EXISTS; exports.NO_CONCURRENCY_CHECK = _chunkAV4SHJQBcjs.NO_CONCURRENCY_CHECK; exports.ObjectId = _chunkAV4SHJQBcjs.ObjectId; exports.OperatorMap = _chunkAV4SHJQBcjs.OperatorMap; exports.PongoError = _chunkAV4SHJQBcjs.PongoError; exports.QueryOperators = _chunkAV4SHJQBcjs.QueryOperators; exports.clientToDbOptions = _chunkAV4SHJQBcjs.clientToDbOptions; exports.deepEquals = _chunkAV4SHJQBcjs.deepEquals; exports.expectedVersion = _chunkAV4SHJQBcjs.expectedVersion; exports.expectedVersionValue = _chunkAV4SHJQBcjs.expectedVersionValue; exports.getPongoDb = _chunkAV4SHJQBcjs.getPongoDb; exports.hasOperators = _chunkAV4SHJQBcjs.hasOperators; exports.isEquatable = _chunkAV4SHJQBcjs.isEquatable; exports.isGeneralExpectedDocumentVersion = _chunkAV4SHJQBcjs.isGeneralExpectedDocumentVersion; exports.isNumber = _chunkAV4SHJQBcjs.isNumber; exports.isOperator = _chunkAV4SHJQBcjs.isOperator; exports.isPostgresClientOptions = _chunkAV4SHJQBcjs.isPostgresClientOptions; exports.isString = _chunkAV4SHJQBcjs.isString; exports.objectEntries = _chunkAV4SHJQBcjs.objectEntries; exports.operationResult = _chunkAV4SHJQBcjs.operationResult; exports.pongoClient = _chunkAV4SHJQBcjs.pongoClient; exports.pongoCollection = _chunkAV4SHJQBcjs.pongoCollection; exports.pongoCollectionPostgreSQLMigrations = _chunkAV4SHJQBcjs.pongoCollectionPostgreSQLMigrations; exports.pongoCollectionSchemaComponent = _chunkAV4SHJQBcjs.pongoCollectionSchemaComponent; exports.pongoDbSchemaComponent = _chunkAV4SHJQBcjs.pongoDbSchemaComponent; exports.pongoSchema = _chunkAV4SHJQBcjs.pongoSchema; exports.pongoSession = _chunkAV4SHJQBcjs.pongoSession; exports.pongoTransaction = _chunkAV4SHJQBcjs.pongoTransaction; exports.postgresDb = _chunkAV4SHJQBcjs.postgresDb; exports.postgresSQLBuilder = _chunkAV4SHJQBcjs.postgresSQLBuilder; exports.proxyClientWithSchema = _chunkAV4SHJQBcjs.proxyClientWithSchema; exports.proxyPongoDbWithSchema = _chunkAV4SHJQBcjs.proxyPongoDbWithSchema; exports.toClientSchemaMetadata = _chunkAV4SHJQBcjs.toClientSchemaMetadata; exports.toDbSchemaMetadata = _chunkAV4SHJQBcjs.toDbSchemaMetadata; exports.transactionExecutorOrDefault = _chunkAV4SHJQBcjs.transactionExecutorOrDefault;
|
|
79
79
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { P as PongoCollectionOptions, b as PongoCollectionSQLBuilder, p as pongoCollection, c as pongoCollectionPostgreSQLMigrations, a as pongoCollectionSchemaComponent, d as postgresSQLBuilder, t as transactionExecutorOrDefault } from './pg-
|
|
2
|
-
import { d as PongoTransactionOptions, e as PongoSession, f as PongoDbTransaction } from './pongoClient-
|
|
3
|
-
export {
|
|
1
|
+
export { P as PongoCollectionOptions, b as PongoCollectionSQLBuilder, p as pongoCollection, c as pongoCollectionPostgreSQLMigrations, a as pongoCollectionSchemaComponent, d as postgresSQLBuilder, t as transactionExecutorOrDefault } from './pg-C9NmCQe7.cjs';
|
|
2
|
+
import { d as PongoTransactionOptions, e as PongoSession, f as PongoDbTransaction } from './pongoClient-D8jPedlZ.cjs';
|
|
3
|
+
export { ae as $inc, af as $push, ac as $set, ad as $unset, A as AllowedDbClientOptions, a7 as AlternativeType, E as CollectionOperationOptions, C as CollectionsMap, a8 as Condition, o as DBsMap, ak as DOCUMENT_DOES_NOT_EXIST, aj as DOCUMENT_EXISTS, K as DeleteManyOptions, J as DeleteOneOptions, a2 as Document, D as DocumentHandler, S as EnhancedOmit, ai as ExpectedDocumentVersion, ag as ExpectedDocumentVersionGeneral, ah as ExpectedDocumentVersionValue, L as FindOptions, H as HandleOptions, M as HasId, Q as InferIdType, F as InsertManyOptions, I as InsertOneOptions, al as NO_CONCURRENCY_CHECK, a6 as NonObjectIdLikeDocument, N as NotPooledPongoOptions, O as ObjectId, a5 as ObjectIdLike, aq as OperationResult, a3 as OptionalId, T as OptionalUnlessRequiredId, W as OptionalUnlessRequiredIdAndVersion, V as OptionalUnlessRequiredVersion, a4 as OptionalVersion, B as PongoClient, b as PongoClientOptions, m as PongoClientSchema, w as PongoClientSchemaMetadata, q as PongoClientWithSchema, c as PongoCollection, k as PongoCollectionSchema, u as PongoCollectionSchemaMetadata, P as PongoDb, i as PongoDbClientOptions, l as PongoDbSchema, v as PongoDbSchemaMetadata, n as PongoDbWithSchema, ax as PongoDeleteManyResult, aw as PongoDeleteResult, ay as PongoDocument, a9 as PongoFilter, ab as PongoFilterOperator, a as PongoHandleResult, at as PongoInsertManyResult, as as PongoInsertOneResult, z as PongoSchemaConfig, ap as PongoUpdate, av as PongoUpdateManyResult, au as PongoUpdateResult, g as PooledPongoClientOptions, az as PostgresDbClientOptions, a1 as RegExpOrString, R as ReplaceOneOptions, aa as RootFilterOperators, G as UpdateManyOptions, U as UpdateOneOptions, X as WithId, $ as WithIdAndVersion, Z as WithVersion, Y as WithoutId, a0 as WithoutIdAndVersion, _ as WithoutVersion, h as clientToDbOptions, ao as expectedVersion, an as expectedVersionValue, j as getPongoDb, am as isGeneralExpectedDocumentVersion, aA as isPostgresClientOptions, ar as operationResult, p as pongoClient, aC as pongoDbSchemaComponent, r as pongoSchema, aB as postgresDb, t as proxyClientWithSchema, s as proxyPongoDbWithSchema, y as toClientSchemaMetadata, x as toDbSchemaMetadata } from './pongoClient-D8jPedlZ.cjs';
|
|
4
4
|
import '@event-driven-io/dumbo';
|
|
5
5
|
import '@event-driven-io/dumbo/pg';
|
|
6
6
|
import 'pg';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { P as PongoCollectionOptions, b as PongoCollectionSQLBuilder, p as pongoCollection, c as pongoCollectionPostgreSQLMigrations, a as pongoCollectionSchemaComponent, d as postgresSQLBuilder, t as transactionExecutorOrDefault } from './pg-
|
|
2
|
-
import { d as PongoTransactionOptions, e as PongoSession, f as PongoDbTransaction } from './pongoClient-
|
|
3
|
-
export {
|
|
1
|
+
export { P as PongoCollectionOptions, b as PongoCollectionSQLBuilder, p as pongoCollection, c as pongoCollectionPostgreSQLMigrations, a as pongoCollectionSchemaComponent, d as postgresSQLBuilder, t as transactionExecutorOrDefault } from './pg-BfTNWLV9.js';
|
|
2
|
+
import { d as PongoTransactionOptions, e as PongoSession, f as PongoDbTransaction } from './pongoClient-D8jPedlZ.js';
|
|
3
|
+
export { ae as $inc, af as $push, ac as $set, ad as $unset, A as AllowedDbClientOptions, a7 as AlternativeType, E as CollectionOperationOptions, C as CollectionsMap, a8 as Condition, o as DBsMap, ak as DOCUMENT_DOES_NOT_EXIST, aj as DOCUMENT_EXISTS, K as DeleteManyOptions, J as DeleteOneOptions, a2 as Document, D as DocumentHandler, S as EnhancedOmit, ai as ExpectedDocumentVersion, ag as ExpectedDocumentVersionGeneral, ah as ExpectedDocumentVersionValue, L as FindOptions, H as HandleOptions, M as HasId, Q as InferIdType, F as InsertManyOptions, I as InsertOneOptions, al as NO_CONCURRENCY_CHECK, a6 as NonObjectIdLikeDocument, N as NotPooledPongoOptions, O as ObjectId, a5 as ObjectIdLike, aq as OperationResult, a3 as OptionalId, T as OptionalUnlessRequiredId, W as OptionalUnlessRequiredIdAndVersion, V as OptionalUnlessRequiredVersion, a4 as OptionalVersion, B as PongoClient, b as PongoClientOptions, m as PongoClientSchema, w as PongoClientSchemaMetadata, q as PongoClientWithSchema, c as PongoCollection, k as PongoCollectionSchema, u as PongoCollectionSchemaMetadata, P as PongoDb, i as PongoDbClientOptions, l as PongoDbSchema, v as PongoDbSchemaMetadata, n as PongoDbWithSchema, ax as PongoDeleteManyResult, aw as PongoDeleteResult, ay as PongoDocument, a9 as PongoFilter, ab as PongoFilterOperator, a as PongoHandleResult, at as PongoInsertManyResult, as as PongoInsertOneResult, z as PongoSchemaConfig, ap as PongoUpdate, av as PongoUpdateManyResult, au as PongoUpdateResult, g as PooledPongoClientOptions, az as PostgresDbClientOptions, a1 as RegExpOrString, R as ReplaceOneOptions, aa as RootFilterOperators, G as UpdateManyOptions, U as UpdateOneOptions, X as WithId, $ as WithIdAndVersion, Z as WithVersion, Y as WithoutId, a0 as WithoutIdAndVersion, _ as WithoutVersion, h as clientToDbOptions, ao as expectedVersion, an as expectedVersionValue, j as getPongoDb, am as isGeneralExpectedDocumentVersion, aA as isPostgresClientOptions, ar as operationResult, p as pongoClient, aC as pongoDbSchemaComponent, r as pongoSchema, aB as postgresDb, t as proxyClientWithSchema, s as proxyPongoDbWithSchema, y as toClientSchemaMetadata, x as toDbSchemaMetadata } from './pongoClient-D8jPedlZ.js';
|
|
4
4
|
import '@event-driven-io/dumbo';
|
|
5
5
|
import '@event-driven-io/dumbo/pg';
|
|
6
6
|
import 'pg';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PongoDb,
|
|
1
|
+
import { P as PongoDb, W as OptionalUnlessRequiredIdAndVersion, a9 as PongoFilter, ap as PongoUpdate, U as UpdateOneOptions, Y as WithoutId, R as ReplaceOneOptions, J as DeleteOneOptions, L as FindOptions, E as CollectionOperationOptions, ay as PongoDocument, c as PongoCollection } from './pongoClient-D8jPedlZ.js';
|
|
2
2
|
import { ConnectorType, Dumbo, SQLMigration, SQL, MigrationStyle, SQLExecutor, SchemaComponent } from '@event-driven-io/dumbo';
|
|
3
3
|
|
|
4
4
|
type PongoCollectionOptions<Connector extends ConnectorType = ConnectorType> = {
|
|
@@ -27,7 +27,7 @@ type PongoCollectionSQLBuilder = {
|
|
|
27
27
|
deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
|
|
28
28
|
deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
29
29
|
findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
|
-
find: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
|
+
find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
|
|
31
31
|
countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
32
32
|
rename: (newName: string) => SQL;
|
|
33
33
|
drop: () => SQL;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PongoDb,
|
|
1
|
+
import { P as PongoDb, W as OptionalUnlessRequiredIdAndVersion, a9 as PongoFilter, ap as PongoUpdate, U as UpdateOneOptions, Y as WithoutId, R as ReplaceOneOptions, J as DeleteOneOptions, L as FindOptions, E as CollectionOperationOptions, ay as PongoDocument, c as PongoCollection } from './pongoClient-D8jPedlZ.cjs';
|
|
2
2
|
import { ConnectorType, Dumbo, SQLMigration, SQL, MigrationStyle, SQLExecutor, SchemaComponent } from '@event-driven-io/dumbo';
|
|
3
3
|
|
|
4
4
|
type PongoCollectionOptions<Connector extends ConnectorType = ConnectorType> = {
|
|
@@ -27,7 +27,7 @@ type PongoCollectionSQLBuilder = {
|
|
|
27
27
|
deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
|
|
28
28
|
deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
29
29
|
findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
|
-
find: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
|
+
find: <T>(filter: PongoFilter<T> | SQL, options?: FindOptions) => SQL;
|
|
31
31
|
countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
32
32
|
rename: (newName: string) => SQL;
|
|
33
33
|
drop: () => SQL;
|
package/dist/pg.cjs
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkAV4SHJQBcjs = require('./chunk-AV4SHJQB.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.isPostgresClientOptions =
|
|
14
|
+
exports.isPostgresClientOptions = _chunkAV4SHJQBcjs.isPostgresClientOptions; exports.pongoCollectionPostgreSQLMigrations = _chunkAV4SHJQBcjs.pongoCollectionPostgreSQLMigrations; exports.pongoDbSchemaComponent = _chunkAV4SHJQBcjs.pongoDbSchemaComponent; exports.postgresDb = _chunkAV4SHJQBcjs.postgresDb; exports.postgresSQLBuilder = _chunkAV4SHJQBcjs.postgresSQLBuilder;
|
|
15
15
|
//# sourceMappingURL=pg.cjs.map
|
package/dist/pg.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { c as pongoCollectionPostgreSQLMigrations, d as postgresSQLBuilder } from './pg-
|
|
1
|
+
export { az as PostgresDbClientOptions, aA as isPostgresClientOptions, aC as pongoDbSchemaComponent, aB as postgresDb } from './pongoClient-D8jPedlZ.cjs';
|
|
2
|
+
export { c as pongoCollectionPostgreSQLMigrations, d as postgresSQLBuilder } from './pg-C9NmCQe7.cjs';
|
|
3
3
|
import '@event-driven-io/dumbo';
|
|
4
4
|
import '@event-driven-io/dumbo/pg';
|
|
5
5
|
import 'pg';
|
package/dist/pg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { c as pongoCollectionPostgreSQLMigrations, d as postgresSQLBuilder } from './pg-
|
|
1
|
+
export { az as PostgresDbClientOptions, aA as isPostgresClientOptions, aC as pongoDbSchemaComponent, aB as postgresDb } from './pongoClient-D8jPedlZ.js';
|
|
2
|
+
export { c as pongoCollectionPostgreSQLMigrations, d as postgresSQLBuilder } from './pg-BfTNWLV9.js';
|
|
3
3
|
import '@event-driven-io/dumbo';
|
|
4
4
|
import '@event-driven-io/dumbo/pg';
|
|
5
5
|
import 'pg';
|
package/dist/pg.js
CHANGED
|
@@ -87,6 +87,10 @@ type DeleteOneOptions = {
|
|
|
87
87
|
type DeleteManyOptions = {
|
|
88
88
|
expectedVersion?: Extract<ExpectedDocumentVersion, 'DOCUMENT_EXISTS' | 'NO_CONCURRENCY_CHECK'>;
|
|
89
89
|
} & CollectionOperationOptions;
|
|
90
|
+
type FindOptions = {
|
|
91
|
+
limit?: number;
|
|
92
|
+
skip?: number;
|
|
93
|
+
} & CollectionOperationOptions;
|
|
90
94
|
interface PongoCollection<T extends PongoDocument> {
|
|
91
95
|
readonly dbName: string;
|
|
92
96
|
readonly collectionName: string;
|
|
@@ -99,7 +103,7 @@ interface PongoCollection<T extends PongoDocument> {
|
|
|
99
103
|
deleteOne(filter?: PongoFilter<T> | SQL, options?: DeleteOneOptions): Promise<PongoDeleteResult>;
|
|
100
104
|
deleteMany(filter?: PongoFilter<T> | SQL, options?: DeleteManyOptions): Promise<PongoDeleteResult>;
|
|
101
105
|
findOne(filter?: PongoFilter<T> | SQL, options?: CollectionOperationOptions): Promise<WithIdAndVersion<T> | null>;
|
|
102
|
-
find(filter?: PongoFilter<T> | SQL, options?:
|
|
106
|
+
find(filter?: PongoFilter<T> | SQL, options?: FindOptions): Promise<WithIdAndVersion<T>[]>;
|
|
103
107
|
findOneAndDelete(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
104
108
|
findOneAndReplace(filter: PongoFilter<T> | SQL, replacement: WithoutId<T>, options?: ReplaceOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
105
109
|
findOneAndUpdate(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions): Promise<WithIdAndVersion<T> | null>;
|
|
@@ -357,4 +361,4 @@ declare const clientToDbOptions: <DbClientOptions extends AllowedDbClientOptions
|
|
|
357
361
|
clientOptions: PongoClientOptions;
|
|
358
362
|
}) => DbClientOptions;
|
|
359
363
|
|
|
360
|
-
export { type
|
|
364
|
+
export { type WithIdAndVersion as $, type AllowedDbClientOptions as A, type PongoClient as B, type CollectionsMap as C, type DocumentHandler as D, type CollectionOperationOptions as E, type InsertManyOptions as F, type UpdateManyOptions as G, type HandleOptions as H, type InsertOneOptions as I, type DeleteOneOptions as J, type DeleteManyOptions as K, type FindOptions as L, type HasId as M, type NotPooledPongoOptions as N, ObjectId as O, type PongoDb as P, type InferIdType as Q, type ReplaceOneOptions as R, type EnhancedOmit as S, type OptionalUnlessRequiredId as T, type UpdateOneOptions as U, type OptionalUnlessRequiredVersion as V, type OptionalUnlessRequiredIdAndVersion as W, type WithId as X, type WithoutId as Y, type WithVersion as Z, type WithoutVersion as _, type PongoHandleResult as a, type WithoutIdAndVersion as a0, type RegExpOrString as a1, type Document as a2, type OptionalId as a3, type OptionalVersion as a4, type ObjectIdLike as a5, type NonObjectIdLikeDocument as a6, type AlternativeType as a7, type Condition as a8, type PongoFilter as a9, isPostgresClientOptions as aA, postgresDb as aB, pongoDbSchemaComponent as aC, type RootFilterOperators as aa, type PongoFilterOperator as ab, type $set as ac, type $unset as ad, type $inc as ae, type $push as af, type ExpectedDocumentVersionGeneral as ag, type ExpectedDocumentVersionValue as ah, type ExpectedDocumentVersion as ai, DOCUMENT_EXISTS as aj, DOCUMENT_DOES_NOT_EXIST as ak, NO_CONCURRENCY_CHECK as al, isGeneralExpectedDocumentVersion as am, expectedVersionValue as an, expectedVersion as ao, type PongoUpdate as ap, type OperationResult as aq, operationResult as ar, type PongoInsertOneResult as as, type PongoInsertManyResult as at, type PongoUpdateResult as au, type PongoUpdateManyResult as av, type PongoDeleteResult as aw, type PongoDeleteManyResult as ax, type PongoDocument as ay, type PostgresDbClientOptions as az, type PongoClientOptions as b, type PongoCollection as c, type PongoTransactionOptions as d, type PongoSession as e, type PongoDbTransaction as f, type PooledPongoClientOptions as g, clientToDbOptions as h, type PongoDbClientOptions as i, getPongoDb as j, type PongoCollectionSchema as k, type PongoDbSchema as l, type PongoClientSchema as m, type PongoDbWithSchema as n, type DBsMap as o, pongoClient as p, type PongoClientWithSchema as q, pongoSchema as r, proxyPongoDbWithSchema as s, proxyClientWithSchema as t, type PongoCollectionSchemaMetadata as u, type PongoDbSchemaMetadata as v, type PongoClientSchemaMetadata as w, toDbSchemaMetadata as x, toClientSchemaMetadata as y, type PongoSchemaConfig as z };
|