@lossless.org/client 1.23.1 → 1.23.2

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.
@@ -1956,7 +1956,7 @@ export class SmartdataExactCollection<
1956
1956
  // the write-revision partition it held is read first.
1957
1957
  const previousPartitionsRead = current._smartdataRevision === undefined
1958
1958
  && await readPreviousWriteRevisions(
1959
- this.collection.smartdataDb, this.collection.mongoDbCollection, sessionArg, selector, deadlineArg,
1959
+ this.collection, sessionArg, selector, deadlineArg,
1960
1960
  );
1961
1961
  const reportTransition = (): void => {
1962
1962
  reportSmartdataCollectionWrite(
@@ -2064,7 +2064,7 @@ export class SmartdataExactCollection<
2064
2064
  };
2065
2065
  const previousPartitionsRead = current._smartdataRevision === undefined
2066
2066
  && await readPreviousWriteRevisions(
2067
- this.collection.smartdataDb, this.collection.mongoDbCollection, sessionArg, selector, deadlineArg,
2067
+ this.collection, sessionArg, selector, deadlineArg,
2068
2068
  );
2069
2069
  let result: plugins.mongodb.DeleteResult;
2070
2070
  const deleteOptions = { session: sessionArg, ...deadlineArg.commandOptions() };
@@ -1162,6 +1162,16 @@ export const captureSmartdataCollectionChange = (
1162
1162
  return () => applyChanges(dbArg, collectionArg, [{ kind: 'unknown', touched: 'all', startedAt: 0 }]);
1163
1163
  };
1164
1164
 
1165
+ /**
1166
+ * @internal Whether an update by operators leaves a field as each document it
1167
+ * updates held it: no operator names the field or a path through it. An update
1168
+ * the tracker cannot follow may change any field.
1169
+ */
1170
+ export const updateLeavesField = (updateArg: unknown, fieldArg: string): boolean => {
1171
+ const { touched } = analyzeUpdate(updateArg, false);
1172
+ return touched !== 'all' && ![...touched].some((pathArg) => pathsOverlap(pathArg, fieldArg));
1173
+ };
1174
+
1165
1175
  /**
1166
1176
  * @internal The write-revision counters one acknowledged write bumps: the
1167
1177
  * partition of each document state it names before and after, and the shared
@@ -1067,19 +1067,26 @@ const bumpTransactionRevisions = (
1067
1067
  * documents a write by selector is about to change, and returns whether it
1068
1068
  * did; the write's report then states `previousPartitionsRead`. `false` when
1069
1069
  * the database keeps no revisions or the write runs outside an owned
1070
- * transaction.
1070
+ * transaction. `false` without a read, too, when the collection's model
1071
+ * persists no partition field: its documents count on the shared counter,
1072
+ * which the write's report bumps for each document state it cannot place, and
1073
+ * every read of the collection depends on that counter.
1071
1074
  */
1072
1075
  export const readPreviousWriteRevisions = async (
1073
- ownerArg: SmartdataDb,
1074
- collectionArg: plugins.mongodb.Collection<any>,
1076
+ collectionArg: SmartdataCollection<any>,
1075
1077
  rawSessionArg: plugins.mongodb.ClientSession | undefined,
1076
1078
  selectorArg: unknown,
1077
1079
  deadlineArg: SmartdataOperationDeadline,
1078
1080
  ): Promise<boolean> => {
1079
- if (!rawSessionArg || !isSmartdataWriteRevisionsActive(ownerArg)) return false;
1081
+ const owner = collectionArg.smartdataDb;
1082
+ if (!rawSessionArg || !isSmartdataWriteRevisionsActive(owner)) return false;
1080
1083
  const binding = bindingsByRawSession.get(rawSessionArg);
1081
- if (!binding?.transactionActive || binding.owner !== ownerArg) return false;
1082
- const ids = await readPreviousRevisionIds(ownerArg, collectionArg, rawSessionArg, selectorArg, deadlineArg);
1084
+ if (!binding?.transactionActive || binding.owner !== owner) return false;
1085
+ const persistedFields = collectionArg.getBoundModelSchema()?.persistedFields;
1086
+ if (persistedFields && !persistedFields.includes(writeRevisionsPartitionField(owner)!)) return false;
1087
+ const ids = await readPreviousRevisionIds(
1088
+ owner, collectionArg.mongoDbCollection, rawSessionArg, selectorArg, deadlineArg,
1089
+ );
1083
1090
  bumpTransactionRevisions(binding, ids);
1084
1091
  return true;
1085
1092
  };