@betterinternship/schema 0.16.1 → 1.0.0

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.
@@ -0,0 +1,20 @@
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("./base"), exports);
18
+ __exportStar(require("./factories"), exports);
19
+ __exportStar(require("./paginator"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/repository/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,8CAA4B;AAC5B,8CAA4B"}
@@ -0,0 +1,5 @@
1
+ import { Kysely } from "kysely";
2
+ export type JsonColumnMap = Record<string, Set<string>>;
3
+ export declare const loadJsonColumnMap: <DB>(db: Kysely<DB>) => Promise<JsonColumnMap>;
4
+ export declare const jsonb: <T>(value: T) => import("kysely").RawBuilder<unknown>;
5
+ export declare const wrapJsonColumns: <T extends Record<string, unknown>>(row: T, tableName: string, jsonCols: JsonColumnMap) => T;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapJsonColumns = exports.jsonb = exports.loadJsonColumnMap = void 0;
4
+ const kysely_1 = require("kysely");
5
+ const cache = new WeakMap();
6
+ const introspect = async (db) => {
7
+ const tables = await db.introspection.getTables();
8
+ const out = {};
9
+ for (const table of tables) {
10
+ const key = table.schema ? `${table.schema}.${table.name}` : table.name;
11
+ out[key] = new Set(table.columns
12
+ .filter((c) => c.dataType === "json" || c.dataType === "jsonb")
13
+ .map((c) => c.name));
14
+ }
15
+ return out;
16
+ };
17
+ const loadJsonColumnMap = (db) => {
18
+ let cached = cache.get(db);
19
+ if (!cached) {
20
+ cached = introspect(db);
21
+ cached.catch(() => cache.delete(db));
22
+ cache.set(db, cached);
23
+ }
24
+ return cached;
25
+ };
26
+ exports.loadJsonColumnMap = loadJsonColumnMap;
27
+ const jsonb = (value) => {
28
+ return (0, kysely_1.sql) `CAST(${JSON.stringify(value)} AS JSONB)`;
29
+ };
30
+ exports.jsonb = jsonb;
31
+ const wrapJsonColumns = (row, tableName, jsonCols) => {
32
+ const cols = jsonCols[tableName];
33
+ if (!cols)
34
+ return row;
35
+ const out = { ...row };
36
+ for (const [key, value] of Object.entries(out)) {
37
+ if (!cols.has(key) || value === undefined)
38
+ continue;
39
+ out[key] = (0, exports.jsonb)(value);
40
+ }
41
+ return out;
42
+ };
43
+ exports.wrapJsonColumns = wrapJsonColumns;
44
+ //# sourceMappingURL=json-columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-columns.js","sourceRoot":"","sources":["../../lib/repository/json-columns.ts"],"names":[],"mappings":";;;AAQA,mCAAqC;AAMrC,MAAM,KAAK,GAAG,IAAI,OAAO,EAAkC,CAAC;AAE5D,MAAM,UAAU,GAAG,KAAK,EAAE,EAAe,EAA0B,EAAE;IACnE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;IAClD,MAAM,GAAG,GAAkB,EAAE,CAAC;IAE9B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,KAAK,CAAC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,OAAO,GAAG,CAAC;IAEtB,MAAM,GAAG,GAA4B,EAAE,GAAG,GAAG,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QACpD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,GAAQ,CAAC;AAClB,CAAC,CAAC;AAfW,QAAA,eAAe,mBAe1B"}
@@ -0,0 +1,4 @@
1
+ export interface PaginationOptions {
2
+ limit?: number;
3
+ offset?: number;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=paginator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginator.js","sourceRoot":"","sources":["../../lib/repository/paginator.ts"],"names":[],"mappings":""}