@molecule/api-mock-server 1.0.0

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 (67) hide show
  1. package/LICENSE +115 -0
  2. package/README.md +853 -0
  3. package/dist/browser-guard.d.ts +2 -0
  4. package/dist/browser-guard.d.ts.map +1 -0
  5. package/dist/browser-guard.js +19 -0
  6. package/dist/browser-guard.js.map +1 -0
  7. package/dist/cli.d.ts +11 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +152 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/fixtures/app-fixtures.d.ts +54 -0
  12. package/dist/fixtures/app-fixtures.d.ts.map +1 -0
  13. package/dist/fixtures/app-fixtures.js +601 -0
  14. package/dist/fixtures/app-fixtures.js.map +1 -0
  15. package/dist/fixtures/index.d.ts +9 -0
  16. package/dist/fixtures/index.d.ts.map +1 -0
  17. package/dist/fixtures/index.js +9 -0
  18. package/dist/fixtures/index.js.map +1 -0
  19. package/dist/fixtures/seed.d.ts +74 -0
  20. package/dist/fixtures/seed.d.ts.map +1 -0
  21. package/dist/fixtures/seed.js +112 -0
  22. package/dist/fixtures/seed.js.map +1 -0
  23. package/dist/fixtures/semantic-generator.d.ts +20 -0
  24. package/dist/fixtures/semantic-generator.d.ts.map +1 -0
  25. package/dist/fixtures/semantic-generator.js +539 -0
  26. package/dist/fixtures/semantic-generator.js.map +1 -0
  27. package/dist/fixtures/zod-walker.d.ts +34 -0
  28. package/dist/fixtures/zod-walker.d.ts.map +1 -0
  29. package/dist/fixtures/zod-walker.js +183 -0
  30. package/dist/fixtures/zod-walker.js.map +1 -0
  31. package/dist/index.d.ts +78 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +78 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/scanner/index.d.ts +6 -0
  36. package/dist/scanner/index.d.ts.map +1 -0
  37. package/dist/scanner/index.js +6 -0
  38. package/dist/scanner/index.js.map +1 -0
  39. package/dist/scanner/scanner.d.ts +21 -0
  40. package/dist/scanner/scanner.d.ts.map +1 -0
  41. package/dist/scanner/scanner.js +463 -0
  42. package/dist/scanner/scanner.js.map +1 -0
  43. package/dist/server/index.d.ts +7 -0
  44. package/dist/server/index.d.ts.map +1 -0
  45. package/dist/server/index.js +7 -0
  46. package/dist/server/index.js.map +1 -0
  47. package/dist/server/middleware.d.ts +51 -0
  48. package/dist/server/middleware.d.ts.map +1 -0
  49. package/dist/server/middleware.js +124 -0
  50. package/dist/server/middleware.js.map +1 -0
  51. package/dist/server/server.d.ts +29 -0
  52. package/dist/server/server.d.ts.map +1 -0
  53. package/dist/server/server.js +314 -0
  54. package/dist/server/server.js.map +1 -0
  55. package/dist/states/index.d.ts +6 -0
  56. package/dist/states/index.d.ts.map +1 -0
  57. package/dist/states/index.js +6 -0
  58. package/dist/states/index.js.map +1 -0
  59. package/dist/states/states.d.ts +57 -0
  60. package/dist/states/states.d.ts.map +1 -0
  61. package/dist/states/states.js +89 -0
  62. package/dist/states/states.js.map +1 -0
  63. package/dist/types.d.ts +214 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +6 -0
  66. package/dist/types.js.map +1 -0
  67. package/package.json +66 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Deterministic seeded PRNG for stable fixture generation.
3
+ * Uses Mulberry32 algorithm for fast, reproducible random numbers.
4
+ */
5
+ /**
6
+ * Fixed "now" anchor (2026-04-01T12:00:00Z) for all generated dates.
7
+ *
8
+ * Dates are deliberately anchored to a constant instead of the wall clock so
9
+ * fixture output is byte-stable across runs (reliable screenshot diffs).
10
+ * Consequence: "recent"/"future" are relative to this anchor, not the real
11
+ * current time — never assert generated dates against `Date.now()`.
12
+ */
13
+ export declare const FIXTURE_NOW: Date;
14
+ /**
15
+ * Create a seeded random number generator using Mulberry32.
16
+ * Returns a function that produces numbers in [0, 1).
17
+ * @param seed - The seed value
18
+ * @returns A function that returns the next pseudo-random number
19
+ */
20
+ export declare function createSeededRandom(seed: number): () => number;
21
+ /**
22
+ * Derive a deterministic seed from an app type and endpoint path.
23
+ * The same app+path always produces the same seed, ensuring stable fixture output.
24
+ * @param appType - The application type (e.g. 'personal-finance')
25
+ * @param path - The endpoint path (e.g. '/accounts')
26
+ * @returns A numeric seed value
27
+ */
28
+ export declare function seedFromPath(appType: string, path: string): number;
29
+ /**
30
+ * Pick a random element from an array using the RNG.
31
+ * @param rng - The seeded random function
32
+ * @param arr - The array to pick from
33
+ * @returns A random element from the array
34
+ */
35
+ export declare function pick<T>(rng: () => number, arr: readonly T[]): T;
36
+ /**
37
+ * Pick a random integer in [min, max] inclusive.
38
+ * @param rng - The seeded random function
39
+ * @param min - Minimum value (inclusive)
40
+ * @param max - Maximum value (inclusive)
41
+ * @returns A random integer in the given range
42
+ */
43
+ export declare function randomInt(rng: () => number, min: number, max: number): number;
44
+ /**
45
+ * Generate a random dollar amount rounded to cents.
46
+ * @param rng - The seeded random function
47
+ * @param min - Minimum value
48
+ * @param max - Maximum value
49
+ * @returns A number rounded to 2 decimal places
50
+ */
51
+ export declare function randomDollars(rng: () => number, min: number, max: number): number;
52
+ /**
53
+ * Generate a "recent" ISO date string within the last N days of the fixed
54
+ * `FIXTURE_NOW` anchor (NOT the wall clock — see `FIXTURE_NOW`).
55
+ * @param rng - The seeded random function
56
+ * @param daysBack - Maximum days in the past (default 90)
57
+ * @returns An ISO date string
58
+ */
59
+ export declare function recentDate(rng: () => number, daysBack?: number): string;
60
+ /**
61
+ * Generate a UUID-like string from the RNG (not cryptographically secure).
62
+ * @param rng - The seeded random function
63
+ * @returns A UUID v4-like string
64
+ */
65
+ export declare function seededUUID(rng: () => number): string;
66
+ /**
67
+ * Generate a "future" ISO date string within the next N days of the fixed
68
+ * `FIXTURE_NOW` anchor (NOT the wall clock — see `FIXTURE_NOW`).
69
+ * @param rng - The seeded random function
70
+ * @param daysAhead - Maximum days in the future (default 365)
71
+ * @returns An ISO date string
72
+ */
73
+ export declare function futureDate(rng: () => number, daysAhead?: number): string;
74
+ //# sourceMappingURL=seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/fixtures/seed.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,MAAmC,CAAA;AAE3D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,MAAM,CAQ7D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CASlE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,CAE/D;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,CAGnE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,MAAM,GAAG,MAAM,CASpD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,MAAM,EAAE,SAAS,SAAM,GAAG,MAAM,CAGrE"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Deterministic seeded PRNG for stable fixture generation.
3
+ * Uses Mulberry32 algorithm for fast, reproducible random numbers.
4
+ */
5
+ /**
6
+ * Fixed "now" anchor (2026-04-01T12:00:00Z) for all generated dates.
7
+ *
8
+ * Dates are deliberately anchored to a constant instead of the wall clock so
9
+ * fixture output is byte-stable across runs (reliable screenshot diffs).
10
+ * Consequence: "recent"/"future" are relative to this anchor, not the real
11
+ * current time — never assert generated dates against `Date.now()`.
12
+ */
13
+ export const FIXTURE_NOW = new Date('2026-04-01T12:00:00Z');
14
+ /**
15
+ * Create a seeded random number generator using Mulberry32.
16
+ * Returns a function that produces numbers in [0, 1).
17
+ * @param seed - The seed value
18
+ * @returns A function that returns the next pseudo-random number
19
+ */
20
+ export function createSeededRandom(seed) {
21
+ let s = seed | 0;
22
+ return function mulberry32() {
23
+ s = (s + 0x6d2b79f5) | 0;
24
+ let t = Math.imul(s ^ (s >>> 15), 1 | s);
25
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
26
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
27
+ };
28
+ }
29
+ /**
30
+ * Derive a deterministic seed from an app type and endpoint path.
31
+ * The same app+path always produces the same seed, ensuring stable fixture output.
32
+ * @param appType - The application type (e.g. 'personal-finance')
33
+ * @param path - The endpoint path (e.g. '/accounts')
34
+ * @returns A numeric seed value
35
+ */
36
+ export function seedFromPath(appType, path) {
37
+ const str = `${appType}:${path}`;
38
+ let hash = 0;
39
+ for (let i = 0; i < str.length; i++) {
40
+ const char = str.charCodeAt(i);
41
+ hash = ((hash << 5) - hash + char) | 0;
42
+ }
43
+ // Ensure positive
44
+ return hash >>> 0;
45
+ }
46
+ /**
47
+ * Pick a random element from an array using the RNG.
48
+ * @param rng - The seeded random function
49
+ * @param arr - The array to pick from
50
+ * @returns A random element from the array
51
+ */
52
+ export function pick(rng, arr) {
53
+ return arr[Math.floor(rng() * arr.length)];
54
+ }
55
+ /**
56
+ * Pick a random integer in [min, max] inclusive.
57
+ * @param rng - The seeded random function
58
+ * @param min - Minimum value (inclusive)
59
+ * @param max - Maximum value (inclusive)
60
+ * @returns A random integer in the given range
61
+ */
62
+ export function randomInt(rng, min, max) {
63
+ return Math.floor(rng() * (max - min + 1)) + min;
64
+ }
65
+ /**
66
+ * Generate a random dollar amount rounded to cents.
67
+ * @param rng - The seeded random function
68
+ * @param min - Minimum value
69
+ * @param max - Maximum value
70
+ * @returns A number rounded to 2 decimal places
71
+ */
72
+ export function randomDollars(rng, min, max) {
73
+ return Math.round((rng() * (max - min) + min) * 100) / 100;
74
+ }
75
+ /**
76
+ * Generate a "recent" ISO date string within the last N days of the fixed
77
+ * `FIXTURE_NOW` anchor (NOT the wall clock — see `FIXTURE_NOW`).
78
+ * @param rng - The seeded random function
79
+ * @param daysBack - Maximum days in the past (default 90)
80
+ * @returns An ISO date string
81
+ */
82
+ export function recentDate(rng, daysBack = 90) {
83
+ const offset = Math.floor(rng() * daysBack) * 24 * 60 * 60 * 1000;
84
+ return new Date(FIXTURE_NOW.getTime() - offset).toISOString();
85
+ }
86
+ /**
87
+ * Generate a UUID-like string from the RNG (not cryptographically secure).
88
+ * @param rng - The seeded random function
89
+ * @returns A UUID v4-like string
90
+ */
91
+ export function seededUUID(rng) {
92
+ const hex = (n) => {
93
+ let result = '';
94
+ for (let i = 0; i < n; i++) {
95
+ result += Math.floor(rng() * 16).toString(16);
96
+ }
97
+ return result;
98
+ };
99
+ return `${hex(8)}-${hex(4)}-4${hex(3)}-${hex(1)}${hex(3)}-${hex(12)}`;
100
+ }
101
+ /**
102
+ * Generate a "future" ISO date string within the next N days of the fixed
103
+ * `FIXTURE_NOW` anchor (NOT the wall clock — see `FIXTURE_NOW`).
104
+ * @param rng - The seeded random function
105
+ * @param daysAhead - Maximum days in the future (default 365)
106
+ * @returns An ISO date string
107
+ */
108
+ export function futureDate(rng, daysAhead = 365) {
109
+ const offset = Math.floor(rng() * daysAhead) * 24 * 60 * 60 * 1000;
110
+ return new Date(FIXTURE_NOW.getTime() + offset).toISOString();
111
+ }
112
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.js","sourceRoot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AI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC/C,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IACD,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,EAAE,CAAA;AACvE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAiB,EAAE,SAAS,GAAG,GAAG;IAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAClE,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,WAAW,EAAE,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Field-name heuristic matching for generating realistic fixture values.
3
+ * Uses pattern matching on field names to select appropriate data generators.
4
+ */
5
+ import type { SemanticRule } from '../types.js';
6
+ /**
7
+ * Default semantic rules that match field names to realistic generators.
8
+ * Rules are checked in order; the first match wins.
9
+ */
10
+ export declare const defaultSemanticRules: SemanticRule[];
11
+ /**
12
+ * Apply semantic rules to generate a value for a given field name.
13
+ * @param fieldName - The name of the field to generate a value for
14
+ * @param rng - The seeded random function
15
+ * @param index - The item index (for cycling through pools)
16
+ * @param rules - Custom rules to apply (defaults to defaultSemanticRules)
17
+ * @returns The generated value, or undefined if no rule matched
18
+ */
19
+ export declare function applySemanticRules(fieldName: string, rng: () => number, index: number, rules?: SemanticRule[]): unknown | undefined;
20
+ //# sourceMappingURL=semantic-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-generator.d.ts","sourceRoot":"","sources":["../../src/fixtures/semantic-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAuR/C;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,YAAY,EAiQ9C,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,YAAY,EAAyB,GAC3C,OAAO,GAAG,SAAS,CAOrB"}