@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DashboardDocument, LocalGiven } from './document';
|
|
2
|
+
import { ParsedMalloy } from './malloyTree';
|
|
2
3
|
/**
|
|
3
4
|
* Read a `dashboards/*.malloy` file into a {@link DashboardDocument}.
|
|
4
5
|
*
|
|
@@ -7,10 +8,10 @@ import { DashboardDocument, LocalGiven } from './document';
|
|
|
7
8
|
* in the browser and in a unit test alike, which is what lets the suite open
|
|
8
9
|
* every dashboard in the repository as a regression gate.
|
|
9
10
|
*
|
|
10
|
-
* Structure comes from
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
11
|
+
* Structure comes from Malloy's own parse tree, through `malloyTree`: imports,
|
|
12
|
+
* sources, views, dimensions, givens and every `where:` clause, each with an
|
|
13
|
+
* exact span. Tags come from `parseAnnotation` over the `#` block above a
|
|
14
|
+
* declaration, which is `malloy-tag`'s grammar rather than Malloy's.
|
|
14
15
|
*
|
|
15
16
|
* Reading tags from the text rather than from the server, which serves them
|
|
16
17
|
* already attached, is deliberate. The splice writer has to LOCATE a tag in
|
|
@@ -43,7 +44,7 @@ export type ReadResult = {
|
|
|
43
44
|
* does not typecheck, in a codebase where most code never notices.
|
|
44
45
|
*/
|
|
45
46
|
export declare const readFailed: (result: ReadResult) => result is ReadFailure;
|
|
46
|
-
/** A
|
|
47
|
+
/** A `#`/comment block above a declaration, and where it sits. */
|
|
47
48
|
export interface Block {
|
|
48
49
|
/** 0-based line of the first line in the block. */
|
|
49
50
|
start: number;
|
|
@@ -57,23 +58,22 @@ export interface Block {
|
|
|
57
58
|
}>;
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
|
-
* The comment-and-tag block immediately above `declLine
|
|
61
|
+
* The comment-and-tag block immediately above `declLine`, up to the blank line
|
|
62
|
+
* that is the author's own separator. Validated against the bundled dashboard,
|
|
63
|
+
* where it collects `revenue_trend`'s three tags and the fourteen-line comment
|
|
64
|
+
* explaining its colspan, then stops at the blank line above — which is the
|
|
65
|
+
* right unit to carry when that tile moves.
|
|
61
66
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
export declare function blockAbove(lines: string[], declLine: number): Block;
|
|
72
|
-
/**
|
|
73
|
-
* One `where: <field> <op> $<GIVEN>` clause. Exported for the writer, which
|
|
74
|
-
* has to find the same clauses in order to replace them and nothing else.
|
|
67
|
+
* WHERE the block starts comes from `parsed`, which takes its comments from the
|
|
68
|
+
* lexer, and not from a scan for `//` here. Malloy spells a comment three ways
|
|
69
|
+
* — `//`, `--` and `/* … *\/` — and this walked upward looking only for the
|
|
70
|
+
* first. The other two stopped it early while the parser read straight past
|
|
71
|
+
* them, so a `#` tag above one was visible to the reader and invisible to the
|
|
72
|
+
* writer, which then wrote a SECOND copy of the tag below the comment. The
|
|
73
|
+
* reader picks the lower one up and the read-back gate is satisfied, so the
|
|
74
|
+
* file quietly ends up carrying two.
|
|
75
75
|
*/
|
|
76
|
-
export declare
|
|
76
|
+
export declare function blockAbove(parsed: ParsedMalloy, lines: string[], declLine: number): Block;
|
|
77
77
|
/**
|
|
78
78
|
* A tag object, as `parseAnnotation` returns it. Only the reads this file makes.
|
|
79
79
|
*/
|
|
@@ -86,10 +86,7 @@ type ParseTags = (lines: string[]) => {
|
|
|
86
86
|
tag?: TagLike | null;
|
|
87
87
|
};
|
|
88
88
|
/**
|
|
89
|
-
* `given:` declarations,
|
|
90
|
-
* its types are query, unnamed_query, explore, field, join, import and
|
|
91
|
-
* import_item. So these are read as text, in BOTH spellings Malloy accepts and
|
|
92
|
-
* this repository uses:
|
|
89
|
+
* `given:` declarations, in BOTH spellings Malloy accepts:
|
|
93
90
|
*
|
|
94
91
|
* given: CATEGORY :: filter<string> is f'' // one per line
|
|
95
92
|
*
|
|
@@ -97,10 +94,8 @@ type ParseTags = (lines: string[]) => {
|
|
|
97
94
|
* CATEGORY :: filter<string> is f''
|
|
98
95
|
* SINCE :: date is @2023-01-01
|
|
99
96
|
*
|
|
100
|
-
*
|
|
101
|
-
* builder emits; the block form is read so a file written the other way still
|
|
102
|
-
* opens. Either way the tags above a declaration are its control contract.
|
|
97
|
+
* Either way the `#` tags above a declaration are its control contract.
|
|
103
98
|
*/
|
|
104
|
-
export declare function localGivens(lines: string[], parse: ParseTags): LocalGiven[] | undefined;
|
|
99
|
+
export declare function localGivens(parsed: ParsedMalloy, lines: string[], parse: ParseTags): LocalGiven[] | undefined;
|
|
105
100
|
export declare function readDashboardDocument(sourceText: string): Promise<ReadResult>;
|
|
106
101
|
export {};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { DashboardDocument, DashboardTile } from './document';
|
|
2
|
+
/**
|
|
3
|
+
* The syntax errors Malloy's own parser reports for `text`, as a multiset of
|
|
4
|
+
* messages.
|
|
5
|
+
*
|
|
6
|
+
* The first `translate()` is enough and is all we want: a document with
|
|
7
|
+
* imports comes back NOT final, asking for the urls it needs, and by then the
|
|
8
|
+
* parse has already happened while nothing has been resolved. So this sees
|
|
9
|
+
* every syntax error and none of the semantic ones, which are not this
|
|
10
|
+
* writer's business -- a dashboard referring to a source in a file we decline
|
|
11
|
+
* to hand over is not damage we caused.
|
|
12
|
+
*/
|
|
13
|
+
export declare function syntaxErrors(text: string): Promise<string[]>;
|
|
2
14
|
/**
|
|
3
15
|
* Write a change back into a `dashboards/*.malloy` file by PATCHING it.
|
|
4
16
|
*
|
|
@@ -16,9 +16,29 @@
|
|
|
16
16
|
* ask for one kind. Everything else a backend may know about a document, who
|
|
17
17
|
* changed it and when, who may see it, stays with the backend.
|
|
18
18
|
*
|
|
19
|
+
* A host hands the SDK ONE storage and keeps handing it the same one. What a
|
|
20
|
+
* storage says about its workspaces decides how the editor routes a save, and
|
|
21
|
+
* the editor asks once, when it opens; a host that re-creates its storage mid
|
|
22
|
+
* session leaves the editor routing by the old answer until the new list
|
|
23
|
+
* resolves.
|
|
24
|
+
*
|
|
19
25
|
* Every method rejects rather than returning a sentinel when the document is
|
|
20
|
-
* not there, so a caller can tell "missing" from "empty".
|
|
26
|
+
* not there, so a caller can tell "missing" from "empty". Absence rejects with
|
|
27
|
+
* a {@link DocumentNotFoundError} specifically, so a caller can tell either of
|
|
28
|
+
* those from a backend that could not be reached: a failed read answered with
|
|
29
|
+
* "there is no document" reads as "the package is the only copy", and saving
|
|
30
|
+
* on that belief overwrites the copy that was actually there.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Absence, and only absence: the document is not at that locator. Every other
|
|
34
|
+
* rejection means the backend could not answer, which is not the same thing and
|
|
35
|
+
* must not be treated as one.
|
|
21
36
|
*/
|
|
37
|
+
export declare class DocumentNotFoundError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/** Whether a rejection means absence rather than a backend that could not answer. */
|
|
41
|
+
export declare const isDocumentNotFound: (error: unknown) => boolean;
|
|
22
42
|
/**
|
|
23
43
|
* The kinds of document the SDK authors. A `dashboard` is a
|
|
24
44
|
* `dashboards/<slug>.malloy` file; a `notebook` is a `.malloynb`.
|
|
@@ -29,7 +49,33 @@ export interface Workspace {
|
|
|
29
49
|
name: string;
|
|
30
50
|
/** False for a workspace this reader may list and open but not save into. */
|
|
31
51
|
writeable: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* What this place is, in the backend's own words, for the editor to show a
|
|
54
|
+
* reader rather than guessing on their behalf.
|
|
55
|
+
*/
|
|
32
56
|
description: string;
|
|
57
|
+
/**
|
|
58
|
+
* This workspace holds the package's system of record: what it keeps for a
|
|
59
|
+
* document IS that document, and the package file is a copy of it or a
|
|
60
|
+
* deploy behind it.
|
|
61
|
+
*
|
|
62
|
+
* Left out, the workspace is a place a reader's work is kept beside the
|
|
63
|
+
* package — the Console's browser copy, a scratch space — and the package
|
|
64
|
+
* file is the record.
|
|
65
|
+
*
|
|
66
|
+
* The contract, which the editor relies on and does not police:
|
|
67
|
+
*
|
|
68
|
+
* - At most one workspace of a storage declares itself authoritative. The
|
|
69
|
+
* editor takes the first it is given and does not arbitrate between two.
|
|
70
|
+
* - It is orthogonal to {@link Workspace.writeable} and to the server's
|
|
71
|
+
* `mutable`. A workspace can be the record and still be read-only to this
|
|
72
|
+
* reader, and a server that refuses writes to its own package says
|
|
73
|
+
* nothing about where the record lives.
|
|
74
|
+
* - A host whose authority differs per package mounts one storage per
|
|
75
|
+
* context rather than flipping this between renders; the editor reads it
|
|
76
|
+
* once, when it opens.
|
|
77
|
+
*/
|
|
78
|
+
authoritative?: boolean;
|
|
33
79
|
}
|
|
34
80
|
/** One document's address: which workspace, which kind, and its path there. */
|
|
35
81
|
export interface DocumentLocator {
|
|
@@ -47,12 +93,30 @@ export interface DocumentStorage {
|
|
|
47
93
|
listWorkspaces(writeableOnly: boolean): Promise<Workspace[]>;
|
|
48
94
|
/** Every document in a workspace, or only those of one kind. */
|
|
49
95
|
listDocuments(workspace: Workspace, type?: DocumentType): Promise<DocumentLocator[]>;
|
|
50
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* The document's content. Rejects with a {@link DocumentNotFoundError} when
|
|
98
|
+
* there is no document there, and with anything else when the backend could
|
|
99
|
+
* not be asked.
|
|
100
|
+
*/
|
|
51
101
|
getDocument(locator: DocumentLocator): Promise<string>;
|
|
52
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Write the content, creating the document or replacing it.
|
|
104
|
+
*
|
|
105
|
+
* There is no expected-version slot, so this is last writer wins and a
|
|
106
|
+
* caller cannot tell that it overwrote someone. A backend that has to stop
|
|
107
|
+
* two authors clobbering each other enforces that itself, in the backend.
|
|
108
|
+
*/
|
|
53
109
|
saveDocument(locator: DocumentLocator, content: string): Promise<void>;
|
|
54
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Remove the document. Rejects with a {@link DocumentNotFoundError} when
|
|
112
|
+
* there is no document there, and with anything else when the backend could
|
|
113
|
+
* not be asked — a caller must not read the second as the first and report
|
|
114
|
+
* the document gone.
|
|
115
|
+
*/
|
|
55
116
|
deleteDocument(locator: DocumentLocator): Promise<void>;
|
|
56
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Rename or relocate a document, keeping its content. Rejects with a
|
|
119
|
+
* {@link DocumentNotFoundError} when `from` is missing.
|
|
120
|
+
*/
|
|
57
121
|
moveDocument(from: DocumentLocator, to: DocumentLocator): Promise<void>;
|
|
58
122
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { DocumentLocator, DocumentStorage, DocumentType, Workspace, } from './DocumentStorage';
|
|
2
|
+
export { DocumentNotFoundError, isDocumentNotFound } from './DocumentStorage';
|
|
2
3
|
export { DocumentStorageProvider, useDocumentStorage, useOptionalDocumentStorage, type DocumentStorageProviderProps, } from './DocumentStorageProvider';
|
|
3
4
|
export { BrowserDocumentStorage } from './BrowserDocumentStorage';
|