@vrplatform/kysely 1.2.22 → 1.2.23
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/build/.data.tar +0 -0
- package/build/main/index.d.ts +1 -0
- package/build/main/index.js +8 -1
- package/build/main/index.js.map +1 -1
- package/build/main/v1.generated.d.ts +291 -173
- package/build/main/v1.generated.js.map +1 -1
- package/build/module/index.d.ts +1 -0
- package/build/module/index.js +7 -1
- package/build/module/index.js.map +1 -1
- package/build/module/v1.generated.d.ts +291 -173
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +8 -5
- package/src/index.ts +8 -1
- package/src/v1.generated.ts +300 -180
package/build/.data.tar
CHANGED
|
Binary file
|
package/build/main/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type Kysely = K<DB>;
|
|
|
8
8
|
export type Postgres = Sql;
|
|
9
9
|
export declare function useKysely(postgres: Sql): K<DB>;
|
|
10
10
|
export declare function usePostgres(connectionString: string, ssl?: boolean): postgres.Sql<{}>;
|
|
11
|
+
export declare function forceCloseAllPostgres(): Promise<void>;
|
|
11
12
|
export declare class DatabaseError extends Error {
|
|
12
13
|
constructor(message: string, cause: any);
|
|
13
14
|
}
|
package/build/main/index.js
CHANGED
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.DatabaseError = exports.sql = void 0;
|
|
21
21
|
exports.useKysely = useKysely;
|
|
22
22
|
exports.usePostgres = usePostgres;
|
|
23
|
+
exports.forceCloseAllPostgres = forceCloseAllPostgres;
|
|
23
24
|
exports.withStack = withStack;
|
|
24
25
|
const utils_1 = require("@finalytic/utils");
|
|
25
26
|
const kysely_1 = require("kysely");
|
|
@@ -37,11 +38,17 @@ function useKysely(postgres) {
|
|
|
37
38
|
plugins: [new kysely_1.CamelCasePlugin()],
|
|
38
39
|
});
|
|
39
40
|
}
|
|
41
|
+
const connections = [];
|
|
40
42
|
function usePostgres(connectionString, ssl) {
|
|
41
|
-
|
|
43
|
+
const pg = (0, postgres_1.default)(connectionString, {
|
|
42
44
|
ssl: ssl ? 'require' : false,
|
|
43
45
|
max: 1,
|
|
44
46
|
});
|
|
47
|
+
connections.push(pg);
|
|
48
|
+
return pg;
|
|
49
|
+
}
|
|
50
|
+
async function forceCloseAllPostgres() {
|
|
51
|
+
await Promise.all(connections.map((pg) => pg.end().catch(() => undefined)));
|
|
45
52
|
}
|
|
46
53
|
class DatabaseError extends Error {
|
|
47
54
|
constructor(message, cause) {
|
package/build/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,8BAOC;AAED,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,8BAOC;AAGD,kCAOC;AAED,sDAEC;AAYD,8BA+BC;AA3FD,4CAAkD;AAClD,mCAAsD;AACtD,2DAAuD;AACvD,wDAA8C;AAe9C,iDAA+B;AAE/B,yCAA2C;AAG3C,iCAA6B;AAApB,6FAAA,GAAG,OAAA;AAIZ,SAAgB,SAAS,CAAC,QAAa;IACrC,OAAO,IAAI,eAAC,CAAK;QACf,OAAO,EAAE,IAAI,sCAAiB,CAAC;YAC7B,QAAQ;SACT,CAAC;QACF,OAAO,EAAE,CAAC,IAAI,wBAAe,EAAE,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,WAAW,GAAwB,EAAE,CAAC;AAC5C,SAAgB,WAAW,CAAC,gBAAwB,EAAE,GAAa;IACjE,MAAM,EAAE,GAAG,IAAA,kBAAQ,EAAC,gBAAgB,EAAE;QACpC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK;QAC5B,GAAG,EAAE,CAAC;KACP,CAAC,CAAC;IACH,WAAW,CAAC,IA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C,CAAC;QACzD,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC;QACvB,OAAO,CAAC,GAAG,CACT,IAAI,SAAS,qBAAqB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAC1E,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,KAAK;YAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;;YAC5C,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;QAC3B,mBAAmB;QACnB,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;QAC1B,MAAM,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,CAAC;QACrC,OAAO,UAAU,CAAC,KAAK,CAAC;QACxB,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,EAAE,EAAE,IAAA,sBAAc,EAAC,KAAK,CAAC,CAAC,CAAC;QACvE,OAAO,CAAC,GAAG,CACT,IAAI,SAAS,qBAAqB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAC1E,CAAC;QACF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { serializeError } from '@finalytic/utils';\nimport { CamelCasePlugin, Kysely as K } from 'kysely';\nimport { PostgresJSDialect } from 'kysely-postgres-js';\nimport postgres, { type Sql } from 'postgres';\n\nexport type {\n ColumnType,\n Expression,\n ExpressionBuilder,\n ExpressionOrFactory,\n Generated,\n Insertable,\n JSONColumnType,\n OperandExpression,\n Selectable,\n SqlBool,\n Updateable,\n} from 'kysely';\nexport * from './v1.generated';\n\nimport { join, relative } from 'node:path';\nimport type { DB } from './v1.generated';\n\nexport { sql } from 'kysely';\n\nexport type Kysely = K<DB>;\nexport type Postgres = Sql;\nexport function useKysely(postgres: Sql) {\n return new K<DB>({\n dialect: new PostgresJSDialect({\n postgres,\n }),\n plugins: [new CamelCasePlugin()],\n });\n}\n\nconst connections: postgres.Sql<any>[] = [];\nexport function usePostgres(connectionString: string, ssl?: boolean) {\n const pg = postgres(connectionString, {\n ssl: ssl ? 'require' : false,\n max: 1,\n });\n connections.push(pg);\n return pg;\n}\n\nexport async function forceCloseAllPostgres() {\n await Promise.all(connections.map((pg) => pg.end().catch(() => undefined)));\n}\n\nexport class DatabaseError extends Error {\n constructor(message: string, cause: any) {\n super(message);\n this.cause = cause;\n }\n}\n\nconst dirname =\n typeof __dirname === 'string' ? join(__dirname, '../../..') : '';\n\nexport async function withStack<T>(a: Promise<T>) {\n // skip if we can't get the stack, probably in a worker\n if (!dirname) return await a;\n\n const now = performance.now();\n const error = new DatabaseError('Error in execute', undefined);\n const stack = error.stack?.split('\\n').slice(3) || undefined;\n const firstLine =\n stack?.length && stack[0]?.includes('(') && dirname\n ? relative(dirname, stack[0].split('(')[1].split(')')[0])\n : undefined;\n try {\n const result = await a;\n console.log(\n `[${firstLine}] Execution time: ${Math.round(performance.now() - now)}ms`\n );\n return result;\n } catch (e: any) {\n if (stack) error.stack = stack.join('\\n').trim();\n else error.stack = e.stack;\n // error.cause = e;\n error.message = e.message;\n const serialized = serializeError(e);\n delete serialized.stack;\n error.cause = serialized;\n console.error(`Error in execute: ${firstLine}`, serializeError(error));\n console.log(\n `[${firstLine}] Execution time: ${Math.round(performance.now() - now)}ms`\n );\n throw error;\n }\n}\n"]}
|