@openclaw/imessage 2026.10.10-beta.5 → 2026.11.5-beta.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.
Files changed (142) hide show
  1. package/dist/.setup/{accounts-DacCvDBt.mjs → accounts-C1Ypv3Wn.mjs} +9 -13
  2. package/dist/.setup/{actions-762Azi-J.mjs → actions-qOuKy8To.mjs} +364 -116
  3. package/dist/.setup/{actions.runtime-DHiRiPHe.mjs → actions.runtime-Ccg9CARL.mjs} +12 -61
  4. package/dist/.setup/{api-Deyo8NDs.mjs → api-BXXuQQCS.mjs} +8 -9
  5. package/dist/.setup/{api-BFGXDHiC.mjs → api-DTbxSOPc.mjs} +9 -9
  6. package/dist/.setup/{approval-handler.runtime-fsSBf2jf.mjs → approval-handler.runtime-B6vrFfZx.mjs} +113 -133
  7. package/dist/.setup/{approval-reactions-CoAkCiwf.mjs → approval-reactions-DBBsqbRC.mjs} +156 -79
  8. package/dist/.setup/{channel-C61YdcZR.mjs → channel-CLaN4mQn.mjs} +151 -137
  9. package/dist/.setup/{channel.runtime-B5jle0g3.mjs → channel.runtime-XJGx1MIH.mjs} +236 -425
  10. package/dist/.setup/chat-context-fTfJVqAi.mjs +77 -0
  11. package/dist/.setup/chat-lookup-xtPsOBkl.mjs +50 -0
  12. package/dist/.setup/client-D_BaG8sC.mjs +367 -0
  13. package/dist/.setup/{config-schema-DXwa_3V5.mjs → config-schema-BjkQV5P5.mjs} +1 -4
  14. package/dist/.setup/{conversation-bindings-DR-dbHjs.mjs → conversation-bindings-8DjxoIYU.mjs} +10 -8
  15. package/dist/.setup/{media-contract-BwWs5PM7.mjs → media-contract-BErFBKV9.mjs} +2 -3
  16. package/dist/.setup/{message-tool-api-B5NfPnFL.mjs → message-tool-api-DtZ1wKbT.mjs} +6 -12
  17. package/dist/.setup/{outbound-send-deps-B-QEsLSM.mjs → outbound-send-deps-_da8jqeo.mjs} +1 -2
  18. package/dist/.setup/{remote-file-B94a787O.mjs → remote-file-DpK3GQFD.mjs} +12 -30
  19. package/dist/.setup/{rolldown-runtime-BBjsoOtd.mjs → rolldown-runtime-782esTHO.mjs} +1 -2
  20. package/dist/.setup/{sanitize-outbound-BtEY324R.mjs → sanitize-outbound-Dhjhz0a-.mjs} +25 -31
  21. package/dist/.setup/{send-BvxKNWzF.mjs → send-DhEW0gfe.mjs} +155 -236
  22. package/dist/.setup/{setup-core-BHyLkAEJ.mjs → setup-core-B1_P_t4T.mjs} +3 -4
  23. package/dist/.setup/{setup-surface-DPqiLGy0.mjs → setup-surface-CD28mXWK.mjs} +13 -29
  24. package/dist/.setup/{targets-B4oU7n-v.mjs → targets-C7CIWJ0k.mjs} +15 -9
  25. package/dist/.source-module-urls/929c518fa2986b0f85f66bceefead22868db0ab452dee914dc6a2bb86b2e60ad.json +1 -1
  26. package/dist/api.js +9 -9
  27. package/dist/channel-config-api.js +1 -1
  28. package/dist/channel-plugin-api.js +1 -1
  29. package/dist/contract-api.js +1 -1
  30. package/dist/doctor-contract-api.js +7 -13
  31. package/dist/index.js +1 -2
  32. package/dist/media-contract-api.js +1 -1
  33. package/dist/message-tool-api.js +1 -1
  34. package/dist/runtime-api.js +1 -3
  35. package/dist/secret-contract-api.js +1 -2
  36. package/dist/session-binding-contract-api.js +1 -1
  37. package/dist/setup-entry.js +2 -3
  38. package/dist/src/chat-db.worker.js +2 -3
  39. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  40. package/node_modules/typebox/build/format/duration.mjs +2 -2
  41. package/node_modules/typebox/build/format/idn_email.d.mts +1 -0
  42. package/node_modules/typebox/build/format/idn_email.mjs +1 -0
  43. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  44. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  45. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  46. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  47. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  48. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  49. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  50. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  51. package/node_modules/typebox/build/schema/build.mjs +1 -0
  52. package/node_modules/typebox/build/schema/engine/_unique.d.mts +4 -2
  53. package/node_modules/typebox/build/schema/engine/_unique.mjs +7 -3
  54. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  55. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +0 -3
  56. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +15 -17
  57. package/node_modules/typebox/build/schema/engine/contains.mjs +3 -3
  58. package/node_modules/typebox/build/schema/engine/index.d.mts +1 -0
  59. package/node_modules/typebox/build/schema/engine/index.mjs +1 -0
  60. package/node_modules/typebox/build/schema/engine/items.mjs +7 -4
  61. package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -2
  62. package/node_modules/typebox/build/schema/engine/minContains.mjs +3 -3
  63. package/node_modules/typebox/build/schema/engine/oneOf.mjs +2 -2
  64. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +2 -2
  65. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +2 -2
  66. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +2 -2
  67. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +2 -2
  68. package/node_modules/typebox/build/system/hashing/hash.mjs +63 -34
  69. package/node_modules/typebox/build/system/locale/en_US.mjs +2 -1
  70. package/node_modules/typebox/build/system/memory/assign.d.mts +2 -8
  71. package/node_modules/typebox/build/system/memory/assign.mjs +13 -6
  72. package/node_modules/typebox/build/system/memory/clone.d.mts +4 -5
  73. package/node_modules/typebox/build/system/memory/clone.mjs +8 -96
  74. package/node_modules/typebox/build/system/memory/create.d.mts +1 -5
  75. package/node_modules/typebox/build/system/memory/create.mjs +18 -13
  76. package/node_modules/typebox/build/system/memory/deep.d.mts +2 -0
  77. package/node_modules/typebox/build/system/memory/deep.mjs +108 -0
  78. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  79. package/node_modules/typebox/build/system/memory/discard.mjs +9 -8
  80. package/node_modules/typebox/build/system/memory/finalize.d.mts +4 -0
  81. package/node_modules/typebox/build/system/memory/finalize.mjs +30 -0
  82. package/node_modules/typebox/build/system/memory/keys.d.mts +2 -0
  83. package/node_modules/typebox/build/system/memory/keys.mjs +8 -0
  84. package/node_modules/typebox/build/system/memory/update.d.mts +1 -4
  85. package/node_modules/typebox/build/system/memory/update.mjs +43 -16
  86. package/node_modules/typebox/build/type/engine/call/index.d.mts +1 -0
  87. package/node_modules/typebox/build/type/engine/call/index.mjs +1 -0
  88. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +2 -24
  89. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +2 -29
  90. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +1 -0
  91. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +1 -0
  92. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +5 -1
  93. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +6 -1
  94. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +30 -0
  95. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +29 -0
  96. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +1 -3
  97. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +1 -4
  98. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  99. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  100. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  101. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  102. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +1 -3
  103. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +1 -4
  104. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +1 -3
  105. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +1 -4
  106. package/node_modules/typebox/build/type/engine/this/index.d.mts +1 -0
  107. package/node_modules/typebox/build/type/engine/this/index.mjs +1 -0
  108. package/node_modules/typebox/build/value/clone/clone.d.mts +4 -3
  109. package/node_modules/typebox/build/value/clone/clone.mjs +5 -7
  110. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +2 -0
  111. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +6 -0
  112. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +25 -14
  113. package/node_modules/typebox/package.json +1 -1
  114. package/node_modules/typebox/readme.md +1 -1
  115. package/node_modules/zod/package.json +1 -1
  116. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  117. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  118. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  119. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  120. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  121. package/node_modules/zod/src/v4/core/util.ts +13 -0
  122. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  123. package/node_modules/zod/v4/core/compile.cjs +8 -0
  124. package/node_modules/zod/v4/core/compile.js +8 -0
  125. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  126. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  127. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  128. package/node_modules/zod/v4/core/schemas.js +30 -0
  129. package/node_modules/zod/v4/core/util.cjs +15 -0
  130. package/node_modules/zod/v4/core/util.d.cts +2 -0
  131. package/node_modules/zod/v4/core/util.d.ts +2 -0
  132. package/node_modules/zod/v4/core/util.js +14 -0
  133. package/node_modules/zod/v4/core/versions.cjs +1 -1
  134. package/node_modules/zod/v4/core/versions.js +1 -1
  135. package/openclaw.plugin.json +0 -30
  136. package/package.json +6 -6
  137. package/dist/.setup/client-CcROCvRq.mjs +0 -746
  138. package/dist/.setup/question-reactions-BD06B1Lx.mjs +0 -68
  139. package/dist/.setup/reaction-context-Q26DYzQH.mjs +0 -106
  140. package/dist/.setup/runtime-Cza4CY5T.mjs +0 -8
  141. package/node_modules/typebox/build/system/memory/freeze.d.mts +0 -4
  142. package/node_modules/typebox/build/system/memory/freeze.mjs +0 -6
@@ -2,9 +2,7 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
2
  import { type TProperties } from '../../types/properties.mjs';
3
3
  import { type TOptional } from '../../types/_optional.mjs';
4
4
  import { type TState, type TInstantiateType } from '../instantiate.mjs';
5
- type TAddOptionalOperation<Type extends TSchema, Result extends TSchema = `~optional` extends keyof Type ? Type : TOptional<Type>> = Result;
6
- export type TAddOptionalAction<Type extends TSchema, Result extends TSchema = TAddOptionalOperation<Type>> = Result;
5
+ export type TAddOptionalAction<Type extends TSchema, Result extends TSchema = '~optional' extends keyof Type ? Type : TOptional<Type>> = Result;
7
6
  export declare function AddOptionalAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddOptionalAction<Type>;
8
7
  export type TAddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddOptionalAction<InstantiateType>;
9
8
  export declare function AddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddOptionalInstantiate<Context, State, Type>;
10
- export {};
@@ -1,11 +1,8 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Memory } from '../../../system/memory/index.mjs';
3
3
  import { InstantiateType } from '../instantiate.mjs';
4
- function AddOptionalOperation(type) {
5
- return Memory.Update(type, { '~optional': true }, {});
6
- }
7
4
  export function AddOptionalAction(type, options) {
8
- const result = Memory.Update(AddOptionalOperation(type), {}, options);
5
+ const result = Memory.Update(type, { '~optional': true }, options);
9
6
  return result;
10
7
  }
11
8
  export function AddOptionalInstantiate(context, state, type, options) {
@@ -2,9 +2,7 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
2
2
  import { type TProperties } from '../../types/properties.mjs';
3
3
  import { type TReadonly } from '../../types/_readonly.mjs';
4
4
  import { type TState, type TInstantiateType } from '../instantiate.mjs';
5
- type TAddReadonlyOperation<Type extends TSchema, Result extends TSchema = `~readonly` extends keyof Type ? Type : TReadonly<Type>> = Result;
6
- export type TAddReadonlyAction<Type extends TSchema, Result extends TSchema = TAddReadonlyOperation<Type>> = Result;
5
+ export type TAddReadonlyAction<Type extends TSchema, Result extends TSchema = '~readonly' extends keyof Type ? Type : TReadonly<Type>> = Result;
7
6
  export declare function AddReadonlyAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddReadonlyAction<Type>;
8
7
  export type TAddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddReadonlyAction<InstantiateType>;
9
8
  export declare function AddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddReadonlyInstantiate<Context, State, Type>;
10
- export {};
@@ -1,11 +1,8 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Memory } from '../../../system/memory/index.mjs';
3
3
  import { InstantiateType } from '../instantiate.mjs';
4
- function AddReadonlyOperation(type) {
5
- return Memory.Update(type, { '~readonly': true }, {});
6
- }
7
4
  export function AddReadonlyAction(type, options) {
8
- const result = Memory.Update(AddReadonlyOperation(type), {}, options);
5
+ const result = Memory.Update(type, { '~readonly': true }, options);
9
6
  return result;
10
7
  }
11
8
  export function AddReadonlyInstantiate(context, state, type, options) {
@@ -0,0 +1 @@
1
+ export * from './expand_this.mjs';
@@ -0,0 +1 @@
1
+ export * from './expand_this.mjs';
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Returns a Clone of the given value. This function is similar to structuredClone()
3
- * but also supports deep cloning instances of Map, Set and TypeArray.
2
+ * Returns a deep Clone of the given value. This function is similar to `structuredClone()`,
3
+ * but also supports deep cloning `Map`, `Set`, and `TypeArray` instances. This function can also be used
4
+ * to clone TypeBox types while retaining their enumerable and non-enumerable properties.
4
5
  */
5
- export declare function Clone<Value extends unknown>(value: Value): Value;
6
+ export declare function Clone<Value extends unknown = unknown>(value: Value): Value;
@@ -1,12 +1,10 @@
1
1
  // deno-fmt-ignore-file
2
- import { Clone as SystemClone } from '../../system/memory/clone.mjs';
3
- // ------------------------------------------------------------------
4
- // Clone
5
- // ------------------------------------------------------------------
2
+ import { Deep } from '../../system/memory/deep.mjs';
6
3
  /**
7
- * Returns a Clone of the given value. This function is similar to structuredClone()
8
- * but also supports deep cloning instances of Map, Set and TypeArray.
4
+ * Returns a deep Clone of the given value. This function is similar to `structuredClone()`,
5
+ * but also supports deep cloning `Map`, `Set`, and `TypeArray` instances. This function can also be used
6
+ * to clone TypeBox types while retaining their enumerable and non-enumerable properties.
9
7
  */
10
8
  export function Clone(value) {
11
- return SystemClone(value);
9
+ return Deep(value);
12
10
  }
@@ -0,0 +1,2 @@
1
+ import { type TProperties, type TCyclic } from '../../type/index.mjs';
2
+ export declare function FromCyclic(context: TProperties, type: TCyclic, value: unknown): unknown;
@@ -0,0 +1,6 @@
1
+ // deno-fmt-ignore-file
2
+ import { Ref } from '../../type/index.mjs';
3
+ import { FromType } from './from_type.mjs';
4
+ export function FromCyclic(context, type, value) {
5
+ return FromType({ ...context, ...type.$defs }, Ref(type.$ref), value);
6
+ }
@@ -1,28 +1,27 @@
1
1
  // deno-fmt-ignore-file
2
2
  import Guard from '../../guard/index.mjs';
3
- import { IsArray, Array as _Array_, ArrayOptions } from '../../type/index.mjs';
4
- import { IsUnion, Union } from '../../type/index.mjs';
3
+ import { Memory } from '../../system/memory/index.mjs';
4
+ import { Array as _Array_, ArrayOptions, IsArray } from '../../type/index.mjs';
5
+ import { Intersect, IsIntersect } from '../../type/index.mjs';
5
6
  import { IsObject, Object as _Object_ } from '../../type/index.mjs';
6
- import { IsRecord, Record, RecordKey, RecordValue } from '../../type/index.mjs';
7
+ import { IsRecord, Record, RecordPattern, RecordValue } from '../../type/index.mjs';
8
+ import { String } from '../../type/index.mjs';
7
9
  import { IsTuple, Tuple } from '../../type/index.mjs';
8
- import { IsIntersect, Intersect } from '../../type/index.mjs';
10
+ import { IsUnion, Union } from '../../type/index.mjs';
9
11
  import { Priority } from '../../type/index.mjs';
10
12
  // ------------------------------------------------------------------
11
13
  // Modifiers (Mutable)
12
14
  //
13
15
  // Prioritized types lose `~modifier` properties and additional constraints
14
16
  // (e.g. additionalProperties) during the mapping phase and need to be
15
- // reassigned afterward. This is a fast mutable assignment to handle that,
16
- // but we should consider a more general solution. (review)
17
+ // reassigned afterward. We previously used a mutable assignment on this
18
+ // function, however `immutableTypes: true` caused errors. We use the
19
+ // Memory.Assign to ensure modifiers are retained and we preserve type
20
+ // configurations (review)
17
21
  //
18
22
  // ------------------------------------------------------------------
19
23
  function Modifiers(type, next) {
20
- for (const key of Guard.Keys(type)) {
21
- if (Guard.HasPropertyKey(next, key))
22
- continue;
23
- next[key] = type[key];
24
- }
25
- return next;
24
+ return Memory.Assign(type, next);
26
25
  }
27
26
  // ------------------------------------------------------------------
28
27
  // Properties
@@ -34,6 +33,18 @@ function FromProperties(properties) {
34
33
  return result;
35
34
  }
36
35
  // ------------------------------------------------------------------
36
+ // FromRecordKey
37
+ //
38
+ // This is required because RecordKey(...) returns a canonical
39
+ // decoded type derived from the pattern. When the pattern is an
40
+ // unrecognized user-defined one, the result falls through to
41
+ // TString (^.*$) and the user-defined pattern is lost. This
42
+ // function ensures the exact pattern is retained.
43
+ // ------------------------------------------------------------------
44
+ function FromRecordKey(type) {
45
+ return String({ pattern: RecordPattern(type) });
46
+ }
47
+ // ------------------------------------------------------------------
37
48
  // PriorityTypes
38
49
  // ------------------------------------------------------------------
39
50
  function FromPriorityTypes(types) {
@@ -43,7 +54,7 @@ function FromPriorityTypes(types) {
43
54
  // Types
44
55
  // ------------------------------------------------------------------
45
56
  function FromTypes(types) {
46
- return types.map(type => FromType(type));
57
+ return types.map((type) => FromType(type));
47
58
  }
48
59
  // ------------------------------------------------------------------
49
60
  // Type
@@ -53,7 +64,7 @@ function FromType(type) {
53
64
  IsIntersect(type) ? Intersect(FromTypes(type.allOf)) :
54
65
  IsUnion(type) ? Union(FromPriorityTypes(type.anyOf)) :
55
66
  IsObject(type) ? _Object_(FromProperties(type.properties)) :
56
- IsRecord(type) ? Record(RecordKey(type), FromType(RecordValue(type))) :
67
+ IsRecord(type) ? Record(FromRecordKey(type), FromType(RecordValue(type))) :
57
68
  IsTuple(type) ? Tuple(FromTypes(type.items)) :
58
69
  type);
59
70
  return Modifiers(type, next);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.3.35",
4
+ "version": "1.4.2",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
@@ -196,7 +196,7 @@ const result = Vector.Parse({ x: 1, y: 0, z: 0 }) // const result: {
196
196
 
197
197
  [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite) | [JSON Schema Compliance Suite](https://github.com/sinclairzx81/json-schema-compliance-suite)
198
198
 
199
- TypeBox supports all versions of JSON Schema and is heavily tested against the official JSON Schema Test Suite. It prioritizes compatibility with modern specifications while also maintaining broad support for legacy versions provided their semantics are not in conflict with modern specifications.
199
+ TypeBox supports all versions of JSON Schema and is heavily tested against the official JSON Schema Test Suite. It has high compatibility with modern specifications while also offering broad support for legacy versions if their semantics are not in conflict with modern specifications.
200
200
 
201
201
  | Spec | 3 | 4 | 6 | 7 | 2019-09 | 2020-12 | v1 |
202
202
  |:-----|:--|:--|:--|:--|:--|:--|:--|
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.6.5",
3
+ "version": "4.6.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -140,6 +140,33 @@ test("continue parsing despite array size error", () => {
140
140
  `);
141
141
  });
142
142
 
143
+ test("an upper size bound fails before any element is parsed", () => {
144
+ let parsed = 0;
145
+ const el = z.string().refine(() => ++parsed);
146
+ let refined = 0;
147
+ const schema = z
148
+ .array(el)
149
+ .max(2, "too many")
150
+ .refine(() => ++refined);
151
+ expect(schema.safeParse([1, 2, 3]).error!.issues).toMatchObject([{ code: "too_big", path: [], message: "too many" }]);
152
+ expect(z.array(el).length(2).safeParse(["a", "b", "c"]).error!.issues).toMatchObject([
153
+ { code: "too_big", exact: true },
154
+ ]);
155
+ expect(z.object({ a: z.array(el).max(1) }).safeParse({ a: [1, 2] }).error!.issues).toMatchObject([
156
+ { code: "too_big", path: ["a"] },
157
+ ]);
158
+ expect([parsed, refined]).toEqual([0, 0]);
159
+
160
+ // a check that may rewrite the value ends the gate
161
+ expect(
162
+ z
163
+ .array(z.number())
164
+ .overwrite((a) => a.slice(0, 2))
165
+ .max(2)
166
+ .parse([1, 2, 3])
167
+ ).toEqual([1, 2]);
168
+ });
169
+
143
170
  test("parse should fail given sparse array", () => {
144
171
  const schema = z.array(z.string()).nonempty().min(1).max(3);
145
172
  const result = schema.safeParse(new Array(3));
@@ -97,6 +97,13 @@ test("failing when map is bigger than max() ", () => {
97
97
  expect(result.success).toEqual(false);
98
98
  expect(result.error!.issues.length).toEqual(1);
99
99
  expect(result.error!.issues[0].code).toEqual("too_big");
100
+ const bad = new Map([
101
+ [1, 1],
102
+ [2, 2],
103
+ ]);
104
+ const capped = z.map(z.string(), z.string()).max(1);
105
+ expect(capped.safeParse(bad).error!.issues).toMatchObject([{ code: "too_big" }]);
106
+ expect(capped.safeParse(new Set([1, 2])).error!.issues[0]).toMatchObject({ code: "invalid_type", expected: "map" });
100
107
  });
101
108
 
102
109
  test("failing when map does not match size() ", () => {
@@ -83,6 +83,12 @@ test("failing when set is bigger than max() ", () => {
83
83
  expect(result.success).toEqual(false);
84
84
  expect(result.error!.issues.length).toEqual(1);
85
85
  expect(result.error!.issues[0].code).toEqual("too_big");
86
+ expect(
87
+ z
88
+ .set(z.string())
89
+ .max(1)
90
+ .safeParse(new Set([1, 2])).error!.issues
91
+ ).toMatchObject([{ code: "too_big" }]);
86
92
  });
87
93
 
88
94
  test("failing when set does not match size() ", () => {
@@ -1551,6 +1551,12 @@ function generateNullableCheck(
1551
1551
  return outputVar;
1552
1552
  }
1553
1553
 
1554
+ function generateSizeGate(doc: Doc, schema: SomeType, size: string): void {
1555
+ for (const [max, check] of util.sizeCaps(schema._zod.def.checks)) {
1556
+ doc.write(`if (${size} > ${numericOperand(max, check._zod.def.check)}) return INVALID;`);
1557
+ }
1558
+ }
1559
+
1554
1560
  function generateArrayCheck(
1555
1561
  doc: Doc,
1556
1562
  ctx: CompileContext,
@@ -1560,6 +1566,7 @@ function generateArrayCheck(
1560
1566
  ): string | null {
1561
1567
  const def = schema._zod.def as unknown as { element: SomeType };
1562
1568
  doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
1569
+ generateSizeGate(doc, schema, `${accessor}.length`);
1563
1570
 
1564
1571
  // Build a new array with validated/transformed elements.
1565
1572
  const outputVar = buildsValue ? newVar(ctx) : null;
@@ -2094,6 +2101,7 @@ function generateMapCheck(doc: Doc, ctx: CompileContext, schema: SomeType, acces
2094
2101
  const def = schema._zod.def as unknown as { keyType: SomeType; valueType: SomeType };
2095
2102
 
2096
2103
  doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
2104
+ generateSizeGate(doc, schema, `${accessor}.size`);
2097
2105
 
2098
2106
  const outputVar = newVar(ctx);
2099
2107
  const kVar = newVar(ctx);
@@ -2115,6 +2123,7 @@ function generateSetCheck(doc: Doc, ctx: CompileContext, schema: SomeType, acces
2115
2123
  const def = schema._zod.def as unknown as { valueType: SomeType };
2116
2124
 
2117
2125
  doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
2126
+ generateSizeGate(doc, schema, `${accessor}.size`);
2118
2127
 
2119
2128
  const outputVar = newVar(ctx);
2120
2129
  const valVar = newVar(ctx);
@@ -1844,6 +1844,34 @@ export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$Zod
1844
1844
 
1845
1845
  export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {}
1846
1846
 
1847
+ // an oversized container fails its leading size checks before any element is parsed
1848
+ function capSize(inst: $ZodType, size: (input: any) => number): void {
1849
+ const caps = util.sizeCaps(inst._zod.def.checks);
1850
+ if (!caps.length) return;
1851
+ const cap = Math.min(...caps.map((c) => c[0]));
1852
+ const parse = inst._zod.parse;
1853
+ inst._zod.parse = (payload, ctx) => {
1854
+ const n = size(payload.value);
1855
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
1856
+ for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
1857
+ if (n > max && ch._zod.def.when!(payload)) {
1858
+ const start = payload.issues.length;
1859
+ ch._zod.check(payload as ParsePayload<never>);
1860
+ // the value is still the raw input, so no later check may read it
1861
+ (payload.issues[start] as { continue?: boolean }).continue = false;
1862
+ util.attachSchema(payload.issues, start, inst);
1863
+ return payload;
1864
+ }
1865
+ }
1866
+ }
1867
+ return parse(payload, ctx);
1868
+ };
1869
+ }
1870
+
1871
+ const arraySize = (input: unknown): number => (Array.isArray(input) ? input.length : -1);
1872
+ const mapSize = (input: unknown): number => (input instanceof Map ? input.size : -1);
1873
+ const setSize = (input: unknown): number => (input instanceof Set ? input.size : -1);
1874
+
1847
1875
  function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>, index: number) {
1848
1876
  if (result.issues.length) {
1849
1877
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -1899,6 +1927,7 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1899
1927
 
1900
1928
  return payload; //handleArrayResultsAsync(parseResults, final);
1901
1929
  };
1930
+ capSize(inst, arraySize);
1902
1931
  });
1903
1932
 
1904
1933
  //////////////////////////////////////////
@@ -3218,8 +3247,11 @@ export type $InferZodRecordInput<
3218
3247
  : Record<core.input<Key> & PropertyKey, core.input<Value>>;
3219
3248
 
3220
3249
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
3221
- extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
3250
+ extends $ZodTypeInternals {
3222
3251
  def: $ZodRecordDef<Key, Value>;
3252
+ // members rather than base type arguments, which TypeScript 7.1 reports as circular for `z.json()`
3253
+ output: $InferZodRecordOutput<Key, Value>;
3254
+ input: $InferZodRecordInput<Key, Value>;
3223
3255
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
3224
3256
  optin?: "optional" | undefined;
3225
3257
  optout?: "optional" | undefined;
@@ -3480,6 +3512,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
3480
3512
  if (proms.length) return Promise.all(proms).then(() => payload);
3481
3513
  return payload;
3482
3514
  };
3515
+ capSize(inst, mapSize);
3483
3516
  });
3484
3517
 
3485
3518
  function handleMapResult(
@@ -3582,6 +3615,7 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
3582
3615
  if (proms.length) return Promise.all(proms).then(() => payload);
3583
3616
  return payload;
3584
3617
  };
3618
+ capSize(inst, setSize);
3585
3619
  });
3586
3620
 
3587
3621
  function handleSetResult(result: ParsePayload, final: ParsePayload<Set<any>>) {
@@ -935,6 +935,19 @@ export function unwrapMessage(message: string | { message: string } | undefined
935
935
  }
936
936
 
937
937
  /* A check holds no link back to the schema it is attached to — the same check instance is shared by every clone of that schema — so the owner is stamped onto the issues a check just raised, at the only point where both are in scope. Runs on the failure path only; `start` is the issue count from before the check ran. */
938
+ /** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
939
+ export function sizeCaps(defChecks: checks.$ZodCheck<never>[] | undefined): [number, checks.$ZodCheck<never>][] {
940
+ const caps: [number, checks.$ZodCheck<never>][] = [];
941
+ for (const ch of defChecks ?? []) {
942
+ const d = ch._zod.def as any;
943
+ // a later check may rewrite the value
944
+ if (!/_(length|size)$|_equals$/.test(d.check)) break;
945
+ const max = d.maximum ?? d.length ?? d.size;
946
+ if (max >= 0) caps.push([max, ch]);
947
+ }
948
+ return caps;
949
+ }
950
+
938
951
  export function attachSchema(issues: errors.$ZodRawIssue[], start: number, inst: schemas.$ZodType): void {
939
952
  for (let i = start; i < issues.length; i++) {
940
953
  (issues[i] as any).schema ??= inst;
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 6,
4
- patch: 5 as number,
4
+ patch: 7 as number,
5
5
  } as const;
@@ -1241,9 +1241,15 @@ function generateNullableCheck(doc, ctx, schema, accessor, buildsValue = true) {
1241
1241
  doc.write(`}`);
1242
1242
  return outputVar;
1243
1243
  }
1244
+ function generateSizeGate(doc, schema, size) {
1245
+ for (const [max, check] of util.sizeCaps(schema._zod.def.checks)) {
1246
+ doc.write(`if (${size} > ${numericOperand(max, check._zod.def.check)}) return INVALID;`);
1247
+ }
1248
+ }
1244
1249
  function generateArrayCheck(doc, ctx, schema, accessor, buildsValue = true) {
1245
1250
  const def = schema._zod.def;
1246
1251
  doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
1252
+ generateSizeGate(doc, schema, `${accessor}.length`);
1247
1253
  // Build a new array with validated/transformed elements.
1248
1254
  const outputVar = buildsValue ? newVar(ctx) : null;
1249
1255
  const iVar = newVar(ctx);
@@ -1707,6 +1713,7 @@ function literalPropertyKey(ctx, key) {
1707
1713
  function generateMapCheck(doc, ctx, schema, accessor) {
1708
1714
  const def = schema._zod.def;
1709
1715
  doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
1716
+ generateSizeGate(doc, schema, `${accessor}.size`);
1710
1717
  const outputVar = newVar(ctx);
1711
1718
  const kVar = newVar(ctx);
1712
1719
  const valVar = newVar(ctx);
@@ -1723,6 +1730,7 @@ function generateMapCheck(doc, ctx, schema, accessor) {
1723
1730
  function generateSetCheck(doc, ctx, schema, accessor) {
1724
1731
  const def = schema._zod.def;
1725
1732
  doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
1733
+ generateSizeGate(doc, schema, `${accessor}.size`);
1726
1734
  const outputVar = newVar(ctx);
1727
1735
  const valVar = newVar(ctx);
1728
1736
  doc.write(`const ${outputVar} = new Set();`);
@@ -1210,9 +1210,15 @@ function generateNullableCheck(doc, ctx, schema, accessor, buildsValue = true) {
1210
1210
  doc.write(`}`);
1211
1211
  return outputVar;
1212
1212
  }
1213
+ function generateSizeGate(doc, schema, size) {
1214
+ for (const [max, check] of util.sizeCaps(schema._zod.def.checks)) {
1215
+ doc.write(`if (${size} > ${numericOperand(max, check._zod.def.check)}) return INVALID;`);
1216
+ }
1217
+ }
1213
1218
  function generateArrayCheck(doc, ctx, schema, accessor, buildsValue = true) {
1214
1219
  const def = schema._zod.def;
1215
1220
  doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
1221
+ generateSizeGate(doc, schema, `${accessor}.length`);
1216
1222
  // Build a new array with validated/transformed elements.
1217
1223
  const outputVar = buildsValue ? newVar(ctx) : null;
1218
1224
  const iVar = newVar(ctx);
@@ -1676,6 +1682,7 @@ function literalPropertyKey(ctx, key) {
1676
1682
  function generateMapCheck(doc, ctx, schema, accessor) {
1677
1683
  const def = schema._zod.def;
1678
1684
  doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
1685
+ generateSizeGate(doc, schema, `${accessor}.size`);
1679
1686
  const outputVar = newVar(ctx);
1680
1687
  const kVar = newVar(ctx);
1681
1688
  const valVar = newVar(ctx);
@@ -1692,6 +1699,7 @@ function generateMapCheck(doc, ctx, schema, accessor) {
1692
1699
  function generateSetCheck(doc, ctx, schema, accessor) {
1693
1700
  const def = schema._zod.def;
1694
1701
  doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
1702
+ generateSizeGate(doc, schema, `${accessor}.size`);
1695
1703
  const outputVar = newVar(ctx);
1696
1704
  const valVar = newVar(ctx);
1697
1705
  doc.write(`const ${outputVar} = new Set();`);
@@ -860,6 +860,33 @@ exports.$ZodDate = core.$constructor("$ZodDate", (inst, def) => {
860
860
  return payload;
861
861
  };
862
862
  });
863
+ // an oversized container fails its leading size checks before any element is parsed
864
+ function capSize(inst, size) {
865
+ const caps = util.sizeCaps(inst._zod.def.checks);
866
+ if (!caps.length)
867
+ return;
868
+ const cap = Math.min(...caps.map((c) => c[0]));
869
+ const parse = inst._zod.parse;
870
+ inst._zod.parse = (payload, ctx) => {
871
+ const n = size(payload.value);
872
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
873
+ for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
874
+ if (n > max && ch._zod.def.when(payload)) {
875
+ const start = payload.issues.length;
876
+ ch._zod.check(payload);
877
+ // the value is still the raw input, so no later check may read it
878
+ payload.issues[start].continue = false;
879
+ util.attachSchema(payload.issues, start, inst);
880
+ return payload;
881
+ }
882
+ }
883
+ }
884
+ return parse(payload, ctx);
885
+ };
886
+ }
887
+ const arraySize = (input) => (Array.isArray(input) ? input.length : -1);
888
+ const mapSize = (input) => (input instanceof Map ? input.size : -1);
889
+ const setSize = (input) => (input instanceof Set ? input.size : -1);
863
890
  function handleArrayResult(result, final, index) {
864
891
  if (result.issues.length) {
865
892
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -905,6 +932,7 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
905
932
  }
906
933
  return payload; //handleArrayResultsAsync(parseResults, final);
907
934
  };
935
+ capSize(inst, arraySize);
908
936
  });
909
937
  function handlePropertyResult(result, final, key, input, optin, optout) {
910
938
  const isPresent = key in input;
@@ -1942,6 +1970,7 @@ exports.$ZodMap = core.$constructor("$ZodMap", (inst, def) => {
1942
1970
  return Promise.all(proms).then(() => payload);
1943
1971
  return payload;
1944
1972
  };
1973
+ capSize(inst, mapSize);
1945
1974
  });
1946
1975
  function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1947
1976
  if (keyResult.issues.length) {
@@ -2011,6 +2040,7 @@ exports.$ZodSet = core.$constructor("$ZodSet", (inst, def) => {
2011
2040
  return Promise.all(proms).then(() => payload);
2012
2041
  return payload;
2013
2042
  };
2043
+ capSize(inst, setSize);
2014
2044
  });
2015
2045
  function handleSetResult(result, final) {
2016
2046
  if (result.issues.length) {
@@ -834,8 +834,10 @@ export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Val
834
834
  export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>> : [
835
835
  Value
836
836
  ] extends [OptionalInSchema] ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>> : Record<core.input<Key> & PropertyKey, core.input<Value>>;
837
- export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
837
+ export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals {
838
838
  def: $ZodRecordDef<Key, Value>;
839
+ output: $InferZodRecordOutput<Key, Value>;
840
+ input: $InferZodRecordInput<Key, Value>;
839
841
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
840
842
  optin?: "optional" | undefined;
841
843
  optout?: "optional" | undefined;
@@ -834,8 +834,10 @@ export type $InferZodRecordOutput<Key extends $ZodRecordKey = $ZodRecordKey, Val
834
834
  export type $InferZodRecordInput<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> = Key extends $partial ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>> : [
835
835
  Value
836
836
  ] extends [OptionalInSchema] ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>> : Record<core.input<Key> & PropertyKey, core.input<Value>>;
837
- export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
837
+ export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals {
838
838
  def: $ZodRecordDef<Key, Value>;
839
+ output: $InferZodRecordOutput<Key, Value>;
840
+ input: $InferZodRecordInput<Key, Value>;
839
841
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
840
842
  optin?: "optional" | undefined;
841
843
  optout?: "optional" | undefined;
@@ -816,6 +816,33 @@ export const $ZodDate = /*@__PURE__*/ core.$constructor("$ZodDate", (inst, def)
816
816
  return payload;
817
817
  };
818
818
  });
819
+ // an oversized container fails its leading size checks before any element is parsed
820
+ function capSize(inst, size) {
821
+ const caps = util.sizeCaps(inst._zod.def.checks);
822
+ if (!caps.length)
823
+ return;
824
+ const cap = Math.min(...caps.map((c) => c[0]));
825
+ const parse = inst._zod.parse;
826
+ inst._zod.parse = (payload, ctx) => {
827
+ const n = size(payload.value);
828
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
829
+ for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
830
+ if (n > max && ch._zod.def.when(payload)) {
831
+ const start = payload.issues.length;
832
+ ch._zod.check(payload);
833
+ // the value is still the raw input, so no later check may read it
834
+ payload.issues[start].continue = false;
835
+ util.attachSchema(payload.issues, start, inst);
836
+ return payload;
837
+ }
838
+ }
839
+ }
840
+ return parse(payload, ctx);
841
+ };
842
+ }
843
+ const arraySize = (input) => (Array.isArray(input) ? input.length : -1);
844
+ const mapSize = (input) => (input instanceof Map ? input.size : -1);
845
+ const setSize = (input) => (input instanceof Set ? input.size : -1);
819
846
  function handleArrayResult(result, final, index) {
820
847
  if (result.issues.length) {
821
848
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -861,6 +888,7 @@ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def
861
888
  }
862
889
  return payload; //handleArrayResultsAsync(parseResults, final);
863
890
  };
891
+ capSize(inst, arraySize);
864
892
  });
865
893
  function handlePropertyResult(result, final, key, input, optin, optout) {
866
894
  const isPresent = key in input;
@@ -1898,6 +1926,7 @@ export const $ZodMap = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) =>
1898
1926
  return Promise.all(proms).then(() => payload);
1899
1927
  return payload;
1900
1928
  };
1929
+ capSize(inst, mapSize);
1901
1930
  });
1902
1931
  function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1903
1932
  if (keyResult.issues.length) {
@@ -1967,6 +1996,7 @@ export const $ZodSet = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) =>
1967
1996
  return Promise.all(proms).then(() => payload);
1968
1997
  return payload;
1969
1998
  };
1999
+ capSize(inst, setSize);
1970
2000
  });
1971
2001
  function handleSetResult(result, final) {
1972
2002
  if (result.issues.length) {