@malloy-publisher/sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{DocumentStorageProvider-CyOJ0hqf.es.js → DocumentStorage-B04sZ5Ie.es.js} +2307 -2334
- package/dist/{DocumentStorageProvider-DGPQEd_l.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +20 -20
- package/dist/{RenderedResult-BnPzJ9Jf.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
- package/dist/RenderedResult-DVuGhatg.cjs.js +135 -0
- package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
- package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
- package/dist/builder/index.cjs.js +57 -52
- package/dist/builder/index.es.js +4421 -3738
- package/dist/client/api.d.ts +14 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/TileCard.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +20 -8
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +16 -4
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +31 -8
- package/dist/components/DashboardBuilder/controls.d.ts +8 -6
- package/dist/components/DashboardBuilder/document.d.ts +19 -5
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
- package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
- package/dist/components/DashboardBuilder/preview.d.ts +17 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
- package/dist/components/DocumentStorage/index.d.ts +1 -0
- package/dist/index.cjs.js +9 -9
- package/dist/index.es.js +508 -506
- package/dist/theme/resolveTheme.d.ts +1 -1
- package/dist/theme/types.d.ts +12 -2
- package/package.json +1 -1
- package/src/components/Dashboard/TileCard.tsx +8 -4
- package/src/components/Dashboard/telemetry.ts +20 -8
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +21 -3
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +468 -103
- package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
- package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
- package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
- package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
- package/src/components/DashboardBuilder/controls.spec.ts +53 -3
- package/src/components/DashboardBuilder/controls.ts +9 -7
- package/src/components/DashboardBuilder/document.ts +17 -5
- package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
- package/src/components/DashboardBuilder/malloyText.ts +4 -109
- package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
- package/src/components/DashboardBuilder/malloyTree.ts +954 -0
- package/src/components/DashboardBuilder/preview.spec.ts +18 -0
- package/src/components/DashboardBuilder/preview.ts +24 -6
- package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
- package/src/components/DashboardBuilder/readDocument.ts +144 -165
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
- package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
- package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
- package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Package/Package.tsx +12 -7
- package/src/components/RenderedResult/RenderedResult.tsx +21 -1
- package/src/components/given/GivensPanel.tsx +15 -3
- package/src/theme/buildTableCssVars.spec.ts +3 -0
- package/src/theme/buildTableCssVars.ts +6 -0
- package/src/theme/defaults.ts +16 -12
- package/src/theme/resolveTheme.spec.ts +14 -7
- package/src/theme/resolveTheme.ts +14 -8
- package/src/theme/types.ts +12 -2
- package/tsconfig.spec.json +5 -1
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +0 -115
- package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `malloyText.ts` is a hand-written scanner that is about to be deleted and
|
|
6
|
+
* replaced by a real-parser adapter. Its own spec (`malloyText.spec.ts`) tests
|
|
7
|
+
* internal functions that die with it. This file re-pins the same Malloy SHAPES
|
|
8
|
+
* end to end, through the public read/splice API only, so a regression in the
|
|
9
|
+
* replacement is caught rather than shipped.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, expect, it } from "bun:test";
|
|
13
|
+
import { readDashboardDocument, readFailed } from "./readDocument";
|
|
14
|
+
import { openDocument, spliced } from "./testing/fixtures";
|
|
15
|
+
|
|
16
|
+
describe("declarations under a source", () => {
|
|
17
|
+
// declarationsUnder / declarationLine / artifactLine: a source's own views
|
|
18
|
+
// and dimensions are found in file order, across more than one extension.
|
|
19
|
+
it("finds each source's own views and dimensions, across two extensions, in file order", async () => {
|
|
20
|
+
const doc = await openDocument(`##! experimental.givens
|
|
21
|
+
## artifact { title="T" tiles=["a -> x", "a -> y", "b -> z"] }
|
|
22
|
+
import "../m.malloy"
|
|
23
|
+
|
|
24
|
+
source: a is one extend {
|
|
25
|
+
dimension: cat is products.category
|
|
26
|
+
view: x is vx
|
|
27
|
+
view: y is { group_by: cat }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
source: b is two extend {
|
|
31
|
+
view: z is vz
|
|
32
|
+
}`);
|
|
33
|
+
expect(doc.sources.map((s) => s.name)).toEqual(["a", "b"]);
|
|
34
|
+
expect(doc.sources[0].dimensions).toEqual([
|
|
35
|
+
{ name: "cat", expression: "products.category" },
|
|
36
|
+
]);
|
|
37
|
+
expect(doc.tiles.map((t) => t.name)).toEqual(["x", "y", "z"]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("a tile expression's steps", () => {
|
|
42
|
+
// tileSteps: the plain and refined forms both resolve to a source and view.
|
|
43
|
+
it("reads a plain tile step and a refined one the same way", async () => {
|
|
44
|
+
const doc =
|
|
45
|
+
await openDocument(`## artifact { title="T" tiles=["a -> x", "a -> y + { limit: 5 }"] }
|
|
46
|
+
import "../m.malloy"
|
|
47
|
+
|
|
48
|
+
source: a is one extend {
|
|
49
|
+
view: x is vx
|
|
50
|
+
view: y is vy
|
|
51
|
+
}`);
|
|
52
|
+
expect(doc.tiles[0]).toMatchObject({ source: "a", name: "x" });
|
|
53
|
+
expect(doc.tiles[1]).toMatchObject({ source: "a", name: "y" });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// tileSteps returns undefined for anything but exactly one `->`, so a
|
|
57
|
+
// multi-stage pipeline is refused the same way a bare name is.
|
|
58
|
+
it("refuses a tile expression with more than one -> step", async () => {
|
|
59
|
+
const r = await readDashboardDocument(
|
|
60
|
+
`## artifact { title="T" tiles=["{ group_by: x } -> y -> z"] }`,
|
|
61
|
+
);
|
|
62
|
+
expect(r.ok).toBe(false);
|
|
63
|
+
if (readFailed(r)) expect(r.reason).toContain("source -> view");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("givens in both spellings", () => {
|
|
68
|
+
// givenDeclarations: one-per-line and the block form coexist in one file,
|
|
69
|
+
// in file order, each readable regardless of which header it sits under.
|
|
70
|
+
it("reads a one-per-line given and a block of givens in file order", async () => {
|
|
71
|
+
const doc = await openDocument(`##! experimental.givens
|
|
72
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
73
|
+
import "../m.malloy"
|
|
74
|
+
|
|
75
|
+
given: CATEGORY :: filter<string> is f''
|
|
76
|
+
|
|
77
|
+
given:
|
|
78
|
+
SINCE :: date is @2023-01-01
|
|
79
|
+
MIN_SALE :: number is 0
|
|
80
|
+
|
|
81
|
+
source: a is one extend {
|
|
82
|
+
view: x is vx
|
|
83
|
+
}`);
|
|
84
|
+
expect(doc.localGivens?.map((g) => g.name)).toEqual([
|
|
85
|
+
"CATEGORY",
|
|
86
|
+
"SINCE",
|
|
87
|
+
"MIN_SALE",
|
|
88
|
+
]);
|
|
89
|
+
expect(doc.localGivens?.[1]).toMatchObject({
|
|
90
|
+
type: "date",
|
|
91
|
+
default: "@2023-01-01",
|
|
92
|
+
});
|
|
93
|
+
expect(doc.localGivens?.[2]).toMatchObject({
|
|
94
|
+
type: "number",
|
|
95
|
+
default: "0",
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("a SQL literal that could be mistaken for the next declaration", () => {
|
|
101
|
+
// declarationExtent: `file:///…` reaches for `<word>:` just as readily as a
|
|
102
|
+
// real declaration does. Read as one, it would end the source's extent at
|
|
103
|
+
// that line — an anchor inside the SQL text rather than after the block.
|
|
104
|
+
it("does not read a URI inside a SQL literal as the next declaration", async () => {
|
|
105
|
+
const source = `## artifact { title="T" tiles=["s -> v"] }
|
|
106
|
+
source: s is duckdb.sql("""
|
|
107
|
+
select * from read_csv(
|
|
108
|
+
file:///data/orders.csv
|
|
109
|
+
)
|
|
110
|
+
""") extend {
|
|
111
|
+
view: v is { group_by: a }
|
|
112
|
+
}`;
|
|
113
|
+
const out = await spliced(source, (d) => {
|
|
114
|
+
d.tiles.push({
|
|
115
|
+
name: "w",
|
|
116
|
+
source: "s",
|
|
117
|
+
declaration: { kind: "reference", from: "vw" },
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
expect(out).toContain(
|
|
121
|
+
'""") extend {\n view: v is { group_by: a }\n\n view: w is vw\n}',
|
|
122
|
+
);
|
|
123
|
+
// Never inside the literal, and never ahead of the source line.
|
|
124
|
+
expect(out.indexOf("view: w")).toBeGreaterThan(
|
|
125
|
+
out.indexOf('""") extend'),
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// declarationExtent: the block itself can open on a LATER line than the
|
|
130
|
+
// `source:` line when the base is a multi-line SQL literal — an edit to
|
|
131
|
+
// this view has to land inside the extension, past the literal.
|
|
132
|
+
it("finds the block that opens after a multi-line SQL literal", async () => {
|
|
133
|
+
const source = `## artifact { title="T" tiles=["regional -> by_region"] }
|
|
134
|
+
source: regional is duckdb.sql("""
|
|
135
|
+
select region, sum(amount) as total from orders group by 1
|
|
136
|
+
""") extend {
|
|
137
|
+
view: by_region is { group_by: region }
|
|
138
|
+
}`;
|
|
139
|
+
const out = await spliced(source, (d) => {
|
|
140
|
+
d.tiles[0].filters = [{ field: "region", given: "REGION" }];
|
|
141
|
+
});
|
|
142
|
+
expect(out).toContain(
|
|
143
|
+
"view: by_region is { group_by: region where: region ~ $REGION }",
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// A brace inside the `"""` span used to be unresolvable by a text scan, so
|
|
148
|
+
// this refused outright. The lexer knows where the literal ends, so the
|
|
149
|
+
// tile is now added inside the right block instead.
|
|
150
|
+
it('adds a tile past a brace inside a """ span', async () => {
|
|
151
|
+
const source = `## artifact { title="T" tiles=["bad -> x"] }
|
|
152
|
+
source: bad is duckdb.sql("""
|
|
153
|
+
select {'region': 'West'} as s
|
|
154
|
+
""") extend {
|
|
155
|
+
view: x is y
|
|
156
|
+
}`;
|
|
157
|
+
const out = await spliced(source, (d) => {
|
|
158
|
+
d.tiles.push({
|
|
159
|
+
name: "w",
|
|
160
|
+
source: "bad",
|
|
161
|
+
declaration: { kind: "reference", from: "vw" },
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
expect(out).toContain(" select {'region': 'West'} as s");
|
|
165
|
+
expect(out).toContain("view: w is vw");
|
|
166
|
+
expect(out.indexOf("view: w is vw")).toBeGreaterThan(
|
|
167
|
+
out.indexOf('""") extend {'),
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("a blockless declaration's own extent", () => {
|
|
173
|
+
// declarationExtent: the LAST blockless view before the enclosing extend's
|
|
174
|
+
// own closing brace must not swallow that brace as if it were its own.
|
|
175
|
+
it("stops before the enclosing block's closing brace, not at it", async () => {
|
|
176
|
+
const source = `## artifact { title="T" tiles=["a -> by_cat", "a -> by_brand"] }
|
|
177
|
+
source: a is one extend {
|
|
178
|
+
view: by_cat is by_category
|
|
179
|
+
view: by_brand is by_brand_view
|
|
180
|
+
}`;
|
|
181
|
+
const out = await spliced(source, (d) => {
|
|
182
|
+
d.tiles = d.tiles.filter((t) => t.name !== "by_brand");
|
|
183
|
+
});
|
|
184
|
+
expect(out).toContain(
|
|
185
|
+
"source: a is one extend {\n view: by_cat is by_category\n}",
|
|
186
|
+
);
|
|
187
|
+
expect(out).not.toContain("by_brand");
|
|
188
|
+
expect(out.match(/^}/gm)).toHaveLength(1);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// declarationExtent: a tag line between a blockless view and the next
|
|
192
|
+
// declaration is skipped whole, not scanned for braces — deleting the
|
|
193
|
+
// FIRST view must not take the tag that belongs to the one after it.
|
|
194
|
+
it("does not count a tag line's brace between a blockless view and the next", async () => {
|
|
195
|
+
const source = `## artifact { title="T" tiles=["a -> by_cat", "a -> by_brand"] }
|
|
196
|
+
source: a is one extend {
|
|
197
|
+
view: by_cat is by_category
|
|
198
|
+
# drill { to=self }
|
|
199
|
+
view: by_brand is by_brand_view
|
|
200
|
+
}`;
|
|
201
|
+
const out = await spliced(source, (d) => {
|
|
202
|
+
d.tiles = d.tiles.filter((t) => t.name !== "by_cat");
|
|
203
|
+
});
|
|
204
|
+
expect(out).toContain(
|
|
205
|
+
"source: a is one extend {\n # drill { to=self }\n view: by_brand is by_brand_view\n}",
|
|
206
|
+
);
|
|
207
|
+
expect(out).not.toContain("by_cat");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// declarationExtent: the stop condition matches ANY `<word>:` line, so a
|
|
211
|
+
// `join_one:` block right after a blockless view has to stop the same way
|
|
212
|
+
// a `view:` would — and survive whole when that view is removed.
|
|
213
|
+
it("stops at a join_one following a blockless view", async () => {
|
|
214
|
+
const source = `## artifact { title="T" tiles=["a -> by_cat", "a -> by_brand"] }
|
|
215
|
+
source: a is one extend {
|
|
216
|
+
view: by_cat is by_category
|
|
217
|
+
join_one: other is other_source on other.id = id
|
|
218
|
+
view: by_brand is by_brand_view
|
|
219
|
+
}`;
|
|
220
|
+
const out = await spliced(source, (d) => {
|
|
221
|
+
d.tiles = d.tiles.filter((t) => t.name !== "by_cat");
|
|
222
|
+
});
|
|
223
|
+
expect(out).toContain(
|
|
224
|
+
" join_one: other is other_source on other.id = id\n view: by_brand is by_brand_view\n}",
|
|
225
|
+
);
|
|
226
|
+
expect(out).not.toContain("by_cat");
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("text that masks structure inside a declaration", () => {
|
|
231
|
+
// declarationExtent: a brace inside a trailing `//` comment is text, not
|
|
232
|
+
// structure — retagging the view AFTER the commented one must land above
|
|
233
|
+
// that view's own line, not somewhere inside the commented view's body.
|
|
234
|
+
it("does not count a brace inside a trailing comment when finding where a view ends", async () => {
|
|
235
|
+
const source = `## artifact { title="T" tiles=["a -> kpis", "a -> other"] }
|
|
236
|
+
source: a is scoped_orders extend {
|
|
237
|
+
view: kpis is {
|
|
238
|
+
group_by: cat // the { brace here is unbalanced
|
|
239
|
+
aggregate: n is count()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
view: other is { aggregate: m is count() }
|
|
243
|
+
}`;
|
|
244
|
+
const out = await spliced(source, (d) => {
|
|
245
|
+
d.tiles[1].colspan = 6;
|
|
246
|
+
});
|
|
247
|
+
expect(out).toContain(
|
|
248
|
+
" # colspan=6\n view: other is { aggregate: m is count() }",
|
|
249
|
+
);
|
|
250
|
+
expect(out).not.toContain("colspan=6\n group_by: cat");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// declarationExtent: `//` inside a quoted literal is not a comment, so a
|
|
254
|
+
// brace that follows it on the same line is still real structure.
|
|
255
|
+
it("still counts a brace that follows a // inside a quoted literal", async () => {
|
|
256
|
+
const source = `## artifact { title="T" tiles=["a -> x", "a -> y"] }
|
|
257
|
+
source: a is one extend {
|
|
258
|
+
view: x is { where: path ~ 'a//b' }
|
|
259
|
+
view: y is vy
|
|
260
|
+
}`;
|
|
261
|
+
const out = await spliced(source, (d) => {
|
|
262
|
+
d.tiles[1].colspan = 4;
|
|
263
|
+
});
|
|
264
|
+
expect(out).toContain(" # colspan=4\n view: y is vy");
|
|
265
|
+
expect(out).not.toContain("colspan=4\n view: x");
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// declarationExtent: a brace inside a single-quoted filter literal is text,
|
|
269
|
+
// not structure — same for one holding a stray `}`.
|
|
270
|
+
it("does not count a brace inside a single-quoted literal", async () => {
|
|
271
|
+
for (const literal of ["'a{b'", "'a}b'"]) {
|
|
272
|
+
const source = `## artifact { title="T" tiles=["a -> kpis", "a -> other"] }
|
|
273
|
+
source: a is one extend {
|
|
274
|
+
view: kpis is {
|
|
275
|
+
where: path ~ ${literal}
|
|
276
|
+
aggregate: n is count()
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
view: other is { aggregate: m is count() }
|
|
280
|
+
}`;
|
|
281
|
+
const out = await spliced(source, (d) => {
|
|
282
|
+
d.tiles[1].colspan = 4;
|
|
283
|
+
});
|
|
284
|
+
expect(out).toContain(
|
|
285
|
+
" # colspan=4\n view: other is { aggregate: m is count() }",
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Same masking, double-quoted.
|
|
291
|
+
it("does not count a brace inside a double-quoted literal", async () => {
|
|
292
|
+
const source = `## artifact { title="T" tiles=["a -> kpis", "a -> other"] }
|
|
293
|
+
source: a is one extend {
|
|
294
|
+
view: kpis is {
|
|
295
|
+
where: path ~ "a{b"
|
|
296
|
+
aggregate: n is count()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
view: other is { aggregate: m is count() }
|
|
300
|
+
}`;
|
|
301
|
+
const out = await spliced(source, (d) => {
|
|
302
|
+
d.tiles[1].colspan = 4;
|
|
303
|
+
});
|
|
304
|
+
expect(out).toContain(
|
|
305
|
+
" # colspan=4\n view: other is { aggregate: m is count() }",
|
|
306
|
+
);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe("depth counting inside a view body", () => {
|
|
311
|
+
// viewBodyStage1: the same masking, one level down — a brace inside a
|
|
312
|
+
// trailing comment must not push a real depth-1 where: to depth 2, where
|
|
313
|
+
// it would stop being read (or written) as the tile's own filter.
|
|
314
|
+
it("does not let a brace inside a trailing comment inflate the depth count", async () => {
|
|
315
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
316
|
+
source: a is one extend {
|
|
317
|
+
view: kpis is {
|
|
318
|
+
group_by: cat // the { brace here is unbalanced
|
|
319
|
+
where: cat ~ $CATEGORY
|
|
320
|
+
aggregate: n is count()
|
|
321
|
+
}
|
|
322
|
+
}`;
|
|
323
|
+
const before = await openDocument(source);
|
|
324
|
+
expect(before.tiles[0].filters).toEqual([
|
|
325
|
+
{ field: "cat", given: "CATEGORY" },
|
|
326
|
+
]);
|
|
327
|
+
const out = await spliced(source, (d) => {
|
|
328
|
+
d.tiles[0].colspan = 4;
|
|
329
|
+
});
|
|
330
|
+
expect(out).toContain(
|
|
331
|
+
" group_by: cat // the { brace here is unbalanced\n where: cat ~ $CATEGORY\n",
|
|
332
|
+
);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// viewBodyStage1: a brace inside a quoted literal on a depth-1 where: line
|
|
336
|
+
// must not throw off the count that decides a LATER where: line's depth.
|
|
337
|
+
it("does not let a brace inside a quoted literal inflate the depth count", async () => {
|
|
338
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
339
|
+
source: a is one extend {
|
|
340
|
+
view: kpis is {
|
|
341
|
+
where: path ~ 'a{b'
|
|
342
|
+
where: cat ~ $CATEGORY
|
|
343
|
+
aggregate: n is count()
|
|
344
|
+
}
|
|
345
|
+
}`;
|
|
346
|
+
const before = await openDocument(source);
|
|
347
|
+
// Both where: lines are seen at depth 1: the literal's phantom brace
|
|
348
|
+
// would otherwise push the second one to depth 2 and drop it.
|
|
349
|
+
expect(before.tiles[0].filters).toEqual([
|
|
350
|
+
{ field: "cat", given: "CATEGORY" },
|
|
351
|
+
]);
|
|
352
|
+
const out = await spliced(source, (d) => {
|
|
353
|
+
d.tiles[0].filters = [{ field: "cat", given: "BRAND" }];
|
|
354
|
+
});
|
|
355
|
+
expect(out).toContain(
|
|
356
|
+
" where: path ~ 'a{b'\n aggregate: n is count()\n where: cat ~ $BRAND",
|
|
357
|
+
);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
describe("a where: sharing a line with the body's own brace", () => {
|
|
362
|
+
// viewBodyStage1: no line of its own to match a whole-line check against —
|
|
363
|
+
// re-binding the same value must be a no-op, not a duplicate append.
|
|
364
|
+
it("round-trips a where: that shares the opening line with the body's brace", async () => {
|
|
365
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
366
|
+
source: a is one extend {
|
|
367
|
+
view: kpis is { where: category ~ $CATEGORY
|
|
368
|
+
aggregate: n is count()
|
|
369
|
+
}
|
|
370
|
+
}`;
|
|
371
|
+
const before = await openDocument(source);
|
|
372
|
+
expect(before.tiles[0].filters).toEqual([
|
|
373
|
+
{ field: "category", given: "CATEGORY" },
|
|
374
|
+
]);
|
|
375
|
+
const out = await spliced(source, (d) => {
|
|
376
|
+
d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
|
|
377
|
+
});
|
|
378
|
+
expect(out).toBe(source);
|
|
379
|
+
expect(out.match(/where:/g)).toHaveLength(1);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// Same, sharing the closing line — the old scan returned as soon as it saw
|
|
383
|
+
// the brace close, before ever looking at the where: beside it.
|
|
384
|
+
it("round-trips a where: that shares the closing line with the body's brace", async () => {
|
|
385
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
386
|
+
source: a is one extend {
|
|
387
|
+
view: kpis is {
|
|
388
|
+
aggregate: n is count()
|
|
389
|
+
where: category ~ $CATEGORY }
|
|
390
|
+
}`;
|
|
391
|
+
const before = await openDocument(source);
|
|
392
|
+
expect(before.tiles[0].filters).toEqual([
|
|
393
|
+
{ field: "category", given: "CATEGORY" },
|
|
394
|
+
]);
|
|
395
|
+
const out = await spliced(source, (d) => {
|
|
396
|
+
d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
|
|
397
|
+
});
|
|
398
|
+
expect(out).toBe(source);
|
|
399
|
+
expect(out.match(/where:/g)).toHaveLength(1);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
describe("a one-liner body's where:", () => {
|
|
404
|
+
// viewBodyStage1: body opens AND closes on the declaration line — its
|
|
405
|
+
// where: is reported once, through the one-liner, never duplicated.
|
|
406
|
+
it("does not double-collect a one-liner's where:", async () => {
|
|
407
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
408
|
+
source: a is one extend {
|
|
409
|
+
view: kpis is { aggregate: n is count(), where: cat ~ $CATEGORY }
|
|
410
|
+
}`;
|
|
411
|
+
const before = await openDocument(source);
|
|
412
|
+
expect(before.tiles[0].filters).toEqual([
|
|
413
|
+
{ field: "cat", given: "CATEGORY" },
|
|
414
|
+
]);
|
|
415
|
+
const out = await spliced(source, (d) => {
|
|
416
|
+
d.tiles[0].filters = [{ field: "cat", given: "CATEGORY" }];
|
|
417
|
+
});
|
|
418
|
+
expect(out).toBe(source);
|
|
419
|
+
expect(out.match(/where:/g)).toHaveLength(1);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
describe("a nested nest:'s own where:", () => {
|
|
424
|
+
// viewBodyStage1: the scan tracks actual brace depth, not which line the
|
|
425
|
+
// text sits on — a nest's where: stays excluded even sharing a line with
|
|
426
|
+
// the outer body's own depth-1 where:, and must never be lifted to the
|
|
427
|
+
// tile's own filters.
|
|
428
|
+
it("excludes a nested nest's where: even sharing a line with the outer one", async () => {
|
|
429
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
430
|
+
source: a is one extend {
|
|
431
|
+
view: kpis is {
|
|
432
|
+
group_by: category
|
|
433
|
+
nest: by_period is {
|
|
434
|
+
where: period ~ $PERIOD
|
|
435
|
+
aggregate: n is count()
|
|
436
|
+
}, where: cat ~ $CATEGORY
|
|
437
|
+
}
|
|
438
|
+
}`;
|
|
439
|
+
const before = await openDocument(source);
|
|
440
|
+
expect(before.tiles[0].filters).toEqual([
|
|
441
|
+
{ field: "cat", given: "CATEGORY" },
|
|
442
|
+
]);
|
|
443
|
+
const out = await spliced(source, (d) => {
|
|
444
|
+
d.tiles[0].filters = [{ field: "cat", given: "BRAND" }];
|
|
445
|
+
});
|
|
446
|
+
// The nest's own binding is untouched, not rewritten alongside the outer one.
|
|
447
|
+
expect(out).toContain(
|
|
448
|
+
" where: period ~ $PERIOD\n aggregate: n is count()\n }\n where: cat ~ $BRAND",
|
|
449
|
+
);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe("a where: inside a multi-line string span", () => {
|
|
454
|
+
// viewBodyStage1: the naive scan did not carry a `"""` span's open state
|
|
455
|
+
// across lines, so a depth-1 line whose TEXT reads exactly like a real
|
|
456
|
+
// binding — `where: cat ~ $CATEGORY` — must still not be read as one when
|
|
457
|
+
// it sits inside a `"""` string opened by an earlier line: it is string
|
|
458
|
+
// content, not a statement, and BINDING_CLAUSE would otherwise match it.
|
|
459
|
+
it('does not read a where: from inside a multi-line """ span as a binding', async () => {
|
|
460
|
+
const source = `## artifact { title="T" tiles=["a -> kpis"] }
|
|
461
|
+
source: a is one extend {
|
|
462
|
+
view: kpis is {
|
|
463
|
+
where: note ~ f"""
|
|
464
|
+
where: cat ~ $CATEGORY
|
|
465
|
+
"""
|
|
466
|
+
aggregate: n is count()
|
|
467
|
+
}
|
|
468
|
+
}`;
|
|
469
|
+
const doc = await openDocument(source);
|
|
470
|
+
expect(doc.tiles[0].filters).toBeUndefined();
|
|
471
|
+
// An unrelated edit must leave the string exactly as written.
|
|
472
|
+
const out = await spliced(source, (d) => {
|
|
473
|
+
d.tiles[0].colspan = 4;
|
|
474
|
+
});
|
|
475
|
+
expect(out).toContain(
|
|
476
|
+
' where: note ~ f"""\nwhere: cat ~ $CATEGORY\n"""\n aggregate: n is count()',
|
|
477
|
+
);
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
describe("splitting a trailing comment off a line", () => {
|
|
482
|
+
// splitTrailingComment: a line with no `//` is left whole.
|
|
483
|
+
it("finds no comment in a plain declaration line", async () => {
|
|
484
|
+
const doc = await openDocument(`## artifact { title="T" tiles=["a -> x"] }
|
|
485
|
+
source: a is one extend {
|
|
486
|
+
view: x is vx
|
|
487
|
+
}`);
|
|
488
|
+
expect(doc.tiles[0].name).toBe("x");
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// splitTrailingComment: the gap before `//` is kept with the code, so an
|
|
492
|
+
// edit to an UNRELATED tile leaves this tile's line, gap and all, byte for
|
|
493
|
+
// byte the same.
|
|
494
|
+
it("keeps the gap with the code so an unchanged line stays unchanged", async () => {
|
|
495
|
+
const source = `## artifact { title="T" tiles=["a -> x", "a -> y"] }
|
|
496
|
+
source: a is one extend {
|
|
497
|
+
view: x is vx // note
|
|
498
|
+
view: y is vy
|
|
499
|
+
}`;
|
|
500
|
+
const out = await spliced(source, (d) => {
|
|
501
|
+
d.tiles[1].colspan = 6;
|
|
502
|
+
});
|
|
503
|
+
expect(out).toContain(" view: x is vx // note\n");
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// splitTrailingComment: `//` inside a quoted default is not a comment, so
|
|
507
|
+
// the given's default text survives whole rather than being truncated.
|
|
508
|
+
it("does not split inside a quoted literal", async () => {
|
|
509
|
+
const doc = await openDocument(`##! experimental.givens
|
|
510
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
511
|
+
given: PATH :: filter<string> is f'a//b'
|
|
512
|
+
|
|
513
|
+
source: a is one extend {
|
|
514
|
+
view: x is vx
|
|
515
|
+
}`);
|
|
516
|
+
expect(doc.localGivens?.[0].default).toBe("f'a//b'");
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// splitTrailingComment: a real comment after the literal has closed is
|
|
520
|
+
// still split off normally.
|
|
521
|
+
it("splits after a literal has closed", async () => {
|
|
522
|
+
const source = `## artifact { title="T" tiles=["a -> x", "a -> y"] }
|
|
523
|
+
source: a is one extend {
|
|
524
|
+
view: x is vx + { where: path ~ 'a//b' } // why
|
|
525
|
+
view: y is vy
|
|
526
|
+
}`;
|
|
527
|
+
const out = await spliced(source, (d) => {
|
|
528
|
+
d.tiles[1].colspan = 6;
|
|
529
|
+
});
|
|
530
|
+
expect(out).toContain(
|
|
531
|
+
" view: x is vx + { where: path ~ 'a//b' } // why\n",
|
|
532
|
+
);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// splitTrailingComment: a backslash-escaped quote is read as text, not a
|
|
536
|
+
// string close, so the comment after it is found in the right place —
|
|
537
|
+
// and the tag survives an unrelated edit exactly as written.
|
|
538
|
+
it("reads an escaped quote as text rather than a close", async () => {
|
|
539
|
+
const source = `## artifact { title="T" tiles=["a -> x", "a -> y"] }
|
|
540
|
+
source: a is one extend {
|
|
541
|
+
# label="Say \\"hi\\"" // why
|
|
542
|
+
view: x is vx
|
|
543
|
+
view: y is vy
|
|
544
|
+
}`;
|
|
545
|
+
const out = await spliced(source, (d) => {
|
|
546
|
+
d.tiles[1].colspan = 6;
|
|
547
|
+
});
|
|
548
|
+
expect(out).toContain(' # label="Say \\"hi\\"" // why\n view: x is vx');
|
|
549
|
+
});
|
|
550
|
+
});
|