@syncular/dialect-pglite 0.0.1-60

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,62 @@
1
+ /**
2
+ * @syncular/dialect-pglite - PGlite dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for PGlite (in-memory/browser Postgres).
5
+ * Uses kysely-pglite-dialect under the hood.
6
+ */
7
+ import { type PGliteWithLive } from '@electric-sql/pglite/live';
8
+ import { Kysely } from 'kysely';
9
+ import { PGliteDialect } from 'kysely-pglite-dialect';
10
+ export interface PgliteOptions {
11
+ /** Optional data directory for persistence */
12
+ dataDir?: string;
13
+ /** Preloaded PGlite fs bundle (avoids runtime network fetches in the browser). */
14
+ fsBundle?: Blob | File;
15
+ /** Precompiled wasm module (avoids runtime network fetches in the browser). */
16
+ wasmModule?: WebAssembly.Module;
17
+ /** Optional data dir archive to initialize from (tar). */
18
+ loadDataDir?: Blob | File;
19
+ /** Optional initial memory (bytes). */
20
+ initialMemory?: number;
21
+ }
22
+ /**
23
+ * Extended Kysely instance that exposes the raw PGlite instance.
24
+ * Use this type when you need access to PGlite's native features like live queries.
25
+ */
26
+ export interface PgliteDb<T> extends Kysely<T> {
27
+ /** Access raw PGlite instance for live queries */
28
+ readonly pglite: PGliteWithLive;
29
+ }
30
+ /**
31
+ * Create a Kysely instance with PGlite dialect.
32
+ * Synchronous version - database may not be fully ready immediately.
33
+ *
34
+ * Note: This version does NOT include the live extension or expose the raw PGlite instance.
35
+ * For live query support, use createPgliteDbAsync() instead.
36
+ *
37
+ * @example
38
+ * const db = createPgliteDb<MyDb>(); // In-memory
39
+ * const db = createPgliteDb<MyDb>({ dataDir: './pgdata' }); // Persistent
40
+ */
41
+ export declare function createPgliteDb<T>(options?: PgliteOptions): Kysely<T>;
42
+ /**
43
+ * Create a Kysely instance with PGlite dialect, waiting for database to be ready.
44
+ * Async version - ensures database is fully initialized before returning.
45
+ * Includes the live extension for reactive queries.
46
+ *
47
+ * @example
48
+ * const db = await createPgliteDbAsync<MyDb>(); // In-memory
49
+ * const db = await createPgliteDbAsync<MyDb>({ dataDir: 'idb://mydb' }); // Persistent
50
+ * // Access raw PGlite for live queries:
51
+ * db.pglite.live.incrementalQuery(...)
52
+ */
53
+ export declare function createPgliteDbAsync<T>(options?: PgliteOptions): Promise<PgliteDb<T>>;
54
+ /**
55
+ * Create the PGlite dialect directly.
56
+ */
57
+ export declare function createPgliteDialect(options?: PgliteOptions): PGliteDialect;
58
+ export declare function getPgliteAssetPaths(): {
59
+ fsBundlePath: string;
60
+ wasmPath: string;
61
+ };
62
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAEvB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC;IAEhC,0DAA0D;IAC1D,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAE1B,uCAAuC;IACvC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IAC5C,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,CAKpE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAoBtB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,aAAa,CAG1E;AAGD,wBAAgB,mBAAmB,IAAI;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAOA"}
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @syncular/dialect-pglite - PGlite dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for PGlite (in-memory/browser Postgres).
5
+ * Uses kysely-pglite-dialect under the hood.
6
+ */
7
+ import { PGlite } from '@electric-sql/pglite';
8
+ import { live } from '@electric-sql/pglite/live';
9
+ import { Kysely } from 'kysely';
10
+ import { PGliteDialect } from 'kysely-pglite-dialect';
11
+ /**
12
+ * Create a Kysely instance with PGlite dialect.
13
+ * Synchronous version - database may not be fully ready immediately.
14
+ *
15
+ * Note: This version does NOT include the live extension or expose the raw PGlite instance.
16
+ * For live query support, use createPgliteDbAsync() instead.
17
+ *
18
+ * @example
19
+ * const db = createPgliteDb<MyDb>(); // In-memory
20
+ * const db = createPgliteDb<MyDb>({ dataDir: './pgdata' }); // Persistent
21
+ */
22
+ export function createPgliteDb(options) {
23
+ const database = options ? new PGlite(options) : new PGlite();
24
+ return new Kysely({
25
+ dialect: new PGliteDialect(database),
26
+ });
27
+ }
28
+ /**
29
+ * Create a Kysely instance with PGlite dialect, waiting for database to be ready.
30
+ * Async version - ensures database is fully initialized before returning.
31
+ * Includes the live extension for reactive queries.
32
+ *
33
+ * @example
34
+ * const db = await createPgliteDbAsync<MyDb>(); // In-memory
35
+ * const db = await createPgliteDbAsync<MyDb>({ dataDir: 'idb://mydb' }); // Persistent
36
+ * // Access raw PGlite for live queries:
37
+ * db.pglite.live.incrementalQuery(...)
38
+ */
39
+ export async function createPgliteDbAsync(options) {
40
+ const database = await PGlite.create({
41
+ ...options,
42
+ extensions: { live },
43
+ });
44
+ const db = new Kysely({
45
+ dialect: new PGliteDialect(database),
46
+ });
47
+ // Attach raw instance for live query access using Object.defineProperty
48
+ // to properly define the readonly property
49
+ Object.defineProperty(db, 'pglite', {
50
+ value: database,
51
+ writable: false,
52
+ enumerable: true,
53
+ configurable: false,
54
+ });
55
+ return db;
56
+ }
57
+ /**
58
+ * Create the PGlite dialect directly.
59
+ */
60
+ export function createPgliteDialect(options) {
61
+ const database = options ? new PGlite(options) : new PGlite();
62
+ return new PGliteDialect(database);
63
+ }
64
+ // Re-export types for convenience
65
+ export function getPgliteAssetPaths() {
66
+ const entry = import.meta.resolve('@electric-sql/pglite');
67
+ return {
68
+ fsBundlePath: new URL('./pglite.data', entry).pathname,
69
+ wasmPath: new URL('./pglite.wasm', entry).pathname,
70
+ };
71
+ }
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAuB,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AA4BtD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAI,OAAuB,EAAa;IACpE,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;IAC9D,OAAO,IAAI,MAAM,CAAI;QACnB,OAAO,EAAE,IAAI,aAAa,CAAC,QAAQ,CAAC;KACrC,CAAC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
5
+ "license": "MIT",
6
+ "author": "Benjamin Kniffler",
7
+ "homepage": "https://syncular.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/syncular/syncular.git",
11
+ "directory": "packages/dialect-pglite"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/syncular/syncular/issues"
15
+ },
16
+ "keywords": [
17
+ "sync",
18
+ "offline-first",
19
+ "realtime",
20
+ "database",
21
+ "typescript",
22
+ "pglite",
23
+ "postgres",
24
+ "wasm"
25
+ ],
26
+ "private": false,
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "type": "module",
31
+ "exports": {
32
+ ".": {
33
+ "bun": "./src/index.ts",
34
+ "import": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ }
38
+ }
39
+ },
40
+ "scripts": {
41
+ "tsgo": "tsgo --noEmit",
42
+ "build": "rm -rf dist && tsgo",
43
+ "release": "bun pm pack --destination . && npm publish ./*.tgz --tag latest && rm -f ./*.tgz"
44
+ },
45
+ "dependencies": {
46
+ "@electric-sql/pglite": "^0.3.15",
47
+ "kysely-pglite-dialect": "^1.2.0"
48
+ },
49
+ "peerDependencies": {
50
+ "kysely": "^0.28.0"
51
+ },
52
+ "devDependencies": {
53
+ "@syncular/config": "0.0.0",
54
+ "kysely": "*"
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "src"
59
+ ]
60
+ }
package/src/index.ts ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @syncular/dialect-pglite - PGlite dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for PGlite (in-memory/browser Postgres).
5
+ * Uses kysely-pglite-dialect under the hood.
6
+ */
7
+
8
+ import { PGlite } from '@electric-sql/pglite';
9
+ import { live, type PGliteWithLive } from '@electric-sql/pglite/live';
10
+ import { Kysely } from 'kysely';
11
+ import { PGliteDialect } from 'kysely-pglite-dialect';
12
+
13
+ export interface PgliteOptions {
14
+ /** Optional data directory for persistence */
15
+ dataDir?: string;
16
+
17
+ /** Preloaded PGlite fs bundle (avoids runtime network fetches in the browser). */
18
+ fsBundle?: Blob | File;
19
+
20
+ /** Precompiled wasm module (avoids runtime network fetches in the browser). */
21
+ wasmModule?: WebAssembly.Module;
22
+
23
+ /** Optional data dir archive to initialize from (tar). */
24
+ loadDataDir?: Blob | File;
25
+
26
+ /** Optional initial memory (bytes). */
27
+ initialMemory?: number;
28
+ }
29
+
30
+ /**
31
+ * Extended Kysely instance that exposes the raw PGlite instance.
32
+ * Use this type when you need access to PGlite's native features like live queries.
33
+ */
34
+ export interface PgliteDb<T> extends Kysely<T> {
35
+ /** Access raw PGlite instance for live queries */
36
+ readonly pglite: PGliteWithLive;
37
+ }
38
+
39
+ /**
40
+ * Create a Kysely instance with PGlite dialect.
41
+ * Synchronous version - database may not be fully ready immediately.
42
+ *
43
+ * Note: This version does NOT include the live extension or expose the raw PGlite instance.
44
+ * For live query support, use createPgliteDbAsync() instead.
45
+ *
46
+ * @example
47
+ * const db = createPgliteDb<MyDb>(); // In-memory
48
+ * const db = createPgliteDb<MyDb>({ dataDir: './pgdata' }); // Persistent
49
+ */
50
+ export function createPgliteDb<T>(options?: PgliteOptions): Kysely<T> {
51
+ const database = options ? new PGlite(options) : new PGlite();
52
+ return new Kysely<T>({
53
+ dialect: new PGliteDialect(database),
54
+ });
55
+ }
56
+
57
+ /**
58
+ * Create a Kysely instance with PGlite dialect, waiting for database to be ready.
59
+ * Async version - ensures database is fully initialized before returning.
60
+ * Includes the live extension for reactive queries.
61
+ *
62
+ * @example
63
+ * const db = await createPgliteDbAsync<MyDb>(); // In-memory
64
+ * const db = await createPgliteDbAsync<MyDb>({ dataDir: 'idb://mydb' }); // Persistent
65
+ * // Access raw PGlite for live queries:
66
+ * db.pglite.live.incrementalQuery(...)
67
+ */
68
+ export async function createPgliteDbAsync<T>(
69
+ options?: PgliteOptions
70
+ ): Promise<PgliteDb<T>> {
71
+ const database = await PGlite.create({
72
+ ...options,
73
+ extensions: { live },
74
+ });
75
+
76
+ const db = new Kysely<T>({
77
+ dialect: new PGliteDialect(database),
78
+ });
79
+
80
+ // Attach raw instance for live query access using Object.defineProperty
81
+ // to properly define the readonly property
82
+ Object.defineProperty(db, 'pglite', {
83
+ value: database,
84
+ writable: false,
85
+ enumerable: true,
86
+ configurable: false,
87
+ });
88
+
89
+ return db as PgliteDb<T>;
90
+ }
91
+
92
+ /**
93
+ * Create the PGlite dialect directly.
94
+ */
95
+ export function createPgliteDialect(options?: PgliteOptions): PGliteDialect {
96
+ const database = options ? new PGlite(options) : new PGlite();
97
+ return new PGliteDialect(database);
98
+ }
99
+ // Re-export types for convenience
100
+
101
+ export function getPgliteAssetPaths(): {
102
+ fsBundlePath: string;
103
+ wasmPath: string;
104
+ } {
105
+ const entry = import.meta.resolve('@electric-sql/pglite');
106
+
107
+ return {
108
+ fsBundlePath: new URL('./pglite.data', entry).pathname,
109
+ wasmPath: new URL('./pglite.wasm', entry).pathname,
110
+ };
111
+ }