@fireproof/core 0.20.0-dev-preview-05 → 0.20.0-dev-preview-06
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -10
- package/index.cjs +25 -25
- package/index.cjs.map +1 -1
- package/index.d.cts +17 -17
- package/index.d.ts +17 -17
- package/index.js +25 -25
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/package.json +3 -3
- package/react/index.cjs +22 -22
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +7 -7
- package/react/index.d.ts +7 -7
- package/react/index.js +22 -22
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/fireproof/all-gateway.test.ts +7 -7
- package/tests/fireproof/crdt.test.ts +10 -10
- package/tests/fireproof/{ledger.test.ts → database.test.ts} +31 -31
- package/tests/fireproof/fireproof.test.ts +34 -34
- package/tests/fireproof/hello.test.ts +6 -6
- package/tests/fireproof/indexer.test.ts +18 -18
- package/tests/fireproof/{multiple-ledger.test.ts → multiple-database.test.ts} +2 -2
- package/tests/react/useFireproof.test.tsx +2 -2
- package/tests/www/gallery.html +2 -2
- package/tests/www/todo-aws.html +1 -1
- package/tests/www/todo-ipfs.html +1 -1
- package/tests/www/todo-local.html +1 -1
- package/tests/www/todo.html +1 -1
package/index.d.cts
CHANGED
@@ -1185,14 +1185,14 @@ interface HasCRDT<T extends DocTypes> {
|
|
1185
1185
|
readonly crdt: CRDT<T> | CRDT<NonNullable<unknown>>;
|
1186
1186
|
}
|
1187
1187
|
declare class CRDT<T extends DocTypes> {
|
1188
|
-
readonly opts:
|
1188
|
+
readonly opts: DatabaseOpts;
|
1189
1189
|
readonly blockstore: BaseBlockstore;
|
1190
1190
|
readonly indexBlockstore: BaseBlockstore;
|
1191
1191
|
readonly indexers: Map<string, Index<IndexKeyType, NonNullable<unknown>>>;
|
1192
1192
|
readonly clock: CRDTClock<T>;
|
1193
1193
|
readonly logger: Logger;
|
1194
1194
|
readonly sthis: SuperThis;
|
1195
|
-
constructor(sthis: SuperThis, opts:
|
1195
|
+
constructor(sthis: SuperThis, opts: DatabaseOpts);
|
1196
1196
|
bulk(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
|
1197
1197
|
readonly onceReady: ResolveOnce<void>;
|
1198
1198
|
ready(): Promise<void>;
|
@@ -1213,7 +1213,7 @@ declare class CRDT<T extends DocTypes> {
|
|
1213
1213
|
}
|
1214
1214
|
|
1215
1215
|
declare function keyConfigOpts(sthis: SuperThis, name?: string, opts?: ConfigOpts): string;
|
1216
|
-
interface
|
1216
|
+
interface DatabaseOpts {
|
1217
1217
|
readonly name?: string;
|
1218
1218
|
readonly meta?: DbMeta;
|
1219
1219
|
readonly gatewayInterceptor?: SerdeGatewayInterceptor;
|
@@ -1222,7 +1222,7 @@ interface LedgerOpts {
|
|
1222
1222
|
readonly storeEnDe: StoreEnDeFile;
|
1223
1223
|
readonly keyBag: KeyBagRuntime;
|
1224
1224
|
}
|
1225
|
-
interface
|
1225
|
+
interface Database<DT extends DocTypes = NonNullable<unknown>> extends HasCRDT<DT> {
|
1226
1226
|
readonly logger: Logger;
|
1227
1227
|
readonly sthis: SuperThis;
|
1228
1228
|
readonly id: string;
|
@@ -1248,11 +1248,11 @@ interface Ledger<DT extends DocTypes = NonNullable<unknown>> extends HasCRDT<DT>
|
|
1248
1248
|
query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
|
1249
1249
|
compact(): Promise<void>;
|
1250
1250
|
}
|
1251
|
-
declare function
|
1252
|
-
declare function
|
1253
|
-
declare class
|
1254
|
-
readonly ref:
|
1255
|
-
constructor(ref:
|
1251
|
+
declare function isDatabase<T extends DocTypes = NonNullable<unknown>>(db: unknown): db is Database<T>;
|
1252
|
+
declare function DatabaseFactory<T extends DocTypes = NonNullable<unknown>>(name: string | undefined, opts?: ConfigOpts): Database<T>;
|
1253
|
+
declare class DatabaseShell<DT extends DocTypes = NonNullable<unknown>> implements Database<DT> {
|
1254
|
+
readonly ref: DatabaseImpl<DT>;
|
1255
|
+
constructor(ref: DatabaseImpl<DT>);
|
1256
1256
|
get id(): string;
|
1257
1257
|
get logger(): Logger;
|
1258
1258
|
get sthis(): SuperThis;
|
@@ -1279,26 +1279,26 @@ declare class LedgerShell<DT extends DocTypes = NonNullable<unknown>> implements
|
|
1279
1279
|
query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
|
1280
1280
|
compact(): Promise<void>;
|
1281
1281
|
}
|
1282
|
-
declare class
|
1283
|
-
readonly opts:
|
1282
|
+
declare class DatabaseImpl<DT extends DocTypes = NonNullable<unknown>> implements Database<DT> {
|
1283
|
+
readonly opts: DatabaseOpts;
|
1284
1284
|
_listening: boolean;
|
1285
1285
|
readonly _listeners: Set<ListenerFn<DT>>;
|
1286
1286
|
readonly _noupdate_listeners: Set<ListenerFn<DT>>;
|
1287
1287
|
readonly crdt: CRDT<DT>;
|
1288
1288
|
readonly _writeQueue: WriteQueue<DT>;
|
1289
|
-
readonly shells: Set<
|
1290
|
-
addShell(shell:
|
1289
|
+
readonly shells: Set<DatabaseShell<DT>>;
|
1290
|
+
addShell(shell: DatabaseShell<DT>): void;
|
1291
1291
|
readonly _onClosedFns: Set<() => void>;
|
1292
1292
|
onClosed(fn: () => void): void;
|
1293
1293
|
close(): Promise<void>;
|
1294
|
-
shellClose(db:
|
1294
|
+
shellClose(db: DatabaseShell<DT>): Promise<void>;
|
1295
1295
|
destroy(): Promise<void>;
|
1296
1296
|
readonly _ready: ResolveOnce<void>;
|
1297
1297
|
ready(): Promise<void>;
|
1298
1298
|
readonly logger: Logger;
|
1299
1299
|
readonly sthis: SuperThis;
|
1300
1300
|
readonly id: string;
|
1301
|
-
constructor(sthis: SuperThis, opts:
|
1301
|
+
constructor(sthis: SuperThis, opts: DatabaseOpts);
|
1302
1302
|
get name(): string;
|
1303
1303
|
get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
|
1304
1304
|
put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
|
@@ -1320,7 +1320,7 @@ declare class LedgerImpl<DT extends DocTypes = NonNullable<unknown>> implements
|
|
1320
1320
|
_no_update_notify(): Promise<void>;
|
1321
1321
|
}
|
1322
1322
|
declare function toStoreURIRuntime(sthis: SuperThis, name?: string, sopts?: StoreUrlsOpts): StoreURIRuntime;
|
1323
|
-
declare function fireproof(name: string, opts?: ConfigOpts):
|
1323
|
+
declare function fireproof(name: string, opts?: ConfigOpts): Database;
|
1324
1324
|
|
1325
1325
|
declare function getPath(url: URI, sthis: SuperThis$1): string;
|
1326
1326
|
declare function getFileName(url: URI, sthis: SuperThis$1): string;
|
@@ -1517,5 +1517,5 @@ declare namespace index {
|
|
1517
1517
|
|
1518
1518
|
declare const PACKAGE_VERSION: string;
|
1519
1519
|
|
1520
|
-
export { type AllDocsQueryOpts, type AllDocsResponse, type BulkResponse, CRDT, type CRDTEntry, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, type DbMeta, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocLiteral, type DocObject, type DocRecord, type DocResponse, type DocSet, type DocTypes, type DocUpdate, type DocValue, type DocWithId, type FPStats, type Falsy, type FileTransactionMeta, type HasCRDT, type IdxMeta, type IdxMetaMap, Index, type IndexKey, type IndexKeyType, type IndexRow, type IndexRows, type IndexTransactionMeta, type IndexUpdate, type IndexUpdateString, type Joiner, type KeyLiteral, type
|
1520
|
+
export { type AllDocsQueryOpts, type AllDocsResponse, type BulkResponse, CRDT, type CRDTEntry, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, type Database, DatabaseFactory, type DatabaseOpts, DatabaseShell, type DbMeta, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocLiteral, type DocObject, type DocRecord, type DocResponse, type DocSet, type DocTypes, type DocUpdate, type DocValue, type DocWithId, type FPStats, type Falsy, type FileTransactionMeta, type HasCRDT, type IdxMeta, type IdxMetaMap, Index, type IndexKey, type IndexKeyType, type IndexRow, type IndexRows, type IndexTransactionMeta, type IndexUpdate, type IndexUpdateString, type Joiner, type KeyLiteral, type ListenerFn, type MapFn, type MetaType, type NoUpdateListenerFn, NotFoundError, PACKAGE_VERSION, PARAM, type PathOps, type PromiseToUInt8, type QueryOpts, type Store, type StoreType, type SuperThis, type SuperThisOpts, type SysFileSystem, type TextEndeCoder, type ToUInt8, UInt8ArrayEqual, type UnknownDoc, type UpdateListenerFn, index$5 as blockstore, index$5 as bs, coerceIntoUint8, coercePromiseIntoUint8, defaultWriteQueueOpts, ensureLogger, ensureSuperLog, ensureSuperThis, exceptionWrapper, falsyToUndef, fireproof, getKey, getName, getStore, index$4 as index, inplaceFilter, isDatabase, isFalsy, isNotFoundError, keyConfigOpts, onSuperThis, index as rt, index as runtime, throwFalsy, toSortedArray, toStoreURIRuntime };
|
1521
1521
|
declare module '@fireproof/core'
|
package/index.d.ts
CHANGED
@@ -1185,14 +1185,14 @@ interface HasCRDT<T extends DocTypes> {
|
|
1185
1185
|
readonly crdt: CRDT<T> | CRDT<NonNullable<unknown>>;
|
1186
1186
|
}
|
1187
1187
|
declare class CRDT<T extends DocTypes> {
|
1188
|
-
readonly opts:
|
1188
|
+
readonly opts: DatabaseOpts;
|
1189
1189
|
readonly blockstore: BaseBlockstore;
|
1190
1190
|
readonly indexBlockstore: BaseBlockstore;
|
1191
1191
|
readonly indexers: Map<string, Index<IndexKeyType, NonNullable<unknown>>>;
|
1192
1192
|
readonly clock: CRDTClock<T>;
|
1193
1193
|
readonly logger: Logger;
|
1194
1194
|
readonly sthis: SuperThis;
|
1195
|
-
constructor(sthis: SuperThis, opts:
|
1195
|
+
constructor(sthis: SuperThis, opts: DatabaseOpts);
|
1196
1196
|
bulk(updates: DocUpdate<T>[]): Promise<CRDTMeta>;
|
1197
1197
|
readonly onceReady: ResolveOnce<void>;
|
1198
1198
|
ready(): Promise<void>;
|
@@ -1213,7 +1213,7 @@ declare class CRDT<T extends DocTypes> {
|
|
1213
1213
|
}
|
1214
1214
|
|
1215
1215
|
declare function keyConfigOpts(sthis: SuperThis, name?: string, opts?: ConfigOpts): string;
|
1216
|
-
interface
|
1216
|
+
interface DatabaseOpts {
|
1217
1217
|
readonly name?: string;
|
1218
1218
|
readonly meta?: DbMeta;
|
1219
1219
|
readonly gatewayInterceptor?: SerdeGatewayInterceptor;
|
@@ -1222,7 +1222,7 @@ interface LedgerOpts {
|
|
1222
1222
|
readonly storeEnDe: StoreEnDeFile;
|
1223
1223
|
readonly keyBag: KeyBagRuntime;
|
1224
1224
|
}
|
1225
|
-
interface
|
1225
|
+
interface Database<DT extends DocTypes = NonNullable<unknown>> extends HasCRDT<DT> {
|
1226
1226
|
readonly logger: Logger;
|
1227
1227
|
readonly sthis: SuperThis;
|
1228
1228
|
readonly id: string;
|
@@ -1248,11 +1248,11 @@ interface Ledger<DT extends DocTypes = NonNullable<unknown>> extends HasCRDT<DT>
|
|
1248
1248
|
query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
|
1249
1249
|
compact(): Promise<void>;
|
1250
1250
|
}
|
1251
|
-
declare function
|
1252
|
-
declare function
|
1253
|
-
declare class
|
1254
|
-
readonly ref:
|
1255
|
-
constructor(ref:
|
1251
|
+
declare function isDatabase<T extends DocTypes = NonNullable<unknown>>(db: unknown): db is Database<T>;
|
1252
|
+
declare function DatabaseFactory<T extends DocTypes = NonNullable<unknown>>(name: string | undefined, opts?: ConfigOpts): Database<T>;
|
1253
|
+
declare class DatabaseShell<DT extends DocTypes = NonNullable<unknown>> implements Database<DT> {
|
1254
|
+
readonly ref: DatabaseImpl<DT>;
|
1255
|
+
constructor(ref: DatabaseImpl<DT>);
|
1256
1256
|
get id(): string;
|
1257
1257
|
get logger(): Logger;
|
1258
1258
|
get sthis(): SuperThis;
|
@@ -1279,26 +1279,26 @@ declare class LedgerShell<DT extends DocTypes = NonNullable<unknown>> implements
|
|
1279
1279
|
query<K extends IndexKeyType, T extends DocTypes, R extends DocFragment = T>(field: string | MapFn<T>, opts?: QueryOpts<K>): Promise<IndexRows<K, T, R>>;
|
1280
1280
|
compact(): Promise<void>;
|
1281
1281
|
}
|
1282
|
-
declare class
|
1283
|
-
readonly opts:
|
1282
|
+
declare class DatabaseImpl<DT extends DocTypes = NonNullable<unknown>> implements Database<DT> {
|
1283
|
+
readonly opts: DatabaseOpts;
|
1284
1284
|
_listening: boolean;
|
1285
1285
|
readonly _listeners: Set<ListenerFn<DT>>;
|
1286
1286
|
readonly _noupdate_listeners: Set<ListenerFn<DT>>;
|
1287
1287
|
readonly crdt: CRDT<DT>;
|
1288
1288
|
readonly _writeQueue: WriteQueue<DT>;
|
1289
|
-
readonly shells: Set<
|
1290
|
-
addShell(shell:
|
1289
|
+
readonly shells: Set<DatabaseShell<DT>>;
|
1290
|
+
addShell(shell: DatabaseShell<DT>): void;
|
1291
1291
|
readonly _onClosedFns: Set<() => void>;
|
1292
1292
|
onClosed(fn: () => void): void;
|
1293
1293
|
close(): Promise<void>;
|
1294
|
-
shellClose(db:
|
1294
|
+
shellClose(db: DatabaseShell<DT>): Promise<void>;
|
1295
1295
|
destroy(): Promise<void>;
|
1296
1296
|
readonly _ready: ResolveOnce<void>;
|
1297
1297
|
ready(): Promise<void>;
|
1298
1298
|
readonly logger: Logger;
|
1299
1299
|
readonly sthis: SuperThis;
|
1300
1300
|
readonly id: string;
|
1301
|
-
constructor(sthis: SuperThis, opts:
|
1301
|
+
constructor(sthis: SuperThis, opts: DatabaseOpts);
|
1302
1302
|
get name(): string;
|
1303
1303
|
get<T extends DocTypes>(id: string): Promise<DocWithId<T>>;
|
1304
1304
|
put<T extends DocTypes>(doc: DocSet<T>): Promise<DocResponse>;
|
@@ -1320,7 +1320,7 @@ declare class LedgerImpl<DT extends DocTypes = NonNullable<unknown>> implements
|
|
1320
1320
|
_no_update_notify(): Promise<void>;
|
1321
1321
|
}
|
1322
1322
|
declare function toStoreURIRuntime(sthis: SuperThis, name?: string, sopts?: StoreUrlsOpts): StoreURIRuntime;
|
1323
|
-
declare function fireproof(name: string, opts?: ConfigOpts):
|
1323
|
+
declare function fireproof(name: string, opts?: ConfigOpts): Database;
|
1324
1324
|
|
1325
1325
|
declare function getPath(url: URI, sthis: SuperThis$1): string;
|
1326
1326
|
declare function getFileName(url: URI, sthis: SuperThis$1): string;
|
@@ -1517,5 +1517,5 @@ declare namespace index {
|
|
1517
1517
|
|
1518
1518
|
declare const PACKAGE_VERSION: string;
|
1519
1519
|
|
1520
|
-
export { type AllDocsQueryOpts, type AllDocsResponse, type BulkResponse, CRDT, type CRDTEntry, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, type DbMeta, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocLiteral, type DocObject, type DocRecord, type DocResponse, type DocSet, type DocTypes, type DocUpdate, type DocValue, type DocWithId, type FPStats, type Falsy, type FileTransactionMeta, type HasCRDT, type IdxMeta, type IdxMetaMap, Index, type IndexKey, type IndexKeyType, type IndexRow, type IndexRows, type IndexTransactionMeta, type IndexUpdate, type IndexUpdateString, type Joiner, type KeyLiteral, type
|
1520
|
+
export { type AllDocsQueryOpts, type AllDocsResponse, type BulkResponse, CRDT, type CRDTEntry, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ChangesResponseRow, type ClockHead, type ClockLink, type ConfigOpts, type Database, DatabaseFactory, type DatabaseOpts, DatabaseShell, type DbMeta, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocLiteral, type DocObject, type DocRecord, type DocResponse, type DocSet, type DocTypes, type DocUpdate, type DocValue, type DocWithId, type FPStats, type Falsy, type FileTransactionMeta, type HasCRDT, type IdxMeta, type IdxMetaMap, Index, type IndexKey, type IndexKeyType, type IndexRow, type IndexRows, type IndexTransactionMeta, type IndexUpdate, type IndexUpdateString, type Joiner, type KeyLiteral, type ListenerFn, type MapFn, type MetaType, type NoUpdateListenerFn, NotFoundError, PACKAGE_VERSION, PARAM, type PathOps, type PromiseToUInt8, type QueryOpts, type Store, type StoreType, type SuperThis, type SuperThisOpts, type SysFileSystem, type TextEndeCoder, type ToUInt8, UInt8ArrayEqual, type UnknownDoc, type UpdateListenerFn, index$5 as blockstore, index$5 as bs, coerceIntoUint8, coercePromiseIntoUint8, defaultWriteQueueOpts, ensureLogger, ensureSuperLog, ensureSuperThis, exceptionWrapper, falsyToUndef, fireproof, getKey, getName, getStore, index$4 as index, inplaceFilter, isDatabase, isFalsy, isNotFoundError, keyConfigOpts, onSuperThis, index as rt, index as runtime, throwFalsy, toSortedArray, toStoreURIRuntime };
|
1521
1521
|
declare module '@fireproof/core'
|
package/index.js
CHANGED
@@ -4,7 +4,7 @@ var __export = (target, all) => {
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
5
5
|
};
|
6
6
|
|
7
|
-
// src/
|
7
|
+
// src/database.ts
|
8
8
|
import { BuildURI as BuildURI2, KeyedResolvOnce as KeyedResolvOnce4, ResolveOnce as ResolveOnce7, URI as URI12 } from "@adviser/cement";
|
9
9
|
|
10
10
|
// src/utils.ts
|
@@ -796,7 +796,7 @@ var EncryptedBlockstore = class extends BaseBlockstore {
|
|
796
796
|
}
|
797
797
|
async getFile(car, cid) {
|
798
798
|
await this.ready();
|
799
|
-
if (!this.loader) throw this.logger.Error().Msg("loader required to get file,
|
799
|
+
if (!this.loader) throw this.logger.Error().Msg("loader required to get file, database must be named").AsError();
|
800
800
|
const reader = await this.loader.loadFileCar(
|
801
801
|
car
|
802
802
|
/*, isPublic */
|
@@ -3256,9 +3256,9 @@ var ConnectionBase = class {
|
|
3256
3256
|
// // await this.compact()
|
3257
3257
|
// // }
|
3258
3258
|
// const currents = await this.loader?.metaStore?.load()
|
3259
|
-
// if (!currents) throw new Error("Can't sync empty
|
3259
|
+
// if (!currents) throw new Error("Can't sync empty database: save data first")
|
3260
3260
|
// if (currents.length > 1)
|
3261
|
-
// throw new Error("Can't sync
|
3261
|
+
// throw new Error("Can't sync database with split heads: make an update first")
|
3262
3262
|
// const current = currents[0]
|
3263
3263
|
// const params = {
|
3264
3264
|
// car: current.car.toString()
|
@@ -3357,7 +3357,7 @@ async function processFiles(store, blocks, doc, logger) {
|
|
3357
3357
|
}
|
3358
3358
|
async function processFileset(logger, store, blocks, files) {
|
3359
3359
|
const dbBlockstore = blocks.parent;
|
3360
|
-
if (!dbBlockstore.loader) throw logger.Error().Msg("Missing loader,
|
3360
|
+
if (!dbBlockstore.loader) throw logger.Error().Msg("Missing loader, database name is required").AsError();
|
3361
3361
|
const t = new CarTransaction(dbBlockstore);
|
3362
3362
|
const didPut = [];
|
3363
3363
|
for (const filename in files) {
|
@@ -3389,7 +3389,7 @@ async function processFileset(logger, store, blocks, files) {
|
|
3389
3389
|
}
|
3390
3390
|
}
|
3391
3391
|
async function getValueFromCrdt(blocks, head, key, logger) {
|
3392
|
-
if (!head.length) throw logger.Debug().Msg("Getting from an empty
|
3392
|
+
if (!head.length) throw logger.Debug().Msg("Getting from an empty database").AsError();
|
3393
3393
|
const link = await get(blocks, head, key);
|
3394
3394
|
if (!link) throw logger.Error().Str("key", key).Msg(`Missing key`).AsError();
|
3395
3395
|
return await getValueFromLink(blocks, link, logger);
|
@@ -4188,8 +4188,8 @@ var CRDT = class {
|
|
4188
4188
|
}
|
4189
4189
|
};
|
4190
4190
|
|
4191
|
-
// src/
|
4192
|
-
var
|
4191
|
+
// src/database.ts
|
4192
|
+
var databases = new KeyedResolvOnce4();
|
4193
4193
|
function keyConfigOpts(sthis, name, opts) {
|
4194
4194
|
return JSON.stringify(
|
4195
4195
|
toSortedArray({
|
@@ -4198,14 +4198,14 @@ function keyConfigOpts(sthis, name, opts) {
|
|
4198
4198
|
})
|
4199
4199
|
);
|
4200
4200
|
}
|
4201
|
-
function
|
4202
|
-
return db instanceof
|
4201
|
+
function isDatabase(db) {
|
4202
|
+
return db instanceof DatabaseImpl || db instanceof DatabaseShell;
|
4203
4203
|
}
|
4204
|
-
function
|
4204
|
+
function DatabaseFactory(name, opts) {
|
4205
4205
|
const sthis = ensureSuperThis(opts);
|
4206
|
-
return new
|
4207
|
-
|
4208
|
-
const db = new
|
4206
|
+
return new DatabaseShell(
|
4207
|
+
databases.get(keyConfigOpts(sthis, name, opts)).once((key) => {
|
4208
|
+
const db = new DatabaseImpl(sthis, {
|
4209
4209
|
name,
|
4210
4210
|
meta: opts?.meta,
|
4211
4211
|
keyBag: defaultKeyBagOpts(sthis, opts?.keyBag),
|
@@ -4219,13 +4219,13 @@ function LedgerFactory(name, opts) {
|
|
4219
4219
|
}
|
4220
4220
|
});
|
4221
4221
|
db.onClosed(() => {
|
4222
|
-
|
4222
|
+
databases.unget(key);
|
4223
4223
|
});
|
4224
4224
|
return db;
|
4225
4225
|
})
|
4226
4226
|
);
|
4227
4227
|
}
|
4228
|
-
var
|
4228
|
+
var DatabaseShell = class {
|
4229
4229
|
constructor(ref) {
|
4230
4230
|
this.ref = ref;
|
4231
4231
|
ref.addShell(this);
|
@@ -4288,7 +4288,7 @@ var LedgerShell = class {
|
|
4288
4288
|
return this.ref.compact();
|
4289
4289
|
}
|
4290
4290
|
};
|
4291
|
-
var
|
4291
|
+
var DatabaseImpl = class {
|
4292
4292
|
constructor(sthis, opts) {
|
4293
4293
|
this._listening = false;
|
4294
4294
|
this._listeners = /* @__PURE__ */ new Set();
|
@@ -4300,7 +4300,7 @@ var LedgerImpl = class {
|
|
4300
4300
|
this.opts = opts;
|
4301
4301
|
this.sthis = sthis;
|
4302
4302
|
this.id = sthis.timeOrderedNextId().str;
|
4303
|
-
this.logger = ensureLogger(this.sthis, "
|
4303
|
+
this.logger = ensureLogger(this.sthis, "Database");
|
4304
4304
|
this.crdt = new CRDT(this.sthis, this.opts);
|
4305
4305
|
this._writeQueue = writeQueue(this.sthis, async (updates) => this.crdt.bulk(updates), this.opts.writeQueue);
|
4306
4306
|
this.crdt.clock.onTock(() => this._no_update_notify());
|
@@ -4316,7 +4316,7 @@ var LedgerImpl = class {
|
|
4316
4316
|
}
|
4317
4317
|
async shellClose(db) {
|
4318
4318
|
if (!this.shells.has(db)) {
|
4319
|
-
throw this.logger.Error().Str("db", this.name).Msg(`
|
4319
|
+
throw this.logger.Error().Str("db", this.name).Msg(`DatabaseShell mismatch`).AsError();
|
4320
4320
|
}
|
4321
4321
|
this.shells.delete(db);
|
4322
4322
|
if (this.shells.size === 0) {
|
@@ -4470,7 +4470,7 @@ function defaultURI2(sthis, curi, uri, store, ctx) {
|
|
4470
4470
|
if (!ret.hasParam("name" /* NAME */)) {
|
4471
4471
|
const name = sthis.pathOps.basename(ret.URI().pathname);
|
4472
4472
|
if (!name) {
|
4473
|
-
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("
|
4473
|
+
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Database name is required").AsError();
|
4474
4474
|
}
|
4475
4475
|
ret.setParam("name" /* NAME */, name);
|
4476
4476
|
}
|
@@ -4519,7 +4519,7 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
4519
4519
|
};
|
4520
4520
|
}
|
4521
4521
|
function fireproof(name, opts) {
|
4522
|
-
return
|
4522
|
+
return DatabaseFactory(name, opts);
|
4523
4523
|
}
|
4524
4524
|
function makeName(fnString) {
|
4525
4525
|
const regex = /\(([^,()]+,\s*[^,()]+|\[[^\]]+\],\s*[^,()]+)\)/g;
|
@@ -4540,13 +4540,13 @@ function makeName(fnString) {
|
|
4540
4540
|
|
4541
4541
|
// src/version.ts
|
4542
4542
|
var PACKAGE_VERSION = Object.keys({
|
4543
|
-
"0.20.0-dev-preview-
|
4543
|
+
"0.20.0-dev-preview-06": "xxxx"
|
4544
4544
|
})[0];
|
4545
4545
|
export {
|
4546
4546
|
CRDT,
|
4547
|
+
DatabaseFactory,
|
4548
|
+
DatabaseShell,
|
4547
4549
|
Index,
|
4548
|
-
LedgerFactory,
|
4549
|
-
LedgerShell,
|
4550
4550
|
NotFoundError,
|
4551
4551
|
PACKAGE_VERSION,
|
4552
4552
|
PARAM,
|
@@ -4567,8 +4567,8 @@ export {
|
|
4567
4567
|
getStore,
|
4568
4568
|
index,
|
4569
4569
|
inplaceFilter,
|
4570
|
+
isDatabase,
|
4570
4571
|
isFalsy,
|
4571
|
-
isLedger,
|
4572
4572
|
isNotFoundError,
|
4573
4573
|
keyConfigOpts,
|
4574
4574
|
onSuperThis,
|