@portel/photon 1.29.0 → 1.31.1
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/README.md +41 -11
- package/dist/asset-resolver.d.ts +44 -0
- package/dist/asset-resolver.d.ts.map +1 -0
- package/dist/asset-resolver.js +105 -0
- package/dist/asset-resolver.js.map +1 -0
- package/dist/auto-ui/beam/external-mcp-manager.d.ts +73 -0
- package/dist/auto-ui/beam/external-mcp-manager.d.ts.map +1 -0
- package/dist/auto-ui/beam/external-mcp-manager.js +65 -0
- package/dist/auto-ui/beam/external-mcp-manager.js.map +1 -0
- package/dist/auto-ui/beam/external-mcp.d.ts.map +1 -1
- package/dist/auto-ui/beam/external-mcp.js +25 -1
- package/dist/auto-ui/beam/external-mcp.js.map +1 -1
- package/dist/auto-ui/beam/photon-management.d.ts.map +1 -1
- package/dist/auto-ui/beam/photon-management.js +11 -8
- package/dist/auto-ui/beam/photon-management.js.map +1 -1
- package/dist/auto-ui/beam/routes/api-browse.d.ts.map +1 -1
- package/dist/auto-ui/beam/routes/api-browse.js +7 -4
- package/dist/auto-ui/beam/routes/api-browse.js.map +1 -1
- package/dist/auto-ui/beam/routes/api-config.d.ts.map +1 -1
- package/dist/auto-ui/beam/routes/api-config.js +3 -2
- package/dist/auto-ui/beam/routes/api-config.js.map +1 -1
- package/dist/auto-ui/beam/routes/api-marketplace.d.ts.map +1 -1
- package/dist/auto-ui/beam/routes/api-marketplace.js +6 -2
- package/dist/auto-ui/beam/routes/api-marketplace.js.map +1 -1
- package/dist/auto-ui/beam/startup.js.map +1 -1
- package/dist/auto-ui/beam/types.d.ts +5 -2
- package/dist/auto-ui/beam/types.d.ts.map +1 -1
- package/dist/auto-ui/beam.d.ts.map +1 -1
- package/dist/auto-ui/beam.js +162 -45
- package/dist/auto-ui/beam.js.map +1 -1
- package/dist/auto-ui/bridge/index.d.ts.map +1 -1
- package/dist/auto-ui/bridge/index.js +11 -0
- package/dist/auto-ui/bridge/index.js.map +1 -1
- package/dist/auto-ui/bridge/types.d.ts +2 -0
- package/dist/auto-ui/bridge/types.d.ts.map +1 -1
- package/dist/auto-ui/openapi-generator.js +1 -4
- package/dist/auto-ui/openapi-generator.js.map +1 -1
- package/dist/auto-ui/photon-bridge.d.ts +4 -0
- package/dist/auto-ui/photon-bridge.d.ts.map +1 -1
- package/dist/auto-ui/photon-bridge.js.map +1 -1
- package/dist/auto-ui/photon-host.js.map +1 -1
- package/dist/auto-ui/streamable-http-transport.d.ts.map +1 -1
- package/dist/auto-ui/streamable-http-transport.js +24 -14
- package/dist/auto-ui/streamable-http-transport.js.map +1 -1
- package/dist/auto-ui/types.d.ts +15 -1
- package/dist/auto-ui/types.d.ts.map +1 -1
- package/dist/auto-ui/types.js.map +1 -1
- package/dist/beam.bundle.js +170 -22
- package/dist/beam.bundle.js.map +3 -3
- package/dist/capability-negotiator.d.ts +39 -1
- package/dist/capability-negotiator.d.ts.map +1 -1
- package/dist/capability-negotiator.js +5 -0
- package/dist/capability-negotiator.js.map +1 -1
- package/dist/cf-bindings-parser.d.ts +15 -0
- package/dist/cf-bindings-parser.d.ts.map +1 -0
- package/dist/cf-bindings-parser.js +98 -0
- package/dist/cf-bindings-parser.js.map +1 -0
- package/dist/cf-usage-scanner.d.ts +76 -0
- package/dist/cf-usage-scanner.d.ts.map +1 -0
- package/dist/cf-usage-scanner.js +179 -0
- package/dist/cf-usage-scanner.js.map +1 -0
- package/dist/cli/commands/build.js +1 -1
- package/dist/cli/commands/cf.d.ts +18 -0
- package/dist/cli/commands/cf.d.ts.map +1 -0
- package/dist/cli/commands/cf.js +207 -0
- package/dist/cli/commands/cf.js.map +1 -0
- package/dist/cli/commands/info.js +1 -1
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +59 -46
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +3 -0
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +43 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/daemon/client.d.ts.map +1 -1
- package/dist/daemon/client.js +40 -33
- package/dist/daemon/client.js.map +1 -1
- package/dist/daemon/manager.d.ts +6 -2
- package/dist/daemon/manager.d.ts.map +1 -1
- package/dist/daemon/manager.js +30 -9
- package/dist/daemon/manager.js.map +1 -1
- package/dist/daemon/server.js +34 -13
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/worker-host.js.map +1 -1
- package/dist/deploy/cloudflare.d.ts +27 -0
- package/dist/deploy/cloudflare.d.ts.map +1 -1
- package/dist/deploy/cloudflare.js +129 -2
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/embedded-runtime.js.map +1 -1
- package/dist/loader.d.ts +43 -66
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +185 -305
- package/dist/loader.js.map +1 -1
- package/dist/photon-cli-runner.d.ts.map +1 -1
- package/dist/photon-cli-runner.js +20 -11
- package/dist/photon-cli-runner.js.map +1 -1
- package/dist/resource-server.d.ts +3 -3
- package/dist/resource-server.d.ts.map +1 -1
- package/dist/resource-server.js.map +1 -1
- package/dist/runtime/cf-local.d.ts +157 -0
- package/dist/runtime/cf-local.d.ts.map +1 -0
- package/dist/runtime/cf-local.js +406 -0
- package/dist/runtime/cf-local.js.map +1 -0
- package/dist/server.d.ts +42 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +166 -14
- package/dist/server.js.map +1 -1
- package/dist/settings-persistence.d.ts +50 -0
- package/dist/settings-persistence.d.ts.map +1 -0
- package/dist/settings-persistence.js +188 -0
- package/dist/settings-persistence.js.map +1 -0
- package/dist/shared/audit-sqlite.d.ts.map +1 -1
- package/dist/shared/audit-sqlite.js +0 -1
- package/dist/shared/audit-sqlite.js.map +1 -1
- package/dist/shared/error-handler.d.ts.map +1 -1
- package/dist/shared/error-handler.js +3 -1
- package/dist/shared/error-handler.js.map +1 -1
- package/dist/shared/io.d.ts.map +1 -1
- package/dist/shared/io.js +5 -2
- package/dist/shared/io.js.map +1 -1
- package/dist/shared/logger.js.map +1 -1
- package/dist/shared/sqlite-runtime.d.ts.map +1 -1
- package/dist/shared/sqlite-runtime.js +0 -1
- package/dist/shared/sqlite-runtime.js.map +1 -1
- package/dist/task-executor.js.map +1 -1
- package/dist/telemetry/sdk.d.ts.map +1 -1
- package/dist/telemetry/sdk.js +0 -1
- package/dist/telemetry/sdk.js.map +1 -1
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js.map +1 -1
- package/dist/types/server-types.d.ts +16 -8
- package/dist/types/server-types.d.ts.map +1 -1
- package/package.json +11 -4
- package/templates/cloudflare/worker.ts.template +338 -11
- package/templates/cloudflare/wrangler.toml.template +1 -6
- package/templates/photon.template.ts +13 -0
|
@@ -22,7 +22,45 @@ export declare class CapabilityNegotiator {
|
|
|
22
22
|
*
|
|
23
23
|
* Key: Server instance → Value: raw capabilities object from initialize request
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Public so PhotonServer can expose a back-compat alias for tests that
|
|
27
|
+
* seed raw capabilities directly. Prefer `setRawCapabilities()` in
|
|
28
|
+
* non-test code paths.
|
|
29
|
+
*/
|
|
30
|
+
rawClientCapabilities: WeakMap<Server<{
|
|
31
|
+
method: string;
|
|
32
|
+
params?: {
|
|
33
|
+
[x: string]: unknown;
|
|
34
|
+
_meta?: {
|
|
35
|
+
[x: string]: unknown;
|
|
36
|
+
progressToken?: string | number | undefined;
|
|
37
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
38
|
+
taskId: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
method: string;
|
|
44
|
+
params?: {
|
|
45
|
+
[x: string]: unknown;
|
|
46
|
+
_meta?: {
|
|
47
|
+
[x: string]: unknown;
|
|
48
|
+
progressToken?: string | number | undefined;
|
|
49
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
50
|
+
taskId: string;
|
|
51
|
+
} | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
[x: string]: unknown;
|
|
56
|
+
_meta?: {
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
progressToken?: string | number | undefined;
|
|
59
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
60
|
+
taskId: string;
|
|
61
|
+
} | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
}>, Record<string, any>>;
|
|
26
64
|
/**
|
|
27
65
|
* Store raw capabilities for a server instance.
|
|
28
66
|
* Called from the transport message interceptor.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-negotiator.d.ts","sourceRoot":"","sources":["../src/capability-negotiator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAIxE,qBAAa,oBAAoB;IAC/B;;;;;;;;;;;OAWG;IACH,
|
|
1
|
+
{"version":3,"file":"capability-negotiator.d.ts","sourceRoot":"","sources":["../src/capability-negotiator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAIxE,qBAAa,oBAAoB;IAC/B;;;;;;;;;;;OAWG;IACH;;;;OAIG;IACH,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAA8C;IAEnE;;;OAGG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAI3E;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAqBnC;;;;;OAKG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAW5C;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAMzC;;;;;;;;;OASG;IACH,oCAAoC,CAClC,SAAS,EAAE;QAAE,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;KAAE,EACnD,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,GACjC,IAAI;CAcR"}
|
|
@@ -22,6 +22,11 @@ export class CapabilityNegotiator {
|
|
|
22
22
|
*
|
|
23
23
|
* Key: Server instance → Value: raw capabilities object from initialize request
|
|
24
24
|
*/
|
|
25
|
+
/**
|
|
26
|
+
* Public so PhotonServer can expose a back-compat alias for tests that
|
|
27
|
+
* seed raw capabilities directly. Prefer `setRawCapabilities()` in
|
|
28
|
+
* non-test code paths.
|
|
29
|
+
*/
|
|
25
30
|
rawClientCapabilities = new WeakMap();
|
|
26
31
|
/**
|
|
27
32
|
* Store raw capabilities for a server instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-negotiator.js","sourceRoot":"","sources":["../src/capability-negotiator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAEvD,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;;;;;OAWG;
|
|
1
|
+
{"version":3,"file":"capability-negotiator.js","sourceRoot":"","sources":["../src/capability-negotiator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAEvD,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;;;;;OAWG;IACH;;;;OAIG;IACH,qBAAqB,GAAG,IAAI,OAAO,EAA+B,CAAC;IAEnE;;;OAGG;IACH,kBAAkB,CAAC,MAAc,EAAE,YAAiC;QAClE,IAAI,CAAC,qBAAqB,CA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AAS,CAAC;QAC1C,SAAS,CAAC,SAAS,GAAG,CAAC,OAAY,EAAE,KAAW,EAAE,EAAE;YAClD,mDAAmD;YACnD,IAAI,OAAO,EAAE,MAAM,KAAK,YAAY,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;gBACxD,IAAI,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;oBAChC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;gBAC5E,CAAC;YACH,CAAC;YACD,0CAA0C;YAC1C,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;YACrB,aAAa,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a photon's `protected cfBindings = { ... }` declaration.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors how `protected settings` is recognized in the schema-extractor
|
|
5
|
+
* (object-literal initializer on a protected class field). Returns null
|
|
6
|
+
* when the photon doesn't declare any CF bindings.
|
|
7
|
+
*
|
|
8
|
+
* The schema is intentionally narrow — only the binding-name → resource
|
|
9
|
+
* mappings (and the boolean opt-ins for ai/images/browser). Anything
|
|
10
|
+
* fancier belongs in the per-photon override JSON layered at deploy
|
|
11
|
+
* time.
|
|
12
|
+
*/
|
|
13
|
+
import type { CfBindingsConfig } from './runtime/cf-local.js';
|
|
14
|
+
export declare function parseCfBindings(tsContent: string): CfBindingsConfig | null;
|
|
15
|
+
//# sourceMappingURL=cf-bindings-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-bindings-parser.d.ts","sourceRoot":"","sources":["../src/cf-bindings-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAK9D,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CA0B1E"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a photon's `protected cfBindings = { ... }` declaration.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors how `protected settings` is recognized in the schema-extractor
|
|
5
|
+
* (object-literal initializer on a protected class field). Returns null
|
|
6
|
+
* when the photon doesn't declare any CF bindings.
|
|
7
|
+
*
|
|
8
|
+
* The schema is intentionally narrow — only the binding-name → resource
|
|
9
|
+
* mappings (and the boolean opt-ins for ai/images/browser). Anything
|
|
10
|
+
* fancier belongs in the per-photon override JSON layered at deploy
|
|
11
|
+
* time.
|
|
12
|
+
*/
|
|
13
|
+
import * as ts from 'typescript';
|
|
14
|
+
const NAMED_BINDING_CATEGORIES = ['r2', 'kv', 'd1', 'queue', 'vectorize'];
|
|
15
|
+
const BOOLEAN_CATEGORIES = ['ai', 'images', 'browser'];
|
|
16
|
+
export function parseCfBindings(tsContent) {
|
|
17
|
+
if (!tsContent.includes('cfBindings'))
|
|
18
|
+
return null;
|
|
19
|
+
const sourceFile = ts.createSourceFile('cf-bindings.ts', tsContent, ts.ScriptTarget.Latest, true);
|
|
20
|
+
let result = null;
|
|
21
|
+
const visit = (node) => {
|
|
22
|
+
if (result)
|
|
23
|
+
return;
|
|
24
|
+
if (ts.isPropertyDeclaration(node) &&
|
|
25
|
+
node.name.getText(sourceFile) === 'cfBindings' &&
|
|
26
|
+
node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ProtectedKeyword) &&
|
|
27
|
+
node.initializer &&
|
|
28
|
+
ts.isObjectLiteralExpression(node.initializer)) {
|
|
29
|
+
result = readBindingsLiteral(node.initializer, sourceFile);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
ts.forEachChild(node, visit);
|
|
33
|
+
};
|
|
34
|
+
visit(sourceFile);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
function readBindingsLiteral(obj, sourceFile) {
|
|
38
|
+
const out = {};
|
|
39
|
+
for (const prop of obj.properties) {
|
|
40
|
+
if (!ts.isPropertyAssignment(prop))
|
|
41
|
+
continue;
|
|
42
|
+
const key = prop.name.getText(sourceFile);
|
|
43
|
+
const init = prop.initializer;
|
|
44
|
+
if (NAMED_BINDING_CATEGORIES.includes(key)) {
|
|
45
|
+
if (!ts.isObjectLiteralExpression(init))
|
|
46
|
+
continue;
|
|
47
|
+
const map = {};
|
|
48
|
+
for (const sub of init.properties) {
|
|
49
|
+
if (!ts.isPropertyAssignment(sub))
|
|
50
|
+
continue;
|
|
51
|
+
const subKey = unquote(sub.name.getText(sourceFile));
|
|
52
|
+
if (ts.isStringLiteral(sub.initializer)) {
|
|
53
|
+
map[subKey] = sub.initializer.text;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// d1 accepts `{ name, id }` so users can hand the deploy adapter
|
|
57
|
+
// a real database UUID for `database_id` separate from the
|
|
58
|
+
// human-readable `database_name`.
|
|
59
|
+
if (key === 'd1' && ts.isObjectLiteralExpression(sub.initializer)) {
|
|
60
|
+
let name;
|
|
61
|
+
let id;
|
|
62
|
+
for (const inner of sub.initializer.properties) {
|
|
63
|
+
if (!ts.isPropertyAssignment(inner))
|
|
64
|
+
continue;
|
|
65
|
+
const innerKey = unquote(inner.name.getText(sourceFile));
|
|
66
|
+
if (!ts.isStringLiteral(inner.initializer))
|
|
67
|
+
continue;
|
|
68
|
+
if (innerKey === 'name')
|
|
69
|
+
name = inner.initializer.text;
|
|
70
|
+
else if (innerKey === 'id')
|
|
71
|
+
id = inner.initializer.text;
|
|
72
|
+
}
|
|
73
|
+
if (name && id) {
|
|
74
|
+
map[subKey] = { name, id };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
out[key] = map;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (BOOLEAN_CATEGORIES.includes(key)) {
|
|
82
|
+
if (init.kind === ts.SyntaxKind.TrueKeyword) {
|
|
83
|
+
out[key] = true;
|
|
84
|
+
}
|
|
85
|
+
else if (init.kind === ts.SyntaxKind.FalseKeyword) {
|
|
86
|
+
out[key] = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
function unquote(s) {
|
|
93
|
+
if (s.length >= 2 && (s.startsWith('"') || s.startsWith("'"))) {
|
|
94
|
+
return s.slice(1, -1);
|
|
95
|
+
}
|
|
96
|
+
return s;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=cf-bindings-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-bindings-parser.js","sourceRoot":"","sources":["../src/cf-bindings-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,MAAM,wBAAwB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,CAAU,CAAC;AACnF,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAEhE,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC;QAAE,OAAO,IAAI,CAAC;IAEnD,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAElG,IAAI,MAAM,GAA4B,IAAI,CAAC;IAE3C,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;QACpC,IAAI,MAAM;YAAE,OAAO;QAEnB,IACE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC;YAC9B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAA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,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;gBAC3C,GAA+B,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YAC/C,CAAC;iBAAM,IAAI,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC;gBACnD,GAA+B,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,CAAS;IACxB,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source scanner for the new `Cloudflare` injection surface.
|
|
3
|
+
*
|
|
4
|
+
* A photon that takes `private cf: Cloudflare` (or any other parameter
|
|
5
|
+
* name typed `Cloudflare`) reaches into per-binding resources via
|
|
6
|
+
* `cf.kv(qualifier?)`, `cf.r2(qualifier?)`, etc. The runtime needs to
|
|
7
|
+
* know — at boot time, before any tool runs — which **qualifiers** the
|
|
8
|
+
* photon will use, because both miniflare (local sandbox) and
|
|
9
|
+
* wrangler.toml (deploy) require every binding to be declared up front.
|
|
10
|
+
*
|
|
11
|
+
* This scanner walks the photon source and discovers:
|
|
12
|
+
* 1. Constructor parameter names typed `Cloudflare` (so we recognize
|
|
13
|
+
* `this.<paramName>.kv(...)` regardless of what the author named
|
|
14
|
+
* the field — `cf`, `xCloud`, `cloud`, etc.).
|
|
15
|
+
* 2. Every literal qualifier passed to a scoped category method on
|
|
16
|
+
* one of those parameter names.
|
|
17
|
+
* 3. The boolean `share` flags inferred from any reference to the
|
|
18
|
+
* shared categories (`ai`, `images`, `browser`).
|
|
19
|
+
*
|
|
20
|
+
* Dynamic qualifiers (e.g. `cf.kv(this.tenantId)`) are flagged as
|
|
21
|
+
* `dynamicQualifiers` per category so the runtime can throw a clear
|
|
22
|
+
* error pointing the author at `protected cfBindings` overrides — far
|
|
23
|
+
* better than letting miniflare crash with "binding undefined."
|
|
24
|
+
*
|
|
25
|
+
* Single source of truth for both runtime seeding and deploy autogen,
|
|
26
|
+
* so the binding-name convention can never drift between the two
|
|
27
|
+
* (a real risk before this scanner — `bindingNameFor(...)` lived in one
|
|
28
|
+
* place but every consumer recomputed it).
|
|
29
|
+
*/
|
|
30
|
+
import { type ScopedBindingCategory } from '@portel/photon-core';
|
|
31
|
+
/** Categories that take an optional qualifier and use auto-naming. */
|
|
32
|
+
declare const SCOPED_CATEGORIES: readonly ScopedBindingCategory[];
|
|
33
|
+
/** Categories with a single shared binding per Worker (no qualifier). */
|
|
34
|
+
declare const SHARED_CATEGORIES: readonly ["ai", "images", "browser"];
|
|
35
|
+
export type SharedCategory = (typeof SHARED_CATEGORIES)[number];
|
|
36
|
+
export interface CfUsage {
|
|
37
|
+
/**
|
|
38
|
+
* Per-category set of literal qualifier strings the photon uses.
|
|
39
|
+
* The empty-string entry `''` means the default (no-qualifier) call
|
|
40
|
+
* `cf.kv()`. Other entries are the literal arg passed to a qualified
|
|
41
|
+
* call like `cf.kv('cache')`.
|
|
42
|
+
*/
|
|
43
|
+
qualifiers: Record<ScopedBindingCategory, Set<string>>;
|
|
44
|
+
/**
|
|
45
|
+
* Categories where at least one call passed a non-literal expression
|
|
46
|
+
* (e.g. a variable). The runtime can't statically resolve the
|
|
47
|
+
* binding name; surfaces as a clear error rather than a silent
|
|
48
|
+
* miniflare miss.
|
|
49
|
+
*/
|
|
50
|
+
dynamicQualifiers: Set<ScopedBindingCategory>;
|
|
51
|
+
/** True if the photon reads the corresponding shared binding. */
|
|
52
|
+
shared: Record<SharedCategory, boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Constructor parameter names (or property names) recognized as the
|
|
55
|
+
* Cloudflare access path on this photon. Always at least includes
|
|
56
|
+
* `cf` for the legacy `this.cf` shape so existing static-analysis
|
|
57
|
+
* sites continue to work; extended with any additional names found
|
|
58
|
+
* via a typed constructor parameter.
|
|
59
|
+
*/
|
|
60
|
+
accessPaths: Set<string>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Scan a photon's TypeScript source and return everything the runtime
|
|
64
|
+
* + deploy code-gen needs to know about its CF usage.
|
|
65
|
+
*/
|
|
66
|
+
export declare function scanCfUsage(tsContent: string): CfUsage;
|
|
67
|
+
/**
|
|
68
|
+
* All scoped binding names the photon will use, expanded against the
|
|
69
|
+
* photon's name. Hands a deduplicated list to miniflare-config emission
|
|
70
|
+
* and wrangler.toml emission. Dynamic qualifiers contribute only the
|
|
71
|
+
* default name — the rest must come from `protected cfBindings`
|
|
72
|
+
* overrides.
|
|
73
|
+
*/
|
|
74
|
+
export declare function expandScopedBindingNames(photonName: string, usage: CfUsage): Record<ScopedBindingCategory, string[]>;
|
|
75
|
+
export { SCOPED_CATEGORIES, SHARED_CATEGORIES };
|
|
76
|
+
//# sourceMappingURL=cf-usage-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-usage-scanner.d.ts","sourceRoot":"","sources":["../src/cf-usage-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,sEAAsE;AACtE,QAAA,MAAM,iBAAiB,EAAE,SAAS,qBAAqB,EAM7C,CAAC;AAEX,yEAAyE;AACzE,QAAA,MAAM,iBAAiB,sCAAuC,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,MAAM,WAAW,OAAO;IACtB;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC,qBAAqB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD;;;;;OAKG;IACH,iBAAiB,EAAE,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC9C,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACxC;;;;;;OAMG;IACH,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AAaD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CA2DtD;AA0DD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,GACb,MAAM,CAAC,qBAAqB,EAAE,MAAM,EAAE,CAAC,CAUzC;AAED,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source scanner for the new `Cloudflare` injection surface.
|
|
3
|
+
*
|
|
4
|
+
* A photon that takes `private cf: Cloudflare` (or any other parameter
|
|
5
|
+
* name typed `Cloudflare`) reaches into per-binding resources via
|
|
6
|
+
* `cf.kv(qualifier?)`, `cf.r2(qualifier?)`, etc. The runtime needs to
|
|
7
|
+
* know — at boot time, before any tool runs — which **qualifiers** the
|
|
8
|
+
* photon will use, because both miniflare (local sandbox) and
|
|
9
|
+
* wrangler.toml (deploy) require every binding to be declared up front.
|
|
10
|
+
*
|
|
11
|
+
* This scanner walks the photon source and discovers:
|
|
12
|
+
* 1. Constructor parameter names typed `Cloudflare` (so we recognize
|
|
13
|
+
* `this.<paramName>.kv(...)` regardless of what the author named
|
|
14
|
+
* the field — `cf`, `xCloud`, `cloud`, etc.).
|
|
15
|
+
* 2. Every literal qualifier passed to a scoped category method on
|
|
16
|
+
* one of those parameter names.
|
|
17
|
+
* 3. The boolean `share` flags inferred from any reference to the
|
|
18
|
+
* shared categories (`ai`, `images`, `browser`).
|
|
19
|
+
*
|
|
20
|
+
* Dynamic qualifiers (e.g. `cf.kv(this.tenantId)`) are flagged as
|
|
21
|
+
* `dynamicQualifiers` per category so the runtime can throw a clear
|
|
22
|
+
* error pointing the author at `protected cfBindings` overrides — far
|
|
23
|
+
* better than letting miniflare crash with "binding undefined."
|
|
24
|
+
*
|
|
25
|
+
* Single source of truth for both runtime seeding and deploy autogen,
|
|
26
|
+
* so the binding-name convention can never drift between the two
|
|
27
|
+
* (a real risk before this scanner — `bindingNameFor(...)` lived in one
|
|
28
|
+
* place but every consumer recomputed it).
|
|
29
|
+
*/
|
|
30
|
+
import * as ts from 'typescript';
|
|
31
|
+
import { bindingNameFor } from '@portel/photon-core';
|
|
32
|
+
/** Categories that take an optional qualifier and use auto-naming. */
|
|
33
|
+
const SCOPED_CATEGORIES = [
|
|
34
|
+
'kv',
|
|
35
|
+
'r2',
|
|
36
|
+
'd1',
|
|
37
|
+
'queue',
|
|
38
|
+
'vectorize',
|
|
39
|
+
];
|
|
40
|
+
/** Categories with a single shared binding per Worker (no qualifier). */
|
|
41
|
+
const SHARED_CATEGORIES = ['ai', 'images', 'browser'];
|
|
42
|
+
function emptyUsage() {
|
|
43
|
+
const qualifiers = {};
|
|
44
|
+
for (const cat of SCOPED_CATEGORIES)
|
|
45
|
+
qualifiers[cat] = new Set();
|
|
46
|
+
return {
|
|
47
|
+
qualifiers,
|
|
48
|
+
dynamicQualifiers: new Set(),
|
|
49
|
+
shared: { ai: false, images: false, browser: false },
|
|
50
|
+
accessPaths: new Set(['cf']),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Scan a photon's TypeScript source and return everything the runtime
|
|
55
|
+
* + deploy code-gen needs to know about its CF usage.
|
|
56
|
+
*/
|
|
57
|
+
export function scanCfUsage(tsContent) {
|
|
58
|
+
const usage = emptyUsage();
|
|
59
|
+
if (!tsContent)
|
|
60
|
+
return usage;
|
|
61
|
+
const sourceFile = ts.createSourceFile('cf-usage.ts', tsContent, ts.ScriptTarget.Latest, true);
|
|
62
|
+
// (1) Walk every class declaration and discover constructor params
|
|
63
|
+
// typed `Cloudflare`. The param name becomes an additional access
|
|
64
|
+
// path the call-scanner recognises.
|
|
65
|
+
const visitForAccessPaths = (node) => {
|
|
66
|
+
if (ts.isClassDeclaration(node)) {
|
|
67
|
+
for (const member of node.members) {
|
|
68
|
+
if (!ts.isConstructorDeclaration(member))
|
|
69
|
+
continue;
|
|
70
|
+
for (const param of member.parameters) {
|
|
71
|
+
if (!param.name || !ts.isIdentifier(param.name))
|
|
72
|
+
continue;
|
|
73
|
+
if (!param.type)
|
|
74
|
+
continue;
|
|
75
|
+
const typeText = param.type.getText(sourceFile).trim();
|
|
76
|
+
if (typeText === 'Cloudflare' || typeText.startsWith('Cloudflare ')) {
|
|
77
|
+
usage.accessPaths.add(param.name.text);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
ts.forEachChild(node, visitForAccessPaths);
|
|
83
|
+
};
|
|
84
|
+
visitForAccessPaths(sourceFile);
|
|
85
|
+
// (2) Walk every property/element access. We're looking for two
|
|
86
|
+
// shapes: `this.<accessPath>.<category>(...)` (scoped) and
|
|
87
|
+
// `this.<accessPath>.<sharedCategory>` (shared). Tracking both in
|
|
88
|
+
// one walker keeps source-file traversal cost down on big photons.
|
|
89
|
+
const visitForUsage = (node) => {
|
|
90
|
+
// Scoped category call: `this.<path>.<cat>(<qualifier?>)`
|
|
91
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
|
|
92
|
+
const access = node.expression;
|
|
93
|
+
const cat = access.name.getText(sourceFile);
|
|
94
|
+
if (SCOPED_CATEGORIES.includes(cat)) {
|
|
95
|
+
if (matchesAccessPath(access.expression, sourceFile, usage.accessPaths)) {
|
|
96
|
+
recordScopedCall(usage, cat, node, sourceFile);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Shared category access: `this.<path>.<shared>` (no call required —
|
|
101
|
+
// `this.cf.ai.run(...)` reads `ai` first).
|
|
102
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
103
|
+
const cat = node.name.getText(sourceFile);
|
|
104
|
+
if (SHARED_CATEGORIES.includes(cat)) {
|
|
105
|
+
if (matchesAccessPath(node.expression, sourceFile, usage.accessPaths)) {
|
|
106
|
+
usage.shared[cat] = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
ts.forEachChild(node, visitForUsage);
|
|
111
|
+
};
|
|
112
|
+
visitForUsage(sourceFile);
|
|
113
|
+
return usage;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Does `expr` resolve to one of the photon's recognized Cloudflare
|
|
117
|
+
* access paths? Accepts both `this.cf` and bare `cf` (the latter shows
|
|
118
|
+
* up when an author destructures the parameter into a local).
|
|
119
|
+
*/
|
|
120
|
+
function matchesAccessPath(expr, sourceFile, paths) {
|
|
121
|
+
// `this.<name>` or `(this as ...).<name>`
|
|
122
|
+
if (ts.isPropertyAccessExpression(expr)) {
|
|
123
|
+
const name = expr.name.getText(sourceFile);
|
|
124
|
+
if (!paths.has(name))
|
|
125
|
+
return false;
|
|
126
|
+
const receiver = unwrapTypeAssertion(expr.expression);
|
|
127
|
+
return receiver.kind === ts.SyntaxKind.ThisKeyword;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
function unwrapTypeAssertion(expr) {
|
|
132
|
+
// `(this as Foo).cf`, `(<Foo>this).cf`, `(this as unknown as Foo).cf`
|
|
133
|
+
if (ts.isParenthesizedExpression(expr)) {
|
|
134
|
+
return unwrapTypeAssertion(expr.expression);
|
|
135
|
+
}
|
|
136
|
+
if (ts.isAsExpression(expr) || ts.isTypeAssertionExpression(expr)) {
|
|
137
|
+
return unwrapTypeAssertion(expr.expression);
|
|
138
|
+
}
|
|
139
|
+
return expr;
|
|
140
|
+
}
|
|
141
|
+
function recordScopedCall(usage, cat, call, sourceFile) {
|
|
142
|
+
const args = call.arguments;
|
|
143
|
+
if (args.length === 0) {
|
|
144
|
+
usage.qualifiers[cat].add('');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const first = args[0];
|
|
148
|
+
if (ts.isStringLiteralLike(first)) {
|
|
149
|
+
usage.qualifiers[cat].add(first.text);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Non-literal — author passed a variable / expression. Track so the
|
|
153
|
+
// runtime can fail clearly when this binding is reached for.
|
|
154
|
+
usage.dynamicQualifiers.add(cat);
|
|
155
|
+
// Best-effort: also add '' so the default binding is at least
|
|
156
|
+
// configured. The dynamic call may still hit a name the runtime
|
|
157
|
+
// doesn't know, but the default keeps simple branches working.
|
|
158
|
+
usage.qualifiers[cat].add('');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* All scoped binding names the photon will use, expanded against the
|
|
162
|
+
* photon's name. Hands a deduplicated list to miniflare-config emission
|
|
163
|
+
* and wrangler.toml emission. Dynamic qualifiers contribute only the
|
|
164
|
+
* default name — the rest must come from `protected cfBindings`
|
|
165
|
+
* overrides.
|
|
166
|
+
*/
|
|
167
|
+
export function expandScopedBindingNames(photonName, usage) {
|
|
168
|
+
const out = {};
|
|
169
|
+
for (const cat of SCOPED_CATEGORIES) {
|
|
170
|
+
const names = [];
|
|
171
|
+
for (const qualifier of usage.qualifiers[cat]) {
|
|
172
|
+
names.push(bindingNameFor(photonName, cat, qualifier || undefined));
|
|
173
|
+
}
|
|
174
|
+
out[cat] = names;
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
export { SCOPED_CATEGORIES, SHARED_CATEGORIES };
|
|
179
|
+
//# sourceMappingURL=cf-usage-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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ACtC,UAAkB,EAClB,KAAc;IAEd,MAAM,GAAG,GAAG,EAA6C,CAAC;IAC1D,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9C,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC;QACtE,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -904,7 +904,7 @@ async function runCli(methodName: string, methodArgs: string[], source: string,
|
|
|
904
904
|
runtime.start();
|
|
905
905
|
|
|
906
906
|
const loader = new PhotonLoader(false);
|
|
907
|
-
if (depMap)
|
|
907
|
+
if (depMap) loader.preloadedDependencies = depMap;
|
|
908
908
|
const photonInstance = await loader.loadFromModule(mod, filePath, source);
|
|
909
909
|
const result = await loader.executeTool(photonInstance, methodName, parsedArgs);
|
|
910
910
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `photon cf` — inspect and edit a photon's CF binding overrides.
|
|
3
|
+
*
|
|
4
|
+
* The override JSON layers on top of `protected cfBindings` so users can
|
|
5
|
+
* repoint a binding (e.g., point `kv: cache` at a different namespace)
|
|
6
|
+
* without editing photon source. This command surface is intentionally
|
|
7
|
+
* thin; the heavier "create resource", "test connection", and Beam UI
|
|
8
|
+
* panel land in later phases.
|
|
9
|
+
*
|
|
10
|
+
* Examples:
|
|
11
|
+
* photon cf bindings my-photon # show declared + override
|
|
12
|
+
* photon cf set my-photon kv.cache prod-cache # repoint a binding
|
|
13
|
+
* photon cf set my-photon ai true # toggle a boolean opt-in
|
|
14
|
+
* photon cf reset my-photon # drop the override
|
|
15
|
+
*/
|
|
16
|
+
import type { Command } from 'commander';
|
|
17
|
+
export declare function registerCfCommands(program: Command): void;
|
|
18
|
+
//# sourceMappingURL=cf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/cf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWzC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4EzD"}
|