@shapeshift-labs/frontier-lang-compiler 0.2.89 → 0.2.90

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.
@@ -44,6 +44,13 @@ export interface CreateSemanticTransformIdentityRecordOptions extends Partial<Se
44
44
  readonly operationId?: string;
45
45
  }
46
46
 
47
+ export interface DeriveSemanticTransformIdentityRecordsOptions extends CreateSemanticTransformIdentityRecordOptions {
48
+ readonly semanticEditProjection?: unknown;
49
+ readonly semanticEditProjections?: readonly unknown[] | unknown;
50
+ readonly projection?: unknown;
51
+ readonly projections?: readonly unknown[] | unknown;
52
+ }
53
+
47
54
  export type CreateSemanticTransformIdentityRecordInput =
48
55
  | Partial<SemanticTransformIdentityRecord>
49
56
  | Record<string, unknown>;
@@ -55,3 +62,7 @@ export declare function createSemanticTransformIdentityRecord(
55
62
  export declare function semanticTransformIdentityFields(
56
63
  record?: SemanticTransformIdentityRecord | Record<string, unknown>
57
64
  ): SemanticTransformIdentityRecord;
65
+ export declare function deriveSemanticTransformIdentityRecords(
66
+ input?: DeriveSemanticTransformIdentityRecordsOptions | Record<string, unknown>,
67
+ options?: DeriveSemanticTransformIdentityRecordsOptions
68
+ ): readonly SemanticTransformIdentityRecord[];
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ export { queryNativeParserFeatureMatrix } from './internal/index-impl/queryNativ
68
68
  export { queryProjectionReadinessMatrix } from './internal/index-impl/queryProjectionReadinessMatrix.js';
69
69
  export { createSemanticPatchBundleRecord, querySemanticPatchBundleRecords, SemanticPatchBundleAdmissionStatuses } from './internal/index-impl/semanticPatchBundleRecords.js';
70
70
  export { compareSemanticPatchBundleRecords, querySemanticPatchBundleOverlaps, SemanticPatchBundleOverlapKinds, SemanticPatchBundleOverlapStatuses } from './internal/index-impl/semanticPatchBundleOverlaps.js';
71
- export { createSemanticTransformIdentityRecord, semanticTransformIdentityFields } from './internal/index-impl/semanticTransformIdentityRecords.js';
71
+ export { createSemanticTransformIdentityRecord, deriveSemanticTransformIdentityRecords, semanticTransformIdentityFields } from './internal/index-impl/semanticTransformIdentityRecords.js';
72
72
  export { createSemanticMergeCandidateAdmissionRecord, decorateSemanticMergeCandidateForAdmission, querySemanticMergeCandidateAdmissionOverlaps, SemanticMergeCandidateProjectionRisks, semanticMergeCandidateReadinessSortKey, sortSemanticMergeCandidateAdmissionRecords } from './internal/index-impl/semanticMergeCandidateRecords.js';
73
73
  export { querySemanticMergeConflictClasses, SemanticMergeConflictClasses, semanticMergeConflictRiskScore, sortSemanticMergeCandidatesByConflictRisk, summarizeSemanticMergeConflicts } from './internal/index-impl/semanticMergeConflicts.js';
74
74
  export { createSemanticEditScript, SemanticEditScriptAdmissionStatuses } from './internal/index-impl/semanticEditScripts.js';
@@ -72,17 +72,30 @@ export function semanticTransformIdentityFields(record = {}) {
72
72
  }
73
73
 
74
74
  export function normalizeSemanticTransformIdentityRecords(records, context = {}) {
75
- return array(records).filter(Boolean).map((record) => createSemanticTransformIdentityRecord(record, context));
75
+ return uniqueRecords(array(records).filter(Boolean).map((record) => createSemanticTransformIdentityRecord(record, context)));
76
76
  }
77
77
 
78
78
  export function semanticTransformInputs(source = {}, options = {}) {
79
+ const projections = [
80
+ ...array(options.semanticEditProjections ?? options.semanticEditProjection),
81
+ ...array(source.semanticEditProjections ?? source.semanticEditProjection)
82
+ ];
79
83
  return [
80
84
  ...array(options.semanticTransformIdentities ?? options.semanticTransformIdentity),
81
85
  ...array(source.semanticTransformIdentities ?? source.semanticTransformIdentity ?? source.semanticTransforms),
82
- ...array(source.index?.semanticTransformIdentities)
86
+ ...array(source.index?.semanticTransformIdentities),
87
+ ...deriveSemanticTransformIdentityRecords({ semanticEditProjections: projections }, { ...source, ...options })
83
88
  ];
84
89
  }
85
90
 
91
+ export function deriveSemanticTransformIdentityRecords(input = {}, options = {}) {
92
+ const projections = semanticEditProjectionInputs(input);
93
+ return uniqueRecords(projections.flatMap((projection, projectionIndex) => {
94
+ const edits = array(projection.edits).filter((edit) => edit && typeof edit === 'object');
95
+ return edits.map((edit, editIndex) => transformRecordForProjectionEdit(edit, projection, input, options, projectionIndex, editIndex));
96
+ }));
97
+ }
98
+
86
99
  export function semanticTransformRecordIndex(records, source = {}) {
87
100
  const index = source.index ?? {};
88
101
  return {
@@ -120,6 +133,49 @@ function semanticTransformKey(record) {
120
133
  return ['semantic-transform', route, scope].filter(Boolean).join(':');
121
134
  }
122
135
 
136
+ function semanticEditProjectionInputs(input) {
137
+ if (input.kind === 'frontier.lang.semanticEditProjection') return [input];
138
+ return [
139
+ ...array(input.semanticEditProjections ?? input.semanticEditProjection),
140
+ ...array(input.projections ?? input.projection)
141
+ ].filter((entry) => entry && typeof entry === 'object');
142
+ }
143
+
144
+ function transformRecordForProjectionEdit(edit, projection, input, options, projectionIndex, editIndex) {
145
+ const sourceLanguage = firstString(edit.sourceLanguage, edit.language, input.sourceLanguage, options.sourceLanguage, projection.sourceLanguage, projection.language);
146
+ const targetLanguage = firstString(edit.targetLanguage, edit.projectedLanguage, input.targetLanguage, options.targetLanguage, projection.targetLanguage, projection.projectedLanguage, projection.language);
147
+ const sourcePath = firstString(edit.originalSourcePath, edit.sourcePath, input.sourcePath, options.sourcePath, projection.sourcePath);
148
+ const targetPath = firstString(edit.targetPath, edit.targetSourcePath, input.targetPath, options.targetPath, projection.targetPath, projection.projectedSourcePath, projection.sourcePath);
149
+ const transformId = [projection.id, edit.operationId, projectionIndex, editIndex].filter((entry) => entry !== undefined && entry !== null).join(':');
150
+ return createSemanticTransformIdentityRecord(edit, {
151
+ id: `semantic_transform_${idFragment(transformId)}`,
152
+ sourceLanguage,
153
+ targetLanguage,
154
+ sourcePath,
155
+ targetPath,
156
+ baseHash: firstString(edit.baseHash, projection.baseHash, input.baseHash, options.baseHash),
157
+ targetHash: firstString(edit.targetHash, projection.projectedHash, projection.targetHash, input.targetHash, options.targetHash),
158
+ readiness: firstString(edit.readiness, projection.admission?.status, projection.status),
159
+ evidenceIds: uniqueStrings([...strings(input.evidenceIds), ...strings(options.evidenceIds), ...strings(projection.evidenceIds), ...strings(edit.evidenceIds)]),
160
+ metadata: compactRecord({
161
+ sourceProjectionId: projection.id,
162
+ sourceProjectionEditOperationId: edit.operationId
163
+ })
164
+ });
165
+ }
166
+
167
+ function uniqueRecords(records) {
168
+ const seen = new Set();
169
+ const result = [];
170
+ for (const record of records) {
171
+ const key = firstString(record.id, record.transformContentHash, record.projectionIdentityHash, record.transformIdentityHash);
172
+ if (!key || seen.has(key)) continue;
173
+ seen.add(key);
174
+ result.push(record);
175
+ }
176
+ return result;
177
+ }
178
+
123
179
  function array(value) { if (value === undefined || value === null) return []; return Array.isArray(value) ? value : [value]; }
124
180
  function strings(value) { return array(value).map((entry) => String(entry ?? '')).filter(Boolean); }
125
181
  function firstString(...values) { return values.map((value) => value === undefined || value === null ? '' : String(value)).find(Boolean); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-compiler",
3
- "version": "0.2.89",
3
+ "version": "0.2.90",
4
4
  "description": "Compiler facade for Frontier Lang source documents and language projection adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",