alchemy 0.8.0 → 0.9.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.
- package/lib/alchemy.d.ts +11 -18
- package/lib/alchemy.js +34 -39
- package/lib/apply.js +3 -1
- package/lib/cloudflare/api-error.js +1 -1
- package/lib/cloudflare/bindings.d.ts +2 -1
- package/lib/cloudflare/bound.d.ts +2 -1
- package/lib/cloudflare/index.d.ts +3 -0
- package/lib/cloudflare/index.js +3 -0
- package/lib/cloudflare/pipeline.js +0 -3
- package/lib/cloudflare/vectorize-index.d.ts +136 -0
- package/lib/cloudflare/vectorize-index.js +170 -0
- package/lib/cloudflare/vectorize-metadata-index.d.ts +95 -0
- package/lib/cloudflare/vectorize-metadata-index.js +120 -0
- package/lib/cloudflare/vite-site.d.ts +39 -0
- package/lib/cloudflare/vite-site.js +57 -0
- package/lib/cloudflare/worker.js +7 -0
- package/lib/cloudflare/wrangler.json.d.ts +7 -0
- package/lib/cloudflare/wrangler.json.js +11 -1
- package/lib/destroy.js +14 -2
- package/lib/fs/file-system-state-store.d.ts +1 -0
- package/lib/fs/file-system-state-store.js +23 -13
- package/lib/scope.d.ts +1 -1
- package/lib/scope.js +5 -2
- package/lib/state.d.ts +2 -2
- package/lib/test/bun.d.ts +1 -6
- package/lib/test/bun.js +18 -37
- package/package.json +1 -1
- package/src/alchemy.ts +51 -45
- package/src/apply.ts +6 -2
- package/src/cloudflare/api-error.ts +1 -1
- package/src/cloudflare/bindings.ts +2 -0
- package/src/cloudflare/bound.ts +8 -5
- package/src/cloudflare/index.ts +3 -0
- package/src/cloudflare/pipeline.ts +0 -4
- package/src/cloudflare/vectorize-index.ts +331 -0
- package/src/cloudflare/vectorize-metadata-index.ts +239 -0
- package/src/cloudflare/vite-site.ts +111 -0
- package/src/cloudflare/worker.ts +6 -0
- package/src/cloudflare/wrangler.json.ts +19 -1
- package/src/destroy.ts +25 -8
- package/src/fs/file-system-state-store.ts +23 -14
- package/src/scope.ts +9 -5
- package/src/state.ts +3 -3
- package/src/test/bun.ts +31 -54
package/src/test/bun.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { afterAll, beforeAll, it } from "bun:test";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { alchemy } from "../alchemy";
|
|
6
6
|
import { R2RestStateStore } from "../cloudflare";
|
|
7
|
-
import {
|
|
8
|
-
import type { Scope } from "../scope";
|
|
7
|
+
import { Scope } from "../scope";
|
|
9
8
|
import type { StateStoreType } from "../state";
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -26,12 +25,6 @@ alchemy.test = test;
|
|
|
26
25
|
* Options for configuring test behavior
|
|
27
26
|
*/
|
|
28
27
|
export interface TestOptions {
|
|
29
|
-
/**
|
|
30
|
-
* Whether to automatically destroy resources after test.
|
|
31
|
-
* @default true.
|
|
32
|
-
*/
|
|
33
|
-
destroy?: boolean;
|
|
34
|
-
|
|
35
28
|
/**
|
|
36
29
|
* Whether to suppress logging output.
|
|
37
30
|
* @default false.
|
|
@@ -121,7 +114,6 @@ type test = {
|
|
|
121
114
|
* ```
|
|
122
115
|
*/
|
|
123
116
|
export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
124
|
-
let isFailed = false;
|
|
125
117
|
defaultOptions = defaultOptions ?? {};
|
|
126
118
|
if (
|
|
127
119
|
defaultOptions.stateStore === undefined &&
|
|
@@ -146,37 +138,21 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
146
138
|
};
|
|
147
139
|
|
|
148
140
|
// Create local test scope based on filename
|
|
149
|
-
const
|
|
150
|
-
`${defaultOptions.prefix ? `${defaultOptions.prefix}-` : ""}${path.basename(meta.filename)}`,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
test.scope = localTestScope;
|
|
141
|
+
const scope = new Scope({
|
|
142
|
+
scopeName: `${defaultOptions.prefix ? `${defaultOptions.prefix}-` : ""}${path.basename(meta.filename)}`,
|
|
143
|
+
// parent: globalTestScope,
|
|
144
|
+
stateStore: defaultOptions?.stateStore,
|
|
145
|
+
});
|
|
157
146
|
|
|
158
147
|
test.beforeAll = (fn: (scope: Scope) => Promise<void>) => {
|
|
159
|
-
return beforeAll(
|
|
160
|
-
test.scope.enter();
|
|
161
|
-
await fn(test.scope);
|
|
162
|
-
});
|
|
148
|
+
return beforeAll(() => scope.run(() => fn(scope)));
|
|
163
149
|
};
|
|
164
150
|
|
|
165
151
|
test.afterAll = (fn: (scope: Scope) => Promise<void>) => {
|
|
166
|
-
return afterAll(
|
|
167
|
-
test.scope.enter();
|
|
168
|
-
await fn(test.scope);
|
|
169
|
-
});
|
|
152
|
+
return afterAll(() => scope.run(() => fn(scope)));
|
|
170
153
|
};
|
|
171
154
|
|
|
172
|
-
|
|
173
|
-
afterAll(async () => {
|
|
174
|
-
if (defaultOptions?.destroy !== false && !isFailed) {
|
|
175
|
-
await alchemy.destroy(test.scope);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
return test as any;
|
|
155
|
+
return test as test;
|
|
180
156
|
|
|
181
157
|
function test(
|
|
182
158
|
...args:
|
|
@@ -189,6 +165,10 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
189
165
|
) {
|
|
190
166
|
const testName = args[0];
|
|
191
167
|
const _options = typeof args[1] === "object" ? args[1] : undefined;
|
|
168
|
+
const timeout =
|
|
169
|
+
typeof args[args.length - 1] === "number"
|
|
170
|
+
? (args[args.length - 1] as number)
|
|
171
|
+
: 120000;
|
|
192
172
|
const spread = (obj: any) =>
|
|
193
173
|
obj && typeof obj === "object"
|
|
194
174
|
? Object.fromEntries(
|
|
@@ -199,8 +179,7 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
199
179
|
: {};
|
|
200
180
|
|
|
201
181
|
// Merge options with defaults
|
|
202
|
-
const options = {
|
|
203
|
-
destroy: true,
|
|
182
|
+
const options: TestOptions = {
|
|
204
183
|
quiet: false,
|
|
205
184
|
password: "test-password",
|
|
206
185
|
...spread(defaultOptions),
|
|
@@ -209,28 +188,26 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
209
188
|
|
|
210
189
|
const fn = typeof args[1] === "function" ? args[1] : args[2]!;
|
|
211
190
|
|
|
212
|
-
return
|
|
191
|
+
return it(
|
|
213
192
|
testName,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
scope
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (options.destroy !== false) {
|
|
229
|
-
await destroy(scope);
|
|
193
|
+
async () =>
|
|
194
|
+
alchemy.run(
|
|
195
|
+
testName,
|
|
196
|
+
{
|
|
197
|
+
...options,
|
|
198
|
+
parent: scope,
|
|
199
|
+
},
|
|
200
|
+
async (scope) => {
|
|
201
|
+
try {
|
|
202
|
+
// Enter test scope since bun calls from different scope
|
|
203
|
+
await scope.run(() => fn(scope));
|
|
204
|
+
} catch (err) {
|
|
205
|
+
console.error(err);
|
|
206
|
+
throw err;
|
|
230
207
|
}
|
|
231
208
|
}
|
|
232
|
-
|
|
233
|
-
|
|
209
|
+
),
|
|
210
|
+
timeout
|
|
234
211
|
);
|
|
235
212
|
}
|
|
236
213
|
}
|