@event-driven-io/pongo 0.14.3 → 0.15.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-7GQ5BP22.cjs +76 -0
- package/dist/chunk-7GQ5BP22.cjs.map +1 -0
- package/dist/chunk-QO7XUM5F.js +76 -0
- package/dist/chunk-QO7XUM5F.js.map +1 -0
- package/dist/cli.cjs +10 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +10 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -14
- package/dist/index.d.ts +30 -14
- package/dist/index.js +1 -1
- package/dist/{pongoClient-CajnU47o.d.cts → pongoClient-BY509WFi.d.cts} +103 -28
- package/dist/{pongoClient-CajnU47o.d.ts → pongoClient-BY509WFi.d.ts} +103 -28
- package/dist/shim.cjs +1 -1
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +3 -3
- package/dist/shim.d.ts +3 -3
- package/dist/shim.js +1 -1
- package/dist/shim.js.map +1 -1
- package/package.json +6 -6
- package/dist/chunk-UGDQF6CW.js +0 -14
- package/dist/chunk-UGDQF6CW.js.map +0 -1
- package/dist/chunk-YQPKY7LN.cjs +0 -14
- package/dist/chunk-YQPKY7LN.cjs.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var
|
|
3
|
-
`),t=o.map(
|
|
2
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunk7GQ5BP22cjs = require('./chunk-7GQ5BP22.cjs');var _commander = require('commander');var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);var S=o=>{if(o.length===0)return o;let n=o.charAt(0).toUpperCase()+o.slice(1);return n.endsWith("s")&&(n=n.slice(0,-1)),n},a=(o=["users"])=>{let n=o.map(e=>`type ${S(e)} = { name: string; description: string; date: Date }`).join(`
|
|
3
|
+
`),t=o.map(e=>` ${e}: pongoSchema.collection<${S(e)}>('${e}'),`).join(`
|
|
4
4
|
`);return`import { pongoSchema } from '@event-driven-io/pongo';
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${n}
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
schema: pongoSchema.client({
|
|
@@ -11,17 +11,17 @@ export default {
|
|
|
11
11
|
${t}
|
|
12
12
|
}),
|
|
13
13
|
}),
|
|
14
|
-
};`},
|
|
14
|
+
};`},E=`Error: Config should contain default export, e.g.
|
|
15
15
|
|
|
16
|
-
${
|
|
16
|
+
${a()}`,D=`Error: Config should contain schema property, e.g.
|
|
17
17
|
|
|
18
|
-
${
|
|
18
|
+
${a()}`,M=`Error: Config should have at least a single database defined, e.g.
|
|
19
19
|
|
|
20
|
-
${
|
|
20
|
+
${a()}`,N=`Error: Config should have a default database defined (without name or or with default database name), e.g.
|
|
21
21
|
|
|
22
|
-
${
|
|
22
|
+
${a()}`,b=`Error: Database should have defined at least one collection, e.g.
|
|
23
23
|
|
|
24
|
-
${
|
|
24
|
+
${a()}`,C=async o=>{let n=new URL(o,`file://${process.cwd()}/`);try{let t=await Promise.resolve().then(() => _interopRequireWildcard(require(n.href))),e=O(t);return typeof e=="string"&&(console.error(e),process.exit(1)),e}catch (e2){console.error(`Error: Couldn't load file: ${n.href}`),process.exit(1)}},$=(o,n)=>{try{_fs2.default.writeFileSync(o,a(n),"utf8"),console.log(`Configuration file stored at: ${o}`)}catch(t){console.error(`Error: Couldn't store config file: ${o}!`),console.error(t),process.exit(1)}},O=o=>{if(!o.default)return E;if(!o.default.schema)return D;if(!o.default.schema.dbs)return M;let t=_chunk7GQ5BP22cjs.s.call(void 0, o.default.schema.dbs).map(i=>i[1]).find(i=>i.name===void 0);return t?!t.collections||_chunk7GQ5BP22cjs.s.call(void 0, t.collections).map(i=>i[1]).length===0?b:_chunk7GQ5BP22cjs.D.call(void 0, t):N},d=new (0, _commander.Command)("config").description("Manage Pongo configuration");d.command("sample").description("Generate or print sample configuration").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).option("-f, --file <path>","Path to configuration file with collection list").option("-g, --generate","Generate sample config file").option("-p, --print","Print sample config file").action(o=>{let n=o.collection.length>0?o.collection:["users"];!("print"in o)&&!("generate"in o)&&(console.error(`Error: Please provide either:
|
|
25
25
|
--print param to print sample config or
|
|
26
|
-
--generate to generate sample config file`),process.exit(1)),"print"in o?console.log(`${
|
|
26
|
+
--generate to generate sample config file`),process.exit(1)),"print"in o?console.log(`${a(n)}`):"generate"in o&&(o.file||(console.error("Error: You need to provide a config file through a --file"),process.exit(1)),$(o.file,n))});var _dumbo = require('@event-driven-io/dumbo');var g=new (0, _commander.Command)("migrate").description("Manage database migrations");g.command("run").description("Run database migrations").option("-cs, --connectionString <string>","Connection string for the database").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).option("-f, --config <path>","Path to configuration file with Pongo config").option("-dr, --dryRun","Perform dry run without commiting changes",!1).action(async o=>{let{collection:n,dryRun:t}=o,e=_nullishCoalesce(o.connectionString, () => (process.env.DB_CONNECTION_STRING)),i;e||(console.error('Error: Connection string is required. Provide it either as a "--connectionString" parameter or through the DB_CONNECTION_STRING environment variable.'),process.exit(1)),o.config?i=(await C(o.config)).collections.map(P=>P.name):n?i=n:(console.error('Error: You need to provide at least one collection name. Provide it either through "--config" file or as a "--collection" parameter.'),process.exit(1));let r=_dumbo.dumbo.call(void 0, {connectionString:e}),x=i.flatMap(f=>_chunk7GQ5BP22cjs.g.call(void 0, f).migrations({connector:"PostgreSQL:pg"}));await _dumbo.runPostgreSQLMigrations.call(void 0, r,x,{dryRun:t})});g.command("sql").description("Generate SQL for database migration").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).option("--print","Print the SQL to the console (default)",!0).action(o=>{let{collection:n}=o;n||(console.error('Error: You need to provide at least one collection name is required. Provide it either as a "col" parameter.'),process.exit(1));let e=[..._dumbo.migrationTableSchemaComponent.migrations({connector:"PostgreSQL:pg"}),...n.flatMap(i=>_chunk7GQ5BP22cjs.g.call(void 0, i).migrations({connector:"PostgreSQL:pg"}))];console.log("Printing SQL:"),console.log(_dumbo.combineMigrations.call(void 0, ...e))});var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var _clitable3 = require('cli-table3'); var _clitable32 = _interopRequireDefault(_clitable3);var _repl = require('repl'); var _repl2 = _interopRequireDefault(_repl);var _=(o,n)=>n.map(e=>Math.max(e.length,...o.map(r=>r[e]?String(r[e]).length:0))+2),j=o=>{if(o.length===0){console.log(_chalk2.default.yellow("No documents found."));return}let n=Object.keys(o[0]),t=_(o,n),e=new (0, _clitable32.default)({head:n.map(i=>_chalk2.default.cyan(i)),colWidths:t});o.forEach(i=>{e.push(n.map(r=>i[r]!==void 0?String(i[r]):""))}),console.log(e.toString())},F=o=>{let n=_repl2.default.start({prompt:_chalk2.default.green("pongo> "),useGlobal:!0}),t=o.schema.collections.length>0?_chunk7GQ5BP22cjs.A.client({database:_chunk7GQ5BP22cjs.A.db({users:_chunk7GQ5BP22cjs.A.collection(o.schema.database)})}):void 0,e=_chunk7GQ5BP22cjs.F.call(void 0, o.connectionString,{...t?{schema:{definition:t}}:{}});n.context.db=t?e.database:e.db(o.schema.database),n.context.displayResults=j,n.on("exit",()=>{console.log(_chalk2.default.yellow("Exiting Pongo Shell...")),process.exit()})},y=new (0, _commander.Command)("shell").description("Start an interactive Pongo shell").option("-cs, --connectionString <string>","Connection string for the database","postgresql://postgres:postgres@localhost:5432/postgres").option("-db, --database <string>","Database name to connect","postgres").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).action(o=>{let{collection:n,database:t}=o,e=_nullishCoalesce(o.connectionString, () => (process.env.DB_CONNECTION_STRING));console.log(_chalk2.default.green("Starting Pongo Shell. Use db.<collection>.<method>() to query.")),F({schema:{collections:n,database:t},connectionString:e})});var c=new _commander.Command;c.name("pongo").description("CLI tool for Pongo");c.addCommand(d);c.addCommand(g);c.addCommand(y);c.parse(process.argv);var go=c;exports.default = go;
|
|
27
27
|
//# sourceMappingURL=cli.cjs.map
|
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"],"names":["formatTypeName","input","formatted","sampleConfig","collectionNames","types","name","collections","missingDefaultExport"],"mappings":"AAAA;AACA,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/cli.cjs","../src/cli.ts","../src/commandLine/configFile.ts"],"names":["formatTypeName","input","formatted","sampleConfig","collectionNames","types","name","collections","missingDefaultExport"],"mappings":"AAAA;AACA,ulBAAoE,sCCA5C,gECAT,IAQTA,CAAAA,CAAkBC,CAAAA,EAA0B,CAChD,EAAA,CAAIA,CAAAA,CAAM,MAAA,GAAW,CAAA,CACnB,OAAOA,CAAAA,CAGT,IAAIC,CAAAA,CAAYD,CAAAA,CAAM,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,CAAY,CAAA,CAAIA,CAAAA,CAAM,KAAA,CAAM,CAAC,CAAA,CAE7D,OAAIC,CAAAA,CAAU,QAAA,CAAS,GAAG,CAAA,EAAA,CACxBA,CAAAA,CAAYA,CAAAA,CAAU,KAAA,CAAM,CAAA,CAAG,CAAA,CAAE,CAAA,CAAA,CAG5BA,CACT,CAAA,CAEMC,CAAAA,CAAe,CAACC,CAAAA,CAA4B,CAAC,OAAO,CAAA,CAAA,EAAM,CAC9D,IAAMC,CAAAA,CAAQD,CAAAA,CACX,GAAA,CACEE,CAAAA,EACC,CAAA,KAAA,EAAQN,CAAAA,CAAeM,CAAI,CAAC,CAAA,oDAAA,CAChC,CAAA,CACC,IAAA,CAAK,CAAA;AAAA,CAAI,CAAA,CAENC,CAAAA,CAAcH,CAAAA,CACjB,GAAA,CACEE,CAAAA,EACC,CAAA,MAAA,EAASA,CAAI,CAAA,yBAAA,EAA4BN,CAAAA,CAAeM,CAAI,CAAC,CAAA,GAAA,EAAMA,CAAI,CAAA,GAAA,CAC3E,CAAA,CACC,IAAA,CAAK,CAAA;AAAA,CAAI,CAAA,CAEZ,MAAO,CAAA;AAAA;AAAA,EAEPD,CAAK,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKLE,CAAW,CAAA;AAAA;AAAA;AAAA,EAAA,CAIb,CAAA,CAEMC,CAAAA,CAAuB,CAAA;AAAA;AAAA,EAAwDL,CAAAA,CAAa,CAAC,CAAA,CAAA;AAC7E;AAAuE;AAC1E;AAAuF;AACjF;AAA+H;AAC7H;AAAsF;AAmHzG;AAAA,yCAAA","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 `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"]}
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
3
|
-
`),t=o.map(
|
|
2
|
+
import{A as l,D as h,F as u,g as m,s as p}from"./chunk-QO7XUM5F.js";import{Command as U}from"commander";import{Command as v}from"commander";import w from"node:fs";var S=o=>{if(o.length===0)return o;let n=o.charAt(0).toUpperCase()+o.slice(1);return n.endsWith("s")&&(n=n.slice(0,-1)),n},a=(o=["users"])=>{let n=o.map(e=>`type ${S(e)} = { name: string; description: string; date: Date }`).join(`
|
|
3
|
+
`),t=o.map(e=>` ${e}: pongoSchema.collection<${S(e)}>('${e}'),`).join(`
|
|
4
4
|
`);return`import { pongoSchema } from '@event-driven-io/pongo';
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${n}
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
schema: pongoSchema.client({
|
|
@@ -11,17 +11,17 @@ export default {
|
|
|
11
11
|
${t}
|
|
12
12
|
}),
|
|
13
13
|
}),
|
|
14
|
-
};`},
|
|
14
|
+
};`},E=`Error: Config should contain default export, e.g.
|
|
15
15
|
|
|
16
|
-
${
|
|
16
|
+
${a()}`,D=`Error: Config should contain schema property, e.g.
|
|
17
17
|
|
|
18
|
-
${
|
|
18
|
+
${a()}`,M=`Error: Config should have at least a single database defined, e.g.
|
|
19
19
|
|
|
20
|
-
${
|
|
20
|
+
${a()}`,N=`Error: Config should have a default database defined (without name or or with default database name), e.g.
|
|
21
21
|
|
|
22
|
-
${
|
|
22
|
+
${a()}`,b=`Error: Database should have defined at least one collection, e.g.
|
|
23
23
|
|
|
24
|
-
${
|
|
24
|
+
${a()}`,C=async o=>{let n=new URL(o,`file://${process.cwd()}/`);try{let t=await import(n.href),e=O(t);return typeof e=="string"&&(console.error(e),process.exit(1)),e}catch{console.error(`Error: Couldn't load file: ${n.href}`),process.exit(1)}},$=(o,n)=>{try{w.writeFileSync(o,a(n),"utf8"),console.log(`Configuration file stored at: ${o}`)}catch(t){console.error(`Error: Couldn't store config file: ${o}!`),console.error(t),process.exit(1)}},O=o=>{if(!o.default)return E;if(!o.default.schema)return D;if(!o.default.schema.dbs)return M;let t=p(o.default.schema.dbs).map(i=>i[1]).find(i=>i.name===void 0);return t?!t.collections||p(t.collections).map(i=>i[1]).length===0?b:h(t):N},d=new v("config").description("Manage Pongo configuration");d.command("sample").description("Generate or print sample configuration").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).option("-f, --file <path>","Path to configuration file with collection list").option("-g, --generate","Generate sample config file").option("-p, --print","Print sample config file").action(o=>{let n=o.collection.length>0?o.collection:["users"];!("print"in o)&&!("generate"in o)&&(console.error(`Error: Please provide either:
|
|
25
25
|
--print param to print sample config or
|
|
26
|
-
--generate to generate sample config file`),process.exit(1)),"print"in o?console.log(`${
|
|
26
|
+
--generate to generate sample config file`),process.exit(1)),"print"in o?console.log(`${a(n)}`):"generate"in o&&(o.file||(console.error("Error: You need to provide a config file through a --file"),process.exit(1)),$(o.file,n))});import{combineMigrations as R,dumbo as T,migrationTableSchemaComponent as L,runPostgreSQLMigrations as W}from"@event-driven-io/dumbo";import{Command as q}from"commander";var g=new q("migrate").description("Manage database migrations");g.command("run").description("Run database migrations").option("-cs, --connectionString <string>","Connection string for the database").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).option("-f, --config <path>","Path to configuration file with Pongo config").option("-dr, --dryRun","Perform dry run without commiting changes",!1).action(async o=>{let{collection:n,dryRun:t}=o,e=o.connectionString??process.env.DB_CONNECTION_STRING,i;e||(console.error('Error: Connection string is required. Provide it either as a "--connectionString" parameter or through the DB_CONNECTION_STRING environment variable.'),process.exit(1)),o.config?i=(await C(o.config)).collections.map(P=>P.name):n?i=n:(console.error('Error: You need to provide at least one collection name. Provide it either through "--config" file or as a "--collection" parameter.'),process.exit(1));let r=T({connectionString:e}),x=i.flatMap(f=>m(f).migrations({connector:"PostgreSQL:pg"}));await W(r,x,{dryRun:t})});g.command("sql").description("Generate SQL for database migration").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).option("--print","Print the SQL to the console (default)",!0).action(o=>{let{collection:n}=o;n||(console.error('Error: You need to provide at least one collection name is required. Provide it either as a "col" parameter.'),process.exit(1));let e=[...L.migrations({connector:"PostgreSQL:pg"}),...n.flatMap(i=>m(i).migrations({connector:"PostgreSQL:pg"}))];console.log("Printing SQL:"),console.log(R(...e))});import s from"chalk";import G from"cli-table3";import{Command as I}from"commander";import Q from"node:repl";var _=(o,n)=>n.map(e=>Math.max(e.length,...o.map(r=>r[e]?String(r[e]).length:0))+2),j=o=>{if(o.length===0){console.log(s.yellow("No documents found."));return}let n=Object.keys(o[0]),t=_(o,n),e=new G({head:n.map(i=>s.cyan(i)),colWidths:t});o.forEach(i=>{e.push(n.map(r=>i[r]!==void 0?String(i[r]):""))}),console.log(e.toString())},F=o=>{let n=Q.start({prompt:s.green("pongo> "),useGlobal:!0}),t=o.schema.collections.length>0?l.client({database:l.db({users:l.collection(o.schema.database)})}):void 0,e=u(o.connectionString,{...t?{schema:{definition:t}}:{}});n.context.db=t?e.database:e.db(o.schema.database),n.context.displayResults=j,n.on("exit",()=>{console.log(s.yellow("Exiting Pongo Shell...")),process.exit()})},y=new I("shell").description("Start an interactive Pongo shell").option("-cs, --connectionString <string>","Connection string for the database","postgresql://postgres:postgres@localhost:5432/postgres").option("-db, --database <string>","Database name to connect","postgres").option("-col, --collection <name>","Specify the collection name",(o,n)=>n.concat([o]),[]).action(o=>{let{collection:n,database:t}=o,e=o.connectionString??process.env.DB_CONNECTION_STRING;console.log(s.green("Starting Pongo Shell. Use db.<collection>.<method>() to query.")),F({schema:{collections:n,database:t},connectionString:e})});var c=new U;c.name("pongo").description("CLI tool for Pongo");c.addCommand(d);c.addCommand(g);c.addCommand(y);c.parse(process.argv);var go=c;export{go as default};
|
|
27
27
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/commandLine/configFile.ts","../src/commandLine/migrate.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { configCommand, migrateCommand } from './commandLine';\n\nconst program = new Command();\n\nprogram.name('pongo').description('CLI tool for Pongo');\n\nprogram.addCommand(configCommand);\nprogram.addCommand(migrateCommand);\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 `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\nconst sampleConfigCommand = configCommand\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\nsampleConfigCommand.command('generate');\n","import {\n combineMigrations,\n dumbo,\n migrationTableSchemaComponent,\n runPostgreSQLMigrations,\n} from '@event-driven-io/dumbo';\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 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, --connectionString <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 \"--connectionString\" parameter or through the DB_CONNECTION_STRING environment variable.',\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('--print', 'Print the SQL to the console (default)', true)\n //.option('--write <filename>', 'Write the SQL to a specified file')\n .action((options: MigrateSqlOptions) => {\n const { collection } = options;\n\n if (!collection) {\n console.error(\n 'Error: You need to provide at least one collection name is required. Provide it either as a \"col\" parameter.',\n );\n process.exit(1);\n }\n const coreMigrations = migrationTableSchemaComponent.migrations({\n connector: 'PostgreSQL:pg',\n });\n const migrations = [\n ...coreMigrations,\n ...collection.flatMap((collectionsName) =>\n pongoCollectionSchemaComponent(collectionsName).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"],"mappings":";iDACA,OAAS,WAAAA,MAAe,YCDxB,OAAS,WAAAC,MAAe,YACxB,OAAOC,MAAQ,UAQf,IAAMC,EAAkBC,GAA0B,CAChD,GAAIA,EAAM,SAAW,EACnB,OAAOA,EAGT,IAAIC,EAAY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AK,CAAC,GAKhB,IAAMQ,EAAa,CACjB,GAJqBI,EAA8B,WAAW,CAC9D,UAAW,eACb,CAAC,EAGC,GAAGZ,EAAW,QAASS,GACrBC,EAA+BD,CAAe,EAAE,WAAW,CACzD,UAAW,eACb,CAAC,CACH,CACF,EAEA,QAAQ,IAAI,eAAe,EAC3B,QAAQ,IAAII,EAAkB,GAAGL,CAAU,CAAC,CAC9C,CAAC,EFrHH,IAAMM,EAAU,IAAIC,EAEpBD,EAAQ,KAAK,OAAO,EAAE,YAAY,oBAAoB,EAEtDA,EAAQ,WAAWE,CAAa,EAChCF,EAAQ,WAAWG,CAAc,EAEjCH,EAAQ,MAAM,QAAQ,IAAI,EAE1B,IAAOI,EAAQJ","names":["Command","Command","fs","formatTypeName","input","formatted","sampleConfig","collectionNames","types","name","collections","missingDefaultExport","missingSchema","missingDbs","missingDefaultDb","missingCollections","loadConfigFile","configPath","configUrl","imported","parsed","parseDefaultDbSchema","generateConfigFile","fs","error","defaultDb","objectEntries","db","col","toDbSchemaMetadata","configCommand","Command","sampleConfigCommand","value","previous","options","combineMigrations","dumbo","migrationTableSchemaComponent","runPostgreSQLMigrations","Command","migrateCommand","Command","value","previous","options","collection","dryRun","connectionString","collectionNames","loadConfigFile","c","pool","dumbo","migrations","collectionsName","pongoCollectionSchemaComponent","runPostgreSQLMigrations","migrationTableSchemaComponent","combineMigrations","program","Command","configCommand","migrateCommand","cli_default"]}
|
|
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 `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 {\n combineMigrations,\n dumbo,\n migrationTableSchemaComponent,\n runPostgreSQLMigrations,\n} from '@event-driven-io/dumbo';\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 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, --connectionString <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 \"--connectionString\" parameter or through the DB_CONNECTION_STRING environment variable.',\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('--print', 'Print the SQL to the console (default)', true)\n //.option('--write <filename>', 'Write the SQL to a specified file')\n .action((options: MigrateSqlOptions) => {\n const { collection } = options;\n\n if (!collection) {\n console.error(\n 'Error: You need to provide at least one collection name is required. Provide it either as a \"col\" parameter.',\n );\n process.exit(1);\n }\n const coreMigrations = migrationTableSchemaComponent.migrations({\n connector: 'PostgreSQL:pg',\n });\n const migrations = [\n ...coreMigrations,\n ...collection.flatMap((collectionsName) =>\n pongoCollectionSchemaComponent(collectionsName).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 chalk from 'chalk';\nimport Table from 'cli-table3';\nimport { Command } from 'commander';\nimport repl from 'node:repl';\nimport { pongoClient, pongoSchema } from '../core';\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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst displayResultsAsTable = (results: any[]) => {\n if (results.length === 0) {\n console.log(chalk.yellow('No documents found.'));\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n const columnNames = Object.keys(results[0]);\n\n const columnWidths = calculateColumnWidths(results, columnNames);\n\n const table = new Table({\n head: columnNames.map((col) => chalk.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 ? String(result[col]) : '',\n ),\n );\n });\n\n console.log(table.toString());\n};\n\nconst startRepl = (options: {\n schema: {\n database: string;\n collections: string[];\n };\n connectionString: string;\n}) => {\n const r = repl.start({\n prompt: chalk.green('pongo> '),\n useGlobal: true,\n });\n\n const schema =\n options.schema.collections.length > 0\n ? pongoSchema.client({\n database: pongoSchema.db({\n users: pongoSchema.collection(options.schema.database),\n }),\n })\n : undefined;\n\n const pongo = pongoClient(options.connectionString, {\n ...(schema ? { schema: { definition: schema } } : {}),\n });\n\n // Expose the db object to the REPL context\n r.context.db = schema ? pongo.database : pongo.db(options.schema.database);\n\n // Handle default output formatting\n r.context.displayResults = displayResultsAsTable;\n\n // Intercept REPL output to display results as a table if they are arrays\n r.on('exit', () => {\n console.log(chalk.yellow('Exiting Pongo Shell...'));\n process.exit();\n });\n};\n\ninterface ShellOptions {\n database: string;\n collection: string[];\n connectionString: string;\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 'postgresql://postgres:postgres@localhost:5432/postgres',\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 .action((options: ShellOptions) => {\n const { collection, database } = options;\n const connectionString =\n options.connectionString ?? process.env.DB_CONNECTION_STRING;\n\n console.log(\n chalk.green(\n 'Starting Pongo Shell. Use db.<collection>.<method>() to query.',\n ),\n );\n startRepl({\n schema: { collections: collection, database },\n connectionString,\n });\n });\n\nexport { shellCommand };\n"],"mappings":";oEACA,OAAS,WAAAA,MAAe,YCDxB,OAAS,WAAAC,MAAe,YACxB,OAAOC,MAAQ,UAQf,IAAMC,EAAkBC,GAA0B,CAChD,GAAIA,EAAM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A,EAAY,GAAG,CACvB,MAAOA,EAAY,WAAWJ,EAAQ,OAAO,QAAQ,CACvD,CAAC,CACH,CAAC,EACD,OAEAK,EAAQC,EAAYN,EAAQ,iBAAkB,CAClD,GAAIG,EAAS,CAAE,OAAQ,CAAE,WAAYA,CAAO,CAAE,EAAI,CAAC,CACrD,CAAC,EAGDF,EAAE,QAAQ,GAAKE,EAASE,EAAM,SAAWA,EAAM,GAAGL,EAAQ,OAAO,QAAQ,EAGzEC,EAAE,QAAQ,eAAiBP,EAG3BO,EAAE,GAAG,OAAQ,IAAM,CACjB,QAAQ,IAAIN,EAAM,OAAO,wBAAwB,CAAC,EAClD,QAAQ,KAAK,CACf,CAAC,CACH,EAQMY,EAAe,IAAIC,EAAQ,OAAO,EACrC,YAAY,kCAAkC,EAC9C,OACC,mCACA,qCACA,wDACF,EACC,OAAO,2BAA4B,2BAA4B,UAAU,EACzE,OACC,4BACA,8BACA,CAACC,EAAeC,IAEPA,EAAS,OAAO,CAACD,CAAK,CAAC,EAEhC,CAAC,CACH,EACC,OAAQT,GAA0B,CACjC,GAAM,CAAE,WAAAW,EAAY,SAAAC,CAAS,EAAIZ,EAC3Ba,EACJb,EAAQ,kBAAoB,QAAQ,IAAI,qBAE1C,QAAQ,IACNL,EAAM,MACJ,gEACF,CACF,EACAI,EAAU,CACR,OAAQ,CAAE,YAAaY,EAAY,SAAAC,CAAS,EAC5C,iBAAAC,CACF,CAAC,CACH,CAAC,EH5HH,IAAMC,EAAU,IAAIC,EAEpBD,EAAQ,KAAK,OAAO,EAAE,YAAY,oBAAoB,EAEtDA,EAAQ,WAAWE,CAAa,EAChCF,EAAQ,WAAWG,CAAc,EACjCH,EAAQ,WAAWI,CAAY,EAE/BJ,EAAQ,MAAM,QAAQ,IAAI,EAE1B,IAAOK,GAAQL","names":["Command","Command","fs","formatTypeName","input","formatted","sampleConfig","collectionNames","types","name","collections","missingDefaultExport","missingSchema","missingDbs","missingDefaultDb","missingCollections","loadConfigFile","configPath","configUrl","imported","parsed","parseDefaultDbSchema","generateConfigFile","fs","error","defaultDb","objectEntries","db","col","toDbSchemaMetadata","configCommand","Command","value","previous","options","combineMigrations","dumbo","migrationTableSchemaComponent","runPostgreSQLMigrations","Command","migrateCommand","Command","value","previous","options","collection","dryRun","connectionString","collectionNames","loadConfigFile","c","pool","dumbo","migrations","collectionsName","pongoCollectionSchemaComponent","runPostgreSQLMigrations","migrationTableSchemaComponent","combineMigrations","chalk","Table","Command","repl","calculateColumnWidths","results","columnNames","col","result","displayResultsAsTable","chalk","columnWidths","table","Table","startRepl","options","r","repl","schema","pongoSchema","pongo","pongoClient","shellCommand","Command","value","previous","collection","database","connectionString","program","Command","configCommand","migrateCommand","shellCommand","cli_default"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk7GQ5BP22cjs = require('./chunk-7GQ5BP22.cjs');exports.ConcurrencyError = _chunk7GQ5BP22cjs.o; exports.DOCUMENT_DOES_NOT_EXIST = _chunk7GQ5BP22cjs.u; exports.DOCUMENT_EXISTS = _chunk7GQ5BP22cjs.t; exports.NO_CONCURRENCY_CHECK = _chunk7GQ5BP22cjs.v; exports.OperatorMap = _chunk7GQ5BP22cjs.i; exports.PongoError = _chunk7GQ5BP22cjs.n; exports.QueryOperators = _chunk7GQ5BP22cjs.h; exports.clientToDbOptions = _chunk7GQ5BP22cjs.G; exports.expectedVersion = _chunk7GQ5BP22cjs.y; exports.expectedVersionValue = _chunk7GQ5BP22cjs.x; exports.getPongoDb = _chunk7GQ5BP22cjs.p; exports.hasOperators = _chunk7GQ5BP22cjs.k; exports.isGeneralExpectedDocumentVersion = _chunk7GQ5BP22cjs.w; exports.isNumber = _chunk7GQ5BP22cjs.l; exports.isOperator = _chunk7GQ5BP22cjs.j; exports.isPostgresClientOptions = _chunk7GQ5BP22cjs.c; exports.isString = _chunk7GQ5BP22cjs.m; exports.objectEntries = _chunk7GQ5BP22cjs.s; exports.operationResult = _chunk7GQ5BP22cjs.z; exports.pongoClient = _chunk7GQ5BP22cjs.F; exports.pongoCollection = _chunk7GQ5BP22cjs.f; exports.pongoCollectionPostgreSQLMigrations = _chunk7GQ5BP22cjs.a; exports.pongoCollectionSchemaComponent = _chunk7GQ5BP22cjs.g; exports.pongoDbSchemaComponent = _chunk7GQ5BP22cjs.e; exports.pongoSchema = _chunk7GQ5BP22cjs.A; exports.pongoSession = _chunk7GQ5BP22cjs.r; exports.pongoTransaction = _chunk7GQ5BP22cjs.q; exports.postgresDb = _chunk7GQ5BP22cjs.d; exports.postgresSQLBuilder = _chunk7GQ5BP22cjs.b; exports.proxyClientWithSchema = _chunk7GQ5BP22cjs.C; exports.proxyPongoDbWithSchema = _chunk7GQ5BP22cjs.B; exports.toClientSchemaMetadata = _chunk7GQ5BP22cjs.E; exports.toDbSchemaMetadata = _chunk7GQ5BP22cjs.D;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/index.cjs"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/index.cjs"],"names":[],"mappings":"AAAA,iIAA2N,0kDAAyvB","file":"/home/runner/work/Pongo/Pongo/src/packages/pongo/dist/index.cjs"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dumbo, MigrationStyle, SchemaComponent, SQLMigration, SQL } from '@event-driven-io/dumbo';
|
|
2
|
-
import { P as PongoDb, a as PongoDocument, b as PongoCollection, O as
|
|
3
|
-
export {
|
|
2
|
+
import { P as PongoDb, a as PongoDocument, b as PongoCollection, O as OptionalUnlessRequiredIdAndVersion, c as PongoFilter, d as PongoUpdate, U as UpdateOneOptions, W as WithoutId, R as ReplaceOneOptions, D as DeleteOneOptions, e as PongoTransactionOptions, f as PongoSession, g as PongoDbTransaction } from './pongoClient-BY509WFi.cjs';
|
|
3
|
+
export { ab as $inc, ac as $push, a9 as $set, aa as $unset, A as AllowedDbClientOptions, a5 as AlternativeType, G as CollectionOperationOptions, C as CollectionsMap, a6 as Condition, r as DBsMap, ah as DOCUMENT_DOES_NOT_EXIST, ag as DOCUMENT_EXISTS, L as DeleteManyOptions, a0 as Document, av as DocumentHandler, T as EnhancedOmit, af as ExpectedDocumentVersion, ad as ExpectedDocumentVersionGeneral, ae as ExpectedDocumentVersionValue, K as HandleOptions, Q as HasId, S as InferIdType, H as InsertManyOptions, I as InsertOneOptions, ai as NO_CONCURRENCY_CHECK, a4 as NonObjectIdLikeDocument, N as NotPooledPongoOptions, M as ObjectId, a3 as ObjectIdLike, am as OperationResult, a1 as OptionalId, V as OptionalUnlessRequiredId, X as OptionalUnlessRequiredVersion, a2 as OptionalVersion, F as PongoClient, i as PongoClientOptions, o as PongoClientSchema, y as PongoClientSchemaMetadata, s as PongoClientWithSchema, m as PongoCollectionSchema, w as PongoCollectionSchemaMetadata, k as PongoDbClientOptions, n as PongoDbSchema, x as PongoDbSchemaMetadata, q as PongoDbWithSchema, at as PongoDeleteManyResult, as as PongoDeleteResult, a8 as PongoFilterOperator, au as PongoHandleResult, ap as PongoInsertManyResult, ao as PongoInsertOneResult, E as PongoSchemaConfig, ar as PongoUpdateManyResult, aq as PongoUpdateResult, h as PooledPongoClientOptions, aw as PostgresDbClientOptions, $ as RegExpOrString, a7 as RootFilterOperators, J as UpdateManyOptions, Y as WithId, Z as WithVersion, _ as WithoutVersion, j as clientToDbOptions, al as expectedVersion, ak as expectedVersionValue, l as getPongoDb, aj as isGeneralExpectedDocumentVersion, ax as isPostgresClientOptions, an as operationResult, p as pongoClient, az as pongoDbSchemaComponent, t as pongoSchema, ay as postgresDb, v as proxyClientWithSchema, u as proxyPongoDbWithSchema, B as toClientSchemaMetadata, z as toDbSchemaMetadata } from './pongoClient-BY509WFi.cjs';
|
|
4
4
|
import 'pg';
|
|
5
5
|
|
|
6
6
|
type PongoCollectionOptions<ConnectorType extends string = string> = {
|
|
@@ -11,22 +11,25 @@ type PongoCollectionOptions<ConnectorType extends string = string> = {
|
|
|
11
11
|
schema?: {
|
|
12
12
|
autoMigration?: MigrationStyle;
|
|
13
13
|
};
|
|
14
|
+
errors?: {
|
|
15
|
+
throwOnOperationFailures?: boolean;
|
|
16
|
+
};
|
|
14
17
|
};
|
|
15
|
-
declare const pongoCollection: <T extends PongoDocument, ConnectorType extends string = string>({ db, collectionName, pool, sqlBuilder: SqlFor, schema, }: PongoCollectionOptions<ConnectorType>) => PongoCollection<T>;
|
|
18
|
+
declare const pongoCollection: <T extends PongoDocument, ConnectorType extends string = string>({ db, collectionName, pool, sqlBuilder: SqlFor, schema, errors, }: PongoCollectionOptions<ConnectorType>) => PongoCollection<T>;
|
|
16
19
|
declare const pongoCollectionSchemaComponent: (collectionName: string) => SchemaComponent;
|
|
17
20
|
type PongoCollectionSQLBuilder = {
|
|
18
21
|
migrations: () => SQLMigration[];
|
|
19
22
|
createCollection: () => SQL;
|
|
20
|
-
insertOne: <T>(document:
|
|
21
|
-
insertMany: <T>(documents:
|
|
22
|
-
updateOne: <T>(filter: PongoFilter<T
|
|
23
|
-
replaceOne: <T>(filter: PongoFilter<T
|
|
24
|
-
updateMany: <T>(filter: PongoFilter<T
|
|
25
|
-
deleteOne: <T>(filter: PongoFilter<T>) => SQL;
|
|
26
|
-
deleteMany: <T>(filter: PongoFilter<T>) => SQL;
|
|
27
|
-
findOne: <T>(filter: PongoFilter<T>) => SQL;
|
|
28
|
-
find: <T>(filter: PongoFilter<T>) => SQL;
|
|
29
|
-
countDocuments: <T>(filter: PongoFilter<T>) => SQL;
|
|
23
|
+
insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
|
|
24
|
+
insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
|
|
25
|
+
updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
|
|
26
|
+
replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
|
|
27
|
+
updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
|
|
28
|
+
deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
|
|
29
|
+
deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
|
+
findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
31
|
+
find: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
32
|
+
countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
33
|
rename: (newName: string) => SQL;
|
|
31
34
|
drop: () => SQL;
|
|
32
35
|
};
|
|
@@ -54,6 +57,19 @@ declare const OperatorMap: {
|
|
|
54
57
|
declare const isOperator: (key: string) => boolean;
|
|
55
58
|
declare const hasOperators: (value: Record<string, unknown>) => boolean;
|
|
56
59
|
|
|
60
|
+
declare const isNumber: (val: unknown) => val is number;
|
|
61
|
+
declare const isString: (val: unknown) => val is string;
|
|
62
|
+
declare class PongoError extends Error {
|
|
63
|
+
errorCode: number;
|
|
64
|
+
constructor(options?: {
|
|
65
|
+
errorCode: number;
|
|
66
|
+
message?: string;
|
|
67
|
+
} | string | number);
|
|
68
|
+
}
|
|
69
|
+
declare class ConcurrencyError extends PongoError {
|
|
70
|
+
constructor(message?: string);
|
|
71
|
+
}
|
|
72
|
+
|
|
57
73
|
type Entry<T> = {
|
|
58
74
|
[K in keyof Required<T>]: [K, Required<T>[K]];
|
|
59
75
|
}[keyof Required<T>];
|
|
@@ -76,4 +92,4 @@ declare const pongoSession: (options?: PongoSessionOptions) => PongoSession;
|
|
|
76
92
|
|
|
77
93
|
declare const pongoTransaction: (options: PongoTransactionOptions) => PongoDbTransaction;
|
|
78
94
|
|
|
79
|
-
export { type NonPartial, OperatorMap,
|
|
95
|
+
export { ConcurrencyError, DeleteOneOptions, type NonPartial, OperatorMap, OptionalUnlessRequiredIdAndVersion, PongoCollection, type PongoCollectionOptions, type PongoCollectionSQLBuilder, PongoDb, PongoDbTransaction, PongoDocument, PongoError, PongoFilter, PongoSession, type PongoSessionOptions, PongoTransactionOptions, PongoUpdate, QueryOperators, ReplaceOneOptions, UpdateOneOptions, WithoutId, hasOperators, isNumber, isOperator, isString, objectEntries, pongoCollection, pongoCollectionPostgreSQLMigrations, pongoCollectionSchemaComponent, pongoSession, pongoTransaction, postgresSQLBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dumbo, MigrationStyle, SchemaComponent, SQLMigration, SQL } from '@event-driven-io/dumbo';
|
|
2
|
-
import { P as PongoDb, a as PongoDocument, b as PongoCollection, O as
|
|
3
|
-
export {
|
|
2
|
+
import { P as PongoDb, a as PongoDocument, b as PongoCollection, O as OptionalUnlessRequiredIdAndVersion, c as PongoFilter, d as PongoUpdate, U as UpdateOneOptions, W as WithoutId, R as ReplaceOneOptions, D as DeleteOneOptions, e as PongoTransactionOptions, f as PongoSession, g as PongoDbTransaction } from './pongoClient-BY509WFi.js';
|
|
3
|
+
export { ab as $inc, ac as $push, a9 as $set, aa as $unset, A as AllowedDbClientOptions, a5 as AlternativeType, G as CollectionOperationOptions, C as CollectionsMap, a6 as Condition, r as DBsMap, ah as DOCUMENT_DOES_NOT_EXIST, ag as DOCUMENT_EXISTS, L as DeleteManyOptions, a0 as Document, av as DocumentHandler, T as EnhancedOmit, af as ExpectedDocumentVersion, ad as ExpectedDocumentVersionGeneral, ae as ExpectedDocumentVersionValue, K as HandleOptions, Q as HasId, S as InferIdType, H as InsertManyOptions, I as InsertOneOptions, ai as NO_CONCURRENCY_CHECK, a4 as NonObjectIdLikeDocument, N as NotPooledPongoOptions, M as ObjectId, a3 as ObjectIdLike, am as OperationResult, a1 as OptionalId, V as OptionalUnlessRequiredId, X as OptionalUnlessRequiredVersion, a2 as OptionalVersion, F as PongoClient, i as PongoClientOptions, o as PongoClientSchema, y as PongoClientSchemaMetadata, s as PongoClientWithSchema, m as PongoCollectionSchema, w as PongoCollectionSchemaMetadata, k as PongoDbClientOptions, n as PongoDbSchema, x as PongoDbSchemaMetadata, q as PongoDbWithSchema, at as PongoDeleteManyResult, as as PongoDeleteResult, a8 as PongoFilterOperator, au as PongoHandleResult, ap as PongoInsertManyResult, ao as PongoInsertOneResult, E as PongoSchemaConfig, ar as PongoUpdateManyResult, aq as PongoUpdateResult, h as PooledPongoClientOptions, aw as PostgresDbClientOptions, $ as RegExpOrString, a7 as RootFilterOperators, J as UpdateManyOptions, Y as WithId, Z as WithVersion, _ as WithoutVersion, j as clientToDbOptions, al as expectedVersion, ak as expectedVersionValue, l as getPongoDb, aj as isGeneralExpectedDocumentVersion, ax as isPostgresClientOptions, an as operationResult, p as pongoClient, az as pongoDbSchemaComponent, t as pongoSchema, ay as postgresDb, v as proxyClientWithSchema, u as proxyPongoDbWithSchema, B as toClientSchemaMetadata, z as toDbSchemaMetadata } from './pongoClient-BY509WFi.js';
|
|
4
4
|
import 'pg';
|
|
5
5
|
|
|
6
6
|
type PongoCollectionOptions<ConnectorType extends string = string> = {
|
|
@@ -11,22 +11,25 @@ type PongoCollectionOptions<ConnectorType extends string = string> = {
|
|
|
11
11
|
schema?: {
|
|
12
12
|
autoMigration?: MigrationStyle;
|
|
13
13
|
};
|
|
14
|
+
errors?: {
|
|
15
|
+
throwOnOperationFailures?: boolean;
|
|
16
|
+
};
|
|
14
17
|
};
|
|
15
|
-
declare const pongoCollection: <T extends PongoDocument, ConnectorType extends string = string>({ db, collectionName, pool, sqlBuilder: SqlFor, schema, }: PongoCollectionOptions<ConnectorType>) => PongoCollection<T>;
|
|
18
|
+
declare const pongoCollection: <T extends PongoDocument, ConnectorType extends string = string>({ db, collectionName, pool, sqlBuilder: SqlFor, schema, errors, }: PongoCollectionOptions<ConnectorType>) => PongoCollection<T>;
|
|
16
19
|
declare const pongoCollectionSchemaComponent: (collectionName: string) => SchemaComponent;
|
|
17
20
|
type PongoCollectionSQLBuilder = {
|
|
18
21
|
migrations: () => SQLMigration[];
|
|
19
22
|
createCollection: () => SQL;
|
|
20
|
-
insertOne: <T>(document:
|
|
21
|
-
insertMany: <T>(documents:
|
|
22
|
-
updateOne: <T>(filter: PongoFilter<T
|
|
23
|
-
replaceOne: <T>(filter: PongoFilter<T
|
|
24
|
-
updateMany: <T>(filter: PongoFilter<T
|
|
25
|
-
deleteOne: <T>(filter: PongoFilter<T>) => SQL;
|
|
26
|
-
deleteMany: <T>(filter: PongoFilter<T>) => SQL;
|
|
27
|
-
findOne: <T>(filter: PongoFilter<T>) => SQL;
|
|
28
|
-
find: <T>(filter: PongoFilter<T>) => SQL;
|
|
29
|
-
countDocuments: <T>(filter: PongoFilter<T>) => SQL;
|
|
23
|
+
insertOne: <T>(document: OptionalUnlessRequiredIdAndVersion<T>) => SQL;
|
|
24
|
+
insertMany: <T>(documents: OptionalUnlessRequiredIdAndVersion<T>[]) => SQL;
|
|
25
|
+
updateOne: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL, options?: UpdateOneOptions) => SQL;
|
|
26
|
+
replaceOne: <T>(filter: PongoFilter<T> | SQL, document: WithoutId<T>, options?: ReplaceOneOptions) => SQL;
|
|
27
|
+
updateMany: <T>(filter: PongoFilter<T> | SQL, update: PongoUpdate<T> | SQL) => SQL;
|
|
28
|
+
deleteOne: <T>(filter: PongoFilter<T> | SQL, options?: DeleteOneOptions) => SQL;
|
|
29
|
+
deleteMany: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
|
+
findOne: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
31
|
+
find: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
32
|
+
countDocuments: <T>(filter: PongoFilter<T> | SQL) => SQL;
|
|
30
33
|
rename: (newName: string) => SQL;
|
|
31
34
|
drop: () => SQL;
|
|
32
35
|
};
|
|
@@ -54,6 +57,19 @@ declare const OperatorMap: {
|
|
|
54
57
|
declare const isOperator: (key: string) => boolean;
|
|
55
58
|
declare const hasOperators: (value: Record<string, unknown>) => boolean;
|
|
56
59
|
|
|
60
|
+
declare const isNumber: (val: unknown) => val is number;
|
|
61
|
+
declare const isString: (val: unknown) => val is string;
|
|
62
|
+
declare class PongoError extends Error {
|
|
63
|
+
errorCode: number;
|
|
64
|
+
constructor(options?: {
|
|
65
|
+
errorCode: number;
|
|
66
|
+
message?: string;
|
|
67
|
+
} | string | number);
|
|
68
|
+
}
|
|
69
|
+
declare class ConcurrencyError extends PongoError {
|
|
70
|
+
constructor(message?: string);
|
|
71
|
+
}
|
|
72
|
+
|
|
57
73
|
type Entry<T> = {
|
|
58
74
|
[K in keyof Required<T>]: [K, Required<T>[K]];
|
|
59
75
|
}[keyof Required<T>];
|
|
@@ -76,4 +92,4 @@ declare const pongoSession: (options?: PongoSessionOptions) => PongoSession;
|
|
|
76
92
|
|
|
77
93
|
declare const pongoTransaction: (options: PongoTransactionOptions) => PongoDbTransaction;
|
|
78
94
|
|
|
79
|
-
export { type NonPartial, OperatorMap,
|
|
95
|
+
export { ConcurrencyError, DeleteOneOptions, type NonPartial, OperatorMap, OptionalUnlessRequiredIdAndVersion, PongoCollection, type PongoCollectionOptions, type PongoCollectionSQLBuilder, PongoDb, PongoDbTransaction, PongoDocument, PongoError, PongoFilter, PongoSession, type PongoSessionOptions, PongoTransactionOptions, PongoUpdate, QueryOperators, ReplaceOneOptions, UpdateOneOptions, WithoutId, hasOperators, isNumber, isOperator, isString, objectEntries, pongoCollection, pongoCollectionPostgreSQLMigrations, pongoCollectionSchemaComponent, pongoSession, pongoTransaction, postgresSQLBuilder };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u}from"./chunk-
|
|
1
|
+
import{A,B,C,D,E,F,G,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"./chunk-QO7XUM5F.js";export{i as ConcurrencyError,s as DOCUMENT_DOES_NOT_EXIST,q as DOCUMENT_EXISTS,u as NO_CONCURRENCY_CHECK,a as OperatorMap,h as PongoError,x as QueryOperators,G as clientToDbOptions,y as expectedVersion,w as expectedVersionValue,j as getPongoDb,c as hasOperators,v as isGeneralExpectedDocumentVersion,d as isNumber,b as isOperator,e as isPostgresClientOptions,g as isString,n as objectEntries,z as operationResult,F as pongoClient,p as pongoCollection,o as pongoCollectionPostgreSQLMigrations,t as pongoCollectionSchemaComponent,m as pongoDbSchemaComponent,A as pongoSchema,l as pongoSession,k as pongoTransaction,f as postgresDb,r as postgresSQLBuilder,C as proxyClientWithSchema,B as proxyPongoDbWithSchema,E as toClientSchemaMetadata,D as toDbSchemaMetadata};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|