@fireproof/core 0.13.4-dev → 0.13.5-dev
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/fireproof.cjs +21586 -4
- package/dist/browser/fireproof.cjs.map +4 -4
- package/dist/browser/fireproof.esm.js +21580 -4
- package/dist/browser/fireproof.esm.js.map +4 -4
- package/dist/browser/fireproof.iife.js +21588 -4
- package/dist/browser/fireproof.iife.js.map +4 -4
- package/dist/node/fireproof.cjs +21591 -4
- package/dist/node/fireproof.cjs.map +4 -4
- package/dist/node/fireproof.esm.js +21568 -4
- package/dist/node/fireproof.esm.js.map +4 -4
- package/dist/types/apply-head-queue.d.ts +18 -0
- package/dist/types/commit-queue.d.ts +6 -0
- package/dist/types/crdt-clock.d.ts +7 -0
- package/dist/types/crdt-helpers.d.ts +2 -2
- package/dist/types/database.d.ts +14 -2
- package/dist/types/encrypt-helpers.d.ts +3 -2
- package/dist/types/loader.d.ts +17 -3
- package/dist/types/loaders.d.ts +7 -0
- package/dist/types/remote-wal.d.ts +3 -2
- package/dist/types/transaction.d.ts +4 -4
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -3
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Transaction } from "./transaction";
|
2
|
+
import { ClockHead, DocUpdate } from "./types";
|
3
|
+
type ApplyHeadWorkerFunction = (id: string, tblocks: Transaction | null, newHead: ClockHead, prevHead: ClockHead, updates: DocUpdate[] | null) => Promise<void>;
|
4
|
+
type ApplyHeadTask = {
|
5
|
+
id: string;
|
6
|
+
tblocks: Transaction | null;
|
7
|
+
newHead: ClockHead;
|
8
|
+
prevHead: ClockHead;
|
9
|
+
updates: DocUpdate[] | null;
|
10
|
+
};
|
11
|
+
export type ApplyHeadQueue = {
|
12
|
+
push(task: ApplyHeadTask): AsyncGenerator<{
|
13
|
+
updates: DocUpdate[];
|
14
|
+
all: boolean;
|
15
|
+
}, void, unknown>;
|
16
|
+
};
|
17
|
+
export declare function applyHeadQueue(worker: ApplyHeadWorkerFunction): ApplyHeadQueue;
|
18
|
+
export {};
|
@@ -1,12 +1,19 @@
|
|
1
1
|
import { TransactionBlockstore, Transaction } from './transaction';
|
2
2
|
import type { DocUpdate, ClockHead } from './types';
|
3
|
+
import { ApplyHeadQueue } from './apply-head-queue';
|
3
4
|
export declare class CRDTClock {
|
4
5
|
head: ClockHead;
|
5
6
|
zoomers: Set<(() => void)>;
|
6
7
|
watchers: Set<((updates: DocUpdate[]) => void)>;
|
8
|
+
emptyWatchers: Set<(() => void)>;
|
7
9
|
blocks: TransactionBlockstore | null;
|
10
|
+
applyHeadQueue: ApplyHeadQueue;
|
11
|
+
constructor();
|
8
12
|
setHead(head: ClockHead): void;
|
9
13
|
applyHead(tblocks: Transaction | null, newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate[] | null): Promise<void>;
|
14
|
+
int_applyHead(taskId: string, tblocks: Transaction | null, newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate[] | null): Promise<void>;
|
15
|
+
notifyWatchers(updates: DocUpdate[]): void;
|
10
16
|
onTick(fn: (updates: DocUpdate[]) => void): void;
|
17
|
+
onTock(fn: () => void): void;
|
11
18
|
onZoom(fn: () => void): void;
|
12
19
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { LoggingFetcher, Transaction } from './transaction';
|
2
2
|
import type { TransactionBlockstore } from './transaction';
|
3
|
-
import type { DocUpdate, ClockHead, DocValue, BulkResult, ChangesOptions } from './types';
|
3
|
+
import type { DocUpdate, ClockHead, AnyLink, DocValue, BulkResult, ChangesOptions } from './types';
|
4
4
|
export declare function applyBulkUpdateToCrdt(tblocks: Transaction, head: ClockHead, updates: DocUpdate[], options?: object): Promise<BulkResult>;
|
5
5
|
export declare function getValueFromCrdt(blocks: TransactionBlockstore, head: ClockHead, key: string): Promise<DocValue>;
|
6
6
|
export declare function readFiles(blocks: TransactionBlockstore | LoggingFetcher, { doc }: DocValue): void;
|
@@ -10,4 +10,4 @@ export declare function clockChangesSince(blocks: TransactionBlockstore | Loggin
|
|
10
10
|
}>;
|
11
11
|
export declare function getAllEntries(blocks: TransactionBlockstore, head: ClockHead): AsyncGenerator<DocUpdate, void, unknown>;
|
12
12
|
export declare function clockVis(blocks: TransactionBlockstore, head: ClockHead): AsyncGenerator<string, void, unknown>;
|
13
|
-
export declare function doCompact(blocks: TransactionBlockstore, head: ClockHead): Promise<
|
13
|
+
export declare function doCompact(blocks: TransactionBlockstore, head: ClockHead): Promise<AnyLink | undefined>;
|
package/dist/types/database.d.ts
CHANGED
@@ -7,7 +7,9 @@ export declare class Database {
|
|
7
7
|
static databases: Map<string, Database>;
|
8
8
|
name: DbName;
|
9
9
|
opts: FireproofOptions;
|
10
|
+
_listening: boolean;
|
10
11
|
_listeners: Set<ListenerFn>;
|
12
|
+
_noupdate_listeners: Set<ListenerFn>;
|
11
13
|
_crdt: CRDT;
|
12
14
|
_writeQueue: WriteQueue;
|
13
15
|
constructor(name?: string, opts?: FireproofOptions);
|
@@ -15,7 +17,14 @@ export declare class Database {
|
|
15
17
|
put(doc: Doc): Promise<DbResponse>;
|
16
18
|
del(id: string): Promise<DbResponse>;
|
17
19
|
changes(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse>;
|
18
|
-
|
20
|
+
allDocs(): Promise<{
|
21
|
+
rows: {
|
22
|
+
key: string;
|
23
|
+
value: Doc;
|
24
|
+
}[];
|
25
|
+
clock: ClockHead;
|
26
|
+
}>;
|
27
|
+
subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void;
|
19
28
|
query(field: string | MapFn, opts?: QueryOpts): Promise<{
|
20
29
|
rows: import("./types").IndexRow[];
|
21
30
|
}>;
|
@@ -23,7 +32,10 @@ export declare class Database {
|
|
23
32
|
getDashboardURL(compact?: boolean): Promise<URL>;
|
24
33
|
openDashboard(): void;
|
25
34
|
_notify(updates: DocUpdate[]): Promise<void>;
|
35
|
+
_no_update_notify(): Promise<void>;
|
26
36
|
}
|
27
|
-
type
|
37
|
+
type UpdateListenerFn = (docs: Doc[]) => Promise<void> | void;
|
38
|
+
type NoUpdateListenerFn = () => Promise<void> | void;
|
39
|
+
type ListenerFn = UpdateListenerFn | NoUpdateListenerFn;
|
28
40
|
export declare function fireproof(name: string, opts?: FireproofOptions): Database;
|
29
41
|
export {};
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import type { CarReader } from '@ipld/car';
|
2
|
-
import type { AnyBlock, CarMakeable, AnyLink
|
2
|
+
import type { AnyBlock, CarMakeable, AnyLink } from './types';
|
3
|
+
import { MemoryBlockstore } from '@alanshaw/pail/block';
|
3
4
|
export declare function encryptedEncodeCarFile(key: string, rootCid: AnyLink, t: CarMakeable): Promise<AnyBlock>;
|
4
5
|
export declare function decodeEncryptedCar(key: string, reader: CarReader): Promise<{
|
5
|
-
blocks:
|
6
|
+
blocks: MemoryBlockstore;
|
6
7
|
root: AnyLink;
|
7
8
|
}>;
|
package/dist/types/loader.d.ts
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
import { CarReader } from '@ipld/car';
|
2
2
|
import { DataStore, MetaStore, RemoteWAL } from './store-browser';
|
3
|
-
import
|
3
|
+
import { DataStore as AbstractDataStore, MetaStore as AbstractMetaStore } from './store';
|
4
4
|
import type { Transaction } from './transaction';
|
5
5
|
import type { AnyBlock, AnyCarHeader, AnyLink, BulkResult, CarLoaderHeader, CommitOpts, DbMeta, FileCarHeader, FileResult, FireproofOptions } from './types';
|
6
6
|
import { type IndexerResult } from './loaders';
|
7
|
+
import { CommitQueue } from './commit-queue';
|
7
8
|
export declare function cidListIncludes(list: AnyLink[], cid: AnyLink): boolean;
|
9
|
+
export declare function uniqueCids(list: AnyLink[], remove?: Set<string>): AnyLink[];
|
8
10
|
export declare function toHexString(byteArray: Uint8Array): string;
|
11
|
+
declare abstract class AbstractRemoteMetaStore extends AbstractMetaStore {
|
12
|
+
abstract handleByteHeads(byteHeads: Uint8Array[], branch?: string): Promise<DbMeta[]>;
|
13
|
+
}
|
9
14
|
export declare abstract class Loader {
|
10
15
|
name: string;
|
11
16
|
opts: FireproofOptions;
|
17
|
+
commitQueue: CommitQueue<AnyLink>;
|
18
|
+
isCompacting: boolean;
|
19
|
+
isWriting: boolean;
|
12
20
|
remoteMetaLoading: Promise<void> | undefined;
|
13
|
-
remoteMetaStore:
|
21
|
+
remoteMetaStore: AbstractRemoteMetaStore | undefined;
|
14
22
|
remoteCarStore: AbstractDataStore | undefined;
|
15
23
|
remoteWAL: RemoteWAL;
|
16
24
|
metaStore: MetaStore;
|
@@ -20,20 +28,25 @@ export declare abstract class Loader {
|
|
20
28
|
ready: Promise<void>;
|
21
29
|
key: string | undefined;
|
22
30
|
keyId: string | undefined;
|
31
|
+
seenCompacted: Set<string>;
|
23
32
|
private getBlockCache;
|
33
|
+
private seenMeta;
|
24
34
|
static defaultHeader: AnyCarHeader;
|
25
35
|
abstract defaultHeader: AnyCarHeader;
|
26
36
|
constructor(name: string, opts?: FireproofOptions);
|
27
37
|
snapToCar(carCid: AnyLink | string): Promise<void>;
|
38
|
+
_readyForMerge(): Promise<void>;
|
39
|
+
_setWaitForWrite(_writing: () => Promise<void>): Promise<void>;
|
28
40
|
handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
|
29
41
|
mergeDbMetaIntoClock(meta: DbMeta): Promise<void>;
|
30
42
|
protected ingestKeyFromMeta(meta: DbMeta): Promise<void>;
|
31
43
|
loadCarHeaderFromMeta({ car: cid }: DbMeta): Promise<CarLoaderHeader>;
|
32
44
|
protected abstract _applyCarHeader(_carHeader: CarLoaderHeader, snap?: boolean): Promise<void>;
|
33
45
|
_getKey(): Promise<string | undefined>;
|
34
|
-
private committing;
|
35
46
|
commit(t: Transaction, done: IndexerResult | BulkResult | FileResult, opts?: CommitOpts): Promise<AnyLink>;
|
36
47
|
_commitInternal(t: Transaction, done: IndexerResult | BulkResult | FileResult, opts?: CommitOpts): Promise<AnyLink>;
|
48
|
+
flushCars(): Promise<void>;
|
49
|
+
entries(): AsyncIterableIterator<AnyBlock>;
|
37
50
|
getBlock(cid: AnyLink): Promise<AnyBlock | undefined>;
|
38
51
|
protected abstract makeCarHeader(_result: BulkResult | IndexerResult | FileResult, _cars: AnyLink[], _compact: boolean): AnyCarHeader | FileCarHeader;
|
39
52
|
protected loadCar(cid: AnyLink): Promise<CarReader>;
|
@@ -46,3 +59,4 @@ export interface Connection {
|
|
46
59
|
loader: Loader;
|
47
60
|
loaded: Promise<void>;
|
48
61
|
}
|
62
|
+
export {};
|
package/dist/types/loaders.d.ts
CHANGED
@@ -5,6 +5,7 @@ import type { CRDTClock } from './crdt-clock';
|
|
5
5
|
import { Loader } from './loader';
|
6
6
|
import type { DataStore as AbstractDataStore } from './store';
|
7
7
|
import { DataStore } from './store-browser';
|
8
|
+
import { TransactionBlockstore } from './transaction';
|
8
9
|
export declare class IdxLoader extends Loader {
|
9
10
|
crdt: CRDT;
|
10
11
|
static defaultHeader: {
|
@@ -34,9 +35,15 @@ export declare class DbLoader extends Loader {
|
|
34
35
|
head: never[];
|
35
36
|
};
|
36
37
|
clock: CRDTClock;
|
38
|
+
awaitingCompact: boolean;
|
39
|
+
compacting: Promise<AnyLink | void>;
|
40
|
+
writing: Promise<BulkResult | void>;
|
37
41
|
remoteFileStore: AbstractDataStore | undefined;
|
38
42
|
fileStore: DataStore;
|
39
43
|
constructor(name: string, clock: CRDTClock, opts?: FireproofOptions);
|
44
|
+
_readyForMerge(): Promise<void>;
|
45
|
+
_setWaitForWrite(_writingFn: () => Promise<any>): Promise<void>;
|
46
|
+
compact(blocks: TransactionBlockstore): Promise<void>;
|
40
47
|
loadFileCar(cid: AnyLink, isPublic?: boolean): Promise<CarReader>;
|
41
48
|
protected _applyCarHeader(carHeader: DbCarHeader, snap?: boolean): Promise<void>;
|
42
49
|
protected makeCarHeader(result: BulkResult | FileResult, cars: AnyLink[], compact?: boolean): DbCarHeader | FileCarHeader;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { AnyLink, CommitOpts, DbMeta } from './types';
|
2
|
-
import type
|
2
|
+
import { type Loader } from './loader';
|
3
3
|
export type WALState = {
|
4
4
|
operations: DbMeta[];
|
5
5
|
noLoaderOps: DbMeta[];
|
@@ -15,11 +15,12 @@ export declare abstract class RemoteWAL {
|
|
15
15
|
ready: Promise<void>;
|
16
16
|
walState: WALState;
|
17
17
|
processing: Promise<void> | undefined;
|
18
|
+
private processQueue;
|
18
19
|
constructor(loader: Loader);
|
19
20
|
enqueue(dbMeta: DbMeta, opts: CommitOpts): Promise<void>;
|
20
21
|
enqueueFile(fileCid: AnyLink, publicFile?: boolean): Promise<void>;
|
21
22
|
_process(): Promise<void>;
|
22
|
-
|
23
|
+
_doProcess(): Promise<void>;
|
23
24
|
abstract load(branch?: string): Promise<WALState | null>;
|
24
25
|
abstract save(state: WALState, branch?: string): Promise<void>;
|
25
26
|
}
|
@@ -4,8 +4,8 @@ import { DbLoader, IdxLoader } from './loaders';
|
|
4
4
|
import { CRDT } from './crdt';
|
5
5
|
import { CRDTClock } from './crdt-clock';
|
6
6
|
export declare class Transaction extends MemoryBlockstore implements CarMakeable {
|
7
|
-
parent:
|
8
|
-
constructor(parent:
|
7
|
+
parent: FireproofBlockstore;
|
8
|
+
constructor(parent: FireproofBlockstore);
|
9
9
|
get(cid: AnyLink): Promise<AnyBlock | undefined>;
|
10
10
|
superGet(cid: AnyLink): Promise<AnyBlock | undefined>;
|
11
11
|
}
|
@@ -21,7 +21,7 @@ declare abstract class FireproofBlockstore implements BlockFetcher {
|
|
21
21
|
}): Promise<BulkResultCar | IdxMetaCar>;
|
22
22
|
put(): Promise<void>;
|
23
23
|
get(cid: AnyLink): Promise<AnyBlock | undefined>;
|
24
|
-
commitCompaction(t: Transaction, head: ClockHead): Promise<AnyLink
|
24
|
+
commitCompaction(t: Transaction, head: ClockHead): Promise<AnyLink>;
|
25
25
|
entries(): AsyncIterableIterator<AnyBlock>;
|
26
26
|
protected executeTransaction<T, R>(fn: (t: Transaction) => Promise<T>, commitHandler: (t: Transaction, done: T) => Promise<{
|
27
27
|
car?: AnyLink;
|
@@ -43,7 +43,7 @@ type BulkResultCar = BulkResult & CarCommit;
|
|
43
43
|
export declare class LoggingFetcher implements BlockFetcher {
|
44
44
|
blocks: TransactionBlockstore;
|
45
45
|
loader: DbLoader | IdxLoader | null;
|
46
|
-
|
46
|
+
loggedBlocks: Transaction;
|
47
47
|
constructor(blocks: TransactionBlockstore);
|
48
48
|
get(cid: AnyLink): Promise<AnyBlock | undefined>;
|
49
49
|
}
|
package/dist/types/version.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const PACKAGE_VERSION = "0.13.
|
1
|
+
export declare const PACKAGE_VERSION = "0.13.5-dev";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fireproof/core",
|
3
|
-
"version": "0.13.
|
3
|
+
"version": "0.13.5-dev",
|
4
4
|
"description": "Live database for the web",
|
5
5
|
"main": "./dist/browser/fireproof.cjs",
|
6
6
|
"module": "./dist/browser/fireproof.esm.js",
|
@@ -36,12 +36,12 @@
|
|
36
36
|
"build:_types": "tsc --declaration --outDir dist/types && node ./scripts/types.js",
|
37
37
|
"build:rollup": "rollup -c scripts/rollup.js",
|
38
38
|
"build:tsc": "npm run clean && tsc && mkdir dist/tsc && mv dist/*.js dist/tsc/ && node ./scripts/types.js",
|
39
|
-
"build": "npm run build:tsc && npm run build:test && cp dist/browser/fireproof.iife.js test/www/",
|
40
39
|
"test:watch:follow": "nodemon -w src -w test -e ts,js --exec \"sleep 2 && npm run test:node\"",
|
41
40
|
"test:node": "node ./scripts/test.js",
|
42
41
|
"test:browser": "node ./scripts/browser-test.js",
|
43
42
|
"lint:fix": "eslint --fix '{src,test}/**/*.{js,ts}'",
|
44
43
|
"lint:exports": "ts-unused-exports tsconfig.json",
|
44
|
+
"serve": "npx serve-http -p 8080 test/www",
|
45
45
|
"lint": "eslint 'src/**/*.{js,ts}'",
|
46
46
|
"analyze": "node ./scripts/analyze.js",
|
47
47
|
"test:coverage": "c8 --reporter=html --include='dist/*' node ./scripts/test.js && open coverage/src/index.html",
|
@@ -50,7 +50,8 @@
|
|
50
50
|
"test:watch": "nodemon -w src -w test -e ts,js --exec \"npm run build:test && npm run test:node\"",
|
51
51
|
"test": "npm run build:test && npm run test:node && tsc",
|
52
52
|
"build:test": "node ./scripts/build.js",
|
53
|
-
"build
|
53
|
+
"build": "npm run build:version && npm run build:tsc && npm run build:test && cp dist/browser/fireproof.iife.* test/www/",
|
54
|
+
"build:all": " npm run build && npm run test:browser"
|
54
55
|
},
|
55
56
|
"keywords": [
|
56
57
|
"database",
|