@elementumai/edk 0.11.0 → 0.12.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.
Files changed (72) hide show
  1. package/README.md +38 -6
  2. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  3. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  7. package/dist-sdk/src/engine/ei/run.js +102 -14
  8. package/dist-sdk/src/engine/pull/ref-only.d.ts +18 -0
  9. package/dist-sdk/src/engine/pull/ref-only.js +52 -0
  10. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +2 -1
  11. package/dist-sdk/src/entities/access-policy/from-tf.js +7 -1
  12. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  13. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  14. package/dist-sdk/src/entities/app/build.js +79 -4
  15. package/dist-sdk/src/entities/app/from-tf.js +1 -2
  16. package/dist-sdk/src/entities/app/stage-keys.d.ts +18 -3
  17. package/dist-sdk/src/entities/app/stage-keys.js +40 -6
  18. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  19. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  20. package/dist-sdk/src/entities/automation/build.js +16 -6
  21. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +32 -3
  22. package/dist-sdk/src/entities/automation/from-tf.d.ts +13 -2
  23. package/dist-sdk/src/entities/automation/from-tf.js +269 -63
  24. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  25. package/dist-sdk/src/entities/automation/module.js +1 -1
  26. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  27. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  28. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  29. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  30. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  31. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  32. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +1 -1
  33. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -1
  34. package/dist-sdk/src/entities/automation/tasks.d.ts +47 -14
  35. package/dist-sdk/src/entities/automation/tasks.js +18 -4
  36. package/dist-sdk/src/entities/automation/to-tf.js +256 -28
  37. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -15
  38. package/dist-sdk/src/entities/automation/triggers.js +9 -9
  39. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  40. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  41. package/dist-sdk/src/entities/chart/from-tf.js +25 -1
  42. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  43. package/dist-sdk/src/entities/chart/printer.js +5 -2
  44. package/dist-sdk/src/entities/chart/to-tf.js +19 -1
  45. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +1 -0
  46. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  47. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  48. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +1 -1
  49. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  50. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  51. package/dist-sdk/src/entities/field/module.js +8 -2
  52. package/dist-sdk/src/entities/field/to-tf.d.ts +8 -2
  53. package/dist-sdk/src/entities/field/to-tf.js +57 -34
  54. package/dist-sdk/src/entities/org/role.js +5 -0
  55. package/dist-sdk/src/entities/service-account/module.js +5 -0
  56. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  57. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  58. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  59. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  60. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  61. package/dist-sdk/src/entities/skill/module.js +2 -0
  62. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  63. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  64. package/dist-sdk/src/entities/view/from-tf.js +3 -5
  65. package/dist-sdk/src/entities/view/module.js +5 -0
  66. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  67. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +5 -3
  68. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  69. package/dist-sdk/src/graph/index.d.ts +15 -2
  70. package/dist-sdk/src/graph/index.js +12 -0
  71. package/dist-sdk/src/graph/types.d.ts +38 -0
  72. package/package.json +1 -1
@@ -31,8 +31,12 @@ export interface RecordTriggerOptions<A extends AppOrElementRef = AppOrElementRe
31
31
  /** Restrict to fire only when one of these fields changes. */
32
32
  readonly changedFields?: readonly FieldRef[];
33
33
  readonly thinkUi?: boolean;
34
- /** Pre-built wire `Filter` (may embed `FieldRef` tokens — resolved at deploy). */
35
- readonly filter?: Filter;
34
+ /**
35
+ * Pre-built wire `Filter` (may embed `FieldRef` tokens — resolved at deploy).
36
+ * Trigger condition. Leaving it out and `null` mean the same thing: no condition.
37
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
38
+ */
39
+ readonly filter?: Filter | null;
36
40
  }
37
41
  /** Fires when a record is created on the given aspect. */
38
42
  export declare function recordCreated<A extends AppOrElementRef>(opts: RecordTriggerOptions<A>): TriggerChain<RecordTriggerOutput<A>>;
@@ -114,8 +118,12 @@ export interface TemporalTriggerOptions<A extends AppOrElementRef = AppOrElement
114
118
  readonly field: FieldRef;
115
119
  readonly temporalUnit: TemporalUnit;
116
120
  readonly value: number;
117
- /** Pre-built wire `Filter` (may embed `FieldRef` tokens — resolved at deploy). */
118
- readonly filter?: Filter;
121
+ /**
122
+ * Pre-built wire `Filter` (may embed `FieldRef` tokens — resolved at deploy).
123
+ * Trigger condition. Leaving it out and `null` mean the same thing: no condition.
124
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
125
+ */
126
+ readonly filter?: Filter | null;
119
127
  }
120
128
  /** Fires relative to a date/datetime field on records in the given aspect. */
121
129
  export declare function temporal<A extends AppOrElementRef>(opts: TemporalTriggerOptions<A>): TriggerChain<RecordTriggerOutput<A>>;
@@ -134,14 +142,22 @@ export interface approvalProcessStatusUpdatedTriggerOptions<A extends AppOrEleme
134
142
  */
135
143
  readonly approvalChain?: ApprovalChainRef | UnsafePlatformId;
136
144
  readonly status: approvalProcessStatusUpdatedStatus;
137
- /** Record filter the approval-chain trigger additionally requires. */
138
- readonly filter?: Filter;
145
+ /**
146
+ * Record filter the approval-chain trigger additionally requires.
147
+ * Trigger condition. Leaving it out and `null` mean the same thing: no condition.
148
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
149
+ */
150
+ readonly filter?: Filter | null;
139
151
  }
140
152
  /** Fires when an approval chain on a record changes to the configured status. */
141
153
  export declare function approvalProcessStatusUpdated<A extends AppOrElementRef>(opts: approvalProcessStatusUpdatedTriggerOptions<A>): TriggerChain<RecordTriggerOutput<A>>;
142
154
  export interface AttachmentTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
143
155
  readonly app: A;
144
- readonly filter?: Filter;
156
+ /**
157
+ * Trigger condition. Leaving it out and `null` mean the same thing: no condition.
158
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
159
+ */
160
+ readonly filter?: Filter | null;
145
161
  readonly thinkUi?: boolean;
146
162
  }
147
163
  export interface AttachmentTriggerOutput<A extends AppOrElementRef = AppOrElementRef> {
@@ -168,10 +184,11 @@ export interface DataMineTriggerOptions {
168
184
  readonly fireOnRecovery?: boolean;
169
185
  /**
170
186
  * Trigger Condition: the datamine's records must also match it (edk#2287).
171
- * Column references must be columns of the datamine's own table. Leaving it
172
- * out means no condition, the same as the platform's `filter: null`.
187
+ * Column references must be columns of the datamine's own table.
188
+ * Leaving it out and `null` mean the same thing: no condition.
189
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
173
190
  */
174
- readonly filter?: Filter;
191
+ readonly filter?: Filter | null;
175
192
  }
176
193
  export interface DataMineTriggerOutput {
177
194
  readonly record: Record<string, unknown>;
@@ -196,9 +213,17 @@ export interface EmailReceivedTriggerOutput {
196
213
  export declare function emailReceived(opts: EmailReceivedTriggerOptions): TriggerChain<EmailReceivedTriggerOutput>;
197
214
  export interface CommentAddedTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
198
215
  readonly app: A;
199
- /** Conversation type the comment was added to (e.g. `"INTERNAL"`). */
216
+ /**
217
+ * Conversation type the comment was added to: `"status"` (status update comments) or
218
+ * `"general"` (general comments). Write it lowercase: pull writes it back lowercase, so
219
+ * any other spelling shows a change on the plan after the next pull.
220
+ */
200
221
  readonly conversationType: string;
201
- readonly filter?: Filter;
222
+ /**
223
+ * Trigger condition. Leaving it out and `null` mean the same thing: no condition.
224
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
225
+ */
226
+ readonly filter?: Filter | null;
202
227
  }
203
228
  export interface CommentAddedTriggerOutput<A extends AppOrElementRef = AppOrElementRef> {
204
229
  readonly record: RecordShape<A>;
@@ -211,7 +236,11 @@ export type ConversationEndConversationType = "A2A" | "ELEMENTUM_UI" | "VOICE" |
211
236
  export interface ConversationEndTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
212
237
  readonly app: A;
213
238
  readonly conversationType: ConversationEndConversationType;
214
- readonly filter?: Filter;
239
+ /**
240
+ * Trigger condition. Leaving it out and `null` mean the same thing: no condition.
241
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
242
+ */
243
+ readonly filter?: Filter | null;
215
244
  }
216
245
  export interface ConversationEndTriggerOutput<A extends AppOrElementRef = AppOrElementRef> {
217
246
  readonly record: RecordShape<A>;
@@ -249,8 +278,12 @@ export interface SurveyResponseCreateTriggerOptions {
249
278
  * explicit wrapper marks this platform-owned value as non-portable.
250
279
  */
251
280
  readonly survey: UnsafePlatformId;
252
- /** Trigger Condition: the record the survey was completed for must match it (edk#2206). */
253
- readonly filter?: Filter;
281
+ /**
282
+ * Trigger Condition: the record the survey was completed for must match it (edk#2206).
283
+ * Leaving it out and `null` mean the same thing: no condition.
284
+ * On update, either one removes a condition the trigger had (apply sends `filter: null`).
285
+ */
286
+ readonly filter?: Filter | null;
254
287
  }
255
288
  export type SurveyResponseCreateTriggerOutput = Record<string, unknown>;
256
289
  /** Fires when a response is created for the selected survey template. */
@@ -6,7 +6,7 @@ function recordTriggerFields(opts) {
6
6
  aspectId: opts.app, // token → aspect id at deploy
7
7
  ...(opts.changedFields !== undefined ? { changedFieldIds: opts.changedFields } : {}),
8
8
  ...(opts.thinkUi !== undefined ? { thinkUi: opts.thinkUi } : {}),
9
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
9
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
10
10
  };
11
11
  }
12
12
  /** Fires when a record is created on the given aspect. */
@@ -105,7 +105,7 @@ export function temporal(opts) {
105
105
  aspectFieldId: opts.field,
106
106
  temporalUnit: opts.temporalUnit,
107
107
  value: opts.value,
108
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
108
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
109
109
  type: "TEMPORAL",
110
110
  },
111
111
  },
@@ -120,7 +120,7 @@ export function approvalProcessStatusUpdated(opts) {
120
120
  aspectId: opts.app,
121
121
  ...(opts.approvalChain !== undefined ? { approvalChainTemplateId: opts.approvalChain } : {}),
122
122
  status: opts.status,
123
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
123
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
124
124
  type: "APPROVAL_CHAIN_UPDATE",
125
125
  },
126
126
  },
@@ -134,7 +134,7 @@ export function attachment(opts) {
134
134
  attachment: {
135
135
  aspectId: opts.app,
136
136
  type: "ATTACHMENT_UPDATE",
137
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
137
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
138
138
  ...(opts.thinkUi !== undefined ? { thinkUi: opts.thinkUi } : {}),
139
139
  },
140
140
  },
@@ -177,7 +177,7 @@ function assertDataMineFilterOnDatamineTable(datamine, condition) {
177
177
  }
178
178
  /** Fires when a data mine meets/no longer meets requirements. */
179
179
  export function dataMine(opts) {
180
- if (opts.filter !== undefined)
180
+ if (opts.filter !== undefined && opts.filter !== null)
181
181
  assertDataMineFilterOnDatamineTable(opts.datamine, opts.filter);
182
182
  return chainableTrigger({
183
183
  wire: {
@@ -186,7 +186,7 @@ export function dataMine(opts) {
186
186
  type: "DATAMINE",
187
187
  ...(opts.fireOnAlert !== undefined ? { fireOnAlert: opts.fireOnAlert } : {}),
188
188
  ...(opts.fireOnRecovery !== undefined ? { fireOnRecovery: opts.fireOnRecovery } : {}),
189
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
189
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
190
190
  },
191
191
  },
192
192
  });
@@ -209,7 +209,7 @@ export function commentAdded(opts) {
209
209
  commentAdded: {
210
210
  aspectId: opts.app,
211
211
  conversationType: opts.conversationType,
212
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
212
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
213
213
  },
214
214
  },
215
215
  __recordApp: opts.app.refName,
@@ -223,7 +223,7 @@ export function conversationEnd(opts) {
223
223
  aspectId: opts.app,
224
224
  conversationType: opts.conversationType,
225
225
  type: "CONVERSATION_END",
226
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
226
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
227
227
  },
228
228
  },
229
229
  __recordApp: opts.app.refName,
@@ -246,7 +246,7 @@ export function surveyResponseCreate(opts) {
246
246
  survey: {
247
247
  aspectId: opts.app,
248
248
  surveyTemplateId: opts.survey,
249
- ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
249
+ ...(opts.filter !== undefined && opts.filter !== null ? { filter: opts.filter } : {}),
250
250
  type: "SURVEY_RESPONSE_CREATE",
251
251
  },
252
252
  },
@@ -64,6 +64,14 @@ export declare function chartJoin<const From extends ChartDatasourceRef, const T
64
64
  readonly datasource: To;
65
65
  readonly type?: ChartJoinType;
66
66
  } & ChartJoinSides<NoInfer<From>, NoInfer<To>>): ChartJoin<From, To>;
67
+ /**
68
+ * A subscription's row limit: at most `count` rows, after skipping `offset`
69
+ * rows (default 0). The platform stores it as `{count, offset}` (#2291).
70
+ */
71
+ export interface ChartSubscriptionLimit {
72
+ readonly count: number;
73
+ readonly offset?: number;
74
+ }
67
75
  declare const chartSubscriptionBrand: unique symbol;
68
76
  export interface ChartSubscription<Datasource extends ChartDatasourceRef = ChartDatasourceRef> {
69
77
  readonly [chartSubscriptionBrand]: Datasource;
@@ -72,7 +80,7 @@ export interface ChartSubscription<Datasource extends ChartDatasourceRef = Chart
72
80
  readonly groupBy?: readonly ChartGroupBy<Datasource>[];
73
81
  readonly joins?: readonly ChartJoin<Datasource, ChartDatasourceRef>[];
74
82
  readonly filter?: Filter<ChartFieldFor<Datasource>, never>;
75
- readonly limit?: string;
83
+ readonly limit?: ChartSubscriptionLimit;
76
84
  readonly tags?: readonly string[];
77
85
  }
78
86
  export type ChartSubscriptionInput = ChartSubscription | ChartOpaqueSubscription;
@@ -1,7 +1,7 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
2
  import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
- import type { ChartProperties } from "./build.js";
4
+ import type { ChartProperties, ChartSubscriptionLimit } from "./build.js";
5
5
  export interface NormalizedChartDatasource {
6
6
  readonly kind: "app" | "element" | "table" | "task";
7
7
  readonly refName: string;
@@ -39,7 +39,7 @@ export interface NormalizedChartSubscription {
39
39
  readonly groupBy?: readonly NormalizedChartGroupBy[];
40
40
  readonly joins?: readonly NormalizedChartJoin[];
41
41
  readonly filter?: Filter<NormalizedChartField, never>;
42
- readonly limit?: string;
42
+ readonly limit?: ChartSubscriptionLimit;
43
43
  readonly tags?: readonly string[];
44
44
  }
45
45
  export interface NormalizedChartOpaqueSubscription {
@@ -213,6 +213,22 @@ function opaqueSubscriptionFromTf(value, where, ctx) {
213
213
  ctx.diagnostics.push(`${where}: preserved UI chart synthetic datasource as an opaque pull-only subscription`);
214
214
  return { kind: "opaque", datasourceId, attributes };
215
215
  }
216
+ /** The platform's Limit scalar, exported as `limit = { count, offset }` (#2291). */
217
+ function limitFromTf(value) {
218
+ const rec = plainObject(value);
219
+ if (rec === undefined)
220
+ return undefined;
221
+ const isCount = (item) => typeof item === "number" && Number.isSafeInteger(item) && item >= 0;
222
+ if (Object.keys(rec).some((key) => key !== "count" && key !== "offset"))
223
+ return undefined;
224
+ const count = rec["count"];
225
+ const offset = rec["offset"];
226
+ if (!isCount(count))
227
+ return undefined;
228
+ if (offset !== undefined && offset !== null && !isCount(offset))
229
+ return undefined;
230
+ return { count, ...(isCount(offset) ? { offset } : {}) };
231
+ }
216
232
  function parseSubscription(value, appLabel, appRefName, ctx, where) {
217
233
  const opaque = opaqueSubscriptionFromTf(value, where, ctx);
218
234
  if (opaque !== undefined)
@@ -320,12 +336,20 @@ function parseSubscription(value, appLabel, appRefName, ctx, where) {
320
336
  return undefined;
321
337
  }
322
338
  }
339
+ let limit;
340
+ if (rec["limit"] !== undefined && rec["limit"] !== null) {
341
+ limit = limitFromTf(rec["limit"]);
342
+ if (limit === undefined) {
343
+ ctx.diagnostics.push(`${where}.limit: expected { count, offset } with non-negative integers; subscription skipped`);
344
+ return undefined;
345
+ }
346
+ }
323
347
  return {
324
348
  datasource, columns,
325
349
  ...(groupBy !== undefined ? { groupBy } : {}),
326
350
  ...(joins !== undefined ? { joins } : {}),
327
351
  ...(filter !== undefined ? { filter } : {}),
328
- ...(typeof rec["limit"] === "string" ? { limit: rec["limit"] } : {}),
352
+ ...(limit !== undefined ? { limit } : {}),
329
353
  ...(stringList(rec["tags"]) !== undefined ? { tags: stringList(rec["tags"]) } : {}),
330
354
  };
331
355
  }
@@ -1,4 +1,4 @@
1
- export { chartAggregation, chartColumnValueType, chartJoin, chartJoinType, chartSubscription, chartType, __pulledChartSubscription, defineChart, type ChartAggregation, type ChartColumn, type ChartColumnValueType, type ChartConfigured, type ChartDatasourceRef, type ChartFieldFor, type ChartGroupBy, type ChartJoin, type ChartJoinType, type ChartOpaqueSubscription, type ChartSubscriptionInput, type ChartProperties, type ChartSubscription, type ChartType, type DefineChartOptions, } from "./build.js";
1
+ export { chartAggregation, chartColumnValueType, chartJoin, chartJoinType, chartSubscription, chartType, __pulledChartSubscription, defineChart, type ChartAggregation, type ChartColumn, type ChartColumnValueType, type ChartConfigured, type ChartDatasourceRef, type ChartFieldFor, type ChartGroupBy, type ChartJoin, type ChartJoinType, type ChartOpaqueSubscription, type ChartSubscriptionInput, type ChartProperties, type ChartSubscription, type ChartSubscriptionLimit, type ChartType, type DefineChartOptions, } from "./build.js";
2
2
  export { dashboardChartWidget, dashboardRecordsWidget, dashboardWidgetSize, type DashboardChartWidget, type DashboardWidgetSize, } from "../dashboard/build.js";
3
3
  export * as filter from "../shared/filters/index.js";
4
4
  export { type Filter } from "../shared/filters/index.js";
@@ -77,8 +77,11 @@ function printSubscription(subscription, keys) {
77
77
  reference: () => { throw new Error("chart pull: filter references are unsupported"); },
78
78
  })},`);
79
79
  }
80
- if (subscription.limit !== undefined)
81
- lines.push(` limit: ${quote(subscription.limit)},`);
80
+ if (subscription.limit !== undefined) {
81
+ // offset 0 is the default, so the source leaves it out.
82
+ const offset = subscription.limit.offset ?? 0;
83
+ lines.push(` limit: { count: ${subscription.limit.count}${offset !== 0 ? `, offset: ${offset}` : ""} },`);
84
+ }
82
85
  if (subscription.tags !== undefined)
83
86
  lines.push(` tags: ${JSON.stringify(subscription.tags)},`);
84
87
  lines.push(" }),");
@@ -166,11 +166,29 @@ function subscriptionToTf(subscription, opts, where) {
166
166
  if (subscription.filter !== undefined)
167
167
  out["filter"] = filterToTf(subscription.filter, datasource, opts, `${where}.filter`);
168
168
  if (subscription.limit !== undefined)
169
- out["limit"] = subscription.limit;
169
+ out["limit"] = limitToTf(subscription.limit, `${where}.limit`);
170
170
  if (subscription.tags !== undefined && subscription.tags.length > 0)
171
171
  out["tags"] = [...subscription.tags];
172
172
  return out;
173
173
  }
174
+ function nonNegativeInteger(value) {
175
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
176
+ }
177
+ /**
178
+ * The platform's Limit scalar is {count, offset}; offset is written even when
179
+ * it is the default 0 so build matches what export writes (#2291).
180
+ */
181
+ function limitToTf(limit, where) {
182
+ if (limit === null || typeof limit !== "object" || Array.isArray(limit)) {
183
+ throw new EntityTfError(`${where}: limit must be { count, offset? }`);
184
+ }
185
+ if (!nonNegativeInteger(limit.count))
186
+ throw new EntityTfError(`${where}.count: must be a non-negative integer`);
187
+ if (limit.offset !== undefined && !nonNegativeInteger(limit.offset)) {
188
+ throw new EntityTfError(`${where}.offset: must be a non-negative integer`);
189
+ }
190
+ return { count: limit.count, offset: limit.offset ?? 0 };
191
+ }
174
192
  function hasSameAppChartWidget(entity, root) {
175
193
  const payload = root.payload;
176
194
  if (payload?.dashboards === undefined)
@@ -325,6 +325,7 @@ export interface AppDynamicLayout {
325
325
  readonly updatedAt?: string;
326
326
  readonly createdBy?: string;
327
327
  readonly description?: string;
328
+ readonly explicitUpdateBlock?: boolean;
328
329
  };
329
330
  }
330
331
  /** Element-owned DASHBOARD layout. Elements have no stages, so it is always the element's default layout. */
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Restore a dynamic layout's authored condition keys on a re-pull (#2414).
3
+ *
4
+ * The platform stores a layout's conditions without their keys, so the export
5
+ * names them `condition_0001`, `condition_0002`, … in document order. State
6
+ * still holds the authored keys (`hasValidationMessage`), and every reference
7
+ * to them — a component's `show_when`, `hide_when`, `enable_when`,
8
+ * `disable_when` and `require_when`, a condition's `all`, `any` and `not`, a
9
+ * dependency's `condition` — would then differ from state, so adoption plans
10
+ * an update.
11
+ *
12
+ * Same pairing the provider applies on its own reads
13
+ * (`preserveDynamicLayoutConditionIDs`): by position from each component and
14
+ * dependency both sides share, following `all`/`any`/`not` children, and only
15
+ * when the two conditions have the same content; then any condition left
16
+ * whose content is unique in state. Several exported conditions can pair with
17
+ * one state key: the platform returns a condition referenced from several
18
+ * places (`all`, `not`, a component) as separate copies, and the rename
19
+ * collapses them back into the one authored condition, as the provider's read
20
+ * does. Content is compared with every referenced
21
+ * condition replaced by its own content, and every reference in the export
22
+ * (`elementum_text_field.x.id`, `data.elementum_role.y.id`, a stage's
23
+ * `local.<app>_stage_ids_by_key["<key>"]`, an option's
24
+ * `local.<field>_options_by_label["<label>"]`) replaced by the value state
25
+ * holds for it. A condition that cannot be compared keeps its exported key.
26
+ *
27
+ * Registered as the dynamic layout's `alignWithState` (module.ts), which
28
+ * `alignExportWithState` runs on a re-pull.
29
+ */
30
+ import type { StateAlignment } from "../../graph/index.js";
31
+ type Plain = null | string | number | boolean | Plain[] | {
32
+ [key: string]: Plain;
33
+ };
34
+ interface LayoutSide {
35
+ readonly conditions: Readonly<Record<string, unknown>>;
36
+ readonly components: Readonly<Record<string, unknown>>;
37
+ readonly dependencies: readonly unknown[];
38
+ /** Plain value of a field reference on this side, or undefined when it cannot be resolved. */
39
+ readonly plain: (value: unknown) => Plain | undefined;
40
+ }
41
+ /** Export condition key → state condition key, the provider's `preserveDynamicLayoutConditionIDs` pairing. */
42
+ export declare function pairLayoutConditions(exported: LayoutSide, state: LayoutSide): Map<string, string>;
43
+ /**
44
+ * The exported layout's attributes with its condition keys restored from the
45
+ * layout's state attributes, or the same object when nothing pairs.
46
+ */
47
+ export declare const restoreLayoutConditionKeys: StateAlignment;
48
+ export {};
@@ -0,0 +1,261 @@
1
+ import { isTfExpr } from "../../engine/tf/model.js";
2
+ const COMPONENT_REFERENCE_LISTS = ["show_when", "hide_when", "enable_when", "disable_when", "require_when"];
3
+ const GROUP_KINDS = ["all", "any"];
4
+ function asMap(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isTfExpr(value)
6
+ ? value
7
+ : undefined;
8
+ }
9
+ function stringList(value) {
10
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
11
+ }
12
+ /**
13
+ * Plain data with nulls dropped and keys sorted, or undefined when a value
14
+ * cannot be resolved. Null and missing are the same value: state lists every
15
+ * optional attribute, the export only the ones it sets.
16
+ */
17
+ function plainValue(value, resolve) {
18
+ if (value === undefined || value === null)
19
+ return null;
20
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean")
21
+ return value;
22
+ if (Array.isArray(value)) {
23
+ const items = value.map((item) => plainValue(item, resolve));
24
+ return items.some((item) => item === undefined) ? undefined : items;
25
+ }
26
+ if (typeof value !== "object")
27
+ return undefined;
28
+ if (isTfExpr(value)) {
29
+ const resolved = resolve === undefined ? undefined : resolve(value);
30
+ return resolved === undefined ? undefined : plainValue(resolved, undefined);
31
+ }
32
+ const out = {};
33
+ for (const key of Object.keys(value).sort()) {
34
+ const child = plainValue(value[key], resolve);
35
+ if (child === undefined)
36
+ return undefined;
37
+ if (child !== null)
38
+ out[key] = child;
39
+ }
40
+ return out;
41
+ }
42
+ /** {@link conditionFingerprint} in the provider: the condition's content with every referenced condition replaced by its fingerprint. */
43
+ function fingerprint(side, id, visiting = new Set()) {
44
+ if (visiting.has(id))
45
+ return undefined;
46
+ const condition = side.conditions[id];
47
+ if (condition === undefined)
48
+ return undefined;
49
+ const normalized = side.plain(condition);
50
+ if (normalized === undefined || normalized === null || typeof normalized !== "object" || Array.isArray(normalized))
51
+ return undefined;
52
+ visiting.add(id);
53
+ try {
54
+ const next = { ...normalized };
55
+ for (const kind of GROUP_KINDS) {
56
+ const group = asMap(next[kind]);
57
+ if (group === undefined)
58
+ continue;
59
+ const refs = Array.isArray(group["conditions"]) ? group["conditions"] : [];
60
+ const children = [];
61
+ for (const ref of refs) {
62
+ const child = typeof ref === "string" ? fingerprint(side, ref, visiting) : undefined;
63
+ if (child === undefined)
64
+ return undefined;
65
+ children.push(child);
66
+ }
67
+ next[kind] = { ...group, conditions: children };
68
+ }
69
+ const negation = asMap(next["not"]);
70
+ if (negation !== undefined) {
71
+ const child = typeof negation["condition"] === "string" ? fingerprint(side, negation["condition"], visiting) : undefined;
72
+ if (child === undefined)
73
+ return undefined;
74
+ next["not"] = { ...negation, condition: child };
75
+ }
76
+ return JSON.stringify(next);
77
+ }
78
+ finally {
79
+ visiting.delete(id);
80
+ }
81
+ }
82
+ /** Export condition key → state condition key, the provider's `preserveDynamicLayoutConditionIDs` pairing. */
83
+ export function pairLayoutConditions(exported, state) {
84
+ const renames = new Map();
85
+ const pair = (exportedId, stateId) => {
86
+ if (renames.has(exportedId))
87
+ return;
88
+ const left = fingerprint(exported, exportedId);
89
+ if (left === undefined || left !== fingerprint(state, stateId))
90
+ return;
91
+ renames.set(exportedId, stateId);
92
+ const exportedCondition = asMap(exported.conditions[exportedId]) ?? {};
93
+ const stateCondition = asMap(state.conditions[stateId]) ?? {};
94
+ for (const kind of GROUP_KINDS) {
95
+ const exportedGroup = asMap(exportedCondition[kind]);
96
+ const stateGroup = asMap(stateCondition[kind]);
97
+ if (exportedGroup !== undefined && stateGroup !== undefined)
98
+ pairLists(stringList(exportedGroup["conditions"]), stringList(stateGroup["conditions"]));
99
+ }
100
+ const exportedNot = asMap(exportedCondition["not"])?.["condition"];
101
+ const stateNot = asMap(stateCondition["not"])?.["condition"];
102
+ if (typeof exportedNot === "string" && typeof stateNot === "string")
103
+ pair(exportedNot, stateNot);
104
+ };
105
+ const pairLists = (exportedRefs, stateRefs) => {
106
+ for (let i = 0; i < exportedRefs.length && i < stateRefs.length; i++)
107
+ pair(exportedRefs[i], stateRefs[i]);
108
+ };
109
+ for (const componentId of Object.keys(exported.components).sort()) {
110
+ const exportedComponent = asMap(exported.components[componentId]);
111
+ const stateComponent = asMap(state.components[componentId]);
112
+ if (exportedComponent === undefined || stateComponent === undefined)
113
+ continue;
114
+ for (const list of COMPONENT_REFERENCE_LISTS)
115
+ pairLists(stringList(exportedComponent[list]), stringList(stateComponent[list]));
116
+ }
117
+ for (let i = 0; i < exported.dependencies.length && i < state.dependencies.length; i++) {
118
+ const exportedDependency = asMap(exported.dependencies[i]);
119
+ const stateDependency = asMap(state.dependencies[i]);
120
+ if (exportedDependency === undefined || stateDependency === undefined)
121
+ continue;
122
+ const same = ["source_field_id", "target_field_id", "type"].every((key) => {
123
+ const left = exported.plain(exportedDependency[key]);
124
+ return left !== undefined && JSON.stringify(left) === JSON.stringify(state.plain(stateDependency[key]));
125
+ });
126
+ const exportedRef = exportedDependency["condition"];
127
+ const stateRef = stateDependency["condition"];
128
+ if (same && typeof exportedRef === "string" && typeof stateRef === "string")
129
+ pair(exportedRef, stateRef);
130
+ }
131
+ // Every valid condition is reachable from a component or dependency; this
132
+ // covers a remotely reordered graph. Only a fingerprint unique in state
133
+ // qualifies, so two authored conditions with equal content are never merged.
134
+ const stateByFingerprint = new Map();
135
+ for (const id of Object.keys(state.conditions).sort()) {
136
+ const print = fingerprint(state, id);
137
+ if (print !== undefined)
138
+ stateByFingerprint.set(print, [...(stateByFingerprint.get(print) ?? []), id]);
139
+ }
140
+ for (const id of Object.keys(exported.conditions).sort()) {
141
+ if (renames.has(id))
142
+ continue;
143
+ const print = fingerprint(exported, id);
144
+ const candidates = print === undefined ? undefined : stateByFingerprint.get(print);
145
+ if (candidates?.length === 1)
146
+ pair(id, candidates[0]);
147
+ }
148
+ // A rename onto a key the export keeps for another condition would merge
149
+ // the two. Dropping one rename can leave the key it vacated in use, which
150
+ // invalidates a rename onto that key in turn, so repeat until none drops.
151
+ for (let dropped = true; dropped;) {
152
+ dropped = false;
153
+ for (const [from, to] of [...renames]) {
154
+ if (from !== to && to in exported.conditions && !renames.has(to)) {
155
+ renames.delete(from);
156
+ dropped = true;
157
+ }
158
+ }
159
+ }
160
+ return renames;
161
+ }
162
+ function renameRef(value, renames) {
163
+ return typeof value === "string" ? (renames.get(value) ?? value) : value;
164
+ }
165
+ function renameList(value, renames) {
166
+ return Array.isArray(value) ? value.map((item) => renameRef(item, renames)) : value;
167
+ }
168
+ function withAttribute(map, key, value) {
169
+ return value === undefined ? map : { ...map, [key]: value };
170
+ }
171
+ /** JSON with object keys sorted, so two equal bodies print the same. */
172
+ function stableJson(value) {
173
+ if (Array.isArray(value))
174
+ return `[${value.map(stableJson).join(",")}]`;
175
+ if (typeof value === "object" && value !== null) {
176
+ const object = value;
177
+ return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${stableJson(object[key])}`).join(",")}}`;
178
+ }
179
+ return JSON.stringify(value) ?? "null";
180
+ }
181
+ /** The renamed conditions; copies of one authored condition collapse onto its key, anything else on one key is a bug. */
182
+ function collapseConditions(address, entries) {
183
+ const out = {};
184
+ const from = new Map();
185
+ for (const [exportedId, key, body] of entries) {
186
+ const earlier = from.get(key);
187
+ if (earlier !== undefined && stableJson(out[key]) !== stableJson(body)) {
188
+ throw new Error(`${address}: restoring authored condition keys from state would merge exported conditions "${earlier}" and "${exportedId}", ` +
189
+ `which differ, into "${key}". This is an EDK bug (edk#2414); please report it with the layout's state and export.`);
190
+ }
191
+ if (earlier === undefined)
192
+ from.set(key, exportedId);
193
+ out[key] = body;
194
+ }
195
+ return out;
196
+ }
197
+ /** The layout's attributes with every renamed condition key and reference rewritten. */
198
+ function renameConditions(address, attrs, renames) {
199
+ const next = { ...attrs };
200
+ const conditions = asMap(attrs["conditions"]);
201
+ if (conditions !== undefined) {
202
+ next["conditions"] = collapseConditions(address, Object.entries(conditions).map(([id, condition]) => {
203
+ let body = (asMap(condition) ?? {});
204
+ for (const kind of GROUP_KINDS) {
205
+ const group = asMap(body[kind]);
206
+ if (group !== undefined)
207
+ body = { ...body, [kind]: withAttribute(group, "conditions", renameList(group["conditions"], renames)) };
208
+ }
209
+ const negation = asMap(body["not"]);
210
+ if (negation !== undefined)
211
+ body = { ...body, not: withAttribute(negation, "condition", renameRef(negation["condition"], renames)) };
212
+ return [id, renames.get(id) ?? id, asMap(condition) === undefined ? condition : body];
213
+ }));
214
+ }
215
+ const components = asMap(attrs["components"]);
216
+ if (components !== undefined) {
217
+ next["components"] = Object.fromEntries(Object.entries(components).map(([id, component]) => {
218
+ const body = asMap(component);
219
+ if (body === undefined)
220
+ return [id, component];
221
+ let renamed = body;
222
+ for (const list of COMPONENT_REFERENCE_LISTS)
223
+ renamed = withAttribute(renamed, list, renameList(body[list], renames));
224
+ return [id, renamed];
225
+ }));
226
+ }
227
+ if (Array.isArray(attrs["dependencies"])) {
228
+ next["dependencies"] = attrs["dependencies"].map((dependency) => {
229
+ const body = asMap(dependency);
230
+ return body === undefined ? dependency : withAttribute(body, "condition", renameRef(body["condition"], renames));
231
+ });
232
+ }
233
+ return next;
234
+ }
235
+ /**
236
+ * The exported layout's attributes with its condition keys restored from the
237
+ * layout's state attributes, or the same object when nothing pairs.
238
+ */
239
+ export const restoreLayoutConditionKeys = (attrs, stateAttributes, { address, resolve }) => {
240
+ const exportedConditions = asMap(attrs["conditions"]);
241
+ const stateConditions = asMap(stateAttributes["conditions"]);
242
+ if (exportedConditions === undefined || stateConditions === undefined)
243
+ return attrs;
244
+ const exported = {
245
+ conditions: exportedConditions,
246
+ components: asMap(attrs["components"]) ?? {},
247
+ dependencies: Array.isArray(attrs["dependencies"]) ? attrs["dependencies"] : [],
248
+ plain: (value) => plainValue(value, resolve),
249
+ };
250
+ const state = {
251
+ conditions: stateConditions,
252
+ components: asMap(stateAttributes["components"]) ?? {},
253
+ dependencies: Array.isArray(stateAttributes["dependencies"]) ? stateAttributes["dependencies"] : [],
254
+ plain: (value) => plainValue(value, undefined),
255
+ };
256
+ const renames = pairLayoutConditions(exported, state);
257
+ for (const [from, to] of [...renames])
258
+ if (from === to)
259
+ renames.delete(from);
260
+ return renames.size === 0 ? attrs : renameConditions(address, attrs, renames);
261
+ };