pi-proactive 0.2.0-beta.2 → 0.2.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +32 -28
  3. package/build/cli.mjs +121 -0
  4. package/build/extensions/proactive.js +47 -6
  5. package/build/src/commands.js +78 -2
  6. package/build/src/config.js +511 -4
  7. package/build/src/daemon-config.js +221 -0
  8. package/build/src/daemon-contact.js +103 -0
  9. package/build/src/daemon-host.js +84 -0
  10. package/build/src/daemon.js +193 -3
  11. package/build/src/health.js +84 -0
  12. package/build/src/lineage.js +41 -2
  13. package/build/src/notify.js +183 -0
  14. package/build/src/progress-eta.js +134 -0
  15. package/build/src/trigger.js +43 -0
  16. package/build/src/trust-loop.js +321 -0
  17. package/build/src/trust-metrics.js +236 -0
  18. package/build/src/trust-notify.js +73 -0
  19. package/build/src/trust-policy.js +58 -0
  20. package/build/src/trust-registry.js +323 -0
  21. package/daemon/launchd.plist +48 -0
  22. package/daemon/pi-proactive-daemon.service +29 -0
  23. package/daemon/run-daemon.sh +84 -0
  24. package/node_modules/typebox/build/compile/code.mjs +2 -1
  25. package/node_modules/typebox/build/compile/validator.mjs +1 -5
  26. package/node_modules/typebox/build/format/date_time.d.mts +1 -2
  27. package/node_modules/typebox/build/format/date_time.mjs +3 -12
  28. package/node_modules/typebox/build/format/duration.d.mts +2 -2
  29. package/node_modules/typebox/build/format/duration.mjs +2 -2
  30. package/node_modules/typebox/build/format/idn_email.d.mts +0 -1
  31. package/node_modules/typebox/build/format/idn_email.mjs +0 -1
  32. package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
  33. package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
  34. package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
  35. package/node_modules/typebox/build/format/ipv4.mjs +2 -2
  36. package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
  37. package/node_modules/typebox/build/format/ipv6.mjs +1 -1
  38. package/node_modules/typebox/build/format/iri.mjs +9 -16
  39. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  40. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  41. package/node_modules/typebox/build/guard/emit.mjs +2 -2
  42. package/node_modules/typebox/build/guard/guard.d.mts +5 -7
  43. package/node_modules/typebox/build/guard/guard.mjs +9 -14
  44. package/node_modules/typebox/build/guard/index.mjs +0 -6
  45. package/node_modules/typebox/build/guard/{unicode/unicode_segment.mjs → string.mjs} +19 -16
  46. package/node_modules/typebox/build/schema/build.mjs +5 -5
  47. package/node_modules/typebox/build/schema/check.mjs +1 -1
  48. package/node_modules/typebox/build/schema/engine/_context.d.mts +1 -5
  49. package/node_modules/typebox/build/schema/engine/_context.mjs +3 -16
  50. package/node_modules/typebox/build/schema/engine/_functions.d.mts +2 -2
  51. package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -1
  52. package/node_modules/typebox/build/schema/engine/_reducer.d.mts +3 -3
  53. package/node_modules/typebox/build/schema/engine/_refine.d.mts +5 -5
  54. package/node_modules/typebox/build/schema/engine/_refine.mjs +9 -14
  55. package/node_modules/typebox/build/schema/engine/_stack.d.mts +20 -34
  56. package/node_modules/typebox/build/schema/engine/_stack.mjs +202 -143
  57. package/node_modules/typebox/build/schema/engine/_unique.d.mts +2 -4
  58. package/node_modules/typebox/build/schema/engine/_unique.mjs +3 -7
  59. package/node_modules/typebox/build/schema/engine/additionalItems.d.mts +4 -4
  60. package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
  61. package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +8 -5
  62. package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +32 -27
  63. package/node_modules/typebox/build/schema/engine/allOf.d.mts +4 -4
  64. package/node_modules/typebox/build/schema/engine/allOf.mjs +1 -1
  65. package/node_modules/typebox/build/schema/engine/anyOf.d.mts +4 -4
  66. package/node_modules/typebox/build/schema/engine/anyOf.mjs +9 -4
  67. package/node_modules/typebox/build/schema/engine/boolean.d.mts +4 -4
  68. package/node_modules/typebox/build/schema/engine/boolean.mjs +6 -2
  69. package/node_modules/typebox/build/schema/engine/const.d.mts +4 -4
  70. package/node_modules/typebox/build/schema/engine/const.mjs +6 -2
  71. package/node_modules/typebox/build/schema/engine/contains.d.mts +4 -4
  72. package/node_modules/typebox/build/schema/engine/contains.mjs +9 -5
  73. package/node_modules/typebox/build/schema/engine/dependencies.d.mts +4 -4
  74. package/node_modules/typebox/build/schema/engine/dependencies.mjs +7 -5
  75. package/node_modules/typebox/build/schema/engine/dependentRequired.d.mts +4 -4
  76. package/node_modules/typebox/build/schema/engine/dependentRequired.mjs +6 -2
  77. package/node_modules/typebox/build/schema/engine/dependentSchemas.d.mts +4 -4
  78. package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +1 -2
  79. package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +4 -4
  80. package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +8 -12
  81. package/node_modules/typebox/build/schema/engine/enum.d.mts +4 -4
  82. package/node_modules/typebox/build/schema/engine/enum.mjs +6 -2
  83. package/node_modules/typebox/build/schema/engine/exclusiveMaximum.d.mts +4 -4
  84. package/node_modules/typebox/build/schema/engine/exclusiveMaximum.mjs +6 -2
  85. package/node_modules/typebox/build/schema/engine/exclusiveMinimum.d.mts +4 -4
  86. package/node_modules/typebox/build/schema/engine/exclusiveMinimum.mjs +6 -2
  87. package/node_modules/typebox/build/schema/engine/format.d.mts +4 -4
  88. package/node_modules/typebox/build/schema/engine/format.mjs +8 -11
  89. package/node_modules/typebox/build/schema/engine/if.d.mts +4 -4
  90. package/node_modules/typebox/build/schema/engine/if.mjs +13 -5
  91. package/node_modules/typebox/build/schema/engine/index.d.mts +0 -1
  92. package/node_modules/typebox/build/schema/engine/index.mjs +0 -1
  93. package/node_modules/typebox/build/schema/engine/items.d.mts +4 -4
  94. package/node_modules/typebox/build/schema/engine/items.mjs +5 -8
  95. package/node_modules/typebox/build/schema/engine/maxContains.d.mts +4 -4
  96. package/node_modules/typebox/build/schema/engine/maxContains.mjs +8 -4
  97. package/node_modules/typebox/build/schema/engine/maxItems.d.mts +4 -4
  98. package/node_modules/typebox/build/schema/engine/maxItems.mjs +6 -2
  99. package/node_modules/typebox/build/schema/engine/maxLength.d.mts +4 -4
  100. package/node_modules/typebox/build/schema/engine/maxLength.mjs +6 -2
  101. package/node_modules/typebox/build/schema/engine/maxProperties.d.mts +4 -4
  102. package/node_modules/typebox/build/schema/engine/maxProperties.mjs +6 -2
  103. package/node_modules/typebox/build/schema/engine/maximum.d.mts +4 -4
  104. package/node_modules/typebox/build/schema/engine/maximum.mjs +6 -2
  105. package/node_modules/typebox/build/schema/engine/minContains.d.mts +4 -4
  106. package/node_modules/typebox/build/schema/engine/minContains.mjs +9 -5
  107. package/node_modules/typebox/build/schema/engine/minItems.d.mts +5 -5
  108. package/node_modules/typebox/build/schema/engine/minItems.mjs +6 -2
  109. package/node_modules/typebox/build/schema/engine/minLength.d.mts +4 -4
  110. package/node_modules/typebox/build/schema/engine/minLength.mjs +6 -2
  111. package/node_modules/typebox/build/schema/engine/minProperties.d.mts +4 -4
  112. package/node_modules/typebox/build/schema/engine/minProperties.mjs +6 -2
  113. package/node_modules/typebox/build/schema/engine/minimum.d.mts +4 -4
  114. package/node_modules/typebox/build/schema/engine/minimum.mjs +6 -2
  115. package/node_modules/typebox/build/schema/engine/multipleOf.d.mts +4 -4
  116. package/node_modules/typebox/build/schema/engine/multipleOf.mjs +6 -2
  117. package/node_modules/typebox/build/schema/engine/not.d.mts +4 -4
  118. package/node_modules/typebox/build/schema/engine/not.mjs +8 -4
  119. package/node_modules/typebox/build/schema/engine/oneOf.d.mts +4 -4
  120. package/node_modules/typebox/build/schema/engine/oneOf.mjs +11 -6
  121. package/node_modules/typebox/build/schema/engine/pattern.d.mts +4 -4
  122. package/node_modules/typebox/build/schema/engine/pattern.mjs +7 -3
  123. package/node_modules/typebox/build/schema/engine/patternProperties.d.mts +4 -4
  124. package/node_modules/typebox/build/schema/engine/patternProperties.mjs +5 -6
  125. package/node_modules/typebox/build/schema/engine/prefixItems.d.mts +4 -4
  126. package/node_modules/typebox/build/schema/engine/prefixItems.mjs +1 -1
  127. package/node_modules/typebox/build/schema/engine/properties.d.mts +4 -4
  128. package/node_modules/typebox/build/schema/engine/properties.mjs +3 -4
  129. package/node_modules/typebox/build/schema/engine/propertyNames.d.mts +4 -4
  130. package/node_modules/typebox/build/schema/engine/propertyNames.mjs +10 -7
  131. package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +4 -4
  132. package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +8 -12
  133. package/node_modules/typebox/build/schema/engine/ref.d.mts +4 -4
  134. package/node_modules/typebox/build/schema/engine/ref.mjs +14 -18
  135. package/node_modules/typebox/build/schema/engine/required.d.mts +4 -4
  136. package/node_modules/typebox/build/schema/engine/required.mjs +6 -2
  137. package/node_modules/typebox/build/schema/engine/schema.d.mts +7 -7
  138. package/node_modules/typebox/build/schema/engine/schema.mjs +138 -136
  139. package/node_modules/typebox/build/schema/engine/type.d.mts +4 -4
  140. package/node_modules/typebox/build/schema/engine/type.mjs +6 -2
  141. package/node_modules/typebox/build/schema/engine/unevaluatedItems.d.mts +4 -4
  142. package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +9 -5
  143. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.d.mts +4 -4
  144. package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +9 -5
  145. package/node_modules/typebox/build/schema/engine/uniqueItems.d.mts +4 -4
  146. package/node_modules/typebox/build/schema/engine/uniqueItems.mjs +6 -2
  147. package/node_modules/typebox/build/schema/errors.mjs +1 -1
  148. package/node_modules/typebox/build/schema/intern/intern.d.mts +9 -6
  149. package/node_modules/typebox/build/schema/intern/intern.mjs +56 -90
  150. package/node_modules/typebox/build/schema/parse.mjs +0 -3
  151. package/node_modules/typebox/build/schema/pointer/pointer.d.mts +6 -1
  152. package/node_modules/typebox/build/schema/pointer/pointer.mjs +64 -47
  153. package/node_modules/typebox/build/schema/resolve/resolve.d.mts +32 -6
  154. package/node_modules/typebox/build/schema/resolve/resolve.mjs +227 -231
  155. package/node_modules/typebox/build/schema/schema.d.mts +0 -1
  156. package/node_modules/typebox/build/schema/schema.mjs +0 -1
  157. package/node_modules/typebox/build/system/hashing/hash.mjs +34 -63
  158. package/node_modules/typebox/build/system/locale/en_US.mjs +1 -2
  159. package/node_modules/typebox/build/system/memory/assign.d.mts +8 -2
  160. package/node_modules/typebox/build/system/memory/assign.mjs +6 -13
  161. package/node_modules/typebox/build/system/memory/clone.d.mts +5 -4
  162. package/node_modules/typebox/build/system/memory/clone.mjs +96 -8
  163. package/node_modules/typebox/build/system/memory/create.d.mts +5 -1
  164. package/node_modules/typebox/build/system/memory/create.mjs +13 -18
  165. package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
  166. package/node_modules/typebox/build/system/memory/discard.mjs +8 -9
  167. package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
  168. package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
  169. package/node_modules/typebox/build/system/memory/update.d.mts +4 -1
  170. package/node_modules/typebox/build/system/memory/update.mjs +16 -43
  171. package/node_modules/typebox/build/system/settings/settings.d.mts +0 -11
  172. package/node_modules/typebox/build/system/settings/settings.mjs +0 -14
  173. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +24 -2
  174. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +29 -2
  175. package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +0 -1
  176. package/node_modules/typebox/build/type/engine/evaluate/index.mjs +0 -1
  177. package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +1 -5
  178. package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +1 -6
  179. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +3 -1
  180. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +4 -1
  181. package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
  182. package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
  183. package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
  184. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  185. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +3 -1
  186. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +4 -1
  187. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +3 -1
  188. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +4 -1
  189. package/node_modules/typebox/build/type/extends/inference.d.mts +1 -1
  190. package/node_modules/typebox/build/type/extends/inference.mjs +2 -15
  191. package/node_modules/typebox/build/type/extends/tuple.d.mts +1 -2
  192. package/node_modules/typebox/build/type/extends/tuple.mjs +1 -21
  193. package/node_modules/typebox/build/value/clean/from_object.mjs +1 -1
  194. package/node_modules/typebox/build/value/clone/clone.d.mts +3 -4
  195. package/node_modules/typebox/build/value/clone/clone.mjs +7 -5
  196. package/node_modules/typebox/build/value/parse/parse.mjs +4 -10
  197. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +14 -25
  198. package/node_modules/typebox/package.json +1 -1
  199. package/node_modules/typebox/readme.md +84 -52
  200. package/package.json +11 -3
  201. package/skills/pi-proactive/SKILL.md +27 -24
  202. package/tools/cli.mjs +121 -0
  203. package/tools/daemon-install.sh +397 -0
  204. package/tools/daemon-uninstall.sh +226 -0
  205. package/node_modules/typebox/build/guard/unicode/unicode.d.mts +0 -6
  206. package/node_modules/typebox/build/guard/unicode/unicode.mjs +0 -35
  207. package/node_modules/typebox/build/schema/engine/_pathing.d.mts +0 -1
  208. package/node_modules/typebox/build/schema/engine/_pathing.mjs +0 -11
  209. package/node_modules/typebox/build/schema/meta/draft_2019_09.d.mts +0 -2
  210. package/node_modules/typebox/build/schema/meta/draft_2019_09.mjs +0 -288
  211. package/node_modules/typebox/build/schema/meta/draft_2020_12.d.mts +0 -2
  212. package/node_modules/typebox/build/schema/meta/draft_2020_12.mjs +0 -300
  213. package/node_modules/typebox/build/schema/meta/draft_3.d.mts +0 -2
  214. package/node_modules/typebox/build/schema/meta/draft_3.mjs +0 -143
  215. package/node_modules/typebox/build/schema/meta/draft_4.d.mts +0 -2
  216. package/node_modules/typebox/build/schema/meta/draft_4.mjs +0 -149
  217. package/node_modules/typebox/build/schema/meta/draft_6.d.mts +0 -2
  218. package/node_modules/typebox/build/schema/meta/draft_6.mjs +0 -155
  219. package/node_modules/typebox/build/schema/meta/draft_7.d.mts +0 -2
  220. package/node_modules/typebox/build/schema/meta/draft_7.mjs +0 -172
  221. package/node_modules/typebox/build/schema/meta/index.d.mts +0 -2
  222. package/node_modules/typebox/build/schema/meta/index.mjs +0 -2
  223. package/node_modules/typebox/build/schema/meta/meta.d.mts +0 -9
  224. package/node_modules/typebox/build/schema/meta/meta.mjs +0 -15
  225. package/node_modules/typebox/build/schema/meta/schema.d.mts +0 -6
  226. package/node_modules/typebox/build/schema/meta/schema.mjs +0 -1
  227. package/node_modules/typebox/build/system/memory/deep.d.mts +0 -2
  228. package/node_modules/typebox/build/system/memory/deep.mjs +0 -108
  229. package/node_modules/typebox/build/system/memory/finalize.d.mts +0 -4
  230. package/node_modules/typebox/build/system/memory/finalize.mjs +0 -30
  231. package/node_modules/typebox/build/system/memory/keys.d.mts +0 -2
  232. package/node_modules/typebox/build/system/memory/keys.mjs +0 -8
  233. package/node_modules/typebox/build/system/settings/internal.d.mts +0 -2
  234. package/node_modules/typebox/build/system/settings/internal.mjs +0 -20
  235. package/node_modules/typebox/build/type/engine/call/index.d.mts +0 -1
  236. package/node_modules/typebox/build/type/engine/call/index.mjs +0 -1
  237. package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +0 -30
  238. package/node_modules/typebox/build/type/engine/evaluate/property.mjs +0 -29
  239. package/node_modules/typebox/build/type/engine/this/index.d.mts +0 -1
  240. package/node_modules/typebox/build/type/engine/this/index.mjs +0 -1
  241. package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +0 -2
  242. package/node_modules/typebox/build/value/repair/from_cyclic.mjs +0 -6
  243. /package/node_modules/typebox/build/guard/{unicode/unicode_segment.d.mts → string.d.mts} +0 -0
@@ -1,9 +1,13 @@
1
- import { Arguments } from '../../system/arguments/index.mjs';
2
1
  import { Hashing, Memory } from '../../system/index.mjs';
3
- import * as Schema from '../types/index.mjs';
4
- import * as Stack from '../engine/_stack.mjs';
5
2
  import { Guard } from '../../guard/index.mjs';
6
3
  import { Resolve } from '../resolve/index.mjs';
4
+ import * as S from '../types/index.mjs';
5
+ // ----------------------------------------------------------------
6
+ // UnsupportedKeyword
7
+ // ----------------------------------------------------------------
8
+ function UnsupportedKeyword(keyword) {
9
+ throw Error(`UnsupportedKeyword '${keyword}'`);
10
+ }
7
11
  // ----------------------------------------------------------------
8
12
  // UnresolvableRef
9
13
  // ----------------------------------------------------------------
@@ -68,7 +72,7 @@ function FromIf(context, schema) {
68
72
  // Items
69
73
  // ----------------------------------------------------------------
70
74
  function FromItems(context, schema) {
71
- return Schema.IsItemsSized(schema) ? FromItemsSized(context, schema) : FromItemsUnsized(context, schema);
75
+ return S.IsItemsSized(schema) ? FromItemsSized(context, schema) : FromItemsUnsized(context, schema);
72
76
  }
73
77
  // ----------------------------------------------------------------
74
78
  // ItemsSized
@@ -121,59 +125,21 @@ function FromPropertyNames(context, schema) {
121
125
  // ----------------------------------------------------------------
122
126
  // Ref
123
127
  // ----------------------------------------------------------------
124
- function ResolveRef(stack, ref) {
125
- const result = Resolve.Ref(stack, { $ref: ref });
126
- return { schema: result.schema ?? UnresolvableRef(ref), stack: result.stack };
127
- }
128
- // ----------------------------------------------------------------
129
- // DynamicRef
130
- // ----------------------------------------------------------------
131
- function ResolveDynamicRef(stack, schema) {
132
- return Resolve.DynamicRef(stack, schema) ?? UnresolvableRef(schema.$dynamicRef);
128
+ function ResolveRef(context, schema, ref) {
129
+ return Resolve.Ref(context, schema, Resolve.DefaultBase, ref) ?? UnresolvableRef(ref);
133
130
  }
134
- // ----------------------------------------------------------------
135
- // RecursiveRef
136
- // ----------------------------------------------------------------
137
- function ResolveRecursiveRef(stack, schema) {
138
- return Resolve.RecursiveRef(stack, schema) ?? UnresolvableRef(schema.$recursiveRef);
139
- }
140
- // ----------------------------------------------------------------
141
- // FromResolvedRef (shared logic for Ref, DynamicRef, RecursiveRef)
142
- // ----------------------------------------------------------------
143
- function FromResolvedRef(context, target, nextStack) {
144
- const nextContext = { ...context, stack: nextStack };
131
+ function FromRef(context, schema) {
132
+ // Resolve target
133
+ const target = ResolveRef(context.context, context.schema, schema.$ref);
134
+ // Check if target is resolving, if not, resolve
145
135
  const resolving = context.resolving.get(target);
146
136
  if (Guard.IsUndefined(resolving))
147
- return FromSchema(nextContext, target);
137
+ return FromSchema(context, target);
148
138
  // Target is mid-intern, so this is a cycle (point at its reserved placeholder)
149
139
  resolving.used = true;
150
140
  return { $ref: `#/$defs/${resolving.key}` };
151
141
  }
152
142
  // ----------------------------------------------------------------
153
- // FromRef
154
- // ----------------------------------------------------------------
155
- function FromRef(context, schema) {
156
- // Resolve target off the current traversal stack, carrying forward any resource crossing
157
- const { schema: target, stack } = ResolveRef(context.stack, schema.$ref);
158
- return FromResolvedRef(context, target, stack);
159
- }
160
- // ----------------------------------------------------------------
161
- // FromDynamicRef
162
- // ----------------------------------------------------------------
163
- function FromDynamicRef(context, schema) {
164
- // Resolve target off the current traversal stack (dynamic scope depends on anchors seen so far)
165
- const target = ResolveDynamicRef(context.stack, schema);
166
- return FromResolvedRef(context, target, { ...context.stack, pendingResource: true });
167
- }
168
- // ----------------------------------------------------------------
169
- // FromRecursiveRef
170
- // ----------------------------------------------------------------
171
- function FromRecursiveRef(context, schema) {
172
- // Resolve target off the current traversal stack (recursive scope depends on the path taken so far)
173
- const target = ResolveRecursiveRef(context.stack, schema);
174
- return FromResolvedRef(context, target, { ...context.stack, pendingResource: true });
175
- }
176
- // ----------------------------------------------------------------
177
143
  // Then
178
144
  // ----------------------------------------------------------------
179
145
  function FromThen(context, schema) {
@@ -195,45 +161,46 @@ function FromUnevaluatedProperties(context, schema) {
195
161
  // SchemaObject
196
162
  // ----------------------------------------------------------------
197
163
  function FromSchemaObject(context, schema) {
198
- // Reference-style schemas resolve to another node and cannot contain other keywords
199
- if (Schema.IsRef(schema))
164
+ // Reference schemas cannot contain other keywords
165
+ if (S.IsRef(schema))
200
166
  return FromRef(context, schema);
201
- if (Schema.IsDynamicRef(schema))
202
- return FromDynamicRef(context, schema);
203
- if (Schema.IsRecursiveRef(schema))
204
- return FromRecursiveRef(context, schema);
205
167
  // Check if the schema has already been resolved
206
168
  const existing = resolved.get(schema);
207
169
  if (!Guard.IsUndefined(existing))
208
170
  return existing;
171
+ // These keywords are unsupported
172
+ if (S.IsDynamicRef(schema))
173
+ UnsupportedKeyword('$dynamicRef');
174
+ if (S.IsRecursiveRef(schema))
175
+ UnsupportedKeyword('$recursiveRef');
209
176
  // Reserve a placeholder key in case a nested ref cycles back to this schema
210
177
  const reservation = { key: `x-ref-${context.resolving.size}`, used: false };
211
178
  context.resolving.set(schema, reservation);
212
179
  // Intern each subschema
213
180
  const remapped = {
214
- ...(Schema.IsRefine(schema) ? { ['~refine']: schema['~refine'] } : {}),
215
- ...(Schema.IsAdditionalItems(schema) ? { additionalItems: FromAdditionalItems(context, schema) } : {}),
216
- ...(Schema.IsAdditionalProperties(schema) ? { additionalProperties: FromAdditionalProperties(context, schema) } : {}),
217
- ...(Schema.IsAllOf(schema) ? { allOf: FromAllOf(context, schema) } : {}),
218
- ...(Schema.IsAnyOf(schema) ? { anyOf: FromAnyOf(context, schema) } : {}),
219
- ...(Schema.IsContains(schema) ? { contains: FromContains(context, schema) } : {}),
220
- ...(Schema.IsDependentSchemas(schema) ? { dependentSchemas: FromDependentSchemas(context, schema) } : {}),
221
- ...(Schema.IsElse(schema) ? { else: FromElse(context, schema) } : {}),
222
- ...(Schema.IsIf(schema) ? { if: FromIf(context, schema) } : {}),
223
- ...(Schema.IsItems(schema) ? { items: FromItems(context, schema) } : {}),
224
- ...(Schema.IsNot(schema) ? { not: FromNot(context, schema) } : {}),
225
- ...(Schema.IsOneOf(schema) ? { oneOf: FromOneOf(context, schema) } : {}),
226
- ...(Schema.IsPatternProperties(schema) ? { patternProperties: FromPatternProperties(context, schema) } : {}),
227
- ...(Schema.IsPrefixItems(schema) ? { prefixItems: FromPrefixItems(context, schema) } : {}),
228
- ...(Schema.IsProperties(schema) ? { properties: FromProperties(context, schema) } : {}),
229
- ...(Schema.IsPropertyNames(schema) ? { propertyNames: FromPropertyNames(context, schema) } : {}),
230
- ...(Schema.IsThen(schema) ? { then: FromThen(context, schema) } : {}),
231
- ...(Schema.IsUnevaluatedItems(schema) ? { unevaluatedItems: FromUnevaluatedItems(context, schema) } : {}),
232
- ...(Schema.IsUnevaluatedProperties(schema) ? { unevaluatedProperties: FromUnevaluatedProperties(context, schema) } : {})
181
+ ...(S.IsRefine(schema) ? { ['~refine']: schema['~refine'] } : {}),
182
+ ...(S.IsAdditionalItems(schema) ? { additionalItems: FromAdditionalItems(context, schema) } : {}),
183
+ ...(S.IsAdditionalProperties(schema) ? { additionalProperties: FromAdditionalProperties(context, schema) } : {}),
184
+ ...(S.IsAllOf(schema) ? { allOf: FromAllOf(context, schema) } : {}),
185
+ ...(S.IsAnyOf(schema) ? { anyOf: FromAnyOf(context, schema) } : {}),
186
+ ...(S.IsContains(schema) ? { contains: FromContains(context, schema) } : {}),
187
+ ...(S.IsDependentSchemas(schema) ? { dependentSchemas: FromDependentSchemas(context, schema) } : {}),
188
+ ...(S.IsElse(schema) ? { else: FromElse(context, schema) } : {}),
189
+ ...(S.IsIf(schema) ? { if: FromIf(context, schema) } : {}),
190
+ ...(S.IsItems(schema) ? { items: FromItems(context, schema) } : {}),
191
+ ...(S.IsNot(schema) ? { not: FromNot(context, schema) } : {}),
192
+ ...(S.IsOneOf(schema) ? { oneOf: FromOneOf(context, schema) } : {}),
193
+ ...(S.IsPatternProperties(schema) ? { patternProperties: FromPatternProperties(context, schema) } : {}),
194
+ ...(S.IsPrefixItems(schema) ? { prefixItems: FromPrefixItems(context, schema) } : {}),
195
+ ...(S.IsProperties(schema) ? { properties: FromProperties(context, schema) } : {}),
196
+ ...(S.IsPropertyNames(schema) ? { propertyNames: FromPropertyNames(context, schema) } : {}),
197
+ ...(S.IsThen(schema) ? { then: FromThen(context, schema) } : {}),
198
+ ...(S.IsUnevaluatedItems(schema) ? { unevaluatedItems: FromUnevaluatedItems(context, schema) } : {}),
199
+ ...(S.IsUnevaluatedProperties(schema) ? { unevaluatedProperties: FromUnevaluatedProperties(context, schema) } : {})
233
200
  };
234
201
  context.resolving.delete(schema);
235
- // Discard resolution keywords and finalize the interned schema
236
- const interned = Memory.Discard(Memory.Assign(schema, remapped), ['$id', '$defs', '$anchor', '$dynamicAnchor', '$recursionAnchor']);
202
+ // Finalize and register the result
203
+ const interned = Memory.Discard(Memory.Assign(schema, remapped), ['$id']);
237
204
  const key = reservation.used ? reservation.key : HashKey(interned);
238
205
  registry.set(key, interned);
239
206
  // Result
@@ -257,8 +224,7 @@ function FromSchemaBoolean(_context, schema) {
257
224
  // Schema
258
225
  // ----------------------------------------------------------------
259
226
  function FromSchema(context, schema) {
260
- const next = { ...context, stack: Stack.NextStack(context.stack, schema) };
261
- return Schema.IsSchemaBoolean(schema) ? FromSchemaBoolean(next, schema) : FromSchemaObject(next, schema);
227
+ return S.IsSchemaBoolean(schema) ? FromSchemaBoolean(context, schema) : FromSchemaObject(context, schema);
262
228
  }
263
229
  // ----------------------------------------------------------------
264
230
  // BooleanEntry
@@ -272,22 +238,22 @@ function BooleanEntry(schema) {
272
238
  // ----------------------------------------------------------------
273
239
  const registry = new Map();
274
240
  const resolved = new Map();
275
- /** (Experimental) This function restructures the schema such that each distinct sub-schema is stored exactly once in a $defs object and keyed by content hash. */
276
- export function Intern(...args) {
277
- const [context, schema] = Arguments.Match(args, {
278
- 2: (context, schema) => [context, schema],
279
- 1: (schema) => [{}, schema]
280
- });
241
+ /**
242
+ * [Experimental] Performs a Common Subexpression Elimination (CSE) transform on the given
243
+ * schema. This function restructures the schema such that each distinct sub-schema is stored
244
+ * exactly once in a $defs object and keyed by content hash. This function can be used to
245
+ * both compress and optimize schemas prior to compilation.
246
+ */
247
+ export function Intern(schema) {
281
248
  registry.clear();
282
249
  resolved.clear();
283
- if (Schema.IsSchemaBoolean(schema))
250
+ if (S.IsSchemaBoolean(schema))
284
251
  return BooleanEntry(schema);
285
- const defs = Schema.IsDefs(schema) ? schema.$defs : {};
286
- const rootStack = Stack.Stack({ ...context, ...defs }, schema);
287
- const { schema: entry, stack } = Schema.IsRef(schema) ? ResolveRef(Stack.NextStack(rootStack, schema), schema.$ref) : { schema, stack: rootStack };
288
- if (Schema.IsSchemaBoolean(entry))
252
+ const context = S.IsDefs(schema) ? schema.$defs : {};
253
+ const entry = S.IsRef(schema) ? ResolveRef(context, schema, schema.$ref) : schema;
254
+ if (S.IsSchemaBoolean(entry))
289
255
  return BooleanEntry(entry);
290
- const ref_context = { stack, resolving: new Map() };
256
+ const ref_context = { schema, context, resolving: new Map() };
291
257
  const result = FromSchema(ref_context, entry);
292
258
  return { $ref: result.$ref, $defs: Object.fromEntries(registry) };
293
259
  }
@@ -1,6 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
2
  // deno-lint-ignore-file
3
- import { EnableParseErrors, DisableParseErrors } from '../system/settings/internal.mjs';
4
3
  import { Arguments } from '../system/arguments/index.mjs';
5
4
  import { Check } from './check.mjs';
6
5
  import { Errors } from './errors.mjs';
@@ -18,9 +17,7 @@ export class ParseError {
18
17
  // ThrowParseError
19
18
  // ------------------------------------------------------------------
20
19
  export function ThrowParseError(context, schema, value) {
21
- EnableParseErrors();
22
20
  const result = Errors(context, schema, value);
23
- DisableParseErrors();
24
21
  throw new ParseError(schema, value, result[1]);
25
22
  }
26
23
  /** Parses a value against the provided schema */
@@ -1,5 +1,10 @@
1
+ /** Returns an array of path indices for the given pointer */
1
2
  export declare function Indices(pointer: string): string[];
2
- export declare function Has(value: unknown, pointer: string): boolean;
3
+ /** Returns true if a value exists at the current pointer */
4
+ export declare function Has(value: unknown, pointer: string): unknown;
5
+ /** Gets a value at the pointer, or undefined if not exists */
3
6
  export declare function Get(value: unknown, pointer: string): unknown;
7
+ /** Sets a value at the given pointer. May throw if the target value is not indexable */
4
8
  export declare function Set(value: unknown, pointer: string, next: unknown): unknown;
9
+ /** Deletes the value at the given pointer. May throw if the target value is not indexable */
5
10
  export declare function Delete(value: unknown, pointer: string): unknown;
@@ -1,89 +1,106 @@
1
1
  // deno-fmt-ignore-file
2
2
  import { Guard } from '../../guard/index.mjs';
3
3
  // ------------------------------------------------------------------
4
- // Throw
4
+ // Asserts
5
5
  // ------------------------------------------------------------------
6
- function Throw(message) {
7
- throw Error(message);
6
+ function AssertNotRoot(indices) {
7
+ if (indices.length === 0)
8
+ throw Error('Cannot set root');
8
9
  }
9
- function ThrowUnsafePropertyKey() {
10
- Throw('Pointer contains unsafe property key');
10
+ function AssertCanSet(value) {
11
+ if (!Guard.IsObject(value))
12
+ throw Error('Cannot set value');
11
13
  }
12
- function ThrowCannotSetRoot() {
13
- Throw('Cannot set value');
14
+ function AssertIndex(index) {
15
+ if (Guard.IsUnsafePropertyKey(index))
16
+ throw Error('Pointer contains unsafe property key');
17
+ }
18
+ function AssertIndices(indices) {
19
+ for (const index of indices)
20
+ AssertIndex(index);
21
+ }
22
+ // ------------------------------------------------------------------
23
+ // Indices
24
+ // ------------------------------------------------------------------
25
+ function IsNumericIndex(index) {
26
+ return /^(0|[1-9]\d*)$/.test(index);
27
+ }
28
+ function TakeIndexRight(indices) {
29
+ return [
30
+ indices.slice(0, indices.length - 1),
31
+ indices.slice(indices.length - 1)[0]
32
+ ];
33
+ }
34
+ function HasIndex(index, value) {
35
+ return Guard.IsObject(value) && Guard.HasPropertyKey(value, index);
36
+ }
37
+ function GetIndex(index, value) {
38
+ return Guard.IsObject(value) && !Guard.IsUnsafePropertyKey(index) ? value[index] : undefined;
39
+ }
40
+ function GetIndices(indices, value) {
41
+ return indices.reduce((value, index) => GetIndex(index, value), value);
14
42
  }
15
43
  // ------------------------------------------------------------------
16
44
  // Indices
17
45
  // ------------------------------------------------------------------
46
+ /** Returns an array of path indices for the given pointer */
18
47
  export function Indices(pointer) {
19
- const indices = pointer.split('/').map(index => index.replace(/~1/g, '/').replace(/~0/g, '~'));
20
- return indices[0] === '' ? indices.slice(1) : indices;
48
+ if (Guard.IsEqual(pointer.length, 0))
49
+ return [];
50
+ const indices = pointer.split("/").map(index => index.replace(/~1/g, "/").replace(/~0/g, "~"));
51
+ return (indices.length > 0 && indices[0] === '') ? indices.slice(1) : indices;
21
52
  }
22
53
  // ------------------------------------------------------------------
23
54
  // Has
24
55
  // ------------------------------------------------------------------
56
+ /** Returns true if a value exists at the current pointer */
25
57
  export function Has(value, pointer) {
26
58
  let current = value;
27
- for (const index of Indices(pointer)) {
28
- if (!Guard.IsObject(current) || !Guard.HasPropertyKey(current, index))
59
+ return Indices(pointer).every(index => {
60
+ if (!HasIndex(index, current))
29
61
  return false;
30
62
  current = current[index];
31
- }
32
- return true;
63
+ return true;
64
+ });
33
65
  }
34
66
  // ------------------------------------------------------------------
35
67
  // Get
36
68
  // ------------------------------------------------------------------
69
+ /** Gets a value at the pointer, or undefined if not exists */
37
70
  export function Get(value, pointer) {
38
- let current = value;
39
- for (const index of Indices(pointer)) {
40
- if (!Guard.IsObject(current) || Guard.IsUnsafePropertyKey(index))
41
- return undefined;
42
- current = current[index];
43
- }
44
- return current;
45
- }
46
- // ------------------------------------------------------------------
47
- // Get
48
- // ------------------------------------------------------------------
49
- function Parent(value, indices, last) {
50
- let current = value;
51
- for (const index of indices) {
52
- if (Guard.IsUnsafePropertyKey(index))
53
- ThrowUnsafePropertyKey();
54
- current = Guard.IsObject(current) ? current[index] : undefined;
55
- }
56
- if (Guard.IsUnsafePropertyKey(last))
57
- ThrowUnsafePropertyKey();
58
- if (!Guard.IsObject(current))
59
- ThrowCannotSetRoot();
60
- return current;
71
+ const indices = Indices(pointer);
72
+ return GetIndices(indices, value);
61
73
  }
62
74
  // ------------------------------------------------------------------
63
75
  // Set
64
76
  // ------------------------------------------------------------------
77
+ /** Sets a value at the given pointer. May throw if the target value is not indexable */
65
78
  export function Set(value, pointer, next) {
66
79
  const indices = Indices(pointer);
67
- const last = indices.pop();
68
- if (Guard.IsUndefined(last))
69
- ThrowCannotSetRoot();
70
- Parent(value, indices, last)[last] = next;
80
+ AssertNotRoot(indices);
81
+ AssertIndices(indices);
82
+ const [head, index] = TakeIndexRight(indices);
83
+ const parent = GetIndices(head, value);
84
+ AssertCanSet(parent);
85
+ parent[index] = next;
71
86
  return value;
72
87
  }
73
88
  // ------------------------------------------------------------------
74
89
  // Delete
75
90
  // ------------------------------------------------------------------
91
+ /** Deletes the value at the given pointer. May throw if the target value is not indexable */
76
92
  export function Delete(value, pointer) {
77
93
  const indices = Indices(pointer);
78
- const last = indices.pop();
79
- if (Guard.IsUndefined(last))
80
- ThrowCannotSetRoot();
81
- const parent = Parent(value, indices, last);
82
- if (Guard.IsArray(parent) && /^(0|[1-9]\d*)$/.test(last)) {
83
- parent.splice(Number(last), 1);
94
+ AssertNotRoot(indices);
95
+ AssertIndices(indices);
96
+ const [head, index] = TakeIndexRight(indices);
97
+ const parent = GetIndices(head, value);
98
+ AssertCanSet(parent);
99
+ if (Guard.IsArray(parent) && IsNumericIndex(index)) {
100
+ parent.splice(+index, 1);
84
101
  }
85
102
  else {
86
- delete parent[last];
103
+ delete parent[index];
87
104
  }
88
105
  return value;
89
106
  }
@@ -1,9 +1,35 @@
1
1
  import * as Schema from '../types/index.mjs';
2
- import * as Stack from '../engine/_stack.mjs';
3
- export interface XRefResult {
2
+ export declare const DefaultBase = "https://json-schema.org";
3
+ export interface StackFrame {
4
+ context: Record<string, Schema.XSchema>;
5
+ root: Schema.XSchemaObject;
6
+ lexicalSchema: Schema.XSchemaObject;
7
+ lexicalBase: string;
8
+ referenceBase: string;
9
+ resourceBase: string;
10
+ ids: Schema.XId[];
11
+ recursiveAnchors: Schema.XRecursiveAnchor[];
12
+ dynamicAnchors: Schema.XDynamicAnchor[];
13
+ inRetrievedFrame: boolean;
14
+ }
15
+ export interface RetrievedResource {
16
+ target: Schema.XSchemaObject;
17
+ base: string;
18
+ root: Schema.XSchemaObject;
19
+ }
20
+ export interface ResolvedResource {
21
+ target: Schema.XSchemaObject;
22
+ resource: Schema.XId;
23
+ }
24
+ export interface RefResult {
4
25
  schema: Schema.XSchema | undefined;
5
- stack: Stack.XStack;
26
+ retrievedResource?: RetrievedResource;
27
+ resolvedResource?: ResolvedResource;
6
28
  }
7
- export declare function Ref(stack: Stack.XStack, ref: Schema.XRef): XRefResult;
8
- export declare function RecursiveRef(stack: Stack.XStack, recursiveRef: Schema.XRecursiveRef): Schema.XSchema | undefined;
9
- export declare function DynamicRef(stack: Stack.XStack, dynamicRef: Schema.XDynamicRef): Schema.XSchema | undefined;
29
+ export declare function Base(schema: Schema.XSchemaObject, base: string, target: Schema.XSchema): string | undefined;
30
+ export declare function Resource(context: Record<string, Schema.XSchema>, schema: Schema.XSchemaObject, base: string, ref: string): Schema.XId | undefined;
31
+ export declare function Ref(remotes: Record<string, Schema.XSchema>, schema: Schema.XSchemaObject, base: string, ref: string, applySchemaId?: boolean): Schema.XSchema | undefined;
32
+ export declare function DynamicRef(context: Record<string, Schema.XSchema>, root: Schema.XSchemaObject, base: string, schema: Schema.XSchemaObject, dynamicRef: Schema.XDynamicRef, dynamicAnchors: Schema.XDynamicAnchor[]): Schema.XSchema | undefined;
33
+ export declare function ResolveRef(stackframe: StackFrame, ref: Schema.XRef): RefResult;
34
+ export declare function ResolveRecursiveRef(stackframe: StackFrame, recursiveRef: Schema.XRecursiveRef): Schema.XSchema | undefined;
35
+ export declare function ResolveDynamicRef(stackframe: StackFrame, dynamicRef: Schema.XDynamicRef): Schema.XSchema | undefined;