@atscript/db-mongo 0.1.183 → 0.1.184

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
@@ -385,20 +385,20 @@ var CollectionPatcher = class {
385
385
  const topLevelArray = flatType?.metadata?.get("db.__topLevelArray");
386
386
  const isObjectValue = typeof value === "object" && value !== null && !Array.isArray(value);
387
387
  if (isObjectValue && topLevelArray && !flatType?.metadata?.has("db.json")) this.parseArrayPatch(key, value, flatType);
388
- else if (isObjectValue && flatType?.metadata?.get("db.patch.strategy") === "merge") this.flattenPayload(value, key);
389
- else if (isObjectValue && flatType?.type.kind === "object" && !flatType.metadata?.has("db.json")) this._flattenReplaceObject(value, key, flatType);
388
+ else if (isObjectValue && this.collection.mergePaths.has(key)) this.flattenPayload(value, key);
389
+ else if (isObjectValue && (0, _atscript_db.storedObjectType)(flatType) && !flatType.metadata?.has("db.json")) this._flattenReplaceObject(value, key, flatType);
390
390
  else if (key !== "_id") this._setLeaf(key, value, flatType);
391
391
  }
392
392
  return this.updatePipeline;
393
393
  }
394
394
  /**
395
- * Walk the schema's props for a replace-strategy nested object so omitted
396
- * optional children become explicit nulls (parity with SQL `column = NULL`).
397
- * Required-missing leaves are caught earlier by the strict validator.
395
+ * Walk the schema's props for a replace-strategy nested object (a `T | null`
396
+ * one included, `storedObjectType`) so omitted optional children become
397
+ * explicit nulls (parity with SQL `column = NULL`). Required-missing leaves
398
+ * are caught earlier by the strict validator.
398
399
  */
399
400
  _flattenReplaceObject(value, prefix, flatType) {
400
- const propsMap = flatType.type.props;
401
- for (const [propKey, propType] of propsMap) {
401
+ for (const [propKey, propType] of (0, _atscript_db.storedObjectType)(flatType).type.props) {
402
402
  const childKey = `${prefix}.${propKey}`;
403
403
  const childValue = value[propKey];
404
404
  if (childValue === void 0) {
@@ -407,15 +407,17 @@ var CollectionPatcher = class {
407
407
  }
408
408
  const childIsObject = typeof childValue === "object" && childValue !== null && !Array.isArray(childValue);
409
409
  const propIsJson = propType.metadata?.has("db.json");
410
- const propIsMerge = propType.metadata?.get("db.patch.strategy") === "merge";
411
410
  const childFlatType = this.collection.flatMap.get(childKey);
412
411
  if (childIsObject && !propIsJson && childFlatType?.metadata?.get("db.__topLevelArray")) {
413
412
  this.parseArrayPatch(childKey, childValue, childFlatType);
414
413
  continue;
415
414
  }
416
- if (childIsObject && propType.type.kind === "object" && !propIsJson) {
417
- if (propIsMerge) this.flattenPayload(childValue, childKey);
418
- else this._flattenReplaceObject(childValue, childKey, propType);
415
+ if (childIsObject && this.collection.mergePaths.has(childKey)) {
416
+ this.flattenPayload(childValue, childKey);
417
+ continue;
418
+ }
419
+ if (childIsObject && (0, _atscript_db.storedObjectType)(propType) && !propIsJson) {
420
+ this._flattenReplaceObject(childValue, childKey, propType);
419
421
  continue;
420
422
  }
421
423
  this._setLeaf(childKey, childValue, propType);
@@ -442,8 +444,8 @@ var CollectionPatcher = class {
442
444
  return;
443
445
  }
444
446
  this._remove(key, toRemove, keys, flatType);
445
- this._update(key, toUpdate, keys, flatType);
446
- this._upsert(key, toUpsert, keys, flatType);
447
+ this._update(key, toUpdate, keys);
448
+ this._upsert(key, toUpsert, keys);
447
449
  this._insert(key, toInsert, keys, flatType);
448
450
  }
449
451
  /**
@@ -545,13 +547,13 @@ var CollectionPatcher = class {
545
547
  * or append when none has it
546
548
  * - key-less → append unless an equal element is stored
547
549
  */
548
- _upsert(key, input, keys, flatType) {
550
+ _upsert(key, input, keys) {
549
551
  if (!input?.length) return;
550
552
  if (keys.length === 0) {
551
553
  this._appendAbsent(key, input);
552
554
  return;
553
555
  }
554
- const mergeStrategy = flatType.metadata?.get("db.patch.strategy") === "merge";
556
+ const mergeStrategy = this.collection.mergePaths.has(key);
555
557
  this._appendUnless(key, input, this._keyStored(keys), { $map: {
556
558
  input: "$$value",
557
559
  as: "el",
@@ -569,9 +571,9 @@ var CollectionPatcher = class {
569
571
  * 0.1.180, as on every other adapter; before, the items were added to
570
572
  * the array as a set union)
571
573
  */
572
- _update(key, input, keys, flatType) {
574
+ _update(key, input, keys) {
573
575
  if (!input?.length || keys.length === 0) return;
574
- const mergeStrategy = flatType.metadata?.get("db.patch.strategy") === "merge";
576
+ const mergeStrategy = this.collection.mergePaths.has(key);
575
577
  this._set(key, { $reduce: {
576
578
  input: literal(input),
577
579
  initialValue: { $ifNull: [`$${key}`, []] },
@@ -1400,15 +1402,12 @@ async function vectorSearchWithCountImpl(host, vector, query, indexName) {
1400
1402
  /**
1401
1403
  * The stages right after `$vectorSearch`: its score into {@link SCORE_FIELD}
1402
1404
  * (the `$meta` is read here, ahead of any `$facet`) and, with a threshold,
1403
- * into `_score` — kept for compatibility — with the `$match` on it.
1405
+ * the `$match` on it.
1404
1406
  */
1405
1407
  function vectorScoreStages(threshold) {
1406
- const score = { $meta: "vectorSearchScore" };
1407
- if (threshold === void 0) return [{ $addFields: { [SCORE_FIELD]: score } }];
1408
- return [{ $addFields: {
1409
- _score: score,
1410
- [SCORE_FIELD]: score
1411
- } }, { $match: { _score: { $gte: threshold } } }];
1408
+ const stages = [{ $addFields: { [SCORE_FIELD]: { $meta: "vectorSearchScore" } } }];
1409
+ if (threshold !== void 0) stages.push({ $match: { [SCORE_FIELD]: { $gte: threshold } } });
1410
+ return stages;
1412
1411
  }
1413
1412
  /**
1414
1413
  * Field name `$geoNear` writes the computed distance into. Renamed to the
@@ -2609,8 +2608,8 @@ var MongoAdapter = class MongoAdapter extends _atscript_db.BaseDbAdapter {
2609
2608
  _hasExplicitId = false;
2610
2609
  /** Unique fields accumulated during onFieldScanned, returned via getMetadataOverrides. */
2611
2610
  _pendingUniqueFields = [];
2612
- /** {@link _patcherFlatMap}'s memo. */
2613
- _patcherFlatMapMemo;
2611
+ /** {@link _patcherMaps}' memo. */
2612
+ _patcherMapsMemo;
2614
2613
  constructor(db, client, options = {}) {
2615
2614
  super();
2616
2615
  this.db = db;
@@ -2926,7 +2925,7 @@ var MongoAdapter = class MongoAdapter extends _atscript_db.BaseDbAdapter {
2926
2925
  /** Returns the context object used by CollectionPatcher. */
2927
2926
  getPatcherContext() {
2928
2927
  return {
2929
- flatMap: this._patcherFlatMap(),
2928
+ ...this._patcherMaps(),
2930
2929
  prepareId: (id) => this.prepareIdFromIdType(id),
2931
2930
  createValidator: (opts) => this._table.createValidator(opts)
2932
2931
  };
@@ -2936,21 +2935,26 @@ var MongoAdapter = class MongoAdapter extends _atscript_db.BaseDbAdapter {
2936
2935
  * with `@db.column` names already applied (`translatePatchKeys`), so a
2937
2936
  * renamed union / `@db.json` field is found — and replaced, not merged —
2938
2937
  * under its stored name. Derived fields are left out (they map to their
2939
- * source's path). Built once per flat map.
2938
+ * source's path). The merge-strategy paths are keyed the same way. Built
2939
+ * once per flat map.
2940
2940
  */
2941
- _patcherFlatMap() {
2941
+ _patcherMaps() {
2942
2942
  const src = this._table.flatMap;
2943
- let memo = this._patcherFlatMapMemo;
2943
+ let memo = this._patcherMapsMemo;
2944
2944
  if (memo?.src !== src) {
2945
2945
  const meta = this._table.getMetadata();
2946
2946
  const map = /* @__PURE__ */ new Map();
2947
2947
  for (const [path, type] of src) if (!meta.derivedFields.has(path)) map.set(meta.documentPath(path), type);
2948
- memo = this._patcherFlatMapMemo = {
2948
+ const mergePaths = new Set([...meta.mergePaths].map((path) => meta.documentPath(path)));
2949
+ memo = this._patcherMapsMemo = {
2949
2950
  src,
2950
- map
2951
+ maps: {
2952
+ flatMap: map,
2953
+ mergePaths
2954
+ }
2951
2955
  };
2952
2956
  }
2953
- return memo.map;
2957
+ return memo.maps;
2954
2958
  }
2955
2959
  async nativePatch(filter, patch, ops, expectedVersion, opts) {
2956
2960
  const mongoFilter = await this._buildCasFilter(filter, expectedVersion, "nativePatch");
package/dist/index.d.cts CHANGED
@@ -11,6 +11,8 @@ import { AggregateFn, BucketUnit } from "@uniqu/core";
11
11
  */
12
12
  interface TCollectionPatcherContext {
13
13
  flatMap: Map<string, TAtscriptAnnotatedType>;
14
+ /** The document paths whose merge strategy applies (`TableMetadata.mergePaths`). */
15
+ mergePaths: ReadonlySet<string>;
14
16
  prepareId(id: any): any;
15
17
  createValidator(opts?: Partial<TValidatorOptions>): Validator<any>;
16
18
  }
@@ -94,9 +96,10 @@ declare class CollectionPatcher {
94
96
  */
95
97
  private flattenPayload;
96
98
  /**
97
- * Walk the schema's props for a replace-strategy nested object so omitted
98
- * optional children become explicit nulls (parity with SQL `column = NULL`).
99
- * Required-missing leaves are caught earlier by the strict validator.
99
+ * Walk the schema's props for a replace-strategy nested object (a `T | null`
100
+ * one included, `storedObjectType`) so omitted optional children become
101
+ * explicit nulls (parity with SQL `column = NULL`). Required-missing leaves
102
+ * are caught earlier by the strict validator.
100
103
  */
101
104
  private _flattenReplaceObject;
102
105
  /**
@@ -345,8 +348,8 @@ declare class MongoAdapter extends BaseDbAdapter {
345
348
  protected _hasExplicitId: boolean;
346
349
  /** Unique fields accumulated during onFieldScanned, returned via getMetadataOverrides. */
347
350
  private _pendingUniqueFields;
348
- /** {@link _patcherFlatMap}'s memo. */
349
- private _patcherFlatMapMemo?;
351
+ /** {@link _patcherMaps}' memo. */
352
+ private _patcherMapsMemo?;
350
353
  constructor(db: Db, client?: MongoClient | undefined, options?: TMongoAdapterOptions);
351
354
  private get _client();
352
355
  /** Every adapter over this client (or database handle) shares one session (since 0.1.128). */
@@ -514,9 +517,10 @@ declare class MongoAdapter extends BaseDbAdapter {
514
517
  * with `@db.column` names already applied (`translatePatchKeys`), so a
515
518
  * renamed union / `@db.json` field is found — and replaced, not merged —
516
519
  * under its stored name. Derived fields are left out (they map to their
517
- * source's path). Built once per flat map.
520
+ * source's path). The merge-strategy paths are keyed the same way. Built
521
+ * once per flat map.
518
522
  */
519
- private _patcherFlatMap;
523
+ private _patcherMaps;
520
524
  nativePatch(filter: FilterExpr, patch: unknown, ops?: TFieldOps, expectedVersion?: number, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
521
525
  /**
522
526
  * `updateMany` with array operators (since 0.1.182): the pipeline
package/dist/index.d.mts CHANGED
@@ -11,6 +11,8 @@ import { TAtscriptAnnotatedType, TMetadataMap, TValidatorOptions, TValidatorPlug
11
11
  */
12
12
  interface TCollectionPatcherContext {
13
13
  flatMap: Map<string, TAtscriptAnnotatedType>;
14
+ /** The document paths whose merge strategy applies (`TableMetadata.mergePaths`). */
15
+ mergePaths: ReadonlySet<string>;
14
16
  prepareId(id: any): any;
15
17
  createValidator(opts?: Partial<TValidatorOptions>): Validator<any>;
16
18
  }
@@ -94,9 +96,10 @@ declare class CollectionPatcher {
94
96
  */
95
97
  private flattenPayload;
96
98
  /**
97
- * Walk the schema's props for a replace-strategy nested object so omitted
98
- * optional children become explicit nulls (parity with SQL `column = NULL`).
99
- * Required-missing leaves are caught earlier by the strict validator.
99
+ * Walk the schema's props for a replace-strategy nested object (a `T | null`
100
+ * one included, `storedObjectType`) so omitted optional children become
101
+ * explicit nulls (parity with SQL `column = NULL`). Required-missing leaves
102
+ * are caught earlier by the strict validator.
100
103
  */
101
104
  private _flattenReplaceObject;
102
105
  /**
@@ -345,8 +348,8 @@ declare class MongoAdapter extends BaseDbAdapter {
345
348
  protected _hasExplicitId: boolean;
346
349
  /** Unique fields accumulated during onFieldScanned, returned via getMetadataOverrides. */
347
350
  private _pendingUniqueFields;
348
- /** {@link _patcherFlatMap}'s memo. */
349
- private _patcherFlatMapMemo?;
351
+ /** {@link _patcherMaps}' memo. */
352
+ private _patcherMapsMemo?;
350
353
  constructor(db: Db, client?: MongoClient | undefined, options?: TMongoAdapterOptions);
351
354
  private get _client();
352
355
  /** Every adapter over this client (or database handle) shares one session (since 0.1.128). */
@@ -514,9 +517,10 @@ declare class MongoAdapter extends BaseDbAdapter {
514
517
  * with `@db.column` names already applied (`translatePatchKeys`), so a
515
518
  * renamed union / `@db.json` field is found — and replaced, not merged —
516
519
  * under its stored name. Derived fields are left out (they map to their
517
- * source's path). Built once per flat map.
520
+ * source's path). The merge-strategy paths are keyed the same way. Built
521
+ * once per flat map.
518
522
  */
519
- private _patcherFlatMap;
523
+ private _patcherMaps;
520
524
  nativePatch(filter: FilterExpr, patch: unknown, ops?: TFieldOps, expectedVersion?: number, opts?: TDbUpdateOptions): Promise<TDbUpdateResult>;
521
525
  /**
522
526
  * `updateMany` with array operators (since 0.1.182): the pipeline
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as buildMongoQuery, c as planStages, f as sortStages, h as queryNodeToExpr, i as buildMongoFilter, l as correlate, m as orNull, n as distinctCountExpr, o as collationOfAdapter, p as exprToMongo, r as REL_FILTER_TEMP_PREFIX, s as mongoFilterStages, t as buildAccumulator, u as hasNullsPlacement } from "./mongo-accumulator-CFVRBDiw.mjs";
2
2
  import { t as dynamicSearchEncryptedMessage } from "./search-messages-mQSpJ4GD.mjs";
3
- import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, andFilters, bucketTimeZoneUnavailable, computeInsights, constraintViolation, containsRelationFilter, createChangeRecorder, createFailureCollector, defaultFulltextIndex, geoIndexNotFoundMessage, getDbFieldOp, getKeyProps, getPath, isAtscriptDbView, isFieldRef, isPlainObject, isViewType, parseDefaultLiteral, queryReadColumns, relationStaticFilter, resolveDesignType, searchIndexNotFoundMessage, searchTermInteger, tableNameOf, translateQueryTree, uniqueKeyTuple, unknownWithRelation, vectorIndexNotFoundMessage } from "@atscript/db";
3
+ import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, andFilters, bucketTimeZoneUnavailable, computeInsights, constraintViolation, containsRelationFilter, createChangeRecorder, createFailureCollector, defaultFulltextIndex, geoIndexNotFoundMessage, getDbFieldOp, getKeyProps, getPath, isAtscriptDbView, isFieldRef, isPlainObject, isViewType, parseDefaultLiteral, queryReadColumns, relationStaticFilter, resolveDesignType, searchIndexNotFoundMessage, searchTermInteger, storedObjectType, tableNameOf, translateQueryTree, uniqueKeyTuple, unknownWithRelation, vectorIndexNotFoundMessage } from "@atscript/db";
4
4
  import { MongoClient, ObjectId } from "mongodb";
5
5
  import { resolveAggregateSearch } from "@atscript/db/agg";
6
6
  //#region src/lib/path-utils.ts
@@ -384,20 +384,20 @@ var CollectionPatcher = class {
384
384
  const topLevelArray = flatType?.metadata?.get("db.__topLevelArray");
385
385
  const isObjectValue = typeof value === "object" && value !== null && !Array.isArray(value);
386
386
  if (isObjectValue && topLevelArray && !flatType?.metadata?.has("db.json")) this.parseArrayPatch(key, value, flatType);
387
- else if (isObjectValue && flatType?.metadata?.get("db.patch.strategy") === "merge") this.flattenPayload(value, key);
388
- else if (isObjectValue && flatType?.type.kind === "object" && !flatType.metadata?.has("db.json")) this._flattenReplaceObject(value, key, flatType);
387
+ else if (isObjectValue && this.collection.mergePaths.has(key)) this.flattenPayload(value, key);
388
+ else if (isObjectValue && storedObjectType(flatType) && !flatType.metadata?.has("db.json")) this._flattenReplaceObject(value, key, flatType);
389
389
  else if (key !== "_id") this._setLeaf(key, value, flatType);
390
390
  }
391
391
  return this.updatePipeline;
392
392
  }
393
393
  /**
394
- * Walk the schema's props for a replace-strategy nested object so omitted
395
- * optional children become explicit nulls (parity with SQL `column = NULL`).
396
- * Required-missing leaves are caught earlier by the strict validator.
394
+ * Walk the schema's props for a replace-strategy nested object (a `T | null`
395
+ * one included, `storedObjectType`) so omitted optional children become
396
+ * explicit nulls (parity with SQL `column = NULL`). Required-missing leaves
397
+ * are caught earlier by the strict validator.
397
398
  */
398
399
  _flattenReplaceObject(value, prefix, flatType) {
399
- const propsMap = flatType.type.props;
400
- for (const [propKey, propType] of propsMap) {
400
+ for (const [propKey, propType] of storedObjectType(flatType).type.props) {
401
401
  const childKey = `${prefix}.${propKey}`;
402
402
  const childValue = value[propKey];
403
403
  if (childValue === void 0) {
@@ -406,15 +406,17 @@ var CollectionPatcher = class {
406
406
  }
407
407
  const childIsObject = typeof childValue === "object" && childValue !== null && !Array.isArray(childValue);
408
408
  const propIsJson = propType.metadata?.has("db.json");
409
- const propIsMerge = propType.metadata?.get("db.patch.strategy") === "merge";
410
409
  const childFlatType = this.collection.flatMap.get(childKey);
411
410
  if (childIsObject && !propIsJson && childFlatType?.metadata?.get("db.__topLevelArray")) {
412
411
  this.parseArrayPatch(childKey, childValue, childFlatType);
413
412
  continue;
414
413
  }
415
- if (childIsObject && propType.type.kind === "object" && !propIsJson) {
416
- if (propIsMerge) this.flattenPayload(childValue, childKey);
417
- else this._flattenReplaceObject(childValue, childKey, propType);
414
+ if (childIsObject && this.collection.mergePaths.has(childKey)) {
415
+ this.flattenPayload(childValue, childKey);
416
+ continue;
417
+ }
418
+ if (childIsObject && storedObjectType(propType) && !propIsJson) {
419
+ this._flattenReplaceObject(childValue, childKey, propType);
418
420
  continue;
419
421
  }
420
422
  this._setLeaf(childKey, childValue, propType);
@@ -441,8 +443,8 @@ var CollectionPatcher = class {
441
443
  return;
442
444
  }
443
445
  this._remove(key, toRemove, keys, flatType);
444
- this._update(key, toUpdate, keys, flatType);
445
- this._upsert(key, toUpsert, keys, flatType);
446
+ this._update(key, toUpdate, keys);
447
+ this._upsert(key, toUpsert, keys);
446
448
  this._insert(key, toInsert, keys, flatType);
447
449
  }
448
450
  /**
@@ -544,13 +546,13 @@ var CollectionPatcher = class {
544
546
  * or append when none has it
545
547
  * - key-less → append unless an equal element is stored
546
548
  */
547
- _upsert(key, input, keys, flatType) {
549
+ _upsert(key, input, keys) {
548
550
  if (!input?.length) return;
549
551
  if (keys.length === 0) {
550
552
  this._appendAbsent(key, input);
551
553
  return;
552
554
  }
553
- const mergeStrategy = flatType.metadata?.get("db.patch.strategy") === "merge";
555
+ const mergeStrategy = this.collection.mergePaths.has(key);
554
556
  this._appendUnless(key, input, this._keyStored(keys), { $map: {
555
557
  input: "$$value",
556
558
  as: "el",
@@ -568,9 +570,9 @@ var CollectionPatcher = class {
568
570
  * 0.1.180, as on every other adapter; before, the items were added to
569
571
  * the array as a set union)
570
572
  */
571
- _update(key, input, keys, flatType) {
573
+ _update(key, input, keys) {
572
574
  if (!input?.length || keys.length === 0) return;
573
- const mergeStrategy = flatType.metadata?.get("db.patch.strategy") === "merge";
575
+ const mergeStrategy = this.collection.mergePaths.has(key);
574
576
  this._set(key, { $reduce: {
575
577
  input: literal(input),
576
578
  initialValue: { $ifNull: [`$${key}`, []] },
@@ -1399,15 +1401,12 @@ async function vectorSearchWithCountImpl(host, vector, query, indexName) {
1399
1401
  /**
1400
1402
  * The stages right after `$vectorSearch`: its score into {@link SCORE_FIELD}
1401
1403
  * (the `$meta` is read here, ahead of any `$facet`) and, with a threshold,
1402
- * into `_score` — kept for compatibility — with the `$match` on it.
1404
+ * the `$match` on it.
1403
1405
  */
1404
1406
  function vectorScoreStages(threshold) {
1405
- const score = { $meta: "vectorSearchScore" };
1406
- if (threshold === void 0) return [{ $addFields: { [SCORE_FIELD]: score } }];
1407
- return [{ $addFields: {
1408
- _score: score,
1409
- [SCORE_FIELD]: score
1410
- } }, { $match: { _score: { $gte: threshold } } }];
1407
+ const stages = [{ $addFields: { [SCORE_FIELD]: { $meta: "vectorSearchScore" } } }];
1408
+ if (threshold !== void 0) stages.push({ $match: { [SCORE_FIELD]: { $gte: threshold } } });
1409
+ return stages;
1411
1410
  }
1412
1411
  /**
1413
1412
  * Field name `$geoNear` writes the computed distance into. Renamed to the
@@ -2608,8 +2607,8 @@ var MongoAdapter = class MongoAdapter extends BaseDbAdapter {
2608
2607
  _hasExplicitId = false;
2609
2608
  /** Unique fields accumulated during onFieldScanned, returned via getMetadataOverrides. */
2610
2609
  _pendingUniqueFields = [];
2611
- /** {@link _patcherFlatMap}'s memo. */
2612
- _patcherFlatMapMemo;
2610
+ /** {@link _patcherMaps}' memo. */
2611
+ _patcherMapsMemo;
2613
2612
  constructor(db, client, options = {}) {
2614
2613
  super();
2615
2614
  this.db = db;
@@ -2925,7 +2924,7 @@ var MongoAdapter = class MongoAdapter extends BaseDbAdapter {
2925
2924
  /** Returns the context object used by CollectionPatcher. */
2926
2925
  getPatcherContext() {
2927
2926
  return {
2928
- flatMap: this._patcherFlatMap(),
2927
+ ...this._patcherMaps(),
2929
2928
  prepareId: (id) => this.prepareIdFromIdType(id),
2930
2929
  createValidator: (opts) => this._table.createValidator(opts)
2931
2930
  };
@@ -2935,21 +2934,26 @@ var MongoAdapter = class MongoAdapter extends BaseDbAdapter {
2935
2934
  * with `@db.column` names already applied (`translatePatchKeys`), so a
2936
2935
  * renamed union / `@db.json` field is found — and replaced, not merged —
2937
2936
  * under its stored name. Derived fields are left out (they map to their
2938
- * source's path). Built once per flat map.
2937
+ * source's path). The merge-strategy paths are keyed the same way. Built
2938
+ * once per flat map.
2939
2939
  */
2940
- _patcherFlatMap() {
2940
+ _patcherMaps() {
2941
2941
  const src = this._table.flatMap;
2942
- let memo = this._patcherFlatMapMemo;
2942
+ let memo = this._patcherMapsMemo;
2943
2943
  if (memo?.src !== src) {
2944
2944
  const meta = this._table.getMetadata();
2945
2945
  const map = /* @__PURE__ */ new Map();
2946
2946
  for (const [path, type] of src) if (!meta.derivedFields.has(path)) map.set(meta.documentPath(path), type);
2947
- memo = this._patcherFlatMapMemo = {
2947
+ const mergePaths = new Set([...meta.mergePaths].map((path) => meta.documentPath(path)));
2948
+ memo = this._patcherMapsMemo = {
2948
2949
  src,
2949
- map
2950
+ maps: {
2951
+ flatMap: map,
2952
+ mergePaths
2953
+ }
2950
2954
  };
2951
2955
  }
2952
- return memo.map;
2956
+ return memo.maps;
2953
2957
  }
2954
2958
  async nativePatch(filter, patch, ops, expectedVersion, opts) {
2955
2959
  const mongoFilter = await this._buildCasFilter(filter, expectedVersion, "nativePatch");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-mongo",
3
- "version": "0.1.183",
3
+ "version": "0.1.184",
4
4
  "description": "Mongodb plugin for atscript.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -58,7 +58,7 @@
58
58
  "@atscript/typescript": "^0.2.13",
59
59
  "@uniqu/core": "^0.2.2",
60
60
  "mongodb": "^6.17.0",
61
- "@atscript/db": "^0.1.183"
61
+ "@atscript/db": "^0.1.184"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "vp pack",