@vrplatform/kysely 1.3.15 → 1.3.20
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.d.ts +8 -0
- package/build/main/camel-case/index.js +61 -0
- package/build/main/camel-case/index.js.map +1 -0
- package/build/main/error.d.ts +3 -0
- package/build/main/error.js +11 -0
- package/build/main/error.js.map +1 -0
- package/build/main/index.d.ts +4 -1
- package/build/main/index.js +8 -14
- package/build/main/index.js.map +1 -1
- package/build/main/local/digest.d.ts +1 -0
- package/build/main/local/digest.js +27 -0
- package/build/main/local/digest.js.map +1 -1
- package/build/main/local/generate.d.ts +1 -1
- package/build/main/local/generate.js +7 -6
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.d.ts +2 -3
- package/build/main/local/index.js +8 -12
- package/build/main/local/index.js.map +1 -1
- package/build/main/plugins.d.ts +6 -0
- package/build/main/plugins.js +21 -0
- package/build/main/plugins.js.map +1 -0
- package/build/main/query/index.d.ts +1 -0
- package/build/main/query/index.js +18 -0
- package/build/main/query/index.js.map +1 -0
- package/build/main/query/listing/index.d.ts +1 -0
- package/build/main/query/listing/index.js +18 -0
- package/build/main/query/listing/index.js.map +1 -0
- package/build/main/query/listing/is-active-or-at-least-one-ownership-period-active.d.ts +6 -0
- package/build/main/query/listing/is-active-or-at-least-one-ownership-period-active.js +24 -0
- package/build/main/query/listing/is-active-or-at-least-one-ownership-period-active.js.map +1 -0
- package/build/main/test/index.js +2 -1
- package/build/main/test/index.js.map +1 -1
- package/build/main/tsconfig.main.tsbuildinfo +1 -1
- package/build/main/v1.generated.d.ts +20 -1
- package/build/main/v1.generated.js.map +1 -1
- package/build/module/camel-case/index.d.ts +8 -0
- package/build/module/camel-case/index.js +57 -0
- package/build/module/camel-case/index.js.map +1 -0
- package/build/module/error.d.ts +3 -0
- package/build/module/error.js +7 -0
- package/build/module/error.js.map +1 -0
- package/build/module/index.d.ts +4 -1
- package/build/module/index.js +8 -14
- package/build/module/index.js.map +1 -1
- package/build/module/local/digest.d.ts +1 -0
- package/build/module/local/digest.js +26 -0
- package/build/module/local/digest.js.map +1 -1
- package/build/module/local/generate.d.ts +1 -1
- package/build/module/local/generate.js +8 -7
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.d.ts +2 -3
- package/build/module/local/index.js +9 -13
- package/build/module/local/index.js.map +1 -1
- package/build/module/plugins.d.ts +6 -0
- package/build/module/plugins.js +18 -0
- package/build/module/plugins.js.map +1 -0
- package/build/module/query/index.d.ts +1 -0
- package/build/module/query/index.js +2 -0
- package/build/module/query/index.js.map +1 -0
- package/build/module/query/listing/index.d.ts +1 -0
- package/build/module/query/listing/index.js +2 -0
- package/build/module/query/listing/index.js.map +1 -0
- package/build/module/query/listing/is-active-or-at-least-one-ownership-period-active.d.ts +6 -0
- package/build/module/query/listing/is-active-or-at-least-one-ownership-period-active.js +21 -0
- package/build/module/query/listing/is-active-or-at-least-one-ownership-period-active.js.map +1 -0
- package/build/module/test/index.js +2 -1
- package/build/module/test/index.js.map +1 -1
- package/build/module/tsconfig.esm.tsbuildinfo +1 -1
- package/build/module/v1.generated.d.ts +20 -1
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +7 -3
- package/src/camel-case/index.ts +68 -0
- package/src/error.ts +6 -0
- package/src/index.ts +12 -21
- package/src/local/digest.ts +26 -0
- package/src/local/generate.ts +9 -13
- package/src/local/index.ts +10 -14
- package/src/plugins.ts +30 -0
- package/src/query/index.ts +1 -0
- package/src/query/listing/index.ts +1 -0
- package/src/query/listing/is-active-or-at-least-one-ownership-period-active.ts +29 -0
- package/src/test/index.ts +2 -1
- package/src/v1.generated.ts +20 -1
- package/build/main/browser/index.d.ts +0 -17
- package/build/main/browser/index.js +0 -65
- package/build/main/browser/index.js.map +0 -1
- package/build/main/browser/worker.d.ts +0 -1
- package/build/main/browser/worker.js +0 -42
- package/build/main/browser/worker.js.map +0 -1
- package/build/main/test.d.ts +0 -4
- package/build/main/test.js +0 -19
- package/build/main/test.js.map +0 -1
- package/build/module/test.d.ts +0 -4
- package/build/module/test.js +0 -16
- package/build/module/test.js.map +0 -1
package/build/.data.tar
CHANGED
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CamelCasePlugin, type SelectQueryNode } from 'kysely';
|
|
2
|
+
export declare class CustomCasePlugin extends CamelCasePlugin {
|
|
3
|
+
constructor();
|
|
4
|
+
transformResult(args: any): Promise<import("kysely").QueryResult<import("kysely").UnknownRow>>;
|
|
5
|
+
transformQuery(args: any): import("kysely").RootOperationNode;
|
|
6
|
+
verifyAlias(node: SelectQueryNode): void;
|
|
7
|
+
protected mapRow(row: any): any;
|
|
8
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomCasePlugin = void 0;
|
|
4
|
+
const kysely_1 = require("kysely");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
class CustomCasePlugin extends kysely_1.CamelCasePlugin {
|
|
7
|
+
// _excludedColumns: Record<string, boolean> = {};
|
|
8
|
+
constructor() {
|
|
9
|
+
super({
|
|
10
|
+
maintainNestedObjectKeys: true,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
transformResult(args) {
|
|
14
|
+
return super.transformResult(args);
|
|
15
|
+
}
|
|
16
|
+
transformQuery(args) {
|
|
17
|
+
this.verifyAlias(args.node);
|
|
18
|
+
return super.transformQuery(args);
|
|
19
|
+
}
|
|
20
|
+
verifyAlias(node) {
|
|
21
|
+
if (!node?.selections)
|
|
22
|
+
return;
|
|
23
|
+
for (const x of node.selections ?? []) {
|
|
24
|
+
const selection = x.selection;
|
|
25
|
+
if (!selection.alias)
|
|
26
|
+
continue;
|
|
27
|
+
const alias = selection.alias;
|
|
28
|
+
// alias can be a raw node (jsonArrayFrom)
|
|
29
|
+
if (selection.node.kind === 'RawNode') {
|
|
30
|
+
const rawNode = selection.node;
|
|
31
|
+
for (const x of rawNode.parameters ?? []) {
|
|
32
|
+
if (x.kind === 'SelectQueryNode') {
|
|
33
|
+
const selectQueryNode = x;
|
|
34
|
+
this.verifyAlias(selectQueryNode);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!alias.name.includes('_'))
|
|
39
|
+
continue;
|
|
40
|
+
throw new error_1.KyselyError(`Alias ${alias.name} contains underscore`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
mapRow(row) {
|
|
44
|
+
if (typeof row !== 'object' || !row)
|
|
45
|
+
return row;
|
|
46
|
+
const newRow = {};
|
|
47
|
+
// we camel case on first layer, and nested ONLY if in an array (jsonArrayFrom), NOT if it's an object (jsonb)
|
|
48
|
+
for (const key of Object.keys(row)) {
|
|
49
|
+
let value = row[key];
|
|
50
|
+
const newKey = super.camelCase(key);
|
|
51
|
+
// array CAN be non object, so we need to check the first element
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
value = value.map((it) => this.mapRow(it));
|
|
54
|
+
}
|
|
55
|
+
newRow[newKey] = value;
|
|
56
|
+
}
|
|
57
|
+
return newRow;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.CustomCasePlugin = CustomCasePlugin;
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["camel-case/index.ts"],"names":[],"mappings":";;;AAAA,mCAMgB;AAChB,oCAAuC;AAEvC,MAAa,gBAAiB,SAAQ,wBAAe;IACnD,kDAAkD;IAClD;QACE,KAAK,CAAC;YACJ,wBAAwB,EAAE,IAAI;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,IAAI;QAClB,OAAO,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,cAAc,CAAC,IAAI;QACjB,IAAI,C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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;IAChB,CAAC;CACF;AA1DD,4CA0DC","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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KyselyError = void 0;
|
|
4
|
+
class KyselyError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'KyselyError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.KyselyError = KyselyError;
|
|
11
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"src/","sources":["error.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AALD,kCAKC","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,6 +1,9 @@
|
|
|
1
|
-
import { Kysely as K,
|
|
1
|
+
import type { Kysely as K, LogConfig } from 'kysely';
|
|
2
2
|
import postgres, { type Sql } from 'postgres';
|
|
3
|
+
export type { LogEvent } from 'kysely';
|
|
4
|
+
export * from './error';
|
|
3
5
|
export * from './isomorphic';
|
|
6
|
+
export * from './query';
|
|
4
7
|
import type { DB } from './v1.generated';
|
|
5
8
|
type KyselyOpts = {
|
|
6
9
|
repositoryName?: string;
|
package/build/main/index.js
CHANGED
|
@@ -23,28 +23,22 @@ exports.useAsyncPostgres = useAsyncPostgres;
|
|
|
23
23
|
exports.useAsyncKysely = useAsyncKysely;
|
|
24
24
|
exports.usePostgres = usePostgres;
|
|
25
25
|
exports.forceCloseAllPostgres = forceCloseAllPostgres;
|
|
26
|
-
const kysely_1 = require("kysely");
|
|
27
26
|
const kysely_postgres_js_1 = require("kysely-postgres-js");
|
|
28
27
|
const postgres_1 = __importDefault(require("postgres"));
|
|
28
|
+
const plugins_1 = require("./plugins");
|
|
29
|
+
__exportStar(require("./error"), exports);
|
|
29
30
|
__exportStar(require("./isomorphic"), exports);
|
|
30
|
-
|
|
31
|
+
__exportStar(require("./query"), exports);
|
|
31
32
|
/**
|
|
32
33
|
* @deprecated This method is deprecated in favor of the useAsyncKysely method.
|
|
33
34
|
*/
|
|
34
35
|
function useKysely(postgres, options) {
|
|
35
36
|
console.debug('Creating Kysely instance');
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
const kysely = new kysely_1.Kysely({
|
|
43
|
-
dialect: new kysely_postgres_js_1.PostgresJSDialect({
|
|
44
|
-
postgres,
|
|
45
|
-
}),
|
|
46
|
-
plugins,
|
|
47
|
-
log: options?.log === true ? ['query', 'error'] : options?.log,
|
|
37
|
+
const kysely = (0, plugins_1.getKysely)(new kysely_postgres_js_1.PostgresJSDialect({
|
|
38
|
+
postgres,
|
|
39
|
+
}), {
|
|
40
|
+
repositoryName: options?.repositoryName,
|
|
41
|
+
log: options?.log,
|
|
48
42
|
});
|
|
49
43
|
kysely.destroy = async () => {
|
|
50
44
|
console.debug('Closing Kysely connection');
|
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","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,8BAsBC;AAGD,4CA6CC;AAED,wCAMC;AAKD,kCAeC;AAED,sDAUC;A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S,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CACtD,CACF;QACD,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC;KACxD,CAAC,CAAC;IACH,YAAY,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,MAAa,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe,EAAE,KAAU;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AALD,sCAKC","sourcesContent":["import type { Kysely as K, LogConfig } from 'kysely';\nimport { PostgresJSDialect } from 'kysely-postgres-js';\nimport postgres, { type Sql } from 'postgres';\nimport { getKysely } from './plugins';\n\nexport type { LogEvent } from 'kysely';\nexport * from './error';\nexport * from './isomorphic';\nexport * from './query';\n\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\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 }),\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 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"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureDigestFunction = ensureDigestFunction;
|
|
4
|
+
exports.ensureGenRandomBytesFunction = ensureGenRandomBytesFunction;
|
|
4
5
|
const isomorphic_1 = require("../isomorphic");
|
|
5
6
|
async function ensureDigestFunction(kysely) {
|
|
6
7
|
try {
|
|
@@ -19,4 +20,30 @@ async function ensureDigestFunction(kysely) {
|
|
|
19
20
|
`.execute(kysely);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
async function ensureGenRandomBytesFunction(kysely) {
|
|
24
|
+
try {
|
|
25
|
+
await (0, isomorphic_1.sql) `select gen_random_bytes(1)`.execute(kysely);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
await (0, isomorphic_1.sql) `
|
|
29
|
+
create or replace function gen_random_bytes(p_len integer)
|
|
30
|
+
returns bytea
|
|
31
|
+
language sql
|
|
32
|
+
stable
|
|
33
|
+
strict
|
|
34
|
+
as $$
|
|
35
|
+
select substring(
|
|
36
|
+
decode(
|
|
37
|
+
repeat(
|
|
38
|
+
md5(random()::text || now()::text),
|
|
39
|
+
((p_len + 15) / 16)
|
|
40
|
+
),
|
|
41
|
+
'hex'
|
|
42
|
+
)
|
|
43
|
+
from 1 for p_len
|
|
44
|
+
);
|
|
45
|
+
$$;
|
|
46
|
+
`.execute(kysely);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
22
49
|
//# sourceMappingURL=digest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest.js","sourceRoot":"src/","sources":["local/digest.ts"],"names":[],"mappings":";;AAEA,oDAeC;
|
|
1
|
+
{"version":3,"file":"digest.js","sourceRoot":"src/","sources":["local/digest.ts"],"names":[],"mappings":";;AAEA,oDAeC;AAED,oEAwBC;AA3CD,8CAAiD;AAE1C,KAAK,UAAU,oBAAoB,CAAC,MAAc;IACvD,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;AACH,CAAC;AAEM,KAAK,UAAU,4BAA4B,CAAC,MAAc;IAC/D,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;AACH,CAAC","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"]}
|
|
@@ -45,6 +45,7 @@ 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
47
|
const kysely_pglite_1 = require("kysely-pglite");
|
|
48
|
+
const plugins_1 = require("../plugins");
|
|
48
49
|
async function migrate(root, client) {
|
|
49
50
|
console.log('migrating pglite ....');
|
|
50
51
|
const glob = new Bun.Glob('initial/*.sql');
|
|
@@ -100,9 +101,9 @@ async function generateDump(root, dumpPath) {
|
|
|
100
101
|
process.exit(1);
|
|
101
102
|
});
|
|
102
103
|
const { dialect } = new kysely_pglite_1.KyselyPGlite(main);
|
|
103
|
-
const kysely =
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const kysely = (0, plugins_1.getKysely)(dialect, {
|
|
105
|
+
repositoryName: 'localTesting',
|
|
106
|
+
log: undefined,
|
|
106
107
|
});
|
|
107
108
|
await migrateKysely(root, kysely).catch(() => {
|
|
108
109
|
console.error('failed to migrate kysely');
|
|
@@ -140,9 +141,9 @@ async function createLocalKysely(root, dumpPath) {
|
|
|
140
141
|
// warm up
|
|
141
142
|
await pglite.sql `SELECT 1`;
|
|
142
143
|
const { dialect } = new kysely_pglite_1.KyselyPGlite(pglite);
|
|
143
|
-
const kysely =
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
const kysely = (0, plugins_1.getKysely)(dialect, {
|
|
145
|
+
repositoryName: 'localTesting',
|
|
146
|
+
log: undefined,
|
|
146
147
|
});
|
|
147
148
|
const originalDestroy = kysely.destroy.bind(kysely);
|
|
148
149
|
kysely.destroy = async () => {
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0GA,8CA8BC;AAxID,qCAAyC;AACzC,+CAA0C;AAC1C,gDAAkC;AAClC,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":["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 { KyselyPGlite } from 'kysely-pglite';\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 KyselyPGlite(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 KyselyPGlite(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,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { DB } from '../v1.generated';
|
|
1
|
+
import type { LogConfig } from 'kysely';
|
|
3
2
|
export declare const root: string;
|
|
4
3
|
export declare const dumpPath: string;
|
|
5
4
|
export type UseLocalKyselyOptions = {
|
|
6
5
|
repositoryName?: string;
|
|
7
6
|
log?: true | LogConfig;
|
|
8
7
|
};
|
|
9
|
-
export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<Kysely<DB>>;
|
|
8
|
+
export declare function useLocalKysely(args?: UseLocalKyselyOptions): Promise<import("kysely").Kysely<import("..").DB>>;
|
|
@@ -4,9 +4,8 @@ exports.dumpPath = exports.root = void 0;
|
|
|
4
4
|
exports.useLocalKysely = useLocalKysely;
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
6
|
const pglite_1 = require("@electric-sql/pglite");
|
|
7
|
-
const kysely_1 = require("kysely");
|
|
8
7
|
const kysely_pglite_dialect_1 = require("kysely-pglite-dialect");
|
|
9
|
-
const
|
|
8
|
+
const plugins_1 = require("../plugins");
|
|
10
9
|
const digest_1 = require("./digest");
|
|
11
10
|
exports.root = (0, node_path_1.join)(__dirname, '../..');
|
|
12
11
|
exports.dumpPath = (0, node_path_1.join)(exports.root, '.data.tar');
|
|
@@ -14,20 +13,17 @@ async function useLocalKysely(args = {}) {
|
|
|
14
13
|
let isDestroyed = false;
|
|
15
14
|
// const now = performance.now();
|
|
16
15
|
const dump = Bun.file(exports.dumpPath);
|
|
17
|
-
const pglite = new pglite_1.PGlite({
|
|
16
|
+
const pglite = new pglite_1.PGlite({
|
|
17
|
+
loadDataDir: dump,
|
|
18
|
+
});
|
|
18
19
|
// warm up
|
|
19
20
|
const dialect = new kysely_pglite_dialect_1.PGliteDialect(pglite);
|
|
20
|
-
const kysely =
|
|
21
|
-
|
|
22
|
-
log: args
|
|
23
|
-
plugins: [
|
|
24
|
-
new kysely_1.CamelCasePlugin(),
|
|
25
|
-
new pganalyze_comment_plugin_1.KyselyPganalyzeCommentPlugin({
|
|
26
|
-
repository: args.repositoryName ?? 'localTesting',
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
21
|
+
const kysely = (0, plugins_1.getKysely)(dialect, {
|
|
22
|
+
repositoryName: args?.repositoryName ?? 'localTesting',
|
|
23
|
+
log: args?.log,
|
|
29
24
|
});
|
|
30
25
|
await (0, digest_1.ensureDigestFunction)(kysely);
|
|
26
|
+
await (0, digest_1.ensureGenRandomBytesFunction)(kysely);
|
|
31
27
|
const originalDestroy = kysely.destroy.bind(kysely);
|
|
32
28
|
kysely.destroy = async () => {
|
|
33
29
|
if (isDestroyed)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["local/index.ts"],"names":[],"mappings":";;;AAcA,wCAiCC;AA/CD,yCAAiC;AACjC,iDAA8C;AAE9C,iEAAsD;AACtD,wCAAuC;AACvC,qCAA8E;AAEjE,QAAA,IAAI,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAChC,QAAA,QAAQ,GAAG,IAAA,gBAAI,EAAC,YAAI,EAAE,WAAW,CAAC,CAAC;AAMzC,KAAK,UAAU,cAAc,CAAC,OAA8B,EAAE;IACnE,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,iCAAiC;IAEjC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,gBAAQ,CAAC,CAAC;IAEhC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;QACxB,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,UAAU;IACV,MAAM,OAAO,GAAG,IAAI,qCAAa,CAAC,MAAM,CAAC,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;IAE3C,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,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;IACN,CAAC,CAAC;IAEF,iFAAiF;IAEjF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport { PGlite } from '@electric-sql/pglite';\nimport type { LogConfig } 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\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 // warm up\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\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
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getKysely = getKysely;
|
|
4
|
+
const kysely_1 = require("kysely");
|
|
5
|
+
const camel_case_1 = require("./camel-case");
|
|
6
|
+
const pganalyze_comment_plugin_1 = require("./pganalyze-comment-plugin");
|
|
7
|
+
function getKysely(dialect, options) {
|
|
8
|
+
const plugins = [new camel_case_1.CustomCasePlugin()];
|
|
9
|
+
if (options?.repositoryName) {
|
|
10
|
+
plugins.push(new pganalyze_comment_plugin_1.KyselyPganalyzeCommentPlugin({
|
|
11
|
+
repository: options.repositoryName,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
const kysely = new kysely_1.Kysely({
|
|
15
|
+
dialect,
|
|
16
|
+
plugins,
|
|
17
|
+
log: options?.log === true ? ['query', 'error'] : options?.log,
|
|
18
|
+
});
|
|
19
|
+
return kysely;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"src/","sources":["plugins.ts"],"names":[],"mappings":";;AAUA,8BAmBC;AA7BD,mCAKgB;AAChB,6CAAgD;AAChD,yEAA0E;AAG1E,SAAgB,SAAS,CACvB,OAAgB,EAChB,OAA4D;IAE5D,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;AAChB,CAAC","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './listing';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./listing"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B","sourcesContent":["export * from './listing';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './is-active-or-at-least-one-ownership-period-active';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./is-active-or-at-least-one-ownership-period-active"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["query/listing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sFAAoE","sourcesContent":["export * from './is-active-or-at-least-one-ownership-period-active';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DB, ExpressionBuilder, PublicListing } from '../../isomorphic';
|
|
2
|
+
export declare function isActiveOrAtLeastOneOwnershipPeriodActive(eb: ExpressionBuilder<DB & {
|
|
3
|
+
listing: PublicListing;
|
|
4
|
+
}, 'listing'>, today: string): import("kysely").ExpressionWrapper<DB & {
|
|
5
|
+
listing: PublicListing;
|
|
6
|
+
}, "listing", import("kysely/dist/cjs/util/type-utils").SqlBool>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isActiveOrAtLeastOneOwnershipPeriodActive = isActiveOrAtLeastOneOwnershipPeriodActive;
|
|
4
|
+
function isActiveOrAtLeastOneOwnershipPeriodActive(eb, today) {
|
|
5
|
+
return eb.or([
|
|
6
|
+
eb('listing.status', '=', 'active'),
|
|
7
|
+
eb.exists(eb
|
|
8
|
+
.selectFrom('public.listingOwnershipPeriod as period')
|
|
9
|
+
.select(eb.lit(1).as('one'))
|
|
10
|
+
.whereRef('period.listingId', '=', 'listing.id')
|
|
11
|
+
.where('period.setListingInactive', '=', false)
|
|
12
|
+
.where((eb2) => eb2.or([
|
|
13
|
+
eb2.and([
|
|
14
|
+
eb2('period.startAt', '<=', today),
|
|
15
|
+
eb2('period.endAt', '>=', today),
|
|
16
|
+
]),
|
|
17
|
+
eb2.and([
|
|
18
|
+
eb2('period.startAt', '<=', today),
|
|
19
|
+
eb2('period.endAt', 'is', null),
|
|
20
|
+
]),
|
|
21
|
+
]))),
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=is-active-or-at-least-one-ownership-period-active.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-active-or-at-least-one-ownership-period-active.js","sourceRoot":"src/","sources":["query/listing/is-active-or-at-least-one-ownership-period-active.ts"],"names":[],"mappings":";;AAEA,8FA0BC;AA1BD,SAAgB,yCAAyC,CACvD,EAAiE,EACjE,KAAa;IAEb,OAAO,EAAE,CAAC,EAAE,CAAC;QACX,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE,QAAQ,CAAC;QACnC,EAAE,CAAC,MAAM,CACP,EAAE;aACC,UAAU,CAAC,yCAAyC,CAAC;aACrD,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;aAC3B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE,YAAY,CAAC;aAC/C,KAAK,CAAC,2BAA2B,EAAE,GAAG,EAAE,KAAK,CAAC;aAC9C,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CACb,GAAG,CAAC,EAAE,CAAC;YACL,GAAG,CAAC,GAAG,CAAC;gBACN,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,KAAK,CAAC;gBAClC,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,CAAC;aACjC,CAAC;YACF,GAAG,CAAC,GAAG,CAAC;gBACN,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,KAAK,CAAC;gBAClC,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,CAAC;aAChC,CAAC;SACH,CAAC,CACH,CACJ;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DB, ExpressionBuilder, PublicListing } from '../../isomorphic';\n\nexport function isActiveOrAtLeastOneOwnershipPeriodActive(\n eb: ExpressionBuilder<DB & { listing: PublicListing }, 'listing'>,\n today: string\n) {\n return eb.or([\n eb('listing.status', '=', 'active'),\n eb.exists(\n eb\n .selectFrom('public.listingOwnershipPeriod as period')\n .select(eb.lit(1).as('one'))\n .whereRef('period.listingId', '=', 'listing.id')\n .where('period.setListingInactive', '=', false)\n .where((eb2) =>\n eb2.or([\n eb2.and([\n eb2('period.startAt', '<=', today),\n eb2('period.endAt', '>=', today),\n ]),\n eb2.and([\n eb2('period.startAt', '<=', today),\n eb2('period.endAt', 'is', null),\n ]),\n ])\n )\n ),\n ]);\n}\n"]}
|
package/build/main/test/index.js
CHANGED
|
@@ -29,7 +29,8 @@ async function useLocalKyselyResource(args) {
|
|
|
29
29
|
const kysely = await (0, local_1.useLocalKysely)(args);
|
|
30
30
|
return new Proxy({}, {
|
|
31
31
|
get(_target, prop) {
|
|
32
|
-
if
|
|
32
|
+
// somehow not working if using Symbol.dispose
|
|
33
|
+
if (prop === Symbol.asyncDispose) {
|
|
33
34
|
return async () => {
|
|
34
35
|
await kysely.destroy();
|
|
35
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["test/index.ts"],"names":[],"mappings":";;AAQA,sCAcC;AAED,4DAQC;AAMD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["test/index.ts"],"names":[],"mappings":";;AAQA,sCAcC;AAED,4DAQC;AAMD,wDAyBC;AA/DD,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,8CAA8C;YAC9C,IAAI,IAAI,KAAK,MAAM,CAAC,YAAY,EAAE,CAAC;gBACjC,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 // somehow not working if using Symbol.dispose\n if (prop === Symbol.asyncDispose) {\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/isomorphic.ts","../../src/v1.generated.ts","../../src/local/digest.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"}
|
|
1
|
+
{"root":["../../src/error.ts","../../src/index.ts","../../src/isomorphic.ts","../../src/plugins.ts","../../src/v1.generated.ts","../../src/camel-case/index.ts","../../src/local/digest.ts","../../src/local/generate.ts","../../src/local/index.ts","../../src/pganalyze-comment-plugin/comment-transformer.ts","../../src/pganalyze-comment-plugin/index.ts","../../src/query/index.ts","../../src/query/listing/index.ts","../../src/query/listing/is-active-or-at-least-one-ownership-period-active.ts","../../src/test/index.ts"],"version":"5.9.3"}
|