@elementumai/edk 0.13.4 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-sdk/src/catalog/factories.d.ts +4 -2
- package/dist-sdk/src/catalog/factories.js +3 -1
- package/dist-sdk/src/catalog/from-authoring.d.ts +8 -3
- package/dist-sdk/src/catalog/from-authoring.js +21 -8
- package/dist-sdk/src/engine/build/context.d.ts +17 -0
- package/dist-sdk/src/engine/coverage-gaps.d.ts +10 -0
- package/dist-sdk/src/engine/coverage-gaps.js +16 -0
- package/dist-sdk/src/engine/pull/context.d.ts +56 -0
- package/dist-sdk/src/engine/pull/context.js +8 -0
- package/dist-sdk/src/engine/pull/pulled-roots.d.ts +14 -1
- package/dist-sdk/src/engine/pull/pulled-roots.js +23 -3
- package/dist-sdk/src/engine/pull/ref-only.d.ts +6 -1
- package/dist-sdk/src/engine/pull/ref-only.js +4 -1
- package/dist-sdk/src/engine/pull/stream-root.d.ts +13 -1
- package/dist-sdk/src/engine/pull/stream-root.js +54 -4
- package/dist-sdk/src/engine/validation.d.ts +36 -1
- package/dist-sdk/src/engine/validation.js +56 -2
- package/dist-sdk/src/engine/workspace/loader.d.ts +6 -0
- package/dist-sdk/src/engine/workspace/loader.js +87 -2
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +58 -17
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +3 -1
- package/dist-sdk/src/entities/access-policy/to-tf.js +1 -1
- package/dist-sdk/src/entities/agent/build.d.ts +15 -0
- package/dist-sdk/src/entities/agent/build.js +139 -16
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -3
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +39 -25
- package/dist-sdk/src/entities/agent/module.js +95 -3
- package/dist-sdk/src/entities/agent/to-tf.js +6 -4
- package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +7 -0
- package/dist-sdk/src/entities/agent-evaluation/from-tf.js +14 -5
- package/dist-sdk/src/entities/agent-evaluation/module.js +4 -2
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +11 -2
- package/dist-sdk/src/entities/agent-tool/from-tf.js +38 -40
- package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -5
- package/dist-sdk/src/entities/app/build.d.ts +1 -1
- package/dist-sdk/src/entities/automation/build.d.ts +75 -42
- package/dist-sdk/src/entities/automation/build.js +17 -7
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +14 -2
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +9 -0
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +57 -12
- package/dist-sdk/src/entities/automation/from-tf.d.ts +51 -0
- package/dist-sdk/src/entities/automation/from-tf.js +476 -93
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/index.js +1 -1
- package/dist-sdk/src/entities/automation/module.js +90 -9
- package/dist-sdk/src/entities/automation/operators.d.ts +6 -2
- package/dist-sdk/src/entities/automation/operators.js +0 -2
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +8 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +11 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +37 -2
- package/dist-sdk/src/entities/automation/tasks.js +38 -1
- package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
- package/dist-sdk/src/entities/automation/to-tf.js +413 -47
- package/dist-sdk/src/entities/chart/to-tf.js +18 -5
- package/dist-sdk/src/entities/dashboard/from-tf.js +45 -11
- package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +5 -3
- package/dist-sdk/src/entities/dashboard-widget-order/order.js +6 -4
- package/dist-sdk/src/entities/datamine/from-tf.js +10 -3
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +9 -2
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +35 -7
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +63 -7
- package/dist-sdk/src/entities/element/build.d.ts +4 -1
- package/dist-sdk/src/entities/element/build.js +3 -4
- package/dist-sdk/src/entities/field/from-tf.js +8 -1
- package/dist-sdk/src/entities/field/to-tf.d.ts +29 -2
- package/dist-sdk/src/entities/field/to-tf.js +106 -7
- package/dist-sdk/src/entities/phone-service/from-tf.d.ts +7 -0
- package/dist-sdk/src/entities/phone-service/from-tf.js +15 -7
- package/dist-sdk/src/entities/phone-service/module.js +4 -2
- package/dist-sdk/src/entities/portal/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/portal/to-tf.js +61 -2
- package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -1
- package/dist-sdk/src/entities/relationship/from-tf.js +34 -4
- package/dist-sdk/src/entities/relationship/to-tf.js +24 -6
- package/dist-sdk/src/entities/role/from-tf.js +3 -1
- package/dist-sdk/src/entities/search-table/from-tf.d.ts +3 -1
- package/dist-sdk/src/entities/search-table/from-tf.js +6 -3
- package/dist-sdk/src/entities/search-table/module.js +18 -2
- package/dist-sdk/src/entities/search-table/to-tf.js +10 -16
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +6 -1
- package/dist-sdk/src/entities/shared/filters/index.d.ts +6 -1
- package/dist-sdk/src/entities/shared/filters/index.js +8 -2
- package/dist-sdk/src/entities/shared/filters/print.js +18 -7
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +11 -0
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +24 -2
- package/dist-sdk/src/entities/shared/run-automation-requirement.d.ts +15 -0
- package/dist-sdk/src/entities/shared/run-automation-requirement.js +28 -0
- package/dist-sdk/src/entities/shared/search-table-address.d.ts +17 -0
- package/dist-sdk/src/entities/shared/search-table-address.js +24 -0
- package/dist-sdk/src/entities/shared/skip-release.d.ts +49 -0
- package/dist-sdk/src/entities/shared/skip-release.js +74 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -3
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +11 -5
- package/dist-sdk/src/entities/skill/module.js +3 -25
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +4 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -27
- package/dist-sdk/src/entities/skill-tool/to-tf.js +12 -5
- package/dist-sdk/src/entities/skill-tool/types.d.ts +1 -0
- package/dist-sdk/src/entities/skill-tool/types.js +2 -1
- package/dist-sdk/src/entities/table/catalog.d.ts +16 -0
- package/dist-sdk/src/entities/table/catalog.js +44 -2
- package/dist-sdk/src/entities/table/from-tf.js +30 -4
- package/dist-sdk/src/entities/table/keys.d.ts +27 -0
- package/dist-sdk/src/entities/table/keys.js +46 -0
- package/dist-sdk/src/entities/table/to-tf.js +2 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +12 -1
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +9 -4
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +215 -10
- package/dist-sdk/src/entities/view/agent-view-layout.d.ts +10 -4
- package/dist-sdk/src/entities/view/custom-view-runtime-rules.d.ts +43 -0
- package/dist-sdk/src/entities/view/custom-view-runtime-rules.js +285 -0
- package/dist-sdk/src/entities/view/custom-view-validate.d.ts +3 -1
- package/dist-sdk/src/entities/view/custom-view-validate.js +24 -5
- package/dist-sdk/src/entities/view/from-tf.js +14 -1
- package/dist-sdk/src/entities/widget/from-tf.js +14 -7
- package/dist-sdk/src/entities/widget/to-tf.js +7 -5
- package/dist-sdk/src/graph/index.d.ts +14 -1
- package/dist-sdk/src/graph/index.js +2 -0
- package/dist-sdk/src/graph/resource-types.d.ts +2 -0
- package/dist-sdk/src/graph/resource-types.js +3 -0
- package/dist-sdk/src/graph/types.d.ts +82 -0
- package/package.json +1 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
2
2
|
import { EntityTfError } from "../../engine/entity.js";
|
|
3
|
-
import { expr } from "../../engine/tf/index.js";
|
|
4
|
-
import {
|
|
3
|
+
import { expr, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
4
|
+
import { fieldRefToTfValue, siblingFieldOwnership } from "../field/to-tf.js";
|
|
5
5
|
import { SUB_TYPE_BY_TYPE_KEY } from "../field/types.js";
|
|
6
6
|
import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
|
|
7
7
|
import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "./types.js";
|
|
8
8
|
import { AGENT_VIEW_SPEC_FILTER_PROPS, AGENT_VIEW_SPEC_ID_PROPS, agentViewFontFamily, } from "./agent-view-layout.js";
|
|
9
9
|
import { reportStructureProblems, validateCustomViewLayout } from "./custom-view-validate.js";
|
|
10
|
+
import { AUTOMATION_RESOURCE_TYPE, automationResourceLabel } from "../automation/types.js";
|
|
11
|
+
import { automationLookupOwnerId } from "../automation/lookup-owner.js";
|
|
12
|
+
import { isTextOptionValue } from "../shared/filters/index.js";
|
|
13
|
+
import { optionsLocalName } from "../shared/filters/option-lookups.js";
|
|
14
|
+
import { isUuid } from "../../engine/tf/index.js";
|
|
10
15
|
const PLATFORM_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
11
16
|
const HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
|
|
12
17
|
const FONT_FAMILIES = new Set(Object.values(agentViewFontFamily));
|
|
@@ -153,13 +158,19 @@ function buttonToTf(item, where, opts) {
|
|
|
153
158
|
}
|
|
154
159
|
return out;
|
|
155
160
|
}
|
|
156
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Actions (`on` events, button `onPress`): app or element references, and the
|
|
163
|
+
* view owner's automations (a triggerAutomation's `automationId`, #3207), may
|
|
164
|
+
* sit at any depth.
|
|
165
|
+
*/
|
|
157
166
|
function deepSourceRefs(value, where, opts) {
|
|
158
167
|
if (isReference(value)) {
|
|
159
168
|
const kind = value.__kind;
|
|
160
169
|
if (kind === undefined || kind === "app" || kind === "element")
|
|
161
170
|
return appRef(value, where, opts);
|
|
162
|
-
|
|
171
|
+
if (kind === "automation")
|
|
172
|
+
return automationRef(value, where, opts);
|
|
173
|
+
throw new EntityTfError(`${where}: only app or element references, the view's own automations, or unsafePlatformId(...) are allowed inside actions`);
|
|
163
174
|
}
|
|
164
175
|
if (Array.isArray(value))
|
|
165
176
|
return value.map((item, i) => deepSourceRefs(item, `${where}[${i}]`, opts));
|
|
@@ -172,6 +183,72 @@ function deepSourceRefs(value, where, opts) {
|
|
|
172
183
|
}
|
|
173
184
|
return literal(value, where, opts);
|
|
174
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* An automation of the view's owner (#3207). It builds the automation's id, as
|
|
188
|
+
* a run-automation widget does; `runAutomationProblem` warns when the page
|
|
189
|
+
* won't run it as expected from a button.
|
|
190
|
+
*/
|
|
191
|
+
function automationRef(value, where, opts) {
|
|
192
|
+
const token = value;
|
|
193
|
+
const refName = token.refName ?? "";
|
|
194
|
+
if (refName === "")
|
|
195
|
+
throw new EntityTfError(`${where}: automation reference has no refName`);
|
|
196
|
+
const ownerKind = opts.ownerKind ?? "app";
|
|
197
|
+
if (token.parent !== undefined && token.parent !== opts.ownerRefName) {
|
|
198
|
+
throw new EntityTfError(`${where}: automation ${JSON.stringify(refName)} belongs to ${JSON.stringify(token.parent)}; a view's action can name only its own ${ownerKind}'s automations (or an unsafePlatformId(...))`);
|
|
199
|
+
}
|
|
200
|
+
const aspect = opts.workspaceAspects?.get(workspaceAspectKey(ownerKind, opts.ownerRefName));
|
|
201
|
+
const authored = aspect?.automationRefNames;
|
|
202
|
+
const label = authored === undefined || authored.has(refName)
|
|
203
|
+
? undefined
|
|
204
|
+
: `${opts.ownerTfLabel}_${tsLabelToTfLabel(refName)}`;
|
|
205
|
+
if (authored !== undefined && authored.has(refName)) {
|
|
206
|
+
const problem = runAutomationProblem(refName, aspect, ownerKind, opts.ownerRefName);
|
|
207
|
+
if (problem !== undefined)
|
|
208
|
+
opts.diagnostics.push(`${where}: automation ${JSON.stringify(token.name ?? refName)} ${problem}`);
|
|
209
|
+
}
|
|
210
|
+
if (label === undefined) {
|
|
211
|
+
const handle = ownerKind === "element"
|
|
212
|
+
? aspect?.streamRootEntity?.payload?.handle
|
|
213
|
+
: undefined;
|
|
214
|
+
return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, automationResourceLabel(opts.ownerTfLabel, refName, opts.scope, handle), ["id"]);
|
|
215
|
+
}
|
|
216
|
+
// Not in source (pull leaves some automations platform-managed): look the
|
|
217
|
+
// live one up by its display name in this owner, as widgets do.
|
|
218
|
+
const displayName = token.displayName ?? token.name ?? "";
|
|
219
|
+
if (displayName === "" || opts.orgRefs === undefined) {
|
|
220
|
+
throw new EntityTfError(`${where}: automation ${JSON.stringify(refName)} is not in this ${ownerKind}'s source and has no display name to look it up by`);
|
|
221
|
+
}
|
|
222
|
+
opts.orgRefs.rawLookup(AUTOMATION_RESOURCE_TYPE, label, displayName, { app_id: automationLookupOwnerId(opts.scope, opts.ownerTfLabel, opts.orgRefs) });
|
|
223
|
+
return expr.dataAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Why the page won't run `refName` from a view button as expected, or
|
|
227
|
+
* undefined. The page (asgard triggerAutomation.ts) runs only an ACTIVE
|
|
228
|
+
* automation with an on-demand trigger, refuses the click when a record
|
|
229
|
+
* input names another app or element, writes the selected row into every
|
|
230
|
+
* record input (ultron executeForRecord), and asks for the other inputs in a
|
|
231
|
+
* dialog.
|
|
232
|
+
*/
|
|
233
|
+
function runAutomationProblem(refName, aspect, ownerKind, ownerRefName) {
|
|
234
|
+
if (aspect?.activeAutomationRefNames !== undefined && !aspect.activeAutomationRefNames.has(refName)) {
|
|
235
|
+
return "isn't active; the page runs only an active automation from a button.";
|
|
236
|
+
}
|
|
237
|
+
const info = aspect?.onDemandRunInfoByAutomationRefName?.get(refName);
|
|
238
|
+
if (info === undefined)
|
|
239
|
+
return undefined;
|
|
240
|
+
if (!info.onDemand)
|
|
241
|
+
return "has no on-demand trigger, so a button can't run it.";
|
|
242
|
+
const self = `${ownerKind}:${ownerRefName}`;
|
|
243
|
+
const foreign = info.recordInputOwners.filter((owner) => owner !== undefined && owner !== self);
|
|
244
|
+
if (foreign.length > 0) {
|
|
245
|
+
return `has a record input for ${foreign.map((owner) => JSON.stringify(owner.split(":")[1])).join(", ")}; the page refuses to run it from a view of this ${ownerKind}.`;
|
|
246
|
+
}
|
|
247
|
+
if (info.recordInputOwners.length === 0) {
|
|
248
|
+
return `has no on-demand input of type record for this ${ownerKind}, so the run gets no record from the selected row (onDemand({ record: { type: "record", app: <this ${ownerKind}> } }) receives it), and the page asks for its other inputs in a dialog.`;
|
|
249
|
+
}
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
175
252
|
function appRef(value, where, opts) {
|
|
176
253
|
const id = unsafeId(value);
|
|
177
254
|
if (id !== undefined)
|
|
@@ -224,7 +301,7 @@ function foreignFieldRef(value, where, opts) {
|
|
|
224
301
|
const sibling = opts.workspaceAspects?.get(workspaceAspectKey(kind, token.parent));
|
|
225
302
|
const siblingType = sibling === undefined ? undefined : siblingFieldType(sibling.streamRootEntity?.payload, token.refName);
|
|
226
303
|
const direct = sibling !== undefined && siblingType !== undefined
|
|
227
|
-
? fieldRefToTfValue(siblingType, token.refName, sibling.tfLabel, kind,
|
|
304
|
+
? fieldRefToTfValue(siblingType, token.refName, sibling.tfLabel, kind, siblingFieldOwnership(sibling.streamRootEntity?.payload, sibling.tfLabel, kind), undefined, token.name)
|
|
228
305
|
: undefined;
|
|
229
306
|
if (direct !== undefined)
|
|
230
307
|
return direct;
|
|
@@ -244,23 +321,151 @@ function siblingFieldType(payload, refName) {
|
|
|
244
321
|
const typeKey = entry === undefined ? undefined : Object.keys(entry)[0];
|
|
245
322
|
return typeKey === undefined ? undefined : SUB_TYPE_BY_TYPE_KEY.get(typeKey)?.authoringType;
|
|
246
323
|
}
|
|
247
|
-
/**
|
|
248
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Filter trees (filter props and `spec.state`): field and app references at
|
|
326
|
+
* any depth, and a Dropdown option named by label (`filter.textOption(label)`,
|
|
327
|
+
* #3206), resolved through the nearest filter node's `field`. The page's form
|
|
328
|
+
* is `{ type: "TEXT", value: <option id> }`.
|
|
329
|
+
*/
|
|
330
|
+
function deepRefs(value, where, opts, field) {
|
|
331
|
+
if (isTextOptionValue(value))
|
|
332
|
+
return optionRef(value.value, field, where, opts);
|
|
249
333
|
if (isReference(value)) {
|
|
250
334
|
const kind = value.__kind;
|
|
251
335
|
return kind === "app" || kind === "element" ? appRef(value, where, opts) : fieldRef(value, where, opts);
|
|
252
336
|
}
|
|
253
337
|
if (Array.isArray(value))
|
|
254
|
-
return value.map((item, i) => deepRefs(item, `${where}[${i}]`, opts));
|
|
338
|
+
return value.map((item, i) => deepRefs(item, `${where}[${i}]`, opts, field));
|
|
255
339
|
const rec = record(value);
|
|
256
340
|
if (rec !== undefined) {
|
|
341
|
+
// A filter node's own field scopes the option labels among its values.
|
|
342
|
+
const isNode = isReference(rec["field"]);
|
|
343
|
+
const nodeField = isNode ? rec["field"] : field;
|
|
344
|
+
warnOptionLabelAsText(rec, nodeField, where, opts);
|
|
257
345
|
const out = {};
|
|
258
|
-
for (const [key, child] of Object.entries(rec))
|
|
259
|
-
|
|
346
|
+
for (const [key, child] of Object.entries(rec)) {
|
|
347
|
+
const childWhere = `${where}.${key}`;
|
|
348
|
+
// filter.textOption written straight as a node's value (or a values
|
|
349
|
+
// item) stands for the whole value: the page reads { type, value }.
|
|
350
|
+
if (isNode && key === "value" && isTextOptionValue(child))
|
|
351
|
+
out[checkKey(key, where)] = textOptionValue(child.value, nodeField, childWhere, opts);
|
|
352
|
+
else if (isNode && key === "values" && Array.isArray(child)) {
|
|
353
|
+
out[checkKey(key, where)] = child.map((item, i) => isTextOptionValue(item)
|
|
354
|
+
? textOptionValue(item.value, nodeField, `${childWhere}[${i}]`, opts)
|
|
355
|
+
: deepRefs(item, `${childWhere}[${i}]`, opts, nodeField));
|
|
356
|
+
}
|
|
357
|
+
else
|
|
358
|
+
out[checkKey(key, where)] = deepRefs(child, childWhere, opts, nodeField);
|
|
359
|
+
}
|
|
260
360
|
return out;
|
|
261
361
|
}
|
|
262
362
|
return literal(value, where, opts);
|
|
263
363
|
}
|
|
364
|
+
/** `{ type: "TEXT", value: <option id> }`: the page's form of a Dropdown value. */
|
|
365
|
+
function textOptionValue(label, field, where, opts) {
|
|
366
|
+
return { type: "TEXT", value: optionRef(label, field, `${where}.value`, opts) };
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* An app's Status or Stage, as optionsLocalName reads them; elements have
|
|
370
|
+
* neither. Keyed by the field's owner, not the view's: an element's own
|
|
371
|
+
* field may be keyed `status`, and an element's view may filter an app's Status.
|
|
372
|
+
*/
|
|
373
|
+
function systemOptionField(token, opts) {
|
|
374
|
+
const viewOwnerKind = opts.ownerKind ?? "app";
|
|
375
|
+
const fieldOwnerKind = token.parentKind ?? (token.parent === undefined || token.parent === opts.ownerRefName ? viewOwnerKind : "app");
|
|
376
|
+
if (fieldOwnerKind !== "app")
|
|
377
|
+
return undefined;
|
|
378
|
+
if (token.tags?.includes("STATUS") === true || token.refName === "status")
|
|
379
|
+
return "Status";
|
|
380
|
+
if (token.tags?.includes("STAGE") === true || token.refName === "stage")
|
|
381
|
+
return "Stage";
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The options-by-label local `filter.textOption(label)` builds through, or why
|
|
386
|
+
* the field can't take one. Only the view owner's own Dropdown and
|
|
387
|
+
* Multi-Select fields: `ei` export prints an option id back as a lookup only
|
|
388
|
+
* for those (#3206), so another owner's field, or the owner's Status or
|
|
389
|
+
* Stage, would pull back as a raw id and stop moving between environments.
|
|
390
|
+
*/
|
|
391
|
+
function optionLocalFor(token, opts) {
|
|
392
|
+
const fieldName = token.name ?? token.refName ?? "unknown";
|
|
393
|
+
const ownerKind = opts.ownerKind ?? "app";
|
|
394
|
+
const own = token.parent === undefined || (token.parent === opts.ownerRefName && (token.parentKind ?? ownerKind) === ownerKind);
|
|
395
|
+
if (!own) {
|
|
396
|
+
return { reason: `field "${fieldName}" belongs to ${token.parentKind ?? "app"} "${token.parent}", not to this view's owner, and pull prints only the owner's own options back by label` };
|
|
397
|
+
}
|
|
398
|
+
const system = systemOptionField(token, opts);
|
|
399
|
+
if (system !== undefined)
|
|
400
|
+
return { reason: `field "${fieldName}" is the ${system}, whose options pull can't print back by label yet` };
|
|
401
|
+
const local = optionsLocalName(opts.ownerTfLabel, ownerKind, token);
|
|
402
|
+
return local === undefined ? { reason: `field "${fieldName}" has no reference name to build its option id from` } : { local };
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* `filter.textOption(label)` in a view filter (#3206): the option's id in this
|
|
406
|
+
* environment, through the field's options-by-label local, as charts and
|
|
407
|
+
* tables build it (#2582). The field must be one of the view owner's own
|
|
408
|
+
* Dropdown or Multi-Select fields (`optionLocalFor`).
|
|
409
|
+
*/
|
|
410
|
+
function optionRef(label, field, where, opts) {
|
|
411
|
+
const token = record(field);
|
|
412
|
+
const call = `filter.textOption(${JSON.stringify(label)})`;
|
|
413
|
+
if (token === undefined || token.__kind !== "field") {
|
|
414
|
+
throw new EntityTfError(`${where}: ${call} needs its filter node's "field" to be a Dropdown or Multi-Select field reference`);
|
|
415
|
+
}
|
|
416
|
+
const fieldName = token.name ?? token.refName ?? "unknown";
|
|
417
|
+
if (token.options === undefined) {
|
|
418
|
+
// Say why: the app's Status/Stage (no options unless declared), a field
|
|
419
|
+
// of another type, or a Dropdown reference that lists none.
|
|
420
|
+
const system = systemOptionField(token, opts);
|
|
421
|
+
if (system !== undefined) {
|
|
422
|
+
throw new EntityTfError(`${where}: ${call}: field "${fieldName}" is the ${system}, whose options pull can't print back by label yet; name the option by id: unsafePlatformId("<option id>")`);
|
|
423
|
+
}
|
|
424
|
+
if (token.fieldType !== undefined && token.fieldType !== "PICKLIST" && token.fieldType !== "MULTI_PICKLIST") {
|
|
425
|
+
throw new EntityTfError(`${where}: ${call} needs its filter node's "field" to be a Dropdown or Multi-Select field; "${fieldName}" is ${token.fieldType}`);
|
|
426
|
+
}
|
|
427
|
+
throw new EntityTfError(`${where}: ${call}: field "${fieldName}" lists no options on its reference. A dynamic Dropdown's values are records, not options, and a hand-written fieldRef(...) needs its options`);
|
|
428
|
+
}
|
|
429
|
+
const matches = token.options.filter((option) => option === label).length;
|
|
430
|
+
if (matches !== 1) {
|
|
431
|
+
throw new EntityTfError(matches === 0
|
|
432
|
+
? `${where}: ${call} names no option of field "${fieldName}"; expected one of: ${token.options.map((option) => JSON.stringify(option)).join(", ")}`
|
|
433
|
+
: `${where}: ${call} matches ${matches} options of field "${fieldName}", so it names no single option`);
|
|
434
|
+
}
|
|
435
|
+
const target = optionLocalFor(token, opts);
|
|
436
|
+
if ("reason" in target)
|
|
437
|
+
throw new EntityTfError(`${where}: ${call}: ${target.reason}; name the option by id: unsafePlatformId("<option id>")`);
|
|
438
|
+
return expr.local(target.local, [{ index: label }]);
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* A Dropdown or Multi-Select option compared as its label text (`{ type:
|
|
442
|
+
* "TEXT", value: "Critical" }`, or in a `UUID` wrapper): KPI tiles read the
|
|
443
|
+
* stored option id and match nothing (#3206), so point to
|
|
444
|
+
* `filter.textOption(label)`, or to the option's id where that can't build.
|
|
445
|
+
* An app's Status or Stage value is always an option id, so any other text
|
|
446
|
+
* there warns too, whether or not its reference lists the options.
|
|
447
|
+
*/
|
|
448
|
+
function warnOptionLabelAsText(rec, field, where, opts) {
|
|
449
|
+
const token = record(field);
|
|
450
|
+
const label = rec["value"];
|
|
451
|
+
if ((rec["type"] !== "TEXT" && rec["type"] !== "UUID") || typeof label !== "string" || label === "" || isUuid(label) || token?.__kind !== "field")
|
|
452
|
+
return;
|
|
453
|
+
const fieldName = token.name ?? token.refName;
|
|
454
|
+
const system = systemOptionField(token, opts);
|
|
455
|
+
if (system !== undefined) {
|
|
456
|
+
opts.diagnostics.push(`${where}: compares the ${system} field "${fieldName}" with the text ${JSON.stringify(label)}. ` +
|
|
457
|
+
`A ${system} value is the option's id, so KPI tiles count nothing; write { type: "TEXT", value: unsafePlatformId("<option id>") }.`);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (token.options?.includes(label) !== true)
|
|
461
|
+
return;
|
|
462
|
+
const target = optionLocalFor(token, opts);
|
|
463
|
+
const fix = "local" in target
|
|
464
|
+
? `write { type: "TEXT", value: filter.textOption(${JSON.stringify(label)}) } so it builds that option's id.`
|
|
465
|
+
: `write the option's id, { type: "TEXT", value: unsafePlatformId("<option id>") }; filter.textOption can't build here: ${target.reason}.`;
|
|
466
|
+
opts.diagnostics.push(`${where}: compares the Dropdown or Multi-Select field "${fieldName}" with the text ${JSON.stringify(label)}. ` +
|
|
467
|
+
`KPI tiles compare the stored option id and count nothing; ${fix}`);
|
|
468
|
+
}
|
|
264
469
|
/** Plain JSON outside the id positions. */
|
|
265
470
|
function literal(value, where, opts) {
|
|
266
471
|
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* nested filters, inside `spec.state`, and inside actions (`on` events,
|
|
14
14
|
* button `onPress`).
|
|
15
15
|
*/
|
|
16
|
-
import type { AppCatalogRef, ElementCatalogRef, FieldRef } from "../../catalog/types.js";
|
|
16
|
+
import type { AppCatalogRef, AutomationRef, ElementCatalogRef, FieldRef } from "../../catalog/types.js";
|
|
17
17
|
import type { UnsafePlatformId } from "../../core/platform-id.js";
|
|
18
|
+
import type { TextOptionValue } from "../shared/filters/index.js";
|
|
18
19
|
import type { SystemFieldKey } from "../../core/system-fields.js";
|
|
19
20
|
import type { ElementumBlocksElement, ElementumBlocksSpec } from "./ragnarok.js";
|
|
20
21
|
/** Font families the agent view renders. */
|
|
@@ -49,7 +50,7 @@ export type ViewBlocksSource = AppCatalogRef | ElementCatalogRef | UnsafePlatfor
|
|
|
49
50
|
/** A self-fetching block's field: the view owner's, another app's or element's, or one by id. */
|
|
50
51
|
export type ViewBlocksField = FieldRef | SystemFieldKey | UnsafePlatformId;
|
|
51
52
|
/** A reference allowed anywhere inside a nested filter prop. */
|
|
52
|
-
export type ViewBlocksFilterRef = ViewBlocksSource | ViewBlocksField;
|
|
53
|
+
export type ViewBlocksFilterRef = ViewBlocksSource | ViewBlocksField | TextOptionValue;
|
|
53
54
|
/** Same as `ViewBlocksSource` (the agent view name). */
|
|
54
55
|
export type AgentViewSpecApp = ViewBlocksSource;
|
|
55
56
|
/** Same as `ViewBlocksField` (the agent view name). */
|
|
@@ -96,8 +97,13 @@ type WithRef<V, R> = V extends string ? R | "" : V;
|
|
|
96
97
|
type WithDeepRefs<V> = V extends string ? V | ViewBlocksFilterRef : V extends ReadonlyArray<infer I> ? ReadonlyArray<WithDeepRefs<I>> : V extends object ? {
|
|
97
98
|
readonly [K in keyof V]: WithDeepRefs<V[K]>;
|
|
98
99
|
} : V;
|
|
99
|
-
/**
|
|
100
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Allow an app or element reference wherever a string sits inside an action
|
|
102
|
+
* (e.g. createRecord's aspectId), and the view owner's automation
|
|
103
|
+
* (triggerAutomation's automationId, `automationRef({ refName, name, parent })`;
|
|
104
|
+
* `catalog.<app>.automations.<key>` cycles inside the app's own file).
|
|
105
|
+
*/
|
|
106
|
+
type WithDeepSourceRefs<V> = V extends string ? V | ViewBlocksSource | AutomationRef : V extends ReadonlyArray<infer I> ? ReadonlyArray<WithDeepSourceRefs<I>> : V extends object ? {
|
|
101
107
|
readonly [K in keyof V]: WithDeepSourceRefs<V[K]>;
|
|
102
108
|
} : V;
|
|
103
109
|
type MapProps<T, P> = P extends unknown ? {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the custom view page accepts at run time, checked offline (#3205).
|
|
3
|
+
* The server's layout validator leaves these opaque, so a layout it accepts
|
|
4
|
+
* can still break or blank the page. Mirrored at plan by the provider
|
|
5
|
+
* (`provider/internal/customviewlayout/runtime_rules.go`).
|
|
6
|
+
*
|
|
7
|
+
* - `visible`: the page runs @json-render/core 0.21.0's `validateSpec` when it
|
|
8
|
+
* loads the view, with its strict `VisibilityCondition` schema; any error
|
|
9
|
+
* refuses the whole view ("This custom view could not be loaded"). The same
|
|
10
|
+
* check refuses `visible`, `on`, `repeat` and `watch` written inside `props`.
|
|
11
|
+
* - `calc`: MetricsRowBlock formulas are parsed by knowhere's calculated
|
|
12
|
+
* expression grammar (`ExpressionParser.g4`, keywords case-insensitive).
|
|
13
|
+
* A function it doesn't have, a `COUNTIF`/`SUMIF` criterion that isn't a
|
|
14
|
+
* quoted string, or a `DATEDIF` unit outside S/MIN/H/D/M/Y fails the
|
|
15
|
+
* calculation and the metric shows nothing.
|
|
16
|
+
* - `state`: the page seeds its state from `spec.state`, then replaces the
|
|
17
|
+
* `query`, `selection`, `ui`, `host` and `permissions` roots with its own
|
|
18
|
+
* (asgard `managed-view-runtime-host.tsx`), keeping only `query.filter`
|
|
19
|
+
* from the layout. It sets `query.statusGroup` from the ListControlsBlock
|
|
20
|
+
* chips' `defaultValue` (asgard `quick-filter-catalog.ts`), so an authored
|
|
21
|
+
* one is ignored; it isn't warned about, because the scaffold writes one.
|
|
22
|
+
*/
|
|
23
|
+
export declare const VISIBLE_FORMS: string;
|
|
24
|
+
/** Why the page would refuse `value` as a `visible` condition, or undefined when it's valid. */
|
|
25
|
+
export declare function visibilityProblem(value: unknown): string | undefined;
|
|
26
|
+
/** Element keys the page refuses inside `props`. */
|
|
27
|
+
export declare const ELEMENT_KEYS_NOT_IN_PROPS: readonly ["visible", "on", "repeat", "watch"];
|
|
28
|
+
/** Problems the calculation would fail on at run time (the metric shows nothing). */
|
|
29
|
+
export declare function calcProblems(calc: string): string[];
|
|
30
|
+
/** True for a path under a root the page replaces (`query`, `selection`, `ui`), where an initial value is dropped. */
|
|
31
|
+
export declare function pageReplacesStatePath(path: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* True for a state path the page fills itself when it opens the view, so a
|
|
34
|
+
* binding to it needs no initial value in the layout (and one there would be
|
|
35
|
+
* replaced).
|
|
36
|
+
*/
|
|
37
|
+
export declare function pageFillsStatePath(path: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Authored `spec.state` values the page replaces when it opens the view, as
|
|
40
|
+
* `[path, why]`. A value equal to the page's own (e.g. `selection.recordId:
|
|
41
|
+
* null`, `query.search: ""`) is left alone.
|
|
42
|
+
*/
|
|
43
|
+
export declare function replacedStateValues(state: unknown): Array<readonly [string, string]>;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the custom view page accepts at run time, checked offline (#3205).
|
|
3
|
+
* The server's layout validator leaves these opaque, so a layout it accepts
|
|
4
|
+
* can still break or blank the page. Mirrored at plan by the provider
|
|
5
|
+
* (`provider/internal/customviewlayout/runtime_rules.go`).
|
|
6
|
+
*
|
|
7
|
+
* - `visible`: the page runs @json-render/core 0.21.0's `validateSpec` when it
|
|
8
|
+
* loads the view, with its strict `VisibilityCondition` schema; any error
|
|
9
|
+
* refuses the whole view ("This custom view could not be loaded"). The same
|
|
10
|
+
* check refuses `visible`, `on`, `repeat` and `watch` written inside `props`.
|
|
11
|
+
* - `calc`: MetricsRowBlock formulas are parsed by knowhere's calculated
|
|
12
|
+
* expression grammar (`ExpressionParser.g4`, keywords case-insensitive).
|
|
13
|
+
* A function it doesn't have, a `COUNTIF`/`SUMIF` criterion that isn't a
|
|
14
|
+
* quoted string, or a `DATEDIF` unit outside S/MIN/H/D/M/Y fails the
|
|
15
|
+
* calculation and the metric shows nothing.
|
|
16
|
+
* - `state`: the page seeds its state from `spec.state`, then replaces the
|
|
17
|
+
* `query`, `selection`, `ui`, `host` and `permissions` roots with its own
|
|
18
|
+
* (asgard `managed-view-runtime-host.tsx`), keeping only `query.filter`
|
|
19
|
+
* from the layout. It sets `query.statusGroup` from the ListControlsBlock
|
|
20
|
+
* chips' `defaultValue` (asgard `quick-filter-catalog.ts`), so an authored
|
|
21
|
+
* one is ignored; it isn't warned about, because the scaffold writes one.
|
|
22
|
+
*/
|
|
23
|
+
function isObj(v) {
|
|
24
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
25
|
+
}
|
|
26
|
+
const CONDITION_SOURCES = ["$state", "$item", "$index"];
|
|
27
|
+
const EQUALITY_OPS = new Set(["eq", "neq"]);
|
|
28
|
+
const NUMERIC_OPS = new Set(["gt", "gte", "lt", "lte"]);
|
|
29
|
+
export const VISIBLE_FORMS = 'true, false, {"$state":"/path","eq":value}, {"$item":"field","eq":value}, {"$index":true,"eq":n} ' +
|
|
30
|
+
'(operators eq, neq, gt, gte, lt, lte, and "not": true), a list of those (all must hold), or {"$and":[...]} / {"$or":[...]}';
|
|
31
|
+
function singleConditionProblem(v) {
|
|
32
|
+
if (!isObj(v))
|
|
33
|
+
return `${JSON.stringify(v)} is not a condition`;
|
|
34
|
+
const sources = CONDITION_SOURCES.filter((key) => key in v);
|
|
35
|
+
if (sources.length !== 1)
|
|
36
|
+
return "use exactly one of $state, $item or $index per condition";
|
|
37
|
+
const source = sources[0];
|
|
38
|
+
if (source === "$index" ? v[source] !== true : typeof v[source] !== "string") {
|
|
39
|
+
return source === "$index" ? '"$index" must be true' : `"${source}" must be a string`;
|
|
40
|
+
}
|
|
41
|
+
for (const [key, value] of Object.entries(v)) {
|
|
42
|
+
if (key === source || EQUALITY_OPS.has(key))
|
|
43
|
+
continue;
|
|
44
|
+
if (key === "not") {
|
|
45
|
+
if (value !== true)
|
|
46
|
+
return '"not" must be true (leave it out otherwise)';
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (NUMERIC_OPS.has(key)) {
|
|
50
|
+
// json-render's `{ $state }` comparison value is a plain object: extra keys are ignored.
|
|
51
|
+
const stateRef = isObj(value) && typeof value["$state"] === "string";
|
|
52
|
+
if (typeof value !== "number" && !stateRef)
|
|
53
|
+
return `"${key}" must be a number or {"$state":"/path"}`;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
return `unknown key "${key}"`;
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Why the page would refuse `value` as a `visible` condition, or undefined when it's valid. */
|
|
61
|
+
export function visibilityProblem(value) {
|
|
62
|
+
if (typeof value === "boolean")
|
|
63
|
+
return undefined;
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
for (const item of value) {
|
|
66
|
+
const problem = singleConditionProblem(item);
|
|
67
|
+
if (problem !== undefined)
|
|
68
|
+
return `in the list: ${problem}`;
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
if (isObj(value) && ("$and" in value || "$or" in value)) {
|
|
73
|
+
const keys = Object.keys(value);
|
|
74
|
+
if (keys.length !== 1)
|
|
75
|
+
return `{"$and":[...]} and {"$or":[...]} take no other keys (found ${keys.join(", ")})`;
|
|
76
|
+
const list = value[keys[0]];
|
|
77
|
+
if (!Array.isArray(list))
|
|
78
|
+
return `"${keys[0]}" must be a list of conditions`;
|
|
79
|
+
for (const item of list) {
|
|
80
|
+
const problem = visibilityProblem(item);
|
|
81
|
+
if (problem !== undefined)
|
|
82
|
+
return `in "${keys[0]}": ${problem}`;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
return singleConditionProblem(value);
|
|
87
|
+
}
|
|
88
|
+
/** Element keys the page refuses inside `props`. */
|
|
89
|
+
export const ELEMENT_KEYS_NOT_IN_PROPS = ["visible", "on", "repeat", "watch"];
|
|
90
|
+
/** knowhere calculated-expression functions (ExpressionParser.g4 `calculatedFunction`). */
|
|
91
|
+
const CALC_FUNCTIONS = new Set([
|
|
92
|
+
"NOW", "TRUE", "FALSE", "UUID", "BLANK", "ROUND", "DATETIME_TRUNC", "DATE", "DATETIME", "DATEDIF",
|
|
93
|
+
"DATEVALUE", "MONTH", "WEEKDAY", "DAY", "YEAR", "HOUR", "MINUTE", "SECOND", "AVERAGE", "COUNT",
|
|
94
|
+
"COUNTUNIQUE", "MAX", "MIN", "STDEV", "SUM", "SQRT", "POWER", "COUNTIF", "SUMIF", "LEFT", "RIGHT",
|
|
95
|
+
"CONCAT", "IF", "IFS", "AND", "OR", "ISBLANK", "JSON_ESCAPE", "JSON_UNESCAPE", "LEN", "FIND",
|
|
96
|
+
"SEARCH", "STRING_AGG", "STRING_AGG_UNIQUE", "MID", "LOWER", "UPPER", "SUBSTITUTE", "REGEXEXTRACT",
|
|
97
|
+
"REGEXMATCH", "REGEXREPLACE", "REPT", "TEXT", "TRIM", "VALUE", "SPLIT",
|
|
98
|
+
]);
|
|
99
|
+
/** Keywords that may stand before "(" without naming a function (`ORDER BY ("Priority")`). */
|
|
100
|
+
const CALC_KEYWORDS_BEFORE_PAREN = new Set(["BY"]);
|
|
101
|
+
/** knowhere `DateDifUnit`: matched exactly, so case matters. */
|
|
102
|
+
const DATEDIF_UNITS = new Set(["S", "MIN", "H", "D", "M", "Y"]);
|
|
103
|
+
/** Splits a formula into names, 'strings', "field names" and punctuation. */
|
|
104
|
+
function tokenizeCalc(calc) {
|
|
105
|
+
const tokens = [];
|
|
106
|
+
let i = 0;
|
|
107
|
+
while (i < calc.length) {
|
|
108
|
+
const ch = calc[i];
|
|
109
|
+
if (/\s/.test(ch)) {
|
|
110
|
+
i++;
|
|
111
|
+
}
|
|
112
|
+
else if (ch === "'" || ch === '"') {
|
|
113
|
+
// knowhere's lexer escapes with a backslash or a doubled quote.
|
|
114
|
+
let j = i + 1;
|
|
115
|
+
while (j < calc.length && calc[j] !== ch)
|
|
116
|
+
j += calc[j] === "\\" ? 2 : 1;
|
|
117
|
+
tokens.push({ kind: ch === "'" ? "string" : "field", text: calc.slice(i + 1, j) });
|
|
118
|
+
i = j + 1;
|
|
119
|
+
}
|
|
120
|
+
else if (/[A-Za-z_]/.test(ch)) {
|
|
121
|
+
let j = i + 1;
|
|
122
|
+
while (j < calc.length && /[A-Za-z0-9_]/.test(calc[j]))
|
|
123
|
+
j++;
|
|
124
|
+
tokens.push({ kind: "name", text: calc.slice(i, j) });
|
|
125
|
+
i = j;
|
|
126
|
+
}
|
|
127
|
+
else if ("(),.".includes(ch)) {
|
|
128
|
+
tokens.push({ kind: "punct", text: ch });
|
|
129
|
+
i++;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
let j = i + 1;
|
|
133
|
+
while (j < calc.length && !/[\s'"A-Za-z_(),.]/.test(calc[j]))
|
|
134
|
+
j++;
|
|
135
|
+
tokens.push({ kind: "other", text: calc.slice(i, j) });
|
|
136
|
+
i = j;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return tokens;
|
|
140
|
+
}
|
|
141
|
+
/** The top-level arguments of the call whose "(" is at `open`, as token lists. */
|
|
142
|
+
function callArguments(tokens, open) {
|
|
143
|
+
const args = [[]];
|
|
144
|
+
let depth = 0;
|
|
145
|
+
for (let k = open + 1; k < tokens.length; k++) {
|
|
146
|
+
const t = tokens[k];
|
|
147
|
+
if (t.kind === "punct" && t.text === "(")
|
|
148
|
+
depth++;
|
|
149
|
+
if (t.kind === "punct" && t.text === ")") {
|
|
150
|
+
if (depth === 0)
|
|
151
|
+
return args;
|
|
152
|
+
depth--;
|
|
153
|
+
}
|
|
154
|
+
if (depth === 0 && t.kind === "punct" && t.text === ",")
|
|
155
|
+
args.push([]);
|
|
156
|
+
else
|
|
157
|
+
args[args.length - 1].push(t);
|
|
158
|
+
}
|
|
159
|
+
return args;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* One aggregate of one quoted field, which the page reads through its field
|
|
163
|
+
* aggregate query, never knowhere (asgard `parseSimpleMetricCalc`): any case,
|
|
164
|
+
* spaces allowed, AVG included.
|
|
165
|
+
*/
|
|
166
|
+
const SIMPLE_METRIC = /^(?:COUNT|SUM|AVERAGE|AVG|MIN|MAX)\s*\(\s*"(?:[^"\\]|\\.)*"\s*\)$/i;
|
|
167
|
+
/** Problems the calculation would fail on at run time (the metric shows nothing). */
|
|
168
|
+
export function calcProblems(calc) {
|
|
169
|
+
if (SIMPLE_METRIC.test(calc.trim()))
|
|
170
|
+
return [];
|
|
171
|
+
const problems = [];
|
|
172
|
+
const tokens = tokenizeCalc(calc);
|
|
173
|
+
tokens.forEach((token, index) => {
|
|
174
|
+
const next = tokens[index + 1];
|
|
175
|
+
if (token.kind !== "name" || next?.kind !== "punct" || next.text !== "(")
|
|
176
|
+
return;
|
|
177
|
+
// FUNCTION.<name>(...) is a stored function.
|
|
178
|
+
const before = tokens[index - 1];
|
|
179
|
+
if (before?.kind === "punct" && before.text === "." && tokens[index - 2]?.text.toUpperCase() === "FUNCTION")
|
|
180
|
+
return;
|
|
181
|
+
const name = token.text.toUpperCase();
|
|
182
|
+
if (CALC_KEYWORDS_BEFORE_PAREN.has(name))
|
|
183
|
+
return;
|
|
184
|
+
if (name === "AVG") {
|
|
185
|
+
problems.push("use AVERAGE, not AVG");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (!CALC_FUNCTIONS.has(name)) {
|
|
189
|
+
problems.push(name === "DATEDIFF"
|
|
190
|
+
? "DATEDIFF is not a calc function; use DATEDIF(\"Start\", \"End\", 'D') with a quoted unit S, MIN, H, D, M or Y"
|
|
191
|
+
: `${token.text} is not a calc function`);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const args = callArguments(tokens, index + 1);
|
|
195
|
+
if (name === "DATEDIF") {
|
|
196
|
+
const unit = args[2];
|
|
197
|
+
const only = unit?.length === 1 ? unit[0] : undefined;
|
|
198
|
+
if (only?.kind !== "string" || !DATEDIF_UNITS.has(only.text)) {
|
|
199
|
+
const written = unit === undefined ? "nothing" : unit.map((t) => (t.kind === "string" ? `'${t.text}'` : t.kind === "field" ? `"${t.text}"` : t.text)).join("");
|
|
200
|
+
problems.push(`DATEDIF's unit must be one of 'S', 'MIN', 'H', 'D', 'M', 'Y' in single quotes (got ${written})`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (name === "COUNTIF" || name === "SUMIF") {
|
|
204
|
+
const criterion = args[1];
|
|
205
|
+
if (criterion === undefined || criterion.length === 0 || criterion.some((t) => t.kind !== "string")) {
|
|
206
|
+
problems.push(`${name}'s criterion must be text in single quotes, e.g. ${name}("Score", '>5') or ${name}("Title", 'Open%')`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return problems;
|
|
211
|
+
}
|
|
212
|
+
/** What the page puts at each root it replaces; `undefined` = a value only the page knows. */
|
|
213
|
+
const PAGE_STATE = {
|
|
214
|
+
query: {
|
|
215
|
+
search: "", groupBy: "status", groupByInitialized: true, sortBy: null, sortByDirection: "ASC",
|
|
216
|
+
sort: null, sortAspectId: null, filterFields: undefined, groupByOptions: undefined, sortByOptions: undefined,
|
|
217
|
+
},
|
|
218
|
+
selection: { recordId: null, aspectId: null, handle: null },
|
|
219
|
+
ui: { panelFull: false },
|
|
220
|
+
};
|
|
221
|
+
/** Roots the page fills entirely from the host (the view's app, the viewer's permissions). */
|
|
222
|
+
const PAGE_OWNED_ROOTS = ["host", "permissions"];
|
|
223
|
+
/** True for a path under a root the page replaces (`query`, `selection`, `ui`), where an initial value is dropped. */
|
|
224
|
+
export function pageReplacesStatePath(path) {
|
|
225
|
+
const root = path.split("/").filter(Boolean)[0];
|
|
226
|
+
return root !== undefined && root in PAGE_STATE;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* True for a state path the page fills itself when it opens the view, so a
|
|
230
|
+
* binding to it needs no initial value in the layout (and one there would be
|
|
231
|
+
* replaced).
|
|
232
|
+
*/
|
|
233
|
+
export function pageFillsStatePath(path) {
|
|
234
|
+
const [root, key] = path.split("/").filter(Boolean);
|
|
235
|
+
if (root === undefined)
|
|
236
|
+
return false;
|
|
237
|
+
if (PAGE_OWNED_ROOTS.includes(root))
|
|
238
|
+
return true;
|
|
239
|
+
if (root === "query" && (key === "filter" || key === "statusGroup"))
|
|
240
|
+
return true;
|
|
241
|
+
return key !== undefined && PAGE_STATE[root] !== undefined && key in PAGE_STATE[root];
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Layout state not warned about under those roots: the page keeps
|
|
245
|
+
* `query.filter`, and sets `query.statusGroup` from the chips' default (the
|
|
246
|
+
* scaffold writes one).
|
|
247
|
+
*/
|
|
248
|
+
const KEPT_STATE = new Set(["query.filter", "query.statusGroup"]);
|
|
249
|
+
/**
|
|
250
|
+
* Authored `spec.state` values the page replaces when it opens the view, as
|
|
251
|
+
* `[path, why]`. A value equal to the page's own (e.g. `selection.recordId:
|
|
252
|
+
* null`, `query.search: ""`) is left alone.
|
|
253
|
+
*/
|
|
254
|
+
export function replacedStateValues(state) {
|
|
255
|
+
if (!isObj(state))
|
|
256
|
+
return [];
|
|
257
|
+
const out = [];
|
|
258
|
+
for (const root of PAGE_OWNED_ROOTS) {
|
|
259
|
+
if (state[root] !== undefined)
|
|
260
|
+
out.push([`/${root}`, `the page sets /${root} itself`]);
|
|
261
|
+
}
|
|
262
|
+
for (const [root, page] of Object.entries(PAGE_STATE)) {
|
|
263
|
+
const authored = state[root];
|
|
264
|
+
if (authored === undefined)
|
|
265
|
+
continue;
|
|
266
|
+
if (!isObj(authored)) {
|
|
267
|
+
out.push([`/${root}`, `the page replaces /${root} with its own object`]);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
for (const [key, value] of Object.entries(authored)) {
|
|
271
|
+
if (KEPT_STATE.has(`${root}.${key}`))
|
|
272
|
+
continue;
|
|
273
|
+
if (key in page) {
|
|
274
|
+
const pageValue = page[key];
|
|
275
|
+
if (pageValue !== undefined && JSON.stringify(pageValue) === JSON.stringify(value))
|
|
276
|
+
continue;
|
|
277
|
+
out.push([`/${root}/${key}`, pageValue === undefined ? "the page sets it itself" : `the page resets it to ${JSON.stringify(pageValue)}`]);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
out.push([`/${root}/${key}`, "the page drops it"]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
285
|
+
}
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
* Layer 3 from source (calc names, tag-dependent helpers) is in
|
|
12
12
|
* custom-view-references.ts (#1784); typed field refs already fail via
|
|
13
13
|
* resolveField, and raw ids are checked at plan against the live App.
|
|
14
|
-
*
|
|
14
|
+
* The empty COUNT rule lives here; the page's own
|
|
15
|
+
* run-time rules (visible, calc functions, replaced state) are in
|
|
16
|
+
* custom-view-runtime-rules.ts (#3205).
|
|
15
17
|
*/
|
|
16
18
|
import type { BuildFieldMetadata } from "../../graph/types.js";
|
|
17
19
|
export interface CustomViewValidateOptions {
|