@vrplatform/kysely 1.3.21 → 1.3.30
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/camel-case/index.js.map +1 -1
- package/build/main/error.js.map +1 -1
- package/build/main/index.d.ts +3 -3
- package/build/main/index.js +21 -2
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +1 -1
- package/build/main/isomorphic.js +2 -2
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local/digest.js.map +1 -1
- package/build/main/local/generate.js +3 -3
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.d.ts +2 -1
- package/build/main/local/index.js +53 -1
- package/build/main/local/index.js.map +1 -1
- package/build/main/pganalyze-comment-plugin/comment-transformer.js +1 -0
- package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/main/pganalyze-comment-plugin/index.js +3 -16
- package/build/main/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/main/plugins.js.map +1 -1
- package/build/main/query/listing/index.d.ts +1 -1
- package/build/main/query/listing/index.js +1 -1
- package/build/main/query/listing/index.js.map +1 -1
- package/build/main/query/listing/status.d.ts +26 -0
- package/build/main/query/listing/status.js +48 -0
- package/build/main/query/listing/status.js.map +1 -0
- package/build/main/test/index.d.ts +3 -0
- package/build/main/test/index.js +9 -0
- package/build/main/test/index.js.map +1 -1
- package/build/main/test.d.ts +4 -0
- package/build/main/test.js +19 -0
- package/build/main/test.js.map +1 -0
- package/build/main/tsconfig.main.tsbuildinfo +1 -1
- package/build/main/v1.generated.d.ts +33 -3
- package/build/main/v1.generated.js.map +1 -1
- package/build/module/camel-case/index.js.map +1 -1
- package/build/module/error.js.map +1 -1
- package/build/module/index.d.ts +3 -3
- package/build/module/index.js +21 -2
- package/build/module/index.js.map +1 -1
- package/build/module/isomorphic.d.ts +1 -1
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local/digest.js.map +1 -1
- package/build/module/local/generate.js +3 -3
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.d.ts +2 -1
- package/build/module/local/index.js +20 -1
- package/build/module/local/index.js.map +1 -1
- package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/module/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/module/plugins.js.map +1 -1
- package/build/module/query/listing/index.d.ts +1 -1
- package/build/module/query/listing/index.js +1 -1
- package/build/module/query/listing/index.js.map +1 -1
- package/build/module/query/listing/status.d.ts +26 -0
- package/build/module/query/listing/status.js +41 -0
- package/build/module/query/listing/status.js.map +1 -0
- package/build/module/test/index.d.ts +3 -0
- package/build/module/test/index.js +9 -0
- package/build/module/test/index.js.map +1 -1
- package/build/module/test.d.ts +4 -0
- package/build/module/test.js +16 -0
- package/build/module/test.js.map +1 -0
- package/build/module/tsconfig.esm.tsbuildinfo +1 -1
- package/build/module/v1.generated.d.ts +33 -3
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +14 -30
- package/build/main/query/listing/is-active-or-at-least-one-ownership-period-active.d.ts +0 -6
- package/build/main/query/listing/is-active-or-at-least-one-ownership-period-active.js +0 -24
- package/build/main/query/listing/is-active-or-at-least-one-ownership-period-active.js.map +0 -1
- package/build/module/query/listing/is-active-or-at-least-one-ownership-period-active.d.ts +0 -6
- package/build/module/query/listing/is-active-or-at-least-one-ownership-period-active.js +0 -21
- package/build/module/query/listing/is-active-or-at-least-one-ownership-period-active.js.map +0 -1
package/build/.data.tar
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":";;;AAAA,mCAMgB;AAChB,oCAAuC;AAEvC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":";;;AAAA,mCAMgB;AAChB,oCAAuC;AAEvC,sBAA8B,SAAQ,wBAAe;IACnD,kDAAkD;IACl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E;QACpB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG;YAAE,OAAO,GAAG,CAAC;QAEhD,MAAM,MAAM,GAAwB,EAAE,CAAC;QACvC,8GAA8G;QAC9G,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACrB,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,iEAAiE;YACjE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACzB,CAAC;QACD,OAAO,MAAM,CAAC;IAAA,CACf;CACF","sourcesContent":["import {\n type AliasNode,\n CamelCasePlugin,\n type IdentifierNode,\n type RawNode,\n type SelectQueryNode,\n} from 'kysely';\nimport { KyselyError } from '../error';\n\nexport class CustomCasePlugin extends CamelCasePlugin {\n // _excludedColumns: Record<string, boolean> = {};\n constructor() {\n super({\n maintainNestedObjectKeys: true,\n });\n }\n\n transformResult(args) {\n return super.transformResult(args);\n }\n\n transformQuery(args) {\n this.verifyAlias(args.node);\n return super.transformQuery(args);\n }\n\n verifyAlias(node: SelectQueryNode) {\n if (!node?.selections) return;\n\n for (const x of node.selections ?? []) {\n const selection = x.selection as AliasNode;\n if (!selection.alias) continue;\n const alias = selection.alias as IdentifierNode;\n\n // alias can be a raw node (jsonArrayFrom)\n if (selection.node.kind === 'RawNode') {\n const rawNode = selection.node as RawNode;\n for (const x of rawNode.parameters ?? []) {\n if (x.kind === 'SelectQueryNode') {\n const selectQueryNode = x as SelectQueryNode;\n this.verifyAlias(selectQueryNode);\n }\n }\n }\n\n if (!alias.name.includes('_')) continue;\n\n throw new KyselyError(`Alias ${alias.name} contains underscore`);\n }\n }\n\n protected mapRow(row) {\n if (typeof row !== 'object' || !row) return row;\n\n const newRow: Record<string, any> = {};\n // we camel case on first layer, and nested ONLY if in an array (jsonArrayFrom), NOT if it's an object (jsonb)\n for (const key of Object.keys(row)) {\n let value = row[key];\n const newKey = super.camelCase(key);\n // array CAN be non object, so we need to check the first element\n if (Array.isArray(value)) {\n value = value.map((it) => this.mapRow(it));\n }\n newRow[newKey] = value;\n }\n return newRow;\n }\n}\n"]}
|
package/build/main/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":";;;AAAA,iBAAyB,SAAQ,KAAK;IACpC,YAAY,OAAe,EAAE;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAAA,CAC3B;CACF","sourcesContent":["export class KyselyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'KyselyError';\n }\n}\n"]}
|
package/build/main/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely as K, LogConfig } from 'kysely';
|
|
2
|
-
import
|
|
2
|
+
import { type Sql } from 'postgres';
|
|
3
3
|
export type { LogEvent } from 'kysely';
|
|
4
4
|
export * from './error';
|
|
5
5
|
export * from './isomorphic';
|
|
@@ -19,12 +19,12 @@ export type Postgres = Sql;
|
|
|
19
19
|
* @deprecated This method is deprecated in favor of the useAsyncKysely method.
|
|
20
20
|
*/
|
|
21
21
|
export declare function useKysely(postgres: Sql, options?: KyselyOpts): K<DB>;
|
|
22
|
-
export declare function useAsyncPostgres(connectionString: string, opt?: PgOpt): Promise<
|
|
22
|
+
export declare function useAsyncPostgres(connectionString: string, opt?: PgOpt): Promise<Sql<{}>>;
|
|
23
23
|
export declare function useAsyncKysely(connectionString: string, opt?: PgOpt & KyselyOpts): Promise<K<DB>>;
|
|
24
24
|
/**
|
|
25
25
|
* @deprecated This method is deprecated in favor of the useAsyncKysely method.
|
|
26
26
|
*/
|
|
27
|
-
export declare function usePostgres(connectionString?: string, opt?: Pick<PgOpt, 'forceDisableSSL'>):
|
|
27
|
+
export declare function usePostgres(connectionString?: string, opt?: Pick<PgOpt, 'forceDisableSSL'>): Sql<{}>;
|
|
28
28
|
export declare function forceCloseAllPostgres(timeoutMs?: number): Promise<void>;
|
|
29
29
|
export declare class DatabaseError extends Error {
|
|
30
30
|
constructor(message: string, cause: any);
|
package/build/main/index.js
CHANGED
|
@@ -23,12 +23,16 @@ exports.useAsyncPostgres = useAsyncPostgres;
|
|
|
23
23
|
exports.useAsyncKysely = useAsyncKysely;
|
|
24
24
|
exports.usePostgres = usePostgres;
|
|
25
25
|
exports.forceCloseAllPostgres = forceCloseAllPostgres;
|
|
26
|
+
const exponential_backoff_1 = require("exponential-backoff");
|
|
26
27
|
const kysely_postgres_js_1 = require("kysely-postgres-js");
|
|
27
28
|
const postgres_1 = __importDefault(require("postgres"));
|
|
29
|
+
const error_1 = require("./error");
|
|
28
30
|
const plugins_1 = require("./plugins");
|
|
29
31
|
__exportStar(require("./error"), exports);
|
|
30
32
|
__exportStar(require("./isomorphic"), exports);
|
|
31
33
|
__exportStar(require("./query"), exports);
|
|
34
|
+
const utils_1 = require("@vrplatform/utils");
|
|
35
|
+
const retryableMessages = ['CONNECTION_CLOSED'];
|
|
32
36
|
/**
|
|
33
37
|
* @deprecated This method is deprecated in favor of the useAsyncKysely method.
|
|
34
38
|
*/
|
|
@@ -36,6 +40,21 @@ function useKysely(postgres, options) {
|
|
|
36
40
|
console.debug('Creating Kysely instance');
|
|
37
41
|
const kysely = (0, plugins_1.getKysely)(new kysely_postgres_js_1.PostgresJSDialect({
|
|
38
42
|
postgres,
|
|
43
|
+
onReserveConnection: async (connection) => {
|
|
44
|
+
const executeQuery = connection.executeQuery.bind(connection);
|
|
45
|
+
connection.executeQuery = (arg) => (0, exponential_backoff_1.backOff)(async () => await executeQuery(arg), {
|
|
46
|
+
numOfAttempts: 3,
|
|
47
|
+
startingDelay: (0, utils_1.parseDuration)('1s'),
|
|
48
|
+
maxDelay: (0, utils_1.parseDuration)('5s'),
|
|
49
|
+
retry: (error) => {
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
if (retryableMessages.some((m) => message?.includes(m))) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
},
|
|
39
58
|
}), {
|
|
40
59
|
repositoryName: options?.repositoryName,
|
|
41
60
|
log: options?.log,
|
|
@@ -92,7 +111,7 @@ async function useAsyncPostgres(connectionString, opt) {
|
|
|
92
111
|
await new Promise((res) => setTimeout(res, delayMs));
|
|
93
112
|
}
|
|
94
113
|
}
|
|
95
|
-
throw new
|
|
114
|
+
throw new error_1.KyselyError('Unable to connect to Postgres');
|
|
96
115
|
}
|
|
97
116
|
async function useAsyncKysely(connectionString, opt) {
|
|
98
117
|
const sql = await useAsyncPostgres(connectionString, opt);
|
|
@@ -103,7 +122,7 @@ async function useAsyncKysely(connectionString, opt) {
|
|
|
103
122
|
*/
|
|
104
123
|
function usePostgres(connectionString, opt) {
|
|
105
124
|
if (!connectionString)
|
|
106
|
-
throw new
|
|
125
|
+
throw new error_1.KyselyError('No connection string');
|
|
107
126
|
const ssl = opt?.forceDisableSSL !== true;
|
|
108
127
|
const url = new URL(connectionString);
|
|
109
128
|
console.debug(`Creating sync Postgres connection with ssl=${ssl} and port=${url.port}`);
|
package/build/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","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KAAU,EAAE;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAAA,CACpB;CACF","sourcesContent":["import { backOff } from 'exponential-backoff';\nimport type { Kysely as K, LogConfig } from 'kysely';\nimport { PostgresJSDialect } from 'kysely-postgres-js';\nimport postgres, { type Sql } from 'postgres';\nimport { KyselyError } from './error';\nimport { getKysely } from './plugins';\n\nexport type { LogEvent } from 'kysely';\nexport * from './error';\nexport * from './isomorphic';\nexport * from './query';\n\nimport { parseDuration } from '@vrplatform/utils';\nimport type { DB } from './v1.generated';\n\ntype KyselyOpts = {\n repositoryName?: string;\n log?: true | LogConfig;\n};\n\ntype PgOpt = {\n forceDisableSSL?: boolean;\n retries?: false | number;\n};\n\nconst retryableMessages = ['CONNECTION_CLOSED'];\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 kysely = getKysely(\n new PostgresJSDialect({\n postgres,\n onReserveConnection: async (connection) => {\n const executeQuery = connection.executeQuery.bind(connection);\n connection.executeQuery = (arg) =>\n backOff(async () => await executeQuery(arg), {\n numOfAttempts: 3,\n startingDelay: parseDuration('1s'),\n maxDelay: parseDuration('5s'),\n retry: (error) => {\n const message =\n error instanceof Error ? error.message : String(error);\n if (retryableMessages.some((m) => message?.includes(m))) {\n return true;\n }\n return false;\n },\n });\n },\n }),\n {\n repositoryName: options?.repositoryName,\n log: 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 KyselyError('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 KyselyError('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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely as K, Transaction as T } from 'kysely';
|
|
2
|
-
export type { ColumnType, Expression, ExpressionBuilder, ExpressionOrFactory, Generated, Insertable, JSONColumnType, Nullable, OperandExpression, Selectable, SelectQueryBuilder, SqlBool, Updateable, } from 'kysely';
|
|
2
|
+
export type { ColumnType, Expression, ExpressionBuilder, ExpressionOrFactory, Generated, Insertable, JSONColumnType, KyselyPlugin, Nullable, OperandExpression, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, RootOperationNode, Selectable, SelectQueryBuilder, SqlBool, UnknownRow, Updateable, } from 'kysely';
|
|
3
3
|
export { jsonArrayFrom } from 'kysely/helpers/postgres';
|
|
4
4
|
export * from './v1.generated';
|
|
5
5
|
import type { DB } from './v1.generated';
|
package/build/main/isomorphic.js
CHANGED
|
@@ -15,10 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.DatabaseError = exports.sql = exports.jsonArrayFrom = void 0;
|
|
18
|
-
|
|
18
|
+
const postgres_1 = require("kysely/helpers/postgres");
|
|
19
19
|
Object.defineProperty(exports, "jsonArrayFrom", { enumerable: true, get: function () { return postgres_1.jsonArrayFrom; } });
|
|
20
20
|
__exportStar(require("./v1.generated"), exports);
|
|
21
|
-
|
|
21
|
+
const kysely_1 = require("kysely");
|
|
22
22
|
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return kysely_1.sql; } });
|
|
23
23
|
class DatabaseError extends Error {
|
|
24
24
|
constructor(message, cause) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isomorphic.js","sourceRoot":"src/","sources":["isomorphic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"isomorphic.js","sourceRoot":"src/","sources":["isomorphic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAuBA,sDAAwD;AAA/C,yGAAA,aAAa,OAAA;AACtB,iDAA+B;AAK/B,mCAA6B;AAApB,6FAAA,GAAG,OAAA;AAIZ,mBAA2B,SAAQ,KAAK;IACtC,YAAY,OAAe,EAAE,KAAU,EAAE;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAAA,CACpB;CACF","sourcesContent":["import type { Kysely as K, Transaction as T } from 'kysely';\n\nexport type {\n ColumnType,\n Expression,\n ExpressionBuilder,\n ExpressionOrFactory,\n Generated,\n Insertable,\n JSONColumnType,\n KyselyPlugin,\n Nullable,\n OperandExpression,\n PluginTransformQueryArgs,\n PluginTransformResultArgs,\n QueryResult,\n RootOperationNode,\n Selectable,\n SelectQueryBuilder,\n SqlBool,\n UnknownRow,\n Updateable,\n} from 'kysely';\nexport { jsonArrayFrom } from 'kysely/helpers/postgres';\nexport * from './v1.generated';\n\nimport type { DB } from './v1.generated';\n\nexport type Transaction = T<DB>;\nexport { sql } from 'kysely';\n\nexport type Kysely = K<DB>;\n\nexport class DatabaseError extends Error {\n constructor(message: string, cause: any) {\n super(message);\n this.cause = cause;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest.js","sourceRoot":"src/","sources":["local/digest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"digest.js","sourceRoot":"src/","sources":["local/digest.ts"],"names":[],"mappings":";;;;AAAA,8CAAiD;AAE1C,KAAK,+BAA+B,MAAc,EAAE;IACzD,IAAI,CAAC;QACH,MAAM,IAAA,gBAAG,EAAA,6BAA6B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAA,gBAAG,EAAA;;;;;;;;;KASR,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;AAAA,CACF;AAEM,KAAK,uCAAuC,MAAc,EAAE;IACjE,IAAI,CAAC;QACH,MAAM,IAAA,gBAAG,EAAA,4BAA4B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAA,gBAAG,EAAA;;;;;;;;;;;;;;;;;;KAkBR,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;AAAA,CACF","sourcesContent":["import { type Kysely, sql } from '../isomorphic';\n\nexport async function ensureDigestFunction(kysely: Kysely) {\n try {\n await sql`select digest('', 'sha256')`.execute(kysely);\n } catch {\n await sql`\n create or replace function digest(input text, algo text)\n returns bytea\n language sql\n immutable\n strict\n as $$\n select '\\\\x0000000000000000000000000000000000000000000000000000000000000000'::bytea;\n $$;\n `.execute(kysely);\n }\n}\n\nexport async function ensureGenRandomBytesFunction(kysely: Kysely) {\n try {\n await sql`select gen_random_bytes(1)`.execute(kysely);\n } catch {\n await sql`\n create or replace function gen_random_bytes(p_len integer)\n returns bytea\n language sql\n stable\n strict\n as $$\n select substring(\n decode(\n repeat(\n md5(random()::text || now()::text),\n ((p_len + 15) / 16)\n ),\n 'hex'\n )\n from 1 for p_len\n );\n $$;\n `.execute(kysely);\n }\n}\n"]}
|
|
@@ -44,7 +44,7 @@ const node_path_1 = require("node:path");
|
|
|
44
44
|
const pglite_1 = require("@electric-sql/pglite");
|
|
45
45
|
const kysely_1 = require("kysely");
|
|
46
46
|
const kysely_codegen_1 = __importDefault(require("kysely-codegen"));
|
|
47
|
-
const
|
|
47
|
+
const kysely_pglite_dialect_1 = require("kysely-pglite-dialect");
|
|
48
48
|
const plugins_1 = require("../plugins");
|
|
49
49
|
async function migrate(root, client) {
|
|
50
50
|
console.log('migrating pglite ....');
|
|
@@ -100,7 +100,7 @@ async function generateDump(root, dumpPath) {
|
|
|
100
100
|
await Bun.write('../logs/migrate-initial-dump.json', JSON.stringify(err, null, 2));
|
|
101
101
|
process.exit(1);
|
|
102
102
|
});
|
|
103
|
-
const
|
|
103
|
+
const dialect = new kysely_pglite_dialect_1.PGliteDialect(main);
|
|
104
104
|
const kysely = (0, plugins_1.getKysely)(dialect, {
|
|
105
105
|
repositoryName: 'localTesting',
|
|
106
106
|
log: undefined,
|
|
@@ -140,7 +140,7 @@ async function createLocalKysely(root, dumpPath) {
|
|
|
140
140
|
const pglite = new pglite_1.PGlite({ loadDataDir: dump });
|
|
141
141
|
// warm up
|
|
142
142
|
await pglite.sql `SELECT 1`;
|
|
143
|
-
const
|
|
143
|
+
const dialect = new kysely_pglite_dialect_1.PGliteDialect(pglite);
|
|
144
144
|
const kysely = (0, plugins_1.getKysely)(dialect, {
|
|
145
145
|
repositoryName: 'localTesting',
|
|
146
146
|
log: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"src/","sources":["local/generate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"src/","sources":["local/generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyC;AACzC,+CAA0C;AAC1C,MAAY,IAAI,sCAAkB;AAClC,yCAAiC;AACjC,iDAA8C;AAC9C,mCAAsE;AACtE,oEAAqC;AACrC,iEAAsD;AACtD,wCAAuC;AAGvC,KAAK,UAAU,OAAO,CAAC,IAAY,EAAE,MAAc,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC3C,IAAI,KAAK,EAAE,MAAM,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC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gCAAgC;IAEhC,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEhD,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,OAAO,GAAG,IAAI,qCAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAA,mBAAS,EAAC,OAAO,EAAE;QAChC,cAAc,EAAE,cAAc;QAC9B,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC;QAC3B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,yCAAyC;QACzC,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,cAAc;QACd,0EAA0E;QAC1E,IAAI;IAHwC,CAI7C,CAAC;IAEF,iFAAiF;IAEjF,OAAO,MAAM,CAAC;AAAA,CACf","sourcesContent":["import { promises as fs } from 'node:fs';\nimport { exists } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport { FileMigrationProvider, type Kysely, Migrator } from 'kysely';\nimport codegen from 'kysely-codegen';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport { getKysely } from '../plugins';\nimport type { DB } from '../v1.generated';\n\nasync function migrate(root: string, client: PGlite) {\n console.log('migrating pglite ....');\n const glob = new Bun.Glob('initial/*.sql');\n for await (const migration of glob.scan(root)) {\n const raw = await Bun.file(join(root, migration)).text();\n // `pg_dump` (v17+) prepends `\\restrict`/`\\unrestrict` psql meta commands\n // which PostgreSQL-compatible parsers (like PGlite) cannot execute.\n const sanitized = raw.replace(/^\\s*\\\\(?:un)?restrict.*$/gim, '');\n await client.exec(sanitized);\n }\n}\n\nasync function migrateKysely(root: string, kysely: Kysely<DB>) {\n console.log('init migrating kysely ....');\n const migrator = new Migrator({\n db: kysely,\n migrationTableSchema: 'core',\n migrationTableName: 'kysely_migration',\n migrationLockTableName: 'kysely_migration_lock',\n provider: new FileMigrationProvider({\n fs,\n path,\n // This needs to be an absolute path.\n migrationFolder: path.join(root, 'migrations'),\n }),\n });\n\n console.log('migrating kysely ....');\n const { error, results } = await migrator.migrateToLatest().catch(() => {\n console.error('failed to migrate');\n process.exit(1);\n });\n\n for (const it of results ?? []) {\n if (it.status === 'Success') {\n console.log(`migration \"${it.migrationName}\" was executed successfully`);\n } else if (it.status === 'Error') {\n console.error(`failed to execute migration \"${it.migrationName}\"`);\n }\n }\n\n if (error) {\n console.error('failed to migrate');\n console.error(error);\n process.exit(1);\n }\n}\n\nasync function generateDump(root: string, dumpPath: string) {\n const dataExists = await exists(dumpPath).catch(() => false);\n if (!dataExists) {\n console.log('Creating initial dump');\n const main = new PGlite();\n await migrate(root, main).catch(async (err) => {\n console.error('failed to migrate initial dump');\n await Bun.write(\n '../logs/migrate-initial-dump.json',\n JSON.stringify(err as any, null, 2)\n );\n process.exit(1);\n });\n const dialect = new PGliteDialect(main);\n const kysely = getKysely(dialect, {\n repositoryName: 'localTesting',\n log: undefined,\n });\n await migrateKysely(root, kysely).catch(() => {\n console.error('failed to migrate kysely');\n process.exit(1);\n });\n await codegen\n .generate({\n db: kysely,\n outFile: path.join(root, 'src/v1.generated.ts'),\n defaultSchemas: ['xxx'],\n camelCase: true,\n dialect: codegen.getDialect('postgres'),\n })\n .catch(() => {\n console.error('failed to generate kysely');\n process.exit(1);\n });\n const content = await main.dumpDataDir('none').catch(() => {\n console.error('failed to dump data');\n process.exit(1);\n });\n await Bun.write(dumpPath, content).catch(() => {\n console.error('failed to write dump');\n process.exit(1);\n });\n return content;\n }\n return Bun.file(dumpPath);\n}\n\nexport async function createLocalKysely(root: string, dumpPath: string) {\n let isDestroyed = false;\n //const now = performance.now();\n\n const dump = await generateDump(root, dumpPath);\n\n const pglite = new PGlite({ loadDataDir: dump });\n // warm up\n await pglite.sql`SELECT 1`;\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely(dialect, {\n repositoryName: 'localTesting',\n log: undefined,\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,8 +1,9 @@
|
|
|
1
1
|
import type { LogConfig } from 'kysely';
|
|
2
|
+
import { type Kysely } from 'kysely';
|
|
2
3
|
export declare const root: string;
|
|
3
4
|
export declare const dumpPath: string;
|
|
4
5
|
export type UseLocalKyselyOptions = {
|
|
5
6
|
repositoryName?: string;
|
|
6
7
|
log?: true | LogConfig;
|
|
7
8
|
};
|
|
8
|
-
export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<
|
|
9
|
+
export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<Kysely<import("..").DB>>;
|
|
@@ -1,14 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.dumpPath = exports.root = void 0;
|
|
4
37
|
exports.useLocalKysely = useLocalKysely;
|
|
38
|
+
const node_fs_1 = require("node:fs");
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
5
40
|
const node_path_1 = require("node:path");
|
|
6
41
|
const pglite_1 = require("@electric-sql/pglite");
|
|
42
|
+
const kysely_1 = require("kysely");
|
|
7
43
|
const kysely_pglite_dialect_1 = require("kysely-pglite-dialect");
|
|
8
44
|
const plugins_1 = require("../plugins");
|
|
9
45
|
const digest_1 = require("./digest");
|
|
10
46
|
exports.root = (0, node_path_1.join)(__dirname, '../..');
|
|
11
47
|
exports.dumpPath = (0, node_path_1.join)(exports.root, '.data.tar');
|
|
48
|
+
async function migrateKysely(kysely) {
|
|
49
|
+
const migrator = new kysely_1.Migrator({
|
|
50
|
+
db: kysely,
|
|
51
|
+
migrationTableSchema: 'core',
|
|
52
|
+
migrationTableName: 'kysely_migration',
|
|
53
|
+
migrationLockTableName: 'kysely_migration_lock',
|
|
54
|
+
provider: new kysely_1.FileMigrationProvider({
|
|
55
|
+
fs: node_fs_1.promises,
|
|
56
|
+
path,
|
|
57
|
+
migrationFolder: path.join(exports.root, 'migrations'),
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
const { error } = await migrator.migrateToLatest();
|
|
61
|
+
if (error)
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
12
64
|
async function useLocalKysely(args = {}) {
|
|
13
65
|
let isDestroyed = false;
|
|
14
66
|
// const now = performance.now();
|
|
@@ -16,7 +68,6 @@ async function useLocalKysely(args = {}) {
|
|
|
16
68
|
const pglite = new pglite_1.PGlite({
|
|
17
69
|
loadDataDir: dump,
|
|
18
70
|
});
|
|
19
|
-
// warm up
|
|
20
71
|
const dialect = new kysely_pglite_dialect_1.PGliteDialect(pglite);
|
|
21
72
|
const kysely = (0, plugins_1.getKysely)(dialect, {
|
|
22
73
|
repositoryName: args?.repositoryName ?? 'localTesting',
|
|
@@ -24,6 +75,7 @@ async function useLocalKysely(args = {}) {
|
|
|
24
75
|
});
|
|
25
76
|
await (0, digest_1.ensureDigestFunction)(kysely);
|
|
26
77
|
await (0, digest_1.ensureGenRandomBytesFunction)(kysely);
|
|
78
|
+
await migrateKysely(kysely);
|
|
27
79
|
const originalDestroy = kysely.destroy.bind(kysely);
|
|
28
80
|
kysely.destroy = async () => {
|
|
29
81
|
if (isDestroyed)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/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AC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAA,mBAAS,EAAC,OAAO,EAAE;QAChC,cAAc,EAAE,IAAI,EAAE,cAAc,IAAI,cAAc;QACtD,GAAG,EAAE,IAAI,EAAE,GAAG;KACf,CAAC,CAAC;IACH,MAAM,IAAA,6BAAoB,EAAC,MAAM,CAAC,CAAC;IACnC,MAAM,IAAA,qCAA4B,EAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;IAE5B,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC;QAC3B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,wCAAwC;QACxC,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,cAAc;QACd,0EAA0E;QAC1E,IAAI;IAHwC,CAI7C,CAAC;IAEF,iFAAiF;IAEjF,OAAO,MAAM,CAAC;AAAA,CACf","sourcesContent":["import { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport type { LogConfig } from 'kysely';\nimport { FileMigrationProvider, type Kysely, Migrator } from 'kysely';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport { getKysely } from '../plugins';\nimport { ensureDigestFunction, ensureGenRandomBytesFunction } from './digest';\n\nexport const root = join(__dirname, '../..');\nexport const dumpPath = join(root, '.data.tar');\n\nasync function migrateKysely(kysely: Kysely<any>) {\n const migrator = new Migrator({\n db: kysely,\n migrationTableSchema: 'core',\n migrationTableName: 'kysely_migration',\n migrationLockTableName: 'kysely_migration_lock',\n provider: new FileMigrationProvider({\n fs,\n path,\n migrationFolder: path.join(root, 'migrations'),\n }),\n });\n\n const { error } = await migrator.migrateToLatest();\n if (error) throw error;\n}\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({\n loadDataDir: dump,\n });\n const dialect = new PGliteDialect(pglite);\n const kysely = getKysely(dialect, {\n repositoryName: args?.repositoryName ?? 'localTesting',\n log: args?.log,\n });\n await ensureDigestFunction(kysely);\n await ensureGenRandomBytesFunction(kysely);\n await migrateKysely(kysely);\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"]}
|
|
@@ -13,6 +13,7 @@ function createCommentNode(repositoryName) {
|
|
|
13
13
|
* similar to how modifyEnd works.
|
|
14
14
|
*/
|
|
15
15
|
class CommentTransformer extends kysely_1.OperationNodeTransformer {
|
|
16
|
+
_repositoryName;
|
|
16
17
|
constructor(_repositoryName) {
|
|
17
18
|
super();
|
|
18
19
|
this._repositoryName = _repositoryName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment-transformer.js","sourceRoot":"src/","sources":["pganalyze-comment-plugin/comment-transformer.ts"],"names":[],"mappings":";;;AAAA,mCASgB;AAEhB,SAAS,iBAAiB,CAAC,cAAsB;
|
|
1
|
+
{"version":3,"file":"comment-transformer.js","sourceRoot":"src/","sources":["pganalyze-comment-plugin/comment-transformer.ts"],"names":[],"mappings":";;;AAAA,mCASgB;AAEhB,SAAS,iBAA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,CAAC,IAAqB,EAAmB;QACtE,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;IAAA,CACH;CACF","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"]}
|
|
@@ -1,31 +1,18 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.KyselyPganalyzeCommentPlugin = void 0;
|
|
16
4
|
const comment_transformer_1 = require("./comment-transformer");
|
|
17
5
|
class KyselyPganalyzeCommentPlugin {
|
|
6
|
+
#transformer;
|
|
18
7
|
constructor(options) {
|
|
19
|
-
|
|
20
|
-
__classPrivateFieldSet(this, _KyselyPganalyzeCommentPlugin_transformer, new comment_transformer_1.CommentTransformer(options.repository), "f");
|
|
8
|
+
this.#transformer = new comment_transformer_1.CommentTransformer(options.repository);
|
|
21
9
|
}
|
|
22
10
|
transformQuery(args) {
|
|
23
|
-
return
|
|
11
|
+
return this.#transformer.transformRootNode(args.node);
|
|
24
12
|
}
|
|
25
13
|
async transformResult(args) {
|
|
26
14
|
return args.result;
|
|
27
15
|
}
|
|
28
16
|
}
|
|
29
17
|
exports.KyselyPganalyzeCommentPlugin = KyselyPganalyzeCommentPlugin;
|
|
30
|
-
_KyselyPganalyzeCommentPlugin_transformer = new WeakMap();
|
|
31
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["pganalyze-comment-plugin/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["pganalyze-comment-plugin/index.ts"],"names":[],"mappings":";;;AAQA,+DAA2D;AAE3D;IACW,YAAY,CAAqB;IAE1C,YAAY,OAA+B,EAAE;QAC3C,IAAI,CAAC,YAAY,GAAG,IAAI,wCAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAAA,CAChE;IAED,cAAc,CAAC,IAA8B,EAAqB;QAChE,OAAO,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAAA,CACvD;IAED,KAAK,CAAC,eAAe,CACnB,IAA+B,EACG;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC;IAAA,CACpB;CACF","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"src/","sources":["plugins.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"src/","sources":["plugins.ts"],"names":[],"mappings":";;;AAAA,mCAKgB;AAChB,6CAAgD;AAChD,yEAA0E;AAG1E,mBACE,OAAgB,EAChB,OAA4D,EAC5D;IACA,MAAM,OAAO,GAAmB,CAAC,IAAI,6BAAgB,EAAE,CAAC,CAAC;IAEzD,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,CAAK;QACvB,OAAO;QACP,OAAO;QACP,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG;KAC/D,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAAA,CACf","sourcesContent":["import {\n type Dialect,\n Kysely as K,\n type KyselyPlugin,\n type LogConfig,\n} from 'kysely';\nimport { CustomCasePlugin } from './camel-case';\nimport { KyselyPganalyzeCommentPlugin } from './pganalyze-comment-plugin';\nimport type { DB } from './v1.generated';\n\nexport function getKysely(\n dialect: Dialect,\n options: { repositoryName?: string; log?: true | LogConfig }\n) {\n const plugins: KyselyPlugin[] = [new CustomCasePlugin()];\n\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,\n plugins,\n log: options?.log === true ? ['query', 'error'] : options?.log,\n });\n return kysely;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './status';
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./status"), exports);
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/listing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/listing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB","sourcesContent":["export * from './status';\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DB, ExpressionBuilder, PublicListing } from '../../isomorphic';
|
|
2
|
+
export declare function whereListingIsInactive(eb: ExpressionBuilder<DB & {
|
|
3
|
+
l: PublicListing;
|
|
4
|
+
}, 'l'>, today?: string): import("kysely").ExpressionWrapper<DB & {
|
|
5
|
+
l: PublicListing;
|
|
6
|
+
}, "l", import("kysely").SqlBool>;
|
|
7
|
+
export declare function whereListingIsActive(eb: ExpressionBuilder<DB & {
|
|
8
|
+
l: PublicListing;
|
|
9
|
+
}, 'l'>, today?: string): import("kysely").ExpressionWrapper<DB & {
|
|
10
|
+
l: PublicListing;
|
|
11
|
+
}, "l", 0 | 1 | boolean>;
|
|
12
|
+
export declare function selectListingIsInactive(eb: ExpressionBuilder<DB & {
|
|
13
|
+
l: PublicListing;
|
|
14
|
+
}, 'l'>, today?: string): import("kysely").ExpressionWrapper<DB & {
|
|
15
|
+
l: PublicListing;
|
|
16
|
+
}, "l", import("kysely").SqlBool>;
|
|
17
|
+
export declare function selectListingIsActive(eb: ExpressionBuilder<DB & {
|
|
18
|
+
l: PublicListing;
|
|
19
|
+
}, 'l'>, today?: string): import("kysely").ExpressionWrapper<DB & {
|
|
20
|
+
l: PublicListing;
|
|
21
|
+
}, "l", 0 | 1 | boolean>;
|
|
22
|
+
export declare function selectListingStatus(eb: ExpressionBuilder<DB & {
|
|
23
|
+
l: PublicListing;
|
|
24
|
+
}, 'l'>, today?: string): import("kysely").ExpressionWrapper<DB & {
|
|
25
|
+
l: PublicListing;
|
|
26
|
+
}, "l", string>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whereListingIsInactive = whereListingIsInactive;
|
|
4
|
+
exports.whereListingIsActive = whereListingIsActive;
|
|
5
|
+
exports.selectListingIsInactive = selectListingIsInactive;
|
|
6
|
+
exports.selectListingIsActive = selectListingIsActive;
|
|
7
|
+
exports.selectListingStatus = selectListingStatus;
|
|
8
|
+
const utils_1 = require("@vrplatform/utils");
|
|
9
|
+
function hasInactiveOwnership(eb, today) {
|
|
10
|
+
return eb.exists(eb
|
|
11
|
+
.selectFrom('public.listingOwnershipPeriod as lop')
|
|
12
|
+
.select('lop.id')
|
|
13
|
+
.whereRef('lop.listingId', '=', 'l.id')
|
|
14
|
+
.whereRef('lop.tenantId', '=', 'l.tenantId')
|
|
15
|
+
.where('lop.setListingInactive', '=', true)
|
|
16
|
+
.where((eb2) => eb2.or([
|
|
17
|
+
eb2.and([
|
|
18
|
+
eb2('lop.startAt', '<=', today),
|
|
19
|
+
eb2('lop.endAt', '>=', today),
|
|
20
|
+
]),
|
|
21
|
+
eb2.and([
|
|
22
|
+
eb2('lop.startAt', '<=', today),
|
|
23
|
+
eb2('lop.endAt', 'is', null),
|
|
24
|
+
]),
|
|
25
|
+
]))
|
|
26
|
+
.limit(1));
|
|
27
|
+
}
|
|
28
|
+
function whereListingIsInactive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
29
|
+
return hasInactiveOwnership(eb, today);
|
|
30
|
+
}
|
|
31
|
+
function whereListingIsActive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
32
|
+
return eb.not(whereListingIsInactive(eb, today));
|
|
33
|
+
}
|
|
34
|
+
function selectListingIsInactive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
35
|
+
return whereListingIsInactive(eb, today);
|
|
36
|
+
}
|
|
37
|
+
function selectListingIsActive(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
38
|
+
return whereListingIsActive(eb, today);
|
|
39
|
+
}
|
|
40
|
+
function selectListingStatus(eb, today = (0, utils_1.day)().yyyymmdd()) {
|
|
41
|
+
return eb
|
|
42
|
+
.case()
|
|
43
|
+
.when(whereListingIsInactive(eb, today))
|
|
44
|
+
.then('inactive')
|
|
45
|
+
.else('active')
|
|
46
|
+
.end();
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sour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ACA,OAAO,sBAAsB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAAA,CAC1C;AAED,+BACE,EAAqD,EACrD,KAAK,GAAW,IAAA,WAAG,GAAE,CAAC,QAAQ,EAAE,EAChC;IACA,OAAO,oBAAoB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAAA,CACxC;AAED,6BACE,EAAqD,EACrD,KAAK,GAAW,IAAA,WAAG,GAAE,CAAC,QAAQ,EAAE,EAChC;IACA,OAAO,EAAE;SACN,IAAI,EAAE;SACN,IAAI,CAAC,sBAAsB,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;SACvC,IAAI,CAAC,UAAU,CAAC;SAChB,IAAI,CAAC,QAAQ,CAAC;SACd,GAAG,EAAE,CAAC;AAAA,CACV","sourcesContent":["import { day } from '@vrplatform/utils';\nimport type { DB, ExpressionBuilder, PublicListing } from '../../isomorphic';\n\nfunction hasInactiveOwnership(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string\n) {\n return eb.exists(\n eb\n .selectFrom('public.listingOwnershipPeriod as lop')\n .select('lop.id')\n .whereRef('lop.listingId', '=', 'l.id')\n .whereRef('lop.tenantId', '=', 'l.tenantId')\n .where('lop.setListingInactive', '=', true)\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('lop.startAt', '<=', today),\n eb2('lop.endAt', '>=', today),\n ]),\n eb2.and([\n eb2('lop.startAt', '<=', today),\n eb2('lop.endAt', 'is', null),\n ]),\n ])\n )\n .limit(1)\n );\n}\n\nexport function whereListingIsInactive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return hasInactiveOwnership(eb, today);\n}\n\nexport function whereListingIsActive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return eb.not(whereListingIsInactive(eb, today));\n}\n\nexport function selectListingIsInactive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return whereListingIsInactive(eb, today);\n}\n\nexport function selectListingIsActive(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return whereListingIsActive(eb, today);\n}\n\nexport function selectListingStatus(\n eb: ExpressionBuilder<DB & { l: PublicListing }, 'l'>,\n today: string = day().yyyymmdd()\n) {\n return eb\n .case()\n .when(whereListingIsInactive(eb, today))\n .then('inactive')\n .else('active')\n .end();\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Kysely } from 'kysely';
|
|
2
2
|
import { type UseLocalKyselyOptions } from '../local';
|
|
3
3
|
import type { DB } from '../v1.generated';
|
|
4
|
+
declare global {
|
|
5
|
+
var __vrplatform_testSharedKysely: Promise<Kysely<DB>> | Kysely<DB> | undefined;
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
8
|
* @deprecated Use `useLocalKyselyResource` instead.
|
|
6
9
|
*/
|