apps 0.0.1-beta.13 → 0.0.1-beta.132

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 (205) hide show
  1. package/README.md +60 -42
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-M3B3DE4K.js → chunk-2XDCAXAR.js} +612 -246
  4. package/js/{chunk-IPI4MFSN.js → chunk-34RH47V5.js} +2 -2
  5. package/js/{chunk-RFVIONFX.js → chunk-36COQXTI.js} +136 -45
  6. package/js/{chunk-ODEIDRGW.js → chunk-3PIXIKHR.js} +1152 -504
  7. package/js/chunk-5SSWQNLR.js +449 -0
  8. package/js/{chunk-KUMBKVJD.js → chunk-6QZVXLF2.js} +2 -2
  9. package/js/chunk-7MPPHKRW.js +5418 -0
  10. package/js/chunk-AYXVIAPV.js +335 -0
  11. package/js/chunk-H2K7OZ47.js +90 -0
  12. package/js/chunk-I6QAWNUM.js +161 -0
  13. package/js/chunk-IMTTIZID.js +576 -0
  14. package/js/chunk-JYH7YLV7.js +49 -0
  15. package/js/{chunk-QS6CAHKC.js → chunk-KVZRGT5A.js} +4 -3
  16. package/js/chunk-LSOHA2RH.js +88 -0
  17. package/js/{chunk-UK573G7W.js → chunk-MB6L5YZE.js} +1817 -632
  18. package/js/chunk-OBT33ZDK.js +95 -0
  19. package/js/chunk-OD3KFKZD.js +1617 -0
  20. package/js/chunk-PZQCBLMC.js +175 -0
  21. package/js/{chunk-JU7VHODU.js → chunk-QTX7OUFH.js} +65 -10
  22. package/js/{chunk-VFZKSM3T.js → chunk-VX36SA7Y.js} +3 -3
  23. package/js/{chunk-5T57N25Q.js → chunk-WXHRUWNT.js} +651 -70
  24. package/js/chunk-XNDA3277.js +724 -0
  25. package/js/{chunk-CDL5PM2Q.js → chunk-YFSOSNF3.js} +17265 -12477
  26. package/js/chunk-YRAKYZJP.js +1945 -0
  27. package/js/{chunk-IJX4CYZO.js → chunk-YVN2AMAU.js} +976 -447
  28. package/js/chunk-YYLI5HVR.js +1016 -0
  29. package/js/client.js +234 -92
  30. package/js/contracts.js +154 -21
  31. package/js/effect.js +18 -19
  32. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  33. package/js/graphql.js +231 -188
  34. package/js/host.js +138 -80
  35. package/js/index.js +153 -300
  36. package/js/mcp/effect.js +21 -21
  37. package/js/mcp.js +91 -57
  38. package/js/openapi.js +4357 -1415
  39. package/js/react.js +2 -3
  40. package/js/skills/effect.js +6 -3
  41. package/js/skills.js +220 -81
  42. package/js/storage/facet.js +1 -540
  43. package/js/ui/auth/contracts.js +2 -2
  44. package/js/ui/auth.js +5 -5
  45. package/js/ui/contracts.js +9 -8
  46. package/js/ui/serving.js +8618 -235
  47. package/package.json +3 -8
  48. package/runtime.json +1 -1
  49. package/types/app-cache/src/contracts/cache.d.ts +18 -0
  50. package/types/app-cache/src/index.d.ts +34 -2
  51. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  52. package/types/apps/src/contracts/app.d.ts +56 -11
  53. package/types/apps/src/contracts/cache.d.ts +20 -0
  54. package/types/apps/src/contracts/context.d.ts +60 -17
  55. package/types/apps/src/contracts/elicitation.d.ts +23 -7
  56. package/types/apps/src/contracts/events.d.ts +94 -0
  57. package/types/apps/src/contracts/failure.d.ts +30 -1
  58. package/types/apps/src/contracts/graphql.d.ts +40 -2
  59. package/types/apps/src/contracts/help-text.d.ts +31 -0
  60. package/types/apps/src/contracts/host.d.ts +1493 -20
  61. package/types/apps/src/contracts/icons.d.ts +28 -0
  62. package/types/apps/src/contracts/live.d.ts +2 -0
  63. package/types/apps/src/contracts/mcp.d.ts +81 -20
  64. package/types/apps/src/contracts/network.d.ts +120 -0
  65. package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
  66. package/types/apps/src/contracts/openapi-document.d.ts +1 -1
  67. package/types/apps/src/contracts/openapi.d.ts +40 -8
  68. package/types/apps/src/contracts/operations.d.ts +14 -7
  69. package/types/apps/src/contracts/placement.d.ts +102 -0
  70. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  71. package/types/apps/src/contracts/protocols/1.d.ts +513 -15
  72. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  73. package/types/apps/src/contracts/protocols/11.d.ts +1149 -0
  74. package/types/apps/src/contracts/protocols/12.d.ts +3310 -0
  75. package/types/apps/src/contracts/protocols/13.d.ts +6001 -0
  76. package/types/apps/src/contracts/protocols/2.d.ts +9 -8
  77. package/types/apps/src/contracts/protocols/3.d.ts +73 -15
  78. package/types/apps/src/contracts/protocols/4.d.ts +22 -15
  79. package/types/apps/src/contracts/protocols/5.d.ts +37 -11
  80. package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
  81. package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
  82. package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
  83. package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
  84. package/types/apps/src/contracts/protocols/current.d.ts +7114 -0
  85. package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
  86. package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
  87. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  88. package/types/apps/src/contracts/provider.d.ts +56 -0
  89. package/types/apps/src/contracts/router.d.ts +2 -1
  90. package/types/apps/src/contracts/schedules.d.ts +7 -1
  91. package/types/apps/src/contracts/schema.d.ts +21 -0
  92. package/types/apps/src/contracts/shared-catalog.d.ts +11 -0
  93. package/types/apps/src/contracts/skills.d.ts +50 -13
  94. package/types/apps/src/contracts/sql.d.ts +63 -0
  95. package/types/apps/src/contracts/ui.d.ts +70 -30
  96. package/types/apps/src/contracts/webhooks.d.ts +24 -7
  97. package/types/apps/src/contracts/workflows.d.ts +56 -34
  98. package/types/apps/src/facet.d.ts +4 -5
  99. package/types/apps/src/host.d.ts +5 -0
  100. package/types/apps/src/implementation/account-router.d.ts +20 -3
  101. package/types/apps/src/implementation/app.d.ts +41 -14
  102. package/types/apps/src/implementation/authoring.d.ts +25 -5
  103. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  104. package/types/apps/src/implementation/cache.d.ts +29 -2
  105. package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
  106. package/types/apps/src/implementation/elicitation.d.ts +16 -13
  107. package/types/apps/src/implementation/events.d.ts +64 -0
  108. package/types/apps/src/implementation/failure-detail.d.ts +28 -5
  109. package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
  110. package/types/apps/src/implementation/graphql.d.ts +4 -3
  111. package/types/apps/src/implementation/help-text.d.ts +5 -0
  112. package/types/apps/src/implementation/input-problems.d.ts +6 -2
  113. package/types/apps/src/implementation/invocation-timing.d.ts +18 -0
  114. package/types/apps/src/implementation/live.d.ts +2 -2
  115. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  116. package/types/apps/src/implementation/mcp-catalog.d.ts +6 -4
  117. package/types/apps/src/implementation/mcp-client.d.ts +17 -9
  118. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  119. package/types/apps/src/implementation/mcp.d.ts +20 -9
  120. package/types/apps/src/implementation/network.d.ts +16 -0
  121. package/types/apps/src/implementation/openapi-compile.d.ts +38 -7
  122. package/types/apps/src/implementation/openapi-document.d.ts +50 -20
  123. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  124. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  125. package/types/apps/src/implementation/openapi-source.d.ts +23 -1
  126. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  127. package/types/apps/src/implementation/operations.d.ts +58 -7
  128. package/types/apps/src/implementation/optimistic.d.ts +1 -1
  129. package/types/apps/src/implementation/placement.d.ts +60 -0
  130. package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
  131. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  132. package/types/apps/src/implementation/provider.d.ts +20 -4
  133. package/types/apps/src/implementation/query-commit.d.ts +1 -1
  134. package/types/apps/src/implementation/router-catalog.d.ts +22 -97
  135. package/types/apps/src/implementation/router.d.ts +26 -6
  136. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  137. package/types/apps/src/implementation/schedules.d.ts +39 -8
  138. package/types/apps/src/implementation/schema.d.ts +125 -17
  139. package/types/apps/src/implementation/skills.d.ts +18 -24
  140. package/types/apps/src/implementation/sql.d.ts +71 -0
  141. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  142. package/types/apps/src/implementation/ui-auth.d.ts +1 -1
  143. package/types/apps/src/implementation/ui-client.d.ts +3 -3
  144. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  145. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  146. package/types/apps/src/implementation/ui-serving.d.ts +38 -12
  147. package/types/apps/src/implementation/upstream-error.d.ts +17 -0
  148. package/types/apps/src/implementation/webhooks.d.ts +15 -6
  149. package/types/apps/src/implementation/workflow-context.d.ts +6 -2
  150. package/types/apps/src/implementation/workflows.d.ts +11 -4
  151. package/types/apps/src/index.d.ts +67 -17
  152. package/types/apps/src/mcp.d.ts +20 -1
  153. package/types/apps/src/openapi.d.ts +22 -1
  154. package/types/apps/src/react.d.ts +1 -1
  155. package/types/apps/src/skills.d.ts +10 -8
  156. package/types/apps/src/ui-serving.d.ts +1 -2
  157. package/types/telemetry/src/app-records.d.ts +42 -0
  158. package/types/telemetry/src/browser-operations.d.ts +2 -2
  159. package/types/telemetry/src/browser.d.ts +8 -3
  160. package/types/telemetry/src/config.d.ts +2 -2
  161. package/types/telemetry/src/index.d.ts +3 -2
  162. package/types/telemetry/src/keepalive.d.ts +36 -0
  163. package/types/telemetry/src/layer.d.ts +10 -4
  164. package/types/telemetry/src/measurements.d.ts +6 -2
  165. package/types/telemetry/src/ownership.d.ts +60 -0
  166. package/types/telemetry/src/recorded-failure.d.ts +29 -0
  167. package/types/telemetry/src/relay.d.ts +32 -7
  168. package/types/telemetry/src/span-attributes.d.ts +22 -3
  169. package/types/telemetry/src/transport.d.ts +8 -1
  170. package/types/utils/src/api-error.d.ts +55 -0
  171. package/types/utils/src/connection-failure.d.ts +33 -0
  172. package/types/utils/src/legacy-keys.d.ts +20 -0
  173. package/types/utils/src/random-uuid.d.ts +6 -0
  174. package/types/utils/src/recorded-message.d.ts +18 -0
  175. package/types/utils/src/schema-definitions.d.ts +13 -0
  176. package/types/utils/src/user-facing-error.d.ts +83 -0
  177. package/js/chunk-27F7W2LG.js +0 -34
  178. package/js/chunk-4ASNKGCV.js +0 -242
  179. package/js/chunk-4DWF4ZWI.js +0 -1280
  180. package/js/chunk-57RKNWL2.js +0 -75
  181. package/js/chunk-6HSH75OI.js +0 -2688
  182. package/js/chunk-G4FT53I7.js +0 -224
  183. package/js/chunk-MKWZPDR6.js +0 -63
  184. package/js/chunk-N7YDVXYJ.js +0 -186
  185. package/js/chunk-NKLWZJLE.js +0 -172
  186. package/js/chunk-PJJ24GU7.js +0 -877
  187. package/js/chunk-PZB6T6KU.js +0 -19
  188. package/js/chunk-R3EV5FTO.js +0 -97
  189. package/js/chunk-S73JGVR5.js +0 -507
  190. package/js/chunk-TG6DOCRO.js +0 -299
  191. package/js/chunk-YPKG2QO5.js +0 -209
  192. package/js/chunk-ZQINWV4W.js +0 -630
  193. package/js/mcp/stdio.js +0 -128
  194. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  195. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  196. package/types/app-data/src/implementation/promise.d.ts +0 -68
  197. package/types/app-data/src/implementation/range.d.ts +0 -8
  198. package/types/app-data/src/implementation/schema.d.ts +0 -18
  199. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  200. package/types/app-data/src/index.d.ts +0 -4
  201. package/types/apps/src/contracts/storage.d.ts +0 -68
  202. package/types/apps/src/implementation/mcp-stdio.d.ts +0 -4
  203. package/types/apps/src/implementation/storage.d.ts +0 -15
  204. package/types/apps/src/implementation/ui-watch.d.ts +0 -2
  205. package/types/apps/src/mcp-stdio.d.ts +0 -5
@@ -1,7 +1,8 @@
1
1
  import {
2
+ DeclarationInvalid,
2
3
  JsonObject,
3
4
  ValidationError
4
- } from "./chunk-27F7W2LG.js";
5
+ } from "./chunk-H2K7OZ47.js";
5
6
  import {
6
7
  Cause_exports,
7
8
  Effect_exports,
@@ -10,7 +11,7 @@ import {
10
11
  SchemaIssue_exports,
11
12
  SchemaParser_exports,
12
13
  Schema_exports
13
- } from "./chunk-CDL5PM2Q.js";
14
+ } from "./chunk-YFSOSNF3.js";
14
15
 
15
16
  // ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
16
17
  function deepCompareStrict(a, b) {
@@ -62,6 +63,19 @@ function escapePointer(p) {
62
63
  }
63
64
 
64
65
  // ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/dereference.js
66
+ var schemaKeyword = {
67
+ additionalItems: true,
68
+ unevaluatedItems: true,
69
+ items: true,
70
+ contains: true,
71
+ additionalProperties: true,
72
+ unevaluatedProperties: true,
73
+ propertyNames: true,
74
+ not: true,
75
+ if: true,
76
+ then: true,
77
+ else: true
78
+ };
65
79
  var schemaArrayKeyword = {
66
80
  prefixItems: true,
67
81
  items: true,
@@ -107,9 +121,9 @@ var ignoredKeyword = {
107
121
  var initialBaseURI = typeof self !== "undefined" && self.location && self.location.origin !== "null" ? new URL(self.location.origin + self.location.pathname + location.search) : new URL("https://github.com/cfworker");
108
122
  function dereference(schema, lookup = /* @__PURE__ */ Object.create(null), baseURI = initialBaseURI, basePointer = "") {
109
123
  if (schema && typeof schema === "object" && !Array.isArray(schema)) {
110
- const id2 = schema.$id || schema.id;
111
- if (id2) {
112
- const url = new URL(id2, baseURI.href);
124
+ const id = schema.$id || schema.id;
125
+ if (id) {
126
+ const url = new URL(id, baseURI.href);
113
127
  if (url.hash.length > 1) {
114
128
  lookup[url.href] = schema;
115
129
  } else {
@@ -175,8 +189,14 @@ function dereference(schema, lookup = /* @__PURE__ */ Object.create(null), baseU
175
189
  for (let subKey in subSchema) {
176
190
  dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);
177
191
  }
178
- } else {
192
+ } else if (schemaKeyword[key]) {
179
193
  dereference(subSchema, lookup, baseURI, keyBase);
194
+ } else if (key === "dependencies" && subSchema && typeof subSchema === "object") {
195
+ for (let subKey in subSchema) {
196
+ if (!Array.isArray(subSchema[subKey])) {
197
+ dereference(subSchema[subKey], lookup, baseURI, `${keyBase}/${encodePointer(subKey)}`);
198
+ }
199
+ }
180
200
  }
181
201
  }
182
202
  return lookup;
@@ -345,7 +365,7 @@ function validate(instance, schema, draft = "2019-09", lookup = dereference(sche
345
365
  if ($recursiveAnchor === true && recursiveAnchor === null) {
346
366
  recursiveAnchor = schema;
347
367
  }
348
- if ($recursiveRef === "#") {
368
+ if ($recursiveRef !== void 0) {
349
369
  const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
350
370
  const keywordLocation = `${schemaLocation}/$recursiveRef`;
351
371
  const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
@@ -1069,40 +1089,57 @@ function schemaPattern(pattern) {
1069
1089
  }
1070
1090
 
1071
1091
  // src/implementation/schema.ts
1072
- var StorageField = /* @__PURE__ */ Symbol("apps.StorageField");
1073
1092
  var Decoder = /* @__PURE__ */ Symbol("apps.Schema");
1074
1093
  var decoderOf = (schema) => schema[Decoder];
1075
1094
  var isSchema = (value) => typeof value === "object" && value !== null && Decoder in value;
1095
+ var schemaArgument = (value, role) => {
1096
+ if (isSchema(value)) return value;
1097
+ const received = value;
1098
+ throw new TypeError(
1099
+ `${role} must be a schema, such as string() or object({ ... }), but ${typeof received === "function" ? "it is a function. Call it, as in string()." : received === void 0 ? "it is undefined. Check that it is defined and imported before this declaration." : typeof received === "object" && received !== null && Object.getPrototypeOf(received) === Object.prototype ? "it is a plain object. Wrap its fields in object({ ... })." : "no apps schema constructor created it."}`
1100
+ );
1101
+ };
1076
1102
  var parse = (decoder, input) => Effect_exports.suspend(() => Schema_exports.decodeUnknownEffect(decoder)(input)).pipe(
1077
1103
  Effect_exports.mapError(() => new ValidationError())
1078
1104
  );
1079
- function wrap(decoder, optionalValue, field) {
1105
+ var declarationIssues = SchemaIssue_exports.makeFormatterStandardSchemaV1({
1106
+ leafHook: SchemaIssue_exports.defaultLeafHook
1107
+ });
1108
+ var parseDeclaration = (decoder, input, declaration, intended = () => decoder) => Effect_exports.suspend(() => Schema_exports.decodeUnknownEffect(decoder)(input)).pipe(
1109
+ Effect_exports.catch(
1110
+ (failed) => Effect_exports.suspend(
1111
+ () => Schema_exports.decodeUnknownEffect(intended(input))(input, { errors: "all" })
1112
+ ).pipe(
1113
+ Effect_exports.flip,
1114
+ Effect_exports.orElseSucceed(() => failed),
1115
+ Effect_exports.flatMap(
1116
+ (error) => Effect_exports.fail(
1117
+ new DeclarationInvalid({
1118
+ declaration,
1119
+ issues: declarationIssues(error.issue).issues.map((issue) => ({
1120
+ path: (issue.path ?? []).map(
1121
+ (segment) => String(typeof segment === "object" ? segment.key : segment)
1122
+ ),
1123
+ message: issue.message
1124
+ }))
1125
+ })
1126
+ )
1127
+ )
1128
+ )
1129
+ )
1130
+ );
1131
+ function wrap(decoder, optionalValue) {
1080
1132
  return {
1081
1133
  [Decoder]: decoder,
1082
- ...field === void 0 ? {} : { [StorageField]: field },
1083
1134
  optionalValue,
1084
1135
  parse: (input) => Effect_exports.runSync(parse(decoder, input)),
1085
- optional: () => wrap(
1086
- Schema_exports.optional(decoder),
1087
- true,
1088
- field === void 0 ? void 0 : { ...field, optional: true }
1089
- ),
1136
+ optional: () => wrap(Schema_exports.optional(decoder), true),
1090
1137
  default: (value) => {
1091
1138
  const parsed = Effect_exports.runSync(parse(decoder, value));
1092
1139
  return {
1093
1140
  ...wrap(
1094
1141
  decoder.annotate({ default: parsed }).pipe(Schema_exports.withDecodingDefault(Effect_exports.succeed(parsed))),
1095
- false,
1096
- field === void 0 || parsed === void 0 ? void 0 : {
1097
- ...field,
1098
- default: Schema_exports.decodeUnknownSync(
1099
- Schema_exports.Union([
1100
- Schema_exports.String,
1101
- Schema_exports.Finite,
1102
- Schema_exports.Boolean
1103
- ])
1104
- )(parsed)
1105
- }
1142
+ false
1106
1143
  ),
1107
1144
  hasDefault: true,
1108
1145
  inputOptional: optionalValue
@@ -1110,17 +1147,29 @@ function wrap(decoder, optionalValue, field) {
1110
1147
  }
1111
1148
  };
1112
1149
  }
1150
+ var annotated = (schema, { title, description }) => title === void 0 && description === void 0 ? schema : schema.annotate({
1151
+ ...title === void 0 ? {} : { title },
1152
+ ...description === void 0 ? {} : { description }
1153
+ });
1113
1154
  function string(options = {}) {
1114
1155
  return wrap(
1115
- options.minLength === void 0 ? Schema_exports.String : Schema_exports.String.check(Schema_exports.isMinLength(options.minLength)),
1116
- false,
1117
- { kind: "string" }
1156
+ annotated(
1157
+ options.minLength === void 0 ? Schema_exports.String : Schema_exports.String.check(Schema_exports.isMinLength(options.minLength)),
1158
+ options
1159
+ ),
1160
+ false
1118
1161
  );
1119
1162
  }
1120
- var number = () => wrap(Schema_exports.Finite, false, { kind: "number" });
1121
- var boolean = () => wrap(Schema_exports.Boolean, false, { kind: "boolean" });
1163
+ var number = (options = {}) => wrap(annotated(Schema_exports.Finite, options), false);
1164
+ var boolean = (options = {}) => wrap(annotated(Schema_exports.Boolean, options), false);
1122
1165
  var json = () => wrap(Schema_exports.Json, false);
1123
- var record = (value) => wrap(Schema_exports.Record(Schema_exports.String, decoderOf(value)), false);
1166
+ var record = (value) => wrap(
1167
+ Schema_exports.Record(
1168
+ Schema_exports.String,
1169
+ decoderOf(schemaArgument(value, "The record() value"))
1170
+ ),
1171
+ false
1172
+ );
1124
1173
  function literal(value) {
1125
1174
  if (typeof value === "number") Effect_exports.runSync(parse(Schema_exports.Finite, value));
1126
1175
  return wrap(
@@ -1128,10 +1177,13 @@ function literal(value) {
1128
1177
  false
1129
1178
  );
1130
1179
  }
1131
- var array = (item) => wrap(Schema_exports.Array(decoderOf(item)), false);
1180
+ var array = (item) => wrap(Schema_exports.Array(decoderOf(schemaArgument(item, "The array() item"))), false);
1132
1181
  function object(fields) {
1133
1182
  const entries = Object.entries(fields).map(
1134
- ([key, field]) => [key, decoderOf(field)]
1183
+ ([key, field]) => [
1184
+ key,
1185
+ decoderOf(schemaArgument(field, `The object() field ${JSON.stringify(key)}`))
1186
+ ]
1135
1187
  );
1136
1188
  const decoder = entries.length === 0 ? withJsonSchemaDocument(
1137
1189
  // Native Struct({}) accepts every non-null value and retains undeclared fields.
@@ -1145,6 +1197,25 @@ function object(fields) {
1145
1197
  ) : Schema_exports.Struct(Object.fromEntries(entries));
1146
1198
  return { ...wrap(decoder, false), fields: Object.freeze({ ...fields }) };
1147
1199
  }
1200
+ var Exposure = /* @__PURE__ */ Symbol("apps.FieldExposure");
1201
+ var exposureOf = (schema) => Exposure in schema && (schema[Exposure] === "plain" || schema[Exposure] === "raw") ? schema[Exposure] : void 0;
1202
+ var expose = (schema, exposure) => (
1203
+ // SAFETY: the copy keeps every member of S, and `optional` and `default` keep the marking.
1204
+ {
1205
+ ...schema,
1206
+ [Exposure]: exposure,
1207
+ optional: () => expose(schema.optional(), exposure),
1208
+ default: (value) => expose(schema.default(value), exposure)
1209
+ }
1210
+ );
1211
+ var plain = (schema) => expose(schema, "plain");
1212
+ var raw = (schema) => expose(schema, "raw");
1213
+ var fieldExposure = (fields) => Object.fromEntries(
1214
+ Object.entries(fields).flatMap(([name, field]) => {
1215
+ const exposure = exposureOf(field);
1216
+ return exposure === void 0 ? [] : [[name, exposure]];
1217
+ })
1218
+ );
1148
1219
  var ImportedJsonSchema = /* @__PURE__ */ Symbol("apps.JsonSchemaDocument");
1149
1220
  var importedJsonSchema = (decoder) => ImportedJsonSchema in decoder ? decoder[ImportedJsonSchema] : void 0;
1150
1221
  var withJsonSchemaDocument = (decoder, document) => Object.assign(decoder, { [ImportedJsonSchema]: document });
@@ -1160,7 +1231,7 @@ var withLazyJsonSchemaDocument = (decoder, document) => Object.defineProperty(de
1160
1231
  var nestJsonSchema = (input, pointer) => {
1161
1232
  const document = structuredClone(input);
1162
1233
  const lookup = dereference(document);
1163
- const schemas = new Set(Object.values(lookup));
1234
+ const evaluated = evaluatedSchemas(document, lookup);
1164
1235
  const pointers = /* @__PURE__ */ new Map();
1165
1236
  const locate = (value, path) => {
1166
1237
  if (!pointers.has(value)) pointers.set(value, path);
@@ -1174,8 +1245,7 @@ var nestJsonSchema = (input, pointer) => {
1174
1245
  };
1175
1246
  locate(document, pointer);
1176
1247
  const references = /* @__PURE__ */ new Map();
1177
- for (const schema of schemas) {
1178
- if (typeof schema === "boolean") continue;
1248
+ for (const schema of evaluated) {
1179
1249
  const refs = {};
1180
1250
  for (const [key, absolute] of [
1181
1251
  ["$ref", schema.__absolute_ref__],
@@ -1201,6 +1271,65 @@ var nestJsonSchema = (input, pointer) => {
1201
1271
  Schema_exports.Record(Schema_exports.String, Schema_exports.Json)
1202
1272
  )(rewrite(document));
1203
1273
  };
1274
+ var identifiers = /* @__PURE__ */ new Set([
1275
+ "$id",
1276
+ "id",
1277
+ "$anchor",
1278
+ "$recursiveAnchor",
1279
+ "$recursiveRef",
1280
+ "$dynamicAnchor",
1281
+ "$dynamicRef"
1282
+ ]);
1283
+ var ownDefinition = (reference) => {
1284
+ if (typeof reference !== "string" || !reference.startsWith("#/$defs/")) return void 0;
1285
+ const segments = pointerSegments(reference);
1286
+ return segments.length === 2 ? segments[1] : void 0;
1287
+ };
1288
+ var rootDefinitions = (schema) => {
1289
+ const definitions = schema.$defs ?? {};
1290
+ if (!isJsonRecord(definitions)) return void 0;
1291
+ const pending = [schema];
1292
+ for (let value = pending.pop(); value !== void 0; value = pending.pop()) {
1293
+ if (!isSchemaObject(value)) continue;
1294
+ for (const [key, item] of Object.entries(value)) {
1295
+ if (identifiers.has(key)) return void 0;
1296
+ if (key === "$ref") {
1297
+ const name = ownDefinition(item);
1298
+ if (name === void 0 || !Object.hasOwn(definitions, name)) return void 0;
1299
+ } else if (Array.isArray(item)) {
1300
+ if (schemaArrays.has(key) || key === "items") pending.push(...item);
1301
+ } else if (schemaMaps.has(key) || key === "dependencies") {
1302
+ if (isJsonRecord(item)) pending.push(...Object.values(item));
1303
+ } else if (schemaNodes.has(key)) pending.push(item);
1304
+ }
1305
+ }
1306
+ return definitions;
1307
+ };
1308
+ var combineJsonSchemas = (schemas, pointer) => {
1309
+ const shared = {};
1310
+ const texts = /* @__PURE__ */ new Map();
1311
+ const combined = schemas.map((schema, index) => {
1312
+ const definitions = rootDefinitions(schema);
1313
+ const entries = Object.entries(definitions ?? {}).map(
1314
+ ([name, definition]) => [name, definition, JSON.stringify(definition)]
1315
+ );
1316
+ if (definitions === void 0 || entries.some(([name, , text]) => texts.has(name) && texts.get(name) !== text))
1317
+ return nestJsonSchema(schema, pointer(index));
1318
+ for (const [name, definition, text] of entries) {
1319
+ if (texts.has(name)) continue;
1320
+ texts.set(name, text);
1321
+ Object.defineProperty(shared, name, {
1322
+ value: definition,
1323
+ enumerable: true,
1324
+ writable: true,
1325
+ configurable: true
1326
+ });
1327
+ }
1328
+ const { $defs: _, ...rest } = schema;
1329
+ return rest;
1330
+ });
1331
+ return texts.size === 0 ? { schemas: combined } : { $defs: shared, schemas: combined };
1332
+ };
1204
1333
  var schemaMaps = /* @__PURE__ */ new Set([
1205
1334
  "$defs",
1206
1335
  "definitions",
@@ -1222,6 +1351,27 @@ var schemaNodes = /* @__PURE__ */ new Set([
1222
1351
  "unevaluatedItems",
1223
1352
  "propertyNames"
1224
1353
  ]);
1354
+ var isSchemaObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1355
+ var evaluatedSchemas = (root, lookup) => {
1356
+ const found = /* @__PURE__ */ new Set();
1357
+ const pending = [root];
1358
+ for (let value = pending.pop(); value !== void 0; value = pending.pop()) {
1359
+ if (!isSchemaObject(value) || found.has(value)) continue;
1360
+ found.add(value);
1361
+ for (const target of [value.__absolute_ref__, value.__absolute_recursive_ref__]) {
1362
+ const schema = target === void 0 ? void 0 : lookup[target];
1363
+ if (schema !== void 0) pending.push(schema);
1364
+ }
1365
+ for (const [key, item] of Object.entries(value)) {
1366
+ if (Array.isArray(item)) {
1367
+ if (schemaArrays.has(key) || key === "items") pending.push(...item);
1368
+ } else if (schemaMaps.has(key) || key === "dependencies") {
1369
+ if (isJsonRecord(item)) pending.push(...Object.values(item));
1370
+ } else if (schemaNodes.has(key)) pending.push(item);
1371
+ }
1372
+ }
1373
+ return found;
1374
+ };
1225
1375
  function interpretedDocument(value) {
1226
1376
  if (typeof value === "boolean") return value;
1227
1377
  if (value === null || typeof value !== "object" || Array.isArray(value))
@@ -1274,18 +1424,425 @@ var containerKeywords = /* @__PURE__ */ new Set([
1274
1424
  "else",
1275
1425
  "dependentSchemas"
1276
1426
  ]);
1277
- var jsonSchemaProblems = (errors) => {
1278
- const problems = errors.flatMap(({ keyword, instanceLocation, error }) => {
1279
- if (containerKeywords.has(keyword)) return [];
1280
- const path = instanceLocation.replace(/^#\/?/, "").split("/").filter((segment) => segment !== "").map((segment) => decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~")).map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
1281
- const required = keyword === "required" ? /required property "([^"]*)"/.exec(error) : null;
1282
- const expected = keyword === "type" ? /Expected "([^.]*)"\.?$/.exec(error) : null;
1283
- const issue = required !== null ? { path: [...path, required[1] ?? ""], issue: "Missing key" } : {
1284
- path,
1285
- issue: expected !== null ? `Expected ${(expected[1] ?? "").replace(/"/g, "")}` : keyword === "const" || keyword === "enum" ? "Expected one of the allowed values" : `Failed the "${keyword}" constraint`
1427
+ var echoableKey = (key) => /^[A-Za-z_$][\w$-]{0,63}$/.test(key);
1428
+ var schemaKey = (name) => echoableKey(name) ? name : JSON.stringify(name.slice(0, 64));
1429
+ var maxShapeKeys = 24;
1430
+ var objectShape = (keys, open, limit = maxShapeKeys) => {
1431
+ const listed = keys.slice(0, limit).map(({ name, optional }) => `${schemaKey(name)}${optional ? "?" : ""}`);
1432
+ const parts = [
1433
+ ...listed,
1434
+ ...keys.length > limit ? [`${keys.length - limit} more`] : [],
1435
+ ...open ? ["..."] : []
1436
+ ];
1437
+ return parts.length === 0 ? "object {} with no keys" : `object {${parts.join(", ")}}`;
1438
+ };
1439
+ var maxListedValues = 10;
1440
+ var maxValuesText = 200;
1441
+ var valueText = (value) => typeof value === "bigint" ? `${value}n` : JSON.stringify(value);
1442
+ var allowedValues = (values) => {
1443
+ const texts = [...new Set(values.map(valueText))];
1444
+ const listed = [];
1445
+ for (const text of texts) {
1446
+ if (listed.length === maxListedValues || [...listed, text].join(", ").length > maxValuesText)
1447
+ break;
1448
+ listed.push(text);
1449
+ }
1450
+ const [only] = listed;
1451
+ if (texts.length === 0) return "no value, since the schema allows none";
1452
+ if (only === void 0)
1453
+ return texts.length === 1 ? "a fixed value too long to list" : `one of ${texts.length} values too long to list`;
1454
+ if (texts.length === 1) return only;
1455
+ const rest = texts.length - listed.length;
1456
+ return `one of ${listed.join(", ")}${rest > 0 ? ` and ${rest} more` : ""}`;
1457
+ };
1458
+ var maxAlternativeKeys = 8;
1459
+ var maxAlternativesText = 360;
1460
+ var unionShape = (alternatives, selector) => {
1461
+ const listed = [];
1462
+ for (const alternative of alternatives) {
1463
+ if (listed.length > 0 && [...listed, alternative].join(" or ").length > maxAlternativesText)
1464
+ break;
1465
+ listed.push(alternative);
1466
+ }
1467
+ const rest = alternatives.length - listed.length;
1468
+ return `${[...listed, ...rest > 0 ? [`${rest} more`] : []].join(" or ")}${selector === void 0 ? "" : `, told apart by ${schemaKey(selector)}`}`;
1469
+ };
1470
+ var missingKey = (expected) => expected === void 0 ? missingKeyText : `${missingKeyText}. Expected ${expected}`;
1471
+ var missingKeyText = "Missing key";
1472
+ var isJsonRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1473
+ var pointerSegments = (pointer) => pointer === "#" || pointer === "" ? [] : pointer.replace(/^#?\//, "").split("/").map((segment) => decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~"));
1474
+ var resolved = (lookup, uri2) => typeof uri2 === "string" && Object.hasOwn(lookup, uri2) ? lookup[uri2] : void 0;
1475
+ var referenced = (lookup, node) => isJsonRecord(node) ? resolved(lookup, Reflect.get(node, "__absolute_ref__") ?? node.$ref) : void 0;
1476
+ var memberKeywords = /* @__PURE__ */ new Set([...schemaMaps, ...schemaArrays, "dependencies"]);
1477
+ var combinators = /* @__PURE__ */ new Set(["allOf", "anyOf", "oneOf"]);
1478
+ var schemaAt = (document, lookup, segments) => {
1479
+ const anchoredAt = (node2, anchor2) => anchor2 === null && isJsonRecord(node2) && node2.$recursiveAnchor === true ? node2 : anchor2;
1480
+ const pending = [...segments];
1481
+ let node = document;
1482
+ let anchor = anchoredAt(document, null);
1483
+ for (let keyword = pending.shift(); keyword !== void 0; keyword = pending.shift()) {
1484
+ if (!isJsonRecord(node)) return void 0;
1485
+ if (keyword === "$recursiveRef") {
1486
+ const target = anchor === null ? resolved(lookup, Reflect.get(node, "__absolute_recursive_ref__")) : anchor;
1487
+ if (anchor !== null) node = anchor;
1488
+ anchor = target;
1489
+ continue;
1490
+ }
1491
+ if (keyword === "$ref") node = referenced(lookup, node);
1492
+ else {
1493
+ const value = Object.hasOwn(node, keyword) ? node[keyword] : void 0;
1494
+ if (memberKeywords.has(keyword) || keyword === "items" && Array.isArray(value)) {
1495
+ const member = pending.shift();
1496
+ if (member === void 0) return value;
1497
+ if (combinators.has(keyword) && node.$recursiveAnchor !== true) anchor = null;
1498
+ node = Array.isArray(value) ? /^\d+$/.test(member) ? value[Number(member)] : void 0 : isJsonRecord(value) && Object.hasOwn(value, member) ? value[member] : void 0;
1499
+ } else node = value;
1500
+ }
1501
+ anchor = anchoredAt(node, anchor);
1502
+ }
1503
+ return node;
1504
+ };
1505
+ var jsonObjectShape = (node) => {
1506
+ if (!isJsonRecord(node)) return "object";
1507
+ const properties = isJsonRecord(node.properties) ? Object.keys(node.properties) : [];
1508
+ const required = new Set(Array.isArray(node.required) ? node.required : []);
1509
+ const open = node.additionalProperties !== false || isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0;
1510
+ return properties.length === 0 && open ? "object" : objectShape(
1511
+ properties.map((name) => ({ name, optional: !required.has(name) })),
1512
+ open
1513
+ );
1514
+ };
1515
+ var locationKey = (segments) => JSON.stringify(segments);
1516
+ var emptyOutline = {
1517
+ types: void 0,
1518
+ properties: /* @__PURE__ */ new Map(),
1519
+ required: /* @__PURE__ */ new Set(),
1520
+ closed: false,
1521
+ values: void 0
1522
+ };
1523
+ var commonValues = (a, b) => a === void 0 ? b : b === void 0 ? a : a.filter((value) => b.some((other) => deepCompareStrict(value, other)));
1524
+ var strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
1525
+ var commonTypes = (a, b) => new Set(
1526
+ [...a].flatMap(
1527
+ (type) => b.has(type) ? [type] : type === "number" && b.has("integer") || type === "integer" && b.has("number") ? ["integer"] : []
1528
+ )
1529
+ );
1530
+ var mergeOutlines = (a, b) => ({
1531
+ types: a.types === void 0 ? b.types : b.types === void 0 ? a.types : commonTypes(a.types, b.types),
1532
+ properties: new Map([...a.properties, ...b.properties]),
1533
+ required: /* @__PURE__ */ new Set([...a.required, ...b.required]),
1534
+ closed: a.closed || b.closed,
1535
+ values: commonValues(a.values, b.values)
1536
+ });
1537
+ var outlineOf = (node, inspection, seen = /* @__PURE__ */ new Set()) => {
1538
+ if (!isJsonRecord(node) || seen.has(node)) return emptyOutline;
1539
+ const within = /* @__PURE__ */ new Set([...seen, node]);
1540
+ const own = {
1541
+ types: typeof node.type === "string" ? /* @__PURE__ */ new Set([node.type]) : Array.isArray(node.type) ? new Set(strings(node.type)) : void 0,
1542
+ properties: new Map(isJsonRecord(node.properties) ? Object.entries(node.properties) : []),
1543
+ required: new Set(strings(node.required)),
1544
+ closed: (node.additionalProperties === false || node.unevaluatedProperties === false) && !(isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0),
1545
+ values: commonValues(
1546
+ Object.hasOwn(node, "const") ? [node.const] : void 0,
1547
+ Array.isArray(node.enum) ? node.enum : void 0
1548
+ )
1549
+ };
1550
+ return [inspection.referenced(node), ...Array.isArray(node.allOf) ? node.allOf : []].reduce(
1551
+ (outline, member) => mergeOutlines(outline, outlineOf(member, inspection, within)),
1552
+ own
1553
+ );
1554
+ };
1555
+ var otherConstraints = "a value with other constraints";
1556
+ var outlineText = (outline, limit) => {
1557
+ if (outline.values !== void 0) return allowedValues(outline.values);
1558
+ const names = [
1559
+ ...outline.properties.keys(),
1560
+ ...[...outline.required].filter((name) => !outline.properties.has(name))
1561
+ ];
1562
+ const shape = names.length === 0 && !outline.closed ? "object" : objectShape(
1563
+ names.map((name) => ({ name, optional: !outline.required.has(name) })),
1564
+ !outline.closed,
1565
+ limit
1566
+ );
1567
+ if (outline.types === void 0)
1568
+ return names.length > 0 || outline.closed ? shape : otherConstraints;
1569
+ return [...outline.types].map((type) => type === "object" ? shape : type).join(" or ");
1570
+ };
1571
+ var describeOutline = (outline) => outlineText(outline, maxAlternativeKeys);
1572
+ var typed = (outline) => outline.values !== void 0 || outline.types !== void 0;
1573
+ var describeProperty = (node, inspection) => {
1574
+ const target = inspection.referenced(node) ?? node;
1575
+ if (isJsonRecord(target) && Object.hasOwn(target, "oneOf")) return void 0;
1576
+ const outline = outlineOf(node, inspection);
1577
+ if (typed(outline)) return outlineText(outline, maxShapeKeys);
1578
+ const members = isJsonRecord(target) && Array.isArray(target.anyOf) ? target.anyOf : [];
1579
+ const outlines = members.filter((member) => member !== false).map((member) => outlineOf(member, inspection));
1580
+ return outlines.length === 0 || !outlines.every(typed) ? void 0 : unionShape([...new Set(outlines.map(describeOutline))], void 0);
1581
+ };
1582
+ var maxPatternText = 160;
1583
+ var count = (amount, noun) => `${amount} ${noun}${amount === 1 ? "" : "s"}`;
1584
+ var constraintProblem = (keyword, node) => {
1585
+ if (!isJsonRecord(node)) return void 0;
1586
+ const value = node[keyword];
1587
+ if (keyword === "pattern")
1588
+ return typeof value !== "string" ? void 0 : value.length <= maxPatternText ? `Expected a string matching the pattern ${JSON.stringify(value)}` : "Expected a string matching the schema's pattern, which is too long to show";
1589
+ if (keyword === "format")
1590
+ return typeof value === "string" ? `Expected a string in the ${JSON.stringify(value.slice(0, 64))} format` : void 0;
1591
+ if (keyword === "uniqueItems") return "Expected an array without repeated items";
1592
+ if (typeof value !== "number") return void 0;
1593
+ switch (keyword) {
1594
+ // Draft 4's boolean `exclusiveMinimum` is not applied: imported schemas validate as draft 7
1595
+ // or 2020-12, where `minimum` and `maximum` always include their bound.
1596
+ case "minimum":
1597
+ return `Expected a number of at least ${value}`;
1598
+ case "maximum":
1599
+ return `Expected a number of at most ${value}`;
1600
+ case "exclusiveMinimum":
1601
+ return `Expected a number greater than ${value}`;
1602
+ case "exclusiveMaximum":
1603
+ return `Expected a number less than ${value}`;
1604
+ case "multipleOf":
1605
+ return `Expected a multiple of ${value}`;
1606
+ case "minLength":
1607
+ return `Expected a string of at least ${count(value, "character")}`;
1608
+ case "maxLength":
1609
+ return `Expected a string of at most ${count(value, "character")}`;
1610
+ case "minItems":
1611
+ return `Expected an array of at least ${count(value, "item")}`;
1612
+ case "maxItems":
1613
+ return `Expected an array of at most ${count(value, "item")}`;
1614
+ case "minProperties":
1615
+ return `Expected an object with at least ${count(value, "key")}`;
1616
+ case "maxProperties":
1617
+ return `Expected an object with at most ${count(value, "key")}`;
1618
+ default:
1619
+ return void 0;
1620
+ }
1621
+ };
1622
+ var overlap = (outline, value, inspection, depth = 0) => !isJsonRecord(value) || depth > 16 ? 0 : Object.entries(value).reduce((total, [key, item]) => {
1623
+ const property = outline.properties.get(key);
1624
+ return property === void 0 ? total : total + 1 + overlap(outlineOf(property, inspection), item, inspection, depth + 1);
1625
+ }, 0);
1626
+ var jsonType = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value === "object" ? "object" : typeof value;
1627
+ var accepted = (outline, value) => {
1628
+ const type = jsonType(value);
1629
+ if (outline.values !== void 0)
1630
+ return outline.values.some((allowed) => jsonType(allowed) === type);
1631
+ if (outline.types === void 0) return true;
1632
+ return outline.types.has(type) || type === "number" && outline.types.has("integer") && Number.isInteger(value);
1633
+ };
1634
+ var valueAt = (input, location2) => location2.reduce(
1635
+ (value, segment) => Array.isArray(value) ? value[Number(segment)] : isJsonRecord(value) && Object.hasOwn(value, segment) ? value[segment] : void 0,
1636
+ input
1637
+ );
1638
+ var discriminatorOf = (holder) => isJsonRecord(holder) && isJsonRecord(holder.discriminator) ? holder.discriminator : void 0;
1639
+ var definitionName = (reference) => {
1640
+ if (typeof reference !== "string" || !reference.startsWith("#/")) return void 0;
1641
+ const segments = pointerSegments(reference);
1642
+ const container = segments.at(-2);
1643
+ return container === "$defs" || container === "definitions" || container === "schemas" && segments.at(-3) === "components" ? segments.at(-1) : void 0;
1644
+ };
1645
+ var discriminatedName = (holder, value) => {
1646
+ const discriminator = discriminatorOf(holder);
1647
+ if (discriminator === void 0 || typeof value !== "string") return void 0;
1648
+ const { mapping } = discriminator;
1649
+ const target = isJsonRecord(mapping) && Object.hasOwn(mapping, value) ? mapping[value] : value;
1650
+ if (typeof target !== "string") return void 0;
1651
+ return /^[\w.-]+$/.test(target) ? target : definitionName(target);
1652
+ };
1653
+ var selectorOf = (holder, alternatives, inspection) => {
1654
+ const declared = discriminatorOf(holder)?.propertyName;
1655
+ if (typeof declared === "string") return declared;
1656
+ const [first] = alternatives;
1657
+ if (first === void 0 || alternatives.length < 2) return void 0;
1658
+ return [...first.properties.keys()].find(
1659
+ (key) => alternatives.every(
1660
+ (alternative) => alternative.properties.has(key) && outlineOf(alternative.properties.get(key), inspection).values !== void 0
1661
+ )
1662
+ );
1663
+ };
1664
+ var alternativeErrors = (errors, head, schemas) => {
1665
+ const prefix = `${errors[head]?.keywordLocation}/`;
1666
+ const alternatives = /* @__PURE__ */ new Map();
1667
+ const settle = (current2, next) => {
1668
+ const collected = alternatives.get(current2);
1669
+ const rejected = Array.isArray(schemas) ? schemas.slice(current2 + 1, next).filter((schema) => schema === false).length : 0;
1670
+ if (collected !== void 0) collected.splice(collected.length - rejected, rejected);
1671
+ };
1672
+ let index = head + 1;
1673
+ let current = -1;
1674
+ for (; index < errors.length; index++) {
1675
+ const error = errors[index];
1676
+ if (error === void 0) break;
1677
+ if (error.keywordLocation.startsWith(prefix)) {
1678
+ const alternative = Number(error.keywordLocation.slice(prefix.length).split("/")[0]);
1679
+ if (alternative !== current) settle(current, alternative);
1680
+ current = alternative;
1681
+ } else if (error.keyword !== "false") break;
1682
+ if (current >= 0) alternatives.set(current, [...alternatives.get(current) ?? [], error]);
1683
+ }
1684
+ settle(current, Array.isArray(schemas) ? schemas.length : current);
1685
+ return { alternatives, end: index };
1686
+ };
1687
+ var pathOf = (location2) => location2.map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
1688
+ var unionProblems = (union, schemas, errorsByAlternative, inspection) => {
1689
+ const location2 = pointerSegments(union.instanceLocation);
1690
+ const path = pathOf(location2);
1691
+ if (!Array.isArray(schemas))
1692
+ return [
1693
+ { path, issue: `Failed the "${union.keyword}" constraint` },
1694
+ ...[...errorsByAlternative.values()].flatMap((errors) => problemsOf(errors, inspection))
1695
+ ];
1696
+ const alternatives = schemas.flatMap(
1697
+ (schema, index) => schema === false ? [] : [
1698
+ {
1699
+ schema,
1700
+ matched: !errorsByAlternative.has(index),
1701
+ problems: () => problemsOf(errorsByAlternative.get(index) ?? [], inspection)
1702
+ }
1703
+ ]
1704
+ );
1705
+ const [only] = alternatives;
1706
+ if (only === void 0) return [{ path, issue: "No value is allowed here" }];
1707
+ if (alternatives.length === 1) return only.problems();
1708
+ const holder = inspection.schemaAt(pointerSegments(union.keywordLocation).slice(0, -1));
1709
+ const shared = outlineOf(holder, inspection);
1710
+ const own = alternatives.map(({ schema }) => outlineOf(schema, inspection));
1711
+ const outlines = own.map((outline) => mergeOutlines(shared, outline));
1712
+ const selector = selectorOf(holder, own, inspection);
1713
+ const expected = `Expected ${unionShape(outlines.map(describeOutline), selector)}`;
1714
+ const matched = alternatives.filter((alternative) => alternative.matched).length;
1715
+ if (union.keyword === "oneOf" && matched > 1)
1716
+ return [{ path, issue: `${expected}. Exactly one may match, but ${matched} do` }];
1717
+ const fixed = outlines.flatMap(({ values }) => values === void 0 ? [] : [values]);
1718
+ if (fixed.length === outlines.length)
1719
+ return [
1720
+ {
1721
+ path,
1722
+ issue: union.keyword === "oneOf" ? `${expected}. Exactly one alternative must match` : `Expected ${allowedValues(fixed.flat())}`
1723
+ }
1724
+ ];
1725
+ const value = valueAt(inspection.input, location2);
1726
+ const selectorValue = selector !== void 0 && isJsonRecord(value) && Object.hasOwn(value, selector) ? { value: value[selector] } : void 0;
1727
+ const named = discriminatedName(holder, selectorValue?.value);
1728
+ const ranked = alternatives.map(({ schema, problems }, index) => {
1729
+ const outline = outlines[index] ?? emptyOutline;
1730
+ const property = own[index]?.properties.get(selector ?? "");
1731
+ return {
1732
+ index,
1733
+ problems: problems(),
1734
+ selected: selectorValue !== void 0 && (named !== void 0 && isJsonRecord(schema) && definitionName(schema.$ref) === named || property !== void 0 && outlineOf(property, inspection).values !== void 0 && inspection.accepts(property, selectorValue.value)),
1735
+ typed: accepted(outline, value),
1736
+ overlap: overlap(outline, value, inspection)
1286
1737
  };
1287
- return [issue];
1288
1738
  });
1739
+ const closest = ranked.reduce(
1740
+ (best, candidate) => ([
1741
+ Number(candidate.selected) - Number(best.selected),
1742
+ Number(candidate.typed) - Number(best.typed),
1743
+ candidate.overlap - best.overlap,
1744
+ best.problems.length - candidate.problems.length
1745
+ ].find((difference) => difference !== 0) ?? 0) > 0 ? candidate : best
1746
+ );
1747
+ return closest.selected || closest.typed ? [
1748
+ {
1749
+ path,
1750
+ issue: `${expected}. Closest is alternative ${closest.index + 1}, whose problems follow`
1751
+ },
1752
+ ...closest.problems
1753
+ ] : [{ path, issue: expected }];
1754
+ };
1755
+ var problemsOf = (errors, inspection) => {
1756
+ const closed = /* @__PURE__ */ new Map();
1757
+ const problems = [];
1758
+ for (let index = 0; index < errors.length; index++) {
1759
+ const error = errors[index];
1760
+ if (error === void 0) break;
1761
+ const { keyword, instanceLocation, keywordLocation } = error;
1762
+ if (keyword === "anyOf" || keyword === "oneOf") {
1763
+ const schemas = inspection.schemaAt(pointerSegments(keywordLocation));
1764
+ const { alternatives, end } = alternativeErrors(errors, index, schemas);
1765
+ problems.push(...unionProblems(error, schemas, alternatives, inspection));
1766
+ index = end - 1;
1767
+ continue;
1768
+ }
1769
+ const location2 = pointerSegments(instanceLocation);
1770
+ const path = pathOf(location2);
1771
+ const problem = (issue, at = path) => problems.push({ path: at, issue });
1772
+ const node = () => inspection.schemaAt(pointerSegments(keywordLocation).slice(0, -1));
1773
+ if (keyword === "additionalProperties" || keyword === "unevaluatedProperties") {
1774
+ closed.set(locationKey(location2), node());
1775
+ continue;
1776
+ }
1777
+ if (containerKeywords.has(keyword)) continue;
1778
+ if (keyword === "false") {
1779
+ const key = location2.at(-1);
1780
+ const parent = locationKey(location2.slice(0, -1));
1781
+ if (key === void 0 || !closed.has(parent)) problem("No value is allowed here");
1782
+ else
1783
+ problem(
1784
+ `Unexpected key${echoableKey(key) ? ` "${key}"` : ""}. Expected ${jsonObjectShape(closed.get(parent))}`,
1785
+ path.slice(0, -1)
1786
+ );
1787
+ continue;
1788
+ }
1789
+ const required = keyword === "required" ? /required property "([^"]*)"/.exec(error.error) : null;
1790
+ if (required !== null) {
1791
+ const name = required[1] ?? "";
1792
+ const property = outlineOf(node(), inspection).properties.get(name);
1793
+ problem(
1794
+ missingKey(property === void 0 ? void 0 : describeProperty(property, inspection)),
1795
+ [...path, name]
1796
+ );
1797
+ continue;
1798
+ }
1799
+ const expected = keyword === "type" ? /Expected "([^.]*)"\.?$/.exec(error.error) : null;
1800
+ if (expected !== null) {
1801
+ const types = (expected[1] ?? "").split('", "').map((type) => type === "object" ? jsonObjectShape(node()) : type);
1802
+ problem(`Expected ${types.join(" or ")}`);
1803
+ continue;
1804
+ }
1805
+ if (keyword === "const" || keyword === "enum") {
1806
+ const schema = node();
1807
+ const values = !isJsonRecord(schema) ? void 0 : keyword === "const" ? Object.hasOwn(schema, "const") ? [schema.const] : void 0 : Array.isArray(schema.enum) ? schema.enum : void 0;
1808
+ problem(
1809
+ values === void 0 ? "Expected one of the allowed values" : `Expected ${allowedValues(values)}`
1810
+ );
1811
+ continue;
1812
+ }
1813
+ problem(constraintProblem(keyword, node()) ?? `Failed the "${keyword}" constraint`);
1814
+ }
1815
+ return problems;
1816
+ };
1817
+ var documentKeys = (document) => {
1818
+ const named = /* @__PURE__ */ new Set();
1819
+ let any = false;
1820
+ const visit = (node, depth) => {
1821
+ if (depth > 64 || typeof node !== "object" || node === null) return;
1822
+ if (Array.isArray(node)) {
1823
+ for (const item of node) visit(item, depth + 1);
1824
+ return;
1825
+ }
1826
+ const record2 = node;
1827
+ if (isJsonRecord(record2.properties))
1828
+ for (const name of Object.keys(record2.properties)) named.add(name);
1829
+ for (const name of strings(record2.required)) named.add(name);
1830
+ if (isJsonRecord(record2.dependentRequired))
1831
+ for (const [name, names] of Object.entries(record2.dependentRequired)) {
1832
+ named.add(name);
1833
+ for (const other of strings(names)) named.add(other);
1834
+ }
1835
+ if (isJsonRecord(record2.patternProperties) && Object.keys(record2.patternProperties).length > 0 || isJsonRecord(record2.additionalProperties) || isJsonRecord(record2.unevaluatedProperties))
1836
+ any = true;
1837
+ for (const value of Object.values(record2)) visit(value, depth + 1);
1838
+ };
1839
+ visit(document, 0);
1840
+ return (key) => any || named.has(key);
1841
+ };
1842
+ var importedKeys = /* @__PURE__ */ new WeakMap();
1843
+ var importedSchemaKeys = (check) => importedKeys.get(check);
1844
+ var jsonSchemaProblems = (errors, inspection) => {
1845
+ const problems = problemsOf(errors, inspection);
1289
1846
  return problems.length === 0 ? false : problems;
1290
1847
  };
1291
1848
  var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
@@ -1296,8 +1853,7 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
1296
1853
  if (normalized === null || typeof normalized !== "object" || Array.isArray(normalized))
1297
1854
  throw new ValidationError();
1298
1855
  const lookup = dereference(normalized);
1299
- for (const schema of new Set(Object.values(lookup))) {
1300
- if (typeof schema === "boolean") continue;
1856
+ for (const schema of evaluatedSchemas(normalized, lookup)) {
1301
1857
  for (const pattern of [schema.pattern, ...Object.keys(schema.patternProperties ?? {})]) {
1302
1858
  if (pattern === void 0) continue;
1303
1859
  try {
@@ -1312,28 +1868,42 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
1312
1868
  throw new ValidationError();
1313
1869
  }
1314
1870
  }
1871
+ const inspection = (input) => ({
1872
+ schemaAt: (segments) => schemaAt(normalized, lookup, segments),
1873
+ referenced: (node) => referenced(lookup, node),
1874
+ accepts: (node, value) => {
1875
+ if (typeof node !== "boolean" && !isJsonRecord(node)) return false;
1876
+ try {
1877
+ return validate(value, node, draft, lookup).valid;
1878
+ } catch {
1879
+ return false;
1880
+ }
1881
+ },
1882
+ input
1883
+ });
1315
1884
  return {
1316
- validate: (input) => validate(input, normalized, draft, lookup)
1885
+ validate: (input) => validate(input, normalized, draft, lookup),
1886
+ inspection
1317
1887
  };
1318
1888
  },
1319
1889
  catch: () => new ValidationError()
1320
1890
  });
1321
- const decoder = Schema_exports.Json.check(
1322
- Schema_exports.makeFilter(
1323
- (value) => {
1324
- try {
1325
- const result = validator.validate(value);
1326
- return result.valid || jsonSchemaProblems(result.errors);
1327
- } catch {
1328
- return false;
1329
- }
1330
- },
1331
- { expected: "a value matching a supported imported JSON Schema" }
1332
- )
1891
+ const check = Schema_exports.makeFilter(
1892
+ (value) => {
1893
+ try {
1894
+ const result = validator.validate(value);
1895
+ return result.valid || jsonSchemaProblems(result.errors, validator.inspection(value));
1896
+ } catch {
1897
+ return false;
1898
+ }
1899
+ },
1900
+ { expected: "a value matching a supported imported JSON Schema" }
1333
1901
  );
1902
+ importedKeys.set(check, documentKeys(document));
1903
+ const decoder = Schema_exports.Json.check(check);
1334
1904
  return Object.assign(decoder, { [ImportedJsonSchema]: document });
1335
1905
  });
1336
- var lazyDecoder = (document) => {
1906
+ var lazyCompiledDecoder = (document) => {
1337
1907
  const read = once(document);
1338
1908
  let compiled;
1339
1909
  const compile = Effect_exports.suspend(
@@ -1353,9 +1923,11 @@ var lazyDecoder = (document) => {
1353
1923
  Effect_exports.flatMap((schema) => SchemaParser_exports.decodeUnknownEffect(schema)(input, options))
1354
1924
  )
1355
1925
  );
1356
- return withLazyJsonSchemaDocument(decoder, read);
1926
+ return { decoder: withLazyJsonSchemaDocument(decoder, read), compile };
1357
1927
  };
1928
+ var lazyDecoder = (document) => lazyCompiledDecoder(document).decoder;
1358
1929
  var lazyJsonSchemaDecoder = (document) => Effect_exports.sync(() => lazyDecoder(document));
1930
+ var preparedJsonSchemaDecoder = (document) => lazyCompiledDecoder(() => document);
1359
1931
  var isJsonValue = Schema_exports.is(Schema_exports.Json);
1360
1932
  var jsonDocument = (input) => {
1361
1933
  if (typeof input !== "object" || input === null || Array.isArray(input)) return void 0;
@@ -1385,9 +1957,6 @@ var jsonSchema = (input) => {
1385
1957
  false
1386
1958
  );
1387
1959
  };
1388
- var storageFieldOf = (schema) => schema[StorageField];
1389
- var id = (table) => wrap(Schema_exports.NonEmptyString, false, { kind: "id", references: table });
1390
- var userId = () => wrap(Schema_exports.NonEmptyString, false, { kind: "userId" });
1391
1960
  var jsonSchemaDocument = (decoder) => {
1392
1961
  const imported = importedJsonSchema(decoder);
1393
1962
  if (imported !== void 0) return Schema_exports.decodeUnknownEffect(JsonObject)(imported);
@@ -1402,7 +1971,9 @@ var jsonSchemaDocument = (decoder) => {
1402
1971
  export {
1403
1972
  decoderOf,
1404
1973
  isSchema,
1974
+ schemaArgument,
1405
1975
  parse,
1976
+ parseDeclaration,
1406
1977
  wrap,
1407
1978
  string,
1408
1979
  number,
@@ -1412,16 +1983,26 @@ export {
1412
1983
  literal,
1413
1984
  array,
1414
1985
  object,
1986
+ plain,
1987
+ raw,
1988
+ fieldExposure,
1415
1989
  importedJsonSchema,
1416
1990
  once,
1417
1991
  withLazyJsonSchemaDocument,
1418
1992
  nestJsonSchema,
1993
+ combineJsonSchemas,
1994
+ echoableKey,
1995
+ objectShape,
1996
+ allowedValues,
1997
+ maxAlternativeKeys,
1998
+ unionShape,
1999
+ missingKey,
2000
+ missingKeyText,
2001
+ importedSchemaKeys,
1419
2002
  compileJsonSchemaDecoder,
1420
2003
  lazyJsonSchemaDecoder,
2004
+ preparedJsonSchemaDecoder,
1421
2005
  jsonSchemaDecoder,
1422
2006
  jsonSchema,
1423
- storageFieldOf,
1424
- id,
1425
- userId,
1426
2007
  jsonSchemaDocument
1427
2008
  };