@rawdash/adapter-libsql 0.5.0 → 0.6.1
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 +2 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ declare class LibsqlStorage implements ServerStorage {
|
|
|
22
22
|
close(): Promise<void>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
declare function migrateIfNeeded(client: Client): Promise<void>;
|
|
25
26
|
declare function applyMigrations(client: Client): Promise<void>;
|
|
26
27
|
|
|
27
28
|
interface BundledMigration {
|
|
@@ -30,4 +31,4 @@ interface BundledMigration {
|
|
|
30
31
|
}
|
|
31
32
|
declare const MIGRATIONS: readonly BundledMigration[];
|
|
32
33
|
|
|
33
|
-
export { type BundledMigration, LibsqlStorage, type LibsqlStorageOptions, MIGRATIONS, applyMigrations, initLibsqlSchema };
|
|
34
|
+
export { type BundledMigration, LibsqlStorage, type LibsqlStorageOptions, MIGRATIONS, applyMigrations, initLibsqlSchema, migrateIfNeeded };
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,23 @@ async function readAppliedTags(client) {
|
|
|
44
44
|
);
|
|
45
45
|
return new Set(result.rows.map((r) => String(r["tag"])));
|
|
46
46
|
}
|
|
47
|
+
async function migrateIfNeeded(client) {
|
|
48
|
+
const latest = MIGRATIONS[MIGRATIONS.length - 1];
|
|
49
|
+
if (latest === void 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const result = await client.execute({
|
|
54
|
+
sql: `SELECT 1 FROM ${SCHEMA_MIGRATIONS_TABLE} WHERE tag = ? LIMIT 1`,
|
|
55
|
+
args: [latest.tag]
|
|
56
|
+
});
|
|
57
|
+
if (result.rows.length > 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
await applyMigrations(client);
|
|
63
|
+
}
|
|
47
64
|
async function applyMigrations(client) {
|
|
48
65
|
const hadSchemaTable = await tableExists(client, SCHEMA_MIGRATIONS_TABLE);
|
|
49
66
|
await client.execute(
|
|
@@ -558,6 +575,7 @@ export {
|
|
|
558
575
|
LibsqlStorage,
|
|
559
576
|
MIGRATIONS,
|
|
560
577
|
applyMigrations,
|
|
561
|
-
initLibsqlSchema
|
|
578
|
+
initLibsqlSchema,
|
|
579
|
+
migrateIfNeeded
|
|
562
580
|
};
|
|
563
581
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/libsql-storage.ts","../src/migrations-bundle.ts","../src/migrate.ts"],"sourcesContent":["import type { Client, InValue } from '@libsql/client/web';\nimport type {\n Distribution,\n DistributionQuery,\n Edge,\n EdgeQuery,\n Entity,\n EntityQuery,\n Event,\n EventQuery,\n JSONValue,\n MetricQuery,\n MetricSample,\n ServerStorage,\n StorageHandle,\n SyncState,\n} from '@rawdash/core';\nimport { type CompiledQuery, type Insertable, Kysely } from 'kysely';\nimport { LibsqlDialect } from 'kysely-libsql';\n\nimport type {\n Database,\n EdgesTable,\n EntitiesTable,\n EventsTable,\n MetricsTable,\n} from './db-schema';\nimport { applyMigrations } from './migrate';\n\ntype Attrs = Record<string, JSONValue>;\n\nconst SYNC_STATE_ID = 1;\n\nexport async function initLibsqlSchema(client: Client): Promise<void> {\n await applyMigrations(client);\n await client.execute({\n sql: \"INSERT OR IGNORE INTO sync_state (id, status, last_sync_at, last_error) VALUES (?, 'idle', NULL, NULL)\",\n args: [SYNC_STATE_ID],\n });\n}\n\nfunction parseJson<T>(value: unknown, fallback: T): T {\n if (typeof value !== 'string') {\n return fallback;\n }\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction createDb(client: Client): Kysely<Database> {\n return new Kysely<Database>({\n dialect: new LibsqlDialect({ client }),\n });\n}\n\nfunction toBatchStmt(q: CompiledQuery): { sql: string; args: InValue[] } {\n return { sql: q.sql, args: q.parameters as InValue[] };\n}\n\nexport interface LibsqlStorageOptions {\n client: Client;\n initSchema?: boolean;\n}\n\nexport class LibsqlStorage implements ServerStorage {\n private client: Client;\n private db: Kysely<Database>;\n private ready: Promise<void>;\n private initError: string | null = null;\n\n constructor(options: LibsqlStorageOptions) {\n this.client = options.client;\n this.db = createDb(options.client);\n this.ready = options.initSchema === false ? Promise.resolve() : this.init();\n }\n\n private async init(): Promise<void> {\n try {\n await initLibsqlSchema(this.client);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n this.initError = `init failed: ${message}`;\n throw err;\n }\n }\n\n async waitUntilReady(): Promise<void> {\n return this.ready;\n }\n\n getStorageHandle(connectorId: string): StorageHandle {\n const ready = this.ready;\n const db = this.db;\n const client = this.client;\n\n const eventRow = (e: Event): Insertable<EventsTable> => ({\n connector_id: connectorId,\n name: e.name,\n start_ts: e.start_ts,\n end_ts: e.end_ts,\n attributes: JSON.stringify(e.attributes),\n });\n\n const entityRow = (e: Entity): Insertable<EntitiesTable> => ({\n connector_id: connectorId,\n type: e.type,\n id: e.id,\n attributes: JSON.stringify(e.attributes),\n updated_at: e.updated_at,\n });\n\n const metricRow = (m: MetricSample): Insertable<MetricsTable> => ({\n connector_id: connectorId,\n name: m.name,\n ts: m.ts,\n value: m.value,\n attributes: JSON.stringify(m.attributes),\n });\n\n const edgeRow = (e: Edge): Insertable<EdgesTable> => ({\n connector_id: connectorId,\n from_type: e.from_type,\n from_id: e.from_id,\n kind: e.kind,\n to_type: e.to_type,\n to_id: e.to_id,\n attributes: JSON.stringify(e.attributes),\n updated_at: e.updated_at,\n });\n\n const distributionRow = (d: Distribution) => ({\n connector_id: connectorId,\n name: d.name,\n ts: d.ts,\n kind: d.kind,\n data: JSON.stringify(d.data),\n attributes: JSON.stringify(d.attributes),\n });\n\n return {\n event: async (e) => {\n await ready;\n await db.insertInto('events').values(eventRow(e)).execute();\n },\n\n entity: async (e) => {\n await ready;\n await db\n .insertInto('entities')\n .values(entityRow(e))\n .onConflict((oc) =>\n oc.columns(['connector_id', 'type', 'id']).doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .execute();\n },\n\n metric: async (m) => {\n await ready;\n await db.insertInto('metrics').values(metricRow(m)).execute();\n },\n\n edge: async (e) => {\n await ready;\n await db\n .insertInto('edges')\n .values(edgeRow(e))\n .onConflict((oc) =>\n oc\n .columns([\n 'connector_id',\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n ])\n .doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .execute();\n },\n\n distribution: async (d) => {\n await ready;\n await db\n .insertInto('distributions')\n .values(distributionRow(d))\n .execute();\n },\n\n events: async (es, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? es.map((e) => e.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('events')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db.insertInto('events').values(es.map(eventRow)).compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n entities: async (es, scope) => {\n await ready;\n const types = Array.from(\n new Set(scope?.types ?? es.map((e) => e.type)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (types.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('entities')\n .where('connector_id', '=', connectorId)\n .where('type', 'in', types)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('entities')\n .values(es.map(entityRow))\n .onConflict((oc) =>\n oc.columns(['connector_id', 'type', 'id']).doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n metrics: async (ms, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? ms.map((m) => m.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('metrics')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (ms.length > 0) {\n stmts.push(\n toBatchStmt(\n db.insertInto('metrics').values(ms.map(metricRow)).compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n edges: async (es, scope) => {\n await ready;\n const kinds = Array.from(\n new Set(scope?.kinds ?? es.map((e) => e.kind)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (kinds.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('edges')\n .where('connector_id', '=', connectorId)\n .where('kind', 'in', kinds)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('edges')\n .values(es.map(edgeRow))\n .onConflict((oc) =>\n oc\n .columns([\n 'connector_id',\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n ])\n .doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n distributions: async (ds, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? ds.map((d) => d.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('distributions')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (ds.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('distributions')\n .values(ds.map(distributionRow))\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n queryEvents: async (q: EventQuery) => {\n await ready;\n let qb = db\n .selectFrom('events')\n .select(['name', 'start_ts', 'end_ts', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('start_ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('start_ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): Event => ({\n name: r.name,\n start_ts: Number(r.start_ts),\n end_ts: r.end_ts === null ? null : Number(r.end_ts),\n attributes: parseJson<Attrs>(r.attributes, {}),\n }),\n );\n },\n\n getEntity: async (type, id) => {\n await ready;\n const r = await db\n .selectFrom('entities')\n .select(['type', 'id', 'attributes', 'updated_at'])\n .where('connector_id', '=', connectorId)\n .where('type', '=', type)\n .where('id', '=', id)\n .limit(1)\n .executeTakeFirst();\n if (!r) {\n return null;\n }\n return {\n type: r.type,\n id: r.id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n };\n },\n\n queryEntities: async (q: EntityQuery) => {\n await ready;\n const rows = await db\n .selectFrom('entities')\n .select(['type', 'id', 'attributes', 'updated_at'])\n .where('connector_id', '=', connectorId)\n .where('type', '=', q.type)\n .execute();\n return rows.map(\n (r): Entity => ({\n type: r.type,\n id: r.id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n }),\n );\n },\n\n queryMetrics: async (q: MetricQuery) => {\n await ready;\n let qb = db\n .selectFrom('metrics')\n .select(['name', 'ts', 'value', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): MetricSample => ({\n name: r.name,\n ts: Number(r.ts),\n value: Number(r.value),\n attributes: parseJson<Attrs>(r.attributes, {}),\n }),\n );\n },\n\n traverse: async (q: EdgeQuery) => {\n await ready;\n let qb = db\n .selectFrom('edges')\n .select([\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n 'attributes',\n 'updated_at',\n ])\n .where('connector_id', '=', connectorId);\n if (q.fromType !== undefined) {\n qb = qb.where('from_type', '=', q.fromType);\n }\n if (q.fromId !== undefined) {\n qb = qb.where('from_id', '=', q.fromId);\n }\n if (q.kind !== undefined) {\n qb = qb.where('kind', '=', q.kind);\n }\n if (q.toType !== undefined) {\n qb = qb.where('to_type', '=', q.toType);\n }\n if (q.toId !== undefined) {\n qb = qb.where('to_id', '=', q.toId);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): Edge => ({\n from_type: r.from_type,\n from_id: r.from_id,\n kind: r.kind,\n to_type: r.to_type,\n to_id: r.to_id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n }),\n );\n },\n\n queryDistributions: async (q: DistributionQuery) => {\n await ready;\n let qb = db\n .selectFrom('distributions')\n .select(['name', 'ts', 'kind', 'data', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map((r) => {\n const base = {\n name: r.name,\n ts: Number(r.ts),\n attributes: parseJson<Attrs>(r.attributes, {}),\n };\n const data = parseJson<Distribution['data']>(r.data, {\n count: 0,\n sum: 0,\n } as unknown as Distribution['data']);\n if (r.kind === 'histogram') {\n return { ...base, kind: 'histogram', data } as Distribution;\n }\n if (r.kind === 'summary') {\n return { ...base, kind: 'summary', data } as Distribution;\n }\n throw new Error(\n `Unknown distribution kind: ${r.kind} (name=${base.name})`,\n );\n });\n },\n\n deleteOlderThan: async (shape, tsUnixMs) => {\n await ready;\n if (shape === 'events') {\n const r = await db\n .deleteFrom('events')\n .where('connector_id', '=', connectorId)\n .where('start_ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n if (shape === 'metrics') {\n const r = await db\n .deleteFrom('metrics')\n .where('connector_id', '=', connectorId)\n .where('ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n if (shape === 'distributions') {\n const r = await db\n .deleteFrom('distributions')\n .where('connector_id', '=', connectorId)\n .where('ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n throw new Error(\n `Unsupported shape for deleteOlderThan: ${String(shape)}`,\n );\n },\n };\n }\n\n async getSyncState(): Promise<SyncState> {\n if (this.initError !== null) {\n return { status: 'error', lastSyncAt: null, lastError: this.initError };\n }\n await this.ready;\n const r = await this.db\n .selectFrom('sync_state')\n .select(['status', 'last_sync_at', 'last_error'])\n .where('id', '=', SYNC_STATE_ID)\n .limit(1)\n .executeTakeFirst();\n if (!r) {\n return { status: 'idle', lastSyncAt: null, lastError: null };\n }\n return {\n status: r.status as SyncState['status'],\n lastSyncAt: r.last_sync_at,\n lastError: r.last_error,\n };\n }\n\n async setSyncing(): Promise<boolean> {\n await this.ready;\n const r = await this.db\n .updateTable('sync_state')\n .set({ status: 'syncing' })\n .where('id', '=', SYNC_STATE_ID)\n .where('status', '!=', 'syncing')\n .executeTakeFirst();\n return Number(r.numUpdatedRows) > 0;\n }\n\n async setSyncSuccess(): Promise<void> {\n await this.ready;\n await this.db\n .updateTable('sync_state')\n .set({\n status: 'idle',\n last_sync_at: new Date().toISOString(),\n last_error: null,\n })\n .where('id', '=', SYNC_STATE_ID)\n .execute();\n }\n\n async setSyncError(error: string): Promise<void> {\n await this.ready;\n await this.db\n .updateTable('sync_state')\n .set({ status: 'error', last_error: error })\n .where('id', '=', SYNC_STATE_ID)\n .execute();\n }\n\n async close(): Promise<void> {\n await this.ready.catch(() => undefined);\n this.client.close();\n }\n}\n","// AUTO-GENERATED by scripts/bundle-migrations.mjs — do not edit by hand.\n// Regenerate with: pnpm db:bundle (or pnpm db:generate).\n\nexport interface BundledMigration {\n tag: string;\n statements: string[];\n}\n\nexport const MIGRATIONS: readonly BundledMigration[] = [\n {\n tag: '0000_nosy_wendell_vaughn',\n statements: [\n \"CREATE TABLE `distributions` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`ts` integer NOT NULL,\\n\\t`kind` text NOT NULL,\\n\\t`data` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `distributions_conn_name_ts` ON `distributions` (`connector_id`,`name`,`ts`);',\n \"CREATE TABLE `edges` (\\n\\t`connector_id` text NOT NULL,\\n\\t`from_type` text NOT NULL,\\n\\t`from_id` text NOT NULL,\\n\\t`kind` text NOT NULL,\\n\\t`to_type` text NOT NULL,\\n\\t`to_id` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL,\\n\\t`updated_at` integer NOT NULL,\\n\\tPRIMARY KEY(`connector_id`, `from_type`, `from_id`, `kind`, `to_type`, `to_id`)\\n);\",\n 'CREATE INDEX `edges_conn_kind` ON `edges` (`connector_id`,`kind`);',\n 'CREATE INDEX `edges_conn_from` ON `edges` (`connector_id`,`from_type`,`from_id`);',\n \"CREATE TABLE `entities` (\\n\\t`connector_id` text NOT NULL,\\n\\t`type` text NOT NULL,\\n\\t`id` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL,\\n\\t`updated_at` integer NOT NULL,\\n\\tPRIMARY KEY(`connector_id`, `type`, `id`)\\n);\",\n 'CREATE INDEX `entities_conn_type` ON `entities` (`connector_id`,`type`);',\n \"CREATE TABLE `events` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`start_ts` integer NOT NULL,\\n\\t`end_ts` integer,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `events_conn_name_start` ON `events` (`connector_id`,`name`,`start_ts`);',\n \"CREATE TABLE `metrics` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`ts` integer NOT NULL,\\n\\t`value` real NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `metrics_conn_name_ts` ON `metrics` (`connector_id`,`name`,`ts`);',\n ],\n },\n {\n tag: '0001_clumsy_siren',\n statements: [\n 'CREATE TABLE `sync_state` (\\n\\t`id` integer PRIMARY KEY NOT NULL,\\n\\t`status` text NOT NULL,\\n\\t`last_sync_at` text,\\n\\t`last_error` text\\n);',\n ],\n },\n] as const;\n","import type { Client, InStatement } from '@libsql/client/web';\n\nimport { MIGRATIONS } from './migrations-bundle';\n\nconst SCHEMA_MIGRATIONS_TABLE = 'schema_migrations';\n\nconst LEGACY_BASELINE_TABLE = 'events';\n\nasync function tableExists(client: Client, name: string): Promise<boolean> {\n const result = await client.execute({\n sql: \"SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1\",\n args: [name],\n });\n return result.rows.length > 0;\n}\n\nasync function readAppliedTags(client: Client): Promise<Set<string>> {\n const result = await client.execute(\n `SELECT tag FROM ${SCHEMA_MIGRATIONS_TABLE}`,\n );\n return new Set(result.rows.map((r) => String(r['tag'])));\n}\n\nexport async function applyMigrations(client: Client): Promise<void> {\n const hadSchemaTable = await tableExists(client, SCHEMA_MIGRATIONS_TABLE);\n\n await client.execute(\n `CREATE TABLE IF NOT EXISTS ${SCHEMA_MIGRATIONS_TABLE} (\n tag TEXT PRIMARY KEY,\n applied_at INTEGER NOT NULL\n )`,\n );\n\n if (!hadSchemaTable) {\n const hasLegacySchema = await tableExists(client, LEGACY_BASELINE_TABLE);\n if (hasLegacySchema) {\n const now = Date.now();\n for (const migration of MIGRATIONS) {\n await client.execute({\n sql: `INSERT OR IGNORE INTO ${SCHEMA_MIGRATIONS_TABLE} (tag, applied_at) VALUES (?, ?)`,\n args: [migration.tag, now],\n });\n }\n return;\n }\n }\n\n let applied = await readAppliedTags(client);\n\n for (const migration of MIGRATIONS) {\n if (applied.has(migration.tag)) {\n continue;\n }\n const batch: InStatement[] = [\n {\n sql: `INSERT INTO ${SCHEMA_MIGRATIONS_TABLE} (tag, applied_at) VALUES (?, ?)`,\n args: [migration.tag, Date.now()],\n },\n ...migration.statements,\n ];\n try {\n await client.batch(batch, 'write');\n } catch (err) {\n applied = await readAppliedTags(client);\n if (!applied.has(migration.tag)) {\n throw err;\n }\n }\n }\n}\n"],"mappings":";AAiBA,SAA8C,cAAc;AAC5D,SAAS,qBAAqB;;;ACVvB,IAAM,aAA0C;AAAA,EACrD;AAAA,IACE,KAAK;AAAA,IACL,YAAY;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,YAAY;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;;;AC3BA,IAAM,0BAA0B;AAEhC,IAAM,wBAAwB;AAE9B,eAAe,YAAY,QAAgB,MAAgC;AACzE,QAAM,SAAS,MAAM,OAAO,QAAQ;AAAA,IAClC,KAAK;AAAA,IACL,MAAM,CAAC,IAAI;AAAA,EACb,CAAC;AACD,SAAO,OAAO,KAAK,SAA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E,QAAQ,QAAQ,YAAY,MAAM,WAAW,KAAK;AAAA,IAC7D;AACA,WAAO;AAAA,MACL,QAAQ,EAAE;AAAA,MACV,YAAY,EAAE;AAAA,MACd,WAAW,EAAE;AAAA,IACf;AAAA,EACF;AAAA,EAEA,MAAM,aAA+B;AACnC,UAAM,KAAK;AACX,UAAM,IAAI,MAAM,KAAK,GAClB,YAAY,YAAY,EACxB,IAAI,EAAE,QAAQ,UAAU,CAAC,EACzB,MAAM,MAAM,KAAK,aAAa,EAC9B,MAAM,UAAU,MAAM,SAAS,EAC/B,iBAAiB;AACpB,WAAO,OAAO,EAAE,cAAc,IAAI;AAAA,EACpC;AAAA,EAEA,MAAM,iBAAgC;AACpC,UAAM,KAAK;AACX,UAAM,KAAK,GACR,YAAY,YAAY,EACxB,IAAI;AAAA,MACH,QAAQ;AAAA,MACR,eAAc,oBAAI,KAAK,GAAE,YAAY;AAAA,MACrC,YAAY;AAAA,IACd,CAAC,EACA,MAAM,MAAM,KAAK,aAAa,EAC9B,QAAQ;AAAA,EACb;AAAA,EAEA,MAAM,aAAa,OAA8B;AAC/C,UAAM,KAAK;AACX,UAAM,KAAK,GACR,YAAY,YAAY,EACxB,IAAI,EAAE,QAAQ,SAAS,YAAY,MAAM,CAAC,EAC1C,MAAM,MAAM,KAAK,aAAa,EAC9B,QAAQ;AAAA,EACb;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK,MAAM,MAAM,MAAM,MAAS;AACtC,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/libsql-storage.ts","../src/migrations-bundle.ts","../src/migrate.ts"],"sourcesContent":["import type { Client, InValue } from '@libsql/client/web';\nimport type {\n Distribution,\n DistributionQuery,\n Edge,\n EdgeQuery,\n Entity,\n EntityQuery,\n Event,\n EventQuery,\n JSONValue,\n MetricQuery,\n MetricSample,\n ServerStorage,\n StorageHandle,\n SyncState,\n} from '@rawdash/core';\nimport { type CompiledQuery, type Insertable, Kysely } from 'kysely';\nimport { LibsqlDialect } from 'kysely-libsql';\n\nimport type {\n Database,\n EdgesTable,\n EntitiesTable,\n EventsTable,\n MetricsTable,\n} from './db-schema';\nimport { applyMigrations } from './migrate';\n\ntype Attrs = Record<string, JSONValue>;\n\nconst SYNC_STATE_ID = 1;\n\nexport async function initLibsqlSchema(client: Client): Promise<void> {\n await applyMigrations(client);\n await client.execute({\n sql: \"INSERT OR IGNORE INTO sync_state (id, status, last_sync_at, last_error) VALUES (?, 'idle', NULL, NULL)\",\n args: [SYNC_STATE_ID],\n });\n}\n\nfunction parseJson<T>(value: unknown, fallback: T): T {\n if (typeof value !== 'string') {\n return fallback;\n }\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction createDb(client: Client): Kysely<Database> {\n return new Kysely<Database>({\n dialect: new LibsqlDialect({ client }),\n });\n}\n\nfunction toBatchStmt(q: CompiledQuery): { sql: string; args: InValue[] } {\n return { sql: q.sql, args: q.parameters as InValue[] };\n}\n\nexport interface LibsqlStorageOptions {\n client: Client;\n initSchema?: boolean;\n}\n\nexport class LibsqlStorage implements ServerStorage {\n private client: Client;\n private db: Kysely<Database>;\n private ready: Promise<void>;\n private initError: string | null = null;\n\n constructor(options: LibsqlStorageOptions) {\n this.client = options.client;\n this.db = createDb(options.client);\n this.ready = options.initSchema === false ? Promise.resolve() : this.init();\n }\n\n private async init(): Promise<void> {\n try {\n await initLibsqlSchema(this.client);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n this.initError = `init failed: ${message}`;\n throw err;\n }\n }\n\n async waitUntilReady(): Promise<void> {\n return this.ready;\n }\n\n getStorageHandle(connectorId: string): StorageHandle {\n const ready = this.ready;\n const db = this.db;\n const client = this.client;\n\n const eventRow = (e: Event): Insertable<EventsTable> => ({\n connector_id: connectorId,\n name: e.name,\n start_ts: e.start_ts,\n end_ts: e.end_ts,\n attributes: JSON.stringify(e.attributes),\n });\n\n const entityRow = (e: Entity): Insertable<EntitiesTable> => ({\n connector_id: connectorId,\n type: e.type,\n id: e.id,\n attributes: JSON.stringify(e.attributes),\n updated_at: e.updated_at,\n });\n\n const metricRow = (m: MetricSample): Insertable<MetricsTable> => ({\n connector_id: connectorId,\n name: m.name,\n ts: m.ts,\n value: m.value,\n attributes: JSON.stringify(m.attributes),\n });\n\n const edgeRow = (e: Edge): Insertable<EdgesTable> => ({\n connector_id: connectorId,\n from_type: e.from_type,\n from_id: e.from_id,\n kind: e.kind,\n to_type: e.to_type,\n to_id: e.to_id,\n attributes: JSON.stringify(e.attributes),\n updated_at: e.updated_at,\n });\n\n const distributionRow = (d: Distribution) => ({\n connector_id: connectorId,\n name: d.name,\n ts: d.ts,\n kind: d.kind,\n data: JSON.stringify(d.data),\n attributes: JSON.stringify(d.attributes),\n });\n\n return {\n event: async (e) => {\n await ready;\n await db.insertInto('events').values(eventRow(e)).execute();\n },\n\n entity: async (e) => {\n await ready;\n await db\n .insertInto('entities')\n .values(entityRow(e))\n .onConflict((oc) =>\n oc.columns(['connector_id', 'type', 'id']).doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .execute();\n },\n\n metric: async (m) => {\n await ready;\n await db.insertInto('metrics').values(metricRow(m)).execute();\n },\n\n edge: async (e) => {\n await ready;\n await db\n .insertInto('edges')\n .values(edgeRow(e))\n .onConflict((oc) =>\n oc\n .columns([\n 'connector_id',\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n ])\n .doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .execute();\n },\n\n distribution: async (d) => {\n await ready;\n await db\n .insertInto('distributions')\n .values(distributionRow(d))\n .execute();\n },\n\n events: async (es, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? es.map((e) => e.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('events')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db.insertInto('events').values(es.map(eventRow)).compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n entities: async (es, scope) => {\n await ready;\n const types = Array.from(\n new Set(scope?.types ?? es.map((e) => e.type)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (types.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('entities')\n .where('connector_id', '=', connectorId)\n .where('type', 'in', types)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('entities')\n .values(es.map(entityRow))\n .onConflict((oc) =>\n oc.columns(['connector_id', 'type', 'id']).doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n metrics: async (ms, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? ms.map((m) => m.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('metrics')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (ms.length > 0) {\n stmts.push(\n toBatchStmt(\n db.insertInto('metrics').values(ms.map(metricRow)).compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n edges: async (es, scope) => {\n await ready;\n const kinds = Array.from(\n new Set(scope?.kinds ?? es.map((e) => e.kind)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (kinds.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('edges')\n .where('connector_id', '=', connectorId)\n .where('kind', 'in', kinds)\n .compile(),\n ),\n );\n }\n if (es.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('edges')\n .values(es.map(edgeRow))\n .onConflict((oc) =>\n oc\n .columns([\n 'connector_id',\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n ])\n .doUpdateSet({\n attributes: (eb) => eb.ref('excluded.attributes'),\n updated_at: (eb) => eb.ref('excluded.updated_at'),\n }),\n )\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n distributions: async (ds, scope) => {\n await ready;\n const names = Array.from(\n new Set(scope?.names ?? ds.map((d) => d.name)),\n );\n const stmts: { sql: string; args: InValue[] }[] = [];\n if (names.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .deleteFrom('distributions')\n .where('connector_id', '=', connectorId)\n .where('name', 'in', names)\n .compile(),\n ),\n );\n }\n if (ds.length > 0) {\n stmts.push(\n toBatchStmt(\n db\n .insertInto('distributions')\n .values(ds.map(distributionRow))\n .compile(),\n ),\n );\n }\n if (stmts.length > 0) {\n await client.batch(stmts, 'write');\n }\n },\n\n queryEvents: async (q: EventQuery) => {\n await ready;\n let qb = db\n .selectFrom('events')\n .select(['name', 'start_ts', 'end_ts', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('start_ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('start_ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): Event => ({\n name: r.name,\n start_ts: Number(r.start_ts),\n end_ts: r.end_ts === null ? null : Number(r.end_ts),\n attributes: parseJson<Attrs>(r.attributes, {}),\n }),\n );\n },\n\n getEntity: async (type, id) => {\n await ready;\n const r = await db\n .selectFrom('entities')\n .select(['type', 'id', 'attributes', 'updated_at'])\n .where('connector_id', '=', connectorId)\n .where('type', '=', type)\n .where('id', '=', id)\n .limit(1)\n .executeTakeFirst();\n if (!r) {\n return null;\n }\n return {\n type: r.type,\n id: r.id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n };\n },\n\n queryEntities: async (q: EntityQuery) => {\n await ready;\n const rows = await db\n .selectFrom('entities')\n .select(['type', 'id', 'attributes', 'updated_at'])\n .where('connector_id', '=', connectorId)\n .where('type', '=', q.type)\n .execute();\n return rows.map(\n (r): Entity => ({\n type: r.type,\n id: r.id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n }),\n );\n },\n\n queryMetrics: async (q: MetricQuery) => {\n await ready;\n let qb = db\n .selectFrom('metrics')\n .select(['name', 'ts', 'value', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): MetricSample => ({\n name: r.name,\n ts: Number(r.ts),\n value: Number(r.value),\n attributes: parseJson<Attrs>(r.attributes, {}),\n }),\n );\n },\n\n traverse: async (q: EdgeQuery) => {\n await ready;\n let qb = db\n .selectFrom('edges')\n .select([\n 'from_type',\n 'from_id',\n 'kind',\n 'to_type',\n 'to_id',\n 'attributes',\n 'updated_at',\n ])\n .where('connector_id', '=', connectorId);\n if (q.fromType !== undefined) {\n qb = qb.where('from_type', '=', q.fromType);\n }\n if (q.fromId !== undefined) {\n qb = qb.where('from_id', '=', q.fromId);\n }\n if (q.kind !== undefined) {\n qb = qb.where('kind', '=', q.kind);\n }\n if (q.toType !== undefined) {\n qb = qb.where('to_type', '=', q.toType);\n }\n if (q.toId !== undefined) {\n qb = qb.where('to_id', '=', q.toId);\n }\n const rows = await qb.execute();\n return rows.map(\n (r): Edge => ({\n from_type: r.from_type,\n from_id: r.from_id,\n kind: r.kind,\n to_type: r.to_type,\n to_id: r.to_id,\n attributes: parseJson<Attrs>(r.attributes, {}),\n updated_at: Number(r.updated_at),\n }),\n );\n },\n\n queryDistributions: async (q: DistributionQuery) => {\n await ready;\n let qb = db\n .selectFrom('distributions')\n .select(['name', 'ts', 'kind', 'data', 'attributes'])\n .where('connector_id', '=', connectorId);\n if (q.name !== undefined) {\n qb = qb.where('name', '=', q.name);\n }\n if (q.start !== undefined) {\n qb = qb.where('ts', '>=', q.start);\n }\n if (q.end !== undefined) {\n qb = qb.where('ts', '<=', q.end);\n }\n const rows = await qb.execute();\n return rows.map((r) => {\n const base = {\n name: r.name,\n ts: Number(r.ts),\n attributes: parseJson<Attrs>(r.attributes, {}),\n };\n const data = parseJson<Distribution['data']>(r.data, {\n count: 0,\n sum: 0,\n } as unknown as Distribution['data']);\n if (r.kind === 'histogram') {\n return { ...base, kind: 'histogram', data } as Distribution;\n }\n if (r.kind === 'summary') {\n return { ...base, kind: 'summary', data } as Distribution;\n }\n throw new Error(\n `Unknown distribution kind: ${r.kind} (name=${base.name})`,\n );\n });\n },\n\n deleteOlderThan: async (shape, tsUnixMs) => {\n await ready;\n if (shape === 'events') {\n const r = await db\n .deleteFrom('events')\n .where('connector_id', '=', connectorId)\n .where('start_ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n if (shape === 'metrics') {\n const r = await db\n .deleteFrom('metrics')\n .where('connector_id', '=', connectorId)\n .where('ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n if (shape === 'distributions') {\n const r = await db\n .deleteFrom('distributions')\n .where('connector_id', '=', connectorId)\n .where('ts', '<', tsUnixMs)\n .executeTakeFirst();\n return { rowsDeleted: Number(r.numDeletedRows) };\n }\n throw new Error(\n `Unsupported shape for deleteOlderThan: ${String(shape)}`,\n );\n },\n };\n }\n\n async getSyncState(): Promise<SyncState> {\n if (this.initError !== null) {\n return { status: 'error', lastSyncAt: null, lastError: this.initError };\n }\n await this.ready;\n const r = await this.db\n .selectFrom('sync_state')\n .select(['status', 'last_sync_at', 'last_error'])\n .where('id', '=', SYNC_STATE_ID)\n .limit(1)\n .executeTakeFirst();\n if (!r) {\n return { status: 'idle', lastSyncAt: null, lastError: null };\n }\n return {\n status: r.status as SyncState['status'],\n lastSyncAt: r.last_sync_at,\n lastError: r.last_error,\n };\n }\n\n async setSyncing(): Promise<boolean> {\n await this.ready;\n const r = await this.db\n .updateTable('sync_state')\n .set({ status: 'syncing' })\n .where('id', '=', SYNC_STATE_ID)\n .where('status', '!=', 'syncing')\n .executeTakeFirst();\n return Number(r.numUpdatedRows) > 0;\n }\n\n async setSyncSuccess(): Promise<void> {\n await this.ready;\n await this.db\n .updateTable('sync_state')\n .set({\n status: 'idle',\n last_sync_at: new Date().toISOString(),\n last_error: null,\n })\n .where('id', '=', SYNC_STATE_ID)\n .execute();\n }\n\n async setSyncError(error: string): Promise<void> {\n await this.ready;\n await this.db\n .updateTable('sync_state')\n .set({ status: 'error', last_error: error })\n .where('id', '=', SYNC_STATE_ID)\n .execute();\n }\n\n async close(): Promise<void> {\n await this.ready.catch(() => undefined);\n this.client.close();\n }\n}\n","// AUTO-GENERATED by scripts/bundle-migrations.mjs — do not edit by hand.\n// Regenerate with: pnpm db:bundle (or pnpm db:generate).\n\nexport interface BundledMigration {\n tag: string;\n statements: string[];\n}\n\nexport const MIGRATIONS: readonly BundledMigration[] = [\n {\n tag: '0000_nosy_wendell_vaughn',\n statements: [\n \"CREATE TABLE `distributions` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`ts` integer NOT NULL,\\n\\t`kind` text NOT NULL,\\n\\t`data` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `distributions_conn_name_ts` ON `distributions` (`connector_id`,`name`,`ts`);',\n \"CREATE TABLE `edges` (\\n\\t`connector_id` text NOT NULL,\\n\\t`from_type` text NOT NULL,\\n\\t`from_id` text NOT NULL,\\n\\t`kind` text NOT NULL,\\n\\t`to_type` text NOT NULL,\\n\\t`to_id` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL,\\n\\t`updated_at` integer NOT NULL,\\n\\tPRIMARY KEY(`connector_id`, `from_type`, `from_id`, `kind`, `to_type`, `to_id`)\\n);\",\n 'CREATE INDEX `edges_conn_kind` ON `edges` (`connector_id`,`kind`);',\n 'CREATE INDEX `edges_conn_from` ON `edges` (`connector_id`,`from_type`,`from_id`);',\n \"CREATE TABLE `entities` (\\n\\t`connector_id` text NOT NULL,\\n\\t`type` text NOT NULL,\\n\\t`id` text NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL,\\n\\t`updated_at` integer NOT NULL,\\n\\tPRIMARY KEY(`connector_id`, `type`, `id`)\\n);\",\n 'CREATE INDEX `entities_conn_type` ON `entities` (`connector_id`,`type`);',\n \"CREATE TABLE `events` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`start_ts` integer NOT NULL,\\n\\t`end_ts` integer,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `events_conn_name_start` ON `events` (`connector_id`,`name`,`start_ts`);',\n \"CREATE TABLE `metrics` (\\n\\t`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\\n\\t`connector_id` text NOT NULL,\\n\\t`name` text NOT NULL,\\n\\t`ts` integer NOT NULL,\\n\\t`value` real NOT NULL,\\n\\t`attributes` text DEFAULT '{}' NOT NULL\\n);\",\n 'CREATE INDEX `metrics_conn_name_ts` ON `metrics` (`connector_id`,`name`,`ts`);',\n ],\n },\n {\n tag: '0001_clumsy_siren',\n statements: [\n 'CREATE TABLE `sync_state` (\\n\\t`id` integer PRIMARY KEY NOT NULL,\\n\\t`status` text NOT NULL,\\n\\t`last_sync_at` text,\\n\\t`last_error` text\\n);',\n ],\n },\n] as const;\n","import type { Client, InStatement } from '@libsql/client/web';\n\nimport { MIGRATIONS } from './migrations-bundle';\n\nconst SCHEMA_MIGRATIONS_TABLE = 'schema_migrations';\n\nconst LEGACY_BASELINE_TABLE = 'events';\n\nasync function tableExists(client: Client, name: string): Promise<boolean> {\n const result = await client.execute({\n sql: \"SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1\",\n args: [name],\n });\n return result.rows.length > 0;\n}\n\nasync function readAppliedTags(client: Client): Promise<Set<string>> {\n const result = await client.execute(\n `SELECT tag FROM ${SCHEMA_MIGRATIONS_TABLE}`,\n );\n return new Set(result.rows.map((r) => String(r['tag'])));\n}\n\nexport async function migrateIfNeeded(client: Client): Promise<void> {\n const latest = MIGRATIONS[MIGRATIONS.length - 1];\n if (latest === undefined) {\n return;\n }\n try {\n const result = await client.execute({\n sql: `SELECT 1 FROM ${SCHEMA_MIGRATIONS_TABLE} WHERE tag = ? LIMIT 1`,\n args: [latest.tag],\n });\n if (result.rows.length > 0) {\n return;\n }\n } catch {\n // schema_migrations table doesn't exist yet — fall through to apply.\n }\n await applyMigrations(client);\n}\n\nexport async function applyMigrations(client: Client): Promise<void> {\n const hadSchemaTable = await tableExists(client, SCHEMA_MIGRATIONS_TABLE);\n\n await client.execute(\n `CREATE TABLE IF NOT EXISTS ${SCHEMA_MIGRATIONS_TABLE} (\n tag TEXT PRIMARY KEY,\n applied_at INTEGER NOT NULL\n )`,\n );\n\n if (!hadSchemaTable) {\n const hasLegacySchema = await tableExists(client, LEGACY_BASELINE_TABLE);\n if (hasLegacySchema) {\n const now = Date.now();\n for (const migration of MIGRATIONS) {\n await client.execute({\n sql: `INSERT OR IGNORE INTO ${SCHEMA_MIGRATIONS_TABLE} (tag, applied_at) VALUES (?, ?)`,\n args: [migration.tag, now],\n });\n }\n return;\n }\n }\n\n let applied = await readAppliedTags(client);\n\n for (const migration of MIGRATIONS) {\n if (applied.has(migration.tag)) {\n continue;\n }\n const batch: InStatement[] = [\n {\n sql: `INSERT INTO ${SCHEMA_MIGRATIONS_TABLE} (tag, applied_at) VALUES (?, ?)`,\n args: [migration.tag, Date.now()],\n },\n ...migration.statements,\n ];\n try {\n await client.batch(batch, 'write');\n } catch (err) {\n applied = await readAppliedTags(client);\n if (!applied.has(migration.tag)) {\n throw err;\n }\n }\n }\n}\n"],"mappings":";AAiBA,SAA8C,cAAc;AAC5D,SAAS,qBAAqB;;;ACVvB,IAAM,aAA0C;AAAA,EACrD;AAAA,IACE,KAAK;AAAA,IACL,YAAY;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,YAAY;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;;;AC3BA,IAAM,0BAA0B;AAEhC,IAAM,wBAAwB;AAE9B,eAAe,YAAY,QAAgB,MAAgC;AACzE,QAAM,SAAS,MAAM,OAAO,QAAQ;AAAA,IAClC,KAAK;AAAA,IACL,MAAM,CAAC,IAAI;AAAA,EACb,CAAC;AACD,SAAO,OAAO,KAAK,SAAS;AAC9B;AAEA,eAAe,gBAAgB,QAAsC;AACnE,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B,mBAAmB,uBAAuB;AAAA,EAC5C;AACA,SAAO,IAAI,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AACzD;AAEA,eAAsB,gBAAgB,QAA+B;AACnE,QAAM,SAAS,WAAW,WAAW,SAAS,CAAC;AAC/C,MAAI,WAAW,QAAW;AACxB;AAAA,EACF;AACA,MAAI;AACF,UAAM,SAAS,MAAM,OAAO,QAAQ;AAAA,MAClC,KAAK,iBAAiB,uBAAuB;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AAK;AAAA,IAC7D;AACA,WAAO;AAAA,MACL,QAAQ,EAAE;AAAA,MACV,YAAY,EAAE;AAAA,MACd,WAAW,EAAE;AAAA,IACf;AAAA,EACF;AAAA,EAEA,MAAM,aAA+B;AACnC,UAAM,KAAK;AACX,UAAM,IAAI,MAAM,KAAK,GAClB,YAAY,YAAY,EACxB,IAAI,EAAE,QAAQ,UAAU,CAAC,EACzB,MAAM,MAAM,KAAK,aAAa,EAC9B,MAAM,UAAU,MAAM,SAAS,EAC/B,iBAAiB;AACpB,WAAO,OAAO,EAAE,cAAc,IAAI;AAAA,EACpC;AAAA,EAEA,MAAM,iBAAgC;AACpC,UAAM,KAAK;AACX,UAAM,KAAK,GACR,YAAY,YAAY,EACxB,IAAI;AAAA,MACH,QAAQ;AAAA,MACR,eAAc,oBAAI,KAAK,GAAE,YAAY;AAAA,MACrC,YAAY;AAAA,IACd,CAAC,EACA,MAAM,MAAM,KAAK,aAAa,EAC9B,QAAQ;AAAA,EACb;AAAA,EAEA,MAAM,aAAa,OAA8B;AAC/C,UAAM,KAAK;AACX,UAAM,KAAK,GACR,YAAY,YAAY,EACxB,IAAI,EAAE,QAAQ,SAAS,YAAY,MAAM,CAAC,EAC1C,MAAM,MAAM,KAAK,aAAa,EAC9B,QAAQ;AAAA,EACb;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK,MAAM,MAAM,MAAM,MAAS;AACtC,SAAK,OAAO,MAAM;AAAA,EACpB;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rawdash/adapter-libsql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Rawdash libSQL/Turso storage adapter",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"kysely": "^0.29.0",
|
|
27
27
|
"kysely-libsql": "^0.7.0",
|
|
28
|
-
"@rawdash/core": "0.
|
|
28
|
+
"@rawdash/core": "0.6.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@libsql/client": ">=0.14.0 <1.0.0"
|