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.
- package/CHANGELOG.md +29 -0
- package/README.md +32 -28
- package/build/cli.mjs +121 -0
- package/build/extensions/proactive.js +47 -6
- package/build/src/commands.js +78 -2
- package/build/src/config.js +511 -4
- package/build/src/daemon-config.js +221 -0
- package/build/src/daemon-contact.js +103 -0
- package/build/src/daemon-host.js +84 -0
- package/build/src/daemon.js +193 -3
- package/build/src/health.js +84 -0
- package/build/src/lineage.js +41 -2
- package/build/src/notify.js +183 -0
- package/build/src/progress-eta.js +134 -0
- package/build/src/trigger.js +43 -0
- package/build/src/trust-loop.js +321 -0
- package/build/src/trust-metrics.js +236 -0
- package/build/src/trust-notify.js +73 -0
- package/build/src/trust-policy.js +58 -0
- package/build/src/trust-registry.js +323 -0
- package/daemon/launchd.plist +48 -0
- package/daemon/pi-proactive-daemon.service +29 -0
- package/daemon/run-daemon.sh +84 -0
- package/node_modules/typebox/build/compile/code.mjs +2 -1
- package/node_modules/typebox/build/compile/validator.mjs +1 -5
- package/node_modules/typebox/build/format/date_time.d.mts +1 -2
- package/node_modules/typebox/build/format/date_time.mjs +3 -12
- package/node_modules/typebox/build/format/duration.d.mts +2 -2
- package/node_modules/typebox/build/format/duration.mjs +2 -2
- package/node_modules/typebox/build/format/idn_email.d.mts +0 -1
- package/node_modules/typebox/build/format/idn_email.mjs +0 -1
- package/node_modules/typebox/build/format/idn_hostname.d.mts +1 -1
- package/node_modules/typebox/build/format/idn_hostname.mjs +1 -1
- package/node_modules/typebox/build/format/ipv4.d.mts +2 -2
- package/node_modules/typebox/build/format/ipv4.mjs +2 -2
- package/node_modules/typebox/build/format/ipv6.d.mts +1 -1
- package/node_modules/typebox/build/format/ipv6.mjs +1 -1
- package/node_modules/typebox/build/format/iri.mjs +9 -16
- package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
- package/node_modules/typebox/build/guard/emit.mjs +2 -2
- package/node_modules/typebox/build/guard/guard.d.mts +5 -7
- package/node_modules/typebox/build/guard/guard.mjs +9 -14
- package/node_modules/typebox/build/guard/index.mjs +0 -6
- package/node_modules/typebox/build/guard/{unicode/unicode_segment.mjs → string.mjs} +19 -16
- package/node_modules/typebox/build/schema/build.mjs +5 -5
- package/node_modules/typebox/build/schema/check.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/_context.d.mts +1 -5
- package/node_modules/typebox/build/schema/engine/_context.mjs +3 -16
- package/node_modules/typebox/build/schema/engine/_functions.d.mts +2 -2
- package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/_reducer.d.mts +3 -3
- package/node_modules/typebox/build/schema/engine/_refine.d.mts +5 -5
- package/node_modules/typebox/build/schema/engine/_refine.mjs +9 -14
- package/node_modules/typebox/build/schema/engine/_stack.d.mts +20 -34
- package/node_modules/typebox/build/schema/engine/_stack.mjs +202 -143
- package/node_modules/typebox/build/schema/engine/_unique.d.mts +2 -4
- package/node_modules/typebox/build/schema/engine/_unique.mjs +3 -7
- package/node_modules/typebox/build/schema/engine/additionalItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/additionalItems.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +8 -5
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +32 -27
- package/node_modules/typebox/build/schema/engine/allOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/allOf.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/anyOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/anyOf.mjs +9 -4
- package/node_modules/typebox/build/schema/engine/boolean.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/boolean.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/const.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/const.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/contains.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/contains.mjs +9 -5
- package/node_modules/typebox/build/schema/engine/dependencies.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dependencies.mjs +7 -5
- package/node_modules/typebox/build/schema/engine/dependentRequired.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dependentRequired.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/dependentSchemas.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dependentSchemas.mjs +1 -2
- package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +8 -12
- package/node_modules/typebox/build/schema/engine/enum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/enum.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/exclusiveMaximum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/exclusiveMaximum.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/exclusiveMinimum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/exclusiveMinimum.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/format.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/format.mjs +8 -11
- package/node_modules/typebox/build/schema/engine/if.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/if.mjs +13 -5
- package/node_modules/typebox/build/schema/engine/index.d.mts +0 -1
- package/node_modules/typebox/build/schema/engine/index.mjs +0 -1
- package/node_modules/typebox/build/schema/engine/items.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/items.mjs +5 -8
- package/node_modules/typebox/build/schema/engine/maxContains.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxContains.mjs +8 -4
- package/node_modules/typebox/build/schema/engine/maxItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxItems.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/maxLength.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxLength.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/maxProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxProperties.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/maximum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maximum.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/minContains.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minContains.mjs +9 -5
- package/node_modules/typebox/build/schema/engine/minItems.d.mts +5 -5
- package/node_modules/typebox/build/schema/engine/minItems.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/minLength.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minLength.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/minProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minProperties.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/minimum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minimum.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/multipleOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/multipleOf.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/not.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/not.mjs +8 -4
- package/node_modules/typebox/build/schema/engine/oneOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/oneOf.mjs +11 -6
- package/node_modules/typebox/build/schema/engine/pattern.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/pattern.mjs +7 -3
- package/node_modules/typebox/build/schema/engine/patternProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +5 -6
- package/node_modules/typebox/build/schema/engine/prefixItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/prefixItems.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/properties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/properties.mjs +3 -4
- package/node_modules/typebox/build/schema/engine/propertyNames.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/propertyNames.mjs +10 -7
- package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +8 -12
- package/node_modules/typebox/build/schema/engine/ref.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/ref.mjs +14 -18
- package/node_modules/typebox/build/schema/engine/required.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/required.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/schema.d.mts +7 -7
- package/node_modules/typebox/build/schema/engine/schema.mjs +138 -136
- package/node_modules/typebox/build/schema/engine/type.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/type.mjs +6 -2
- package/node_modules/typebox/build/schema/engine/unevaluatedItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +9 -5
- package/node_modules/typebox/build/schema/engine/unevaluatedProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +9 -5
- package/node_modules/typebox/build/schema/engine/uniqueItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/uniqueItems.mjs +6 -2
- package/node_modules/typebox/build/schema/errors.mjs +1 -1
- package/node_modules/typebox/build/schema/intern/intern.d.mts +9 -6
- package/node_modules/typebox/build/schema/intern/intern.mjs +56 -90
- package/node_modules/typebox/build/schema/parse.mjs +0 -3
- package/node_modules/typebox/build/schema/pointer/pointer.d.mts +6 -1
- package/node_modules/typebox/build/schema/pointer/pointer.mjs +64 -47
- package/node_modules/typebox/build/schema/resolve/resolve.d.mts +32 -6
- package/node_modules/typebox/build/schema/resolve/resolve.mjs +227 -231
- package/node_modules/typebox/build/schema/schema.d.mts +0 -1
- package/node_modules/typebox/build/schema/schema.mjs +0 -1
- package/node_modules/typebox/build/system/hashing/hash.mjs +34 -63
- package/node_modules/typebox/build/system/locale/en_US.mjs +1 -2
- package/node_modules/typebox/build/system/memory/assign.d.mts +8 -2
- package/node_modules/typebox/build/system/memory/assign.mjs +6 -13
- package/node_modules/typebox/build/system/memory/clone.d.mts +5 -4
- package/node_modules/typebox/build/system/memory/clone.mjs +96 -8
- package/node_modules/typebox/build/system/memory/create.d.mts +5 -1
- package/node_modules/typebox/build/system/memory/create.mjs +13 -18
- package/node_modules/typebox/build/system/memory/discard.d.mts +1 -1
- package/node_modules/typebox/build/system/memory/discard.mjs +8 -9
- package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
- package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
- package/node_modules/typebox/build/system/memory/update.d.mts +4 -1
- package/node_modules/typebox/build/system/memory/update.mjs +16 -43
- package/node_modules/typebox/build/system/settings/settings.d.mts +0 -11
- package/node_modules/typebox/build/system/settings/settings.mjs +0 -14
- package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +24 -2
- package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +29 -2
- package/node_modules/typebox/build/type/engine/evaluate/index.d.mts +0 -1
- package/node_modules/typebox/build/type/engine/evaluate/index.mjs +0 -1
- package/node_modules/typebox/build/type/engine/evaluate/narrow.d.mts +1 -5
- package/node_modules/typebox/build/type/engine/evaluate/narrow.mjs +1 -6
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +4 -1
- package/node_modules/typebox/build/type/engine/object/from_intersect.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/object/from_intersect.mjs +2 -2
- package/node_modules/typebox/build/type/engine/object/from_union.d.mts +2 -2
- package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +4 -1
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +3 -1
- package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +4 -1
- package/node_modules/typebox/build/type/extends/inference.d.mts +1 -1
- package/node_modules/typebox/build/type/extends/inference.mjs +2 -15
- package/node_modules/typebox/build/type/extends/tuple.d.mts +1 -2
- package/node_modules/typebox/build/type/extends/tuple.mjs +1 -21
- package/node_modules/typebox/build/value/clean/from_object.mjs +1 -1
- package/node_modules/typebox/build/value/clone/clone.d.mts +3 -4
- package/node_modules/typebox/build/value/clone/clone.mjs +7 -5
- package/node_modules/typebox/build/value/parse/parse.mjs +4 -10
- package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +14 -25
- package/node_modules/typebox/package.json +1 -1
- package/node_modules/typebox/readme.md +84 -52
- package/package.json +11 -3
- package/skills/pi-proactive/SKILL.md +27 -24
- package/tools/cli.mjs +121 -0
- package/tools/daemon-install.sh +397 -0
- package/tools/daemon-uninstall.sh +226 -0
- package/node_modules/typebox/build/guard/unicode/unicode.d.mts +0 -6
- package/node_modules/typebox/build/guard/unicode/unicode.mjs +0 -35
- package/node_modules/typebox/build/schema/engine/_pathing.d.mts +0 -1
- package/node_modules/typebox/build/schema/engine/_pathing.mjs +0 -11
- package/node_modules/typebox/build/schema/meta/draft_2019_09.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/draft_2019_09.mjs +0 -288
- package/node_modules/typebox/build/schema/meta/draft_2020_12.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/draft_2020_12.mjs +0 -300
- package/node_modules/typebox/build/schema/meta/draft_3.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/draft_3.mjs +0 -143
- package/node_modules/typebox/build/schema/meta/draft_4.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/draft_4.mjs +0 -149
- package/node_modules/typebox/build/schema/meta/draft_6.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/draft_6.mjs +0 -155
- package/node_modules/typebox/build/schema/meta/draft_7.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/draft_7.mjs +0 -172
- package/node_modules/typebox/build/schema/meta/index.d.mts +0 -2
- package/node_modules/typebox/build/schema/meta/index.mjs +0 -2
- package/node_modules/typebox/build/schema/meta/meta.d.mts +0 -9
- package/node_modules/typebox/build/schema/meta/meta.mjs +0 -15
- package/node_modules/typebox/build/schema/meta/schema.d.mts +0 -6
- package/node_modules/typebox/build/schema/meta/schema.mjs +0 -1
- package/node_modules/typebox/build/system/memory/deep.d.mts +0 -2
- package/node_modules/typebox/build/system/memory/deep.mjs +0 -108
- package/node_modules/typebox/build/system/memory/finalize.d.mts +0 -4
- package/node_modules/typebox/build/system/memory/finalize.mjs +0 -30
- package/node_modules/typebox/build/system/memory/keys.d.mts +0 -2
- package/node_modules/typebox/build/system/memory/keys.mjs +0 -8
- package/node_modules/typebox/build/system/settings/internal.d.mts +0 -2
- package/node_modules/typebox/build/system/settings/internal.mjs +0 -20
- package/node_modules/typebox/build/type/engine/call/index.d.mts +0 -1
- package/node_modules/typebox/build/type/engine/call/index.mjs +0 -1
- package/node_modules/typebox/build/type/engine/evaluate/property.d.mts +0 -30
- package/node_modules/typebox/build/type/engine/evaluate/property.mjs +0 -29
- package/node_modules/typebox/build/type/engine/this/index.d.mts +0 -1
- package/node_modules/typebox/build/type/engine/this/index.mjs +0 -1
- package/node_modules/typebox/build/value/repair/from_cyclic.d.mts +0 -2
- package/node_modules/typebox/build/value/repair/from_cyclic.mjs +0 -6
- /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
|
|
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(
|
|
125
|
-
|
|
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
|
-
//
|
|
136
|
-
|
|
137
|
-
|
|
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(
|
|
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
|
|
199
|
-
if (
|
|
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
|
-
...(
|
|
215
|
-
...(
|
|
216
|
-
...(
|
|
217
|
-
...(
|
|
218
|
-
...(
|
|
219
|
-
...(
|
|
220
|
-
...(
|
|
221
|
-
...(
|
|
222
|
-
...(
|
|
223
|
-
...(
|
|
224
|
-
...(
|
|
225
|
-
...(
|
|
226
|
-
...(
|
|
227
|
-
...(
|
|
228
|
-
...(
|
|
229
|
-
...(
|
|
230
|
-
...(
|
|
231
|
-
...(
|
|
232
|
-
...(
|
|
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
|
-
//
|
|
236
|
-
const interned = Memory.Discard(Memory.Assign(schema, remapped), ['$id'
|
|
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
|
-
|
|
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
|
-
/**
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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 (
|
|
250
|
+
if (S.IsSchemaBoolean(schema))
|
|
284
251
|
return BooleanEntry(schema);
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
|
|
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 = {
|
|
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
|
-
|
|
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
|
-
//
|
|
4
|
+
// Asserts
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
|
-
function
|
|
7
|
-
|
|
6
|
+
function AssertNotRoot(indices) {
|
|
7
|
+
if (indices.length === 0)
|
|
8
|
+
throw Error('Cannot set root');
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
10
|
+
function AssertCanSet(value) {
|
|
11
|
+
if (!Guard.IsObject(value))
|
|
12
|
+
throw Error('Cannot set value');
|
|
11
13
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
28
|
-
if (!
|
|
59
|
+
return Indices(pointer).every(index => {
|
|
60
|
+
if (!HasIndex(index, current))
|
|
29
61
|
return false;
|
|
30
62
|
current = current[index];
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const parent =
|
|
82
|
-
|
|
83
|
-
|
|
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[
|
|
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
|
-
|
|
3
|
-
export interface
|
|
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
|
-
|
|
26
|
+
retrievedResource?: RetrievedResource;
|
|
27
|
+
resolvedResource?: ResolvedResource;
|
|
6
28
|
}
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
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;
|