@ghostry/fabricator 0.0.12 → 0.0.13
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 +1 -1
- package/dist/esm/Fabricator/Fabricate.js +1 -6
- package/dist/esm/Primitive/boolean/Registry.js +10 -8
- package/dist/esm/Primitive/date/Registry.js +48 -42
- package/dist/esm/Primitive/null/Registry.js +6 -4
- package/dist/esm/Primitive/number/Registry.js +35 -29
- package/dist/esm/Primitive/symbol/Registry.js +15 -13
- package/dist/esm/Primitive/undefined/Registry.js +6 -4
- package/dist/esm/Schema/Core.js +9 -1
- package/dist/esm/Schema/Registry.js +27 -7
- package/dist/esm/Utility/DeepMerge.js +47 -6
- package/dist/esm/internal.js +1 -0
- package/dist/types/Fabricator/Fabricate.d.ts +4 -2
- package/dist/types/Primitive/boolean/Registry.d.ts +6 -1
- package/dist/types/Primitive/date/Registry.d.ts +7 -1
- package/dist/types/Primitive/null/Registry.d.ts +6 -1
- package/dist/types/Primitive/number/Registry.d.ts +8 -1
- package/dist/types/Primitive/symbol/Registry.d.ts +6 -1
- package/dist/types/Primitive/undefined/Registry.d.ts +6 -1
- package/dist/types/Schema/Core.d.ts +16 -1
- package/dist/types/Schema/Registry.d.ts +7 -4
- package/dist/types/Utility/DeepMerge.d.ts +11 -0
- package/dist/types/internal.d.ts +8 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,4 +50,4 @@ const item = Product.fabricate();
|
|
|
50
50
|
const widget = Product.fabricate({ name: "Widget", inStock: true });
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
`initialize()` takes no required configuration. Its `clock` (by default, the wall-clock instant of the call) is the run's entropy, so every run differs, and passing that one number back as `clock` replays the run exactly. See the [docs site](https://docs.ghostry.dev/fabricator
|
|
53
|
+
`initialize()` takes no required configuration. Its `clock` (by default, the wall-clock instant of the call) is the run's entropy, so every run differs, and passing that one number back as `clock` replays the run exactly. See the [docs site](https://docs.ghostry.dev/fabricator) for the full guide: the mental model behind Schemas and Fabricators, composing and overriding schemas, custom types, distributions, and the [TypeBox adapter](https://www.npmjs.com/package/@ghostry/fabricator-adapter-typebox-v0).
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { toEffectiveSource } from "../Instance/Stack/Visible.js";
|
|
2
2
|
import { FabricatorError } from "../Error/index.js";
|
|
3
|
-
import {
|
|
4
|
-
function isSchema(candidate) {
|
|
5
|
-
if ("object" != typeof candidate || null === candidate) return false;
|
|
6
|
-
if ("string" != typeof candidate[Kind]) return false;
|
|
7
|
-
return !("fabricate" in candidate);
|
|
8
|
-
}
|
|
3
|
+
import { isSchema } from "../Schema/Core.js";
|
|
9
4
|
function Fabricate(construct, source, stack, ancestry, fabricatorCache) {
|
|
10
5
|
function cacheFor(base) {
|
|
11
6
|
const existing = fabricatorCache.get(base);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
3
|
+
function registry() {
|
|
4
|
+
return {
|
|
5
|
+
...Schema({
|
|
6
|
+
[Kind]: "boolean",
|
|
7
|
+
[Meta]: {},
|
|
8
|
+
[Produces]: void 0,
|
|
9
|
+
[Adaptation]: void 0
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
}
|
|
11
13
|
const Registry = registry;
|
|
12
14
|
export default Registry;
|
|
@@ -2,54 +2,60 @@ import { assertNonemptyDiscrete, epochBound, toBound } from "../../Bound.js";
|
|
|
2
2
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
3
3
|
import { unboundedEpoch } from "./Defaults.js";
|
|
4
4
|
import { Schema } from "./Schema.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[Kind]: "date",
|
|
8
|
-
[Meta]: {},
|
|
9
|
-
[Produces]: void 0,
|
|
10
|
-
[Adaptation]: void 0
|
|
11
|
-
}),
|
|
12
|
-
whereby: (whereby)=>{
|
|
13
|
-
const converted = toWhereby(whereby);
|
|
14
|
-
assertNonemptyDiscrete("T.date.whereby", converted.min ? epochBound(converted.min) : unboundedEpoch.min, converted.max ? epochBound(converted.max) : unboundedEpoch.max);
|
|
15
|
-
return Schema({
|
|
16
|
-
[Kind]: "date",
|
|
17
|
-
[Meta]: {
|
|
18
|
-
whereby: converted
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
past: {
|
|
5
|
+
function registry() {
|
|
6
|
+
return {
|
|
23
7
|
...Schema({
|
|
24
8
|
[Kind]: "date",
|
|
25
|
-
[Meta]: {
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
[Meta]: {},
|
|
10
|
+
[Produces]: void 0,
|
|
11
|
+
[Adaptation]: void 0
|
|
28
12
|
}),
|
|
29
|
-
whereby: (whereby)=>
|
|
13
|
+
whereby: (whereby)=>{
|
|
14
|
+
const converted = toWhereby(whereby);
|
|
15
|
+
assertNonemptyDiscrete("T.date.whereby", converted.min ? epochBound(converted.min) : unboundedEpoch.min, converted.max ? epochBound(converted.max) : unboundedEpoch.max);
|
|
16
|
+
return Schema({
|
|
30
17
|
[Kind]: "date",
|
|
31
18
|
[Meta]: {
|
|
32
|
-
|
|
33
|
-
whereby: toWhereby(whereby)
|
|
19
|
+
whereby: converted
|
|
34
20
|
}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
get past () {
|
|
24
|
+
return {
|
|
25
|
+
...Schema({
|
|
26
|
+
[Kind]: "date",
|
|
27
|
+
[Meta]: {
|
|
28
|
+
mode: "past"
|
|
29
|
+
}
|
|
30
|
+
}),
|
|
31
|
+
whereby: (whereby)=>Schema({
|
|
32
|
+
[Kind]: "date",
|
|
33
|
+
[Meta]: {
|
|
34
|
+
mode: "past",
|
|
35
|
+
whereby: toWhereby(whereby)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
get future () {
|
|
41
|
+
return {
|
|
42
|
+
...Schema({
|
|
43
|
+
[Kind]: "date",
|
|
44
|
+
[Meta]: {
|
|
45
|
+
mode: "future"
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
whereby: (whereby)=>Schema({
|
|
49
|
+
[Kind]: "date",
|
|
50
|
+
[Meta]: {
|
|
51
|
+
mode: "future",
|
|
52
|
+
whereby: toWhereby(whereby)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
53
59
|
const Registry = registry;
|
|
54
60
|
function toWhereby(input) {
|
|
55
61
|
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Kind, Meta } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
function registry() {
|
|
4
|
+
return Schema({
|
|
5
|
+
[Kind]: "null",
|
|
6
|
+
[Meta]: {}
|
|
7
|
+
});
|
|
8
|
+
}
|
|
7
9
|
const Registry = registry;
|
|
8
10
|
export default Registry;
|
|
@@ -3,43 +3,49 @@ import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
|
3
3
|
import bigint from "../bigint/index.js";
|
|
4
4
|
import { unboundedContinuous, unboundedDiscrete } from "./Defaults.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[Kind]: "number",
|
|
9
|
-
[Meta]: {},
|
|
10
|
-
[Produces]: void 0,
|
|
11
|
-
[Adaptation]: void 0
|
|
12
|
-
}),
|
|
13
|
-
whereby: (whereby)=>Schema({
|
|
14
|
-
[Kind]: "number",
|
|
15
|
-
[Meta]: {
|
|
16
|
-
whereby: toWhereby(whereby, false)
|
|
17
|
-
}
|
|
18
|
-
}),
|
|
19
|
-
integer: {
|
|
6
|
+
function registry() {
|
|
7
|
+
return {
|
|
20
8
|
...Schema({
|
|
21
9
|
[Kind]: "number",
|
|
22
|
-
[Meta]: {
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
[Meta]: {},
|
|
11
|
+
[Produces]: void 0,
|
|
12
|
+
[Adaptation]: void 0
|
|
25
13
|
}),
|
|
26
14
|
whereby: (whereby)=>Schema({
|
|
27
15
|
[Kind]: "number",
|
|
28
16
|
[Meta]: {
|
|
29
|
-
|
|
30
|
-
whereby: toWhereby(whereby, true)
|
|
17
|
+
whereby: toWhereby(whereby, false)
|
|
31
18
|
}
|
|
32
19
|
}),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
get integer () {
|
|
21
|
+
return {
|
|
22
|
+
...Schema({
|
|
23
|
+
[Kind]: "number",
|
|
24
|
+
[Meta]: {
|
|
25
|
+
integer: true
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
whereby: (whereby)=>Schema({
|
|
29
|
+
[Kind]: "number",
|
|
30
|
+
[Meta]: {
|
|
31
|
+
integer: true,
|
|
32
|
+
whereby: toWhereby(whereby, true)
|
|
33
|
+
}
|
|
34
|
+
}),
|
|
35
|
+
get sequence () {
|
|
36
|
+
return Schema({
|
|
37
|
+
[Kind]: "number",
|
|
38
|
+
[Meta]: {
|
|
39
|
+
sequence: true,
|
|
40
|
+
integer: true
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
big: bigint
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
43
49
|
const Registry = registry;
|
|
44
50
|
function toWhereby(input, integer) {
|
|
45
51
|
const min = void 0 === input.min ? void 0 : toBound(input.min);
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Adaptation, Kind, Meta, Produces } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[Meta]: {},
|
|
7
|
-
[Produces]: void 0,
|
|
8
|
-
[Adaptation]: void 0
|
|
9
|
-
}),
|
|
10
|
-
keyed: (key)=>Schema({
|
|
3
|
+
function registry() {
|
|
4
|
+
return {
|
|
5
|
+
...Schema({
|
|
11
6
|
[Kind]: "symbol",
|
|
12
|
-
[Meta]: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
|
|
7
|
+
[Meta]: {},
|
|
8
|
+
[Produces]: void 0,
|
|
9
|
+
[Adaptation]: void 0
|
|
10
|
+
}),
|
|
11
|
+
keyed: (key)=>Schema({
|
|
12
|
+
[Kind]: "symbol",
|
|
13
|
+
[Meta]: {
|
|
14
|
+
key
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
};
|
|
18
|
+
}
|
|
17
19
|
const Registry = registry;
|
|
18
20
|
export default Registry;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Kind, Meta } from "../../Types.js";
|
|
2
2
|
import { Schema } from "./Schema.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
function registry() {
|
|
4
|
+
return Schema({
|
|
5
|
+
[Kind]: "undefined",
|
|
6
|
+
[Meta]: {}
|
|
7
|
+
});
|
|
8
|
+
}
|
|
7
9
|
const Registry = registry;
|
|
8
10
|
export default Registry;
|
package/dist/esm/Schema/Core.js
CHANGED
|
@@ -11,6 +11,14 @@ function toSchema(value) {
|
|
|
11
11
|
[Meta]: value[Meta]
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
function isBuildable(candidate) {
|
|
15
|
+
if ("object" != typeof candidate || null === candidate) return false;
|
|
16
|
+
if ("string" != typeof candidate[Kind]) return false;
|
|
17
|
+
return Meta in candidate;
|
|
18
|
+
}
|
|
19
|
+
function isSchema(candidate) {
|
|
20
|
+
return isBuildable(candidate) && !("fabricate" in candidate);
|
|
21
|
+
}
|
|
14
22
|
function toValueKind(schema) {
|
|
15
23
|
switch(schema[Kind]){
|
|
16
24
|
case "object.compute":
|
|
@@ -77,4 +85,4 @@ function violatesKind(kind, value) {
|
|
|
77
85
|
return never(kind);
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
export { toSchema, toValueKind, violatesKind };
|
|
88
|
+
export { isBuildable, isSchema, toSchema, toValueKind, violatesKind };
|
|
@@ -5,13 +5,33 @@ const Registry = (registrations)=>{
|
|
|
5
5
|
T: registrations,
|
|
6
6
|
augment: deepMerge
|
|
7
7
|
})));
|
|
8
|
-
return {
|
|
9
|
-
...registrations,
|
|
8
|
+
return deepMerge(registrations, {
|
|
10
9
|
extend
|
|
11
|
-
};
|
|
10
|
+
});
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
const { Primitive: _, ...
|
|
15
|
-
return
|
|
16
|
-
|
|
12
|
+
function builders() {
|
|
13
|
+
const { Primitive: _, ...rest } = __rspack_external__Primitive_index_js_8ad84a20;
|
|
14
|
+
return {
|
|
15
|
+
...rest,
|
|
16
|
+
get boolean () {
|
|
17
|
+
return __rspack_external__Primitive_index_js_8ad84a20.boolean();
|
|
18
|
+
},
|
|
19
|
+
get date () {
|
|
20
|
+
return __rspack_external__Primitive_index_js_8ad84a20.date();
|
|
21
|
+
},
|
|
22
|
+
get null () {
|
|
23
|
+
return __rspack_external__Primitive_index_js_8ad84a20["null"]();
|
|
24
|
+
},
|
|
25
|
+
get number () {
|
|
26
|
+
return __rspack_external__Primitive_index_js_8ad84a20.number();
|
|
27
|
+
},
|
|
28
|
+
get symbol () {
|
|
29
|
+
return __rspack_external__Primitive_index_js_8ad84a20.symbol();
|
|
30
|
+
},
|
|
31
|
+
get undefined () {
|
|
32
|
+
return __rspack_external__Primitive_index_js_8ad84a20.undefined();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const registry = Registry({}).extend(builders);
|
|
17
37
|
export { registry };
|
|
@@ -3,16 +3,57 @@ import { isPlainObject, mergeableKeys } from "./Core.js";
|
|
|
3
3
|
function deepMerge(a, b) {
|
|
4
4
|
const result = {};
|
|
5
5
|
if (Replace in b && true === b[Replace]) {
|
|
6
|
-
for (const key of mergeableKeys(b))result
|
|
6
|
+
for (const key of mergeableKeys(b))copy(result, b, key);
|
|
7
7
|
return result;
|
|
8
8
|
}
|
|
9
|
-
for (const key of mergeableKeys(a))result
|
|
9
|
+
for (const key of mergeableKeys(a))copy(result, a, key);
|
|
10
10
|
for (const key of mergeableKeys(b)){
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
else result[key] = bValue;
|
|
11
|
+
const getter = isGetter(result, key) || isGetter(b, key);
|
|
12
|
+
const value = mergeValue(result[key], b[key]);
|
|
13
|
+
Object.defineProperty(result, key, property(value, getter));
|
|
15
14
|
}
|
|
16
15
|
return result;
|
|
17
16
|
}
|
|
17
|
+
function mergeValue(left, right) {
|
|
18
|
+
if (isPlainObject(left) && isPlainObject(right)) return deepMerge(left, right);
|
|
19
|
+
return right;
|
|
20
|
+
}
|
|
21
|
+
function property(value, getter) {
|
|
22
|
+
if (getter && isPlainObject(value)) return {
|
|
23
|
+
get: ()=>rebuilt(value),
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true
|
|
26
|
+
};
|
|
27
|
+
return own({
|
|
28
|
+
value
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function rebuilt(value) {
|
|
32
|
+
return Object.defineProperties({}, Object.getOwnPropertyDescriptors(value));
|
|
33
|
+
}
|
|
34
|
+
function copy(target, source, key) {
|
|
35
|
+
Object.defineProperty(target, key, own(descriptorOf(source, key)));
|
|
36
|
+
}
|
|
37
|
+
function own(descriptor) {
|
|
38
|
+
const normalized = {
|
|
39
|
+
...descriptor,
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true
|
|
42
|
+
};
|
|
43
|
+
if (isAccessor(descriptor)) return normalized;
|
|
44
|
+
return {
|
|
45
|
+
...normalized,
|
|
46
|
+
writable: true
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function isAccessor(descriptor) {
|
|
50
|
+
return "get" in descriptor || "set" in descriptor;
|
|
51
|
+
}
|
|
52
|
+
function isGetter(source, key) {
|
|
53
|
+
var _Object_getOwnPropertyDescriptor;
|
|
54
|
+
return (null == (_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(source, key)) ? void 0 : _Object_getOwnPropertyDescriptor.get) !== void 0;
|
|
55
|
+
}
|
|
56
|
+
function descriptorOf(source, key) {
|
|
57
|
+
return Object.getOwnPropertyDescriptor(source, key);
|
|
58
|
+
}
|
|
18
59
|
export { deepMerge };
|
package/dist/esm/internal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Children, Kind, Meta, Produces } from "./Types.js";
|
|
2
2
|
export { isArray, isPlainObject } from "./Utility/Core.js";
|
|
3
|
+
export { isBuildable, isSchema } from "./Schema/Core.js";
|
|
3
4
|
export { plan, resolve } from "./Enumeration/Plan.js";
|
|
4
5
|
export { defaultAlgorithm, encode, randomSalt, toRandomSource, toStream, toStreamFromTrace } from "./Random/index.js";
|
|
5
6
|
export { normalCdf, normalInv, weighted } from "./Distribution/index.js";
|
|
@@ -12,8 +12,10 @@ import type { NaiveFabricator } from "./Types";
|
|
|
12
12
|
* The key is the schema's identity. A schema held in a variable — including an
|
|
13
13
|
* overridden one, `const Admin = User.override({ ... })` — is reused. One
|
|
14
14
|
* written at the call site — `fabricate(User.override({ ... }))`, an inline
|
|
15
|
-
* `.whereby(...)
|
|
16
|
-
*
|
|
15
|
+
* `.whereby(...)`, a bare registry entry like `fabricate(T.number)`, whose
|
|
16
|
+
* every read is a fresh Schema — is a new object on every call, so every call
|
|
17
|
+
* builds and takes an ordinal, exactly as `new Fabricator(...).fabricate()`
|
|
18
|
+
* would.
|
|
17
19
|
*
|
|
18
20
|
* A Schema only, never a built Fabricator: given one, neither reusing it nor
|
|
19
21
|
* caching a fresh build of it is the obvious reading, so the type rejects it
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { Adaptations } from "../../Adapter/Types";
|
|
2
2
|
import { Schema } from "./Schema";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
5
|
+
* `T.boolean` getter, so every read is a distinct Schema — see AGENTS.md's
|
|
6
|
+
* "Registry entries are getters."
|
|
7
|
+
*/
|
|
8
|
+
declare function registry(): Schema<{}, Adaptations>;
|
|
4
9
|
export default registry;
|
|
@@ -53,5 +53,11 @@ type ThisRegistry = Schema<{}, Adaptations> & {
|
|
|
53
53
|
}>;
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
-
|
|
56
|
+
/**
|
|
57
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
58
|
+
* `T.date` getter, so every read is a distinct Schema. `past` and `future` are
|
|
59
|
+
* getters for the same reason — see AGENTS.md's "Registry entries are
|
|
60
|
+
* getters."
|
|
61
|
+
*/
|
|
62
|
+
declare function registry(): ThisRegistry;
|
|
57
63
|
export default registry;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Schema } from "./Schema";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
4
|
+
* `T.null` getter, so every read is a distinct Schema — see AGENTS.md's
|
|
5
|
+
* "Registry entries are getters."
|
|
6
|
+
*/
|
|
7
|
+
declare function registry(): Schema;
|
|
3
8
|
export default registry;
|
|
@@ -30,5 +30,12 @@ type ThisRegistry = Schema<{}, Adaptations> & {
|
|
|
30
30
|
big: typeof bigint;
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
35
|
+
* `T.number` getter, so every read is a distinct Schema. `integer` and
|
|
36
|
+
* `integer.sequence` are getters for the same reason; `big` is a builder, not a
|
|
37
|
+
* Schema, so it stays a plain property — see AGENTS.md's "Registry entries are
|
|
38
|
+
* getters."
|
|
39
|
+
*/
|
|
40
|
+
declare function registry(): ThisRegistry;
|
|
34
41
|
export default registry;
|
|
@@ -5,5 +5,10 @@ type ThisRegistry = Schema<{}, Adaptations> & {
|
|
|
5
5
|
key: string;
|
|
6
6
|
}>;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
10
|
+
* `T.symbol` getter, so every read is a distinct Schema — see AGENTS.md's
|
|
11
|
+
* "Registry entries are getters."
|
|
12
|
+
*/
|
|
13
|
+
declare function registry(): ThisRegistry;
|
|
9
14
|
export default registry;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Schema } from "./Schema";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A function, not the Schema itself: `Schema/Registry.ts` installs it as the
|
|
4
|
+
* `T.undefined` getter, so every read is a distinct Schema — see AGENTS.md's
|
|
5
|
+
* "Registry entries are getters."
|
|
6
|
+
*/
|
|
7
|
+
declare function registry(): Schema;
|
|
3
8
|
export default registry;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Adaptations } from "../Adapter/Types";
|
|
2
2
|
import type { Kind as SchemaKind } from "../Primitive";
|
|
3
|
-
import { Adaptation, Kind, Meta, type Produced, type Produces } from "../Types";
|
|
3
|
+
import { Adaptation, Kind, Meta, type Buildable, type Produced, type Produces } from "../Types";
|
|
4
4
|
import { type PlainObject } from "../Utility/Types";
|
|
5
|
+
import type { AnySchema } from "./Types";
|
|
5
6
|
/**
|
|
6
7
|
* Normalize a Schema, a builder namespace, or an already-built Fabricator into
|
|
7
8
|
* a clean, storable Schema — keeping only `[Kind]`/ `[Meta]`/`[Adaptation]` and
|
|
@@ -36,6 +37,20 @@ export declare function toSchema<$Kind extends string, $Meta extends PlainObject
|
|
|
36
37
|
readonly [Produces]?: Produced<$Produces>;
|
|
37
38
|
readonly [Adaptation]?: $Adaptations;
|
|
38
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Whether `candidate` is something `new Fabricator(...)` can build: a Schema or
|
|
42
|
+
* a built Fabricator, which both carry a `[Kind]` tag and a `[Meta]`. A bare
|
|
43
|
+
* builder that is a function (`T.array`, `T.recursive`) fails the first test;
|
|
44
|
+
* one that is an object but has no `[Kind]` fails the second. `T.string` and
|
|
45
|
+
* `T.bigint` carry `[Kind]` so they can name a compute source, but have no
|
|
46
|
+
* `[Meta]` until `.whereby(...)`, and fail the third.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isBuildable(candidate: unknown): candidate is Buildable;
|
|
49
|
+
/**
|
|
50
|
+
* {@link isBuildable}, excluding a built Fabricator: a Schema is inert, and only
|
|
51
|
+
* a Fabricator has `fabricate`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isSchema(candidate: unknown): candidate is AnySchema;
|
|
39
54
|
/**
|
|
40
55
|
* The `[Kind]` a schema's fabricated value should be checked against with
|
|
41
56
|
* {@link violatesKind}. For most kinds that is its own `[Kind]`, but
|
|
@@ -2,11 +2,14 @@ import * as primitives from "../Primitive";
|
|
|
2
2
|
import { deepMerge, type DeepMerge } from "../Utility/DeepMerge";
|
|
3
3
|
import { type PlainObject } from "../Utility/Types";
|
|
4
4
|
/**
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* A kind whose `Registry.ts` default export takes no arguments returns a bare
|
|
6
|
+
* Schema, which `builders` installs behind a getter; every builder takes at
|
|
7
|
+
* least one. A bare kind left without a getter therefore fails to compile in
|
|
8
|
+
* `builders`, where the spread supplies the function itself.
|
|
8
9
|
*/
|
|
9
|
-
type Builders =
|
|
10
|
+
type Builders = {
|
|
11
|
+
[$K in Exclude<keyof typeof primitives, "Primitive">]: (typeof primitives)[$K] extends () => infer $Schema ? $Schema : (typeof primitives)[$K];
|
|
12
|
+
};
|
|
10
13
|
type RegistryInterface<$Registry> = {
|
|
11
14
|
extend: <const $Extension extends PlainObject>(types: (params: {
|
|
12
15
|
T: $Registry;
|
|
@@ -11,4 +11,15 @@ export type DeepMerge<$A, $B> = $B extends {
|
|
|
11
11
|
[_ in $K]?: infer $BV;
|
|
12
12
|
} ? $BV : never;
|
|
13
13
|
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Copies property descriptors rather than values, so a getter stays a getter on
|
|
16
|
+
* the result. The registry depends on that: every registry entry that is a
|
|
17
|
+
* Schema is a getter returning a fresh object (`Schema/Registry.ts`), and a
|
|
18
|
+
* merge that copied its value would pin it to one.
|
|
19
|
+
*
|
|
20
|
+
* Where both sides hold a key, each is read once — a getter included — and the
|
|
21
|
+
* values merge as they always have. If either side was a getter, the result is
|
|
22
|
+
* a getter again, returning a new object {@link rebuilt} from the merged one on
|
|
23
|
+
* every read, so an entry an extension merges into stays fresh.
|
|
24
|
+
*/
|
|
14
25
|
export declare function deepMerge<$A extends PlainObject, $B extends PlainObject>(a: $A, b: $B): DeepMerge<$A, $B>;
|
package/dist/types/internal.d.ts
CHANGED
|
@@ -44,6 +44,14 @@ export type { AsFabricator } from "./Fabricator/Types";
|
|
|
44
44
|
*/
|
|
45
45
|
export { Children, Kind, Meta, Produces, type Buildable, type Produced, } from "./Types";
|
|
46
46
|
export { isArray, isPlainObject } from "./Utility/Core";
|
|
47
|
+
/**
|
|
48
|
+
* The runtime counterparts of `Buildable` and `AnySchema`, for an integration
|
|
49
|
+
* that takes one from an untyped caller. `@ghostry/extern`'s fabricator
|
|
50
|
+
* extension claims a block identity with `isSchema`: a built Fabricator is not
|
|
51
|
+
* an identity, since a block could either continue its streams or build afresh
|
|
52
|
+
* from its schema.
|
|
53
|
+
*/
|
|
54
|
+
export { isBuildable, isSchema } from "./Schema/Core";
|
|
47
55
|
export type * as Primitive from "./Primitive/namespace";
|
|
48
56
|
/**
|
|
49
57
|
* `Schema/Types.ts`'s own value-type resolution, needed by tests asserting
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostry/fabricator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Fabricate typed data from composable schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"url": "git+https://github.com/ghostry-dev/fabricator",
|
|
21
21
|
"directory": "pkg/fabricator"
|
|
22
22
|
},
|
|
23
|
-
"homepage": "https://docs.ghostry.dev/fabricator
|
|
23
|
+
"homepage": "https://docs.ghostry.dev/fabricator",
|
|
24
24
|
"bugs": "https://github.com/ghostry-dev/fabricator/issues",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"sideEffects": false,
|