@fireproof/core 0.6.5 → 0.7.0-alpha.0
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 +2 -2
- package/dist/{src/blockstore.js → blockstore.js} +7 -3
- package/dist/{src/database.js → database.js} +74 -48
- package/dist/{src/db-index.js → db-index.js} +2 -1
- package/dist/fireproof.js +92 -0
- package/dist/{src/loader.js → loader.js} +2 -3
- package/dist/{src/prolly.js → prolly.js} +1 -0
- package/dist/src/fireproof.d.ts +137 -136
- package/dist/src/fireproof.js +18179 -11484
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +18180 -11484
- package/dist/src/fireproof.mjs.map +1 -1
- package/dist/{src/storage → storage}/filesystem.js +2 -2
- package/dist/{src/sync.js → sync.js} +1 -1
- package/dist/valet.js +200 -0
- package/package.json +4 -5
- package/src/blockstore.js +6 -3
- package/src/database.js +80 -52
- package/src/db-index.js +2 -1
- package/src/fireproof.js +41 -30
- package/src/import.js +34 -0
- package/src/loader.js +26 -0
- package/src/prolly.js +2 -0
- package/src/storage/base.js +371 -0
- package/src/storage/browser.js +67 -0
- package/src/storage/filesystem.js +70 -0
- package/src/storage/rest.js +60 -0
- package/src/storage/ucan.js +0 -0
- package/src/sync.js +1 -1
- package/src/valet.js +57 -359
- package/dist/hooks/use-fireproof.js +0 -150
- package/dist/src/crypto-poly.js +0 -4
- package/dist/src/link.js +0 -1
- package/dist/src/valet.js +0 -476
- package/hooks/use-fireproof.js +0 -173
- package/src/listener.js +0 -119
- package/src/utils.js +0 -16
- /package/dist/{src/clock.js → clock.js} +0 -0
- /package/dist/{src/crypto.js → crypto.js} +0 -0
- /package/dist/{src/import.js → import.js} +0 -0
- /package/dist/{src/listener.js → listener.js} +0 -0
- /package/dist/{src/sha1.js → sha1.js} +0 -0
- /package/dist/{src/storage → storage}/base.js +0 -0
- /package/dist/{src/storage → storage}/browser.js +0 -0
- /package/dist/{src/storage → storage}/rest.js +0 -0
- /package/dist/{src/storage → storage}/ucan.js +0 -0
- /package/dist/{src/utils.js → utils.js} +0 -0
package/src/listener.js
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* A Fireproof database Listener allows you to react to events in the database.
|
3
|
-
*
|
4
|
-
* @class Listener
|
5
|
-
* @classdesc An listener attaches to a Fireproof database and runs a routing function on each change, sending the results to subscribers.
|
6
|
-
*
|
7
|
-
* @param {import('./database.js').Database} database - The Database database instance to index.
|
8
|
-
* @param {Function} routingFn - The routing function to apply to each entry in the database.
|
9
|
-
*/
|
10
|
-
// import { ChangeEvent } from './db-index'
|
11
|
-
/**
|
12
|
-
* @deprecated since version 0.7.0
|
13
|
-
*/
|
14
|
-
export class Listener {
|
15
|
-
subcribers = new Map()
|
16
|
-
doStopListening = null
|
17
|
-
|
18
|
-
/**
|
19
|
-
* @param {import('./database.js').Database} database
|
20
|
-
* @param {(_: any, emit: any) => void} routingFn
|
21
|
-
*/
|
22
|
-
constructor (
|
23
|
-
database,
|
24
|
-
routingFn = function (/** @type {any} */ _, /** @type {(arg0: string) => void} */ emit) {
|
25
|
-
emit('*')
|
26
|
-
}
|
27
|
-
) {
|
28
|
-
this.database = database
|
29
|
-
this.doStopListening = database.registerListener((/** @type {any} */ changes) => this.onChanges(changes))
|
30
|
-
/**
|
31
|
-
* The map function to apply to each entry in the database.
|
32
|
-
* @type {Function}
|
33
|
-
*/
|
34
|
-
this.routingFn = routingFn
|
35
|
-
|
36
|
-
this.dbHead = null
|
37
|
-
}
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Subscribe to a topic emitted by the event function.
|
41
|
-
* @param {string} topic - The topic to subscribe to.
|
42
|
-
* @param {Function} subscriber - The function to call when the topic is emitted.
|
43
|
-
* @returns {Function} A function to unsubscribe from the topic.
|
44
|
-
* @memberof Listener
|
45
|
-
* @instance
|
46
|
-
* @param {any} [since] - clock to flush from on launch, pass null for all
|
47
|
-
*/
|
48
|
-
on (topic, subscriber, since = undefined) {
|
49
|
-
const listOfTopicSubscribers = getTopicList(this.subcribers, topic)
|
50
|
-
listOfTopicSubscribers.push(subscriber)
|
51
|
-
if (typeof since !== 'undefined') {
|
52
|
-
this.database.changesSince(since).then(({ rows: changes }) => {
|
53
|
-
const keys = topicsForChanges(changes, this.routingFn).get(topic)
|
54
|
-
if (keys) keys.forEach((/** @type {any} */ key) => subscriber(key))
|
55
|
-
})
|
56
|
-
}
|
57
|
-
return () => {
|
58
|
-
const index = listOfTopicSubscribers.indexOf(subscriber)
|
59
|
-
if (index > -1) listOfTopicSubscribers.splice(index, 1)
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* @typedef {import('./db-index').ChangeEvent} ChangeEvent
|
65
|
-
*/
|
66
|
-
|
67
|
-
/**
|
68
|
-
* @param {ChangeEvent[]} changes
|
69
|
-
*/
|
70
|
-
onChanges (changes) {
|
71
|
-
if (Array.isArray(changes)) {
|
72
|
-
const seenTopics = topicsForChanges(changes, this.routingFn)
|
73
|
-
for (const [topic, keys] of seenTopics) {
|
74
|
-
const listOfTopicSubscribers = getTopicList(this.subcribers, topic)
|
75
|
-
listOfTopicSubscribers.forEach((/** @type {(arg0: any) => any} */ subscriber) =>
|
76
|
-
keys.forEach((/** @type {any} */ key) => subscriber(key))
|
77
|
-
)
|
78
|
-
}
|
79
|
-
} else {
|
80
|
-
// non-arrays go to all subscribers
|
81
|
-
for (const [, listOfTopicSubscribers] of this.subcribers) {
|
82
|
-
listOfTopicSubscribers.forEach((/** @type {(arg0: any) => any} */ subscriber) => subscriber(changes))
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
/**
|
89
|
-
* @param {Map<any, any>} subscribersMap
|
90
|
-
* @param {string} name
|
91
|
-
*/
|
92
|
-
function getTopicList (subscribersMap, name) {
|
93
|
-
let topicList = subscribersMap.get(name)
|
94
|
-
if (!topicList) {
|
95
|
-
topicList = []
|
96
|
-
subscribersMap.set(name, topicList)
|
97
|
-
}
|
98
|
-
return topicList
|
99
|
-
}
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Transforms a set of changes to events using an emitter function.
|
103
|
-
*
|
104
|
-
* @param {ChangeEvent[]} changes
|
105
|
-
* @param {Function} routingFn
|
106
|
-
* @returns {Map<string,string[]>} The topics emmitted by the event function.
|
107
|
-
* @private
|
108
|
-
*/
|
109
|
-
const topicsForChanges = (changes, routingFn) => {
|
110
|
-
const seenTopics = new Map()
|
111
|
-
changes.forEach(({ key, value, del }) => {
|
112
|
-
if (del || !value) value = { _deleted: true }
|
113
|
-
routingFn({ _id: key, ...value }, (/** @type {any} */ t) => {
|
114
|
-
const topicList = getTopicList(seenTopics, t)
|
115
|
-
topicList.push(key)
|
116
|
-
})
|
117
|
-
})
|
118
|
-
return seenTopics
|
119
|
-
}
|
package/src/utils.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
|
2
|
-
/* global localStorage */
|
3
|
-
let storageSupported = false
|
4
|
-
try {
|
5
|
-
storageSupported = window.localStorage && true
|
6
|
-
} catch (e) {}
|
7
|
-
export function localGet (key) {
|
8
|
-
if (storageSupported) {
|
9
|
-
return localStorage && localStorage.getItem(key)
|
10
|
-
}
|
11
|
-
}
|
12
|
-
export function localSet (key, value) {
|
13
|
-
if (storageSupported) {
|
14
|
-
return localStorage && localStorage.setItem(key, value)
|
15
|
-
}
|
16
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|