@positronic/cloudflare 0.0.3 → 0.0.4
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/dist/src/api.js +1270 -0
- package/dist/src/brain-runner-do.js +654 -0
- package/dist/src/dev-server.js +1357 -0
- package/{src/index.ts → dist/src/index.js} +1 -6
- package/dist/src/manifest.js +278 -0
- package/dist/src/monitor-do.js +408 -0
- package/{src/node-index.ts → dist/src/node-index.js} +3 -7
- package/dist/src/r2-loader.js +207 -0
- package/dist/src/schedule-do.js +705 -0
- package/dist/src/sqlite-adapter.js +69 -0
- package/dist/types/api.d.ts +21 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/brain-runner-do.d.ts +25 -0
- package/dist/types/brain-runner-do.d.ts.map +1 -0
- package/dist/types/dev-server.d.ts +45 -0
- package/dist/types/dev-server.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/manifest.d.ts +11 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/monitor-do.d.ts +16 -0
- package/dist/types/monitor-do.d.ts.map +1 -0
- package/dist/types/node-index.d.ts +10 -0
- package/dist/types/node-index.d.ts.map +1 -0
- package/dist/types/r2-loader.d.ts +10 -0
- package/dist/types/r2-loader.d.ts.map +1 -0
- package/dist/types/schedule-do.d.ts +47 -0
- package/dist/types/schedule-do.d.ts.map +1 -0
- package/dist/types/sqlite-adapter.d.ts +10 -0
- package/dist/types/sqlite-adapter.d.ts.map +1 -0
- package/package.json +5 -1
- package/src/api.ts +0 -579
- package/src/brain-runner-do.ts +0 -309
- package/src/dev-server.ts +0 -776
- package/src/manifest.ts +0 -69
- package/src/monitor-do.ts +0 -268
- package/src/r2-loader.ts +0 -27
- package/src/schedule-do.ts +0 -377
- package/src/sqlite-adapter.ts +0 -50
- package/test-project/package-lock.json +0 -3010
- package/test-project/package.json +0 -21
- package/test-project/src/index.ts +0 -70
- package/test-project/src/runner.ts +0 -24
- package/test-project/tests/api.test.ts +0 -1005
- package/test-project/tests/r2loader.test.ts +0 -73
- package/test-project/tests/resources-api.test.ts +0 -671
- package/test-project/tests/spec.test.ts +0 -135
- package/test-project/tests/tsconfig.json +0 -7
- package/test-project/tsconfig.json +0 -20
- package/test-project/vitest.config.ts +0 -12
- package/test-project/wrangler.jsonc +0 -53
- package/tsconfig.json +0 -11
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { env } from 'cloudflare:test';
|
|
2
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
3
|
-
import { CloudflareR2Loader } from '../../src/r2-loader.js';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
|
-
import type { BrainRunnerDO } from '../../src/brain-runner-do.js';
|
|
6
|
-
import type { MonitorDO } from '../../src/monitor-do.js';
|
|
7
|
-
|
|
8
|
-
interface TestEnv {
|
|
9
|
-
BRAIN_RUNNER_DO: DurableObjectNamespace<BrainRunnerDO>;
|
|
10
|
-
MONITOR_DO: DurableObjectNamespace<MonitorDO>;
|
|
11
|
-
DB: D1Database;
|
|
12
|
-
TEST_RESOURCES_BUCKET: R2Bucket;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('CloudflareR2Loader Tests', () => {
|
|
16
|
-
const testEnv = env as TestEnv;
|
|
17
|
-
let r2Loader: CloudflareR2Loader;
|
|
18
|
-
const textFileName = 'test.txt';
|
|
19
|
-
const textFileContent = 'Hello R2!';
|
|
20
|
-
const binaryFileName = 'test.bin';
|
|
21
|
-
const binaryFileContent = Buffer.from([0x01, 0x02, 0x03, 0x04]);
|
|
22
|
-
const nonExistentFileName = 'not-found.txt';
|
|
23
|
-
|
|
24
|
-
beforeAll(async () => {
|
|
25
|
-
if (!testEnv.TEST_RESOURCES_BUCKET) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
'TEST_RESOURCES_BUCKET binding not found in test environment. Ensure wrangler.jsonc is configured and wrangler types generated.'
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
r2Loader = new CloudflareR2Loader(testEnv.TEST_RESOURCES_BUCKET);
|
|
31
|
-
|
|
32
|
-
// Populate R2 bucket with test files
|
|
33
|
-
await testEnv.TEST_RESOURCES_BUCKET.put(textFileName, textFileContent);
|
|
34
|
-
await testEnv.TEST_RESOURCES_BUCKET.put(
|
|
35
|
-
binaryFileName,
|
|
36
|
-
binaryFileContent.buffer // R2 put expects ArrayBuffer for binary
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// Clean up any pre-existing non-existent file to ensure test is valid
|
|
40
|
-
await testEnv.TEST_RESOURCES_BUCKET.delete(nonExistentFileName);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should load a text file from R2', async () => {
|
|
44
|
-
const content = await r2Loader.load(textFileName, 'text');
|
|
45
|
-
expect(content).toBe(textFileContent);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should load a binary file from R2 and return as Buffer', async () => {
|
|
49
|
-
const content = await r2Loader.load(binaryFileName, 'binary');
|
|
50
|
-
expect(content).toBeInstanceOf(Buffer);
|
|
51
|
-
expect(Buffer.compare(content, binaryFileContent)).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should throw an error if the resource is not found', async () => {
|
|
55
|
-
await expect(r2Loader.load(nonExistentFileName, 'text')).rejects.toThrow(
|
|
56
|
-
`Resource "${nonExistentFileName}" not found in R2 bucket.`
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should default to loading as text if type is not specified', async () => {
|
|
61
|
-
const content = (await r2Loader.load(textFileName, 'text')) as string;
|
|
62
|
-
expect(content).toBe(textFileContent);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should load a text file from a subdirectory in R2', async () => {
|
|
66
|
-
const subDirFileName = 'subdir/another.txt';
|
|
67
|
-
const subDirFileContent = 'Hello from subdirectory!';
|
|
68
|
-
await testEnv.TEST_RESOURCES_BUCKET.put(subDirFileName, subDirFileContent);
|
|
69
|
-
|
|
70
|
-
const content = await r2Loader.load(subDirFileName, 'text');
|
|
71
|
-
expect(content).toBe(subDirFileContent);
|
|
72
|
-
});
|
|
73
|
-
});
|