@principal-ai/subsystems-core 0.51.6 → 0.51.8
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/infra/c4.d.ts +59 -0
- package/dist/infra/c4.d.ts.map +1 -0
- package/dist/infra/c4.js +101 -0
- package/dist/infra/c4.js.map +1 -0
- package/dist/infra/index.d.ts +13 -0
- package/dist/infra/index.d.ts.map +1 -0
- package/dist/infra/index.js +22 -0
- package/dist/infra/index.js.map +1 -0
- package/dist/infra/jsonc.d.ts +10 -0
- package/dist/infra/jsonc.d.ts.map +1 -0
- package/dist/infra/jsonc.js +77 -0
- package/dist/infra/jsonc.js.map +1 -0
- package/dist/infra/terraform.d.ts +41 -0
- package/dist/infra/terraform.d.ts.map +1 -0
- package/dist/infra/terraform.js +208 -0
- package/dist/infra/terraform.js.map +1 -0
- package/dist/infra/types.d.ts +107 -0
- package/dist/infra/types.d.ts.map +1 -0
- package/dist/infra/types.js +47 -0
- package/dist/infra/types.js.map +1 -0
- package/dist/infra/wrangler.d.ts +24 -0
- package/dist/infra/wrangler.d.ts.map +1 -0
- package/dist/infra/wrangler.js +116 -0
- package/dist/infra/wrangler.js.map +1 -0
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/storage/topic-share.d.ts +23 -11
- package/dist/storage/topic-share.d.ts.map +1 -1
- package/dist/storage/topic-share.js +19 -7
- package/dist/storage/topic-share.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/infra/c4.ts +141 -0
- package/src/infra/index.ts +21 -0
- package/src/infra/infra.test.ts +300 -0
- package/src/infra/jsonc.ts +70 -0
- package/src/infra/terraform.ts +251 -0
- package/src/infra/types.ts +136 -0
- package/src/infra/wrangler.ts +148 -0
- package/src/node.ts +1 -1
- package/src/storage/topic-share.test.ts +23 -3
- package/src/storage/topic-share.ts +38 -11
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infrastructure-as-code read side — what a config file *declares* and what a
|
|
3
|
+
* live account was *observed* to be running.
|
|
4
|
+
*
|
|
5
|
+
* Two facts, kept apart on purpose:
|
|
6
|
+
*
|
|
7
|
+
* - **Configured** ({@link InfraManifest}) is a static parse of a file at a
|
|
8
|
+
* commit. No credentials, always available, verifiable like source.
|
|
9
|
+
* - **Deployed** ({@link InfraDeploymentObservation}) is an observation of
|
|
10
|
+
* the live account. It needs credentials, carries a timestamp, and goes
|
|
11
|
+
* stale. Nothing here fetches one; the tooling that does is separate and
|
|
12
|
+
* only has to produce this shape.
|
|
13
|
+
*
|
|
14
|
+
* Everything in this folder is pure and browser-safe: extractors take text or
|
|
15
|
+
* parsed JSON, never a path.
|
|
16
|
+
*/
|
|
17
|
+
/** The tool whose file declared a resource. */
|
|
18
|
+
export type InfraTool = 'wrangler' | 'terraform';
|
|
19
|
+
/** Where a declaration lives — the infra analogue of `file` + `symbol`. */
|
|
20
|
+
export interface InfraResourceSource {
|
|
21
|
+
tool: InfraTool;
|
|
22
|
+
/** Repo-root-relative path of the file the caller parsed. */
|
|
23
|
+
file: string;
|
|
24
|
+
/**
|
|
25
|
+
* Location inside that file. A JSON pointer for wrangler
|
|
26
|
+
* (`/r2_buckets/0`), a resource address for terraform
|
|
27
|
+
* (`cloudflare_r2_bucket.blobs`).
|
|
28
|
+
*/
|
|
29
|
+
pointer: string;
|
|
30
|
+
}
|
|
31
|
+
/** One declared piece of infrastructure. */
|
|
32
|
+
export interface InfraResource {
|
|
33
|
+
/**
|
|
34
|
+
* Stable identity, `<provider>:<resourceType>:<identifier>` — e.g.
|
|
35
|
+
* `cloudflare:worker:topic-share`. Chosen so the same resource declared by
|
|
36
|
+
* two tools yields the same key; observations join on it.
|
|
37
|
+
*/
|
|
38
|
+
key: string;
|
|
39
|
+
/** Hosting provider, lowercase: `cloudflare`. */
|
|
40
|
+
provider: string;
|
|
41
|
+
/** Provider-neutral-ish type: `worker`, `r2_bucket`, `d1_database`, `kv_namespace`, `queue`. */
|
|
42
|
+
resourceType: string;
|
|
43
|
+
/** The provider's own name or id for the resource. */
|
|
44
|
+
name: string;
|
|
45
|
+
/** What to show a reader. Falls back to the binding name when the provider name is an opaque id. */
|
|
46
|
+
label: string;
|
|
47
|
+
source: InfraResourceSource;
|
|
48
|
+
/** Small declared facts worth showing (`crons`, `assets`, `id`). Never secrets or env values. */
|
|
49
|
+
attributes?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
/** A declared access path from one resource to another — a Worker's binding. */
|
|
52
|
+
export interface InfraBinding {
|
|
53
|
+
/** Key of the resource that holds the binding (the Worker). */
|
|
54
|
+
from: string;
|
|
55
|
+
/** Key of the resource it reaches. May name a resource no parsed file declares. */
|
|
56
|
+
to: string;
|
|
57
|
+
/** The name code uses, e.g. `TOPIC_BLOBS` for `env.TOPIC_BLOBS`. */
|
|
58
|
+
binding: string;
|
|
59
|
+
source: InfraResourceSource;
|
|
60
|
+
}
|
|
61
|
+
/** Everything one or more config files declare. */
|
|
62
|
+
export interface InfraManifest {
|
|
63
|
+
resources: InfraResource[];
|
|
64
|
+
bindings: InfraBinding[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether a resource was found live.
|
|
68
|
+
*
|
|
69
|
+
* `unknown` means the check could not be made (no permission, network
|
|
70
|
+
* failure). It is deliberately not `not-found`: a failed check must never read
|
|
71
|
+
* as "not deployed".
|
|
72
|
+
*/
|
|
73
|
+
export type InfraDeploymentStatus = 'deployed' | 'not-found' | 'unknown';
|
|
74
|
+
/**
|
|
75
|
+
* One observation of one resource in a live account.
|
|
76
|
+
*
|
|
77
|
+
* Produced by credentialed tooling outside this package. Carries no
|
|
78
|
+
* credential, token, or environment value.
|
|
79
|
+
*/
|
|
80
|
+
export interface InfraDeploymentObservation {
|
|
81
|
+
/** Joins to {@link InfraResource.key}. */
|
|
82
|
+
resourceKey: string;
|
|
83
|
+
status: InfraDeploymentStatus;
|
|
84
|
+
/** Provider id, e.g. a D1 database id. */
|
|
85
|
+
resourceId?: string;
|
|
86
|
+
/** Where the running thing answers — workers.dev, routes, custom domains. */
|
|
87
|
+
liveUrls?: string[];
|
|
88
|
+
/** The provider dashboard page for this resource. */
|
|
89
|
+
consoleUrl?: string;
|
|
90
|
+
/** Deployed version or deployment id, when the provider exposes one. */
|
|
91
|
+
version?: string;
|
|
92
|
+
/** When that version went live (ISO). */
|
|
93
|
+
deployedAt?: string;
|
|
94
|
+
/** When we looked (ISO). Required so a view can show staleness. */
|
|
95
|
+
observedAt: string;
|
|
96
|
+
/** Who said so: `cloudflare-api`, `terraform-state`, `authored`. */
|
|
97
|
+
source: string;
|
|
98
|
+
}
|
|
99
|
+
/** Build a resource key. Exported so observers produce the same string. */
|
|
100
|
+
export declare function infraResourceKey(provider: string, resourceType: string, identifier: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Merge manifests from several files. The first declaration of a key wins, so
|
|
103
|
+
* pass the more authoritative file first; bindings are de-duplicated on
|
|
104
|
+
* `from` + `to` + `binding`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function mergeInfraManifests(manifests: readonly InfraManifest[]): InfraManifest;
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/infra/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,+CAA+C;AAC/C,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;AAEjD,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4CAA4C;AAC5C,MAAM,WAAW,aAAa;I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AChB;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,aAAa,EAAE,GAClC,aAAa,CAaf"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Infrastructure-as-code read side — what a config file *declares* and what a
|
|
4
|
+
* live account was *observed* to be running.
|
|
5
|
+
*
|
|
6
|
+
* Two facts, kept apart on purpose:
|
|
7
|
+
*
|
|
8
|
+
* - **Configured** ({@link InfraManifest}) is a static parse of a file at a
|
|
9
|
+
* commit. No credentials, always available, verifiable like source.
|
|
10
|
+
* - **Deployed** ({@link InfraDeploymentObservation}) is an observation of
|
|
11
|
+
* the live account. It needs credentials, carries a timestamp, and goes
|
|
12
|
+
* stale. Nothing here fetches one; the tooling that does is separate and
|
|
13
|
+
* only has to produce this shape.
|
|
14
|
+
*
|
|
15
|
+
* Everything in this folder is pure and browser-safe: extractors take text or
|
|
16
|
+
* parsed JSON, never a path.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.mergeInfraManifests = exports.infraResourceKey = void 0;
|
|
20
|
+
/** Build a resource key. Exported so observers produce the same string. */
|
|
21
|
+
function infraResourceKey(provider, resourceType, identifier) {
|
|
22
|
+
return `${provider}:${resourceType}:${identifier}`;
|
|
23
|
+
}
|
|
24
|
+
exports.infraResourceKey = infraResourceKey;
|
|
25
|
+
/**
|
|
26
|
+
* Merge manifests from several files. The first declaration of a key wins, so
|
|
27
|
+
* pass the more authoritative file first; bindings are de-duplicated on
|
|
28
|
+
* `from` + `to` + `binding`.
|
|
29
|
+
*/
|
|
30
|
+
function mergeInfraManifests(manifests) {
|
|
31
|
+
const resources = new Map();
|
|
32
|
+
const bindings = new Map();
|
|
33
|
+
for (const manifest of manifests) {
|
|
34
|
+
for (const resource of manifest.resources) {
|
|
35
|
+
if (!resources.has(resource.key))
|
|
36
|
+
resources.set(resource.key, resource);
|
|
37
|
+
}
|
|
38
|
+
for (const binding of manifest.bindings) {
|
|
39
|
+
const id = `${binding.from}\u0000${binding.to}\u0000${binding.binding}`;
|
|
40
|
+
if (!bindings.has(id))
|
|
41
|
+
bindings.set(id, binding);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { resources: [...resources.values()], bindings: [...bindings.values()] };
|
|
45
|
+
}
|
|
46
|
+
exports.mergeInfraManifests = mergeInfraManifests;
|
|
47
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/infra/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AA2FH,2EAA2E;AAC3E,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,YAAoB,EACpB,UAAkB;IAElB,OAAO,GAAG,QAAQ,IAAI,YAAY,IAAI,UAAU,EAAE,CAAC;AACrD,CAAC;AAND,4CAMC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CACjC,SAAmC;IAEnC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IACjD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC,SAAS,EAAE;YACzC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SACzE;QACD,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE;YACvC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,SAAS,OAAO,CAAC,EAAE,SAAS,OAAO,CAAC,OAAO,EAAE,CAAC;YACxE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;SAClD;KACF;IACD,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;AAClF,CAAC;AAfD,kDAeC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrangler config → {@link InfraManifest}.
|
|
3
|
+
*
|
|
4
|
+
* A `wrangler.jsonc` declares one Worker and the resources it binds. That maps
|
|
5
|
+
* cleanly: the Worker is a resource, each bound store is a resource, and each
|
|
6
|
+
* binding is the access path between them — named exactly as code names it
|
|
7
|
+
* (`env.TOPIC_BLOBS`), which is what makes the binding a join to trail steps.
|
|
8
|
+
*
|
|
9
|
+
* Top-level config only. Named environments (`env.staging`) are not read yet.
|
|
10
|
+
*/
|
|
11
|
+
import { type InfraManifest } from './types';
|
|
12
|
+
export interface ExtractWranglerOptions {
|
|
13
|
+
/** Repo-root-relative path of the config, recorded on every source. */
|
|
14
|
+
file: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Read a wrangler config. Accepts JSONC text or an already-parsed object, so a
|
|
18
|
+
* caller holding a `wrangler.toml` can parse it and pass the result.
|
|
19
|
+
*
|
|
20
|
+
* Returns an empty manifest when the config names no Worker. Malformed JSONC
|
|
21
|
+
* text throws `SyntaxError`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractWranglerManifest(config: string | unknown, options: ExtractWranglerOptions): InfraManifest;
|
|
24
|
+
//# sourceMappingURL=wrangler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/infra/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,SAAS,CAAC;AA+CjB,MAAM,WAAW,sBAAsB;IACrC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,OAAO,EAAE,sBAAsB,GAC9B,aAAa,CAmEf"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Wrangler config → {@link InfraManifest}.
|
|
4
|
+
*
|
|
5
|
+
* A `wrangler.jsonc` declares one Worker and the resources it binds. That maps
|
|
6
|
+
* cleanly: the Worker is a resource, each bound store is a resource, and each
|
|
7
|
+
* binding is the access path between them — named exactly as code names it
|
|
8
|
+
* (`env.TOPIC_BLOBS`), which is what makes the binding a join to trail steps.
|
|
9
|
+
*
|
|
10
|
+
* Top-level config only. Named environments (`env.staging`) are not read yet.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.extractWranglerManifest = void 0;
|
|
14
|
+
const jsonc_1 = require("./jsonc");
|
|
15
|
+
const types_1 = require("./types");
|
|
16
|
+
const PROVIDER = 'cloudflare';
|
|
17
|
+
function isObject(value) {
|
|
18
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function str(value) {
|
|
21
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
22
|
+
}
|
|
23
|
+
const BINDING_FAMILIES = [
|
|
24
|
+
{ path: ['kv_namespaces'], resourceType: 'kv_namespace', bindingField: 'binding', identifierField: 'id' },
|
|
25
|
+
{ path: ['r2_buckets'], resourceType: 'r2_bucket', bindingField: 'binding', identifierField: 'bucket_name' },
|
|
26
|
+
{
|
|
27
|
+
path: ['d1_databases'],
|
|
28
|
+
resourceType: 'd1_database',
|
|
29
|
+
bindingField: 'binding',
|
|
30
|
+
identifierField: 'database_name',
|
|
31
|
+
idField: 'database_id',
|
|
32
|
+
},
|
|
33
|
+
{ path: ['queues', 'producers'], resourceType: 'queue', bindingField: 'binding', identifierField: 'queue' },
|
|
34
|
+
{ path: ['services'], resourceType: 'worker', bindingField: 'binding', identifierField: 'service' },
|
|
35
|
+
];
|
|
36
|
+
/** A KV namespace is declared by opaque id only, so the binding names it. */
|
|
37
|
+
const OPAQUE_IDENTIFIER = new Set(['kv_namespace']);
|
|
38
|
+
/**
|
|
39
|
+
* Read a wrangler config. Accepts JSONC text or an already-parsed object, so a
|
|
40
|
+
* caller holding a `wrangler.toml` can parse it and pass the result.
|
|
41
|
+
*
|
|
42
|
+
* Returns an empty manifest when the config names no Worker. Malformed JSONC
|
|
43
|
+
* text throws `SyntaxError`.
|
|
44
|
+
*/
|
|
45
|
+
function extractWranglerManifest(config, options) {
|
|
46
|
+
const root = typeof config === 'string' ? (0, jsonc_1.parseJsonc)(config) : config;
|
|
47
|
+
if (!isObject(root))
|
|
48
|
+
return { resources: [], bindings: [] };
|
|
49
|
+
const workerName = str(root.name);
|
|
50
|
+
if (!workerName)
|
|
51
|
+
return { resources: [], bindings: [] };
|
|
52
|
+
const source = (pointer) => ({
|
|
53
|
+
tool: 'wrangler',
|
|
54
|
+
file: options.file,
|
|
55
|
+
pointer,
|
|
56
|
+
});
|
|
57
|
+
const workerKey = (0, types_1.infraResourceKey)(PROVIDER, 'worker', workerName);
|
|
58
|
+
const workerAttributes = {};
|
|
59
|
+
const main = str(root.main);
|
|
60
|
+
if (main)
|
|
61
|
+
workerAttributes.main = main;
|
|
62
|
+
if (isObject(root.assets))
|
|
63
|
+
workerAttributes.assets = 'true';
|
|
64
|
+
const crons = isObject(root.triggers) ? root.triggers.crons : undefined;
|
|
65
|
+
if (Array.isArray(crons) && crons.length > 0) {
|
|
66
|
+
workerAttributes.crons = crons.filter((c) => typeof c === 'string').join(', ');
|
|
67
|
+
}
|
|
68
|
+
const resources = [
|
|
69
|
+
{
|
|
70
|
+
key: workerKey,
|
|
71
|
+
provider: PROVIDER,
|
|
72
|
+
resourceType: 'worker',
|
|
73
|
+
name: workerName,
|
|
74
|
+
label: workerName,
|
|
75
|
+
source: source(''),
|
|
76
|
+
...(Object.keys(workerAttributes).length > 0 ? { attributes: workerAttributes } : {}),
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
const bindings = [];
|
|
80
|
+
for (const family of BINDING_FAMILIES) {
|
|
81
|
+
let entries = root;
|
|
82
|
+
for (const segment of family.path) {
|
|
83
|
+
entries = isObject(entries) ? entries[segment] : undefined;
|
|
84
|
+
}
|
|
85
|
+
if (!Array.isArray(entries))
|
|
86
|
+
continue;
|
|
87
|
+
entries.forEach((entry, index) => {
|
|
88
|
+
if (!isObject(entry))
|
|
89
|
+
return;
|
|
90
|
+
const binding = str(entry[family.bindingField]);
|
|
91
|
+
const identifier = str(entry[family.identifierField]);
|
|
92
|
+
if (!binding || !identifier)
|
|
93
|
+
return;
|
|
94
|
+
const pointer = `/${family.path.join('/')}/${index}`;
|
|
95
|
+
const key = (0, types_1.infraResourceKey)(PROVIDER, family.resourceType, identifier);
|
|
96
|
+
const id = family.idField ? str(entry[family.idField]) : undefined;
|
|
97
|
+
// A service binding points at another Worker, which its own config
|
|
98
|
+
// declares; emit the access path but not a second declaration of it.
|
|
99
|
+
if (family.resourceType !== 'worker') {
|
|
100
|
+
resources.push({
|
|
101
|
+
key,
|
|
102
|
+
provider: PROVIDER,
|
|
103
|
+
resourceType: family.resourceType,
|
|
104
|
+
name: identifier,
|
|
105
|
+
label: OPAQUE_IDENTIFIER.has(family.resourceType) ? binding : identifier,
|
|
106
|
+
source: source(pointer),
|
|
107
|
+
...(id ? { attributes: { id } } : {}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
bindings.push({ from: workerKey, to: key, binding, source: source(pointer) });
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return { resources, bindings };
|
|
114
|
+
}
|
|
115
|
+
exports.extractWranglerManifest = extractWranglerManifest;
|
|
116
|
+
//# sourceMappingURL=wrangler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../src/infra/wrangler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAqC;AACrC,mCAMiB;AAEjB,MAAM,QAAQ,GAAG,YAAY,CAAC;AAI9B,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAkBD,MAAM,gBAAgB,GAA6B;IACjD,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE;IACzG,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE;IAC5G;QACE,IAAI,EAAE,CAAC,cAAc,CAAC;QACtB,YAAY,EAAE,aAAa;QAC3B,YAAY,EAAE,SAAS;QACvB,eAAe,EAAE,eAAe;QAChC,OAAO,EAAE,aAAa;KACvB;IACD,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE;IAC3G,EAAE,I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CAAC;KACJ;IAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC;AAtED,0DAsEC"}
|
package/dist/node.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type { TopicIndexEntry, TopicCreate, TopicUpdate, MigrationResult, } from
|
|
|
13
13
|
export type { DraftTopic, TopicAsset, TopicCreator, TopicSubsystemModelRef, TopicReference, } from './storage/topic-types';
|
|
14
14
|
export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
|
|
15
15
|
export { toSharedTopic } from './storage/topic-share';
|
|
16
|
-
export type { SharedTopic, SharedTopicAsset, SharedTopicProjection } from './storage/topic-share';
|
|
16
|
+
export type { SharedTopic, SharedTopicAsset, SharedTopicProjection, SharedTopicReference } from './storage/topic-share';
|
|
17
17
|
export { OpenCodeEventStore, defaultOpenCodeDBPath } from './opencode/OpenCodeEventStore';
|
|
18
18
|
export type { OpenCodeRawEvent, OpenCodeSessionEvents, OpenCodeEventRetriever, OpenCodeStoreOptions, SessionSummary, SessionListResult, } from './opencode/types';
|
|
19
19
|
export { listAgentSessions, detectAgent, fetchRawEvents } from './opencode/agent-sessions';
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,iCA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,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
* Portable projection of a topic for sharing outside the machine that authored
|
|
3
3
|
* it. Browser-safe (no `node:*`).
|
|
4
4
|
*
|
|
5
|
-
* A {@link DraftTopic} carries fields that only mean something locally:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* A {@link DraftTopic} carries fields that only mean something locally: inline
|
|
6
|
+
* image bytes, local asset origins and drawing references. {@link toSharedTopic}
|
|
7
|
+
* drops those and splits image bytes out so a host can upload each one
|
|
8
|
+
* separately.
|
|
9
|
+
*
|
|
10
|
+
* References to subsystem models, C4 sketches and other topics are kept as ids.
|
|
11
|
+
* A share is published under its local id, so a reader resolves the same id
|
|
12
|
+
* against the sharing service instead of the local store. A reference whose
|
|
13
|
+
* target was not shared (or not with the reader) is simply unavailable.
|
|
9
14
|
*/
|
|
10
|
-
import type { DraftTopic, TopicCreator } from './topic-types';
|
|
15
|
+
import type { DraftTopic, TopicCreator, TopicReference, TopicSubsystemModelRef } from './topic-types';
|
|
16
|
+
/** A reference a shared topic can carry. Drawings have no shared form yet. */
|
|
17
|
+
export type SharedTopicReference = Exclude<TopicReference, {
|
|
18
|
+
kind: 'drawing';
|
|
19
|
+
}>;
|
|
11
20
|
/** An image a shared topic refers to. Bytes travel separately, keyed by `id`. */
|
|
12
21
|
export interface SharedTopicAsset {
|
|
13
22
|
/** Content hash; the `asset://<id>` target in the description. */
|
|
@@ -20,9 +29,8 @@ export interface SharedTopicAsset {
|
|
|
20
29
|
alt?: string;
|
|
21
30
|
}
|
|
22
31
|
/**
|
|
23
|
-
* A topic as it leaves the authoring machine. No
|
|
24
|
-
*
|
|
25
|
-
* against `assets`.
|
|
32
|
+
* A topic as it leaves the authoring machine. No inline bytes; `description`
|
|
33
|
+
* is unchanged, so `asset://<id>` links still resolve against `assets`.
|
|
26
34
|
*/
|
|
27
35
|
export interface SharedTopic {
|
|
28
36
|
id: string;
|
|
@@ -36,6 +44,10 @@ export interface SharedTopic {
|
|
|
36
44
|
updatedAt: string;
|
|
37
45
|
createdBy?: TopicCreator;
|
|
38
46
|
assets?: SharedTopicAsset[];
|
|
47
|
+
/** Subsystem models the topic concerns, by share id (same as the local id). */
|
|
48
|
+
subsystemModels?: TopicSubsystemModelRef[];
|
|
49
|
+
/** Attached C4 sketches and related topics, by share id. */
|
|
50
|
+
references?: SharedTopicReference[];
|
|
39
51
|
}
|
|
40
52
|
export interface SharedTopicProjection {
|
|
41
53
|
topic: SharedTopic;
|
|
@@ -49,9 +61,9 @@ export interface SharedTopicProjection {
|
|
|
49
61
|
/**
|
|
50
62
|
* Project a local topic into its shared form.
|
|
51
63
|
*
|
|
52
|
-
* Dropped:
|
|
53
|
-
*
|
|
54
|
-
*
|
|
64
|
+
* Dropped: drawing references (no shared form), each asset's `source` (local
|
|
65
|
+
* Storybook origin) and inline `data`. Assets with neither `data` nor `url`
|
|
66
|
+
* cannot be resolved by a reader and are omitted.
|
|
55
67
|
*/
|
|
56
68
|
export declare function toSharedTopic(topic: DraftTopic): SharedTopicProjection;
|
|
57
69
|
//# sourceMappingURL=topic-share.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic-share.d.ts","sourceRoot":"","sources":["../../src/storage/topic-share.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"topic-share.d.ts","sourceRoot":"","sources":["../../src/storage/topic-share.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EACZ,cAAc,EACd,s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the machine that authored
|
|
4
4
|
* it. Browser-safe (no `node:*`).
|
|
5
5
|
*
|
|
6
|
-
* A {@link DraftTopic} carries fields that only mean something locally:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* A {@link DraftTopic} carries fields that only mean something locally: inline
|
|
7
|
+
* image bytes, local asset origins and drawing references. {@link toSharedTopic}
|
|
8
|
+
* drops those and splits image bytes out so a host can upload each one
|
|
9
|
+
* separately.
|
|
10
|
+
*
|
|
11
|
+
* References to subsystem models, C4 sketches and other topics are kept as ids.
|
|
12
|
+
* A share is published under its local id, so a reader resolves the same id
|
|
13
|
+
* against the sharing service instead of the local store. A reference whose
|
|
14
|
+
* target was not shared (or not with the reader) is simply unavailable.
|
|
10
15
|
*/
|
|
11
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
17
|
exports.toSharedTopic = void 0;
|
|
13
18
|
/**
|
|
14
19
|
* Project a local topic into its shared form.
|
|
15
20
|
*
|
|
16
|
-
* Dropped:
|
|
17
|
-
*
|
|
18
|
-
*
|
|
21
|
+
* Dropped: drawing references (no shared form), each asset's `source` (local
|
|
22
|
+
* Storybook origin) and inline `data`. Assets with neither `data` nor `url`
|
|
23
|
+
* cannot be resolved by a reader and are omitted.
|
|
19
24
|
*/
|
|
20
25
|
function toSharedTopic(topic) {
|
|
21
26
|
const assets = [];
|
|
@@ -34,6 +39,11 @@ function toSharedTopic(topic) {
|
|
|
34
39
|
if (asset.data)
|
|
35
40
|
uploads.push({ id: asset.id, mime: asset.mime, data: asset.data });
|
|
36
41
|
}
|
|
42
|
+
const subsystemModels = (topic.subsystemModels ?? []).map((ref) => ({
|
|
43
|
+
modelId: ref.modelId,
|
|
44
|
+
...(ref.trailIds?.length ? { trailIds: [...ref.trailIds] } : {}),
|
|
45
|
+
}));
|
|
46
|
+
const references = (topic.references ?? []).filter((ref) => ref.kind !== 'drawing');
|
|
37
47
|
return {
|
|
38
48
|
topic: {
|
|
39
49
|
id: topic.id,
|
|
@@ -44,6 +54,8 @@ function toSharedTopic(topic) {
|
|
|
44
54
|
updatedAt: topic.updatedAt,
|
|
45
55
|
...(topic.createdBy ? { createdBy: { ...topic.createdBy } } : {}),
|
|
46
56
|
...(assets.length ? { assets } : {}),
|
|
57
|
+
...(subsystemModels.length ? { subsystemModels } : {}),
|
|
58
|
+
...(references.length ? { references: references.map((ref) => ({ ...ref })) } : {}),
|
|
47
59
|
},
|
|
48
60
|
uploads,
|
|
49
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic-share.js","sourceRoot":"","sources":["../../src/storage/topic-share.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"topic-share.js","sourceRoot":"","sources":["../../src/storage/topic-share.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAqDH;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,KAAiB;IAC7C,MAAM,MAAM,GAAuB,EAAE,CAAC;IACtC,MAAM,OAAO,GAAqC,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;YAAE,SAAS;QACzD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC;YACV,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KA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C1B,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpC,GAAG,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtD,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpF;QACD,OAAO;KACR,CAAC;AACJ,CAAC;AAxCD,sCAwCC;AAED,SAAS,YAAY,CAAC,KAAiB;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -22,7 +22,11 @@ export type {
|
|
|
22
22
|
} from './storage/topic-types';
|
|
23
23
|
export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
|
|
24
24
|
export { toSharedTopic } from './storage/topic-share';
|
|
25
|
-
export type { SharedTopic, SharedTopicAsset, SharedTopicProjection } from './storage/topic-share';
|
|
25
|
+
export type { SharedTopic, SharedTopicAsset, SharedTopicProjection, SharedTopicReference } from './storage/topic-share';
|
|
26
|
+
|
|
27
|
+
// Infrastructure-as-code read side: what wrangler / terraform declare, and the
|
|
28
|
+
// shape a live-deployment observation takes. Pure — text and JSON in.
|
|
29
|
+
export * from './infra';
|
|
26
30
|
|
|
27
31
|
// Cross-field validation (the rules the JSON Schema can't express). Structural
|
|
28
32
|
// (schema) validation is enforced per surface against
|
package/src/infra/c4.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link InfraManifest} → proposed C4 containers and edges.
|
|
3
|
+
*
|
|
4
|
+
* The full C4 model lives in the viewer package, which depends on this one, so
|
|
5
|
+
* the shapes here are structural: they are assignable to the viewer's
|
|
6
|
+
* `C4Container` / `C4Edge` without this package importing them (the same
|
|
7
|
+
* arrangement as `audit/c4.ts`).
|
|
8
|
+
*
|
|
9
|
+
* Everything produced is `proposed`. A config file is evidence that a
|
|
10
|
+
* deployable unit exists, not a reviewer's acceptance of it as architecture.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { InfraManifest, InfraResource, InfraResourceSource } from './types';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The configured anchor a container carries — which declared resource it is.
|
|
17
|
+
* Holds no live fact: whether it is running is a separate observation, joined
|
|
18
|
+
* on `resourceKey`.
|
|
19
|
+
*/
|
|
20
|
+
export interface InfraC4Deployment {
|
|
21
|
+
resourceKey: string;
|
|
22
|
+
provider: string;
|
|
23
|
+
resourceType: string;
|
|
24
|
+
name: string;
|
|
25
|
+
source: InfraResourceSource;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface InfraC4Container {
|
|
29
|
+
id: string;
|
|
30
|
+
kind: 'container';
|
|
31
|
+
containerKind: 'application' | 'data-store';
|
|
32
|
+
label: string;
|
|
33
|
+
technology: string;
|
|
34
|
+
state: 'proposed';
|
|
35
|
+
rationale: string;
|
|
36
|
+
deployment: InfraC4Deployment;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface InfraC4Edge {
|
|
40
|
+
id: string;
|
|
41
|
+
source: string;
|
|
42
|
+
target: string;
|
|
43
|
+
label: string;
|
|
44
|
+
draft: true;
|
|
45
|
+
mechanisms: string[];
|
|
46
|
+
count: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const TECHNOLOGY: Record<string, string> = {
|
|
50
|
+
'cloudflare:worker': 'Cloudflare Worker',
|
|
51
|
+
'cloudflare:r2_bucket': 'Cloudflare R2',
|
|
52
|
+
'cloudflare:d1_database': 'Cloudflare D1',
|
|
53
|
+
'cloudflare:kv_namespace': 'Cloudflare KV',
|
|
54
|
+
'cloudflare:queue': 'Cloudflare Queue',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Resource types that run code. Everything else is something code reads or writes. */
|
|
58
|
+
const APPLICATION_TYPES = new Set(['worker']);
|
|
59
|
+
|
|
60
|
+
/** Short suffix that keeps a store's id distinct from a same-named Worker. */
|
|
61
|
+
const ID_SUFFIX: Record<string, string> = {
|
|
62
|
+
r2_bucket: 'r2',
|
|
63
|
+
d1_database: 'd1',
|
|
64
|
+
kv_namespace: 'kv',
|
|
65
|
+
queue: 'queue',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function slug(text: string): string {
|
|
69
|
+
return text
|
|
70
|
+
.toLowerCase()
|
|
71
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
72
|
+
.replace(/^-+|-+$/g, '');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The stable C4 element id for a declared resource. */
|
|
76
|
+
export function infraContainerId(resource: Pick<InfraResource, 'resourceType' | 'label'>): string {
|
|
77
|
+
const suffix = ID_SUFFIX[resource.resourceType];
|
|
78
|
+
const base = slug(resource.label) || 'resource';
|
|
79
|
+
return `container:${suffix ? `${base}-${suffix}` : base}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The configured anchor for one resource. */
|
|
83
|
+
export function infraDeploymentRef(resource: InfraResource): InfraC4Deployment {
|
|
84
|
+
return {
|
|
85
|
+
resourceKey: resource.key,
|
|
86
|
+
provider: resource.provider,
|
|
87
|
+
resourceType: resource.resourceType,
|
|
88
|
+
name: resource.name,
|
|
89
|
+
source: resource.source,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Propose one container per declared resource and one edge per binding.
|
|
95
|
+
*
|
|
96
|
+
* A binding whose target no parsed file declares (a service binding to a
|
|
97
|
+
* Worker configured elsewhere) is dropped rather than drawn to nothing; merge
|
|
98
|
+
* the other config's manifest in first to keep it.
|
|
99
|
+
*/
|
|
100
|
+
export function infraToC4(manifest: InfraManifest): {
|
|
101
|
+
nodes: InfraC4Container[];
|
|
102
|
+
edges: InfraC4Edge[];
|
|
103
|
+
} {
|
|
104
|
+
const idByKey = new Map<string, string>();
|
|
105
|
+
const nodes = manifest.resources.map((resource): InfraC4Container => {
|
|
106
|
+
const id = infraContainerId(resource);
|
|
107
|
+
idByKey.set(resource.key, id);
|
|
108
|
+
const where = resource.source.pointer
|
|
109
|
+
? `${resource.source.file} at ${resource.source.pointer}`
|
|
110
|
+
: resource.source.file;
|
|
111
|
+
return {
|
|
112
|
+
id,
|
|
113
|
+
kind: 'container',
|
|
114
|
+
containerKind: APPLICATION_TYPES.has(resource.resourceType) ? 'application' : 'data-store',
|
|
115
|
+
label: resource.label,
|
|
116
|
+
technology:
|
|
117
|
+
TECHNOLOGY[`${resource.provider}:${resource.resourceType}`] ??
|
|
118
|
+
`${resource.provider} ${resource.resourceType}`,
|
|
119
|
+
state: 'proposed',
|
|
120
|
+
rationale: `Declared by ${resource.source.tool} in ${where}.`,
|
|
121
|
+
deployment: infraDeploymentRef(resource),
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const edges: InfraC4Edge[] = [];
|
|
126
|
+
for (const binding of manifest.bindings) {
|
|
127
|
+
const source = idByKey.get(binding.from);
|
|
128
|
+
const target = idByKey.get(binding.to);
|
|
129
|
+
if (!source || !target) continue;
|
|
130
|
+
edges.push({
|
|
131
|
+
id: `edge:${source}->${target}:${binding.binding}`,
|
|
132
|
+
source,
|
|
133
|
+
target,
|
|
134
|
+
label: `env.${binding.binding}`,
|
|
135
|
+
draft: true,
|
|
136
|
+
mechanisms: [],
|
|
137
|
+
count: 0,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return { nodes, edges };
|
|
141
|
+
}
|