@monlite/core 0.5.0 → 0.6.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 +92 -12
- package/dist/index.cjs +331 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -6
- package/dist/index.d.ts +66 -6
- package/dist/index.js +327 -111
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -67,6 +67,11 @@ interface FieldFilter<V = any> {
|
|
|
67
67
|
has?: any;
|
|
68
68
|
/** Field presence. `true` requires the field to exist, `false` requires absence. */
|
|
69
69
|
exists?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Case sensitivity for `contains`/`startsWith`/`endsWith`. Default is
|
|
72
|
+
* case-sensitive; `"insensitive"` matches case-insensitively (ASCII).
|
|
73
|
+
*/
|
|
74
|
+
mode?: "default" | "insensitive";
|
|
70
75
|
}
|
|
71
76
|
/** A value used directly as a filter is shorthand for `{ equals: value }`. */
|
|
72
77
|
type FilterInput<V> = V | FieldFilter<V>;
|
|
@@ -220,6 +225,8 @@ interface MonliteOptions {
|
|
|
220
225
|
readonly?: boolean;
|
|
221
226
|
/** Use SQLite WAL journal mode for better concurrency. Default `true`. */
|
|
222
227
|
wal?: boolean;
|
|
228
|
+
/** Milliseconds to wait on a locked database before erroring. Default `5000`. */
|
|
229
|
+
busyTimeout?: number;
|
|
223
230
|
/** Verbose logger for executed SQL (debugging). */
|
|
224
231
|
verbose?: (sql: string) => void;
|
|
225
232
|
}
|
|
@@ -245,6 +252,8 @@ declare class Collection<T = Doc> {
|
|
|
245
252
|
private readonly trackPath;
|
|
246
253
|
constructor(mon: Monlite, name: string, options?: CollectionOptions);
|
|
247
254
|
private get db();
|
|
255
|
+
/** Run a DB operation, normalizing driver errors into typed MonliteErrors. */
|
|
256
|
+
private guard;
|
|
248
257
|
/** Native column names declared for this collection (structured mode). */
|
|
249
258
|
get columnNames(): string[];
|
|
250
259
|
private ensureTable;
|
|
@@ -264,6 +273,12 @@ declare class Collection<T = Doc> {
|
|
|
264
273
|
}>;
|
|
265
274
|
findMany(args?: FindManyArgs<T>): Promise<WithId<T>[]>;
|
|
266
275
|
findFirst(args?: FindFirstArgs<T>): Promise<WithId<T> | null>;
|
|
276
|
+
/** Alias of {@link findFirst} for Prisma familiarity. */
|
|
277
|
+
findUnique(args?: FindFirstArgs<T>): Promise<WithId<T> | null>;
|
|
278
|
+
/** Like {@link findFirst} but throws if no document matches. */
|
|
279
|
+
findFirstOrThrow(args?: FindFirstArgs<T>): Promise<WithId<T>>;
|
|
280
|
+
/** True if at least one document matches. */
|
|
281
|
+
exists(where?: WhereInput<T>): Promise<boolean>;
|
|
267
282
|
findById(id: string): Promise<WithId<T> | null>;
|
|
268
283
|
count(args?: CountArgs<T>): Promise<number>;
|
|
269
284
|
/**
|
|
@@ -338,7 +353,12 @@ declare class AutoIndexer {
|
|
|
338
353
|
* the on-disk column is a plain string, so the format can evolve.)
|
|
339
354
|
*/
|
|
340
355
|
type Version = string;
|
|
341
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Build a version token. The optional `seq` is a per-node monotonic counter
|
|
358
|
+
* that makes versions unique even within the same millisecond — important so
|
|
359
|
+
* that cursor-based pulls (`> version`) never skip a same-timestamp change.
|
|
360
|
+
*/
|
|
361
|
+
declare function makeVersion(ts: number, nodeId: string, seq?: number): Version;
|
|
342
362
|
declare function compareVersions(a: Version, b: Version): number;
|
|
343
363
|
declare function versionTs(v: Version): number;
|
|
344
364
|
|
|
@@ -402,6 +422,7 @@ interface ConflictRow {
|
|
|
402
422
|
declare class SyncStore {
|
|
403
423
|
private readonly db;
|
|
404
424
|
readonly nodeId: string;
|
|
425
|
+
private versionSeq;
|
|
405
426
|
constructor(db: Driver, nodeId?: string);
|
|
406
427
|
private init;
|
|
407
428
|
private resolveNodeId;
|
|
@@ -412,7 +433,7 @@ declare class SyncStore {
|
|
|
412
433
|
/** Current (latest) version of a document, or null if never recorded. */
|
|
413
434
|
currentVersion(collection: string, id: string): Version | null;
|
|
414
435
|
/** Latest unpushed local change per document (the push queue). */
|
|
415
|
-
pending(collections?: string[]): LocalChange[];
|
|
436
|
+
pending(collections?: string[], limit?: number): LocalChange[];
|
|
416
437
|
/** Mark the given changes (and any earlier local rows per doc) as pushed. */
|
|
417
438
|
markPushed(changes: LocalChange[]): void;
|
|
418
439
|
/**
|
|
@@ -427,7 +448,7 @@ declare class SyncStore {
|
|
|
427
448
|
* as RemoteChanges (used when this database acts as a sync *source*, e.g. the
|
|
428
449
|
* monlite-as-remote adapter). Returns the new watermark to resume from.
|
|
429
450
|
*/
|
|
430
|
-
changesSince(seq: number, collections?: string[]): {
|
|
451
|
+
changesSince(seq: number, collections?: string[], limit?: number): {
|
|
431
452
|
changes: RemoteChange[];
|
|
432
453
|
maxSeq: number;
|
|
433
454
|
};
|
|
@@ -503,15 +524,54 @@ declare function createDb(filename: string, options?: MonliteOptions): Monlite;
|
|
|
503
524
|
|
|
504
525
|
/** Base error for all monlite-originated failures. */
|
|
505
526
|
declare class MonliteError extends Error {
|
|
506
|
-
constructor(message: string
|
|
527
|
+
constructor(message: string, options?: {
|
|
528
|
+
cause?: unknown;
|
|
529
|
+
});
|
|
507
530
|
}
|
|
508
531
|
/** Thrown when a query/update payload is malformed. */
|
|
509
532
|
declare class MonliteQueryError extends MonliteError {
|
|
510
|
-
constructor(message: string
|
|
533
|
+
constructor(message: string, options?: {
|
|
534
|
+
cause?: unknown;
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
/** A database constraint was violated (base class for the specific kinds). */
|
|
538
|
+
declare class MonliteConstraintError extends MonliteError {
|
|
539
|
+
readonly collection?: string;
|
|
540
|
+
constructor(message: string, options?: {
|
|
541
|
+
cause?: unknown;
|
|
542
|
+
collection?: string;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
/** A UNIQUE (or primary-key) constraint was violated. */
|
|
546
|
+
declare class MonliteUniqueConstraintError extends MonliteConstraintError {
|
|
547
|
+
constructor(message: string, options?: {
|
|
548
|
+
cause?: unknown;
|
|
549
|
+
collection?: string;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
/** A NOT NULL constraint was violated. */
|
|
553
|
+
declare class MonliteNotNullError extends MonliteConstraintError {
|
|
554
|
+
constructor(message: string, options?: {
|
|
555
|
+
cause?: unknown;
|
|
556
|
+
collection?: string;
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
/** A FOREIGN KEY constraint was violated. */
|
|
560
|
+
declare class MonliteForeignKeyError extends MonliteConstraintError {
|
|
561
|
+
constructor(message: string, options?: {
|
|
562
|
+
cause?: unknown;
|
|
563
|
+
collection?: string;
|
|
564
|
+
});
|
|
511
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Normalize a raw driver error (better-sqlite3 `SqliteError` or node:sqlite
|
|
568
|
+
* error) into a typed {@link MonliteError}. The two backends differ in error
|
|
569
|
+
* shape, so we sniff both the `code` and the message text.
|
|
570
|
+
*/
|
|
571
|
+
declare function normalizeDriverError(err: unknown, collection?: string): MonliteError;
|
|
512
572
|
|
|
513
573
|
declare function objectId(): string;
|
|
514
574
|
/** True when a value looks like a monlite/ObjectId id (24 hex chars). */
|
|
515
575
|
declare function isObjectId(value: unknown): value is string;
|
|
516
576
|
|
|
517
|
-
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 FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LocalChange, Monlite, MonliteError, type MonliteOptions, MonliteQueryError, type OrderBy, 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 WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, objectId, versionTs };
|
|
577
|
+
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 FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LocalChange, Monlite, MonliteConstraintError, MonliteError, MonliteForeignKeyError, MonliteNotNullError, type MonliteOptions, MonliteQueryError, MonliteUniqueConstraintError, type OrderBy, 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 WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, normalizeDriverError, objectId, versionTs };
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,11 @@ interface FieldFilter<V = any> {
|
|
|
67
67
|
has?: any;
|
|
68
68
|
/** Field presence. `true` requires the field to exist, `false` requires absence. */
|
|
69
69
|
exists?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Case sensitivity for `contains`/`startsWith`/`endsWith`. Default is
|
|
72
|
+
* case-sensitive; `"insensitive"` matches case-insensitively (ASCII).
|
|
73
|
+
*/
|
|
74
|
+
mode?: "default" | "insensitive";
|
|
70
75
|
}
|
|
71
76
|
/** A value used directly as a filter is shorthand for `{ equals: value }`. */
|
|
72
77
|
type FilterInput<V> = V | FieldFilter<V>;
|
|
@@ -220,6 +225,8 @@ interface MonliteOptions {
|
|
|
220
225
|
readonly?: boolean;
|
|
221
226
|
/** Use SQLite WAL journal mode for better concurrency. Default `true`. */
|
|
222
227
|
wal?: boolean;
|
|
228
|
+
/** Milliseconds to wait on a locked database before erroring. Default `5000`. */
|
|
229
|
+
busyTimeout?: number;
|
|
223
230
|
/** Verbose logger for executed SQL (debugging). */
|
|
224
231
|
verbose?: (sql: string) => void;
|
|
225
232
|
}
|
|
@@ -245,6 +252,8 @@ declare class Collection<T = Doc> {
|
|
|
245
252
|
private readonly trackPath;
|
|
246
253
|
constructor(mon: Monlite, name: string, options?: CollectionOptions);
|
|
247
254
|
private get db();
|
|
255
|
+
/** Run a DB operation, normalizing driver errors into typed MonliteErrors. */
|
|
256
|
+
private guard;
|
|
248
257
|
/** Native column names declared for this collection (structured mode). */
|
|
249
258
|
get columnNames(): string[];
|
|
250
259
|
private ensureTable;
|
|
@@ -264,6 +273,12 @@ declare class Collection<T = Doc> {
|
|
|
264
273
|
}>;
|
|
265
274
|
findMany(args?: FindManyArgs<T>): Promise<WithId<T>[]>;
|
|
266
275
|
findFirst(args?: FindFirstArgs<T>): Promise<WithId<T> | null>;
|
|
276
|
+
/** Alias of {@link findFirst} for Prisma familiarity. */
|
|
277
|
+
findUnique(args?: FindFirstArgs<T>): Promise<WithId<T> | null>;
|
|
278
|
+
/** Like {@link findFirst} but throws if no document matches. */
|
|
279
|
+
findFirstOrThrow(args?: FindFirstArgs<T>): Promise<WithId<T>>;
|
|
280
|
+
/** True if at least one document matches. */
|
|
281
|
+
exists(where?: WhereInput<T>): Promise<boolean>;
|
|
267
282
|
findById(id: string): Promise<WithId<T> | null>;
|
|
268
283
|
count(args?: CountArgs<T>): Promise<number>;
|
|
269
284
|
/**
|
|
@@ -338,7 +353,12 @@ declare class AutoIndexer {
|
|
|
338
353
|
* the on-disk column is a plain string, so the format can evolve.)
|
|
339
354
|
*/
|
|
340
355
|
type Version = string;
|
|
341
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Build a version token. The optional `seq` is a per-node monotonic counter
|
|
358
|
+
* that makes versions unique even within the same millisecond — important so
|
|
359
|
+
* that cursor-based pulls (`> version`) never skip a same-timestamp change.
|
|
360
|
+
*/
|
|
361
|
+
declare function makeVersion(ts: number, nodeId: string, seq?: number): Version;
|
|
342
362
|
declare function compareVersions(a: Version, b: Version): number;
|
|
343
363
|
declare function versionTs(v: Version): number;
|
|
344
364
|
|
|
@@ -402,6 +422,7 @@ interface ConflictRow {
|
|
|
402
422
|
declare class SyncStore {
|
|
403
423
|
private readonly db;
|
|
404
424
|
readonly nodeId: string;
|
|
425
|
+
private versionSeq;
|
|
405
426
|
constructor(db: Driver, nodeId?: string);
|
|
406
427
|
private init;
|
|
407
428
|
private resolveNodeId;
|
|
@@ -412,7 +433,7 @@ declare class SyncStore {
|
|
|
412
433
|
/** Current (latest) version of a document, or null if never recorded. */
|
|
413
434
|
currentVersion(collection: string, id: string): Version | null;
|
|
414
435
|
/** Latest unpushed local change per document (the push queue). */
|
|
415
|
-
pending(collections?: string[]): LocalChange[];
|
|
436
|
+
pending(collections?: string[], limit?: number): LocalChange[];
|
|
416
437
|
/** Mark the given changes (and any earlier local rows per doc) as pushed. */
|
|
417
438
|
markPushed(changes: LocalChange[]): void;
|
|
418
439
|
/**
|
|
@@ -427,7 +448,7 @@ declare class SyncStore {
|
|
|
427
448
|
* as RemoteChanges (used when this database acts as a sync *source*, e.g. the
|
|
428
449
|
* monlite-as-remote adapter). Returns the new watermark to resume from.
|
|
429
450
|
*/
|
|
430
|
-
changesSince(seq: number, collections?: string[]): {
|
|
451
|
+
changesSince(seq: number, collections?: string[], limit?: number): {
|
|
431
452
|
changes: RemoteChange[];
|
|
432
453
|
maxSeq: number;
|
|
433
454
|
};
|
|
@@ -503,15 +524,54 @@ declare function createDb(filename: string, options?: MonliteOptions): Monlite;
|
|
|
503
524
|
|
|
504
525
|
/** Base error for all monlite-originated failures. */
|
|
505
526
|
declare class MonliteError extends Error {
|
|
506
|
-
constructor(message: string
|
|
527
|
+
constructor(message: string, options?: {
|
|
528
|
+
cause?: unknown;
|
|
529
|
+
});
|
|
507
530
|
}
|
|
508
531
|
/** Thrown when a query/update payload is malformed. */
|
|
509
532
|
declare class MonliteQueryError extends MonliteError {
|
|
510
|
-
constructor(message: string
|
|
533
|
+
constructor(message: string, options?: {
|
|
534
|
+
cause?: unknown;
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
/** A database constraint was violated (base class for the specific kinds). */
|
|
538
|
+
declare class MonliteConstraintError extends MonliteError {
|
|
539
|
+
readonly collection?: string;
|
|
540
|
+
constructor(message: string, options?: {
|
|
541
|
+
cause?: unknown;
|
|
542
|
+
collection?: string;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
/** A UNIQUE (or primary-key) constraint was violated. */
|
|
546
|
+
declare class MonliteUniqueConstraintError extends MonliteConstraintError {
|
|
547
|
+
constructor(message: string, options?: {
|
|
548
|
+
cause?: unknown;
|
|
549
|
+
collection?: string;
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
/** A NOT NULL constraint was violated. */
|
|
553
|
+
declare class MonliteNotNullError extends MonliteConstraintError {
|
|
554
|
+
constructor(message: string, options?: {
|
|
555
|
+
cause?: unknown;
|
|
556
|
+
collection?: string;
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
/** A FOREIGN KEY constraint was violated. */
|
|
560
|
+
declare class MonliteForeignKeyError extends MonliteConstraintError {
|
|
561
|
+
constructor(message: string, options?: {
|
|
562
|
+
cause?: unknown;
|
|
563
|
+
collection?: string;
|
|
564
|
+
});
|
|
511
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Normalize a raw driver error (better-sqlite3 `SqliteError` or node:sqlite
|
|
568
|
+
* error) into a typed {@link MonliteError}. The two backends differ in error
|
|
569
|
+
* shape, so we sniff both the `code` and the message text.
|
|
570
|
+
*/
|
|
571
|
+
declare function normalizeDriverError(err: unknown, collection?: string): MonliteError;
|
|
512
572
|
|
|
513
573
|
declare function objectId(): string;
|
|
514
574
|
/** True when a value looks like a monlite/ObjectId id (24 hex chars). */
|
|
515
575
|
declare function isObjectId(value: unknown): value is string;
|
|
516
576
|
|
|
517
|
-
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 FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LocalChange, Monlite, MonliteError, type MonliteOptions, MonliteQueryError, type OrderBy, 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 WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, objectId, versionTs };
|
|
577
|
+
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 FieldFilter, type FieldSelection, type FilterInput, type FindFirstArgs, type FindManyArgs, type GroupByArgs, type GroupByResult, type HavingComparison, type HavingInput, type LocalChange, Monlite, MonliteConstraintError, MonliteError, MonliteForeignKeyError, MonliteNotNullError, type MonliteOptions, MonliteQueryError, MonliteUniqueConstraintError, type OrderBy, 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 WhereInput as WhereClause, type WhereInput, type WithId, compareVersions, createDb, isObjectId, makeVersion, normalizeDriverError, objectId, versionTs };
|