ai-evaluate 2.1.8 → 2.3.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 (74) hide show
  1. package/README.md +16 -0
  2. package/dist/evaluate.d.ts.map +1 -1
  3. package/dist/evaluate.js +10 -10
  4. package/dist/evaluate.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/miniflare-pool.d.ts.map +1 -1
  8. package/dist/miniflare-pool.js +1 -1
  9. package/dist/miniflare-pool.js.map +1 -1
  10. package/dist/node.d.ts.map +1 -1
  11. package/dist/node.js.map +1 -1
  12. package/dist/repl.js +6 -6
  13. package/dist/repl.js.map +1 -1
  14. package/dist/shared.d.ts.map +1 -1
  15. package/dist/shared.js +5 -2
  16. package/dist/shared.js.map +1 -1
  17. package/dist/static/index.d.ts +111 -0
  18. package/dist/static/index.d.ts.map +1 -0
  19. package/dist/static/index.js +347 -0
  20. package/dist/static/index.js.map +1 -0
  21. package/dist/type-guards.d.ts.map +1 -1
  22. package/dist/type-guards.js +64 -62
  23. package/dist/type-guards.js.map +1 -1
  24. package/dist/worker-template/core.d.ts.map +1 -1
  25. package/dist/worker-template/core.js +1 -1
  26. package/dist/worker-template/core.js.map +1 -1
  27. package/package.json +19 -6
  28. package/public/capnweb.mjs +220 -0
  29. package/public/index.mjs +426 -0
  30. package/public/scaffold.mjs +198 -0
  31. package/.turbo/turbo-build.log +0 -4
  32. package/.turbo/turbo-test.log +0 -54
  33. package/.turbo/turbo-typecheck.log +0 -4
  34. package/CHANGELOG.md +0 -48
  35. package/dist/worker-template.d.ts +0 -41
  36. package/dist/worker-template.d.ts.map +0 -1
  37. package/dist/worker-template.js +0 -3748
  38. package/dist/worker-template.js.map +0 -1
  39. package/example/package.json +0 -20
  40. package/example/src/index.ts +0 -221
  41. package/example/wrangler.jsonc +0 -25
  42. package/src/capnweb-bundle.ts +0 -2596
  43. package/src/evaluate.ts +0 -329
  44. package/src/index.ts +0 -23
  45. package/src/miniflare-pool.ts +0 -395
  46. package/src/node.ts +0 -245
  47. package/src/repl.ts +0 -228
  48. package/src/shared.ts +0 -186
  49. package/src/type-guards.ts +0 -323
  50. package/src/types.ts +0 -196
  51. package/src/validation.ts +0 -120
  52. package/src/worker-template/code-transforms.ts +0 -32
  53. package/src/worker-template/core.ts +0 -557
  54. package/src/worker-template/helpers.ts +0 -90
  55. package/src/worker-template/index.ts +0 -23
  56. package/src/worker-template/sdk-generator.ts +0 -2515
  57. package/src/worker-template/test-generator.ts +0 -358
  58. package/test/evaluate-extended.test.js +0 -429
  59. package/test/evaluate-extended.test.ts +0 -469
  60. package/test/evaluate.test.js +0 -235
  61. package/test/evaluate.test.ts +0 -253
  62. package/test/index.test.js +0 -77
  63. package/test/index.test.ts +0 -95
  64. package/test/miniflare-pool.test.ts +0 -246
  65. package/test/node.test.ts +0 -467
  66. package/test/security.test.ts +0 -1009
  67. package/test/shared.test.ts +0 -105
  68. package/test/type-guards.test.ts +0 -303
  69. package/test/validation.test.ts +0 -240
  70. package/test/worker-template.test.js +0 -365
  71. package/test/worker-template.test.ts +0 -432
  72. package/tsconfig.json +0 -22
  73. package/vitest.config.js +0 -21
  74. package/vitest.config.ts +0 -28
@@ -1,358 +0,0 @@
1
- /**
2
- * Test framework embedding for worker templates
3
- *
4
- * Generates the embedded test framework code used in dev mode
5
- * (vitest-compatible API without external dependencies)
6
- */
7
-
8
- /**
9
- * Generate the embedded test framework code
10
- * This creates a vitest-compatible testing API that runs in the sandbox
11
- */
12
- export function generateTestFrameworkCode(): string {
13
- return `
14
- // Test framework (vitest-compatible API)
15
- let currentDescribe = '';
16
- let beforeEachFns = [];
17
- let afterEachFns = [];
18
-
19
- const describe = (name, fn) => {
20
- const prev = currentDescribe;
21
- const prevBeforeEach = [...beforeEachFns];
22
- const prevAfterEach = [...afterEachFns];
23
- currentDescribe = currentDescribe ? currentDescribe + ' > ' + name : name;
24
- try { fn(); } finally {
25
- currentDescribe = prev;
26
- beforeEachFns = prevBeforeEach;
27
- afterEachFns = prevAfterEach;
28
- }
29
- };
30
-
31
- // Hooks
32
- const beforeEach = (fn) => { beforeEachFns.push(fn); };
33
- const afterEach = (fn) => { afterEachFns.push(fn); };
34
-
35
- const it = (name, fn) => {
36
- const fullName = currentDescribe ? currentDescribe + ' > ' + name : name;
37
- const hooks = { before: [...beforeEachFns], after: [...afterEachFns] };
38
- pendingTests.push({ name: fullName, fn, hooks });
39
- };
40
- const test = it;
41
-
42
- it.skip = (name, fn) => {
43
- const fullName = currentDescribe ? currentDescribe + ' > ' + name : name;
44
- pendingTests.push({ name: fullName, fn: null, skip: true });
45
- };
46
- test.skip = it.skip;
47
-
48
- it.only = (name, fn) => {
49
- const fullName = currentDescribe ? currentDescribe + ' > ' + name : name;
50
- const hooks = { before: [...beforeEachFns], after: [...afterEachFns] };
51
- pendingTests.push({ name: fullName, fn, hooks, only: true });
52
- };
53
- test.only = it.only;
54
-
55
- // Deep equality check
56
- const deepEqual = (a, b) => {
57
- if (a === b) return true;
58
- if (a == null || b == null) return false;
59
- if (typeof a !== typeof b) return false;
60
- if (typeof a !== 'object') return false;
61
- if (Array.isArray(a) !== Array.isArray(b)) return false;
62
- if (Array.isArray(a)) {
63
- if (a.length !== b.length) return false;
64
- return a.every((v, i) => deepEqual(v, b[i]));
65
- }
66
- const keysA = Object.keys(a);
67
- const keysB = Object.keys(b);
68
- if (keysA.length !== keysB.length) return false;
69
- return keysA.every(k => deepEqual(a[k], b[k]));
70
- };
71
-
72
- // Expect implementation with vitest-compatible matchers
73
- const expect = (actual) => {
74
- const matchers = {
75
- toBe: (expected) => {
76
- if (actual !== expected) {
77
- throw new Error(\`Expected \${JSON.stringify(expected)} but got \${JSON.stringify(actual)}\`);
78
- }
79
- },
80
- toEqual: (expected) => {
81
- if (!deepEqual(actual, expected)) {
82
- throw new Error(\`Expected \${JSON.stringify(expected)} but got \${JSON.stringify(actual)}\`);
83
- }
84
- },
85
- toStrictEqual: (expected) => {
86
- if (!deepEqual(actual, expected)) {
87
- throw new Error(\`Expected \${JSON.stringify(expected)} but got \${JSON.stringify(actual)}\`);
88
- }
89
- },
90
- toBeTruthy: () => {
91
- if (!actual) throw new Error(\`Expected truthy but got \${JSON.stringify(actual)}\`);
92
- },
93
- toBeFalsy: () => {
94
- if (actual) throw new Error(\`Expected falsy but got \${JSON.stringify(actual)}\`);
95
- },
96
- toBeNull: () => {
97
- if (actual !== null) throw new Error(\`Expected null but got \${JSON.stringify(actual)}\`);
98
- },
99
- toBeUndefined: () => {
100
- if (actual !== undefined) throw new Error(\`Expected undefined but got \${JSON.stringify(actual)}\`);
101
- },
102
- toBeDefined: () => {
103
- if (actual === undefined) throw new Error('Expected defined but got undefined');
104
- },
105
- toBeNaN: () => {
106
- if (!Number.isNaN(actual)) throw new Error(\`Expected NaN but got \${actual}\`);
107
- },
108
- toContain: (item) => {
109
- if (Array.isArray(actual)) {
110
- if (!actual.includes(item)) throw new Error(\`Expected array to contain \${JSON.stringify(item)}\`);
111
- } else if (typeof actual === 'string') {
112
- if (!actual.includes(item)) throw new Error(\`Expected string to contain "\${item}"\`);
113
- } else {
114
- throw new Error('toContain only works on arrays and strings');
115
- }
116
- },
117
- toContainEqual: (item) => {
118
- if (!Array.isArray(actual)) throw new Error('toContainEqual only works on arrays');
119
- if (!actual.some(v => deepEqual(v, item))) {
120
- throw new Error(\`Expected array to contain \${JSON.stringify(item)}\`);
121
- }
122
- },
123
- toHaveLength: (length) => {
124
- if (actual?.length !== length) {
125
- throw new Error(\`Expected length \${length} but got \${actual?.length}\`);
126
- }
127
- },
128
- toHaveProperty: function(path, value) {
129
- const parts = typeof path === 'string' ? path.split('.') : [path];
130
- let obj = actual;
131
- for (const part of parts) {
132
- if (obj == null || !(part in obj)) {
133
- throw new Error(\`Expected object to have property "\${path}"\`);
134
- }
135
- obj = obj[part];
136
- }
137
- if (arguments.length > 1 && !deepEqual(obj, value)) {
138
- throw new Error(\`Expected property "\${path}" to be \${JSON.stringify(value)} but got \${JSON.stringify(obj)}\`);
139
- }
140
- },
141
- toMatchObject: (expected) => {
142
- if (typeof actual !== 'object' || actual === null) {
143
- throw new Error('toMatchObject expects an object');
144
- }
145
- for (const key of Object.keys(expected)) {
146
- if (!deepEqual(actual[key], expected[key])) {
147
- throw new Error(\`Expected property "\${key}" to be \${JSON.stringify(expected[key])} but got \${JSON.stringify(actual[key])}\`);
148
- }
149
- }
150
- },
151
- toThrow: (expected) => {
152
- if (typeof actual !== 'function') throw new Error('toThrow expects a function');
153
- let threw = false;
154
- let error;
155
- try {
156
- actual();
157
- } catch (e) {
158
- threw = true;
159
- error = e;
160
- }
161
- if (!threw) throw new Error('Expected function to throw');
162
- if (expected !== undefined) {
163
- if (typeof expected === 'string' && !error.message.includes(expected)) {
164
- throw new Error(\`Expected error message to contain "\${expected}" but got "\${error.message}"\`);
165
- }
166
- if (expected instanceof RegExp && !expected.test(error.message)) {
167
- throw new Error(\`Expected error message to match \${expected} but got "\${error.message}"\`);
168
- }
169
- if (typeof expected === 'function' && !(error instanceof expected)) {
170
- throw new Error(\`Expected error to be instance of \${expected.name}\`);
171
- }
172
- }
173
- },
174
- toBeGreaterThan: (n) => {
175
- if (!(actual > n)) throw new Error(\`Expected \${actual} to be greater than \${n}\`);
176
- },
177
- toBeLessThan: (n) => {
178
- if (!(actual < n)) throw new Error(\`Expected \${actual} to be less than \${n}\`);
179
- },
180
- toBeGreaterThanOrEqual: (n) => {
181
- if (!(actual >= n)) throw new Error(\`Expected \${actual} to be >= \${n}\`);
182
- },
183
- toBeLessThanOrEqual: (n) => {
184
- if (!(actual <= n)) throw new Error(\`Expected \${actual} to be <= \${n}\`);
185
- },
186
- toBeCloseTo: (n, digits = 2) => {
187
- const diff = Math.abs(actual - n);
188
- const threshold = Math.pow(10, -digits) / 2;
189
- if (diff > threshold) {
190
- throw new Error(\`Expected \${actual} to be close to \${n}\`);
191
- }
192
- },
193
- toMatch: (pattern) => {
194
- if (typeof actual !== 'string') throw new Error('toMatch expects a string');
195
- const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
196
- if (!regex.test(actual)) {
197
- throw new Error(\`Expected "\${actual}" to match \${pattern}\`);
198
- }
199
- },
200
- toBeInstanceOf: (cls) => {
201
- if (!(actual instanceof cls)) {
202
- throw new Error(\`Expected instance of \${cls.name}\`);
203
- }
204
- },
205
- toBeTypeOf: (type) => {
206
- if (typeof actual !== type) {
207
- throw new Error(\`Expected typeof to be "\${type}" but got "\${typeof actual}"\`);
208
- }
209
- },
210
- };
211
-
212
- matchers.not = {
213
- toBe: (expected) => {
214
- if (actual === expected) throw new Error(\`Expected not \${JSON.stringify(expected)}\`);
215
- },
216
- toEqual: (expected) => {
217
- if (deepEqual(actual, expected)) {
218
- throw new Error(\`Expected not equal to \${JSON.stringify(expected)}\`);
219
- }
220
- },
221
- toBeTruthy: () => {
222
- if (actual) throw new Error('Expected not truthy');
223
- },
224
- toBeFalsy: () => {
225
- if (!actual) throw new Error('Expected not falsy');
226
- },
227
- toBeNull: () => {
228
- if (actual === null) throw new Error('Expected not null');
229
- },
230
- toBeUndefined: () => {
231
- if (actual === undefined) throw new Error('Expected not undefined');
232
- },
233
- toBeDefined: () => {
234
- if (actual !== undefined) throw new Error('Expected undefined');
235
- },
236
- toContain: (item) => {
237
- if (Array.isArray(actual) && actual.includes(item)) {
238
- throw new Error(\`Expected array not to contain \${JSON.stringify(item)}\`);
239
- }
240
- if (typeof actual === 'string' && actual.includes(item)) {
241
- throw new Error(\`Expected string not to contain "\${item}"\`);
242
- }
243
- },
244
- toHaveProperty: (path) => {
245
- const parts = typeof path === 'string' ? path.split('.') : [path];
246
- let obj = actual;
247
- try {
248
- for (const part of parts) {
249
- if (obj == null || !(part in obj)) return;
250
- obj = obj[part];
251
- }
252
- throw new Error(\`Expected object not to have property "\${path}"\`);
253
- } catch {}
254
- },
255
- toThrow: () => {
256
- if (typeof actual !== 'function') throw new Error('toThrow expects a function');
257
- try {
258
- actual();
259
- } catch (e) {
260
- throw new Error('Expected function not to throw');
261
- }
262
- },
263
- toMatch: (pattern) => {
264
- if (typeof actual !== 'string') throw new Error('toMatch expects a string');
265
- const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
266
- if (regex.test(actual)) {
267
- throw new Error(\`Expected "\${actual}" not to match \${pattern}\`);
268
- }
269
- },
270
- };
271
-
272
- matchers.resolves = new Proxy({}, {
273
- get: (_, prop) => async (...args) => {
274
- const resolved = await actual;
275
- return expect(resolved)[prop](...args);
276
- }
277
- });
278
-
279
- matchers.rejects = new Proxy({}, {
280
- get: (_, prop) => async (...args) => {
281
- try {
282
- await actual;
283
- throw new Error('Expected promise to reject');
284
- } catch (e) {
285
- if (e.message === 'Expected promise to reject') throw e;
286
- return expect(e)[prop](...args);
287
- }
288
- }
289
- });
290
-
291
- return matchers;
292
- };
293
- `
294
- }
295
-
296
- /**
297
- * Generate the test runner code that executes pending tests
298
- */
299
- export function generateTestRunnerCode(): string {
300
- return `
301
- // Run all pending tests
302
- const testStart = Date.now();
303
- const hasOnly = pendingTests.some(t => t.only);
304
- const testsToRun = hasOnly ? pendingTests.filter(t => t.only || t.skip) : pendingTests;
305
-
306
- for (const { name, fn, hooks, skip } of testsToRun) {
307
- testResults.total++;
308
-
309
- if (skip) {
310
- testResults.skipped++;
311
- testResults.tests.push({ name, passed: true, skipped: true, duration: 0 });
312
- continue;
313
- }
314
-
315
- const start = Date.now();
316
- try {
317
- // Run beforeEach hooks
318
- if (hooks?.before) {
319
- for (const hook of hooks.before) {
320
- const hookResult = hook();
321
- if (hookResult && typeof hookResult.then === 'function') {
322
- await hookResult;
323
- }
324
- }
325
- }
326
-
327
- // Run the test
328
- const result = fn();
329
- if (result && typeof result.then === 'function') {
330
- await result;
331
- }
332
-
333
- // Run afterEach hooks
334
- if (hooks?.after) {
335
- for (const hook of hooks.after) {
336
- const hookResult = hook();
337
- if (hookResult && typeof hookResult.then === 'function') {
338
- await hookResult;
339
- }
340
- }
341
- }
342
-
343
- testResults.passed++;
344
- testResults.tests.push({ name, passed: true, duration: Date.now() - start });
345
- } catch (e) {
346
- testResults.failed++;
347
- testResults.tests.push({
348
- name,
349
- passed: false,
350
- error: e.message || String(e),
351
- duration: Date.now() - start
352
- });
353
- }
354
- }
355
-
356
- testResults.duration = Date.now() - testStart;
357
- `
358
- }