@trojanbox-vcp-test/site-edit-engine 0.1.0 → 0.2.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 (163) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.js +127 -2
  3. package/dist/internal/protocol/operation.d.ts +2 -0
  4. package/dist/internal/protocol/render.d.ts +3 -30
  5. package/dist/internal/protocol.d.ts +1 -1
  6. package/dist/next-app-router.js +1 -140
  7. package/dist/preview-runtime.d.ts +249 -303
  8. package/dist/runtime-sync.d.ts +8 -8
  9. package/dist/runtime.d.ts +1 -127
  10. package/dist/site-edit-instrumentation.d.ts +1 -1
  11. package/dist/source-watcher.js +1 -150
  12. package/dist/types.d.ts +12 -14
  13. package/dist/webpack-loader.cjs +50 -588
  14. package/package.json +2 -2
  15. package/dist/execute-integration/execute-fixture-harness.d.ts +0 -25
  16. package/dist/execute-integration/execute-fixture-harness.js +0 -37
  17. package/dist/internal/ast/diagnostics/index.d.ts +0 -5
  18. package/dist/internal/ast/diagnostics/index.js +0 -25
  19. package/dist/internal/ast/history/index.d.ts +0 -15
  20. package/dist/internal/ast/history/index.js +0 -62
  21. package/dist/internal/ast/index.d.ts +0 -8
  22. package/dist/internal/ast/index.js +0 -5
  23. package/dist/internal/ast/locators/index.d.ts +0 -1
  24. package/dist/internal/ast/locators/index.js +0 -1
  25. package/dist/internal/ast/locators/resolve-locator.d.ts +0 -16
  26. package/dist/internal/ast/locators/resolve-locator.js +0 -920
  27. package/dist/internal/ast/parser/SourceParser.d.ts +0 -30
  28. package/dist/internal/ast/parser/SourceParser.js +0 -49
  29. package/dist/internal/ast/parser/index.d.ts +0 -21
  30. package/dist/internal/ast/parser/index.js +0 -64
  31. package/dist/internal/ast/primitives/conditional/conditional-primitives.d.ts +0 -18
  32. package/dist/internal/ast/primitives/conditional/conditional-primitives.js +0 -237
  33. package/dist/internal/ast/primitives/conditional/index.d.ts +0 -1
  34. package/dist/internal/ast/primitives/conditional/index.js +0 -1
  35. package/dist/internal/ast/primitives/imports/add-import.d.ts +0 -18
  36. package/dist/internal/ast/primitives/imports/add-import.js +0 -111
  37. package/dist/internal/ast/primitives/imports/index.d.ts +0 -2
  38. package/dist/internal/ast/primitives/imports/index.js +0 -2
  39. package/dist/internal/ast/primitives/imports/remove-import.d.ts +0 -15
  40. package/dist/internal/ast/primitives/imports/remove-import.js +0 -72
  41. package/dist/internal/ast/primitives/index.d.ts +0 -10
  42. package/dist/internal/ast/primitives/index.js +0 -10
  43. package/dist/internal/ast/primitives/jsx/index.d.ts +0 -4
  44. package/dist/internal/ast/primitives/jsx/index.js +0 -4
  45. package/dist/internal/ast/primitives/jsx/insert-child.d.ts +0 -11
  46. package/dist/internal/ast/primitives/jsx/insert-child.js +0 -69
  47. package/dist/internal/ast/primitives/jsx/move-node.d.ts +0 -9
  48. package/dist/internal/ast/primitives/jsx/move-node.js +0 -76
  49. package/dist/internal/ast/primitives/jsx/remove-node.d.ts +0 -7
  50. package/dist/internal/ast/primitives/jsx/remove-node.js +0 -36
  51. package/dist/internal/ast/primitives/jsx/update-text.d.ts +0 -8
  52. package/dist/internal/ast/primitives/jsx/update-text.js +0 -81
  53. package/dist/internal/ast/primitives/next/index.d.ts +0 -1
  54. package/dist/internal/ast/primitives/next/index.js +0 -1
  55. package/dist/internal/ast/primitives/next/next-primitives.d.ts +0 -43
  56. package/dist/internal/ast/primitives/next/next-primitives.js +0 -211
  57. package/dist/internal/ast/primitives/shared.d.ts +0 -60
  58. package/dist/internal/ast/primitives/shared.js +0 -176
  59. package/dist/internal/ast/primitives/style/class-expression.d.ts +0 -23
  60. package/dist/internal/ast/primitives/style/class-expression.js +0 -174
  61. package/dist/internal/ast/primitives/style/index.d.ts +0 -1
  62. package/dist/internal/ast/primitives/style/index.js +0 -1
  63. package/dist/internal/ast/primitives/style/style-primitives.d.ts +0 -49
  64. package/dist/internal/ast/primitives/style/style-primitives.js +0 -555
  65. package/dist/internal/ast/primitives/values/index.d.ts +0 -1
  66. package/dist/internal/ast/primitives/values/index.js +0 -1
  67. package/dist/internal/ast/primitives/values/value-primitives.d.ts +0 -42
  68. package/dist/internal/ast/primitives/values/value-primitives.js +0 -158
  69. package/dist/internal/ast/printer/SourcePrinter.d.ts +0 -21
  70. package/dist/internal/ast/printer/SourcePrinter.js +0 -76
  71. package/dist/internal/ast/printer/index.d.ts +0 -6
  72. package/dist/internal/ast/printer/index.js +0 -126
  73. package/dist/internal/ast/types.d.ts +0 -190
  74. package/dist/internal/ast/types.js +0 -1
  75. package/dist/internal/capability/capability-resolver.d.ts +0 -16
  76. package/dist/internal/capability/capability-resolver.js +0 -127
  77. package/dist/internal/classname-source.d.ts +0 -24
  78. package/dist/internal/classname-source.js +0 -220
  79. package/dist/internal/contracts/IEditEngineRuntime.d.ts +0 -18
  80. package/dist/internal/contracts/IEditEngineRuntime.js +0 -1
  81. package/dist/internal/domain/EditDiagnostic.d.ts +0 -38
  82. package/dist/internal/domain/EditDiagnostic.js +0 -43
  83. package/dist/internal/events/event-bus.d.ts +0 -14
  84. package/dist/internal/events/event-bus.js +0 -21
  85. package/dist/internal/graph/graph-builder.d.ts +0 -12
  86. package/dist/internal/graph/graph-builder.js +0 -1371
  87. package/dist/internal/graph/import-resolver.d.ts +0 -31
  88. package/dist/internal/graph/import-resolver.js +0 -109
  89. package/dist/internal/graph/project-graph-builder.d.ts +0 -32
  90. package/dist/internal/graph/project-graph-builder.js +0 -133
  91. package/dist/internal/graph/types.d.ts +0 -114
  92. package/dist/internal/graph/types.js +0 -6
  93. package/dist/internal/history/undo-redo.d.ts +0 -28
  94. package/dist/internal/history/undo-redo.js +0 -42
  95. package/dist/internal/index.d.ts +0 -2
  96. package/dist/internal/index.js +0 -1
  97. package/dist/internal/planner/planner.d.ts +0 -104
  98. package/dist/internal/planner/planner.js +0 -2533
  99. package/dist/internal/planner/types.d.ts +0 -275
  100. package/dist/internal/planner/types.js +0 -6
  101. package/dist/internal/protocol/boundary.js +0 -3
  102. package/dist/internal/protocol/capability.js +0 -8
  103. package/dist/internal/protocol/error.js +0 -38
  104. package/dist/internal/protocol/event.js +0 -3
  105. package/dist/internal/protocol/identity.js +0 -30
  106. package/dist/internal/protocol/operation.js +0 -8
  107. package/dist/internal/protocol/render.js +0 -3
  108. package/dist/internal/protocol.js +0 -2
  109. package/dist/internal/provenance/binding-graph.d.ts +0 -39
  110. package/dist/internal/provenance/binding-graph.js +0 -184
  111. package/dist/internal/provenance/capability-policy.d.ts +0 -15
  112. package/dist/internal/provenance/capability-policy.js +0 -96
  113. package/dist/internal/provenance/data-source-classifier.d.ts +0 -14
  114. package/dist/internal/provenance/data-source-classifier.js +0 -281
  115. package/dist/internal/provenance/resolve-text-provenance.d.ts +0 -45
  116. package/dist/internal/provenance/resolve-text-provenance.js +0 -3090
  117. package/dist/internal/provenance/types.d.ts +0 -89
  118. package/dist/internal/provenance/types.js +0 -1
  119. package/dist/internal/render/component-semantic.d.ts +0 -11
  120. package/dist/internal/render/component-semantic.js +0 -141
  121. package/dist/internal/render/content-model.d.ts +0 -3
  122. package/dist/internal/render/content-model.js +0 -89
  123. package/dist/internal/render/media-model.d.ts +0 -3
  124. package/dist/internal/render/media-model.js +0 -45
  125. package/dist/internal/render/provenance-types.d.ts +0 -33
  126. package/dist/internal/render/provenance-types.js +0 -1
  127. package/dist/internal/render/render-projection.d.ts +0 -24
  128. package/dist/internal/render/render-projection.js +0 -281
  129. package/dist/internal/render/tailwind-style-model.d.ts +0 -19
  130. package/dist/internal/render/tailwind-style-model.js +0 -1187
  131. package/dist/internal/runtime/EditEngineRuntime.d.ts +0 -25
  132. package/dist/internal/runtime/EditEngineRuntime.js +0 -89
  133. package/dist/internal/runtime/EditEngineRuntimeSnapshot.d.ts +0 -31
  134. package/dist/internal/runtime/EditEngineRuntimeSnapshot.js +0 -15
  135. package/dist/internal/runtime/InternalEditEngine.d.ts +0 -44
  136. package/dist/internal/runtime/InternalEditEngine.js +0 -1391
  137. package/dist/internal/runtime.d.ts +0 -3
  138. package/dist/internal/runtime.js +0 -1
  139. package/dist/internal/topology/topology.d.ts +0 -6
  140. package/dist/internal/topology/topology.js +0 -98
  141. package/dist/internal/topology/types.d.ts +0 -35
  142. package/dist/internal/topology/types.js +0 -5
  143. package/dist/internal/types.d.ts +0 -1
  144. package/dist/internal/types.js +0 -1
  145. package/dist/internal/writeback/in-memory-fs.d.ts +0 -7
  146. package/dist/internal/writeback/in-memory-fs.js +0 -44
  147. package/dist/internal/writeback/types.d.ts +0 -45
  148. package/dist/internal/writeback/types.js +0 -7
  149. package/dist/internal/writeback/writeback-service.d.ts +0 -7
  150. package/dist/internal/writeback/writeback-service.js +0 -568
  151. package/dist/internal-adapter.d.ts +0 -18
  152. package/dist/internal-adapter.js +0 -350
  153. package/dist/next-app-router-fs.js +0 -64
  154. package/dist/preview-runtime.js +0 -102
  155. package/dist/public-file-system.js +0 -1
  156. package/dist/runtime-sync.js +0 -321
  157. package/dist/runtime.js +0 -134
  158. package/dist/site-edit-instrumentation.js +0 -322
  159. package/dist/snapshot-file-system.d.ts +0 -19
  160. package/dist/snapshot-file-system.js +0 -49
  161. package/dist/source-writeback-test-harness.d.ts +0 -244
  162. package/dist/source-writeback-test-harness.js +0 -119
  163. package/dist/types.js +0 -1
@@ -1,275 +0,0 @@
1
- import type { DirectiveLocator, ExportLocator, JsxAttributeLocator, JsxNodeLocator, Placement, PrimitiveValue, ValueLocator, ValuePathSegment, ValueRootSelector } from "../ast/index.js";
2
- import type { OperationTarget as ProtocolOperationTarget, OperationRequest as ProtocolOperationRequest, OperationType as ProtocolOperationType, OperationValue as ProtocolOperationValue } from "../protocol.js";
3
- import type { ExternalAdapterCapability } from "../provenance/types.js";
4
- export type ExternalSourceKind = "api-field" | "cms-field" | "i18n-message" | "config-entry";
5
- export type OperationType = ProtocolOperationType;
6
- export type OperationTarget = ProtocolOperationTarget;
7
- export type OperationValue = ProtocolOperationValue;
8
- /**
9
- * protocol-facing 请求 — planner 的输入。
10
- * targetKey 是 protocol 层 key,不是 source position。
11
- */
12
- export type OperationRequest = ProtocolOperationRequest;
13
- /**
14
- * RewriteStep 是 planner 展开后的执行形状。
15
- * 到了这一步,所有 locator / jsx / import 变更已经确定。
16
- * writeback 照着执行即可,不需要反查 graph。
17
- */
18
- export type RewriteStep = RewriteStep_UpdateText | RewriteStep_UpdateValue | RewriteStep_SetObjectField | RewriteStep_InsertObjectField | RewriteStep_RemoveObjectField | RewriteStep_UpdateArrayItem | RewriteStep_InsertArrayItem | RewriteStep_RemoveArrayItem | RewriteStep_MoveArrayItem | RewriteStep_ReplaceConditionalExpression | RewriteStep_SetConditionalBranchContent | RewriteStep_RemoveNode | RewriteStep_InsertChild | RewriteStep_MoveNode | RewriteStep_SetJsxProp | RewriteStep_RemoveJsxProp | RewriteStep_SetClassName | RewriteStep_AddClassToken | RewriteStep_RemoveClassToken | RewriteStep_SetStyleProperty | RewriteStep_SetStyleProperties | RewriteStep_SetCssModuleClass | RewriteStep_SetDirective | RewriteStep_RemoveDirective | RewriteStep_SetRouteExport | RewriteStep_SetMetadataField | RewriteStep_SetGenerateMetadata | RewriteStep_InvokeExternalAdapter | RewriteStep_AddImport | RewriteStep_RemoveImport;
19
- interface RewriteStepBase {
20
- /** 步骤序号,writeback 按此顺序执行 */
21
- order: number;
22
- /** 目标文件路径 */
23
- file: string;
24
- }
25
- export interface RewriteStep_UpdateText extends RewriteStepBase {
26
- type: "update-text";
27
- locator: JsxNodeLocator;
28
- segmentIndex: number;
29
- newText: string;
30
- }
31
- export interface RewriteStep_UpdateValue extends RewriteStepBase {
32
- type: "update-value";
33
- locator: ValueLocator;
34
- value: PrimitiveValue;
35
- }
36
- export interface RewriteStep_SetObjectField extends RewriteStepBase {
37
- type: "set-object-field";
38
- locator: ValueLocator;
39
- value: PrimitiveValue;
40
- }
41
- export interface RewriteStep_InsertObjectField extends RewriteStepBase {
42
- type: "insert-object-field";
43
- locator: ValueLocator;
44
- field: string;
45
- value: PrimitiveValue;
46
- }
47
- export interface RewriteStep_RemoveObjectField extends RewriteStepBase {
48
- type: "remove-object-field";
49
- locator: ValueLocator;
50
- field: string;
51
- }
52
- export interface RewriteStep_UpdateArrayItem extends RewriteStepBase {
53
- type: "update-array-item";
54
- locator: ValueLocator;
55
- value: PrimitiveValue;
56
- }
57
- export interface RewriteStep_InsertArrayItem extends RewriteStepBase {
58
- type: "insert-array-item";
59
- locator: ValueLocator;
60
- index: number;
61
- value: PrimitiveValue;
62
- }
63
- export interface RewriteStep_RemoveArrayItem extends RewriteStepBase {
64
- type: "remove-array-item";
65
- locator: ValueLocator;
66
- index: number;
67
- }
68
- export interface RewriteStep_MoveArrayItem extends RewriteStepBase {
69
- type: "move-array-item";
70
- locator: ValueLocator;
71
- fromIndex: number;
72
- toIndex: number;
73
- }
74
- export interface RewriteStep_ReplaceConditionalExpression extends RewriteStepBase {
75
- type: "replace-conditional-expression";
76
- locator: JsxNodeLocator;
77
- nextExpression: string;
78
- }
79
- export interface RewriteStep_SetConditionalBranchContent extends RewriteStepBase {
80
- type: "set-conditional-branch-content";
81
- locator: JsxNodeLocator;
82
- branch: "then" | "else";
83
- content: {
84
- jsx: string;
85
- };
86
- }
87
- export interface RewriteStep_RemoveNode extends RewriteStepBase {
88
- type: "remove-node";
89
- locator: JsxNodeLocator;
90
- removeWhitespace?: boolean;
91
- }
92
- export interface RewriteStep_InsertChild extends RewriteStepBase {
93
- type: "insert-child";
94
- parentLocator: JsxNodeLocator;
95
- node: {
96
- jsx: string;
97
- };
98
- placement: Placement;
99
- anchorLocator?: JsxNodeLocator;
100
- }
101
- export interface RewriteStep_MoveNode extends RewriteStepBase {
102
- type: "move-node";
103
- locator: JsxNodeLocator;
104
- targetParentLocator: JsxNodeLocator;
105
- placement: Placement;
106
- anchorLocator?: JsxNodeLocator;
107
- }
108
- export interface RewriteStep_SetJsxProp extends RewriteStepBase {
109
- type: "set-jsx-prop";
110
- locator: JsxAttributeLocator;
111
- value: OperationValue;
112
- }
113
- export interface RewriteStep_RemoveJsxProp extends RewriteStepBase {
114
- type: "remove-jsx-prop";
115
- locator: JsxAttributeLocator;
116
- }
117
- export interface RewriteStep_SetClassName extends RewriteStepBase {
118
- type: "set-class-name";
119
- locator: JsxAttributeLocator;
120
- value: string;
121
- }
122
- export interface RewriteStep_AddClassToken extends RewriteStepBase {
123
- type: "add-class-token";
124
- locator: JsxAttributeLocator;
125
- token: string;
126
- }
127
- export interface RewriteStep_RemoveClassToken extends RewriteStepBase {
128
- type: "remove-class-token";
129
- locator: JsxAttributeLocator;
130
- token: string;
131
- }
132
- export interface RewriteStep_SetStyleProperty extends RewriteStepBase {
133
- type: "set-style-property";
134
- locator: JsxAttributeLocator;
135
- property: string;
136
- value: OperationValue;
137
- }
138
- export interface RewriteStep_SetStyleProperties extends RewriteStepBase {
139
- type: "set-style-properties";
140
- locator: JsxAttributeLocator;
141
- properties: Record<string, OperationValue>;
142
- }
143
- export interface RewriteStep_SetCssModuleClass extends RewriteStepBase {
144
- type: "set-css-module-class";
145
- locator: JsxAttributeLocator;
146
- from: string;
147
- to: string;
148
- }
149
- export interface RewriteStep_SetDirective extends RewriteStepBase {
150
- type: "set-directive";
151
- mode: "add" | "update";
152
- value: DirectiveLocator["value"];
153
- currentValue?: DirectiveLocator["value"];
154
- }
155
- export interface RewriteStep_RemoveDirective extends RewriteStepBase {
156
- type: "remove-directive";
157
- value: DirectiveLocator["value"];
158
- }
159
- export interface RewriteStep_SetRouteExport extends RewriteStepBase {
160
- type: "set-route-export";
161
- name: Extract<ExportLocator, {
162
- exportKind: "named";
163
- }>["name"];
164
- value: OperationValue;
165
- }
166
- export interface RewriteStep_SetMetadataField extends RewriteStepBase {
167
- type: "set-metadata-field";
168
- field: string;
169
- value: OperationValue | null;
170
- }
171
- export interface RewriteStep_SetGenerateMetadata extends RewriteStepBase {
172
- type: "set-generate-metadata";
173
- field: string;
174
- value: OperationValue | null;
175
- }
176
- export interface RewriteStep_InvokeExternalAdapter extends RewriteStepBase {
177
- type: "invoke-external-adapter";
178
- sourceType: ExternalSourceKind;
179
- sourceId: string;
180
- adapterId?: string;
181
- capability?: ExternalAdapterCapability;
182
- value: OperationValue;
183
- }
184
- export interface RewriteStep_AddImport extends RewriteStepBase {
185
- type: "add-import";
186
- moduleSpecifier: string;
187
- imports: Array<{
188
- kind: "named";
189
- imported: string;
190
- local?: string;
191
- } | {
192
- kind: "default";
193
- local: string;
194
- } | {
195
- kind: "namespace";
196
- local: string;
197
- }>;
198
- }
199
- export interface RewriteStep_RemoveImport extends RewriteStepBase {
200
- type: "remove-import";
201
- moduleSpecifier: string;
202
- imports: Array<{
203
- kind: "named";
204
- imported: string;
205
- } | {
206
- kind: "default";
207
- } | {
208
- kind: "namespace";
209
- }>;
210
- }
211
- export interface FileSnapshot {
212
- file: string;
213
- content: string;
214
- version: number;
215
- }
216
- export type ResolvedTextWriteTarget = {
217
- kind: "value-binding";
218
- file: string;
219
- locator: ValueLocator | null;
220
- root?: ValueRootSelector;
221
- path?: ValuePathSegment[];
222
- displayExpression: string;
223
- sourceKind: "literal" | "binding" | "imported-binding" | "repeat-template";
224
- collectionIndexMap?: number[];
225
- collectionPathMap?: ValuePathSegment[][];
226
- } | {
227
- kind: "external-entry";
228
- file: string;
229
- sourceType: ExternalSourceKind;
230
- sourceId: string;
231
- adapterId?: string;
232
- displayExpression: string;
233
- };
234
- export interface NodeCapabilitySnapshot {
235
- key: string;
236
- canUpdateText: boolean;
237
- canRemove: boolean;
238
- canInsertChild: boolean;
239
- canMove: boolean;
240
- constraints: string[];
241
- }
242
- /**
243
- * RewritePlan = planner 的完整产物。
244
- * writeback 接收到 plan 后按 steps 顺序执行。
245
- */
246
- export interface RewritePlan {
247
- /** 操作唯一 ID */
248
- operationId: string;
249
- /** 操作类型 */
250
- kind: OperationType;
251
- /** 协议层目标 */
252
- target: OperationTarget;
253
- /** 请求时的文档版本号 */
254
- documentVersion: number;
255
- /** 按顺序执行的步骤 */
256
- steps: RewriteStep[];
257
- /** 涉及文件的快照(用于 rollback) */
258
- preSnapshots: FileSnapshot[];
259
- /** 经过校验的能力快照 */
260
- validatedCapability?: NodeCapabilitySnapshot;
261
- }
262
- export type OperationResult = {
263
- ok: true;
264
- operationId: string;
265
- resultVersion: number;
266
- affectedFiles: string[];
267
- } | {
268
- ok: false;
269
- operationId: string;
270
- errorCode: OperationErrorCode;
271
- reason: string;
272
- rolledBack?: boolean;
273
- };
274
- export type OperationErrorCode = "stale-version" | "capability-denied" | "invalid-params" | "locator-miss" | "route-not-found" | "unsupported-operation" | "invalid-target" | "ast-error" | "writeback-failed" | "rollback-failed" | "unknown";
275
- export {};
@@ -1,6 +0,0 @@
1
- // ── RewritePlan / RewriteStep 形状 ─────────────────────────────
2
- // 根文档 03 §4 定义:
3
- // - RewritePlan 是 planner 的产物
4
- // - RewriteStep 是执行形状,不是请求形状
5
- // - writeback 不再反查 graph、不再把 request 重新解释
6
- export {};
@@ -1,3 +0,0 @@
1
- // ─── Boundary 契约 ────────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §6.2
3
- export {};
@@ -1,8 +0,0 @@
1
- // ─── Capability 契约 ──────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §4
3
- //
4
- // 关键约束:
5
- // canMove 不能被解释为只有同级排序
6
- // canInsertChild 不能被解释为只有 native tag
7
- // repeat / boundary / opaque 的限制必须显式通过 constraint 返回
8
- export {};
@@ -1,38 +0,0 @@
1
- // ─── Error 契约 ───────────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §6.1
3
- /**
4
- * 操作错误码枚举 —— 覆盖从节点查找到写回的所有失败路径。
5
- */
6
- export var OperationErrorCode;
7
- (function (OperationErrorCode) {
8
- /** 目标节点 key 在 graph 中不存在 */
9
- OperationErrorCode["NODE_NOT_FOUND"] = "NODE_NOT_FOUND";
10
- /** 目标路由不存在 */
11
- OperationErrorCode["ROUTE_NOT_FOUND"] = "ROUTE_NOT_FOUND";
12
- /** capability 检查拒绝(如 canMove = false) */
13
- OperationErrorCode["CAPABILITY_REJECTED"] = "CAPABILITY_REJECTED";
14
- /** 约束违反(如试图往 void element 插入子节点) */
15
- OperationErrorCode["CONSTRAINT_VIOLATED"] = "CONSTRAINT_VIOLATED";
16
- /** 请求参数不合法 */
17
- OperationErrorCode["INVALID_PARAMS"] = "INVALID_PARAMS";
18
- /** planner 无法生成合法执行计划 */
19
- OperationErrorCode["PLAN_FAILED"] = "PLAN_FAILED";
20
- /** documentVersion 过期 */
21
- OperationErrorCode["VERSION_STALE"] = "VERSION_STALE";
22
- /** AST 解析失败 */
23
- OperationErrorCode["AST_PARSE_ERROR"] = "AST_PARSE_ERROR";
24
- /** 操作在当前受支持语法形状外 */
25
- OperationErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
26
- /** NodeLocator 定位失败 */
27
- OperationErrorCode["LOCATOR_FAILED"] = "LOCATOR_FAILED";
28
- /** 目标关系非法,例如无效父子关系或自闭合元素插子节点 */
29
- OperationErrorCode["INVALID_TARGET"] = "INVALID_TARGET";
30
- /** 文件写入 I/O 错误 */
31
- OperationErrorCode["WRITE_IO_ERROR"] = "WRITE_IO_ERROR";
32
- /** 并发修改冲突 */
33
- OperationErrorCode["CONCURRENT_MODIFIED"] = "CONCURRENT_MODIFIED";
34
- /** 回滚失败 */
35
- OperationErrorCode["ROLLBACK_FAILED"] = "ROLLBACK_FAILED";
36
- /** 内部错误 */
37
- OperationErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
38
- })(OperationErrorCode || (OperationErrorCode = {}));
@@ -1,3 +0,0 @@
1
- // ─── Event 契约 ───────────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §6.3
3
- export {};
@@ -1,30 +0,0 @@
1
- // ─── 身份契约 ───────────────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §2
3
- //
4
- // 规则:
5
- // key = "{file}::{component}::{structuralPath}"
6
- // DOM / protocol / engine / bridge 全部统一使用 key
7
- // SourceIdentity 不携带 SourceRange(SourceRange 是 engine-internal)
8
- const SOURCE_IDENTITY_SEPARATOR = "::";
9
- /**
10
- * 生成稳定的 SourceIdentity.key。
11
- */
12
- export function computeSourceIdentityKey(file, component, structuralPath) {
13
- return `${file}${SOURCE_IDENTITY_SEPARATOR}${component}${SOURCE_IDENTITY_SEPARATOR}${structuralPath}`;
14
- }
15
- /**
16
- * 解析 SourceIdentity.key。
17
- *
18
- * structuralPath 允许包含分隔符,所以只切前两个段,余下部分全部并回 structuralPath。
19
- */
20
- export function parseSourceIdentityKey(key) {
21
- const [file, component, ...pathParts] = key.split(SOURCE_IDENTITY_SEPARATOR);
22
- if (!file || !component || pathParts.length === 0) {
23
- return null;
24
- }
25
- return {
26
- file,
27
- component,
28
- structuralPath: pathParts.join(SOURCE_IDENTITY_SEPARATOR),
29
- };
30
- }
@@ -1,8 +0,0 @@
1
- // ─── Operation 契约 ───────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §5
3
- //
4
- // 关键规则:
5
- // MoveTarget 必须允许跨组件 / 跨文件目标表达
6
- // InsertNodeSpec 必须允许 component-call
7
- // protocol 只表达请求意图,不表达内部 locator 展开方式
8
- export {};
@@ -1,3 +0,0 @@
1
- // ─── Render 契约 ──────────────────────────────────────
2
- // 来源: docs/02-contracts-and-protocol.md §3
3
- export {};
@@ -1,2 +0,0 @@
1
- export { computeSourceIdentityKey, parseSourceIdentityKey, } from "./protocol/identity.js";
2
- export { OperationErrorCode } from "./protocol/error.js";
@@ -1,39 +0,0 @@
1
- import type { Binding, NodePath } from "@babel/traverse";
2
- import * as t from "@babel/types";
3
- import type { TextExpressionSource } from "../graph/types.js";
4
- import type { ValuePathSegment } from "../ast/types.js";
5
- export type BindingGraphNodeKind = "literal" | "local-binding" | "param" | "prop-default" | "alias" | "imported-binding" | "hook-state" | "async-result";
6
- export type BindingGraphEdgeKind = "assigned-from" | "destructured-from" | "defaulted-from" | "passed-prop" | "imported-from" | "setter-updated-by";
7
- export interface BindingGraphNode {
8
- id: string;
9
- kind: BindingGraphNodeKind;
10
- name: string;
11
- path: NodePath;
12
- }
13
- export interface BindingGraphEdge {
14
- from: string;
15
- to: string;
16
- kind: BindingGraphEdgeKind;
17
- }
18
- export interface BindingGraph {
19
- nodes: BindingGraphNode[];
20
- edges: BindingGraphEdge[];
21
- }
22
- export interface PropDefaultBinding {
23
- propName: string;
24
- componentName: string;
25
- expressionPath: NodePath<t.Expression>;
26
- displayPath: string;
27
- }
28
- export interface ParamPropReference {
29
- propName: string;
30
- remainingPath: ValuePathSegment[];
31
- }
32
- export interface AliasInitializer {
33
- expressionPath: NodePath<t.Expression>;
34
- }
35
- export declare function createBindingGraph(): BindingGraph;
36
- export declare function findAliasInitializer(binding: Binding): AliasInitializer | null;
37
- export declare function getParamPropReference(binding: Binding, sourceInfo?: TextExpressionSource): ParamPropReference | null;
38
- export declare function findPropDefaultBinding(binding: Binding, componentName: string, expectedPropName?: string): PropDefaultBinding | null;
39
- export declare function findPatternBindingPath(pattern: t.PatternLike, bindingName: string, prefix?: ValuePathSegment[]): ValuePathSegment[] | null;
@@ -1,184 +0,0 @@
1
- import * as t from "@babel/types";
2
- export function createBindingGraph() {
3
- return { nodes: [], edges: [] };
4
- }
5
- export function findAliasInitializer(binding) {
6
- if (binding.path.isVariableDeclarator()) {
7
- const initPath = binding.path.get("init");
8
- return initPath?.isExpression() ? { expressionPath: initPath } : null;
9
- }
10
- if (!binding.path.isIdentifier() ||
11
- !binding.path.parentPath?.isVariableDeclarator()) {
12
- return null;
13
- }
14
- const initPath = binding.path.parentPath.get("init");
15
- if (!initPath?.isExpression()) {
16
- return null;
17
- }
18
- return { expressionPath: initPath };
19
- }
20
- export function getParamPropReference(binding, sourceInfo) {
21
- if (binding.path.isObjectPattern()) {
22
- return sourceInfo
23
- ? {
24
- propName: sourceInfo.base,
25
- remainingPath: sourceInfo.path,
26
- }
27
- : null;
28
- }
29
- const objectProperty = getDestructuredPropPropertyPath(binding);
30
- if (objectProperty) {
31
- const propName = getObjectPropertyKey(objectProperty.node);
32
- if (!propName) {
33
- return null;
34
- }
35
- return {
36
- propName,
37
- remainingPath: sourceInfo?.path ?? [],
38
- };
39
- }
40
- if (binding.path.isIdentifier() &&
41
- binding.path.key === 0 &&
42
- Array.isArray(binding.path.container)) {
43
- const [firstPath, ...restPath] = sourceInfo?.path ?? [];
44
- if (!firstPath || firstPath.kind !== "property") {
45
- return null;
46
- }
47
- return {
48
- propName: firstPath.name,
49
- remainingPath: restPath,
50
- };
51
- }
52
- return null;
53
- }
54
- export function findPropDefaultBinding(binding, componentName, expectedPropName) {
55
- if (binding.path.isObjectPattern()) {
56
- for (const property of binding.path.get("properties")) {
57
- if (!property.isObjectProperty()) {
58
- continue;
59
- }
60
- const propName = getObjectPropertyKey(property.node);
61
- if (!propName || (expectedPropName && propName !== expectedPropName)) {
62
- continue;
63
- }
64
- const valuePath = property.get("value");
65
- if (!valuePath.isAssignmentPattern()) {
66
- continue;
67
- }
68
- const rightPath = valuePath.get("right");
69
- if (!rightPath.isExpression()) {
70
- continue;
71
- }
72
- return {
73
- propName,
74
- componentName,
75
- expressionPath: rightPath,
76
- displayPath: `${componentName}.${propName}.default`,
77
- };
78
- }
79
- }
80
- const assignmentPath = getDefaultAssignmentPath(binding);
81
- if (!assignmentPath) {
82
- return null;
83
- }
84
- const objectProperty = assignmentPath.parentPath;
85
- if (!objectProperty?.isObjectProperty()) {
86
- return null;
87
- }
88
- const propName = getObjectPropertyKey(objectProperty.node);
89
- if (!propName || (expectedPropName && propName !== expectedPropName)) {
90
- return null;
91
- }
92
- const rightPath = assignmentPath.get("right");
93
- if (!rightPath.isExpression()) {
94
- return null;
95
- }
96
- return {
97
- propName,
98
- componentName,
99
- expressionPath: rightPath,
100
- displayPath: `${componentName}.${propName}.default`,
101
- };
102
- }
103
- export function findPatternBindingPath(pattern, bindingName, prefix = []) {
104
- if (t.isIdentifier(pattern)) {
105
- return pattern.name === bindingName ? prefix : null;
106
- }
107
- if (t.isObjectPattern(pattern)) {
108
- for (const property of pattern.properties) {
109
- if (t.isObjectProperty(property)) {
110
- const key = getObjectPropertyKey(property);
111
- if (!key) {
112
- continue;
113
- }
114
- const result = findPatternBindingPath(property.value, bindingName, [...prefix, { kind: "property", name: key }]);
115
- if (result) {
116
- return result;
117
- }
118
- }
119
- else if (t.isRestElement(property)) {
120
- const result = findPatternBindingPath(property.argument, bindingName, prefix);
121
- if (result) {
122
- return result;
123
- }
124
- }
125
- }
126
- }
127
- if (t.isArrayPattern(pattern)) {
128
- for (let index = 0; index < pattern.elements.length; index += 1) {
129
- const element = pattern.elements[index];
130
- if (!element) {
131
- continue;
132
- }
133
- const target = t.isRestElement(element) ? element.argument : element;
134
- const result = findPatternBindingPath(target, bindingName, [...prefix, { kind: "index", index }]);
135
- if (result) {
136
- return result;
137
- }
138
- }
139
- }
140
- if (t.isAssignmentPattern(pattern)) {
141
- return findPatternBindingPath(pattern.left, bindingName, prefix);
142
- }
143
- return null;
144
- }
145
- function getDefaultAssignmentPath(binding) {
146
- if (!binding.path.isIdentifier()) {
147
- return null;
148
- }
149
- const parent = binding.path.parentPath;
150
- if (parent?.isAssignmentPattern() && parent.node.left === binding.path.node) {
151
- return parent;
152
- }
153
- return null;
154
- }
155
- function getDestructuredPropPropertyPath(binding) {
156
- if (!binding.path.isIdentifier()) {
157
- return null;
158
- }
159
- const directParent = binding.path.parentPath;
160
- if (directParent?.isObjectProperty() &&
161
- directParent.parentPath?.isObjectPattern()) {
162
- return directParent;
163
- }
164
- const assignmentParent = directParent?.isAssignmentPattern()
165
- ? directParent.parentPath
166
- : null;
167
- if (assignmentParent?.isObjectProperty() &&
168
- assignmentParent.parentPath?.isObjectPattern()) {
169
- return assignmentParent;
170
- }
171
- return null;
172
- }
173
- function getObjectPropertyKey(property) {
174
- if (property.computed) {
175
- return null;
176
- }
177
- if (t.isIdentifier(property.key)) {
178
- return property.key.name;
179
- }
180
- if (t.isStringLiteral(property.key)) {
181
- return property.key.value;
182
- }
183
- return null;
184
- }
@@ -1,15 +0,0 @@
1
- export interface SourceRangeLike {
2
- startLine: number;
3
- startColumn: number;
4
- endLine: number;
5
- endColumn: number;
6
- }
7
- export interface PolicyNodeLike {
8
- sourceRange: SourceRangeLike;
9
- }
10
- export interface CapabilityPolicyResult {
11
- allowed: boolean;
12
- reason?: string;
13
- }
14
- export declare function evaluateInsertChildPolicy(source: string, node: PolicyNodeLike): CapabilityPolicyResult;
15
- export declare function evaluateCrossFileMovePolicy(source: string, node: PolicyNodeLike): CapabilityPolicyResult;