@principal-ai/subsystems-core 0.52.0 → 0.53.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.
Files changed (214) hide show
  1. package/README.md +30 -2
  2. package/dist/audit/boundary.d.ts +104 -0
  3. package/dist/audit/boundary.d.ts.map +1 -0
  4. package/dist/audit/boundary.js +363 -0
  5. package/dist/audit/boundary.js.map +1 -0
  6. package/dist/audit/c4.d.ts +41 -0
  7. package/dist/audit/c4.d.ts.map +1 -0
  8. package/dist/audit/c4.js +41 -0
  9. package/dist/audit/c4.js.map +1 -0
  10. package/dist/audit/engine.d.ts +135 -0
  11. package/dist/audit/engine.d.ts.map +1 -0
  12. package/dist/audit/engine.js +865 -0
  13. package/dist/audit/engine.js.map +1 -0
  14. package/dist/audit/fixes.d.ts +80 -0
  15. package/dist/audit/fixes.d.ts.map +1 -0
  16. package/dist/audit/fixes.js +162 -0
  17. package/dist/audit/fixes.js.map +1 -0
  18. package/dist/audit/graphify-provider.d.ts +51 -0
  19. package/dist/audit/graphify-provider.d.ts.map +1 -0
  20. package/dist/audit/graphify-provider.js +36 -0
  21. package/dist/audit/graphify-provider.js.map +1 -0
  22. package/dist/audit/hash.d.ts +25 -0
  23. package/dist/audit/hash.d.ts.map +1 -0
  24. package/dist/audit/hash.js +53 -0
  25. package/dist/audit/hash.js.map +1 -0
  26. package/dist/audit/index.d.ts +12 -0
  27. package/dist/audit/index.d.ts.map +1 -0
  28. package/dist/audit/index.js +40 -0
  29. package/dist/audit/index.js.map +1 -0
  30. package/dist/audit/local-graphify.d.ts +75 -0
  31. package/dist/audit/local-graphify.d.ts.map +1 -0
  32. package/dist/audit/local-graphify.js +283 -0
  33. package/dist/audit/local-graphify.js.map +1 -0
  34. package/dist/audit/paths.d.ts +16 -0
  35. package/dist/audit/paths.d.ts.map +1 -0
  36. package/dist/audit/paths.js +31 -0
  37. package/dist/audit/paths.js.map +1 -0
  38. package/dist/audit/pure.d.ts +18 -0
  39. package/dist/audit/pure.d.ts.map +1 -0
  40. package/dist/audit/pure.js +50 -0
  41. package/dist/audit/pure.js.map +1 -0
  42. package/dist/audit/report-logic.d.ts +17 -0
  43. package/dist/audit/report-logic.d.ts.map +1 -0
  44. package/dist/audit/report-logic.js +206 -0
  45. package/dist/audit/report-logic.js.map +1 -0
  46. package/dist/audit/report.d.ts +140 -0
  47. package/dist/audit/report.d.ts.map +1 -0
  48. package/dist/audit/report.js +3 -0
  49. package/dist/audit/report.js.map +1 -0
  50. package/dist/audit/trail.d.ts +29 -0
  51. package/dist/audit/trail.d.ts.map +1 -0
  52. package/dist/audit/trail.js +59 -0
  53. package/dist/audit/trail.js.map +1 -0
  54. package/dist/audit/verification.d.ts +98 -0
  55. package/dist/audit/verification.d.ts.map +1 -0
  56. package/dist/audit/verification.js +11 -0
  57. package/dist/audit/verification.js.map +1 -0
  58. package/dist/audit/verify/component.d.ts +68 -0
  59. package/dist/audit/verify/component.d.ts.map +1 -0
  60. package/dist/audit/verify/component.js +500 -0
  61. package/dist/audit/verify/component.js.map +1 -0
  62. package/dist/audit/verify/declarations.d.ts +58 -0
  63. package/dist/audit/verify/declarations.d.ts.map +1 -0
  64. package/dist/audit/verify/declarations.js +227 -0
  65. package/dist/audit/verify/declarations.js.map +1 -0
  66. package/dist/audit/verify/grammar.d.ts +12 -0
  67. package/dist/audit/verify/grammar.d.ts.map +1 -0
  68. package/dist/audit/verify/grammar.js +57 -0
  69. package/dist/audit/verify/grammar.js.map +1 -0
  70. package/dist/audit/verify/index.d.ts +12 -0
  71. package/dist/audit/verify/index.d.ts.map +1 -0
  72. package/dist/audit/verify/index.js +31 -0
  73. package/dist/audit/verify/index.js.map +1 -0
  74. package/dist/audit/verify/parser.d.ts +19 -0
  75. package/dist/audit/verify/parser.d.ts.map +1 -0
  76. package/dist/audit/verify/parser.js +122 -0
  77. package/dist/audit/verify/parser.js.map +1 -0
  78. package/dist/audit/verify/span.d.ts +49 -0
  79. package/dist/audit/verify/span.d.ts.map +1 -0
  80. package/dist/audit/verify/span.js +377 -0
  81. package/dist/audit/verify/span.js.map +1 -0
  82. package/dist/graphify/anchor.d.ts +45 -0
  83. package/dist/graphify/anchor.d.ts.map +1 -0
  84. package/dist/graphify/anchor.js +179 -0
  85. package/dist/graphify/anchor.js.map +1 -0
  86. package/dist/graphify/consolidated.d.ts +259 -0
  87. package/dist/graphify/consolidated.d.ts.map +1 -0
  88. package/dist/graphify/consolidated.js +12 -0
  89. package/dist/graphify/consolidated.js.map +1 -0
  90. package/dist/graphify/construct.d.ts +41 -0
  91. package/dist/graphify/construct.d.ts.map +1 -0
  92. package/dist/graphify/construct.js +106 -0
  93. package/dist/graphify/construct.js.map +1 -0
  94. package/dist/graphify/ids.d.ts +19 -0
  95. package/dist/graphify/ids.d.ts.map +1 -0
  96. package/dist/graphify/ids.js +53 -0
  97. package/dist/graphify/ids.js.map +1 -0
  98. package/dist/graphify/index.d.ts +16 -0
  99. package/dist/graphify/index.d.ts.map +1 -0
  100. package/dist/graphify/index.js +32 -0
  101. package/dist/graphify/index.js.map +1 -0
  102. package/dist/graphify/resolve.d.ts +48 -0
  103. package/dist/graphify/resolve.d.ts.map +1 -0
  104. package/dist/graphify/resolve.js +89 -0
  105. package/dist/graphify/resolve.js.map +1 -0
  106. package/dist/graphify/signature.d.ts +87 -0
  107. package/dist/graphify/signature.d.ts.map +1 -0
  108. package/dist/graphify/signature.js +282 -0
  109. package/dist/graphify/signature.js.map +1 -0
  110. package/dist/graphify/types.d.ts +141 -0
  111. package/dist/graphify/types.d.ts.map +1 -0
  112. package/dist/graphify/types.js +9 -0
  113. package/dist/graphify/types.js.map +1 -0
  114. package/dist/index.d.ts +4 -0
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +9 -1
  117. package/dist/index.js.map +1 -1
  118. package/dist/infra/c4.d.ts +59 -0
  119. package/dist/infra/c4.d.ts.map +1 -0
  120. package/dist/infra/c4.js +106 -0
  121. package/dist/infra/c4.js.map +1 -0
  122. package/dist/infra/index.d.ts +13 -0
  123. package/dist/infra/index.d.ts.map +1 -0
  124. package/dist/infra/index.js +22 -0
  125. package/dist/infra/index.js.map +1 -0
  126. package/dist/infra/jsonc.d.ts +10 -0
  127. package/dist/infra/jsonc.d.ts.map +1 -0
  128. package/dist/infra/jsonc.js +77 -0
  129. package/dist/infra/jsonc.js.map +1 -0
  130. package/dist/infra/terraform.d.ts +41 -0
  131. package/dist/infra/terraform.d.ts.map +1 -0
  132. package/dist/infra/terraform.js +208 -0
  133. package/dist/infra/terraform.js.map +1 -0
  134. package/dist/infra/types.d.ts +107 -0
  135. package/dist/infra/types.d.ts.map +1 -0
  136. package/dist/infra/types.js +47 -0
  137. package/dist/infra/types.js.map +1 -0
  138. package/dist/infra/wrangler.d.ts +32 -0
  139. package/dist/infra/wrangler.d.ts.map +1 -0
  140. package/dist/infra/wrangler.js +177 -0
  141. package/dist/infra/wrangler.js.map +1 -0
  142. package/dist/node.d.ts +3 -0
  143. package/dist/node.d.ts.map +1 -1
  144. package/dist/node.js +4 -1
  145. package/dist/node.js.map +1 -1
  146. package/dist/storage/topic-reference-links.d.ts +3 -3
  147. package/dist/storage/topic-reference-links.d.ts.map +1 -1
  148. package/dist/storage/topic-reference-links.js +23 -8
  149. package/dist/storage/topic-reference-links.js.map +1 -1
  150. package/dist/storage/topic-share.d.ts +69 -0
  151. package/dist/storage/topic-share.d.ts.map +1 -0
  152. package/dist/storage/topic-share.js +67 -0
  153. package/dist/storage/topic-share.js.map +1 -0
  154. package/dist/storage/topic-types.d.ts +5 -1
  155. package/dist/storage/topic-types.d.ts.map +1 -1
  156. package/dist/types/subsystem-model.d.ts +59 -0
  157. package/dist/types/subsystem-model.d.ts.map +1 -1
  158. package/dist/types/subsystem-model.js +50 -1
  159. package/dist/types/subsystem-model.js.map +1 -1
  160. package/dist/validation.d.ts.map +1 -1
  161. package/dist/validation.js +25 -2
  162. package/dist/validation.js.map +1 -1
  163. package/package.json +22 -2
  164. package/schemas/subsystem-model.schema.json +35 -19
  165. package/src/audit/boundary.ts +447 -0
  166. package/src/audit/c4.ts +70 -0
  167. package/src/audit/engine.ts +1099 -0
  168. package/src/audit/fixes.ts +192 -0
  169. package/src/audit/graphify-provider.test.ts +58 -0
  170. package/src/audit/graphify-provider.ts +77 -0
  171. package/src/audit/hash.ts +58 -0
  172. package/src/audit/index.ts +34 -0
  173. package/src/audit/local-graphify.test.ts +163 -0
  174. package/src/audit/local-graphify.ts +354 -0
  175. package/src/audit/paths.ts +25 -0
  176. package/src/audit/pure.ts +91 -0
  177. package/src/audit/report-logic.test.ts +145 -0
  178. package/src/audit/report-logic.ts +245 -0
  179. package/src/audit/report.ts +207 -0
  180. package/src/audit/trail.ts +77 -0
  181. package/src/audit/verification.ts +104 -0
  182. package/src/audit/verify/component.ts +760 -0
  183. package/src/audit/verify/declarations.ts +284 -0
  184. package/src/audit/verify/grammar.ts +57 -0
  185. package/src/audit/verify/index.ts +41 -0
  186. package/src/audit/verify/parser.ts +124 -0
  187. package/src/audit/verify/span.ts +478 -0
  188. package/src/graphify/anchor.ts +206 -0
  189. package/src/graphify/consolidated.ts +298 -0
  190. package/src/graphify/construct.ts +153 -0
  191. package/src/graphify/ids.ts +48 -0
  192. package/src/graphify/index.ts +16 -0
  193. package/src/graphify/resolve.ts +115 -0
  194. package/src/graphify/signature.ts +354 -0
  195. package/src/graphify/types.ts +164 -0
  196. package/src/index.ts +10 -0
  197. package/src/infra/c4.ts +146 -0
  198. package/src/infra/index.ts +21 -0
  199. package/src/infra/infra.test.ts +360 -0
  200. package/src/infra/jsonc.ts +70 -0
  201. package/src/infra/terraform.ts +251 -0
  202. package/src/infra/types.ts +136 -0
  203. package/src/infra/wrangler.ts +203 -0
  204. package/src/node.ts +3 -0
  205. package/src/storage/topic-reference-links.test.ts +7 -1
  206. package/src/storage/topic-reference-links.ts +24 -8
  207. package/src/storage/topic-share.test.ts +91 -0
  208. package/src/storage/topic-share.ts +118 -0
  209. package/src/storage/topic-types.ts +3 -1
  210. package/src/storage/topicStore.test.ts +1 -0
  211. package/src/types/subsystem-model.test.ts +52 -2
  212. package/src/types/subsystem-model.ts +104 -0
  213. package/src/validation.test.ts +71 -7
  214. package/src/validation.ts +27 -2
@@ -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;IAC5B;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,YAAY,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,mBAAmB,CAAC;IAC5B,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;CAChB;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,32 @@
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
+ * A `containers` entry is a second deployable unit: a Cloudflare Container the
10
+ * Worker starts and routes to through a Durable Object. The access path is the
11
+ * Durable Object binding of the same class, so that is the edge.
12
+ *
13
+ * Secrets are not in a wrangler config, so anything reached through one (an
14
+ * external Postgres behind `DATABASE_URL`, say) is not declared here and cannot
15
+ * be read from it.
16
+ *
17
+ * Top-level config only. Named environments (`env.staging`) are not read yet.
18
+ */
19
+ import { type InfraManifest } from './types';
20
+ export interface ExtractWranglerOptions {
21
+ /** Repo-root-relative path of the config, recorded on every source. */
22
+ file: string;
23
+ }
24
+ /**
25
+ * Read a wrangler config. Accepts JSONC text or an already-parsed object, so a
26
+ * caller holding a `wrangler.toml` can parse it and pass the result.
27
+ *
28
+ * Returns an empty manifest when the config names no Worker. Malformed JSONC
29
+ * text throws `SyntaxError`.
30
+ */
31
+ export declare function extractWranglerManifest(config: string | unknown, options: ExtractWranglerOptions): InfraManifest;
32
+ //# sourceMappingURL=wrangler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/infra/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;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,CAkHf"}
@@ -0,0 +1,177 @@
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
+ * A `containers` entry is a second deployable unit: a Cloudflare Container the
11
+ * Worker starts and routes to through a Durable Object. The access path is the
12
+ * Durable Object binding of the same class, so that is the edge.
13
+ *
14
+ * Secrets are not in a wrangler config, so anything reached through one (an
15
+ * external Postgres behind `DATABASE_URL`, say) is not declared here and cannot
16
+ * be read from it.
17
+ *
18
+ * Top-level config only. Named environments (`env.staging`) are not read yet.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.extractWranglerManifest = void 0;
22
+ const jsonc_1 = require("./jsonc");
23
+ const types_1 = require("./types");
24
+ const PROVIDER = 'cloudflare';
25
+ function isObject(value) {
26
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
27
+ }
28
+ function str(value) {
29
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
30
+ }
31
+ const BINDING_FAMILIES = [
32
+ { path: ['kv_namespaces'], resourceType: 'kv_namespace', bindingField: 'binding', identifierField: 'id' },
33
+ { path: ['r2_buckets'], resourceType: 'r2_bucket', bindingField: 'binding', identifierField: 'bucket_name' },
34
+ {
35
+ path: ['d1_databases'],
36
+ resourceType: 'd1_database',
37
+ bindingField: 'binding',
38
+ identifierField: 'database_name',
39
+ idField: 'database_id',
40
+ },
41
+ { path: ['queues', 'producers'], resourceType: 'queue', bindingField: 'binding', identifierField: 'queue' },
42
+ { path: ['services'], resourceType: 'worker', bindingField: 'binding', identifierField: 'service' },
43
+ ];
44
+ /** A KV namespace is declared by opaque id only, so the binding names it. */
45
+ const OPAQUE_IDENTIFIER = new Set(['kv_namespace']);
46
+ /**
47
+ * Read a wrangler config. Accepts JSONC text or an already-parsed object, so a
48
+ * caller holding a `wrangler.toml` can parse it and pass the result.
49
+ *
50
+ * Returns an empty manifest when the config names no Worker. Malformed JSONC
51
+ * text throws `SyntaxError`.
52
+ */
53
+ function extractWranglerManifest(config, options) {
54
+ const root = typeof config === 'string' ? (0, jsonc_1.parseJsonc)(config) : config;
55
+ if (!isObject(root))
56
+ return { resources: [], bindings: [] };
57
+ const workerName = str(root.name);
58
+ if (!workerName)
59
+ return { resources: [], bindings: [] };
60
+ const source = (pointer) => ({
61
+ tool: 'wrangler',
62
+ file: options.file,
63
+ pointer,
64
+ });
65
+ const workerKey = (0, types_1.infraResourceKey)(PROVIDER, 'worker', workerName);
66
+ const workerAttributes = {};
67
+ const main = str(root.main);
68
+ if (main)
69
+ workerAttributes.main = main;
70
+ if (isObject(root.assets))
71
+ workerAttributes.assets = 'true';
72
+ const crons = isObject(root.triggers) ? root.triggers.crons : undefined;
73
+ if (Array.isArray(crons) && crons.length > 0) {
74
+ workerAttributes.crons = crons.filter((c) => typeof c === 'string').join(', ');
75
+ }
76
+ const resources = [
77
+ {
78
+ key: workerKey,
79
+ provider: PROVIDER,
80
+ resourceType: 'worker',
81
+ name: workerName,
82
+ label: workerName,
83
+ source: source(''),
84
+ ...(Object.keys(workerAttributes).length > 0 ? { attributes: workerAttributes } : {}),
85
+ },
86
+ ];
87
+ const bindings = [];
88
+ for (const family of BINDING_FAMILIES) {
89
+ let entries = root;
90
+ for (const segment of family.path) {
91
+ entries = isObject(entries) ? entries[segment] : undefined;
92
+ }
93
+ if (!Array.isArray(entries))
94
+ continue;
95
+ entries.forEach((entry, index) => {
96
+ if (!isObject(entry))
97
+ return;
98
+ const binding = str(entry[family.bindingField]);
99
+ const identifier = str(entry[family.identifierField]);
100
+ if (!binding || !identifier)
101
+ return;
102
+ const pointer = `/${family.path.join('/')}/${index}`;
103
+ const key = (0, types_1.infraResourceKey)(PROVIDER, family.resourceType, identifier);
104
+ const id = family.idField ? str(entry[family.idField]) : undefined;
105
+ // A service binding points at another Worker, which its own config
106
+ // declares; emit the access path but not a second declaration of it.
107
+ if (family.resourceType !== 'worker') {
108
+ resources.push({
109
+ key,
110
+ provider: PROVIDER,
111
+ resourceType: family.resourceType,
112
+ name: identifier,
113
+ label: OPAQUE_IDENTIFIER.has(family.resourceType) ? binding : identifier,
114
+ source: source(pointer),
115
+ ...(id ? { attributes: { id } } : {}),
116
+ });
117
+ }
118
+ bindings.push({ from: workerKey, to: key, binding, source: source(pointer) });
119
+ });
120
+ }
121
+ // Containers. Wrangler names the application `<worker>-<class_name>`,
122
+ // lowercased with spaces dashed, unless the entry names it.
123
+ const durableBindings = isObject(root.durable_objects) ? root.durable_objects.bindings : undefined;
124
+ const containers = Array.isArray(root.containers) ? root.containers : [];
125
+ containers.forEach((entry, index) => {
126
+ if (!isObject(entry))
127
+ return;
128
+ const className = str(entry.class_name);
129
+ const name = str(entry.name) ??
130
+ (className ? `${workerName}-${className}`.toLowerCase().replace(/ /g, '-') : undefined);
131
+ if (!name)
132
+ return;
133
+ const pointer = `/containers/${index}`;
134
+ const key = (0, types_1.infraResourceKey)(PROVIDER, 'container', name);
135
+ const attributes = {};
136
+ const image = str(entry.image);
137
+ if (image)
138
+ attributes.image = image;
139
+ const instanceType = str(entry.instance_type);
140
+ if (instanceType)
141
+ attributes.instanceType = instanceType;
142
+ if (typeof entry.max_instances === 'number') {
143
+ attributes.maxInstances = String(entry.max_instances);
144
+ }
145
+ resources.push({
146
+ key,
147
+ provider: PROVIDER,
148
+ resourceType: 'container',
149
+ name,
150
+ label: className ?? name,
151
+ source: source(pointer),
152
+ ...(Object.keys(attributes).length > 0 ? { attributes } : {}),
153
+ });
154
+ if (!className || !Array.isArray(durableBindings))
155
+ return;
156
+ durableBindings.forEach((durable, durableIndex) => {
157
+ if (!isObject(durable) || str(durable.class_name) !== className)
158
+ return;
159
+ // A binding with `script_name` reaches a class another Worker defines.
160
+ const script = str(durable.script_name);
161
+ if (script && script !== workerName)
162
+ return;
163
+ const binding = str(durable.name);
164
+ if (!binding)
165
+ return;
166
+ bindings.push({
167
+ from: workerKey,
168
+ to: key,
169
+ binding,
170
+ source: source(`/durable_objects/bindings/${durableIndex}`),
171
+ });
172
+ });
173
+ });
174
+ return { resources, bindings };
175
+ }
176
+ exports.extractWranglerManifest = extractWranglerManifest;
177
+ //# sourceMappingURL=wrangler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../src/infra/wrangler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;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,E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C,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,SAAS;gBAAE,OAAO;YACxE,uEAAuE;YACvE,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACxC,IAAI,MAAM,IAAI,MAAM,KAAK,UAAU;gBAAE,OAAO;YAC5C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,SAAS;gBACf,EAAE,EAAE,GAAG;gBACP,OAAO;gBACP,MAAM,EAAE,MAAM,CAAC,6BAA6B,YAAY,EAAE,CAAC;aAC5D,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC;AArHD,0DAqHC"}
package/dist/node.d.ts CHANGED
@@ -7,10 +7,13 @@
7
7
  * (no better-sqlite3 native binding).
8
8
  */
9
9
  export * from './types';
10
+ export * from './audit';
10
11
  export { TopicStore, PRINCIPAL_DIR, TOPICS_DIR, LEGACY_TOPICS_BLOB, } from './storage/topicStore';
11
12
  export type { TopicIndexEntry, TopicCreate, TopicUpdate, MigrationResult, } from './storage/topicStore';
12
13
  export type { DraftTopic, TopicAsset, TopicCreator, TopicSubsystemModelRef, TopicReference, } from './storage/topic-types';
13
14
  export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
15
+ export { toSharedTopic } from './storage/topic-share';
16
+ export type { SharedTopic, SharedTopicAsset, SharedTopicProjection, SharedTopicReference } from './storage/topic-share';
14
17
  export { OpenCodeEventStore, defaultOpenCodeDBPath } from './opencode/OpenCodeEventStore';
15
18
  export type { OpenCodeRawEvent, OpenCodeSessionEvents, OpenCodeEventRetriever, OpenCodeStoreOptions, SessionSummary, SessionListResult, } from './opencode/types';
16
19
  export { listAgentSessions, detectAgent, fetchRawEvents } from './opencode/agent-sessions';
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,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,iCAAiC,CAAC;AAGpG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1F,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3F,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,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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,EAChB,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/node.js CHANGED
@@ -22,8 +22,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
22
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.opencodeRowsToUniversalEvents = exports.collectRepositories = exports.accumulateEvents = exports.normalizeEventsWithAdapter = exports.normalizeEvents = exports.NodePathNormalizationAdapter = exports.buildAgentSessionFixture = exports.fetchRawEvents = exports.detectAgent = exports.listAgentSessions = exports.defaultOpenCodeDBPath = exports.OpenCodeEventStore = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = exports.LEGACY_TOPICS_BLOB = exports.TOPICS_DIR = exports.PRINCIPAL_DIR = exports.TopicStore = void 0;
25
+ exports.opencodeRowsToUniversalEvents = exports.collectRepositories = exports.accumulateEvents = exports.normalizeEventsWithAdapter = exports.normalizeEvents = exports.NodePathNormalizationAdapter = exports.buildAgentSessionFixture = exports.fetchRawEvents = exports.detectAgent = exports.listAgentSessions = exports.defaultOpenCodeDBPath = exports.OpenCodeEventStore = exports.toSharedTopic = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = exports.LEGACY_TOPICS_BLOB = exports.TOPICS_DIR = exports.PRINCIPAL_DIR = exports.TopicStore = void 0;
26
26
  __exportStar(require("./types"), exports);
27
+ __exportStar(require("./audit"), exports);
27
28
  // File-per-topic store (~/.principal/topics) — node:fs only
28
29
  var topicStore_1 = require("./storage/topicStore");
29
30
  Object.defineProperty(exports, "TopicStore", { enumerable: true, get: function () { return topicStore_1.TopicStore; } });
@@ -33,6 +34,8 @@ Object.defineProperty(exports, "LEGACY_TOPICS_BLOB", { enumerable: true, get: fu
33
34
  var topic_reference_links_1 = require("./storage/topic-reference-links");
34
35
  Object.defineProperty(exports, "formatTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.formatTopicReferenceLink; } });
35
36
  Object.defineProperty(exports, "parseTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.parseTopicReferenceLink; } });
37
+ var topic_share_1 = require("./storage/topic-share");
38
+ Object.defineProperty(exports, "toSharedTopic", { enumerable: true, get: function () { return topic_share_1.toSharedTopic; } });
36
39
  // OpenCode event retrieval (Node.js only - SQLite)
37
40
  var OpenCodeEventStore_1 = require("./opencode/OpenCodeEventStore");
38
41
  Object.defineProperty(exports, "OpenCodeEventStore", { enumerable: true, get: function () { return OpenCodeEventStore_1.OpenCodeEventStore; } });
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AAExB,4DAA4D;AAC5D,mDAK8B;AAJ5B,wGAAA,UAAU,OAAA;AACV,2GAAA,aAAa,OAAA;AACb,wGAAA,UAAU,OAAA;AACV,gHAAA,kBAAkB,OAAA;AAepB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAE1D,mDAAmD;AACnD,oEAA0F;AAAjF,wHAAA,kBAAkB,OAAA;AAAE,2HAAA,qBAAqB,OAAA;AAUlD,iEAAiE;AACjE,4DAA2F;AAAlF,mHAAA,iBAAiB,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,gHAAA,cAAc,OAAA;AAOvD,mDAAmD;AACnD,oDAAoE;AAA3D,mHAAA,wBAAwB,OAAA;AAWjC,sEAAsE;AACtE,gDAO6B;AAN3B,wHAAA,4BAA4B,OAAA;AAC5B,2GAAA,eAAe,OAAA;AACf,sHAAA,0BAA0B,OAAA;AAC1B,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,yHAAA,6BAA6B,OAAA"}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,0CAAwB;AAExB,4DAA4D;AAC5D,mDAK8B;AAJ5B,wGAAA,UAAU,OAAA;AACV,2GAAA,aAAa,OAAA;AACb,wGAAA,UAAU,OAAA;AACV,gHAAA,kBAAkB,OAAA;AAepB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAC1D,qDAAsD;AAA7C,4GAAA,aAAa,OAAA;AAGtB,mDAAmD;AACnD,oEAA0F;AAAjF,wHAAA,kBAAkB,OAAA;AAAE,2HAAA,qBAAqB,OAAA;AAUlD,iEAAiE;AACjE,4DAA2F;AAAlF,mHAAA,iBAAiB,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,gHAAA,cAAc,OAAA;AAOvD,mDAAmD;AACnD,oDAAoE;AAA3D,mHAAA,wBAAwB,OAAA;AAWjC,sEAAsE;AACtE,gDAO6B;AAN3B,wHAAA,4BAA4B,OAAA;AAC5B,2GAAA,eAAe,OAAA;AACf,sHAAA,0BAA0B,OAAA;AAC1B,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,yHAAA,6BAA6B,OAAA"}
@@ -2,9 +2,9 @@ import type { TopicReference } from './topic-types';
2
2
  /** Format a Markdown-safe href. Does not attach or resolve the target. */
3
3
  export declare function formatTopicReferenceLink(reference: TopicReference): string;
4
4
  /**
5
- * Parse a local topic/sketch href without I/O. Unknown kinds, malformed escapes,
6
- * extra path segments, queries, and fragments return null. Target existence and
7
- * navigation belong to the host. Parsing never creates an attachment.
5
+ * Parse a local topic/sketch/drawing href without I/O. Unknown kinds, malformed
6
+ * escapes, extra path segments, queries, and fragments return null. Target
7
+ * existence and navigation belong to the host. Parsing never creates an attachment.
8
8
  */
9
9
  export declare function parseTopicReferenceLink(href: string): TopicReference | null;
10
10
  //# sourceMappingURL=topic-reference-links.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"topic-reference-links.d.ts","sourceRoot":"","sources":["../../src/storage/topic-reference-links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAQpD,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,cAAc,GAAG,MAAM,CAQ1E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAa3E"}
1
+ {"version":3,"file":"topic-reference-links.d.ts","sourceRoot":"","sources":["../../src/storage/topic-reference-links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAmBpD,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,cAAc,GAAG,MAAM,CAQ1E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAkB3E"}
@@ -6,9 +6,19 @@ exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = void 0;
6
6
  function isReferenceId(id) {
7
7
  return id.length > 0 && id !== '.' && id !== '..' && !/[/\\\s\u0000-\u001f\u007f]/.test(id);
8
8
  }
9
+ function referenceId(reference) {
10
+ switch (reference.kind) {
11
+ case 'topic':
12
+ return reference.topicId;
13
+ case 'c4-sketch':
14
+ return reference.sketchId;
15
+ case 'drawing':
16
+ return reference.drawingId;
17
+ }
18
+ }
9
19
  /** Format a Markdown-safe href. Does not attach or resolve the target. */
10
20
  function formatTopicReferenceLink(reference) {
11
- const id = reference.kind === 'topic' ? reference.topicId : reference.sketchId;
21
+ const id = referenceId(reference);
12
22
  if (!isReferenceId(id))
13
23
  throw new Error('Invalid topic reference id');
14
24
  const encoded = encodeURIComponent(id).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
@@ -16,12 +26,12 @@ function formatTopicReferenceLink(reference) {
16
26
  }
17
27
  exports.formatTopicReferenceLink = formatTopicReferenceLink;
18
28
  /**
19
- * Parse a local topic/sketch href without I/O. Unknown kinds, malformed escapes,
20
- * extra path segments, queries, and fragments return null. Target existence and
21
- * navigation belong to the host. Parsing never creates an attachment.
29
+ * Parse a local topic/sketch/drawing href without I/O. Unknown kinds, malformed
30
+ * escapes, extra path segments, queries, and fragments return null. Target
31
+ * existence and navigation belong to the host. Parsing never creates an attachment.
22
32
  */
23
33
  function parseTopicReferenceLink(href) {
24
- const match = /^principal:\/\/(topic|c4-sketch)\/([^/?#]+)$/.exec(href);
34
+ const match = /^principal:\/\/(topic|c4-sketch|drawing)\/([^/?#]+)$/.exec(href);
25
35
  if (!match)
26
36
  return null;
27
37
  let id;
@@ -33,9 +43,14 @@ function parseTopicReferenceLink(href) {
33
43
  }
34
44
  if (!isReferenceId(id))
35
45
  return null;
36
- return match[1] === 'topic'
37
- ? { kind: 'topic', topicId: id }
38
- : { kind: 'c4-sketch', sketchId: id };
46
+ switch (match[1]) {
47
+ case 'topic':
48
+ return { kind: 'topic', topicId: id };
49
+ case 'c4-sketch':
50
+ return { kind: 'c4-sketch', sketchId: id };
51
+ default:
52
+ return { kind: 'drawing', drawingId: id };
53
+ }
39
54
  }
40
55
  exports.parseTopicReferenceLink = parseTopicReferenceLink;
41
56
  //# sourceMappingURL=topic-reference-links.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"topic-reference-links.js","sourceRoot":"","sources":["../../src/storage/topic-reference-links.ts"],"names":[],"mappings":";;;AAEA,0EAA0E;AAC1E,oEAAoE;AACpE,SAAS,aAAa,CAAC,EAAU;IAC/B,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC;AAED,0EAA0E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AAC,CAAC,CAAC,CAAC,CAAC;KACnC;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;IACD,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE;QAChB,KAAK,OAAO;YACV,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QACxC,KAAK,WAAW;YACd,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QAC7C;YACE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;KAC7C;AACH,CAAC;AAlBD,0DAkBC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Portable projection of a topic for sharing outside the machine that authored
3
+ * it. Browser-safe (no `node:*`).
4
+ *
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.
14
+ */
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
+ }>;
20
+ /** An image a shared topic refers to. Bytes travel separately, keyed by `id`. */
21
+ export interface SharedTopicAsset {
22
+ /** Content hash; the `asset://<id>` target in the description. */
23
+ id: string;
24
+ /** MIME type, e.g. "image/png". */
25
+ mime: string;
26
+ /** Resolvable URL, when the bytes already live somewhere public. */
27
+ url?: string;
28
+ /** Markdown alt text. */
29
+ alt?: string;
30
+ }
31
+ /**
32
+ * A topic as it leaves the authoring machine. No inline bytes; `description`
33
+ * is unchanged, so `asset://<id>` links still resolve against `assets`.
34
+ */
35
+ export interface SharedTopic {
36
+ id: string;
37
+ title: string;
38
+ description?: string;
39
+ /** Repositories as PURL strings. */
40
+ repos?: string[];
41
+ /** ISO 8601. */
42
+ createdAt: string;
43
+ /** ISO 8601. */
44
+ updatedAt: string;
45
+ createdBy?: TopicCreator;
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[];
51
+ }
52
+ export interface SharedTopicProjection {
53
+ topic: SharedTopic;
54
+ /** Assets whose bytes must be uploaded alongside the topic (those with `data`). */
55
+ uploads: Array<{
56
+ id: string;
57
+ mime: string;
58
+ data: string;
59
+ }>;
60
+ }
61
+ /**
62
+ * Project a local topic into its shared form.
63
+ *
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.
67
+ */
68
+ export declare function toSharedTopic(topic: DraftTopic): SharedTopicProjection;
69
+ //# sourceMappingURL=topic-share.d.ts.map
@@ -0,0 +1 @@
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,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAEvB,8EAA8E;AAC9E,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAEhF,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,mCAAmC;IACnC,IAAI,E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