@atscript/db-memory 0.1.163 → 0.1.165

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 CHANGED
@@ -1210,16 +1210,12 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
1210
1210
  }
1211
1211
  }
1212
1212
  /**
1213
- * Builds the duplicate-primary-key {@link DbError}. The reported `path` is the
1214
- * physical `@meta.id` name, falling back to the first (logical) primary key,
1215
- * then `""`. Centralized so the insert and re-key paths raise an identical
1216
- * CONFLICT.
1213
+ * Builds the duplicate-primary-key {@link DbError} — a primary-key hint the
1214
+ * table layer turns into the key's logical paths. Centralized so the insert
1215
+ * and re-key paths raise an identical CONFLICT.
1217
1216
  */
1218
1217
  _pkConflict() {
1219
- return new _atscript_db.DbError("CONFLICT", [{
1220
- path: this._table.metaIdPhysical ?? this._table.primaryKeys[0] ?? "",
1221
- message: "Duplicate primary key"
1222
- }]);
1218
+ return (0, _atscript_db.constraintViolation)("CONFLICT", { primaryKey: true }, "Duplicate primary key");
1223
1219
  }
1224
1220
  /**
1225
1221
  * Derives the storage key from a row's PRIMARY KEY value(s), read by PHYSICAL
@@ -1386,10 +1382,10 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
1386
1382
  _enforceUniqueIndexes(state, row, excludeKey) {
1387
1383
  return state.uniqueIndexes.map((index) => {
1388
1384
  const tuple = uniqueTupleKey(index, row);
1389
- if (tuple !== void 0 && tupleTaken(index, tuple, excludeKey)) throw new _atscript_db.DbError("CONFLICT", [{
1390
- path: index.fields[0] ?? index.name,
1391
- message: `Duplicate value for unique index "${index.name}"`
1392
- }]);
1385
+ if (tuple !== void 0 && tupleTaken(index, tuple, excludeKey)) throw (0, _atscript_db.constraintViolation)("CONFLICT", {
1386
+ name: index.name,
1387
+ columns: index.fields
1388
+ }, `Duplicate value for unique index "${index.name}"`);
1393
1389
  return tuple;
1394
1390
  });
1395
1391
  }
@@ -1503,6 +1499,14 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
1503
1499
  for (const col of this._table.onUpdateIncPhysical) target[col] = (oldRow[col] ?? 0) + 1;
1504
1500
  }
1505
1501
  /**
1502
+ * Carries the old row's insert-only values (`number.timestamp.created`)
1503
+ * over to a full replace (since 0.1.165).
1504
+ */
1505
+ _keepInsertOnly(target, oldRow) {
1506
+ for (const col of this._table.insertOnlyPhysical) if (col in oldRow) target[col] = oldRow[col];
1507
+ else delete target[col];
1508
+ }
1509
+ /**
1506
1510
  * Applies a merge-style update to `row` IN PLACE — the memory analogue of
1507
1511
  * `buildMongoUpdateDoc`:
1508
1512
  *
@@ -1570,6 +1574,7 @@ var MemoryAdapter = class MemoryAdapter extends _atscript_db.BaseDbAdapter {
1570
1574
  const next = cloneValue(data);
1571
1575
  this._bumpVersion(next, row);
1572
1576
  this._bumpCounters(next, row);
1577
+ this._keepInsertOnly(next, row);
1573
1578
  const tuples = this._enforceUniqueIndexes(state, next, key);
1574
1579
  this._commitRow(state, key, row, next, tuples);
1575
1580
  return {
package/dist/index.d.cts CHANGED
@@ -167,10 +167,9 @@ declare class MemoryAdapter extends BaseDbAdapter {
167
167
  */
168
168
  private _applyIncrements;
169
169
  /**
170
- * Builds the duplicate-primary-key {@link DbError}. The reported `path` is the
171
- * physical `@meta.id` name, falling back to the first (logical) primary key,
172
- * then `""`. Centralized so the insert and re-key paths raise an identical
173
- * CONFLICT.
170
+ * Builds the duplicate-primary-key {@link DbError} — a primary-key hint the
171
+ * table layer turns into the key's logical paths. Centralized so the insert
172
+ * and re-key paths raise an identical CONFLICT.
174
173
  */
175
174
  private _pkConflict;
176
175
  /**
@@ -332,6 +331,11 @@ declare class MemoryAdapter extends BaseDbAdapter {
332
331
  * value + 1 (a missing one counts as `0`; since 0.1.162).
333
332
  */
334
333
  private _bumpCounters;
334
+ /**
335
+ * Carries the old row's insert-only values (`number.timestamp.created`)
336
+ * over to a full replace (since 0.1.165).
337
+ */
338
+ private _keepInsertOnly;
335
339
  /**
336
340
  * Applies a merge-style update to `row` IN PLACE — the memory analogue of
337
341
  * `buildMongoUpdateDoc`:
package/dist/index.d.mts CHANGED
@@ -167,10 +167,9 @@ declare class MemoryAdapter extends BaseDbAdapter {
167
167
  */
168
168
  private _applyIncrements;
169
169
  /**
170
- * Builds the duplicate-primary-key {@link DbError}. The reported `path` is the
171
- * physical `@meta.id` name, falling back to the first (logical) primary key,
172
- * then `""`. Centralized so the insert and re-key paths raise an identical
173
- * CONFLICT.
170
+ * Builds the duplicate-primary-key {@link DbError} — a primary-key hint the
171
+ * table layer turns into the key's logical paths. Centralized so the insert
172
+ * and re-key paths raise an identical CONFLICT.
174
173
  */
175
174
  private _pkConflict;
176
175
  /**
@@ -332,6 +331,11 @@ declare class MemoryAdapter extends BaseDbAdapter {
332
331
  * value + 1 (a missing one counts as `0`; since 0.1.162).
333
332
  */
334
333
  private _bumpCounters;
334
+ /**
335
+ * Carries the old row's insert-only values (`number.timestamp.created`)
336
+ * over to a full replace (since 0.1.165).
337
+ */
338
+ private _keepInsertOnly;
335
339
  /**
336
340
  * Applies a merge-style update to `row` IN PLACE — the memory analogue of
337
341
  * `buildMongoUpdateDoc`:
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_ISOLATION_LEVELS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, INTEGER_REGEX_OP, constraintViolation, 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
@@ -1209,16 +1209,12 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
1209
1209
  }
1210
1210
  }
1211
1211
  /**
1212
- * Builds the duplicate-primary-key {@link DbError}. The reported `path` is the
1213
- * physical `@meta.id` name, falling back to the first (logical) primary key,
1214
- * then `""`. Centralized so the insert and re-key paths raise an identical
1215
- * CONFLICT.
1212
+ * Builds the duplicate-primary-key {@link DbError} — a primary-key hint the
1213
+ * table layer turns into the key's logical paths. Centralized so the insert
1214
+ * and re-key paths raise an identical CONFLICT.
1216
1215
  */
1217
1216
  _pkConflict() {
1218
- return new DbError("CONFLICT", [{
1219
- path: this._table.metaIdPhysical ?? this._table.primaryKeys[0] ?? "",
1220
- message: "Duplicate primary key"
1221
- }]);
1217
+ return constraintViolation("CONFLICT", { primaryKey: true }, "Duplicate primary key");
1222
1218
  }
1223
1219
  /**
1224
1220
  * Derives the storage key from a row's PRIMARY KEY value(s), read by PHYSICAL
@@ -1385,10 +1381,10 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
1385
1381
  _enforceUniqueIndexes(state, row, excludeKey) {
1386
1382
  return state.uniqueIndexes.map((index) => {
1387
1383
  const tuple = uniqueTupleKey(index, row);
1388
- if (tuple !== void 0 && tupleTaken(index, tuple, excludeKey)) throw new DbError("CONFLICT", [{
1389
- path: index.fields[0] ?? index.name,
1390
- message: `Duplicate value for unique index "${index.name}"`
1391
- }]);
1384
+ if (tuple !== void 0 && tupleTaken(index, tuple, excludeKey)) throw constraintViolation("CONFLICT", {
1385
+ name: index.name,
1386
+ columns: index.fields
1387
+ }, `Duplicate value for unique index "${index.name}"`);
1392
1388
  return tuple;
1393
1389
  });
1394
1390
  }
@@ -1502,6 +1498,14 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
1502
1498
  for (const col of this._table.onUpdateIncPhysical) target[col] = (oldRow[col] ?? 0) + 1;
1503
1499
  }
1504
1500
  /**
1501
+ * Carries the old row's insert-only values (`number.timestamp.created`)
1502
+ * over to a full replace (since 0.1.165).
1503
+ */
1504
+ _keepInsertOnly(target, oldRow) {
1505
+ for (const col of this._table.insertOnlyPhysical) if (col in oldRow) target[col] = oldRow[col];
1506
+ else delete target[col];
1507
+ }
1508
+ /**
1505
1509
  * Applies a merge-style update to `row` IN PLACE — the memory analogue of
1506
1510
  * `buildMongoUpdateDoc`:
1507
1511
  *
@@ -1569,6 +1573,7 @@ var MemoryAdapter = class MemoryAdapter extends BaseDbAdapter {
1569
1573
  const next = cloneValue(data);
1570
1574
  this._bumpVersion(next, row);
1571
1575
  this._bumpCounters(next, row);
1576
+ this._keepInsertOnly(next, row);
1572
1577
  const tuples = this._enforceUniqueIndexes(state, next, key);
1573
1578
  this._commitRow(state, key, row, next, tuples);
1574
1579
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-memory",
3
- "version": "0.1.163",
3
+ "version": "0.1.165",
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.109",
40
- "@atscript/typescript": "^0.1.109",
39
+ "@atscript/core": "^0.2.1",
40
+ "@atscript/typescript": "^0.2.1",
41
41
  "@uniqu/core": "^0.1.15",
42
- "unplugin-atscript": "^0.1.109"
42
+ "unplugin-atscript": "^0.2.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@atscript/core": "^0.1.109",
46
- "@atscript/typescript": "^0.1.109",
45
+ "@atscript/core": "^0.2.1",
46
+ "@atscript/typescript": "^0.2.1",
47
47
  "@uniqu/core": "^0.1.15",
48
- "@atscript/db": "^0.1.163"
48
+ "@atscript/db": "^0.1.165"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "vp pack",