@malloy-publisher/sdk 0.2.7 → 0.3.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.
Files changed (99) hide show
  1. package/README.md +172 -204
  2. package/dist/ServerProvider-CGnLjzag.cjs.js +1 -0
  3. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-DSK9rfSY.es.js} +245 -245
  4. package/dist/client/api.d.ts +13 -1
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +1 -1
  7. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  8. package/dist/components/Dashboard/Dashboard.d.ts +4 -2
  9. package/dist/components/Dashboard/promoteMeasureRow.d.ts +36 -0
  10. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  11. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  12. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +18 -0
  13. package/dist/components/DocumentStorage/index.d.ts +3 -0
  14. package/dist/components/Model/index.d.ts +0 -1
  15. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  16. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  17. package/dist/components/RenderedResult/index.d.ts +1 -0
  18. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  19. package/dist/components/drill/index.d.ts +1 -0
  20. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  21. package/dist/components/given/filterValue.d.ts +63 -0
  22. package/dist/components/given/index.d.ts +1 -0
  23. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  24. package/dist/components/index.d.ts +2 -3
  25. package/dist/components/styles.d.ts +3 -3
  26. package/dist/core-8NVBCLZh.cjs.js +148 -0
  27. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  28. package/dist/hooks/index.d.ts +1 -1
  29. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  30. package/dist/index.cjs.js +281 -1
  31. package/dist/index.es.js +45803 -79
  32. package/dist/sdk.css +1 -1
  33. package/dist/styles.css +0 -1
  34. package/package.json +2 -6
  35. package/src/components/ApiErrorDisplay.tsx +1 -1
  36. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  37. package/src/components/Dashboard/Dashboard.tsx +60 -95
  38. package/src/components/Dashboard/DashboardTile.tsx +25 -2
  39. package/src/components/Dashboard/promoteMeasureRow.spec.ts +137 -0
  40. package/src/components/Dashboard/promoteMeasureRow.ts +129 -0
  41. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  42. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  43. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  44. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +46 -0
  45. package/src/components/DocumentStorage/index.ts +15 -0
  46. package/src/components/Model/ModelCell.tsx +2 -1
  47. package/src/components/Model/index.ts +0 -1
  48. package/src/components/Notebook/Notebook.tsx +10 -76
  49. package/src/components/Notebook/NotebookCell.tsx +2 -8
  50. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  51. package/src/components/RenderedResult/ResultContainer.tsx +21 -24
  52. package/src/components/RenderedResult/index.ts +15 -0
  53. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  54. package/src/components/RenderedResult/resultSizing.ts +308 -0
  55. package/src/components/ResultsDialog.tsx +2 -1
  56. package/src/components/drill/index.ts +5 -0
  57. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  58. package/src/components/drill/useDrillSelf.ts +110 -0
  59. package/src/components/given/GivenInput.spec.tsx +196 -2
  60. package/src/components/given/GivenInput.tsx +300 -25
  61. package/src/components/given/filterValue.spec.ts +112 -0
  62. package/src/components/given/filterValue.ts +188 -0
  63. package/src/components/given/index.ts +4 -0
  64. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  65. package/src/components/given/useGivenUrlParams.ts +87 -0
  66. package/src/components/index.ts +5 -3
  67. package/src/hooks/index.ts +0 -1
  68. package/src/hooks/useGivensState.spec.ts +158 -0
  69. package/src/hooks/useGivensState.ts +114 -23
  70. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  71. package/src/hooks/useSuggestOptions.ts +94 -51
  72. package/vite.config.ts +0 -1
  73. package/dist/ServerProvider-xXW1HJOJ.cjs.js +0 -1
  74. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  75. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  76. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  77. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  78. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  79. package/dist/components/Workbook/Workbook.d.ts +0 -7
  80. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  81. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  82. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  83. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  84. package/dist/components/Workbook/index.d.ts +0 -7
  85. package/dist/core-CWKmWEg2.cjs.js +0 -148
  86. package/dist/index-B0WyZAUA.es.js +0 -66412
  87. package/dist/index-kxVD1RjY.cjs.js +0 -356
  88. package/dist/markdown-editor.css +0 -341
  89. package/src/components/AnalyzePackageButton.tsx +0 -319
  90. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  91. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  92. package/src/components/Workbook/ModelPicker.tsx +0 -134
  93. package/src/components/Workbook/MutableCell.tsx +0 -458
  94. package/src/components/Workbook/Workbook.tsx +0 -501
  95. package/src/components/Workbook/WorkbookList.tsx +0 -110
  96. package/src/components/Workbook/WorkbookManager.ts +0 -214
  97. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  98. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  99. package/src/components/Workbook/index.ts +0 -10
@@ -1,214 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import type { WorkbookLocator, WorkbookStorage } from "./WorkbookStorage";
5
-
6
- /**
7
- * Interface representing the data structure of a Mutable Workbook
8
- * @interface WorkbookData
9
- * @property {string[]} models - Array of model paths used in the workbook
10
- * @property {WorkbookCellValue[]} cells - Array of cells in the workbook
11
- * @property {WorkbookLocator} workbookPath - Path to the workbook file (relative to project/package)
12
- */
13
- export interface WorkbookData {
14
- models: string[];
15
- cells: WorkbookCellValue[];
16
- workbookPath: WorkbookLocator;
17
- }
18
-
19
- /**
20
- * Interface representing a cell in the workbook
21
- * @interface WorkbookCellValue
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 WorkbookCellValue {
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 workbook operations
40
- * @class WorkbookManager
41
- */
42
- export class WorkbookManager {
43
- private isSaved: boolean;
44
- private workbookStorage: WorkbookStorage;
45
-
46
- /**
47
- * Creates a new WorkbookManager instance
48
- * @param {WorkbookStorage} workbookStorage - Storage implementation
49
- * @param {WorkbookData} workbookData - Initial workbook data
50
- */
51
- constructor(
52
- workbookStorage: WorkbookStorage,
53
- private workbookData: WorkbookData,
54
- ) {
55
- this.workbookStorage = workbookStorage;
56
- if (this.workbookData) {
57
- this.isSaved = true;
58
- } else {
59
- this.workbookData = {
60
- models: [],
61
- cells: [],
62
- workbookPath: undefined,
63
- };
64
- this.isSaved = false;
65
- }
66
- }
67
-
68
- /**
69
- * Gets the current workbook data
70
- * @returns {WorkbookData} The current workbook data
71
- */
72
- getWorkbookData(): WorkbookData {
73
- return this.workbookData;
74
- }
75
-
76
- /**
77
- * Gets the current workbook path
78
- * @returns {string} The path to the workbook
79
- */
80
- getWorkbookPath(): WorkbookLocator {
81
- return this.workbookData.workbookPath;
82
- }
83
-
84
- /**
85
- * Renames the workbook and updates storage
86
- * @param {string} workbookPath - New path for the workbook
87
- * @returns {WorkbookManager} The updated WorkbookManager instance
88
- */
89
- async renameWorkbook(workbookPath: string): Promise<WorkbookManager> {
90
- if (this.workbookData.workbookPath.path !== workbookPath) {
91
- try {
92
- await this.workbookStorage.moveWorkbook(
93
- this.workbookData.workbookPath,
94
- {
95
- path: workbookPath,
96
- workspace: this.workbookData.workbookPath.workspace,
97
- },
98
- );
99
- } catch {
100
- // ignore if not found
101
- }
102
- }
103
- this.workbookData.workbookPath.path = workbookPath;
104
- this.isSaved = false;
105
- return await this.saveWorkbook();
106
- }
107
-
108
- getCells(): WorkbookCellValue[] {
109
- return this.workbookData.cells;
110
- }
111
- deleteCell(index: number): WorkbookManager {
112
- this.workbookData.cells = [
113
- ...this.workbookData.cells.slice(0, index),
114
- ...this.workbookData.cells.slice(index + 1),
115
- ];
116
- this.isSaved = false;
117
- return this;
118
- }
119
- insertCell(index: number, cell: WorkbookCellValue): WorkbookManager {
120
- this.workbookData.cells = [
121
- ...this.workbookData.cells.slice(0, index),
122
- cell,
123
- ...this.workbookData.cells.slice(index),
124
- ];
125
- this.isSaved = false;
126
- return this;
127
- }
128
- setCell(index: number, cell: WorkbookCellValue): WorkbookManager {
129
- this.workbookData.cells[index] = cell;
130
- this.isSaved = false;
131
- return this;
132
- }
133
- setModels(models: string[]): WorkbookManager {
134
- this.workbookData.models = models;
135
- this.isSaved = false;
136
- return this;
137
- }
138
- getModels(): string[] {
139
- return this.workbookData.models;
140
- }
141
-
142
- updateWorkbookData(workbookData: WorkbookData): WorkbookManager {
143
- this.workbookData = workbookData;
144
- this.isSaved = false;
145
- return this;
146
- }
147
-
148
- async saveWorkbook(): Promise<WorkbookManager> {
149
- if (!this.isSaved) {
150
- if (!this.workbookData.workbookPath) {
151
- throw new Error("Workbook path is not set");
152
- }
153
- await this.workbookStorage.saveWorkbook(
154
- this.workbookData.workbookPath,
155
- JSON.stringify(this.workbookData),
156
- );
157
- this.isSaved = true;
158
- }
159
- return new WorkbookManager(this.workbookStorage, this.workbookData);
160
- }
161
-
162
- /**
163
- * Converts the workbook data to a Malloy workbook string.
164
- * @returns {string} The Malloy workbook string
165
- */
166
- toMalloyWorkbook(): string {
167
- return this.workbookData.cells
168
- .map((cell) => {
169
- if (cell.isMarkdown) {
170
- return ">>>markdown\n" + cell.value;
171
- } else {
172
- return (
173
- ">>>malloy\n" +
174
- `import {${cell.sourceName}}" from '${cell.modelPath}'"\n` +
175
- cell.value +
176
- "\n"
177
- );
178
- }
179
- })
180
- .join("\n");
181
- }
182
-
183
- static newWorkbook(workbookStorage: WorkbookStorage): WorkbookManager {
184
- return new WorkbookManager(workbookStorage, undefined);
185
- }
186
-
187
- /**
188
- * Creates a new workbook manager by loading from local storage.
189
- * Returns an empty instance if the workbook is not found.
190
- * @param workbookStorage - The storage implementation
191
- * @param userContext - The user context for storage
192
- * @param workbookPath - The path to the workbook file (relative to project/package)
193
- */
194
- static async loadWorkbook(
195
- workbookStorage: WorkbookStorage,
196
- workbookPath: WorkbookLocator,
197
- ): Promise<WorkbookManager> {
198
- let workbookData: WorkbookData | undefined = undefined;
199
- try {
200
- const saved = await workbookStorage.getWorkbook(workbookPath);
201
- if (saved) {
202
- workbookData = JSON.parse(saved);
203
- }
204
- } catch {
205
- // Not found, create a new workbook
206
- workbookData = {
207
- models: [],
208
- cells: [],
209
- workbookPath: workbookPath,
210
- };
211
- }
212
- return new WorkbookManager(workbookStorage, workbookData);
213
- }
214
- }
@@ -1,35 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- export interface Workspace {
5
- name: string;
6
- writeable: boolean;
7
- description: string;
8
- }
9
-
10
- export interface WorkbookLocator {
11
- path: string;
12
- workspace: string;
13
- }
14
-
15
- export interface WorkbookStorage {
16
- // Lists all available workspaces for the context.
17
- listWorkspaces(writeableOnly: boolean): Promise<Workspace[]>;
18
-
19
- // Lists all available workbooks for the context.
20
- // Workbooks names are like S3 paths- / denote hierarchical
21
- // folders, but otherwise folders are not "real" objects
22
- listWorkbooks(workspace: Workspace): Promise<WorkbookLocator[]>;
23
-
24
- // Returns the workbook at the specific path, throws an exception if no such workbook exists (or cannot be accessed)
25
- getWorkbook(path: WorkbookLocator): Promise<string>;
26
-
27
- // Deletes the workbook at the specified path, or throws an
28
- // Exception on failure
29
- deleteWorkbook(path: WorkbookLocator): Promise<void>;
30
-
31
- saveWorkbook(path: WorkbookLocator, workbook: string): Promise<void>;
32
-
33
- // Moves workbook from the "from" path to the "to" path
34
- moveWorkbook(from: WorkbookLocator, to: WorkbookLocator): Promise<void>;
35
- }
@@ -1,40 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import React, { createContext, useContext, useMemo } from "react";
5
- import type { WorkbookStorage } from "./WorkbookStorage";
6
-
7
- export interface WorkbookStorageProviderProps {
8
- children: React.ReactNode;
9
- workbookStorage: WorkbookStorage;
10
- }
11
-
12
- interface WorkbookStorageContextValue {
13
- workbookStorage: WorkbookStorage;
14
- }
15
-
16
- const WorkbookStorageContext = createContext<
17
- WorkbookStorageContextValue | undefined
18
- >(undefined);
19
-
20
- export function WorkbookStorageProvider({
21
- children,
22
- workbookStorage,
23
- }: WorkbookStorageProviderProps) {
24
- const value = useMemo(() => ({ workbookStorage }), [workbookStorage]);
25
- return (
26
- <WorkbookStorageContext.Provider value={value}>
27
- {children}
28
- </WorkbookStorageContext.Provider>
29
- );
30
- }
31
-
32
- export function useWorkbookStorage() {
33
- const context = useContext(WorkbookStorageContext);
34
- if (!context) {
35
- throw new Error(
36
- "useWorkbookStorage must be used within a WorkbookStorageProvider",
37
- );
38
- }
39
- return context;
40
- }
@@ -1,10 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- export type { WorkbookStorage } from "./WorkbookStorage";
5
- export { default as Workbook } from "./Workbook";
6
- export { WorkbookList } from "./WorkbookList";
7
- export { WorkbookStorageProvider } from "./WorkbookStorageProvider";
8
- export type { WorkbookLocator, Workspace } from "./WorkbookStorage";
9
- export { BrowserWorkbookStorage } from "./BrowserWorkbookStorage";
10
- export { WorkbookManager } from "./WorkbookManager";