@syncular/dialect-libsql 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,47 @@
1
+ /**
2
+ * @syncular/dialect-libsql - LibSQL/Turso dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for LibSQL/Turso with SerializePlugin
5
+ * for automatic JSON serialization/deserialization.
6
+ * SQLite-compatible — use with @syncular/server-dialect-sqlite.
7
+ */
8
+ import { SerializePlugin } from '@syncular/core';
9
+ import { Kysely, SqliteDialect } from 'kysely';
10
+ import Database from 'libsql';
11
+ type LibsqlNativeOptions = NonNullable<ConstructorParameters<typeof Database>[1]>;
12
+ export interface LibsqlOptions {
13
+ /** LibSQL URL or local SQLite filename (e.g. `:memory:` or `./data.db`). */
14
+ url: string;
15
+ /** Auth token for remote databases (e.g. Turso). */
16
+ authToken?: string;
17
+ /**
18
+ * Optional sync URL for embedded replicas.
19
+ *
20
+ * When set, `Database.sync()` is called once during initialization.
21
+ */
22
+ syncUrl?: string;
23
+ /** Pass-through options to libsql-js. */
24
+ nativeOptions?: LibsqlNativeOptions;
25
+ }
26
+ /**
27
+ * Create a Kysely instance with LibSQL dialect and SerializePlugin.
28
+ *
29
+ * @example
30
+ * // Turso cloud
31
+ * const db = createLibsqlDb<MyDb>({
32
+ * url: 'libsql://my-db-org.turso.io',
33
+ * authToken: 'your-token',
34
+ * });
35
+ *
36
+ * // Local file / memory
37
+ * const db = createLibsqlDb<MyDb>({ url: ':memory:' });
38
+ * const db = createLibsqlDb<MyDb>({ url: './data.db' });
39
+ */
40
+ export declare function createLibsqlDb<T>(options: LibsqlOptions): Kysely<T>;
41
+ /**
42
+ * Create the LibSQL dialect directly (without SerializePlugin).
43
+ */
44
+ export declare function createLibsqlDialect(options: LibsqlOptions): SqliteDialect;
45
+ export declare function createSerializePlugin(): SerializePlugin;
46
+ export {};
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,QAAQ,MAAM,QAAQ,CAAC;AAE9B,KAAK,mBAAmB,GAAG,WAAW,CACpC,qBAAqB,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAC1C,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IAEZ,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yCAAyC;IACzC,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,CAKnE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAezE;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CAEvD"}
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @syncular/dialect-libsql - LibSQL/Turso dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for LibSQL/Turso with SerializePlugin
5
+ * for automatic JSON serialization/deserialization.
6
+ * SQLite-compatible — use with @syncular/server-dialect-sqlite.
7
+ */
8
+ import { SerializePlugin } from '@syncular/core';
9
+ import { Kysely, SqliteDialect } from 'kysely';
10
+ import Database from 'libsql';
11
+ /**
12
+ * Create a Kysely instance with LibSQL dialect and SerializePlugin.
13
+ *
14
+ * @example
15
+ * // Turso cloud
16
+ * const db = createLibsqlDb<MyDb>({
17
+ * url: 'libsql://my-db-org.turso.io',
18
+ * authToken: 'your-token',
19
+ * });
20
+ *
21
+ * // Local file / memory
22
+ * const db = createLibsqlDb<MyDb>({ url: ':memory:' });
23
+ * const db = createLibsqlDb<MyDb>({ url: './data.db' });
24
+ */
25
+ export function createLibsqlDb(options) {
26
+ return new Kysely({
27
+ dialect: createLibsqlDialect(options),
28
+ plugins: [new SerializePlugin()],
29
+ });
30
+ }
31
+ /**
32
+ * Create the LibSQL dialect directly (without SerializePlugin).
33
+ */
34
+ export function createLibsqlDialect(options) {
35
+ const { url, authToken, syncUrl, nativeOptions } = options;
36
+ const mergedOptions = {
37
+ ...nativeOptions,
38
+ ...(syncUrl ? { syncUrl } : {}),
39
+ ...(authToken ? { authToken } : {}),
40
+ };
41
+ const database = new Database(url, mergedOptions);
42
+ if (syncUrl) {
43
+ database.sync();
44
+ }
45
+ return new SqliteDialect({ database });
46
+ }
47
+ export function createSerializePlugin() {
48
+ return new SerializePlugin();
49
+ }
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,QAAQ,MAAM,QAAQ,CAAC;AAwB9B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAI,OAAsB,EAAa;IACnE,OAAO,IAAI,MAAM,CAAI;QACnB,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC;QACrC,OAAO,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;KACjC,CAAC,CAAC;AAAA,CACJ;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAsB,EAAiB;IACzE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAE3D,MAAM,aAAa,GAAiD;QAClE,GAAG,aAAa;QAChB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpC,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IAClD,IAAI,OAAO,EAAE,CAAC;QACZ,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClB,CAAC;IAED,OAAO,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAAA,CACxC;AAED,MAAM,UAAU,qBAAqB,GAAoB;IACvD,OAAO,IAAI,eAAe,EAAE,CAAC;AAAA,CAC9B"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@syncular/dialect-libsql",
3
+ "version": "0.0.1-60",
4
+ "description": "LibSQL/Turso dialect for the Syncular client",
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-libsql"
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
+ "libsql",
23
+ "turso",
24
+ "sqlite"
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
+ "@syncular/core": "0.0.1",
47
+ "libsql": "^0.5.22"
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,78 @@
1
+ /**
2
+ * @syncular/dialect-libsql - LibSQL/Turso dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for LibSQL/Turso with SerializePlugin
5
+ * for automatic JSON serialization/deserialization.
6
+ * SQLite-compatible — use with @syncular/server-dialect-sqlite.
7
+ */
8
+
9
+ import { SerializePlugin } from '@syncular/core';
10
+ import { Kysely, SqliteDialect } from 'kysely';
11
+ import Database from 'libsql';
12
+
13
+ type LibsqlNativeOptions = NonNullable<
14
+ ConstructorParameters<typeof Database>[1]
15
+ >;
16
+
17
+ export interface LibsqlOptions {
18
+ /** LibSQL URL or local SQLite filename (e.g. `:memory:` or `./data.db`). */
19
+ url: string;
20
+
21
+ /** Auth token for remote databases (e.g. Turso). */
22
+ authToken?: string;
23
+
24
+ /**
25
+ * Optional sync URL for embedded replicas.
26
+ *
27
+ * When set, `Database.sync()` is called once during initialization.
28
+ */
29
+ syncUrl?: string;
30
+
31
+ /** Pass-through options to libsql-js. */
32
+ nativeOptions?: LibsqlNativeOptions;
33
+ }
34
+
35
+ /**
36
+ * Create a Kysely instance with LibSQL dialect and SerializePlugin.
37
+ *
38
+ * @example
39
+ * // Turso cloud
40
+ * const db = createLibsqlDb<MyDb>({
41
+ * url: 'libsql://my-db-org.turso.io',
42
+ * authToken: 'your-token',
43
+ * });
44
+ *
45
+ * // Local file / memory
46
+ * const db = createLibsqlDb<MyDb>({ url: ':memory:' });
47
+ * const db = createLibsqlDb<MyDb>({ url: './data.db' });
48
+ */
49
+ export function createLibsqlDb<T>(options: LibsqlOptions): Kysely<T> {
50
+ return new Kysely<T>({
51
+ dialect: createLibsqlDialect(options),
52
+ plugins: [new SerializePlugin()],
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Create the LibSQL dialect directly (without SerializePlugin).
58
+ */
59
+ export function createLibsqlDialect(options: LibsqlOptions): SqliteDialect {
60
+ const { url, authToken, syncUrl, nativeOptions } = options;
61
+
62
+ const mergedOptions: LibsqlNativeOptions & { authToken?: string } = {
63
+ ...nativeOptions,
64
+ ...(syncUrl ? { syncUrl } : {}),
65
+ ...(authToken ? { authToken } : {}),
66
+ };
67
+
68
+ const database = new Database(url, mergedOptions);
69
+ if (syncUrl) {
70
+ database.sync();
71
+ }
72
+
73
+ return new SqliteDialect({ database });
74
+ }
75
+
76
+ export function createSerializePlugin(): SerializePlugin {
77
+ return new SerializePlugin();
78
+ }