@atscript/db-memory 0.1.161 → 0.1.163
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/index.cjs +26 -11
- package/dist/index.d.cts +15 -1
- package/dist/index.d.mts +15 -1
- package/dist/index.mjs +26 -11
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -860,18 +860,9 @@ function identityToken(value) {
|
|
|
860
860
|
case "number":
|
|
861
861
|
case "bigint": return `n${String(value)}`;
|
|
862
862
|
case "boolean": return value ? "b1" : "b0";
|
|
863
|
-
default: return `j${stableJson(value)}`;
|
|
863
|
+
default: return `j${(0, _atscript_db.stableJson)(value)}`;
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
|
-
/** `JSON.stringify` with object keys sorted at every level. */
|
|
867
|
-
function stableJson(value) {
|
|
868
|
-
return JSON.stringify(value, (_key, v) => {
|
|
869
|
-
if (v === null || typeof v !== "object" || Array.isArray(v)) return v;
|
|
870
|
-
const sorted = {};
|
|
871
|
-
for (const k of Object.keys(v).toSorted()) sorted[k] = v[k];
|
|
872
|
-
return sorted;
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
866
|
/** Numeric value of a measure, or `undefined` for null / missing / non-numeric. */
|
|
876
867
|
function numericValue(value) {
|
|
877
868
|
if (typeof value === "number") return Number.isNaN(value) ? void 0 : value;
|
|
@@ -1505,6 +1496,13 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1505
1496
|
if (versionColumn !== void 0) target[versionColumn] = (oldRow[versionColumn] ?? 0) + 1;
|
|
1506
1497
|
}
|
|
1507
1498
|
/**
|
|
1499
|
+
* Sets each `@db.onUpdate.inc` counter of a full replace to the old row's
|
|
1500
|
+
* value + 1 (a missing one counts as `0`; since 0.1.162).
|
|
1501
|
+
*/
|
|
1502
|
+
_bumpCounters(target, oldRow) {
|
|
1503
|
+
for (const col of this._table.onUpdateIncPhysical) target[col] = (oldRow[col] ?? 0) + 1;
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1508
1506
|
* Applies a merge-style update to `row` IN PLACE — the memory analogue of
|
|
1509
1507
|
* `buildMongoUpdateDoc`:
|
|
1510
1508
|
*
|
|
@@ -1571,6 +1569,7 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1571
1569
|
const { key, row } = matched[0];
|
|
1572
1570
|
const next = cloneValue(data);
|
|
1573
1571
|
this._bumpVersion(next, row);
|
|
1572
|
+
this._bumpCounters(next, row);
|
|
1574
1573
|
const tuples = this._enforceUniqueIndexes(state, next, key);
|
|
1575
1574
|
this._commitRow(state, key, row, next, tuples);
|
|
1576
1575
|
return {
|
|
@@ -1752,6 +1751,21 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1752
1751
|
supportsNullsPlacement() {
|
|
1753
1752
|
return true;
|
|
1754
1753
|
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Locking reads are accepted and ignored inside a `withTransaction` scope
|
|
1756
|
+
* (since 0.1.162) — the in-memory store has no concurrent transactions to
|
|
1757
|
+
* lock rows against.
|
|
1758
|
+
*/
|
|
1759
|
+
supportsReadLocks() {
|
|
1760
|
+
return true;
|
|
1761
|
+
}
|
|
1762
|
+
/** Every level is accepted and ignored (no transaction isolation). @since 0.1.162 */
|
|
1763
|
+
isolationLevels() {
|
|
1764
|
+
return _atscript_db.ALL_ISOLATION_LEVELS;
|
|
1765
|
+
}
|
|
1766
|
+
_inherentIsolation() {
|
|
1767
|
+
return "serializable";
|
|
1768
|
+
}
|
|
1755
1769
|
/** Managed views render nothing (non-goal) — both are accepted like `aggregateFns()`. */
|
|
1756
1770
|
viewCapabilities() {
|
|
1757
1771
|
return _atscript_db.ALL_VIEW_CAPABILITIES;
|
|
@@ -1780,7 +1794,8 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1780
1794
|
modifiedCount: 0
|
|
1781
1795
|
};
|
|
1782
1796
|
const matched = this._selectForWrite(state, filter, void 0, true, sets);
|
|
1783
|
-
|
|
1797
|
+
const ops = this._onUpdateIncOps();
|
|
1798
|
+
for (const { key, row } of matched) this._commitUpdate(state, key, row, data, ops);
|
|
1784
1799
|
return {
|
|
1785
1800
|
matchedCount: matched.length,
|
|
1786
1801
|
modifiedCount: matched.length
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, ResolvedRelationFilter, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateOptions, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
1
|
+
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, ResolvedRelationFilter, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbIsolationLevel, TDbObjectKind, TDbUpdateOptions, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
2
2
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
3
|
import { NullsPlacement } from "@uniqu/core";
|
|
4
4
|
|
|
@@ -327,6 +327,11 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
327
327
|
* {@link replaceOne} (full-replace path).
|
|
328
328
|
*/
|
|
329
329
|
private _bumpVersion;
|
|
330
|
+
/**
|
|
331
|
+
* Sets each `@db.onUpdate.inc` counter of a full replace to the old row's
|
|
332
|
+
* value + 1 (a missing one counts as `0`; since 0.1.162).
|
|
333
|
+
*/
|
|
334
|
+
private _bumpCounters;
|
|
330
335
|
/**
|
|
331
336
|
* Applies a merge-style update to `row` IN PLACE — the memory analogue of
|
|
332
337
|
* `buildMongoUpdateDoc`:
|
|
@@ -452,6 +457,15 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
452
457
|
supportsAggregateExpressions(): boolean;
|
|
453
458
|
/** NULL placement (`$nulls`, `@db.sort.nulls`) — `sortRows` honours it per key. */
|
|
454
459
|
supportsNullsPlacement(): boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Locking reads are accepted and ignored inside a `withTransaction` scope
|
|
462
|
+
* (since 0.1.162) — the in-memory store has no concurrent transactions to
|
|
463
|
+
* lock rows against.
|
|
464
|
+
*/
|
|
465
|
+
supportsReadLocks(): boolean;
|
|
466
|
+
/** Every level is accepted and ignored (no transaction isolation). @since 0.1.162 */
|
|
467
|
+
isolationLevels(): ReadonlySet<TDbIsolationLevel>;
|
|
468
|
+
protected _inherentIsolation(): TDbIsolationLevel;
|
|
455
469
|
/** Managed views render nothing (non-goal) — both are accepted like `aggregateFns()`. */
|
|
456
470
|
viewCapabilities(): ReadonlySet<TViewCapability>;
|
|
457
471
|
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, ResolvedRelationFilter, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateOptions, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
1
|
+
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, ResolvedRelationFilter, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbIsolationLevel, TDbObjectKind, TDbUpdateOptions, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
2
2
|
import { NullsPlacement } from "@uniqu/core";
|
|
3
3
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
4
4
|
|
|
@@ -327,6 +327,11 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
327
327
|
* {@link replaceOne} (full-replace path).
|
|
328
328
|
*/
|
|
329
329
|
private _bumpVersion;
|
|
330
|
+
/**
|
|
331
|
+
* Sets each `@db.onUpdate.inc` counter of a full replace to the old row's
|
|
332
|
+
* value + 1 (a missing one counts as `0`; since 0.1.162).
|
|
333
|
+
*/
|
|
334
|
+
private _bumpCounters;
|
|
330
335
|
/**
|
|
331
336
|
* Applies a merge-style update to `row` IN PLACE — the memory analogue of
|
|
332
337
|
* `buildMongoUpdateDoc`:
|
|
@@ -452,6 +457,15 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
452
457
|
supportsAggregateExpressions(): boolean;
|
|
453
458
|
/** NULL placement (`$nulls`, `@db.sort.nulls`) — `sortRows` honours it per key. */
|
|
454
459
|
supportsNullsPlacement(): boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Locking reads are accepted and ignored inside a `withTransaction` scope
|
|
462
|
+
* (since 0.1.162) — the in-memory store has no concurrent transactions to
|
|
463
|
+
* lock rows against.
|
|
464
|
+
*/
|
|
465
|
+
supportsReadLocks(): boolean;
|
|
466
|
+
/** Every level is accepted and ignored (no transaction isolation). @since 0.1.162 */
|
|
467
|
+
isolationLevels(): ReadonlySet<TDbIsolationLevel>;
|
|
468
|
+
protected _inherentIsolation(): TDbIsolationLevel;
|
|
455
469
|
/** Managed views render nothing (non-goal) — both are accepted like `aggregateFns()`. */
|
|
456
470
|
viewCapabilities(): ReadonlySet<TViewCapability>;
|
|
457
471
|
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, INTEGER_REGEX_OP, containsRelationFilter, deletePath, evaluateExpr, forEachResolvedRelation, getPath, isAtscriptDbView, isConflict, isPlainObject, isResolvedRelationFilter, walkFilter } from "@atscript/db";
|
|
1
|
+
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_ISOLATION_LEVELS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, INTEGER_REGEX_OP, containsRelationFilter, deletePath, evaluateExpr, forEachResolvedRelation, getPath, isAtscriptDbView, isConflict, isPlainObject, isResolvedRelationFilter, stableJson, walkFilter } from "@atscript/db";
|
|
2
2
|
import { assertAggregateFn, resolveAlias } from "@atscript/db/agg";
|
|
3
3
|
import { bucketer } from "@uniqu/core";
|
|
4
4
|
//#region src/lib/memory-clone.ts
|
|
@@ -862,15 +862,6 @@ function identityToken(value) {
|
|
|
862
862
|
default: return `j${stableJson(value)}`;
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
|
-
/** `JSON.stringify` with object keys sorted at every level. */
|
|
866
|
-
function stableJson(value) {
|
|
867
|
-
return JSON.stringify(value, (_key, v) => {
|
|
868
|
-
if (v === null || typeof v !== "object" || Array.isArray(v)) return v;
|
|
869
|
-
const sorted = {};
|
|
870
|
-
for (const k of Object.keys(v).toSorted()) sorted[k] = v[k];
|
|
871
|
-
return sorted;
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
865
|
/** Numeric value of a measure, or `undefined` for null / missing / non-numeric. */
|
|
875
866
|
function numericValue(value) {
|
|
876
867
|
if (typeof value === "number") return Number.isNaN(value) ? void 0 : value;
|
|
@@ -1504,6 +1495,13 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1504
1495
|
if (versionColumn !== void 0) target[versionColumn] = (oldRow[versionColumn] ?? 0) + 1;
|
|
1505
1496
|
}
|
|
1506
1497
|
/**
|
|
1498
|
+
* Sets each `@db.onUpdate.inc` counter of a full replace to the old row's
|
|
1499
|
+
* value + 1 (a missing one counts as `0`; since 0.1.162).
|
|
1500
|
+
*/
|
|
1501
|
+
_bumpCounters(target, oldRow) {
|
|
1502
|
+
for (const col of this._table.onUpdateIncPhysical) target[col] = (oldRow[col] ?? 0) + 1;
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1507
1505
|
* Applies a merge-style update to `row` IN PLACE — the memory analogue of
|
|
1508
1506
|
* `buildMongoUpdateDoc`:
|
|
1509
1507
|
*
|
|
@@ -1570,6 +1568,7 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1570
1568
|
const { key, row } = matched[0];
|
|
1571
1569
|
const next = cloneValue(data);
|
|
1572
1570
|
this._bumpVersion(next, row);
|
|
1571
|
+
this._bumpCounters(next, row);
|
|
1573
1572
|
const tuples = this._enforceUniqueIndexes(state, next, key);
|
|
1574
1573
|
this._commitRow(state, key, row, next, tuples);
|
|
1575
1574
|
return {
|
|
@@ -1751,6 +1750,21 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1751
1750
|
supportsNullsPlacement() {
|
|
1752
1751
|
return true;
|
|
1753
1752
|
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Locking reads are accepted and ignored inside a `withTransaction` scope
|
|
1755
|
+
* (since 0.1.162) — the in-memory store has no concurrent transactions to
|
|
1756
|
+
* lock rows against.
|
|
1757
|
+
*/
|
|
1758
|
+
supportsReadLocks() {
|
|
1759
|
+
return true;
|
|
1760
|
+
}
|
|
1761
|
+
/** Every level is accepted and ignored (no transaction isolation). @since 0.1.162 */
|
|
1762
|
+
isolationLevels() {
|
|
1763
|
+
return ALL_ISOLATION_LEVELS;
|
|
1764
|
+
}
|
|
1765
|
+
_inherentIsolation() {
|
|
1766
|
+
return "serializable";
|
|
1767
|
+
}
|
|
1754
1768
|
/** Managed views render nothing (non-goal) — both are accepted like `aggregateFns()`. */
|
|
1755
1769
|
viewCapabilities() {
|
|
1756
1770
|
return ALL_VIEW_CAPABILITIES;
|
|
@@ -1779,7 +1793,8 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1779
1793
|
modifiedCount: 0
|
|
1780
1794
|
};
|
|
1781
1795
|
const matched = this._selectForWrite(state, filter, void 0, true, sets);
|
|
1782
|
-
|
|
1796
|
+
const ops = this._onUpdateIncOps();
|
|
1797
|
+
for (const { key, row } of matched) this._commitUpdate(state, key, row, data, ops);
|
|
1783
1798
|
return {
|
|
1784
1799
|
matchedCount: matched.length,
|
|
1785
1800
|
modifiedCount: matched.length
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.163",
|
|
4
4
|
"description": "In-memory adapter for atscript-db.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@atscript/core": "^0.1.
|
|
40
|
-
"@atscript/typescript": "^0.1.
|
|
39
|
+
"@atscript/core": "^0.1.109",
|
|
40
|
+
"@atscript/typescript": "^0.1.109",
|
|
41
41
|
"@uniqu/core": "^0.1.15",
|
|
42
|
-
"unplugin-atscript": "^0.1.
|
|
42
|
+
"unplugin-atscript": "^0.1.109"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@atscript/core": "^0.1.
|
|
46
|
-
"@atscript/typescript": "^0.1.
|
|
45
|
+
"@atscript/core": "^0.1.109",
|
|
46
|
+
"@atscript/typescript": "^0.1.109",
|
|
47
47
|
"@uniqu/core": "^0.1.15",
|
|
48
|
-
"@atscript/db": "^0.1.
|
|
48
|
+
"@atscript/db": "^0.1.163"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "vp pack",
|