@elementumai/edk 0.9.2 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -26
- package/dist-sdk/elementum-entity-client/clients/automation/models/automation.d.ts +1 -1
- package/dist-sdk/elementum-entity-client/clients/skills/models/skill.d.ts +1 -1
- package/dist-sdk/elementum-entity-client/clients/skills/models/skill.js +1 -1
- package/dist-sdk/pull/util.d.ts +1 -1
- package/dist-sdk/pull/util.js +3 -3
- package/dist-sdk/src/catalog/factories.d.ts +49 -10
- package/dist-sdk/src/catalog/factories.js +94 -13
- package/dist-sdk/src/catalog/from-authoring.d.ts +5 -5
- package/dist-sdk/src/catalog/from-authoring.js +7 -7
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +1 -1
- package/dist-sdk/src/catalog/org.js +62 -4
- package/dist-sdk/src/catalog/render-helpers.d.ts +1 -1
- package/dist-sdk/src/catalog/render-helpers.js +1 -1
- package/dist-sdk/src/catalog/render.d.ts +1 -0
- package/dist-sdk/src/catalog/render.js +2 -2
- package/dist-sdk/src/catalog/token.js +11 -4
- package/dist-sdk/src/catalog/types.d.ts +33 -4
- package/dist-sdk/src/catalog/types.js +5 -0
- package/dist-sdk/src/core/index.d.ts +10 -10
- package/dist-sdk/src/core/index.js +9 -9
- package/dist-sdk/src/core/render-tree.d.ts +1 -1
- package/dist-sdk/src/core/render-tree.js +1 -2
- package/dist-sdk/src/core/types/ai-provider.d.ts +1 -1
- package/dist-sdk/src/core/types/ai-provider.js +1 -1
- package/dist-sdk/src/core/types/app.d.ts +66 -30
- package/dist-sdk/src/core/types/app.js +2 -2
- package/dist-sdk/src/core/types/aspect-category.d.ts +4 -4
- package/dist-sdk/src/core/types/aspect-category.js +4 -4
- package/dist-sdk/src/core/types/cloud-link.d.ts +3 -3
- package/dist-sdk/src/core/types/cloud-link.js +3 -3
- package/dist-sdk/src/core/types/display-block.d.ts +2 -2
- package/dist-sdk/src/core/types/display-block.js +2 -2
- package/dist-sdk/src/core/types/group.d.ts +1 -1
- package/dist-sdk/src/core/types/group.js +1 -1
- package/dist-sdk/src/core/types/user.d.ts +1 -1
- package/dist-sdk/src/core/types/user.js +1 -1
- package/dist-sdk/src/core/wire/ref-serializer.js +3 -3
- package/dist-sdk/src/engine/build/context.d.ts +20 -13
- package/dist-sdk/src/engine/entity.d.ts +1 -1
- package/dist-sdk/src/engine/pull/context.d.ts +34 -0
- package/dist-sdk/src/engine/pull/context.js +14 -0
- package/dist-sdk/src/engine/pull/org.d.ts +9 -0
- package/dist-sdk/src/engine/pull/org.js +33 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +37 -0
- package/dist-sdk/src/engine/pull/ref-only.js +204 -0
- package/dist-sdk/src/engine/tf/expr.d.ts +6 -2
- package/dist-sdk/src/engine/tf/expr.js +18 -13
- package/dist-sdk/src/engine/tf/index.d.ts +1 -1
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/model.d.ts +8 -1
- package/dist-sdk/src/engine/tf/model.js +4 -0
- package/dist-sdk/src/engine/tf/parse.js +13 -2
- package/dist-sdk/src/engine/tf/render.js +4 -0
- package/dist-sdk/src/entities/access-policy/build.d.ts +4 -5
- package/dist-sdk/src/entities/access-policy/build.js +1 -1
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +4 -4
- package/dist-sdk/src/entities/access-policy/from-tf.js +12 -13
- package/dist-sdk/src/entities/access-policy/principal.d.ts +14 -4
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +14 -2
- package/dist-sdk/src/entities/access-policy/to-tf.js +36 -6
- package/dist-sdk/src/entities/agent/build.d.ts +3 -3
- package/dist-sdk/src/entities/agent/build.js +5 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +6 -1
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -18
- package/dist-sdk/src/entities/agent/from-tf.d.ts +3 -1
- package/dist-sdk/src/entities/agent/from-tf.js +12 -4
- package/dist-sdk/src/entities/agent/index.d.ts +2 -2
- package/dist-sdk/src/entities/agent/index.js +1 -1
- package/dist-sdk/src/entities/agent/module.js +2 -0
- package/dist-sdk/src/entities/agent/to-tf.d.ts +5 -2
- package/dist-sdk/src/entities/agent/to-tf.js +56 -8
- package/dist-sdk/src/entities/agent/tools.d.ts +38 -23
- package/dist-sdk/src/entities/agent/tools.js +21 -7
- package/dist-sdk/src/entities/agent-evaluation/build.d.ts +19 -0
- package/dist-sdk/src/entities/agent-evaluation/build.js +41 -0
- package/dist-sdk/src/entities/agent-evaluation/deserializer/print-agent-evaluation.d.ts +4 -0
- package/dist-sdk/src/entities/agent-evaluation/deserializer/print-agent-evaluation.js +30 -0
- package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +12 -0
- package/dist-sdk/src/entities/agent-evaluation/from-tf.js +46 -0
- package/dist-sdk/src/entities/agent-evaluation/index.d.ts +1 -0
- package/dist-sdk/src/entities/agent-evaluation/index.js +1 -0
- package/dist-sdk/src/entities/agent-evaluation/module.d.ts +3 -0
- package/dist-sdk/src/entities/agent-evaluation/module.js +58 -0
- package/dist-sdk/src/entities/agent-evaluation/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/agent-evaluation/to-tf.js +35 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +8 -7
- package/dist-sdk/src/entities/agent-tool/from-tf.js +48 -6
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +10 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +76 -28
- package/dist-sdk/src/entities/agent-tool/types.d.ts +0 -1
- package/dist-sdk/src/entities/agent-tool/types.js +10 -37
- package/dist-sdk/src/entities/app/build.d.ts +97 -42
- package/dist-sdk/src/entities/app/build.js +25 -14
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +32 -24
- package/dist-sdk/src/entities/app/deserializer/pulled-expression.d.ts +1 -1
- package/dist-sdk/src/entities/app/deserializer/pulled-expression.js +2 -0
- package/dist-sdk/src/entities/app/index.d.ts +11 -8
- package/dist-sdk/src/entities/app/index.js +10 -7
- package/dist-sdk/src/entities/app/module.js +2 -2
- package/dist-sdk/src/entities/app/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/app/to-tf.js +22 -6
- package/dist-sdk/src/entities/approval-chain/build.d.ts +1 -1
- package/dist-sdk/src/entities/approval-chain/build.js +5 -5
- package/dist-sdk/src/entities/approval-chain/index.d.ts +1 -1
- package/dist-sdk/src/entities/approval-chain/index.js +1 -1
- package/dist-sdk/src/entities/approval-chain/printer.js +2 -2
- package/dist-sdk/src/entities/automation/build.d.ts +172 -94
- package/dist-sdk/src/entities/automation/build.js +159 -68
- package/dist-sdk/src/entities/automation/calculation-expression.d.ts +191 -0
- package/dist-sdk/src/entities/automation/calculation-expression.js +57 -0
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +11 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +18 -14
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +164 -198
- package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -2
- package/dist-sdk/src/entities/automation/from-tf.js +510 -80
- package/dist-sdk/src/entities/automation/index.d.ts +9 -12
- package/dist-sdk/src/entities/automation/index.js +11 -13
- package/dist-sdk/src/entities/automation/module.js +74 -6
- package/dist-sdk/src/entities/automation/operators.d.ts +32 -48
- package/dist-sdk/src/entities/automation/operators.js +10 -37
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +1 -1
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +1 -1
- package/dist-sdk/src/entities/automation/script-code.js +13 -22
- package/dist-sdk/src/entities/automation/serialize.js +1 -1
- package/dist-sdk/src/entities/automation/tasks.d.ts +153 -89
- package/dist-sdk/src/entities/automation/tasks.js +64 -11
- package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -1
- package/dist-sdk/src/entities/automation/to-tf.js +342 -71
- package/dist-sdk/src/entities/automation/triggers.d.ts +17 -10
- package/dist-sdk/src/entities/automation/triggers.js +7 -1
- package/dist-sdk/src/entities/automation/types.d.ts +3 -2
- package/dist-sdk/src/entities/automation/types.js +3 -2
- package/dist-sdk/src/entities/chart/build.d.ts +95 -0
- package/dist-sdk/src/entities/chart/build.js +42 -0
- package/dist-sdk/src/entities/chart/from-tf.d.ts +55 -0
- package/dist-sdk/src/entities/chart/from-tf.js +269 -0
- package/dist-sdk/src/entities/chart/index.d.ts +4 -0
- package/dist-sdk/src/entities/chart/index.js +3 -0
- package/dist-sdk/src/entities/chart/module.d.ts +3 -0
- package/dist-sdk/src/entities/chart/module.js +61 -0
- package/dist-sdk/src/entities/chart/printer.d.ts +5 -0
- package/dist-sdk/src/entities/chart/printer.js +104 -0
- package/dist-sdk/src/entities/chart/to-tf.d.ts +15 -0
- package/dist-sdk/src/entities/chart/to-tf.js +150 -0
- package/dist-sdk/src/entities/chart/types.d.ts +53 -0
- package/dist-sdk/src/entities/chart/types.js +22 -0
- package/dist-sdk/src/entities/dashboard/build.d.ts +34 -7
- package/dist-sdk/src/entities/dashboard/build.js +16 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +22 -4
- package/dist-sdk/src/entities/dashboard/to-tf.d.ts +16 -3
- package/dist-sdk/src/entities/dashboard/to-tf.js +37 -10
- package/dist-sdk/src/entities/datamine/module.js +1 -1
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +4 -3
- package/dist-sdk/src/entities/dynamic-layout/build.js +1 -1
- package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +2 -0
- package/dist-sdk/src/entities/dynamic-layout/dialect.js +43 -5
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +12 -6
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +10 -10
- package/dist-sdk/src/entities/element/build.d.ts +25 -32
- package/dist-sdk/src/entities/element/build.js +15 -32
- package/dist-sdk/src/entities/element/index.d.ts +7 -5
- package/dist-sdk/src/entities/element/index.js +7 -4
- package/dist-sdk/src/entities/element/module.js +7 -3
- package/dist-sdk/src/entities/element/to-tf.d.ts +2 -1
- package/dist-sdk/src/entities/element/to-tf.js +7 -3
- package/dist-sdk/src/entities/field/build.d.ts +51 -24
- package/dist-sdk/src/entities/field/build.js +31 -6
- package/dist-sdk/src/entities/field/calc/aggregate.d.ts +52 -21
- package/dist-sdk/src/entities/field/calc/aggregate.js +59 -29
- package/dist-sdk/src/entities/field/calc/date.d.ts +78 -29
- package/dist-sdk/src/entities/field/calc/date.js +120 -29
- package/dist-sdk/src/entities/field/calc/index.d.ts +80 -85
- package/dist-sdk/src/entities/field/calc/index.js +82 -139
- package/dist-sdk/src/entities/field/calc/numeric.d.ts +8 -12
- package/dist-sdk/src/entities/field/calc/numeric.js +10 -27
- package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -2
- package/dist-sdk/src/entities/field/calc/runtime.js +79 -8
- package/dist-sdk/src/entities/field/calc/text.d.ts +32 -23
- package/dist-sdk/src/entities/field/calc/text.js +43 -31
- package/dist-sdk/src/entities/field/calc/types.d.ts +36 -81
- package/dist-sdk/src/entities/field/calc/types.js +1 -22
- package/dist-sdk/src/entities/field/calc.d.ts +71 -48
- package/dist-sdk/src/entities/field/calc.js +5 -15
- package/dist-sdk/src/entities/field/calculation-types.js +10 -3
- package/dist-sdk/src/entities/field/from-tf.js +156 -10
- package/dist-sdk/src/entities/field/locals.d.ts +11 -3
- package/dist-sdk/src/entities/field/locals.js +15 -2
- package/dist-sdk/src/entities/field/module.js +23 -6
- package/dist-sdk/src/entities/field/record-shape.d.ts +24 -10
- package/dist-sdk/src/entities/field/to-tf.d.ts +40 -1
- package/dist-sdk/src/entities/field/to-tf.js +293 -35
- package/dist-sdk/src/entities/field/types.d.ts +1 -1
- package/dist-sdk/src/entities/field/types.js +7 -1
- package/dist-sdk/src/entities/file-reader/build.d.ts +5 -0
- package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +1 -1
- package/dist-sdk/src/entities/org/cloud-link.js +4 -5
- package/dist-sdk/src/entities/org/email-alias.d.ts +2 -0
- package/dist-sdk/src/entities/org/email-alias.js +12 -0
- package/dist-sdk/src/entities/org/index.d.ts +1 -0
- package/dist-sdk/src/entities/org/index.js +1 -0
- package/dist-sdk/src/entities/org/phone-provider.js +4 -7
- package/dist-sdk/src/entities/organization/build.d.ts +214 -2
- package/dist-sdk/src/entities/organization/build.js +145 -4
- package/dist-sdk/src/entities/organization/index.d.ts +1 -1
- package/dist-sdk/src/entities/organization/index.js +1 -1
- package/dist-sdk/src/entities/organization/module.js +4 -1
- package/dist-sdk/src/entities/organization/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/organization/to-tf.js +118 -1
- package/dist-sdk/src/entities/phone-service/build.d.ts +1 -1
- package/dist-sdk/src/entities/phone-service/build.js +2 -2
- package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +5 -3
- package/dist-sdk/src/entities/phone-service/index.d.ts +1 -1
- package/dist-sdk/src/entities/phone-service/index.js +1 -1
- package/dist-sdk/src/entities/phone-service/types.js +1 -1
- package/dist-sdk/src/entities/record-create-form/to-tf.js +9 -1
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/relationship/to-tf.js +5 -13
- package/dist-sdk/src/entities/search-table/build.d.ts +4 -4
- package/dist-sdk/src/entities/search-table/build.js +13 -13
- package/dist-sdk/src/entities/search-table/index.d.ts +2 -2
- package/dist-sdk/src/entities/search-table/index.js +2 -2
- package/dist-sdk/src/entities/search-table/printer.js +5 -5
- package/dist-sdk/src/entities/service-account/to-tf.d.ts +21 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +32 -1
- package/dist-sdk/src/entities/shared/context.d.ts +25 -24
- package/dist-sdk/src/entities/shared/context.js +36 -35
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +10 -3
- package/dist-sdk/src/entities/shared/filters/ast.js +1 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -1
- package/dist-sdk/src/entities/shared/filters/index.js +11 -4
- package/dist-sdk/src/entities/shared/foreign-ref.d.ts +14 -0
- package/dist-sdk/src/entities/shared/foreign-ref.js +12 -0
- package/dist-sdk/src/entities/shared/ref.d.ts +26 -11
- package/dist-sdk/src/entities/shared/ref.js +8 -3
- package/dist-sdk/src/entities/shared/types/common.d.ts +2 -2
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +1 -1
- package/dist-sdk/src/entities/shared/types/field-types.js +1 -1
- package/dist-sdk/src/entities/skill/build.d.ts +2 -2
- package/dist-sdk/src/entities/skill/build.js +3 -3
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +26 -7
- package/dist-sdk/src/entities/skill/index.d.ts +1 -1
- package/dist-sdk/src/entities/skill/index.js +1 -1
- package/dist-sdk/src/entities/skill/module.js +2 -2
- package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/skill/to-tf.js +2 -2
- package/dist-sdk/src/entities/skill/tools.d.ts +4 -3
- package/dist-sdk/src/entities/skill/tools.js +4 -3
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +13 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +42 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -6
- package/dist-sdk/src/entities/table/build.d.ts +1 -1
- package/dist-sdk/src/entities/table/build.js +9 -9
- package/dist-sdk/src/entities/table/catalog-render.js +9 -1
- package/dist-sdk/src/entities/table/deserializer/normalize.js +4 -4
- package/dist-sdk/src/entities/table/fields/types.d.ts +1 -1
- package/dist-sdk/src/entities/table/fields/types.js +1 -1
- package/dist-sdk/src/entities/table/index.d.ts +2 -2
- package/dist-sdk/src/entities/table/index.js +3 -3
- package/dist-sdk/src/entities/table/module.js +1 -1
- package/dist-sdk/src/entities/table/to-tf.js +22 -30
- package/dist-sdk/src/entities/task/build.d.ts +1 -1
- package/dist-sdk/src/entities/task/build.js +5 -5
- package/dist-sdk/src/entities/task/index.d.ts +1 -1
- package/dist-sdk/src/entities/task/index.js +1 -1
- package/dist-sdk/src/entities/view/build.d.ts +46 -0
- package/dist-sdk/src/entities/view/build.js +19 -0
- package/dist-sdk/src/entities/view/from-tf.js +68 -18
- package/dist-sdk/src/entities/view/module.d.ts +6 -13
- package/dist-sdk/src/entities/view/module.js +7 -14
- package/dist-sdk/src/entities/view/sharing.d.ts +10 -0
- package/dist-sdk/src/entities/view/sharing.js +6 -0
- package/dist-sdk/src/entities/view/to-tf.d.ts +21 -19
- package/dist-sdk/src/entities/view/to-tf.js +61 -26
- package/dist-sdk/src/entities/view/types.js +3 -0
- package/dist-sdk/src/entities/visual-flow/build.d.ts +1 -1
- package/dist-sdk/src/entities/visual-flow/build.js +8 -8
- package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
- package/dist-sdk/src/entities/visual-flow/index.js +1 -1
- package/dist-sdk/src/entities/visual-flow/module.js +1 -1
- package/dist-sdk/src/entities/visual-flow/printer.js +3 -3
- package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/visual-flow/to-tf.js +3 -7
- package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/widget/to-tf.js +9 -7
- package/dist-sdk/src/graph/index.d.ts +5 -1
- package/dist-sdk/src/graph/index.js +4 -1
- package/dist-sdk/src/graph/modules.js +6 -1
- package/dist-sdk/src/graph/types.d.ts +52 -1
- package/dist-sdk/src/internal/safe-identifier.d.ts +4 -0
- package/dist-sdk/src/internal/safe-identifier.js +13 -0
- package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
- package/dist-sdk/src/internal/sdk-package.js +1 -0
- package/package.json +12 -3
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* both these and the bare keywords; the function form is the
|
|
21
21
|
* canonical shape per the Java test).
|
|
22
22
|
*/
|
|
23
|
+
import { isRef } from "../../shared/ref.js";
|
|
23
24
|
import { isUuid } from "../../../../pull/util.js";
|
|
24
25
|
// ---------------------------------------------------------------------------
|
|
25
26
|
// Node construction
|
|
@@ -28,10 +29,12 @@ import { isUuid } from "../../../../pull/util.js";
|
|
|
28
29
|
* Build an `Expr<T>` node from its type brand and a serializer
|
|
29
30
|
* closure. Internal — public builders compose this.
|
|
30
31
|
*/
|
|
31
|
-
export function makeExpr(type, serialize) {
|
|
32
|
+
export function makeExpr(type, serialize, metadata) {
|
|
32
33
|
return {
|
|
33
34
|
__calc: true,
|
|
34
35
|
__exprType: type,
|
|
36
|
+
__exprCardinality: metadata?.cardinality ?? "single",
|
|
37
|
+
__exprContext: metadata?.context ?? "standalone",
|
|
35
38
|
toCalcString: serialize,
|
|
36
39
|
};
|
|
37
40
|
}
|
|
@@ -39,12 +42,20 @@ export function makeExpr(type, serialize) {
|
|
|
39
42
|
* True if `value` is already an `Expr<T>` (built by a prior `calc.*`
|
|
40
43
|
* call or a pulled-expression marker). Discriminator-checked.
|
|
41
44
|
*/
|
|
42
|
-
function isExpr(value) {
|
|
45
|
+
export function isExpr(value) {
|
|
43
46
|
return (typeof value === "object" &&
|
|
44
47
|
value !== null &&
|
|
45
48
|
"__calc" in value &&
|
|
46
49
|
value.__calc === true);
|
|
47
50
|
}
|
|
51
|
+
/** Aggregate runtime context metadata for a composed expression. */
|
|
52
|
+
export function expressionContext(expressions) {
|
|
53
|
+
return expressions.some((expression) => expression.__exprContext === "record") ? "record" : "standalone";
|
|
54
|
+
}
|
|
55
|
+
/** Build a scalar parent node while preserving record-context metadata. */
|
|
56
|
+
export function makeComposedExpr(type, expressions, serialize) {
|
|
57
|
+
return makeExpr(type, serialize, { context: expressionContext(expressions) });
|
|
58
|
+
}
|
|
48
59
|
/**
|
|
49
60
|
* True if `value` looks like an `AppField`. Structural check — looks
|
|
50
61
|
* for the `type` + `id` + `name` triplet every variant carries.
|
|
@@ -56,6 +67,14 @@ function isAppField(value) {
|
|
|
56
67
|
"id" in value &&
|
|
57
68
|
"name" in value);
|
|
58
69
|
}
|
|
70
|
+
function isFieldRef(value) {
|
|
71
|
+
return (typeof value === "object" &&
|
|
72
|
+
value !== null &&
|
|
73
|
+
"__kind" in value &&
|
|
74
|
+
value.__kind === "field" &&
|
|
75
|
+
"fieldType" in value &&
|
|
76
|
+
"name" in value);
|
|
77
|
+
}
|
|
59
78
|
// ---------------------------------------------------------------------------
|
|
60
79
|
// Field-ref serialization
|
|
61
80
|
// ---------------------------------------------------------------------------
|
|
@@ -87,14 +106,14 @@ function appFieldExprType(field) {
|
|
|
87
106
|
case "NUMBER": return "number";
|
|
88
107
|
case "DECIMAL": return "decimal";
|
|
89
108
|
case "TEXT":
|
|
90
|
-
case "RICH_TEXT":
|
|
91
|
-
case "HTML":
|
|
92
|
-
case "HANDLE": return "
|
|
109
|
+
case "RICH_TEXT": return "text";
|
|
110
|
+
case "HTML": return "html";
|
|
111
|
+
case "HANDLE": return "handle";
|
|
93
112
|
case "BOOLEAN": return "bool";
|
|
94
113
|
case "DATE": return "date";
|
|
95
114
|
case "DATETIME": return "datetime";
|
|
96
|
-
case "PICKLIST":
|
|
97
|
-
case "MULTI_PICKLIST": return "
|
|
115
|
+
case "PICKLIST": return "picklist";
|
|
116
|
+
case "MULTI_PICKLIST": return "multiPicklist";
|
|
98
117
|
case "USER":
|
|
99
118
|
case "USER_ID": return "user";
|
|
100
119
|
case "GROUP":
|
|
@@ -118,6 +137,44 @@ function appFieldExprType(field) {
|
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
139
|
}
|
|
140
|
+
function catalogFieldExprType(field) {
|
|
141
|
+
switch (field.fieldType) {
|
|
142
|
+
case "NUMBER": return "number";
|
|
143
|
+
case "DECIMAL": return "decimal";
|
|
144
|
+
case "TEXT":
|
|
145
|
+
case "RICH_TEXT": return "text";
|
|
146
|
+
case "HANDLE": return "handle";
|
|
147
|
+
case "HTML": return "html";
|
|
148
|
+
case "BOOLEAN": return "bool";
|
|
149
|
+
case "DATE": return "date";
|
|
150
|
+
case "DATETIME": return "datetime";
|
|
151
|
+
case "PICKLIST": return "picklist";
|
|
152
|
+
case "MULTI_PICKLIST": return "multiPicklist";
|
|
153
|
+
case "USER":
|
|
154
|
+
case "USER_ID": return "user";
|
|
155
|
+
case "GROUP":
|
|
156
|
+
case "GROUP_ID": return "group";
|
|
157
|
+
case "ATTACHMENT":
|
|
158
|
+
case "ATTACHMENT_ID": return "attachment";
|
|
159
|
+
case "JSON": return "json";
|
|
160
|
+
default:
|
|
161
|
+
throw new Error(`calc: unsupported catalog field type "${field.fieldType}" on "${field.name}".`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
let activeWorkflowRefRenderer;
|
|
165
|
+
/** Install the automation calculation parameter collector for one render. */
|
|
166
|
+
export function withWorkflowRefRenderer(renderer, render) {
|
|
167
|
+
if (activeWorkflowRefRenderer !== undefined) {
|
|
168
|
+
throw new Error("nested calculation expression rendering is not supported.");
|
|
169
|
+
}
|
|
170
|
+
activeWorkflowRefRenderer = renderer;
|
|
171
|
+
try {
|
|
172
|
+
return render();
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
activeWorkflowRefRenderer = undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
121
178
|
// ---------------------------------------------------------------------------
|
|
122
179
|
// Literal serialization
|
|
123
180
|
// ---------------------------------------------------------------------------
|
|
@@ -152,10 +209,24 @@ export function coerce(value) {
|
|
|
152
209
|
if (isExpr(value)) {
|
|
153
210
|
return value;
|
|
154
211
|
}
|
|
212
|
+
if (isFieldRef(value)) {
|
|
213
|
+
const field = value;
|
|
214
|
+
const exprType = catalogFieldExprType(field);
|
|
215
|
+
return makeExpr(exprType, () => `"${field.name.replace(/"/g, '""')}"`, { context: "record" });
|
|
216
|
+
}
|
|
155
217
|
if (isAppField(value)) {
|
|
156
218
|
const field = value;
|
|
157
219
|
const exprType = appFieldExprType(field);
|
|
158
|
-
return makeExpr(exprType, () => emitFieldRef(field));
|
|
220
|
+
return makeExpr(exprType, () => emitFieldRef(field), { context: "record" });
|
|
221
|
+
}
|
|
222
|
+
if (isRef(value)) {
|
|
223
|
+
const ref = value;
|
|
224
|
+
return makeExpr("text", () => {
|
|
225
|
+
if (activeWorkflowRefRenderer === undefined) {
|
|
226
|
+
throw new Error("workflow refs can only be rendered by calculation(); pass this expression directly to a calculation value.");
|
|
227
|
+
}
|
|
228
|
+
return activeWorkflowRefRenderer(ref);
|
|
229
|
+
});
|
|
159
230
|
}
|
|
160
231
|
if (typeof value === "number") {
|
|
161
232
|
// Integer → number, fractional → decimal. The runtime split
|
|
@@ -7,67 +7,67 @@
|
|
|
7
7
|
* wire form, and brands the result.
|
|
8
8
|
*
|
|
9
9
|
* Type rules baked in:
|
|
10
|
-
* - `concat` accepts
|
|
11
|
-
*
|
|
12
|
-
* `CONCAT("Partner", "Closed on")` case where a datetime concatenates
|
|
13
|
-
* into a text result).
|
|
10
|
+
* - `concat` accepts the scalar families Knowhere can stringify directly:
|
|
11
|
+
* date, datetime, decimal, number, boolean, and text.
|
|
14
12
|
* - `len` accepts text only (server rejects numeric).
|
|
15
13
|
* - `regexMatch` returns bool; the rest return text.
|
|
16
14
|
* - Argument naming favors readability over wire-form parity
|
|
17
15
|
* (`needle` / `haystack` for FIND/SEARCH; `pattern` for regex).
|
|
18
16
|
*/
|
|
19
|
-
import type {
|
|
17
|
+
import type { ComposedExpr, ExprLike, ExprType } from "./types.js";
|
|
18
|
+
/** Types Knowhere currently permits as direct CONCAT arguments. */
|
|
19
|
+
export type ConcatExprType = "datetime" | "date" | "decimal" | "number" | "bool" | "text";
|
|
20
20
|
/**
|
|
21
21
|
* Concatenate two or more expressions into a single text value.
|
|
22
22
|
* Non-text expressions are stringified by the server. At least two
|
|
23
23
|
* args are required — wire `CONCAT` rejects a single-arg call.
|
|
24
24
|
*/
|
|
25
|
-
export declare function concat
|
|
25
|
+
export declare function concat<const A extends ExprLike<ConcatExprType>, const B extends ExprLike<ConcatExprType>, const Rest extends readonly ExprLike<ConcatExprType>[]>(a: A, b: B, ...rest: Rest): ComposedExpr<"text", [A, B, ...Rest]>;
|
|
26
26
|
/**
|
|
27
27
|
* Coerce any expression to text. Wire `TEXT(value)`. Useful for
|
|
28
28
|
* embedding non-text values inside a string-shaped expression where
|
|
29
29
|
* the server's implicit promotion isn't enough.
|
|
30
30
|
*/
|
|
31
|
-
export declare function toText<T extends ExprType
|
|
31
|
+
export declare function toText<T extends ExprType, const Value extends ExprLike<T>>(value: Value): ComposedExpr<"text", [Value]>;
|
|
32
32
|
/** Character length of a text expression. Returns NUMBER. */
|
|
33
|
-
export declare function len
|
|
33
|
+
export declare function len<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"number", [Value]>;
|
|
34
34
|
/** Strip leading/trailing whitespace. */
|
|
35
|
-
export declare function trim
|
|
35
|
+
export declare function trim<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"text", [Value]>;
|
|
36
36
|
/** Upper-case. */
|
|
37
|
-
export declare function upper
|
|
37
|
+
export declare function upper<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"text", [Value]>;
|
|
38
38
|
/** Lower-case. */
|
|
39
|
-
export declare function lower
|
|
39
|
+
export declare function lower<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"text", [Value]>;
|
|
40
40
|
/**
|
|
41
41
|
* Leftmost `n` characters of a text expression. `n` defaults to 1 on
|
|
42
42
|
* the server when omitted. Wire emits `LEFT(text)` or `LEFT(text, n)`.
|
|
43
43
|
*/
|
|
44
|
-
export declare function left
|
|
44
|
+
export declare function left<const Value extends ExprLike<"text">, const N extends ExprLike<"number"> | undefined = undefined>(value: Value, n?: N): ComposedExpr<"text", [Value, N]>;
|
|
45
45
|
/**
|
|
46
46
|
* Rightmost `n` characters of a text expression. `n` defaults to 1 on
|
|
47
47
|
* the server when omitted.
|
|
48
48
|
*/
|
|
49
|
-
export declare function right
|
|
49
|
+
export declare function right<const Value extends ExprLike<"text">, const N extends ExprLike<"number"> | undefined = undefined>(value: Value, n?: N): ComposedExpr<"text", [Value, N]>;
|
|
50
50
|
/**
|
|
51
51
|
* Substring from `start` (1-indexed) for `length` characters. Wire
|
|
52
52
|
* emits `MID(text, start, length)`.
|
|
53
53
|
*/
|
|
54
|
-
export declare function mid
|
|
54
|
+
export declare function mid<const Value extends ExprLike<"text">, const Start extends ExprLike<"number">, const Length extends ExprLike<"number">>(value: Value, start: Start, length: Length): ComposedExpr<"text", [Value, Start, Length]>;
|
|
55
55
|
/**
|
|
56
56
|
* Replace every occurrence of `find` with `replace` in `value`. Wire
|
|
57
57
|
* emits `SUBSTITUTE(value, find, replace)`. For pattern-based
|
|
58
58
|
* replacement use `regexReplace`.
|
|
59
59
|
*/
|
|
60
|
-
export declare function substitute
|
|
60
|
+
export declare function substitute<const Value extends ExprLike<"text">, const Find extends ExprLike<"text">, const Replace extends ExprLike<"text">>(value: Value, find: Find, replace: Replace): ComposedExpr<"text", [Value, Find, Replace]>;
|
|
61
61
|
/**
|
|
62
62
|
* Case-sensitive index of `needle` within `haystack` (1-indexed).
|
|
63
63
|
* `start` is the 1-indexed position to begin searching from. Wire:
|
|
64
64
|
* `FIND(needle, haystack)` / `FIND(needle, haystack, start)`.
|
|
65
65
|
*/
|
|
66
|
-
export declare function find
|
|
66
|
+
export declare function find<const Needle extends ExprLike<"text">, const Haystack extends ExprLike<"text">, const Start extends ExprLike<"number"> | undefined = undefined>(needle: Needle, haystack: Haystack, start?: Start): ComposedExpr<"number", [Needle, Haystack, Start]>;
|
|
67
67
|
/**
|
|
68
68
|
* Case-INsensitive variant of `find`. Wire: `SEARCH(...)`.
|
|
69
69
|
*/
|
|
70
|
-
export declare function search
|
|
70
|
+
export declare function search<const Needle extends ExprLike<"text">, const Haystack extends ExprLike<"text">, const Start extends ExprLike<"number"> | undefined = undefined>(needle: Needle, haystack: Haystack, start?: Start): ComposedExpr<"number", [Needle, Haystack, Start]>;
|
|
71
71
|
/**
|
|
72
72
|
* Split a text expression by a separator. Wire `SPLIT(text, sep)`.
|
|
73
73
|
* The server returns a text array internally; in expression context
|
|
@@ -76,25 +76,34 @@ export declare function search(needle: ExprLike<"text">, haystack: ExprLike<"tex
|
|
|
76
76
|
* JS keyword `split` in `calc.split` — `splitText` reads cleanly in
|
|
77
77
|
* the calc namespace.
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
/** @deprecated Prefer {@link split}. */
|
|
80
|
+
export declare function splitText<const Value extends ExprLike<"text">, const Separator extends ExprLike<"text">>(value: Value, separator: Separator): ComposedExpr<"text", [Value, Separator], "multiple">;
|
|
81
|
+
/** Canonical concise name for the multi-valued SPLIT function. */
|
|
82
|
+
export declare const split: typeof splitText;
|
|
80
83
|
/**
|
|
81
84
|
* Regex match test. Wire `REGEXMATCH(text, pattern)` or
|
|
82
85
|
* `REGEXMATCH(text, pattern, TRUE)` for case-insensitive matching.
|
|
83
86
|
* The `ignoreCase` flag is a bool literal on the wire — TS accepts a
|
|
84
87
|
* raw boolean here so the agent doesn't have to wrap it.
|
|
85
88
|
*/
|
|
86
|
-
export declare function regexMatch
|
|
89
|
+
export declare function regexMatch<const Value extends ExprLike<"text">, const Pattern extends ExprLike<"text">>(value: Value, pattern: Pattern, options?: boolean | {
|
|
90
|
+
readonly ignoreCase?: boolean;
|
|
91
|
+
}): ComposedExpr<"bool", [Value, Pattern]>;
|
|
87
92
|
/**
|
|
88
93
|
* Regex search-and-replace. Wire `REGEXREPLACE(text, pattern, repl)`
|
|
89
94
|
* or `REGEXREPLACE(text, pattern, repl, TRUE)` for case-insensitive.
|
|
90
95
|
*/
|
|
91
|
-
export declare function regexReplace
|
|
96
|
+
export declare function regexReplace<const Value extends ExprLike<"text">, const Pattern extends ExprLike<"text">, const Replacement extends ExprLike<"text">>(value: Value, pattern: Pattern, replacement: Replacement, options?: boolean | {
|
|
97
|
+
readonly ignoreCase?: boolean;
|
|
98
|
+
}): ComposedExpr<"text", [Value, Pattern, Replacement]>;
|
|
92
99
|
/**
|
|
93
100
|
* Regex extract — returns the first matching substring (or capture
|
|
94
101
|
* group) as text. Wire `REGEXEXTRACT(text, pattern)`.
|
|
95
102
|
*/
|
|
96
|
-
export declare function regexExtract
|
|
103
|
+
export declare function regexExtract<const Value extends ExprLike<"text">, const Pattern extends ExprLike<"text">>(value: Value, pattern: Pattern): ComposedExpr<"text", [Value, Pattern]>;
|
|
97
104
|
/** Escape a text value for embedding in a JSON string literal. */
|
|
98
|
-
export declare function jsonEscape
|
|
105
|
+
export declare function jsonEscape<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"text", [Value]>;
|
|
99
106
|
/** Reverse the effect of `jsonEscape` — decode a JSON-escaped string. */
|
|
100
|
-
export declare function jsonUnescape
|
|
107
|
+
export declare function jsonUnescape<const Value extends ExprLike<"text">>(value: Value): ComposedExpr<"text", [Value]>;
|
|
108
|
+
/** Repeat text a whole-number count of times. Wire `REPT(text, count)`. */
|
|
109
|
+
export declare function repeat<const Value extends ExprLike<"text">, const Count extends ExprLike<"number">>(value: Value, count: Count): ComposedExpr<"text", [Value, Count]>;
|
|
@@ -7,16 +7,14 @@
|
|
|
7
7
|
* wire form, and brands the result.
|
|
8
8
|
*
|
|
9
9
|
* Type rules baked in:
|
|
10
|
-
* - `concat` accepts
|
|
11
|
-
*
|
|
12
|
-
* `CONCAT("Partner", "Closed on")` case where a datetime concatenates
|
|
13
|
-
* into a text result).
|
|
10
|
+
* - `concat` accepts the scalar families Knowhere can stringify directly:
|
|
11
|
+
* date, datetime, decimal, number, boolean, and text.
|
|
14
12
|
* - `len` accepts text only (server rejects numeric).
|
|
15
13
|
* - `regexMatch` returns bool; the rest return text.
|
|
16
14
|
* - Argument naming favors readability over wire-form parity
|
|
17
15
|
* (`needle` / `haystack` for FIND/SEARCH; `pattern` for regex).
|
|
18
16
|
*/
|
|
19
|
-
import { coerce, makeExpr } from "./runtime.js";
|
|
17
|
+
import { coerce, expressionContext, makeComposedExpr, makeExpr } from "./runtime.js";
|
|
20
18
|
// ---------------------------------------------------------------------------
|
|
21
19
|
// CONCAT / TEXT — assembling text values
|
|
22
20
|
// ---------------------------------------------------------------------------
|
|
@@ -27,7 +25,7 @@ import { coerce, makeExpr } from "./runtime.js";
|
|
|
27
25
|
*/
|
|
28
26
|
export function concat(a, b, ...rest) {
|
|
29
27
|
const exprs = [a, b, ...rest].map((v) => coerce(v));
|
|
30
|
-
return
|
|
28
|
+
return makeComposedExpr("text", exprs, () => `CONCAT(${exprs.map((e) => e.toCalcString()).join(", ")})`);
|
|
31
29
|
}
|
|
32
30
|
/**
|
|
33
31
|
* Coerce any expression to text. Wire `TEXT(value)`. Useful for
|
|
@@ -36,7 +34,7 @@ export function concat(a, b, ...rest) {
|
|
|
36
34
|
*/
|
|
37
35
|
export function toText(value) {
|
|
38
36
|
const e = coerce(value);
|
|
39
|
-
return
|
|
37
|
+
return makeComposedExpr("text", [e], () => `TEXT(${e.toCalcString()})`);
|
|
40
38
|
}
|
|
41
39
|
// ---------------------------------------------------------------------------
|
|
42
40
|
// LEN / TRIM / case
|
|
@@ -44,22 +42,22 @@ export function toText(value) {
|
|
|
44
42
|
/** Character length of a text expression. Returns NUMBER. */
|
|
45
43
|
export function len(value) {
|
|
46
44
|
const e = coerce(value);
|
|
47
|
-
return
|
|
45
|
+
return makeComposedExpr("number", [e], () => `LEN(${e.toCalcString()})`);
|
|
48
46
|
}
|
|
49
47
|
/** Strip leading/trailing whitespace. */
|
|
50
48
|
export function trim(value) {
|
|
51
49
|
const e = coerce(value);
|
|
52
|
-
return
|
|
50
|
+
return makeComposedExpr("text", [e], () => `TRIM(${e.toCalcString()})`);
|
|
53
51
|
}
|
|
54
52
|
/** Upper-case. */
|
|
55
53
|
export function upper(value) {
|
|
56
54
|
const e = coerce(value);
|
|
57
|
-
return
|
|
55
|
+
return makeComposedExpr("text", [e], () => `UPPER(${e.toCalcString()})`);
|
|
58
56
|
}
|
|
59
57
|
/** Lower-case. */
|
|
60
58
|
export function lower(value) {
|
|
61
59
|
const e = coerce(value);
|
|
62
|
-
return
|
|
60
|
+
return makeComposedExpr("text", [e], () => `LOWER(${e.toCalcString()})`);
|
|
63
61
|
}
|
|
64
62
|
// ---------------------------------------------------------------------------
|
|
65
63
|
// LEFT / RIGHT / MID — substring helpers
|
|
@@ -71,10 +69,10 @@ export function lower(value) {
|
|
|
71
69
|
export function left(value, n) {
|
|
72
70
|
const e = coerce(value);
|
|
73
71
|
if (n === undefined) {
|
|
74
|
-
return
|
|
72
|
+
return makeComposedExpr("text", [e], () => `LEFT(${e.toCalcString()})`);
|
|
75
73
|
}
|
|
76
74
|
const ne = coerce(n);
|
|
77
|
-
return
|
|
75
|
+
return makeComposedExpr("text", [e, ne], () => `LEFT(${e.toCalcString()}, ${ne.toCalcString()})`);
|
|
78
76
|
}
|
|
79
77
|
/**
|
|
80
78
|
* Rightmost `n` characters of a text expression. `n` defaults to 1 on
|
|
@@ -83,10 +81,10 @@ export function left(value, n) {
|
|
|
83
81
|
export function right(value, n) {
|
|
84
82
|
const e = coerce(value);
|
|
85
83
|
if (n === undefined) {
|
|
86
|
-
return
|
|
84
|
+
return makeComposedExpr("text", [e], () => `RIGHT(${e.toCalcString()})`);
|
|
87
85
|
}
|
|
88
86
|
const ne = coerce(n);
|
|
89
|
-
return
|
|
87
|
+
return makeComposedExpr("text", [e, ne], () => `RIGHT(${e.toCalcString()}, ${ne.toCalcString()})`);
|
|
90
88
|
}
|
|
91
89
|
/**
|
|
92
90
|
* Substring from `start` (1-indexed) for `length` characters. Wire
|
|
@@ -96,7 +94,7 @@ export function mid(value, start, length) {
|
|
|
96
94
|
const e = coerce(value);
|
|
97
95
|
const se = coerce(start);
|
|
98
96
|
const le = coerce(length);
|
|
99
|
-
return
|
|
97
|
+
return makeComposedExpr("text", [e, se, le], () => `MID(${e.toCalcString()}, ${se.toCalcString()}, ${le.toCalcString()})`);
|
|
100
98
|
}
|
|
101
99
|
/**
|
|
102
100
|
* Replace every occurrence of `find` with `replace` in `value`. Wire
|
|
@@ -107,7 +105,7 @@ export function substitute(value, find, replace) {
|
|
|
107
105
|
const v = coerce(value);
|
|
108
106
|
const f = coerce(find);
|
|
109
107
|
const r = coerce(replace);
|
|
110
|
-
return
|
|
108
|
+
return makeComposedExpr("text", [v, f, r], () => `SUBSTITUTE(${v.toCalcString()}, ${f.toCalcString()}, ${r.toCalcString()})`);
|
|
111
109
|
}
|
|
112
110
|
// ---------------------------------------------------------------------------
|
|
113
111
|
// FIND / SEARCH — substring location
|
|
@@ -121,10 +119,10 @@ export function find(needle, haystack, start) {
|
|
|
121
119
|
const n = coerce(needle);
|
|
122
120
|
const h = coerce(haystack);
|
|
123
121
|
if (start === undefined) {
|
|
124
|
-
return
|
|
122
|
+
return makeComposedExpr("number", [n, h], () => `FIND(${n.toCalcString()}, ${h.toCalcString()})`);
|
|
125
123
|
}
|
|
126
124
|
const s = coerce(start);
|
|
127
|
-
return
|
|
125
|
+
return makeComposedExpr("number", [n, h, s], () => `FIND(${n.toCalcString()}, ${h.toCalcString()}, ${s.toCalcString()})`);
|
|
128
126
|
}
|
|
129
127
|
/**
|
|
130
128
|
* Case-INsensitive variant of `find`. Wire: `SEARCH(...)`.
|
|
@@ -133,10 +131,10 @@ export function search(needle, haystack, start) {
|
|
|
133
131
|
const n = coerce(needle);
|
|
134
132
|
const h = coerce(haystack);
|
|
135
133
|
if (start === undefined) {
|
|
136
|
-
return
|
|
134
|
+
return makeComposedExpr("number", [n, h], () => `SEARCH(${n.toCalcString()}, ${h.toCalcString()})`);
|
|
137
135
|
}
|
|
138
136
|
const s = coerce(start);
|
|
139
|
-
return
|
|
137
|
+
return makeComposedExpr("number", [n, h, s], () => `SEARCH(${n.toCalcString()}, ${h.toCalcString()}, ${s.toCalcString()})`);
|
|
140
138
|
}
|
|
141
139
|
// ---------------------------------------------------------------------------
|
|
142
140
|
// SPLIT
|
|
@@ -149,11 +147,17 @@ export function search(needle, haystack, start) {
|
|
|
149
147
|
* JS keyword `split` in `calc.split` — `splitText` reads cleanly in
|
|
150
148
|
* the calc namespace.
|
|
151
149
|
*/
|
|
150
|
+
/** @deprecated Prefer {@link split}. */
|
|
152
151
|
export function splitText(value, separator) {
|
|
153
152
|
const v = coerce(value);
|
|
154
153
|
const s = coerce(separator);
|
|
155
|
-
return makeExpr("text", () => `SPLIT(${v.toCalcString()}, ${s.toCalcString()})
|
|
154
|
+
return makeExpr("text", () => `SPLIT(${v.toCalcString()}, ${s.toCalcString()})`, {
|
|
155
|
+
cardinality: "multiple",
|
|
156
|
+
context: expressionContext([v, s]),
|
|
157
|
+
});
|
|
156
158
|
}
|
|
159
|
+
/** Canonical concise name for the multi-valued SPLIT function. */
|
|
160
|
+
export const split = splitText;
|
|
157
161
|
// ---------------------------------------------------------------------------
|
|
158
162
|
// REGEX
|
|
159
163
|
// ---------------------------------------------------------------------------
|
|
@@ -163,26 +167,28 @@ export function splitText(value, separator) {
|
|
|
163
167
|
* The `ignoreCase` flag is a bool literal on the wire — TS accepts a
|
|
164
168
|
* raw boolean here so the agent doesn't have to wrap it.
|
|
165
169
|
*/
|
|
166
|
-
export function regexMatch(value, pattern,
|
|
170
|
+
export function regexMatch(value, pattern, options) {
|
|
167
171
|
const v = coerce(value);
|
|
168
172
|
const p = coerce(pattern);
|
|
173
|
+
const ignoreCase = typeof options === "boolean" ? options : options?.ignoreCase;
|
|
169
174
|
if (ignoreCase === undefined) {
|
|
170
|
-
return
|
|
175
|
+
return makeComposedExpr("bool", [v, p], () => `REGEXMATCH(${v.toCalcString()}, ${p.toCalcString()})`);
|
|
171
176
|
}
|
|
172
|
-
return
|
|
177
|
+
return makeComposedExpr("bool", [v, p], () => `REGEXMATCH(${v.toCalcString()}, ${p.toCalcString()}, ${ignoreCase ? "TRUE" : "FALSE"})`);
|
|
173
178
|
}
|
|
174
179
|
/**
|
|
175
180
|
* Regex search-and-replace. Wire `REGEXREPLACE(text, pattern, repl)`
|
|
176
181
|
* or `REGEXREPLACE(text, pattern, repl, TRUE)` for case-insensitive.
|
|
177
182
|
*/
|
|
178
|
-
export function regexReplace(value, pattern, replacement,
|
|
183
|
+
export function regexReplace(value, pattern, replacement, options) {
|
|
179
184
|
const v = coerce(value);
|
|
180
185
|
const p = coerce(pattern);
|
|
181
186
|
const r = coerce(replacement);
|
|
187
|
+
const ignoreCase = typeof options === "boolean" ? options : options?.ignoreCase;
|
|
182
188
|
if (ignoreCase === undefined) {
|
|
183
|
-
return
|
|
189
|
+
return makeComposedExpr("text", [v, p, r], () => `REGEXREPLACE(${v.toCalcString()}, ${p.toCalcString()}, ${r.toCalcString()})`);
|
|
184
190
|
}
|
|
185
|
-
return
|
|
191
|
+
return makeComposedExpr("text", [v, p, r], () => `REGEXREPLACE(${v.toCalcString()}, ${p.toCalcString()}, ${r.toCalcString()}, ${ignoreCase ? "TRUE" : "FALSE"})`);
|
|
186
192
|
}
|
|
187
193
|
/**
|
|
188
194
|
* Regex extract — returns the first matching substring (or capture
|
|
@@ -191,7 +197,7 @@ export function regexReplace(value, pattern, replacement, ignoreCase) {
|
|
|
191
197
|
export function regexExtract(value, pattern) {
|
|
192
198
|
const v = coerce(value);
|
|
193
199
|
const p = coerce(pattern);
|
|
194
|
-
return
|
|
200
|
+
return makeComposedExpr("text", [v, p], () => `REGEXEXTRACT(${v.toCalcString()}, ${p.toCalcString()})`);
|
|
195
201
|
}
|
|
196
202
|
// ---------------------------------------------------------------------------
|
|
197
203
|
// JSON escape helpers
|
|
@@ -199,10 +205,16 @@ export function regexExtract(value, pattern) {
|
|
|
199
205
|
/** Escape a text value for embedding in a JSON string literal. */
|
|
200
206
|
export function jsonEscape(value) {
|
|
201
207
|
const e = coerce(value);
|
|
202
|
-
return
|
|
208
|
+
return makeComposedExpr("text", [e], () => `JSON_ESCAPE(${e.toCalcString()})`);
|
|
203
209
|
}
|
|
204
210
|
/** Reverse the effect of `jsonEscape` — decode a JSON-escaped string. */
|
|
205
211
|
export function jsonUnescape(value) {
|
|
206
212
|
const e = coerce(value);
|
|
207
|
-
return
|
|
213
|
+
return makeComposedExpr("text", [e], () => `JSON_UNESCAPE(${e.toCalcString()})`);
|
|
214
|
+
}
|
|
215
|
+
/** Repeat text a whole-number count of times. Wire `REPT(text, count)`. */
|
|
216
|
+
export function repeat(value, count) {
|
|
217
|
+
const v = coerce(value);
|
|
218
|
+
const c = coerce(count);
|
|
219
|
+
return makeComposedExpr("text", [v, c], () => `REPT(${v.toCalcString()}, ${c.toCalcString()})`);
|
|
208
220
|
}
|
|
@@ -1,86 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Every node the `calc.*` builder produces is an `Expr<T>` — a
|
|
5
|
-
* `CalculationExpression` (the brand `CalculatedAppField.expression`
|
|
6
|
-
* accepts) augmented with a phantom `__exprType` literal carrying the
|
|
7
|
-
* type the expression evaluates to. The phantom drives compile-time
|
|
8
|
-
* argument checking for operators, comparisons, sub-selects, and
|
|
9
|
-
* `if`/`coalesce` shape rules — bad types fail `tsc --noEmit` before
|
|
10
|
-
* the agent ever calls `.deploy()`.
|
|
11
|
-
*
|
|
12
|
-
* `ExprLike<T>` is the argument-position union: every builder accepts
|
|
13
|
-
* either an `Expr<T>`, a typed `AppField` whose type maps to `T`, or
|
|
14
|
-
* (for the primitive types) a raw TS literal. Coercion happens inside
|
|
15
|
-
* the builder via `coerce()` in `runtime.ts`.
|
|
16
|
-
*
|
|
17
|
-
* The 12 `ExprType` brands track the GraphQL `AspectFieldType` enum
|
|
18
|
-
* plus `decimal` (split from `number`) and `uuid` (the `UUID()`
|
|
19
|
-
* built-in's return type — used in tier 2). `text` collapses
|
|
20
|
-
* HTML/RICH_TEXT/HANDLE since they're indistinguishable inside an
|
|
21
|
-
* expression.
|
|
22
|
-
*/
|
|
1
|
+
/** Static type system for Elementum calculated expressions. */
|
|
2
|
+
import type { FieldRef } from "../../../catalog/types.js";
|
|
23
3
|
import type { AppField, AttachmentAppField, BooleanAppField, CalculationExpression, DateAppField, DateTimeAppField, DecimalAppField, FieldScope, GroupAppField, HandleAppField, HtmlAppField, JsonAppField, MultiPicklistAppField, NumberAppField, PicklistAppField, TextAppField, UserAppField } from "../../../core/types/app.js";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* `expression` slot. The `__exprType` phantom carries the output type
|
|
35
|
-
* the operator/function declared.
|
|
36
|
-
*/
|
|
37
|
-
export interface Expr<T extends ExprType> extends CalculationExpression {
|
|
4
|
+
import type { Ref } from "../../shared/ref.js";
|
|
5
|
+
/** Exact Knowhere/Ultron scalar result families plus UUID's internal type. */
|
|
6
|
+
export type ExprType = "number" | "decimal" | "text" | "handle" | "html" | "bool" | "date" | "datetime" | "picklist" | "multiPicklist" | "user" | "group" | "attachment" | "json" | "uuid";
|
|
7
|
+
export type ExprCardinality = "single" | "multiple";
|
|
8
|
+
export type ExprContext = "standalone" | "record";
|
|
9
|
+
export type CalculationInclude = "auto" | "manual" | "both" | {
|
|
10
|
+
readonly picklist: FieldRef<string, string, "PICKLIST">;
|
|
11
|
+
};
|
|
12
|
+
/** A calculation node's exact result family, cardinality, and context. */
|
|
13
|
+
export interface Expr<T extends ExprType, Cardinality extends ExprCardinality = "single", Context extends ExprContext = "standalone"> extends CalculationExpression {
|
|
38
14
|
readonly __exprType: T;
|
|
15
|
+
readonly __exprCardinality: Cardinality;
|
|
16
|
+
readonly __exprContext: Context;
|
|
39
17
|
}
|
|
40
|
-
|
|
41
|
-
export type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* field handles in argument position.
|
|
52
|
-
*
|
|
53
|
-
* Picklist/user/group/attachment fields surface here as their **id**
|
|
54
|
-
* brand — text projections require an explicit `calc.label(...)` /
|
|
55
|
-
* `calc.email(...)` / `calc.name(...)` call. This is the
|
|
56
|
-
* hallucination-control choice: a bare field reference doesn't quietly
|
|
57
|
-
* coerce to the server's implicit default sub-select; the author has
|
|
58
|
-
* to declare which projection they want.
|
|
59
|
-
*/
|
|
60
|
-
export type AppFieldOfExprType<T extends ExprType, Scope extends FieldScope = FieldScope> = T extends "number" ? NumberAppField<Scope> : T extends "decimal" ? DecimalAppField<Scope> : T extends "text" ? TextAppField<Scope> | HandleAppField<Scope> | HtmlAppField<Scope> : T extends "bool" ? BooleanAppField<Scope> : T extends "date" ? DateAppField<Scope> : T extends "datetime" ? DateTimeAppField<Scope> : T extends "picklist" ? PicklistAppField<Scope> | MultiPicklistAppField<Scope> : T extends "user" ? UserAppField<Scope> : T extends "group" ? GroupAppField<Scope> : T extends "attachment" ? AttachmentAppField<Scope> : T extends "json" ? JsonAppField<Scope> : never;
|
|
61
|
-
/**
|
|
62
|
-
* Raw TS literals that coerce into the matching `Expr<T>`. Limited to
|
|
63
|
-
* the primitive types — `date`, `datetime`, and the reference types
|
|
64
|
-
* (picklist/user/group/attachment) require explicit builders so
|
|
65
|
-
* intent is unambiguous. A bare `number` literal coerces to
|
|
66
|
-
* `Expr<"number"> | Expr<"decimal">` (the builder picks based on
|
|
67
|
-
* Number.isInteger at runtime); functions that need a specific
|
|
68
|
-
* sub-type use the explicit `calc.num` / `calc.dec` literals.
|
|
69
|
-
*/
|
|
70
|
-
export type LiteralOfExprType<T extends ExprType> = T extends "number" ? number : T extends "decimal" ? number : T extends "text" ? string : T extends "bool" ? boolean : never;
|
|
71
|
-
/**
|
|
72
|
-
* Argument-position union — every `calc.*` builder accepts these
|
|
73
|
-
* shapes interchangeably. Coercion to `Expr<T>` happens at runtime
|
|
74
|
-
* inside the builder.
|
|
75
|
-
*/
|
|
76
|
-
export type ExprLike<T extends ExprType> = Expr<T> | AppFieldOfExprType<T> | LiteralOfExprType<T>;
|
|
77
|
-
/** Convenience: anything that can be passed where a numeric expr is required. */
|
|
18
|
+
export type AnyExpr = Expr<ExprType, ExprCardinality, ExprContext>;
|
|
19
|
+
export type ScalarExpr<T extends ExprType = ExprType, Context extends ExprContext = ExprContext> = Expr<T, "single", Context>;
|
|
20
|
+
export type NumericExpr<Context extends ExprContext = ExprContext> = Expr<"number", "single", Context> | Expr<"decimal", "single", Context>;
|
|
21
|
+
export type ComparableExprType = "number" | "decimal" | "text" | "handle" | "html" | "date" | "datetime";
|
|
22
|
+
export type AppFieldOfExprType<T extends ExprType, Scope extends FieldScope = FieldScope> = T extends "number" ? NumberAppField<Scope> : T extends "decimal" ? DecimalAppField<Scope> : T extends "text" ? TextAppField<Scope> : T extends "handle" ? HandleAppField<Scope> : T extends "html" ? HtmlAppField<Scope> : T extends "bool" ? BooleanAppField<Scope> : T extends "date" ? DateAppField<Scope> : T extends "datetime" ? DateTimeAppField<Scope> : T extends "picklist" ? PicklistAppField<Scope> : T extends "multiPicklist" ? MultiPicklistAppField<Scope> : T extends "user" ? UserAppField<Scope> : T extends "group" ? GroupAppField<Scope> : T extends "attachment" ? AttachmentAppField<Scope> : T extends "json" ? JsonAppField<Scope> : never;
|
|
23
|
+
type FieldTypeForExprType<T extends ExprType> = T extends "number" ? "NUMBER" : T extends "decimal" ? "DECIMAL" : T extends "text" ? "TEXT" | "RICH_TEXT" : T extends "handle" ? "HANDLE" : T extends "html" ? "HTML" : T extends "bool" ? "BOOLEAN" : T extends "date" ? "DATE" : T extends "datetime" ? "DATETIME" : T extends "picklist" ? "PICKLIST" : T extends "multiPicklist" ? "MULTI_PICKLIST" : T extends "user" ? "USER" | "USER_ID" : T extends "group" ? "GROUP" | "GROUP_ID" : T extends "attachment" ? "ATTACHMENT" | "ATTACHMENT_ID" : T extends "json" ? "JSON" : never;
|
|
24
|
+
export type FieldRefOfExprType<T extends ExprType> = FieldRef<string, string, FieldTypeForExprType<T>>;
|
|
25
|
+
export type FieldRefExprType<F extends FieldRef> = F["fieldType"] extends "NUMBER" ? "number" : F["fieldType"] extends "DECIMAL" ? "decimal" : F["fieldType"] extends "BOOLEAN" ? "bool" : F["fieldType"] extends "DATE" ? "date" : F["fieldType"] extends "DATETIME" ? "datetime" : F["fieldType"] extends "PICKLIST" ? "picklist" : F["fieldType"] extends "MULTI_PICKLIST" ? "multiPicklist" : F["fieldType"] extends "USER" | "USER_ID" ? "user" : F["fieldType"] extends "GROUP" | "GROUP_ID" ? "group" : F["fieldType"] extends "ATTACHMENT" | "ATTACHMENT_ID" ? "attachment" : F["fieldType"] extends "JSON" ? "json" : F["fieldType"] extends "HANDLE" ? "handle" : F["fieldType"] extends "HTML" ? "html" : F["fieldType"] extends "TEXT" | "RICH_TEXT" ? "text" : ExprType;
|
|
26
|
+
export type LiteralOfExprType<T extends ExprType> = T extends "number" | "decimal" ? number : T extends "text" ? string : T extends "bool" ? boolean : never;
|
|
27
|
+
/** Inputs accepted by calc builders, including direct catalog/workflow refs. */
|
|
28
|
+
export type ExprLike<T extends ExprType> = ScalarExpr<T> | AppFieldOfExprType<T> | FieldRefOfExprType<T> | Ref<unknown, T> | LiteralOfExprType<T>;
|
|
78
29
|
export type NumericLike = ExprLike<"number"> | ExprLike<"decimal">;
|
|
79
|
-
/** Convenience: anything that can be passed where a boolean expr is required. */
|
|
80
30
|
export type BoolLike = ExprLike<"bool">;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export type
|
|
31
|
+
export type AppFieldExprType<F extends AppField<FieldScope>> = F extends NumberAppField<FieldScope> ? "number" : F extends DecimalAppField<FieldScope> ? "decimal" : F extends TextAppField<FieldScope> ? "text" : F extends HandleAppField<FieldScope> ? "handle" : F extends HtmlAppField<FieldScope> ? "html" : F extends BooleanAppField<FieldScope> ? "bool" : F extends DateAppField<FieldScope> ? "date" : F extends DateTimeAppField<FieldScope> ? "datetime" : F extends PicklistAppField<FieldScope> ? "picklist" : F extends MultiPicklistAppField<FieldScope> ? "multiPicklist" : F extends UserAppField<FieldScope> ? "user" : F extends GroupAppField<FieldScope> ? "group" : F extends AttachmentAppField<FieldScope> ? "attachment" : F extends JsonAppField<FieldScope> ? "json" : never;
|
|
32
|
+
export type ExprTypeOf<Value> = Value extends Expr<infer T, ExprCardinality, ExprContext> ? T : Value extends FieldRef ? FieldRefExprType<Value> : Value extends Ref<unknown, infer T extends ExprType> ? T : Value extends AppField<FieldScope> ? AppFieldExprType<Value> : Value extends boolean ? "bool" : Value extends string ? "text" : Value extends number ? NumberLiteralExprType<Value> : never;
|
|
33
|
+
export type ExprContextOf<Value> = Value extends Expr<ExprType, ExprCardinality, infer Context> ? Context : Value extends FieldRef | AppField<FieldScope> ? "record" : "standalone";
|
|
34
|
+
export type MergeContext<A extends ExprContext, B extends ExprContext> = "record" extends A | B ? "record" : "standalone";
|
|
35
|
+
export type ContextOfValues<Values extends readonly unknown[]> = Values extends readonly [infer Head, ...infer Rest] ? MergeContext<ExprContextOf<Head>, ContextOfValues<Rest>> : "standalone";
|
|
36
|
+
export type ComposedExpr<T extends ExprType, Values extends readonly unknown[], Cardinality extends ExprCardinality = "single"> = Expr<T, Cardinality, ContextOfValues<Values>>;
|
|
37
|
+
export type NumberLiteralExprType<N extends number> = number extends N ? "number" | "decimal" : `${N}` extends `${string}.${string}` ? "decimal" : "number";
|
|
38
|
+
export type NumericExprTypeOf<Value> = Extract<ExprTypeOf<Value>, "number" | "decimal">;
|
|
39
|
+
export type NumericPromotion<A, B> = "decimal" extends NumericExprTypeOf<A> | NumericExprTypeOf<B> ? "decimal" : "number";
|
|
40
|
+
export type DateMathPromotion<A, B> = ExprTypeOf<A> extends "datetime" ? "datetime" : ExprTypeOf<A> extends "date" ? "decimal" extends NumericExprTypeOf<B> ? "datetime" : "date" : NumericPromotion<A, B>;
|
|
41
|
+
export {};
|