@yahoo/uds-create-config 5.100.1 → 5.100.3

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.
@@ -1,6 +1,6 @@
1
1
  import { MINTED, collectRefs, entityPathProblem, entityRefOf, isExtendedRef, isMintedRow, isRef, kindOf, memberOf, memberRef, pathOf, qualifyRefs, ref, rewriteRefNamespace, rewriteRefSource, rewriteRefs, routedSource, singletonRef, sourceHops, sourceOf, splitRef } from "./utils/refs.js";
2
2
  import { ConfigFormatError, ConfigRejection, isConfigRejection, issuePath, refusalIssues, reject, rejectData, rejectInvalid, rejectReferrers } from "./rejection.js";
3
- import { applyPathDelta, isPlainObject, namedFields, pathSegments, sectionDelta, touchedFields } from "./utils/field-path.js";
3
+ import { applyPathDelta, applyValidatedDelta, isPlainObject, namedFields, pathSegments, sectionDelta, touchedFields } from "./utils/field-path.js";
4
4
  import "./config-operation-kind.js";
5
5
  import { describePatch } from "./plan.js";
6
6
  import { METADATA_KEYS, declaredField } from "./utils/field-schema.js";
@@ -2244,10 +2244,35 @@ var Config = class Config {
2244
2244
  path: patch.path,
2245
2245
  data: { [topField]: body[topField] }
2246
2246
  }, mode);
2247
- const delta = {
2247
+ let delta = {
2248
2248
  ...extension.extend,
2249
2249
  [topField]: body[topField]
2250
2250
  };
2251
+ const sub = subEntityAt(entry, patch.field);
2252
+ if (patch.operation === "sub-update" && !sub?.singleton) {
2253
+ const members = collectionIn(body, patch);
2254
+ const member = members[patch.key];
2255
+ const renamed = member === void 0 && Object.keys(members).some((key) => !(key in collectionIn(inherited, patch)));
2256
+ const [outerField, innerField] = patch.field.split("/");
2257
+ const outer = extension.extend[outerField];
2258
+ const owner = isPlainObject(outer) ? outer[String(patch.owner)] : void 0;
2259
+ let own = outer;
2260
+ if (innerField) own = isPlainObject(owner) ? owner[innerField] : void 0;
2261
+ const localMembers = { ...isPlainObject(own) ? own : {} };
2262
+ const localMember = localMembers[patch.key];
2263
+ if (member === void 0) delete localMembers[patch.key];
2264
+ else {
2265
+ const next = isPlainObject(patch.data) && isPlainObject(member) && !isRef(member) ? applyValidatedDelta({
2266
+ local: isPlainObject(localMember) ? localMember : {},
2267
+ delta: patch.data,
2268
+ validated: member,
2269
+ isField: this.memberFields(entry, patch.field, inherited, patch.key)
2270
+ }) : member;
2271
+ if (sub?.vacant?.(next)) delete localMembers[patch.key];
2272
+ else localMembers[patch.key] = next;
2273
+ }
2274
+ if (!renamed) delta = storeCollection(extension.extend, patch, localMembers);
2275
+ }
2251
2276
  return changed.withChanges([extensionChange(entry, patch.kind, patch.path, {
2252
2277
  __ref: extension.__ref,
2253
2278
  extend: delta
@@ -2342,10 +2367,13 @@ var Config = class Config {
2342
2367
  extend: current.overlay,
2343
2368
  source: this.configFor(extension)
2344
2369
  }) : resolved.toJSON(), delta, isField);
2345
- const local = { ...current ? current.overlay : extension.extend };
2346
- for (const field of touched) if (Object.hasOwn(delta, field) && delta[field] === null) delete local[field];
2347
- else if (Object.hasOwn(written, field)) local[field] = written[field];
2348
- else delete local[field];
2370
+ const previous = current ? current.overlay : extension.extend;
2371
+ let local = applyValidatedDelta({
2372
+ local: previous,
2373
+ delta,
2374
+ validated: written,
2375
+ isField
2376
+ });
2349
2377
  const sourceBody = this.configFor(extension)?.resolve(patch.kind, pathOf(extension))?.toJSON();
2350
2378
  if (!sourceBody) reject("NOT_FOUND", `Cannot edit ${patch.kind} "${patch.path}" — its source "${extension.__ref}" is unavailable`);
2351
2379
  const candidate = this.at(snapshot).laidLinkedBody({
@@ -2363,7 +2391,17 @@ var Config = class Config {
2363
2391
  if (checked.success) merged = checked.data;
2364
2392
  }
2365
2393
  const normalized = this.normalizeMembers(entry, merged, { written: touched });
2366
- for (const field of touched) if (Object.hasOwn(local, field)) local[field] = normalized[field];
2394
+ local = applyValidatedDelta({
2395
+ local: previous,
2396
+ delta,
2397
+ validated: normalized,
2398
+ isField
2399
+ });
2400
+ for (const field of touched) {
2401
+ const before = merged[field];
2402
+ const after = normalized[field];
2403
+ if (isPlainObject(before) && isPlainObject(after) && Object.keys(before).some((key) => !(key in after))) local[field] = after;
2404
+ }
2367
2405
  if (isMintedRow(stored)) {
2368
2406
  const slug = sourceOf(extension);
2369
2407
  if (slug === void 0) reject("UNSUPPORTED", `Cannot edit ${patch.kind} "${patch.path}" — its minted body names no source`);
@@ -159,6 +159,23 @@ function applyPathDelta(current, delta, isField) {
159
159
  for (const [key, value] of Object.entries(delta)) out = setAtPath(out, pathSegments(key, isField), value);
160
160
  return out;
161
161
  }
162
+ /** Apply only addressed values from a validated body to a local extension. An indexed write owns
163
+ * the resulting array, since extension arrays replace rather than merge by index. */
164
+ function applyValidatedDelta({ local, delta, validated, isField }) {
165
+ let out = local;
166
+ for (const [key, value] of Object.entries(delta)) {
167
+ const segments = pathSegments(key, isField);
168
+ let at = validated;
169
+ let depth = 0;
170
+ while (depth < segments.length && !Array.isArray(at)) {
171
+ at = isPlainObject(at) ? at[segments[depth]] : void 0;
172
+ depth++;
173
+ }
174
+ const indexed = depth < segments.length;
175
+ out = setAtPath(out, segments.slice(0, depth), value === null && !indexed ? null : at ?? null);
176
+ }
177
+ return out;
178
+ }
162
179
  /**
163
180
  * The inverse of {@link applyPathDelta}: the path-keyed delta that turns `existing` into `desired`,
164
181
  * over `fields` — one entry per changed member (`null` removes), nothing restated. This is what
@@ -201,4 +218,4 @@ function touchedFields(delta, isField) {
201
218
  return new Set(Object.keys(delta).map((key) => pathSegments(key, isField)[0]));
202
219
  }
203
220
  //#endregion
204
- export { applyPathDelta, isPlainObject, namedFields, pathDelta, pathSegments, sectionDelta, setAtPath, touchedFields };
221
+ export { applyPathDelta, applyValidatedDelta, isPlainObject, namedFields, pathDelta, pathSegments, sectionDelta, setAtPath, touchedFields };