@malloy-publisher/sdk 0.0.80 → 0.0.81
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/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 +62 -62
- package/dist/index.es.js +6466 -6337
- package/package.json +3 -2
- package/src/components/AnalyzePackageButton.tsx +121 -24
- package/src/components/Model/Model.tsx +7 -1
- 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/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,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
|