@concavejs/runtime-cf-base 0.0.1-alpha.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.

Potentially problematic release.


This version of @concavejs/runtime-cf-base might be problematic. Click here for more details.

Files changed (45) hide show
  1. package/dist/adapters/cf-websocket-adapter.d.ts +38 -0
  2. package/dist/adapters/cf-websocket-adapter.js +83 -0
  3. package/dist/durable-objects/concave-do-base.d.ts +158 -0
  4. package/dist/durable-objects/concave-do-base.js +412 -0
  5. package/dist/http/dx-http.d.ts +28 -0
  6. package/dist/http/dx-http.js +306 -0
  7. package/dist/http/http-api.d.ts +1 -0
  8. package/dist/http/http-api.js +262 -0
  9. package/dist/http/index.d.ts +7 -0
  10. package/dist/http/index.js +7 -0
  11. package/dist/index.d.ts +15 -0
  12. package/dist/index.js +25 -0
  13. package/dist/internal.d.ts +4 -0
  14. package/dist/internal.js +4 -0
  15. package/dist/routing/instance.d.ts +25 -0
  16. package/dist/routing/instance.js +101 -0
  17. package/dist/rpc/blobstore-proxy.d.ts +11 -0
  18. package/dist/rpc/blobstore-proxy.js +28 -0
  19. package/dist/rpc/docstore-proxy.d.ts +11 -0
  20. package/dist/rpc/docstore-proxy.js +72 -0
  21. package/dist/rpc/index.d.ts +2 -0
  22. package/dist/rpc/index.js +2 -0
  23. package/dist/sync/cf-websocket-adapter.d.ts +15 -0
  24. package/dist/sync/cf-websocket-adapter.js +22 -0
  25. package/dist/sync/concave-do-udf-executor.d.ts +37 -0
  26. package/dist/sync/concave-do-udf-executor.js +67 -0
  27. package/dist/sync/index.d.ts +2 -0
  28. package/dist/sync/index.js +2 -0
  29. package/dist/udf/executor/do-client-executor.d.ts +14 -0
  30. package/dist/udf/executor/do-client-executor.js +42 -0
  31. package/dist/udf/executor/index.d.ts +9 -0
  32. package/dist/udf/executor/index.js +9 -0
  33. package/dist/udf/executor/inline-executor.d.ts +13 -0
  34. package/dist/udf/executor/inline-executor.js +25 -0
  35. package/dist/udf/executor/isolated-executor.d.ts +24 -0
  36. package/dist/udf/executor/isolated-executor.js +31 -0
  37. package/dist/udf/executor/shim-content.d.ts +1 -0
  38. package/dist/udf/executor/shim-content.js +3 -0
  39. package/dist/worker/create-concave-worker.d.ts +34 -0
  40. package/dist/worker/create-concave-worker.js +162 -0
  41. package/dist/worker/index.d.ts +6 -0
  42. package/dist/worker/index.js +6 -0
  43. package/dist/worker/udf-worker.d.ts +14 -0
  44. package/dist/worker/udf-worker.js +63 -0
  45. package/package.json +45 -0
@@ -0,0 +1,63 @@
1
+ import { WorkerEntrypoint } from "cloudflare:workers";
2
+ import { D1DocStore } from "@concavejs/docstore-cf-d1";
3
+ import { R2BlobStore } from "@concavejs/blobstore-cf-r2";
4
+ import { getSearchIndexesFromSchema, getVectorIndexesFromSchema } from "@concavejs/core/docstore";
5
+ import { SchemaService } from "@concavejs/core";
6
+ import { UdfExecInline } from "../udf/executor/inline-executor";
7
+ import { createDocStoreProxy, createBlobStoreProxy } from "../rpc";
8
+ /**
9
+ * RPC entrypoint for executing UDFs in an isolated worker.
10
+ *
11
+ * Supports two modes:
12
+ * 1. Syscall mode (recommended): Routes through ConcaveDO for proper isolation
13
+ * 2. Direct mode (fallback): Direct D1/R2 access when no DO binding available
14
+ */
15
+ export class UdfExecutorRpc extends WorkerEntrypoint {
16
+ udfExecutor;
17
+ constructor(ctx, env) {
18
+ super(ctx, env);
19
+ let docstore;
20
+ let blobstore;
21
+ // Check if we have CONCAVE_DO binding for RPC-based execution
22
+ if (env.CONCAVE_DO) {
23
+ // Get instance from environment or default to "singleton"
24
+ const instance = env.CONCAVE_INSTANCE ?? "singleton";
25
+ // Create DO stub for RPC
26
+ const doId = env.CONCAVE_DO.idFromName(instance);
27
+ const doStub = env.CONCAVE_DO.get(doId);
28
+ console.log(`[UdfExecutorRpc] Using RPC mode via ConcaveDO (instance=${instance})`);
29
+ // Use RPC proxies that delegate to DO methods directly
30
+ docstore = createDocStoreProxy(doStub);
31
+ if (env.STORAGE_BUCKET) {
32
+ blobstore = createBlobStoreProxy(doStub);
33
+ }
34
+ }
35
+ else {
36
+ // Fallback to direct D1/R2 access (for local dev or legacy setups)
37
+ console.warn("[UdfExecutorRpc] No CONCAVE_DO binding - using direct D1/R2. " +
38
+ "Configure CONCAVE_DO binding for proper isolation.");
39
+ docstore = new D1DocStore(env.DB, env.VECTORIZE_INDEX);
40
+ if (env.STORAGE_BUCKET) {
41
+ blobstore = new R2BlobStore(env.STORAGE_BUCKET, env.R2_PUBLIC_URL);
42
+ }
43
+ // Only setup schema for direct mode (DO handles its own schema setup)
44
+ ctx.waitUntil((async () => {
45
+ const schemaService = new SchemaService();
46
+ const searchIndexes = await getSearchIndexesFromSchema(schemaService);
47
+ const vectorIndexes = await getVectorIndexesFromSchema(schemaService);
48
+ await docstore.setupSchema({ searchIndexes, vectorIndexes });
49
+ })());
50
+ }
51
+ // Pass blobstore if available, otherwise fall back to R2Bucket for direct mode
52
+ this.udfExecutor = new UdfExecInline(docstore, blobstore ?? env.STORAGE_BUCKET, env.R2_PUBLIC_URL);
53
+ }
54
+ async execute(path, args, type, auth, componentPath, requestId, _instance, _projectId) {
55
+ // Note: instance and projectId are passed for per-request context but
56
+ // currently we rely on the environment settings for syscall routing.
57
+ // This can be enhanced to create per-request syscall clients if needed.
58
+ return this.udfExecutor.execute(path, args, type, auth, componentPath, requestId);
59
+ }
60
+ async executeHttp(request, auth, requestId, _instance, _projectId) {
61
+ return this.udfExecutor.executeHttp(request, auth, requestId);
62
+ }
63
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@concavejs/runtime-cf-base",
3
+ "version": "0.0.1-alpha.4",
4
+ "license": "FSL-1.1-Apache-2.0",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./internal": "./dist/internal.js",
12
+ "./adapters/cf-websocket-adapter": "./dist/adapters/cf-websocket-adapter.js",
13
+ "./http": "./dist/http/index.js",
14
+ "./http/http-api": "./dist/http/http-api.js",
15
+ "./http/dx-http": "./dist/http/dx-http.js",
16
+ "./rpc": "./dist/rpc/index.js",
17
+ "./udf/executor": "./dist/udf/executor/index.js",
18
+ "./udf/executor/inline-executor": "./dist/udf/executor/inline-executor.js",
19
+ "./udf/executor/isolated-executor": "./dist/udf/executor/isolated-executor.js",
20
+ "./udf/executor/do-client-executor": "./dist/udf/executor/do-client-executor.js",
21
+ "./udf/executor/shim-content": "./dist/udf/executor/shim-content.js",
22
+ "./worker": "./dist/worker/index.js",
23
+ "./worker/create-concave-worker": "./dist/worker/create-concave-worker.js",
24
+ "./worker/udf-worker": "./dist/worker/udf-worker.js",
25
+ "./sync": "./dist/sync/index.js"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "build": "rm -rf dist && tsc -p tsconfig.json --noCheck",
32
+ "test": "bun test --run --passWithNoTests || true"
33
+ },
34
+ "dependencies": {
35
+ "@concavejs/core": "0.0.1-alpha.4",
36
+ "@concavejs/runtime-base": "0.0.1-alpha.4",
37
+ "@concavejs/docstore-cf-do": "0.0.1-alpha.4",
38
+ "@concavejs/docstore-cf-d1": "0.0.1-alpha.4",
39
+ "@concavejs/blobstore-cf-r2": "0.0.1-alpha.4",
40
+ "convex": "^1.27.3"
41
+ },
42
+ "devDependencies": {
43
+ "@cloudflare/workers-types": "^4.20251001.0"
44
+ }
45
+ }