@datalayer/core 0.0.9 → 0.0.11
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/lib/__tests__/shared/cleanup-shared.d.ts +4 -0
- package/lib/__tests__/shared/cleanup-shared.js +228 -0
- package/lib/__tests__/shared/test-config.d.ts +51 -0
- package/lib/__tests__/shared/test-config.js +110 -0
- package/lib/__tests__/shared/test-constants.d.ts +66 -0
- package/lib/__tests__/shared/test-constants.js +79 -0
- package/lib/api/DatalayerApi.d.ts +1 -1
- package/lib/api/DatalayerApi.js +73 -42
- package/lib/api/__tests__/iam.authentication.integration.test.d.ts +1 -0
- package/lib/api/__tests__/iam.authentication.integration.test.js +247 -0
- package/lib/api/__tests__/iam.healthz.integration.test.d.ts +1 -0
- package/lib/api/__tests__/iam.healthz.integration.test.js +63 -0
- package/lib/api/__tests__/iam.profile.integration.test.d.ts +1 -0
- package/lib/api/__tests__/iam.profile.integration.test.js +252 -0
- package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +1 -0
- package/lib/api/__tests__/runtimes.environments.integration.test.js +122 -0
- package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +1 -0
- package/lib/api/__tests__/runtimes.healthz.integration.test.js +50 -0
- package/lib/api/__tests__/runtimes.integration.test.d.ts +1 -0
- package/lib/api/__tests__/runtimes.integration.test.js +369 -0
- package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +1 -0
- package/lib/api/__tests__/spacer.healthz.integration.test.js +50 -0
- package/lib/api/__tests__/spacer.integration.test.d.ts +1 -0
- package/lib/api/__tests__/spacer.integration.test.js +519 -0
- package/lib/api/constants.d.ts +19 -0
- package/lib/api/constants.js +23 -0
- package/lib/api/iam/__tests__/authentication.unit.test.d.ts +1 -0
- package/lib/api/iam/__tests__/authentication.unit.test.js +63 -0
- package/lib/api/iam/__tests__/healthz.unit.test.d.ts +1 -0
- package/lib/api/iam/__tests__/healthz.unit.test.js +60 -0
- package/lib/api/iam/__tests__/profile.unit.test.d.ts +1 -0
- package/lib/api/iam/__tests__/profile.unit.test.js +57 -0
- package/lib/api/iam/authentication.d.ts +40 -0
- package/lib/api/iam/authentication.js +128 -0
- package/lib/api/iam/healthz.d.ts +15 -0
- package/lib/api/iam/healthz.js +43 -0
- package/lib/api/iam/index.d.ts +12 -0
- package/lib/api/iam/index.js +17 -0
- package/lib/api/iam/profile.d.ts +15 -0
- package/lib/api/iam/profile.js +41 -0
- package/lib/api/index.d.ts +20 -3
- package/lib/api/index.js +22 -3
- package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +1 -0
- package/lib/api/runtimes/__tests__/environments.unit.test.js +77 -0
- package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +1 -0
- package/lib/api/runtimes/__tests__/healthz.unit.test.js +57 -0
- package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +1 -0
- package/lib/api/runtimes/__tests__/runtimes.unit.test.js +139 -0
- package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +1 -0
- package/lib/api/runtimes/__tests__/snapshots.unit.test.js +96 -0
- package/lib/api/runtimes/environments.d.ts +9 -0
- package/lib/api/runtimes/environments.js +28 -0
- package/lib/api/runtimes/healthz.d.ts +25 -0
- package/lib/api/runtimes/healthz.js +43 -0
- package/lib/api/runtimes/index.d.ts +10 -5
- package/lib/api/runtimes/index.js +10 -5
- package/lib/api/runtimes/runtimes.d.ts +54 -0
- package/lib/api/runtimes/runtimes.js +169 -0
- package/lib/api/runtimes/snapshots.d.ts +34 -21
- package/lib/api/runtimes/snapshots.js +69 -138
- package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +1 -0
- package/lib/api/spacer/__tests__/healthz.unit.test.js +57 -0
- package/lib/api/spacer/__tests__/items.unit.test.d.ts +1 -0
- package/lib/api/spacer/__tests__/items.unit.test.js +165 -0
- package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +1 -0
- package/lib/api/spacer/__tests__/lexicals.unit.test.js +323 -0
- package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +1 -0
- package/lib/api/spacer/__tests__/notebooks.unit.test.js +224 -0
- package/lib/api/spacer/__tests__/users.unit.test.d.ts +1 -0
- package/lib/api/spacer/__tests__/users.unit.test.js +132 -0
- package/lib/api/spacer/healthz.d.ts +25 -0
- package/lib/api/spacer/healthz.js +43 -0
- package/lib/api/spacer/index.d.ts +13 -0
- package/lib/api/spacer/index.js +17 -0
- package/lib/api/spacer/items.d.ts +17 -0
- package/lib/api/spacer/items.js +40 -0
- package/lib/api/spacer/lexicals.d.ts +26 -0
- package/lib/api/spacer/lexicals.js +74 -0
- package/lib/api/spacer/notebooks.d.ts +26 -0
- package/lib/api/spacer/notebooks.js +74 -0
- package/lib/api/spacer/spaces.d.ts +9 -0
- package/lib/api/spacer/spaces.js +29 -0
- package/lib/api/spacer/users.d.ts +9 -0
- package/lib/api/spacer/users.js +28 -0
- package/lib/api/types/iam.d.ts +180 -0
- package/lib/api/types/index.d.ts +32 -0
- package/lib/api/types/index.js +36 -0
- package/lib/api/types/runtimes.d.ts +235 -0
- package/lib/api/types/runtimes.js +5 -0
- package/lib/api/types/spacer.d.ts +271 -0
- package/lib/api/types/spacer.js +5 -0
- package/lib/api/utils/__tests__/validation.test.d.ts +1 -0
- package/lib/api/utils/__tests__/validation.test.js +109 -0
- package/lib/api/utils/validation.d.ts +24 -0
- package/lib/api/utils/validation.js +133 -0
- package/lib/components/display/JupyterDialog.js +4 -8
- package/lib/components/progress/CreditsIndicator.d.ts +1 -1
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +2 -2
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.js +5 -2
- package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.js +1 -1
- package/lib/components/runtimes/RuntimePickerCell.js +2 -1
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
- package/lib/components/runtimes/RuntimeSimplePicker.js +2 -1
- package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
- package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +2 -2
- package/lib/components/snippets/SnippetDialog.js +1 -1
- package/lib/components/storage/ContentsBrowser.js +2 -2
- package/lib/components/tables/DataTable.js +2 -1
- package/lib/hooks/useDatalayer.d.ts +1 -1
- package/lib/hooks/useDatalayer.js +1 -1
- package/lib/hooks/useIAM.js +1 -1
- package/lib/hooks/useRuntimes.js +1 -1
- package/lib/index.d.ts +9 -0
- package/lib/index.js +10 -0
- package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +1 -0
- package/lib/sdk/client/__tests__/sdk.health.integration.test.js +110 -0
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +1 -0
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +179 -0
- package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +1 -0
- package/lib/sdk/client/__tests__/sdk.models.integration.test.js +376 -0
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +1 -0
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +276 -0
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +1 -0
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +361 -0
- package/lib/sdk/client/base.d.ts +88 -0
- package/lib/sdk/client/base.js +112 -0
- package/lib/sdk/client/index.d.ts +192 -0
- package/lib/sdk/client/index.js +128 -0
- package/lib/sdk/client/mixins/HealthMixin.d.ts +100 -0
- package/lib/sdk/client/mixins/HealthMixin.js +133 -0
- package/lib/sdk/client/mixins/IAMMixin.d.ts +59 -0
- package/lib/sdk/client/mixins/IAMMixin.js +83 -0
- package/lib/sdk/client/mixins/RuntimesMixin.d.ts +134 -0
- package/lib/sdk/client/mixins/RuntimesMixin.js +221 -0
- package/lib/sdk/client/mixins/SpacerMixin.d.ts +184 -0
- package/lib/sdk/client/mixins/SpacerMixin.js +278 -0
- package/lib/sdk/client/models/Lexical.d.ts +156 -0
- package/lib/sdk/client/models/Lexical.js +275 -0
- package/lib/sdk/client/models/Notebook.d.ts +174 -0
- package/lib/sdk/client/models/Notebook.js +311 -0
- package/lib/sdk/client/models/Runtime.d.ts +221 -0
- package/lib/sdk/client/models/Runtime.js +341 -0
- package/lib/sdk/client/models/Snapshot.d.ts +156 -0
- package/lib/sdk/client/models/Snapshot.js +244 -0
- package/lib/sdk/client/models/Space.d.ts +182 -0
- package/lib/sdk/client/models/Space.js +276 -0
- package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +1 -0
- package/lib/sdk/client/models/__tests__/Lexical.test.js +288 -0
- package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +1 -0
- package/lib/sdk/client/models/__tests__/Notebook.test.js +206 -0
- package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +1 -0
- package/lib/sdk/client/models/__tests__/Runtime.test.js +133 -0
- package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +1 -0
- package/lib/sdk/client/models/__tests__/Snapshot.test.js +244 -0
- package/lib/sdk/client/models/__tests__/Space.test.d.ts +1 -0
- package/lib/sdk/client/models/__tests__/Space.test.js +334 -0
- package/lib/sdk/client/models/index.d.ts +30 -0
- package/lib/sdk/client/models/index.js +30 -0
- package/lib/sdk/client/utils/mixins.d.ts +42 -0
- package/lib/sdk/client/utils/mixins.js +47 -0
- package/lib/sdk/index.d.ts +26 -0
- package/lib/sdk/index.js +32 -0
- package/lib/sdk/stateful/index.d.ts +3 -0
- package/lib/sdk/stateful/index.js +7 -0
- package/lib/{api → sdk/stateful}/runtimes/actions.d.ts +1 -1
- package/lib/{api → sdk/stateful}/runtimes/actions.js +3 -3
- package/lib/{api → sdk/stateful}/runtimes/apis.d.ts +1 -1
- package/lib/sdk/stateful/runtimes/apis.js +5 -0
- package/lib/sdk/stateful/runtimes/index.d.ts +5 -0
- package/lib/sdk/stateful/runtimes/index.js +9 -0
- package/lib/sdk/stateful/runtimes/snapshots.d.ts +25 -0
- package/lib/sdk/stateful/runtimes/snapshots.js +150 -0
- package/lib/services/DatalayerServiceManager.js +1 -1
- package/lib/state/substates/IAMState.js +1 -1
- package/lib/state/substates/RuntimesState.d.ts +1 -1
- package/lib/state/substates/RuntimesState.js +1 -1
- package/lib/state/substates/SurveysState.js +1 -1
- package/lib/test-setup.js +1 -0
- package/package.json +19 -9
- /package/lib/api/{runtimes/apis.js → types/iam.js} +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/exec/Python.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/exec/Python.js +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.js +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/exec/index.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/exec/index.js +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/index.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/index.js +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.js +0 -0
- /package/lib/{api → sdk/stateful}/runtimes/settings.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/runtimes/settings.js +0 -0
- /package/lib/{api → sdk/stateful}/runtimes/utils.d.ts +0 -0
- /package/lib/{api → sdk/stateful}/runtimes/utils.js +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sdk/client/models/Notebook
|
|
3
|
+
* @description Notebook domain model for the Datalayer SDK.
|
|
4
|
+
*
|
|
5
|
+
* This model provides a rich, object-oriented interface for working with
|
|
6
|
+
* Jupyter notebooks, including content management and lifecycle operations.
|
|
7
|
+
*/
|
|
8
|
+
import type { Notebook as NotebookData, UpdateNotebookRequest } from '../../../api/types/spacer';
|
|
9
|
+
import type { DatalayerSDK } from '../index';
|
|
10
|
+
/**
|
|
11
|
+
* Notebook domain model that wraps API responses with convenient methods.
|
|
12
|
+
*
|
|
13
|
+
* Provides a rich, object-oriented interface for managing Jupyter notebooks
|
|
14
|
+
* with automatic data refresh and lifecycle operations.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const formData = new FormData();
|
|
19
|
+
* formData.append('spaceId', 'space-123');
|
|
20
|
+
* formData.append('name', 'Data Analysis');
|
|
21
|
+
* const notebook = await sdk.createNotebook(formData);
|
|
22
|
+
*
|
|
23
|
+
* // Static properties - instant access
|
|
24
|
+
* console.log(notebook.id);
|
|
25
|
+
* console.log(notebook.spaceId);
|
|
26
|
+
*
|
|
27
|
+
* // Dynamic data - always fresh from API
|
|
28
|
+
* const currentName = await notebook.getName();
|
|
29
|
+
* const content = await notebook.getContent();
|
|
30
|
+
*
|
|
31
|
+
* // Update notebook
|
|
32
|
+
* const updated = await notebook.update({ name: 'New Analysis' });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class Notebook {
|
|
36
|
+
protected _data: NotebookData;
|
|
37
|
+
private _sdk;
|
|
38
|
+
private _deleted;
|
|
39
|
+
private _freshData;
|
|
40
|
+
private _lastFetch;
|
|
41
|
+
private _cacheTimeout;
|
|
42
|
+
/**
|
|
43
|
+
* Create a Notebook instance.
|
|
44
|
+
*
|
|
45
|
+
* @param data - Raw notebook data from API
|
|
46
|
+
* @param sdk - DatalayerSDK instance for making API calls
|
|
47
|
+
*/
|
|
48
|
+
constructor(data: NotebookData, sdk: DatalayerSDK);
|
|
49
|
+
/**
|
|
50
|
+
* Check if this notebook has been deleted.
|
|
51
|
+
*/
|
|
52
|
+
get isDeleted(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if this notebook has been deleted and throw error if so.
|
|
55
|
+
* @throws Error if the notebook has been deleted
|
|
56
|
+
*/
|
|
57
|
+
private _checkDeleted;
|
|
58
|
+
/**
|
|
59
|
+
* Get fresh data from API with caching to avoid redundant calls.
|
|
60
|
+
* @returns Current NotebookData from API or cache
|
|
61
|
+
*/
|
|
62
|
+
private _getFreshData;
|
|
63
|
+
/**
|
|
64
|
+
* Notebook ID.
|
|
65
|
+
*/
|
|
66
|
+
get id(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Unique identifier for the notebook.
|
|
69
|
+
*/
|
|
70
|
+
get uid(): string;
|
|
71
|
+
/**
|
|
72
|
+
* File path within the space.
|
|
73
|
+
*/
|
|
74
|
+
get path(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Parent space ID.
|
|
77
|
+
*/
|
|
78
|
+
get spaceId(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Owner user ID.
|
|
81
|
+
*/
|
|
82
|
+
get ownerId(): string;
|
|
83
|
+
/**
|
|
84
|
+
* When the notebook was created.
|
|
85
|
+
*/
|
|
86
|
+
get createdAt(): Date;
|
|
87
|
+
/**
|
|
88
|
+
* Version number.
|
|
89
|
+
*/
|
|
90
|
+
get version(): number;
|
|
91
|
+
/**
|
|
92
|
+
* Notebook metadata.
|
|
93
|
+
*/
|
|
94
|
+
get metadata(): Record<string, any>;
|
|
95
|
+
/**
|
|
96
|
+
* Get the current name of the notebook.
|
|
97
|
+
*
|
|
98
|
+
* This method fetches fresh data from the API (with caching) and updates
|
|
99
|
+
* the internal data to keep everything in sync.
|
|
100
|
+
*
|
|
101
|
+
* @returns Promise resolving to current notebook name
|
|
102
|
+
* @throws Error if the notebook has been deleted
|
|
103
|
+
*/
|
|
104
|
+
getName(): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* Get the notebook content (cells, etc.).
|
|
107
|
+
*
|
|
108
|
+
* @returns Promise resolving to notebook content
|
|
109
|
+
*/
|
|
110
|
+
getContent(): Promise<any>;
|
|
111
|
+
/**
|
|
112
|
+
* Get the kernel specification.
|
|
113
|
+
*
|
|
114
|
+
* @returns Promise resolving to kernel spec
|
|
115
|
+
*/
|
|
116
|
+
getKernelSpec(): Promise<any>;
|
|
117
|
+
/**
|
|
118
|
+
* Get when the notebook was last updated.
|
|
119
|
+
*
|
|
120
|
+
* @returns Promise resolving to last update time
|
|
121
|
+
*/
|
|
122
|
+
getUpdatedAt(): Promise<Date>;
|
|
123
|
+
/**
|
|
124
|
+
* Update the notebook name and/or description.
|
|
125
|
+
*
|
|
126
|
+
* @param data - Update data containing name and/or description
|
|
127
|
+
* @returns Promise resolving to updated Notebook instance
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const updated = await notebook.update({
|
|
132
|
+
* name: 'Advanced Analysis',
|
|
133
|
+
* description: 'Updated analysis notebook'
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
update(data: UpdateNotebookRequest): Promise<Notebook>;
|
|
138
|
+
/**
|
|
139
|
+
* Delete this notebook permanently.
|
|
140
|
+
*
|
|
141
|
+
* After deletion, this object will be marked as deleted and subsequent
|
|
142
|
+
* calls to dynamic methods will throw errors.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* await notebook.delete();
|
|
147
|
+
* console.log('Notebook deleted');
|
|
148
|
+
* // notebook.getName() will now throw an error
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
delete(): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Get raw notebook data object with latest information.
|
|
154
|
+
*
|
|
155
|
+
* This method ensures the returned data includes the most recent information
|
|
156
|
+
* by refreshing from the API before returning.
|
|
157
|
+
*
|
|
158
|
+
* @returns Promise resolving to raw notebook data
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const latestData = await notebook.toJSON();
|
|
163
|
+
* console.log('Current name:', latestData.name);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
toJSON(): Promise<NotebookData>;
|
|
167
|
+
/**
|
|
168
|
+
* String representation of the notebook.
|
|
169
|
+
*
|
|
170
|
+
* @returns String representation for logging/debugging
|
|
171
|
+
*/
|
|
172
|
+
toString(): string;
|
|
173
|
+
}
|
|
174
|
+
export type { NotebookData };
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
import { notebooks } from '../../../api/spacer';
|
|
6
|
+
import { items } from '../../../api/spacer';
|
|
7
|
+
/**
|
|
8
|
+
* Notebook domain model that wraps API responses with convenient methods.
|
|
9
|
+
*
|
|
10
|
+
* Provides a rich, object-oriented interface for managing Jupyter notebooks
|
|
11
|
+
* with automatic data refresh and lifecycle operations.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const formData = new FormData();
|
|
16
|
+
* formData.append('spaceId', 'space-123');
|
|
17
|
+
* formData.append('name', 'Data Analysis');
|
|
18
|
+
* const notebook = await sdk.createNotebook(formData);
|
|
19
|
+
*
|
|
20
|
+
* // Static properties - instant access
|
|
21
|
+
* console.log(notebook.id);
|
|
22
|
+
* console.log(notebook.spaceId);
|
|
23
|
+
*
|
|
24
|
+
* // Dynamic data - always fresh from API
|
|
25
|
+
* const currentName = await notebook.getName();
|
|
26
|
+
* const content = await notebook.getContent();
|
|
27
|
+
*
|
|
28
|
+
* // Update notebook
|
|
29
|
+
* const updated = await notebook.update({ name: 'New Analysis' });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class Notebook {
|
|
33
|
+
_data;
|
|
34
|
+
_sdk;
|
|
35
|
+
_deleted = false;
|
|
36
|
+
_freshData = null;
|
|
37
|
+
_lastFetch = 0;
|
|
38
|
+
_cacheTimeout = 5000; // 5 seconds cache timeout
|
|
39
|
+
/**
|
|
40
|
+
* Create a Notebook instance.
|
|
41
|
+
*
|
|
42
|
+
* @param data - Raw notebook data from API
|
|
43
|
+
* @param sdk - DatalayerSDK instance for making API calls
|
|
44
|
+
*/
|
|
45
|
+
constructor(data, sdk) {
|
|
46
|
+
this._data = data;
|
|
47
|
+
this._sdk = sdk;
|
|
48
|
+
}
|
|
49
|
+
// ========================================================================
|
|
50
|
+
// Deletion State
|
|
51
|
+
// ========================================================================
|
|
52
|
+
/**
|
|
53
|
+
* Check if this notebook has been deleted.
|
|
54
|
+
*/
|
|
55
|
+
get isDeleted() {
|
|
56
|
+
return this._deleted;
|
|
57
|
+
}
|
|
58
|
+
// ========================================================================
|
|
59
|
+
// Helper Methods
|
|
60
|
+
// ========================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Check if this notebook has been deleted and throw error if so.
|
|
63
|
+
* @throws Error if the notebook has been deleted
|
|
64
|
+
*/
|
|
65
|
+
_checkDeleted() {
|
|
66
|
+
if (this._deleted) {
|
|
67
|
+
throw new Error(`Notebook ${this._data.id} has been deleted and no longer exists`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get fresh data from API with caching to avoid redundant calls.
|
|
72
|
+
* @returns Current NotebookData from API or cache
|
|
73
|
+
*/
|
|
74
|
+
async _getFreshData() {
|
|
75
|
+
this._checkDeleted();
|
|
76
|
+
const now = Date.now();
|
|
77
|
+
if (this._freshData && now - this._lastFetch < this._cacheTimeout) {
|
|
78
|
+
// Return cached data if recent enough
|
|
79
|
+
return this._freshData;
|
|
80
|
+
}
|
|
81
|
+
// Fetch fresh data from API
|
|
82
|
+
const token = this._sdk.getToken();
|
|
83
|
+
const spacerRunUrl = this._sdk.getSpacerRunUrl();
|
|
84
|
+
const response = await notebooks.getNotebook(token, this.uid, spacerRunUrl);
|
|
85
|
+
if (response.notebook) {
|
|
86
|
+
this._freshData = response.notebook;
|
|
87
|
+
this._data = response.notebook; // Keep internal data up to date
|
|
88
|
+
this._lastFetch = now;
|
|
89
|
+
return this._freshData;
|
|
90
|
+
}
|
|
91
|
+
return this._data; // Fallback to existing data
|
|
92
|
+
}
|
|
93
|
+
// ========================================================================
|
|
94
|
+
// Static Properties (set at creation, never change)
|
|
95
|
+
// ========================================================================
|
|
96
|
+
/**
|
|
97
|
+
* Notebook ID.
|
|
98
|
+
*/
|
|
99
|
+
get id() {
|
|
100
|
+
this._checkDeleted();
|
|
101
|
+
return this._data.id;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Unique identifier for the notebook.
|
|
105
|
+
*/
|
|
106
|
+
get uid() {
|
|
107
|
+
this._checkDeleted();
|
|
108
|
+
return this._data.uid;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* File path within the space.
|
|
112
|
+
*/
|
|
113
|
+
get path() {
|
|
114
|
+
this._checkDeleted();
|
|
115
|
+
return this._data.path || '';
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Parent space ID.
|
|
119
|
+
*/
|
|
120
|
+
get spaceId() {
|
|
121
|
+
this._checkDeleted();
|
|
122
|
+
// Try the direct field first (if API provides it)
|
|
123
|
+
if (this._data.space_id) {
|
|
124
|
+
return this._data.space_id;
|
|
125
|
+
}
|
|
126
|
+
// Extract from s3_path_s if available: "datalayer.app/SPACE_ID/nbformat/..."
|
|
127
|
+
const s3Path = this._data.s3_path_s;
|
|
128
|
+
if (s3Path && typeof s3Path === 'string') {
|
|
129
|
+
const match = s3Path.match(/^datalayer\.app\/([^/]+)\//);
|
|
130
|
+
if (match) {
|
|
131
|
+
return match[1];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Fallback to empty string if no space ID can be determined
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Owner user ID.
|
|
139
|
+
*/
|
|
140
|
+
get ownerId() {
|
|
141
|
+
this._checkDeleted();
|
|
142
|
+
return this._data.owner_id || this._data.creator_uid || '';
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* When the notebook was created.
|
|
146
|
+
*/
|
|
147
|
+
get createdAt() {
|
|
148
|
+
this._checkDeleted();
|
|
149
|
+
const dateStr = this._data.creation_ts_dt || this._data.created_at;
|
|
150
|
+
if (!dateStr) {
|
|
151
|
+
throw new Error('No creation timestamp available for notebook');
|
|
152
|
+
}
|
|
153
|
+
return new Date(dateStr);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Version number.
|
|
157
|
+
*/
|
|
158
|
+
get version() {
|
|
159
|
+
this._checkDeleted();
|
|
160
|
+
return this._data.version || 0;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Notebook metadata.
|
|
164
|
+
*/
|
|
165
|
+
get metadata() {
|
|
166
|
+
this._checkDeleted();
|
|
167
|
+
return this._data.metadata || {};
|
|
168
|
+
}
|
|
169
|
+
// ========================================================================
|
|
170
|
+
// Dynamic Methods (always fetch fresh data and update internal state)
|
|
171
|
+
// ========================================================================
|
|
172
|
+
/**
|
|
173
|
+
* Get the current name of the notebook.
|
|
174
|
+
*
|
|
175
|
+
* This method fetches fresh data from the API (with caching) and updates
|
|
176
|
+
* the internal data to keep everything in sync.
|
|
177
|
+
*
|
|
178
|
+
* @returns Promise resolving to current notebook name
|
|
179
|
+
* @throws Error if the notebook has been deleted
|
|
180
|
+
*/
|
|
181
|
+
async getName() {
|
|
182
|
+
const freshData = await this._getFreshData();
|
|
183
|
+
return (freshData.name_t ||
|
|
184
|
+
freshData.notebook_name_s ||
|
|
185
|
+
freshData.name ||
|
|
186
|
+
'');
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the notebook content (cells, etc.).
|
|
190
|
+
*
|
|
191
|
+
* @returns Promise resolving to notebook content
|
|
192
|
+
*/
|
|
193
|
+
async getContent() {
|
|
194
|
+
const freshData = await this._getFreshData();
|
|
195
|
+
// Try to parse model_s if content is not available
|
|
196
|
+
if (!freshData.content && freshData.model_s) {
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(freshData.model_s);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Fall back to raw model_s if parsing fails
|
|
202
|
+
return freshData.model_s;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return freshData.content;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get the kernel specification.
|
|
209
|
+
*
|
|
210
|
+
* @returns Promise resolving to kernel spec
|
|
211
|
+
*/
|
|
212
|
+
async getKernelSpec() {
|
|
213
|
+
const freshData = await this._getFreshData();
|
|
214
|
+
return freshData.kernel_spec;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get when the notebook was last updated.
|
|
218
|
+
*
|
|
219
|
+
* @returns Promise resolving to last update time
|
|
220
|
+
*/
|
|
221
|
+
async getUpdatedAt() {
|
|
222
|
+
const freshData = await this._getFreshData();
|
|
223
|
+
const dateStr = freshData.last_update_ts_dt ||
|
|
224
|
+
freshData.updated_at ||
|
|
225
|
+
freshData.creation_ts_dt ||
|
|
226
|
+
freshData.created_at;
|
|
227
|
+
if (!dateStr) {
|
|
228
|
+
throw new Error('No timestamp available for notebook');
|
|
229
|
+
}
|
|
230
|
+
return new Date(dateStr);
|
|
231
|
+
}
|
|
232
|
+
// ========================================================================
|
|
233
|
+
// Action Methods
|
|
234
|
+
// ========================================================================
|
|
235
|
+
/**
|
|
236
|
+
* Update the notebook name and/or description.
|
|
237
|
+
*
|
|
238
|
+
* @param data - Update data containing name and/or description
|
|
239
|
+
* @returns Promise resolving to updated Notebook instance
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const updated = await notebook.update({
|
|
244
|
+
* name: 'Advanced Analysis',
|
|
245
|
+
* description: 'Updated analysis notebook'
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
async update(data) {
|
|
250
|
+
this._checkDeleted();
|
|
251
|
+
const token = this._sdk.getToken();
|
|
252
|
+
const spacerRunUrl = this._sdk.getSpacerRunUrl();
|
|
253
|
+
const response = await notebooks.updateNotebook(token, this.uid, data, spacerRunUrl);
|
|
254
|
+
return new Notebook(response.notebook, this._sdk);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Delete this notebook permanently.
|
|
258
|
+
*
|
|
259
|
+
* After deletion, this object will be marked as deleted and subsequent
|
|
260
|
+
* calls to dynamic methods will throw errors.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* await notebook.delete();
|
|
265
|
+
* console.log('Notebook deleted');
|
|
266
|
+
* // notebook.getName() will now throw an error
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
async delete() {
|
|
270
|
+
this._checkDeleted(); // Add check to prevent double deletion
|
|
271
|
+
const token = this._sdk.getToken();
|
|
272
|
+
const spacerRunUrl = this._sdk.getSpacerRunUrl();
|
|
273
|
+
await items.deleteItem(token, this.uid, spacerRunUrl);
|
|
274
|
+
this._deleted = true;
|
|
275
|
+
}
|
|
276
|
+
// ========================================================================
|
|
277
|
+
// Utility Methods
|
|
278
|
+
// ========================================================================
|
|
279
|
+
/**
|
|
280
|
+
* Get raw notebook data object with latest information.
|
|
281
|
+
*
|
|
282
|
+
* This method ensures the returned data includes the most recent information
|
|
283
|
+
* by refreshing from the API before returning.
|
|
284
|
+
*
|
|
285
|
+
* @returns Promise resolving to raw notebook data
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const latestData = await notebook.toJSON();
|
|
290
|
+
* console.log('Current name:', latestData.name);
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
async toJSON() {
|
|
294
|
+
this._checkDeleted();
|
|
295
|
+
await this.getName(); // This updates internal data
|
|
296
|
+
return this._data;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* String representation of the notebook.
|
|
300
|
+
*
|
|
301
|
+
* @returns String representation for logging/debugging
|
|
302
|
+
*/
|
|
303
|
+
toString() {
|
|
304
|
+
this._checkDeleted();
|
|
305
|
+
const name = this._data.name_t ||
|
|
306
|
+
this._data.notebook_name_s ||
|
|
307
|
+
this._data.name ||
|
|
308
|
+
'Unnamed';
|
|
309
|
+
return `Notebook(${this.id}, ${name})`;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { Runtime as RuntimeData } from '../../../api/types/runtimes';
|
|
2
|
+
import type { DatalayerSDK } from '../index';
|
|
3
|
+
import { Snapshot } from './Snapshot';
|
|
4
|
+
/**
|
|
5
|
+
* Runtime domain model that wraps API responses with convenient methods.
|
|
6
|
+
*
|
|
7
|
+
* Provides a rich, object-oriented interface for managing computational runtimes
|
|
8
|
+
* with automatic state refresh and lifecycle operations.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const runtime = await sdk.createRuntime({
|
|
13
|
+
* environment_name: 'python-cpu'
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Static properties - instant access
|
|
17
|
+
* console.log(runtime.podName);
|
|
18
|
+
* console.log(runtime.jupyterUrl);
|
|
19
|
+
*
|
|
20
|
+
* // Dynamic state - always fresh from API
|
|
21
|
+
* if (await runtime.isRunning()) {
|
|
22
|
+
* console.log('Runtime is ready!');
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* // Wait for runtime to be ready
|
|
26
|
+
* await runtime.waitUntilReady();
|
|
27
|
+
*
|
|
28
|
+
* // Create snapshot
|
|
29
|
+
* const snapshot = await runtime.createSnapshot('my-snapshot');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class Runtime {
|
|
33
|
+
protected _data: RuntimeData;
|
|
34
|
+
private _sdk;
|
|
35
|
+
private _deleted;
|
|
36
|
+
/**
|
|
37
|
+
* Create a Runtime instance.
|
|
38
|
+
*
|
|
39
|
+
* @param data - Raw runtime data from API
|
|
40
|
+
* @param sdk - DatalayerSDK instance for making API calls
|
|
41
|
+
*/
|
|
42
|
+
constructor(data: RuntimeData, sdk: DatalayerSDK);
|
|
43
|
+
/**
|
|
44
|
+
* Check if this runtime has been deleted and throw error if so.
|
|
45
|
+
* @throws Error if the runtime has been deleted
|
|
46
|
+
*/
|
|
47
|
+
private _checkDeleted;
|
|
48
|
+
/**
|
|
49
|
+
* Kubernetes pod name for the runtime instance.
|
|
50
|
+
*/
|
|
51
|
+
get podName(): string;
|
|
52
|
+
/**
|
|
53
|
+
* Unique identifier for the runtime.
|
|
54
|
+
*/
|
|
55
|
+
get uid(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Name of the environment this runtime is based on.
|
|
58
|
+
*/
|
|
59
|
+
get environmentName(): string;
|
|
60
|
+
/**
|
|
61
|
+
* URL for accessing Jupyter server.
|
|
62
|
+
*/
|
|
63
|
+
get jupyterUrl(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Token for Jupyter server authentication.
|
|
66
|
+
*/
|
|
67
|
+
get jupyterToken(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Credits consumed per hour.
|
|
70
|
+
*/
|
|
71
|
+
get burningRate(): number;
|
|
72
|
+
/**
|
|
73
|
+
* User-friendly name for the runtime.
|
|
74
|
+
*/
|
|
75
|
+
get givenName(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Type of runtime (notebook, terminal, or job).
|
|
78
|
+
*/
|
|
79
|
+
get type(): string;
|
|
80
|
+
/**
|
|
81
|
+
* When the runtime was created.
|
|
82
|
+
*/
|
|
83
|
+
get createdAt(): Date;
|
|
84
|
+
/**
|
|
85
|
+
* When the runtime started.
|
|
86
|
+
*/
|
|
87
|
+
get startedAt(): Date;
|
|
88
|
+
/**
|
|
89
|
+
* When the runtime will expire.
|
|
90
|
+
*/
|
|
91
|
+
get expiredAt(): Date;
|
|
92
|
+
/**
|
|
93
|
+
* Get the current state of the runtime.
|
|
94
|
+
*
|
|
95
|
+
* This method always fetches fresh data from the API and updates
|
|
96
|
+
* the internal data to keep everything in sync.
|
|
97
|
+
*
|
|
98
|
+
* @returns Promise resolving to current runtime state
|
|
99
|
+
* @throws Error if the runtime has been deleted
|
|
100
|
+
*/
|
|
101
|
+
getState(): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Check if runtime is in running state.
|
|
104
|
+
*
|
|
105
|
+
* @returns Promise resolving to true if runtime is running
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* if (await runtime.isRunning()) {
|
|
110
|
+
* console.log('Runtime is ready for use');
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
isRunning(): Promise<boolean>;
|
|
115
|
+
/**
|
|
116
|
+
* Check if runtime is in starting state.
|
|
117
|
+
*
|
|
118
|
+
* @returns Promise resolving to true if runtime is starting
|
|
119
|
+
*/
|
|
120
|
+
isStarting(): Promise<boolean>;
|
|
121
|
+
/**
|
|
122
|
+
* Check if runtime is in stopping state.
|
|
123
|
+
*
|
|
124
|
+
* @returns Promise resolving to true if runtime is stopping
|
|
125
|
+
*/
|
|
126
|
+
isStopping(): Promise<boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* Check if runtime is in stopped state.
|
|
129
|
+
*
|
|
130
|
+
* @returns Promise resolving to true if runtime is stopped
|
|
131
|
+
*/
|
|
132
|
+
isStopped(): Promise<boolean>;
|
|
133
|
+
/**
|
|
134
|
+
* Check if runtime is in error state.
|
|
135
|
+
*
|
|
136
|
+
* @returns Promise resolving to true if runtime has error
|
|
137
|
+
*/
|
|
138
|
+
hasError(): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Delete this runtime permanently.
|
|
141
|
+
*
|
|
142
|
+
* After deletion, this object will be marked as deleted and subsequent
|
|
143
|
+
* calls to dynamic methods will throw errors.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* await runtime.delete();
|
|
148
|
+
* console.log('Runtime deleted');
|
|
149
|
+
* // runtime.getState() will now throw an error
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
delete(): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Update runtime from a snapshot.
|
|
155
|
+
*
|
|
156
|
+
* @param from - Snapshot identifier to restore from
|
|
157
|
+
* @returns Promise resolving to updated Runtime instance
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const updatedRuntime = await runtime.update('snapshot-uid');
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
update(from: string): Promise<Runtime>;
|
|
165
|
+
/**
|
|
166
|
+
* Create a snapshot of this runtime.
|
|
167
|
+
*
|
|
168
|
+
* @param name - Name for the snapshot
|
|
169
|
+
* @param description - Optional description for the snapshot
|
|
170
|
+
* @param stop - Whether to stop the runtime after snapshotting
|
|
171
|
+
* @returns Promise resolving to created Snapshot instance
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const snapshot = await runtime.createSnapshot(
|
|
176
|
+
* 'my-checkpoint',
|
|
177
|
+
* 'Before major changes'
|
|
178
|
+
* );
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
createSnapshot(name: string, description?: string, stop?: boolean): Promise<Snapshot>;
|
|
182
|
+
/**
|
|
183
|
+
* Wait for runtime to reach running state.
|
|
184
|
+
*
|
|
185
|
+
* Polls the runtime state until it becomes 'running' or throws on error/timeout.
|
|
186
|
+
*
|
|
187
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 60000)
|
|
188
|
+
* @returns Promise resolving to this Runtime instance when ready
|
|
189
|
+
* @throws Error if runtime enters error state or timeout is reached
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const runtime = await sdk.createRuntime(config);
|
|
194
|
+
* await runtime.waitUntilReady();
|
|
195
|
+
* console.log('Runtime is ready to use!');
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
waitUntilReady(timeoutMs?: number): Promise<Runtime>;
|
|
199
|
+
/**
|
|
200
|
+
* Get raw runtime data object with latest state.
|
|
201
|
+
*
|
|
202
|
+
* This method ensures the returned data includes the most recent state
|
|
203
|
+
* by refreshing from the API before returning.
|
|
204
|
+
*
|
|
205
|
+
* @returns Promise resolving to raw runtime data
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const latestData = await runtime.toJSON();
|
|
210
|
+
* console.log('Current state:', latestData.state);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
toJSON(): Promise<RuntimeData>;
|
|
214
|
+
/**
|
|
215
|
+
* String representation of the runtime.
|
|
216
|
+
*
|
|
217
|
+
* @returns String representation for logging/debugging
|
|
218
|
+
*/
|
|
219
|
+
toString(): string;
|
|
220
|
+
}
|
|
221
|
+
export type { RuntimeData };
|