@elementumai/edk 0.9.14 → 0.9.15

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 (82) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +4 -2
  2. package/dist-sdk/src/catalog/factories.js +4 -0
  3. package/dist-sdk/src/catalog/from-authoring.js +5 -1
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/token.js +2 -2
  7. package/dist-sdk/src/catalog/types.d.ts +7 -2
  8. package/dist-sdk/src/core/types/app.d.ts +4 -4
  9. package/dist-sdk/src/engine/build/context.d.ts +3 -2
  10. package/dist-sdk/src/engine/build/source-context.d.ts +2 -0
  11. package/dist-sdk/src/engine/build/source-context.js +16 -0
  12. package/dist-sdk/src/engine/progress.d.ts +15 -1
  13. package/dist-sdk/src/engine/progress.js +17 -1
  14. package/dist-sdk/src/engine/pull/context.d.ts +4 -1
  15. package/dist-sdk/src/engine/pull/ref-only.d.ts +2 -2
  16. package/dist-sdk/src/engine/pull/ref-only.js +3 -3
  17. package/dist-sdk/src/engine/workspace/loader.js +23 -2
  18. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +6 -0
  19. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +23 -2
  20. package/dist-sdk/src/entities/agent/module.js +1 -0
  21. package/dist-sdk/src/entities/agent/to-tf.js +1 -0
  22. package/dist-sdk/src/entities/agent/tools.d.ts +20 -4
  23. package/dist-sdk/src/entities/agent/tools.js +10 -2
  24. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +4 -0
  25. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -1
  26. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +11 -6
  28. package/dist-sdk/src/entities/app/build.d.ts +2 -2
  29. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +4 -4
  30. package/dist-sdk/src/entities/approval-chain/build.d.ts +8 -1
  31. package/dist-sdk/src/entities/approval-chain/build.js +3 -0
  32. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +2 -1
  33. package/dist-sdk/src/entities/approval-chain/from-tf.js +20 -7
  34. package/dist-sdk/src/entities/approval-chain/printer.js +13 -2
  35. package/dist-sdk/src/entities/approval-chain/to-tf.js +3 -0
  36. package/dist-sdk/src/entities/automation/build.d.ts +7 -7
  37. package/dist-sdk/src/entities/automation/build.js +6 -2
  38. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +19 -0
  39. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +114 -42
  40. package/dist-sdk/src/entities/automation/from-tf.d.ts +13 -1
  41. package/dist-sdk/src/entities/automation/from-tf.js +105 -33
  42. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  43. package/dist-sdk/src/entities/automation/index.js +2 -2
  44. package/dist-sdk/src/entities/automation/module.js +15 -9
  45. package/dist-sdk/src/entities/automation/script-code.d.ts +32 -0
  46. package/dist-sdk/src/entities/automation/script-code.js +59 -1
  47. package/dist-sdk/src/entities/automation/tasks.d.ts +19 -19
  48. package/dist-sdk/src/entities/automation/tasks.js +2 -5
  49. package/dist-sdk/src/entities/automation/to-tf.js +38 -10
  50. package/dist-sdk/src/entities/chart/build.d.ts +3 -3
  51. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  52. package/dist-sdk/src/entities/chart/from-tf.js +20 -13
  53. package/dist-sdk/src/entities/chart/to-tf.js +7 -5
  54. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +3 -2
  55. package/dist-sdk/src/entities/field/build.d.ts +2 -2
  56. package/dist-sdk/src/entities/field/from-tf.js +35 -3
  57. package/dist-sdk/src/entities/field/to-tf.d.ts +1 -1
  58. package/dist-sdk/src/entities/field/to-tf.js +11 -4
  59. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -2
  60. package/dist-sdk/src/entities/relationship/from-tf.js +6 -3
  61. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  62. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +3 -3
  63. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +10 -6
  64. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -2
  65. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  66. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  67. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +6 -0
  68. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +29 -16
  69. package/dist-sdk/src/entities/skill/module.js +1 -0
  70. package/dist-sdk/src/entities/skill/to-tf.js +1 -0
  71. package/dist-sdk/src/entities/skill/tools.d.ts +11 -3
  72. package/dist-sdk/src/entities/skill/tools.js +5 -1
  73. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +6 -0
  74. package/dist-sdk/src/entities/skill-tool/from-tf.js +19 -1
  75. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -0
  76. package/dist-sdk/src/entities/skill-tool/to-tf.js +13 -4
  77. package/dist-sdk/src/entities/task/module.js +1 -1
  78. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  79. package/dist-sdk/src/graph/index.d.ts +2 -0
  80. package/dist-sdk/src/graph/index.js +14 -0
  81. package/dist-sdk/src/graph/types.d.ts +27 -1
  82. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { serializeValueOrRef } from "../../core/wire/ref-serializer.js";
2
2
  import { isExpr } from "../field/calc/runtime.js";
3
3
  import { renderCalculationExpression, } from "./calculation-expression.js";
4
- import { extractScriptBody } from "./script-code.js";
4
+ import { extractScriptBody, isScriptFile, readScriptFile } from "./script-code.js";
5
5
  function workflowFields(fields) {
6
6
  return fields.map((f) => {
7
7
  const updateMode = "updateMode" in f ? f.updateMode : undefined;
@@ -251,7 +251,7 @@ export function executeScriptActionDefWithBody(body, opts) {
251
251
  };
252
252
  }
253
253
  export function executeScript(opts) {
254
- return executeScriptActionDefWithBody(extractScriptBody(opts.code), opts);
254
+ return executeScriptActionDefWithBody(isScriptFile(opts.code) ? readScriptFile(opts.code) : extractScriptBody(opts.code), opts);
255
255
  }
256
256
  function apiRequestHeaders(headers) {
257
257
  return (headers ?? []).map((h) => ({ name: h.name, value: serializeValueOrRef(h.value) }));
@@ -458,9 +458,6 @@ export function notification(opts) {
458
458
  },
459
459
  };
460
460
  }
461
- export function filterAction(opts) {
462
- return { key: "filter", config: { filter: opts.condition } };
463
- }
464
461
  export function assignUser(opts) {
465
462
  return { key: "assignUser", config: { fieldId: opts.field, userId: opts.userId } };
466
463
  }
@@ -299,9 +299,9 @@ function resolveTableColumnFieldExpr(opts) {
299
299
  * its own foreign-field label: an app and an element can share a refName,
300
300
  * and `elementum_field` is one shared data-source type for both.
301
301
  */
302
- /** App/element root lookup attrs when orgRefs is unavailable (mirrors graph rootNamespace strategy). */
302
+ /** App/element/task root lookup attrs when orgRefs is unavailable (mirrors graph rootNamespace strategy). */
303
303
  function foreignRootLookup(kind, identity) {
304
- const resourceType = kind === "element" ? "elementum_element" : "elementum_app";
304
+ const resourceType = kind === "task" ? "elementum_task" : kind === "element" ? "elementum_element" : "elementum_app";
305
305
  if (identity.namespace !== undefined && identity.namespace !== "") {
306
306
  return {
307
307
  resourceType,
@@ -318,7 +318,7 @@ function foreignRootLookup(kind, identity) {
318
318
  };
319
319
  }
320
320
  /**
321
- * Validates and derives the shared naming for a cross-app/element field
321
+ * Validates and derives the shared naming for a cross-app/element/task field
322
322
  * token — the `data.elementum_field` label {@link crossAppFieldToTf} emits,
323
323
  * and the matching `<fieldLabel>_options_by_label` local a foreign PICKLIST
324
324
  * field's option-label lookup (in {@link picklistFilterValueToTf}) resolves
@@ -343,7 +343,7 @@ function foreignFieldNaming(value) {
343
343
  throw new EntityTfError(`field ref "${value.refName}" has a parent ("${parent}") but no parentName — incomplete foreign-field provenance; the owner lookup would key on the refName instead of its real display name and silently miss at apply`);
344
344
  }
345
345
  const fieldName = value.name ?? value.refName;
346
- const ownerKind = value.parentKind === "element" ? "element" : "app";
346
+ const ownerKind = value.parentKind === "task" ? "task" : value.parentKind === "element" ? "element" : "app";
347
347
  const resolved = foreignRootLookup(ownerKind, {
348
348
  name: value.parentName,
349
349
  namespace: value.parentNamespace,
@@ -385,7 +385,7 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
385
385
  // filtered out rather than cast away — the map holds tables too, because a
386
386
  // table-owned search table has to be distinguishable from an element-owned
387
387
  // one.
388
- if (sibling !== undefined && sibling.kind !== "table") {
388
+ if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
389
389
  const fieldValue = fieldRefToTfValue(value.fieldType ?? "", value.refName, sibling.tfLabel, sibling.kind);
390
390
  if (fieldValue === undefined) {
391
391
  throw new EntityTfError(`field ref "${value.refName}" on sibling ${sibling.kind} "${value.parent}" has no terraform field resource mapping (fieldType ${JSON.stringify(value.fieldType ?? "")})`);
@@ -394,7 +394,7 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
394
394
  }
395
395
  }
396
396
  const { fieldName, fieldLabel } = foreignFieldNaming(value);
397
- const ownerKind = value.parentKind === "element" ? "element" : "app";
397
+ const ownerKind = value.parentKind === "task" ? "task" : value.parentKind === "element" ? "element" : "app";
398
398
  if (ctx.orgRefs !== undefined) {
399
399
  const owner = resolveForeignRef(ownerKind, { name: value.parentName, namespace: value.parentNamespace }, ctx.orgRefs, ctx.diagnostics, `automation field "${value.refName}" owner`);
400
400
  ctx.orgRefs.foreignField("elementum_field", fieldLabel, owner.value, fieldName);
@@ -556,6 +556,28 @@ function tokenToTf(value, ctx, dataBlocks) {
556
556
  }
557
557
  case "userField":
558
558
  return value.refName;
559
+ case "task": {
560
+ const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("task", value.refName));
561
+ if (sibling !== undefined) {
562
+ return expr.resourceAttr("elementum_task", sibling.tfLabel, ["id"]);
563
+ }
564
+ const name = value.name ?? value.refName;
565
+ if (!name)
566
+ throw new EntityTfError(`task ref "${value.refName}" has no lookup name`);
567
+ if (ctx.orgRefs !== undefined) {
568
+ const tfLabel = sanitizeName(value.namespace ?? name);
569
+ ctx.orgRefs.rawLookup("elementum_task", tfLabel, name);
570
+ return expr.dataAttr("elementum_task", tfLabel, ["id"]);
571
+ }
572
+ const resolved = foreignRootLookup("task", { name, namespace: value.namespace });
573
+ dataBlocks.set(`${resolved.resourceType}.${resolved.tfLabel}`, {
574
+ kind: "data",
575
+ type: resolved.resourceType,
576
+ label: resolved.tfLabel,
577
+ attrs: { [resolved.lookupAttr]: resolved.lookupValue },
578
+ });
579
+ return expr.dataAttr(resolved.resourceType, resolved.tfLabel, ["id"]);
580
+ }
559
581
  case "app":
560
582
  case "element":
561
583
  if (value.refName !== ctx.appRefName || value.__kind !== ctx.parentScope) {
@@ -586,7 +608,7 @@ function tokenToTf(value, ctx, dataBlocks) {
586
608
  // kind+refName, not refName alone), so a same-named element field
587
609
  // must still resolve as foreign — the automation's own app is
588
610
  // always an app (automations are app-owned only, for now).
589
- if (value.parent !== undefined && (value.parent !== ctx.appRefName || value.parentKind === "element")) {
611
+ if (value.parent !== undefined && (value.parent !== ctx.appRefName || value.parentKind === "element" || value.parentKind === "task")) {
590
612
  return crossAppFieldToTf(value, ctx, dataBlocks);
591
613
  }
592
614
  const address = ctx.fieldAddresses.get(value.refName);
@@ -1254,6 +1276,9 @@ const RECORD_COLLECTION_TASK_WIRE_TYPES = new Set([
1254
1276
  const TS_FOR_EACH_GENERIC_SEGMENT_TO_WIRE = {
1255
1277
  iteration: "Iteration",
1256
1278
  };
1279
+ function forEachCompactFilterName(name) {
1280
+ return name === "recordId" ? "item" : name;
1281
+ }
1257
1282
  function forEachWireRefName(name, ctx, isRecordCollection) {
1258
1283
  // A recordSearch collection's whole item and branded record identity both
1259
1284
  // point at the loop's ASPECT_RECORD_ID reference. Live provider state
@@ -1885,8 +1910,11 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1885
1910
  const task = refs.tasks.get(value.forEachTaskRefKey);
1886
1911
  if (task === undefined)
1887
1912
  throw new EntityTfError(`unresolved forEach filter ref "${value.forEachTaskRefKey}"`);
1888
- const index = forEachWireRefName(value.name, refs.owner, refs.recordItemForEachRefKeys.has(value.forEachTaskRefKey));
1889
- return expr.resourceAttr(task.type, task.label, ["inner", "refs", { index }]);
1913
+ return expr.template([
1914
+ "for_each.",
1915
+ expr.resourceAttr(task.type, task.label, ["id"]),
1916
+ `.${forEachCompactFilterName(value.name)}`,
1917
+ ]);
1890
1918
  }
1891
1919
  case "VALUE":
1892
1920
  return valueToTf(value.value, refs);
@@ -1956,7 +1984,7 @@ function picklistFilterValueToTf(value, field, refs) {
1956
1984
  const sibling = refs.owner.workspaceAspects?.get(workspaceAspectKey(field.parentKind, field.parent));
1957
1985
  // Table siblings excluded for the same reason as in `crossAppFieldToTf`: a
1958
1986
  // picklist field's owner is an app or an element, never a table.
1959
- if (sibling !== undefined && sibling.kind !== "table") {
1987
+ if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
1960
1988
  const localName = field.tags?.includes("STATUS")
1961
1989
  ? `${sibling.tfLabel}_status_options_by_label`
1962
1990
  : field.tags?.includes("STAGE")
@@ -1,17 +1,17 @@
1
- import { type AppCatalogRef, type AppOrElementRef, type ChartRef, type FieldRef, type TableColumnRef, type TableRef } from "../../catalog/index.js";
1
+ import { type AppCatalogRef, type AppOrElementOrTaskRef, type ChartRef, type FieldRef, type TableColumnRef, type TableRef } from "../../catalog/index.js";
2
2
  import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
4
  import type { UnsafePlatformId } from "../../core/platform-id.js";
5
5
  import type { ChartAggregation, ChartColumnValueType, ChartJoinType, ChartType } from "./types.js";
6
6
  export { chartAggregation, chartColumnValueType, chartJoinType, chartType, type ChartAggregation, type ChartColumnValueType, type ChartJoinType, type ChartType, } from "./types.js";
7
- export type ChartDatasourceRef = AppOrElementRef | TableRef;
7
+ export type ChartDatasourceRef = AppOrElementOrTaskRef | TableRef;
8
8
  type RefBagValue<T> = T extends Readonly<Record<string, infer Value>> ? Value : never;
9
9
  export type ChartFieldFor<Datasource> = Datasource extends {
10
10
  readonly __kind: "table";
11
11
  readonly columns?: infer Columns;
12
12
  } ? Extract<RefBagValue<NonNullable<Columns>>, TableColumnRef> : Datasource extends {
13
13
  readonly fields: infer Fields;
14
- } ? Extract<RefBagValue<Fields>, FieldRef> : Datasource extends AppOrElementRef<infer Parent> ? FieldRef<Parent> : Datasource extends TableRef<infer Parent> ? TableColumnRef<Parent> : never;
14
+ } ? Extract<RefBagValue<Fields>, FieldRef> : Datasource extends AppOrElementOrTaskRef<infer Parent> ? FieldRef<Parent> : Datasource extends TableRef<infer Parent> ? TableColumnRef<Parent> : never;
15
15
  interface ChartColumnBase {
16
16
  readonly name?: string;
17
17
  }
@@ -3,7 +3,7 @@ import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
4
  import type { ChartProperties } from "./build.js";
5
5
  export interface NormalizedChartDatasource {
6
- readonly kind: "app" | "element" | "table";
6
+ readonly kind: "app" | "element" | "table" | "task";
7
7
  readonly refName: string;
8
8
  readonly name?: string;
9
9
  readonly local: boolean;
@@ -11,7 +11,7 @@ export interface NormalizedChartDatasource {
11
11
  }
12
12
  export interface NormalizedChartField {
13
13
  readonly kind: "field" | "tableColumn";
14
- readonly parentKind: "app" | "element" | "table";
14
+ readonly parentKind: "app" | "element" | "table" | "task";
15
15
  readonly parentRefName: string;
16
16
  readonly refName: string;
17
17
  readonly name?: string;
@@ -22,7 +22,7 @@ function decodeJson(value) {
22
22
  return value;
23
23
  }
24
24
  function datasourceFromTf(value, appLabel, appRefName, ctx, where) {
25
- for (const [type, kind] of [[APP_RESOURCE_TYPE, "app"], ["elementum_element", "element"], [TABLE_RESOURCE_TYPE, "table"]]) {
25
+ for (const [type, kind] of [[APP_RESOURCE_TYPE, "app"], ["elementum_element", "element"], ["elementum_task", "task"], [TABLE_RESOURCE_TYPE, "table"]]) {
26
26
  const resourceLabel = resourceRefLabel(value, type);
27
27
  if (resourceLabel !== undefined) {
28
28
  return {
@@ -39,15 +39,17 @@ function datasourceFromTf(value, appLabel, appRefName, ctx, where) {
39
39
  ? ctx.foreignAppRefNames?.get(name) ?? tfLabelToTsLabel(dataLabel)
40
40
  : kind === "element"
41
41
  ? ctx.foreignElementRefNames?.get(name) ?? tfLabelToTsLabel(dataLabel)
42
- : (() => {
43
- const attrs = ctx.dataAttrs?.(type, dataLabel);
44
- const id = typeof attrs?.["id"] === "string" ? attrs["id"] : ctx.importId(`data.${type}.${dataLabel}`);
45
- const byId = id === undefined ? undefined : ctx.foreignTableRefsById?.get(id);
46
- if (byId !== undefined)
47
- return byId.tableRefName;
48
- const matches = [...(ctx.foreignTableRefsById?.values() ?? [])].filter((candidate) => candidate.name === name);
49
- return matches.length === 1 ? matches[0].tableRefName : undefined;
50
- })();
42
+ : kind === "task"
43
+ ? tfLabelToTsLabel(dataLabel)
44
+ : (() => {
45
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
46
+ const id = typeof attrs?.["id"] === "string" ? attrs["id"] : ctx.importId(`data.${type}.${dataLabel}`);
47
+ const byId = id === undefined ? undefined : ctx.foreignTableRefsById?.get(id);
48
+ if (byId !== undefined)
49
+ return byId.tableRefName;
50
+ const matches = [...(ctx.foreignTableRefsById?.values() ?? [])].filter((candidate) => candidate.name === name);
51
+ return matches.length === 1 ? matches[0].tableRefName : undefined;
52
+ })();
51
53
  if (refName === undefined) {
52
54
  ctx.diagnostics.push(`${where}: table datasource ${name} cannot be resolved to the org catalog; skipped`);
53
55
  return undefined;
@@ -60,7 +62,7 @@ function datasourceFromTf(value, appLabel, appRefName, ctx, where) {
60
62
  if (table !== undefined)
61
63
  return { kind: "table", refName: table.tableRefName, name: table.name, local: false, tfLabel: table.tableRefName };
62
64
  }
63
- ctx.diagnostics.push(`${where}: datasource_id is not a typed app, element, or table reference; skipped`);
65
+ ctx.diagnostics.push(`${where}: datasource_id is not a typed app, element, task, or table reference; skipped`);
64
66
  return undefined;
65
67
  }
66
68
  function indexedField(value) {
@@ -72,8 +74,8 @@ function indexedField(value) {
72
74
  return { label: value.label, name: index.index, data: value.$expr === "data-attr" };
73
75
  }
74
76
  function fieldFromTf(value, datasource, ctx, where) {
75
- if (value !== undefined && (datasource.kind === "app" || datasource.kind === "element")) {
76
- const refName = fieldKeyFromTfValue(value, datasource.refName, datasource.tfLabel, datasource.kind, ctx);
77
+ if (value !== undefined && (datasource.kind === "app" || datasource.kind === "element" || datasource.kind === "task")) {
78
+ const refName = fieldKeyFromTfValue(value, datasource.refName, datasource.tfLabel, datasource.kind === "task" ? "app" : datasource.kind, ctx);
77
79
  if (refName !== undefined)
78
80
  return { kind: "field", parentKind: datasource.kind, parentRefName: datasource.refName, refName };
79
81
  }
@@ -108,7 +110,12 @@ function fieldFromTf(value, datasource, ctx, where) {
108
110
  const id = typeof attrs?.["id"] === "string"
109
111
  ? attrs["id"]
110
112
  : ctx.importId(`data.elementum_field.${dataLabel}`);
113
+ const fromDataAddr = ctx.foreignFieldRefsByDataAddress?.get(`data.elementum_field.${dataLabel}`)
114
+ ?? ctx.foreignFieldRefsByDataAddress?.get(`elementum_field.${dataLabel}`);
111
115
  let resolved = id === undefined ? undefined : ctx.foreignFieldRefsById?.get(id);
116
+ if (resolved === undefined && fromDataAddr !== undefined) {
117
+ resolved = { ownerRefName: fromDataAddr.ownerRefName, fieldKey: fromDataAddr.fieldKey, fieldName: fromDataAddr.fieldName };
118
+ }
112
119
  if (resolved === undefined && name !== undefined) {
113
120
  const matches = [...(ctx.foreignFieldRefsById?.values() ?? [])].filter((candidate) => candidate.ownerRefName === datasource.refName && candidate.fieldName === name);
114
121
  if (matches.length === 1)
@@ -9,14 +9,14 @@ const APP_RESOURCE_TYPE = "elementum_app";
9
9
  const TABLE_RESOURCE_TYPE = "elementum_table";
10
10
  function datasourceId(ref, opts, where) {
11
11
  if (ref?.refName === undefined || ref.refName === "" || ref.__kind === undefined) {
12
- throw new EntityTfError(`${where}: datasource must be a typed app, element, or table ref`);
12
+ throw new EntityTfError(`${where}: datasource must be a typed app, element, task, or table ref`);
13
13
  }
14
- if (ref.__kind !== "app" && ref.__kind !== "element" && ref.__kind !== "table") {
14
+ if (ref.__kind !== "app" && ref.__kind !== "element" && ref.__kind !== "table" && ref.__kind !== "task") {
15
15
  throw new EntityTfError(`${where}: unsupported datasource kind ${JSON.stringify(ref.__kind)}`);
16
16
  }
17
17
  const local = opts.workspaceAspects?.get(workspaceAspectKey(ref.__kind, ref.refName));
18
18
  if (local !== undefined) {
19
- const type = ref.__kind === "app" ? APP_RESOURCE_TYPE : ref.__kind === "element" ? "elementum_element" : TABLE_RESOURCE_TYPE;
19
+ const type = ref.__kind === "app" ? APP_RESOURCE_TYPE : ref.__kind === "element" ? "elementum_element" : ref.__kind === "task" ? "elementum_task" : TABLE_RESOURCE_TYPE;
20
20
  return { ref, id: expr.resourceAttr(type, local.tfLabel, ["id"]), tfLabel: local.tfLabel, local: true };
21
21
  }
22
22
  const name = ref.name ?? ref.refName;
@@ -25,9 +25,11 @@ function datasourceId(ref, opts, where) {
25
25
  opts.orgRefs.foreignApp(label, name);
26
26
  else if (ref.__kind === "element")
27
27
  opts.orgRefs.foreignElement(label, name);
28
+ else if (ref.__kind === "task")
29
+ opts.orgRefs.rawLookup("elementum_task", label, name);
28
30
  else
29
31
  opts.orgRefs.rawLookup(TABLE_RESOURCE_TYPE, label, name);
30
- const type = ref.__kind === "app" ? APP_RESOURCE_TYPE : ref.__kind === "element" ? "elementum_element" : TABLE_RESOURCE_TYPE;
32
+ const type = ref.__kind === "app" ? APP_RESOURCE_TYPE : ref.__kind === "element" ? "elementum_element" : ref.__kind === "task" ? "elementum_task" : TABLE_RESOURCE_TYPE;
31
33
  return { ref, id: expr.dataAttr(type, label, ["id"]), tfLabel: label, local: false };
32
34
  }
33
35
  function fieldId(ref, datasource, opts, where) {
@@ -46,7 +48,7 @@ function fieldId(ref, datasource, opts, where) {
46
48
  throw new EntityTfError(`${where}: expected a field or table-column ref`);
47
49
  if (datasource.ref.__kind === "table")
48
50
  throw new EntityTfError(`${where}: app/element fields cannot belong to a table datasource`);
49
- if (datasource.local) {
51
+ if (datasource.local && datasource.ref.__kind !== "task") {
50
52
  const scope = datasource.ref.__kind === "element" ? "element" : "app";
51
53
  const direct = fieldRefToTfValue(ref.fieldType ?? "", ref.refName, datasource.tfLabel, scope);
52
54
  if (direct !== undefined)
@@ -222,8 +222,9 @@ function dependency(value, owner, ctx, where) {
222
222
  }
223
223
  function fieldKey(value, owner, ctx, where) {
224
224
  const key = fieldKeyFromTfRef(value, owner.ownerTfLabel, "app");
225
- if (key === undefined)
226
- ctx.diagnostics.push(`${where}: field reference is not resolvable; dropped`);
225
+ if (key === undefined) {
226
+ ctx.diagnostics.push(`${where}: field reference ${JSON.stringify(value)} is not resolvable; dropped`);
227
+ }
227
228
  return key;
228
229
  }
229
230
  function stageKey(value, owner) {
@@ -18,7 +18,7 @@
18
18
  * AppField is accepted.
19
19
  */
20
20
  import type { AppField, AppPicklistConfig, PicklistOption } from "../app/build.js";
21
- import type { AppOrElementRef, FieldRef } from "../../catalog/index.js";
21
+ import type { AppOrElementOrTaskRef, AppOrElementRef, FieldRef } from "../../catalog/index.js";
22
22
  import type { AppFieldOfExprType, CalculationInclude, Expr, ExprContext, ExprType, ExprTypeOf, FieldRefOfExprType } from "./calc/types.js";
23
23
  import type { UnsafePlatformId } from "../../core/platform-id.js";
24
24
  import type { AspectFieldQrFormat, AspectNumericFieldFormat } from "../../../elementum-entity-client/clients/aspects/models/format.js";
@@ -151,7 +151,7 @@ export interface TextFieldOptions extends BaseFieldOptions {
151
151
  * workspace needs that.
152
152
  */
153
153
  export interface RelationFieldOptions extends BaseFieldOptions {
154
- readonly relatedObject: AppOrElementRef | UnsafePlatformId;
154
+ readonly relatedObject: AppOrElementOrTaskRef | UnsafePlatformId;
155
155
  readonly relatedLabelField: FieldRef | UnsafePlatformId;
156
156
  /**
157
157
  * Defaults to `true` on the platform. Selecting a related record creates an
@@ -80,6 +80,14 @@ function resolveRelatedObject(v, ctx) {
80
80
  ctx.unresolvedForeignRefs?.elements.add(name);
81
81
  return undefined;
82
82
  }
83
+ if (v.type === "elementum_task") {
84
+ const attrs = ctx.dataAttrs?.("elementum_task", v.label);
85
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
86
+ const name = ctx.dataName("elementum_task", v.label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
87
+ const refName = namespace !== undefined ? ctx.foreignTaskRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignTaskRefNames?.get(name) : undefined;
88
+ const finalRefName = refName ?? tfLabelToTsLabel(v.label);
89
+ return { __kind: "task", refName: finalRefName, name: name ?? finalRefName, ...(namespace !== undefined ? { namespace } : {}) };
90
+ }
83
91
  return undefined;
84
92
  }
85
93
  function resolveRelatedField(v, ctx) {
@@ -88,7 +96,31 @@ function resolveRelatedField(v, ctx) {
88
96
  return raw;
89
97
  if (v === undefined || !isTfExpr(v) || v.$expr !== "data-attr" || v.path.join(".") !== "id")
90
98
  return undefined;
91
- return ctx.foreignFieldRefsByDataAddress?.get(`${v.type}.${v.label}`);
99
+ const fromMap = ctx.foreignFieldRefsByDataAddress?.get(`${v.type}.${v.label}`);
100
+ if (fromMap !== undefined)
101
+ return fromMap;
102
+ if (v.type === "elementum_field") {
103
+ const attrs = ctx.dataAttrs?.("elementum_field", v.label);
104
+ const objectId = attrs?.["object_id"];
105
+ if (objectId !== undefined && isTfExpr(objectId) && objectId.$expr === "data-attr" && objectId.type === "elementum_task") {
106
+ const taskAttrs = ctx.dataAttrs?.("elementum_task", objectId.label);
107
+ const taskName = ctx.dataName("elementum_task", objectId.label) ?? (typeof taskAttrs?.name === "string" ? taskAttrs.name : objectId.label);
108
+ const taskNamespace = typeof taskAttrs?.namespace === "string" ? taskAttrs.namespace : undefined;
109
+ const taskRefName = (taskNamespace !== undefined ? ctx.foreignTaskRefNamespaces?.get(taskNamespace) : undefined) ?? (taskName !== undefined ? ctx.foreignTaskRefNames?.get(taskName) : undefined) ?? tfLabelToTsLabel(objectId.label);
110
+ const fieldName = typeof attrs?.name === "string" ? attrs.name : undefined;
111
+ const strippedKey = fieldKeyFromForeignDataLabel(v.label, { key: taskRefName, name: taskName, kind: "task" });
112
+ const fieldKey = strippedKey ?? tfLabelToTsLabel(v.label);
113
+ return {
114
+ ownerRefName: taskRefName,
115
+ ownerKind: "task",
116
+ ownerName: taskName,
117
+ ...(taskNamespace !== undefined ? { ownerNamespace: taskNamespace } : {}),
118
+ fieldKey,
119
+ ...(fieldName !== undefined ? { fieldName } : {}),
120
+ };
121
+ }
122
+ }
123
+ return undefined;
92
124
  }
93
125
  /**
94
126
  * A dynamic picklist filter's field reference → `RefExpr`. Every field a
@@ -559,8 +591,8 @@ function fieldTypeFromRegistry(ctx, ownerRefName, fieldKey) {
559
591
  }
560
592
  /** Strip ei's owner-display prefix from a `data.elementum_field` label. */
561
593
  export function fieldKeyFromForeignDataLabel(dataLabel, target) {
562
- const kind = target.kind === "element" || target.kind === "app" ? target.kind : undefined;
563
- const ownerType = kind === "element" ? "elementum_element" : kind === "app" ? "elementum_app" : undefined;
594
+ const kind = target.kind === "element" || target.kind === "app" || target.kind === "task" ? target.kind : undefined;
595
+ const ownerType = kind === "element" ? "elementum_element" : kind === "app" ? "elementum_app" : kind === "task" ? "elementum_task" : undefined;
564
596
  const slugs = [
565
597
  target.name !== undefined && target.name !== "" ? sanitizeName(target.name) : undefined,
566
598
  target.namespace,
@@ -26,7 +26,7 @@ interface FieldTokenWire {
26
26
  readonly name?: string;
27
27
  readonly parent?: string;
28
28
  readonly parentNamespace?: string;
29
- readonly parentKind?: "app" | "element";
29
+ readonly parentKind?: "app" | "element" | "task";
30
30
  readonly parentName?: string;
31
31
  readonly fieldType?: string;
32
32
  }
@@ -86,11 +86,11 @@ function resolveRelatedObject(token, opts, where) {
86
86
  return { value: token };
87
87
  }
88
88
  const refName = token.refName ?? "";
89
- const kind = token.__kind === "element" ? "element" : "app";
89
+ const kind = token.__kind === "element" ? "element" : token.__kind === "task" ? "task" : "app";
90
90
  if (kind === (opts.scope ?? "app") && refName === opts.appRefName) {
91
91
  return { value: opts.objectId, refName, kind, target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel } };
92
92
  }
93
- const sibling = opts.workspaceAspects?.get(workspaceAspectKey(kind, refName));
93
+ const sibling = kind !== "task" ? opts.workspaceAspects?.get(workspaceAspectKey(kind, refName)) : undefined;
94
94
  if (sibling !== undefined) {
95
95
  const resourceType = kind === "element" ? "elementum_element" : "elementum_app";
96
96
  return { value: expr.resourceAttr(resourceType, sibling.tfLabel, ["id"]), refName, kind, target: sibling };
@@ -111,6 +111,12 @@ function resolveRelatedObject(token, opts, where) {
111
111
  opts.diagnostics.push(`${where}: foreign element ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
112
112
  return { value: expr.dataAttr("elementum_element", tfLabel, ["id"]), refName, kind, foreignTfLabel: tfLabel };
113
113
  }
114
+ if (kind === "task") {
115
+ opts.orgRefs.foreignTask(tfLabel, name, token.namespace);
116
+ if (token.namespace === undefined)
117
+ opts.diagnostics.push(`${where}: foreign task ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
118
+ return { value: expr.dataAttr("elementum_task", tfLabel, ["id"]), refName, kind, foreignTfLabel: tfLabel };
119
+ }
114
120
  opts.orgRefs.foreignApp(tfLabel, name, token.namespace);
115
121
  if (token.namespace === undefined)
116
122
  opts.diagnostics.push(`${where}: foreign app ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
@@ -154,7 +160,7 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
154
160
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" belongs to "${token.parent}", not the resolved target "${object.refName}"; dropped`);
155
161
  return undefined;
156
162
  }
157
- if (object.target !== undefined) {
163
+ if (object.target !== undefined && object.target.kind !== "task") {
158
164
  // A field belongs to an app or element; a table exposes columns, not fields.
159
165
  // Guard rather than widen fieldRefToTfValue's scope parameter.
160
166
  if (object.target.kind === "table") {
@@ -177,7 +183,7 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
177
183
  // display name. Re-deriving it from the public refName produces a second,
178
184
  // semantically identical data block when (for example) a relationship and
179
185
  // a dynamic Dropdown both reference the same foreign field.
180
- const ownerType = object.kind === "element" ? "elementum_element" : object.kind === "app" ? "elementum_app" : undefined;
186
+ const ownerType = object.kind === "element" ? "elementum_element" : object.kind === "app" ? "elementum_app" : object.kind === "task" ? "elementum_task" : undefined;
181
187
  const parentLabel = object.foreignTfLabel ?? (token.parent !== undefined ? tsLabelToTfLabel(token.parent) : "related");
182
188
  const tfLabel = ownerType === undefined
183
189
  ? sanitizeName(`${parentLabel}_${name}`)
@@ -211,6 +217,7 @@ function stageOrgRefs(real) {
211
217
  foreignSkill: (tfLabel, name, appId) => pending.push(() => real.foreignSkill(tfLabel, name, appId)),
212
218
  rawLookup: (type, tfLabel, value, extraAttrs) => pending.push(() => real.rawLookup(type, tfLabel, value, extraAttrs)),
213
219
  foreignApp: (tfLabel, name, namespace) => pending.push(() => real.foreignApp(tfLabel, name, namespace)),
220
+ foreignTask: (tfLabel, name, namespace) => pending.push(() => real.foreignTask(tfLabel, name, namespace)),
214
221
  foreignElement: (tfLabel, name, namespace) => pending.push(() => real.foreignElement(tfLabel, name, namespace)),
215
222
  foreignField: (type, tfLabel, objectId, name) => pending.push(() => real.foreignField(type, tfLabel, objectId, name)),
216
223
  };
@@ -47,8 +47,9 @@ function sectionFromTf(raw, index, formWhere, owner, ctx) {
47
47
  const fields = [];
48
48
  for (const fieldId of fieldIds) {
49
49
  const key = fieldKeyFromTfValue(fieldId, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope, ctx);
50
- if (key === undefined)
51
- ctx.diagnostics.push(`${where}: a field_ids entry is not a known field reference; dropped`);
50
+ if (key === undefined) {
51
+ ctx.diagnostics.push(`${where}: field_ids entry ${JSON.stringify(fieldId)} is not a known field reference; dropped`);
52
+ }
52
53
  else
53
54
  fields.push(key);
54
55
  }
@@ -116,13 +116,14 @@ function targetRef(value, owner, ctx) {
116
116
  ["elementum_app", "app"],
117
117
  ["elementum_element", "element"],
118
118
  ["elementum_table", "table"],
119
+ ["elementum_task", "task"],
119
120
  ]) {
120
121
  const resourceLabel = resourceRefLabel(value, type);
121
122
  if (resourceLabel !== undefined)
122
123
  return { kind, key: tfLabelToTsLabel(resourceLabel), name: tfLabelToTsLabel(resourceLabel), tfLabel: resourceLabel, managed: true };
123
124
  const dataLabel = dataRefLabel(value, type);
124
125
  if (dataLabel !== undefined) {
125
- if (kind === "app" || kind === "element") {
126
+ if (kind === "app" || kind === "element" || kind === "task") {
126
127
  return { kind, tfLabel: dataLabel, managed: false, ...resolveDataAspectTarget(ctx, kind, dataLabel) };
127
128
  }
128
129
  const name = ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel);
@@ -134,14 +135,16 @@ function targetRef(value, owner, ctx) {
134
135
  function relatedFieldRef(value, target, ctx) {
135
136
  if (value === undefined)
136
137
  return undefined;
137
- if (isTfExpr(value) && value.$expr === "resource-attr" && value.path.length === 1 && value.path[0] === "id") {
138
+ if (isTfExpr(value) && (value.$expr === "resource-attr" || value.$expr === "data-attr") && value.path.length === 1 && value.path[0] === "id") {
138
139
  const targetType = target.kind === "app"
139
140
  ? "elementum_app"
140
141
  : target.kind === "element"
141
142
  ? "elementum_element"
142
143
  : target.kind === "table"
143
144
  ? "elementum_table"
144
- : undefined;
145
+ : target.kind === "task"
146
+ ? "elementum_task"
147
+ : undefined;
145
148
  if (value.type === RELATIONSHIP_RESOURCE_TYPE || value.type === targetType) {
146
149
  return { kind: "recordIdentity", key: "id", name: "Record ID", target };
147
150
  }
@@ -91,7 +91,9 @@ function resolveTarget(value, where, opts) {
91
91
  ? "element"
92
92
  : value?.__kind === "table"
93
93
  ? "table"
94
- : "app";
94
+ : value?.__kind === "task"
95
+ ? "task"
96
+ : "app";
95
97
  const refName = value?.refName ?? "";
96
98
  if (kind === opts.scope && refName === opts.ownerRefName) {
97
99
  return {
@@ -106,7 +108,11 @@ function resolveTarget(value, where, opts) {
106
108
  const sibling = opts.workspaceAspects?.get(workspaceAspectKey(kind, refName));
107
109
  if (sibling !== undefined) {
108
110
  return {
109
- value: expr.resourceAttr(kind === "app" ? "elementum_app" : "elementum_element", sibling.tfLabel, ["id"]),
111
+ value: expr.resourceAttr(kind === "app"
112
+ ? "elementum_app"
113
+ : kind === "element"
114
+ ? "elementum_element"
115
+ : "elementum_task", sibling.tfLabel, ["id"]),
110
116
  kind,
111
117
  refName,
112
118
  tfLabel: sibling.tfLabel,
@@ -159,6 +165,7 @@ function resolveRelatedField(value, target, where, opts) {
159
165
  }
160
166
  if (target.managed &&
161
167
  target.kind !== "table" &&
168
+ target.kind !== "task" &&
162
169
  target.tfLabel !== undefined) {
163
170
  const direct = fieldRefToTfValue(value?.fieldType ?? "", refName, target.tfLabel, target.kind);
164
171
  if (direct !== undefined)
@@ -169,7 +176,9 @@ function resolveRelatedField(value, target, where, opts) {
169
176
  ? "elementum_app"
170
177
  : target.kind === "element"
171
178
  ? "elementum_element"
172
- : "elementum_table";
179
+ : target.kind === "task"
180
+ ? "elementum_task"
181
+ : "elementum_table";
173
182
  const label = sanitizeName(`${targetResourceType}_${target.tfLabel ?? target.refName}_${name}`);
174
183
  opts.orgRefs.foreignField("elementum_field", label, target.value, name);
175
184
  return expr.dataAttr("elementum_field", label, ["id"]);
@@ -4,9 +4,9 @@ import type { FromTfContext } from "../../engine/pull/context.js";
4
4
  * lookups are intentionally namespace-only, so fall back through the
5
5
  * recursive pull's namespace -> refName and display-name -> refName maps.
6
6
  */
7
- export declare function dataAspectDisplayName(ctx: FromTfContext, kind: "app" | "element", label: string): string | undefined;
7
+ export declare function dataAspectDisplayName(ctx: FromTfContext, kind: "app" | "element" | "task", label: string): string | undefined;
8
8
  /** Resolve the stable pulled catalog key for the same foreign lookup. */
9
- export declare function dataAspectRefName(ctx: FromTfContext, kind: "app" | "element", label: string, displayName?: string): string | undefined;
9
+ export declare function dataAspectRefName(ctx: FromTfContext, kind: "app" | "element" | "task", label: string, displayName?: string): string | undefined;
10
10
  export interface ResolvedAspectTarget {
11
11
  readonly key: string;
12
12
  readonly name: string;
@@ -21,4 +21,4 @@ export interface ResolvedAspectTarget {
21
21
  * the real namespace still attached) when it wasn't - never a bare guessed
22
22
  * name with no namespace, which matches nothing on the platform.
23
23
  */
24
- export declare function resolveDataAspectTarget(ctx: FromTfContext, kind: "app" | "element", dataLabel: string): ResolvedAspectTarget;
24
+ export declare function resolveDataAspectTarget(ctx: FromTfContext, kind: "app" | "element" | "task", dataLabel: string): ResolvedAspectTarget;
@@ -5,7 +5,7 @@ import { tfLabelToTsLabel } from "../../engine/tf/index.js";
5
5
  * recursive pull's namespace -> refName and display-name -> refName maps.
6
6
  */
7
7
  export function dataAspectDisplayName(ctx, kind, label) {
8
- const type = kind === "app" ? "elementum_app" : "elementum_element";
8
+ const type = kind === "app" ? "elementum_app" : kind === "element" ? "elementum_element" : "elementum_task";
9
9
  const direct = ctx.dataName(type, label);
10
10
  if (direct !== undefined)
11
11
  return direct;
@@ -17,25 +17,29 @@ export function dataAspectDisplayName(ctx, kind, label) {
17
17
  return undefined;
18
18
  const refName = kind === "app"
19
19
  ? ctx.foreignAppRefNamespaces?.get(namespace)
20
- : ctx.foreignElementRefNamespaces?.get(namespace);
20
+ : kind === "element"
21
+ ? ctx.foreignElementRefNamespaces?.get(namespace)
22
+ : undefined;
21
23
  if (refName === undefined)
22
24
  return undefined;
23
- const names = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
25
+ const names = kind === "app" ? ctx.foreignAppRefNames : kind === "element" ? ctx.foreignElementRefNames : undefined;
24
26
  return [...(names?.entries() ?? [])].find(([, candidateRefName]) => candidateRefName === refName)?.[0];
25
27
  }
26
28
  /** Resolve the stable pulled catalog key for the same foreign lookup. */
27
29
  export function dataAspectRefName(ctx, kind, label, displayName) {
30
+ if (kind === "task")
31
+ return tfLabelToTsLabel(label);
28
32
  const type = kind === "app" ? "elementum_app" : "elementum_element";
29
33
  const attrs = ctx.dataAttrs?.(type, label);
30
34
  const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
31
- const byNamespace = kind === "app" ? ctx.foreignAppRefNamespaces : ctx.foreignElementRefNamespaces;
35
+ const byNamespace = kind === "app" ? ctx.foreignAppRefNamespaces : kind === "element" ? ctx.foreignElementRefNamespaces : undefined;
32
36
  if (namespace !== undefined) {
33
37
  const refName = byNamespace?.get(namespace);
34
38
  if (refName !== undefined)
35
39
  return refName;
36
40
  }
37
41
  const name = displayName ?? dataAspectDisplayName(ctx, kind, label);
38
- const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
42
+ const byName = kind === "app" ? ctx.foreignAppRefNames : kind === "element" ? ctx.foreignElementRefNames : undefined;
39
43
  return name === undefined ? undefined : byName?.get(name);
40
44
  }
41
45
  /**
@@ -46,7 +50,7 @@ export function dataAspectRefName(ctx, kind, label, displayName) {
46
50
  * name with no namespace, which matches nothing on the platform.
47
51
  */
48
52
  export function resolveDataAspectTarget(ctx, kind, dataLabel) {
49
- const type = kind === "app" ? "elementum_app" : "elementum_element";
53
+ const type = kind === "app" ? "elementum_app" : kind === "element" ? "elementum_element" : "elementum_task";
50
54
  const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
51
55
  const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
52
56
  const attrs = ctx.dataAttrs?.(type, dataLabel);