@webda/mock 4.0.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.
Files changed (43) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +121 -0
  3. package/lib/ai/anthropic.d.ts +30 -0
  4. package/lib/ai/anthropic.d.ts.map +1 -0
  5. package/lib/ai/anthropic.js +43 -0
  6. package/lib/ai/anthropic.js.map +1 -0
  7. package/lib/ai/provider.d.ts +35 -0
  8. package/lib/ai/provider.d.ts.map +1 -0
  9. package/lib/ai/provider.js +27 -0
  10. package/lib/ai/provider.js.map +1 -0
  11. package/lib/cli/seed.d.ts +22 -0
  12. package/lib/cli/seed.d.ts.map +1 -0
  13. package/lib/cli/seed.js +43 -0
  14. package/lib/cli/seed.js.map +1 -0
  15. package/lib/engine/faker.d.ts +10 -0
  16. package/lib/engine/faker.d.ts.map +1 -0
  17. package/lib/engine/faker.js +14 -0
  18. package/lib/engine/faker.js.map +1 -0
  19. package/lib/engine/generate.d.ts +37 -0
  20. package/lib/engine/generate.d.ts.map +1 -0
  21. package/lib/engine/generate.js +171 -0
  22. package/lib/engine/generate.js.map +1 -0
  23. package/lib/engine/graph.d.ts +22 -0
  24. package/lib/engine/graph.d.ts.map +1 -0
  25. package/lib/engine/graph.js +37 -0
  26. package/lib/engine/graph.js.map +1 -0
  27. package/lib/engine/infer.d.ts +15 -0
  28. package/lib/engine/infer.d.ts.map +1 -0
  29. package/lib/engine/infer.js +54 -0
  30. package/lib/engine/infer.js.map +1 -0
  31. package/lib/engine/pool.d.ts +47 -0
  32. package/lib/engine/pool.d.ts.map +1 -0
  33. package/lib/engine/pool.js +82 -0
  34. package/lib/engine/pool.js.map +1 -0
  35. package/lib/index.d.ts +10 -0
  36. package/lib/index.d.ts.map +1 -0
  37. package/lib/index.js +9 -0
  38. package/lib/index.js.map +1 -0
  39. package/lib/service/mock-service.d.ts +59 -0
  40. package/lib/service/mock-service.d.ts.map +1 -0
  41. package/lib/service/mock-service.js +66 -0
  42. package/lib/service/mock-service.js.map +1 -0
  43. package/package.json +81 -0
@@ -0,0 +1,171 @@
1
+ import { readMockMeta } from "@webda/models";
2
+ import { makeFaker } from "./faker.js";
3
+ import { SessionPool } from "./pool.js";
4
+ import { inferKind } from "./infer.js";
5
+ /**
6
+ * Generate `count` instances of `ModelClass`, resolving each field through the
7
+ * fallback chain (explicit `@Mock.*` → name-heuristic → type fallback → throw/skip).
8
+ *
9
+ * @param ModelClass - the target model constructor.
10
+ * @param options - generation options (count, seed, mode, overrides, ai, pool, strict).
11
+ * @returns the generated instances.
12
+ */
13
+ export async function generate(ModelClass, options = {}) {
14
+ const count = options.count ?? 1;
15
+ const mode = options.mode ?? (process.env.VITEST ? "test" : "dev");
16
+ const seedDefault = mode === "test" ? 0 : Date.now();
17
+ const seed = options.seed ?? seedDefault;
18
+ const faker = makeFaker(seed);
19
+ const rng = () => faker.number.float({ min: 0, max: 1 });
20
+ const pool = options.pool ?? new SessionPool(rng);
21
+ const metaMap = readMockMeta(ModelClass);
22
+ const aiFn = async (prompt, opts) => {
23
+ if (!options.ai)
24
+ throw new Error("generate: no AIProvider configured for an @Mock.ai field");
25
+ return options.ai.complete(prompt, opts);
26
+ };
27
+ // Determine the full field set by:
28
+ // 1. Own enumerable keys on a fresh instance (regular class fields).
29
+ // 2. Getter/setter pairs on the prototype chain (auto-accessor fields created with `accessor` keyword).
30
+ // 3. Any field names stashed in the @Mock decorator metadata map.
31
+ const probe = new ModelClass();
32
+ const protoFieldNames = new Set();
33
+ let proto = Object.getPrototypeOf(probe);
34
+ while (proto && proto !== Object.prototype) {
35
+ for (const key of Object.getOwnPropertyNames(proto)) {
36
+ if (key === "constructor")
37
+ continue;
38
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
39
+ if (desc && typeof desc.get === "function" && typeof desc.set === "function") {
40
+ protoFieldNames.add(key);
41
+ }
42
+ }
43
+ proto = Object.getPrototypeOf(proto);
44
+ }
45
+ const fieldNames = new Set([...Object.keys(probe), ...protoFieldNames, ...Object.keys(metaMap)]);
46
+ const out = [];
47
+ for (let i = 0; i < count; i++) {
48
+ const instance = new ModelClass();
49
+ for (const fieldName of fieldNames) {
50
+ if (options.overrides && fieldName in options.overrides) {
51
+ instance[fieldName] = options.overrides[fieldName];
52
+ continue;
53
+ }
54
+ const meta = metaMap[fieldName];
55
+ const ctx = {
56
+ faker,
57
+ rng,
58
+ ai: aiFn,
59
+ pool,
60
+ index: i,
61
+ total: count,
62
+ model: ModelClass,
63
+ fieldName
64
+ };
65
+ let kind = meta?.kind ?? null;
66
+ const opts = meta?.options ?? {};
67
+ if (!kind && !options.strict) {
68
+ kind = inferKind({
69
+ fieldName,
70
+ declaredType: typeof instance[fieldName]
71
+ });
72
+ }
73
+ if (!kind) {
74
+ if (options.strict) {
75
+ throw new Error(`generate: no @Mock decorator or inference rule for field "${fieldName}"`);
76
+ }
77
+ continue;
78
+ }
79
+ if (kind === "ai" && mode === "test") {
80
+ throw new Error(`generate: mode="test" forbids @Mock.ai (field "${fieldName}")`);
81
+ }
82
+ instance[fieldName] = await resolveKind(kind, opts, ctx);
83
+ }
84
+ out.push(instance);
85
+ pool.add(instance);
86
+ }
87
+ return out;
88
+ }
89
+ /**
90
+ * Route a resolved kind to its Faker / AI / custom generator.
91
+ *
92
+ * @param kind - the `MockKind` to produce.
93
+ * @param opts - decorator-time options for that kind.
94
+ * @param ctx - the mock context (faker, rng, pool, etc.).
95
+ * @returns the generated value.
96
+ */
97
+ async function resolveKind(kind, opts, ctx) {
98
+ const f = ctx.faker;
99
+ switch (kind) {
100
+ case "uuid":
101
+ return f.string.uuid();
102
+ case "email":
103
+ return f.internet.email();
104
+ case "firstName":
105
+ return f.person.firstName();
106
+ case "lastName":
107
+ return f.person.lastName();
108
+ case "fullName":
109
+ return f.person.fullName();
110
+ case "phone":
111
+ return f.phone.number();
112
+ case "url":
113
+ return f.internet.url();
114
+ case "avatar":
115
+ return f.image.avatar();
116
+ case "word":
117
+ return f.word.sample();
118
+ case "percentage":
119
+ return f.number.int({ min: 0, max: 100 });
120
+ case "recentDate":
121
+ return f.date.recent();
122
+ case "lorem": {
123
+ const o = opts;
124
+ if (o.paragraphs !== undefined)
125
+ return f.lorem.paragraphs(o.paragraphs);
126
+ if (o.sentences !== undefined)
127
+ return f.lorem.sentences(o.sentences);
128
+ return f.lorem.words(o.words ?? 3);
129
+ }
130
+ case "integer": {
131
+ const o = opts;
132
+ return f.number.int({ min: o.min ?? 0, max: o.max ?? 100 });
133
+ }
134
+ case "float": {
135
+ const o = opts;
136
+ return f.number.float({ min: o.min ?? 0, max: o.max ?? 100 });
137
+ }
138
+ case "pastDate": {
139
+ const within = opts.within ?? "year";
140
+ const years = within === "year" ? 1 : within === "month" ? 1 / 12 : within === "week" ? 1 / 52 : 1 / 365;
141
+ return f.date.past({ years });
142
+ }
143
+ case "futureDate": {
144
+ const within = opts.within ?? "year";
145
+ const years = within === "year" ? 1 : within === "month" ? 1 / 12 : within === "week" ? 1 / 52 : 1 / 365;
146
+ return f.date.future({ years });
147
+ }
148
+ case "pick": {
149
+ const values = opts.values;
150
+ return values[Math.floor(ctx.rng() * values.length)];
151
+ }
152
+ case "boolean":
153
+ return ctx.rng() < 0.5;
154
+ case "custom": {
155
+ const fn = opts.fn;
156
+ return fn(ctx);
157
+ }
158
+ case "ai": {
159
+ const o = opts;
160
+ return ctx.ai(o.prompt, { maxTokens: o.maxTokens });
161
+ }
162
+ case "count":
163
+ case "linkExisting":
164
+ case "linkNew":
165
+ // Relation kinds are handled by generateGraph, not here.
166
+ return undefined;
167
+ default:
168
+ return undefined;
169
+ }
170
+ }
171
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/engine/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgC,MAAM,eAAe,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO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AC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACzG,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,MAAM,EAAE,CAAC;YACZ,MAAM,MAAM,GAAI,IAAuC,CAAC,MAAM,CAAC;YAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACvD,CAAC;QACD,KAAK,SAAS;YACZ,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC;QACzB,KAAK,QAAQ,EAAE,CAAC;YACd,MAAM,EAAE,GAAI,IAA8C,CAAC,EAAE,CAAC;YAC9D,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;QACD,KAAK,IAAI,EAAE,CAAC;YACV,MAAM,CAAC,GAAG,IAA8C,CAAC;YACzD,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,KAAK,OAAO,CAAC;QACb,KAAK,cAAc,CAAC;QACpB,KAAK,SAAS;YACZ,yDAAyD;YACzD,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type GenerateOptions } from "./generate.js";
2
+ type ModelClass<T> = new (...args: any[]) => T;
3
+ /**
4
+ * Generate instances of multiple models in the order given, reusing the same
5
+ * seeded RNG and session pool so that later models can reference earlier
6
+ * instances (when/if the callers' models support @ModelLink / @ModelRelated
7
+ * style fields resolving against the pool).
8
+ *
9
+ * For v1 the order is the caller-declared `options.models` order. A future
10
+ * version may add a topological-sort step based on declared relations.
11
+ *
12
+ * @param spec - { ModelName: count }
13
+ * @param options - shared generation options plus the model classes in the
14
+ * order they should be generated.
15
+ * @returns a map of model name → generated instances (empty array for models
16
+ * not listed in `spec`).
17
+ */
18
+ export declare function generateGraph(spec: Record<string, number>, options?: GenerateOptions & {
19
+ models: ModelClass<unknown>[];
20
+ }): Promise<Record<string, unknown[]>>;
21
+ export {};
22
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/engine/graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAG/D,KAAK,UAAU,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE/C;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,OAAO,GAAE,eAAe,GAAG;IAAE,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;CAAmB,GAC5E,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAkBpC"}
@@ -0,0 +1,37 @@
1
+ import { SessionPool } from "./pool.js";
2
+ import { generate } from "./generate.js";
3
+ import { makeFaker } from "./faker.js";
4
+ /**
5
+ * Generate instances of multiple models in the order given, reusing the same
6
+ * seeded RNG and session pool so that later models can reference earlier
7
+ * instances (when/if the callers' models support @ModelLink / @ModelRelated
8
+ * style fields resolving against the pool).
9
+ *
10
+ * For v1 the order is the caller-declared `options.models` order. A future
11
+ * version may add a topological-sort step based on declared relations.
12
+ *
13
+ * @param spec - { ModelName: count }
14
+ * @param options - shared generation options plus the model classes in the
15
+ * order they should be generated.
16
+ * @returns a map of model name → generated instances (empty array for models
17
+ * not listed in `spec`).
18
+ */
19
+ export async function generateGraph(spec, options = { models: [] }) {
20
+ const mode = options.mode ?? (process.env.VITEST ? "test" : "dev");
21
+ const seed = options.seed ?? (mode === "test" ? 0 : Date.now());
22
+ const faker = makeFaker(seed);
23
+ const rng = () => faker.number.float({ min: 0, max: 1 });
24
+ const pool = options.pool ?? new SessionPool(rng);
25
+ const out = {};
26
+ for (const ModelClass of options.models) {
27
+ const name = ModelClass.name;
28
+ const count = spec[name] ?? 0;
29
+ if (count === 0) {
30
+ out[name] = [];
31
+ continue;
32
+ }
33
+ out[name] = await generate(ModelClass, { ...options, count, pool });
34
+ }
35
+ return out;
36
+ }
37
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/engine/graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAwB,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAA4B,EAC5B,OAAO,GAAwD,EAAE,MAAM,EAAE,EAAE,EAAE;IAE7E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAChE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;IAElD,MAAM,GAAG,GAA8B,EAAE,CAAC;IAC1C,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACf,SAAS;QACX,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,QAAQ,CAAC,UAAiC,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { MockKind } from "@webda/models";
2
+ export type InferContext = {
3
+ fieldName: string;
4
+ declaredType?: string;
5
+ };
6
+ /**
7
+ * Resolve a mock kind from a field's name (strong signal) or declared type
8
+ * (weak fallback). Returns `null` when no rule matches — callers decide
9
+ * whether to warn, throw, or skip.
10
+ *
11
+ * @param ctx - the inference context (field name + optional declared type).
12
+ * @returns the inferred `MockKind`, or `null` when no rule matches.
13
+ */
14
+ export declare function inferKind(ctx: InferContext): MockKind | null;
15
+ //# sourceMappingURL=infer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer.d.ts","sourceRoot":"","sources":["../../src/engine/infer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAmCF;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,QAAQ,GAAG,IAAI,CAc5D"}
@@ -0,0 +1,54 @@
1
+ /** Case-insensitive exact-match field-name heuristic. Includes type-guarded `*At` rule. */
2
+ const NAME_TO_KIND = {
3
+ email: "email",
4
+ phone: "phone",
5
+ phonenumber: "phone",
6
+ url: "url",
7
+ website: "url",
8
+ firstname: "firstName",
9
+ lastname: "lastName",
10
+ fullname: "fullName",
11
+ uuid: "uuid",
12
+ id: "uuid",
13
+ avatar: "avatar",
14
+ image: "avatar",
15
+ photo: "avatar",
16
+ createdat: "recentDate",
17
+ updatedat: "recentDate",
18
+ age: "integer",
19
+ count: "integer",
20
+ quantity: "integer",
21
+ amount: "float",
22
+ price: "float",
23
+ score: "float",
24
+ rating: "float"
25
+ };
26
+ const TYPE_TO_KIND = {
27
+ string: "lorem",
28
+ number: "integer",
29
+ boolean: "boolean",
30
+ date: "recentDate"
31
+ };
32
+ /**
33
+ * Resolve a mock kind from a field's name (strong signal) or declared type
34
+ * (weak fallback). Returns `null` when no rule matches — callers decide
35
+ * whether to warn, throw, or skip.
36
+ *
37
+ * @param ctx - the inference context (field name + optional declared type).
38
+ * @returns the inferred `MockKind`, or `null` when no rule matches.
39
+ */
40
+ export function inferKind(ctx) {
41
+ const lower = ctx.fieldName.toLowerCase();
42
+ const direct = NAME_TO_KIND[lower];
43
+ if (direct)
44
+ return direct;
45
+ if (lower.endsWith("at") && ctx.declaredType === "Date")
46
+ return "pastDate";
47
+ if (ctx.declaredType) {
48
+ const tk = TYPE_TO_KIND[ctx.declaredType.toLowerCase()];
49
+ if (tk)
50
+ return tk;
51
+ }
52
+ return null;
53
+ }
54
+ //# sourceMappingURL=infer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer.js","sourceRoot":"","sources":["../../src/engine/infer.ts"],"names":[],"mappings":"AAOA,2FAA2F;AAC3F,MAAM,YAAY,GAA6B;IAC7C,K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
+ /**
2
+ * Session-scoped instance pool. Holds every instance generated during one
3
+ * `generate()` / `generateGraph()` call so that later relation-aware fields
4
+ * (`@ModelLink`, `@ModelRelated`) can reference real earlier instances rather
5
+ * than made-up ids.
6
+ *
7
+ * All randomness is driven by the constructor-injected `rng: () => number`
8
+ * so outcomes are reproducible when the caller supplies a seeded RNG.
9
+ */
10
+ export declare class SessionPool {
11
+ private rng;
12
+ private byClass;
13
+ /**
14
+ * @param rng - deterministic RNG returning a float in `[0, 1)`. Defaults to
15
+ * `Math.random` when no seed is needed.
16
+ */
17
+ constructor(rng?: () => number);
18
+ /**
19
+ * Add an instance to the pool, keyed by its constructor.
20
+ *
21
+ * @param instance - the object to add. Non-objects are ignored.
22
+ */
23
+ add(instance: unknown): void;
24
+ /**
25
+ * Pick one random instance of the given class from the pool.
26
+ *
27
+ * @param ctor - the class to pick an instance of.
28
+ * @returns a pooled instance, or `null` when the pool has none.
29
+ */
30
+ pickOne<T>(ctor: new (...args: any[]) => T): T | null;
31
+ /**
32
+ * Pick a unique subset of instances of the given class.
33
+ *
34
+ * @param ctor - the class to pick from.
35
+ * @param count - requested subset size; clamped to `pool.size(ctor)`.
36
+ * @returns the selected instances (may be shorter than `count`).
37
+ */
38
+ pickMany<T>(ctor: new (...args: any[]) => T, count: number): T[];
39
+ /**
40
+ * Number of pooled instances of the given class.
41
+ *
42
+ * @param ctor - the class to count.
43
+ * @returns the current pool size for that class (0 when absent).
44
+ */
45
+ size(ctor: new (...args: any[]) => unknown): number;
46
+ }
47
+ //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/engine/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,WAAW;IAOV,OAAO,CAAC,GAAG;IANvB,OAAO,CAAC,OAAO,CAAkC;IAEjD;;;OAGG;IACH,YAAoB,GAAG,GAAE,MAAM,MAAoB,EAAI;IAEvD;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAS3B;IAED;;;;;OAKG;IACH,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAKpD;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAc/D;IAED;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,GAAG,MAAM,CAElD;CACF"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Session-scoped instance pool. Holds every instance generated during one
3
+ * `generate()` / `generateGraph()` call so that later relation-aware fields
4
+ * (`@ModelLink`, `@ModelRelated`) can reference real earlier instances rather
5
+ * than made-up ids.
6
+ *
7
+ * All randomness is driven by the constructor-injected `rng: () => number`
8
+ * so outcomes are reproducible when the caller supplies a seeded RNG.
9
+ */
10
+ export class SessionPool {
11
+ rng;
12
+ byClass = new Map();
13
+ /**
14
+ * @param rng - deterministic RNG returning a float in `[0, 1)`. Defaults to
15
+ * `Math.random` when no seed is needed.
16
+ */
17
+ constructor(rng = Math.random) {
18
+ this.rng = rng;
19
+ }
20
+ /**
21
+ * Add an instance to the pool, keyed by its constructor.
22
+ *
23
+ * @param instance - the object to add. Non-objects are ignored.
24
+ */
25
+ add(instance) {
26
+ if (instance == null || typeof instance !== "object")
27
+ return;
28
+ const ctor = instance.constructor;
29
+ let list = this.byClass.get(ctor);
30
+ if (!list) {
31
+ list = [];
32
+ this.byClass.set(ctor, list);
33
+ }
34
+ list.push(instance);
35
+ }
36
+ /**
37
+ * Pick one random instance of the given class from the pool.
38
+ *
39
+ * @param ctor - the class to pick an instance of.
40
+ * @returns a pooled instance, or `null` when the pool has none.
41
+ */
42
+ pickOne(ctor) {
43
+ const list = this.byClass.get(ctor);
44
+ if (!list || list.length === 0)
45
+ return null;
46
+ const idx = Math.floor(this.rng() * list.length);
47
+ return list[Math.min(idx, list.length - 1)];
48
+ }
49
+ /**
50
+ * Pick a unique subset of instances of the given class.
51
+ *
52
+ * @param ctor - the class to pick from.
53
+ * @param count - requested subset size; clamped to `pool.size(ctor)`.
54
+ * @returns the selected instances (may be shorter than `count`).
55
+ */
56
+ pickMany(ctor, count) {
57
+ const list = this.byClass.get(ctor);
58
+ if (!list || list.length === 0)
59
+ return [];
60
+ const take = Math.min(count, list.length);
61
+ // Fisher-Yates-style selection using our rng, taking the first `take`.
62
+ const copy = [...list];
63
+ for (let i = 0; i < take; i++) {
64
+ const j = i + Math.floor(this.rng() * (copy.length - i));
65
+ const swap = Math.min(j, copy.length - 1);
66
+ const tmp = copy[i];
67
+ copy[i] = copy[swap];
68
+ copy[swap] = tmp;
69
+ }
70
+ return copy.slice(0, take);
71
+ }
72
+ /**
73
+ * Number of pooled instances of the given class.
74
+ *
75
+ * @param ctor - the class to count.
76
+ * @returns the current pool size for that class (0 when absent).
77
+ */
78
+ size(ctor) {
79
+ return this.byClass.get(ctor)?.length ?? 0;
80
+ }
81
+ }
82
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/engine/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IAOF,GAAG;IANf,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEjD;;;OAGG;IACH,YAAoB,GAAG,GAAiB,IAAI,CAAC,MAAM;mBAA/B,GAAG;IAA+B,CAAC;IAEvD;;;;OAIG;IACH,GAAG,CAAC,QAAiB;QACnB,IAAI,QAAQ,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAAE,OAAO;QAC7D,MAAM,IAAI,GAAI,QAAsC,CAAC,WAAW,CA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I,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YACzD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAQ,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,IAAqC;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IAC7C,CAAC;CACF"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const VERSION = "4.0.0-beta.1";
2
+ export { generate, type GenerateOptions, type MockContext, type Mode } from "./engine/generate.js";
3
+ export { generateGraph } from "./engine/graph.js";
4
+ export { SessionPool } from "./engine/pool.js";
5
+ export { makeFaker } from "./engine/faker.js";
6
+ export { inferKind, type InferContext } from "./engine/infer.js";
7
+ export type { AIProvider } from "./ai/provider.js";
8
+ export { MockAIProvider } from "./ai/provider.js";
9
+ export { AnthropicProvider } from "./ai/anthropic.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,iBAAiB,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export const VERSION = "4.0.0-beta.1";
2
+ export { generate } from "./engine/generate.js";
3
+ export { generateGraph } from "./engine/graph.js";
4
+ export { SessionPool } from "./engine/pool.js";
5
+ export { makeFaker } from "./engine/faker.js";
6
+ export { inferKind } from "./engine/infer.js";
7
+ export { MockAIProvider } from "./ai/provider.js";
8
+ export { AnthropicProvider } from "./ai/anthropic.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAqD,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAqB,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { type GenerateOptions } from "../engine/generate.js";
2
+ type ModelClass<T> = new (...args: any[]) => T;
3
+ export type MockServiceParameters = {
4
+ mode?: "test" | "dev" | "demo" | "load" | "custom";
5
+ seed?: number;
6
+ aiProvider?: "anthropic" | "openai" | "none";
7
+ aiApiKey?: string;
8
+ };
9
+ /**
10
+ * Thin service facade exposing mock-data generation. Holds default
11
+ * configuration (mode/seed/AI) so callers don't repeat options per call.
12
+ *
13
+ * For v1 this is a standalone class; integrators wrap it into a `@Bean`
14
+ * subclass in their own project as needed. A first-class `@webda/core`
15
+ * Service subclass is a planned follow-up once the core package export
16
+ * graph on `main` is repaired.
17
+ */
18
+ export declare class MockService {
19
+ private parameters;
20
+ /**
21
+ * @param _webda - reserved for a future `@webda/core` Service subclass wiring.
22
+ * @param _name - reserved service name (unused in the v1 standalone class).
23
+ * @param parameters - default mode/seed/AI configuration.
24
+ */
25
+ constructor(_webda?: unknown, _name?: string, parameters?: MockServiceParameters);
26
+ /**
27
+ * Generate instances using the service's defaults merged with per-call options.
28
+ *
29
+ * @param ModelClass - the target model constructor.
30
+ * @param options - per-call overrides for the service defaults.
31
+ * @returns the generated instances.
32
+ */
33
+ generate<T>(ModelClass: ModelClass<T>, options?: GenerateOptions<T>): Promise<T[]>;
34
+ /**
35
+ * Generate across multiple models in one call, sharing one seeded pool.
36
+ *
37
+ * @param spec - `{ ModelName: count }` map.
38
+ * @param options - per-call overrides plus the model classes to generate.
39
+ * @returns `{ ModelName: instances[] }`.
40
+ */
41
+ seed(spec: Record<string, number>, options?: Partial<GenerateOptions> & {
42
+ models: ModelClass<unknown>[];
43
+ }): Promise<Record<string, unknown[]>>;
44
+ /**
45
+ * Clear generated data. In v1 this is a no-op — persistent clearing
46
+ * requires webda Store registry access and is planned as a follow-up.
47
+ *
48
+ * @param _modelNames - models to clear. Ignored in v1.
49
+ */
50
+ clear(_modelNames?: string[]): Promise<void>;
51
+ /**
52
+ * Build the default `GenerateOptions` from the service's parameters.
53
+ *
54
+ * @returns the default options bag (mode + seed from constructor params).
55
+ */
56
+ private defaults;
57
+ }
58
+ export {};
59
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O,CAAC,IAAI,CAAC,CAGjD;IAED;;;;OAIG;IACH,OAAO,CAAC,QAAQ;CAMjB"}
@@ -0,0 +1,66 @@
1
+ import { generate } from "../engine/generate.js";
2
+ import { generateGraph } from "../engine/graph.js";
3
+ /**
4
+ * Thin service facade exposing mock-data generation. Holds default
5
+ * configuration (mode/seed/AI) so callers don't repeat options per call.
6
+ *
7
+ * For v1 this is a standalone class; integrators wrap it into a `@Bean`
8
+ * subclass in their own project as needed. A first-class `@webda/core`
9
+ * Service subclass is a planned follow-up once the core package export
10
+ * graph on `main` is repaired.
11
+ */
12
+ export class MockService {
13
+ parameters;
14
+ /**
15
+ * @param _webda - reserved for a future `@webda/core` Service subclass wiring.
16
+ * @param _name - reserved service name (unused in the v1 standalone class).
17
+ * @param parameters - default mode/seed/AI configuration.
18
+ */
19
+ constructor(_webda, _name, parameters = {}) {
20
+ this.parameters = parameters;
21
+ }
22
+ /**
23
+ * Generate instances using the service's defaults merged with per-call options.
24
+ *
25
+ * @param ModelClass - the target model constructor.
26
+ * @param options - per-call overrides for the service defaults.
27
+ * @returns the generated instances.
28
+ */
29
+ async generate(ModelClass, options) {
30
+ const merged = { ...this.defaults(), ...options };
31
+ return generate(ModelClass, merged);
32
+ }
33
+ /**
34
+ * Generate across multiple models in one call, sharing one seeded pool.
35
+ *
36
+ * @param spec - `{ ModelName: count }` map.
37
+ * @param options - per-call overrides plus the model classes to generate.
38
+ * @returns `{ ModelName: instances[] }`.
39
+ */
40
+ async seed(spec, options) {
41
+ const models = options?.models ?? [];
42
+ return generateGraph(spec, { ...this.defaults(), ...options, models });
43
+ }
44
+ /**
45
+ * Clear generated data. In v1 this is a no-op — persistent clearing
46
+ * requires webda Store registry access and is planned as a follow-up.
47
+ *
48
+ * @param _modelNames - models to clear. Ignored in v1.
49
+ */
50
+ async clear(_modelNames) {
51
+ // v1 no-op — persistent clearing requires webda Store registry access
52
+ // and is blocked on the @webda/core export graph. Planned for follow-up.
53
+ }
54
+ /**
55
+ * Build the default `GenerateOptions` from the service's parameters.
56
+ *
57
+ * @returns the default options bag (mode + seed from constructor params).
58
+ */
59
+ defaults() {
60
+ return {
61
+ mode: this.parameters.mode,
62
+ seed: this.parameters.seed
63
+ };
64
+ }
65
+ }
66
+ //# sourceMappingURL=mock-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-service.js","sourceRoot":"","sources":["../../src/service/mock-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWnD;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IAMgC,UAAU;IALhE;;;;OAIG;IACH,YAAY,MAAgB,EAAE,KAAc,EAAU,UAAU,GAA0B,EAAE;0BAAtC,UAAU;IAA+B,CAAC;IAEhG;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAI,UAAyB,EAAE,OAA4B;QACvE,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,EAAwB,CAAC;QACxE,OAAO,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CACR,IAA4B,EAC5B,OAAsE;QAEtE,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,CAAC;QACrC,OAAO,aAAa,CAAC,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,WAAsB;QAChC,sEAAsE;QACtE,yEAAyE;IAC3E,CAAC;IAED;;;;OAIG;IACK,QAAQ;QACd,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI;YAC1B,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI;SAC3B,CAAC;IACJ,CAAC;CACF"}