@malloy-publisher/sdk 0.4.0 → 0.4.1
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-BiFqO15i.es.js} +137 -129
- package/dist/{DocumentStorageProvider-DGPQEd_l.cjs.js → DocumentStorage-CMyLifsz.cjs.js} +26 -26
- package/dist/{RenderedResult-Dp22kZsQ.cjs.js → RenderedResult-CZzE8wv-.cjs.js} +2 -2
- package/dist/{RenderedResult-BnPzJ9Jf.es.js → RenderedResult-CvrmYyr5.es.js} +1 -1
- package/dist/builder/index.cjs.js +50 -50
- package/dist/builder/index.es.js +3265 -3185
- 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 +17 -5
- 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/package.json +1 -1
- package/src/components/Dashboard/telemetry.ts +20 -8
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +21 -3
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +358 -84
- 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
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export type DashboardEvent = {
|
|
10
10
|
type: "dashboard.opened";
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The package file, a draft the host had saved beside it, or the
|
|
13
|
+
* host's own copy when that copy is the record. A record open is not a
|
|
14
|
+
* "draft" open: nothing was resumed and nothing is pending.
|
|
15
|
+
*/
|
|
16
|
+
from: "package" | "draft" | "record";
|
|
13
17
|
tiles: number;
|
|
14
18
|
durationMs: number;
|
|
15
19
|
} | {
|
|
@@ -21,13 +25,21 @@ export type DashboardEvent = {
|
|
|
21
25
|
/** Whether a tile was added or removed, which moves declarations. */
|
|
22
26
|
structural: boolean;
|
|
23
27
|
/**
|
|
24
|
-
* Where it went
|
|
25
|
-
* that
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* Where it went, named by which storage took the write rather than by
|
|
29
|
+
* where that storage happens to keep things, since "browser" and
|
|
30
|
+
* "host" do not divide by English: `package` is the package file on
|
|
31
|
+
* the server, `browser` is the Console's own browser store, and `host`
|
|
32
|
+
* is a host storage that holds the record.
|
|
33
|
+
*
|
|
34
|
+
* Separate because they are not the same event. A save into the
|
|
35
|
+
* package or the record is a change every reader sees; a browser save
|
|
36
|
+
* is one person's copy on one machine. Counting them together makes
|
|
37
|
+
* "dashboards are being edited" unreadable, because a read-only server
|
|
38
|
+
* reports exactly as much saving as a writable one.
|
|
29
39
|
*/
|
|
30
|
-
where: "package" | "browser";
|
|
40
|
+
where: "package" | "browser" | "host";
|
|
41
|
+
/** The workspace that took the write, so the event says so itself. */
|
|
42
|
+
workspace?: string;
|
|
31
43
|
durationMs: number;
|
|
32
44
|
} | {
|
|
33
45
|
type: "dashboard.save_refused";
|
|
@@ -102,12 +102,24 @@ export interface DashboardBuilderProps {
|
|
|
102
102
|
dashboards?: string[];
|
|
103
103
|
/** Saves and refusals, for the host to log; see `DashboardEvent`. */
|
|
104
104
|
onEvent?: DashboardEventHandler;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the document differs from what was last saved, on every change
|
|
107
|
+
* and on mount.
|
|
108
|
+
*
|
|
109
|
+
* For a host that has to decide whether it may replace what is open — a
|
|
110
|
+
* newer version arriving from its store, a navigation away. `onChange`
|
|
111
|
+
* cannot answer that: the saved baseline lives in this hook, so a parent
|
|
112
|
+
* comparing the document it is handed against the one it passed in reads
|
|
113
|
+
* dirty immediately after a successful save.
|
|
114
|
+
*/
|
|
115
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
105
116
|
/**
|
|
106
117
|
* Where `onSave` puts the file, for the event it reports. The builder
|
|
107
|
-
* cannot tell — it is handed a function — and a save into the package
|
|
108
|
-
*
|
|
118
|
+
* cannot tell — it is handed a function — and a save into the package, into
|
|
119
|
+
* this browser, and into a host store that holds the record are not the
|
|
120
|
+
* same event.
|
|
109
121
|
*/
|
|
110
|
-
savesTo?: "package" | "browser";
|
|
122
|
+
savesTo?: "package" | "browser" | "host";
|
|
111
123
|
/**
|
|
112
124
|
* The host's own actions for the edit bar — Done — rendered beside
|
|
113
125
|
* undo, redo and save. The builder owns the edits; where the file goes
|
|
@@ -115,4 +127,4 @@ export interface DashboardBuilderProps {
|
|
|
115
127
|
*/
|
|
116
128
|
toolbar?: ReactNode;
|
|
117
129
|
}
|
|
118
|
-
export declare function DashboardBuilder({ source, document, onSave, onChange, renderTile, controls, givens, catalog, toolbar, dashboards, onEvent, savesTo, }: DashboardBuilderProps): import("react/jsx-runtime").JSX.Element;
|
|
130
|
+
export declare function DashboardBuilder({ source, document, onSave, onChange, onDirtyChange, renderTile, controls, givens, catalog, toolbar, dashboards, onEvent, savesTo, }: DashboardBuilderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,10 +5,13 @@ import { DashboardEventHandler } from '../Dashboard/telemetry';
|
|
|
5
5
|
* control row and live tiles that follow the document, a catalog for the
|
|
6
6
|
* filter window's field search, and saving.
|
|
7
7
|
*
|
|
8
|
-
* SAVING goes
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* SAVING goes wherever the record is. A {@link Workspace} the host marks
|
|
9
|
+
* `authoritative` IS the record, so the editor opens that copy and writes back
|
|
10
|
+
* to it, and the package file is a deploy of it. Otherwise the record is the
|
|
11
|
+
* package: the editor writes there on a server that takes writes, and
|
|
12
|
+
* otherwise keeps a copy beside it in the host's {@link DocumentStorage} — the
|
|
13
|
+
* Console's default is this browser, where the copy is offered back on the
|
|
14
|
+
* next visit. A host with neither still gets the editor, without Save.
|
|
12
15
|
*
|
|
13
16
|
* What that costs is stated in the toolbar: a control added here is live in the
|
|
14
17
|
* editor (its value is written into each tile's query) but reaches the package
|
|
@@ -26,5 +29,14 @@ export interface DashboardEditorProps {
|
|
|
26
29
|
* count; see `DashboardEvent`.
|
|
27
30
|
*/
|
|
28
31
|
onEvent?: DashboardEventHandler;
|
|
32
|
+
/**
|
|
33
|
+
* Whether there are edits the record does not have, on every change and
|
|
34
|
+
* whenever the editor opens a document.
|
|
35
|
+
*
|
|
36
|
+
* For a host that owns the way out: a route change, a tab close, its own
|
|
37
|
+
* "are you sure". The editor will not discard unsaved work on its own, so
|
|
38
|
+
* without this a host cannot tell whether leaving costs anything.
|
|
39
|
+
*/
|
|
40
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
29
41
|
}
|
|
30
|
-
export declare function DashboardEditor({ environmentName, packageName, dashboardName, onExit, onEvent, }: DashboardEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export declare function DashboardEditor({ environmentName, packageName, dashboardName, onExit, onEvent, onDirtyChange, }: DashboardEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -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';
|