@rawdash/adapter-sqlite 0.15.0

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/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @rawdash/adapter-sqlite
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@rawdash/adapter-sqlite)](https://www.npmjs.com/package/@rawdash/adapter-sqlite)
4
+ [![license](https://img.shields.io/npm/l/@rawdash/adapter-sqlite)](https://github.com/rawdash/rawdash/blob/main/LICENSE)
5
+
6
+ File-backed SQLite `ServerStorage` for rawdash. Designed for local OSS
7
+ development: drop a single file in `.rawdash/storage.sqlite`, survive dev
8
+ server restarts, never burn through API rate limits cold-starting on every
9
+ file change.
10
+
11
+ Internally a thin wrapper over [`@rawdash/adapter-libsql`](../libsql) pointed
12
+ at a local file via libSQL's `file:` URL scheme — same schema, same
13
+ migrations, same advisory-lock semantics.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ npm install @rawdash/adapter-sqlite
19
+ ```
20
+
21
+ ## Quick example
22
+
23
+ ```ts
24
+ import { serve as honoServe } from '@hono/node-server';
25
+ import { SqliteStorage } from '@rawdash/adapter-sqlite';
26
+ import { mountEngine } from '@rawdash/hono';
27
+
28
+ import config from './rawdash.config';
29
+
30
+ const storage = new SqliteStorage('.rawdash/storage.sqlite');
31
+
32
+ const { app } = mountEngine(config, { storage });
33
+ honoServe({ fetch: app.fetch, port: 8080 });
34
+ ```
35
+
36
+ The parent directory is created automatically. To opt out, pass
37
+ `{ ensureDir: false }`.
38
+
39
+ ## Resetting
40
+
41
+ Nuke the file (or its containing directory) to start fresh:
42
+
43
+ ```sh
44
+ rm -rf .rawdash
45
+ ```
46
+
47
+ ## License
48
+
49
+ Apache-2.0
@@ -0,0 +1,19 @@
1
+ import { ServerStorage, GetStorageHandleOptions, StorageHandle, SyncState } from '@rawdash/core';
2
+
3
+ interface SqliteStorageOptions {
4
+ ensureDir?: boolean;
5
+ }
6
+ declare class SqliteStorage implements ServerStorage {
7
+ private inner;
8
+ constructor(path: string, options?: SqliteStorageOptions);
9
+ waitUntilReady(): Promise<void>;
10
+ getStorageHandle(connectorId: string, options?: GetStorageHandleOptions): StorageHandle;
11
+ getSyncState(): Promise<SyncState>;
12
+ markSyncQueued(): Promise<boolean>;
13
+ markSyncRunning(): Promise<boolean>;
14
+ markSyncSucceeded(): Promise<void>;
15
+ markSyncFailed(error: string): Promise<void>;
16
+ close(): Promise<void>;
17
+ }
18
+
19
+ export { SqliteStorage, type SqliteStorageOptions };
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ // src/sqlite-storage.ts
2
+ import { createClient } from "@libsql/client";
3
+ import { LibsqlStorage } from "@rawdash/adapter-libsql";
4
+ import { mkdirSync } from "fs";
5
+ import { dirname, isAbsolute, resolve } from "path";
6
+ import { pathToFileURL } from "url";
7
+ function toFileUrl(path) {
8
+ if (path === ":memory:") {
9
+ return ":memory:";
10
+ }
11
+ const absolute = isAbsolute(path) ? path : resolve(process.cwd(), path);
12
+ return pathToFileURL(absolute).toString();
13
+ }
14
+ function makeClient(path, ensureDir) {
15
+ if (ensureDir && path !== ":memory:") {
16
+ const absolute = isAbsolute(path) ? path : resolve(process.cwd(), path);
17
+ mkdirSync(dirname(absolute), { recursive: true });
18
+ }
19
+ return createClient({ url: toFileUrl(path) });
20
+ }
21
+ var SqliteStorage = class {
22
+ inner;
23
+ constructor(path, options = {}) {
24
+ const ensureDir = options.ensureDir ?? true;
25
+ const client = makeClient(path, ensureDir);
26
+ this.inner = new LibsqlStorage({ client });
27
+ }
28
+ waitUntilReady() {
29
+ return this.inner.waitUntilReady();
30
+ }
31
+ getStorageHandle(connectorId, options) {
32
+ return this.inner.getStorageHandle(connectorId, options);
33
+ }
34
+ getSyncState() {
35
+ return this.inner.getSyncState();
36
+ }
37
+ markSyncQueued() {
38
+ return this.inner.markSyncQueued();
39
+ }
40
+ markSyncRunning() {
41
+ return this.inner.markSyncRunning();
42
+ }
43
+ markSyncSucceeded() {
44
+ return this.inner.markSyncSucceeded();
45
+ }
46
+ markSyncFailed(error) {
47
+ return this.inner.markSyncFailed(error);
48
+ }
49
+ close() {
50
+ return this.inner.close();
51
+ }
52
+ };
53
+ export {
54
+ SqliteStorage
55
+ };
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sqlite-storage.ts"],"sourcesContent":["import { type Client, createClient } from '@libsql/client';\nimport { LibsqlStorage } from '@rawdash/adapter-libsql';\nimport type {\n GetStorageHandleOptions,\n ServerStorage,\n StorageHandle,\n SyncState,\n} from '@rawdash/core';\nimport { mkdirSync } from 'node:fs';\nimport { dirname, isAbsolute, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nexport interface SqliteStorageOptions {\n ensureDir?: boolean;\n}\n\nfunction toFileUrl(path: string): string {\n if (path === ':memory:') {\n return ':memory:';\n }\n const absolute = isAbsolute(path) ? path : resolve(process.cwd(), path);\n return pathToFileURL(absolute).toString();\n}\n\nfunction makeClient(path: string, ensureDir: boolean): Client {\n if (ensureDir && path !== ':memory:') {\n const absolute = isAbsolute(path) ? path : resolve(process.cwd(), path);\n mkdirSync(dirname(absolute), { recursive: true });\n }\n return createClient({ url: toFileUrl(path) });\n}\n\nexport class SqliteStorage implements ServerStorage {\n private inner: LibsqlStorage;\n\n constructor(path: string, options: SqliteStorageOptions = {}) {\n const ensureDir = options.ensureDir ?? true;\n const client = makeClient(path, ensureDir);\n this.inner = new LibsqlStorage({ client });\n }\n\n waitUntilReady(): Promise<void> {\n return this.inner.waitUntilReady();\n }\n\n getStorageHandle(\n connectorId: string,\n options?: GetStorageHandleOptions,\n ): StorageHandle {\n return this.inner.getStorageHandle(connectorId, options);\n }\n\n getSyncState(): Promise<SyncState> {\n return this.inner.getSyncState();\n }\n\n markSyncQueued(): Promise<boolean> {\n return this.inner.markSyncQueued();\n }\n\n markSyncRunning(): Promise<boolean> {\n return this.inner.markSyncRunning();\n }\n\n markSyncSucceeded(): Promise<void> {\n return this.inner.markSyncSucceeded();\n }\n\n markSyncFailed(error: string): Promise<void> {\n return this.inner.markSyncFailed(error);\n }\n\n close(): Promise<void> {\n return this.inner.close();\n }\n}\n"],"mappings":";AAAA,SAAsB,oBAAoB;AAC1C,SAAS,qBAAqB;AAO9B,SAAS,iBAAiB;AAC1B,SAAS,SAAS,YAAY,eAAe;AAC7C,SAAS,qBAAqB;AAM9B,SAAS,UAAU,MAAsB;AACvC,MAAI,SAAS,YAAY;AACvB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,WAAW,IAAI,IAAI,OAAO,QAAQ,QAAQ,IAAI,GAAG,IAAI;AACtE,SAAO,cAAc,QAAQ,EAAE,SAAS;AAC1C;AAEA,SAAS,WAAW,MAAc,WAA4B;AAC5D,MAAI,aAAa,SAAS,YAAY;AACpC,UAAM,WAAW,WAAW,IAAI,IAAI,OAAO,QAAQ,QAAQ,IAAI,GAAG,IAAI;AACtE,cAAU,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAK,CAAC;AAAA,EAClD;AACA,SAAO,aAAa,EAAE,KAAK,UAAU,IAAI,EAAE,CAAC;AAC9C;AAEO,IAAM,gBAAN,MAA6C;AAAA,EAC1C;AAAA,EAER,YAAY,MAAc,UAAgC,CAAC,GAAG;AAC5D,UAAM,YAAY,QAAQ,aAAa;AACvC,UAAM,SAAS,WAAW,MAAM,SAAS;AACzC,SAAK,QAAQ,IAAI,cAAc,EAAE,OAAO,CAAC;AAAA,EAC3C;AAAA,EAEA,iBAAgC;AAC9B,WAAO,KAAK,MAAM,eAAe;AAAA,EACnC;AAAA,EAEA,iBACE,aACA,SACe;AACf,WAAO,KAAK,MAAM,iBAAiB,aAAa,OAAO;AAAA,EACzD;AAAA,EAEA,eAAmC;AACjC,WAAO,KAAK,MAAM,aAAa;AAAA,EACjC;AAAA,EAEA,iBAAmC;AACjC,WAAO,KAAK,MAAM,eAAe;AAAA,EACnC;AAAA,EAEA,kBAAoC;AAClC,WAAO,KAAK,MAAM,gBAAgB;AAAA,EACpC;AAAA,EAEA,oBAAmC;AACjC,WAAO,KAAK,MAAM,kBAAkB;AAAA,EACtC;AAAA,EAEA,eAAe,OAA8B;AAC3C,WAAO,KAAK,MAAM,eAAe,KAAK;AAAA,EACxC;AAAA,EAEA,QAAuB;AACrB,WAAO,KAAK,MAAM,MAAM;AAAA,EAC1B;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@rawdash/adapter-sqlite",
3
+ "version": "0.15.0",
4
+ "description": "Rawdash SQLite storage adapter for local development (file-backed, survives restarts)",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/rawdash/rawdash.git",
10
+ "directory": "packages/adapters/sqlite"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "@rawdash/source": "./src/index.ts",
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "typecheck": "tsc --noEmit",
27
+ "lint": "eslint src",
28
+ "test": "vitest run"
29
+ },
30
+ "dependencies": {
31
+ "@libsql/client": "^0.17.0",
32
+ "@rawdash/adapter-libsql": "workspace:*",
33
+ "@rawdash/core": "workspace:*"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^22.19.17",
37
+ "tsup": "^8.0.0",
38
+ "typescript": "^5.7.2",
39
+ "vitest": "^4.1.4"
40
+ }
41
+ }