zod-nest 2.1.0 → 2.1.1

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.d.mts CHANGED
@@ -118,6 +118,15 @@ declare const registerSchema: (schema: z.ZodType, registry?: ZodNestRegistry, op
118
118
  interface LineageEntry {
119
119
  readonly op: 'extend';
120
120
  readonly parent: z.ZodObject;
121
+ /**
122
+ * Keys the child redeclared with a *different* schema than the parent's
123
+ * (e.g. narrowing `type: SomeEnum` to `type: z.literal('A')`). Computed by
124
+ * reference comparison at `extend()` time — Zod's `.extend()` keeps the same
125
+ * shape reference for untouched keys and assigns a fresh one for overrides.
126
+ * The composition override keeps these in the delta instead of dropping them
127
+ * as parent-owned, so the narrowing survives in the emitted `allOf`.
128
+ */
129
+ readonly overriddenKeys: ReadonlySet<string>;
121
130
  }
122
131
  /**
123
132
  * Wraps a derived `z.ZodObject` and records the parent → child link so
package/dist/index.d.ts CHANGED
@@ -118,6 +118,15 @@ declare const registerSchema: (schema: z.ZodType, registry?: ZodNestRegistry, op
118
118
  interface LineageEntry {
119
119
  readonly op: 'extend';
120
120
  readonly parent: z.ZodObject;
121
+ /**
122
+ * Keys the child redeclared with a *different* schema than the parent's
123
+ * (e.g. narrowing `type: SomeEnum` to `type: z.literal('A')`). Computed by
124
+ * reference comparison at `extend()` time — Zod's `.extend()` keeps the same
125
+ * shape reference for untouched keys and assigns a fresh one for overrides.
126
+ * The composition override keeps these in the delta instead of dropping them
127
+ * as parent-owned, so the narrowing survives in the emitted `allOf`.
128
+ */
129
+ readonly overriddenKeys: ReadonlySet<string>;
121
130
  }
122
131
  /**
123
132
  * Wraps a derived `z.ZodObject` and records the parent → child link so
package/dist/index.js CHANGED
@@ -246,11 +246,22 @@ var computeShapeKeys = /* @__PURE__ */ __name((schema) => {
246
246
  required
247
247
  };
248
248
  }, "computeShapeKeys");
249
+ var computeOverriddenKeys = /* @__PURE__ */ __name((parent, child) => {
250
+ const overriddenKeys = /* @__PURE__ */ new Set();
251
+ for (const key of Object.keys(child.shape)) {
252
+ const parentProp = parent.shape[key];
253
+ if (parentProp !== void 0 && parentProp !== child.shape[key]) {
254
+ overriddenKeys.add(key);
255
+ }
256
+ }
257
+ return overriddenKeys;
258
+ }, "computeOverriddenKeys");
249
259
  var extend = /* @__PURE__ */ __name((parent, build) => {
250
260
  const result = build(parent);
251
261
  lineageMap.set(result, {
252
262
  op: "extend",
253
- parent
263
+ parent,
264
+ overriddenKeys: computeOverriddenKeys(parent, result)
254
265
  });
255
266
  if (!propsMap.has(parent)) {
256
267
  propsMap.set(parent, computeShapeKeys(parent));
@@ -284,7 +295,7 @@ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
284
295
  const parentReqSet = new Set(parentCache.required);
285
296
  const deltaProps = {};
286
297
  for (const [key, value] of Object.entries(childProps)) {
287
- if (parentPropSet.has(key)) {
298
+ if (parentPropSet.has(key) && !entry.overriddenKeys.has(key)) {
288
299
  continue;
289
300
  }
290
301
  deltaProps[key] = value;