@elementumai/edk 0.10.3 → 0.11.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.
- package/README.md +11 -7
- package/dist-sdk/src/catalog/token.js +2 -1
- package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
- package/dist-sdk/src/engine/build/context.d.ts +4 -0
- package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
- package/dist-sdk/src/engine/coverage-gaps.js +3 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
- package/dist-sdk/src/engine/ei/run.d.ts +22 -0
- package/dist-sdk/src/engine/ei/run.js +99 -18
- package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
- package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
- package/dist-sdk/src/engine/ei/state.d.ts +1 -1
- package/dist-sdk/src/engine/ei/state.js +17 -4
- package/dist-sdk/src/engine/progress.d.ts +3 -1
- package/dist-sdk/src/engine/progress.js +7 -3
- package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
- package/dist-sdk/src/engine/pull/authored-address.js +180 -29
- package/dist-sdk/src/engine/pull/context.d.ts +52 -7
- package/dist-sdk/src/engine/pull/context.js +7 -4
- package/dist-sdk/src/engine/tf/index.d.ts +3 -2
- package/dist-sdk/src/engine/tf/index.js +3 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
- package/dist-sdk/src/engine/tf/labels.js +50 -0
- package/dist-sdk/src/engine/tf/model.d.ts +2 -0
- package/dist-sdk/src/engine/tf/model.js +26 -0
- package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
- package/dist-sdk/src/engine/tf/scan.js +123 -0
- package/dist-sdk/src/engine/validation.d.ts +2 -0
- package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
- package/dist-sdk/src/engine/workspace/loader.js +20 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
- package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
- package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
- package/dist-sdk/src/entities/access-policy/module.js +5 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
- package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
- package/dist-sdk/src/entities/agent/build.js +7 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
- package/dist-sdk/src/entities/agent/from-tf.js +13 -3
- package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
- package/dist-sdk/src/entities/agent/to-tf.js +28 -17
- package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
- package/dist-sdk/src/entities/agent/tools.js +6 -2
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -3
- package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
- package/dist-sdk/src/entities/agent-tool/types.js +13 -9
- package/dist-sdk/src/entities/app/build.d.ts +11 -0
- package/dist-sdk/src/entities/app/build.js +1 -0
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +11 -7
- package/dist-sdk/src/entities/app/from-tf.js +19 -9
- package/dist-sdk/src/entities/app/to-tf.js +6 -4
- package/dist-sdk/src/entities/automation/build.d.ts +2 -7
- package/dist-sdk/src/entities/automation/build.js +55 -16
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
- package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
- package/dist-sdk/src/entities/automation/from-tf.js +456 -34
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +22 -2
- package/dist-sdk/src/entities/automation/module.js +273 -58
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -3
- package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
- package/dist-sdk/src/entities/automation/run-target.js +99 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
- package/dist-sdk/src/entities/automation/script-code.js +24 -3
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
- package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -3
- package/dist-sdk/src/entities/automation/to-tf.js +171 -58
- package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
- package/dist-sdk/src/entities/automation/triggers.js +40 -0
- package/dist-sdk/src/entities/automation/types.d.ts +21 -0
- package/dist-sdk/src/entities/automation/types.js +26 -0
- package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
- package/dist-sdk/src/entities/element/build.d.ts +10 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +16 -9
- package/dist-sdk/src/entities/element/to-tf.js +6 -4
- package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
- package/dist-sdk/src/entities/field/from-tf.js +79 -1
- package/dist-sdk/src/entities/field/module.js +7 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
- package/dist-sdk/src/entities/field/to-tf.js +51 -0
- package/dist-sdk/src/entities/file-reader/module.js +3 -3
- package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
- package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
- package/dist-sdk/src/entities/file-reader/types.js +7 -0
- package/dist-sdk/src/entities/org/group.d.ts +1 -0
- package/dist-sdk/src/entities/org/group.js +2 -1
- package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
- package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
- package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
- package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
- package/dist-sdk/src/entities/role/from-tf.js +24 -7
- package/dist-sdk/src/entities/role/to-tf.js +25 -7
- package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
- package/dist-sdk/src/entities/service-account/module.js +15 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
- package/dist-sdk/src/entities/skill/from-tf.js +10 -3
- package/dist-sdk/src/entities/skill/module.js +44 -2
- package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
- package/dist-sdk/src/entities/skill/to-tf.js +23 -14
- package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
- package/dist-sdk/src/entities/skill/tools.js +6 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +10 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
- package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
- package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
- package/dist-sdk/src/entities/view/from-tf.js +503 -25
- package/dist-sdk/src/entities/view/module.js +15 -0
- package/dist-sdk/src/entities/view/portable.d.ts +11 -0
- package/dist-sdk/src/entities/view/portable.js +47 -0
- package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
- package/dist-sdk/src/entities/view/to-tf.js +25 -7
- package/dist-sdk/src/entities/view/types.js +1 -1
- package/dist-sdk/src/entities/widget/build.d.ts +4 -3
- package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/widget/from-tf.js +100 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
- package/dist-sdk/src/entities/widget/to-tf.js +77 -14
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
- package/dist-sdk/src/graph/field-resource-types.js +11 -0
- package/dist-sdk/src/graph/index.d.ts +28 -3
- package/dist-sdk/src/graph/index.js +12 -2
- package/dist-sdk/src/graph/types.d.ts +164 -5
- package/package.json +1 -1
|
@@ -6,13 +6,17 @@
|
|
|
6
6
|
* module never names the app's own resource type.
|
|
7
7
|
*/
|
|
8
8
|
import { agentViewLayoutFromTf, viewBlocksFromTf, } from "./agent-view-layout-from-tf.js";
|
|
9
|
-
import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
|
|
9
|
+
import { dataRefLabel, optionalString, plainObject, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
|
|
10
10
|
import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
|
|
11
|
-
import {
|
|
11
|
+
import { canonicalImportId } from "../../engine/pull/authored-address.js";
|
|
12
|
+
import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
|
|
13
|
+
import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
|
|
14
|
+
import { expr, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
12
15
|
import { lostStageMessage, pulledStageHandle } from "../app/stage-keys.js";
|
|
13
|
-
import { decodeForeignDataField, fieldKeyFromTfValue } from "../field/from-tf.js";
|
|
16
|
+
import { decodeForeignDataField, fieldBlockOwner, fieldKeyFromForeignDataLabel, fieldKeyFromTfValue, ownerMayHaveCustomField } from "../field/from-tf.js";
|
|
14
17
|
import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
|
|
15
18
|
import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
|
|
19
|
+
import { DASHBOARD_WIDGET_RESOURCE_TYPE } from "../dashboard-widget/module.js";
|
|
16
20
|
import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
|
|
17
21
|
import { filterFromTf, principalList } from "../access-policy/from-tf.js";
|
|
18
22
|
import { listViewDensity, } from "./build.js";
|
|
@@ -86,14 +90,25 @@ export function viewsFromTf(layoutBlocks, listViewBlocks, calendarViewBlocks, ka
|
|
|
86
90
|
}
|
|
87
91
|
// Singleton per aspect — at most one block is expected; extras are reported.
|
|
88
92
|
let viewOrder;
|
|
93
|
+
let deleteDefaultListView;
|
|
89
94
|
for (const [i, block] of managedViewOrderBlocks.entries()) {
|
|
90
95
|
if (i > 0) {
|
|
91
96
|
ctx.diagnostics.push(`unexpected additional elementum_managed_view_order.${block.label ?? "?"} for one aspect; ignored`);
|
|
92
97
|
continue;
|
|
93
98
|
}
|
|
94
99
|
viewOrder = managedViewOrderFromTf(block, owner, keyByAddress, ctx);
|
|
100
|
+
const deleteAttr = block.attrs["delete_platform_default_list_view"];
|
|
101
|
+
if (deleteAttr === true)
|
|
102
|
+
deleteDefaultListView = true;
|
|
103
|
+
else if (deleteAttr !== undefined && deleteAttr !== false && deleteAttr !== null) {
|
|
104
|
+
ctx.diagnostics.push(`managed view order "${block.label ?? "?"}": delete_platform_default_list_view is not a boolean; dropped`);
|
|
105
|
+
}
|
|
95
106
|
}
|
|
96
|
-
return {
|
|
107
|
+
return {
|
|
108
|
+
layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews,
|
|
109
|
+
...(viewOrder !== undefined ? { viewOrder } : {}),
|
|
110
|
+
...(deleteDefaultListView !== undefined ? { deleteDefaultListView } : {}),
|
|
111
|
+
};
|
|
97
112
|
}
|
|
98
113
|
function customViewFromTf(block, owner, ctx) {
|
|
99
114
|
const label = block.label;
|
|
@@ -132,7 +147,7 @@ function customViewFromTf(block, owner, ctx) {
|
|
|
132
147
|
if (layoutAttr !== undefined && layoutAttr !== null) {
|
|
133
148
|
if (!isTfExpr(layoutAttr) || layoutAttr.$expr !== "jsonencode")
|
|
134
149
|
return unmanaged("layout is not a jsonencode(...) expression");
|
|
135
|
-
const decoded = viewBlocksFromTf(layoutAttr.value, layoutRefOptions(owner, ctx));
|
|
150
|
+
const decoded = viewBlocksFromTf(layoutAttr.value, layoutRefOptions(owner, ctx, where));
|
|
136
151
|
if (!decoded.ok)
|
|
137
152
|
return unmanaged(decoded.reason);
|
|
138
153
|
layout = decoded.layout;
|
|
@@ -222,8 +237,8 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
|
|
|
222
237
|
return undefined;
|
|
223
238
|
}
|
|
224
239
|
const fields = [];
|
|
225
|
-
for (const value of raw) {
|
|
226
|
-
const key = fieldRefFromTf(value, owner
|
|
240
|
+
for (const [index, value] of raw.entries()) {
|
|
241
|
+
const key = fieldRefFromTf(value, owner, ctx, `${where} ${attr}[${index}]`);
|
|
227
242
|
if (key !== undefined)
|
|
228
243
|
fields.push(key);
|
|
229
244
|
}
|
|
@@ -231,7 +246,7 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
|
|
|
231
246
|
};
|
|
232
247
|
const columns = readFields("columns") ?? [];
|
|
233
248
|
const displayByField = attrs["display_by_field"] !== undefined
|
|
234
|
-
? fieldRefFromTf(attrs["display_by_field"], owner
|
|
249
|
+
? fieldRefFromTf(attrs["display_by_field"], owner, ctx, `${where} display_by_field`)
|
|
235
250
|
: undefined;
|
|
236
251
|
const allowedFilterFields = includeAllowedFilterFields ? readFields("allowed_filter_fields") : undefined;
|
|
237
252
|
const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
|
|
@@ -257,7 +272,7 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
|
|
|
257
272
|
* How a blocks layout's references pull: the owner and its fields, and other
|
|
258
273
|
* apps and elements and their fields through the export's data lookups.
|
|
259
274
|
*/
|
|
260
|
-
function layoutRefOptions(owner, ctx) {
|
|
275
|
+
function layoutRefOptions(owner, ctx, where) {
|
|
261
276
|
const foreignSource = (value) => {
|
|
262
277
|
for (const [type, kind] of [["elementum_app", "app"], ["elementum_element", "element"]]) {
|
|
263
278
|
const dataLabel = dataRefLabel(value, type);
|
|
@@ -270,7 +285,9 @@ function layoutRefOptions(owner, ctx) {
|
|
|
270
285
|
};
|
|
271
286
|
return {
|
|
272
287
|
isOwnApp: (value) => resourceRefLabel(value, owner.type) === owner.label,
|
|
273
|
-
fieldKey: (value) => fieldRefFromTf(value, owner
|
|
288
|
+
fieldKey: (value) => fieldRefFromTf(value, owner, ctx, `${where} layout`),
|
|
289
|
+
ownFieldKey: (id, systemKeys) => ownExtractedFieldKey(id, owner, ctx, systemKeys),
|
|
290
|
+
noteRawFieldId: (id) => noteRawUnextractedFieldId(id, owner, ctx, `${where} layout`),
|
|
274
291
|
foreignSource,
|
|
275
292
|
foreignField: (value) => {
|
|
276
293
|
const dataLabel = dataRefLabel(value, "elementum_field");
|
|
@@ -322,7 +339,7 @@ function agentViewFromTf(block, owner, ctx) {
|
|
|
322
339
|
const filter = viewFilter(attrs["filter"], owner, where, ctx);
|
|
323
340
|
let layout;
|
|
324
341
|
if (attrs["layout"] !== undefined && attrs["layout"] !== null) {
|
|
325
|
-
const decoded = agentViewLayoutFromTf(attrs["layout"], layoutRefOptions(owner, ctx));
|
|
342
|
+
const decoded = agentViewLayoutFromTf(attrs["layout"], layoutRefOptions(owner, ctx, where));
|
|
326
343
|
if (!decoded.ok) {
|
|
327
344
|
// The code owns the layout: printing the view without it would make the
|
|
328
345
|
// next apply clear the live customization. Leave the view unmanaged.
|
|
@@ -370,8 +387,8 @@ function layoutFromTf(block, owner, ctx) {
|
|
|
370
387
|
const sectionsAttr = attrs["sections"];
|
|
371
388
|
const sections = [];
|
|
372
389
|
if (Array.isArray(sectionsAttr)) {
|
|
373
|
-
for (const item of sectionsAttr) {
|
|
374
|
-
const section = sectionFromTf(item, owner
|
|
390
|
+
for (const [index, item] of sectionsAttr.entries()) {
|
|
391
|
+
const section = sectionFromTf(item, owner, `${where} sections[${index}]`, ctx);
|
|
375
392
|
if (section !== undefined)
|
|
376
393
|
sections.push(section);
|
|
377
394
|
}
|
|
@@ -429,8 +446,8 @@ function layoutFromTf(block, owner, ctx) {
|
|
|
429
446
|
const sectionsAttr = attrs["sections"];
|
|
430
447
|
const sections = [];
|
|
431
448
|
if (Array.isArray(sectionsAttr)) {
|
|
432
|
-
for (const item of sectionsAttr) {
|
|
433
|
-
const section = sectionFromTf(item, owner
|
|
449
|
+
for (const [index, item] of sectionsAttr.entries()) {
|
|
450
|
+
const section = sectionFromTf(item, owner, `${where} sections[${index}]`, ctx);
|
|
434
451
|
if (section !== undefined)
|
|
435
452
|
sections.push(section);
|
|
436
453
|
}
|
|
@@ -448,7 +465,9 @@ function stageIndexFromTf(v, ownerLabel) {
|
|
|
448
465
|
const seg = v.path[0];
|
|
449
466
|
return v.path.length === 1 && typeof seg === "object" && "index" in seg ? seg.index : undefined;
|
|
450
467
|
}
|
|
451
|
-
function sectionFromTf(raw,
|
|
468
|
+
function sectionFromTf(raw, owner, where, ctx) {
|
|
469
|
+
const ownerTfLabel = owner.ownerTfLabel;
|
|
470
|
+
const scope = owner.scope ?? "app";
|
|
452
471
|
const rec = plainObject(raw);
|
|
453
472
|
if (rec === undefined) {
|
|
454
473
|
ctx.diagnostics.push(`${where}: a sections entry has an unrecognized shape; dropped`);
|
|
@@ -494,7 +513,7 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
|
|
|
494
513
|
const fields = [];
|
|
495
514
|
const widgets = [];
|
|
496
515
|
const widgetAts = {};
|
|
497
|
-
for (const f of fieldIds) {
|
|
516
|
+
for (const [index, f] of fieldIds.entries()) {
|
|
498
517
|
const widgetLabel = resourceRefLabel(f, WIDGET_RESOURCE_TYPE);
|
|
499
518
|
if (widgetLabel !== undefined) {
|
|
500
519
|
const key = scopedLabelToBagKey(ownerTfLabel, widgetLabel, scope);
|
|
@@ -504,7 +523,7 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
|
|
|
504
523
|
widgetAts[key] = fields.length;
|
|
505
524
|
continue;
|
|
506
525
|
}
|
|
507
|
-
const key = fieldRefFromTf(f,
|
|
526
|
+
const key = fieldRefFromTf(f, owner, ctx, `${where} field_ids[${index}]`);
|
|
508
527
|
if (key !== undefined)
|
|
509
528
|
fields.push(key);
|
|
510
529
|
}
|
|
@@ -522,10 +541,19 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
|
|
|
522
541
|
return section;
|
|
523
542
|
}
|
|
524
543
|
/** A `field_ids`/`columns` entry → a system-field key or a custom field's bag key. */
|
|
525
|
-
function fieldRefFromTf(v,
|
|
526
|
-
const
|
|
544
|
+
function fieldRefFromTf(v, owner, ctx, site) {
|
|
545
|
+
const ownerLabel = owner.label;
|
|
546
|
+
const fieldKey = fieldKeyFromTfValue(v, tfLabelToTsLabel(ownerLabel), owner.ownerTfLabel, owner.scope ?? "app", ctx);
|
|
527
547
|
if (fieldKey !== undefined)
|
|
528
|
-
return fieldKey;
|
|
548
|
+
return keptIdOrKey(unextractedFieldId(v, fieldKey, owner, ctx, site), fieldKey);
|
|
549
|
+
const ownData = ownDataFieldRef(v, owner, ctx, site, false);
|
|
550
|
+
if (ownData !== undefined)
|
|
551
|
+
return authoredRef(ownData);
|
|
552
|
+
// Clone: a bare id is the SOURCE app's, so it never stays as is (#1991).
|
|
553
|
+
if (typeof v === "string" && ctx.cloning !== undefined && PLATFORM_ID.test(v))
|
|
554
|
+
return authoredRef(bareFieldIdRef(v, owner, ctx, site));
|
|
555
|
+
if (typeof v === "string" && importedUnextractedFieldId(v, owner, ctx, site) !== undefined)
|
|
556
|
+
return v;
|
|
529
557
|
if (typeof v === "string" && v !== "") {
|
|
530
558
|
// The field itself couldn't be resolved to a portable reference at all
|
|
531
559
|
// - ei's own export already fell back to a bare platform-id string here
|
|
@@ -554,6 +582,451 @@ function fieldRefFromTf(v, ownerLabel, ownerTfLabel, scope, ctx) {
|
|
|
554
582
|
ctx.diagnostics.push(`field reference ${JSON.stringify(v)} does not resolve to a known field; dropped`);
|
|
555
583
|
return undefined;
|
|
556
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* What a field reference resolver returns when it failed closed: it recorded
|
|
587
|
+
* an authoring blocker for this one reference, so the caller authors nothing
|
|
588
|
+
* for it, not even a key it resolved (#1991). Other references at the same
|
|
589
|
+
* site resolve on their own.
|
|
590
|
+
*/
|
|
591
|
+
const FAILED_CLOSED = Symbol("failed closed");
|
|
592
|
+
/** A resolver's result as the value to author: undefined when it failed closed. */
|
|
593
|
+
function authoredRef(ref) {
|
|
594
|
+
return ref === FAILED_CLOSED ? undefined : ref;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* The platform id of a field reference whose field pull did not extract for
|
|
598
|
+
* this owner (#1736). Its key prints as nothing, so build drops the column
|
|
599
|
+
* or section field and plan removes it. The id keeps it: a raw platform id
|
|
600
|
+
* as is (a re-pull of this fix's own output), or a resource reference's
|
|
601
|
+
* import id. Print marks it as intentional through `unextractedFieldIds`.
|
|
602
|
+
* Undefined when the field was extracted; FAILED_CLOSED when this reference
|
|
603
|
+
* recorded an authoring blocker.
|
|
604
|
+
*/
|
|
605
|
+
function unextractedFieldId(v, fieldKey, owner, ctx, site, failClosed = false) {
|
|
606
|
+
if (owner.fieldKeys === undefined || owner.fieldKeys.has(fieldKey))
|
|
607
|
+
return undefined;
|
|
608
|
+
// A system key is never in the extracted fields bag (element audit keys
|
|
609
|
+
// never are; an app's only when system_field_config names it), yet print
|
|
610
|
+
// and build turn it into the owner's system-field local. It stays a key.
|
|
611
|
+
if (isOwnerSystemFieldKey(fieldKey, owner))
|
|
612
|
+
return undefined;
|
|
613
|
+
let field;
|
|
614
|
+
let id;
|
|
615
|
+
if (typeof v === "string") {
|
|
616
|
+
field = `"${fieldKey}"`;
|
|
617
|
+
id = PLATFORM_ID.test(v) ? v : undefined;
|
|
618
|
+
}
|
|
619
|
+
else if (isTfExpr(v) && v.$expr === "resource-attr") {
|
|
620
|
+
field = `${v.type}.${v.label}`;
|
|
621
|
+
const importId = ctx.importId(field);
|
|
622
|
+
const canonical = importId === undefined ? undefined : canonicalImportId(importId);
|
|
623
|
+
id = canonical !== undefined && PLATFORM_ID.test(canonical) ? canonical : undefined;
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
// A shape with no id to keep, such as a data source
|
|
627
|
+
// (`data.elementum_field.<label>.id`) or a local, for a field pull did not
|
|
628
|
+
// extract. A view outside a clone keeps it as before. Everywhere else it
|
|
629
|
+
// fails closed, naming the site and the key: the key would print as
|
|
630
|
+
// nothing, so handing it back would drop the reference silently (#1991).
|
|
631
|
+
if (!failClosed && ctx.cloning === undefined)
|
|
632
|
+
return undefined;
|
|
633
|
+
reportUnresolvableUnextractedField(ctx, `${unkeptFieldAddress(v)} (key ${JSON.stringify(fieldKey)})`, site, "which is a field of the source app that its export did not extract, so the clone would not have it", "which pull did not extract and which has no platform id to keep");
|
|
634
|
+
return FAILED_CLOSED;
|
|
635
|
+
}
|
|
636
|
+
if (id === undefined && ctx.cloning !== undefined) {
|
|
637
|
+
// Clone dropped the import blocks and never copies the field, so at
|
|
638
|
+
// every site, views included, it keeps only another owner's field, by
|
|
639
|
+
// the export's id, and fails on any other (#1990).
|
|
640
|
+
const kept = cloneKeptFieldId(v, field, owner, ctx);
|
|
641
|
+
if (typeof kept !== "string") {
|
|
642
|
+
reportUnresolvableUnextractedField(ctx, field, site, kept.reason);
|
|
643
|
+
return FAILED_CLOSED;
|
|
644
|
+
}
|
|
645
|
+
id = kept;
|
|
646
|
+
}
|
|
647
|
+
else if (id === undefined && failClosed) {
|
|
648
|
+
reportUnresolvableUnextractedField(ctx, field, site);
|
|
649
|
+
return FAILED_CLOSED;
|
|
650
|
+
}
|
|
651
|
+
reportUnextractedField(ctx, field, id, site, failClosed);
|
|
652
|
+
if (id !== undefined)
|
|
653
|
+
owner.unextractedFieldIds?.add(id);
|
|
654
|
+
return id;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Outside views, a reference to a field pull did not extract and has no
|
|
658
|
+
* platform id for fails the pull (Dax, #1978): leaving the entry out would
|
|
659
|
+
* make the next apply remove it. Each site is one blocker, so the pull-abort
|
|
660
|
+
* error names every one before any file is written. `site` starts with the
|
|
661
|
+
* holding resource's address (`type.label`).
|
|
662
|
+
*/
|
|
663
|
+
function reportUnresolvableUnextractedField(ctx, field, site, cloneReason, pullReason) {
|
|
664
|
+
const address = site.split(".").slice(0, 2).join(".");
|
|
665
|
+
const cloning = ctx.cloning !== undefined;
|
|
666
|
+
const description = cloning
|
|
667
|
+
? `${site} references field ${field}, ${cloneReason ?? "which the clone does not copy"}; the clone cannot keep this reference`
|
|
668
|
+
: `${site} references field ${field}, ${pullReason ?? "which pull did not extract and whose import block has no platform id"}, so the reference cannot be resolved`;
|
|
669
|
+
if (ctx.authoringBlockers?.some((blocker) => blocker.description === description) === true)
|
|
670
|
+
return;
|
|
671
|
+
reportAuthoringBlocker(ctx, { address, description, remedy: cloning ? UNRESOLVABLE_CLONE_FIELD_REMEDY : UNRESOLVABLE_UNEXTRACTED_FIELD_REMEDY });
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* A data source lookup of one of this owner's own fields
|
|
675
|
+
* (`data.elementum_field.<label>.id` whose object_id is the owner).
|
|
676
|
+
* `fieldKeyFromTfValue` keys a data source only for a system field, so
|
|
677
|
+
* without this the caller dropped it with only a diagnostic (#1991).
|
|
678
|
+
* - An extracted field resolves to its key by the data source's `name`.
|
|
679
|
+
* A name no extracted field has means the field was not extracted. Only
|
|
680
|
+
* with no name, or one two fields share, does the label decide, with ei's
|
|
681
|
+
* owner prefixes stripped (`elementum_app_<display name>_`, the namespace,
|
|
682
|
+
* the owner's label), as the widget decodes another owner's field.
|
|
683
|
+
* - A field pull did not extract fails closed with `unextractedFieldId`'s
|
|
684
|
+
* report, naming `site` and that key (or the name, when the label's key
|
|
685
|
+
* is another, extracted field's). `failClosed` is false for views, which fail
|
|
686
|
+
* closed only in a clone; in pull they keep dropping it (#1978).
|
|
687
|
+
* Undefined for any other value, a data source whose owner is another or
|
|
688
|
+
* unknown, or an unextracted field in a pull view: the caller's existing
|
|
689
|
+
* handling stands.
|
|
690
|
+
*/
|
|
691
|
+
function ownDataFieldRef(v, owner, ctx, site, failClosed) {
|
|
692
|
+
if (!isTfExpr(v) || v.$expr !== "data-attr" || v.type !== "elementum_field" || v.path.length !== 1 || v.path[0] !== "id")
|
|
693
|
+
return undefined;
|
|
694
|
+
if (owner.fieldKeys === undefined)
|
|
695
|
+
return undefined;
|
|
696
|
+
const address = `${owner.type}.${owner.label}`;
|
|
697
|
+
const ownerId = platformIdOf(ctx.cloning !== undefined ? ctx.cloning.sourceImportId(address) : ctx.importId(address));
|
|
698
|
+
if (fieldBlockOwner(ctx.dataAttrs?.(v.type, v.label)?.["object_id"], owner, ctx, ownerId) !== "own")
|
|
699
|
+
return undefined;
|
|
700
|
+
const field = ownDataFieldKey(v.label, owner, ctx);
|
|
701
|
+
if (field.extracted)
|
|
702
|
+
return field.key;
|
|
703
|
+
if (!failClosed && ctx.cloning === undefined)
|
|
704
|
+
return undefined;
|
|
705
|
+
// Not `unextractedFieldId`: with an unmatched name, the label's key may be
|
|
706
|
+
// an extracted field's, which that check would read as extracted. Such a
|
|
707
|
+
// key would misname the field, so the blocker names the data source's name.
|
|
708
|
+
const named = field.name !== undefined && owner.fieldKeys.has(field.key);
|
|
709
|
+
reportUnresolvableUnextractedField(ctx, `${unkeptFieldAddress(v)} (${named ? `name ${JSON.stringify(field.name)}` : `key ${JSON.stringify(field.key)}`})`, site, "which is a field of the source app that its export did not extract, so the clone would not have it", "which pull did not extract and which has no platform id to keep");
|
|
710
|
+
return FAILED_CLOSED;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* `ViewOwner.fieldKeysByName` from the extracted fields: lower-cased display
|
|
714
|
+
* name → key, or null for a name two fields share (it names neither).
|
|
715
|
+
*/
|
|
716
|
+
export function fieldKeysByDisplayName(fields) {
|
|
717
|
+
const byName = new Map();
|
|
718
|
+
for (const { key, field } of fields) {
|
|
719
|
+
const name = field.name.toLowerCase();
|
|
720
|
+
const prior = byName.get(name);
|
|
721
|
+
byName.set(name, prior === undefined ? key : prior === key ? key : null);
|
|
722
|
+
}
|
|
723
|
+
return byName;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* The field an own-app `data.elementum_field.<label>` names (see
|
|
727
|
+
* `ownDataFieldRef`). The provider looks the field up by `name`, so a name
|
|
728
|
+
* is authoritative: one extracted field's name gives its key, and a name no
|
|
729
|
+
* extracted field has means the field was not extracted, whatever the label
|
|
730
|
+
* says. Only with no name, or one two extracted fields share, does the
|
|
731
|
+
* label decide, with ei's owner prefixes stripped. `key` names the field in
|
|
732
|
+
* a blocker; `extracted` says whether to author it.
|
|
733
|
+
*/
|
|
734
|
+
function ownDataFieldKey(label, owner, ctx) {
|
|
735
|
+
const name = ctx.dataName("elementum_field", label);
|
|
736
|
+
const byName = name === undefined ? undefined : owner.fieldKeysByName?.get(name.toLowerCase());
|
|
737
|
+
if (typeof byName === "string")
|
|
738
|
+
return { key: byName, extracted: true };
|
|
739
|
+
const attrs = ctx.resourceByAddress?.(`${owner.type}.${owner.label}`)?.attrs;
|
|
740
|
+
const ownerName = attrs?.["name"];
|
|
741
|
+
const ownerNamespace = attrs?.["namespace"];
|
|
742
|
+
const key = fieldKeyFromForeignDataLabel(label, {
|
|
743
|
+
key: tfLabelToTsLabel(owner.label),
|
|
744
|
+
kind: owner.scope ?? "app",
|
|
745
|
+
...(typeof ownerName === "string" && { name: ownerName }),
|
|
746
|
+
...(typeof ownerNamespace === "string" && { namespace: ownerNamespace }),
|
|
747
|
+
}) ?? tfLabelToTsLabel(label);
|
|
748
|
+
// A name no extracted field has: never let the label pick another field.
|
|
749
|
+
if (name !== undefined && byName === undefined && owner.fieldKeysByName !== undefined)
|
|
750
|
+
return { key, extracted: false, name };
|
|
751
|
+
return { key, extracted: owner.fieldKeys?.has(key) === true || isOwnerSystemFieldKey(key, owner) };
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* `ownDataFieldRef` for a caller outside this module (a widget column, a
|
|
755
|
+
* relationship's related field on its own app): the key to author, or
|
|
756
|
+
* "failedClosed" once the blocker naming `site` is recorded. Undefined when
|
|
757
|
+
* `v` is not an own-app data source lookup; the caller's handling stands.
|
|
758
|
+
*/
|
|
759
|
+
export function resolveOwnDataFieldRef(v, owner, ctx, site) {
|
|
760
|
+
if (v === undefined)
|
|
761
|
+
return undefined;
|
|
762
|
+
const ref = ownDataFieldRef(v, owner, ctx, site, true);
|
|
763
|
+
return ref === FAILED_CLOSED ? "failedClosed" : ref === undefined ? undefined : { key: ref };
|
|
764
|
+
}
|
|
765
|
+
/** How a field reference that isn't an id or a resource reference reads in a blocker. */
|
|
766
|
+
function unkeptFieldAddress(v) {
|
|
767
|
+
if (isTfExpr(v) && v.$expr === "data-attr")
|
|
768
|
+
return `data.${v.type}.${v.label}`;
|
|
769
|
+
if (isTfExpr(v) && v.$expr === "local")
|
|
770
|
+
return `local.${v.name}`;
|
|
771
|
+
return "a reference with no platform id";
|
|
772
|
+
}
|
|
773
|
+
function platformIdOf(importId) {
|
|
774
|
+
const canonical = importId === undefined ? undefined : canonicalImportId(importId);
|
|
775
|
+
return canonical !== undefined && PLATFORM_ID.test(canonical) ? canonical : undefined;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* The id a clone keeps for a reference to a field it does not copy (#1990):
|
|
779
|
+
* the export's platform id, only when the field's block names another app,
|
|
780
|
+
* element or task as its owner, so the field exists without the clone. A
|
|
781
|
+
* field of the source app itself (or of no owner the clone can name) would
|
|
782
|
+
* leave the clone pointing at the source app or at nothing, so it fails
|
|
783
|
+
* with the reason instead.
|
|
784
|
+
*/
|
|
785
|
+
function cloneKeptFieldId(v, field, owner, ctx) {
|
|
786
|
+
const sourceId = isTfExpr(v) && v.$expr === "resource-attr" ? platformIdOf(ctx.cloning?.sourceImportId(field)) : undefined;
|
|
787
|
+
const block = isTfExpr(v) && v.$expr === "resource-attr" ? ctx.resourceByAddress?.(field) : undefined;
|
|
788
|
+
if (block === undefined) {
|
|
789
|
+
return {
|
|
790
|
+
reason: sourceId !== undefined
|
|
791
|
+
? `which the source app's export imports as ${sourceId} but has no field block for, so its owner is unknown`
|
|
792
|
+
: "which the source app's export does not include and has no platform id for",
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
const ownerId = platformIdOf(ctx.cloning?.sourceImportId(`${owner.type}.${owner.label}`));
|
|
796
|
+
switch (fieldBlockOwner(block.attrs["object_id"], owner, ctx, ownerId)) {
|
|
797
|
+
case "own":
|
|
798
|
+
return { reason: "which is a field of the source app that its export did not extract, so the clone would not have it" };
|
|
799
|
+
case "unresolved":
|
|
800
|
+
return { reason: "whose owner the clone cannot identify from its object_id" };
|
|
801
|
+
case "foreign":
|
|
802
|
+
return sourceId ?? { reason: "which belongs to another app, element or task but has no platform id in the source app's export" };
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const UNRESOLVABLE_UNEXTRACTED_FIELD_REMEDY = "Pull keeps a reference to a field it did not extract only by that field's platform id (#1966). " +
|
|
806
|
+
"Check that each field still exists on its app or element and pull again; if the export keeps omitting it, report it to the EDK maintainers.";
|
|
807
|
+
const UNRESOLVABLE_CLONE_FIELD_REMEDY = "Clone copies the source app's own fields and keeps a reference to another app's, element's or task's field by that field's platform id (#1990). " +
|
|
808
|
+
"Check that each field still exists on the app, element or task that owns it and that the source app's export includes it; if the export keeps omitting it, report it to the EDK maintainers.";
|
|
809
|
+
const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
|
|
810
|
+
function isOwnerSystemFieldKey(fieldKey, owner) {
|
|
811
|
+
return (owner.scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET).has(fieldKey);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* A raw platform id this owner's export imports as one of its own fields
|
|
815
|
+
* that pull did not extract: a re-pull of an id #1736 kept. Undefined
|
|
816
|
+
* otherwise.
|
|
817
|
+
*/
|
|
818
|
+
function importedUnextractedFieldId(v, owner, ctx, site, failClosed = false) {
|
|
819
|
+
if (!PLATFORM_ID.test(v))
|
|
820
|
+
return undefined;
|
|
821
|
+
const imported = ctx.importedResource?.(v);
|
|
822
|
+
if (imported === undefined)
|
|
823
|
+
return undefined;
|
|
824
|
+
const importedRef = expr.resourceAttr(imported.type, imported.label, ["id"]);
|
|
825
|
+
const importedKey = fieldKeyFromTfValue(importedRef, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope ?? "app", ctx);
|
|
826
|
+
if (importedKey === undefined)
|
|
827
|
+
return undefined;
|
|
828
|
+
return unextractedFieldId(importedRef, importedKey, owner, ctx, site, failClosed) === v ? v : undefined;
|
|
829
|
+
}
|
|
830
|
+
/** The kept id, else the caller's key; undefined, never the key, when this reference failed closed. */
|
|
831
|
+
function keptIdOrKey(kept, fieldKey) {
|
|
832
|
+
return kept === FAILED_CLOSED ? undefined : kept ?? fieldKey;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* The value to author for a field reference outside views (#1966):
|
|
836
|
+
* `fieldKey` is what the caller resolved the reference to, if anything. A
|
|
837
|
+
* field pull did not extract keeps its platform id; otherwise the caller's
|
|
838
|
+
* key stands. Undefined when nothing resolves, or when this reference failed
|
|
839
|
+
* closed: no id is known, which fails the pull with an authoring blocker
|
|
840
|
+
* naming `site`, which must start with the holding resource's address (#1978).
|
|
841
|
+
* The result never depends on another reference's blocker at the same site.
|
|
842
|
+
* Clone drops import blocks, so it keeps the export's dropped id only for
|
|
843
|
+
* another owner's field and fails the same way for any other (#1990). A kept
|
|
844
|
+
* id is reported once per field, naming every site.
|
|
845
|
+
*/
|
|
846
|
+
export function unextractedFieldRefId(v, fieldKey, owner, ctx, site) {
|
|
847
|
+
if (fieldKey !== undefined)
|
|
848
|
+
return keptIdOrKey(unextractedFieldId(v, fieldKey, owner, ctx, site, true), fieldKey);
|
|
849
|
+
const ownData = ownDataFieldRef(v, owner, ctx, site, true);
|
|
850
|
+
if (ownData !== undefined)
|
|
851
|
+
return authoredRef(ownData);
|
|
852
|
+
return typeof v === "string" && PLATFORM_ID.test(v) ? authoredRef(bareFieldIdRef(v, owner, ctx, site)) : undefined;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* A bare platform-id field reference no key resolves: what an export writes
|
|
856
|
+
* when it can't name the field (#1991). It resolves through the import that
|
|
857
|
+
* names the id (in a clone, the source export's dropped one) to the field's
|
|
858
|
+
* key, or to the kept id of a field pull did not extract (another owner's,
|
|
859
|
+
* in a clone). Anything else fails the pull or clone with an authoring
|
|
860
|
+
* blocker naming `site` and the id, instead of dropping the entry or, in a
|
|
861
|
+
* clone, leaving the source app's id in place. Views outside a clone keep
|
|
862
|
+
* a bare id as is (#1178) and don't come here.
|
|
863
|
+
*/
|
|
864
|
+
function bareFieldIdRef(v, owner, ctx, site) {
|
|
865
|
+
const imported = ctx.importedResource?.(v);
|
|
866
|
+
if (imported !== undefined) {
|
|
867
|
+
const ref = expr.resourceAttr(imported.type, imported.label, ["id"]);
|
|
868
|
+
const key = fieldKeyFromTfValue(ref, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope ?? "app", ctx);
|
|
869
|
+
if (key !== undefined) {
|
|
870
|
+
// A reference that failed closed never hands back the key, so nothing
|
|
871
|
+
// can author a field the clone doesn't have. Only this call's own
|
|
872
|
+
// result decides it, not blockers other references left at the site.
|
|
873
|
+
const kept = unextractedFieldId(ref, key, owner, ctx, site, true);
|
|
874
|
+
return kept === FAILED_CLOSED ? FAILED_CLOSED : kept ?? key;
|
|
875
|
+
}
|
|
876
|
+
if (ctx.cloning !== undefined) {
|
|
877
|
+
const kept = cloneKeptFieldId(ref, `${imported.type}.${imported.label}`, owner, ctx);
|
|
878
|
+
if (typeof kept === "string") {
|
|
879
|
+
reportUnextractedField(ctx, `${imported.type}.${imported.label}`, kept, site, true);
|
|
880
|
+
owner.unextractedFieldIds?.add(kept);
|
|
881
|
+
return kept;
|
|
882
|
+
}
|
|
883
|
+
reportUnresolvableUnextractedField(ctx, `${imported.type}.${imported.label}`, site, kept.reason);
|
|
884
|
+
return FAILED_CLOSED;
|
|
885
|
+
}
|
|
886
|
+
// Pull: the export names the id, so it is the platform's own; keep it.
|
|
887
|
+
ctx.diagnostics.push(`${site}: field id ${v} is imported as ${imported.type}.${imported.label}, not a field of this owner; kept as is`);
|
|
888
|
+
return v;
|
|
889
|
+
}
|
|
890
|
+
reportUnimportedBareFieldId(v, ctx, site);
|
|
891
|
+
return FAILED_CLOSED;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* A bare platform-id field reference on another owner's side: a widget column
|
|
895
|
+
* whose target is another app or element, or a relationship's related field
|
|
896
|
+
* (#1991). `foreignOwner` names that owner when it is not this one, so the id
|
|
897
|
+
* is its field and keeps its platform id (Dax, 11:45). An id the export
|
|
898
|
+
* imports is checked through its field block instead: in a clone, a field of
|
|
899
|
+
* the source app fails and another owner's keeps its id (#1990); in pull, it
|
|
900
|
+
* is the platform's own and stays as is. With no foreign owner and no import,
|
|
901
|
+
* it fails like `bareFieldIdRef`, naming `site` and the id.
|
|
902
|
+
*/
|
|
903
|
+
export function bareForeignFieldIdRef(v, owner, ctx, site, foreignOwner) {
|
|
904
|
+
const imported = ctx.importedResource?.(v);
|
|
905
|
+
if (imported !== undefined) {
|
|
906
|
+
const field = `${imported.type}.${imported.label}`;
|
|
907
|
+
if (ctx.cloning !== undefined) {
|
|
908
|
+
const kept = cloneKeptFieldId(expr.resourceAttr(imported.type, imported.label, ["id"]), field, owner, ctx);
|
|
909
|
+
if (typeof kept === "string") {
|
|
910
|
+
reportUnextractedField(ctx, field, kept, site, true);
|
|
911
|
+
owner.unextractedFieldIds?.add(kept);
|
|
912
|
+
return kept;
|
|
913
|
+
}
|
|
914
|
+
reportUnresolvableUnextractedField(ctx, field, site, kept.reason);
|
|
915
|
+
return undefined;
|
|
916
|
+
}
|
|
917
|
+
ctx.diagnostics.push(`${site}: field id ${v} is imported as ${field}, not a field of ${foreignOwner ?? "this owner"}; kept as is`);
|
|
918
|
+
return v;
|
|
919
|
+
}
|
|
920
|
+
if (foreignOwner !== undefined) {
|
|
921
|
+
ctx.diagnostics.push(`${site}: field id ${v} is a field of ${foreignOwner}, which this ${ctx.cloning !== undefined ? "clone" : "pull"} does not copy; kept as its platform id`);
|
|
922
|
+
owner.unextractedFieldIds?.add(v);
|
|
923
|
+
return v;
|
|
924
|
+
}
|
|
925
|
+
reportUnimportedBareFieldId(v, ctx, site);
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* The blocker for a bare field id no import names (#1991). In a clone whose
|
|
930
|
+
* live system-field read failed, the id may be one of the source app's
|
|
931
|
+
* system fields, so the message names that read instead (#1492).
|
|
932
|
+
*/
|
|
933
|
+
function reportUnimportedBareFieldId(v, ctx, site) {
|
|
934
|
+
const address = site.split(".").slice(0, 2).join(".");
|
|
935
|
+
const readFailure = ctx.cloning?.systemFieldReadFailure;
|
|
936
|
+
const description = ctx.cloning === undefined
|
|
937
|
+
? `${site} references field id ${v}, which no import in the export names, so pull cannot resolve it to a field`
|
|
938
|
+
: readFailure !== undefined
|
|
939
|
+
? `${site} references field id ${v}, which no import in the source app's export names. It may be one of the source app's system fields, but the clone couldn't map them (${readFailure})`
|
|
940
|
+
: `${site} references field id ${v}, which no import in the source app's export names, so the clone cannot tell whose field it is`;
|
|
941
|
+
if (ctx.authoringBlockers?.some((blocker) => blocker.description === description) === true)
|
|
942
|
+
return;
|
|
943
|
+
const remedy = ctx.cloning === undefined
|
|
944
|
+
? UNRESOLVABLE_UNEXTRACTED_FIELD_REMEDY
|
|
945
|
+
: readFailure !== undefined
|
|
946
|
+
? "Fix the failed system-field read (check the profile's access to the source app) and run the clone again."
|
|
947
|
+
: UNRESOLVABLE_CLONE_FIELD_REMEDY;
|
|
948
|
+
reportAuthoringBlocker(ctx, { address, description, remedy });
|
|
949
|
+
}
|
|
950
|
+
/** Whether `v` is a bare platform id, the shape an export writes for a field it can't name (#1991). */
|
|
951
|
+
export function isBarePlatformId(v) {
|
|
952
|
+
return PLATFORM_ID.test(v);
|
|
953
|
+
}
|
|
954
|
+
/** Whether `fieldKey` names a field of this owner that pull did not extract (system keys never count). */
|
|
955
|
+
export function isUnextractedFieldKey(fieldKey, owner) {
|
|
956
|
+
return owner.fieldKeys !== undefined && !owner.fieldKeys.has(fieldKey) && !isOwnerSystemFieldKey(fieldKey, owner);
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Records a raw platform id that a caller keeps as is (a sort order, a blocks
|
|
960
|
+
* layout id prop) when it names a field pull did not extract, so print marks
|
|
961
|
+
* it as intentional too (#1736). The caller's value does not change.
|
|
962
|
+
*/
|
|
963
|
+
function noteRawUnextractedFieldId(v, owner, ctx, site) {
|
|
964
|
+
if (!PLATFORM_ID.test(v))
|
|
965
|
+
return;
|
|
966
|
+
const fieldKey = fieldKeyFromTfValue(v, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope ?? "app", ctx);
|
|
967
|
+
if (fieldKey !== undefined)
|
|
968
|
+
unextractedFieldId(v, fieldKey, owner, ctx, site);
|
|
969
|
+
else
|
|
970
|
+
importedUnextractedFieldId(v, owner, ctx, site);
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* The key of this owner's own field a raw platform id names, when pull
|
|
974
|
+
* extracted it (#2155): by its state identity, else by the import that names
|
|
975
|
+
* it. A system field counts only with `systemKeys` (it has no import), and
|
|
976
|
+
* not when a custom field of the owner shares its key. Any other id is
|
|
977
|
+
* undefined, and so is every id in a clone, whose ids are the
|
|
978
|
+
* source app's.
|
|
979
|
+
*/
|
|
980
|
+
function ownExtractedFieldKey(v, owner, ctx, systemKeys) {
|
|
981
|
+
if (ctx.cloning !== undefined || !PLATFORM_ID.test(v))
|
|
982
|
+
return undefined;
|
|
983
|
+
const ownerRefName = tfLabelToTsLabel(owner.label);
|
|
984
|
+
const scope = owner.scope ?? "app";
|
|
985
|
+
const imported = ctx.importedResource?.(v);
|
|
986
|
+
const key = fieldKeyFromTfValue(v, ownerRefName, owner.ownerTfLabel, scope, ctx)
|
|
987
|
+
?? (imported === undefined ? undefined : fieldKeyFromTfValue(expr.resourceAttr(imported.type, imported.label, ["id"]), ownerRefName, owner.ownerTfLabel, scope, ctx));
|
|
988
|
+
if (key === undefined)
|
|
989
|
+
return undefined;
|
|
990
|
+
// A custom field may own a system key (an element's createdAt); build
|
|
991
|
+
// resolves that key to the platform field, which would retarget the
|
|
992
|
+
// reference, so its id stays raw (as selfSystemField does).
|
|
993
|
+
if (isOwnerSystemFieldKey(key, owner))
|
|
994
|
+
return systemKeys && imported === undefined && !ownerMayHaveCustomField(owner, key, ctx) ? key : undefined;
|
|
995
|
+
return owner.fieldKeys?.has(key) === true ? key : undefined;
|
|
996
|
+
}
|
|
997
|
+
/** One diagnostic per unextracted field per pull, naming every site that references it (#1736, #1966). */
|
|
998
|
+
const unextractedFieldReports = new WeakMap();
|
|
999
|
+
function reportUnextractedField(ctx, field, id, site, outsideViews) {
|
|
1000
|
+
let byField = unextractedFieldReports.get(ctx.diagnostics);
|
|
1001
|
+
if (byField === undefined) {
|
|
1002
|
+
byField = new Map();
|
|
1003
|
+
unextractedFieldReports.set(ctx.diagnostics, byField);
|
|
1004
|
+
}
|
|
1005
|
+
let report = byField.get(field);
|
|
1006
|
+
if (report === undefined) {
|
|
1007
|
+
report = { index: ctx.diagnostics.length, sites: [], outsideViews: false };
|
|
1008
|
+
byField.set(field, report);
|
|
1009
|
+
ctx.diagnostics.push("");
|
|
1010
|
+
}
|
|
1011
|
+
if (!report.sites.includes(site))
|
|
1012
|
+
report.sites.push(site);
|
|
1013
|
+
report.outsideViews ||= outsideViews;
|
|
1014
|
+
const sites = report.sites.join(", ");
|
|
1015
|
+
// Views and dashboard widget sorts share this report, so name what holds
|
|
1016
|
+
// the reference: a view, a dashboard widget, or several kinds of site.
|
|
1017
|
+
const onDashboard = report.sites.filter((s) => s.startsWith(`${DASHBOARD_WIDGET_RESOURCE_TYPE}.`)).length;
|
|
1018
|
+
const holder = report.outsideViews || (onDashboard > 0 && onDashboard < report.sites.length)
|
|
1019
|
+
? undefined
|
|
1020
|
+
: onDashboard > 0 ? "dashboard widget" : "view";
|
|
1021
|
+
ctx.diagnostics[report.index] = id !== undefined
|
|
1022
|
+
? ctx.cloning !== undefined
|
|
1023
|
+
// A clone keeps only another owner's field, which exists without it (#1990).
|
|
1024
|
+
? `field ${field} belongs to another app, element or task, so the clone does not copy it; kept as its platform id ${id} at ${sites}`
|
|
1025
|
+
: `field ${field} was not extracted by pull; kept as its platform id ${id} at ${sites}, so plan keeps it ${holder === undefined ? "there" : `in the ${holder}`} (dropping it would make plan remove it)`
|
|
1026
|
+
// Only a view or dashboard widget sort outside a clone gets here;
|
|
1027
|
+
// anywhere else, and in a clone, that fails (#1978, #1990).
|
|
1028
|
+
: `field ${field} was not extracted by pull and has no platform id; ${sites} builds without it, so plan would remove it from ${holder === undefined ? "there" : `the ${holder}`}`;
|
|
1029
|
+
}
|
|
557
1030
|
function listViewFromTf(block, owner, ctx) {
|
|
558
1031
|
const label = block.label;
|
|
559
1032
|
if (label === undefined || label === "") {
|
|
@@ -573,8 +1046,8 @@ function listViewFromTf(block, owner, ctx) {
|
|
|
573
1046
|
const columnsAttr = attrs["columns"];
|
|
574
1047
|
const columns = [];
|
|
575
1048
|
if (Array.isArray(columnsAttr)) {
|
|
576
|
-
for (const c of columnsAttr) {
|
|
577
|
-
const key = fieldRefFromTf(c, owner
|
|
1049
|
+
for (const [index, c] of columnsAttr.entries()) {
|
|
1050
|
+
const key = fieldRefFromTf(c, owner, ctx, `${where} columns[${index}]`);
|
|
578
1051
|
if (key !== undefined)
|
|
579
1052
|
columns.push(key);
|
|
580
1053
|
}
|
|
@@ -640,9 +1113,14 @@ export function managedViewSortFromTf(value, owner, where, ctx) {
|
|
|
640
1113
|
return undefined;
|
|
641
1114
|
}
|
|
642
1115
|
const rawField = order["field"];
|
|
643
|
-
const
|
|
1116
|
+
const site = `${where} sort.orders[${index}].field`;
|
|
1117
|
+
// A clone resolves a bare id like any field reference (#1991).
|
|
1118
|
+
const cloningBareId = typeof rawField === "string" && ctx.cloning !== undefined && PLATFORM_ID.test(rawField);
|
|
1119
|
+
if (typeof rawField === "string" && !cloningBareId)
|
|
1120
|
+
noteRawUnextractedFieldId(rawField, owner, ctx, site);
|
|
1121
|
+
const field = typeof rawField === "string" && !cloningBareId
|
|
644
1122
|
? (PLATFORM_ID.test(rawField) ? rawField : undefined)
|
|
645
|
-
: fieldRefFromTf(rawField, owner
|
|
1123
|
+
: fieldRefFromTf(rawField, owner, ctx, site);
|
|
646
1124
|
if (field === undefined) {
|
|
647
1125
|
ctx.diagnostics.push(`${where}: sort.orders[${index}].field does not resolve to a field; dropped sort`);
|
|
648
1126
|
return undefined;
|