@ghostry/fabricator-extension-faker-v10 0.0.1 → 0.0.2
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
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://docs.ghostry.dev/fabricator/logo.png" alt="fabricator" width="96" height="96">
|
|
4
|
+
|
|
1
5
|
# @ghostry/fabricator-extension-faker-v10
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
**Seeded faker generators for `@ghostry/fabricator`.**
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@ghostry/fabricator-extension-faker-v10)
|
|
10
|
+
[](https://npmx.dev/package/@ghostry/fabricator-extension-faker-v10)
|
|
11
|
+
[](https://jsr.io/@ghostry/fabricator-extension-faker-v10)
|
|
12
|
+
[](https://github.com/ghostry-dev/fabricator)
|
|
13
|
+
[](#)
|
|
14
|
+
[](#)
|
|
15
|
+
[](#)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
[`@faker-js/faker`](https://fakerjs.dev) integration for [`@ghostry/fabricator`](https://www.npmjs.com/package/@ghostry/fabricator). Faker's generators draw from the same stream as every other builder in a schema, so `T.faker.person.fullName()` replays exactly like `T.string` does — nothing additional to track, no drift between runs.
|
|
4
20
|
|
|
5
21
|
Targets `@faker-js/faker` 10.x specifically — hence the `-v10` suffix, matching the adapter packages' convention. A future faker major is a sibling package with its own peer range, not a version bump of this one.
|
|
6
22
|
|
|
@@ -43,21 +59,21 @@ Faker's relative-date methods resolve against the same instance `clock` that `T.
|
|
|
43
59
|
|
|
44
60
|
A faker method could have been wrapped as an opaque producer, and that is the one thing this package refuses to do — an `opaque` schema converts to `Type.Unknown()` in any adapter and is invisible to `combinatorial`/`coverage`. Each builder instead returns the core kind matching the method's own return type:
|
|
45
61
|
|
|
46
|
-
| faker returns
|
|
47
|
-
|
|
|
48
|
-
| `string` (207)
|
|
49
|
-
| `Date` (7)
|
|
50
|
-
| a record shape (7)
|
|
51
|
-
| a literal union (6)
|
|
52
|
-
| `number` (6)
|
|
53
|
-
| `boolean` (1)
|
|
54
|
-
| `bigint` (1)
|
|
55
|
-
| `number
|
|
56
|
-
| `Date[]` (1)
|
|
62
|
+
| faker returns | builder returns | via the TypeBox adapter |
|
|
63
|
+
| ---------------------- | ------------------------------- | -------------------------------------------- |
|
|
64
|
+
| `string` (207) | `T.string` | `Type.String()` |
|
|
65
|
+
| `Date` (7) | `T.date` | `Type.Date()` |
|
|
66
|
+
| a record shape (7) | `T.object({ ... })` | `Type.Object({ ... })` |
|
|
67
|
+
| a literal union (6) | `T.enum.uniform([...])` | `Type.Union([Type.Literal(), …])` |
|
|
68
|
+
| `number` (6) | `T.number` | `Type.Number()` |
|
|
69
|
+
| `boolean` (1) | `T.boolean` | `Type.Boolean()` |
|
|
70
|
+
| `bigint` (1) | `T.bigint` | `Type.BigInt()` |
|
|
71
|
+
| `[number, number]` (1) | `T.tuple([T.number, T.number])` | `Type.Tuple([Type.Number(), Type.Number()])` |
|
|
72
|
+
| `Date[]` (1) | `T.array(T.date)` | `Type.Array(Type.Date())` |
|
|
57
73
|
|
|
58
74
|
Seventeen string methods whose output satisfies a JSON-Schema format regardless of the options passed additionally carry it — `internet.email()` converts to `Type.String({ format: "email" })`, `database.mongodbObjectId()` to a `pattern`.
|
|
59
75
|
|
|
60
|
-
The
|
|
76
|
+
The mirror is hand-written, not generated — one declaration per builder and one implementation, kept in agreement by the compiler. A compile-time assertion checks every entry's value type against faker's own declared return type, so a faker release that changes one fails `tsc` at that entry rather than silently emitting a wrong schema.
|
|
61
77
|
|
|
62
78
|
## Three deviations from faker's own API
|
|
63
79
|
|
|
@@ -75,7 +91,7 @@ T.faker.color.rgb.channels({ includeAlpha: true });
|
|
|
75
91
|
|
|
76
92
|
The same applies to `cmyk`, `hsl`, `hwb`, `lab`, `lch`, and `colorByCSSColorSpace`. `color`'s other four methods are ordinary builders.
|
|
77
93
|
|
|
78
|
-
**
|
|
94
|
+
**Where faker's declared return type is narrower than its JS type, the kind narrows with it.** A literal union becomes an `enum`, not a `string`: `person.sexType()` gives `T.enum.uniform(["female", "generic", "male"])`, so it converts to a union of literals and is enumerable by `combinatorial`/`coverage` rather than an unconstrained string. A fixed-arity array becomes a `tuple`, not an `array`: `location.nearbyGPSCoordinate()` gives `T.tuple([T.number, T.number])`, since no option can change its `[latitude, longitude]` arity — unlike the color channels above, which is why those stay `T.array`.
|
|
79
95
|
|
|
80
96
|
## `use` — for what the mirror doesn't cover
|
|
81
97
|
|
|
@@ -94,7 +110,7 @@ T.faker.use.opaque((f) => f.helpers.arrayElement(["free", "pro"] as const));
|
|
|
94
110
|
|
|
95
111
|
## Notes
|
|
96
112
|
|
|
97
|
-
`faker.seed(...)` is inert here, by design: fabricator's
|
|
113
|
+
`faker.seed(...)` is inert here, by design: fabricator's seeding governs, and a second one competing for control of the same output is the bug this package exists to remove. Change the instance's `clock` — or its `salt`, if it has one — instead.
|
|
98
114
|
|
|
99
115
|
A builder called outside `fabricate()` throws `FakerExtensionError.NoActiveScopeError` — there is no active fabrication to draw from. `FakerExtensionError` extends core's `FabricatorError`, so one `catch` still covers both packages.
|
|
100
116
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* producer rather than a length bound.
|
|
25
25
|
* - `color`'s 7 split methods are a `{ text, channels }` pair each rather than
|
|
26
26
|
* one ambiguous builder, since their return type depends on their arguments;
|
|
27
|
-
* see the deviation policy in `
|
|
27
|
+
* see the deviation policy in `AGENTS.md`'s "The faker extension". All 7 name
|
|
28
28
|
* `format: "decimal"` on `.channels()`, not only `rgb`: bare is right at
|
|
29
29
|
* runtime for the other 6, but not provable through faker's declarations,
|
|
30
30
|
* whose _first_ overload takes `format?: StringColorFormat` and returns
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* Fix the entry in **both** files; the annotation on `build` fails until they
|
|
46
46
|
* agree.
|
|
47
47
|
*
|
|
48
|
-
* These assertions resolve through built `dist/`, not `src/` (`
|
|
48
|
+
* These assertions resolve through built `dist/`, not `src/` (`AGENTS.md`'s
|
|
49
49
|
* test-import convention), so a `src`-only edit proves nothing about faker
|
|
50
50
|
* drift until you rebuild. A disagreement between this file and `./Build.ts` is
|
|
51
51
|
* caught without one, being internal to `src`.
|
package/dist/types/Types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type Registry = Pick<typeof registry, "array" | "bigint" | "boolean" | "d
|
|
|
12
12
|
* Every module the mirror covers, intersected with `keyof Faker` so every
|
|
13
13
|
* downstream `Faker[$M]` indexing is sound. `FakerModules/Types.ts` is the
|
|
14
14
|
* source of truth — `helpers` is absent from it deliberately (deviation policy
|
|
15
|
-
* in `
|
|
15
|
+
* in `AGENTS.md`'s "The faker extension"), so this type excludes it without
|
|
16
16
|
* saying so twice.
|
|
17
17
|
*
|
|
18
18
|
* `test/index.types.test.ts`'s `_ModulesExhaustive` holds this to faker's own
|
|
@@ -60,7 +60,7 @@ export type FakerExtension = FakerModules & {
|
|
|
60
60
|
* (`src/index.ts`'s `draw`).
|
|
61
61
|
*
|
|
62
62
|
* How `helpers` is reached (omitted from the mirror — deviation policy in
|
|
63
|
-
* `
|
|
63
|
+
* `AGENTS.md`'s "The faker extension"). Kind-tagged forms (`.string`,
|
|
64
64
|
* `.number`, `.date`, `.boolean`, `.bigint`) keep adapter compatibility
|
|
65
65
|
* available there too. `.opaque` is the **only** way to get an `opaque`
|
|
66
66
|
* schema out of this package — honest, since it is the one place the caller
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { FakerExtension as FakerTypes } from "./Types";
|
|
|
7
7
|
* The mirror's type-level machinery — not needed to _use_ it, but exported so a
|
|
8
8
|
* consumer (or this package's compile-time checks in
|
|
9
9
|
* `test/index.types.test.ts`) can name a module or method without a relative
|
|
10
|
-
* `./Types` path tests otherwise avoid (`
|
|
10
|
+
* `./Types` path tests otherwise avoid (`AGENTS.md`: tests resolve through the
|
|
11
11
|
* package specifier, exercising built `dist/`).
|
|
12
12
|
*
|
|
13
13
|
* `FakerModules` is the surface those checks are made _against_ — every
|
|
@@ -29,9 +29,9 @@ export type FakerConfig = ConstructorParameters<typeof Faker>[0]["config"];
|
|
|
29
29
|
*
|
|
30
30
|
* No `seed` option and no pre-built `Faker`: a pre-built instance's randomizer
|
|
31
31
|
* is fixed at construction, and accepting one would either ignore it silently
|
|
32
|
-
* or let it compete with fabricator's
|
|
33
|
-
* caller builds the instance; it still receives this bridge's `randomizer`,
|
|
34
|
-
* reproducibility survives.
|
|
32
|
+
* or let it compete with fabricator's seeding. `create` is the honest escape:
|
|
33
|
+
* the caller builds the instance; it still receives this bridge's `randomizer`,
|
|
34
|
+
* so reproducibility survives.
|
|
35
35
|
*/
|
|
36
36
|
export type Options = {
|
|
37
37
|
locale: LocaleDefinition | LocaleDefinition[];
|
|
@@ -63,7 +63,7 @@ export type Options = {
|
|
|
63
63
|
* `FakerExtension` (`./Types.ts`) is spelled out explicitly rather than
|
|
64
64
|
* inferred. An inferred type would reach into each kind's `Schema` interface —
|
|
65
65
|
* internal to `@ghostry/fabricator`, unreachable from its `.` export — and
|
|
66
|
-
* declaration emission (`tsgo`, not `tsc --noEmit`; see `
|
|
66
|
+
* declaration emission (`tsgo`, not `tsc --noEmit`; see `AGENTS.md`'s
|
|
67
67
|
* declaration-emit trap) refuses to print an anonymous expansion of one. Even
|
|
68
68
|
* where it printed it would be the wrong contract: inference would surface each
|
|
69
69
|
* builder's incidental narrowness (`Schema<{ produce; hints }>`) where the
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostry/fabricator-extension-faker-v10",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "@faker-js/faker integration for @ghostry/fabricator — faker's data generators, seeded and reproducible through the fabricator instance that calls them.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"factory",
|
|
8
|
+
"reproducible",
|
|
9
|
+
"fixtures",
|
|
10
|
+
"testing",
|
|
11
|
+
"mock",
|
|
12
|
+
"schema",
|
|
8
13
|
"faker",
|
|
9
|
-
"
|
|
14
|
+
"typescript"
|
|
10
15
|
],
|
|
11
16
|
"author": {
|
|
12
17
|
"name": "Patrick Rebsch"
|
|
@@ -16,9 +21,13 @@
|
|
|
16
21
|
"url": "git+https://github.com/ghostry-dev/fabricator",
|
|
17
22
|
"directory": "pkg/fabricator-extension-faker-v10"
|
|
18
23
|
},
|
|
19
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://docs.ghostry.dev/fabricator/",
|
|
20
25
|
"bugs": "https://github.com/ghostry-dev/fabricator/issues",
|
|
21
26
|
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.0.0"
|
|
30
|
+
},
|
|
22
31
|
"types": "./dist/types/index.d.ts",
|
|
23
32
|
"module": "./dist/esm/index.js",
|
|
24
33
|
"exports": {
|
|
@@ -55,8 +64,8 @@
|
|
|
55
64
|
"@faker-js/faker": "^10.5.0"
|
|
56
65
|
},
|
|
57
66
|
"devDependencies": {
|
|
58
|
-
"@ghostry/fabricator": "0.0.
|
|
59
|
-
"@ghostry/fabricator-adapter-typebox-v0": "0.0.
|
|
67
|
+
"@ghostry/fabricator": "0.0.5",
|
|
68
|
+
"@ghostry/fabricator-adapter-typebox-v0": "0.0.2",
|
|
60
69
|
"@faker-js/faker": "^10.5.0",
|
|
61
70
|
"@sinclair/typebox": "^0.34.52"
|
|
62
71
|
}
|