@atscript/db-memory 0.1.148 → 0.1.150
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 +17 -7
- package/dist/index.d.cts +5 -4
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +18 -8
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -144,6 +144,14 @@ const memoryVisitor = {
|
|
|
144
144
|
return (row) => !child(row);
|
|
145
145
|
},
|
|
146
146
|
comparison(field, op, value) {
|
|
147
|
+
if (op === _atscript_db.INTEGER_REGEX_OP) {
|
|
148
|
+
const { pattern, flags } = parseRegexString(value);
|
|
149
|
+
const regex = new RegExp(pattern, flags);
|
|
150
|
+
return (row) => {
|
|
151
|
+
const fieldValue = (0, _atscript_db.getPath)(row, field);
|
|
152
|
+
return (typeof fieldValue === "bigint" || typeof fieldValue === "number" && Number.isInteger(fieldValue)) && regex.test(String(fieldValue));
|
|
153
|
+
};
|
|
154
|
+
}
|
|
147
155
|
switch (op) {
|
|
148
156
|
case "$eq": return (row) => evalEq(row, field, value);
|
|
149
157
|
case "$ne": return (row) => !evalEq(row, field, value);
|
|
@@ -1230,12 +1238,13 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1230
1238
|
* `row`), enforces unique indexes on the result EXCLUDING the row's own key (so
|
|
1231
1239
|
* a row keeping/rewriting its own unique value never self-conflicts), then
|
|
1232
1240
|
* commits. Nothing is written to the store until both the unique and PK checks
|
|
1233
|
-
* pass, so a conflict leaves the store untouched.
|
|
1241
|
+
* pass, so a conflict leaves the store untouched. `keepVersion` skips the
|
|
1242
|
+
* bump (a version-exempt patch, since 0.1.150).
|
|
1234
1243
|
*/
|
|
1235
|
-
_commitUpdate(state, oldKey, row, data, ops) {
|
|
1244
|
+
_commitUpdate(state, oldKey, row, data, ops, keepVersion = false) {
|
|
1236
1245
|
const next = structuredClone(row);
|
|
1237
1246
|
this._applyUpdate(next, data, ops);
|
|
1238
|
-
this._bumpVersion(next, row);
|
|
1247
|
+
if (!keepVersion) this._bumpVersion(next, row);
|
|
1239
1248
|
this._enforceUniqueIndexes(state, next, oldKey);
|
|
1240
1249
|
this._commitRow(state.rows, oldKey, next);
|
|
1241
1250
|
}
|
|
@@ -1258,7 +1267,8 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1258
1267
|
modifiedCount: 1
|
|
1259
1268
|
};
|
|
1260
1269
|
}
|
|
1261
|
-
async updateOne(filter, data, ops, expectedVersion) {
|
|
1270
|
+
async updateOne(filter, data, ops, expectedVersion, opts) {
|
|
1271
|
+
const keepVersion = this._versionColumnFor(opts, expectedVersion) === void 0;
|
|
1262
1272
|
this._assertWritable();
|
|
1263
1273
|
const sets = (0, _atscript_db.containsRelationFilter)(filter) ? await this._relationSets(filter) : void 0;
|
|
1264
1274
|
const state = this._peekState();
|
|
@@ -1268,7 +1278,7 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1268
1278
|
modifiedCount: 0
|
|
1269
1279
|
};
|
|
1270
1280
|
const { key, row } = matched[0];
|
|
1271
|
-
this._commitUpdate(state, key, row, data, ops);
|
|
1281
|
+
this._commitUpdate(state, key, row, data, ops, keepVersion);
|
|
1272
1282
|
return {
|
|
1273
1283
|
matchedCount: 1,
|
|
1274
1284
|
modifiedCount: 1
|
|
@@ -1400,7 +1410,7 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1400
1410
|
viewCapabilities() {
|
|
1401
1411
|
return _atscript_db.ALL_VIEW_CAPABILITIES;
|
|
1402
1412
|
}
|
|
1403
|
-
async updateMany(filter, data, ops) {
|
|
1413
|
+
async updateMany(filter, data, ops, opts) {
|
|
1404
1414
|
this._assertWritable();
|
|
1405
1415
|
const sets = (0, _atscript_db.containsRelationFilter)(filter) ? await this._relationSets(filter) : void 0;
|
|
1406
1416
|
const state = this._peekState();
|
|
@@ -1409,7 +1419,7 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1409
1419
|
modifiedCount: 0
|
|
1410
1420
|
};
|
|
1411
1421
|
const matched = this._selectForWrite(state, filter, void 0, true, sets);
|
|
1412
|
-
for (const { key, row } of matched) this._commitUpdate(state, key, row, data, ops);
|
|
1422
|
+
for (const { key, row } of matched) this._commitUpdate(state, key, row, data, ops, opts?.keepVersion);
|
|
1413
1423
|
return {
|
|
1414
1424
|
matchedCount: matched.length,
|
|
1415
1425
|
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, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
1
|
+
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, ResolvedRelationFilter, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateOptions, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
2
2
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
3
|
|
|
4
4
|
//#region src/lib/memory-adapter.d.ts
|
|
@@ -335,11 +335,12 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
335
335
|
* `row`), enforces unique indexes on the result EXCLUDING the row's own key (so
|
|
336
336
|
* a row keeping/rewriting its own unique value never self-conflicts), then
|
|
337
337
|
* commits. Nothing is written to the store until both the unique and PK checks
|
|
338
|
-
* pass, so a conflict leaves the store untouched.
|
|
338
|
+
* pass, so a conflict leaves the store untouched. `keepVersion` skips the
|
|
339
|
+
* bump (a version-exempt patch, since 0.1.150).
|
|
339
340
|
*/
|
|
340
341
|
private _commitUpdate;
|
|
341
342
|
replaceOne(filter: FilterExpr, data: Record<string, unknown>, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
342
|
-
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
343
|
+
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, expectedVersion?: number, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
|
|
343
344
|
deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
344
345
|
/**
|
|
345
346
|
* Stable multi-key comparator from `$sort`, with a final tie-break on
|
|
@@ -415,7 +416,7 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
415
416
|
supportsAggregateExpressions(): boolean;
|
|
416
417
|
/** Managed views render nothing (non-goal) — both are accepted like `aggregateFns()`. */
|
|
417
418
|
viewCapabilities(): ReadonlySet<TViewCapability>;
|
|
418
|
-
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
|
|
419
|
+
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
|
|
419
420
|
replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
420
421
|
deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
421
422
|
/**
|
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, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
1
|
+
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, ResolvedRelationFilter, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateOptions, TDbUpdateResult, TFieldOps, TViewCapability } from "@atscript/db";
|
|
2
2
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
3
|
|
|
4
4
|
//#region src/lib/memory-adapter.d.ts
|
|
@@ -335,11 +335,12 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
335
335
|
* `row`), enforces unique indexes on the result EXCLUDING the row's own key (so
|
|
336
336
|
* a row keeping/rewriting its own unique value never self-conflicts), then
|
|
337
337
|
* commits. Nothing is written to the store until both the unique and PK checks
|
|
338
|
-
* pass, so a conflict leaves the store untouched.
|
|
338
|
+
* pass, so a conflict leaves the store untouched. `keepVersion` skips the
|
|
339
|
+
* bump (a version-exempt patch, since 0.1.150).
|
|
339
340
|
*/
|
|
340
341
|
private _commitUpdate;
|
|
341
342
|
replaceOne(filter: FilterExpr, data: Record<string, unknown>, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
342
|
-
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, expectedVersion?: number): Promise<TDbUpdateResult>;
|
|
343
|
+
updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, expectedVersion?: number, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
|
|
343
344
|
deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
344
345
|
/**
|
|
345
346
|
* Stable multi-key comparator from `$sort`, with a final tie-break on
|
|
@@ -415,7 +416,7 @@ declare class MemoryAdapter extends BaseDbAdapter {
|
|
|
415
416
|
supportsAggregateExpressions(): boolean;
|
|
416
417
|
/** Managed views render nothing (non-goal) — both are accepted like `aggregateFns()`. */
|
|
417
418
|
viewCapabilities(): ReadonlySet<TViewCapability>;
|
|
418
|
-
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
|
|
419
|
+
updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
|
|
419
420
|
replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
420
421
|
deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
421
422
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, containsRelationFilter, deletePath, evaluateExpr, forEachResolvedRelation, getPath, getPath as getPath$1, isAtscriptDbView, isConflict, isResolvedRelationFilter, walkFilter } from "@atscript/db";
|
|
1
|
+
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, INTEGER_REGEX_OP, containsRelationFilter, deletePath, evaluateExpr, forEachResolvedRelation, getPath, getPath as getPath$1, isAtscriptDbView, isConflict, isResolvedRelationFilter, 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-filter.ts
|
|
@@ -143,6 +143,14 @@ const memoryVisitor = {
|
|
|
143
143
|
return (row) => !child(row);
|
|
144
144
|
},
|
|
145
145
|
comparison(field, op, value) {
|
|
146
|
+
if (op === INTEGER_REGEX_OP) {
|
|
147
|
+
const { pattern, flags } = parseRegexString(value);
|
|
148
|
+
const regex = new RegExp(pattern, flags);
|
|
149
|
+
return (row) => {
|
|
150
|
+
const fieldValue = getPath$1(row, field);
|
|
151
|
+
return (typeof fieldValue === "bigint" || typeof fieldValue === "number" && Number.isInteger(fieldValue)) && regex.test(String(fieldValue));
|
|
152
|
+
};
|
|
153
|
+
}
|
|
146
154
|
switch (op) {
|
|
147
155
|
case "$eq": return (row) => evalEq(row, field, value);
|
|
148
156
|
case "$ne": return (row) => !evalEq(row, field, value);
|
|
@@ -1229,12 +1237,13 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1229
1237
|
* `row`), enforces unique indexes on the result EXCLUDING the row's own key (so
|
|
1230
1238
|
* a row keeping/rewriting its own unique value never self-conflicts), then
|
|
1231
1239
|
* commits. Nothing is written to the store until both the unique and PK checks
|
|
1232
|
-
* pass, so a conflict leaves the store untouched.
|
|
1240
|
+
* pass, so a conflict leaves the store untouched. `keepVersion` skips the
|
|
1241
|
+
* bump (a version-exempt patch, since 0.1.150).
|
|
1233
1242
|
*/
|
|
1234
|
-
_commitUpdate(state, oldKey, row, data, ops) {
|
|
1243
|
+
_commitUpdate(state, oldKey, row, data, ops, keepVersion = false) {
|
|
1235
1244
|
const next = structuredClone(row);
|
|
1236
1245
|
this._applyUpdate(next, data, ops);
|
|
1237
|
-
this._bumpVersion(next, row);
|
|
1246
|
+
if (!keepVersion) this._bumpVersion(next, row);
|
|
1238
1247
|
this._enforceUniqueIndexes(state, next, oldKey);
|
|
1239
1248
|
this._commitRow(state.rows, oldKey, next);
|
|
1240
1249
|
}
|
|
@@ -1257,7 +1266,8 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1257
1266
|
modifiedCount: 1
|
|
1258
1267
|
};
|
|
1259
1268
|
}
|
|
1260
|
-
async updateOne(filter, data, ops, expectedVersion) {
|
|
1269
|
+
async updateOne(filter, data, ops, expectedVersion, opts) {
|
|
1270
|
+
const keepVersion = this._versionColumnFor(opts, expectedVersion) === void 0;
|
|
1261
1271
|
this._assertWritable();
|
|
1262
1272
|
const sets = containsRelationFilter(filter) ? await this._relationSets(filter) : void 0;
|
|
1263
1273
|
const state = this._peekState();
|
|
@@ -1267,7 +1277,7 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1267
1277
|
modifiedCount: 0
|
|
1268
1278
|
};
|
|
1269
1279
|
const { key, row } = matched[0];
|
|
1270
|
-
this._commitUpdate(state, key, row, data, ops);
|
|
1280
|
+
this._commitUpdate(state, key, row, data, ops, keepVersion);
|
|
1271
1281
|
return {
|
|
1272
1282
|
matchedCount: 1,
|
|
1273
1283
|
modifiedCount: 1
|
|
@@ -1399,7 +1409,7 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1399
1409
|
viewCapabilities() {
|
|
1400
1410
|
return ALL_VIEW_CAPABILITIES;
|
|
1401
1411
|
}
|
|
1402
|
-
async updateMany(filter, data, ops) {
|
|
1412
|
+
async updateMany(filter, data, ops, opts) {
|
|
1403
1413
|
this._assertWritable();
|
|
1404
1414
|
const sets = containsRelationFilter(filter) ? await this._relationSets(filter) : void 0;
|
|
1405
1415
|
const state = this._peekState();
|
|
@@ -1408,7 +1418,7 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
|
|
|
1408
1418
|
modifiedCount: 0
|
|
1409
1419
|
};
|
|
1410
1420
|
const matched = this._selectForWrite(state, filter, void 0, true, sets);
|
|
1411
|
-
for (const { key, row } of matched) this._commitUpdate(state, key, row, data, ops);
|
|
1421
|
+
for (const { key, row } of matched) this._commitUpdate(state, key, row, data, ops, opts?.keepVersion);
|
|
1412
1422
|
return {
|
|
1413
1423
|
matchedCount: matched.length,
|
|
1414
1424
|
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.150",
|
|
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.101",
|
|
40
|
+
"@atscript/typescript": "^0.1.101",
|
|
41
41
|
"@uniqu/core": "^0.1.13",
|
|
42
|
-
"unplugin-atscript": "^0.1.
|
|
42
|
+
"unplugin-atscript": "^0.1.101"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@atscript/core": "^0.1.
|
|
46
|
-
"@atscript/typescript": "^0.1.
|
|
45
|
+
"@atscript/core": "^0.1.101",
|
|
46
|
+
"@atscript/typescript": "^0.1.101",
|
|
47
47
|
"@uniqu/core": "^0.1.13",
|
|
48
|
-
"@atscript/db": "^0.1.
|
|
48
|
+
"@atscript/db": "^0.1.150"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"postinstall": "asc -f dts",
|