@fireproof/core 0.15.0-dev → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. package/LICENSE.md +232 -0
  2. package/README.md +2 -0
  3. package/dist/browser/fireproof.cjs +27910 -14036
  4. package/dist/browser/fireproof.cjs.map +4 -4
  5. package/dist/browser/fireproof.esm.js +27910 -14036
  6. package/dist/browser/fireproof.esm.js.map +4 -4
  7. package/dist/browser/fireproof.iife.js +27910 -14036
  8. package/dist/browser/fireproof.iife.js.map +4 -4
  9. package/dist/node/fireproof.cjs +37969 -24187
  10. package/dist/node/fireproof.cjs.map +4 -4
  11. package/dist/node/fireproof.esm.js +37978 -24185
  12. package/dist/node/fireproof.esm.js.map +4 -4
  13. package/dist/types/crdt-clock.d.ts +2 -2
  14. package/dist/types/crdt-helpers.d.ts +9 -14
  15. package/dist/types/crdt.d.ts +8 -9
  16. package/dist/types/database.d.ts +6 -6
  17. package/dist/types/eb-edge.d.ts +0 -0
  18. package/dist/types/eb-node.d.ts +3 -0
  19. package/dist/types/eb-web.d.ts +3 -0
  20. package/dist/types/fireproof.d.ts +0 -4
  21. package/dist/types/index.d.ts +3 -3
  22. package/dist/types/indexer-helpers.d.ts +3 -3
  23. package/dist/types/types.d.ts +35 -69
  24. package/dist/types/version.d.ts +1 -1
  25. package/dist/types/write-queue.d.ts +3 -3
  26. package/package.json +31 -30
  27. package/dist/memory/fireproof.esm.js +0 -21349
  28. package/dist/memory/fireproof.esm.js.map +0 -7
  29. package/dist/types/commit-queue.d.ts +0 -6
  30. package/dist/types/crypto-ipld.d.ts +0 -20
  31. package/dist/types/crypto-node.d.ts +0 -4
  32. package/dist/types/crypto-web.d.ts +0 -4
  33. package/dist/types/encrypt-helpers.d.ts +0 -8
  34. package/dist/types/encrypted-block.d.ts +0 -44
  35. package/dist/types/loader-helpers.d.ts +0 -5
  36. package/dist/types/loader.d.ts +0 -62
  37. package/dist/types/loaders.d.ts +0 -51
  38. package/dist/types/remote-wal.d.ts +0 -26
  39. package/dist/types/store-browser.d.ts +0 -24
  40. package/dist/types/store-fs.d.ts +0 -26
  41. package/dist/types/store-memory.d.ts +0 -24
  42. package/dist/types/store.d.ts +0 -28
  43. package/dist/types/transaction.d.ts +0 -50
@@ -1,6 +0,0 @@
1
- export declare class CommitQueue<T = void> {
2
- private queue;
3
- private processing;
4
- enqueue(fn: () => Promise<T>): Promise<T>;
5
- private processNext;
6
- }
@@ -1,20 +0,0 @@
1
- import type { AnyBlock, AnyLink } from './types.js';
2
- import type { MultihashHasher } from 'multiformats';
3
- declare const encrypt: ({ get, cids, hasher, key, cache, chunker, root }: {
4
- get: (cid: AnyLink) => Promise<AnyBlock | undefined>;
5
- key: ArrayBuffer;
6
- cids: AnyLink[];
7
- hasher: MultihashHasher<number>;
8
- chunker: (bytes: Uint8Array) => AsyncGenerator<Uint8Array>;
9
- cache: (cid: AnyLink) => Promise<AnyBlock>;
10
- root: AnyLink;
11
- }) => AsyncGenerator<any, void, unknown>;
12
- declare const decrypt: ({ root, get, key, cache, chunker, hasher }: {
13
- root: AnyLink;
14
- get: (cid: AnyLink) => Promise<AnyBlock | undefined>;
15
- key: ArrayBuffer;
16
- cache: (cid: AnyLink) => Promise<AnyBlock>;
17
- chunker: (bytes: Uint8Array) => AsyncGenerator<Uint8Array>;
18
- hasher: MultihashHasher<number>;
19
- }) => AsyncGenerator<AnyBlock, void, undefined>;
20
- export { encrypt, decrypt };
@@ -1,4 +0,0 @@
1
- import { Crypto } from '@peculiar/webcrypto';
2
- export declare function getCrypto(): Crypto | null;
3
- export declare const crypto: Crypto | null;
4
- export declare function randomBytes(size: number): Uint8Array;
@@ -1,4 +0,0 @@
1
- export declare function getCrypto(): Crypto | null;
2
- declare const gotCrypto: Crypto | null;
3
- export { gotCrypto as crypto };
4
- export declare function randomBytes(size: number): Uint8Array;
@@ -1,8 +0,0 @@
1
- import type { CarReader } from '@ipld/car';
2
- import type { AnyBlock, CarMakeable, AnyLink } from './types';
3
- import { MemoryBlockstore } from '@alanshaw/pail/block';
4
- export declare function encryptedEncodeCarFile(key: string, rootCid: AnyLink, t: CarMakeable): Promise<AnyBlock>;
5
- export declare function decodeEncryptedCar(key: string, reader: CarReader): Promise<{
6
- blocks: MemoryBlockstore;
7
- root: AnyLink;
8
- }>;
@@ -1,44 +0,0 @@
1
- import type { AnyLink } from './types';
2
- declare const encode: ({ iv, bytes }: {
3
- iv: Uint8Array;
4
- bytes: Uint8Array;
5
- }) => Uint8Array;
6
- declare const decode: (bytes: Uint8Array) => {
7
- iv: Uint8Array;
8
- bytes: Uint8Array;
9
- };
10
- declare const code: number;
11
- declare const decrypt: ({ key, value }: {
12
- key: ArrayBuffer;
13
- value: {
14
- bytes: Uint8Array;
15
- iv: Uint8Array;
16
- };
17
- }) => Promise<{
18
- cid: AnyLink;
19
- bytes: Uint8Array;
20
- }>;
21
- declare const encrypt: ({ key, cid, bytes }: {
22
- key: ArrayBuffer;
23
- cid: AnyLink;
24
- bytes: Uint8Array;
25
- }) => Promise<{
26
- value: {
27
- bytes: Uint8Array;
28
- iv: Uint8Array;
29
- };
30
- }>;
31
- declare const cryptoFn: (key: Uint8Array) => {
32
- encrypt: (opts: any) => Promise<{
33
- value: {
34
- bytes: Uint8Array;
35
- iv: Uint8Array;
36
- };
37
- }>;
38
- decrypt: (opts: any) => Promise<{
39
- cid: AnyLink;
40
- bytes: Uint8Array;
41
- }>;
42
- };
43
- declare const name = "jchris@encrypted-block:aes-gcm";
44
- export { encode, decode, code, name, encrypt, decrypt, cryptoFn as crypto };
@@ -1,5 +0,0 @@
1
- import { CarReader } from '@ipld/car';
2
- import { AnyBlock, AnyCarHeader, AnyLink, CarMakeable } from './types';
3
- export declare function encodeCarFile(roots: AnyLink[], t: CarMakeable): Promise<AnyBlock>;
4
- export declare function encodeCarHeader(fp: AnyCarHeader): Promise<AnyBlock>;
5
- export declare function parseCarFile(reader: CarReader): Promise<AnyCarHeader>;
@@ -1,62 +0,0 @@
1
- import { CarReader } from '@ipld/car';
2
- import { DataStore, MetaStore, RemoteWAL } from './store-browser';
3
- import { DataStore as AbstractDataStore, MetaStore as AbstractMetaStore } from './store';
4
- import type { Transaction } from './transaction';
5
- import type { AnyBlock, AnyCarHeader, AnyLink, BulkResult, CarLoaderHeader, CommitOpts, DbMeta, FileCarHeader, FileResult, FireproofOptions } from './types';
6
- import { type IndexerResult } from './loaders';
7
- import { CommitQueue } from './commit-queue';
8
- export declare function cidListIncludes(list: AnyLink[], cid: AnyLink): boolean;
9
- export declare function uniqueCids(list: AnyLink[], remove?: Set<string>): AnyLink[];
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
- }
14
- export declare abstract class Loader {
15
- name: string;
16
- opts: FireproofOptions;
17
- commitQueue: CommitQueue<AnyLink>;
18
- isCompacting: boolean;
19
- isWriting: boolean;
20
- remoteMetaLoading: Promise<void> | undefined;
21
- remoteMetaStore: AbstractRemoteMetaStore | undefined;
22
- remoteCarStore: AbstractDataStore | undefined;
23
- remoteWAL: RemoteWAL;
24
- metaStore: MetaStore;
25
- carStore: DataStore;
26
- carLog: AnyLink[];
27
- carReaders: Map<string, Promise<CarReader>>;
28
- ready: Promise<void>;
29
- key: string | undefined;
30
- keyId: string | undefined;
31
- seenCompacted: Set<string>;
32
- private getBlockCache;
33
- private seenMeta;
34
- static defaultHeader: AnyCarHeader;
35
- abstract defaultHeader: AnyCarHeader;
36
- constructor(name: string, opts?: FireproofOptions);
37
- snapToCar(carCid: AnyLink | string): Promise<void>;
38
- _readyForMerge(): Promise<void>;
39
- _setWaitForWrite(_writing: () => Promise<void>): Promise<void>;
40
- handleDbMetasFromStore(metas: DbMeta[]): Promise<void>;
41
- mergeDbMetaIntoClock(meta: DbMeta): Promise<void>;
42
- protected ingestKeyFromMeta(meta: DbMeta): Promise<void>;
43
- loadCarHeaderFromMeta({ car: cid }: DbMeta): Promise<CarLoaderHeader>;
44
- protected abstract _applyCarHeader(_carHeader: CarLoaderHeader, snap?: boolean): Promise<void>;
45
- _getKey(): Promise<string | undefined>;
46
- commit(t: Transaction, done: IndexerResult | BulkResult | FileResult, opts?: CommitOpts): Promise<AnyLink>;
47
- _commitInternal(t: Transaction, done: IndexerResult | BulkResult | FileResult, opts?: CommitOpts): Promise<AnyLink>;
48
- flushCars(): Promise<void>;
49
- entries(): AsyncIterableIterator<AnyBlock>;
50
- getBlock(cid: AnyLink): Promise<AnyBlock | undefined>;
51
- protected abstract makeCarHeader(_result: BulkResult | IndexerResult | FileResult, _cars: AnyLink[], _compact: boolean): AnyCarHeader | FileCarHeader;
52
- protected loadCar(cid: AnyLink): Promise<CarReader>;
53
- protected storesLoadCar(cid: AnyLink, local: AbstractDataStore, remote?: AbstractDataStore, publicFiles?: boolean): Promise<CarReader>;
54
- protected ensureDecryptedReader(reader: CarReader): Promise<CarReader>;
55
- protected setKey(key: string): Promise<void>;
56
- protected getMoreReaders(cids: AnyLink[]): Promise<void>;
57
- }
58
- export interface Connection {
59
- loader: Loader;
60
- loaded: Promise<void>;
61
- }
62
- export {};
@@ -1,51 +0,0 @@
1
- import type { CarReader } from '@ipld/car';
2
- import type { AnyLink, BulkResult, CarCommit, DbCarHeader, FileCarHeader, FileResult, FireproofOptions, IdxCarHeader, IdxMeta, IdxMetaMap } from './types';
3
- import type { CRDT } from './crdt';
4
- import type { CRDTClock } from './crdt-clock';
5
- import { Loader } from './loader';
6
- import type { DataStore as AbstractDataStore } from './store';
7
- import { DataStore } from './store-browser';
8
- import { TransactionBlockstore } from './transaction';
9
- export declare class IdxLoader extends Loader {
10
- crdt: CRDT;
11
- static defaultHeader: {
12
- cars: never[];
13
- compact: never[];
14
- indexes: Map<string, IdxMeta>;
15
- };
16
- defaultHeader: {
17
- cars: never[];
18
- compact: never[];
19
- indexes: Map<string, IdxMeta>;
20
- };
21
- constructor(name: string, crdt: CRDT, opts?: FireproofOptions);
22
- _applyCarHeader(header: IdxCarHeader): Promise<void>;
23
- protected makeCarHeader({ indexes }: IndexerResult, cars: AnyLink[], compact?: boolean): IdxCarHeader;
24
- }
25
- export type IndexerResult = CarCommit & IdxMetaMap;
26
- export declare class DbLoader extends Loader {
27
- static defaultHeader: {
28
- cars: never[];
29
- compact: never[];
30
- head: never[];
31
- };
32
- defaultHeader: {
33
- cars: never[];
34
- compact: never[];
35
- head: never[];
36
- };
37
- clock: CRDTClock;
38
- awaitingCompact: boolean;
39
- compacting: Promise<AnyLink | void>;
40
- writing: Promise<BulkResult | void>;
41
- remoteFileStore: AbstractDataStore | undefined;
42
- fileStore: DataStore;
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>;
47
- loadFileCar(cid: AnyLink, isPublic?: boolean): Promise<CarReader>;
48
- protected _applyCarHeader(carHeader: DbCarHeader, snap?: boolean): Promise<void>;
49
- protected makeCarHeader(result: BulkResult | FileResult, cars: AnyLink[], compact?: boolean): DbCarHeader | FileCarHeader;
50
- }
51
- export declare function isFileResult(result: IndexerResult | BulkResult | FileResult): result is FileResult;
@@ -1,26 +0,0 @@
1
- import { AnyLink, CommitOpts, DbMeta } from './types';
2
- import { type Loader } from './loader';
3
- export type WALState = {
4
- operations: DbMeta[];
5
- noLoaderOps: DbMeta[];
6
- fileOperations: {
7
- cid: AnyLink;
8
- public: boolean;
9
- }[];
10
- };
11
- export declare abstract class RemoteWAL {
12
- tag: string;
13
- STORAGE_VERSION: string;
14
- loader: Loader;
15
- ready: Promise<void>;
16
- walState: WALState;
17
- processing: Promise<void> | undefined;
18
- private processQueue;
19
- constructor(loader: Loader);
20
- enqueue(dbMeta: DbMeta, opts: CommitOpts): Promise<void>;
21
- enqueueFile(fileCid: AnyLink, publicFile?: boolean): Promise<void>;
22
- _process(): Promise<void>;
23
- _doProcess(): Promise<void>;
24
- abstract load(branch?: string): Promise<WALState | null>;
25
- abstract save(state: WALState, branch?: string): Promise<void>;
26
- }
@@ -1,24 +0,0 @@
1
- import { IDBPDatabase } from 'idb';
2
- import { AnyBlock, AnyLink, DbMeta } from './types';
3
- import { DataStore as DataStoreBase, MetaStore as MetaStoreBase } from './store';
4
- import { RemoteWAL as RemoteWALBase, WALState } from './remote-wal';
5
- export declare class DataStore extends DataStoreBase {
6
- tag: string;
7
- idb: IDBPDatabase<unknown> | null;
8
- _withDB(dbWorkFun: (arg0: any) => any): Promise<any>;
9
- load(cid: AnyLink): Promise<AnyBlock>;
10
- save(car: AnyBlock): Promise<void>;
11
- remove(cid: AnyLink): Promise<void>;
12
- }
13
- export declare class RemoteWAL extends RemoteWALBase {
14
- tag: string;
15
- headerKey(branch: string): string;
16
- load(branch?: string): Promise<WALState | null>;
17
- save(state: WALState, branch?: string): Promise<void>;
18
- }
19
- export declare class MetaStore extends MetaStoreBase {
20
- tag: string;
21
- headerKey(branch: string): string;
22
- load(branch?: string): Promise<DbMeta[] | null>;
23
- save(meta: DbMeta, branch?: string): Promise<null>;
24
- }
@@ -1,26 +0,0 @@
1
- import type { AnyBlock, AnyLink, DbMeta } from './types';
2
- import { MetaStore as MetaStoreBase, DataStore as DataStoreBase } from './store';
3
- import { RemoteWAL as RemoteWALBase, WALState } from './remote-wal';
4
- export declare class RemoteWAL extends RemoteWALBase {
5
- filePathForBranch(branch: string): string;
6
- load(branch?: string): Promise<WALState | null>;
7
- save(state: WALState, branch?: string): Promise<void>;
8
- }
9
- export declare class MetaStore extends MetaStoreBase {
10
- tag: string;
11
- static dataDir: string;
12
- filePathForBranch(branch: string): string;
13
- load(branch?: string): Promise<DbMeta[] | null>;
14
- save(meta: DbMeta, branch?: string): Promise<null>;
15
- }
16
- export declare const testConfig: {
17
- dataDir: string;
18
- };
19
- export declare class DataStore extends DataStoreBase {
20
- tag: string;
21
- static dataDir: string;
22
- save(car: AnyBlock): Promise<void>;
23
- private cidPath;
24
- load(cid: AnyLink): Promise<AnyBlock>;
25
- remove(cid: AnyLink): Promise<void>;
26
- }
@@ -1,24 +0,0 @@
1
- import { AnyBlock, AnyLink, DbMeta } from './types';
2
- import { DataStore as DataStoreBase, MetaStore as MetaStoreBase } from './store';
3
- import { RemoteWAL as RemoteWALBase, WALState } from './remote-wal';
4
- export declare class DataStore extends DataStoreBase {
5
- tag: string;
6
- store: Map<string, Uint8Array>;
7
- load(cid: AnyLink): Promise<AnyBlock>;
8
- save(car: AnyBlock): Promise<void>;
9
- remove(cid: AnyLink): Promise<void>;
10
- }
11
- export declare class MetaStore extends MetaStoreBase {
12
- tag: string;
13
- store: Map<string, string>;
14
- headerKey(branch: string): string;
15
- load(branch?: string): Promise<DbMeta[] | null>;
16
- save(meta: DbMeta, branch?: string): Promise<null>;
17
- }
18
- export declare class RemoteWAL extends RemoteWALBase {
19
- tag: string;
20
- store: Map<string, string>;
21
- headerKey(branch: string): string;
22
- load(branch?: string): Promise<WALState | null>;
23
- save(state: WALState, branch?: string): Promise<void>;
24
- }
@@ -1,28 +0,0 @@
1
- import { ToString } from '@ipld/dag-json';
2
- import { AnyBlock, AnyLink, DbMeta } from './types';
3
- export declare const STORAGE_VERSION: string;
4
- declare abstract class VersionedStore {
5
- STORAGE_VERSION: string;
6
- name: string;
7
- constructor(name: string);
8
- }
9
- export declare abstract class MetaStore extends VersionedStore {
10
- tag: string;
11
- makeHeader({ car, key }: DbMeta): ToString<DbMeta>;
12
- parseHeader(headerData: ToString<DbMeta>): DbMeta;
13
- abstract load(branch?: string): Promise<DbMeta[] | null>;
14
- abstract save(dbMeta: DbMeta, branch?: string): Promise<DbMeta[] | null>;
15
- }
16
- type DataSaveOpts = {
17
- public?: boolean;
18
- };
19
- export declare abstract class DataStore {
20
- tag: string;
21
- STORAGE_VERSION: string;
22
- name: string;
23
- constructor(name: string);
24
- abstract load(cid: AnyLink): Promise<AnyBlock>;
25
- abstract save(car: AnyBlock, opts?: DataSaveOpts): Promise<void | AnyLink>;
26
- abstract remove(cid: AnyLink): Promise<void>;
27
- }
28
- export {};
@@ -1,50 +0,0 @@
1
- import { MemoryBlockstore } from '@alanshaw/pail/block';
2
- import { BlockFetcher, AnyBlock, AnyLink, BulkResult, ClockHead, IdxMeta, CarCommit, CarMakeable, FireproofOptions } from './types';
3
- import { DbLoader, IdxLoader } from './loaders';
4
- import { CRDT } from './crdt';
5
- import { CRDTClock } from './crdt-clock';
6
- export declare class Transaction extends MemoryBlockstore implements CarMakeable {
7
- parent: FireproofBlockstore;
8
- constructor(parent: FireproofBlockstore);
9
- get(cid: AnyLink): Promise<AnyBlock | undefined>;
10
- superGet(cid: AnyLink): Promise<AnyBlock | undefined>;
11
- }
12
- declare abstract class FireproofBlockstore implements BlockFetcher {
13
- ready: Promise<void>;
14
- name: string | null;
15
- loader: DbLoader | IdxLoader | null;
16
- opts: FireproofOptions;
17
- transactions: Set<Transaction>;
18
- constructor(name: string | null, loader?: DbLoader | IdxLoader, opts?: FireproofOptions);
19
- abstract transaction(fn: (t: Transaction) => Promise<IdxMeta | BulkResult>, indexes?: Map<string, IdxMeta>, opts?: {
20
- noLoader: boolean;
21
- }): Promise<BulkResultCar | IdxMetaCar>;
22
- put(): Promise<void>;
23
- get(cid: AnyLink): Promise<AnyBlock | undefined>;
24
- commitCompaction(t: Transaction, head: ClockHead): Promise<AnyLink>;
25
- entries(): AsyncIterableIterator<AnyBlock>;
26
- protected executeTransaction<T, R>(fn: (t: Transaction) => Promise<T>, commitHandler: (t: Transaction, done: T) => Promise<{
27
- car?: AnyLink;
28
- done: R;
29
- }>): Promise<R>;
30
- }
31
- export declare class IndexBlockstore extends FireproofBlockstore {
32
- constructor(name: string | null, crdt: CRDT, opts?: FireproofOptions);
33
- transaction(fn: (t: Transaction) => Promise<IdxMeta>, indexes: Map<string, IdxMeta>): Promise<IdxMetaCar>;
34
- }
35
- export declare class TransactionBlockstore extends FireproofBlockstore {
36
- constructor(name: string | null, clock: CRDTClock, opts?: FireproofOptions);
37
- transaction(fn: (t: Transaction) => Promise<BulkResult>, _indexes?: undefined, opts?: {
38
- noLoader: boolean;
39
- }): Promise<BulkResultCar>;
40
- }
41
- type IdxMetaCar = IdxMeta & CarCommit;
42
- type BulkResultCar = BulkResult & CarCommit;
43
- export declare class LoggingFetcher implements BlockFetcher {
44
- blocks: TransactionBlockstore;
45
- loader: DbLoader | IdxLoader | null;
46
- loggedBlocks: Transaction;
47
- constructor(blocks: TransactionBlockstore);
48
- get(cid: AnyLink): Promise<AnyBlock | undefined>;
49
- }
50
- export {};