bun-sqlite-for-rxdb 1.1.3 → 1.4.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.
@@ -38,5 +38,6 @@ export declare class BunSQLiteStorageInstance<RxDocType> implements RxStorageIns
38
38
  lwt: number;
39
39
  } | null;
40
40
  }>;
41
+ private queryWithOurMemory;
41
42
  }
42
43
  //# sourceMappingURL=instance.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import type { RxJsonSchema, MangoQuerySelector, RxDocumentData } from 'rxdb';
2
2
  import type { SqlFragment } from './operators';
3
+ export declare function canTranslateToSQL<RxDocType>(selector: MangoQuerySelector<RxDocumentData<RxDocType>>, schema?: RxJsonSchema<RxDocumentData<RxDocType>>): boolean;
3
4
  export declare function getCacheSize(): number;
4
5
  export declare function clearCache(): void;
5
- export declare function buildWhereClause<RxDocType>(selector: MangoQuerySelector<RxDocumentData<RxDocType>>, schema: RxJsonSchema<RxDocumentData<RxDocType>>): SqlFragment;
6
+ export declare function buildWhereClause<RxDocType>(selector: MangoQuerySelector<RxDocumentData<RxDocType>>, schema: RxJsonSchema<RxDocumentData<RxDocType>>, collectionName: string): SqlFragment;
6
7
  //# sourceMappingURL=builder.d.ts.map
@@ -1,7 +1,13 @@
1
+ import type { RxJsonSchema, RxDocumentData } from 'rxdb';
1
2
  export interface SqlFragment {
2
3
  sql: string;
3
4
  args: (string | number | boolean | null)[];
4
5
  }
6
+ type QueryValue = string | number | boolean | null;
7
+ type OperatorExpression = {
8
+ [key: string]: unknown;
9
+ };
10
+ export type ElemMatchCriteria = QueryValue | OperatorExpression;
5
11
  export declare function translateEq(field: string, value: unknown): SqlFragment;
6
12
  export declare function translateNe(field: string, value: unknown): SqlFragment;
7
13
  export declare function translateGt(field: string, value: unknown): SqlFragment;
@@ -11,11 +17,12 @@ export declare function translateLte(field: string, value: unknown): SqlFragment
11
17
  export declare function translateIn(field: string, values: unknown[]): SqlFragment;
12
18
  export declare function translateNin(field: string, values: unknown[]): SqlFragment;
13
19
  export declare function translateExists(field: string, exists: boolean): SqlFragment;
14
- export declare function translateRegex(field: string, pattern: string, options?: string): SqlFragment | null;
15
- export declare function translateElemMatch(field: string, criteria: any): SqlFragment | null;
16
- export declare function translateNot(field: string, criteria: any): SqlFragment;
17
- export declare function translateNor(conditions: any[]): SqlFragment;
18
- export declare function translateType(field: string, type: string): SqlFragment | null;
20
+ export declare function translateRegex<RxDocType>(field: string, pattern: string, options: string | undefined, schema: RxJsonSchema<RxDocumentData<RxDocType>>, fieldName: string): SqlFragment | null;
21
+ export declare function translateElemMatch(field: string, criteria: ElemMatchCriteria): SqlFragment | null;
22
+ export declare function translateNot(field: string, criteria: unknown): SqlFragment;
23
+ export declare function translateType(jsonColumn: string, // rename from tableName — it's the JSON column ("data", "payload", etc.)
24
+ fieldName: string, type: string): SqlFragment | null;
19
25
  export declare function translateSize(field: string, size: number): SqlFragment;
20
26
  export declare function translateMod(field: string, [divisor, remainder]: [number, number]): SqlFragment;
27
+ export {};
21
28
  //# sourceMappingURL=operators.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare function matchesRegex(value: unknown, pattern: string, options?: string): boolean;
2
+ //# sourceMappingURL=regex-matcher.d.ts.map
@@ -1,6 +1,7 @@
1
+ import type { RxJsonSchema, RxDocumentData } from 'rxdb';
1
2
  export interface SqlFragment {
2
3
  sql: string;
3
4
  args: (string | number | boolean)[];
4
5
  }
5
- export declare function smartRegexToLike(field: string, pattern: string, options?: string): SqlFragment | null;
6
+ export declare function smartRegexToLike<RxDocType>(field: string, pattern: string, options: string | undefined, schema: RxJsonSchema<RxDocumentData<RxDocType>>, fieldName: string): SqlFragment | null;
6
7
  //# sourceMappingURL=smart-regex.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { Database } from 'bun:sqlite';
2
+ export declare function getDatabase(databaseName: string, filename: string): Database;
3
+ export declare function releaseDatabase(databaseName: string): void;
4
+ //# sourceMappingURL=connection-pool.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { getRxStorageBunSQLite } from './storage';
2
+ export type { BunSQLiteStorageSettings } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,43 @@
1
+ import { Observable } from 'rxjs';
2
+ import type { RxStorageInstance, RxStorageInstanceCreationParams, BulkWriteRow, RxDocumentData, RxStorageBulkWriteResponse, RxStorageQueryResult, RxStorageCountResult, EventBulk, RxStorageChangeEvent, PreparedQuery, RxJsonSchema, RxStorageDefaultCheckpoint } from 'rxdb';
3
+ import type { BunSQLiteStorageSettings, BunSQLiteInternals } from './types';
4
+ export declare class BunSQLiteStorageInstance<RxDocType> implements RxStorageInstance<RxDocType, BunSQLiteInternals, BunSQLiteStorageSettings> {
5
+ private db;
6
+ private stmtManager;
7
+ private changeStream$;
8
+ readonly databaseName: string;
9
+ readonly collectionName: string;
10
+ readonly schema: Readonly<RxJsonSchema<RxDocumentData<RxDocType>>>;
11
+ readonly internals: Readonly<BunSQLiteInternals>;
12
+ readonly options: Readonly<BunSQLiteStorageSettings>;
13
+ private primaryPath;
14
+ private tableName;
15
+ closed?: Promise<void>;
16
+ constructor(params: RxStorageInstanceCreationParams<RxDocType, BunSQLiteStorageSettings>, settings?: BunSQLiteStorageSettings);
17
+ private initTable;
18
+ bulkWrite(documentWrites: BulkWriteRow<RxDocType>[], context: string): Promise<RxStorageBulkWriteResponse<RxDocType>>;
19
+ findDocumentsById(ids: string[], withDeleted: boolean): Promise<RxDocumentData<RxDocType>[]>;
20
+ query(preparedQuery: PreparedQuery<RxDocType>): Promise<RxStorageQueryResult<RxDocType>>;
21
+ private sortDocuments;
22
+ private getNestedValue;
23
+ count(preparedQuery: PreparedQuery<RxDocType>): Promise<RxStorageCountResult>;
24
+ changeStream(): Observable<EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, RxStorageDefaultCheckpoint>>;
25
+ cleanup(minimumDeletedTime: number): Promise<boolean>;
26
+ close(): Promise<void>;
27
+ remove(): Promise<void>;
28
+ private attachmentMapKey;
29
+ getAttachmentData(documentId: string, attachmentId: string, digest: string): Promise<string>;
30
+ getChangedDocumentsSince(limit: number, checkpoint?: {
31
+ id: string;
32
+ lwt: number;
33
+ }): Promise<{
34
+ documents: RxDocumentData<RxDocType>[];
35
+ checkpoint: {
36
+ id: string;
37
+ lwt: number;
38
+ } | null;
39
+ }>;
40
+ private queryWithOurMemory;
41
+ private matchesRegexSelector;
42
+ }
43
+ //# sourceMappingURL=instance.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { RxJsonSchema, MangoQuerySelector, RxDocumentData } from 'rxdb';
2
+ import type { SqlFragment } from './operators';
3
+ export declare function getCacheSize(): number;
4
+ export declare function clearCache(): void;
5
+ export declare function buildWhereClause<RxDocType>(selector: MangoQuerySelector<RxDocumentData<RxDocType>>, schema: RxJsonSchema<RxDocumentData<RxDocType>>, collectionName: string): SqlFragment | null;
6
+ export declare function buildLogicalOperator<RxDocType>(operator: 'or' | 'nor' | 'and', conditions: MangoQuerySelector<RxDocumentData<RxDocType>>[], schema: RxJsonSchema<RxDocumentData<RxDocType>>, logicalDepth: number): SqlFragment | null;
7
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { RxDocumentData, MangoQuerySelector } from 'rxdb';
2
+ export declare function matchesSelector<RxDocType>(doc: RxDocumentData<RxDocType>, selector: MangoQuerySelector<RxDocumentData<RxDocType>>): boolean;
3
+ //# sourceMappingURL=lightweight-matcher.d.ts.map
@@ -0,0 +1,27 @@
1
+ import type { RxJsonSchema, RxDocumentData } from 'rxdb';
2
+ export interface SqlFragment {
3
+ sql: string;
4
+ args: (string | number | boolean | null)[];
5
+ }
6
+ type QueryValue = string | number | boolean | null;
7
+ type OperatorExpression = {
8
+ [key: string]: unknown;
9
+ };
10
+ export type ElemMatchCriteria = QueryValue | OperatorExpression;
11
+ export declare function translateEq<RxDocType>(field: string, value: unknown, schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
12
+ export declare function translateNe<RxDocType>(field: string, value: unknown, schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
13
+ export declare function translateGt<RxDocType>(field: string, value: unknown, schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
14
+ export declare function translateGte<RxDocType>(field: string, value: unknown, schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
15
+ export declare function translateLt<RxDocType>(field: string, value: unknown, schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
16
+ export declare function translateLte<RxDocType>(field: string, value: unknown, schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
17
+ export declare function translateIn<RxDocType>(field: string, values: unknown[], schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
18
+ export declare function translateNin<RxDocType>(field: string, values: unknown[], schema?: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName?: string): SqlFragment;
19
+ export declare function translateExists(field: string, exists: boolean): SqlFragment;
20
+ export declare function translateRegex<RxDocType>(field: string, pattern: string, options: string | undefined, schema: RxJsonSchema<RxDocumentData<RxDocType>>, fieldName: string): SqlFragment | null;
21
+ export declare function translateElemMatch<RxDocType>(field: string, criteria: ElemMatchCriteria, schema: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName: string): SqlFragment | null;
22
+ export declare function translateNot<RxDocType>(field: string, criteria: unknown, schema: RxJsonSchema<RxDocumentData<RxDocType>>, actualFieldName: string): SqlFragment | null;
23
+ export declare function translateType(jsonColumn: string, fieldName: string, type: string, isDirectPath?: boolean): SqlFragment | null;
24
+ export declare function translateSize(field: string, size: number): SqlFragment;
25
+ export declare function translateMod(field: string, value: unknown): SqlFragment | null;
26
+ export {};
27
+ //# sourceMappingURL=operators.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare function matchesRegex(value: unknown, pattern: string, options?: string): boolean;
2
+ //# sourceMappingURL=regex-matcher.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { RxJsonSchema, RxDocumentData } from 'rxdb';
2
+ export interface ColumnInfo {
3
+ column?: string;
4
+ jsonPath?: string;
5
+ type: 'string' | 'number' | 'boolean' | 'array' | 'unknown';
6
+ }
7
+ export declare function getColumnInfo<RxDocType>(path: string, schema: RxJsonSchema<RxDocumentData<RxDocType>>): ColumnInfo;
8
+ //# sourceMappingURL=schema-mapper.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { RxJsonSchema, RxDocumentData } from 'rxdb';
2
+ export interface SqlFragment {
3
+ sql: string;
4
+ args: (string | number | boolean)[];
5
+ }
6
+ export declare function smartRegexToLike<RxDocType>(field: string, pattern: string, options: string | undefined, schema: RxJsonSchema<RxDocumentData<RxDocType>>, fieldName: string): SqlFragment | null;
7
+ //# sourceMappingURL=smart-regex.d.ts.map
@@ -0,0 +1,28 @@
1
+ import type { RxDocumentData, RxStorageWriteError, BulkWriteRow, RxAttachmentWriteData, RxAttachmentData, RxStorageInstance, RxStorageInstanceCreationParams, EventBulk, RxStorageChangeEvent, RxStorageDefaultCheckpoint } from 'rxdb';
2
+ export interface AttachmentOperation {
3
+ documentId: string;
4
+ attachmentId: string;
5
+ attachmentData: RxAttachmentWriteData;
6
+ digest: string;
7
+ }
8
+ export interface AttachmentRemoveOperation {
9
+ documentId: string;
10
+ attachmentId: string;
11
+ digest: string;
12
+ }
13
+ export declare function getAttachmentSize(attachmentBase64String: string): number;
14
+ export declare function attachmentWriteDataToNormalData(writeData: RxAttachmentWriteData): RxAttachmentData;
15
+ export declare function stripAttachmentsDataFromDocument<T>(doc: RxDocumentData<T>): RxDocumentData<T>;
16
+ export declare function stripAttachmentsDataFromRow<T>(writeRow: BulkWriteRow<T>): BulkWriteRow<T>;
17
+ export declare function categorizeBulkWriteRows<RxDocType>(storageInstance: RxStorageInstance<RxDocType, any, any>, primaryPath: string, docsInDb: Map<string, RxDocumentData<RxDocType>>, bulkWriteRows: BulkWriteRow<RxDocType>[], context: string): {
18
+ bulkInsertDocs: BulkWriteRow<RxDocType>[];
19
+ bulkUpdateDocs: BulkWriteRow<RxDocType>[];
20
+ errors: RxStorageWriteError<RxDocType>[];
21
+ eventBulk: EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, RxStorageDefaultCheckpoint>;
22
+ newestRow?: BulkWriteRow<RxDocType>;
23
+ attachmentsAdd: AttachmentOperation[];
24
+ attachmentsRemove: AttachmentRemoveOperation[];
25
+ attachmentsUpdate: AttachmentOperation[];
26
+ };
27
+ export declare function ensureRxStorageInstanceParamsAreCorrect(params: RxStorageInstanceCreationParams<any, any>): void;
28
+ //# sourceMappingURL=rxdb-helpers.d.ts.map
@@ -0,0 +1,20 @@
1
+ import type { Database, Changes, SQLQueryBindings } from 'bun:sqlite';
2
+ export type QueryWithParams = {
3
+ query: string;
4
+ params: SQLQueryBindings[];
5
+ };
6
+ export declare class StatementManager {
7
+ private db;
8
+ private staticStatements;
9
+ private static readonly MAX_STATEMENTS;
10
+ private closed;
11
+ constructor(db: Database);
12
+ private checkClosed;
13
+ private evictOldest;
14
+ all<T = unknown>(queryWithParams: QueryWithParams): T[];
15
+ get(queryWithParams: QueryWithParams): unknown;
16
+ run(queryWithParams: QueryWithParams): Changes;
17
+ close(): void;
18
+ private isStaticSQL;
19
+ }
20
+ //# sourceMappingURL=statement-manager.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { RxStorage } from 'rxdb';
2
+ import type { BunSQLiteStorageSettings, BunSQLiteInternals } from './types';
3
+ export declare function getRxStorageBunSQLite(settings?: BunSQLiteStorageSettings): RxStorage<BunSQLiteInternals, BunSQLiteStorageSettings>;
4
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export declare function sqliteTransaction<T>(database: Database, handler: () => Promise<T>): Promise<T>;
3
+ //# sourceMappingURL=transaction-queue.d.ts.map
@@ -0,0 +1,20 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export interface BunSQLiteStorageSettings {
3
+ /**
4
+ * Database file path. Use ':memory:' for in-memory database.
5
+ * @default ':memory:'
6
+ */
7
+ filename?: string;
8
+ /**
9
+ * Memory-mapped I/O size in bytes. Set to 0 to disable.
10
+ * Enables 2-5x faster reads for large databases (>500MB).
11
+ * Trade-off: I/O errors become signals (SIGBUS) instead of returnable errors.
12
+ * @default 268435456 (256MB)
13
+ */
14
+ mmapSize?: number;
15
+ }
16
+ export interface BunSQLiteInternals {
17
+ db: Database;
18
+ primaryPath: string;
19
+ }
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Bun-optimized deterministic JSON stringification.
3
+ * Phase 1: Basic implementation with core optimizations + edge case handling.
4
+ *
5
+ * Performance target: >21,000 ops/sec (baseline)
6
+ * Optimizations:
7
+ * - Manual loops (no .map() overhead)
8
+ * - Custom insertion sort for small arrays (<200 elements)
9
+ * - String escape fast path
10
+ * - Direct string concatenation
11
+ * - Circular reference detection
12
+ * - BigInt support
13
+ * - Non-plain object handling (Date, RegExp, Error)
14
+ */
15
+ export declare function stableStringify(value: unknown): string;
16
+ //# sourceMappingURL=stable-stringify.d.ts.map
package/package.json CHANGED
@@ -1,23 +1,29 @@
1
1
  {
2
2
  "name": "bun-sqlite-for-rxdb",
3
- "version": "1.1.3",
3
+ "version": "1.4.0",
4
4
  "author": "adam2am",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/adam2am/bun-sqlite-for-rxdb.git"
8
8
  },
9
9
  "main": "dist/index.js",
10
+ "dependencies": {},
10
11
  "devDependencies": {
11
12
  "@types/better-sqlite3": "^7.6.13",
12
13
  "@types/bun": "latest",
13
- "@types/fast-stable-stringify": "^1.0.0",
14
14
  "better-sqlite3": "^12.6.2",
15
+ "fast-check": "^4.5.3",
16
+ "mingo": "^7.2.0",
15
17
  "rxdb": "^16.21.1",
18
+ "sift": "^17.1.3",
16
19
  "typescript": "^5.0.0"
17
20
  },
18
21
  "peerDependencies": {
19
22
  "rxdb": "^16.0.0 || ^17.0.0-beta"
20
23
  },
24
+ "engines": {
25
+ "bun": ">=1.0.0"
26
+ },
21
27
  "description": "RxDB storage adapter for Bun's native SQLite (bun:sqlite)",
22
28
  "keywords": [
23
29
  "rxdb",
@@ -32,11 +38,12 @@
32
38
  "license": "MIT",
33
39
  "files": [
34
40
  "dist/",
41
+ "!dist/test/",
35
42
  "!dist/**/*.test.d.ts",
36
43
  "!dist/**/*.test.d.ts.map",
44
+ "!dist/**/*.d.ts.map",
37
45
  "README.md",
38
- "LICENSE",
39
- "CHANGELOG.md"
46
+ "LICENSE"
40
47
  ],
41
48
  "scripts": {
42
49
  "build": "bun build src/index.ts --outdir dist --target bun && tsc --emitDeclarationOnly --declaration --outDir dist",
@@ -44,9 +51,5 @@
44
51
  "typecheck": "tsc --noEmit"
45
52
  },
46
53
  "type": "module",
47
- "types": "dist/index.d.ts",
48
- "dependencies": {
49
- "fast-stable-stringify": "^1.0.0",
50
- "mingo": "^7.2.0"
51
- }
54
+ "types": "dist/index.d.ts"
52
55
  }