@fireproof/core 0.7.0-alpha.4 → 0.7.0-alpha.6

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 CHANGED
@@ -8,8 +8,8 @@
8
8
  </h3>
9
9
 
10
10
  <p align="center">
11
- <a href="https://github.com/jchris/fireproof/actions/workflows/test.yml">
12
- <img src="https://github.com/jchris/fireproof/actions/workflows/test.yml/badge.svg" alt="Test" style="max-width: 100%;">
11
+ <a href="https://github.com/fireproof-storage/fireproof/actions/workflows/test.yml">
12
+ <img src="https://github.com/fireproof-storage/fireproof/actions/workflows/test.yml/badge.svg" alt="Test" style="max-width: 100%;">
13
13
  </a>
14
14
  <a href="https://standardjs.com" rel="nofollow">
15
15
  <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="JavaScript Style Guide" style="max-width: 100%;">
package/dist/fireproof.js CHANGED
@@ -38,7 +38,7 @@ class Fireproof {
38
38
  clock: {
39
39
  byId: byId ? parseCID(byId) : null,
40
40
  byKey: byKey ? parseCID(byKey) : null,
41
- db: (db && db.length > 0) ? db.map(c => parseCID(c)) : null
41
+ db: db && db.length > 0 ? db.map(c => parseCID(c)) : null
42
42
  },
43
43
  code,
44
44
  name
@@ -59,7 +59,9 @@ class Fireproof {
59
59
  }
60
60
  const withBlocks = new Database(database.name);
61
61
  withBlocks.blocks = database.blocks;
62
- withBlocks.clock = definition.clock;
62
+ withBlocks.ready.then(() => {
63
+ withBlocks.clock = definition.clock.map(c => parseCID(c));
64
+ });
63
65
  const snappedDb = Fireproof.fromJSON(definition, null, withBlocks);
64
66
  [...database.indexes.values()].forEach(index => {
65
67
  snappedDb.indexes.get(index.mapFnString).mapFn = index.mapFn;
package/dist/loader.js CHANGED
@@ -1,23 +1,13 @@
1
1
  import { Browser } from './storage/browser.js';
2
- import { Filesystem } from './storage/filesystem.js';
3
- import { Rest } from './storage/rest.js';
4
- const FORCE_IDB = typeof process !== 'undefined' && !!process.env?.FORCE_IDB;
5
- /* global window */
2
+ // import { Rest } from './storage/rest.js'
6
3
  export const Loader = {
7
4
  appropriate: (name, config = {}) => {
8
- let isBrowser = false;
9
- try {
10
- isBrowser = window.localStorage && true;
11
- }
12
- catch (e) { }
13
- if (config.type === 'rest') {
14
- return new Rest(name, config);
15
- }
16
- if (FORCE_IDB || isBrowser) {
17
- return new Browser(name, config);
18
- }
19
- else {
20
- return new Filesystem(name, config);
5
+ if (config.StorageClass) {
6
+ return new config.StorageClass(name, config);
21
7
  }
8
+ // if (config.type === 'rest') {
9
+ // return new Rest(name, config)
10
+ // }
11
+ return new Browser(name, config);
22
12
  }
23
13
  };
@@ -1,119 +1,8 @@
1
1
  import * as multiformats from 'multiformats';
2
2
  import { Link, CID } from 'multiformats';
3
- import * as multiformats_link from 'multiformats/link';
4
- import * as _ipld_car_dist_src_api_js from '@ipld/car/dist/src/api.js';
5
- import * as idb from 'idb';
6
3
 
7
4
  type AnyLink = Link<unknown, number, number, 1|0>
8
5
 
9
- declare class Base {
10
- constructor(name: any, config?: {});
11
- valetRootCarCid: any;
12
- keyMaterial: any;
13
- keyId: string;
14
- instanceId: string;
15
- name: any;
16
- config: {};
17
- ready: Promise<{}>;
18
- setCarCidMapCarCid(carCid: any): void;
19
- valetCarCidMap: Map<any, any>;
20
- setKeyMaterial(km: any): void;
21
- saveCar(carCid: any, value: any, cids: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
22
- applyHeaders(headers: any): void;
23
- headers: any;
24
- getHeaders(): Promise<{}>;
25
- loadHeader(branch?: string): void;
26
- saveHeader(header: any): Promise<void>;
27
- prepareHeader(header: any, json?: boolean): any;
28
- writeHeader(branch: any, header: any): void;
29
- getCarCIDForCID(cid: any): Promise<{
30
- result: any;
31
- }>;
32
- readCar(carCid: any): Promise<Uint8Array>;
33
- getLoaderBlock(dataCID: any): Promise<{
34
- block: any;
35
- reader: {
36
- entries: () => Generator<any, void, unknown>;
37
- root: any;
38
- gat: (dataCID: any) => Promise<any>;
39
- get: (dataCID: any) => Promise<any>;
40
- } | {
41
- entries: any;
42
- root: any;
43
- gat: (dataCID: any) => Promise<_ipld_car_dist_src_api_js.Block>;
44
- get: (dataCID: any) => Promise<Uint8Array>;
45
- };
46
- carCid: any;
47
- }>;
48
- /** Private - internal **/
49
- getCidCarMap(): Promise<Map<any, any>>;
50
- mapForIPLDHashmapCarCid(carCid: any): Promise<Map<any, any>>;
51
- getWriteableCarReader(carCid: any): Promise<{
52
- blocks: VMemoryBlockstore;
53
- root: any;
54
- put: (cid: any, bytes: any) => Promise<void>;
55
- get: (cid: any) => Promise<any>;
56
- }>;
57
- getCarReader(carCid: any): Promise<{
58
- entries: () => Generator<any, void, unknown>;
59
- root: any;
60
- gat: (dataCID: any) => Promise<any>;
61
- get: (dataCID: any) => Promise<any>;
62
- } | {
63
- entries: any;
64
- root: any;
65
- gat: (dataCID: any) => Promise<_ipld_car_dist_src_api_js.Block>;
66
- get: (dataCID: any) => Promise<Uint8Array>;
67
- }>;
68
- writeCars(cars: any): void;
69
- updateCarCidMap(carCid: any, cids: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
70
- persistCarMap(theCarMap: any): Promise<multiformats.BlockView<Uint8Array, 85, 18, 1>>;
71
- }
72
- declare class VMemoryBlockstore {
73
- /** @type {Map<string, Uint8Array>} */
74
- blocks: Map<string, Uint8Array>;
75
- instanceId: string;
76
- get(cid: any): Promise<{
77
- cid: any;
78
- bytes: Uint8Array;
79
- }>;
80
- /**
81
- * @param {any} cid
82
- * @param {Uint8Array} bytes
83
- */
84
- put(cid: any, bytes: Uint8Array): Promise<void>;
85
- entries(): Generator<{
86
- cid: multiformats_link.Link<unknown, number, number, multiformats_link.Version>;
87
- bytes: Uint8Array;
88
- }, void, unknown>;
89
- }
90
-
91
- declare class Rest extends Base {
92
- headerURL(branch?: string): string;
93
- writeCars(cars: any): Promise<void>;
94
- loadHeader(branch?: string): Promise<unknown>;
95
- writeHeader(branch: any, header: any): Promise<void>;
96
- }
97
-
98
- declare class Filesystem extends Base {
99
- writeCars(cars: any): Promise<void>;
100
- readCar(carCid: any): Promise<any>;
101
- loadHeader(branch?: string): any;
102
- writeHeader(branch: any, header: any): Promise<void>;
103
- headerFilename(branch?: string): any;
104
- }
105
-
106
- declare class Browser extends Base {
107
- isBrowser: boolean;
108
- withDB: (dbWorkFun: any) => Promise<any>;
109
- idb: idb.IDBPDatabase<unknown>;
110
- writeCars(cars: any): Promise<any>;
111
- readCar(carCid: any): Promise<any>;
112
- loadHeader(branch?: string): string;
113
- writeHeader(branch: any, header: any): Promise<void>;
114
- headerKey(branch?: string): string;
115
- }
116
-
117
6
  declare class Valet {
118
7
  constructor(name?: string, config?: {});
119
8
  idb: any;
@@ -121,10 +10,10 @@ declare class Valet {
121
10
  uploadQueue: any;
122
11
  alreadyEnqueued: Set<any>;
123
12
  instanceId: string;
124
- primary: Browser | Filesystem | Rest;
125
- secondary: Browser | Filesystem | Rest;
126
- ready: Promise<{}[]>;
127
- saveHeader(header: any): Promise<void>;
13
+ primary: any;
14
+ secondary: any;
15
+ ready: Promise<any[]>;
16
+ saveHeader(header: any): Promise<any>;
128
17
  /**
129
18
  * Group the blocks into a car and write it to the valet.
130
19
  * @param {import('./blockstore.js').InnerBlockstore} innerBlockstore
@@ -167,7 +56,7 @@ declare class TransactionBlockstore {
167
56
  instanceId: string;
168
57
  inflightTransactions: Set<any>;
169
58
  syncs: Set<any>;
170
- ready: Promise<void> | Promise<{}[]>;
59
+ ready: Promise<void> | Promise<any[]>;
171
60
  remoteBlockFunction: any;
172
61
  /**
173
62
  * Get a block from the store.