@malloy-publisher/sdk 0.0.80 → 0.0.82
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/dist/components/Model/Model.d.ts +3 -1
- package/dist/components/Model/ModelExplorer.d.ts +19 -0
- package/dist/components/Model/index.d.ts +3 -0
- package/dist/components/Model/useModelData.d.ts +8 -0
- package/dist/components/Package/index.d.ts +1 -0
- package/dist/components/Project/index.d.ts +1 -0
- package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +11 -0
- package/dist/components/{MutableNotebook → Workbook}/EditableMalloyCell.d.ts +2 -2
- package/dist/components/{MutableNotebook → Workbook}/MutableCell.d.ts +3 -3
- package/dist/components/Workbook/Workbook.d.ts +9 -0
- package/dist/components/Workbook/WorkbookList.d.ts +7 -0
- package/dist/components/Workbook/WorkbookManager.d.ts +87 -0
- package/dist/components/Workbook/WorkbookStorage.d.ts +18 -0
- package/dist/components/Workbook/WorkbookStorageProvider.d.ts +12 -0
- package/dist/components/Workbook/index.d.ts +7 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/index.cjs.js +67 -67
- package/dist/index.es.js +9481 -9329
- package/package.json +3 -2
- package/src/components/AnalyzePackageButton.tsx +121 -24
- package/src/components/Model/Model.tsx +19 -110
- package/src/components/Model/ModelExplorer.tsx +138 -0
- package/src/components/Model/SourcesExplorer.tsx +65 -79
- package/src/components/Model/index.ts +3 -0
- package/src/components/Model/useModelData.ts +38 -0
- package/src/components/Package/index.ts +1 -0
- package/src/components/Project/index.ts +1 -0
- package/src/components/Workbook/BrowserWorkbookStorage.ts +100 -0
- package/src/components/{MutableNotebook → Workbook}/EditableMalloyCell.tsx +2 -2
- package/src/components/{MutableNotebook → Workbook}/MutableCell.tsx +3 -3
- package/src/components/{MutableNotebook/MutableNotebook.tsx → Workbook/Workbook.tsx} +81 -57
- package/src/components/Workbook/WorkbookList.tsx +111 -0
- package/src/components/Workbook/WorkbookManager.ts +230 -0
- package/src/components/Workbook/WorkbookStorage.ts +54 -0
- package/src/components/Workbook/WorkbookStorageProvider.tsx +37 -0
- package/src/components/Workbook/index.ts +7 -0
- package/src/components/index.ts +3 -1
- package/src/components/styles.ts +0 -3
- package/dist/components/MutableNotebook/BrowserNotebookStorage.d.ts +0 -9
- package/dist/components/MutableNotebook/MutableNotebook.d.ts +0 -8
- package/dist/components/MutableNotebook/MutableNotebookList.d.ts +0 -6
- package/dist/components/MutableNotebook/NotebookStorage.d.ts +0 -11
- package/dist/components/MutableNotebook/NotebookStorageProvider.d.ts +0 -14
- package/dist/components/MutableNotebook/index.d.ts +0 -5
- package/dist/components/NotebookManager.d.ts +0 -86
- package/src/components/MutableNotebook/BrowserNotebookStorage.ts +0 -58
- package/src/components/MutableNotebook/MutableNotebookList.tsx +0 -69
- package/src/components/MutableNotebook/NotebookStorage.ts +0 -27
- package/src/components/MutableNotebook/NotebookStorageProvider.tsx +0 -43
- package/src/components/MutableNotebook/index.ts +0 -8
- package/src/components/NotebookManager.ts +0 -225
- /package/dist/components/{MutableNotebook → Workbook}/ModelPicker.d.ts +0 -0
- /package/src/components/{MutableNotebook → Workbook}/ModelPicker.tsx +0 -0
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Box, Divider, List, ListItem, ListItemText } from "@mui/material";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { useNotebookStorage } from "./NotebookStorageProvider";
|
|
4
|
-
|
|
5
|
-
interface MutableNotebookListProps {
|
|
6
|
-
onNotebookClick: (notebook: string, event: React.MouseEvent) => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function MutableNotebookList({
|
|
10
|
-
onNotebookClick,
|
|
11
|
-
}: MutableNotebookListProps) {
|
|
12
|
-
const { notebookStorage, userContext } = useNotebookStorage();
|
|
13
|
-
const [notebooks, setNotebooks] = React.useState<string[]>([]);
|
|
14
|
-
|
|
15
|
-
React.useEffect(() => {
|
|
16
|
-
if (notebookStorage && userContext) {
|
|
17
|
-
setNotebooks(notebookStorage.listNotebooks(userContext));
|
|
18
|
-
}
|
|
19
|
-
}, [notebookStorage, userContext]);
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<>
|
|
23
|
-
<Divider />
|
|
24
|
-
<Box
|
|
25
|
-
sx={{
|
|
26
|
-
maxHeight: "300px",
|
|
27
|
-
overflow: "auto",
|
|
28
|
-
"&::-webkit-scrollbar": {
|
|
29
|
-
width: "8px",
|
|
30
|
-
},
|
|
31
|
-
"&::-webkit-scrollbar-track": {
|
|
32
|
-
background: "transparent",
|
|
33
|
-
},
|
|
34
|
-
"&::-webkit-scrollbar-thumb": {
|
|
35
|
-
background: "rgba(0,0,0,0.2)",
|
|
36
|
-
borderRadius: "4px",
|
|
37
|
-
},
|
|
38
|
-
}}
|
|
39
|
-
>
|
|
40
|
-
<List dense>
|
|
41
|
-
{notebooks.length === 0 && (
|
|
42
|
-
<ListItem>
|
|
43
|
-
<ListItemText
|
|
44
|
-
primary="No notebooks found."
|
|
45
|
-
sx={{ textAlign: "center" }}
|
|
46
|
-
/>
|
|
47
|
-
</ListItem>
|
|
48
|
-
)}
|
|
49
|
-
{notebooks.map((notebook) => (
|
|
50
|
-
<ListItem
|
|
51
|
-
key={notebook}
|
|
52
|
-
onClick={(event: React.MouseEvent) =>
|
|
53
|
-
onNotebookClick(notebook, event)
|
|
54
|
-
}
|
|
55
|
-
sx={{
|
|
56
|
-
cursor: "pointer",
|
|
57
|
-
"&:hover": {
|
|
58
|
-
backgroundColor: "action.hover",
|
|
59
|
-
},
|
|
60
|
-
}}
|
|
61
|
-
>
|
|
62
|
-
<ListItemText primary={notebook} />
|
|
63
|
-
</ListItem>
|
|
64
|
-
))}
|
|
65
|
-
</List>
|
|
66
|
-
</Box>
|
|
67
|
-
</>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export interface UserContext {
|
|
2
|
-
// UserContext holds the project & package associated with
|
|
3
|
-
// the notebook. PublisherStorage interfaces will
|
|
4
|
-
// implement this and add data representing configuration,
|
|
5
|
-
// user permissions, and access tokens.
|
|
6
|
-
project: string;
|
|
7
|
-
package: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface NotebookStorage {
|
|
11
|
-
// Lists all available notebooks for the context.
|
|
12
|
-
// Notebooks names are like S3 paths- / denote hierarchical
|
|
13
|
-
// folders, but otherwise folders are not "real" objects
|
|
14
|
-
listNotebooks(context: UserContext): string[];
|
|
15
|
-
|
|
16
|
-
// Returns the notebook at the specific path, throws an exception if no such notebook exists (or cannot be accessed)
|
|
17
|
-
getNotebook(context: UserContext, path: string): string;
|
|
18
|
-
|
|
19
|
-
// Deletes the notebook at the specified path, or throws an
|
|
20
|
-
// Exception on failure
|
|
21
|
-
deleteNotebook(context: UserContext, path: string): void;
|
|
22
|
-
|
|
23
|
-
saveNotebook(context: UserContext, path: string, notebook: string): void;
|
|
24
|
-
|
|
25
|
-
// Moves notebook from the "from" path to the "to" path
|
|
26
|
-
moveNotebook(context: UserContext, from: string, to: string): void;
|
|
27
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useMemo } from "react";
|
|
2
|
-
import type { NotebookStorage, UserContext } from "./NotebookStorage";
|
|
3
|
-
|
|
4
|
-
interface NotebookStorageProviderProps {
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
userContext: UserContext;
|
|
7
|
-
notebookStorage: NotebookStorage;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface NotebookStorageContextValue {
|
|
11
|
-
notebookStorage: NotebookStorage;
|
|
12
|
-
userContext: UserContext;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const NotebookStorageContext = createContext<
|
|
16
|
-
NotebookStorageContextValue | undefined
|
|
17
|
-
>(undefined);
|
|
18
|
-
|
|
19
|
-
export default function NotebookStorageProvider({
|
|
20
|
-
children,
|
|
21
|
-
userContext,
|
|
22
|
-
notebookStorage,
|
|
23
|
-
}: NotebookStorageProviderProps) {
|
|
24
|
-
const value = useMemo(
|
|
25
|
-
() => ({ notebookStorage, userContext }),
|
|
26
|
-
[notebookStorage, userContext],
|
|
27
|
-
);
|
|
28
|
-
return (
|
|
29
|
-
<NotebookStorageContext.Provider value={value}>
|
|
30
|
-
{children}
|
|
31
|
-
</NotebookStorageContext.Provider>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function useNotebookStorage() {
|
|
36
|
-
const context = useContext(NotebookStorageContext);
|
|
37
|
-
if (!context) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
"useNotebookStorage must be used within a NotebookStorageProvider",
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return context;
|
|
43
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { BrowserNotebookStorage } from "./BrowserNotebookStorage";
|
|
2
|
-
export { default as MutableNotebook } from "./MutableNotebook";
|
|
3
|
-
export type { NotebookStorage, UserContext } from "./NotebookStorage";
|
|
4
|
-
export { MutableNotebookList } from "./MutableNotebookList";
|
|
5
|
-
export {
|
|
6
|
-
default as NotebookStorageProvider,
|
|
7
|
-
useNotebookStorage,
|
|
8
|
-
} from "./NotebookStorageProvider";
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
NotebookStorage,
|
|
3
|
-
UserContext,
|
|
4
|
-
} from "./MutableNotebook/NotebookStorage";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Interface representing the data structure of a Mutable Notebook
|
|
8
|
-
* @interface NotebookData
|
|
9
|
-
* @property {string[]} models - Array of model paths used in the notebook
|
|
10
|
-
* @property {NotebookCellValue[]} cells - Array of cells in the notebook
|
|
11
|
-
* @property {string} notebookPath - Path to the notebook file (relative to project/package)
|
|
12
|
-
*/
|
|
13
|
-
export interface NotebookData {
|
|
14
|
-
models: string[];
|
|
15
|
-
cells: NotebookCellValue[];
|
|
16
|
-
notebookPath: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Interface representing a cell in the notebook
|
|
21
|
-
* @interface NotebookCellValue
|
|
22
|
-
* @property {boolean} isMarkdown - Whether the cell is a markdown cell
|
|
23
|
-
* @property {string} [value] - The content of the cell
|
|
24
|
-
* @property {string} [result] - The result of executing the cell
|
|
25
|
-
* @property {string} [modelPath] - modelPath associated with the query in the cell
|
|
26
|
-
* @property {string} [sourceName] - Name of the source associated with the cell
|
|
27
|
-
* @property {string} [queryInfo] - Information about the query in the cell
|
|
28
|
-
*/
|
|
29
|
-
export interface NotebookCellValue {
|
|
30
|
-
isMarkdown: boolean;
|
|
31
|
-
value?: string;
|
|
32
|
-
result?: string;
|
|
33
|
-
modelPath?: string;
|
|
34
|
-
sourceName?: string;
|
|
35
|
-
queryInfo?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Class for managing notebook operations
|
|
40
|
-
* @class NotebookManager
|
|
41
|
-
*/
|
|
42
|
-
export class NotebookManager {
|
|
43
|
-
private isSaved: boolean;
|
|
44
|
-
private notebookStorage: NotebookStorage;
|
|
45
|
-
private userContext: UserContext;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Creates a new NotebookManager instance
|
|
49
|
-
* @param {NotebookStorage} notebookStorage - Storage implementation
|
|
50
|
-
* @param {UserContext} userContext - User context for storage
|
|
51
|
-
* @param {NotebookData} notebookData - Initial notebook data
|
|
52
|
-
*/
|
|
53
|
-
constructor(
|
|
54
|
-
notebookStorage: NotebookStorage,
|
|
55
|
-
userContext: UserContext,
|
|
56
|
-
private notebookData: NotebookData,
|
|
57
|
-
) {
|
|
58
|
-
this.notebookStorage = notebookStorage;
|
|
59
|
-
this.userContext = userContext;
|
|
60
|
-
if (this.notebookData) {
|
|
61
|
-
this.isSaved = true;
|
|
62
|
-
} else {
|
|
63
|
-
this.notebookData = {
|
|
64
|
-
models: [],
|
|
65
|
-
cells: [],
|
|
66
|
-
notebookPath: undefined,
|
|
67
|
-
};
|
|
68
|
-
this.isSaved = false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Gets the current notebook data
|
|
74
|
-
* @returns {NotebookData} The current notebook data
|
|
75
|
-
*/
|
|
76
|
-
getNotebookData(): NotebookData {
|
|
77
|
-
return this.notebookData;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Gets the current notebook path
|
|
82
|
-
* @returns {string} The path to the notebook
|
|
83
|
-
*/
|
|
84
|
-
getNotebookPath(): string {
|
|
85
|
-
return this.notebookData.notebookPath;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Renames the notebook and updates storage
|
|
90
|
-
* @param {string} notebookPath - New path for the notebook
|
|
91
|
-
* @returns {NotebookManager} The updated NotebookManager instance
|
|
92
|
-
*/
|
|
93
|
-
renameNotebook(notebookPath: string): NotebookManager {
|
|
94
|
-
if (this.notebookData.notebookPath !== notebookPath) {
|
|
95
|
-
try {
|
|
96
|
-
this.notebookStorage.deleteNotebook(
|
|
97
|
-
this.userContext,
|
|
98
|
-
this.notebookData.notebookPath,
|
|
99
|
-
);
|
|
100
|
-
} catch {
|
|
101
|
-
// ignore if not found
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
this.notebookData.notebookPath = notebookPath;
|
|
105
|
-
this.isSaved = false;
|
|
106
|
-
this.saveNotebook();
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
getCells(): NotebookCellValue[] {
|
|
111
|
-
return this.notebookData.cells;
|
|
112
|
-
}
|
|
113
|
-
deleteCell(index: number): NotebookManager {
|
|
114
|
-
this.notebookData.cells = [
|
|
115
|
-
...this.notebookData.cells.slice(0, index),
|
|
116
|
-
...this.notebookData.cells.slice(index + 1),
|
|
117
|
-
];
|
|
118
|
-
this.isSaved = false;
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
insertCell(index: number, cell: NotebookCellValue): NotebookManager {
|
|
122
|
-
this.notebookData.cells = [
|
|
123
|
-
...this.notebookData.cells.slice(0, index),
|
|
124
|
-
cell,
|
|
125
|
-
...this.notebookData.cells.slice(index),
|
|
126
|
-
];
|
|
127
|
-
this.isSaved = false;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
setCell(index: number, cell: NotebookCellValue): NotebookManager {
|
|
131
|
-
this.notebookData.cells[index] = cell;
|
|
132
|
-
this.isSaved = false;
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
setModels(models: string[]): NotebookManager {
|
|
136
|
-
this.notebookData.models = models;
|
|
137
|
-
this.isSaved = false;
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
getModels(): string[] {
|
|
141
|
-
return this.notebookData.models;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
updateNotebookData(notebookData: NotebookData): NotebookManager {
|
|
145
|
-
this.notebookData = notebookData;
|
|
146
|
-
this.isSaved = false;
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
saveNotebook(): NotebookManager {
|
|
151
|
-
if (!this.isSaved) {
|
|
152
|
-
if (!this.notebookData.notebookPath) {
|
|
153
|
-
throw new Error("Notebook path is not set");
|
|
154
|
-
}
|
|
155
|
-
this.notebookStorage.saveNotebook(
|
|
156
|
-
this.userContext,
|
|
157
|
-
this.notebookData.notebookPath,
|
|
158
|
-
JSON.stringify(this.notebookData),
|
|
159
|
-
);
|
|
160
|
-
this.isSaved = true;
|
|
161
|
-
}
|
|
162
|
-
return new NotebookManager(
|
|
163
|
-
this.notebookStorage,
|
|
164
|
-
this.userContext,
|
|
165
|
-
this.notebookData,
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Converts the notebook data to a Malloy notebook string.
|
|
171
|
-
* @returns {string} The Malloy notebook string
|
|
172
|
-
*/
|
|
173
|
-
toMalloyNotebook(): string {
|
|
174
|
-
return this.notebookData.cells
|
|
175
|
-
.map((cell) => {
|
|
176
|
-
if (cell.isMarkdown) {
|
|
177
|
-
return ">>>markdown\n" + cell.value;
|
|
178
|
-
} else {
|
|
179
|
-
return (
|
|
180
|
-
">>>malloy\n" +
|
|
181
|
-
`import {${cell.sourceName}}" from '${cell.modelPath}'"\n` +
|
|
182
|
-
cell.value +
|
|
183
|
-
"\n"
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
})
|
|
187
|
-
.join("\n");
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
static newNotebook(
|
|
191
|
-
notebookStorage: NotebookStorage,
|
|
192
|
-
userContext: UserContext,
|
|
193
|
-
): NotebookManager {
|
|
194
|
-
return new NotebookManager(notebookStorage, userContext, undefined);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Creates a new notebook manager by loading from local storage.
|
|
199
|
-
* Returns an empty instance if the notebook is not found.
|
|
200
|
-
* @param notebookStorage - The storage implementation
|
|
201
|
-
* @param userContext - The user context for storage
|
|
202
|
-
* @param notebookPath - The path to the notebook file (relative to project/package)
|
|
203
|
-
*/
|
|
204
|
-
static loadNotebook(
|
|
205
|
-
notebookStorage: NotebookStorage,
|
|
206
|
-
userContext: UserContext,
|
|
207
|
-
notebookPath: string,
|
|
208
|
-
): NotebookManager {
|
|
209
|
-
let notebookData: NotebookData | undefined = undefined;
|
|
210
|
-
try {
|
|
211
|
-
const saved = notebookStorage.getNotebook(userContext, notebookPath);
|
|
212
|
-
if (saved) {
|
|
213
|
-
notebookData = JSON.parse(saved);
|
|
214
|
-
}
|
|
215
|
-
} catch {
|
|
216
|
-
// Not found, create a new notebook
|
|
217
|
-
notebookData = {
|
|
218
|
-
models: [],
|
|
219
|
-
cells: [],
|
|
220
|
-
notebookPath: notebookPath,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
return new NotebookManager(notebookStorage, userContext, notebookData);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
File without changes
|
|
File without changes
|