derive-dashboards 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/cache.mjs +2 -1
  2. package/dist/cli/add.mjs +1 -1
  3. package/dist/cli/doctor.mjs +39 -24
  4. package/dist/core/document/display.d.mts +63 -0
  5. package/dist/core/document/display.mjs +139 -0
  6. package/dist/core/engine/version.d.mts +5 -4
  7. package/dist/core/engine/version.mjs +5 -4
  8. package/dist/core/error/codes.d.mts +2 -0
  9. package/dist/core/error/codes.mjs +2 -0
  10. package/dist/core/index.d.mts +9 -7
  11. package/dist/core/index.mjs +7 -5
  12. package/dist/core/model/validate/drill.mjs +6 -15
  13. package/dist/core/model/validate/fields.mjs +130 -0
  14. package/dist/core/model/validate/index.mjs +11 -3
  15. package/dist/core/model/validate/known-members.mjs +133 -0
  16. package/dist/core/model/validate/known-nested.mjs +85 -0
  17. package/dist/core/model/validate/known.mjs +94 -0
  18. package/dist/core/model/validate/source.mjs +8 -1
  19. package/dist/core/query/alias.mjs +11 -1
  20. package/dist/core/query/drill/selection.d.mts +7 -2
  21. package/dist/core/query/drill/selection.mjs +18 -15
  22. package/dist/core/result/columns.d.mts +10 -1
  23. package/dist/core/result/columns.mjs +21 -2
  24. package/dist/core/result/time-axis.d.mts +23 -0
  25. package/dist/core/result/time-axis.mjs +72 -0
  26. package/dist/core/result/types.d.mts +36 -1
  27. package/dist/core/schema/answer-parts.mjs +23 -1
  28. package/dist/core/schema/answers.d.mts +203 -0
  29. package/dist/core/schema/answers.mjs +1 -0
  30. package/dist/core/schema/tools.d.mts +2 -0
  31. package/dist/core/schema/tools.mjs +27 -1
  32. package/dist/core/time/bucket.mjs +8 -2
  33. package/dist/core/types/api.d.mts +1 -1
  34. package/dist/core/types/api.mjs +1 -1
  35. package/dist/drill-change.mjs +1 -1
  36. package/dist/drill-seal.mjs +1 -0
  37. package/dist/endpoints/index.d.mts +3 -0
  38. package/dist/execute.mjs +13 -7
  39. package/dist/index.mjs +6 -1
  40. package/dist/react/Dashboard.d.mts +4 -0
  41. package/dist/react/Dashboard.mjs +12 -1
  42. package/dist/react/Tile.mjs +11 -4
  43. package/dist/react/context.d.mts +2 -1
  44. package/dist/react/drill/Bars.mjs +2 -2
  45. package/dist/react/drill/props.mjs +2 -1
  46. package/dist/react/index.d.mts +5 -2
  47. package/dist/react/index.mjs +4 -2
  48. package/dist/react/renderers/index.d.mts +3 -21
  49. package/dist/react/renderers/index.mjs +3 -3
  50. package/dist/react/renderers/list.d.mts +2 -1
  51. package/dist/react/renderers/list.mjs +8 -11
  52. package/dist/react/renderers/props.d.mts +26 -0
  53. package/dist/react/scope.d.mts +4 -0
  54. package/dist/react/scope.mjs +19 -2
  55. package/dist/react/series-slots.d.mts +37 -0
  56. package/dist/react/series-slots.mjs +71 -0
  57. package/dist/react/series.d.mts +19 -6
  58. package/dist/react/series.mjs +75 -74
  59. package/dist/recharts/bar.mjs +5 -4
  60. package/dist/recharts/line.mjs +5 -4
  61. package/dist/recharts/parts.mjs +29 -14
  62. package/dist/skills/derive-dashboards/SKILL.md +1 -1
  63. package/dist/store/apply.mjs +3 -1
  64. package/package.json +4 -4
@@ -0,0 +1,130 @@
1
+ import { issue } from "./issues.mjs";
2
+ // src/model/validate/fields.ts
3
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
4
+ /** A field name's letters. Field names are plain identifiers, so each code unit is a letter. */
5
+ const letters = (word) => Array.from({ length: word.length }, (_v, i) => word.charAt(i));
6
+ /** How many single-letter edits turn one word into the other. */
7
+ function distance(a, b) {
8
+ const across = letters(b);
9
+ let row = Array.from({ length: across.length + 1 }, (_v, i) => i);
10
+ for (const [i, letter] of letters(a).entries()) {
11
+ const next = [i + 1];
12
+ for (const [j, other] of across.entries()) {
13
+ const swap = (row[j] ?? 0) + (letter === other ? 0 : 1);
14
+ next.push(Math.min(swap, (row[j + 1] ?? 0) + 1, (next[j] ?? 0) + 1));
15
+ }
16
+ row = next;
17
+ }
18
+ return row[across.length] ?? 0;
19
+ }
20
+ /** The known field a misspelled one most likely meant: at most two edits away, and under half its letters. */
21
+ function nearest(key, known) {
22
+ const [best] = known.map((name) => ({
23
+ name,
24
+ edits: distance(key.toLowerCase(), name.toLowerCase())
25
+ })).toSorted((x, y) => x.edits - y.edits);
26
+ return best !== void 0 && best.edits <= 2 && best.edits * 2 <= key.length ? best.name : void 0;
27
+ }
28
+ const meant = (near) => near === void 0 ? "" : ` Did you mean "${near}"?`;
29
+ function unknownField(what, key, known) {
30
+ return `"${key}" is not a field of ${what}.${meant(nearest(key, known))} Its fields are ${known.join(", ")}.`;
31
+ }
32
+ /** What a value is, in a word, for a message that says what it should have been. */
33
+ function kindOf(value) {
34
+ if (Array.isArray(value)) return "a list";
35
+ if (value === null) return "null";
36
+ return typeof value === "object" ? "an object" : `a ${typeof value}`;
37
+ }
38
+ /**
39
+ * Named when a value is not the object, map or list it must be. Left alone, a list where an
40
+ * object belongs has none of the object's fields, so each would be read as absent: a rule's
41
+ * `when` given as a list would match everyone.
42
+ */
43
+ function misshapen(what, wanted, value, path) {
44
+ return issue("MODEL_SHAPE", path, `${capital(what)} is ${wanted}, not ${kindOf(value)}.`);
45
+ }
46
+ const capital = (what) => what.charAt(0).toUpperCase() + what.slice(1);
47
+ /**
48
+ * An object with these fields and no others; `inside` checks the values of some of them, and
49
+ * `removed` says where a field an earlier release had went. A value that is there and is not an
50
+ * object is named.
51
+ */
52
+ function fields(what, known, inside = {}, removed = {}) {
53
+ return (value, path) => {
54
+ if (value === void 0) return [];
55
+ if (!isObject(value)) return [misshapen(what, "an object", value, path)];
56
+ const unknown = Object.keys(value).filter((key) => !known.includes(key)).map((key) => {
57
+ const went = Object.hasOwn(removed, key) ? removed[key] : void 0;
58
+ return issue("MODEL_FIELD_UNKNOWN", [...path, key], went ?? unknownField(what, key, known));
59
+ });
60
+ const deeper = Object.entries(inside).flatMap(([key, check]) => check(value[key], [...path, key]));
61
+ return [...unknown, ...deeper];
62
+ };
63
+ }
64
+ /** Every value of a map by name (sources, measures). A value that is there and is not a map is named. */
65
+ function mapOf(what, check) {
66
+ return (value, path) => {
67
+ if (value === void 0) return [];
68
+ if (!isObject(value)) return [misshapen(what, "a map by name", value, path)];
69
+ return Object.entries(value).flatMap(([key, v]) => check(v, [...path, key]));
70
+ };
71
+ }
72
+ /** Every entry of a list (a policy's rules, a filter's all). A value that is there and is not a list is named. */
73
+ function listOf(what, check = () => []) {
74
+ return (value, path) => {
75
+ if (value === void 0) return [];
76
+ if (!Array.isArray(value)) return [misshapen(what, "a list", value, path)];
77
+ return value.flatMap((v, i) => check(v, [...path, i]));
78
+ };
79
+ }
80
+ /** A field that is a word or an object (a policy's name or its rules): the word passes, the rest is checked. */
81
+ const orWord = (check) => (value, path) => typeof value === "string" ? [] : check(value, path);
82
+ /** A field that is one of a few words or an object (a rule's allow): another word is named. */
83
+ function orWords(what, words, check) {
84
+ return (value, path) => {
85
+ if (typeof value !== "string") return check(value, path);
86
+ if (words.includes(value)) return [];
87
+ const named = words.map((word) => `"${word}"`).join(", ");
88
+ return [issue("MODEL_SHAPE", path, `${capital(what)} is ${named} or an object, not "${value}".`)];
89
+ };
90
+ }
91
+ /** A field that is a word or a list of words (a rule's channel, a policy's via). */
92
+ function wordOrList(what) {
93
+ return (value, path) => {
94
+ return value === void 0 || (Array.isArray(value) ? value : [value]).every((word) => typeof word === "string") ? [] : [misshapen(what, "a word or a list of words", value, path)];
95
+ };
96
+ }
97
+ /** A field that is `false` or an object (a source's drill). */
98
+ const orFalse = (check) => (value, path) => value === false ? [] : check(value, path);
99
+ /**
100
+ * The check of the first of these fields an object holds itself: a filter's `all`, a tenant's
101
+ * `via`. An object that holds none is read by `otherwise`.
102
+ */
103
+ function byKey(what, variants, otherwise) {
104
+ return (value, path) => {
105
+ if (value === void 0) return [];
106
+ if (!isObject(value)) return [misshapen(what, "an object", value, path)];
107
+ const key = Object.keys(variants).find((k) => Object.hasOwn(value, k));
108
+ const check = key === void 0 ? otherwise : variants[key];
109
+ return check === void 0 ? [] : check(value, path);
110
+ };
111
+ }
112
+ /** The check of an object's `kind`. A kind that does not exist is named by the shape check. */
113
+ function byKind(what, variants) {
114
+ return (value, path) => {
115
+ if (value === void 0) return [];
116
+ if (!isObject(value)) return [misshapen(what, "an object", value, path)];
117
+ const kind = value["kind"];
118
+ const check = typeof kind === "string" && Object.hasOwn(variants, kind) ? variants[kind] : void 0;
119
+ return check === void 0 ? [] : check(value, path);
120
+ };
121
+ }
122
+ /** An object that must hold one of these fields and holds none of them. */
123
+ function lacking(what, keys) {
124
+ return (value, path) => {
125
+ if (!isObject(value)) return [];
126
+ const near = Object.keys(value).map((key) => nearest(key, keys)).find((name) => name !== void 0);
127
+ return [issue("MODEL_SHAPE", path, `${what} holds one of ${keys.join(", ")}.${meant(near)}`)];
128
+ };
129
+ }
130
+ export { byKey, byKind, fields, lacking, listOf, mapOf, orFalse, orWord, orWords, wordOrList };
@@ -1,4 +1,5 @@
1
1
  import { nameIssues, when } from "./issues.mjs";
2
+ import { fieldIssues } from "./known.mjs";
2
3
  import { rowPolicyIssues } from "./policy.mjs";
3
4
  import { shapeIssues } from "./shape.mjs";
4
5
  import { sourceIssues } from "./source.mjs";
@@ -12,19 +13,26 @@ import { viaCycleIssues } from "./via.mjs";
12
13
  * job of the `check` command.
13
14
  */
14
15
  function validateModel(model) {
15
- const shaped = shapeIssues(model);
16
- if (shaped.length > 0) return [...headerIssues(model), ...shaped];
16
+ const shaped = oncePerPlace([...shapeIssues(model), ...fieldIssues(model)]);
17
+ if (shaped.some((i) => i.code === "MODEL_SHAPE")) return [...headerIssues(model), ...shaped];
17
18
  const sources = Object.entries(model.sources ?? {});
18
19
  return [
19
20
  ...headerIssues(model),
21
+ ...shaped,
20
22
  ...Object.entries(model.policies ?? {}).flatMap(([name, policy]) => [...nameIssues(name, ["policies", name]), ...rowPolicyIssues(policy, ["policies", name])]),
21
23
  ...when(sources.length === 0, "SOURCES_EMPTY", ["sources"], "A model needs a source."),
22
24
  ...sources.flatMap(([name, source]) => sourceIssues(model, name, source)),
23
25
  ...viaCycleIssues(model)
24
26
  ];
25
27
  }
28
+ /** Each problem once: the shape check and the field check may both name a value that is not an object. */
29
+ function oncePerPlace(issues) {
30
+ const place = (i) => `${i.code} ${i.path.join(".")}`;
31
+ return issues.filter((i, at) => issues.findIndex((j) => place(j) === place(i)) === at);
32
+ }
26
33
  function headerIssues(model) {
27
- const keys = model.tenant?.keys ?? [];
34
+ const given = model.tenant?.keys;
35
+ const keys = Array.isArray(given) ? given : [];
28
36
  return [
29
37
  ...when(model.version !== 1, "MODEL_VERSION", ["version"], "The model version must be 1."),
30
38
  ...keys.flatMap((key, i) => nameIssues(key, [
@@ -0,0 +1,133 @@
1
+ import { byKey, byKind, fields, orWord } from "./fields.mjs";
2
+ import { expr, fieldsOf, filter } from "./known-nested.mjs";
3
+ // src/model/validate/known-members.ts
4
+ const META = [
5
+ "label",
6
+ "description",
7
+ "sensitive",
8
+ "hidden"
9
+ ];
10
+ const HINTS = [
11
+ "drill",
12
+ "format",
13
+ "buckets",
14
+ "tones"
15
+ ];
16
+ const OVER = [
17
+ "of",
18
+ "where",
19
+ "format",
20
+ "partitionBy"
21
+ ];
22
+ const NUMERIC = fields("an exact number", fieldsOf()(["scale", "stored"]));
23
+ const over = {
24
+ of: orWord(expr),
25
+ where: filter,
26
+ numeric: orWord(NUMERIC)
27
+ };
28
+ const SUMMED = fields("a sum, min or max measure", fieldsOf()([
29
+ "kind",
30
+ "merge",
31
+ "numeric",
32
+ "unit",
33
+ ...OVER,
34
+ ...META
35
+ ]), over);
36
+ const MEASURE = byKind("a measure", {
37
+ count: fields("a count measure", fieldsOf()([
38
+ "kind",
39
+ "merge",
40
+ "distinct",
41
+ "where",
42
+ ...META
43
+ ]), { where: filter }),
44
+ sum: SUMMED,
45
+ min: SUMMED,
46
+ max: SUMMED,
47
+ avg: fields("an avg measure", fieldsOf()([
48
+ "kind",
49
+ "merge",
50
+ "numeric",
51
+ ...OVER,
52
+ ...META
53
+ ]), over),
54
+ percentile: fields("a percentile measure", fieldsOf()([
55
+ "kind",
56
+ "merge",
57
+ "p",
58
+ ...OVER,
59
+ ...META
60
+ ]), over),
61
+ ratio: fields("a ratio measure", fieldsOf()([
62
+ "kind",
63
+ "merge",
64
+ "numerator",
65
+ "denominator",
66
+ "format",
67
+ ...META
68
+ ]))
69
+ });
70
+ const STORAGE = byKey("a time storage", {
71
+ timestamp: fields("a time storage", ["timestamp"], { timestamp: fields("a timestamp storage", fieldsOf()([
72
+ "zone",
73
+ "ambiguous",
74
+ "nonexistent"
75
+ ])) }),
76
+ iso_utc_fixed: fields("a time storage", ["iso_utc_fixed"], { iso_utc_fixed: fields("an iso_utc_fixed storage", fieldsOf()(["constraint", "fractionDigits"])) })
77
+ }, () => []);
78
+ const hints = { format: fields("a number format", fieldsOf()(["unit", "minor"])) };
79
+ const PLAIN = fields("a number or boolean dimension", fieldsOf()([
80
+ "kind",
81
+ "column",
82
+ ...HINTS,
83
+ ...META
84
+ ]), hints);
85
+ const DIMENSION = byKind("a dimension", {
86
+ string: fields("a string dimension", fieldsOf()([
87
+ "kind",
88
+ "column",
89
+ "values",
90
+ "search",
91
+ "collation",
92
+ ...HINTS,
93
+ ...META
94
+ ]), hints),
95
+ number: PLAIN,
96
+ boolean: PLAIN,
97
+ time: fields("a time dimension", fieldsOf()([
98
+ "kind",
99
+ "column",
100
+ "storage",
101
+ ...HINTS,
102
+ ...META
103
+ ]), {
104
+ ...hints,
105
+ storage: orWord(STORAGE)
106
+ }),
107
+ ref: fields("a ref dimension", fieldsOf()([
108
+ "kind",
109
+ "join",
110
+ "label",
111
+ ...HINTS,
112
+ ...META
113
+ ]), hints),
114
+ bucket: fields("a bucket dimension", fieldsOf()([
115
+ "kind",
116
+ "of",
117
+ "edges",
118
+ "labels",
119
+ ...HINTS,
120
+ ...META
121
+ ]), hints),
122
+ expr: fields("an expr dimension", fieldsOf()([
123
+ "kind",
124
+ "expr",
125
+ "type",
126
+ ...HINTS,
127
+ ...META
128
+ ]), {
129
+ ...hints,
130
+ expr
131
+ })
132
+ });
133
+ export { DIMENSION, MEASURE };
@@ -0,0 +1,85 @@
1
+ import { byKey, fields, lacking, listOf } from "./fields.mjs";
2
+ // src/model/validate/known-nested.ts
3
+ /** The fields of `T`, every one and no other. */
4
+ const fieldsOf = () => (list) => list;
5
+ function filter(value, path) {
6
+ return FILTER(value, path);
7
+ }
8
+ const group = (key, inner) => fields(`a filter's ${key}`, [key], { [key]: inner });
9
+ const child = fields("a filter through a join", fieldsOf()(["join", "where"]), { where: filter });
10
+ const FILTER = byKey("a filter", {
11
+ all: group("all", listOf("a filter's all", filter)),
12
+ any: group("any", listOf("a filter's any", filter)),
13
+ not: group("not", filter),
14
+ some: group("some", child),
15
+ none: group("none", child),
16
+ member: fields("a filter", fieldsOf()([
17
+ "member",
18
+ "op",
19
+ "values",
20
+ "viewer",
21
+ "variable"
22
+ ]), { values: listOf("a filter's values") })
23
+ }, lacking("A filter", [
24
+ "all",
25
+ "any",
26
+ "not",
27
+ "some",
28
+ "none",
29
+ "member"
30
+ ]));
31
+ function policyFilter(value, path) {
32
+ return POLICY_FILTER(value, path);
33
+ }
34
+ const POLICY_FILTER = byKey("a row rule's filter", {
35
+ exists: () => [],
36
+ all: group("all", listOf("a filter's all", policyFilter)),
37
+ any: group("any", listOf("a filter's any", policyFilter)),
38
+ not: group("not", policyFilter)
39
+ }, fields("a row rule's filter", fieldsOf()([
40
+ "column",
41
+ "op",
42
+ "values",
43
+ "viewer"
44
+ ]), { values: listOf("a row rule's values") }));
45
+ function expr(value, path) {
46
+ return EXPR(value, path);
47
+ }
48
+ const CONDITION = fields("a case's condition", fieldsOf()([
49
+ "left",
50
+ "op",
51
+ "values"
52
+ ]), {
53
+ left: expr,
54
+ values: listOf("a condition's values")
55
+ });
56
+ const BRANCH = fields("a case's branch", fieldsOf()(["when", "then"]), {
57
+ when: CONDITION,
58
+ then: expr
59
+ });
60
+ const EXPR_FIELDS = fieldsOf()([
61
+ "col",
62
+ "lit",
63
+ "op",
64
+ "args",
65
+ "fn",
66
+ "case",
67
+ "else",
68
+ "datePart",
69
+ "of",
70
+ "elapsed"
71
+ ]);
72
+ const args = { args: listOf("an expression's args", expr) };
73
+ const EXPR = byKey("an expression", {
74
+ col: fields("a column expression", fieldsOf()(["col"])),
75
+ lit: fields("a literal", fieldsOf()(["lit"])),
76
+ op: fields("an arithmetic expression", fieldsOf()(["op", "args"]), args),
77
+ fn: fields("a function call", fieldsOf()(["fn", "args"]), args),
78
+ case: fields("a case expression", fieldsOf()(["case", "else"]), {
79
+ case: listOf("a case's branches", BRANCH),
80
+ else: expr
81
+ }),
82
+ datePart: fields("a datePart expression", fieldsOf()(["datePart", "of"])),
83
+ elapsed: fields("an elapsed expression", fieldsOf()(["elapsed"]), { elapsed: fields("elapsed", fieldsOf()(["start", "end"])) })
84
+ }, lacking("An expression", EXPR_FIELDS));
85
+ export { expr, fieldsOf, filter, policyFilter };
@@ -0,0 +1,94 @@
1
+ import { byKey, fields, lacking, listOf, mapOf, orFalse, orWord, orWords, wordOrList } from "./fields.mjs";
2
+ import { DIMENSION, MEASURE } from "./known-members.mjs";
3
+ import { fieldsOf, filter, policyFilter } from "./known-nested.mjs";
4
+ // src/model/validate/known.ts
5
+ const WHEN = fields("a rule's when", fieldsOf()([
6
+ "channel",
7
+ "roles",
8
+ "attribute"
9
+ ]), {
10
+ channel: wordOrList("a rule's channel"),
11
+ roles: listOf("a rule's roles"),
12
+ attribute: fields("a rule's attribute", fieldsOf()(["key", "in"]), { in: listOf("an attribute's in") })
13
+ });
14
+ const RULE = fields("a row rule", fieldsOf()([
15
+ "name",
16
+ "when",
17
+ "allow"
18
+ ]), {
19
+ when: WHEN,
20
+ allow: orWords("a row rule's allow", ["all", "none"], policyFilter)
21
+ });
22
+ const POLICY = fields("a policy", fieldsOf()(["rules"]), { rules: listOf("a policy's rules", RULE) });
23
+ const TENANT = fieldsOf()([
24
+ "columns",
25
+ "via",
26
+ "shared"
27
+ ]);
28
+ const POLICY_BINDING = fieldsOf()(["rules", "via"]);
29
+ const SOURCE = fields("a source", fieldsOf()([
30
+ "table",
31
+ "schema",
32
+ "sql",
33
+ "in",
34
+ "key",
35
+ "unproven",
36
+ "time",
37
+ "tenant",
38
+ "policy",
39
+ "acknowledgeOpenPolicy",
40
+ "where",
41
+ "records",
42
+ "noun",
43
+ "joins",
44
+ "measures",
45
+ "dimensions",
46
+ "segments",
47
+ "limits",
48
+ "drill"
49
+ ]), {
50
+ key: listOf("a source's key"),
51
+ tenant: byKey("a source's tenant", Object.fromEntries(TENANT.map((key) => [key, fields("a source's tenant", [key])])), lacking("A source's tenant", TENANT)),
52
+ policy: orWord(byKey("a source's policy", {
53
+ rules: POLICY,
54
+ via: fields("a source's policy", ["via"], { via: wordOrList("a policy's via") })
55
+ }, lacking("A source's policy", POLICY_BINDING))),
56
+ where: filter,
57
+ records: fields("a source's records", fieldsOf()([
58
+ "order",
59
+ "columns",
60
+ "title",
61
+ "key"
62
+ ]), {}, { link: "records.link was removed: pass itemLinks to deriveDashboards and the React UI instead." }),
63
+ noun: fields("a source's noun", fieldsOf()(["one", "other"])),
64
+ joins: mapOf("a source's joins", fields("a join", fieldsOf()([
65
+ "to",
66
+ "on",
67
+ "relationship",
68
+ "pick"
69
+ ]), {
70
+ on: listOf("a join's on"),
71
+ pick: listOf("a join's pick")
72
+ })),
73
+ measures: mapOf("a source's measures", MEASURE),
74
+ dimensions: mapOf("a source's dimensions", DIMENSION),
75
+ segments: mapOf("a source's segments", filter),
76
+ limits: fields("a source's limits", fieldsOf()(["maxWindowDays"])),
77
+ drill: orFalse(fields("a source's drill", fieldsOf()(["prefer"]), { prefer: listOf("a source's drill.prefer") }))
78
+ });
79
+ const MODEL = fields("the model", fieldsOf()([
80
+ "version",
81
+ "tenant",
82
+ "policies",
83
+ "sources",
84
+ "dimensions"
85
+ ]), {
86
+ tenant: fields("the model's tenant", fieldsOf()(["keys"]), { keys: listOf("the model's tenant keys") }),
87
+ policies: mapOf("the model's policies", POLICY),
88
+ sources: mapOf("the model's sources", SOURCE)
89
+ });
90
+ /** Every field of the model the library does not know, each at its place, with what was likely meant. */
91
+ function fieldIssues(model) {
92
+ return MODEL(model, []);
93
+ }
94
+ export { fieldIssues };
@@ -60,7 +60,7 @@ function tenantIssues(model, source, path) {
60
60
  const keys = tenantKeys(model);
61
61
  if (tenant === void 0) return when(keys.length > 0, "TENANT_BINDING_MISSING", path, "The model has tenant keys, so every source must say how it is tied to them (or that it is shared).");
62
62
  if ("via" in tenant) return viaJoinIssues(source, tenant.via, [...path, "via"]);
63
- if (!("columns" in tenant)) return [];
63
+ if (!("columns" in tenant)) return sharedIssues(tenant, path);
64
64
  return [...keys.flatMap((key) => when((tenant.columns[key] ?? "") === "", "TENANT_COLUMN_MISSING", [
65
65
  ...path,
66
66
  "columns",
@@ -71,6 +71,13 @@ function tenantIssues(model, source, path) {
71
71
  key
72
72
  ], `"${key}" is not a tenant key of the model.`))];
73
73
  }
74
+ /**
75
+ * A source is shared by saying `shared: true`. The engine reads the field's presence, so
76
+ * `shared: false` would read as shared and drop the tenant filter: it is refused.
77
+ */
78
+ function sharedIssues(tenant, path) {
79
+ return when(tenant.shared !== true, "MODEL_SHAPE", [...path, "shared"], "A shared source says shared: true. To tie it to a tenant, give columns or via in its place.");
80
+ }
74
81
  function filterIssues(model, name, source, path) {
75
82
  return [...source.where ? modelFilterIssues(model, name, source.where, [...path, "where"]) : [], ...Object.entries(source.segments ?? {}).flatMap(([segment, filter]) => modelFilterIssues(model, name, filter, [
76
83
  ...path,
@@ -17,4 +17,14 @@ function lineAlias(text) {
17
17
  const n = Number(text.slice(1));
18
18
  return text.startsWith("m") ? `m${n}` : `c${n}`;
19
19
  }
20
- export { aliasPart, lineAlias };
20
+ /**
21
+ * What a result column's id names: `t` is the time bucket, any other id the query's alias for
22
+ * it. Only for a column drawn before columns carried their `role` (a drill link sealed by an
23
+ * earlier release); every other reader reads the role.
24
+ */
25
+ function idRole(id) {
26
+ if (id === "t") return "time";
27
+ if (id.startsWith("m")) return "measure";
28
+ return id.startsWith("d") ? "dimension" : "calc";
29
+ }
30
+ export { aliasPart, idRole, lineAlias };
@@ -3,9 +3,13 @@ import { ResultCell, ResultColumn, ResultRows } from "../../result/types.mjs";
3
3
  import { Span } from "../../time/range.mjs";
4
4
  import { Calendar } from "../types.mjs";
5
5
  import { Cuts, Selection } from "./types.mjs";
6
+ /** A drawn answer's column. One sealed by an earlier release has no `role`, only its id. */
7
+ type DrawnColumn = Omit<ResultColumn, "role"> & {
8
+ role?: ResultColumn["role"];
9
+ };
6
10
  /** An answer as it was drawn: its columns and rows, its resolved range and its calendar. */
7
11
  export type Drawn = {
8
- columns: readonly ResultColumn[];
12
+ columns: readonly DrawnColumn[];
9
13
  rows: ResultRows;
10
14
  span?: Span;
11
15
  calendar: Calendar;
@@ -34,4 +38,5 @@ export type Picked = {
34
38
  * reason, for a row that cannot drill: a field the answer does not name, or an Other whose
35
39
  * kept set is too large or not whole.
36
40
  */
37
- export declare function rowSelection(drawn: Drawn, row: readonly ResultCell[]): Picked;
41
+ export declare function rowSelection(given: Drawn, row: readonly ResultCell[]): Picked;
42
+ export {};
@@ -1,14 +1,13 @@
1
+ import { roleOf } from "../../result/columns.mjs";
1
2
  import { isMark } from "../../result/marks.mjs";
2
- import { nextBucketStart } from "../../time/bucket.mjs";
3
- import { formatTextTime, parseDate, parseTextTime } from "../../time/instant.mjs";
4
- import { startOfDate } from "../../time/zone.mjs";
3
+ import { labelStart, nextBucketStart } from "../../time/bucket.mjs";
4
+ import { formatTextTime } from "../../time/instant.mjs";
5
5
  // src/query/drill/selection.ts
6
- /** The instant a bucket's label starts at: a local date in the zone, or an hour's instant. */
7
- function labelStart(label, grain, calendar) {
8
- if (grain === "hour") return parseTextTime(label);
9
- const date = parseDate(label);
10
- return date === void 0 ? void 0 : startOfDate(date, calendar.timezone);
11
- }
6
+ /** A drawn column with its role: its own, or for one an earlier release sealed, its id's. */
7
+ const withRole = (c) => ({
8
+ ...c,
9
+ role: roleOf(c)
10
+ });
12
11
  /** A time point's step: its bucket's exact window from the engine's calendar, cut to the range. */
13
12
  function bucketStep(drawn, column, cell) {
14
13
  if (column.member === void 0 || column.grain === void 0 || typeof cell !== "string") return void 0;
@@ -32,7 +31,7 @@ function groupParts(columns, row) {
32
31
  };
33
32
  for (const [i, column] of columns.entries()) {
34
33
  const cell = row[i] ?? null;
35
- if (!column.id.startsWith("d")) continue;
34
+ if (column.role !== "dimension") continue;
36
35
  if (column.member === void 0) return void 0;
37
36
  if (isMark(cell)) {
38
37
  if (cell.mark === "other") parts.others.push(i);
@@ -63,7 +62,7 @@ function keptStep(members, kept) {
63
62
  /** A dimension's own limit's Other: the rows outside every value the engine kept for it. */
64
63
  function segmentStep(drawn, at) {
65
64
  const column = drawn.columns[at];
66
- const index = drawn.columns.slice(0, at).filter((c) => c.id.startsWith("d")).length;
65
+ const index = drawn.columns.slice(0, at).filter((c) => c.role === "dimension").length;
67
66
  const kept = drawn.cuts?.segments.find(([i]) => i === index)?.[1];
68
67
  if (column?.member === void 0 || kept === void 0) return { refused: "OTHER_CUT" };
69
68
  const values = kept.flatMap((v) => typeof v === "object" && v !== null ? [] : [[v]]);
@@ -106,7 +105,7 @@ function clickedOf(columns, row) {
106
105
  const clicked = {};
107
106
  for (const [i, column] of columns.entries()) {
108
107
  const cell = row[i] ?? null;
109
- if ((column.id.startsWith("m") || column.id.startsWith("c")) && !isMark(cell)) clicked[column.id] = cell;
108
+ if ((column.role === "measure" || column.role === "calc") && !isMark(cell)) clicked[column.id] = cell;
110
109
  }
111
110
  return clicked;
112
111
  }
@@ -117,11 +116,15 @@ function clickedOf(columns, row) {
117
116
  * reason, for a row that cannot drill: a field the answer does not name, or an Other whose
118
117
  * kept set is too large or not whole.
119
118
  */
120
- function rowSelection(drawn, row) {
119
+ function rowSelection(given, row) {
120
+ const drawn = {
121
+ ...given,
122
+ columns: given.columns.map((c) => withRole(c))
123
+ };
121
124
  const time = timeSteps(drawn, row);
122
125
  const parts = groupParts(drawn.columns, row);
123
126
  if (time === void 0 || parts === void 0) return { refused: "OTHER_CUT" };
124
- const dims = drawn.columns.filter((c) => c.id.startsWith("d")).length;
127
+ const dims = drawn.columns.filter((c) => c.role === "dimension").length;
125
128
  const other = parts.others.length === 0 ? { steps: [] } : otherSteps(drawn, parts.others, dims);
126
129
  if ("refused" in other) return other;
127
130
  return { selection: {
@@ -135,7 +138,7 @@ function rowSelection(drawn, row) {
135
138
  }
136
139
  /** A row's time step, if the answer has a bucket column; undefined when its label does not read. */
137
140
  function timeSteps(drawn, row) {
138
- const at = drawn.columns.findIndex((c) => c.id === "t");
141
+ const at = drawn.columns.findIndex((c) => c.role === "time");
139
142
  const bucket = drawn.columns[at];
140
143
  if (bucket === void 0) return [];
141
144
  const step = bucketStep(drawn, bucket, row[at] ?? null);
@@ -1,8 +1,17 @@
1
1
  import { Model } from "../model/types.mjs";
2
2
  import { WireQuery } from "../query/types.mjs";
3
- import { RecordColumn, ResultColumn } from "./types.mjs";
3
+ import { ColumnRole, RecordColumn, ResultColumn } from "./types.mjs";
4
4
  /** A member's label: the model's, or its name in words. */
5
5
  export declare function memberLabel(id: string, label?: string): string;
6
+ /**
7
+ * What a column is: its `role`, or for a column that has none, what its id names. Every answer
8
+ * this release makes carries roles; one made a release back does not, and a browser can meet it
9
+ * while a deploy rolls out, so every reader asks here and none reads the id itself.
10
+ */
11
+ export declare function roleOf(column: {
12
+ id: string;
13
+ role?: ColumnRole;
14
+ }): ColumnRole;
6
15
  /**
7
16
  * The columns of a query's rows, in row order: the time bucket, the dimensions, the measures
8
17
  * and the calcs. Labels come from the model; a member reached through a join is named by the