@elementumai/edk 0.13.2 → 0.13.4

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 (45) hide show
  1. package/dist-sdk/src/engine/coverage-gaps.d.ts +3 -0
  2. package/dist-sdk/src/engine/coverage-gaps.js +5 -0
  3. package/dist-sdk/src/engine/pull/context.d.ts +10 -4
  4. package/dist-sdk/src/engine/pull/context.js +2 -0
  5. package/dist-sdk/src/engine/pull/stream-root.d.ts +7 -1
  6. package/dist-sdk/src/engine/pull/stream-root.js +6 -0
  7. package/dist-sdk/src/engine/tf/index.d.ts +1 -0
  8. package/dist-sdk/src/engine/tf/index.js +1 -0
  9. package/dist-sdk/src/engine/tf/jsonencode.d.ts +19 -0
  10. package/dist-sdk/src/engine/tf/jsonencode.js +49 -0
  11. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  12. package/dist-sdk/src/entities/automation/approval-trigger-refs.d.ts +20 -0
  13. package/dist-sdk/src/entities/automation/approval-trigger-refs.js +83 -0
  14. package/dist-sdk/src/entities/automation/build.js +1 -1
  15. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +15 -0
  16. package/dist-sdk/src/entities/automation/from-tf.d.ts +2 -0
  17. package/dist-sdk/src/entities/automation/from-tf.js +104 -14
  18. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  19. package/dist-sdk/src/entities/automation/lookup-owner.d.ts +23 -0
  20. package/dist-sdk/src/entities/automation/lookup-owner.js +27 -0
  21. package/dist-sdk/src/entities/automation/module.js +200 -20
  22. package/dist-sdk/src/entities/automation/omitted-ref.d.ts +12 -0
  23. package/dist-sdk/src/entities/automation/omitted-ref.js +21 -0
  24. package/dist-sdk/src/entities/automation/to-tf.js +170 -5
  25. package/dist-sdk/src/entities/automation/triggers.d.ts +47 -1
  26. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +10 -5
  27. package/dist-sdk/src/entities/automation/unsafe-script-output.js +10 -5
  28. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +43 -18
  29. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +37 -21
  30. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +47 -5
  31. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  32. package/dist-sdk/src/entities/shared/filters/ast.d.ts +6 -0
  33. package/dist-sdk/src/entities/shared/filters/index.d.ts +15 -3
  34. package/dist-sdk/src/entities/shared/filters/index.js +19 -1
  35. package/dist-sdk/src/entities/shared/filters/print.js +5 -0
  36. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +13 -0
  37. package/dist-sdk/src/entities/shared/filters/tf-codec.js +74 -1
  38. package/dist-sdk/src/entities/shared/filters/types.d.ts +8 -1
  39. package/dist-sdk/src/entities/widget/from-tf.js +8 -4
  40. package/dist-sdk/src/entities/widget/to-tf.js +2 -1
  41. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +4 -2
  42. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  43. package/dist-sdk/src/graph/index.d.ts +1 -1
  44. package/dist-sdk/src/graph/types.d.ts +36 -0
  45. package/package.json +1 -1
@@ -20,4 +20,4 @@ export { ScriptCodeError, scriptFile, type ScriptCodeFn, type ScriptFile, type S
20
20
  export { unsafeScriptOutput } from "./unsafe-script-output.js";
21
21
  export { workflowOutput, workflowOutputType, type WorkflowOutputDeclaration, type WorkflowOutputType, } from "./workflow-output.js";
22
22
  export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, requiredSecret, assignGroup, assignUser, assignmentEngine, bulkExcel, bulkUpdateFields, calculation, createRecord, executeScript, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch, withFieldMappings, type AddWatcherOptions, type AiAgentAttachment, type AiAgentOptions, type AiAgentOutput, type AiAgentOutputField, type AiAgentOutputFieldType, type AiClassifyCategorySource, type AiClassifyOptions, type AiClassifyStaticCategory, type AiEmailAnalysisOptions, type AiFileAnalysisOptions, type AiSearchTableOptions, type AiSearchTableOutput, type AiSummarizeOptions, type AiTransformOptions, type ApiRequestHeader, type ApiRequestOptions, type ApiRequestOutputs, type ApiResponseType, type ApprovalChainOptions, type RequiredSecret, type ApprovalChainTemplateOptions, type ApprovalStatusUpdateOptions, type ApprovalStatusUpdateStatus, type AssignGroupOptions, type AssignUserOptions, type AssignmentEngineOptions, type BulkExcelFieldMapping, type BulkExcelFieldSource, type BulkExcelOptions, type BulkUpdateFieldsOptions, type BulkUpdateFieldsOutput, type CalculationEntry, type CalculationExpression, type CalculationInclude, type CalculationOptions, type CalculationOutputs, type CalculationValueInput, type CalculationValueOptions, type CalculationValueOutputs, type CalculationValues, type CreateRecordOptions, type CreateRecordOutput, type EmailAttachment, type ExecuteScriptFieldMapping, type ExecuteScriptOptions, type ExecuteScriptOutput, type FieldAssignment, type FindRelatedRecordsOptions, type FindRelatedRecordsOutput, type GenerateReportOptions, type InitiateCallOptions, type InitiateEmailConversationOptions, type InitiateEmailFirstEmail, type LegacyCalculationOptions, type MultiSelectUpdateMode, type NotificationOptions, type StaticGroupRecipient, type StaticUserRecipient, type PostCommentOptions, type PostTeamsMessageOptions, type LegacyProcedureOptions, type ProcedureOptions, type TypedProcedureOptions, type ReadFileDataSource, type ReadFileOptions, type RecordFieldLockingOptions, type RecordId, type RecordReference, type RecordSearchOptions, type RecordSearchOutput, type RelateRecordsOptions, type RunAutomationInput, type RunAutomationDynamicReferenceOptions, type RunAutomationOptions, type RunAutomationStaticOptions, type SaveAttachmentOptions, type ScriptOutputProperties, type ScriptOutputScalarType, type ScriptOutputType, type ScriptOutputs, type SendEmailOptions, type SendSurveyOptions, type SetVariableOptions, type TableRecordsSearchOptions, type TableRecordsSearchOutput, type UnzipOptions, type UpdateFieldAssignment, type UpdateFieldOptions, type UserGroupSearchOptions, type UserGroupSearchOutput, type UserGroupShape, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
23
- export { approvalProcessStatusUpdated, attachment, commentAdded, conversationEnd, dataMine, emailReceived, onDemand, recordCreated, recordUpdated, schedule, slackMessage, surveyResponseCreate, temporal, webHook, webhook, type AttachmentTriggerOptions, type AttachmentTriggerOutput, type CommentAddedTriggerOptions, type CommentAddedTriggerOutput, type ConversationEndConversationType, type ConversationEndTriggerOptions, type ConversationEndTriggerOutput, type DataMineTriggerOptions, type DataMineTriggerOutput, type EmailReceivedTriggerOptions, type EmailReceivedTriggerOutput, type RecordTriggerOptions, type RecordTriggerOutput, type ScheduleFrequency, type ScheduleTriggerOptions, type ScheduleTriggerOutput, type SlackMessageTriggerOutput, type SurveyResponseCreateTriggerOptions, type SurveyResponseCreateTriggerOutput, type TemporalTriggerOptions, type TemporalUnit, type WebhookTriggerOptions, type WebhookTriggerOutput, type Weekday, type approvalProcessStatusUpdatedStatus, type approvalProcessStatusUpdatedTriggerOptions } from "./triggers.js";
23
+ export { approvalProcessStatusUpdated, attachment, commentAdded, conversationEnd, dataMine, emailReceived, onDemand, recordCreated, recordUpdated, schedule, slackMessage, surveyResponseCreate, temporal, webHook, webhook, type ApprovalProcessStatusUpdatedApprover, type ApprovalProcessStatusUpdatedTriggerOutput, type AttachmentTriggerOptions, type AttachmentTriggerOutput, type CommentAddedTriggerOptions, type CommentAddedTriggerOutput, type ConversationEndConversationType, type ConversationEndTriggerOptions, type ConversationEndTriggerOutput, type DataMineTriggerOptions, type DataMineTriggerOutput, type EmailReceivedTriggerOptions, type EmailReceivedTriggerOutput, type RecordTriggerOptions, type RecordTriggerOutput, type ScheduleFrequency, type ScheduleTriggerOptions, type ScheduleTriggerOutput, type SlackMessageTriggerOutput, type SurveyResponseCreateTriggerOptions, type SurveyResponseCreateTriggerOutput, type TemporalTriggerOptions, type TemporalUnit, type WebhookTriggerOptions, type WebhookTriggerOutput, type Weekday, type approvalProcessStatusUpdatedStatus, type approvalProcessStatusUpdatedTriggerOptions } from "./triggers.js";
@@ -0,0 +1,23 @@
1
+ import type { OrgRefLookup } from "../../engine/build/context.js";
2
+ import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
+ /** The owner kinds an automation can belong to, and the data source each is looked up with. */
4
+ declare const OWNER_DATA_TYPE: {
5
+ readonly app: "elementum_app";
6
+ readonly element: "elementum_element";
7
+ };
8
+ export type AutomationOwnerScope = keyof typeof OWNER_DATA_TYPE;
9
+ /**
10
+ * The owner lookup a `data.elementum_automation` lookup by display name
11
+ * reads its `app_id` from, for an automation of this app or element that is
12
+ * not in source (a widget, a dynamic-layout button, a Run Automation call,
13
+ * and adoption's stand-in for a skipped automation, #3047). The owner is
14
+ * looked up by its namespace, which is its Terraform label, rather than read
15
+ * from the managed app or element resource: OpenTofu defers a data source
16
+ * whose dependency has planned changes, so a plan that changes the app record
17
+ * would otherwise make the automation's id and parameter ids unknown, and
18
+ * every run task and reader of its outputs with them (edk#1514).
19
+ */
20
+ export declare function automationLookupOwnerBlock(scope: AutomationOwnerScope, ownerTfLabel: string): TfBlock;
21
+ /** `automationLookupOwnerBlock`'s id, registering the block with `orgRefs`, or in `dataBlocks` when a build has no org lookup. */
22
+ export declare function automationLookupOwnerId(scope: AutomationOwnerScope, ownerTfLabel: string, orgRefs: OrgRefLookup | undefined, dataBlocks?: Map<string, TfBlock>): TfValue;
23
+ export {};
@@ -0,0 +1,27 @@
1
+ import { expr } from "../../engine/tf/index.js";
2
+ /** The owner kinds an automation can belong to, and the data source each is looked up with. */
3
+ const OWNER_DATA_TYPE = { app: "elementum_app", element: "elementum_element" };
4
+ /**
5
+ * The owner lookup a `data.elementum_automation` lookup by display name
6
+ * reads its `app_id` from, for an automation of this app or element that is
7
+ * not in source (a widget, a dynamic-layout button, a Run Automation call,
8
+ * and adoption's stand-in for a skipped automation, #3047). The owner is
9
+ * looked up by its namespace, which is its Terraform label, rather than read
10
+ * from the managed app or element resource: OpenTofu defers a data source
11
+ * whose dependency has planned changes, so a plan that changes the app record
12
+ * would otherwise make the automation's id and parameter ids unknown, and
13
+ * every run task and reader of its outputs with them (edk#1514).
14
+ */
15
+ export function automationLookupOwnerBlock(scope, ownerTfLabel) {
16
+ return { kind: "data", type: OWNER_DATA_TYPE[scope], label: ownerTfLabel, attrs: { namespace: ownerTfLabel } };
17
+ }
18
+ /** `automationLookupOwnerBlock`'s id, registering the block with `orgRefs`, or in `dataBlocks` when a build has no org lookup. */
19
+ export function automationLookupOwnerId(scope, ownerTfLabel, orgRefs, dataBlocks) {
20
+ if (orgRefs !== undefined) {
21
+ const resolved = orgRefs.resolveForeignRoot(scope, { tfLabel: ownerTfLabel, name: ownerTfLabel, namespace: ownerTfLabel });
22
+ return expr.dataAttr(resolved.resourceType, resolved.tfLabel, ["id"]);
23
+ }
24
+ const block = automationLookupOwnerBlock(scope, ownerTfLabel);
25
+ dataBlocks?.set(`${block.type}.${block.label}`, block);
26
+ return expr.dataAttr(block.type, block.label, ["id"]);
27
+ }
@@ -1,6 +1,6 @@
1
1
  /** The automation entity's registry entry (see src/graph/). */
2
2
  import { canonicalAuditRefKey } from "./system-ref-name.js";
3
- import { appScopedResourceLabel, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, isTfExpr } from "../../engine/tf/index.js";
3
+ import { appScopedResourceLabel, expr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel, isTfExpr } from "../../engine/tf/index.js";
4
4
  function elementOwnerHandle(payload) {
5
5
  if (payload === null || typeof payload !== "object" || !("handle" in payload))
6
6
  return undefined;
@@ -8,6 +8,7 @@ function elementOwnerHandle(payload) {
8
8
  return typeof handle === "string" && handle !== "" ? handle : undefined;
9
9
  }
10
10
  import { renderAutomationCatalogEntry } from "./catalog-render.js";
11
+ import { automationLookupOwnerBlock } from "./lookup-owner.js";
11
12
  import { hasUnresolvedForEachItem, preserveAuthoredAutomationPullMeta, printAutomationV2WithScriptFiles, SCRIPT_FILES_DIR } from "./deserializer/print-automation.js";
12
13
  import { automationFromTf, automationOwnedAddresses, ForEachItemOutsideLoopError, UnresolvedForeignServiceAccountError, UnresolvedTaskFilterRefError, UnsupportedMultiTriggerError } from "./from-tf.js";
13
14
  import { scriptFileRefs } from "./script-code.js";
@@ -153,6 +154,38 @@ export function droppedAutomationGap(autoBlock, autoLabel, gap) {
153
154
  : `it is not adopted. If this workspace already manages it, its state and its existing source file are kept as they were, so the next plan compares that older source with the live automation: it can undo edits made in the platform, or delete the automation if its source file is gone. Review the plan before applying. ${gap.nextStep}`,
154
155
  });
155
156
  }
157
+ /**
158
+ * The `data.elementum_automation` lookup by display name that stands in for a
159
+ * skipped automation, the shape build emits for a dynamic-layout button whose
160
+ * automation is not in source (edk#2693). A button input reads its on-demand
161
+ * trigger's `parameter_ids`, which the lookup carries too (#3023).
162
+ */
163
+ function unmanagedAutomationLookup(autoBlock, owned, label, uniqueName) {
164
+ const name = autoBlock.attrs["name"];
165
+ const appId = autoBlock.attrs["app_id"];
166
+ const triggers = owned.filter((address) => address.startsWith("elementum_on_demand_trigger."));
167
+ // A Run Automation call reads the automation's id from the same lookup
168
+ // build emits for it (#3047), when the display name finds only this one.
169
+ const automation = uniqueName && autoBlock.label !== undefined ? [`${AUTOMATION_RESOURCE_TYPE}.${autoBlock.label}`] : [];
170
+ if (typeof name !== "string" || name === "" || appId === undefined || triggers.length + automation.length === 0)
171
+ return undefined;
172
+ // The owner by namespace, as build reads it (`automationLookupOwnerId`),
173
+ // so the lookups pair in the build-vs-export check (#3047).
174
+ const owner = isTfExpr(appId) && appId.$expr === "resource-attr" && (appId.type === "elementum_app" || appId.type === "elementum_element")
175
+ ? automationLookupOwnerBlock(appId.type === "elementum_element" ? "element" : "app", appId.label)
176
+ : undefined;
177
+ return {
178
+ lookup: {
179
+ kind: "data",
180
+ type: AUTOMATION_RESOURCE_TYPE,
181
+ label,
182
+ attrs: { app_id: owner === undefined ? appId : expr.dataAttr(owner.type, owner.label, ["id"]), name },
183
+ },
184
+ addresses: triggers,
185
+ ...(automation.length > 0 && { idAddresses: automation }),
186
+ ...(owner !== undefined && { supporting: [owner] }),
187
+ };
188
+ }
156
189
  const FIX_IN_PLATFORM = "To manage it with the EDK, change what the reason names in the platform, then pull again.";
157
190
  const FIX_OR_REPORT = "If you can change what the reason names in the platform, do so and pull again; otherwise report it as an EDK bug.";
158
191
  /**
@@ -162,7 +195,7 @@ const FIX_OR_REPORT = "If you can change what the reason names in the platform,
162
195
  * display-name lookup (#1901), so archiving is safe. A dynamic-layout button
163
196
  * does not count either (#2693). Any other reference from that layout still does.
164
197
  */
165
- function externalReferrers(stream, owned, inSource) {
198
+ function externalReferrers(stream, owned, inSource, runnable = new Set()) {
166
199
  const ownedSet = new Set(owned);
167
200
  const referrers = [];
168
201
  for (const block of stream.allBlocks) {
@@ -171,7 +204,9 @@ function externalReferrers(stream, owned, inSource) {
171
204
  const address = `${block.type}.${block.label}`;
172
205
  if (ownedSet.has(address) || block.type === "elementum_widget" || !inSource(address))
173
206
  continue;
174
- const attrs = block.type === "elementum_dynamic_layout" ? withoutAutomationButtons(block.attrs) : block.attrs;
207
+ // A Run Automation call looks an automation that is not in source up by
208
+ // display name (#3047), so it does not keep the file either.
209
+ const attrs = block.type === "elementum_dynamic_layout" ? withoutAutomationButtons(block.attrs) : withoutRunTargetSites(block, runnable);
175
210
  if (referenceIn(attrs, ownedSet) !== undefined)
176
211
  referrers.push(address);
177
212
  }
@@ -232,18 +267,119 @@ function referenceIn(value, targets) {
232
267
  }
233
268
  return undefined;
234
269
  }
270
+ /**
271
+ * How many automations carry each display name: the stream's, plus every one
272
+ * the export left out (omitted-automations.json). The provider's name lookup
273
+ * sees those too and prefers an ACTIVE match, so a namesake it left out could
274
+ * take the lookup; counting them all is the conservative side (#3047).
275
+ */
276
+ function automationDisplayNameCounts(stream, ctx) {
277
+ const counts = new Map();
278
+ const count = (name) => {
279
+ if (typeof name === "string")
280
+ counts.set(name, (counts.get(name) ?? 0) + 1);
281
+ };
282
+ for (const block of stream.allBlocks) {
283
+ if (block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE)
284
+ count(block.attrs["name"]);
285
+ }
286
+ for (const omitted of ctx.omittedAutomationsById?.values() ?? [])
287
+ count(omitted.name);
288
+ return counts;
289
+ }
235
290
  /** The first of `targets` that any block at `owned` references, if any. */
236
- function referencedAddress(stream, owned, targets) {
291
+ function referencedAddress(stream, owned, targets, runnable = new Set()) {
237
292
  const ownedSet = new Set(owned);
238
293
  for (const block of stream.allBlocks) {
239
294
  if (block.type === undefined || block.label === undefined || !ownedSet.has(`${block.type}.${block.label}`))
240
295
  continue;
241
- const hit = referenceIn(block.attrs, targets);
296
+ const hit = referenceIn(withoutRunTargetSites(block, runnable), targets);
242
297
  if (hit !== undefined)
243
298
  return hit;
244
299
  }
245
300
  return undefined;
246
301
  }
302
+ const RUN_AUTOMATION_TASK_TYPE = "elementum_run_automation_task";
303
+ /** The address a bare or attribute reference names, if it is a resource reference. */
304
+ function referencedResource(value) {
305
+ if (value === null || typeof value !== "object")
306
+ return undefined;
307
+ const record = value;
308
+ return record["$expr"] === "resource-attr" && typeof record["type"] === "string" && typeof record["label"] === "string"
309
+ ? `${record["type"]}.${record["label"]}`
310
+ : undefined;
311
+ }
312
+ /**
313
+ * A block's attrs without the places a static Run Automation call names the
314
+ * automation it runs, when that automation is one of `runnable`: the run
315
+ * task's target, its inputs' trigger `parameter_ids` and `depends_on`, and the
316
+ * caller's publish `depends_on`. Pulled source names such a target with
317
+ * `automationRef({ refName, name, parent })`, and build looks the live
318
+ * automation up by that display name when it is not in source (#3047), as it
319
+ * does for a dynamic-layout button (#2693). Every other reference stays.
320
+ */
321
+ function withoutRunTargetSites(block, runnable) {
322
+ if (runnable.size === 0 || (block.type !== RUN_AUTOMATION_TASK_TYPE && block.type !== WORKFLOW_PUBLISH_RESOURCE_TYPE))
323
+ return block.attrs;
324
+ const named = (value) => {
325
+ const address = referencedResource(value);
326
+ return address !== undefined && runnable.has(address);
327
+ };
328
+ const out = { ...block.attrs };
329
+ if (Array.isArray(out["depends_on"]))
330
+ out["depends_on"] = out["depends_on"].filter((entry) => !named(entry));
331
+ if (block.type !== RUN_AUTOMATION_TASK_TYPE)
332
+ return out;
333
+ for (const key of ["target_automation_id", "target_automation_ref"]) {
334
+ if (named(out[key]))
335
+ delete out[key];
336
+ }
337
+ if (Array.isArray(out["input_mappings"])) {
338
+ out["input_mappings"] = out["input_mappings"].map((mapping) => {
339
+ if (mapping === null || typeof mapping !== "object" || !named(mapping["parameter_id"]))
340
+ return mapping;
341
+ const { parameter_id: _parameterId, ...rest } = mapping;
342
+ return rest;
343
+ });
344
+ }
345
+ return out;
346
+ }
347
+ /**
348
+ * `value` with each automation ref of this owner (`ownerHandle`) whose key is
349
+ * in `names` given that display name (#3047). Another app's automation can
350
+ * have the same key, so the owner has to match too.
351
+ */
352
+ function withUnmanagedRunTargets(value, names, ownerHandle) {
353
+ if (names.size === 0)
354
+ return value;
355
+ // Copy on write, through plain arrays and objects only: every other value
356
+ // (and any subtree with no such ref) keeps its identity and prototype.
357
+ const walk = (node) => {
358
+ if (Array.isArray(node)) {
359
+ const mapped = node.map(walk);
360
+ return mapped.some((child, index) => child !== node[index]) ? mapped : node;
361
+ }
362
+ if (node === null || typeof node !== "object")
363
+ return node;
364
+ const prototype = Object.getPrototypeOf(node);
365
+ if (prototype !== Object.prototype && prototype !== null)
366
+ return node;
367
+ const record = node;
368
+ if (record["kind"] === "automation" && typeof record["automationKey"] === "string") {
369
+ const name = record["appHandle"] === ownerHandle ? names.get(record["automationKey"]) : undefined;
370
+ return name === undefined ? record : { ...record, unmanagedName: name };
371
+ }
372
+ let changed = false;
373
+ const entries = Object.entries(record).map(([key, child]) => {
374
+ const next = walk(child);
375
+ if (next !== child)
376
+ changed = true;
377
+ return [key, next];
378
+ });
379
+ return changed ? Object.fromEntries(entries) : record;
380
+ };
381
+ return walk(value);
382
+ }
247
383
  function extractAutomations(ownBlocks, stream, ctx) {
248
384
  const items = [];
249
385
  const skipped = [];
@@ -255,9 +391,46 @@ function extractAutomations(ownBlocks, stream, ctx) {
255
391
  const released = [];
256
392
  // Which file each skipped automation's resources come from (#1877).
257
393
  const skippedOwnFiles = [];
258
- const skip = (owned, refName) => {
394
+ const unmanagedLookups = [];
395
+ // What the pull summary lists for each skipped automation (#3053): a
396
+ // caller skipped only because of another skipped automation names that
397
+ // one's root cause, so the summary can group them.
398
+ const skippedReports = [];
399
+ const skippedOwner = new Map();
400
+ const rootCause = new Map();
401
+ // Skipped automations a Run Automation call can still name by display
402
+ // name (#3047): each one's addresses, and its key -> display name.
403
+ const runnable = new Set();
404
+ const runnableNames = new Map();
405
+ const displayNameCounts = automationDisplayNameCounts(stream, ctx);
406
+ const skip = (autoBlock, owned, refName, why, causedBy) => {
259
407
  skipped.push(...owned);
260
408
  skippedOwnFiles.push({ refName, addresses: owned });
409
+ const address = `${AUTOMATION_RESOURCE_TYPE}.${autoBlock.label ?? ""}`;
410
+ for (const member of owned)
411
+ skippedOwner.set(member, address);
412
+ const owner = causedBy === undefined ? undefined : skippedOwner.get(causedBy);
413
+ const root = owner === undefined ? undefined : rootCause.get(owner) ?? owner;
414
+ if (root !== undefined)
415
+ rootCause.set(address, root);
416
+ const name = autoBlock.attrs["name"];
417
+ skippedReports.push({
418
+ address,
419
+ name: typeof name === "string" && name !== "" ? name : autoBlock.label ?? "",
420
+ reason: why,
421
+ ...(root !== undefined && { causedBy: root }),
422
+ });
423
+ // A name lookup fails when two automations in the app share the name.
424
+ const uniqueName = typeof name === "string" && name !== "" && displayNameCounts.get(name) === 1 && autoBlock.attrs["app_id"] !== undefined;
425
+ const lookup = unmanagedAutomationLookup(autoBlock, owned, `${ctx.appTfLabel}_${tsLabelToTfLabel(refName)}`, uniqueName);
426
+ if (lookup !== undefined)
427
+ unmanagedLookups.push(lookup);
428
+ if (uniqueName) {
429
+ for (const member of owned)
430
+ runnable.add(member);
431
+ // Keyed as the caller's decoded target ref is (from-tf `decodeValue`).
432
+ runnableNames.set(scopedLabelToBagKey(ctx.appTfLabel, autoBlock.label ?? ""), name);
433
+ }
261
434
  };
262
435
  const settledByState = new Set();
263
436
  const release = (entry) => {
@@ -282,10 +455,11 @@ function extractAutomations(ownBlocks, stream, ctx) {
282
455
  const owned = automationOwnedAddresses(doc, autoLabel);
283
456
  const chain = referencedAddress(stream, owned, lostChains);
284
457
  if (chain !== undefined) {
285
- skip(owned, scopedLabelToBagKey(ctx.appTfLabel, autoLabel));
458
+ const why = `it uses ${chain}, which pull leaves unmanaged because its stage has no handle of its own (#1136)`;
459
+ skip(autoBlock, owned, scopedLabelToBagKey(ctx.appTfLabel, autoLabel), why);
286
460
  release({
287
461
  autoBlock, autoLabel, owned, refName: scopedLabelToBagKey(ctx.appTfLabel, autoLabel),
288
- why: `it uses ${chain}, which pull leaves unmanaged because its stage has no handle of its own (#1136)`,
462
+ why,
289
463
  nextStep: "To manage it with the EDK, give that stage its own handle in the platform, then pull again.",
290
464
  });
291
465
  continue;
@@ -299,10 +473,11 @@ function extractAutomations(ownBlocks, stream, ctx) {
299
473
  // second copy of the live automation.
300
474
  if (extracted.stringifiedValueReferences === true) {
301
475
  const owned = automationOwnedAddresses(doc, autoLabel);
302
- skip(owned, extracted.refName);
476
+ const why = "its export embeds a value reference as text that source cannot rebuild exactly (edk#1646)";
477
+ skip(autoBlock, owned, extracted.refName, why);
303
478
  release({
304
479
  autoBlock, autoLabel, owned, refName: extracted.refName,
305
- why: "its export embeds a value reference as text that source cannot rebuild exactly (edk#1646)",
480
+ why,
306
481
  nextStep: "Keep editing it in the platform.",
307
482
  });
308
483
  continue;
@@ -333,7 +508,7 @@ function extractAutomations(ownBlocks, stream, ctx) {
333
508
  message: err.message,
334
509
  code: "unresolved-task-filter-ref",
335
510
  });
336
- skip(owned, scopedLabelToBagKey(ctx.appTfLabel, autoLabel));
511
+ skip(autoBlock, owned, scopedLabelToBagKey(ctx.appTfLabel, autoLabel), `pull could not turn its export into source: ${err.message}`);
337
512
  release({
338
513
  autoBlock, autoLabel, owned, refName: scopedLabelToBagKey(ctx.appTfLabel, autoLabel),
339
514
  why: `pull could not turn its export into source: ${err.message}`,
@@ -343,7 +518,10 @@ function extractAutomations(ownBlocks, stream, ctx) {
343
518
  });
344
519
  continue;
345
520
  }
346
- skip(owned, scopedLabelToBagKey(ctx.appTfLabel, autoLabel));
521
+ // edk#1480: name the dropped automation and say what that means, as a
522
+ // typed gap so it counts (and fails --strict-coverage) by itself.
523
+ const why = `pull could not turn its export into source: ${err instanceof Error ? err.message : String(err)}`;
524
+ skip(autoBlock, owned, scopedLabelToBagKey(ctx.appTfLabel, autoLabel), why);
347
525
  // No authored form can manage these, so release an earlier adoption
348
526
  // rather than let the next apply destroy the live automation:
349
527
  // sibling-loop item refs (#1320) and multi-trigger (#1785 / #39).
@@ -352,9 +530,6 @@ function extractAutomations(ownBlocks, stream, ctx) {
352
530
  const released = err instanceof ForEachItemOutsideLoopError ||
353
531
  err instanceof UnsupportedMultiTriggerError ||
354
532
  err instanceof UnresolvedForeignServiceAccountError;
355
- // edk#1480: name the dropped automation and say what that means, as a
356
- // typed gap so it counts (and fails --strict-coverage) by itself.
357
- const why = `pull could not turn its export into source: ${err instanceof Error ? err.message : String(err)}`;
358
533
  if (released) {
359
534
  release({
360
535
  autoBlock, autoLabel, owned, refName: scopedLabelToBagKey(ctx.appTfLabel, autoLabel), why,
@@ -378,16 +553,19 @@ function extractAutomations(ownBlocks, stream, ctx) {
378
553
  const skippedAddresses = new Set(skipped);
379
554
  const releasedAddresses = new Set(releaseIfManaged);
380
555
  for (const entry of kept) {
381
- const target = referencedAddress(stream, entry.owned, skippedAddresses);
556
+ // A Run Automation call to a skipped automation keeps the caller: its
557
+ // source names the target by display name (#3047). Any other reference
558
+ // to a skipped resource still skips it.
559
+ const target = referencedAddress(stream, entry.owned, skippedAddresses, runnable);
382
560
  if (target === undefined)
383
561
  continue;
384
562
  kept.delete(entry);
385
563
  cascaded = true;
386
- skip(entry.owned, entry.extracted.refName);
387
564
  const gap = {
388
565
  why: `it uses ${target}, which pull skipped, so its reference would point at nothing`,
389
566
  nextStep: `Fix ${target} first (see its own warning), then pull again.`,
390
567
  };
568
+ skip(entry.autoBlock, entry.owned, entry.extracted.refName, gap.why, target);
391
569
  if (releasedAddresses.has(target)) {
392
570
  release({
393
571
  autoBlock: entry.autoBlock, autoLabel: entry.autoLabel, owned: entry.owned, refName: entry.extracted.refName, ...gap,
@@ -421,7 +599,7 @@ function extractAutomations(ownBlocks, stream, ctx) {
421
599
  changed = false;
422
600
  const isSource = sourceGiven(archivedOwned());
423
601
  for (const entry of [...archived]) {
424
- if (externalReferrers(stream, entry.owned, isSource).length === 0)
602
+ if (externalReferrers(stream, entry.owned, isSource, runnable).length === 0)
425
603
  continue;
426
604
  archived.delete(entry);
427
605
  changed = true;
@@ -431,7 +609,7 @@ function extractAutomations(ownBlocks, stream, ctx) {
431
609
  const quarantineOwnFiles = [];
432
610
  const settled = [];
433
611
  for (const entry of released) {
434
- const keptFor = archived.has(entry) ? [] : externalReferrers(stream, entry.owned, isSource);
612
+ const keptFor = archived.has(entry) ? [] : externalReferrers(stream, entry.owned, isSource, runnable);
435
613
  if (keptFor.length === 0) {
436
614
  quarantineOwnFiles.push({
437
615
  kind: "automation",
@@ -459,7 +637,7 @@ function extractAutomations(ownBlocks, stream, ctx) {
459
637
  // the same scopedLabelToBagKey as automationKey. Pushing bare AST (name
460
638
  // only) made missing-automation diagnostics false-positive on every real
461
639
  // extract (issue #395 / PR #417 review).
462
- items.push({ ...extracted.ast, refName: extracted.refName });
640
+ items.push({ ...withUnmanagedRunTargets(extracted.ast, runnableNames, ctx.appRefName), refName: extracted.refName });
463
641
  adoptionAddressAliases.push(...extracted.adoptionAddressAliases);
464
642
  diagnostics.push(...(extracted.diagnostics ?? []).map((diagnostic) => `${autoLabel}: ${diagnostic}`));
465
643
  }
@@ -499,6 +677,8 @@ function extractAutomations(ownBlocks, stream, ctx) {
499
677
  items, skipped, releaseIfManaged, diagnostics, adoptionAddressAliases,
500
678
  ...(validations.length > 0 && { validations }),
501
679
  ...(skippedOwnFiles.length > 0 && { skippedOwnFiles }),
680
+ ...(unmanagedLookups.length > 0 && { unmanagedLookups }),
681
+ ...(skippedReports.length > 0 && { skippedReports }),
502
682
  ...(settleAfterExtract !== undefined && { settleAfterExtract }),
503
683
  };
504
684
  }
@@ -0,0 +1,12 @@
1
+ import type { FromTfContext } from "../../engine/pull/context.js";
2
+ /**
3
+ * The export writes a live automation it left out (no draft, for example) as
4
+ * its platform id. Its display name from omitted-automations.json lets build
5
+ * look it up by name (edk#2693), so the reference keeps its automation with
6
+ * no id in source. A DISABLED automation is deleted, and a key that names an
7
+ * exported automation would build that one instead, so neither gets a key.
8
+ */
9
+ export declare function omittedAutomationKey(id: string, ownerTfLabel: string, ctx: FromTfContext): {
10
+ readonly key: string;
11
+ readonly name: string;
12
+ } | undefined;
@@ -0,0 +1,21 @@
1
+ import { isTfLabel, sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
2
+ import { AUTOMATION_RESOURCE_TYPE, automationResourceLabel } from "./types.js";
3
+ /**
4
+ * The export writes a live automation it left out (no draft, for example) as
5
+ * its platform id. Its display name from omitted-automations.json lets build
6
+ * look it up by name (edk#2693), so the reference keeps its automation with
7
+ * no id in source. A DISABLED automation is deleted, and a key that names an
8
+ * exported automation would build that one instead, so neither gets a key.
9
+ */
10
+ export function omittedAutomationKey(id, ownerTfLabel, ctx) {
11
+ const omitted = ctx.omittedAutomationsById?.get(id);
12
+ if (omitted === undefined || omitted.kind === "disabled")
13
+ return undefined;
14
+ const label = sanitizeName(omitted.name);
15
+ if (!isTfLabel(label))
16
+ return undefined;
17
+ const key = tfLabelToTsLabel(label);
18
+ if (ctx.resourceByAddress?.(`${AUTOMATION_RESOURCE_TYPE}.${automationResourceLabel(ownerTfLabel, key)}`) !== undefined)
19
+ return undefined;
20
+ return { key, name: omitted.name };
21
+ }