or3-provider-sqlite 0.0.4 → 0.0.6
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 +112 -19
- package/dist/module.json +1 -1
- package/dist/runtime/server/admin/adapters/sync-sqlite.js +90 -16
- package/dist/runtime/server/admin/stores/sqlite-store.js +7 -8
- package/dist/runtime/server/auth/sqlite-auth-workspace-store.d.ts +5 -0
- package/dist/runtime/server/auth/sqlite-auth-workspace-store.js +368 -40
- package/dist/runtime/server/connect/sqlite-connect-store.js +19 -5
- package/dist/runtime/server/db/d1-dialect.d.ts +39 -0
- package/dist/runtime/server/db/d1-dialect.js +70 -0
- package/dist/runtime/server/db/d1.d.ts +13 -0
- package/dist/runtime/server/db/d1.js +30 -0
- package/dist/runtime/server/db/kysely.d.ts +53 -15
- package/dist/runtime/server/db/kysely.js +374 -16
- package/dist/runtime/server/db/migrate.js +3 -1
- package/dist/runtime/server/db/migrations/016_connect_runtime_binding.d.ts +4 -0
- package/dist/runtime/server/db/migrations/016_connect_runtime_binding.js +28 -0
- package/dist/runtime/server/db/schema.d.ts +3 -0
- package/dist/runtime/server/plugins/register.js +33 -13
- package/dist/runtime/server/rate-limit/sqlite-provider.d.ts +2 -0
- package/dist/runtime/server/rate-limit/sqlite-provider.js +70 -1
- package/dist/runtime/server/sync/maintenance-state.d.ts +26 -0
- package/dist/runtime/server/sync/maintenance-state.js +66 -0
- package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.d.ts +15 -4
- package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.js +780 -21
- package/dist/runtime/server/webhooks/sqlite-webhook-store.d.ts +3 -2
- package/dist/runtime/server/webhooks/sqlite-webhook-store.js +90 -39
- package/package.json +10 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
1
|
import type { WebhookStore } from '~~/server/utils/webhooks/store/types';
|
|
3
|
-
type
|
|
2
|
+
import { type SqliteRawDatabase } from '../db/kysely.js';
|
|
3
|
+
type SqliteDatabase = SqliteRawDatabase;
|
|
4
4
|
export interface SqliteWebhookStoreOptions {
|
|
5
5
|
database?: SqliteDatabase;
|
|
6
|
+
/** @deprecated Initialize the shared SQLite provider instead. */
|
|
6
7
|
path?: string;
|
|
7
8
|
}
|
|
8
9
|
export declare function createSqliteWebhookStore(options?: SqliteWebhookStoreOptions): WebhookStore;
|
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
7
|
-
}
|
|
8
|
-
function resolveDatabasePath() {
|
|
9
|
-
const isTestEnv = process.env.NODE_ENV === "test" || envFlag(process.env.VITEST);
|
|
10
|
-
const allowInMemory = envFlag(process.env.OR3_SQLITE_ALLOW_IN_MEMORY);
|
|
11
|
-
const strictMode = envFlag(process.env.OR3_SQLITE_STRICT);
|
|
12
|
-
const configuredPath = process.env.OR3_SQLITE_DB_PATH;
|
|
13
|
-
const path = configuredPath ?? ":memory:";
|
|
14
|
-
if (!configuredPath && !isTestEnv && !allowInMemory) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
"OR3_SQLITE_DB_PATH is required in non-test environments. Set OR3_SQLITE_ALLOW_IN_MEMORY=true only if you intentionally want ephemeral storage."
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
if (strictMode && path === ":memory:") {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"OR3_SQLITE_STRICT=true forbids in-memory SQLite. Set OR3_SQLITE_DB_PATH to a persistent file path."
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
if (!isTestEnv && path === ":memory:" && allowInMemory) {
|
|
25
|
-
console.warn(
|
|
26
|
-
"[webhooks:sqlite] OR3_SQLITE_ALLOW_IN_MEMORY=true enabled. Data will be lost on process restart."
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return path;
|
|
30
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
getRawDb,
|
|
3
|
+
getSqliteDriver,
|
|
4
|
+
initializeSqliteDb
|
|
5
|
+
} from "../db/kysely.js";
|
|
31
6
|
function parseStringArray(raw) {
|
|
32
7
|
try {
|
|
33
8
|
const parsed = JSON.parse(raw);
|
|
@@ -79,10 +54,12 @@ class SqliteWebhookStore {
|
|
|
79
54
|
this.initialize();
|
|
80
55
|
}
|
|
81
56
|
initialize() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
if (getSqliteDriver() !== "turso") {
|
|
58
|
+
this.db.pragma?.("journal_mode = WAL");
|
|
59
|
+
this.db.pragma?.("synchronous = NORMAL");
|
|
60
|
+
this.db.pragma?.("foreign_keys = ON");
|
|
61
|
+
}
|
|
62
|
+
this.db.exec?.(`
|
|
86
63
|
CREATE TABLE IF NOT EXISTS webhook_registrations (
|
|
87
64
|
id TEXT PRIMARY KEY,
|
|
88
65
|
scope TEXT NOT NULL CHECK (scope IN ('user', 'admin')),
|
|
@@ -136,7 +113,7 @@ class SqliteWebhookStore {
|
|
|
136
113
|
CREATE INDEX IF NOT EXISTS idx_webhook_custom_hooks_hook_name
|
|
137
114
|
ON webhook_custom_hooks (hook_name);
|
|
138
115
|
`);
|
|
139
|
-
this.db.exec(`
|
|
116
|
+
this.db.exec?.(`
|
|
140
117
|
INSERT OR IGNORE INTO webhook_custom_hooks (webhook_id, hook_name)
|
|
141
118
|
SELECT wr.id, json_each.value
|
|
142
119
|
FROM webhook_registrations AS wr,
|
|
@@ -153,7 +130,7 @@ class SqliteWebhookStore {
|
|
|
153
130
|
const now = Date.now();
|
|
154
131
|
const row = {
|
|
155
132
|
...webhook,
|
|
156
|
-
id: randomUUID(),
|
|
133
|
+
id: globalThis.crypto.randomUUID(),
|
|
157
134
|
health: "unknown",
|
|
158
135
|
created_at: now,
|
|
159
136
|
updated_at: now
|
|
@@ -357,7 +334,7 @@ class SqliteWebhookStore {
|
|
|
357
334
|
async createDeliveryLog(log) {
|
|
358
335
|
const row = {
|
|
359
336
|
...log,
|
|
360
|
-
id: randomUUID()
|
|
337
|
+
id: globalThis.crypto.randomUUID()
|
|
361
338
|
};
|
|
362
339
|
this.db.prepare(
|
|
363
340
|
`
|
|
@@ -515,7 +492,81 @@ class SqliteWebhookStore {
|
|
|
515
492
|
return result.changes;
|
|
516
493
|
}
|
|
517
494
|
}
|
|
495
|
+
class LazySqliteWebhookStore {
|
|
496
|
+
constructor(store) {
|
|
497
|
+
this.store = store;
|
|
498
|
+
}
|
|
499
|
+
createWebhook(webhook) {
|
|
500
|
+
return this.store.then((store) => store.createWebhook(webhook));
|
|
501
|
+
}
|
|
502
|
+
updateWebhook(webhookId, patch) {
|
|
503
|
+
return this.store.then((store) => store.updateWebhook(webhookId, patch));
|
|
504
|
+
}
|
|
505
|
+
deleteWebhook(webhookId) {
|
|
506
|
+
return this.store.then((store) => store.deleteWebhook(webhookId));
|
|
507
|
+
}
|
|
508
|
+
getWebhook(webhookId) {
|
|
509
|
+
return this.store.then((store) => store.getWebhook(webhookId));
|
|
510
|
+
}
|
|
511
|
+
listWebhooks(userId, workspaceId) {
|
|
512
|
+
return this.store.then((store) => store.listWebhooks(userId, workspaceId));
|
|
513
|
+
}
|
|
514
|
+
listAdminWebhooks() {
|
|
515
|
+
return this.store.then((store) => store.listAdminWebhooks());
|
|
516
|
+
}
|
|
517
|
+
listWebhooksByEvent(eventType, scope, workspaceId) {
|
|
518
|
+
return this.store.then(
|
|
519
|
+
(store) => store.listWebhooksByEvent(eventType, scope, workspaceId)
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
listWebhooksByCustomHook(hookName) {
|
|
523
|
+
return this.store.then((store) => store.listWebhooksByCustomHook(hookName));
|
|
524
|
+
}
|
|
525
|
+
listActiveCustomHookNames() {
|
|
526
|
+
return this.store.then((store) => store.listActiveCustomHookNames());
|
|
527
|
+
}
|
|
528
|
+
updateWebhookHealth(webhookId, health) {
|
|
529
|
+
return this.store.then((store) => store.updateWebhookHealth(webhookId, health));
|
|
530
|
+
}
|
|
531
|
+
disableAllWebhooks(userId, workspaceId) {
|
|
532
|
+
return this.store.then((store) => store.disableAllWebhooks(userId, workspaceId));
|
|
533
|
+
}
|
|
534
|
+
createDeliveryLog(log) {
|
|
535
|
+
return this.store.then((store) => store.createDeliveryLog(log));
|
|
536
|
+
}
|
|
537
|
+
updateDeliveryLog(logId, patch) {
|
|
538
|
+
return this.store.then((store) => store.updateDeliveryLog(logId, patch));
|
|
539
|
+
}
|
|
540
|
+
getDeliveryLogs(webhookId, since) {
|
|
541
|
+
return this.store.then((store) => store.getDeliveryLogs(webhookId, since));
|
|
542
|
+
}
|
|
543
|
+
getRecentTerminalDeliveries(webhookId, limit) {
|
|
544
|
+
return this.store.then(
|
|
545
|
+
(store) => store.getRecentTerminalDeliveries(webhookId, limit)
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
claimPendingDeliveries(workerId, limit) {
|
|
549
|
+
return this.store.then((store) => store.claimPendingDeliveries(workerId, limit));
|
|
550
|
+
}
|
|
551
|
+
resetStaleInFlightDeliveries(olderThanMs) {
|
|
552
|
+
return this.store.then(
|
|
553
|
+
(store) => store.resetStaleInFlightDeliveries(olderThanMs)
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
cancelDeliveriesByWebhook(webhookId) {
|
|
557
|
+
return this.store.then((store) => store.cancelDeliveriesByWebhook(webhookId));
|
|
558
|
+
}
|
|
559
|
+
deleteDeliveryLogsByWebhook(webhookId) {
|
|
560
|
+
return this.store.then((store) => store.deleteDeliveryLogsByWebhook(webhookId));
|
|
561
|
+
}
|
|
562
|
+
purgeExpiredLogs(beforeTimestamp) {
|
|
563
|
+
return this.store.then((store) => store.purgeExpiredLogs(beforeTimestamp));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
518
566
|
export function createSqliteWebhookStore(options = {}) {
|
|
519
|
-
|
|
520
|
-
|
|
567
|
+
if (options.database) return new SqliteWebhookStore(options.database);
|
|
568
|
+
const dbOptions = options.path ? { path: options.path } : void 0;
|
|
569
|
+
return new LazySqliteWebhookStore(
|
|
570
|
+
initializeSqliteDb(dbOptions).then(() => new SqliteWebhookStore(getRawDb()))
|
|
571
|
+
);
|
|
521
572
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "or3-provider-sqlite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/Saluana/or3-provider-sqlite.git"
|
|
@@ -34,18 +34,22 @@
|
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
36
|
"prepack": "bun run build",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
"build": "nuxt-module-build build",
|
|
38
|
+
"lint": "eslint src --max-warnings 0",
|
|
39
|
+
"type-check": "tsc --noEmit",
|
|
40
|
+
"type-check:standalone": "tsc -p tsconfig.release.json --noEmit",
|
|
41
|
+
"test": "vitest run"
|
|
41
42
|
},
|
|
42
43
|
"publishConfig": {
|
|
43
44
|
"access": "public"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"better-sqlite3": "^12.6.2",
|
|
47
47
|
"kysely": "^0.28.11"
|
|
48
48
|
},
|
|
49
|
+
"optionalDependencies": {
|
|
50
|
+
"better-sqlite3": "^13.0.3",
|
|
51
|
+
"libsql": "^0.5.29"
|
|
52
|
+
},
|
|
49
53
|
"peerDependencies": {
|
|
50
54
|
"@nuxt/kit": "^3.0.0 || ^4.0.0",
|
|
51
55
|
"nuxt": "^3.0.0 || ^4.0.0"
|