@korajs/tauri 0.0.0-canary-20261008174129

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dr. Obed Ehoneah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ TauriAdapterError: () => TauriAdapterError,
34
+ TauriSqliteAdapter: () => TauriSqliteAdapter,
35
+ TauriStoreNotOpenError: () => TauriStoreNotOpenError
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/tauri-sqlite-adapter.ts
40
+ var import_core = require("@korajs/core");
41
+ var TauriAdapterError = class extends Error {
42
+ code;
43
+ context;
44
+ constructor(message, context) {
45
+ super(message);
46
+ this.name = "TauriAdapterError";
47
+ this.code = "TAURI_ADAPTER_ERROR";
48
+ this.context = context;
49
+ }
50
+ };
51
+ var TauriStoreNotOpenError = class extends Error {
52
+ code;
53
+ constructor() {
54
+ super("Store is not open. Call adapter.open() before performing operations.");
55
+ this.name = "TauriStoreNotOpenError";
56
+ this.code = "STORE_NOT_OPEN";
57
+ }
58
+ };
59
+ var AsyncMutex = class {
60
+ queue = [];
61
+ locked = false;
62
+ async acquire() {
63
+ if (!this.locked) {
64
+ this.locked = true;
65
+ return () => this.release();
66
+ }
67
+ return new Promise((resolve) => {
68
+ this.queue.push(() => {
69
+ resolve(() => this.release());
70
+ });
71
+ });
72
+ }
73
+ release() {
74
+ const next = this.queue.shift();
75
+ if (next) {
76
+ next();
77
+ } else {
78
+ this.locked = false;
79
+ }
80
+ }
81
+ };
82
+ async function resolveDefaultInvoke() {
83
+ try {
84
+ const { invoke } = await import("@tauri-apps/api/core");
85
+ return invoke;
86
+ } catch {
87
+ throw new TauriAdapterError(
88
+ "Failed to import @tauri-apps/api/core. Ensure @tauri-apps/api is installed and you are running inside a Tauri application."
89
+ );
90
+ }
91
+ }
92
+ var PLUGIN_PREFIX = "plugin:kora-sqlite|";
93
+ var TauriSqliteAdapter = class {
94
+ opened = false;
95
+ invoker;
96
+ dbPath;
97
+ txMutex = new AsyncMutex();
98
+ inTransaction = false;
99
+ constructor(options) {
100
+ this.dbPath = options?.path ?? "kora.db";
101
+ this.invoker = options?.invoke ?? null;
102
+ }
103
+ async getInvoke() {
104
+ if (!this.invoker) {
105
+ this.invoker = await resolveDefaultInvoke();
106
+ }
107
+ return this.invoker;
108
+ }
109
+ async invoke(cmd, args) {
110
+ const invokeFn = await this.getInvoke();
111
+ return invokeFn(`${PLUGIN_PREFIX}${cmd}`, args);
112
+ }
113
+ /**
114
+ * Open or create the database. Generates DDL from the schema and sends it
115
+ * to the Rust plugin for execution. The plugin configures WAL mode,
116
+ * foreign keys, and other pragmas before running the DDL.
117
+ */
118
+ async open(schema) {
119
+ const statements = (0, import_core.generateFullDDL)(schema);
120
+ await this.invoke("open", { path: this.dbPath, statements });
121
+ this.opened = true;
122
+ }
123
+ /**
124
+ * Close the database and release resources.
125
+ */
126
+ async close() {
127
+ if (this.opened) {
128
+ await this.invoke("close", { path: this.dbPath });
129
+ this.opened = false;
130
+ }
131
+ }
132
+ /**
133
+ * Execute a write query (INSERT, UPDATE, DELETE).
134
+ */
135
+ async execute(sql, params) {
136
+ this.ensureOpen();
137
+ try {
138
+ await this.invoke("execute", {
139
+ path: this.dbPath,
140
+ sql,
141
+ params: params ?? []
142
+ });
143
+ } catch (error) {
144
+ throw new TauriAdapterError(`Execute failed: ${error.message}`, {
145
+ sql,
146
+ params
147
+ });
148
+ }
149
+ }
150
+ /**
151
+ * Execute a read query (SELECT).
152
+ */
153
+ async query(sql, params) {
154
+ this.ensureOpen();
155
+ try {
156
+ return await this.invoke("query", {
157
+ path: this.dbPath,
158
+ sql,
159
+ params: params ?? []
160
+ });
161
+ } catch (error) {
162
+ throw new TauriAdapterError(`Query failed: ${error.message}`, {
163
+ sql,
164
+ params
165
+ });
166
+ }
167
+ }
168
+ /**
169
+ * Execute multiple operations atomically within a transaction.
170
+ *
171
+ * Uses a mutex to prevent interleaving of concurrent transactions.
172
+ * The transaction is committed on success or rolled back on error.
173
+ */
174
+ async transaction(fn) {
175
+ this.ensureOpen();
176
+ const release = await this.txMutex.acquire();
177
+ try {
178
+ this.inTransaction = true;
179
+ await this.invoke("execute", { path: this.dbPath, sql: "BEGIN", params: [] });
180
+ try {
181
+ const tx = {
182
+ execute: async (sql, params) => {
183
+ try {
184
+ await this.invoke("execute", {
185
+ path: this.dbPath,
186
+ sql,
187
+ params: params ?? []
188
+ });
189
+ } catch (error) {
190
+ throw new TauriAdapterError(
191
+ `Transaction execute failed: ${error.message}`,
192
+ { sql, params }
193
+ );
194
+ }
195
+ },
196
+ query: async (sql, params) => {
197
+ try {
198
+ return await this.invoke("query", {
199
+ path: this.dbPath,
200
+ sql,
201
+ params: params ?? []
202
+ });
203
+ } catch (error) {
204
+ throw new TauriAdapterError(`Transaction query failed: ${error.message}`, {
205
+ sql,
206
+ params
207
+ });
208
+ }
209
+ }
210
+ };
211
+ await fn(tx);
212
+ await this.invoke("execute", { path: this.dbPath, sql: "COMMIT", params: [] });
213
+ } catch (error) {
214
+ try {
215
+ await this.invoke("execute", { path: this.dbPath, sql: "ROLLBACK", params: [] });
216
+ } catch {
217
+ }
218
+ throw error;
219
+ }
220
+ } finally {
221
+ this.inTransaction = false;
222
+ release();
223
+ }
224
+ }
225
+ /**
226
+ * Apply a schema migration within a transaction.
227
+ */
228
+ async migrate(from, to, migration) {
229
+ this.ensureOpen();
230
+ try {
231
+ await this.invoke("migrate", {
232
+ path: this.dbPath,
233
+ statements: migration.statements
234
+ });
235
+ } catch (error) {
236
+ throw new TauriAdapterError(
237
+ `Migration from v${from} to v${to} failed: ${error.message}`,
238
+ { from, to }
239
+ );
240
+ }
241
+ }
242
+ ensureOpen() {
243
+ if (!this.opened) {
244
+ throw new TauriStoreNotOpenError();
245
+ }
246
+ }
247
+ };
248
+ // Annotate the CommonJS export names for ESM import in node:
249
+ 0 && (module.exports = {
250
+ TauriAdapterError,
251
+ TauriSqliteAdapter,
252
+ TauriStoreNotOpenError
253
+ });
254
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/tauri-sqlite-adapter.ts"],"sourcesContent":["export {\n\tTauriSqliteAdapter,\n\tTauriAdapterError,\n\tTauriStoreNotOpenError,\n\ttype TauriSqliteOptions,\n\ttype InvokeFn,\n\ttype StorageAdapter,\n\ttype Transaction,\n\ttype MigrationPlan,\n} from './tauri-sqlite-adapter'\n","import { generateFullDDL } from '@korajs/core'\nimport type { SchemaDefinition } from '@korajs/core'\n\n/**\n * Transaction interface for executing multiple operations atomically.\n * Mirrors @korajs/store's Transaction type to avoid a runtime dependency.\n */\nexport interface Transaction {\n\texecute(sql: string, params?: unknown[]): Promise<void>\n\tquery<T>(sql: string, params?: unknown[]): Promise<T[]>\n}\n\n/**\n * Migration plan containing SQL statements and optional data transforms.\n * Mirrors @korajs/store's MigrationPlan type.\n */\nexport interface MigrationPlan {\n\tstatements: string[]\n\ttransforms?: Array<(row: Record<string, unknown>) => Record<string, unknown>>\n}\n\n/**\n * Storage adapter interface. Mirrors @korajs/store's StorageAdapter.\n * Redeclared here to avoid a runtime dependency on @korajs/store.\n */\nexport interface StorageAdapter {\n\topen(schema: SchemaDefinition): Promise<void>\n\tclose(): Promise<void>\n\texecute(sql: string, params?: unknown[]): Promise<void>\n\tquery<T>(sql: string, params?: unknown[]): Promise<T[]>\n\ttransaction(fn: (tx: Transaction) => Promise<void>): Promise<void>\n\tmigrate(from: number, to: number, migration: MigrationPlan): Promise<void>\n}\n\n/**\n * Function signature for Tauri's invoke IPC call.\n * Matches `invoke` from `@tauri-apps/api/core`.\n */\nexport type InvokeFn = <T>(cmd: string, args?: Record<string, unknown>) => Promise<T>\n\n/**\n * Configuration options for the Tauri SQLite adapter.\n */\nexport interface TauriSqliteOptions {\n\t/**\n\t * Database file path relative to the app's data directory.\n\t * Defaults to 'kora.db'.\n\t */\n\tpath?: string\n\n\t/**\n\t * Custom invoke function. Defaults to Tauri's `invoke` from `@tauri-apps/api/core`.\n\t * Useful for testing — inject a mock invoke to test without a Tauri runtime.\n\t */\n\tinvoke?: InvokeFn\n}\n\n/**\n * Thrown when a storage adapter operation fails in the Tauri plugin.\n */\nexport class TauriAdapterError extends Error {\n\tpublic readonly code: string\n\tpublic readonly context?: Record<string, unknown>\n\n\tconstructor(message: string, context?: Record<string, unknown>) {\n\t\tsuper(message)\n\t\tthis.name = 'TauriAdapterError'\n\t\tthis.code = 'TAURI_ADAPTER_ERROR'\n\t\tthis.context = context\n\t}\n}\n\n/**\n * Thrown when an operation is attempted on an adapter that has not been opened.\n */\nexport class TauriStoreNotOpenError extends Error {\n\tpublic readonly code: string\n\n\tconstructor() {\n\t\tsuper('Store is not open. Call adapter.open() before performing operations.')\n\t\tthis.name = 'TauriStoreNotOpenError'\n\t\tthis.code = 'STORE_NOT_OPEN'\n\t}\n}\n\n// Mutex for serializing transactions over async IPC\nclass AsyncMutex {\n\tprivate queue: Array<() => void> = []\n\tprivate locked = false\n\n\tasync acquire(): Promise<() => void> {\n\t\tif (!this.locked) {\n\t\t\tthis.locked = true\n\t\t\treturn () => this.release()\n\t\t}\n\t\treturn new Promise<() => void>((resolve) => {\n\t\t\tthis.queue.push(() => {\n\t\t\t\tresolve(() => this.release())\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate release(): void {\n\t\tconst next = this.queue.shift()\n\t\tif (next) {\n\t\t\tnext()\n\t\t} else {\n\t\t\tthis.locked = false\n\t\t}\n\t}\n}\n\n/**\n * Resolves the default Tauri invoke function by dynamically importing `@tauri-apps/api/core`.\n * Returns null if not in a Tauri environment.\n */\nasync function resolveDefaultInvoke(): Promise<InvokeFn> {\n\ttry {\n\t\tconst { invoke } = await import('@tauri-apps/api/core')\n\t\treturn invoke as InvokeFn\n\t} catch {\n\t\tthrow new TauriAdapterError(\n\t\t\t'Failed to import @tauri-apps/api/core. Ensure @tauri-apps/api is installed and you are running inside a Tauri application.',\n\t\t)\n\t}\n}\n\nconst PLUGIN_PREFIX = 'plugin:kora-sqlite|'\n\n/**\n * Storage adapter backed by native SQLite via a Tauri plugin.\n *\n * Uses Tauri IPC to communicate with the `tauri-plugin-kora` Rust plugin,\n * which provides native SQLite access with WAL mode, foreign keys, and\n * proper connection management — zero WASM overhead.\n *\n * @example\n * ```typescript\n * import { TauriSqliteAdapter } from '@korajs/tauri'\n *\n * const adapter = new TauriSqliteAdapter({ path: 'my-app.db' })\n * ```\n *\n * @example\n * ```typescript\n * // With createApp (auto-detected in Tauri environments)\n * import { createApp, defineSchema, t } from 'korajs'\n *\n * const app = createApp({\n * schema: defineSchema({\n * version: 1,\n * collections: {\n * todos: { fields: { title: t.string(), completed: t.boolean().default(false) } }\n * }\n * })\n * })\n * ```\n */\nexport class TauriSqliteAdapter implements StorageAdapter {\n\tprivate opened = false\n\tprivate invoker: InvokeFn | null\n\tprivate readonly dbPath: string\n\tprivate readonly txMutex = new AsyncMutex()\n\tprivate inTransaction = false\n\n\tconstructor(options?: TauriSqliteOptions) {\n\t\tthis.dbPath = options?.path ?? 'kora.db'\n\t\tthis.invoker = options?.invoke ?? null\n\t}\n\n\tprivate async getInvoke(): Promise<InvokeFn> {\n\t\tif (!this.invoker) {\n\t\t\tthis.invoker = await resolveDefaultInvoke()\n\t\t}\n\t\treturn this.invoker\n\t}\n\n\tprivate async invoke<T>(cmd: string, args?: Record<string, unknown>): Promise<T> {\n\t\tconst invokeFn = await this.getInvoke()\n\t\treturn invokeFn<T>(`${PLUGIN_PREFIX}${cmd}`, args)\n\t}\n\n\t/**\n\t * Open or create the database. Generates DDL from the schema and sends it\n\t * to the Rust plugin for execution. The plugin configures WAL mode,\n\t * foreign keys, and other pragmas before running the DDL.\n\t */\n\tasync open(schema: SchemaDefinition): Promise<void> {\n\t\tconst statements = generateFullDDL(schema)\n\t\tawait this.invoke('open', { path: this.dbPath, statements })\n\t\tthis.opened = true\n\t}\n\n\t/**\n\t * Close the database and release resources.\n\t */\n\tasync close(): Promise<void> {\n\t\tif (this.opened) {\n\t\t\tawait this.invoke('close', { path: this.dbPath })\n\t\t\tthis.opened = false\n\t\t}\n\t}\n\n\t/**\n\t * Execute a write query (INSERT, UPDATE, DELETE).\n\t */\n\tasync execute(sql: string, params?: unknown[]): Promise<void> {\n\t\tthis.ensureOpen()\n\t\ttry {\n\t\t\tawait this.invoke('execute', {\n\t\t\t\tpath: this.dbPath,\n\t\t\t\tsql,\n\t\t\t\tparams: params ?? [],\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tthrow new TauriAdapterError(`Execute failed: ${(error as Error).message}`, {\n\t\t\t\tsql,\n\t\t\t\tparams,\n\t\t\t})\n\t\t}\n\t}\n\n\t/**\n\t * Execute a read query (SELECT).\n\t */\n\tasync query<T>(sql: string, params?: unknown[]): Promise<T[]> {\n\t\tthis.ensureOpen()\n\t\ttry {\n\t\t\treturn await this.invoke<T[]>('query', {\n\t\t\t\tpath: this.dbPath,\n\t\t\t\tsql,\n\t\t\t\tparams: params ?? [],\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tthrow new TauriAdapterError(`Query failed: ${(error as Error).message}`, {\n\t\t\t\tsql,\n\t\t\t\tparams,\n\t\t\t})\n\t\t}\n\t}\n\n\t/**\n\t * Execute multiple operations atomically within a transaction.\n\t *\n\t * Uses a mutex to prevent interleaving of concurrent transactions.\n\t * The transaction is committed on success or rolled back on error.\n\t */\n\tasync transaction(fn: (tx: Transaction) => Promise<void>): Promise<void> {\n\t\tthis.ensureOpen()\n\t\tconst release = await this.txMutex.acquire()\n\t\ttry {\n\t\t\tthis.inTransaction = true\n\t\t\tawait this.invoke('execute', { path: this.dbPath, sql: 'BEGIN', params: [] })\n\t\t\ttry {\n\t\t\t\tconst tx: Transaction = {\n\t\t\t\t\texecute: async (sql: string, params?: unknown[]): Promise<void> => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.invoke('execute', {\n\t\t\t\t\t\t\t\tpath: this.dbPath,\n\t\t\t\t\t\t\t\tsql,\n\t\t\t\t\t\t\t\tparams: params ?? [],\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tthrow new TauriAdapterError(\n\t\t\t\t\t\t\t\t`Transaction execute failed: ${(error as Error).message}`,\n\t\t\t\t\t\t\t\t{ sql, params },\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tquery: async <T>(sql: string, params?: unknown[]): Promise<T[]> => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await this.invoke<T[]>('query', {\n\t\t\t\t\t\t\t\tpath: this.dbPath,\n\t\t\t\t\t\t\t\tsql,\n\t\t\t\t\t\t\t\tparams: params ?? [],\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tthrow new TauriAdapterError(`Transaction query failed: ${(error as Error).message}`, {\n\t\t\t\t\t\t\t\tsql,\n\t\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tawait fn(tx)\n\t\t\t\tawait this.invoke('execute', { path: this.dbPath, sql: 'COMMIT', params: [] })\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.invoke('execute', { path: this.dbPath, sql: 'ROLLBACK', params: [] })\n\t\t\t\t} catch {\n\t\t\t\t\t// Rollback failed — connection may be in a bad state, but we still throw the original error\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.inTransaction = false\n\t\t\trelease()\n\t\t}\n\t}\n\n\t/**\n\t * Apply a schema migration within a transaction.\n\t */\n\tasync migrate(from: number, to: number, migration: MigrationPlan): Promise<void> {\n\t\tthis.ensureOpen()\n\t\ttry {\n\t\t\tawait this.invoke('migrate', {\n\t\t\t\tpath: this.dbPath,\n\t\t\t\tstatements: migration.statements,\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tthrow new TauriAdapterError(\n\t\t\t\t`Migration from v${from} to v${to} failed: ${(error as Error).message}`,\n\t\t\t\t{ from, to },\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate ensureOpen(): void {\n\t\tif (!this.opened) {\n\t\t\tthrow new TauriStoreNotOpenError()\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAgC;AA4DzB,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC5B;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,SAAmC;AAC/D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,UAAU;AAAA,EAChB;AACD;AAKO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACjC;AAAA,EAEhB,cAAc;AACb,UAAM,sEAAsE;AAC5E,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACb;AACD;AAGA,IAAM,aAAN,MAAiB;AAAA,EACR,QAA2B,CAAC;AAAA,EAC5B,SAAS;AAAA,EAEjB,MAAM,UAA+B;AACpC,QAAI,CAAC,KAAK,QAAQ;AACjB,WAAK,SAAS;AACd,aAAO,MAAM,KAAK,QAAQ;AAAA,IAC3B;AACA,WAAO,IAAI,QAAoB,CAAC,YAAY;AAC3C,WAAK,MA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EACD;AACD;","names":[]}
@@ -0,0 +1,136 @@
1
+ import { SchemaDefinition } from '@korajs/core';
2
+
3
+ /**
4
+ * Transaction interface for executing multiple operations atomically.
5
+ * Mirrors @korajs/store's Transaction type to avoid a runtime dependency.
6
+ */
7
+ interface Transaction {
8
+ execute(sql: string, params?: unknown[]): Promise<void>;
9
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
10
+ }
11
+ /**
12
+ * Migration plan containing SQL statements and optional data transforms.
13
+ * Mirrors @korajs/store's MigrationPlan type.
14
+ */
15
+ interface MigrationPlan {
16
+ statements: string[];
17
+ transforms?: Array<(row: Record<string, unknown>) => Record<string, unknown>>;
18
+ }
19
+ /**
20
+ * Storage adapter interface. Mirrors @korajs/store's StorageAdapter.
21
+ * Redeclared here to avoid a runtime dependency on @korajs/store.
22
+ */
23
+ interface StorageAdapter {
24
+ open(schema: SchemaDefinition): Promise<void>;
25
+ close(): Promise<void>;
26
+ execute(sql: string, params?: unknown[]): Promise<void>;
27
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
28
+ transaction(fn: (tx: Transaction) => Promise<void>): Promise<void>;
29
+ migrate(from: number, to: number, migration: MigrationPlan): Promise<void>;
30
+ }
31
+ /**
32
+ * Function signature for Tauri's invoke IPC call.
33
+ * Matches `invoke` from `@tauri-apps/api/core`.
34
+ */
35
+ type InvokeFn = <T>(cmd: string, args?: Record<string, unknown>) => Promise<T>;
36
+ /**
37
+ * Configuration options for the Tauri SQLite adapter.
38
+ */
39
+ interface TauriSqliteOptions {
40
+ /**
41
+ * Database file path relative to the app's data directory.
42
+ * Defaults to 'kora.db'.
43
+ */
44
+ path?: string;
45
+ /**
46
+ * Custom invoke function. Defaults to Tauri's `invoke` from `@tauri-apps/api/core`.
47
+ * Useful for testing — inject a mock invoke to test without a Tauri runtime.
48
+ */
49
+ invoke?: InvokeFn;
50
+ }
51
+ /**
52
+ * Thrown when a storage adapter operation fails in the Tauri plugin.
53
+ */
54
+ declare class TauriAdapterError extends Error {
55
+ readonly code: string;
56
+ readonly context?: Record<string, unknown>;
57
+ constructor(message: string, context?: Record<string, unknown>);
58
+ }
59
+ /**
60
+ * Thrown when an operation is attempted on an adapter that has not been opened.
61
+ */
62
+ declare class TauriStoreNotOpenError extends Error {
63
+ readonly code: string;
64
+ constructor();
65
+ }
66
+ /**
67
+ * Storage adapter backed by native SQLite via a Tauri plugin.
68
+ *
69
+ * Uses Tauri IPC to communicate with the `tauri-plugin-kora` Rust plugin,
70
+ * which provides native SQLite access with WAL mode, foreign keys, and
71
+ * proper connection management — zero WASM overhead.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { TauriSqliteAdapter } from '@korajs/tauri'
76
+ *
77
+ * const adapter = new TauriSqliteAdapter({ path: 'my-app.db' })
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // With createApp (auto-detected in Tauri environments)
83
+ * import { createApp, defineSchema, t } from 'korajs'
84
+ *
85
+ * const app = createApp({
86
+ * schema: defineSchema({
87
+ * version: 1,
88
+ * collections: {
89
+ * todos: { fields: { title: t.string(), completed: t.boolean().default(false) } }
90
+ * }
91
+ * })
92
+ * })
93
+ * ```
94
+ */
95
+ declare class TauriSqliteAdapter implements StorageAdapter {
96
+ private opened;
97
+ private invoker;
98
+ private readonly dbPath;
99
+ private readonly txMutex;
100
+ private inTransaction;
101
+ constructor(options?: TauriSqliteOptions);
102
+ private getInvoke;
103
+ private invoke;
104
+ /**
105
+ * Open or create the database. Generates DDL from the schema and sends it
106
+ * to the Rust plugin for execution. The plugin configures WAL mode,
107
+ * foreign keys, and other pragmas before running the DDL.
108
+ */
109
+ open(schema: SchemaDefinition): Promise<void>;
110
+ /**
111
+ * Close the database and release resources.
112
+ */
113
+ close(): Promise<void>;
114
+ /**
115
+ * Execute a write query (INSERT, UPDATE, DELETE).
116
+ */
117
+ execute(sql: string, params?: unknown[]): Promise<void>;
118
+ /**
119
+ * Execute a read query (SELECT).
120
+ */
121
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
122
+ /**
123
+ * Execute multiple operations atomically within a transaction.
124
+ *
125
+ * Uses a mutex to prevent interleaving of concurrent transactions.
126
+ * The transaction is committed on success or rolled back on error.
127
+ */
128
+ transaction(fn: (tx: Transaction) => Promise<void>): Promise<void>;
129
+ /**
130
+ * Apply a schema migration within a transaction.
131
+ */
132
+ migrate(from: number, to: number, migration: MigrationPlan): Promise<void>;
133
+ private ensureOpen;
134
+ }
135
+
136
+ export { type InvokeFn, type MigrationPlan, type StorageAdapter, TauriAdapterError, TauriSqliteAdapter, type TauriSqliteOptions, TauriStoreNotOpenError, type Transaction };
@@ -0,0 +1,136 @@
1
+ import { SchemaDefinition } from '@korajs/core';
2
+
3
+ /**
4
+ * Transaction interface for executing multiple operations atomically.
5
+ * Mirrors @korajs/store's Transaction type to avoid a runtime dependency.
6
+ */
7
+ interface Transaction {
8
+ execute(sql: string, params?: unknown[]): Promise<void>;
9
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
10
+ }
11
+ /**
12
+ * Migration plan containing SQL statements and optional data transforms.
13
+ * Mirrors @korajs/store's MigrationPlan type.
14
+ */
15
+ interface MigrationPlan {
16
+ statements: string[];
17
+ transforms?: Array<(row: Record<string, unknown>) => Record<string, unknown>>;
18
+ }
19
+ /**
20
+ * Storage adapter interface. Mirrors @korajs/store's StorageAdapter.
21
+ * Redeclared here to avoid a runtime dependency on @korajs/store.
22
+ */
23
+ interface StorageAdapter {
24
+ open(schema: SchemaDefinition): Promise<void>;
25
+ close(): Promise<void>;
26
+ execute(sql: string, params?: unknown[]): Promise<void>;
27
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
28
+ transaction(fn: (tx: Transaction) => Promise<void>): Promise<void>;
29
+ migrate(from: number, to: number, migration: MigrationPlan): Promise<void>;
30
+ }
31
+ /**
32
+ * Function signature for Tauri's invoke IPC call.
33
+ * Matches `invoke` from `@tauri-apps/api/core`.
34
+ */
35
+ type InvokeFn = <T>(cmd: string, args?: Record<string, unknown>) => Promise<T>;
36
+ /**
37
+ * Configuration options for the Tauri SQLite adapter.
38
+ */
39
+ interface TauriSqliteOptions {
40
+ /**
41
+ * Database file path relative to the app's data directory.
42
+ * Defaults to 'kora.db'.
43
+ */
44
+ path?: string;
45
+ /**
46
+ * Custom invoke function. Defaults to Tauri's `invoke` from `@tauri-apps/api/core`.
47
+ * Useful for testing — inject a mock invoke to test without a Tauri runtime.
48
+ */
49
+ invoke?: InvokeFn;
50
+ }
51
+ /**
52
+ * Thrown when a storage adapter operation fails in the Tauri plugin.
53
+ */
54
+ declare class TauriAdapterError extends Error {
55
+ readonly code: string;
56
+ readonly context?: Record<string, unknown>;
57
+ constructor(message: string, context?: Record<string, unknown>);
58
+ }
59
+ /**
60
+ * Thrown when an operation is attempted on an adapter that has not been opened.
61
+ */
62
+ declare class TauriStoreNotOpenError extends Error {
63
+ readonly code: string;
64
+ constructor();
65
+ }
66
+ /**
67
+ * Storage adapter backed by native SQLite via a Tauri plugin.
68
+ *
69
+ * Uses Tauri IPC to communicate with the `tauri-plugin-kora` Rust plugin,
70
+ * which provides native SQLite access with WAL mode, foreign keys, and
71
+ * proper connection management — zero WASM overhead.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * import { TauriSqliteAdapter } from '@korajs/tauri'
76
+ *
77
+ * const adapter = new TauriSqliteAdapter({ path: 'my-app.db' })
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // With createApp (auto-detected in Tauri environments)
83
+ * import { createApp, defineSchema, t } from 'korajs'
84
+ *
85
+ * const app = createApp({
86
+ * schema: defineSchema({
87
+ * version: 1,
88
+ * collections: {
89
+ * todos: { fields: { title: t.string(), completed: t.boolean().default(false) } }
90
+ * }
91
+ * })
92
+ * })
93
+ * ```
94
+ */
95
+ declare class TauriSqliteAdapter implements StorageAdapter {
96
+ private opened;
97
+ private invoker;
98
+ private readonly dbPath;
99
+ private readonly txMutex;
100
+ private inTransaction;
101
+ constructor(options?: TauriSqliteOptions);
102
+ private getInvoke;
103
+ private invoke;
104
+ /**
105
+ * Open or create the database. Generates DDL from the schema and sends it
106
+ * to the Rust plugin for execution. The plugin configures WAL mode,
107
+ * foreign keys, and other pragmas before running the DDL.
108
+ */
109
+ open(schema: SchemaDefinition): Promise<void>;
110
+ /**
111
+ * Close the database and release resources.
112
+ */
113
+ close(): Promise<void>;
114
+ /**
115
+ * Execute a write query (INSERT, UPDATE, DELETE).
116
+ */
117
+ execute(sql: string, params?: unknown[]): Promise<void>;
118
+ /**
119
+ * Execute a read query (SELECT).
120
+ */
121
+ query<T>(sql: string, params?: unknown[]): Promise<T[]>;
122
+ /**
123
+ * Execute multiple operations atomically within a transaction.
124
+ *
125
+ * Uses a mutex to prevent interleaving of concurrent transactions.
126
+ * The transaction is committed on success or rolled back on error.
127
+ */
128
+ transaction(fn: (tx: Transaction) => Promise<void>): Promise<void>;
129
+ /**
130
+ * Apply a schema migration within a transaction.
131
+ */
132
+ migrate(from: number, to: number, migration: MigrationPlan): Promise<void>;
133
+ private ensureOpen;
134
+ }
135
+
136
+ export { type InvokeFn, type MigrationPlan, type StorageAdapter, TauriAdapterError, TauriSqliteAdapter, type TauriSqliteOptions, TauriStoreNotOpenError, type Transaction };