@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.
- package/LICENSE +166 -0
- package/README.md +121 -0
- package/lib/ai/anthropic.d.ts +30 -0
- package/lib/ai/anthropic.d.ts.map +1 -0
- package/lib/ai/anthropic.js +43 -0
- package/lib/ai/anthropic.js.map +1 -0
- package/lib/ai/provider.d.ts +35 -0
- package/lib/ai/provider.d.ts.map +1 -0
- package/lib/ai/provider.js +27 -0
- package/lib/ai/provider.js.map +1 -0
- package/lib/cli/seed.d.ts +22 -0
- package/lib/cli/seed.d.ts.map +1 -0
- package/lib/cli/seed.js +43 -0
- package/lib/cli/seed.js.map +1 -0
- package/lib/engine/faker.d.ts +10 -0
- package/lib/engine/faker.d.ts.map +1 -0
- package/lib/engine/faker.js +14 -0
- package/lib/engine/faker.js.map +1 -0
- package/lib/engine/generate.d.ts +37 -0
- package/lib/engine/generate.d.ts.map +1 -0
- package/lib/engine/generate.js +171 -0
- package/lib/engine/generate.js.map +1 -0
- package/lib/engine/graph.d.ts +22 -0
- package/lib/engine/graph.d.ts.map +1 -0
- package/lib/engine/graph.js +37 -0
- package/lib/engine/graph.js.map +1 -0
- package/lib/engine/infer.d.ts +15 -0
- package/lib/engine/infer.d.ts.map +1 -0
- package/lib/engine/infer.js +54 -0
- package/lib/engine/infer.js.map +1 -0
- package/lib/engine/pool.d.ts +47 -0
- package/lib/engine/pool.d.ts.map +1 -0
- package/lib/engine/pool.js +82 -0
- package/lib/engine/pool.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -0
- package/lib/service/mock-service.d.ts +59 -0
- package/lib/service/mock-service.d.ts.map +1 -0
- package/lib/service/mock-service.js +66 -0
- package/lib/service/mock-service.js.map +1 -0
- package/package.json +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
166
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @webda/mock module
|
|
2
|
+
|
|
3
|
+
This module is part of Webda Application Framework that allows you to quickly develop applications with all modern prerequisites: Security, Extensibility, GraphQL, REST, CloudNative [https://webda.io](https://webda.io)
|
|
4
|
+
|
|
5
|
+
<img src="https://webda.io/images/webda.svg" width="128" />
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
[](https://gitter.im/loopingz/webda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
10
|
+
[](https://codecov.io/gh/loopingz/webda.io)
|
|
11
|
+
[](https://sonarcloud.io/summary/new_code?id=loopingz_webda.io)
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
<!-- README_HEADER -->
|
|
15
|
+
|
|
16
|
+
# @webda/mock
|
|
17
|
+
|
|
18
|
+
> Coherent mock-data generation for `@webda/models` classes — decorator-driven field population with deterministic seeding, multi-model graph support, and optional AI-generated text.
|
|
19
|
+
|
|
20
|
+
## When to use it
|
|
21
|
+
|
|
22
|
+
- You need realistic, consistent test fixtures for Webda models without writing manual factory functions.
|
|
23
|
+
- You want reproducible test data with `mode: "test"` (seed=0) and varied demo data with `mode: "demo"`.
|
|
24
|
+
- You need to populate an entire relational graph of models (e.g. Users + Orders + Posts) in one call.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add -D @webda/mock
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
`@webda/mock` is a pure library — no `webda.config.json` entry is required. Field hints are added via `@Mock.*` decorators from `@webda/models` (zero production cost — tree-shaken out).
|
|
35
|
+
|
|
36
|
+
| Option | Type | Default | Description |
|
|
37
|
+
|---|---|---|---|
|
|
38
|
+
| `count` | number | `1` | Number of instances to generate |
|
|
39
|
+
| `seed` | number | `0` (test) / `Date.now()` (dev) | RNG seed for reproducibility |
|
|
40
|
+
| `mode` | `"test"` \| `"dev"` \| `"demo"` \| `"load"` | `"test"` in Vitest | Controls seed default, AI usage, and session pool |
|
|
41
|
+
| `overrides` | `Partial<T>` | — | Force-set specific fields regardless of inference |
|
|
42
|
+
| `strict` | boolean | `false` | Throw instead of skip on unhinted, uninferable fields |
|
|
43
|
+
| `ai` | `AIProvider` | — | AI provider for `@Mock.ai` fields (e.g. `AnthropicProvider`) |
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Mock } from "@webda/models";
|
|
49
|
+
import { generate, generateGraph } from "@webda/mock";
|
|
50
|
+
|
|
51
|
+
// Annotate your model fields
|
|
52
|
+
class Post {
|
|
53
|
+
@Mock.word accessor title!: string;
|
|
54
|
+
@Mock.paragraph accessor body!: string;
|
|
55
|
+
@Mock.pastDate accessor publishedAt!: Date;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class User {
|
|
59
|
+
@Mock.firstName accessor firstName!: string;
|
|
60
|
+
@Mock.email accessor email!: string;
|
|
61
|
+
@Mock.integer({ min: 18, max: 99 }) accessor age!: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Generate 5 deterministic posts (seed=42)
|
|
65
|
+
const posts = await generate(Post, { count: 5, seed: 42, mode: "test" });
|
|
66
|
+
// posts[0].title is always the same string across runs
|
|
67
|
+
|
|
68
|
+
// Generate a relational graph: 10 users and 50 posts
|
|
69
|
+
const graph = await generateGraph(
|
|
70
|
+
{ User: 10, Post: 50 },
|
|
71
|
+
{ models: [User, Post], seed: 1, mode: "dev" }
|
|
72
|
+
);
|
|
73
|
+
// graph.User → User[], graph.Post → Post[]
|
|
74
|
+
|
|
75
|
+
// Optional: AI-generated text fields (Anthropic)
|
|
76
|
+
import { AnthropicProvider } from "@webda/mock";
|
|
77
|
+
|
|
78
|
+
const ai = new AnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY });
|
|
79
|
+
|
|
80
|
+
class Product {
|
|
81
|
+
@Mock.word accessor name!: string;
|
|
82
|
+
@Mock.ai({ prompt: "One-sentence marketing tagline for a fictional product." })
|
|
83
|
+
accessor tagline!: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const products = await generate(Product, { count: 3, mode: "demo", ai });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Modes
|
|
90
|
+
|
|
91
|
+
| Mode | Seed default | AI | Use case |
|
|
92
|
+
|------|-------------|-----|---------|
|
|
93
|
+
| `test` | `0` (deterministic) | Throws on `@Mock.ai` | Unit tests, snapshots |
|
|
94
|
+
| `dev` | `Date.now()` | Enabled if provider given | Local development seeding |
|
|
95
|
+
| `demo` | Logged | Enabled + preferred for text | Demo environments |
|
|
96
|
+
| `load` | Caller-supplied | Disabled | Load/performance testing |
|
|
97
|
+
|
|
98
|
+
## Reference
|
|
99
|
+
|
|
100
|
+
- API reference: see the auto-generated typedoc at `docs/pages/Modules/mock/`.
|
|
101
|
+
- Source: [`packages/mock`](https://github.com/loopingz/webda.io/tree/main/packages/mock)
|
|
102
|
+
- Related: [`@webda/models`](../models) for the `@Mock.*` decorator definitions; [`@webda/test`](../test) for the `WebdaTest` harness where mock data is typically used; [`@webda/fs`](../fs) for `FileStore` to persist generated data locally.
|
|
103
|
+
|
|
104
|
+
<!-- README_FOOTER -->
|
|
105
|
+
## Sponsors
|
|
106
|
+
|
|
107
|
+
<!--
|
|
108
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](mailto:sponsor@webda.io)
|
|
109
|
+
-->
|
|
110
|
+
|
|
111
|
+
Arize AI is a machine learning observability and model monitoring platform. It helps you visualize, monitor, and explain your machine learning models. [Learn more](https://arize.com)
|
|
112
|
+
|
|
113
|
+
[<img src="https://arize.com/hubfs/arize/brand/arize-logomark-1.png" width="200">](https://arize.com)
|
|
114
|
+
|
|
115
|
+
Loopingz is a software development company that provides consulting and development services. [Learn more](https://loopingz.com)
|
|
116
|
+
|
|
117
|
+
[<img src="https://loopingz.com/images/logo.png" width="200">](https://loopingz.com)
|
|
118
|
+
|
|
119
|
+
Tellae is an innovative consulting firm specialized in cities transportation issues. We provide our clients, both public and private, with solutions to support your strategic and operational decisions. [Learn more](https://tellae.fr)
|
|
120
|
+
|
|
121
|
+
[<img src="https://tellae.fr/" width="200">](https://tellae.fr)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AIProvider } from "./provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* `AIProvider` backed by Anthropic's Claude API. Loads `@anthropic-ai/sdk`
|
|
4
|
+
* lazily on the first `complete()` call so the package does not force the
|
|
5
|
+
* SDK into consumers' graphs at import time.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AnthropicProvider implements AIProvider {
|
|
8
|
+
private opts;
|
|
9
|
+
/**
|
|
10
|
+
* @param opts - construction options.
|
|
11
|
+
* @param opts.apiKey - Anthropic API key (falls back to `ANTHROPIC_API_KEY` env).
|
|
12
|
+
* @param opts.model - model identifier (defaults to the current Haiku).
|
|
13
|
+
*/
|
|
14
|
+
constructor(opts?: {
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Send a single completion request to Claude.
|
|
20
|
+
*
|
|
21
|
+
* @param prompt - the user-side prompt text.
|
|
22
|
+
* @param options - optional tuning parameters.
|
|
23
|
+
* @param options.maxTokens - maximum tokens for the response (default 512).
|
|
24
|
+
* @returns the first text block of the response; empty string if none.
|
|
25
|
+
*/
|
|
26
|
+
complete(prompt: string, options?: {
|
|
27
|
+
maxTokens?: number;
|
|
28
|
+
}): Promise<string>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/ai/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,UAAU;IAMtC,OAAO,CAAC,IAAI;IALxB;;;;OAIG;IACH,YAAoB,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,EAAI;IAEtE;;;;;;;OAOG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBhF;CACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AIProvider` backed by Anthropic's Claude API. Loads `@anthropic-ai/sdk`
|
|
3
|
+
* lazily on the first `complete()` call so the package does not force the
|
|
4
|
+
* SDK into consumers' graphs at import time.
|
|
5
|
+
*/
|
|
6
|
+
export class AnthropicProvider {
|
|
7
|
+
opts;
|
|
8
|
+
/**
|
|
9
|
+
* @param opts - construction options.
|
|
10
|
+
* @param opts.apiKey - Anthropic API key (falls back to `ANTHROPIC_API_KEY` env).
|
|
11
|
+
* @param opts.model - model identifier (defaults to the current Haiku).
|
|
12
|
+
*/
|
|
13
|
+
constructor(opts = {}) {
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Send a single completion request to Claude.
|
|
18
|
+
*
|
|
19
|
+
* @param prompt - the user-side prompt text.
|
|
20
|
+
* @param options - optional tuning parameters.
|
|
21
|
+
* @param options.maxTokens - maximum tokens for the response (default 512).
|
|
22
|
+
* @returns the first text block of the response; empty string if none.
|
|
23
|
+
*/
|
|
24
|
+
async complete(prompt, options) {
|
|
25
|
+
const apiKey = this.opts.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
26
|
+
if (!apiKey) {
|
|
27
|
+
throw new Error("AnthropicProvider: no apiKey configured and ANTHROPIC_API_KEY is not set in env");
|
|
28
|
+
}
|
|
29
|
+
// Lazy-load the SDK so the package does not require it at import time.
|
|
30
|
+
const mod = await import("@anthropic-ai/sdk");
|
|
31
|
+
const Anthropic = mod.default ?? mod.Anthropic;
|
|
32
|
+
const client = new Anthropic({ apiKey });
|
|
33
|
+
const model = this.opts.model ?? "claude-haiku-4-5-20251001";
|
|
34
|
+
const res = await client.messages.create({
|
|
35
|
+
model,
|
|
36
|
+
max_tokens: options?.maxTokens ?? 512,
|
|
37
|
+
messages: [{ role: "user", content: prompt }]
|
|
38
|
+
});
|
|
39
|
+
const first = res.content.find((b) => b.type === "text");
|
|
40
|
+
return first?.text ?? "";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/ai/anthropic.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAMR,IAAI;IALxB;;;;OAIG;IACH,YAAoB,IAAI,GAAwC,EAAE;oBAA9C,IAAI;IAA6C,CAAC;IAEtE;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,OAAgC;QAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACjE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;QACJ,CAAC;QACD,uEAAuE;QACvE,MAAM,GAAG,GAAQ,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACnD,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,SAAS,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACzC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,2BAA2B,CAAC;QAC7D,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;YACvC,KAAK;YACL,UAAU,EAAE,OAAO,EAAE,SAAS,IAAI,GAAG;YACrC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;SAC9C,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAmB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAkC,CAAC;QAC5G,OAAO,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Abstracts the LLM used to resolve `@Mock.ai` fields. */
|
|
2
|
+
export interface AIProvider {
|
|
3
|
+
/**
|
|
4
|
+
* Complete a prompt.
|
|
5
|
+
*
|
|
6
|
+
* @param prompt - the input text.
|
|
7
|
+
* @param options - optional tuning.
|
|
8
|
+
* @param options.maxTokens - maximum tokens for the response.
|
|
9
|
+
* @returns the completion text.
|
|
10
|
+
*/
|
|
11
|
+
complete(prompt: string, options?: {
|
|
12
|
+
maxTokens?: number;
|
|
13
|
+
}): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
/** Deterministic fake provider for unit tests. */
|
|
16
|
+
export declare class MockAIProvider implements AIProvider {
|
|
17
|
+
private opts;
|
|
18
|
+
private i;
|
|
19
|
+
/**
|
|
20
|
+
* @param opts - construction options.
|
|
21
|
+
* @param opts.canned - canned responses returned in order (last repeats if exhausted).
|
|
22
|
+
* When omitted, `complete()` echoes the prompt back.
|
|
23
|
+
*/
|
|
24
|
+
constructor(opts?: {
|
|
25
|
+
canned?: string[];
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Return the next canned answer, or the prompt itself when none were given.
|
|
29
|
+
*
|
|
30
|
+
* @param prompt - the input text.
|
|
31
|
+
* @returns the next canned answer, or the prompt echoed back.
|
|
32
|
+
*/
|
|
33
|
+
complete(prompt: string): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/ai/provider.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,MAAM,WAAW,UAAU;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7E;AAED,kDAAkD;AAClD,qBAAa,cAAe,YAAW,UAAU;IAOnC,OAAO,CAAC,IAAI;IANxB,OAAO,CAAC,CAAC,CAAK;IACd;;;;OAIG;IACH,YAAoB,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO,EAAI;IAExD;;;;;OAKG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9C;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Deterministic fake provider for unit tests. */
|
|
2
|
+
export class MockAIProvider {
|
|
3
|
+
opts;
|
|
4
|
+
i = 0;
|
|
5
|
+
/**
|
|
6
|
+
* @param opts - construction options.
|
|
7
|
+
* @param opts.canned - canned responses returned in order (last repeats if exhausted).
|
|
8
|
+
* When omitted, `complete()` echoes the prompt back.
|
|
9
|
+
*/
|
|
10
|
+
constructor(opts = {}) {
|
|
11
|
+
this.opts = opts;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Return the next canned answer, or the prompt itself when none were given.
|
|
15
|
+
*
|
|
16
|
+
* @param prompt - the input text.
|
|
17
|
+
* @returns the next canned answer, or the prompt echoed back.
|
|
18
|
+
*/
|
|
19
|
+
async complete(prompt) {
|
|
20
|
+
if (!this.opts.canned || this.opts.canned.length === 0)
|
|
21
|
+
return prompt;
|
|
22
|
+
const idx = Math.min(this.i, this.opts.canned.length - 1);
|
|
23
|
+
this.i++;
|
|
24
|
+
return this.opts.canned[idx];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/ai/provider.ts"],"names":[],"mappings":"AAaA,kDAAkD;AAClD,MAAM,OAAO,cAAc;IAOL,IAAI;IANhB,CAAC,GAAG,CAAC,CAAC;IACd;;;;OAIG;IACH,YAAoB,IAAI,GAA0B,EAAE;oBAAhC,IAAI;IAA+B,CAAC;IAExD;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAc;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QACtE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SeedParsed = {
|
|
2
|
+
spec: Record<string, number>;
|
|
3
|
+
specPath?: string;
|
|
4
|
+
options: {
|
|
5
|
+
seed?: number;
|
|
6
|
+
mode?: "test" | "dev" | "demo" | "load" | "custom";
|
|
7
|
+
disableAi?: boolean;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Parse `webda mock seed` argv. Recognises:
|
|
12
|
+
* --ModelName N count for a model
|
|
13
|
+
* --seed N deterministic seed
|
|
14
|
+
* --mode dev|demo|…
|
|
15
|
+
* --ai | --no-ai enable / disable AI provider
|
|
16
|
+
* --spec ./file.json alternate source for model counts
|
|
17
|
+
*
|
|
18
|
+
* @param argv - the command-line arguments to parse (without the `webda mock seed` prefix).
|
|
19
|
+
* @returns the parsed spec map, optional spec file path, and options bag.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseSeedArgs(argv: string[]): SeedParsed;
|
|
22
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/cli/seed.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;QACnD,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;CACH,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAwBxD"}
|
package/lib/cli/seed.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse `webda mock seed` argv. Recognises:
|
|
3
|
+
* --ModelName N count for a model
|
|
4
|
+
* --seed N deterministic seed
|
|
5
|
+
* --mode dev|demo|…
|
|
6
|
+
* --ai | --no-ai enable / disable AI provider
|
|
7
|
+
* --spec ./file.json alternate source for model counts
|
|
8
|
+
*
|
|
9
|
+
* @param argv - the command-line arguments to parse (without the `webda mock seed` prefix).
|
|
10
|
+
* @returns the parsed spec map, optional spec file path, and options bag.
|
|
11
|
+
*/
|
|
12
|
+
export function parseSeedArgs(argv) {
|
|
13
|
+
const out = { spec: {}, options: {} };
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < argv.length) {
|
|
16
|
+
const flag = argv[i];
|
|
17
|
+
if (flag === "--seed") {
|
|
18
|
+
out.options.seed = Number(argv[++i]);
|
|
19
|
+
}
|
|
20
|
+
else if (flag === "--mode") {
|
|
21
|
+
out.options.mode = argv[++i];
|
|
22
|
+
}
|
|
23
|
+
else if (flag === "--no-ai") {
|
|
24
|
+
out.options.disableAi = true;
|
|
25
|
+
}
|
|
26
|
+
else if (flag === "--ai") {
|
|
27
|
+
out.options.disableAi = false;
|
|
28
|
+
}
|
|
29
|
+
else if (flag === "--spec") {
|
|
30
|
+
out.specPath = argv[++i];
|
|
31
|
+
}
|
|
32
|
+
else if (flag.startsWith("--")) {
|
|
33
|
+
const name = flag.slice(2);
|
|
34
|
+
const value = argv[++i];
|
|
35
|
+
const n = Number(value);
|
|
36
|
+
if (!Number.isNaN(n))
|
|
37
|
+
out.spec[name] = n;
|
|
38
|
+
}
|
|
39
|
+
i++;
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=seed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../../src/cli/seed.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAc;IAC1C,MAAM,GAAG,GAAe,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAClD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAkC,CAAC;QAChE,CAAC;aAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YAC9B,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAC/B,CAAC;aAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YAC3B,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC;aAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YACxB,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC;QACD,CAAC,EAAE,CAAC;IACN,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Faker } from "@faker-js/faker";
|
|
2
|
+
/**
|
|
3
|
+
* Build a seeded Faker instance. Uses the English locale plus the base locale
|
|
4
|
+
* (numbers, dates) as fallbacks — matches Faker v9's recommended defaults.
|
|
5
|
+
*
|
|
6
|
+
* @param seed - optional numeric seed. Defaults to Date.now() for non-deterministic runs.
|
|
7
|
+
* @returns a seeded Faker instance.
|
|
8
|
+
*/
|
|
9
|
+
export declare function makeFaker(seed?: number): Faker;
|
|
10
|
+
//# sourceMappingURL=faker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faker.d.ts","sourceRoot":"","sources":["../../src/engine/faker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,iBAAiB,CAAC;AAElD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAI9C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Faker, en, base } from "@faker-js/faker";
|
|
2
|
+
/**
|
|
3
|
+
* Build a seeded Faker instance. Uses the English locale plus the base locale
|
|
4
|
+
* (numbers, dates) as fallbacks — matches Faker v9's recommended defaults.
|
|
5
|
+
*
|
|
6
|
+
* @param seed - optional numeric seed. Defaults to Date.now() for non-deterministic runs.
|
|
7
|
+
* @returns a seeded Faker instance.
|
|
8
|
+
*/
|
|
9
|
+
export function makeFaker(seed) {
|
|
10
|
+
const faker = new Faker({ locale: [en, base] });
|
|
11
|
+
faker.seed(seed ?? Date.now());
|
|
12
|
+
return faker;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=faker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faker.js","sourceRoot":"","sources":["../../src/engine/faker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Faker } from "@faker-js/faker";
|
|
2
|
+
import { SessionPool } from "./pool.js";
|
|
3
|
+
import type { AIProvider } from "../ai/provider.js";
|
|
4
|
+
export type Mode = "test" | "dev" | "demo" | "load" | "custom";
|
|
5
|
+
export type GenerateOptions<T = unknown> = {
|
|
6
|
+
count?: number;
|
|
7
|
+
seed?: number;
|
|
8
|
+
mode?: Mode;
|
|
9
|
+
ai?: AIProvider;
|
|
10
|
+
pool?: SessionPool;
|
|
11
|
+
overrides?: Partial<T>;
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type ModelClass<T> = new (...args: any[]) => T;
|
|
15
|
+
export type MockContext = {
|
|
16
|
+
faker: Faker;
|
|
17
|
+
rng: () => number;
|
|
18
|
+
ai: (prompt: string, opts?: {
|
|
19
|
+
maxTokens?: number;
|
|
20
|
+
}) => Promise<string>;
|
|
21
|
+
pool: SessionPool;
|
|
22
|
+
index: number;
|
|
23
|
+
total: number;
|
|
24
|
+
model: Function;
|
|
25
|
+
fieldName: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Generate `count` instances of `ModelClass`, resolving each field through the
|
|
29
|
+
* fallback chain (explicit `@Mock.*` → name-heuristic → type fallback → throw/skip).
|
|
30
|
+
*
|
|
31
|
+
* @param ModelClass - the target model constructor.
|
|
32
|
+
* @param options - generation options (count, seed, mode, overrides, ai, pool, strict).
|
|
33
|
+
* @returns the generated instances.
|
|
34
|
+
*/
|
|
35
|
+
export declare function generate<T>(ModelClass: ModelClass<T>, options?: GenerateOptions<T>): Promise<T[]>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/engine/generate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE/D,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,IAAI;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,UAAU,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,eAAe,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CA8E3G"}
|