@vrplatform/kysely 1.3.9 → 1.3.10
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/isomorphic.d.ts +1 -1
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local.d.ts +3 -0
- package/build/main/local.js +158 -0
- package/build/main/local.js.map +1 -0
- package/build/main/v0.generated.d.ts +1996 -0
- package/build/main/v0.generated.js +7 -0
- package/build/main/v0.generated.js.map +1 -0
- package/build/main/v1.generated.d.ts +14 -0
- package/build/main/v1.generated.js.map +1 -1
- package/build/module/isomorphic.d.ts +1 -1
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local.d.ts +3 -0
- package/build/module/local.js +119 -0
- package/build/module/local.js.map +1 -0
- package/build/module/v0.generated.d.ts +1996 -0
- package/build/module/v0.generated.js +6 -0
- package/build/module/v0.generated.js.map +1 -0
- package/build/module/v1.generated.d.ts +14 -0
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +1 -1
- package/src/isomorphic.ts +1 -0
- package/src/v1.generated.ts +15 -0
- 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
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
exports.useBrowserKysely = useBrowserKysely;
|
|
18
|
-
// import { live } from '@electric-sql/pglite/live';
|
|
19
|
-
const worker_1 = require("@electric-sql/pglite/worker");
|
|
20
|
-
const kysely_1 = require("kysely");
|
|
21
|
-
const kysely_pglite_dialect_1 = require("kysely-pglite-dialect");
|
|
22
|
-
__exportStar(require("../isomorphic"), exports);
|
|
23
|
-
// Create worker with Vite-compatible URL
|
|
24
|
-
const worker = new Worker(new URL('./worker.ts', import.meta.url), {
|
|
25
|
-
type: 'module',
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Initialize Kysely with PGlite for browser environments.
|
|
29
|
-
*
|
|
30
|
-
* @param dumpData - The database dump data as a Blob, ArrayBuffer, or Uint8Array.
|
|
31
|
-
* This should be the .data.tar file loaded as a blob.
|
|
32
|
-
* @param options - Configuration options
|
|
33
|
-
* @returns A Kysely instance connected to the in-memory PGlite database
|
|
34
|
-
*/
|
|
35
|
-
async function useBrowserKysely(options = {}) {
|
|
36
|
-
let isDestroyed = false;
|
|
37
|
-
//const now = performance.now();
|
|
38
|
-
const pglite = new worker_1.PGliteWorker(worker, {
|
|
39
|
-
dataDir: options.adapter === 'idb' ? 'idb://pglite' : 'memory://',
|
|
40
|
-
extensions: {
|
|
41
|
-
//live,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
const dialect = new kysely_pglite_dialect_1.PGliteDialect(pglite);
|
|
45
|
-
const kysely = new kysely_1.Kysely({
|
|
46
|
-
dialect,
|
|
47
|
-
log: options.log === true ? ['query', 'error'] : options.log,
|
|
48
|
-
plugins: [new kysely_1.CamelCasePlugin()],
|
|
49
|
-
});
|
|
50
|
-
const originalDestroy = kysely.destroy.bind(kysely);
|
|
51
|
-
kysely.destroy = async () => {
|
|
52
|
-
if (isDestroyed)
|
|
53
|
-
return;
|
|
54
|
-
isDestroyed = true;
|
|
55
|
-
//const destroyTime = performance.now();
|
|
56
|
-
await originalDestroy().catch(() => undefined);
|
|
57
|
-
await pglite.close().catch(() => undefined);
|
|
58
|
-
//console.log(
|
|
59
|
-
// `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`
|
|
60
|
-
//);
|
|
61
|
-
};
|
|
62
|
-
//console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);
|
|
63
|
-
return kysely;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["browser/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA2BA,4CAmCC;AA9DD,oDAAoD;AACpD,wDAA2D;AAC3D,mCAAsE;AACtE,iEAAsD;AAGtD,gDAA8B;AAQ9B,yCAAyC;AACzC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;IACjE,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC;AAEH;;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CACpC,UAAmC,EAAE;IAErC,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,gCAAgC;IAEhC,MAAM,MAAM,GAAG,IAAI,qBAAY,CAAC,MAAM,EAAE;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,WAAW;QACjE,UAAU,EAAE;QACV,OAAO;SACR;KACF,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,qCAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,eAAC,CAAK;QACvB,OAAO;QACP,GAAG,EAAE,OAAO,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG;QAC5D,OAAO,EAAE,CAAC,IAAI,wBAAe,EAAE,CAAC;KACjC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,WAAW;YAAE,OAAO;QACxB,WAAW,GAAG,IAAI,CAAC;QACnB,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,gFAAgF;IAEhF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// import { live } from '@electric-sql/pglite/live';\nimport { PGliteWorker } from '@electric-sql/pglite/worker';\nimport { CamelCasePlugin, Kysely as K, type LogConfig } from 'kysely';\nimport { PGliteDialect } from 'kysely-pglite-dialect';\nimport type { DB, Kysely } from '../isomorphic';\n\nexport * from '../isomorphic';\n\nexport type UseBrowserKyselyOptions = {\n repositoryName?: string;\n log?: true | LogConfig;\n adapter?: 'memory' | 'idb';\n};\n\n// Create worker with Vite-compatible URL\nconst worker = new Worker(new URL('./worker.ts', import.meta.url), {\n type: 'module',\n});\n\n/**\n * Initialize Kysely with PGlite for browser environments.\n *\n * @param dumpData - The database dump data as a Blob, ArrayBuffer, or Uint8Array.\n * This should be the .data.tar file loaded as a blob.\n * @param options - Configuration options\n * @returns A Kysely instance connected to the in-memory PGlite database\n */\nexport async function useBrowserKysely(\n options: UseBrowserKyselyOptions = {}\n): Promise<Kysely> {\n let isDestroyed = false;\n //const now = performance.now();\n\n const pglite = new PGliteWorker(worker, {\n dataDir: options.adapter === 'idb' ? 'idb://pglite' : 'memory://',\n extensions: {\n //live,\n },\n });\n\n const dialect = new PGliteDialect(pglite);\n const kysely = new K<DB>({\n dialect,\n log: options.log === true ? ['query', 'error'] : options.log,\n plugins: [new CamelCasePlugin()],\n });\n\n const originalDestroy = kysely.destroy.bind(kysely);\n kysely.destroy = async () => {\n if (isDestroyed) return;\n isDestroyed = true;\n //const destroyTime = performance.now();\n await originalDestroy().catch(() => undefined);\n await pglite.close().catch(() => undefined);\n //console.log(\n // `Database destroyed: ${Math.round(performance.now() - destroyTime)}ms`\n //);\n };\n\n //console.log(`Database initialized: ${Math.round(performance.now() - now)}ms`);\n\n return kysely;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const pglite_1 = require("@electric-sql/pglite");
|
|
4
|
-
const worker_1 = require("@electric-sql/pglite/worker");
|
|
5
|
-
(0, worker_1.worker)({
|
|
6
|
-
async init({ dataDir }) {
|
|
7
|
-
const databases = await self.indexedDB.databases();
|
|
8
|
-
if (dataDir?.startsWith('idb://') && databases.length) {
|
|
9
|
-
const pglite = new pglite_1.PGlite({
|
|
10
|
-
dataDir,
|
|
11
|
-
});
|
|
12
|
-
// warm up
|
|
13
|
-
await pglite.sql `SELECT 1`;
|
|
14
|
-
return pglite;
|
|
15
|
-
}
|
|
16
|
-
console.log('Loading database dump...', dataDir);
|
|
17
|
-
// Load the database dump file
|
|
18
|
-
const dumpResponse = await fetch('/.data.tar').catch((error) => {
|
|
19
|
-
console.error('Failed to load database dump:', error);
|
|
20
|
-
throw new Error(`Failed to load database dump: ${error.message}`);
|
|
21
|
-
});
|
|
22
|
-
if (!dumpResponse.ok) {
|
|
23
|
-
console.error('Failed to load database dump:', dumpResponse.statusText);
|
|
24
|
-
throw new Error(`Failed to load database dump: ${dumpResponse.statusText}`);
|
|
25
|
-
}
|
|
26
|
-
console.log('Loaded database dump:', dumpResponse.status);
|
|
27
|
-
const dumpBlob = await dumpResponse.blob();
|
|
28
|
-
if (!dumpBlob.size) {
|
|
29
|
-
console.error('Failed to load database dump:', dumpBlob.size);
|
|
30
|
-
throw new Error(`Failed to load database dump: ${dumpBlob.size}`);
|
|
31
|
-
}
|
|
32
|
-
const pglite = new pglite_1.PGlite({
|
|
33
|
-
dataDir,
|
|
34
|
-
loadDataDir: dumpBlob,
|
|
35
|
-
});
|
|
36
|
-
// warm up
|
|
37
|
-
await pglite.sql `SELECT 1`;
|
|
38
|
-
return pglite;
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
console.log('Worker process started');
|
|
42
|
-
//# sourceMappingURL=worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"src/","sources":["browser/worker.ts"],"names":[],"mappings":";;AAEA,iDAA8C;AAC9C,wDAAqD;AAErD,IAAA,eAAM,EAAC;IACL,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE;QACpB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;QACnD,IAAI,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;YACtD,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;gBACxB,OAAO;aACR,CAAC,CAAC;YACH,UAAU;YACV,MAAM,MAAM,CAAC,GAAG,CAAA,UAAU,CAAC;YAC3B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;QACjD,8BAA8B;QAC9B,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAC7D,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;YACxE,MAAM,IAAI,KAAK,CACb,iCAAiC,YAAY,CAAC,UAAU,EAAE,CAC3D,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;YACxB,OAAO;YACP,WAAW,EAAE,QAAQ;SACtB,CAAC,CAAC;QACH,UAAU;QACV,MAAM,MAAM,CAAC,GAAG,CAAA,UAAU,CAAC;QAE3B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["declare var self: Worker & { indexedDB: typeof window.indexedDB };\n\nimport { PGlite } from '@electric-sql/pglite';\nimport { worker } from '@electric-sql/pglite/worker';\n\nworker({\n async init({ dataDir }) {\n const databases = await self.indexedDB.databases();\n if (dataDir?.startsWith('idb://') && databases.length) {\n const pglite = new PGlite({\n dataDir,\n });\n // warm up\n await pglite.sql`SELECT 1`;\n return pglite;\n }\n\n console.log('Loading database dump...', dataDir);\n // Load the database dump file\n const dumpResponse = await fetch('/.data.tar').catch((error) => {\n console.error('Failed to load database dump:', error);\n throw new Error(`Failed to load database dump: ${error.message}`);\n });\n if (!dumpResponse.ok) {\n console.error('Failed to load database dump:', dumpResponse.statusText);\n throw new Error(\n `Failed to load database dump: ${dumpResponse.statusText}`\n );\n }\n\n console.log('Loaded database dump:', dumpResponse.status);\n const dumpBlob = await dumpResponse.blob();\n if (!dumpBlob.size) {\n console.error('Failed to load database dump:', dumpBlob.size);\n throw new Error(`Failed to load database dump: ${dumpBlob.size}`);\n }\n\n const pglite = new PGlite({\n dataDir,\n loadDataDir: dumpBlob,\n });\n // warm up\n await pglite.sql`SELECT 1`;\n\n return pglite;\n },\n});\n\nconsole.log('Worker process started');\n"]}
|