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,14 +1,41 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
// deno-lint-ignore-file
|
|
3
3
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
|
+
import { IsReadonly } from '../../types/_readonly.mjs';
|
|
5
|
+
import { IsOptional } from '../../types/_optional.mjs';
|
|
4
6
|
import { Object, IsObject } from '../../types/object.mjs';
|
|
5
7
|
import { Never } from '../../types/never.mjs';
|
|
6
8
|
import { IsTuple } from '../../types/tuple.mjs';
|
|
9
|
+
import { AddReadonly } from '../../action/_add_readonly.mjs';
|
|
10
|
+
import { AddOptional } from '../../action/_add_optional.mjs';
|
|
11
|
+
import { RemoveReadonly } from '../../action/_remove_readonly.mjs';
|
|
12
|
+
import { RemoveOptional } from '../../action/_remove_optional.mjs';
|
|
7
13
|
import { TupleElementsToProperties } from '../tuple/to_object.mjs';
|
|
8
|
-
import {
|
|
14
|
+
import { EvaluateIntersect } from './evaluate.mjs';
|
|
15
|
+
/** Returns true if the type is a valid operand to Composite. */
|
|
16
|
+
export function CanComposite(type) {
|
|
17
|
+
return (IsObject(type) || IsTuple(type));
|
|
18
|
+
}
|
|
19
|
+
function IsReadonlyProperty(left, right) {
|
|
20
|
+
return (IsReadonly(left) ? IsReadonly(right) ? true : false : false);
|
|
21
|
+
}
|
|
22
|
+
function IsOptionalProperty(left, right) {
|
|
23
|
+
return (IsOptional(left) ? IsOptional(right) ? true : false : false);
|
|
24
|
+
}
|
|
25
|
+
function CompositeProperty(left, right) {
|
|
26
|
+
const isReadonly = IsReadonlyProperty(left, right);
|
|
27
|
+
const isOptional = IsOptionalProperty(left, right);
|
|
28
|
+
const evaluated = EvaluateIntersect([left, right]);
|
|
29
|
+
// Modifiers need to be discarded and re-applied
|
|
30
|
+
const property = RemoveReadonly(RemoveOptional(evaluated));
|
|
31
|
+
return (isReadonly && isOptional ? AddReadonly(AddOptional(property)) :
|
|
32
|
+
isReadonly && !isOptional ? AddReadonly(property) :
|
|
33
|
+
!isReadonly && isOptional ? AddOptional(property) :
|
|
34
|
+
property);
|
|
35
|
+
}
|
|
9
36
|
function CompositePropertyKey(left, right, key) {
|
|
10
37
|
return (key in left
|
|
11
|
-
? key in right ?
|
|
38
|
+
? key in right ? CompositeProperty(left[key], right[key]) : left[key]
|
|
12
39
|
: key in right ? right[key] : Never());
|
|
13
40
|
}
|
|
14
41
|
function CompositeProperties(left, right) {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
-
import { type TProperties } from '../../types/properties.mjs';
|
|
3
|
-
import { type TObject } from '../../types/object.mjs';
|
|
4
2
|
import { type TAny } from '../../types/any.mjs';
|
|
5
3
|
import { type TNever } from '../../types/never.mjs';
|
|
6
|
-
import { type TTuple } from '../../types/tuple.mjs';
|
|
7
4
|
import { type TUnknown } from '../../types/unknown.mjs';
|
|
8
5
|
import { type TCompare, type TCompareResult, CompareResultLeftInside, CompareResultRightInside, CompareResultEqual } from './compare.mjs';
|
|
9
|
-
import { type TComposite } from './composite.mjs';
|
|
6
|
+
import { type TComposite, type TCanComposite } from './composite.mjs';
|
|
10
7
|
type TNarrowCompareRule<Left extends TSchema, Right extends TSchema, Result extends TCompareResult = TCompare<Left, Right>> = (Result extends typeof CompareResultLeftInside ? Left : Result extends typeof CompareResultRightInside ? Right : Result extends typeof CompareResultEqual ? Right : TNever);
|
|
11
|
-
type TCanComposite<Type extends TSchema> = (Type extends TObject<infer _ extends TProperties> ? true : Type extends TTuple<infer _ extends TSchema[]> ? true : false);
|
|
12
8
|
type TNarrowCompositeRule<Left extends TSchema, Right extends TSchema, CanCompositeLeft extends boolean = TCanComposite<Left>, CanCompositeRight extends boolean = TCanComposite<Right>> = ([
|
|
13
9
|
CanCompositeLeft,
|
|
14
10
|
CanCompositeRight
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
|
-
import { IsObject } from '../../types/object.mjs';
|
|
4
3
|
import { IsAny } from '../../types/any.mjs';
|
|
5
4
|
import { Never, IsNever } from '../../types/never.mjs';
|
|
6
|
-
import { IsTuple } from '../../types/tuple.mjs';
|
|
7
5
|
import { IsUnknown } from '../../types/unknown.mjs';
|
|
8
6
|
import { Compare, CompareResultLeftInside, CompareResultRightInside, CompareResultEqual } from './compare.mjs';
|
|
9
|
-
import { Composite } from './composite.mjs';
|
|
7
|
+
import { Composite, CanComposite } from './composite.mjs';
|
|
10
8
|
function NarrowCompareRule(left, right) {
|
|
11
9
|
const result = Compare(left, right);
|
|
12
10
|
return (Guard.IsEqual(result, CompareResultLeftInside) ? left :
|
|
@@ -14,9 +12,6 @@ function NarrowCompareRule(left, right) {
|
|
|
14
12
|
Guard.IsEqual(result, CompareResultEqual) ? right :
|
|
15
13
|
Never());
|
|
16
14
|
}
|
|
17
|
-
function CanComposite(type) {
|
|
18
|
-
return (IsObject(type) || IsTuple(type));
|
|
19
|
-
}
|
|
20
15
|
function NarrowCompositeRule(left, right) {
|
|
21
16
|
const canCompositeLeft = CanComposite(left);
|
|
22
17
|
const canCompositeRight = CanComposite(right);
|
|
@@ -2,7 +2,9 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TImmutable } from '../../types/_immutable.mjs';
|
|
4
4
|
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
-
|
|
5
|
+
type TAddImmutableOperation<Type extends TSchema, Result extends TSchema = '~immutable' extends keyof Type ? Type : TImmutable<Type>> = Result;
|
|
6
|
+
export type TAddImmutableAction<Type extends TSchema, Result extends TSchema = TAddImmutableOperation<Type>> = Result;
|
|
6
7
|
export declare function AddImmutableAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddImmutableAction<Type>;
|
|
7
8
|
export type TAddImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddImmutableAction<InstantiateType>;
|
|
8
9
|
export declare function AddImmutableInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddImmutableInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
3
|
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function AddImmutableOperation(type) {
|
|
5
|
+
return Memory.Update(type, { '~immutable': true }, {});
|
|
6
|
+
}
|
|
4
7
|
export function AddImmutableAction(type, options) {
|
|
5
|
-
const result = Memory.Update(type, {
|
|
8
|
+
const result = Memory.Update(AddImmutableOperation(type), {}, options);
|
|
6
9
|
return result;
|
|
7
10
|
}
|
|
8
11
|
export function AddImmutableInstantiate(context, state, type, options) {
|
|
@@ -2,13 +2,13 @@ import { Memory } from '../../../system/memory/index.mjs';
|
|
|
2
2
|
import { type TSchema } from '../../types/schema.mjs';
|
|
3
3
|
import { type TProperties } from '../../types/properties.mjs';
|
|
4
4
|
import { type TFromType } from './from_type.mjs';
|
|
5
|
-
import { type
|
|
5
|
+
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
6
6
|
type TCollapseIntersectProperties<Left extends TProperties, Right extends TProperties, LeftKeys extends keyof Left = Exclude<keyof Left, keyof Right>, RightKeys extends keyof Right = Exclude<keyof Right, keyof Left>, SharedKeys extends keyof Left & keyof Right = Extract<keyof Left, keyof Right>, LeftProperties extends TProperties = {
|
|
7
7
|
[Key in LeftKeys]: Left[Key];
|
|
8
8
|
}, RightProperties extends TProperties = {
|
|
9
9
|
[Key in RightKeys]: Right[Key];
|
|
10
10
|
}, SharedProperties extends TProperties = {
|
|
11
|
-
[Key in SharedKeys]:
|
|
11
|
+
[Key in SharedKeys]: TEvaluateIntersect<[Left[Key], Right[Key]]>;
|
|
12
12
|
}, Unique extends TProperties = Memory.TAssign<LeftProperties, RightProperties>, Shared extends TProperties = Memory.TAssign<Unique, SharedProperties>> = Shared;
|
|
13
13
|
export type TFromIntersect<Types extends TSchema[], Result extends TProperties = {}> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromIntersect<Right, TCollapseIntersectProperties<Result, TFromType<Left>>> : {
|
|
14
14
|
[Key in keyof Result]: Result[Key];
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
4
4
|
import { Guard } from '../../../guard/index.mjs';
|
|
5
5
|
import { FromType } from './from_type.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { EvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
7
7
|
function CollapseIntersectProperties(left, right) {
|
|
8
8
|
const leftKeys = Guard.Keys(left).filter((key) => !Guard.HasPropertyKey(right, key));
|
|
9
9
|
const rightKeys = Guard.Keys(right).filter((key) => !Guard.HasPropertyKey(left, key));
|
|
10
10
|
const sharedKeys = Guard.Keys(left).filter((key) => Guard.HasPropertyKey(right, key));
|
|
11
11
|
const leftProperties = leftKeys.reduce((result, key) => ({ ...result, [key]: left[key] }), {});
|
|
12
12
|
const rightProperties = rightKeys.reduce((result, key) => ({ ...result, [key]: right[key] }), {});
|
|
13
|
-
const sharedProperties = sharedKeys.reduce((result, key) => ({ ...result, [key]:
|
|
13
|
+
const sharedProperties = sharedKeys.reduce((result, key) => ({ ...result, [key]: EvaluateIntersect([left[key], right[key]]) }), {});
|
|
14
14
|
const unique = Memory.Assign(leftProperties, rightProperties);
|
|
15
15
|
const shared = Memory.Assign(unique, sharedProperties);
|
|
16
16
|
return shared;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type TUnreachable } from '../../../system/unreachable/index.mjs';
|
|
2
2
|
import { type TSchema } from '../../types/schema.mjs';
|
|
3
3
|
import { type TProperties } from '../../types/properties.mjs';
|
|
4
|
-
import { type
|
|
4
|
+
import { type TEvaluateUnion } from '../evaluate/evaluate.mjs';
|
|
5
5
|
import { type TFromType } from './from_type.mjs';
|
|
6
6
|
type TCollapseUnionProperties<Left extends TProperties, Right extends TProperties, SharedKeys extends PropertyKey = keyof Left & keyof Right, Result extends TProperties = {
|
|
7
|
-
[Key in SharedKeys]:
|
|
7
|
+
[Key in SharedKeys]: TEvaluateUnion<[Left[Key], Right[Key]]>;
|
|
8
8
|
}> = Result;
|
|
9
9
|
type TReduceVariants<Types extends TSchema[], Result extends TProperties> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReduceVariants<Right, TCollapseUnionProperties<Result, TFromType<Left>>> : Result);
|
|
10
10
|
export type TFromUnion<Types extends TSchema[]> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TReduceVariants<Right, TFromType<Left>> : TUnreachable);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
3
3
|
import { Unreachable } from '../../../system/unreachable/index.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { EvaluateUnion } from '../evaluate/evaluate.mjs';
|
|
5
5
|
import { FromType } from './from_type.mjs';
|
|
6
6
|
function CollapseUnionProperties(left, right) {
|
|
7
7
|
const sharedKeys = Guard.Keys(left).filter((key) => key in right);
|
|
8
8
|
const result = sharedKeys.reduce((result, key) => {
|
|
9
|
-
return { ...result, [key]:
|
|
9
|
+
return { ...result, [key]: EvaluateUnion([left[key], right[key]]) };
|
|
10
10
|
}, {});
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
@@ -2,7 +2,9 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TOptional } from '../../types/_optional.mjs';
|
|
4
4
|
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
-
|
|
5
|
+
type TAddOptionalOperation<Type extends TSchema, Result extends TSchema = `~optional` extends keyof Type ? Type : TOptional<Type>> = Result;
|
|
6
|
+
export type TAddOptionalAction<Type extends TSchema, Result extends TSchema = TAddOptionalOperation<Type>> = Result;
|
|
6
7
|
export declare function AddOptionalAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddOptionalAction<Type>;
|
|
7
8
|
export type TAddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddOptionalAction<InstantiateType>;
|
|
8
9
|
export declare function AddOptionalInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddOptionalInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
3
|
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function AddOptionalOperation(type) {
|
|
5
|
+
return Memory.Update(type, { '~optional': true }, {});
|
|
6
|
+
}
|
|
4
7
|
export function AddOptionalAction(type, options) {
|
|
5
|
-
const result = Memory.Update(type, {
|
|
8
|
+
const result = Memory.Update(AddOptionalOperation(type), {}, options);
|
|
6
9
|
return result;
|
|
7
10
|
}
|
|
8
11
|
export function AddOptionalInstantiate(context, state, type, options) {
|
|
@@ -2,7 +2,9 @@ import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TReadonly } from '../../types/_readonly.mjs';
|
|
4
4
|
import { type TState, type TInstantiateType } from '../instantiate.mjs';
|
|
5
|
-
|
|
5
|
+
type TAddReadonlyOperation<Type extends TSchema, Result extends TSchema = `~readonly` extends keyof Type ? Type : TReadonly<Type>> = Result;
|
|
6
|
+
export type TAddReadonlyAction<Type extends TSchema, Result extends TSchema = TAddReadonlyOperation<Type>> = Result;
|
|
6
7
|
export declare function AddReadonlyAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TAddReadonlyAction<Type>;
|
|
7
8
|
export type TAddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TAddReadonlyAction<InstantiateType>;
|
|
8
9
|
export declare function AddReadonlyInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TAddReadonlyInstantiate<Context, State, Type>;
|
|
10
|
+
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
3
|
import { InstantiateType } from '../instantiate.mjs';
|
|
4
|
+
function AddReadonlyOperation(type) {
|
|
5
|
+
return Memory.Update(type, { '~readonly': true }, {});
|
|
6
|
+
}
|
|
4
7
|
export function AddReadonlyAction(type, options) {
|
|
5
|
-
const result = Memory.Update(type, {
|
|
8
|
+
const result = Memory.Update(AddReadonlyOperation(type), {}, options);
|
|
6
9
|
return result;
|
|
7
10
|
}
|
|
8
11
|
export function AddReadonlyInstantiate(context, state, type, options) {
|
|
@@ -22,7 +22,7 @@ export declare function TryRestInferable<Type extends TSchema>(type: Type): TTry
|
|
|
22
22
|
export type TTryInferable<Type extends TSchema, Result extends TInferable | undefined = (Type extends TInfer<infer Name extends string, infer Type extends TSchema> ? TInferable<Name, Type> : undefined)> = Result;
|
|
23
23
|
export declare function TryInferable<Type extends TSchema>(type: Type): TTryInferable<Type>;
|
|
24
24
|
type TryInferResults<Rest extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Rest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<{}, Head, Right> extends Result.TExtendsTrueLike ? TryInferResults<Tail, Right, [...Result, Head]> : undefined : Result);
|
|
25
|
-
declare function TryInferResults<Rest extends TSchema[], Right extends TSchema>(rest: [...Rest], right: Right): TryInferResults<Rest, Right>;
|
|
25
|
+
declare function TryInferResults<Rest extends TSchema[], Right extends TSchema>(rest: [...Rest], right: Right, result?: TSchema[]): TryInferResults<Rest, Right>;
|
|
26
26
|
export type TInferTupleResult<Inferred extends TProperties, Name extends string, Left extends TSchema[], Right extends TSchema, Results extends TSchema[] | undefined = TryInferResults<Left, Right>> = (Results extends [...infer Results extends TSchema[]] ? Result.TExtendsTrue<Memory.TAssign<Inferred, {
|
|
27
27
|
[_ in Name]: TTuple<Results>;
|
|
28
28
|
}>> : Result.TExtendsFalse);
|
|
@@ -45,21 +45,8 @@ export function TryInferable(type) {
|
|
|
45
45
|
return (IsInfer(type) ? Inferrable(type.name, type.extends) :
|
|
46
46
|
undefined);
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Result.Match(ExtendsLeft({}, head, right),
|
|
51
|
-
// () => TryInferResults(tail, right, [...result, head]), // Stack Overflow Here (Large Rest)
|
|
52
|
-
// () => undefined),
|
|
53
|
-
// () => result) as never
|
|
54
|
-
// }
|
|
55
|
-
function TryInferResults(rest, right) {
|
|
56
|
-
const result = [];
|
|
57
|
-
for (const head of rest) {
|
|
58
|
-
if (!Result.IsExtendsTrueLike(ExtendsLeft({}, head, right)))
|
|
59
|
-
return undefined;
|
|
60
|
-
result.push(head);
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
48
|
+
function TryInferResults(rest, right, result = []) {
|
|
49
|
+
return Guard.ShiftLeft(rest, (head, tail) => Result.Match(ExtendsLeft({}, head, right), () => TryInferResults(tail, right, [...result, head]), () => undefined), () => result);
|
|
63
50
|
}
|
|
64
51
|
export function InferTupleResult(inferred, name, left, right) {
|
|
65
52
|
const results = TryInferResults(left, right);
|
|
@@ -16,8 +16,7 @@ type TElementsLeft<Inferred extends TProperties, Reversed extends boolean, LeftR
|
|
|
16
16
|
type TElementsRight<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = (RightRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TElementsLeft<Inferred, Reversed, LeftRest, Head, Tail> : LeftRest['length'] extends 0 ? Result.TExtendsTrue<Inferred> : Result.TExtendsFalse);
|
|
17
17
|
type TElements<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = TElementsRight<Inferred, Reversed, LeftRest, RightRest>;
|
|
18
18
|
type TExtendsTupleToTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[], InstantiatedRight extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Right>, Reversed extends boolean = TReversed<InstantiatedRight>> = TElements<Inferred, Reversed, TApplyReverse<Left, Reversed>, TApplyReverse<InstantiatedRight, Reversed>>;
|
|
19
|
-
type
|
|
20
|
-
type TExtendsTupleToArray<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Inferrable extends TInferable | undefined = TTryInferable<Right>> = (Inferrable extends TInferable ? TInferUnionResult<Inferred, Inferrable['name'], Left, Inferrable['type']> : TExtendsTupleToArrayReduce<Inferred, Left, Right>);
|
|
19
|
+
type TExtendsTupleToArray<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Inferrable extends TInferable | undefined = TTryInferable<Right>> = (Inferrable extends TInferable ? TInferUnionResult<Inferred, Inferrable['name'], Left, Inferrable['type']> : Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Head, Right> extends Result.TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTupleToArray<Inferred, Tail, Right> : Result.TExtendsFalse : Result.TExtendsTrue<Inferred>);
|
|
21
20
|
export type TExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, InstantiatedLeft extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Left>> = (Right extends TTuple<infer Types extends TSchema[]> ? TExtendsTupleToTuple<Inferred, InstantiatedLeft, Types> : Right extends TArray<infer Type extends TSchema> ? TExtendsTupleToArray<Inferred, InstantiatedLeft, Type> : TExtendsRight<Inferred, TTuple<InstantiatedLeft>, Right>);
|
|
22
21
|
export declare function ExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsTuple<Inferred, Left, Right>;
|
|
23
22
|
export {};
|
|
@@ -47,31 +47,11 @@ function ExtendsTupleToTuple(inferred, left, right) {
|
|
|
47
47
|
const reversed = Reversed(instantiatedRight);
|
|
48
48
|
return Elements(inferred, reversed, ApplyReverse(left, reversed), ApplyReverse(instantiatedRight, reversed));
|
|
49
49
|
}
|
|
50
|
-
// function ExtendsTupleToArrayReduce<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema>
|
|
51
|
-
// (inferred: Inferred, left: [...Left], right: Right):
|
|
52
|
-
// TExtendsTupleToArrayReduce<Inferred, Left, Right> {
|
|
53
|
-
// return (
|
|
54
|
-
// Guard.ShiftLeft(left, (head, tail) =>
|
|
55
|
-
// Result.Match(ExtendsLeft(inferred, head, right), inferred =>
|
|
56
|
-
// ExtendsTupleToArrayReduce(inferred, tail, right), // Stack Overflow Here (Large Left)
|
|
57
|
-
// () => Result.ExtendsFalse()),
|
|
58
|
-
// () => Result.ExtendsTrue(inferred))
|
|
59
|
-
// ) as never
|
|
60
|
-
// }
|
|
61
|
-
function ExtendsTupleToArrayReduce(inferred, left, right) {
|
|
62
|
-
for (const head of left) {
|
|
63
|
-
const result = ExtendsLeft(inferred, head, right);
|
|
64
|
-
if (!Result.IsExtendsTrueLike(result))
|
|
65
|
-
return result;
|
|
66
|
-
inferred = result.inferred; // (review-assign-to-argument)
|
|
67
|
-
}
|
|
68
|
-
return Result.ExtendsTrue(inferred);
|
|
69
|
-
}
|
|
70
50
|
function ExtendsTupleToArray(inferred, left, right) {
|
|
71
51
|
const inferrable = TryInferable(right);
|
|
72
52
|
return (IsInferable(inferrable)
|
|
73
53
|
? InferUnionResult(inferred, inferrable['name'], left, inferrable['type'])
|
|
74
|
-
:
|
|
54
|
+
: Guard.ShiftLeft(left, (head, tail) => Result.Match(ExtendsLeft(inferred, head, right), inferred => ExtendsTupleToArray(inferred, tail, right), () => Result.ExtendsFalse()), () => Result.ExtendsTrue(inferred)));
|
|
75
55
|
}
|
|
76
56
|
export function ExtendsTuple(inferred, left, right) {
|
|
77
57
|
const instantiatedLeft = InstantiateElements(inferred, State([], []), left);
|
|
@@ -12,7 +12,7 @@ export function FromObject(context, type, value) {
|
|
|
12
12
|
return value;
|
|
13
13
|
const additionalProperties = GetAdditionalProperties(type);
|
|
14
14
|
for (const key of Guard.Keys(value)) {
|
|
15
|
-
if (Guard.HasPropertyKey(type.properties, key)
|
|
15
|
+
if (Guard.HasPropertyKey(type.properties, key)) {
|
|
16
16
|
value[key] = FromType(context, type.properties[key], value[key]);
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns a
|
|
3
|
-
* but also supports deep cloning
|
|
4
|
-
* to clone TypeBox types while retaining their enumerable and non-enumerable properties.
|
|
2
|
+
* Returns a Clone of the given value. This function is similar to structuredClone()
|
|
3
|
+
* but also supports deep cloning instances of Map, Set and TypeArray.
|
|
5
4
|
*/
|
|
6
|
-
export declare function Clone<Value extends unknown
|
|
5
|
+
export declare function Clone<Value extends unknown>(value: Value): Value;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import {
|
|
2
|
+
import { Clone as SystemClone } from '../../system/memory/clone.mjs';
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
// Clone
|
|
5
|
+
// ------------------------------------------------------------------
|
|
3
6
|
/**
|
|
4
|
-
* Returns a
|
|
5
|
-
* but also supports deep cloning
|
|
6
|
-
* to clone TypeBox types while retaining their enumerable and non-enumerable properties.
|
|
7
|
+
* Returns a Clone of the given value. This function is similar to structuredClone()
|
|
8
|
+
* but also supports deep cloning instances of Map, Set and TypeArray.
|
|
7
9
|
*/
|
|
8
10
|
export function Clone(value) {
|
|
9
|
-
return
|
|
11
|
+
return SystemClone(value);
|
|
10
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import {
|
|
3
|
-
import { Arguments
|
|
2
|
+
import { Settings } from '../../system/system.mjs';
|
|
3
|
+
import { Arguments } from '../../system/arguments/index.mjs';
|
|
4
4
|
import { AssertError } from '../assert/index.mjs';
|
|
5
5
|
import { Check } from '../check/index.mjs';
|
|
6
6
|
import { Errors } from '../errors/index.mjs';
|
|
@@ -18,11 +18,8 @@ export class ParseError extends AssertError {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
function Assert(context, type, value) {
|
|
21
|
-
EnableParseErrors();
|
|
22
|
-
const errors = Errors(context, type, value);
|
|
23
|
-
DisableParseErrors();
|
|
24
21
|
if (!Check(context, type, value))
|
|
25
|
-
throw new ParseError(value,
|
|
22
|
+
throw new ParseError(value, Errors(context, type, value));
|
|
26
23
|
return value;
|
|
27
24
|
}
|
|
28
25
|
// ------------------------------------------------------------------
|
|
@@ -46,8 +43,5 @@ export function Parse(...args) {
|
|
|
46
43
|
return value;
|
|
47
44
|
if (Settings.Get().correctiveParse)
|
|
48
45
|
return Parser(context, type, value);
|
|
49
|
-
|
|
50
|
-
const errors = Errors(context, type, value);
|
|
51
|
-
DisableParseErrors();
|
|
52
|
-
throw new ParseError(value, errors);
|
|
46
|
+
throw new ParseError(value, Errors(context, type, value));
|
|
53
47
|
}
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import Guard from '../../guard/index.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Intersect, IsIntersect } from '../../type/index.mjs';
|
|
3
|
+
import { IsArray, Array as _Array_, ArrayOptions } from '../../type/index.mjs';
|
|
4
|
+
import { IsUnion, Union } from '../../type/index.mjs';
|
|
6
5
|
import { IsObject, Object as _Object_ } from '../../type/index.mjs';
|
|
7
|
-
import { IsRecord, Record,
|
|
8
|
-
import { String } from '../../type/index.mjs';
|
|
6
|
+
import { IsRecord, Record, RecordKey, RecordValue } from '../../type/index.mjs';
|
|
9
7
|
import { IsTuple, Tuple } from '../../type/index.mjs';
|
|
10
|
-
import {
|
|
8
|
+
import { IsIntersect, Intersect } from '../../type/index.mjs';
|
|
11
9
|
import { Priority } from '../../type/index.mjs';
|
|
12
10
|
// ------------------------------------------------------------------
|
|
13
11
|
// Modifiers (Mutable)
|
|
14
12
|
//
|
|
15
13
|
// Prioritized types lose `~modifier` properties and additional constraints
|
|
16
14
|
// (e.g. additionalProperties) during the mapping phase and need to be
|
|
17
|
-
// reassigned afterward.
|
|
18
|
-
//
|
|
19
|
-
// Memory.Assign to ensure modifiers are retained and we preserve type
|
|
20
|
-
// configurations (review)
|
|
15
|
+
// reassigned afterward. This is a fast mutable assignment to handle that,
|
|
16
|
+
// but we should consider a more general solution. (review)
|
|
21
17
|
//
|
|
22
18
|
// ------------------------------------------------------------------
|
|
23
19
|
function Modifiers(type, next) {
|
|
24
|
-
|
|
20
|
+
for (const key of Guard.Keys(type)) {
|
|
21
|
+
if (Guard.HasPropertyKey(next, key))
|
|
22
|
+
continue;
|
|
23
|
+
next[key] = type[key];
|
|
24
|
+
}
|
|
25
|
+
return next;
|
|
25
26
|
}
|
|
26
27
|
// ------------------------------------------------------------------
|
|
27
28
|
// Properties
|
|
@@ -33,18 +34,6 @@ function FromProperties(properties) {
|
|
|
33
34
|
return result;
|
|
34
35
|
}
|
|
35
36
|
// ------------------------------------------------------------------
|
|
36
|
-
// FromRecordKey
|
|
37
|
-
//
|
|
38
|
-
// This is required because RecordKey(...) returns a canonical
|
|
39
|
-
// decoded type derived from the pattern. When the pattern is an
|
|
40
|
-
// unrecognized user-defined one, the result falls through to
|
|
41
|
-
// TString (^.*$) and the user-defined pattern is lost. This
|
|
42
|
-
// function ensures the exact pattern is retained.
|
|
43
|
-
// ------------------------------------------------------------------
|
|
44
|
-
function FromRecordKey(type) {
|
|
45
|
-
return String({ pattern: RecordPattern(type) });
|
|
46
|
-
}
|
|
47
|
-
// ------------------------------------------------------------------
|
|
48
37
|
// PriorityTypes
|
|
49
38
|
// ------------------------------------------------------------------
|
|
50
39
|
function FromPriorityTypes(types) {
|
|
@@ -54,7 +43,7 @@ function FromPriorityTypes(types) {
|
|
|
54
43
|
// Types
|
|
55
44
|
// ------------------------------------------------------------------
|
|
56
45
|
function FromTypes(types) {
|
|
57
|
-
return types.map(
|
|
46
|
+
return types.map(type => FromType(type));
|
|
58
47
|
}
|
|
59
48
|
// ------------------------------------------------------------------
|
|
60
49
|
// Type
|
|
@@ -64,7 +53,7 @@ function FromType(type) {
|
|
|
64
53
|
IsIntersect(type) ? Intersect(FromTypes(type.allOf)) :
|
|
65
54
|
IsUnion(type) ? Union(FromPriorityTypes(type.anyOf)) :
|
|
66
55
|
IsObject(type) ? _Object_(FromProperties(type.properties)) :
|
|
67
|
-
IsRecord(type) ? Record(
|
|
56
|
+
IsRecord(type) ? Record(RecordKey(type), FromType(RecordValue(type))) :
|
|
68
57
|
IsTuple(type) ? Tuple(FromTypes(type.items)) :
|
|
69
58
|
type);
|
|
70
59
|
return Modifiers(type, next);
|