@vrplatform/kysely 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/build/main/index.d.ts +7 -5
  2. package/build/main/index.js +13 -6
  3. package/build/main/index.js.map +1 -1
  4. package/build/main/local/index.d.ts +6 -2
  5. package/build/main/local/index.js +9 -2
  6. package/build/main/local/index.js.map +1 -1
  7. package/build/main/pganalyze-comment-plugin/comment-transformer.d.ts +21 -0
  8. package/build/main/pganalyze-comment-plugin/comment-transformer.js +90 -0
  9. package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -0
  10. package/build/main/pganalyze-comment-plugin/index.d.ts +9 -0
  11. package/build/main/pganalyze-comment-plugin/index.js +31 -0
  12. package/build/main/pganalyze-comment-plugin/index.js.map +1 -0
  13. package/build/main/test/index.d.ts +15 -0
  14. package/build/main/test/index.js +47 -0
  15. package/build/main/test/index.js.map +1 -0
  16. package/build/main/tsconfig.main.tsbuildinfo +1 -1
  17. package/build/main/v1.generated.d.ts +1 -0
  18. package/build/main/v1.generated.js.map +1 -1
  19. package/build/module/index.d.ts +7 -5
  20. package/build/module/index.js +14 -7
  21. package/build/module/index.js.map +1 -1
  22. package/build/module/local/index.d.ts +6 -2
  23. package/build/module/local/index.js +9 -2
  24. package/build/module/local/index.js.map +1 -1
  25. package/build/module/pganalyze-comment-plugin/comment-transformer.d.ts +21 -0
  26. package/build/module/pganalyze-comment-plugin/comment-transformer.js +87 -0
  27. package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -0
  28. package/build/module/pganalyze-comment-plugin/index.d.ts +9 -0
  29. package/build/module/pganalyze-comment-plugin/index.js +14 -0
  30. package/build/module/pganalyze-comment-plugin/index.js.map +1 -0
  31. package/build/module/test/index.d.ts +15 -0
  32. package/build/module/test/index.js +42 -0
  33. package/build/module/test/index.js.map +1 -0
  34. package/build/module/tsconfig.esm.tsbuildinfo +1 -1
  35. package/build/module/v1.generated.d.ts +1 -0
  36. package/build/module/v1.generated.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/index.ts +31 -8
  39. package/src/local/index.ts +14 -3
  40. package/src/pganalyze-comment-plugin/comment-transformer.ts +117 -0
  41. package/src/pganalyze-comment-plugin/index.ts +27 -0
  42. package/src/test/index.ts +63 -0
  43. package/src/v1.generated.ts +1 -0
  44. package/src/test.ts +0 -19
@@ -1,4 +1,4 @@
1
- import { Kysely as K, type Transaction as T } from 'kysely';
1
+ import { Kysely as K, type LogConfig, type Transaction as T } from 'kysely';
2
2
  import postgres, { type Sql } from 'postgres';
3
3
  export type { ColumnType, Expression, ExpressionBuilder, ExpressionOrFactory, Generated, Insertable, JSONColumnType, OperandExpression, Selectable, SelectQueryBuilder, SqlBool, Updateable, } from 'kysely';
4
4
  export { jsonArrayFrom } from 'kysely/helpers/postgres';
@@ -6,6 +6,10 @@ export * from './v1.generated';
6
6
  import type { DB } from './v1.generated';
7
7
  export type Transaction = T<DB>;
8
8
  export { sql } from 'kysely';
9
+ type KyselyOpts = {
10
+ repositoryName?: string;
11
+ log?: true | LogConfig;
12
+ };
9
13
  type PgOpt = {
10
14
  forceDisableSSL?: boolean;
11
15
  retries?: false | number;
@@ -15,11 +19,9 @@ export type Postgres = Sql;
15
19
  /**
16
20
  * @deprecated This method is deprecated in favor of the useAsyncKysely method.
17
21
  */
18
- export declare function useKysely(postgres: Sql, options?: {
19
- log?: boolean;
20
- }): K<DB>;
22
+ export declare function useKysely(postgres: Sql, options?: KyselyOpts): K<DB>;
21
23
  export declare function useAsyncPostgres(connectionString: string, opt?: PgOpt): Promise<postgres.Sql<{}>>;
22
- export declare function useAsyncKysely(connectionString: string, opt?: PgOpt): Promise<K<DB>>;
24
+ export declare function useAsyncKysely(connectionString: string, opt?: PgOpt & KyselyOpts): Promise<K<DB>>;
23
25
  /**
24
26
  * @deprecated This method is deprecated in favor of the useAsyncKysely method.
25
27
  */
@@ -32,19 +32,26 @@ var postgres_2 = require("kysely/helpers/postgres");
32
32
  Object.defineProperty(exports, "jsonArrayFrom", { enumerable: true, get: function () { return postgres_2.jsonArrayFrom; } });
33
33
  __exportStar(require("./v1.generated"), exports);
34
34
  const node_path_1 = require("node:path");
35
+ const pganalyze_comment_plugin_1 = require("./pganalyze-comment-plugin");
35
36
  var kysely_2 = require("kysely");
36
37
  Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return kysely_2.sql; } });
37
38
  /**
38
39
  * @deprecated This method is deprecated in favor of the useAsyncKysely method.
39
40
  */
40
- function useKysely(postgres, options = {}) {
41
+ function useKysely(postgres, options) {
41
42
  console.debug('Creating Kysely instance');
43
+ const plugins = [new kysely_1.CamelCasePlugin()];
44
+ if (options?.repositoryName) {
45
+ plugins.push(new pganalyze_comment_plugin_1.KyselyPganalyzeCommentPlugin({
46
+ repository: options.repositoryName,
47
+ }));
48
+ }
42
49
  const kysely = new kysely_1.Kysely({
43
50
  dialect: new kysely_postgres_js_1.PostgresJSDialect({
44
51
  postgres,
45
52
  }),
46
- plugins: [new kysely_1.CamelCasePlugin()],
47
- log: options?.log ? ['query', 'error'] : undefined,
53
+ plugins,
54
+ log: options?.log === true ? ['query', 'error'] : options?.log,
48
55
  });
49
56
  kysely.destroy = async () => {
50
57
  console.debug('Closing Kysely connection');
@@ -73,8 +80,8 @@ async function useAsyncPostgres(connectionString, opt) {
73
80
  ssl: ssl ? 'require' : false,
74
81
  // connect_timeout: 10
75
82
  // idle_timeout: 10
76
- // disable prepare statements since we use pgbouncer
77
- prepare: false,
83
+ // enable prepare statements, pgbouncer on crunchy allows for prepared statements
84
+ prepare: true,
78
85
  connect_timeout: 10,
79
86
  idle_timeout: 60,
80
87
  });
@@ -102,7 +109,7 @@ async function useAsyncPostgres(connectionString, opt) {
102
109
  }
103
110
  async function useAsyncKysely(connectionString, opt) {
104
111
  const sql = await useAsyncPostgres(connectionString, opt);
105
- return useKysely(sql);
112
+ return useKysely(sql, opt);
106
113
  }
107
114
  /**
108
115
  * @deprecated This method is deprecated in favor of the useAsyncKysely method.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAsCA,8BAqBC;AAGD,4CA6CC;AAED,wCAGC;AAKD,kCAeC;AAED,sDAUC;AAYD,8BA+BC;AA3LD,4CAAkD;AAClD,mCAA6E;AAC7E,2DAAuD;AACvD,wDAA8C;AAgB9C,oDAAwD;AAA/C,yGAAA,aAAa,OAAA;AACtB,iDAA+B;AAE/B,yCAA2C;AAI3C,iCAA6B;AAApB,6FAAA,GAAG,OAAA;AASZ;;GAEG;AACH,SAAgB,SAAS,CAAC,QAAa,EAAE,UAA6B,EAAE;IACtE,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,eAAC,CAAK;QACvB,OAAO,EAAE,IAAI,sCAAiB,CAAC;YAC7B,QAAQ;SACT,CAAC;QACF,OAAO,EAAE,CAAC,IAAI,wBAAe,EAAE,CAAC;QAChC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;KACnD,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC3C,MAAM,OAAO,CAAC,IAAI,CAAC;YACjB,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;YACtD,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SAC5C,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,KAAK,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,CAC1E,CAAC;QACF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { serializeError } from '@finalytic/utils';\nimport { CamelCasePlugin, Kysely as K, type Transaction as T } 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 SelectQueryBuilder,\n SqlBool,\n Updateable,\n} from 'kysely';\nexport { jsonArrayFrom } from 'kysely/helpers/postgres';\nexport * from './v1.generated';\n\nimport { join, relative } from 'node:path';\nimport type { DB } from './v1.generated';\n\nexport type Transaction = T<DB>;\nexport { sql } from 'kysely';\n\ntype PgOpt = {\n forceDisableSSL?: boolean;\n retries?: false | number;\n};\n\nexport type Kysely = K<DB>;\nexport type Postgres = Sql;\n/**\n * @deprecated This method is deprecated in favor of the useAsyncKysely method.\n */\nexport function useKysely(postgres: Sql, options: { log?: boolean } = {}) {\n console.debug('Creating Kysely instance');\n const kysely = new K<DB>({\n dialect: new PostgresJSDialect({\n postgres,\n }),\n plugins: [new CamelCasePlugin()],\n log: options?.log ? ['query', 'error'] : undefined,\n });\n\n kysely.destroy = async () => {\n console.debug('Closing Kysely connection');\n await Promise.race([\n postgres.end({ timeout: 5000 }).catch(() => undefined),\n new Promise((res) => setTimeout(res, 6000)),\n ]);\n const index = _connections.indexOf(postgres);\n if (index !== -1) _connections.splice(index, 1);\n };\n\n return kysely;\n}\n\nlet _connections: postgres.Sql[] = [];\nexport async function useAsyncPostgres(connectionString: string, opt?: PgOpt) {\n const delayMs = 2500;\n const retries = opt?.retries === false ? 0 : opt?.retries || 3;\n const ssl = opt?.forceDisableSSL !== true;\n const url = new URL(connectionString);\n\n console.debug(\n `Creating Postgres connection with ${retries} retries and ssl=${ssl} and port=${url.port}`\n );\n if (_connections.length > 0)\n console.warn(`We already have ${_connections.length} Postgres connections`);\n\n for (let attempt = 1; attempt <= retries; attempt++) {\n try {\n const sql = postgres(connectionString, {\n ssl: ssl ? 'require' : false,\n // connect_timeout: 10\n // idle_timeout: 10\n // disable prepare statements since we use pgbouncer\n prepare: false,\n connect_timeout: 10,\n idle_timeout: 60,\n });\n\n await sql`select 1`;\n try {\n // connect 30s, idle 60s, max lifetime 45min, statement 60s, lock 10s, log_min_duration 20s, log_lock_waits off\n await sql`set statement_timeout to '30s';`;\n await sql`set lock_timeout to '10s';`;\n } catch (e) {\n console.warn('Failed to set statement timeout, continuing', e);\n }\n\n _connections.push(sql);\n return sql;\n } catch (err) {\n if (attempt === retries) throw err;\n console.warn(\n `Postgres connection failed (attempt ${attempt}), retrying...`\n );\n console.error('error', err);\n await new Promise((res) => setTimeout(res, delayMs));\n }\n }\n throw new Error('Unable to connect to Postgres');\n}\n\nexport async function useAsyncKysely(connectionString: string, opt?: PgOpt) {\n const sql = await useAsyncPostgres(connectionString, opt);\n return useKysely(sql);\n}\n\n/**\n * @deprecated This method is deprecated in favor of the useAsyncKysely method.\n */\nexport function usePostgres(\n connectionString?: string,\n opt?: Pick<PgOpt, 'forceDisableSSL'>\n) {\n if (!connectionString) throw new Error('No connection string');\n const ssl = opt?.forceDisableSSL !== true;\n const url = new URL(connectionString);\n console.debug(\n `Creating sync Postgres connection with ssl=${ssl} and port=${url.port}`\n );\n const pg = postgres(connectionString, {\n ssl: ssl ? 'require' : false,\n });\n _connections.push(pg);\n return pg;\n}\n\nexport async function forceCloseAllPostgres(timeoutMs = 5000) {\n await Promise.race([\n Promise.all(\n _connections.map((pg) =>\n pg.end({ timeout: timeoutMs }).catch(() => undefined)\n )\n ),\n new Promise((res) => setTimeout(res, timeoutMs + 1000)),\n ]);\n _connections = [];\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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAkDA,8BA6BC;AAGD,4CA6CC;AAED,wCAMC;AAKD,kCAeC;AAED,sDAUC;AAYD,8BA+BC;AAlND,4CAAkD;AAClD,mCAMgB;AAChB,2DAAuD;AACvD,wDAA8C;AAgB9C,oDAAwD;AAA/C,yGAAA,aAAa,OAAA;AACtB,iDAA+B;AAE/B,yCAA2C;AAC3C,yEAA0E;AAI1E,iCAA6B;AAApB,6FAAA,GAAG,OAAA;AAcZ;;GAEG;AACH,SAAgB,SAAS,CAAC,QAAa,EAAE,OAAoB;IAC3D,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAmB,CAAC,IAAI,wBAAe,EAAE,CAAC,CAAC;IACxD,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CACV,IAAI,uDAA4B,CAAC;YAC/B,UAAU,EAAE,OAAO,CAAC,cAAc;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,eAAC,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,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 {\n CamelCasePlugin,\n Kysely as K,\n type KyselyPlugin,\n type LogConfig,\n type Transaction as T,\n} 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 SelectQueryBuilder,\n SqlBool,\n Updateable,\n} from 'kysely';\nexport { jsonArrayFrom } from 'kysely/helpers/postgres';\nexport * from './v1.generated';\n\nimport { join, relative } from 'node:path';\nimport { KyselyPganalyzeCommentPlugin } from './pganalyze-comment-plugin';\nimport type { DB } from './v1.generated';\n\nexport type Transaction = T<DB>;\nexport { sql } from 'kysely';\n\ntype KyselyOpts = {\n repositoryName?: string;\n log?: true | LogConfig;\n};\n\ntype PgOpt = {\n forceDisableSSL?: boolean;\n retries?: false | number;\n};\n\nexport type Kysely = K<DB>;\nexport type Postgres = Sql;\n/**\n * @deprecated This method is deprecated in favor of the useAsyncKysely method.\n */\nexport function useKysely(postgres: Sql, options?: KyselyOpts) {\n console.debug('Creating Kysely instance');\n const plugins: KyselyPlugin[] = [new CamelCasePlugin()];\n if (options?.repositoryName) {\n plugins.push(\n new KyselyPganalyzeCommentPlugin({\n repository: options.repositoryName,\n })\n );\n }\n const kysely = new K<DB>({\n dialect: new PostgresJSDialect({\n postgres,\n }),\n plugins,\n log: options?.log === true ? ['query', 'error'] : options?.log,\n });\n\n kysely.destroy = async () => {\n console.debug('Closing Kysely connection');\n await Promise.race([\n postgres.end({ timeout: 5000 }).catch(() => undefined),\n new Promise((res) => setTimeout(res, 6000)),\n ]);\n const index = _connections.indexOf(postgres);\n if (index !== -1) _connections.splice(index, 1);\n };\n\n return kysely;\n}\n\nlet _connections: postgres.Sql[] = [];\nexport async function useAsyncPostgres(connectionString: string, opt?: PgOpt) {\n const delayMs = 2500;\n const retries = opt?.retries === false ? 0 : opt?.retries || 3;\n const ssl = opt?.forceDisableSSL !== true;\n const url = new URL(connectionString);\n\n console.debug(\n `Creating Postgres connection with ${retries} retries and ssl=${ssl} and port=${url.port}`\n );\n if (_connections.length > 0)\n console.warn(`We already have ${_connections.length} Postgres connections`);\n\n for (let attempt = 1; attempt <= retries; attempt++) {\n try {\n const sql = postgres(connectionString, {\n ssl: ssl ? 'require' : false,\n // connect_timeout: 10\n // idle_timeout: 10\n // enable prepare statements, pgbouncer on crunchy allows for prepared statements\n prepare: true,\n connect_timeout: 10,\n idle_timeout: 60,\n });\n\n await sql`select 1`;\n try {\n // connect 30s, idle 60s, max lifetime 45min, statement 60s, lock 10s, log_min_duration 20s, log_lock_waits off\n await sql`set statement_timeout to '30s';`;\n await sql`set lock_timeout to '10s';`;\n } catch (e) {\n console.warn('Failed to set statement timeout, continuing', e);\n }\n\n _connections.push(sql);\n return sql;\n } catch (err) {\n if (attempt === retries) throw err;\n console.warn(\n `Postgres connection failed (attempt ${attempt}), retrying...`\n );\n console.error('error', err);\n await new Promise((res) => setTimeout(res, delayMs));\n }\n }\n throw new Error('Unable to connect to Postgres');\n}\n\nexport async function useAsyncKysely(\n connectionString: string,\n opt?: PgOpt & KyselyOpts\n) {\n const sql = await useAsyncPostgres(connectionString, opt);\n return useKysely(sql, opt);\n}\n\n/**\n * @deprecated This method is deprecated in favor of the useAsyncKysely method.\n */\nexport function usePostgres(\n connectionString?: string,\n opt?: Pick<PgOpt, 'forceDisableSSL'>\n) {\n if (!connectionString) throw new Error('No connection string');\n const ssl = opt?.forceDisableSSL !== true;\n const url = new URL(connectionString);\n console.debug(\n `Creating sync Postgres connection with ssl=${ssl} and port=${url.port}`\n );\n const pg = postgres(connectionString, {\n ssl: ssl ? 'require' : false,\n });\n _connections.push(pg);\n return pg;\n}\n\nexport async function forceCloseAllPostgres(timeoutMs = 5000) {\n await Promise.race([\n Promise.all(\n _connections.map((pg) =>\n pg.end({ timeout: timeoutMs }).catch(() => undefined)\n )\n ),\n new Promise((res) => setTimeout(res, timeoutMs + 1000)),\n ]);\n _connections = [];\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"]}
@@ -1,5 +1,9 @@
1
- import { Kysely } from 'kysely';
1
+ import { Kysely, type LogConfig } from 'kysely';
2
2
  import type { DB } from '../v1.generated';
3
3
  export declare const root: string;
4
4
  export declare const dumpPath: string;
5
- export declare function useLocalKysely(): Promise<Kysely<DB>>;
5
+ export type UseLocalKyselyOptions = {
6
+ repositoryName?: string;
7
+ log?: true | LogConfig;
8
+ };
9
+ export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<Kysely<DB>>;
@@ -6,9 +6,10 @@ const node_path_1 = require("node:path");
6
6
  const pglite_1 = require("@electric-sql/pglite");
7
7
  const kysely_1 = require("kysely");
8
8
  const kysely_pglite_1 = require("kysely-pglite");
9
+ const pganalyze_comment_plugin_1 = require("../pganalyze-comment-plugin");
9
10
  exports.root = (0, node_path_1.join)(__dirname, '../..');
10
11
  exports.dumpPath = (0, node_path_1.join)(exports.root, '.data.tar');
11
- async function useLocalKysely() {
12
+ async function useLocalKysely(args = {}) {
12
13
  let isDestroyed = false;
13
14
  const now = performance.now();
14
15
  const dump = Bun.file(exports.dumpPath);
@@ -18,7 +19,13 @@ async function useLocalKysely() {
18
19
  const { dialect } = new kysely_pglite_1.KyselyPGlite(pglite);
19
20
  const kysely = new kysely_1.Kysely({
20
21
  dialect,
21
- plugins: [new kysely_1.CamelCasePlugin()],
22
+ log: args.log === true ? ['query', 'error'] : args.log,
23
+ plugins: [
24
+ new kysely_1.CamelCasePlugin(),
25
+ new pganalyze_comment_plugin_1.KyselyPganalyzeCommentPlugin({
26
+ repository: args.repositoryName ?? 'localTesting',
27
+ }),
28
+ ],
22
29
  });
23
30
  const originalDestroy = kysely.destroy.bind(kysely);
24
31
  kysely.destroy = async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/index.ts"],"names":[],"mappings":";;;AASA,wCA8BC;AAvCD,yCAAiC;AACjC,iDAA8C;AAC9C,mCAAiD;AACjD,iDAA6C;AAGhC,QAAA,IAAI,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAChC,QAAA,QAAQ,GAAG,IAAA,gBAAI,EAAC,YAAI,EAAE,WAAW,CAAC,CAAC;AAEzC,KAAK,UAAU,cAAc;IAClC,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAE9B,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,gBAAQ,CAAC,CAAC;IAEhC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,UAAU;IACV,MAAM,MAAM,CAAC,GAAG,CAAA,UAAU,CAAC;IAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,4BAAY,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,IAAI,eAAM,CAAK;QAC5B,OAAO;QACP,OAAO,EAAE,CAAC,IAAI,wBAAe,EAAE,CAAC;KACjC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACtC,MAAM,eAAe,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CACT,uBAAuB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,IAAI,CACvE,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IAE9E,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { CamelCasePlugin, Kysely } from 'kysely';\nimport { KyselyPGlite } from 'kysely-pglite';\nimport type { DB } from '../v1.generated';\n\nexport const root = join(__dirname, '../..');\nexport const dumpPath = join(root, '.data.tar');\n\nexport async function useLocalKysely() {\n let isDestroyed = false;\n const now = performance.now();\n\n const dump = Bun.file(dumpPath);\n\n const pglite = new PGlite({ loadDataDir: dump });\n // warm up\n await pglite.sql`SELECT 1`;\n const { dialect } = new KyselyPGlite(pglite);\n const kysely = new Kysely<DB>({\n dialect,\n plugins: [new CamelCasePlugin()],\n });\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n const destroyTime = performance.now();\n await originalDestroy().catch(() => undefined);\n await pglite.close().catch(() => undefined);\n console.log(\n `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n );\n };\n\n console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/index.ts"],"names":[],"mappings":";;;AAcA,wCAoCC;AAlDD,yCAAiC;AACjC,iDAA8C;AAC9C,mCAAiE;AACjE,iDAA6C;AAC7C,0EAA2E;AAG9D,QAAA,IAAI,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,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GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CACT,uBAAuB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,IAAI,CACvE,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IAE9E,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { CamelCasePlugin, Kysely, type LogConfig } from 'kysely';\nimport { KyselyPGlite } from 'kysely-pglite';\nimport { KyselyPganalyzeCommentPlugin } from '../pganalyze-comment-plugin';\nimport type { DB } from '../v1.generated';\n\nexport const root = join(__dirname, '../..');\nexport const dumpPath = join(root, '.data.tar');\n\nexport type UseLocalKyselyOptions = {\n repositoryName?: string;\n log?: true | LogConfig;\n};\nexport async function useLocalKysely(args: UseLocalKyselyOptions = {}) {\n let isDestroyed = false;\n const now = performance.now();\n\n const dump = Bun.file(dumpPath);\n\n const pglite = new PGlite({ loadDataDir: dump });\n // warm up\n await pglite.sql`SELECT 1`;\n const { dialect } = new KyselyPGlite(pglite);\n const kysely = new Kysely<DB>({\n dialect,\n log: args.log === true ? ['query', 'error'] : args.log,\n plugins: [\n new CamelCasePlugin(),\n new KyselyPganalyzeCommentPlugin({\n repository: args.repositoryName ?? 'localTesting',\n }),\n ],\n });\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n const destroyTime = performance.now();\n await originalDestroy().catch(() => undefined);\n await pglite.close().catch(() => undefined);\n console.log(\n `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n );\n };\n\n console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely;\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { type DeleteQueryNode, type InsertQueryNode, OperationNodeTransformer, type RootOperationNode, type SelectQueryNode, type UpdateQueryNode } from 'kysely';
2
+ /**
3
+ * Transformer that adds a SQL comment to queries for pganalyze tracking.
4
+ * The comment format is: repository: REPOSITORY_NAME
5
+ *
6
+ * This works by appending the comment to queries using the endModifiers property,
7
+ * similar to how modifyEnd works.
8
+ */
9
+ export declare class CommentTransformer extends OperationNodeTransformer {
10
+ readonly _repositoryName: string;
11
+ constructor(_repositoryName: string);
12
+ transformRootNode(node: RootOperationNode): RootOperationNode;
13
+ protected transformSelectQuery(node: SelectQueryNode): SelectQueryNode;
14
+ protected transformInsertQuery(node: InsertQueryNode): InsertQueryNode;
15
+ protected transformUpdateQuery(node: UpdateQueryNode): UpdateQueryNode;
16
+ protected transformDeleteQuery(node: DeleteQueryNode): DeleteQueryNode;
17
+ private addCommentToSelectQuery;
18
+ private addCommentToInsertQuery;
19
+ private addCommentToUpdateQuery;
20
+ private addCommentToDeleteQuery;
21
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommentTransformer = void 0;
4
+ const kysely_1 = require("kysely");
5
+ function createCommentNode(repositoryName) {
6
+ return kysely_1.SelectModifierNode.createWithExpression(kysely_1.sql.raw(`/* repository: ${repositoryName} */`).toOperationNode());
7
+ }
8
+ /**
9
+ * Transformer that adds a SQL comment to queries for pganalyze tracking.
10
+ * The comment format is: repository: REPOSITORY_NAME
11
+ *
12
+ * This works by appending the comment to queries using the endModifiers property,
13
+ * similar to how modifyEnd works.
14
+ */
15
+ class CommentTransformer extends kysely_1.OperationNodeTransformer {
16
+ constructor(_repositoryName) {
17
+ super();
18
+ this._repositoryName = _repositoryName;
19
+ }
20
+ transformRootNode(node) {
21
+ if (node.kind === 'SelectQueryNode') {
22
+ return this.transformSelectQuery(node);
23
+ }
24
+ if (node.kind === 'InsertQueryNode') {
25
+ return this.transformInsertQuery(node);
26
+ }
27
+ if (node.kind === 'UpdateQueryNode') {
28
+ return this.transformUpdateQuery(node);
29
+ }
30
+ if (node.kind === 'DeleteQueryNode') {
31
+ return this.transformDeleteQuery(node);
32
+ }
33
+ return node;
34
+ }
35
+ transformSelectQuery(node) {
36
+ const transformed = super.transformSelectQuery(node);
37
+ return this.addCommentToSelectQuery(transformed);
38
+ }
39
+ transformInsertQuery(node) {
40
+ const transformed = super.transformInsertQuery(node);
41
+ return this.addCommentToInsertQuery(transformed);
42
+ }
43
+ transformUpdateQuery(node) {
44
+ const transformed = super.transformUpdateQuery(node);
45
+ return this.addCommentToUpdateQuery(transformed);
46
+ }
47
+ transformDeleteQuery(node) {
48
+ const transformed = super.transformDeleteQuery(node);
49
+ return this.addCommentToDeleteQuery(transformed);
50
+ }
51
+ addCommentToSelectQuery(node) {
52
+ // Append comment using endModifiers property, similar to modifyEnd
53
+ const commentNode = createCommentNode(this._repositoryName);
54
+ return {
55
+ ...node,
56
+ endModifiers: node.endModifiers
57
+ ? [...node.endModifiers, commentNode]
58
+ : [commentNode],
59
+ };
60
+ }
61
+ addCommentToInsertQuery(node) {
62
+ const commentNode = createCommentNode(this._repositoryName);
63
+ return {
64
+ ...node,
65
+ endModifiers: node.endModifiers
66
+ ? [...node.endModifiers, commentNode]
67
+ : [commentNode],
68
+ };
69
+ }
70
+ addCommentToUpdateQuery(node) {
71
+ const commentNode = createCommentNode(this._repositoryName);
72
+ return {
73
+ ...node,
74
+ endModifiers: node.endModifiers
75
+ ? [...node.endModifiers, commentNode]
76
+ : [commentNode],
77
+ };
78
+ }
79
+ addCommentToDeleteQuery(node) {
80
+ const commentNode = createCommentNode(this._repositoryName);
81
+ return {
82
+ ...node,
83
+ endModifiers: node.endModifiers
84
+ ? [...node.endModifiers, commentNode]
85
+ : [commentNode],
86
+ };
87
+ }
88
+ }
89
+ exports.CommentTransformer = CommentTransformer;
90
+ //# sourceMappingURL=comment-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment-trans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AAC,WAAW,CAAC;SAClB,CAAC;IACJ,CAAC;IAEO,uBAAuB,CAAC,IAAqB;QACnD,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAE5D,OAAO;YACL,GAAG,IAAI;YACP,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC7B,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;gBACrC,CAAC,CAAC,CAAC,WAAW,CAAC;SAClB,CAAC;IACJ,CAAC;CACF;AA7FD,gDA6FC","sourcesContent":["import {\n type DeleteQueryNode,\n type InsertQueryNode,\n OperationNodeTransformer,\n type RootOperationNode,\n SelectModifierNode,\n type SelectQueryNode,\n sql,\n type UpdateQueryNode,\n} from 'kysely';\n\nfunction createCommentNode(repositoryName: string): SelectModifierNode {\n return SelectModifierNode.createWithExpression(\n sql.raw(`/* repository: ${repositoryName} */`).toOperationNode()\n );\n}\n/**\n * Transformer that adds a SQL comment to queries for pganalyze tracking.\n * The comment format is: repository: REPOSITORY_NAME\n *\n * This works by appending the comment to queries using the endModifiers property,\n * similar to how modifyEnd works.\n */\nexport class CommentTransformer extends OperationNodeTransformer {\n constructor(readonly _repositoryName: string) {\n super();\n }\n\n transformRootNode(node: RootOperationNode): RootOperationNode {\n if (node.kind === 'SelectQueryNode') {\n return this.transformSelectQuery(node);\n }\n if (node.kind === 'InsertQueryNode') {\n return this.transformInsertQuery(node);\n }\n if (node.kind === 'UpdateQueryNode') {\n return this.transformUpdateQuery(node);\n }\n if (node.kind === 'DeleteQueryNode') {\n return this.transformDeleteQuery(node);\n }\n return node;\n }\n\n protected override transformSelectQuery(\n node: SelectQueryNode\n ): SelectQueryNode {\n const transformed = super.transformSelectQuery(node);\n return this.addCommentToSelectQuery(transformed);\n }\n\n protected override transformInsertQuery(\n node: InsertQueryNode\n ): InsertQueryNode {\n const transformed = super.transformInsertQuery(node);\n return this.addCommentToInsertQuery(transformed);\n }\n\n protected override transformUpdateQuery(\n node: UpdateQueryNode\n ): UpdateQueryNode {\n const transformed = super.transformUpdateQuery(node);\n return this.addCommentToUpdateQuery(transformed);\n }\n\n protected override transformDeleteQuery(\n node: DeleteQueryNode\n ): DeleteQueryNode {\n const transformed = super.transformDeleteQuery(node);\n return this.addCommentToDeleteQuery(transformed);\n }\n\n private addCommentToSelectQuery(node: SelectQueryNode): SelectQueryNode {\n // Append comment using endModifiers property, similar to modifyEnd\n const commentNode = createCommentNode(this._repositoryName);\n\n return {\n ...node,\n endModifiers: node.endModifiers\n ? [...node.endModifiers, commentNode]\n : [commentNode],\n };\n }\n\n private addCommentToInsertQuery(node: InsertQueryNode): InsertQueryNode {\n const commentNode = createCommentNode(this._repositoryName);\n\n return {\n ...node,\n endModifiers: node.endModifiers\n ? [...node.endModifiers, commentNode]\n : [commentNode],\n };\n }\n\n private addCommentToUpdateQuery(node: UpdateQueryNode): UpdateQueryNode {\n const commentNode = createCommentNode(this._repositoryName);\n\n return {\n ...node,\n endModifiers: node.endModifiers\n ? [...node.endModifiers, commentNode]\n : [commentNode],\n };\n }\n\n private addCommentToDeleteQuery(node: DeleteQueryNode): DeleteQueryNode {\n const commentNode = createCommentNode(this._repositoryName);\n\n return {\n ...node,\n endModifiers: node.endModifiers\n ? [...node.endModifiers, commentNode]\n : [commentNode],\n };\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, RootOperationNode, UnknownRow } from 'kysely';
2
+ export declare class KyselyPganalyzeCommentPlugin implements KyselyPlugin {
3
+ #private;
4
+ constructor(options: {
5
+ repository: string;
6
+ });
7
+ transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
8
+ transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
9
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _KyselyPganalyzeCommentPlugin_transformer;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.KyselyPganalyzeCommentPlugin = void 0;
16
+ const comment_transformer_1 = require("./comment-transformer");
17
+ class KyselyPganalyzeCommentPlugin {
18
+ constructor(options) {
19
+ _KyselyPganalyzeCommentPlugin_transformer.set(this, void 0);
20
+ __classPrivateFieldSet(this, _KyselyPganalyzeCommentPlugin_transformer, new comment_transformer_1.CommentTransformer(options.repository), "f");
21
+ }
22
+ transformQuery(args) {
23
+ return __classPrivateFieldGet(this, _KyselyPganalyzeCommentPlugin_transformer, "f").transformRootNode(args.node);
24
+ }
25
+ async transformResult(args) {
26
+ return args.result;
27
+ }
28
+ }
29
+ exports.KyselyPganalyzeCommentPlugin = KyselyPganalyzeCommentPlugin;
30
+ _KyselyPganalyzeCommentPlugin_transformer = new WeakMap();
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["pganalyze-comment-plugin/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,+DAA2D;AAE3D,MAAa,4BAA4B;IAGvC,YAAY,OAA+B;QAFlC,4DAAiC;QAGxC,uBAAA,IAAI,6CAAgB,IAAI,wCAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,MAAA,CAAC;IACjE,CAAC;IAED,cAAc,CAAC,IAA8B;QAC3C,OAAO,uBAAA,IAAI,iDAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,IAA+B;QAE/B,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAhBD,oEAgBC","sourcesContent":["import type {\n KyselyPlugin,\n PluginTransformQueryArgs,\n PluginTransformResultArgs,\n QueryResult,\n RootOperationNode,\n UnknownRow,\n} from 'kysely';\nimport { CommentTransformer } from './comment-transformer';\n\nexport class KyselyPganalyzeCommentPlugin implements KyselyPlugin {\n readonly #transformer: CommentTransformer;\n\n constructor(options: { repository: string }) {\n this.#transformer = new CommentTransformer(options.repository);\n }\n\n transformQuery(args: PluginTransformQueryArgs): RootOperationNode {\n return this.#transformer.transformRootNode(args.node);\n }\n\n async transformResult(\n args: PluginTransformResultArgs\n ): Promise<QueryResult<UnknownRow>> {\n return args.result;\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { type UseLocalKyselyOptions } from '../local';
3
+ import type { DB } from '../v1.generated';
4
+ /**
5
+ * @deprecated Use `useLocalKyselyResource` instead.
6
+ */
7
+ export declare function useTestKysely(cleanupStrategy: 'afterAll', args?: UseLocalKyselyOptions): Promise<{
8
+ kysely: Kysely<DB>;
9
+ }>;
10
+ export declare function useTestAutoCleanupKysely(args?: UseLocalKyselyOptions): Promise<Kysely<DB>>;
11
+ type ReturnType = Kysely<DB> & {
12
+ [Symbol.dispose]: () => Promise<void>;
13
+ };
14
+ export declare function useLocalKyselyResource(args?: UseLocalKyselyOptions): Promise<ReturnType>;
15
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTestKysely = useTestKysely;
4
+ exports.useTestAutoCleanupKysely = useTestAutoCleanupKysely;
5
+ exports.useLocalKyselyResource = useLocalKyselyResource;
6
+ const bun_test_1 = require("bun:test");
7
+ const local_1 = require("../local");
8
+ /**
9
+ * @deprecated Use `useLocalKyselyResource` instead.
10
+ */
11
+ async function useTestKysely(cleanupStrategy, args) {
12
+ const kysely = await (0, local_1.useLocalKysely)(args);
13
+ if (cleanupStrategy === 'afterAll')
14
+ (0, bun_test_1.afterAll)(async () => {
15
+ await kysely.destroy();
16
+ });
17
+ return {
18
+ kysely,
19
+ };
20
+ }
21
+ async function useTestAutoCleanupKysely(args) {
22
+ const kysely = await (0, local_1.useLocalKysely)(args);
23
+ (0, bun_test_1.afterAll)(async () => {
24
+ await kysely.destroy();
25
+ });
26
+ return kysely;
27
+ }
28
+ async function useLocalKyselyResource(args) {
29
+ const kysely = await (0, local_1.useLocalKysely)(args);
30
+ return new Proxy({}, {
31
+ get(_target, prop) {
32
+ if (prop === Symbol.dispose) {
33
+ return async () => {
34
+ await kysely.destroy();
35
+ };
36
+ }
37
+ if (prop === 'kysely') {
38
+ return kysely;
39
+ }
40
+ if (typeof kysely[prop] === 'function') {
41
+ return kysely[prop].bind(kysely);
42
+ }
43
+ return kysely[prop];
44
+ },
45
+ });
46
+ }
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["test/index.ts"],"names":[],"mappings":";;AAQA,sCAcC;AAED,4DAQC;AAMD,wDAwBC;AA9DD,uCAAoC;AAEpC,oCAAsE;AAGtE;;GAEG;AACI,KAAK,UAAU,aAAa,CACjC,eAA2B,EAC3B,IAA4B;IAE5B,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC;IAE1C,IAAI,eAAe,KAAK,UAAU;QAChC,IAAA,mBAAQ,EAAC,KAAK,IAAI,EAAE;YAClB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IAEL,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAAC,IAA4B;IACzE,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC;IAE1C,IAAA,mBAAQ,EAAC,KAAK,IAAI,EAAE;QAClB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAMM,KAAK,UAAU,sBAAsB,CAC1C,IAA4B;IAE5B,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAC;IAE1C,OAAO,IAAI,KAAK,CACd,EAAE,EACF;QACE,GAAG,CAAC,OAAO,EAAE,IAAI;YACf,IAAI,IAAI,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC5B,OAAO,KAAK,IAAI,EAAE;oBAChB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;gBACzB,CAAC,CAAC;YACJ,CAAC;YACD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtB,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;gBACvC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;KACF,CACY,CAAC;AAClB,CAAC","sourcesContent":["import { afterAll } from 'bun:test';\nimport type { Kysely } from 'kysely';\nimport { type UseLocalKyselyOptions, useLocalKysely } from '../local';\nimport type { DB } from '../v1.generated';\n\n/**\n * @deprecated Use `useLocalKyselyResource` instead.\n */\nexport async function useTestKysely(\n cleanupStrategy: 'afterAll',\n args?: UseLocalKyselyOptions\n) {\n const kysely = await useLocalKysely(args);\n\n if (cleanupStrategy === 'afterAll')\n afterAll(async () => {\n await kysely.destroy();\n });\n\n return {\n kysely,\n };\n}\n\nexport async function useTestAutoCleanupKysely(args?: UseLocalKyselyOptions) {\n const kysely = await useLocalKysely(args);\n\n afterAll(async () => {\n await kysely.destroy();\n });\n\n return kysely;\n}\n\ntype ReturnType = Kysely<DB> & {\n [Symbol.dispose]: () => Promise<void>;\n};\n\nexport async function useLocalKyselyResource(\n args?: UseLocalKyselyOptions\n): Promise<ReturnType> {\n const kysely = await useLocalKysely(args);\n\n return new Proxy(\n {},\n {\n get(_target, prop) {\n if (prop === Symbol.dispose) {\n return async () => {\n await kysely.destroy();\n };\n }\n if (prop === 'kysely') {\n return kysely;\n }\n if (typeof kysely[prop] === 'function') {\n return kysely[prop].bind(kysely);\n }\n return kysely[prop];\n },\n }\n ) as ReturnType;\n}\n"]}
@@ -1 +1 @@
1
- {"root":["../../src/index.ts","../../src/test.ts","../../src/v1.generated.ts","../../src/local/generate.ts","../../src/local/index.ts"],"version":"5.9.3"}
1
+ {"root":["../../src/index.ts","../../src/v1.generated.ts","../../src/local/generate.ts","../../src/local/index.ts","../../src/pganalyze-comment-plugin/comment-transformer.ts","../../src/pganalyze-comment-plugin/index.ts","../../src/test/index.ts"],"version":"5.9.3"}
@@ -1214,6 +1214,7 @@ export interface PublicReservation {
1214
1214
  lineMap: Json | null;
1215
1215
  listingConnectionId: string | null;
1216
1216
  listingId: string | null;
1217
+ matchPaymentCustomerRef: string | null;
1217
1218
  metadata: Json | null;
1218
1219
  nights: number | null;
1219
1220
  otaReservationId: string | null;