document-dataply 0.0.9-alpha.7 → 0.0.9-alpha.9
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/dist/cjs/index.js +137 -83
- package/dist/types/core/documentAPI.d.ts +1 -3
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -873,7 +873,7 @@ var require_cjs = __commonJS({
|
|
|
873
873
|
};
|
|
874
874
|
var AsyncMVCCStrategy = class extends MVCCStrategy {
|
|
875
875
|
};
|
|
876
|
-
var
|
|
876
|
+
var Ryoiki = class _Ryoiki {
|
|
877
877
|
readings;
|
|
878
878
|
writings;
|
|
879
879
|
readQueue;
|
|
@@ -1130,7 +1130,7 @@ var require_cjs = __commonJS({
|
|
|
1130
1130
|
}
|
|
1131
1131
|
};
|
|
1132
1132
|
var AsyncMVCCTransaction = class _AsyncMVCCTransaction extends MVCCTransaction {
|
|
1133
|
-
lock = new
|
|
1133
|
+
lock = new Ryoiki();
|
|
1134
1134
|
async writeLock(fn) {
|
|
1135
1135
|
let lockId;
|
|
1136
1136
|
return this.lock.writeLock(async (_lockId) => {
|
|
@@ -2890,7 +2890,7 @@ var require_cjs = __commonJS({
|
|
|
2890
2890
|
}
|
|
2891
2891
|
}
|
|
2892
2892
|
};
|
|
2893
|
-
var
|
|
2893
|
+
var Ryoiki2 = class _Ryoiki2 {
|
|
2894
2894
|
readings;
|
|
2895
2895
|
writings;
|
|
2896
2896
|
readQueue;
|
|
@@ -3157,7 +3157,7 @@ var require_cjs = __commonJS({
|
|
|
3157
3157
|
comparator,
|
|
3158
3158
|
option
|
|
3159
3159
|
);
|
|
3160
|
-
this.lock = new
|
|
3160
|
+
this.lock = new Ryoiki2();
|
|
3161
3161
|
}
|
|
3162
3162
|
async writeLock(id, fn) {
|
|
3163
3163
|
let lockId;
|
|
@@ -4099,7 +4099,7 @@ var require_cjs = __commonJS({
|
|
|
4099
4099
|
}
|
|
4100
4100
|
};
|
|
4101
4101
|
var SerializeStrategyAsync2 = class extends SerializeStrategy {
|
|
4102
|
-
lock = new
|
|
4102
|
+
lock = new Ryoiki2();
|
|
4103
4103
|
async acquireLock(action) {
|
|
4104
4104
|
let lockId;
|
|
4105
4105
|
return this.lock.writeLock((_lockId) => {
|
|
@@ -8499,7 +8499,6 @@ var require_cjs = __commonJS({
|
|
|
8499
8499
|
const nextFreePageId = reusedPageManager.getNextPageId(reusedPage);
|
|
8500
8500
|
metadataManager.setFreePageId(metadata, nextFreePageId);
|
|
8501
8501
|
await this.setPage(0, metadata, tx);
|
|
8502
|
-
await this.updateBitmap(reusedPageId, false, tx);
|
|
8503
8502
|
const manager2 = this.pageFactory.getManagerFromType(pageType);
|
|
8504
8503
|
const newPage2 = manager2.create(this.pageSize, reusedPageId);
|
|
8505
8504
|
await this.setPage(reusedPageId, newPage2, tx);
|
|
@@ -8515,18 +8514,17 @@ var require_cjs = __commonJS({
|
|
|
8515
8514
|
const emptyManager = this.pageFactory.getManagerFromType(PageManager.CONSTANT.PAGE_TYPE_EMPTY);
|
|
8516
8515
|
const firstFreeIndex = newPageIndex + 1;
|
|
8517
8516
|
const lastFreeIndex = newPageIndex + preallocationCount - 1;
|
|
8517
|
+
metadataManager.setPageCount(metadata, newTotalCount);
|
|
8518
|
+
if (preallocationCount > 1) {
|
|
8519
|
+
metadataManager.setFreePageId(metadata, firstFreeIndex);
|
|
8520
|
+
}
|
|
8521
|
+
await this.setPage(0, metadata, tx);
|
|
8518
8522
|
for (let i = firstFreeIndex; i <= lastFreeIndex; i++) {
|
|
8519
8523
|
const emptyPage = emptyManager.create(this.pageSize, i);
|
|
8520
8524
|
const nextId = i < lastFreeIndex ? i + 1 : -1;
|
|
8521
8525
|
emptyManager.setNextPageId(emptyPage, nextId);
|
|
8522
8526
|
await this.setPage(i, emptyPage, tx);
|
|
8523
|
-
await this.updateBitmap(i, true, tx);
|
|
8524
8527
|
}
|
|
8525
|
-
if (preallocationCount > 1) {
|
|
8526
|
-
metadataManager.setFreePageId(metadata, firstFreeIndex);
|
|
8527
|
-
}
|
|
8528
|
-
metadataManager.setPageCount(metadata, newTotalCount);
|
|
8529
|
-
await this.setPage(0, metadata, tx);
|
|
8530
8528
|
return newPageIndex;
|
|
8531
8529
|
}
|
|
8532
8530
|
/**
|
|
@@ -8623,7 +8621,6 @@ var require_cjs = __commonJS({
|
|
|
8623
8621
|
const emptyPage = emptyPageManager.create(this.pageSize, pageId);
|
|
8624
8622
|
emptyPageManager.setNextPageId(emptyPage, currentHeadFreePageId);
|
|
8625
8623
|
await this.setPage(pageId, emptyPage, tx);
|
|
8626
|
-
await this.updateBitmap(pageId, true, tx);
|
|
8627
8624
|
metadataManager.setFreePageId(metadata, pageId);
|
|
8628
8625
|
await this.setPage(0, metadata, tx);
|
|
8629
8626
|
}
|
|
@@ -9460,6 +9457,8 @@ var require_cjs = __commonJS({
|
|
|
9460
9457
|
commitHooks = [];
|
|
9461
9458
|
/** Page MVCC Strategy for disk access */
|
|
9462
9459
|
pageStrategy;
|
|
9460
|
+
/** Release function for global write lock, set by DataplyAPI */
|
|
9461
|
+
_writeLockRelease = null;
|
|
9463
9462
|
/**
|
|
9464
9463
|
* Sets the BPTree transaction.
|
|
9465
9464
|
* @param tx BPTree transaction
|
|
@@ -9494,6 +9493,19 @@ var require_cjs = __commonJS({
|
|
|
9494
9493
|
onCommit(hook) {
|
|
9495
9494
|
this.commitHooks.push(hook);
|
|
9496
9495
|
}
|
|
9496
|
+
/**
|
|
9497
|
+
* Sets the global write lock release function.
|
|
9498
|
+
* Called by DataplyAPI.runWithDefaultWrite when acquiring the lock.
|
|
9499
|
+
*/
|
|
9500
|
+
__setWriteLockRelease(release) {
|
|
9501
|
+
this._writeLockRelease = release;
|
|
9502
|
+
}
|
|
9503
|
+
/**
|
|
9504
|
+
* Returns whether this transaction already has a write lock.
|
|
9505
|
+
*/
|
|
9506
|
+
__hasWriteLockRelease() {
|
|
9507
|
+
return this._writeLockRelease !== null;
|
|
9508
|
+
}
|
|
9497
9509
|
/**
|
|
9498
9510
|
* Reads a page. Uses dirty buffer if available, otherwise disk.
|
|
9499
9511
|
* @param pageId Page ID
|
|
@@ -9539,44 +9551,58 @@ var require_cjs = __commonJS({
|
|
|
9539
9551
|
* Commits the transaction.
|
|
9540
9552
|
*/
|
|
9541
9553
|
async commit() {
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
});
|
|
9547
|
-
let shouldTriggerCheckpoint = false;
|
|
9548
|
-
await this.pfs.runGlobalLock(async () => {
|
|
9549
|
-
if (this.pfs.wal && this.dirtyPages.size > 0) {
|
|
9550
|
-
await this.pfs.wal.prepareCommit(this.dirtyPages);
|
|
9551
|
-
await this.pfs.wal.writeCommitMarker();
|
|
9552
|
-
}
|
|
9553
|
-
for (const [pageId, data] of this.dirtyPages) {
|
|
9554
|
-
await this.pageStrategy.write(pageId, data);
|
|
9555
|
-
}
|
|
9556
|
-
if (this.pfs.wal) {
|
|
9557
|
-
this.pfs.wal.incrementWrittenPages(this.dirtyPages.size);
|
|
9558
|
-
if (this.pfs.wal.shouldCheckpoint(this.pfs.options.walCheckpointThreshold)) {
|
|
9559
|
-
shouldTriggerCheckpoint = true;
|
|
9554
|
+
try {
|
|
9555
|
+
await this.context.run(this, async () => {
|
|
9556
|
+
for (const hook of this.commitHooks) {
|
|
9557
|
+
await hook();
|
|
9560
9558
|
}
|
|
9559
|
+
});
|
|
9560
|
+
let shouldTriggerCheckpoint = false;
|
|
9561
|
+
await this.pfs.runGlobalLock(async () => {
|
|
9562
|
+
if (this.pfs.wal && this.dirtyPages.size > 0) {
|
|
9563
|
+
await this.pfs.wal.prepareCommit(this.dirtyPages);
|
|
9564
|
+
await this.pfs.wal.writeCommitMarker();
|
|
9565
|
+
}
|
|
9566
|
+
for (const [pageId, data] of this.dirtyPages) {
|
|
9567
|
+
await this.pageStrategy.write(pageId, data);
|
|
9568
|
+
}
|
|
9569
|
+
if (this.pfs.wal) {
|
|
9570
|
+
this.pfs.wal.incrementWrittenPages(this.dirtyPages.size);
|
|
9571
|
+
if (this.pfs.wal.shouldCheckpoint(this.pfs.options.walCheckpointThreshold)) {
|
|
9572
|
+
shouldTriggerCheckpoint = true;
|
|
9573
|
+
}
|
|
9574
|
+
}
|
|
9575
|
+
});
|
|
9576
|
+
if (shouldTriggerCheckpoint) {
|
|
9577
|
+
await this.pfs.checkpoint();
|
|
9578
|
+
}
|
|
9579
|
+
this.dirtyPages.clear();
|
|
9580
|
+
this.undoPages.clear();
|
|
9581
|
+
this.releaseAllLocks();
|
|
9582
|
+
} finally {
|
|
9583
|
+
if (this._writeLockRelease) {
|
|
9584
|
+
this._writeLockRelease();
|
|
9585
|
+
this._writeLockRelease = null;
|
|
9561
9586
|
}
|
|
9562
|
-
});
|
|
9563
|
-
if (shouldTriggerCheckpoint) {
|
|
9564
|
-
await this.pfs.checkpoint();
|
|
9565
9587
|
}
|
|
9566
|
-
this.dirtyPages.clear();
|
|
9567
|
-
this.undoPages.clear();
|
|
9568
|
-
this.releaseAllLocks();
|
|
9569
9588
|
}
|
|
9570
9589
|
/**
|
|
9571
9590
|
* Rolls back the transaction.
|
|
9572
9591
|
*/
|
|
9573
9592
|
async rollback() {
|
|
9574
|
-
|
|
9575
|
-
this.bptreeTx
|
|
9593
|
+
try {
|
|
9594
|
+
if (this.bptreeTx) {
|
|
9595
|
+
this.bptreeTx.rollback();
|
|
9596
|
+
}
|
|
9597
|
+
this.dirtyPages.clear();
|
|
9598
|
+
this.undoPages.clear();
|
|
9599
|
+
this.releaseAllLocks();
|
|
9600
|
+
} finally {
|
|
9601
|
+
if (this._writeLockRelease) {
|
|
9602
|
+
this._writeLockRelease();
|
|
9603
|
+
this._writeLockRelease = null;
|
|
9604
|
+
}
|
|
9576
9605
|
}
|
|
9577
|
-
this.dirtyPages.clear();
|
|
9578
|
-
this.undoPages.clear();
|
|
9579
|
-
this.releaseAllLocks();
|
|
9580
9606
|
}
|
|
9581
9607
|
/**
|
|
9582
9608
|
* Returns the dirty pages map.
|
|
@@ -9653,6 +9679,8 @@ var require_cjs = __commonJS({
|
|
|
9653
9679
|
/** Whether the database was created this time. */
|
|
9654
9680
|
isNewlyCreated;
|
|
9655
9681
|
txIdCounter;
|
|
9682
|
+
/** Promise-chain mutex for serializing write operations */
|
|
9683
|
+
writeQueue = Promise.resolve();
|
|
9656
9684
|
/**
|
|
9657
9685
|
* Verifies if the page file is a valid Dataply file.
|
|
9658
9686
|
* The metadata page must be located at the beginning of the Dataply file.
|
|
@@ -9810,6 +9838,52 @@ var require_cjs = __commonJS({
|
|
|
9810
9838
|
* @param tx The transaction to use. If not provided, a new transaction is created.
|
|
9811
9839
|
* @returns The result of the callback function.
|
|
9812
9840
|
*/
|
|
9841
|
+
/**
|
|
9842
|
+
* Acquires the global write lock.
|
|
9843
|
+
* Returns a release function that MUST be called to unlock.
|
|
9844
|
+
* Used internally by runWithDefaultWrite.
|
|
9845
|
+
* @returns A release function
|
|
9846
|
+
*/
|
|
9847
|
+
acquireWriteLock() {
|
|
9848
|
+
const previous = this.writeQueue;
|
|
9849
|
+
let release;
|
|
9850
|
+
this.writeQueue = new Promise((resolve) => {
|
|
9851
|
+
release = resolve;
|
|
9852
|
+
});
|
|
9853
|
+
return previous.then(() => release);
|
|
9854
|
+
}
|
|
9855
|
+
/**
|
|
9856
|
+
* Runs a write callback within a transaction context with global write serialization.
|
|
9857
|
+
* If no transaction is provided, a new transaction is created, committed on success, rolled back on error.
|
|
9858
|
+
* If a transaction is provided (external), the write lock is acquired on first call and held until commit/rollback.
|
|
9859
|
+
* Subclasses MUST use this method for all write operations instead of runWithDefault.
|
|
9860
|
+
* @param callback The callback function to run.
|
|
9861
|
+
* @param tx Optional external transaction.
|
|
9862
|
+
* @returns The result of the callback.
|
|
9863
|
+
*/
|
|
9864
|
+
async runWithDefaultWrite(callback, tx) {
|
|
9865
|
+
if (!tx) {
|
|
9866
|
+
const release = await this.acquireWriteLock();
|
|
9867
|
+
const internalTx = this.createTransaction();
|
|
9868
|
+
internalTx.__setWriteLockRelease(release);
|
|
9869
|
+
const [error2, result2] = await catchPromise2(this.txContext.run(internalTx, () => callback(internalTx)));
|
|
9870
|
+
if (error2) {
|
|
9871
|
+
await internalTx.rollback();
|
|
9872
|
+
throw error2;
|
|
9873
|
+
}
|
|
9874
|
+
await internalTx.commit();
|
|
9875
|
+
return result2;
|
|
9876
|
+
}
|
|
9877
|
+
if (!tx.__hasWriteLockRelease()) {
|
|
9878
|
+
const release = await this.acquireWriteLock();
|
|
9879
|
+
tx.__setWriteLockRelease(release);
|
|
9880
|
+
}
|
|
9881
|
+
const [error, result] = await catchPromise2(this.txContext.run(tx, () => callback(tx)));
|
|
9882
|
+
if (error) {
|
|
9883
|
+
throw error;
|
|
9884
|
+
}
|
|
9885
|
+
return result;
|
|
9886
|
+
}
|
|
9813
9887
|
async runWithDefault(callback, tx) {
|
|
9814
9888
|
const isInternalTx = !tx;
|
|
9815
9889
|
if (!tx) {
|
|
@@ -9881,7 +9955,7 @@ var require_cjs = __commonJS({
|
|
|
9881
9955
|
if (!this.initialized) {
|
|
9882
9956
|
throw new Error("Dataply instance is not initialized");
|
|
9883
9957
|
}
|
|
9884
|
-
return this.
|
|
9958
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
9885
9959
|
incrementRowCount = incrementRowCount ?? true;
|
|
9886
9960
|
if (typeof data === "string") {
|
|
9887
9961
|
data = this.textCodec.encode(data);
|
|
@@ -9901,7 +9975,7 @@ var require_cjs = __commonJS({
|
|
|
9901
9975
|
if (!this.initialized) {
|
|
9902
9976
|
throw new Error("Dataply instance is not initialized");
|
|
9903
9977
|
}
|
|
9904
|
-
return this.
|
|
9978
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
9905
9979
|
incrementRowCount = incrementRowCount ?? true;
|
|
9906
9980
|
if (typeof data === "string") {
|
|
9907
9981
|
data = this.textCodec.encode(data);
|
|
@@ -9922,7 +9996,7 @@ var require_cjs = __commonJS({
|
|
|
9922
9996
|
if (!this.initialized) {
|
|
9923
9997
|
throw new Error("Dataply instance is not initialized");
|
|
9924
9998
|
}
|
|
9925
|
-
return this.
|
|
9999
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
9926
10000
|
incrementRowCount = incrementRowCount ?? true;
|
|
9927
10001
|
const encodedList = dataList.map(
|
|
9928
10002
|
(data) => typeof data === "string" ? this.textCodec.encode(data) : data
|
|
@@ -9940,7 +10014,7 @@ var require_cjs = __commonJS({
|
|
|
9940
10014
|
if (!this.initialized) {
|
|
9941
10015
|
throw new Error("Dataply instance is not initialized");
|
|
9942
10016
|
}
|
|
9943
|
-
return this.
|
|
10017
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
9944
10018
|
if (typeof data === "string") {
|
|
9945
10019
|
data = this.textCodec.encode(data);
|
|
9946
10020
|
}
|
|
@@ -9957,7 +10031,7 @@ var require_cjs = __commonJS({
|
|
|
9957
10031
|
if (!this.initialized) {
|
|
9958
10032
|
throw new Error("Dataply instance is not initialized");
|
|
9959
10033
|
}
|
|
9960
|
-
return this.
|
|
10034
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
9961
10035
|
decrementRowCount = decrementRowCount ?? true;
|
|
9962
10036
|
await this.rowTableEngine.delete(pk, decrementRowCount, tx2);
|
|
9963
10037
|
}, tx);
|
|
@@ -10378,7 +10452,6 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10378
10452
|
trees = /* @__PURE__ */ new Map();
|
|
10379
10453
|
comparator = new DocumentValueComparator();
|
|
10380
10454
|
pendingBackfillFields = [];
|
|
10381
|
-
lock;
|
|
10382
10455
|
_initialized = false;
|
|
10383
10456
|
indexedFields;
|
|
10384
10457
|
/**
|
|
@@ -10409,7 +10482,6 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10409
10482
|
constructor(file, options) {
|
|
10410
10483
|
super(file, options);
|
|
10411
10484
|
this.trees = /* @__PURE__ */ new Map();
|
|
10412
|
-
this.lock = new import_dataply3.Ryoiki();
|
|
10413
10485
|
this.indexedFields = /* @__PURE__ */ new Set(["_id"]);
|
|
10414
10486
|
this.hook.onceAfter("init", async (tx, isNewlyCreated) => {
|
|
10415
10487
|
if (isNewlyCreated) {
|
|
@@ -10514,7 +10586,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10514
10586
|
const existing = this.registeredIndices.get(name);
|
|
10515
10587
|
if (JSON.stringify(existing) === JSON.stringify(config)) return;
|
|
10516
10588
|
}
|
|
10517
|
-
await this.
|
|
10589
|
+
await this.runWithDefaultWrite(async (tx2) => {
|
|
10518
10590
|
const metadata = await this.getDocumentInnerMetadata(tx2);
|
|
10519
10591
|
metadata.indices[name] = [-1, config];
|
|
10520
10592
|
await this.updateDocumentInnerMetadata(metadata, tx2);
|
|
@@ -10562,7 +10634,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10562
10634
|
if (!this.registeredIndices.has(name)) {
|
|
10563
10635
|
throw new Error(`Index '${name}' does not exist`);
|
|
10564
10636
|
}
|
|
10565
|
-
await this.
|
|
10637
|
+
await this.runWithDefaultWrite(async (tx2) => {
|
|
10566
10638
|
const config = this.registeredIndices.get(name);
|
|
10567
10639
|
const metadata = await this.getDocumentInnerMetadata(tx2);
|
|
10568
10640
|
delete metadata.indices[name];
|
|
@@ -10697,24 +10769,6 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10697
10769
|
return JSON.parse(row);
|
|
10698
10770
|
}, tx);
|
|
10699
10771
|
}
|
|
10700
|
-
async readLock(fn) {
|
|
10701
|
-
let lockId;
|
|
10702
|
-
return this.lock.readLock(async (_lockId) => {
|
|
10703
|
-
lockId = _lockId;
|
|
10704
|
-
return await fn();
|
|
10705
|
-
}).finally(() => {
|
|
10706
|
-
this.lock.readUnlock(lockId);
|
|
10707
|
-
});
|
|
10708
|
-
}
|
|
10709
|
-
async writeLock(fn) {
|
|
10710
|
-
let lockId;
|
|
10711
|
-
return this.lock.writeLock(async (_lockId) => {
|
|
10712
|
-
lockId = _lockId;
|
|
10713
|
-
return await fn();
|
|
10714
|
-
}).finally(() => {
|
|
10715
|
-
this.lock.writeUnlock(lockId);
|
|
10716
|
-
});
|
|
10717
|
-
}
|
|
10718
10772
|
/**
|
|
10719
10773
|
* Backfill indices for newly created indices after data was inserted.
|
|
10720
10774
|
* This method should be called after `init()`.
|
|
@@ -10722,7 +10776,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10722
10776
|
* @returns Number of documents that were backfilled
|
|
10723
10777
|
*/
|
|
10724
10778
|
async backfillIndices(tx) {
|
|
10725
|
-
return this.
|
|
10779
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
10726
10780
|
if (this.pendingBackfillFields.length === 0) {
|
|
10727
10781
|
return 0;
|
|
10728
10782
|
}
|
|
@@ -10900,7 +10954,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10900
10954
|
* @param tx Optional transaction
|
|
10901
10955
|
*/
|
|
10902
10956
|
async migration(version, callback, tx) {
|
|
10903
|
-
await this.
|
|
10957
|
+
await this.runWithDefaultWrite(async (tx2) => {
|
|
10904
10958
|
const innerMetadata = await this.getDocumentInnerMetadata(tx2);
|
|
10905
10959
|
const currentVersion = innerMetadata.schemeVersion ?? 0;
|
|
10906
10960
|
if (currentVersion < version) {
|
|
@@ -11213,7 +11267,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11213
11267
|
* @returns The primary key of the inserted document
|
|
11214
11268
|
*/
|
|
11215
11269
|
async insertSingleDocument(document, tx) {
|
|
11216
|
-
return this.
|
|
11270
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
11217
11271
|
const { pk: dpk, document: dataplyDocument } = await this.insertDocumentInternal(document, tx2);
|
|
11218
11272
|
const flattenDocument = this.flattenDocument(dataplyDocument);
|
|
11219
11273
|
for (const [indexName, config] of this.registeredIndices) {
|
|
@@ -11239,7 +11293,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11239
11293
|
}
|
|
11240
11294
|
}
|
|
11241
11295
|
return dataplyDocument._id;
|
|
11242
|
-
}, tx)
|
|
11296
|
+
}, tx);
|
|
11243
11297
|
}
|
|
11244
11298
|
/**
|
|
11245
11299
|
* Insert a batch of documents into the database
|
|
@@ -11248,7 +11302,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11248
11302
|
* @returns The primary keys of the inserted documents
|
|
11249
11303
|
*/
|
|
11250
11304
|
async insertBatchDocuments(documents, tx) {
|
|
11251
|
-
return this.
|
|
11305
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
11252
11306
|
const metadata = await this.getDocumentInnerMetadata(tx2);
|
|
11253
11307
|
const startId = metadata.lastId + 1;
|
|
11254
11308
|
metadata.lastId += documents.length;
|
|
@@ -11307,7 +11361,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11307
11361
|
}
|
|
11308
11362
|
}
|
|
11309
11363
|
return ids;
|
|
11310
|
-
}, tx)
|
|
11364
|
+
}, tx);
|
|
11311
11365
|
}
|
|
11312
11366
|
/**
|
|
11313
11367
|
* Internal update method used by both fullUpdate and partialUpdate
|
|
@@ -11388,12 +11442,12 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11388
11442
|
* @returns The number of updated documents
|
|
11389
11443
|
*/
|
|
11390
11444
|
async fullUpdate(query, newRecord, tx) {
|
|
11391
|
-
return
|
|
11445
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
11392
11446
|
return this.updateInternal(query, (doc) => {
|
|
11393
11447
|
const newDoc = typeof newRecord === "function" ? newRecord(doc) : newRecord;
|
|
11394
11448
|
return { _id: doc._id, ...newDoc };
|
|
11395
11449
|
}, tx2);
|
|
11396
|
-
}, tx)
|
|
11450
|
+
}, tx);
|
|
11397
11451
|
}
|
|
11398
11452
|
/**
|
|
11399
11453
|
* Partially update documents from the database that match the query
|
|
@@ -11403,14 +11457,14 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11403
11457
|
* @returns The number of updated documents
|
|
11404
11458
|
*/
|
|
11405
11459
|
async partialUpdate(query, newRecord, tx) {
|
|
11406
|
-
return this.
|
|
11460
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
11407
11461
|
return this.updateInternal(query, (doc) => {
|
|
11408
11462
|
const partialUpdateContent = typeof newRecord === "function" ? newRecord(doc) : newRecord;
|
|
11409
11463
|
const finalUpdate = { ...partialUpdateContent };
|
|
11410
11464
|
delete finalUpdate._id;
|
|
11411
11465
|
return { ...doc, ...finalUpdate };
|
|
11412
11466
|
}, tx2);
|
|
11413
|
-
}, tx)
|
|
11467
|
+
}, tx);
|
|
11414
11468
|
}
|
|
11415
11469
|
/**
|
|
11416
11470
|
* Delete documents from the database that match the query
|
|
@@ -11419,7 +11473,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11419
11473
|
* @returns The number of deleted documents
|
|
11420
11474
|
*/
|
|
11421
11475
|
async deleteDocuments(query, tx) {
|
|
11422
|
-
return this.
|
|
11476
|
+
return this.runWithDefaultWrite(async (tx2) => {
|
|
11423
11477
|
const pks = await this.getKeys(query);
|
|
11424
11478
|
let deletedCount = 0;
|
|
11425
11479
|
for (let i = 0, len = pks.length; i < len; i++) {
|
|
@@ -11449,7 +11503,7 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11449
11503
|
deletedCount++;
|
|
11450
11504
|
}
|
|
11451
11505
|
return deletedCount;
|
|
11452
|
-
}, tx)
|
|
11506
|
+
}, tx);
|
|
11453
11507
|
}
|
|
11454
11508
|
/**
|
|
11455
11509
|
* Count documents from the database that match the query
|
|
@@ -11458,10 +11512,10 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
11458
11512
|
* @returns The number of documents that match the query
|
|
11459
11513
|
*/
|
|
11460
11514
|
async countDocuments(query, tx) {
|
|
11461
|
-
return this.
|
|
11515
|
+
return this.runWithDefault(async (tx2) => {
|
|
11462
11516
|
const pks = await this.getKeys(query);
|
|
11463
11517
|
return pks.length;
|
|
11464
|
-
}, tx)
|
|
11518
|
+
}, tx);
|
|
11465
11519
|
}
|
|
11466
11520
|
/**
|
|
11467
11521
|
* FTS 조건에 대해 문서가 유효한지 검증합니다.
|
|
@@ -3,12 +3,12 @@ import { DataplyAPI, Transaction, BPTreeAsync } from 'dataply';
|
|
|
3
3
|
import { DocumentValueComparator } from './bptree/documentComparator';
|
|
4
4
|
export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyAPI {
|
|
5
5
|
runWithDefault: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
6
|
+
runWithDefaultWrite: <T_1>(callback: (tx: Transaction) => Promise<T_1>, tx?: Transaction) => Promise<T_1>;
|
|
6
7
|
streamWithDefault: <T_1>(callback: (tx: Transaction) => AsyncGenerator<T_1>, tx?: Transaction) => AsyncGenerator<T_1>;
|
|
7
8
|
indices: DocumentDataplyInnerMetadata['indices'];
|
|
8
9
|
readonly trees: Map<string, BPTreeAsync<string | number, DataplyTreeValue<Primitive>>>;
|
|
9
10
|
readonly comparator: DocumentValueComparator<DataplyTreeValue<Primitive>, Primitive>;
|
|
10
11
|
private pendingBackfillFields;
|
|
11
|
-
private readonly lock;
|
|
12
12
|
private _initialized;
|
|
13
13
|
readonly indexedFields: Set<string>;
|
|
14
14
|
/**
|
|
@@ -76,8 +76,6 @@ export declare class DocumentDataplyAPI<T extends DocumentJSON> extends DataplyA
|
|
|
76
76
|
*/
|
|
77
77
|
private getFtsConfig;
|
|
78
78
|
getDocument(pk: number, tx?: Transaction): Promise<DataplyDocument<T>>;
|
|
79
|
-
readLock<T>(fn: () => T): Promise<T>;
|
|
80
|
-
writeLock<T>(fn: () => T): Promise<T>;
|
|
81
79
|
/**
|
|
82
80
|
* Backfill indices for newly created indices after data was inserted.
|
|
83
81
|
* This method should be called after `init()`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.9-alpha.
|
|
3
|
+
"version": "0.0.9-alpha.9",
|
|
4
4
|
"description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "izure <admin@izure.org>",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dataply"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"dataply": "^0.0.24-alpha.
|
|
45
|
+
"dataply": "^0.0.24-alpha.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "^30.0.0",
|