@rippling/rippling-sdk 0.2.0-alpha.107 → 0.2.0-alpha.109
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/client.d.mts +10 -1
- package/client.d.mts.map +1 -1
- package/client.d.ts +10 -1
- package/client.d.ts.map +1 -1
- package/client.js +10 -1
- package/client.js.map +1 -1
- package/client.mjs +10 -1
- package/client.mjs.map +1 -1
- package/lib/charts/builders.d.mts +18 -19
- package/lib/charts/builders.d.mts.map +1 -1
- package/lib/charts/builders.d.ts +18 -19
- package/lib/charts/builders.d.ts.map +1 -1
- package/lib/charts/builders.js +35 -28
- package/lib/charts/builders.js.map +1 -1
- package/lib/charts/builders.mjs +35 -28
- package/lib/charts/builders.mjs.map +1 -1
- package/lib/charts/describe.d.mts +6 -7
- package/lib/charts/describe.d.mts.map +1 -1
- package/lib/charts/describe.d.ts +6 -7
- package/lib/charts/describe.d.ts.map +1 -1
- package/lib/charts/describe.js +26 -27
- package/lib/charts/describe.js.map +1 -1
- package/lib/charts/describe.mjs +27 -28
- package/lib/charts/describe.mjs.map +1 -1
- package/lib/charts/errors.d.mts +2 -6
- package/lib/charts/errors.d.mts.map +1 -1
- package/lib/charts/errors.d.ts +2 -6
- package/lib/charts/errors.d.ts.map +1 -1
- package/lib/charts/errors.js +2 -6
- package/lib/charts/errors.js.map +1 -1
- package/lib/charts/errors.mjs +2 -6
- package/lib/charts/errors.mjs.map +1 -1
- package/lib/charts/evaluate.d.mts +5 -7
- package/lib/charts/evaluate.d.mts.map +1 -1
- package/lib/charts/evaluate.d.ts +5 -7
- package/lib/charts/evaluate.d.ts.map +1 -1
- package/lib/charts/evaluate.js +21 -35
- package/lib/charts/evaluate.js.map +1 -1
- package/lib/charts/evaluate.mjs +22 -36
- package/lib/charts/evaluate.mjs.map +1 -1
- package/lib/charts/schema.d.mts +8 -97
- package/lib/charts/schema.d.mts.map +1 -1
- package/lib/charts/schema.d.ts +8 -97
- package/lib/charts/schema.d.ts.map +1 -1
- package/lib/charts/schema.js +186 -65
- package/lib/charts/schema.js.map +1 -1
- package/lib/charts/schema.mjs +185 -65
- package/lib/charts/schema.mjs.map +1 -1
- package/lib/charts/types.d.mts +40 -25
- package/lib/charts/types.d.mts.map +1 -1
- package/lib/charts/types.d.ts +40 -25
- package/lib/charts/types.d.ts.map +1 -1
- package/lib/charts/types.js +8 -10
- package/lib/charts/types.js.map +1 -1
- package/lib/charts/types.mjs +8 -10
- package/lib/charts/types.mjs.map +1 -1
- package/lib/charts/visualization-grammar.d.mts +66 -0
- package/lib/charts/visualization-grammar.d.mts.map +1 -0
- package/lib/charts/visualization-grammar.d.ts +66 -0
- package/lib/charts/visualization-grammar.d.ts.map +1 -0
- package/lib/charts/visualization-grammar.js +70 -0
- package/lib/charts/visualization-grammar.js.map +1 -0
- package/lib/charts/visualization-grammar.mjs +67 -0
- package/lib/charts/visualization-grammar.mjs.map +1 -0
- package/lib/charts/vocabulary.d.mts +7 -0
- package/lib/charts/vocabulary.d.mts.map +1 -0
- package/lib/charts/vocabulary.d.ts +7 -0
- package/lib/charts/vocabulary.d.ts.map +1 -0
- package/lib/charts/vocabulary.js +10 -0
- package/lib/charts/vocabulary.js.map +1 -0
- package/lib/charts/vocabulary.mjs +7 -0
- package/lib/charts/vocabulary.mjs.map +1 -0
- package/lib/charts.d.mts +3 -3
- package/lib/charts.d.mts.map +1 -1
- package/lib/charts.d.ts +3 -3
- package/lib/charts.d.ts.map +1 -1
- package/lib/charts.js +2 -1
- package/lib/charts.js.map +1 -1
- package/lib/charts.mjs +1 -1
- package/lib/charts.mjs.map +1 -1
- package/package.json +4 -2
- package/resources/card-transactions.d.mts +579 -0
- package/resources/card-transactions.d.mts.map +1 -0
- package/resources/card-transactions.d.ts +579 -0
- package/resources/card-transactions.d.ts.map +1 -0
- package/resources/card-transactions.js +116 -0
- package/resources/card-transactions.js.map +1 -0
- package/resources/card-transactions.mjs +112 -0
- package/resources/card-transactions.mjs.map +1 -0
- package/resources/earning-types.d.mts +50 -10
- package/resources/earning-types.d.mts.map +1 -1
- package/resources/earning-types.d.ts +50 -10
- package/resources/earning-types.d.ts.map +1 -1
- package/resources/earning-types.js +21 -2
- package/resources/earning-types.js.map +1 -1
- package/resources/earning-types.mjs +21 -2
- package/resources/earning-types.mjs.map +1 -1
- package/resources/index.d.mts +4 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +4 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +10 -4
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +4 -1
- package/resources/index.mjs.map +1 -1
- package/resources/reimbursements.d.mts +954 -0
- package/resources/reimbursements.d.mts.map +1 -0
- package/resources/reimbursements.d.ts +954 -0
- package/resources/reimbursements.d.ts.map +1 -0
- package/resources/reimbursements.js +140 -0
- package/resources/reimbursements.js.map +1 -0
- package/resources/reimbursements.mjs +136 -0
- package/resources/reimbursements.mjs.map +1 -0
- package/resources/spend-categories.d.mts +140 -0
- package/resources/spend-categories.d.mts.map +1 -0
- package/resources/spend-categories.d.ts +140 -0
- package/resources/spend-categories.d.ts.map +1 -0
- package/resources/spend-categories.js +83 -0
- package/resources/spend-categories.js.map +1 -0
- package/resources/spend-categories.mjs +79 -0
- package/resources/spend-categories.mjs.map +1 -0
- package/resources/workflows/executions.d.mts +153 -0
- package/resources/workflows/executions.d.mts.map +1 -0
- package/resources/workflows/executions.d.ts +153 -0
- package/resources/workflows/executions.d.ts.map +1 -0
- package/resources/workflows/executions.js +74 -0
- package/resources/workflows/executions.js.map +1 -0
- package/resources/workflows/executions.mjs +70 -0
- package/resources/workflows/executions.mjs.map +1 -0
- package/resources/workflows/index.d.mts +3 -0
- package/resources/workflows/index.d.mts.map +1 -0
- package/resources/workflows/index.d.ts +3 -0
- package/resources/workflows/index.d.ts.map +1 -0
- package/resources/workflows/index.js +9 -0
- package/resources/workflows/index.js.map +1 -0
- package/resources/workflows/index.mjs +4 -0
- package/resources/workflows/index.mjs.map +1 -0
- package/resources/workflows/workflows.d.mts +977 -0
- package/resources/workflows/workflows.d.mts.map +1 -0
- package/resources/workflows/workflows.d.ts +977 -0
- package/resources/workflows/workflows.d.ts.map +1 -0
- package/resources/workflows/workflows.js +246 -0
- package/resources/workflows/workflows.js.map +1 -0
- package/resources/workflows/workflows.mjs +241 -0
- package/resources/workflows/workflows.mjs.map +1 -0
- package/resources/workflows.d.mts +1 -972
- package/resources/workflows.d.mts.map +1 -1
- package/resources/workflows.d.ts +1 -972
- package/resources/workflows.d.ts.map +1 -1
- package/resources/workflows.js +2 -234
- package/resources/workflows.js.map +1 -1
- package/resources/workflows.mjs +1 -232
- package/resources/workflows.mjs.map +1 -1
- package/src/client.ts +63 -12
- package/src/lib/charts/README.md +35 -28
- package/src/lib/charts/agent-reference.md +73 -0
- package/src/lib/charts/builders.ts +51 -35
- package/src/lib/charts/capabilities.json +96 -0
- package/src/lib/charts/describe.ts +31 -29
- package/src/lib/charts/errors.ts +2 -6
- package/src/lib/charts/evaluate.ts +25 -38
- package/src/lib/charts/schema.ts +232 -66
- package/src/lib/charts/types.ts +42 -31
- package/src/lib/charts/visualization-grammar.ts +67 -0
- package/src/lib/charts/vocabulary.ts +7 -0
- package/src/lib/charts.ts +8 -1
- package/src/resources/card-transactions.ts +718 -0
- package/src/resources/earning-types.ts +52 -10
- package/src/resources/index.ts +22 -1
- package/src/resources/reimbursements.ts +1157 -0
- package/src/resources/spend-categories.ts +175 -0
- package/src/resources/workflows/executions.ts +191 -0
- package/src/resources/workflows/index.ts +15 -0
- package/src/resources/workflows/workflows.ts +1661 -0
- package/src/resources/workflows.ts +1 -1647
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/lib/charts/guards.d.mts +0 -15
- package/lib/charts/guards.d.mts.map +0 -1
- package/lib/charts/guards.d.ts +0 -15
- package/lib/charts/guards.d.ts.map +0 -1
- package/lib/charts/guards.js +0 -38
- package/lib/charts/guards.js.map +0 -1
- package/lib/charts/guards.mjs +0 -34
- package/lib/charts/guards.mjs.map +0 -1
- package/src/lib/charts/guards.ts +0 -42
package/lib/charts/schema.mjs
CHANGED
|
@@ -1,71 +1,191 @@
|
|
|
1
|
+
import { boolean, finite, literal, null_, number, picklist, pipe, safeParse, strictObject, string, summarize, union, variant, } from 'valibot';
|
|
2
|
+
import { MalformedRuleError, UnknownNodeError } from "./errors.mjs";
|
|
1
3
|
import { CHART_RULE_CONTRACT_VERSION } from "./types.mjs";
|
|
2
|
-
|
|
4
|
+
import { EQUALITY_COMPARISON_KINDS, NUMERIC_COMPARISON_KINDS, RULE_CHANNELS, RULE_NODE_KINDS, } from "./vocabulary.mjs";
|
|
5
|
+
const ruleNodeKinds = new Set(RULE_NODE_KINDS);
|
|
6
|
+
const placeholderKeys = new Set(['$rule', 'channel']);
|
|
7
|
+
const ruleFieldKeys = ['$rule', 'channel', 'kind', 'value', 'left', 'right', 'cond', 'then', 'else'];
|
|
8
|
+
const scalarSchema = union([
|
|
9
|
+
pipe(number(), finite()),
|
|
10
|
+
string(),
|
|
11
|
+
boolean(),
|
|
12
|
+
null_(),
|
|
13
|
+
]);
|
|
14
|
+
const parsedRules = new WeakSet();
|
|
15
|
+
/** @deprecated Use `CHART_RULE_CONTRACT_VERSION` to identify the executable contract. */
|
|
3
16
|
export const CHART_RULE_SCHEMA_ID = `https://rippling.com/schemas/${CHART_RULE_CONTRACT_VERSION}.json`;
|
|
17
|
+
function hasOwn(value, key) {
|
|
18
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
19
|
+
}
|
|
20
|
+
const refNodeSchema = strictObject({ kind: literal('value') });
|
|
21
|
+
const literalNodeSchema = strictObject({ kind: literal('literal'), value: scalarSchema });
|
|
22
|
+
const numericLiteralNodeSchema = strictObject({
|
|
23
|
+
kind: literal('literal'),
|
|
24
|
+
value: pipe(number(), finite()),
|
|
25
|
+
});
|
|
26
|
+
const requiredColorLiteralNodeSchema = strictObject({
|
|
27
|
+
kind: literal('literal'),
|
|
28
|
+
value: string(),
|
|
29
|
+
});
|
|
30
|
+
const optionalColorLiteralNodeSchema = strictObject({
|
|
31
|
+
kind: literal('literal'),
|
|
32
|
+
value: union([string(), null_()]),
|
|
33
|
+
});
|
|
34
|
+
const comparisonOperandSchema = variant('kind', [refNodeSchema, literalNodeSchema]);
|
|
35
|
+
const numericOperandSchema = variant('kind', [refNodeSchema, numericLiteralNodeSchema]);
|
|
36
|
+
const equalityComparisonNodeSchema = strictObject({
|
|
37
|
+
kind: picklist(EQUALITY_COMPARISON_KINDS),
|
|
38
|
+
left: comparisonOperandSchema,
|
|
39
|
+
right: comparisonOperandSchema,
|
|
40
|
+
});
|
|
41
|
+
const numericComparisonNodeSchema = strictObject({
|
|
42
|
+
kind: picklist(NUMERIC_COMPARISON_KINDS),
|
|
43
|
+
left: numericOperandSchema,
|
|
44
|
+
right: numericOperandSchema,
|
|
45
|
+
});
|
|
46
|
+
const comparisonNodeSchema = variant('kind', [equalityComparisonNodeSchema, numericComparisonNodeSchema]);
|
|
47
|
+
const ifElseNodeSchema = strictObject({
|
|
48
|
+
kind: literal('ifElse'),
|
|
49
|
+
cond: comparisonNodeSchema,
|
|
50
|
+
then: requiredColorLiteralNodeSchema,
|
|
51
|
+
else: optionalColorLiteralNodeSchema,
|
|
52
|
+
});
|
|
4
53
|
/**
|
|
5
|
-
*
|
|
54
|
+
* Executable runtime schema for a chart-rule node.
|
|
6
55
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
56
|
+
* v1 is intentionally non-recursive. A comparison contains only `value` or
|
|
57
|
+
* literal operands, and a conditional contains one comparison plus two colour
|
|
58
|
+
* literals. Contract tests prove that every public builder output parses.
|
|
10
59
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
60
|
+
const ruleNodeSchema = variant('kind', [
|
|
61
|
+
refNodeSchema,
|
|
62
|
+
literalNodeSchema,
|
|
63
|
+
equalityComparisonNodeSchema,
|
|
64
|
+
numericComparisonNodeSchema,
|
|
65
|
+
ifElseNodeSchema,
|
|
66
|
+
]);
|
|
67
|
+
/** Runtime schema for the `{$rule, channel}` value embedded in a chart option. */
|
|
68
|
+
const rulePlaceholderSchema = strictObject({
|
|
69
|
+
$rule: ifElseNodeSchema,
|
|
70
|
+
channel: picklist(RULE_CHANNELS),
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Runtime schema for either a bare rule node or a chart-option placeholder.
|
|
74
|
+
* Persisted and agent-authored JSON crosses this boundary as `unknown`.
|
|
75
|
+
*/
|
|
76
|
+
export const chartRuleSchema = union([
|
|
77
|
+
rulePlaceholderSchema,
|
|
78
|
+
ruleNodeSchema,
|
|
79
|
+
]);
|
|
80
|
+
/** Parse untrusted chart-rule JSON and return an immutable validated clone. */
|
|
81
|
+
export function parseChartRule(input) {
|
|
82
|
+
if (isParsedRule(input)) {
|
|
83
|
+
return input;
|
|
84
|
+
}
|
|
85
|
+
preflight(input);
|
|
86
|
+
const result = safeParse(chartRuleSchema, input);
|
|
87
|
+
if (result.success) {
|
|
88
|
+
return markParsedRule(result.output);
|
|
89
|
+
}
|
|
90
|
+
throw new MalformedRuleError(summarize(result.issues));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Valibot's object schemas use `key in input`, which also reads inherited
|
|
94
|
+
* properties. Reject inherited rule fields before parsing so prototype data
|
|
95
|
+
* cannot supply required operands or bypass the flat v1 contract.
|
|
96
|
+
*/
|
|
97
|
+
function preflight(input) {
|
|
98
|
+
assertNoInheritedRuleFields(input);
|
|
99
|
+
const root = unwrapPlaceholder(input);
|
|
100
|
+
assertNoInheritedRuleFields(root);
|
|
101
|
+
assertKnownNode(root);
|
|
102
|
+
if (!isRecord(root) || !hasOwn(root, 'kind')) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (root['kind'] === 'ifElse') {
|
|
106
|
+
inspectChildren(root, ['cond', 'then', 'else']);
|
|
107
|
+
const condition = root['cond'];
|
|
108
|
+
inspectComparison(condition);
|
|
109
|
+
}
|
|
110
|
+
else if (typeof root['kind'] === 'string' && isComparisonKind(root['kind'])) {
|
|
111
|
+
inspectComparison(root);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function inspectComparison(value) {
|
|
115
|
+
assertNoInheritedRuleFields(value);
|
|
116
|
+
assertKnownNode(value);
|
|
117
|
+
if (isRecord(value)) {
|
|
118
|
+
inspectChildren(value, ['left', 'right']);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function inspectChildren(parent, keys) {
|
|
122
|
+
for (const key of keys) {
|
|
123
|
+
if (hasOwn(parent, key)) {
|
|
124
|
+
const child = parent[key];
|
|
125
|
+
assertNoInheritedRuleFields(child);
|
|
126
|
+
assertKnownNode(child);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function assertNoInheritedRuleFields(value) {
|
|
131
|
+
if (!isRecord(value)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (const key of ruleFieldKeys) {
|
|
135
|
+
if (key in value && !hasOwn(value, key)) {
|
|
136
|
+
throw new MalformedRuleError(`a chart rule must not inherit the ${key} property`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function assertKnownNode(value) {
|
|
141
|
+
if (isRecord(value) &&
|
|
142
|
+
hasOwn(value, 'kind') &&
|
|
143
|
+
typeof value['kind'] === 'string' &&
|
|
144
|
+
!ruleNodeKinds.has(value['kind'])) {
|
|
145
|
+
throw new UnknownNodeError(value['kind']);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function isComparisonKind(kind) {
|
|
149
|
+
return kind !== 'literal' && kind !== 'value' && kind !== 'ifElse' && ruleNodeKinds.has(kind);
|
|
150
|
+
}
|
|
151
|
+
function isRecord(value) {
|
|
152
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
153
|
+
}
|
|
154
|
+
function unwrapPlaceholder(input) {
|
|
155
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input) || !hasOwn(input, '$rule')) {
|
|
156
|
+
return input;
|
|
157
|
+
}
|
|
158
|
+
const unexpectedKey = Object.keys(input).find((key) => !placeholderKeys.has(key));
|
|
159
|
+
if (unexpectedKey !== undefined) {
|
|
160
|
+
throw new MalformedRuleError(`a rule placeholder has an unexpected property: ${unexpectedKey}`);
|
|
161
|
+
}
|
|
162
|
+
return input.$rule;
|
|
163
|
+
}
|
|
164
|
+
function isParsedRule(input) {
|
|
165
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input) && parsedRules.has(input);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Mark the validated clone so `evaluate(parseChartRule(input), ctx)` does not
|
|
169
|
+
* reparse the full value for every datum. Freezing prevents a caller from
|
|
170
|
+
* mutating a trusted value after validation.
|
|
171
|
+
*/
|
|
172
|
+
function markParsedRule(rule) {
|
|
173
|
+
const stack = [rule];
|
|
174
|
+
const seen = new WeakSet();
|
|
175
|
+
while (stack.length > 0) {
|
|
176
|
+
const current = stack.pop();
|
|
177
|
+
if (!current || seen.has(current)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
seen.add(current);
|
|
181
|
+
for (const value of Object.values(current)) {
|
|
182
|
+
if (value !== null && typeof value === 'object') {
|
|
183
|
+
stack.push(value);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
Object.freeze(current);
|
|
187
|
+
}
|
|
188
|
+
parsedRules.add(rule);
|
|
189
|
+
return rule;
|
|
190
|
+
}
|
|
71
191
|
//# sourceMappingURL=schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","sourceRoot":"","sources":["../../src/lib/charts/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"schema.mjs","sourceRoot":"","sources":["../../src/lib/charts/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EAEP,MAAM,EACN,OAAO,EACP,KAAK,EACL,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,MAAM,EACN,SAAS,EACT,KAAK,EACL,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,qBAAiB;AAChE,OAAO,EAAE,2BAA2B,EAA0D,oBAAgB;AAC9G,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,aAAa,EACb,eAAe,GAChB,yBAAqB;AAEtB,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;AACpE,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AAC3E,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE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ACxB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAChD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAkB,CAAC;AAC5B,CAAC"}
|
package/lib/charts/types.d.mts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chart rule vocabulary — shared types.
|
|
3
3
|
*
|
|
4
|
-
* A rule is a small, serializable
|
|
4
|
+
* A rule is a small, serializable value discriminated by `kind`. The
|
|
5
5
|
* agent builds it with the helpers in `builders.ts`, which emit it wrapped in a
|
|
6
6
|
* `{$rule}` placeholder — the same idea as the `{$fn}` placeholders a chart
|
|
7
7
|
* already emits. The renderer resolves it with `evaluate`; the settings panel
|
|
8
8
|
* reads it with `describe`. All three agree because a node can only ever be one
|
|
9
|
-
* of the kinds defined here — the closed set the `chartRuleSchema`
|
|
9
|
+
* of the kinds defined here — the closed set the executable `chartRuleSchema`
|
|
10
|
+
* validates at runtime.
|
|
10
11
|
*
|
|
11
|
-
* v1 is
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* v1 is deliberately non-recursive: compare this datum's `value` or a literal
|
|
13
|
+
* against another literal, then choose between two colour literals. Rules may
|
|
14
|
+
* not appear inside operands or branches. Richer expressions require a future
|
|
15
|
+
* contract version.
|
|
14
16
|
*/
|
|
17
|
+
import { COMPARISON_KINDS, RULE_CHANNELS } from "./vocabulary.mjs";
|
|
15
18
|
export declare const CHART_RULE_CONTRACT_VERSION: "chart_rule.v1";
|
|
16
19
|
export type ChartRuleContractVersion = typeof CHART_RULE_CONTRACT_VERSION;
|
|
17
20
|
/** A leaf value a rule can carry or resolve to. */
|
|
@@ -20,53 +23,64 @@ export type Scalar = number | string | boolean | null;
|
|
|
20
23
|
export type RefNode = {
|
|
21
24
|
kind: 'value';
|
|
22
25
|
};
|
|
23
|
-
export interface LiteralNode {
|
|
26
|
+
export interface LiteralNode<TValue extends Scalar = Scalar> {
|
|
24
27
|
kind: 'literal';
|
|
25
|
-
value:
|
|
28
|
+
value: TValue;
|
|
26
29
|
}
|
|
27
|
-
export type
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
export type ComparisonOperandNode = RefNode | LiteralNode;
|
|
31
|
+
export type NumericOperandNode = RefNode | LiteralNode<number>;
|
|
32
|
+
export type ComparisonKind = (typeof COMPARISON_KINDS)[number];
|
|
33
|
+
export interface EqualityComparisonNode {
|
|
34
|
+
kind: 'equals' | 'isNot';
|
|
35
|
+
left: ComparisonOperandNode;
|
|
36
|
+
right: ComparisonOperandNode;
|
|
32
37
|
}
|
|
38
|
+
export interface NumericComparisonNode {
|
|
39
|
+
kind: Exclude<ComparisonKind, EqualityComparisonNode['kind']>;
|
|
40
|
+
left: NumericOperandNode;
|
|
41
|
+
right: NumericOperandNode;
|
|
42
|
+
}
|
|
43
|
+
export type ComparisonNode = EqualityComparisonNode | NumericComparisonNode;
|
|
44
|
+
/** A node whose evaluated result is valid as a `when(...)` condition in v1. */
|
|
45
|
+
export type ConditionNode = ComparisonNode;
|
|
33
46
|
/** The conditional-value form produced by `when(cond, then, else)`. */
|
|
34
47
|
export interface IfElseNode {
|
|
35
48
|
kind: 'ifElse';
|
|
36
|
-
cond:
|
|
37
|
-
then:
|
|
38
|
-
else:
|
|
49
|
+
cond: ConditionNode;
|
|
50
|
+
then: LiteralNode<string>;
|
|
51
|
+
else: LiteralNode<string | null>;
|
|
39
52
|
}
|
|
40
|
-
/** Any node
|
|
53
|
+
/** Any top-level node accepted by the v1 runtime boundary. */
|
|
41
54
|
export type RuleNode = RefNode | LiteralNode | ComparisonNode | IfElseNode;
|
|
42
55
|
/**
|
|
43
56
|
* The chart channel a rule drives. v1 supports colour only — a rule decides the
|
|
44
57
|
* colour of a series/datum. Other channels (opacity, label visibility, …) are
|
|
45
58
|
* the documented roadmap and would be added here.
|
|
46
59
|
*/
|
|
47
|
-
export type RuleChannel =
|
|
60
|
+
export type RuleChannel = (typeof RULE_CHANNELS)[number];
|
|
48
61
|
/**
|
|
49
|
-
* What a builder returns: a rule
|
|
62
|
+
* What a builder returns: a flat rule value, marked so the renderer can find it, and
|
|
50
63
|
* tagged with the channel it targets. `channel: 'color'` says this resolves to a
|
|
51
64
|
* colour — so a reader sees the target without inferring it from where it sits.
|
|
52
65
|
*/
|
|
53
66
|
export interface RulePlaceholder {
|
|
54
|
-
$rule:
|
|
67
|
+
$rule: IfElseNode;
|
|
55
68
|
channel: RuleChannel;
|
|
56
69
|
}
|
|
57
|
-
/** A placeholder, or
|
|
70
|
+
/** A placeholder, or a bare node — what `evaluate` and `describe` accept. */
|
|
58
71
|
export type Rule = RulePlaceholder | RuleNode;
|
|
72
|
+
type DeepReadonly<T> = T extends object ? {
|
|
73
|
+
readonly [Key in keyof T]: DeepReadonly<T[Key]>;
|
|
74
|
+
} : T;
|
|
75
|
+
/** The deeply frozen value returned by `parseChartRule`. */
|
|
76
|
+
export type ParsedRule = DeepReadonly<Rule>;
|
|
59
77
|
/** What a rule is evaluated against: the current datum's value. */
|
|
60
78
|
export interface RuleContext {
|
|
61
79
|
value: number;
|
|
62
80
|
}
|
|
63
81
|
/** The result of evaluating a node. */
|
|
64
82
|
export type RuleValue = Scalar;
|
|
65
|
-
/**
|
|
66
|
-
* The deepest a rule may nest before `evaluate`/`describe` refuse it. Real rules
|
|
67
|
-
* are a handful of levels; this only stops a pathological deserialized tree from
|
|
68
|
-
* overflowing the stack. Far below the JS call-stack limit.
|
|
69
|
-
*/
|
|
83
|
+
/** @deprecated v1 is non-recursive. Retained for source compatibility. */
|
|
70
84
|
export declare const MAX_RULE_DEPTH = 256;
|
|
71
85
|
export type ControlRole = 'rule' | 'comparison' | 'ref' | 'literal';
|
|
72
86
|
/** A node as the panel should show it: a label, its editable value, its parts. */
|
|
@@ -76,4 +90,5 @@ export interface Control {
|
|
|
76
90
|
value?: Scalar;
|
|
77
91
|
parts?: Control[];
|
|
78
92
|
}
|
|
93
|
+
export {};
|
|
79
94
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,yBAAqB;AAE/D,eAAO,MAAM,2BAA2B,EAAG,eAAwB,CAAC;AACpE,MAAM,MAAM,wBAAwB,GAAG,OAAO,2BAA2B,CAAC;AAE1E,mDAAmD;AACnD,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAMtD,gFAAgF;AAChF,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,WAAW,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACzD,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,WAAW,CAAC;AAC1D,MAAM,MAAM,kBAA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E,GAAG,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,GAAG,CAAC,CAAC;AAElG,4DAA4D;AAC5D,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AAM5C,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uCAAuC;AACvC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,0EAA0E;AAC1E,eAAO,MAAM,cAAc,MAAM,CAAC;AAMlC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,KAAK,GAAG,SAAS,CAAC;AAEpE,kFAAkF;AAClF,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;CACnB"}
|
package/lib/charts/types.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chart rule vocabulary — shared types.
|
|
3
3
|
*
|
|
4
|
-
* A rule is a small, serializable
|
|
4
|
+
* A rule is a small, serializable value discriminated by `kind`. The
|
|
5
5
|
* agent builds it with the helpers in `builders.ts`, which emit it wrapped in a
|
|
6
6
|
* `{$rule}` placeholder — the same idea as the `{$fn}` placeholders a chart
|
|
7
7
|
* already emits. The renderer resolves it with `evaluate`; the settings panel
|
|
8
8
|
* reads it with `describe`. All three agree because a node can only ever be one
|
|
9
|
-
* of the kinds defined here — the closed set the `chartRuleSchema`
|
|
9
|
+
* of the kinds defined here — the closed set the executable `chartRuleSchema`
|
|
10
|
+
* validates at runtime.
|
|
10
11
|
*
|
|
11
|
-
* v1 is
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* v1 is deliberately non-recursive: compare this datum's `value` or a literal
|
|
13
|
+
* against another literal, then choose between two colour literals. Rules may
|
|
14
|
+
* not appear inside operands or branches. Richer expressions require a future
|
|
15
|
+
* contract version.
|
|
14
16
|
*/
|
|
17
|
+
import { COMPARISON_KINDS, RULE_CHANNELS } from "./vocabulary.js";
|
|
15
18
|
export declare const CHART_RULE_CONTRACT_VERSION: "chart_rule.v1";
|
|
16
19
|
export type ChartRuleContractVersion = typeof CHART_RULE_CONTRACT_VERSION;
|
|
17
20
|
/** A leaf value a rule can carry or resolve to. */
|
|
@@ -20,53 +23,64 @@ export type Scalar = number | string | boolean | null;
|
|
|
20
23
|
export type RefNode = {
|
|
21
24
|
kind: 'value';
|
|
22
25
|
};
|
|
23
|
-
export interface LiteralNode {
|
|
26
|
+
export interface LiteralNode<TValue extends Scalar = Scalar> {
|
|
24
27
|
kind: 'literal';
|
|
25
|
-
value:
|
|
28
|
+
value: TValue;
|
|
26
29
|
}
|
|
27
|
-
export type
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
export type ComparisonOperandNode = RefNode | LiteralNode;
|
|
31
|
+
export type NumericOperandNode = RefNode | LiteralNode<number>;
|
|
32
|
+
export type ComparisonKind = (typeof COMPARISON_KINDS)[number];
|
|
33
|
+
export interface EqualityComparisonNode {
|
|
34
|
+
kind: 'equals' | 'isNot';
|
|
35
|
+
left: ComparisonOperandNode;
|
|
36
|
+
right: ComparisonOperandNode;
|
|
32
37
|
}
|
|
38
|
+
export interface NumericComparisonNode {
|
|
39
|
+
kind: Exclude<ComparisonKind, EqualityComparisonNode['kind']>;
|
|
40
|
+
left: NumericOperandNode;
|
|
41
|
+
right: NumericOperandNode;
|
|
42
|
+
}
|
|
43
|
+
export type ComparisonNode = EqualityComparisonNode | NumericComparisonNode;
|
|
44
|
+
/** A node whose evaluated result is valid as a `when(...)` condition in v1. */
|
|
45
|
+
export type ConditionNode = ComparisonNode;
|
|
33
46
|
/** The conditional-value form produced by `when(cond, then, else)`. */
|
|
34
47
|
export interface IfElseNode {
|
|
35
48
|
kind: 'ifElse';
|
|
36
|
-
cond:
|
|
37
|
-
then:
|
|
38
|
-
else:
|
|
49
|
+
cond: ConditionNode;
|
|
50
|
+
then: LiteralNode<string>;
|
|
51
|
+
else: LiteralNode<string | null>;
|
|
39
52
|
}
|
|
40
|
-
/** Any node
|
|
53
|
+
/** Any top-level node accepted by the v1 runtime boundary. */
|
|
41
54
|
export type RuleNode = RefNode | LiteralNode | ComparisonNode | IfElseNode;
|
|
42
55
|
/**
|
|
43
56
|
* The chart channel a rule drives. v1 supports colour only — a rule decides the
|
|
44
57
|
* colour of a series/datum. Other channels (opacity, label visibility, …) are
|
|
45
58
|
* the documented roadmap and would be added here.
|
|
46
59
|
*/
|
|
47
|
-
export type RuleChannel =
|
|
60
|
+
export type RuleChannel = (typeof RULE_CHANNELS)[number];
|
|
48
61
|
/**
|
|
49
|
-
* What a builder returns: a rule
|
|
62
|
+
* What a builder returns: a flat rule value, marked so the renderer can find it, and
|
|
50
63
|
* tagged with the channel it targets. `channel: 'color'` says this resolves to a
|
|
51
64
|
* colour — so a reader sees the target without inferring it from where it sits.
|
|
52
65
|
*/
|
|
53
66
|
export interface RulePlaceholder {
|
|
54
|
-
$rule:
|
|
67
|
+
$rule: IfElseNode;
|
|
55
68
|
channel: RuleChannel;
|
|
56
69
|
}
|
|
57
|
-
/** A placeholder, or
|
|
70
|
+
/** A placeholder, or a bare node — what `evaluate` and `describe` accept. */
|
|
58
71
|
export type Rule = RulePlaceholder | RuleNode;
|
|
72
|
+
type DeepReadonly<T> = T extends object ? {
|
|
73
|
+
readonly [Key in keyof T]: DeepReadonly<T[Key]>;
|
|
74
|
+
} : T;
|
|
75
|
+
/** The deeply frozen value returned by `parseChartRule`. */
|
|
76
|
+
export type ParsedRule = DeepReadonly<Rule>;
|
|
59
77
|
/** What a rule is evaluated against: the current datum's value. */
|
|
60
78
|
export interface RuleContext {
|
|
61
79
|
value: number;
|
|
62
80
|
}
|
|
63
81
|
/** The result of evaluating a node. */
|
|
64
82
|
export type RuleValue = Scalar;
|
|
65
|
-
/**
|
|
66
|
-
* The deepest a rule may nest before `evaluate`/`describe` refuse it. Real rules
|
|
67
|
-
* are a handful of levels; this only stops a pathological deserialized tree from
|
|
68
|
-
* overflowing the stack. Far below the JS call-stack limit.
|
|
69
|
-
*/
|
|
83
|
+
/** @deprecated v1 is non-recursive. Retained for source compatibility. */
|
|
70
84
|
export declare const MAX_RULE_DEPTH = 256;
|
|
71
85
|
export type ControlRole = 'rule' | 'comparison' | 'ref' | 'literal';
|
|
72
86
|
/** A node as the panel should show it: a label, its editable value, its parts. */
|
|
@@ -76,4 +90,5 @@ export interface Control {
|
|
|
76
90
|
value?: Scalar;
|
|
77
91
|
parts?: Control[];
|
|
78
92
|
}
|
|
93
|
+
export {};
|
|
79
94
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,wBAAqB;AAE/D,eAAO,MAAM,2BAA2B,EAAG,eAAwB,CAAC;AACpE,MAAM,MAAM,wBAAwB,GAAG,OAAO,2BAA2B,CAAC;AAE1E,mDAAmD;AACnD,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAMtD,gFAAgF;AAChF,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,WAAW,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACzD,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,qBAAqB,GAAG,OA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AAI,CAAC,SAAS,MAAM,GAAG;IAAE,QAAQ,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,GAAG,CAAC,CAAC;AAElG,4DAA4D;AAC5D,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AAM5C,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uCAAuC;AACvC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,0EAA0E;AAC1E,eAAO,MAAM,cAAc,MAAM,CAAC;AAMlC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,YAAY,GAAG,KAAK,GAAG,SAAS,CAAC;AAEpE,kFAAkF;AAClF,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;CACnB"}
|
package/lib/charts/types.js
CHANGED
|
@@ -2,24 +2,22 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Chart rule vocabulary — shared types.
|
|
4
4
|
*
|
|
5
|
-
* A rule is a small, serializable
|
|
5
|
+
* A rule is a small, serializable value discriminated by `kind`. The
|
|
6
6
|
* agent builds it with the helpers in `builders.ts`, which emit it wrapped in a
|
|
7
7
|
* `{$rule}` placeholder — the same idea as the `{$fn}` placeholders a chart
|
|
8
8
|
* already emits. The renderer resolves it with `evaluate`; the settings panel
|
|
9
9
|
* reads it with `describe`. All three agree because a node can only ever be one
|
|
10
|
-
* of the kinds defined here — the closed set the `chartRuleSchema`
|
|
10
|
+
* of the kinds defined here — the closed set the executable `chartRuleSchema`
|
|
11
|
+
* validates at runtime.
|
|
11
12
|
*
|
|
12
|
-
* v1 is
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* v1 is deliberately non-recursive: compare this datum's `value` or a literal
|
|
14
|
+
* against another literal, then choose between two colour literals. Rules may
|
|
15
|
+
* not appear inside operands or branches. Richer expressions require a future
|
|
16
|
+
* contract version.
|
|
15
17
|
*/
|
|
16
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
19
|
exports.MAX_RULE_DEPTH = exports.CHART_RULE_CONTRACT_VERSION = void 0;
|
|
18
20
|
exports.CHART_RULE_CONTRACT_VERSION = 'chart_rule.v1';
|
|
19
|
-
/**
|
|
20
|
-
* The deepest a rule may nest before `evaluate`/`describe` refuse it. Real rules
|
|
21
|
-
* are a handful of levels; this only stops a pathological deserialized tree from
|
|
22
|
-
* overflowing the stack. Far below the JS call-stack limit.
|
|
23
|
-
*/
|
|
21
|
+
/** @deprecated v1 is non-recursive. Retained for source compatibility. */
|
|
24
22
|
exports.MAX_RULE_DEPTH = 256;
|
|
25
23
|
//# sourceMappingURL=types.js.map
|
package/lib/charts/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAIU,QAAA,2BAA2B,GAAG,eAAwB,CAAC;AAyFpE,0EAA0E;AAC7D,QAAA,cAAc,GAAG,GAAG,CAAC"}
|
package/lib/charts/types.mjs
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chart rule vocabulary — shared types.
|
|
3
3
|
*
|
|
4
|
-
* A rule is a small, serializable
|
|
4
|
+
* A rule is a small, serializable value discriminated by `kind`. The
|
|
5
5
|
* agent builds it with the helpers in `builders.ts`, which emit it wrapped in a
|
|
6
6
|
* `{$rule}` placeholder — the same idea as the `{$fn}` placeholders a chart
|
|
7
7
|
* already emits. The renderer resolves it with `evaluate`; the settings panel
|
|
8
8
|
* reads it with `describe`. All three agree because a node can only ever be one
|
|
9
|
-
* of the kinds defined here — the closed set the `chartRuleSchema`
|
|
9
|
+
* of the kinds defined here — the closed set the executable `chartRuleSchema`
|
|
10
|
+
* validates at runtime.
|
|
10
11
|
*
|
|
11
|
-
* v1 is
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* v1 is deliberately non-recursive: compare this datum's `value` or a literal
|
|
13
|
+
* against another literal, then choose between two colour literals. Rules may
|
|
14
|
+
* not appear inside operands or branches. Richer expressions require a future
|
|
15
|
+
* contract version.
|
|
14
16
|
*/
|
|
15
17
|
export const CHART_RULE_CONTRACT_VERSION = 'chart_rule.v1';
|
|
16
|
-
/**
|
|
17
|
-
* The deepest a rule may nest before `evaluate`/`describe` refuse it. Real rules
|
|
18
|
-
* are a handful of levels; this only stops a pathological deserialized tree from
|
|
19
|
-
* overflowing the stack. Far below the JS call-stack limit.
|
|
20
|
-
*/
|
|
18
|
+
/** @deprecated v1 is non-recursive. Retained for source compatibility. */
|
|
21
19
|
export const MAX_RULE_DEPTH = 256;
|
|
22
20
|
//# sourceMappingURL=types.mjs.map
|
package/lib/charts/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/lib/charts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,CAAC,MAAM,2BAA2B,GAAG,eAAwB,CAAC;AAyFpE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC"}
|