@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/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) realtime
|
1
|
+
# <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) realtime database
|
2
2
|
|
3
3
|
<p align="right">
|
4
4
|
<img src="https://img.shields.io/bundlephobia/minzip/%40fireproof%2Fcore" alt="Package size">
|
@@ -9,11 +9,11 @@
|
|
9
9
|
|
10
10
|
### No setup: write features first, access your data anywhere
|
11
11
|
|
12
|
-
Add collaboration to any app with Fireproof. Access data from JavaScript servers and edge functions. Use live queries to update your UI automatically when the
|
12
|
+
Add collaboration to any app with Fireproof. Access data from JavaScript servers and edge functions. Use live queries to update your UI automatically when the database changes. [Connect realtime sync](https://www.npmjs.com/package/@fireproof/connect) and those changes will sync between browsers and backend functions. Apps built this way are multi-player by default.
|
13
13
|
|
14
14
|
### JavaScript quick start
|
15
15
|
|
16
|
-
The document
|
16
|
+
The document database API will feel familiar. Queries use dynamic indexes, and the database can refresh your UI, as seen in the `db.subscribe` call below, as well as the React liveQuery hook.
|
17
17
|
|
18
18
|
```js
|
19
19
|
import { fireproof } from "@fireproof/core";
|
@@ -32,7 +32,7 @@ beyonceDoc.hitSingles += 1;
|
|
32
32
|
await db.put(beyonceDoc);
|
33
33
|
```
|
34
34
|
|
35
|
-
Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/
|
35
|
+
Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/database-api/basics)
|
36
36
|
|
37
37
|
### Live data hooks for React
|
38
38
|
|
@@ -51,16 +51,16 @@ Read the [step-by-step React tutorial](https://use-fireproof.com/docs/react-tuto
|
|
51
51
|
|
52
52
|
## Why choose Fireproof
|
53
53
|
|
54
|
-
Compared to other embedded
|
54
|
+
Compared to other embedded databases, Fireproof:
|
55
55
|
|
56
56
|
- is network aware, encrypted, and multi-writer safe
|
57
57
|
- is designed for real-time collaboration with CRDTs
|
58
58
|
- offers cryptographic causal integrity for all operations
|
59
59
|
- is built for the web, with a small package size and no wasm
|
60
60
|
|
61
|
-
Deliver interactive experiences without waiting on the backend. Fireproof runs in any cloud, browser, or edge environment, so your application can access
|
61
|
+
Deliver interactive experiences without waiting on the backend. Fireproof runs in any cloud, browser, or edge environment, so your application can access data anywhere.
|
62
62
|
|
63
|
-
[Get the latest roadmap updates on our blog](https://fireproof.storage/blog/) or join our [Discord](https://discord.gg/cCryrNHePH) to collaborate. Read the docs to learn more about the
|
63
|
+
[Get the latest roadmap updates on our blog](https://fireproof.storage/blog/) or join our [Discord](https://discord.gg/cCryrNHePH) to collaborate. Read the docs to learn more about the database [architecture](https://use-fireproof.com/docs/architecture).
|
64
64
|
|
65
65
|
### Use cases
|
66
66
|
|
@@ -84,7 +84,7 @@ Get started with the React hooks:
|
|
84
84
|
npm install use-fireproof
|
85
85
|
```
|
86
86
|
|
87
|
-
or install the
|
87
|
+
or install the database in any JavaScript environment:
|
88
88
|
|
89
89
|
```sh
|
90
90
|
npm install @fireproof/core
|
@@ -96,7 +96,7 @@ The default build is optimized for browsers, to load the node build add `/node`:
|
|
96
96
|
import { fireproof } from "@fireproof/core/node";
|
97
97
|
```
|
98
98
|
|
99
|
-
Add the
|
99
|
+
Add the database to any web page via HTML script tag (global is `Fireproof`):
|
100
100
|
|
101
101
|
```html
|
102
102
|
<script src="https://cdn.jsdelivr.net/npm/@fireproof/core/dist/browser/fireproof.global.js"></script>
|
@@ -166,7 +166,7 @@ pnpm run build:doc
|
|
166
166
|
|
167
167
|
## Thanks 🙏
|
168
168
|
|
169
|
-
Fireproof is a synthesis of work done by people in the web community over the years. I couldn't even begin to name all the folks who made pivotal contributions. Without npm, React, and VS Code all this would have taken so much longer. Thanks to everyone who supported me getting into
|
169
|
+
Fireproof is a synthesis of work done by people in the web community over the years. I couldn't even begin to name all the folks who made pivotal contributions. Without npm, React, and VS Code all this would have taken so much longer. Thanks to everyone who supported me getting into database development via Apache CouchDB, one of the original document databases. The distinguishing work on immutable data-structures comes from the years of consideration [IPFS](https://ipfs.tech), [IPLD](https://ipld.io), and the [Filecoin APIs](https://docs.filecoin.io) have enjoyed.
|
170
170
|
|
171
171
|
Thanks to Alan Shaw and Mikeal Rogers without whom this project would have never got started. The core Merkle hash-tree clock is based on [Alan's Pail](https://github.com/alanshaw/pail), and you can see the repository history goes all the way back to work begun as a branch of that repo. Mikeal wrote [the prolly trees implementation](https://github.com/mikeal/prolly-trees).
|
172
172
|
|
package/index.cjs
CHANGED
@@ -31,9 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
31
31
|
var index_exports = {};
|
32
32
|
__export(index_exports, {
|
33
33
|
CRDT: () => CRDT,
|
34
|
+
DatabaseFactory: () => DatabaseFactory,
|
35
|
+
DatabaseShell: () => DatabaseShell,
|
34
36
|
Index: () => Index,
|
35
|
-
LedgerFactory: () => LedgerFactory,
|
36
|
-
LedgerShell: () => LedgerShell,
|
37
37
|
NotFoundError: () => NotFoundError,
|
38
38
|
PACKAGE_VERSION: () => PACKAGE_VERSION,
|
39
39
|
PARAM: () => PARAM,
|
@@ -54,8 +54,8 @@ __export(index_exports, {
|
|
54
54
|
getStore: () => getStore,
|
55
55
|
index: () => index,
|
56
56
|
inplaceFilter: () => inplaceFilter,
|
57
|
+
isDatabase: () => isDatabase,
|
57
58
|
isFalsy: () => isFalsy,
|
58
|
-
isLedger: () => isLedger,
|
59
59
|
isNotFoundError: () => isNotFoundError,
|
60
60
|
keyConfigOpts: () => keyConfigOpts,
|
61
61
|
onSuperThis: () => onSuperThis,
|
@@ -67,7 +67,7 @@ __export(index_exports, {
|
|
67
67
|
});
|
68
68
|
module.exports = __toCommonJS(index_exports);
|
69
69
|
|
70
|
-
// src/
|
70
|
+
// src/database.ts
|
71
71
|
var import_cement20 = require("@adviser/cement");
|
72
72
|
|
73
73
|
// src/utils.ts
|
@@ -849,7 +849,7 @@ var EncryptedBlockstore = class extends BaseBlockstore {
|
|
849
849
|
}
|
850
850
|
async getFile(car, cid) {
|
851
851
|
await this.ready();
|
852
|
-
if (!this.loader) throw this.logger.Error().Msg("loader required to get file,
|
852
|
+
if (!this.loader) throw this.logger.Error().Msg("loader required to get file, database must be named").AsError();
|
853
853
|
const reader = await this.loader.loadFileCar(
|
854
854
|
car
|
855
855
|
/*, isPublic */
|
@@ -3301,9 +3301,9 @@ var ConnectionBase = class {
|
|
3301
3301
|
// // await this.compact()
|
3302
3302
|
// // }
|
3303
3303
|
// const currents = await this.loader?.metaStore?.load()
|
3304
|
-
// if (!currents) throw new Error("Can't sync empty
|
3304
|
+
// if (!currents) throw new Error("Can't sync empty database: save data first")
|
3305
3305
|
// if (currents.length > 1)
|
3306
|
-
// throw new Error("Can't sync
|
3306
|
+
// throw new Error("Can't sync database with split heads: make an update first")
|
3307
3307
|
// const current = currents[0]
|
3308
3308
|
// const params = {
|
3309
3309
|
// car: current.car.toString()
|
@@ -3402,7 +3402,7 @@ async function processFiles(store, blocks, doc, logger) {
|
|
3402
3402
|
}
|
3403
3403
|
async function processFileset(logger, store, blocks, files) {
|
3404
3404
|
const dbBlockstore = blocks.parent;
|
3405
|
-
if (!dbBlockstore.loader) throw logger.Error().Msg("Missing loader,
|
3405
|
+
if (!dbBlockstore.loader) throw logger.Error().Msg("Missing loader, database name is required").AsError();
|
3406
3406
|
const t = new CarTransaction(dbBlockstore);
|
3407
3407
|
const didPut = [];
|
3408
3408
|
for (const filename in files) {
|
@@ -3434,7 +3434,7 @@ async function processFileset(logger, store, blocks, files) {
|
|
3434
3434
|
}
|
3435
3435
|
}
|
3436
3436
|
async function getValueFromCrdt(blocks, head, key, logger) {
|
3437
|
-
if (!head.length) throw logger.Debug().Msg("Getting from an empty
|
3437
|
+
if (!head.length) throw logger.Debug().Msg("Getting from an empty database").AsError();
|
3438
3438
|
const link = await (0, import_crdt.get)(blocks, head, key);
|
3439
3439
|
if (!link) throw logger.Error().Str("key", key).Msg(`Missing key`).AsError();
|
3440
3440
|
return await getValueFromLink(blocks, link, logger);
|
@@ -4233,8 +4233,8 @@ var CRDT = class {
|
|
4233
4233
|
}
|
4234
4234
|
};
|
4235
4235
|
|
4236
|
-
// src/
|
4237
|
-
var
|
4236
|
+
// src/database.ts
|
4237
|
+
var databases = new import_cement20.KeyedResolvOnce();
|
4238
4238
|
function keyConfigOpts(sthis, name, opts) {
|
4239
4239
|
return JSON.stringify(
|
4240
4240
|
toSortedArray({
|
@@ -4243,14 +4243,14 @@ function keyConfigOpts(sthis, name, opts) {
|
|
4243
4243
|
})
|
4244
4244
|
);
|
4245
4245
|
}
|
4246
|
-
function
|
4247
|
-
return db instanceof
|
4246
|
+
function isDatabase(db) {
|
4247
|
+
return db instanceof DatabaseImpl || db instanceof DatabaseShell;
|
4248
4248
|
}
|
4249
|
-
function
|
4249
|
+
function DatabaseFactory(name, opts) {
|
4250
4250
|
const sthis = ensureSuperThis(opts);
|
4251
|
-
return new
|
4252
|
-
|
4253
|
-
const db = new
|
4251
|
+
return new DatabaseShell(
|
4252
|
+
databases.get(keyConfigOpts(sthis, name, opts)).once((key) => {
|
4253
|
+
const db = new DatabaseImpl(sthis, {
|
4254
4254
|
name,
|
4255
4255
|
meta: opts?.meta,
|
4256
4256
|
keyBag: defaultKeyBagOpts(sthis, opts?.keyBag),
|
@@ -4264,13 +4264,13 @@ function LedgerFactory(name, opts) {
|
|
4264
4264
|
}
|
4265
4265
|
});
|
4266
4266
|
db.onClosed(() => {
|
4267
|
-
|
4267
|
+
databases.unget(key);
|
4268
4268
|
});
|
4269
4269
|
return db;
|
4270
4270
|
})
|
4271
4271
|
);
|
4272
4272
|
}
|
4273
|
-
var
|
4273
|
+
var DatabaseShell = class {
|
4274
4274
|
constructor(ref) {
|
4275
4275
|
this.ref = ref;
|
4276
4276
|
ref.addShell(this);
|
@@ -4333,7 +4333,7 @@ var LedgerShell = class {
|
|
4333
4333
|
return this.ref.compact();
|
4334
4334
|
}
|
4335
4335
|
};
|
4336
|
-
var
|
4336
|
+
var DatabaseImpl = class {
|
4337
4337
|
constructor(sthis, opts) {
|
4338
4338
|
this._listening = false;
|
4339
4339
|
this._listeners = /* @__PURE__ */ new Set();
|
@@ -4345,7 +4345,7 @@ var LedgerImpl = class {
|
|
4345
4345
|
this.opts = opts;
|
4346
4346
|
this.sthis = sthis;
|
4347
4347
|
this.id = sthis.timeOrderedNextId().str;
|
4348
|
-
this.logger = ensureLogger(this.sthis, "
|
4348
|
+
this.logger = ensureLogger(this.sthis, "Database");
|
4349
4349
|
this.crdt = new CRDT(this.sthis, this.opts);
|
4350
4350
|
this._writeQueue = writeQueue(this.sthis, async (updates) => this.crdt.bulk(updates), this.opts.writeQueue);
|
4351
4351
|
this.crdt.clock.onTock(() => this._no_update_notify());
|
@@ -4361,7 +4361,7 @@ var LedgerImpl = class {
|
|
4361
4361
|
}
|
4362
4362
|
async shellClose(db) {
|
4363
4363
|
if (!this.shells.has(db)) {
|
4364
|
-
throw this.logger.Error().Str("db", this.name).Msg(`
|
4364
|
+
throw this.logger.Error().Str("db", this.name).Msg(`DatabaseShell mismatch`).AsError();
|
4365
4365
|
}
|
4366
4366
|
this.shells.delete(db);
|
4367
4367
|
if (this.shells.size === 0) {
|
@@ -4515,7 +4515,7 @@ function defaultURI2(sthis, curi, uri, store, ctx) {
|
|
4515
4515
|
if (!ret.hasParam("name" /* NAME */)) {
|
4516
4516
|
const name = sthis.pathOps.basename(ret.URI().pathname);
|
4517
4517
|
if (!name) {
|
4518
|
-
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("
|
4518
|
+
throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Database name is required").AsError();
|
4519
4519
|
}
|
4520
4520
|
ret.setParam("name" /* NAME */, name);
|
4521
4521
|
}
|
@@ -4564,7 +4564,7 @@ function toStoreURIRuntime(sthis, name, sopts) {
|
|
4564
4564
|
};
|
4565
4565
|
}
|
4566
4566
|
function fireproof(name, opts) {
|
4567
|
-
return
|
4567
|
+
return DatabaseFactory(name, opts);
|
4568
4568
|
}
|
4569
4569
|
function makeName(fnString) {
|
4570
4570
|
const regex = /\(([^,()]+,\s*[^,()]+|\[[^\]]+\],\s*[^,()]+)\)/g;
|
@@ -4585,6 +4585,6 @@ function makeName(fnString) {
|
|
4585
4585
|
|
4586
4586
|
// src/version.ts
|
4587
4587
|
var PACKAGE_VERSION = Object.keys({
|
4588
|
-
"0.20.0-dev-preview-
|
4588
|
+
"0.20.0-dev-preview-06": "xxxx"
|
4589
4589
|
})[0];
|
4590
4590
|
//# sourceMappingURL=index.cjs.map
|