@monlite/core 1.2.0 → 1.3.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 +6 -4
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -30
- package/dist/index.d.ts +46 -30
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -140,6 +140,48 @@ interface MonlitePlugin {
|
|
|
140
140
|
collectionMethods?: Record<string, (collection: Collection<any>, ...args: any[]) => any>;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* The minimal SQLite driver surface monlite needs. Implemented by both the
|
|
145
|
+
* better-sqlite3 and the built-in node:sqlite backends so the rest of the
|
|
146
|
+
* codebase is engine-agnostic.
|
|
147
|
+
*/
|
|
148
|
+
interface RunResult {
|
|
149
|
+
changes: number;
|
|
150
|
+
lastInsertRowid: number | bigint;
|
|
151
|
+
}
|
|
152
|
+
interface PreparedStatement {
|
|
153
|
+
run(...params: any[]): RunResult;
|
|
154
|
+
get(...params: any[]): any;
|
|
155
|
+
all(...params: any[]): any[];
|
|
156
|
+
}
|
|
157
|
+
interface Driver {
|
|
158
|
+
/** Backend identifier, e.g. "better-sqlite3" or "node:sqlite". */
|
|
159
|
+
readonly name: string;
|
|
160
|
+
exec(sql: string): void;
|
|
161
|
+
prepare(sql: string): PreparedStatement;
|
|
162
|
+
/** Run `fn` inside a transaction; rolls back and rethrows if it throws. */
|
|
163
|
+
transaction<T>(fn: () => T): T;
|
|
164
|
+
close(): void;
|
|
165
|
+
/** Rotate the encryption key (encrypted backends only). */
|
|
166
|
+
rekey?(key: string, cipher?: string): void;
|
|
167
|
+
/** The underlying native handle (better-sqlite3 Database / node:sqlite DatabaseSync). */
|
|
168
|
+
readonly raw: any;
|
|
169
|
+
}
|
|
170
|
+
interface DriverOpenOptions {
|
|
171
|
+
readonly?: boolean;
|
|
172
|
+
wal?: boolean;
|
|
173
|
+
/** Milliseconds to wait on a locked database before erroring. Default 5000. */
|
|
174
|
+
busyTimeout?: number;
|
|
175
|
+
/** Allow loading SQLite extensions (needed by `@monlite/vector`). Default false. */
|
|
176
|
+
allowExtensions?: boolean;
|
|
177
|
+
/** Encrypt the database at rest (better-sqlite3-multiple-ciphers only). */
|
|
178
|
+
encryption?: {
|
|
179
|
+
key: string;
|
|
180
|
+
cipher?: string;
|
|
181
|
+
};
|
|
182
|
+
verbose?: (sql: string) => void;
|
|
183
|
+
}
|
|
184
|
+
|
|
143
185
|
/**
|
|
144
186
|
* Public type surface for monlite.
|
|
145
187
|
*
|
|
@@ -396,8 +438,10 @@ interface MonliteOptions {
|
|
|
396
438
|
/**
|
|
397
439
|
* Which SQLite backend to use. `"auto"` (default) prefers `better-sqlite3`
|
|
398
440
|
* when installed, otherwise the built-in `node:sqlite` (Node >= 22.5).
|
|
441
|
+
* You can also pass a custom {@link Driver} instance (e.g. `@monlite/wasm`
|
|
442
|
+
* for the browser).
|
|
399
443
|
*/
|
|
400
|
-
driver?: DriverName;
|
|
444
|
+
driver?: DriverName | Driver;
|
|
401
445
|
/**
|
|
402
446
|
* Encrypt the database at rest. Requires the `better-sqlite3-multiple-ciphers`
|
|
403
447
|
* package (a drop-in for `better-sqlite3`); not supported on `node:sqlite`.
|
|
@@ -433,34 +477,6 @@ interface MonliteOptions {
|
|
|
433
477
|
verbose?: (sql: string) => void;
|
|
434
478
|
}
|
|
435
479
|
|
|
436
|
-
/**
|
|
437
|
-
* The minimal SQLite driver surface monlite needs. Implemented by both the
|
|
438
|
-
* better-sqlite3 and the built-in node:sqlite backends so the rest of the
|
|
439
|
-
* codebase is engine-agnostic.
|
|
440
|
-
*/
|
|
441
|
-
interface RunResult {
|
|
442
|
-
changes: number;
|
|
443
|
-
lastInsertRowid: number | bigint;
|
|
444
|
-
}
|
|
445
|
-
interface PreparedStatement {
|
|
446
|
-
run(...params: any[]): RunResult;
|
|
447
|
-
get(...params: any[]): any;
|
|
448
|
-
all(...params: any[]): any[];
|
|
449
|
-
}
|
|
450
|
-
interface Driver {
|
|
451
|
-
/** Backend identifier, e.g. "better-sqlite3" or "node:sqlite". */
|
|
452
|
-
readonly name: string;
|
|
453
|
-
exec(sql: string): void;
|
|
454
|
-
prepare(sql: string): PreparedStatement;
|
|
455
|
-
/** Run `fn` inside a transaction; rolls back and rethrows if it throws. */
|
|
456
|
-
transaction<T>(fn: () => T): T;
|
|
457
|
-
close(): void;
|
|
458
|
-
/** Rotate the encryption key (encrypted backends only). */
|
|
459
|
-
rekey?(key: string, cipher?: string): void;
|
|
460
|
-
/** The underlying native handle (better-sqlite3 Database / node:sqlite DatabaseSync). */
|
|
461
|
-
readonly raw: any;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
480
|
/**
|
|
465
481
|
* Tracks which JSON paths are queried per collection and silently creates a
|
|
466
482
|
* SQLite expression index once a path crosses the configured threshold.
|
|
@@ -772,4 +788,4 @@ declare function objectId(): string;
|
|
|
772
788
|
/** True when a value looks like a monlite/ObjectId id (24 hex chars). */
|
|
773
789
|
declare function isObjectId(value: unknown): value is string;
|
|
774
790
|
|
|
775
|
-
export { type AggregateArgs, type AggregateResult, type ApplyResult, Collection, type CollectionMode, type CollectionOptions, type CollectionSchema, type ColumnDef, type ColumnInfo, type ColumnType, type ConflictResolver, type ConflictRow, type CountArgs, type CreateArgs, type CreateManyArgs, Monlite as Db, type DeleteArgs, type Doc, type Driver, type DriverName, type EncryptionOptions, type ExplainResult, type FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LiveEvent, type LocalChange, type MigrateOptions, Monlite, MonliteConstraintError, MonliteEncryptionError, MonliteError, MonliteForeignKeyError, MonliteNotNullError, type MonliteOptions, type MonlitePlugin, MonliteQueryError, MonliteUniqueConstraintError, type OrderBy, type PluginChange, type PreparedStatement, type RemoteChange, type Select, type SortOrder, type SyncOp, type SyncStateRow, SyncStore, type SystemFields, type UpdateArgs, type UpdateData, type UpdateOperators, type UpsertArgs, type Version, type WatchHandle, type WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, normalizeDriverError, objectId, versionTs };
|
|
791
|
+
export { type AggregateArgs, type AggregateResult, type ApplyResult, Collection, type CollectionMode, type CollectionOptions, type CollectionSchema, type ColumnDef, type ColumnInfo, type ColumnType, type ConflictResolver, type ConflictRow, type CountArgs, type CreateArgs, type CreateManyArgs, Monlite as Db, type DeleteArgs, type Doc, type Driver, type DriverName, type DriverOpenOptions, type EncryptionOptions, type ExplainResult, type FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LiveEvent, type LocalChange, type MigrateOptions, Monlite, MonliteConstraintError, MonliteEncryptionError, MonliteError, MonliteForeignKeyError, MonliteNotNullError, type MonliteOptions, type MonlitePlugin, MonliteQueryError, MonliteUniqueConstraintError, type OrderBy, type PluginChange, type PreparedStatement, type RemoteChange, type RunResult, type Select, type SortOrder, type SyncOp, type SyncStateRow, SyncStore, type SystemFields, type UpdateArgs, type UpdateData, type UpdateOperators, type UpsertArgs, type Version, type WatchHandle, type WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, normalizeDriverError, objectId, versionTs };
|
package/dist/index.d.ts
CHANGED
|
@@ -140,6 +140,48 @@ interface MonlitePlugin {
|
|
|
140
140
|
collectionMethods?: Record<string, (collection: Collection<any>, ...args: any[]) => any>;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* The minimal SQLite driver surface monlite needs. Implemented by both the
|
|
145
|
+
* better-sqlite3 and the built-in node:sqlite backends so the rest of the
|
|
146
|
+
* codebase is engine-agnostic.
|
|
147
|
+
*/
|
|
148
|
+
interface RunResult {
|
|
149
|
+
changes: number;
|
|
150
|
+
lastInsertRowid: number | bigint;
|
|
151
|
+
}
|
|
152
|
+
interface PreparedStatement {
|
|
153
|
+
run(...params: any[]): RunResult;
|
|
154
|
+
get(...params: any[]): any;
|
|
155
|
+
all(...params: any[]): any[];
|
|
156
|
+
}
|
|
157
|
+
interface Driver {
|
|
158
|
+
/** Backend identifier, e.g. "better-sqlite3" or "node:sqlite". */
|
|
159
|
+
readonly name: string;
|
|
160
|
+
exec(sql: string): void;
|
|
161
|
+
prepare(sql: string): PreparedStatement;
|
|
162
|
+
/** Run `fn` inside a transaction; rolls back and rethrows if it throws. */
|
|
163
|
+
transaction<T>(fn: () => T): T;
|
|
164
|
+
close(): void;
|
|
165
|
+
/** Rotate the encryption key (encrypted backends only). */
|
|
166
|
+
rekey?(key: string, cipher?: string): void;
|
|
167
|
+
/** The underlying native handle (better-sqlite3 Database / node:sqlite DatabaseSync). */
|
|
168
|
+
readonly raw: any;
|
|
169
|
+
}
|
|
170
|
+
interface DriverOpenOptions {
|
|
171
|
+
readonly?: boolean;
|
|
172
|
+
wal?: boolean;
|
|
173
|
+
/** Milliseconds to wait on a locked database before erroring. Default 5000. */
|
|
174
|
+
busyTimeout?: number;
|
|
175
|
+
/** Allow loading SQLite extensions (needed by `@monlite/vector`). Default false. */
|
|
176
|
+
allowExtensions?: boolean;
|
|
177
|
+
/** Encrypt the database at rest (better-sqlite3-multiple-ciphers only). */
|
|
178
|
+
encryption?: {
|
|
179
|
+
key: string;
|
|
180
|
+
cipher?: string;
|
|
181
|
+
};
|
|
182
|
+
verbose?: (sql: string) => void;
|
|
183
|
+
}
|
|
184
|
+
|
|
143
185
|
/**
|
|
144
186
|
* Public type surface for monlite.
|
|
145
187
|
*
|
|
@@ -396,8 +438,10 @@ interface MonliteOptions {
|
|
|
396
438
|
/**
|
|
397
439
|
* Which SQLite backend to use. `"auto"` (default) prefers `better-sqlite3`
|
|
398
440
|
* when installed, otherwise the built-in `node:sqlite` (Node >= 22.5).
|
|
441
|
+
* You can also pass a custom {@link Driver} instance (e.g. `@monlite/wasm`
|
|
442
|
+
* for the browser).
|
|
399
443
|
*/
|
|
400
|
-
driver?: DriverName;
|
|
444
|
+
driver?: DriverName | Driver;
|
|
401
445
|
/**
|
|
402
446
|
* Encrypt the database at rest. Requires the `better-sqlite3-multiple-ciphers`
|
|
403
447
|
* package (a drop-in for `better-sqlite3`); not supported on `node:sqlite`.
|
|
@@ -433,34 +477,6 @@ interface MonliteOptions {
|
|
|
433
477
|
verbose?: (sql: string) => void;
|
|
434
478
|
}
|
|
435
479
|
|
|
436
|
-
/**
|
|
437
|
-
* The minimal SQLite driver surface monlite needs. Implemented by both the
|
|
438
|
-
* better-sqlite3 and the built-in node:sqlite backends so the rest of the
|
|
439
|
-
* codebase is engine-agnostic.
|
|
440
|
-
*/
|
|
441
|
-
interface RunResult {
|
|
442
|
-
changes: number;
|
|
443
|
-
lastInsertRowid: number | bigint;
|
|
444
|
-
}
|
|
445
|
-
interface PreparedStatement {
|
|
446
|
-
run(...params: any[]): RunResult;
|
|
447
|
-
get(...params: any[]): any;
|
|
448
|
-
all(...params: any[]): any[];
|
|
449
|
-
}
|
|
450
|
-
interface Driver {
|
|
451
|
-
/** Backend identifier, e.g. "better-sqlite3" or "node:sqlite". */
|
|
452
|
-
readonly name: string;
|
|
453
|
-
exec(sql: string): void;
|
|
454
|
-
prepare(sql: string): PreparedStatement;
|
|
455
|
-
/** Run `fn` inside a transaction; rolls back and rethrows if it throws. */
|
|
456
|
-
transaction<T>(fn: () => T): T;
|
|
457
|
-
close(): void;
|
|
458
|
-
/** Rotate the encryption key (encrypted backends only). */
|
|
459
|
-
rekey?(key: string, cipher?: string): void;
|
|
460
|
-
/** The underlying native handle (better-sqlite3 Database / node:sqlite DatabaseSync). */
|
|
461
|
-
readonly raw: any;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
480
|
/**
|
|
465
481
|
* Tracks which JSON paths are queried per collection and silently creates a
|
|
466
482
|
* SQLite expression index once a path crosses the configured threshold.
|
|
@@ -772,4 +788,4 @@ declare function objectId(): string;
|
|
|
772
788
|
/** True when a value looks like a monlite/ObjectId id (24 hex chars). */
|
|
773
789
|
declare function isObjectId(value: unknown): value is string;
|
|
774
790
|
|
|
775
|
-
export { type AggregateArgs, type AggregateResult, type ApplyResult, Collection, type CollectionMode, type CollectionOptions, type CollectionSchema, type ColumnDef, type ColumnInfo, type ColumnType, type ConflictResolver, type ConflictRow, type CountArgs, type CreateArgs, type CreateManyArgs, Monlite as Db, type DeleteArgs, type Doc, type Driver, type DriverName, type EncryptionOptions, type ExplainResult, type FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LiveEvent, type LocalChange, type MigrateOptions, Monlite, MonliteConstraintError, MonliteEncryptionError, MonliteError, MonliteForeignKeyError, MonliteNotNullError, type MonliteOptions, type MonlitePlugin, MonliteQueryError, MonliteUniqueConstraintError, type OrderBy, type PluginChange, type PreparedStatement, type RemoteChange, type Select, type SortOrder, type SyncOp, type SyncStateRow, SyncStore, type SystemFields, type UpdateArgs, type UpdateData, type UpdateOperators, type UpsertArgs, type Version, type WatchHandle, type WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, normalizeDriverError, objectId, versionTs };
|
|
791
|
+
export { type AggregateArgs, type AggregateResult, type ApplyResult, Collection, type CollectionMode, type CollectionOptions, type CollectionSchema, type ColumnDef, type ColumnInfo, type ColumnType, type ConflictResolver, type ConflictRow, type CountArgs, type CreateArgs, type CreateManyArgs, Monlite as Db, type DeleteArgs, type Doc, type Driver, type DriverName, type DriverOpenOptions, type EncryptionOptions, type ExplainResult, type FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LiveEvent, type LocalChange, type MigrateOptions, Monlite, MonliteConstraintError, MonliteEncryptionError, MonliteError, MonliteForeignKeyError, MonliteNotNullError, type MonliteOptions, type MonlitePlugin, MonliteQueryError, MonliteUniqueConstraintError, type OrderBy, type PluginChange, type PreparedStatement, type RemoteChange, type RunResult, type Select, type SortOrder, type SyncOp, type SyncStateRow, SyncStore, type SystemFields, type UpdateArgs, type UpdateData, type UpdateOperators, type UpsertArgs, type Version, type WatchHandle, type WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, normalizeDriverError, objectId, versionTs };
|
package/dist/index.js
CHANGED
|
@@ -1612,7 +1612,11 @@ function loadNodeSqlite() {
|
|
|
1612
1612
|
return null;
|
|
1613
1613
|
}
|
|
1614
1614
|
}
|
|
1615
|
+
function isDriverInstance(d) {
|
|
1616
|
+
return typeof d === "object" && d !== null && typeof d.prepare === "function" && typeof d.exec === "function";
|
|
1617
|
+
}
|
|
1615
1618
|
function createDriver(filename, options = {}) {
|
|
1619
|
+
if (isDriverInstance(options.driver)) return options.driver;
|
|
1616
1620
|
const choice = options.driver ?? "auto";
|
|
1617
1621
|
if (options.encryption) {
|
|
1618
1622
|
if (choice === "node:sqlite") {
|