@principal-ai/subsystems-core 0.52.0 → 0.53.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.
Files changed (220) 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 +10 -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 +17 -0
  123. package/dist/infra/index.d.ts.map +1 -0
  124. package/dist/infra/index.js +30 -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/observe.d.ts +102 -0
  131. package/dist/infra/observe.d.ts.map +1 -0
  132. package/dist/infra/observe.js +347 -0
  133. package/dist/infra/observe.js.map +1 -0
  134. package/dist/infra/terraform.d.ts +41 -0
  135. package/dist/infra/terraform.d.ts.map +1 -0
  136. package/dist/infra/terraform.js +208 -0
  137. package/dist/infra/terraform.js.map +1 -0
  138. package/dist/infra/types.d.ts +107 -0
  139. package/dist/infra/types.d.ts.map +1 -0
  140. package/dist/infra/types.js +47 -0
  141. package/dist/infra/types.js.map +1 -0
  142. package/dist/infra/wrangler.d.ts +32 -0
  143. package/dist/infra/wrangler.d.ts.map +1 -0
  144. package/dist/infra/wrangler.js +177 -0
  145. package/dist/infra/wrangler.js.map +1 -0
  146. package/dist/node.d.ts +3 -0
  147. package/dist/node.d.ts.map +1 -1
  148. package/dist/node.js +4 -1
  149. package/dist/node.js.map +1 -1
  150. package/dist/storage/topic-reference-links.d.ts +3 -3
  151. package/dist/storage/topic-reference-links.d.ts.map +1 -1
  152. package/dist/storage/topic-reference-links.js +23 -8
  153. package/dist/storage/topic-reference-links.js.map +1 -1
  154. package/dist/storage/topic-share.d.ts +69 -0
  155. package/dist/storage/topic-share.d.ts.map +1 -0
  156. package/dist/storage/topic-share.js +67 -0
  157. package/dist/storage/topic-share.js.map +1 -0
  158. package/dist/storage/topic-types.d.ts +5 -1
  159. package/dist/storage/topic-types.d.ts.map +1 -1
  160. package/dist/types/subsystem-model.d.ts +59 -0
  161. package/dist/types/subsystem-model.d.ts.map +1 -1
  162. package/dist/types/subsystem-model.js +50 -1
  163. package/dist/types/subsystem-model.js.map +1 -1
  164. package/dist/validation.d.ts.map +1 -1
  165. package/dist/validation.js +25 -2
  166. package/dist/validation.js.map +1 -1
  167. package/package.json +22 -2
  168. package/schemas/subsystem-model.schema.json +35 -19
  169. package/src/audit/boundary.ts +447 -0
  170. package/src/audit/c4.ts +70 -0
  171. package/src/audit/engine.ts +1099 -0
  172. package/src/audit/fixes.ts +192 -0
  173. package/src/audit/graphify-provider.test.ts +58 -0
  174. package/src/audit/graphify-provider.ts +77 -0
  175. package/src/audit/hash.ts +58 -0
  176. package/src/audit/index.ts +34 -0
  177. package/src/audit/local-graphify.test.ts +163 -0
  178. package/src/audit/local-graphify.ts +354 -0
  179. package/src/audit/paths.ts +25 -0
  180. package/src/audit/pure.ts +91 -0
  181. package/src/audit/report-logic.test.ts +145 -0
  182. package/src/audit/report-logic.ts +245 -0
  183. package/src/audit/report.ts +207 -0
  184. package/src/audit/trail.ts +77 -0
  185. package/src/audit/verification.ts +104 -0
  186. package/src/audit/verify/component.ts +760 -0
  187. package/src/audit/verify/declarations.ts +284 -0
  188. package/src/audit/verify/grammar.ts +57 -0
  189. package/src/audit/verify/index.ts +41 -0
  190. package/src/audit/verify/parser.ts +124 -0
  191. package/src/audit/verify/span.ts +478 -0
  192. package/src/graphify/anchor.ts +206 -0
  193. package/src/graphify/consolidated.ts +298 -0
  194. package/src/graphify/construct.ts +153 -0
  195. package/src/graphify/ids.ts +48 -0
  196. package/src/graphify/index.ts +16 -0
  197. package/src/graphify/resolve.ts +115 -0
  198. package/src/graphify/signature.ts +354 -0
  199. package/src/graphify/types.ts +164 -0
  200. package/src/index.ts +11 -0
  201. package/src/infra/c4.ts +146 -0
  202. package/src/infra/index.ts +36 -0
  203. package/src/infra/infra.test.ts +360 -0
  204. package/src/infra/jsonc.ts +70 -0
  205. package/src/infra/observe.test.ts +202 -0
  206. package/src/infra/observe.ts +451 -0
  207. package/src/infra/terraform.ts +251 -0
  208. package/src/infra/types.ts +136 -0
  209. package/src/infra/wrangler.ts +203 -0
  210. package/src/node.ts +3 -0
  211. package/src/storage/topic-reference-links.test.ts +7 -1
  212. package/src/storage/topic-reference-links.ts +24 -8
  213. package/src/storage/topic-share.test.ts +91 -0
  214. package/src/storage/topic-share.ts +118 -0
  215. package/src/storage/topic-types.ts +3 -1
  216. package/src/storage/topicStore.test.ts +1 -0
  217. package/src/types/subsystem-model.test.ts +52 -2
  218. package/src/types/subsystem-model.ts +104 -0
  219. package/src/validation.test.ts +71 -7
  220. package/src/validation.ts +27 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,SAAS,CAAC;AAExB,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;AAKpG,OAAO,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,SAAS,CAAC;AAExB,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;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAKxH,cAAc,SAAS,CAAC;AAKxB,OAAO,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAI/D,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -26,14 +26,23 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.validateSubsystemModelCrossField = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = void 0;
29
+ exports.validateSubsystemModelCrossField = exports.toSharedTopic = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = void 0;
30
30
  __exportStar(require("./types"), exports);
31
31
  var topic_reference_links_1 = require("./storage/topic-reference-links");
32
32
  Object.defineProperty(exports, "formatTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.formatTopicReferenceLink; } });
33
33
  Object.defineProperty(exports, "parseTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.parseTopicReferenceLink; } });
34
+ var topic_share_1 = require("./storage/topic-share");
35
+ Object.defineProperty(exports, "toSharedTopic", { enumerable: true, get: function () { return topic_share_1.toSharedTopic; } });
36
+ // Infrastructure-as-code read side: what wrangler / terraform declare, the
37
+ // shape a live-deployment observation takes, and the checks that produce one
38
+ // from a credential the caller supplies. Browser-safe — no Node built-ins.
39
+ __exportStar(require("./infra"), exports);
34
40
  // Cross-field validation (the rules the JSON Schema can't express). Structural
35
41
  // (schema) validation is enforced per surface against
36
42
  // `schemas/subsystem-model.schema.json`.
37
43
  var validation_1 = require("./validation");
38
44
  Object.defineProperty(exports, "validateSubsystemModelCrossField", { enumerable: true, get: function () { return validation_1.validateSubsystemModelCrossField; } });
45
+ // Audit policy and report rules are runtime-neutral. The Node-only engine lives
46
+ // behind `./audit` so the main entry never pulls in filesystem/crypto.
47
+ __exportStar(require("./audit/pure"), exports);
39
48
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AASxB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAE1D,+EAA+E;AAC/E,sDAAsD;AACtD,yCAAyC;AACzC,2CAAgE;AAAvD,8HAAA,gCAAgC,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AASxB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAC1D,qDAAsD;AAA7C,4GAAA,aAAa,OAAA;AAGtB,2EAA2E;AAC3E,6EAA6E;AAC7E,2EAA2E;AAC3E,0CAAwB;AAExB,+EAA+E;AAC/E,sDAAsD;AACtD,yCAAyC;AACzC,2CAAgE;AAAvD,8HAAA,gCAAgC,OAAA;AAGzC,gFAAgF;AAChF,uEAAuE;AACvE,+CAA6B"}
@@ -0,0 +1,59 @@
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
+ import type { InfraManifest, InfraResource, InfraResourceSource } from './types';
13
+ /**
14
+ * The configured anchor a container carries — which declared resource it is.
15
+ * Holds no live fact: whether it is running is a separate observation, joined
16
+ * on `resourceKey`.
17
+ */
18
+ export interface InfraC4Deployment {
19
+ resourceKey: string;
20
+ provider: string;
21
+ resourceType: string;
22
+ name: string;
23
+ source: InfraResourceSource;
24
+ }
25
+ export interface InfraC4Container {
26
+ id: string;
27
+ kind: 'container';
28
+ containerKind: 'application' | 'data-store';
29
+ label: string;
30
+ technology: string;
31
+ state: 'proposed';
32
+ rationale: string;
33
+ deployment: InfraC4Deployment;
34
+ }
35
+ export interface InfraC4Edge {
36
+ id: string;
37
+ source: string;
38
+ target: string;
39
+ label: string;
40
+ draft: true;
41
+ mechanisms: string[];
42
+ count: number;
43
+ }
44
+ /** The stable C4 element id for a declared resource. */
45
+ export declare function infraContainerId(resource: Pick<InfraResource, 'resourceType' | 'label'>): string;
46
+ /** The configured anchor for one resource. */
47
+ export declare function infraDeploymentRef(resource: InfraResource): InfraC4Deployment;
48
+ /**
49
+ * Propose one container per declared resource and one edge per binding.
50
+ *
51
+ * A binding whose target no parsed file declares (a service binding to a
52
+ * Worker configured elsewhere) is dropped rather than drawn to nothing; merge
53
+ * the other config's manifest in first to keep it.
54
+ */
55
+ export declare function infraToC4(manifest: InfraManifest): {
56
+ nodes: InfraC4Container[];
57
+ edges: InfraC4Edge[];
58
+ };
59
+ //# sourceMappingURL=c4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4.d.ts","sourceRoot":"","sources":["../../src/infra/c4.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEjF;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,EAAE,aAAa,GAAG,YAAY,CAAC;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,iBAAiB,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAiCD,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,GAAG,OAAO,CAAC,GAAG,MAAM,CAIhG;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,iBAAiB,CAQ7E;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG;IAClD,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB,CAsCA"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /**
3
+ * {@link InfraManifest} → proposed C4 containers and edges.
4
+ *
5
+ * The full C4 model lives in the viewer package, which depends on this one, so
6
+ * the shapes here are structural: they are assignable to the viewer's
7
+ * `C4Container` / `C4Edge` without this package importing them (the same
8
+ * arrangement as `audit/c4.ts`).
9
+ *
10
+ * Everything produced is `proposed`. A config file is evidence that a
11
+ * deployable unit exists, not a reviewer's acceptance of it as architecture.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.infraToC4 = exports.infraDeploymentRef = exports.infraContainerId = void 0;
15
+ const TECHNOLOGY = {
16
+ 'cloudflare:worker': 'Cloudflare Worker',
17
+ 'cloudflare:r2_bucket': 'Cloudflare R2',
18
+ 'cloudflare:d1_database': 'Cloudflare D1',
19
+ 'cloudflare:kv_namespace': 'Cloudflare KV',
20
+ 'cloudflare:queue': 'Cloudflare Queue',
21
+ 'cloudflare:container': 'Cloudflare Container',
22
+ // Not read from any config yet — here so a hand-declared resource reads well.
23
+ 'neon:database': 'Neon Postgres',
24
+ };
25
+ /** Resource types that run code. Everything else is something code reads or writes. */
26
+ const APPLICATION_TYPES = new Set(['worker', 'container']);
27
+ /** Short suffix that keeps a store's id distinct from a same-named Worker. */
28
+ const ID_SUFFIX = {
29
+ r2_bucket: 'r2',
30
+ d1_database: 'd1',
31
+ kv_namespace: 'kv',
32
+ queue: 'queue',
33
+ container: 'container',
34
+ database: 'db',
35
+ };
36
+ function slug(text) {
37
+ return text
38
+ .toLowerCase()
39
+ .replace(/[^a-z0-9]+/g, '-')
40
+ .replace(/^-+|-+$/g, '');
41
+ }
42
+ /** The stable C4 element id for a declared resource. */
43
+ function infraContainerId(resource) {
44
+ const suffix = ID_SUFFIX[resource.resourceType];
45
+ const base = slug(resource.label) || 'resource';
46
+ return `container:${suffix ? `${base}-${suffix}` : base}`;
47
+ }
48
+ exports.infraContainerId = infraContainerId;
49
+ /** The configured anchor for one resource. */
50
+ function infraDeploymentRef(resource) {
51
+ return {
52
+ resourceKey: resource.key,
53
+ provider: resource.provider,
54
+ resourceType: resource.resourceType,
55
+ name: resource.name,
56
+ source: resource.source,
57
+ };
58
+ }
59
+ exports.infraDeploymentRef = infraDeploymentRef;
60
+ /**
61
+ * Propose one container per declared resource and one edge per binding.
62
+ *
63
+ * A binding whose target no parsed file declares (a service binding to a
64
+ * Worker configured elsewhere) is dropped rather than drawn to nothing; merge
65
+ * the other config's manifest in first to keep it.
66
+ */
67
+ function infraToC4(manifest) {
68
+ const idByKey = new Map();
69
+ const nodes = manifest.resources.map((resource) => {
70
+ const id = infraContainerId(resource);
71
+ idByKey.set(resource.key, id);
72
+ const where = resource.source.pointer
73
+ ? `${resource.source.file} at ${resource.source.pointer}`
74
+ : resource.source.file;
75
+ return {
76
+ id,
77
+ kind: 'container',
78
+ containerKind: APPLICATION_TYPES.has(resource.resourceType) ? 'application' : 'data-store',
79
+ label: resource.label,
80
+ technology: TECHNOLOGY[`${resource.provider}:${resource.resourceType}`] ??
81
+ `${resource.provider} ${resource.resourceType}`,
82
+ state: 'proposed',
83
+ rationale: `Declared by ${resource.source.tool} in ${where}.`,
84
+ deployment: infraDeploymentRef(resource),
85
+ };
86
+ });
87
+ const edges = [];
88
+ for (const binding of manifest.bindings) {
89
+ const source = idByKey.get(binding.from);
90
+ const target = idByKey.get(binding.to);
91
+ if (!source || !target)
92
+ continue;
93
+ edges.push({
94
+ id: `edge:${source}->${target}:${binding.binding}`,
95
+ source,
96
+ target,
97
+ label: `env.${binding.binding}`,
98
+ draft: true,
99
+ mechanisms: [],
100
+ count: 0,
101
+ });
102
+ }
103
+ return { nodes, edges };
104
+ }
105
+ exports.infraToC4 = infraToC4;
106
+ //# sourceMappingURL=c4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4.js","sourceRoot":"","sources":["../../src/infra/c4.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAsCH,MAAM,UAAU,GAA2B;IACzC,mBAAmB,EAAE,mBAAmB;IACxC,sBAAsB,EAAE,eAAe;IACvC,wBAAwB,EAAE,eAAe;IACzC,yBAAyB,EAAE,eAAe;IAC1C,kBAAkB,EAAE,kBAAkB;IACtC,sBAAsB,EAAE,sBAAsB;IAC9C,8EAA8E;IAC9E,eAAe,EAAE,eAAe;CACjC,CAAC;AAEF,uFAAuF;AACvF,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AAE3D,8EAA8E;AAC9E,MAAM,SAAS,GAA2B;IACxC,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF,SAAS,IA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,CAAC;AAzCD,8BAyCC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Infrastructure-as-code read side. Browser-safe. Everything is pure except
3
+ * `./observe`, which asks a provider's API what is running, with a credential
4
+ * the caller supplies.
5
+ */
6
+ export { infraResourceKey, mergeInfraManifests } from './types';
7
+ export type { InfraBinding, InfraDeploymentObservation, InfraDeploymentStatus, InfraManifest, InfraResource, InfraResourceSource, InfraTool, } from './types';
8
+ export { parseJsonc, stripJsonc } from './jsonc';
9
+ export { extractWranglerManifest } from './wrangler';
10
+ export type { ExtractWranglerOptions } from './wrangler';
11
+ export { extractTerraformManifest, terraformStateObservations } from './terraform';
12
+ export type { ExtractTerraformOptions } from './terraform';
13
+ export { infraContainerId, infraDeploymentRef, infraToC4 } from './c4';
14
+ export type { InfraC4Container, InfraC4Deployment, InfraC4Edge } from './c4';
15
+ export { CLOUDFLARE_OBSERVED_TYPES, observeCloudflare, parseWranglerAuthToken, resolveCloudflareAccount, withoutUnknownOverwrites, } from './observe';
16
+ export type { CloudflareAccess, CloudflareAccountResult, InfraObserveDeps, InfraObserveResult, } from './observe';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/infra/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAChE,YAAY,EACV,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACnF,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC7E,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /**
3
+ * Infrastructure-as-code read side. Browser-safe. Everything is pure except
4
+ * `./observe`, which asks a provider's API what is running, with a credential
5
+ * the caller supplies.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.withoutUnknownOverwrites = exports.resolveCloudflareAccount = exports.parseWranglerAuthToken = exports.observeCloudflare = exports.CLOUDFLARE_OBSERVED_TYPES = exports.infraToC4 = exports.infraDeploymentRef = exports.infraContainerId = exports.terraformStateObservations = exports.extractTerraformManifest = exports.extractWranglerManifest = exports.stripJsonc = exports.parseJsonc = exports.mergeInfraManifests = exports.infraResourceKey = void 0;
9
+ var types_1 = require("./types");
10
+ Object.defineProperty(exports, "infraResourceKey", { enumerable: true, get: function () { return types_1.infraResourceKey; } });
11
+ Object.defineProperty(exports, "mergeInfraManifests", { enumerable: true, get: function () { return types_1.mergeInfraManifests; } });
12
+ var jsonc_1 = require("./jsonc");
13
+ Object.defineProperty(exports, "parseJsonc", { enumerable: true, get: function () { return jsonc_1.parseJsonc; } });
14
+ Object.defineProperty(exports, "stripJsonc", { enumerable: true, get: function () { return jsonc_1.stripJsonc; } });
15
+ var wrangler_1 = require("./wrangler");
16
+ Object.defineProperty(exports, "extractWranglerManifest", { enumerable: true, get: function () { return wrangler_1.extractWranglerManifest; } });
17
+ var terraform_1 = require("./terraform");
18
+ Object.defineProperty(exports, "extractTerraformManifest", { enumerable: true, get: function () { return terraform_1.extractTerraformManifest; } });
19
+ Object.defineProperty(exports, "terraformStateObservations", { enumerable: true, get: function () { return terraform_1.terraformStateObservations; } });
20
+ var c4_1 = require("./c4");
21
+ Object.defineProperty(exports, "infraContainerId", { enumerable: true, get: function () { return c4_1.infraContainerId; } });
22
+ Object.defineProperty(exports, "infraDeploymentRef", { enumerable: true, get: function () { return c4_1.infraDeploymentRef; } });
23
+ Object.defineProperty(exports, "infraToC4", { enumerable: true, get: function () { return c4_1.infraToC4; } });
24
+ var observe_1 = require("./observe");
25
+ Object.defineProperty(exports, "CLOUDFLARE_OBSERVED_TYPES", { enumerable: true, get: function () { return observe_1.CLOUDFLARE_OBSERVED_TYPES; } });
26
+ Object.defineProperty(exports, "observeCloudflare", { enumerable: true, get: function () { return observe_1.observeCloudflare; } });
27
+ Object.defineProperty(exports, "parseWranglerAuthToken", { enumerable: true, get: function () { return observe_1.parseWranglerAuthToken; } });
28
+ Object.defineProperty(exports, "resolveCloudflareAccount", { enumerable: true, get: function () { return observe_1.resolveCloudflareAccount; } });
29
+ Object.defineProperty(exports, "withoutUnknownOverwrites", { enumerable: true, get: function () { return observe_1.withoutUnknownOverwrites; } });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/infra/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,iCAAgE;AAAvD,yGAAA,gBAAgB,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAU9C,iCAAiD;AAAxC,mGAAA,UAAU,OAAA;AAAE,mGAAA,UAAU,OAAA;AAC/B,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA;AAEhC,yCAAmF;AAA1E,qHAAA,wBAAwB,OAAA;AAAE,uHAAA,0BAA0B,OAAA;AAE7D,2BAAuE;AAA9D,sGAAA,gBAAgB,OAAA;AAAE,wGAAA,kBAAkB,OAAA;AAAE,+FAAA,SAAS,OAAA;AAExD,qCAMmB;AALjB,oHAAA,yBAAyB,OAAA;AACzB,4GAAA,iBAAiB,OAAA;AACjB,iHAAA,sBAAsB,OAAA;AACtB,mHAAA,wBAAwB,OAAA;AACxB,mHAAA,wBAAwB,OAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Minimal JSONC reader — JSON with `//` and block comments and trailing
3
+ * commas, which is what `wrangler.jsonc` allows. Kept in-house so the
4
+ * browser-safe entry gains no dependency for a small job.
5
+ */
6
+ /** Remove comments and trailing commas, leaving string contents untouched. */
7
+ export declare function stripJsonc(text: string): string;
8
+ /** Parse JSONC text. Throws `SyntaxError` like `JSON.parse` on malformed input. */
9
+ export declare function parseJsonc(text: string): unknown;
10
+ //# sourceMappingURL=jsonc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonc.d.ts","sourceRoot":"","sources":["../../src/infra/jsonc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyDH,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * Minimal JSONC reader — JSON with `//` and block comments and trailing
4
+ * commas, which is what `wrangler.jsonc` allows. Kept in-house so the
5
+ * browser-safe entry gains no dependency for a small job.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.parseJsonc = exports.stripJsonc = void 0;
9
+ /** Index just past the string literal that opens at `start`. */
10
+ function skipString(text, start) {
11
+ let i = start + 1;
12
+ while (i < text.length && text[i] !== '"')
13
+ i += text[i] === '\\' ? 2 : 1;
14
+ return i + 1;
15
+ }
16
+ function stripComments(text) {
17
+ let out = '';
18
+ let i = 0;
19
+ while (i < text.length) {
20
+ const ch = text[i];
21
+ const next = text[i + 1];
22
+ if (ch === '"') {
23
+ const end = skipString(text, i);
24
+ out += text.slice(i, end);
25
+ i = end;
26
+ }
27
+ else if (ch === '/' && next === '/') {
28
+ while (i < text.length && text[i] !== '\n')
29
+ i += 1;
30
+ }
31
+ else if (ch === '/' && next === '*') {
32
+ const end = text.indexOf('*/', i + 2);
33
+ i = end === -1 ? text.length : end + 2;
34
+ }
35
+ else {
36
+ out += ch;
37
+ i += 1;
38
+ }
39
+ }
40
+ return out;
41
+ }
42
+ function stripTrailingCommas(text) {
43
+ let out = '';
44
+ let i = 0;
45
+ while (i < text.length) {
46
+ const ch = text[i];
47
+ if (ch === '"') {
48
+ const end = skipString(text, i);
49
+ out += text.slice(i, end);
50
+ i = end;
51
+ continue;
52
+ }
53
+ if (ch === ',') {
54
+ let j = i + 1;
55
+ while (j < text.length && /\s/.test(text[j]))
56
+ j += 1;
57
+ if (text[j] === '}' || text[j] === ']') {
58
+ i += 1;
59
+ continue;
60
+ }
61
+ }
62
+ out += ch;
63
+ i += 1;
64
+ }
65
+ return out;
66
+ }
67
+ /** Remove comments and trailing commas, leaving string contents untouched. */
68
+ function stripJsonc(text) {
69
+ return stripTrailingCommas(stripComments(text));
70
+ }
71
+ exports.stripJsonc = stripJsonc;
72
+ /** Parse JSONC text. Throws `SyntaxError` like `JSON.parse` on malformed input. */
73
+ function parseJsonc(text) {
74
+ return JSON.parse(stripJsonc(text));
75
+ }
76
+ exports.parseJsonc = parseJsonc;
77
+ //# sourceMappingURL=jsonc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonc.js","sourceRoot":"","sources":["../../src/infra/jsonc.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,gEAAgE;AAChE,SAAS,UAAU,CAAC,IAAY,EAAE,KAAa;IAC7C,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;IAClB,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,C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,CAAC,IAAY;IACvC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE;QACtB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QACpB,IAAI,EAAE,KAAK,GAAG,EAAE;YACd,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAChC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAC1B,CAAC,GAAG,GAAG,CAAC;YACR,SAAS;SACV;QACD,IAAI,EAAE,KAAK,GAAG,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC;gBAAE,CAAC,IAAI,CAAC,CAAC;YACtD,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBACtC,CAAC,IAAI,CAAC,CAAC;gBACP,SAAS;aACV;SACF;QACD,GAAG,IAAI,EAAE,CAAC;QACV,CAAC,IAAI,CAAC,CAAC;KACR;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,8EAA8E;AAC9E,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,mBAAmB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AAClD,CAAC;AAFD,gCAEC;AAED,mFAAmF;AACnF,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AACtC,CAAC;AAFD,gCAEC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Looking at a live account — the checks that turn declared resource keys into
3
+ * {@link InfraDeploymentObservation}s.
4
+ *
5
+ * This is the one place that knows how to ask a provider whether a declared
6
+ * resource exists. It is given a credential and returns observations; it does
7
+ * not know where the credential came from (a pasted token, a CLI login, a
8
+ * server-held token) and it stores nothing. Hosts own both ends: Studio and
9
+ * the desktop app run it in their main process, a hosted service can run it in
10
+ * a Worker.
11
+ *
12
+ * Fetch-only and browser-safe. The token travels only in the Authorization
13
+ * header of requests to the provider's API, and never appears in a result.
14
+ *
15
+ * Cloudflare only: Workers, R2, D1, KV, Queues and Containers. A resource type
16
+ * with no lookup is reported as skipped rather than guessed at.
17
+ */
18
+ import type { InfraDeploymentObservation } from './types';
19
+ /** What a check needs to run, besides the credential. */
20
+ export interface InfraObserveDeps {
21
+ fetch?: typeof fetch;
22
+ now?: () => Date;
23
+ }
24
+ /** A credential for one Cloudflare account. */
25
+ export interface CloudflareAccess {
26
+ /** An API token or an OAuth access token; sent as a Bearer token. */
27
+ token: string;
28
+ accountId: string;
29
+ }
30
+ export type CloudflareAccountResult = {
31
+ ok: true;
32
+ accountId: string;
33
+ account?: string;
34
+ } | {
35
+ ok: false;
36
+ error: string;
37
+ /** Set when the token sees several accounts and one must be chosen. */
38
+ accounts?: Array<{
39
+ id: string;
40
+ name: string;
41
+ }>;
42
+ };
43
+ /**
44
+ * Work out which account a Cloudflare token is for, and prove it can do the
45
+ * job: it must resolve to one account and be able to read that account's
46
+ * Workers. A token that cannot is refused with the reason, so a person finds
47
+ * out when connecting rather than from cards that never light up.
48
+ */
49
+ export declare function resolveCloudflareAccount(input: {
50
+ token: string;
51
+ accountId?: string;
52
+ }, deps?: InfraObserveDeps): Promise<CloudflareAccountResult>;
53
+ /** Cloudflare resource types a check can look at. */
54
+ export declare const CLOUDFLARE_OBSERVED_TYPES: readonly string[];
55
+ /** What one run of checks learned. Nothing here has been stored. */
56
+ export interface InfraObserveResult {
57
+ /**
58
+ * One observation per resource that was looked at, `unknown` ones included.
59
+ * A host that already holds an observation for a key should pass these
60
+ * through {@link withoutUnknownOverwrites} before storing them.
61
+ */
62
+ observations: InfraDeploymentObservation[];
63
+ /** Keys that were not looked at, with the reason. */
64
+ skipped: Array<{
65
+ resourceKey: string;
66
+ reason: string;
67
+ }>;
68
+ /** Why some lookups could not be made, when any could not. */
69
+ failure?: string;
70
+ }
71
+ /**
72
+ * Look at the named Cloudflare resources and say what was seen.
73
+ *
74
+ * Three outcomes per resource, kept apart on purpose:
75
+ * - it is there → `deployed`, with whatever address and dashboard page it has;
76
+ * - Cloudflare says it does not exist → `not-found`;
77
+ * - the question could not be asked (auth, network) → `unknown`.
78
+ *
79
+ * Failures are per resource: a token that cannot read R2 still gets the
80
+ * Workers checked, and the R2 failure is reported in `failure`. Keys for other
81
+ * providers are ignored.
82
+ */
83
+ export declare function observeCloudflare(resourceKeys: readonly string[], access: CloudflareAccess, deps?: InfraObserveDeps): Promise<InfraObserveResult>;
84
+ /**
85
+ * Drop `unknown` observations for resources something is already known about.
86
+ * A failed check must not erase what was known: `unknown` is only worth
87
+ * keeping when it is the first thing said about a resource.
88
+ */
89
+ export declare function withoutUnknownOverwrites(observations: readonly InfraDeploymentObservation[], alreadyKnown: ReadonlySet<string>): InfraDeploymentObservation[];
90
+ /**
91
+ * Read the answer of `wrangler auth token --json` — the credential of whoever
92
+ * is logged in to wrangler on this machine, refreshed by wrangler itself.
93
+ *
94
+ * Only a Bearer credential is usable here: an OAuth login or an API token. A
95
+ * global API key (key + email) is not, and reads as null, as does anything
96
+ * that is not wrangler's JSON.
97
+ */
98
+ export declare function parseWranglerAuthToken(stdout: string): {
99
+ token: string;
100
+ type: 'oauth' | 'api_token';
101
+ } | null;
102
+ //# sourceMappingURL=observe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/infra/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAM1D,yDAAyD;AACzD,MAAM,WAAW,gB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