@optimystic/db-core 0.0.1
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 +328 -0
- package/dist/index.min.js +18 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/blocks/block-store.d.ts +12 -0
- package/dist/src/blocks/block-store.d.ts.map +1 -0
- package/dist/src/blocks/block-store.js +2 -0
- package/dist/src/blocks/block-store.js.map +1 -0
- package/dist/src/blocks/block-types.d.ts +3 -0
- package/dist/src/blocks/block-types.d.ts.map +1 -0
- package/dist/src/blocks/block-types.js +9 -0
- package/dist/src/blocks/block-types.js.map +1 -0
- package/dist/src/blocks/helpers.d.ts +4 -0
- package/dist/src/blocks/helpers.d.ts.map +1 -0
- package/dist/src/blocks/helpers.js +12 -0
- package/dist/src/blocks/helpers.js.map +1 -0
- package/dist/src/blocks/index.d.ts +5 -0
- package/dist/src/blocks/index.d.ts.map +1 -0
- package/dist/src/blocks/index.js +5 -0
- package/dist/src/blocks/index.js.map +1 -0
- package/dist/src/blocks/structs.d.ts +14 -0
- package/dist/src/blocks/structs.d.ts.map +1 -0
- package/dist/src/blocks/structs.js +2 -0
- package/dist/src/blocks/structs.js.map +1 -0
- package/dist/src/btree/btree.d.ts +135 -0
- package/dist/src/btree/btree.d.ts.map +1 -0
- package/dist/src/btree/btree.js +727 -0
- package/dist/src/btree/btree.js.map +1 -0
- package/dist/src/btree/independent-trunk.d.ts +17 -0
- package/dist/src/btree/independent-trunk.d.ts.map +1 -0
- package/dist/src/btree/independent-trunk.js +41 -0
- package/dist/src/btree/independent-trunk.js.map +1 -0
- package/dist/src/btree/index.d.ts +6 -0
- package/dist/src/btree/index.d.ts.map +1 -0
- package/dist/src/btree/index.js +6 -0
- package/dist/src/btree/index.js.map +1 -0
- package/dist/src/btree/key-range.d.ts +13 -0
- package/dist/src/btree/key-range.d.ts.map +1 -0
- package/dist/src/btree/key-range.js +20 -0
- package/dist/src/btree/key-range.js.map +1 -0
- package/dist/src/btree/keyset.d.ts +4 -0
- package/dist/src/btree/keyset.d.ts.map +1 -0
- package/dist/src/btree/keyset.js +4 -0
- package/dist/src/btree/keyset.js.map +1 -0
- package/dist/src/btree/nodes.d.ts +16 -0
- package/dist/src/btree/nodes.d.ts.map +1 -0
- package/dist/src/btree/nodes.js +9 -0
- package/dist/src/btree/nodes.js.map +1 -0
- package/dist/src/btree/path.d.ts +22 -0
- package/dist/src/btree/path.d.ts.map +1 -0
- package/dist/src/btree/path.js +39 -0
- package/dist/src/btree/path.js.map +1 -0
- package/dist/src/btree/tree-block.d.ts +7 -0
- package/dist/src/btree/tree-block.d.ts.map +1 -0
- package/dist/src/btree/tree-block.js +5 -0
- package/dist/src/btree/tree-block.js.map +1 -0
- package/dist/src/btree/trunk.d.ts +13 -0
- package/dist/src/btree/trunk.d.ts.map +1 -0
- package/dist/src/btree/trunk.js +2 -0
- package/dist/src/btree/trunk.js.map +1 -0
- package/dist/src/chain/chain-nodes.d.ts +18 -0
- package/dist/src/chain/chain-nodes.d.ts.map +1 -0
- package/dist/src/chain/chain-nodes.js +10 -0
- package/dist/src/chain/chain-nodes.js.map +1 -0
- package/dist/src/chain/chain.d.ts +75 -0
- package/dist/src/chain/chain.d.ts.map +1 -0
- package/dist/src/chain/chain.js +268 -0
- package/dist/src/chain/chain.js.map +1 -0
- package/dist/src/chain/index.d.ts +2 -0
- package/dist/src/chain/index.d.ts.map +1 -0
- package/dist/src/chain/index.js +2 -0
- package/dist/src/chain/index.js.map +1 -0
- package/dist/src/cluster/i-cluster.d.ts +5 -0
- package/dist/src/cluster/i-cluster.d.ts.map +1 -0
- package/dist/src/cluster/i-cluster.js +2 -0
- package/dist/src/cluster/i-cluster.js.map +1 -0
- package/dist/src/cluster/index.d.ts +3 -0
- package/dist/src/cluster/index.d.ts.map +1 -0
- package/dist/src/cluster/index.js +3 -0
- package/dist/src/cluster/index.js.map +1 -0
- package/dist/src/cluster/structs.d.ts +47 -0
- package/dist/src/cluster/structs.d.ts.map +1 -0
- package/dist/src/cluster/structs.js +2 -0
- package/dist/src/cluster/structs.js.map +1 -0
- package/dist/src/collection/action.d.ts +26 -0
- package/dist/src/collection/action.d.ts.map +1 -0
- package/dist/src/collection/action.js +2 -0
- package/dist/src/collection/action.js.map +1 -0
- package/dist/src/collection/collection.d.ts +48 -0
- package/dist/src/collection/collection.d.ts.map +1 -0
- package/dist/src/collection/collection.js +175 -0
- package/dist/src/collection/collection.js.map +1 -0
- package/dist/src/collection/index.d.ts +4 -0
- package/dist/src/collection/index.d.ts.map +1 -0
- package/dist/src/collection/index.js +4 -0
- package/dist/src/collection/index.js.map +1 -0
- package/dist/src/collection/struct.d.ts +16 -0
- package/dist/src/collection/struct.d.ts.map +1 -0
- package/dist/src/collection/struct.js +2 -0
- package/dist/src/collection/struct.js.map +1 -0
- package/dist/src/collections/diary/diary.d.ts +9 -0
- package/dist/src/collections/diary/diary.d.ts.map +1 -0
- package/dist/src/collections/diary/diary.js +37 -0
- package/dist/src/collections/diary/diary.js.map +1 -0
- package/dist/src/collections/diary/index.d.ts +3 -0
- package/dist/src/collections/diary/index.d.ts.map +1 -0
- package/dist/src/collections/diary/index.js +3 -0
- package/dist/src/collections/diary/index.js.map +1 -0
- package/dist/src/collections/diary/struct.d.ts +2 -0
- package/dist/src/collections/diary/struct.d.ts.map +1 -0
- package/dist/src/collections/diary/struct.js +3 -0
- package/dist/src/collections/diary/struct.js.map +1 -0
- package/dist/src/collections/index.d.ts +3 -0
- package/dist/src/collections/index.d.ts.map +1 -0
- package/dist/src/collections/index.js +3 -0
- package/dist/src/collections/index.js.map +1 -0
- package/dist/src/collections/tree/collection-trunk.d.ts +11 -0
- package/dist/src/collections/tree/collection-trunk.d.ts.map +1 -0
- package/dist/src/collections/tree/collection-trunk.js +22 -0
- package/dist/src/collections/tree/collection-trunk.js.map +1 -0
- package/dist/src/collections/tree/index.d.ts +3 -0
- package/dist/src/collections/tree/index.d.ts.map +1 -0
- package/dist/src/collections/tree/index.js +3 -0
- package/dist/src/collections/tree/index.js.map +1 -0
- package/dist/src/collections/tree/struct.d.ts +12 -0
- package/dist/src/collections/tree/struct.d.ts.map +1 -0
- package/dist/src/collections/tree/struct.js +4 -0
- package/dist/src/collections/tree/struct.js.map +1 -0
- package/dist/src/collections/tree/tree.d.ts +34 -0
- package/dist/src/collections/tree/tree.d.ts.map +1 -0
- package/dist/src/collections/tree/tree.js +100 -0
- package/dist/src/collections/tree/tree.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/log/index.d.ts +3 -0
- package/dist/src/log/index.d.ts.map +1 -0
- package/dist/src/log/index.js +3 -0
- package/dist/src/log/index.js.map +1 -0
- package/dist/src/log/log.d.ts +57 -0
- package/dist/src/log/log.d.ts.map +1 -0
- package/dist/src/log/log.js +131 -0
- package/dist/src/log/log.js.map +1 -0
- package/dist/src/log/struct.d.ts +36 -0
- package/dist/src/log/struct.d.ts.map +1 -0
- package/dist/src/log/struct.js +3 -0
- package/dist/src/log/struct.js.map +1 -0
- package/dist/src/network/i-key-network.d.ts +21 -0
- package/dist/src/network/i-key-network.d.ts.map +1 -0
- package/dist/src/network/i-key-network.js +2 -0
- package/dist/src/network/i-key-network.js.map +1 -0
- package/dist/src/network/i-peer-network.d.ts +8 -0
- package/dist/src/network/i-peer-network.d.ts.map +1 -0
- package/dist/src/network/i-peer-network.js +2 -0
- package/dist/src/network/i-peer-network.js.map +1 -0
- package/dist/src/network/i-repo.d.ts +17 -0
- package/dist/src/network/i-repo.d.ts.map +1 -0
- package/dist/src/network/i-repo.js +2 -0
- package/dist/src/network/i-repo.js.map +1 -0
- package/dist/src/network/index.d.ts +6 -0
- package/dist/src/network/index.d.ts.map +1 -0
- package/dist/src/network/index.js +6 -0
- package/dist/src/network/index.js.map +1 -0
- package/dist/src/network/repo-protocol.d.ts +19 -0
- package/dist/src/network/repo-protocol.d.ts.map +1 -0
- package/dist/src/network/repo-protocol.js +2 -0
- package/dist/src/network/repo-protocol.js.map +1 -0
- package/dist/src/network/struct.d.ts +115 -0
- package/dist/src/network/struct.d.ts.map +1 -0
- package/dist/src/network/struct.js +2 -0
- package/dist/src/network/struct.js.map +1 -0
- package/dist/src/transaction/actions-engine.d.ts +37 -0
- package/dist/src/transaction/actions-engine.d.ts.map +1 -0
- package/dist/src/transaction/actions-engine.js +67 -0
- package/dist/src/transaction/actions-engine.js.map +1 -0
- package/dist/src/transaction/context.d.ts +60 -0
- package/dist/src/transaction/context.d.ts.map +1 -0
- package/dist/src/transaction/context.js +91 -0
- package/dist/src/transaction/context.js.map +1 -0
- package/dist/src/transaction/coordinator.d.ts +118 -0
- package/dist/src/transaction/coordinator.d.ts.map +1 -0
- package/dist/src/transaction/coordinator.js +417 -0
- package/dist/src/transaction/coordinator.js.map +1 -0
- package/dist/src/transaction/index.d.ts +10 -0
- package/dist/src/transaction/index.d.ts.map +1 -0
- package/dist/src/transaction/index.js +7 -0
- package/dist/src/transaction/index.js.map +1 -0
- package/dist/src/transaction/session.d.ts +80 -0
- package/dist/src/transaction/session.d.ts.map +1 -0
- package/dist/src/transaction/session.js +161 -0
- package/dist/src/transaction/session.js.map +1 -0
- package/dist/src/transaction/transaction.d.ts +156 -0
- package/dist/src/transaction/transaction.d.ts.map +1 -0
- package/dist/src/transaction/transaction.js +31 -0
- package/dist/src/transaction/transaction.js.map +1 -0
- package/dist/src/transaction/validator.d.ts +46 -0
- package/dist/src/transaction/validator.d.ts.map +1 -0
- package/dist/src/transaction/validator.js +97 -0
- package/dist/src/transaction/validator.js.map +1 -0
- package/dist/src/transactor/index.d.ts +4 -0
- package/dist/src/transactor/index.d.ts.map +1 -0
- package/dist/src/transactor/index.js +4 -0
- package/dist/src/transactor/index.js.map +1 -0
- package/dist/src/transactor/network-transactor.d.ts +36 -0
- package/dist/src/transactor/network-transactor.d.ts.map +1 -0
- package/dist/src/transactor/network-transactor.js +297 -0
- package/dist/src/transactor/network-transactor.js.map +1 -0
- package/dist/src/transactor/transactor-source.d.ts +24 -0
- package/dist/src/transactor/transactor-source.d.ts.map +1 -0
- package/dist/src/transactor/transactor-source.js +62 -0
- package/dist/src/transactor/transactor-source.js.map +1 -0
- package/dist/src/transactor/transactor.d.ts +38 -0
- package/dist/src/transactor/transactor.d.ts.map +1 -0
- package/dist/src/transactor/transactor.js +2 -0
- package/dist/src/transactor/transactor.js.map +1 -0
- package/dist/src/transform/atomic.d.ts +8 -0
- package/dist/src/transform/atomic.d.ts.map +1 -0
- package/dist/src/transform/atomic.js +14 -0
- package/dist/src/transform/atomic.js.map +1 -0
- package/dist/src/transform/cache-source.d.ts +13 -0
- package/dist/src/transform/cache-source.d.ts.map +1 -0
- package/dist/src/transform/cache-source.js +52 -0
- package/dist/src/transform/cache-source.js.map +1 -0
- package/dist/src/transform/helpers.d.ts +25 -0
- package/dist/src/transform/helpers.d.ts.map +1 -0
- package/dist/src/transform/helpers.js +105 -0
- package/dist/src/transform/helpers.js.map +1 -0
- package/dist/src/transform/index.d.ts +6 -0
- package/dist/src/transform/index.d.ts.map +1 -0
- package/dist/src/transform/index.js +6 -0
- package/dist/src/transform/index.js.map +1 -0
- package/dist/src/transform/struct.d.ts +19 -0
- package/dist/src/transform/struct.d.ts.map +1 -0
- package/dist/src/transform/struct.js +2 -0
- package/dist/src/transform/struct.js.map +1 -0
- package/dist/src/transform/tracker.d.ts +22 -0
- package/dist/src/transform/tracker.d.ts.map +1 -0
- package/dist/src/transform/tracker.js +64 -0
- package/dist/src/transform/tracker.js.map +1 -0
- package/dist/src/utility/actor.d.ts +11 -0
- package/dist/src/utility/actor.d.ts.map +1 -0
- package/dist/src/utility/actor.js +39 -0
- package/dist/src/utility/actor.js.map +1 -0
- package/dist/src/utility/batch-coordinator.d.ts +56 -0
- package/dist/src/utility/batch-coordinator.d.ts.map +1 -0
- package/dist/src/utility/batch-coordinator.js +127 -0
- package/dist/src/utility/batch-coordinator.js.map +1 -0
- package/dist/src/utility/block-id-to-bytes.d.ts +3 -0
- package/dist/src/utility/block-id-to-bytes.d.ts.map +1 -0
- package/dist/src/utility/block-id-to-bytes.js +7 -0
- package/dist/src/utility/block-id-to-bytes.js.map +1 -0
- package/dist/src/utility/ensured.d.ts +3 -0
- package/dist/src/utility/ensured.d.ts.map +1 -0
- package/dist/src/utility/ensured.js +24 -0
- package/dist/src/utility/ensured.js.map +1 -0
- package/dist/src/utility/groupby.d.ts +8 -0
- package/dist/src/utility/groupby.d.ts.map +1 -0
- package/dist/src/utility/groupby.js +15 -0
- package/dist/src/utility/groupby.js.map +1 -0
- package/dist/src/utility/is-record-empty.d.ts +3 -0
- package/dist/src/utility/is-record-empty.d.ts.map +1 -0
- package/dist/src/utility/is-record-empty.js +7 -0
- package/dist/src/utility/is-record-empty.js.map +1 -0
- package/dist/src/utility/latches.d.ts +11 -0
- package/dist/src/utility/latches.d.ts.map +1 -0
- package/dist/src/utility/latches.js +36 -0
- package/dist/src/utility/latches.js.map +1 -0
- package/dist/src/utility/nameof.d.ts +3 -0
- package/dist/src/utility/nameof.d.ts.map +1 -0
- package/dist/src/utility/nameof.js +5 -0
- package/dist/src/utility/nameof.js.map +1 -0
- package/dist/src/utility/pending.d.ts +13 -0
- package/dist/src/utility/pending.d.ts.map +1 -0
- package/dist/src/utility/pending.js +37 -0
- package/dist/src/utility/pending.js.map +1 -0
- package/package.json +56 -0
- package/src/blocks/block-store.ts +13 -0
- package/src/blocks/block-types.ts +11 -0
- package/src/blocks/helpers.ts +13 -0
- package/src/blocks/index.ts +5 -0
- package/src/blocks/structs.ts +17 -0
- package/src/btree/btree.ts +804 -0
- package/src/btree/independent-trunk.ts +54 -0
- package/src/btree/index.ts +5 -0
- package/src/btree/key-range.ts +15 -0
- package/src/btree/keyset.ts +6 -0
- package/src/btree/nodes.ts +25 -0
- package/src/btree/path.ts +37 -0
- package/src/btree/tree-block.ts +11 -0
- package/src/btree/trunk.ts +14 -0
- package/src/chain/chain-nodes.ts +24 -0
- package/src/chain/chain.ts +324 -0
- package/src/chain/index.ts +2 -0
- package/src/cluster/i-cluster.ts +6 -0
- package/src/cluster/index.ts +2 -0
- package/src/cluster/structs.ts +46 -0
- package/src/collection/action.ts +31 -0
- package/src/collection/collection.ts +200 -0
- package/src/collection/index.ts +3 -0
- package/src/collection/struct.ts +20 -0
- package/src/collections/diary/diary.ts +43 -0
- package/src/collections/diary/index.ts +2 -0
- package/src/collections/diary/struct.ts +3 -0
- package/src/collections/index.ts +2 -0
- package/src/collections/tree/collection-trunk.ts +25 -0
- package/src/collections/tree/index.ts +2 -0
- package/src/collections/tree/readme.md +19 -0
- package/src/collections/tree/struct.ts +18 -0
- package/src/collections/tree/tree.ts +124 -0
- package/src/index.ts +17 -0
- package/src/log/index.ts +2 -0
- package/src/log/log.ts +155 -0
- package/src/log/struct.ts +40 -0
- package/src/network/i-key-network.ts +24 -0
- package/src/network/i-peer-network.ts +8 -0
- package/src/network/i-repo.ts +19 -0
- package/src/network/index.ts +5 -0
- package/src/network/repo-protocol.ts +12 -0
- package/src/network/struct.ts +137 -0
- package/src/transaction/actions-engine.ts +83 -0
- package/src/transaction/context.ts +103 -0
- package/src/transaction/coordinator.ts +583 -0
- package/src/transaction/index.ts +30 -0
- package/src/transaction/session.ts +182 -0
- package/src/transaction/transaction.ts +205 -0
- package/src/transaction/validator.ts +150 -0
- package/src/transactor/index.ts +4 -0
- package/src/transactor/network-transactor.ts +435 -0
- package/src/transactor/transactor-source.ts +65 -0
- package/src/transactor/transactor.ts +44 -0
- package/src/transform/atomic.ts +16 -0
- package/src/transform/cache-source.ts +57 -0
- package/src/transform/helpers.ts +117 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/struct.ts +22 -0
- package/src/transform/tracker.ts +70 -0
- package/src/utility/actor.ts +62 -0
- package/src/utility/batch-coordinator.ts +174 -0
- package/src/utility/block-id-to-bytes.ts +8 -0
- package/src/utility/ensured.ts +32 -0
- package/src/utility/groupby.ts +18 -0
- package/src/utility/is-record-empty.ts +5 -0
- package/src/utility/latches.ts +42 -0
- package/src/utility/nameof.ts +7 -0
- package/src/utility/pending.ts +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-record-empty.d.ts","sourceRoot":"","sources":["../../../src/utility/is-record-empty.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,OAAO,CAGnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-record-empty.js","sourceRoot":"","sources":["../../../src/utility/is-record-empty.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,MAAM,UAAU,aAAa,CAAI,MAAyB;IACzD,KAAK,MAAM,GAAG,IAAI,MAAM;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Lightweight implementation of a mutex lock queue. */
|
|
2
|
+
export declare class Latches {
|
|
3
|
+
private static lockQueues;
|
|
4
|
+
/**
|
|
5
|
+
* Acquires a lock for the given key. Waits if another operation holds the lock.
|
|
6
|
+
* Returns a release function that must be called to release the lock.
|
|
7
|
+
* WARNING: The key scope is global to the entire process, so follow the convention of using `ClassName.methodName:${id}` to avoid conflicts.
|
|
8
|
+
*/
|
|
9
|
+
static acquire(key: string): Promise<() => void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=latches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"latches.d.ts","sourceRoot":"","sources":["../../../src/utility/latches.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,qBAAa,OAAO;IAEhB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAoC;IAE7D;;;;OAIG;WACU,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;CA+BzD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Lightweight implementation of a mutex lock queue. */
|
|
2
|
+
export class Latches {
|
|
3
|
+
// Stores the promise representing the completion of the last queued operation for a key.
|
|
4
|
+
static lockQueues = new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Acquires a lock for the given key. Waits if another operation holds the lock.
|
|
7
|
+
* Returns a release function that must be called to release the lock.
|
|
8
|
+
* WARNING: The key scope is global to the entire process, so follow the convention of using `ClassName.methodName:${id}` to avoid conflicts.
|
|
9
|
+
*/
|
|
10
|
+
static async acquire(key) {
|
|
11
|
+
// Get the promise the current operation needs to wait for (if any)
|
|
12
|
+
const currentTail = this.lockQueues.get(key) ?? Promise.resolve();
|
|
13
|
+
let resolveNewTail;
|
|
14
|
+
// Create the promise that the *next* operation will wait for
|
|
15
|
+
const newTail = new Promise(resolve => {
|
|
16
|
+
resolveNewTail = resolve;
|
|
17
|
+
});
|
|
18
|
+
// Immediately set the new promise as the tail for this key
|
|
19
|
+
this.lockQueues.set(key, newTail);
|
|
20
|
+
// Wait for the previous operation (if any) to complete
|
|
21
|
+
await currentTail;
|
|
22
|
+
// Lock acquired. Return the function to release *this* lock.
|
|
23
|
+
const release = () => {
|
|
24
|
+
// Signal that this operation is complete, allowing the next awaiter (if any)
|
|
25
|
+
resolveNewTail();
|
|
26
|
+
// Optimization: If this promise is still the current tail in the map,
|
|
27
|
+
// it means no other operation queued up behind this one while it was running.
|
|
28
|
+
// We can safely remove the entry from the map to prevent unbounded growth.
|
|
29
|
+
if (this.lockQueues.get(key) === newTail) {
|
|
30
|
+
this.lockQueues.delete(key);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return release;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=latches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"latches.js","sourceRoot":"","sources":["../../../src/utility/latches.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,OAAO,OAAO;IAChB,yFAAyF;IACjF,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE7D;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAW;QAC5B,mEAAmE;QACnE,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAElE,IAAI,cAA0B,CAAC;QAC/B,6DAA6D;QAC7D,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;YACxC,cAAc,GAAG,OAAO,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,2DAA2D;QAC3D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAElC,uDAAuD;QACvD,MAAM,WAAW,CAAC;QAElB,6DAA6D;QAC7D,MAAM,OAAO,GAAG,GAAG,EAAE;YACjB,6EAA6E;YAC7E,cAAc,EAAE,CAAC;YAEjB,sEAAsE;YACtE,8EAA8E;YAC9E,2EAA2E;YAC3E,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAC;gBACvC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;QACL,CAAC,CAAC;QAEF,OAAO,OAAO,CAAC;IACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nameof.d.ts","sourceRoot":"","sources":["../../../src/utility/nameof.ts"],"names":[],"mappings":"AACA,wBAAgB,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC;AAC1E,wBAAgB,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nameof.js","sourceRoot":"","sources":["../../../src/utility/nameof.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,MAAM,CAAC,IAAS,EAAE,IAAU;IAC1C,OAAO,IAAI,IAAI,IAAI,CAAC;AACtB,CAAC;AACD,mBAAmB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Pending<T> {
|
|
2
|
+
promise: Promise<T>;
|
|
3
|
+
response?: T;
|
|
4
|
+
error?: unknown;
|
|
5
|
+
t1: number;
|
|
6
|
+
duration?: number;
|
|
7
|
+
get isResponse(): boolean;
|
|
8
|
+
get isError(): boolean;
|
|
9
|
+
get isComplete(): boolean;
|
|
10
|
+
result(): Promise<T>;
|
|
11
|
+
constructor(promise: Promise<T>);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=pending.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending.d.ts","sourceRoot":"","sources":["../../../src/utility/pending.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO,CAAC,CAAC;IA6Bb,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IA5B3B,QAAQ,CAAC,EAAE,CAAC,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,SAAc;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAEK,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC;gBAWlB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;CAW3B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class Pending {
|
|
2
|
+
promise;
|
|
3
|
+
response;
|
|
4
|
+
error;
|
|
5
|
+
t1 = Date.now();
|
|
6
|
+
duration;
|
|
7
|
+
get isResponse() {
|
|
8
|
+
return this.response !== undefined;
|
|
9
|
+
}
|
|
10
|
+
get isError() {
|
|
11
|
+
return this.error !== undefined;
|
|
12
|
+
}
|
|
13
|
+
get isComplete() {
|
|
14
|
+
return this.isResponse || this.isError;
|
|
15
|
+
}
|
|
16
|
+
async result() {
|
|
17
|
+
if (this.isResponse) {
|
|
18
|
+
return this.response;
|
|
19
|
+
}
|
|
20
|
+
if (this.isError) {
|
|
21
|
+
throw this.error;
|
|
22
|
+
}
|
|
23
|
+
return await this.promise;
|
|
24
|
+
}
|
|
25
|
+
constructor(promise) {
|
|
26
|
+
this.promise = promise;
|
|
27
|
+
promise.then(response => {
|
|
28
|
+
this.duration = Date.now() - this.t1;
|
|
29
|
+
this.response = response;
|
|
30
|
+
return response;
|
|
31
|
+
}, error => {
|
|
32
|
+
this.duration = Date.now() - this.t1;
|
|
33
|
+
this.error = error;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=pending.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending.js","sourceRoot":"","sources":["../../../src/utility/pending.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,OAAO;IA6BX;IA5BR,QAAQ,CAAK;IACb,KAAK,CAAW;IAChB,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAChB,QAAQ,CAAU;IAElB,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;IACpC,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;IACjC,CAAC;IAED,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,MAAM;QACX,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,QAAS,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,KAAM,CAAC;QACnB,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,YACQ,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAE1B,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,OAAO,QAAQ,CAAC;QACjB,CAAC,EAAE,KAAK,CAAC,EAAE;YACV,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACpB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@optimystic/db-core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Core database functionality for Optimystic",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"dist",
|
|
11
|
+
"!dist/test",
|
|
12
|
+
"!**/*.tsbuildinfo"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/src/index.d.ts",
|
|
17
|
+
"import": "./dist/src/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/gotchoices/optimystic.git",
|
|
23
|
+
"directory": "packages/db-core"
|
|
24
|
+
},
|
|
25
|
+
"author": "Got Choices Foundation",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"optimystic",
|
|
29
|
+
"database",
|
|
30
|
+
"core",
|
|
31
|
+
"distributed",
|
|
32
|
+
"transactional",
|
|
33
|
+
"acid"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "aegir clean",
|
|
37
|
+
"build": "aegir build --env node",
|
|
38
|
+
"lint": "aegir lint",
|
|
39
|
+
"test": "aegir test",
|
|
40
|
+
"test:node": "aegir test -t node",
|
|
41
|
+
"dep-check": "aegir dep-check"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.13.10",
|
|
45
|
+
"aegir": "^45.1.4"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@libp2p/crypto": "^5.1.7",
|
|
49
|
+
"@libp2p/interface": "^2.10.5",
|
|
50
|
+
"@libp2p/peer-id": "^5.1.8",
|
|
51
|
+
"@libp2p/peer-id-factory": "^4.2.4",
|
|
52
|
+
"@multiformats/multiaddr": "^12.5.1",
|
|
53
|
+
"debug": "^4.4.1",
|
|
54
|
+
"uint8arrays": "^5.1.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BlockType, IBlock, BlockId, BlockHeader, BlockOperation } from "./index.js";
|
|
2
|
+
|
|
3
|
+
export type BlockSource<T extends IBlock> = {
|
|
4
|
+
createBlockHeader(type: BlockType, newId?: BlockId): BlockHeader;
|
|
5
|
+
tryGet(id: BlockId): Promise<T | undefined>;
|
|
6
|
+
generateId(): BlockId;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type BlockStore<T extends IBlock> = BlockSource<T> & {
|
|
10
|
+
insert(block: T): void;
|
|
11
|
+
update(blockId: BlockId, op: BlockOperation): void;
|
|
12
|
+
delete(blockId: BlockId): void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BlockType } from ".";
|
|
2
|
+
|
|
3
|
+
const blockTypes = new Map<BlockType, string>();
|
|
4
|
+
|
|
5
|
+
export function registerBlockType(blockType: BlockType, name: string) {
|
|
6
|
+
if (blockTypes.has(blockType)) {
|
|
7
|
+
throw new Error(`Block type ${blockType} (${name}) already registered (${blockTypes.get(blockType)})`);
|
|
8
|
+
}
|
|
9
|
+
blockTypes.set(blockType, name);
|
|
10
|
+
return blockType;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BlockOperation, IBlock, BlockId, BlockStore } from "../index.js";
|
|
2
|
+
import { applyOperation } from "../transform/helpers.js";
|
|
3
|
+
|
|
4
|
+
export async function get<T extends IBlock>(store: BlockStore<T>, id: BlockId): Promise<T> {
|
|
5
|
+
const block = await store.tryGet(id);
|
|
6
|
+
if (!block) throw Error(`Missing block (${id})`);
|
|
7
|
+
return block;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function apply<T extends IBlock>(store: BlockStore<T>, block: IBlock, op: BlockOperation) {
|
|
11
|
+
applyOperation(block, op);
|
|
12
|
+
store.update(block.header.id, op);
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type BlockId = string; // base32 encoded
|
|
2
|
+
export type BlockType = string; // Generally a short code
|
|
3
|
+
|
|
4
|
+
export type BlockHeader = {
|
|
5
|
+
id: BlockId; // Domain wide block identifier
|
|
6
|
+
type: BlockType;
|
|
7
|
+
collectionId: BlockId;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** A simple block with only a header. Blocks should be treated as immutable */
|
|
11
|
+
export type IBlock = {
|
|
12
|
+
header: BlockHeader;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type BlockOperation = [entity: string, index: number, deleteCount: number, inserted: unknown[] | unknown]
|
|
16
|
+
export type BlockOperations = BlockOperation[];
|
|
17
|
+
|