@shapeshift-labs/frontier-lang-compiler 0.2.81 → 0.2.82

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.
@@ -120,6 +120,20 @@ export interface SemanticEditScript {
120
120
  readonly metadata?: Record<string, unknown>;
121
121
  }
122
122
 
123
+ export interface SemanticEditProjectionEdit {
124
+ readonly operationId?: string;
125
+ readonly status: 'applied' | 'already-applied';
126
+ readonly headStart: number;
127
+ readonly headEnd: number;
128
+ readonly workerStart?: number;
129
+ readonly workerEnd?: number;
130
+ readonly deletedBytes: number;
131
+ readonly replacementBytes: number;
132
+ readonly deletedTextHash?: string;
133
+ readonly replacementTextHash?: string;
134
+ readonly replacementText?: string;
135
+ }
136
+
123
137
  export interface SemanticEditProjection {
124
138
  readonly kind: 'frontier.lang.semanticEditProjection';
125
139
  readonly version: 1;
@@ -135,6 +149,7 @@ export interface SemanticEditProjection {
135
149
  readonly projectedHash?: string;
136
150
  readonly appliedOperations: readonly string[];
137
151
  readonly skippedOperations: readonly string[];
152
+ readonly edits: readonly SemanticEditProjectionEdit[];
138
153
  readonly sourceText?: string;
139
154
  readonly admission: {
140
155
  readonly status: 'auto-merge-candidate' | 'blocked';
@@ -32,6 +32,7 @@ export function projectSemanticEditScriptToSource(input = {}) {
32
32
  projectedHash: sourceText === undefined ? undefined : hashSemanticValue(sourceText),
33
33
  appliedOperations: blocked ? [] : edits.map((edit) => edit.operationId),
34
34
  skippedOperations: blocked ? (script.operations ?? []).map((operation) => operation.id) : [],
35
+ edits: blocked ? [] : edits.map(projectionEditRecord),
35
36
  sourceText,
36
37
  admission: {
37
38
  status: blocked ? 'blocked' : 'auto-merge-candidate',
@@ -43,6 +44,8 @@ export function projectSemanticEditScriptToSource(input = {}) {
43
44
  autoMergeClaim: false,
44
45
  semanticEquivalenceClaim: false,
45
46
  editCount: edits.length,
47
+ appliedEditCount: edits.filter((edit) => !edit.alreadyApplied).length,
48
+ alreadyAppliedEditCount: edits.filter((edit) => edit.alreadyApplied).length,
46
49
  ...input.metadata
47
50
  })
48
51
  };
@@ -51,7 +54,7 @@ export function projectSemanticEditScriptToSource(input = {}) {
51
54
 
52
55
  function sourceEditForOperation(operation, workerSourceText, headSourceText) {
53
56
  if (operation.status === 'already-applied') {
54
- return { ok: true, value: { operationId: operation.id, start: 0, end: 0, replacement: '', alreadyApplied: true } };
57
+ return { ok: true, value: { operationId: operation.id, start: 0, end: 0, replacement: '', current: '', alreadyApplied: true } };
55
58
  }
56
59
  if (operation.status !== 'portable') return { ok: false, reasonCodes: [`operation-not-portable:${operation.id}`] };
57
60
  const workerOffsets = spanOffsets(workerSourceText, operation.spans?.worker);
@@ -70,7 +73,34 @@ function sourceEditForOperation(operation, workerSourceText, headSourceText) {
70
73
  reasons.push(`head-span-hash-mismatch:${operation.id}`);
71
74
  }
72
75
  if (reasons.length) return { ok: false, reasonCodes: reasons };
73
- return { ok: true, value: { operationId: operation.id, start: headOffsets.start, end: headOffsets.end, replacement } };
76
+ return {
77
+ ok: true,
78
+ value: {
79
+ operationId: operation.id,
80
+ start: headOffsets.start,
81
+ end: headOffsets.end,
82
+ workerStart: workerOffsets.start,
83
+ workerEnd: workerOffsets.end,
84
+ replacement,
85
+ current
86
+ }
87
+ };
88
+ }
89
+
90
+ function projectionEditRecord(edit) {
91
+ return compactRecord({
92
+ operationId: edit.operationId,
93
+ status: edit.alreadyApplied ? 'already-applied' : 'applied',
94
+ headStart: edit.start,
95
+ headEnd: edit.end,
96
+ workerStart: edit.workerStart,
97
+ workerEnd: edit.workerEnd,
98
+ deletedBytes: edit.current.length,
99
+ replacementBytes: edit.replacement.length,
100
+ deletedTextHash: hashSemanticValue(edit.current),
101
+ replacementTextHash: hashSemanticValue(edit.replacement),
102
+ replacementText: edit.replacement
103
+ });
74
104
  }
75
105
 
76
106
  function applySourceEdits(sourceText, edits) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-compiler",
3
- "version": "0.2.81",
3
+ "version": "0.2.82",
4
4
  "description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",