@ghostry/fabricator 0.0.1 → 0.0.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/README.md +18 -12
- package/dist/esm/Adapter/Core.js +3 -3
- package/dist/esm/Enumeration/Enumerate.js +16 -13
- package/dist/esm/Error/index.js +16 -8
- package/dist/esm/Fabricator/Constructor.js +12 -14
- package/dist/esm/Harnessing/Core.js +30 -0
- package/dist/esm/Harnessing/Salt.js +12 -0
- package/dist/esm/Harnessing/Types.js +1 -0
- package/dist/esm/Instance/Core.js +25 -41
- package/dist/esm/Instance/Stack/Async.js +10 -0
- package/dist/esm/Instance/Stack/Sync.js +16 -0
- package/dist/esm/Primitive/bigint/Registry.js +12 -12
- package/dist/esm/Primitive/boolean/Registry.js +2 -1
- package/dist/esm/Primitive/date/Registry.js +15 -14
- package/dist/esm/Primitive/null/Registry.js +2 -1
- package/dist/esm/Primitive/number/Registry.js +18 -17
- package/dist/esm/Primitive/recursive/Fabricator.js +1 -1
- package/dist/esm/Primitive/symbol/Registry.js +2 -1
- package/dist/esm/Primitive/undefined/Registry.js +2 -1
- package/dist/esm/Random/index.js +24 -79
- package/dist/esm/Utility/Core.js +6 -1
- package/dist/esm/adapting.js +2 -0
- package/dist/esm/harnessing.js +1 -0
- package/dist/esm/index.js +5 -4
- package/dist/esm/internal.js +2 -2
- package/dist/types/Adapter/Core.d.ts +30 -33
- package/dist/types/Adapter/Types.d.ts +78 -88
- package/dist/types/Bound.d.ts +15 -15
- package/dist/types/Distribution/index.d.ts +54 -61
- package/dist/types/Enumeration/Enumerate.d.ts +24 -24
- package/dist/types/Enumeration/Plan.d.ts +22 -26
- package/dist/types/Enumeration/Types.d.ts +38 -43
- package/dist/types/Error/index.d.ts +103 -89
- package/dist/types/Fabricator/Constructor.d.ts +24 -26
- package/dist/types/Fabricator/Types.d.ts +73 -81
- package/dist/types/Harnessing/Core.d.ts +43 -0
- package/dist/types/Harnessing/Salt.d.ts +31 -0
- package/dist/types/Harnessing/Types.d.ts +79 -0
- package/dist/types/Instance/Core.d.ts +38 -74
- package/dist/types/Instance/Stack/Async.d.ts +14 -0
- package/dist/types/Instance/Stack/Sync.d.ts +14 -0
- package/dist/types/Instance/Types.d.ts +98 -102
- package/dist/types/Primitive/always/Schema.d.ts +8 -8
- package/dist/types/Primitive/always/Types.d.ts +7 -7
- package/dist/types/Primitive/array/Registry.d.ts +10 -8
- package/dist/types/Primitive/array/Schema.d.ts +4 -5
- package/dist/types/Primitive/array/Types.d.ts +6 -6
- package/dist/types/Primitive/bigint/Registry.d.ts +6 -6
- package/dist/types/Primitive/bigint/Schema.d.ts +8 -8
- package/dist/types/Primitive/bigint/Types.d.ts +5 -5
- package/dist/types/Primitive/boolean/Outcomes.d.ts +8 -8
- package/dist/types/Primitive/boolean/Registry.d.ts +2 -12
- package/dist/types/Primitive/boolean/Schema.d.ts +8 -8
- package/dist/types/Primitive/boolean/Types.d.ts +3 -3
- package/dist/types/Primitive/choice/Fabricator.d.ts +6 -7
- package/dist/types/Primitive/choice/Registry.d.ts +13 -13
- package/dist/types/Primitive/choice/Schema.d.ts +6 -6
- package/dist/types/Primitive/choice/Types.d.ts +11 -11
- package/dist/types/Primitive/date/Registry.d.ts +25 -48
- package/dist/types/Primitive/date/Schema.d.ts +9 -10
- package/dist/types/Primitive/date/Types.d.ts +4 -4
- package/dist/types/Primitive/enum/Registry.d.ts +13 -13
- package/dist/types/Primitive/enum/Schema.d.ts +5 -5
- package/dist/types/Primitive/enum/Types.d.ts +17 -19
- package/dist/types/Primitive/namespace.d.ts +10 -10
- package/dist/types/Primitive/null/Registry.d.ts +2 -2
- package/dist/types/Primitive/null/Schema.d.ts +2 -2
- package/dist/types/Primitive/null/Types.d.ts +3 -3
- package/dist/types/Primitive/nullable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/nullable/Schema.d.ts +13 -13
- package/dist/types/Primitive/nullable/Types.d.ts +9 -10
- package/dist/types/Primitive/nullish/Fabricator.d.ts +12 -13
- package/dist/types/Primitive/nullish/Schema.d.ts +8 -8
- package/dist/types/Primitive/nullish/Types.d.ts +12 -13
- package/dist/types/Primitive/number/Registry.d.ts +20 -38
- package/dist/types/Primitive/number/Schema.d.ts +11 -12
- package/dist/types/Primitive/number/Types.d.ts +13 -13
- package/dist/types/Primitive/number/defaults.d.ts +3 -3
- package/dist/types/Primitive/object/Fabricator.d.ts +15 -15
- package/dist/types/Primitive/object/Registry.d.ts +8 -8
- package/dist/types/Primitive/object/Schema.d.ts +10 -10
- package/dist/types/Primitive/object/Types.d.ts +20 -22
- package/dist/types/Primitive/object/compute/Fabricator.d.ts +4 -5
- package/dist/types/Primitive/object/compute/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/compute/Types.d.ts +19 -20
- package/dist/types/Primitive/object/omittable/Fabricator.d.ts +10 -10
- package/dist/types/Primitive/object/omittable/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/omittable/Schema.d.ts +11 -11
- package/dist/types/Primitive/object/omittable/Types.d.ts +14 -15
- package/dist/types/Primitive/object/optional/Fabricator.d.ts +16 -18
- package/dist/types/Primitive/object/optional/Outcomes.d.ts +2 -2
- package/dist/types/Primitive/object/optional/Schema.d.ts +4 -4
- package/dist/types/Primitive/object/optional/Types.d.ts +17 -17
- package/dist/types/Primitive/opaque/Registry.d.ts +3 -3
- package/dist/types/Primitive/opaque/Schema.d.ts +8 -9
- package/dist/types/Primitive/record/Registry.d.ts +8 -6
- package/dist/types/Primitive/record/Schema.d.ts +9 -11
- package/dist/types/Primitive/record/Types.d.ts +25 -25
- package/dist/types/Primitive/recursive/Fabricator.d.ts +20 -21
- package/dist/types/Primitive/recursive/Registry.d.ts +6 -7
- package/dist/types/Primitive/recursive/Schema.d.ts +8 -8
- package/dist/types/Primitive/recursive/Terminate.d.ts +13 -14
- package/dist/types/Primitive/recursive/Types.d.ts +31 -31
- package/dist/types/Primitive/recursive/self/Fabricator.d.ts +11 -12
- package/dist/types/Primitive/recursive/self/Schema.d.ts +10 -10
- package/dist/types/Primitive/recursive/self/Types.d.ts +7 -8
- package/dist/types/Primitive/string/Constants.d.ts +12 -13
- package/dist/types/Primitive/string/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/string/Registry.d.ts +10 -16
- package/dist/types/Primitive/string/Schema.d.ts +5 -5
- package/dist/types/Primitive/string/Types.d.ts +17 -17
- package/dist/types/Primitive/symbol/Fabricator.d.ts +2 -2
- package/dist/types/Primitive/symbol/Registry.d.ts +4 -11
- package/dist/types/Primitive/symbol/Schema.d.ts +6 -6
- package/dist/types/Primitive/symbol/Types.d.ts +2 -2
- package/dist/types/Primitive/tuple/Fabricator.d.ts +7 -8
- package/dist/types/Primitive/tuple/Schema.d.ts +5 -5
- package/dist/types/Primitive/tuple/Types.d.ts +24 -25
- package/dist/types/Primitive/undefinable/Fabricator.d.ts +7 -7
- package/dist/types/Primitive/undefinable/Schema.d.ts +13 -13
- package/dist/types/Primitive/undefinable/Types.d.ts +10 -10
- package/dist/types/Primitive/undefined/Registry.d.ts +2 -2
- package/dist/types/Primitive/undefined/Schema.d.ts +4 -4
- package/dist/types/Primitive/undefined/Types.d.ts +3 -3
- package/dist/types/Random/Generator/sfc32.d.ts +4 -4
- package/dist/types/Random/Types.d.ts +151 -293
- package/dist/types/Random/index.d.ts +56 -81
- package/dist/types/Schema/Core.d.ts +19 -21
- package/dist/types/Schema/Registry.d.ts +3 -3
- package/dist/types/Schema/Types.d.ts +41 -48
- package/dist/types/Types.d.ts +39 -45
- package/dist/types/Utility/Core.d.ts +18 -9
- package/dist/types/adapting.d.ts +32 -0
- package/dist/types/harnessing.d.ts +30 -0
- package/dist/types/index.d.ts +95 -128
- package/dist/types/internal.d.ts +53 -40
- package/package.json +39 -7
- package/dist/esm/Random/CallSite.js +0 -56
- package/dist/types/Random/CallSite.d.ts +0 -59
package/dist/esm/Random/index.js
CHANGED
|
@@ -1,85 +1,53 @@
|
|
|
1
|
-
import { FabricatorError } from "../Error/index.js";
|
|
2
1
|
import { Layer, MAX_TIME } from "../Types.js";
|
|
3
|
-
import { inline } from "../Utility/Core.js";
|
|
4
2
|
import { cyrb128 } from "../Utility/Digest.js";
|
|
5
|
-
import { directoryOf, normalizeLocation, relativize, resolveCallerFile } from "./CallSite.js";
|
|
6
3
|
import { sfc32 } from "./Generator/sfc32.js";
|
|
7
4
|
function defaultAlgorithm(seed) {
|
|
8
5
|
return sfc32(...cyrb128(seed));
|
|
9
6
|
}
|
|
10
|
-
function
|
|
7
|
+
function randomSalt() {
|
|
11
8
|
return (0x100000000 * Math.random() >>> 0).toString(10);
|
|
12
9
|
}
|
|
13
|
-
function deriveClock(algorithm,
|
|
10
|
+
function deriveClock(algorithm, salt) {
|
|
14
11
|
const stream = toStream(algorithm, JSON.stringify([
|
|
15
|
-
|
|
12
|
+
salt,
|
|
16
13
|
"clock"
|
|
17
14
|
]));
|
|
18
15
|
return Math.trunc((2 * stream.next() - 1) * MAX_TIME);
|
|
19
16
|
}
|
|
20
|
-
function
|
|
21
|
-
var _ref, _ref1;
|
|
17
|
+
function envSalt() {
|
|
22
18
|
const env = "object" == typeof process ? process.env : void 0;
|
|
23
|
-
return null
|
|
19
|
+
return null == env ? void 0 : env["FABRICATOR_SALT"];
|
|
24
20
|
}
|
|
25
21
|
function encode(trace) {
|
|
26
22
|
return JSON.stringify([
|
|
27
|
-
trace.
|
|
23
|
+
trace.salt,
|
|
28
24
|
trace.clock,
|
|
29
|
-
trace.root,
|
|
30
|
-
trace.file,
|
|
31
25
|
trace.path,
|
|
32
26
|
trace.kind,
|
|
33
27
|
trace.ordinal
|
|
34
28
|
]);
|
|
35
29
|
}
|
|
36
|
-
function
|
|
37
|
-
if (void 0 ===
|
|
38
|
-
const fromEnv =
|
|
30
|
+
function normalizeSalt(salt) {
|
|
31
|
+
if (void 0 === salt) {
|
|
32
|
+
const fromEnv = envSalt();
|
|
39
33
|
return void 0 === fromEnv ? [] : [
|
|
40
34
|
fromEnv
|
|
41
35
|
];
|
|
42
36
|
}
|
|
43
|
-
return "string" == typeof
|
|
44
|
-
|
|
37
|
+
return "string" == typeof salt ? [
|
|
38
|
+
salt
|
|
45
39
|
] : [
|
|
46
|
-
...
|
|
40
|
+
...salt
|
|
47
41
|
];
|
|
48
42
|
}
|
|
49
|
-
function Random_layer(
|
|
43
|
+
function Random_layer(salt) {
|
|
50
44
|
return {
|
|
51
|
-
[Layer]:
|
|
45
|
+
[Layer]: salt
|
|
52
46
|
};
|
|
53
47
|
}
|
|
54
48
|
function isLayered(value) {
|
|
55
49
|
return "object" == typeof value && null !== value && Layer in value;
|
|
56
50
|
}
|
|
57
|
-
function resolveAttribution(attribution) {
|
|
58
|
-
const policy = null != attribution ? attribution : {
|
|
59
|
-
kind: "call site"
|
|
60
|
-
};
|
|
61
|
-
switch(policy.kind){
|
|
62
|
-
case "none":
|
|
63
|
-
return policy;
|
|
64
|
-
case "rooted":
|
|
65
|
-
{
|
|
66
|
-
const root = normalizeLocation(policy.root);
|
|
67
|
-
if (!root.startsWith("/")) throw new FabricatorError.InvalidAttributionRootError(policy.root);
|
|
68
|
-
return toRooted(root);
|
|
69
|
-
}
|
|
70
|
-
case "call site":
|
|
71
|
-
{
|
|
72
|
-
const root = directoryOf(resolveCallerFile());
|
|
73
|
-
return toRooted(root);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function toRooted(root) {
|
|
78
|
-
return {
|
|
79
|
-
kind: "rooted",
|
|
80
|
-
root: root.endsWith("/") ? root : `${root}/`
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
51
|
function toStream(algorithm, seed) {
|
|
84
52
|
const generator = algorithm(seed);
|
|
85
53
|
let iterations = 0;
|
|
@@ -99,53 +67,30 @@ function toStreamFromTrace(algorithm, trace) {
|
|
|
99
67
|
}
|
|
100
68
|
function toRandomSource(options) {
|
|
101
69
|
var _options_algorithm;
|
|
102
|
-
let
|
|
70
|
+
let salt = normalizeSalt(options.salt);
|
|
103
71
|
let algorithm = null != (_options_algorithm = options.algorithm) ? _options_algorithm : defaultAlgorithm;
|
|
104
|
-
let attribution = resolveAttribution(options.attribution);
|
|
105
72
|
const clock = options.clock;
|
|
106
|
-
let
|
|
107
|
-
function
|
|
108
|
-
var
|
|
109
|
-
const ordinal = null != (_constructionOrdinals_get = constructionOrdinals.get(file)) ? _constructionOrdinals_get : 0;
|
|
110
|
-
constructionOrdinals.set(file, ordinal + 1);
|
|
111
|
-
return ordinal;
|
|
112
|
-
}
|
|
113
|
-
function toRoot(kind, pins = {}) {
|
|
114
|
-
var _pins_root, _pins_clock;
|
|
115
|
-
const replaying = void 0 !== pins.root;
|
|
116
|
-
const root = null != (_pins_root = pins.root) ? _pins_root : kind;
|
|
117
|
-
const file = replaying || void 0 !== pins.file ? pins.file : resolveRootFile(kind);
|
|
118
|
-
const ordinal = inline(()=>{
|
|
119
|
-
if (replaying || void 0 !== pins.ordinal) return pins.ordinal;
|
|
120
|
-
if ("unattributed" === root) return;
|
|
121
|
-
return nextConstructionOrdinal(file);
|
|
122
|
-
});
|
|
73
|
+
let constructionOrdinal = 0;
|
|
74
|
+
function toRoot(pins = {}) {
|
|
75
|
+
var _pins_salt, _pins_clock;
|
|
123
76
|
return {
|
|
124
|
-
|
|
77
|
+
salt: null != (_pins_salt = pins.salt) ? _pins_salt : salt,
|
|
125
78
|
clock: null != (_pins_clock = pins.clock) ? _pins_clock : clock,
|
|
126
|
-
|
|
127
|
-
file,
|
|
128
|
-
ordinal
|
|
79
|
+
ordinal: void 0 !== pins.ordinal ? pins.ordinal : constructionOrdinal++
|
|
129
80
|
};
|
|
130
81
|
}
|
|
131
|
-
function
|
|
132
|
-
if ("attributed" !== kind) return;
|
|
133
|
-
if ("none" === attribution.kind) return;
|
|
134
|
-
return relativize(attribution.root, resolveCallerFile());
|
|
135
|
-
}
|
|
136
|
-
function fork(childSeed) {
|
|
82
|
+
function fork(childSalt) {
|
|
137
83
|
return toRandomSource({
|
|
138
|
-
|
|
84
|
+
salt: childSalt,
|
|
139
85
|
algorithm,
|
|
140
|
-
attribution,
|
|
141
86
|
clock
|
|
142
87
|
});
|
|
143
88
|
}
|
|
144
89
|
return {
|
|
145
90
|
toRoot,
|
|
146
91
|
algorithm,
|
|
147
|
-
|
|
92
|
+
salt,
|
|
148
93
|
fork
|
|
149
94
|
};
|
|
150
95
|
}
|
|
151
|
-
export { Random_layer as layer, defaultAlgorithm, deriveClock, encode, isLayered,
|
|
96
|
+
export { Random_layer as layer, defaultAlgorithm, deriveClock, encode, isLayered, normalizeSalt, randomSalt, toRandomSource, toStream, toStreamFromTrace };
|
package/dist/esm/Utility/Core.js
CHANGED
|
@@ -3,6 +3,11 @@ function inline(fn) {
|
|
|
3
3
|
return fn();
|
|
4
4
|
}
|
|
5
5
|
function never(_) {}
|
|
6
|
+
function noop() {}
|
|
7
|
+
function isThenable(value) {
|
|
8
|
+
if ("object" != typeof value || null === value) return false;
|
|
9
|
+
return "function" == typeof value.then;
|
|
10
|
+
}
|
|
6
11
|
function isArray(candidate) {
|
|
7
12
|
return Array.isArray(candidate);
|
|
8
13
|
}
|
|
@@ -33,4 +38,4 @@ function replace(value) {
|
|
|
33
38
|
[Replace]: true
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
|
-
export { inline, isArray, isPlainObject, isPollutionKey, mergeableKeys, never, replace };
|
|
41
|
+
export { inline, isArray, isPlainObject, isPollutionKey, isThenable, mergeableKeys, never, noop, replace };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { integration } from "./Harnessing/Core.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toStack } from "#stack";
|
|
2
|
+
import { instantiate, overlay } from "./Instance/Core.js";
|
|
2
3
|
function initialize(config) {
|
|
3
|
-
|
|
4
|
+
var _ref;
|
|
5
|
+
return instantiate(overlay({}, null != config ? config : {}), null != (_ref = null == config ? void 0 : config.stack) ? _ref : toStack()).instance;
|
|
4
6
|
}
|
|
5
|
-
export {
|
|
7
|
+
export { Omitted } from "./Types.js";
|
|
6
8
|
export { layer } from "./Random/index.js";
|
|
7
9
|
export { FabricatorError } from "./Error/index.js";
|
|
8
|
-
export { drive } from "./Adapter/Core.js";
|
|
9
10
|
export { registry } from "./Schema/Registry.js";
|
|
10
11
|
export { effectiveDiscrete, toBound } from "./Bound.js";
|
|
11
12
|
export { initialize };
|
package/dist/esm/internal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Children, Kind, Meta, Produces } from "./Types.js";
|
|
2
2
|
export { isPlainObject } from "./Utility/Core.js";
|
|
3
3
|
export { plan, resolve } from "./Enumeration/Plan.js";
|
|
4
|
-
export { defaultAlgorithm, encode,
|
|
5
|
-
export {
|
|
4
|
+
export { defaultAlgorithm, encode, randomSalt, toRandomSource, toStream, toStreamFromTrace } from "./Random/index.js";
|
|
5
|
+
export { toStack as toSynchronousStack } from "./Instance/Stack/Sync.js";
|
|
@@ -4,61 +4,58 @@ type OverrideSchemaAdaptation<$Schema extends object, $Map extends Adaptations>
|
|
|
4
4
|
readonly [Adaptation]?: WithAdaptations<AdaptationsOf<$Schema>, $Map>;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
|
-
* One adapter's entry, keyed by `$Adapter["key"]`. Written as a mapped
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* One adapter's entry, keyed by `$Adapter["key"]`. Written as a mapped type
|
|
8
|
+
* rather than built inline: a computed key in an object literal (`{
|
|
9
|
+
* [adapter.key]: produce }`) widens to a `string` index signature, which no
|
|
10
|
+
* adapter's literal-keyed dispatch matches.
|
|
11
11
|
*/
|
|
12
12
|
export type AdaptationEntry<$Adapter extends Adapter, $Returnable> = {
|
|
13
13
|
readonly [$K in $Adapter["key"]]: (schema: any) => $Returnable;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* A copy of `schema` carrying `produce` as `adapter`'s adaptation:
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* `Schema<..., WithAdaptations<...>>`.
|
|
16
|
+
* A copy of `schema` carrying `produce` as `adapter`'s adaptation: that
|
|
17
|
+
* adapter's prior entry is replaced (via {@link layer}), every other adapter's
|
|
18
|
+
* is carried forward. Every kind's `.adapt(...)` is a call to this, re-typed to
|
|
19
|
+
* that kind's own `Schema<..., WithAdaptations<...>>`.
|
|
21
20
|
*
|
|
22
|
-
* Takes the adapter and producer separately rather than a prebuilt map
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
21
|
+
* Takes the adapter and producer separately rather than a prebuilt map so the
|
|
22
|
+
* key stays a literal, per {@link AdaptationEntry}. The return type mirrors the
|
|
23
|
+
* merge (rather than handing back `$Schema`) so call sites need no cast:
|
|
24
|
+
* `AdaptationsOf<$Schema>` recovers the prior map from whichever kind's `Core`
|
|
25
|
+
* was passed in.
|
|
27
26
|
*/
|
|
28
27
|
export declare function withAdaptations<const $Schema extends object, const $Adapter extends Adapter, $Returnable>(schema: $Schema, adapter: $Adapter, produce: (adapting: Adapting<any>) => $Returnable): OverrideSchemaAdaptation<$Schema, AdaptationEntry<$Adapter, $Returnable>>;
|
|
29
28
|
/**
|
|
30
29
|
* {@link withAdaptations} at the map level, for a kind that keeps its
|
|
31
30
|
* adaptations beside its schema rather than on it — `object`, whose
|
|
32
31
|
* `extend`/`refine`/`override` each rebuild the schema from scratch, so
|
|
33
|
-
* `Registry.ts`'s `make` has to thread the map through explicitly (see
|
|
34
|
-
*
|
|
32
|
+
* `Registry.ts`'s `make` has to thread the map through explicitly (see its
|
|
33
|
+
* `adapt`).
|
|
35
34
|
*
|
|
36
|
-
* `undefined` rather than an empty map when there is nothing to carry,
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* runtime.
|
|
35
|
+
* `undefined` rather than an empty map when there is nothing to carry, for the
|
|
36
|
+
* same reason `patched` drops the symbol: an absent map and an empty one mean
|
|
37
|
+
* the same thing, and only one of them should exist at runtime.
|
|
40
38
|
*/
|
|
41
39
|
export declare function mergeAdaptations<$Prior extends Adaptations, const $Adapter extends Adapter, $Returnable>(prior: $Prior | undefined, adapter: $Adapter, produce: (adapting: Adapting<any>) => $Returnable): WithAdaptations<$Prior, AdaptationEntry<$Adapter, $Returnable>> | undefined;
|
|
42
40
|
/**
|
|
43
41
|
* Walk `schema` with `adapter`, resolving each node to its external
|
|
44
42
|
* counterpart. Every adapter's entry point is a call to this.
|
|
45
43
|
*
|
|
46
|
-
* The adaptation lookup lives here, ahead of the adapter's own
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* `object` field, `array` element, or `choice` option gets the same
|
|
44
|
+
* The adaptation lookup lives here, ahead of the adapter's own per-kind
|
|
45
|
+
* dispatch, so an explicit adaptation wins over the kind's mapping — and here
|
|
46
|
+
* rather than in each adapter so it applies at _every_ node the walk reaches,
|
|
47
|
+
* not just the one it started from. That is why an adapter recurses through the
|
|
48
|
+
* {@link Recurse} it is handed rather than calling its own `convert` again: a
|
|
49
|
+
* nested `object` field, `array` element, or `choice` option gets the same
|
|
53
50
|
* treatment as the root.
|
|
54
51
|
*
|
|
55
|
-
* Paired with {@link layer}: together they make `toTypeBox(schema)`
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
52
|
+
* Paired with {@link layer}: together they make `toTypeBox(schema)` _inside_ an
|
|
53
|
+
* adaptation resolve to the layer that adaptation replaced instead of
|
|
54
|
+
* re-entering itself. This reads the entry; `layer` already substituted the
|
|
55
|
+
* previous one into the argument. Splitting the two across packages is how they
|
|
56
|
+
* drift.
|
|
60
57
|
*/
|
|
61
|
-
export declare function
|
|
58
|
+
export declare function walk<$Context, $Returnable>(adapter: Adapter<string, $Context, $Returnable>, schema: {
|
|
62
59
|
[Adaptation]?: Adaptations;
|
|
63
60
|
}, context: $Context): $Returnable;
|
|
64
61
|
export {};
|
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
import type { Adaptation, Meta } from "../Types";
|
|
2
2
|
/**
|
|
3
|
-
* One adapter's override for one schema,
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* One adapter's override for one schema, _as stored_ in `[Adaptation]` — the
|
|
4
|
+
* loosest signature the mechanism needs. An adapter states its real return type
|
|
5
|
+
* on {@link Adapter.convert}, and `.adapt(...)` checks a supplied adaptation
|
|
6
|
+
* against that; nothing here reads either end.
|
|
7
7
|
*
|
|
8
|
-
* Not the shape a caller writes: a kind's `.adapt(...)` takes a producer
|
|
9
|
-
*
|
|
10
|
-
* `mergeAdaptations` wrap into this one entry point-side. The stored
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* account of what a schema carries.
|
|
8
|
+
* Not the shape a caller writes: a kind's `.adapt(...)` takes a producer of
|
|
9
|
+
* {@link Adapting}, which `Adapter/Core.ts`'s `withAdaptations`/
|
|
10
|
+
* `mergeAdaptations` wrap into this one entry point-side. The stored form stays
|
|
11
|
+
* schema-taking so `patched`/`layer` treat an incoming producer and a prior
|
|
12
|
+
* layered entry as one type, and so `AdaptationEntry`'s `(schema: any) =>
|
|
13
|
+
* $Returnable` is an accurate account of what a schema carries.
|
|
15
14
|
*/
|
|
16
15
|
export type SchemaAdaptation = (schema: any) => unknown;
|
|
17
16
|
/**
|
|
18
|
-
* What a kind's `.adapt(adapter, produce)` hands its producer: the schema
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* What a kind's `.adapt(adapter, produce)` hands its producer: the schema being
|
|
18
|
+
* adapted, and that schema's `[Meta]` — one object rather than two parameters,
|
|
19
|
+
* so destructuring picks whichever half is needed and neither is reachable only
|
|
20
|
+
* through a well-known symbol.
|
|
22
21
|
*
|
|
23
|
-
* `schema` carries whichever adaptation for this same adapter it
|
|
24
|
-
*
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* describe one object.
|
|
22
|
+
* `schema` carries whichever adaptation for this same adapter it replaced,
|
|
23
|
+
* absent at the bottom of the stack (see `Adapter/Core.ts`'s `layer`) — so
|
|
24
|
+
* `toTypeBox(schema)` inside a producer resolves to the previous layer, or to
|
|
25
|
+
* the kind's ordinary mapping when there is none. `meta` is read off that same
|
|
26
|
+
* substituted schema, so the two keys describe one object.
|
|
29
27
|
*
|
|
30
|
-
* `meta`'s shape is the kind's own config blob, derived by indexed
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
28
|
+
* `meta`'s shape is the kind's own config blob, derived by indexed access
|
|
29
|
+
* rather than named separately so no kind states its own `Meta` twice in an
|
|
30
|
+
* `adapt` signature. **Readable but not stabilized**: an adaptation may read
|
|
31
|
+
* it; a kind stays free to restructure it — nothing outside a kind's own files
|
|
32
|
+
* should _interpret_ another kind's `[Meta]`.
|
|
35
33
|
*
|
|
36
34
|
* A kind with no bare-form default carries no `[Meta]` at runtime until
|
|
37
35
|
* configured (`string`/`bigint`'s registry exports — see "Anatomy of a
|
|
38
|
-
* primitive"), so `meta` can be `undefined` there despite this type.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
36
|
+
* primitive"), so `meta` can be `undefined` there despite this type. Same
|
|
37
|
+
* imprecision `Schema<$Meta>` already states, and why the TypeBox adapter reads
|
|
38
|
+
* `[Meta]` defensively for those kinds.
|
|
41
39
|
*/
|
|
42
40
|
export type Adapting<$Schema extends {
|
|
43
41
|
[Meta]: unknown;
|
|
@@ -46,70 +44,64 @@ export type Adapting<$Schema extends {
|
|
|
46
44
|
readonly meta: $Schema[typeof Meta];
|
|
47
45
|
};
|
|
48
46
|
/**
|
|
49
|
-
* What a Schema's `[Adaptation]` holds: each adapter's override, under
|
|
50
|
-
*
|
|
47
|
+
* What a Schema's `[Adaptation]` holds: each adapter's override, under that
|
|
48
|
+
* adapter's own key.
|
|
51
49
|
*
|
|
52
|
-
* Open rather than a closed registry of known libraries: an adapter is
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* nothing.
|
|
50
|
+
* Open rather than a closed registry of known libraries: an adapter is a value
|
|
51
|
+
* (see {@link Adapter}), not a name this package knows. Nothing has to be
|
|
52
|
+
* declared for a third party's adapter to work, and two adapters for different
|
|
53
|
+
* versions of the same library collide with nothing.
|
|
57
54
|
*/
|
|
58
55
|
export type Adaptations = {
|
|
59
56
|
readonly [key: string]: SchemaAdaptation;
|
|
60
57
|
};
|
|
61
58
|
/**
|
|
62
59
|
* An {@link Adaptations} update as `withAdaptations` accepts it. Identical
|
|
63
|
-
* except that an explicitly-`undefined` entry
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* at the bottom of the stack.
|
|
60
|
+
* except that an explicitly-`undefined` entry _removes_ that adapter's override
|
|
61
|
+
* — how the layering hands an adaptation the schema it is adapting with its own
|
|
62
|
+
* entry replaced by the previous one, or absent at the bottom of the stack.
|
|
67
63
|
*
|
|
68
|
-
* Not what a kind's `.adapt(...)` accepts: removal is an internal need
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* {@link Adaptations}.
|
|
64
|
+
* Not what a kind's `.adapt(...)` accepts: removal is an internal need of the
|
|
65
|
+
* layering, and letting a caller express it would produce a `[Adaptation]` type
|
|
66
|
+
* that `exactOptionalPropertyTypes` rejects against {@link Adaptations}.
|
|
72
67
|
*/
|
|
73
68
|
export type Patch = {
|
|
74
69
|
readonly [key: string]: SchemaAdaptation | undefined;
|
|
75
70
|
};
|
|
76
71
|
/**
|
|
77
72
|
* How an adapter recurses into a nested schema — handed to
|
|
78
|
-
* {@link Adapter.convert} by `Adapter/Core.ts`'s `
|
|
79
|
-
*
|
|
80
|
-
*
|
|
73
|
+
* {@link Adapter.convert} by `Adapter/Core.ts`'s `walk` rather than being the
|
|
74
|
+
* adapter's own private recursion, so every nested node goes back through the
|
|
75
|
+
* adaptation lookup, not only the outermost one.
|
|
81
76
|
*
|
|
82
|
-
* `$Context` is the adapter's own, and opaque here: an adapter that
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* (`Type.Array(recurse(element, context))`) with no cast at any call
|
|
77
|
+
* `$Context` is the adapter's own, and opaque here: an adapter that needs to
|
|
78
|
+
* carry something down its recursion (the enclosing `T.recursive`'s
|
|
79
|
+
* placeholder, say) threads it through unchanged. `$Returnable` is likewise the
|
|
80
|
+
* adapter's own — stated so a nested node's result drops straight into a
|
|
81
|
+
* composite (`Type.Array(recurse(element, context))`) with no cast at any call
|
|
88
82
|
* site.
|
|
89
83
|
*/
|
|
90
84
|
export type Recurse<$Context, $Returnable> = (schema: any, context: $Context) => $Returnable;
|
|
91
85
|
/**
|
|
92
|
-
* An adapter to one external schema library: a plain value, imported
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
86
|
+
* An adapter to one external schema library: a plain value, imported directly
|
|
87
|
+
* by whoever adapts a schema (`schema.adapt(typebox, ...)`) and by whoever
|
|
88
|
+
* converts one. Nothing to register — no global interface to declaration-merge,
|
|
89
|
+
* and no name chosen anywhere but here.
|
|
96
90
|
*
|
|
97
|
-
* `key` is the adapter's `[Adaptation]` namespace. Read off the value
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* adapters can coexist.
|
|
91
|
+
* `key` is the adapter's `[Adaptation]` namespace. Read off the value as a
|
|
92
|
+
* literal type, so a wrong one is an import error rather than an entry nothing
|
|
93
|
+
* looks up. Give it something collision-proof — a package specifier, versioned
|
|
94
|
+
* when a library's major rewrite means two adapters can coexist.
|
|
102
95
|
*
|
|
103
|
-
* `convert`'s declared return type is this adapter's external bound:
|
|
104
|
-
*
|
|
105
|
-
*
|
|
96
|
+
* `convert`'s declared return type is this adapter's external bound: the type
|
|
97
|
+
* every `.adapt(...)` against it must produce, and why an adaptation that
|
|
98
|
+
* returns the wrong thing fails at the call site.
|
|
106
99
|
*
|
|
107
|
-
* Deliberately
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* `$Bindings` uses, for no gain.
|
|
100
|
+
* Deliberately _not_ carrying the adapter's type-level mapping. An adapter
|
|
101
|
+
* package declares its own conversion entry point with its own return type
|
|
102
|
+
* (`toTypeBox<$S>(schema: $S): ToTypeBox<$S>`), so nothing has to compute a
|
|
103
|
+
* type-level mapping out of a stored value — which would need the
|
|
104
|
+
* interface-member-lookup encoding `ValueOf`'s `$Bindings` uses, for no gain.
|
|
113
105
|
*/
|
|
114
106
|
export interface Adapter<$Key extends string = string, $Context = unknown, $Returnable = unknown> {
|
|
115
107
|
readonly key: $Key;
|
|
@@ -119,27 +111,25 @@ export interface Adapter<$Key extends string = string, $Context = unknown, $Retu
|
|
|
119
111
|
* The adaptations a Schema (or a built Fabricator, which carries them
|
|
120
112
|
* identically) declares, or `{}` for one that declares none.
|
|
121
113
|
*
|
|
122
|
-
* The two steps — extract the map, then match against it — are
|
|
123
|
-
*
|
|
124
|
-
* `
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* which then fails each adapter's `Record<Key, ...>` check as it
|
|
132
|
-
* should.
|
|
114
|
+
* The two steps — extract the map, then match against it — are load-bearing,
|
|
115
|
+
* and why no adapter matches `{ [Adaptation]?: Record<Key, ...> }` directly.
|
|
116
|
+
* Every kind's `Core` declares `[Adaptation]` as _optional_, and a conditional
|
|
117
|
+
* matching an optional property against a schema that lacks it entirely still
|
|
118
|
+
* _succeeds_, inferring `unknown` (the same behavior `ValueOf` relies on for
|
|
119
|
+
* `[Produces]`) — so a direct match would resolve every unadapted schema to
|
|
120
|
+
* whatever the adapter's adaptation branch produces. Constraining the `infer`
|
|
121
|
+
* sends that case here, to `{}`, which then fails each adapter's `Record<Key,
|
|
122
|
+
* ...>` check as it should.
|
|
133
123
|
*/
|
|
134
124
|
export type AdaptationsOf<$Schema> = $Schema extends {
|
|
135
125
|
[Adaptation]?: infer $Adaptations extends Adaptations;
|
|
136
126
|
} ? $Adaptations : {};
|
|
137
127
|
/**
|
|
138
|
-
* `$Prior` with `$Map` applied: an adapter named in `$Map` takes its new
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
128
|
+
* `$Prior` with `$Map` applied: an adapter named in `$Map` takes its new entry;
|
|
129
|
+
* one it doesn't name is carried forward. `Omit` first (rather than a plain
|
|
130
|
+
* `$Prior & $Map`) so a replaced entry is genuinely replaced — intersecting two
|
|
131
|
+
* call signatures for the same adapter would produce an overload, from which an
|
|
132
|
+
* adapter's `infer` would read whichever member TypeScript happens to resolve
|
|
133
|
+
* last.
|
|
144
134
|
*/
|
|
145
135
|
export type WithAdaptations<$Prior extends Adaptations, $Map extends Adaptations> = Omit<$Prior, keyof $Map> & $Map;
|
package/dist/types/Bound.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Canonical endpoint stored on `[Meta].whereby`. Call sites still accept a
|
|
3
|
-
* scalar (inclusive) via {@link InputBound}; `.whereby()` runs {@link toBound}
|
|
4
|
-
*
|
|
3
|
+
* scalar (inclusive) via {@link InputBound}; `.whereby()` runs {@link toBound} so
|
|
4
|
+
* adapters always see this shape — never a scalar/object union.
|
|
5
5
|
*/
|
|
6
6
|
export type Bound<$T> = {
|
|
7
7
|
value: $T;
|
|
8
8
|
exclusive: boolean;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* What `.whereby({ min, max })` accepts: a scalar is inclusive, an object
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* What `.whereby({ min, max })` accepts: a scalar is inclusive, an object names
|
|
12
|
+
* an endpoint policy. `exclusive` is required on the object form so that form
|
|
13
|
+
* exists only to state one.
|
|
14
14
|
*/
|
|
15
15
|
export type InputBound<$T> = $T | Bound<$T>;
|
|
16
16
|
/**
|
|
@@ -20,8 +20,8 @@ export type InputBound<$T> = $T | Bound<$T>;
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function toBound<$T>(input: InputBound<$T>): Bound<$T>;
|
|
22
22
|
/**
|
|
23
|
-
* Inclusive integer interval implied by a discrete Bound pair. Exclusive min
|
|
24
|
-
*
|
|
23
|
+
* Inclusive integer interval implied by a discrete Bound pair. Exclusive min is
|
|
24
|
+
* `value + 1`, exclusive max is `value - 1` — the same unit the length/
|
|
25
25
|
* integer/bigint draws already use. Empty iff `min > max`.
|
|
26
26
|
*/
|
|
27
27
|
export declare function effectiveDiscrete(min: Bound<number>, max: Bound<number>): {
|
|
@@ -37,15 +37,15 @@ export declare function assertNonemptyDiscreteBigint(label: string, min: Bound<b
|
|
|
37
37
|
/**
|
|
38
38
|
* Continuous emptiness: inverted bounds, a point range with either end
|
|
39
39
|
* exclusive, or both ends exclusive with no float strictly between them.
|
|
40
|
-
* Sampling still uses the closed interval and {@link constrainContinuous}
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* Sampling still uses the closed interval and {@link constrainContinuous} steps
|
|
41
|
+
* off an exclusive endpoint — this check is what makes that step always have
|
|
42
|
+
* somewhere to land.
|
|
43
43
|
*/
|
|
44
44
|
export declare function assertNonemptyContinuous(label: string, min: Bound<number>, max: Bound<number>): void;
|
|
45
45
|
/**
|
|
46
|
-
* One ulp toward `toward` from `value`. Approximate, and enough to leave
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* One ulp toward `toward` from `value`. Approximate, and enough to leave an
|
|
47
|
+
* exclusive endpoint without rejection-looping a truncated distribution that
|
|
48
|
+
* clamped onto it.
|
|
49
49
|
*/
|
|
50
50
|
export declare function towardInterior(value: number, toward: number): number;
|
|
51
51
|
/**
|
|
@@ -56,8 +56,8 @@ export declare function towardInterior(value: number, toward: number): number;
|
|
|
56
56
|
export declare function constrainContinuous(next: () => number, min: Bound<number>, max: Bound<number>): () => number;
|
|
57
57
|
export declare function epochBound(bound: Bound<Date>): Bound<number>;
|
|
58
58
|
/**
|
|
59
|
-
* Array/string `length`: a bare number is an exact count; an omitted `min`
|
|
60
|
-
*
|
|
59
|
+
* Array/string `length`: a bare number is an exact count; an omitted `min` is
|
|
60
|
+
* inclusive `0`. Always stored as a Bound pair so adapters have one path.
|
|
61
61
|
*/
|
|
62
62
|
export declare function toLengthRange(length: number | {
|
|
63
63
|
max: InputBound<number>;
|