@syncular/dialect-d1 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.
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
- package/src/index.ts +43 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/dialect-d1 - Cloudflare D1 dialect for sync
|
|
3
|
+
*
|
|
4
|
+
* Provides a Kysely dialect for Cloudflare D1 with SerializePlugin
|
|
5
|
+
* for automatic JSON serialization/deserialization.
|
|
6
|
+
* SQLite-compatible — use with @syncular/server-dialect-sqlite.
|
|
7
|
+
*/
|
|
8
|
+
import type { D1Database } from '@cloudflare/workers-types';
|
|
9
|
+
import { SerializePlugin } from '@syncular/core';
|
|
10
|
+
import { Kysely } from 'kysely';
|
|
11
|
+
/**
|
|
12
|
+
* Create a Kysely instance with Cloudflare D1 dialect and SerializePlugin.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* export default {
|
|
16
|
+
* async fetch(request: Request, env: Env) {
|
|
17
|
+
* const db = createD1Db<MyDb>(env.DB);
|
|
18
|
+
* const dialect = createSqliteServerDialect();
|
|
19
|
+
* await ensureSyncSchema(db, dialect);
|
|
20
|
+
* // ...
|
|
21
|
+
* }
|
|
22
|
+
* };
|
|
23
|
+
*/
|
|
24
|
+
export declare function createD1Db<T>(database: D1Database): Kysely<T>;
|
|
25
|
+
export declare function createSerializePlugin(): SerializePlugin;
|
|
26
|
+
//# 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,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAK7D;AASD,wBAAgB,qBAAqB,IAAI,eAAe,CAEvD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/dialect-d1 - Cloudflare D1 dialect for sync
|
|
3
|
+
*
|
|
4
|
+
* Provides a Kysely dialect for Cloudflare D1 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 } from 'kysely';
|
|
10
|
+
import { D1Dialect } from 'kysely-d1';
|
|
11
|
+
/**
|
|
12
|
+
* Create a Kysely instance with Cloudflare D1 dialect and SerializePlugin.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* export default {
|
|
16
|
+
* async fetch(request: Request, env: Env) {
|
|
17
|
+
* const db = createD1Db<MyDb>(env.DB);
|
|
18
|
+
* const dialect = createSqliteServerDialect();
|
|
19
|
+
* await ensureSyncSchema(db, dialect);
|
|
20
|
+
* // ...
|
|
21
|
+
* }
|
|
22
|
+
* };
|
|
23
|
+
*/
|
|
24
|
+
export function createD1Db(database) {
|
|
25
|
+
return new Kysely({
|
|
26
|
+
dialect: createD1Dialect(database),
|
|
27
|
+
plugins: [new SerializePlugin()],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create the D1 dialect directly (without SerializePlugin).
|
|
32
|
+
*/
|
|
33
|
+
function createD1Dialect(database) {
|
|
34
|
+
return new D1Dialect({ database });
|
|
35
|
+
}
|
|
36
|
+
export function createSerializePlugin() {
|
|
37
|
+
return new SerializePlugin();
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAI,QAAoB,EAAa;IAC7D,OAAO,IAAI,MAAM,CAAI;QACnB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC;QAClC,OAAO,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;KACjC,CAAC,CAAC;AAAA,CACJ;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,QAAoB,EAAa;IACxD,OAAO,IAAI,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAAA,CACpC;AAED,MAAM,UAAU,qBAAqB,GAAoB;IACvD,OAAO,IAAI,eAAe,EAAE,CAAC;AAAA,CAC9B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@syncular/dialect-d1",
|
|
3
|
+
"version": "0.0.1-60",
|
|
4
|
+
"description": "Cloudflare D1 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-d1"
|
|
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
|
+
"cloudflare",
|
|
23
|
+
"d1",
|
|
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
|
+
"@cloudflare/workers-types": "*",
|
|
47
|
+
"@syncular/core": "0.0.1",
|
|
48
|
+
"kysely-d1": "^0.4.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"kysely": "^0.28.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@syncular/config": "0.0.0",
|
|
55
|
+
"kysely": "*"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist",
|
|
59
|
+
"src"
|
|
60
|
+
]
|
|
61
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @syncular/dialect-d1 - Cloudflare D1 dialect for sync
|
|
3
|
+
*
|
|
4
|
+
* Provides a Kysely dialect for Cloudflare D1 with SerializePlugin
|
|
5
|
+
* for automatic JSON serialization/deserialization.
|
|
6
|
+
* SQLite-compatible — use with @syncular/server-dialect-sqlite.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { D1Database } from '@cloudflare/workers-types';
|
|
10
|
+
import { SerializePlugin } from '@syncular/core';
|
|
11
|
+
import { Kysely } from 'kysely';
|
|
12
|
+
import { D1Dialect } from 'kysely-d1';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a Kysely instance with Cloudflare D1 dialect and SerializePlugin.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* export default {
|
|
19
|
+
* async fetch(request: Request, env: Env) {
|
|
20
|
+
* const db = createD1Db<MyDb>(env.DB);
|
|
21
|
+
* const dialect = createSqliteServerDialect();
|
|
22
|
+
* await ensureSyncSchema(db, dialect);
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* };
|
|
26
|
+
*/
|
|
27
|
+
export function createD1Db<T>(database: D1Database): Kysely<T> {
|
|
28
|
+
return new Kysely<T>({
|
|
29
|
+
dialect: createD1Dialect(database),
|
|
30
|
+
plugins: [new SerializePlugin()],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create the D1 dialect directly (without SerializePlugin).
|
|
36
|
+
*/
|
|
37
|
+
function createD1Dialect(database: D1Database): D1Dialect {
|
|
38
|
+
return new D1Dialect({ database });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createSerializePlugin(): SerializePlugin {
|
|
42
|
+
return new SerializePlugin();
|
|
43
|
+
}
|