@vrplatform/kysely 1.3.15 → 1.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/build/.data.tar +0 -0
  2. package/build/main/camel-case/index.d.ts +8 -0
  3. package/build/main/camel-case/index.js +61 -0
  4. package/build/main/camel-case/index.js.map +1 -0
  5. package/build/main/error.d.ts +3 -0
  6. package/build/main/error.js +11 -0
  7. package/build/main/error.js.map +1 -0
  8. package/build/main/index.d.ts +3 -1
  9. package/build/main/index.js +7 -14
  10. package/build/main/index.js.map +1 -1
  11. package/build/main/local/digest.d.ts +1 -0
  12. package/build/main/local/digest.js +27 -0
  13. package/build/main/local/digest.js.map +1 -1
  14. package/build/main/local/generate.d.ts +1 -1
  15. package/build/main/local/generate.js +7 -6
  16. package/build/main/local/generate.js.map +1 -1
  17. package/build/main/local/index.d.ts +2 -3
  18. package/build/main/local/index.js +8 -12
  19. package/build/main/local/index.js.map +1 -1
  20. package/build/main/local.d.ts +3 -0
  21. package/build/main/local.js +158 -0
  22. package/build/main/local.js.map +1 -0
  23. package/build/main/plugins.d.ts +6 -0
  24. package/build/main/plugins.js +21 -0
  25. package/build/main/plugins.js.map +1 -0
  26. package/build/main/test/index.js +2 -1
  27. package/build/main/test/index.js.map +1 -1
  28. package/build/main/tsconfig.main.tsbuildinfo +1 -1
  29. package/build/main/v0.generated.d.ts +1996 -0
  30. package/build/main/v0.generated.js +7 -0
  31. package/build/main/v0.generated.js.map +1 -0
  32. package/build/main/v1.generated.d.ts +20 -1
  33. package/build/main/v1.generated.js.map +1 -1
  34. package/build/module/camel-case/index.d.ts +8 -0
  35. package/build/module/camel-case/index.js +57 -0
  36. package/build/module/camel-case/index.js.map +1 -0
  37. package/build/module/error.d.ts +3 -0
  38. package/build/module/error.js +7 -0
  39. package/build/module/error.js.map +1 -0
  40. package/build/module/index.d.ts +3 -1
  41. package/build/module/index.js +7 -14
  42. package/build/module/index.js.map +1 -1
  43. package/build/module/local/digest.d.ts +1 -0
  44. package/build/module/local/digest.js +26 -0
  45. package/build/module/local/digest.js.map +1 -1
  46. package/build/module/local/generate.d.ts +1 -1
  47. package/build/module/local/generate.js +8 -7
  48. package/build/module/local/generate.js.map +1 -1
  49. package/build/module/local/index.d.ts +2 -3
  50. package/build/module/local/index.js +9 -13
  51. package/build/module/local/index.js.map +1 -1
  52. package/build/module/local.d.ts +3 -0
  53. package/build/module/local.js +119 -0
  54. package/build/module/local.js.map +1 -0
  55. package/build/module/plugins.d.ts +6 -0
  56. package/build/module/plugins.js +18 -0
  57. package/build/module/plugins.js.map +1 -0
  58. package/build/module/test/index.js +2 -1
  59. package/build/module/test/index.js.map +1 -1
  60. package/build/module/tsconfig.esm.tsbuildinfo +1 -1
  61. package/build/module/v0.generated.d.ts +1996 -0
  62. package/build/module/v0.generated.js +6 -0
  63. package/build/module/v0.generated.js.map +1 -0
  64. package/build/module/v1.generated.d.ts +20 -1
  65. package/build/module/v1.generated.js.map +1 -1
  66. package/package.json +3 -3
  67. package/src/camel-case/index.ts +68 -0
  68. package/src/error.ts +6 -0
  69. package/src/index.ts +11 -21
  70. package/src/local/digest.ts +26 -0
  71. package/src/local/generate.ts +9 -13
  72. package/src/local/index.ts +10 -14
  73. package/src/plugins.ts +30 -0
  74. package/src/test/index.ts +2 -1
  75. package/src/v1.generated.ts +20 -1
  76. package/build/main/browser/index.d.ts +0 -17
  77. package/build/main/browser/index.js +0 -65
  78. package/build/main/browser/index.js.map +0 -1
  79. package/build/main/browser/worker.d.ts +0 -1
  80. package/build/main/browser/worker.js +0 -42
  81. package/build/main/browser/worker.js.map +0 -1
package/src/index.ts CHANGED
@@ -1,15 +1,12 @@
1
- import {
2
- CamelCasePlugin,
3
- Kysely as K,
4
- type KyselyPlugin,
5
- type LogConfig,
6
- } from 'kysely';
1
+ import type { Kysely as K, LogConfig } from 'kysely';
7
2
  import { PostgresJSDialect } from 'kysely-postgres-js';
8
3
  import postgres, { type Sql } from 'postgres';
4
+ import { getKysely } from './plugins';
9
5
 
6
+ export type { LogEvent } from 'kysely';
7
+ export * from './error';
10
8
  export * from './isomorphic';
11
9
 
12
- import { KyselyPganalyzeCommentPlugin } from './pganalyze-comment-plugin';
13
10
  import type { DB } from './v1.generated';
14
11
 
15
12
  type KyselyOpts = {
@@ -29,22 +26,15 @@ export type Postgres = Sql;
29
26
  */
30
27
  export function useKysely(postgres: Sql, options?: KyselyOpts) {
31
28
  console.debug('Creating Kysely instance');
32
- const plugins: KyselyPlugin[] = [new CamelCasePlugin()];
33
- if (options?.repositoryName) {
34
- plugins.push(
35
- new KyselyPganalyzeCommentPlugin({
36
- repository: options.repositoryName,
37
- })
38
- );
39
- }
40
- const kysely = new K<DB>({
41
- dialect: new PostgresJSDialect({
29
+ const kysely = getKysely(
30
+ new PostgresJSDialect({
42
31
  postgres,
43
32
  }),
44
- plugins,
45
- log: options?.log === true ? ['query', 'error'] : options?.log,
46
- });
47
-
33
+ {
34
+ repositoryName: options?.repositoryName,
35
+ log: options?.log,
36
+ }
37
+ );
48
38
  kysely.destroy = async () => {
49
39
  console.debug('Closing Kysely connection');
50
40
  await Promise.race([
@@ -16,3 +16,29 @@ export async function ensureDigestFunction(kysely: Kysely) {
16
16
  `.execute(kysely);
17
17
  }
18
18
  }
19
+
20
+ export async function ensureGenRandomBytesFunction(kysely: Kysely) {
21
+ try {
22
+ await sql`select gen_random_bytes(1)`.execute(kysely);
23
+ } catch {
24
+ await sql`
25
+ create or replace function gen_random_bytes(p_len integer)
26
+ returns bytea
27
+ language sql
28
+ stable
29
+ strict
30
+ as $$
31
+ select substring(
32
+ decode(
33
+ repeat(
34
+ md5(random()::text || now()::text),
35
+ ((p_len + 15) / 16)
36
+ ),
37
+ 'hex'
38
+ )
39
+ from 1 for p_len
40
+ );
41
+ $$;
42
+ `.execute(kysely);
43
+ }
44
+ }
@@ -3,14 +3,10 @@ import { exists } from 'node:fs/promises';
3
3
  import * as path from 'node:path';
4
4
  import { join } from 'node:path';
5
5
  import { PGlite } from '@electric-sql/pglite';
6
- import {
7
- CamelCasePlugin,
8
- FileMigrationProvider,
9
- Kysely,
10
- Migrator,
11
- } from 'kysely';
6
+ import { FileMigrationProvider, type Kysely, Migrator } from 'kysely';
12
7
  import codegen from 'kysely-codegen';
13
8
  import { KyselyPGlite } from 'kysely-pglite';
9
+ import { getKysely } from '../plugins';
14
10
  import type { DB } from '../v1.generated';
15
11
 
16
12
  async function migrate(root: string, client: PGlite) {
@@ -25,7 +21,7 @@ async function migrate(root: string, client: PGlite) {
25
21
  }
26
22
  }
27
23
 
28
- async function migrateKysely(root: string, kysely: Kysely<any>) {
24
+ async function migrateKysely(root: string, kysely: Kysely<DB>) {
29
25
  console.log('init migrating kysely ....');
30
26
  const migrator = new Migrator({
31
27
  db: kysely,
@@ -75,9 +71,9 @@ async function generateDump(root: string, dumpPath: string) {
75
71
  process.exit(1);
76
72
  });
77
73
  const { dialect } = new KyselyPGlite(main);
78
- const kysely = new Kysely<DB>({
79
- dialect,
80
- plugins: [new CamelCasePlugin()],
74
+ const kysely = getKysely(dialect, {
75
+ repositoryName: 'localTesting',
76
+ log: undefined,
81
77
  });
82
78
  await migrateKysely(root, kysely).catch(() => {
83
79
  console.error('failed to migrate kysely');
@@ -118,9 +114,9 @@ export async function createLocalKysely(root: string, dumpPath: string) {
118
114
  // warm up
119
115
  await pglite.sql`SELECT 1`;
120
116
  const { dialect } = new KyselyPGlite(pglite);
121
- const kysely = new Kysely<DB>({
122
- dialect,
123
- plugins: [new CamelCasePlugin()],
117
+ const kysely = getKysely(dialect, {
118
+ repositoryName: 'localTesting',
119
+ log: undefined,
124
120
  });
125
121
 
126
122
  const originalDestroy = kysely.destroy.bind(kysely);
@@ -1,10 +1,9 @@
1
1
  import { join } from 'node:path';
2
2
  import { PGlite } from '@electric-sql/pglite';
3
- import { CamelCasePlugin, Kysely, type LogConfig } from 'kysely';
3
+ import type { LogConfig } from 'kysely';
4
4
  import { PGliteDialect } from 'kysely-pglite-dialect';
5
- import { KyselyPganalyzeCommentPlugin } from '../pganalyze-comment-plugin';
6
- import type { DB } from '../v1.generated';
7
- import { ensureDigestFunction } from './digest';
5
+ import { getKysely } from '../plugins';
6
+ import { ensureDigestFunction, ensureGenRandomBytesFunction } from './digest';
8
7
 
9
8
  export const root = join(__dirname, '../..');
10
9
  export const dumpPath = join(root, '.data.tar');
@@ -19,20 +18,17 @@ export async function useLocalKysely(args: UseLocalKyselyOptions = {}) {
19
18
 
20
19
  const dump = Bun.file(dumpPath);
21
20
 
22
- const pglite = new PGlite({ loadDataDir: dump });
21
+ const pglite = new PGlite({
22
+ loadDataDir: dump,
23
+ });
23
24
  // warm up
24
25
  const dialect = new PGliteDialect(pglite);
25
- const kysely = new Kysely<DB>({
26
- dialect,
27
- log: args.log === true ? ['query', 'error'] : args.log,
28
- plugins: [
29
- new CamelCasePlugin(),
30
- new KyselyPganalyzeCommentPlugin({
31
- repository: args.repositoryName ?? 'localTesting',
32
- }),
33
- ],
26
+ const kysely = getKysely(dialect, {
27
+ repositoryName: args?.repositoryName ?? 'localTesting',
28
+ log: args?.log,
34
29
  });
35
30
  await ensureDigestFunction(kysely);
31
+ await ensureGenRandomBytesFunction(kysely);
36
32
 
37
33
  const originalDestroy = kysely.destroy.bind(kysely);
38
34
  kysely.destroy = async () => {
package/src/plugins.ts ADDED
@@ -0,0 +1,30 @@
1
+ import {
2
+ type Dialect,
3
+ Kysely as K,
4
+ type KyselyPlugin,
5
+ type LogConfig,
6
+ } from 'kysely';
7
+ import { CustomCasePlugin } from './camel-case';
8
+ import { KyselyPganalyzeCommentPlugin } from './pganalyze-comment-plugin';
9
+ import type { DB } from './v1.generated';
10
+
11
+ export function getKysely(
12
+ dialect: Dialect,
13
+ options: { repositoryName?: string; log?: true | LogConfig }
14
+ ) {
15
+ const plugins: KyselyPlugin[] = [new CustomCasePlugin()];
16
+
17
+ if (options?.repositoryName) {
18
+ plugins.push(
19
+ new KyselyPganalyzeCommentPlugin({
20
+ repository: options.repositoryName,
21
+ })
22
+ );
23
+ }
24
+ const kysely = new K<DB>({
25
+ dialect,
26
+ plugins,
27
+ log: options?.log === true ? ['query', 'error'] : options?.log,
28
+ });
29
+ return kysely;
30
+ }
package/src/test/index.ts CHANGED
@@ -45,7 +45,8 @@ export async function useLocalKyselyResource(
45
45
  {},
46
46
  {
47
47
  get(_target, prop) {
48
- if (prop === Symbol.dispose) {
48
+ // somehow not working if using Symbol.dispose
49
+ if (prop === Symbol.asyncDispose) {
49
50
  return async () => {
50
51
  await kysely.destroy();
51
52
  };
@@ -180,6 +180,10 @@ export interface AccountingContact {
180
180
  name: string;
181
181
  phone: string | null;
182
182
  pmsStatus: string | null;
183
+ /**
184
+ * Human-readable system ID (CNT-XXX-XXXX-XXX).
185
+ */
186
+ shortRef: string | null;
183
187
  sourceId: string | null;
184
188
  status: Generated<string | null>;
185
189
  taxId: string | null;
@@ -298,6 +302,10 @@ export interface AccountingTransaction {
298
302
  recurringFeeId: string | null;
299
303
  recurringPattern: Json | null;
300
304
  recurringTemplateId: string | null;
305
+ /**
306
+ * Human-readable system ID (EXP/DEP/TRF-XXX-XXXX-XXX depending on transaction.type).
307
+ */
308
+ shortRef: string | null;
301
309
  sourceId: string | null;
302
310
  status: Generated<string>;
303
311
  tenantId: string;
@@ -406,18 +414,21 @@ export interface CoreFlow {
406
414
  leftType: string | null;
407
415
  mappingSchema: Json;
408
416
  rightType: string | null;
417
+ runSchema: Generated<Json>;
409
418
  settingSchema: Json;
410
419
  title: string;
411
420
  type: Generated<PublicFlowType | null>;
412
421
  uniqueRef: string;
422
+ useGlobalMapping: Generated<boolean>;
413
423
  }
414
424
 
415
425
  export interface CoreFlowMapping {
416
426
  accountId: string | null;
417
427
  bookingChannelId: string | null;
428
+ connectionId: string;
418
429
  contactId: string | null;
419
430
  createdAt: Generated<Timestamp>;
420
- flowId: string;
431
+ flowId: string | null;
421
432
  id: Generated<string>;
422
433
  listingId: string | null;
423
434
  mappingKey: string;
@@ -908,6 +919,10 @@ export interface PublicListing {
908
919
  ownerContactId: string | null;
909
920
  pmsAddressData: Json | null;
910
921
  pmsStatus: string | null;
922
+ /**
923
+ * Human-readable system ID (LST-XXX-XXXX-XXX).
924
+ */
925
+ shortRef: string | null;
911
926
  sourceId: string | null;
912
927
  status: string | null;
913
928
  tenantId: string;
@@ -1299,6 +1314,10 @@ export interface PublicReservation {
1299
1314
  paidStatus: string | null;
1300
1315
  paymentMethod: string | null;
1301
1316
  pmsReferenceCode: string | null;
1317
+ /**
1318
+ * Human-readable system ID (RES-XXX-XXXX-XXX).
1319
+ */
1320
+ shortRef: string | null;
1302
1321
  sourceId: string | null;
1303
1322
  status: Generated<string | null>;
1304
1323
  tenantId: string | null;
@@ -1,17 +0,0 @@
1
- import { type LogConfig } from 'kysely';
2
- import type { Kysely } from '../isomorphic';
3
- export * from '../isomorphic';
4
- export type UseBrowserKyselyOptions = {
5
- repositoryName?: string;
6
- log?: true | LogConfig;
7
- adapter?: 'memory' | 'idb';
8
- };
9
- /**
10
- * Initialize Kysely with PGlite for browser environments.
11
- *
12
- * @param dumpData - The database dump data as a Blob, ArrayBuffer, or Uint8Array.
13
- * This should be the .data.tar file loaded as a blob.
14
- * @param options - Configuration options
15
- * @returns A Kysely instance connected to the in-memory PGlite database
16
- */
17
- export declare function useBrowserKysely(options?: UseBrowserKyselyOptions): Promise<Kysely>;
@@ -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":[],"mapp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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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AM,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"]}