@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,341 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module sdk/client/models/Runtime
|
|
7
|
+
* @description Runtime domain model for the Datalayer SDK.
|
|
8
|
+
*
|
|
9
|
+
* This model provides a rich, object-oriented interface for working with
|
|
10
|
+
* computational runtimes, including state management and lifecycle operations.
|
|
11
|
+
*/
|
|
12
|
+
import { updateRuntime } from '../../../api/runtimes/runtimes';
|
|
13
|
+
/**
|
|
14
|
+
* Runtime domain model that wraps API responses with convenient methods.
|
|
15
|
+
*
|
|
16
|
+
* Provides a rich, object-oriented interface for managing computational runtimes
|
|
17
|
+
* with automatic state refresh and lifecycle operations.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const runtime = await sdk.createRuntime({
|
|
22
|
+
* environment_name: 'python-cpu'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Static properties - instant access
|
|
26
|
+
* console.log(runtime.podName);
|
|
27
|
+
* console.log(runtime.jupyterUrl);
|
|
28
|
+
*
|
|
29
|
+
* // Dynamic state - always fresh from API
|
|
30
|
+
* if (await runtime.isRunning()) {
|
|
31
|
+
* console.log('Runtime is ready!');
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // Wait for runtime to be ready
|
|
35
|
+
* await runtime.waitUntilReady();
|
|
36
|
+
*
|
|
37
|
+
* // Create snapshot
|
|
38
|
+
* const snapshot = await runtime.createSnapshot('my-snapshot');
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class Runtime {
|
|
42
|
+
_data;
|
|
43
|
+
_sdk;
|
|
44
|
+
_deleted = false;
|
|
45
|
+
/**
|
|
46
|
+
* Create a Runtime instance.
|
|
47
|
+
*
|
|
48
|
+
* @param data - Raw runtime data from API
|
|
49
|
+
* @param sdk - DatalayerSDK instance for making API calls
|
|
50
|
+
*/
|
|
51
|
+
constructor(data, sdk) {
|
|
52
|
+
this._data = data;
|
|
53
|
+
this._sdk = sdk;
|
|
54
|
+
}
|
|
55
|
+
// ========================================================================
|
|
56
|
+
// Helper Methods
|
|
57
|
+
// ========================================================================
|
|
58
|
+
/**
|
|
59
|
+
* Check if this runtime has been deleted and throw error if so.
|
|
60
|
+
* @throws Error if the runtime has been deleted
|
|
61
|
+
*/
|
|
62
|
+
_checkDeleted() {
|
|
63
|
+
if (this._deleted) {
|
|
64
|
+
throw new Error(`Runtime ${this._data.pod_name} has been deleted and no longer exists`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ========================================================================
|
|
68
|
+
// Static Properties (set at creation, never change)
|
|
69
|
+
// ========================================================================
|
|
70
|
+
/**
|
|
71
|
+
* Kubernetes pod name for the runtime instance.
|
|
72
|
+
*/
|
|
73
|
+
get podName() {
|
|
74
|
+
this._checkDeleted();
|
|
75
|
+
return this._data.pod_name;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Unique identifier for the runtime.
|
|
79
|
+
*/
|
|
80
|
+
get uid() {
|
|
81
|
+
this._checkDeleted();
|
|
82
|
+
return this._data.uid;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Name of the environment this runtime is based on.
|
|
86
|
+
*/
|
|
87
|
+
get environmentName() {
|
|
88
|
+
this._checkDeleted();
|
|
89
|
+
return this._data.environment_name;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* URL for accessing Jupyter server.
|
|
93
|
+
*/
|
|
94
|
+
get jupyterUrl() {
|
|
95
|
+
this._checkDeleted();
|
|
96
|
+
return this._data.jupyter_url || '';
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Token for Jupyter server authentication.
|
|
100
|
+
*/
|
|
101
|
+
get jupyterToken() {
|
|
102
|
+
this._checkDeleted();
|
|
103
|
+
return this._data.jupyter_token || '';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Credits consumed per hour.
|
|
107
|
+
*/
|
|
108
|
+
get burningRate() {
|
|
109
|
+
this._checkDeleted();
|
|
110
|
+
return this._data.burning_rate;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* User-friendly name for the runtime.
|
|
114
|
+
*/
|
|
115
|
+
get givenName() {
|
|
116
|
+
this._checkDeleted();
|
|
117
|
+
return this._data.given_name || '';
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Type of runtime (notebook, terminal, or job).
|
|
121
|
+
*/
|
|
122
|
+
get type() {
|
|
123
|
+
this._checkDeleted();
|
|
124
|
+
return this._data.type || 'notebook';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* When the runtime was created.
|
|
128
|
+
*/
|
|
129
|
+
get createdAt() {
|
|
130
|
+
this._checkDeleted();
|
|
131
|
+
return new Date(this._data.created_at || '');
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* When the runtime started.
|
|
135
|
+
*/
|
|
136
|
+
get startedAt() {
|
|
137
|
+
this._checkDeleted();
|
|
138
|
+
return new Date(this._data.started_at || '');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* When the runtime will expire.
|
|
142
|
+
*/
|
|
143
|
+
get expiredAt() {
|
|
144
|
+
this._checkDeleted();
|
|
145
|
+
return new Date(this._data.expired_at || '');
|
|
146
|
+
}
|
|
147
|
+
// ========================================================================
|
|
148
|
+
// Dynamic State (always fetches fresh and updates internal data)
|
|
149
|
+
// ========================================================================
|
|
150
|
+
/**
|
|
151
|
+
* Get the current state of the runtime.
|
|
152
|
+
*
|
|
153
|
+
* This method always fetches fresh data from the API and updates
|
|
154
|
+
* the internal data to keep everything in sync.
|
|
155
|
+
*
|
|
156
|
+
* @returns Promise resolving to current runtime state
|
|
157
|
+
* @throws Error if the runtime has been deleted
|
|
158
|
+
*/
|
|
159
|
+
async getState() {
|
|
160
|
+
this._checkDeleted();
|
|
161
|
+
const freshRuntime = await this._sdk.getRuntime(this.podName);
|
|
162
|
+
// Update internal data with fresh runtime data
|
|
163
|
+
this._data = freshRuntime._data;
|
|
164
|
+
return this._data.state || 'unknown';
|
|
165
|
+
}
|
|
166
|
+
// ========================================================================
|
|
167
|
+
// State Checking Methods (always fresh)
|
|
168
|
+
// ========================================================================
|
|
169
|
+
/**
|
|
170
|
+
* Check if runtime is in running state.
|
|
171
|
+
*
|
|
172
|
+
* @returns Promise resolving to true if runtime is running
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* if (await runtime.isRunning()) {
|
|
177
|
+
* console.log('Runtime is ready for use');
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async isRunning() {
|
|
182
|
+
return (await this.getState()) === 'running';
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Check if runtime is in starting state.
|
|
186
|
+
*
|
|
187
|
+
* @returns Promise resolving to true if runtime is starting
|
|
188
|
+
*/
|
|
189
|
+
async isStarting() {
|
|
190
|
+
return (await this.getState()) === 'starting';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Check if runtime is in stopping state.
|
|
194
|
+
*
|
|
195
|
+
* @returns Promise resolving to true if runtime is stopping
|
|
196
|
+
*/
|
|
197
|
+
async isStopping() {
|
|
198
|
+
return (await this.getState()) === 'stopping';
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if runtime is in stopped state.
|
|
202
|
+
*
|
|
203
|
+
* @returns Promise resolving to true if runtime is stopped
|
|
204
|
+
*/
|
|
205
|
+
async isStopped() {
|
|
206
|
+
return (await this.getState()) === 'stopped';
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Check if runtime is in error state.
|
|
210
|
+
*
|
|
211
|
+
* @returns Promise resolving to true if runtime has error
|
|
212
|
+
*/
|
|
213
|
+
async hasError() {
|
|
214
|
+
return (await this.getState()) === 'error';
|
|
215
|
+
}
|
|
216
|
+
// ========================================================================
|
|
217
|
+
// Action Methods
|
|
218
|
+
// ========================================================================
|
|
219
|
+
/**
|
|
220
|
+
* Delete this runtime permanently.
|
|
221
|
+
*
|
|
222
|
+
* After deletion, this object will be marked as deleted and subsequent
|
|
223
|
+
* calls to dynamic methods will throw errors.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* await runtime.delete();
|
|
228
|
+
* console.log('Runtime deleted');
|
|
229
|
+
* // runtime.getState() will now throw an error
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
async delete() {
|
|
233
|
+
await this._sdk.deleteRuntime(this.podName);
|
|
234
|
+
this._deleted = true;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Update runtime from a snapshot.
|
|
238
|
+
*
|
|
239
|
+
* @param from - Snapshot identifier to restore from
|
|
240
|
+
* @returns Promise resolving to updated Runtime instance
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const updatedRuntime = await runtime.update('snapshot-uid');
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
async update(from) {
|
|
248
|
+
this._checkDeleted();
|
|
249
|
+
const updated = await updateRuntime(this._sdk.getToken(), this.podName, from, this._sdk.getRuntimesRunUrl());
|
|
250
|
+
return new Runtime(updated, this._sdk);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Create a snapshot of this runtime.
|
|
254
|
+
*
|
|
255
|
+
* @param name - Name for the snapshot
|
|
256
|
+
* @param description - Optional description for the snapshot
|
|
257
|
+
* @param stop - Whether to stop the runtime after snapshotting
|
|
258
|
+
* @returns Promise resolving to created Snapshot instance
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const snapshot = await runtime.createSnapshot(
|
|
263
|
+
* 'my-checkpoint',
|
|
264
|
+
* 'Before major changes'
|
|
265
|
+
* );
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
async createSnapshot(name, description, stop) {
|
|
269
|
+
this._checkDeleted();
|
|
270
|
+
const request = {
|
|
271
|
+
pod_name: this.podName,
|
|
272
|
+
name,
|
|
273
|
+
description: description || '',
|
|
274
|
+
stop: stop || false,
|
|
275
|
+
};
|
|
276
|
+
// The SDK's createSnapshot already returns a Snapshot instance
|
|
277
|
+
return await this._sdk.createSnapshot(request);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Wait for runtime to reach running state.
|
|
281
|
+
*
|
|
282
|
+
* Polls the runtime state until it becomes 'running' or throws on error/timeout.
|
|
283
|
+
*
|
|
284
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 60000)
|
|
285
|
+
* @returns Promise resolving to this Runtime instance when ready
|
|
286
|
+
* @throws Error if runtime enters error state or timeout is reached
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const runtime = await sdk.createRuntime(config);
|
|
291
|
+
* await runtime.waitUntilReady();
|
|
292
|
+
* console.log('Runtime is ready to use!');
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
async waitUntilReady(timeoutMs = 60000) {
|
|
296
|
+
this._checkDeleted();
|
|
297
|
+
const startTime = Date.now();
|
|
298
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
299
|
+
if (await this.isRunning()) {
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
if (await this.hasError()) {
|
|
303
|
+
throw new Error(`Runtime ${this.podName} entered error state`);
|
|
304
|
+
}
|
|
305
|
+
// Wait 2 seconds before checking again
|
|
306
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
307
|
+
}
|
|
308
|
+
throw new Error(`Timeout waiting for runtime ${this.podName} to be ready`);
|
|
309
|
+
}
|
|
310
|
+
// ========================================================================
|
|
311
|
+
// Utility Methods
|
|
312
|
+
// ========================================================================
|
|
313
|
+
/**
|
|
314
|
+
* Get raw runtime data object with latest state.
|
|
315
|
+
*
|
|
316
|
+
* This method ensures the returned data includes the most recent state
|
|
317
|
+
* by refreshing from the API before returning.
|
|
318
|
+
*
|
|
319
|
+
* @returns Promise resolving to raw runtime data
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const latestData = await runtime.toJSON();
|
|
324
|
+
* console.log('Current state:', latestData.state);
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
async toJSON() {
|
|
328
|
+
this._checkDeleted();
|
|
329
|
+
await this.getState(); // This updates internal data
|
|
330
|
+
return this._data;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* String representation of the runtime.
|
|
334
|
+
*
|
|
335
|
+
* @returns String representation for logging/debugging
|
|
336
|
+
*/
|
|
337
|
+
toString() {
|
|
338
|
+
this._checkDeleted();
|
|
339
|
+
return `Runtime(${this.podName}, ${this.environmentName})`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sdk/client/models/Snapshot
|
|
3
|
+
* @description Snapshot domain model for the Datalayer SDK.
|
|
4
|
+
*
|
|
5
|
+
* This model provides a rich, object-oriented interface for working with
|
|
6
|
+
* runtime snapshots, including fresh data fetching and lifecycle operations.
|
|
7
|
+
*/
|
|
8
|
+
import type { RuntimeSnapshot } from '../../../api/types/runtimes';
|
|
9
|
+
import type { DatalayerSDK } from '../index';
|
|
10
|
+
/**
|
|
11
|
+
* Snapshot domain model that wraps API responses with convenient methods.
|
|
12
|
+
*
|
|
13
|
+
* Provides a rich, object-oriented interface for managing runtime snapshots
|
|
14
|
+
* with automatic data refresh and lifecycle operations.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const snapshot = await runtime.createSnapshot('my-checkpoint', 'Before changes');
|
|
19
|
+
*
|
|
20
|
+
* // Static properties - instant access
|
|
21
|
+
* console.log(snapshot.uid);
|
|
22
|
+
* console.log(snapshot.environment);
|
|
23
|
+
*
|
|
24
|
+
* // Dynamic data - always fresh from API
|
|
25
|
+
* const currentStatus = await snapshot.getStatus();
|
|
26
|
+
* const size = await snapshot.getSize();
|
|
27
|
+
*
|
|
28
|
+
* // Delete snapshot
|
|
29
|
+
* await snapshot.delete();
|
|
30
|
+
*
|
|
31
|
+
* // Restore runtime from snapshot
|
|
32
|
+
* const runtime = await snapshot.restore();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class Snapshot {
|
|
36
|
+
protected _data: RuntimeSnapshot;
|
|
37
|
+
private _sdk;
|
|
38
|
+
private _deleted;
|
|
39
|
+
/**
|
|
40
|
+
* Create a Snapshot instance.
|
|
41
|
+
*
|
|
42
|
+
* @param data - Raw snapshot data from API
|
|
43
|
+
* @param sdk - DatalayerSDK instance for making API calls
|
|
44
|
+
*/
|
|
45
|
+
constructor(data: RuntimeSnapshot, sdk: DatalayerSDK);
|
|
46
|
+
/**
|
|
47
|
+
* Check if this snapshot has been deleted and throw error if so.
|
|
48
|
+
* @throws Error if the snapshot has been deleted
|
|
49
|
+
*/
|
|
50
|
+
private _checkDeleted;
|
|
51
|
+
/**
|
|
52
|
+
* Unique identifier for the snapshot.
|
|
53
|
+
*/
|
|
54
|
+
get uid(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Name of the snapshot.
|
|
57
|
+
*/
|
|
58
|
+
get name(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Description of the snapshot.
|
|
61
|
+
*/
|
|
62
|
+
get description(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Name of the environment used by the runtime.
|
|
65
|
+
*/
|
|
66
|
+
get environment(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Format of the snapshot.
|
|
69
|
+
*/
|
|
70
|
+
get format(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Format version of the snapshot.
|
|
73
|
+
*/
|
|
74
|
+
get formatVersion(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Snapshot metadata.
|
|
77
|
+
*/
|
|
78
|
+
get metadata(): Record<string, any>;
|
|
79
|
+
/**
|
|
80
|
+
* When the snapshot was last updated.
|
|
81
|
+
*/
|
|
82
|
+
get updatedAt(): Date;
|
|
83
|
+
/**
|
|
84
|
+
* Get the current status of the snapshot.
|
|
85
|
+
*
|
|
86
|
+
* This method always fetches fresh data from the API and updates
|
|
87
|
+
* the internal data to keep everything in sync.
|
|
88
|
+
*
|
|
89
|
+
* @returns Promise resolving to current snapshot status
|
|
90
|
+
* @throws Error if the snapshot has been deleted
|
|
91
|
+
*/
|
|
92
|
+
getStatus(): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* Get the current size of the snapshot.
|
|
95
|
+
*
|
|
96
|
+
* @returns Promise resolving to snapshot size in bytes
|
|
97
|
+
*/
|
|
98
|
+
getSize(): Promise<number>;
|
|
99
|
+
/**
|
|
100
|
+
* Get the latest metadata of the snapshot.
|
|
101
|
+
*
|
|
102
|
+
* @returns Promise resolving to snapshot metadata
|
|
103
|
+
*/
|
|
104
|
+
getLatestMetadata(): Promise<Record<string, any>>;
|
|
105
|
+
/**
|
|
106
|
+
* Delete this snapshot permanently.
|
|
107
|
+
*
|
|
108
|
+
* After deletion, this object will be marked as deleted and subsequent
|
|
109
|
+
* calls to dynamic methods will throw errors.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* await snapshot.delete();
|
|
114
|
+
* console.log('Snapshot deleted');
|
|
115
|
+
* // snapshot.getStatus() will now throw an error
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
delete(): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Create a runtime from this snapshot (restore functionality).
|
|
121
|
+
*
|
|
122
|
+
* @param config - Optional runtime configuration to override defaults
|
|
123
|
+
* @returns Promise resolving to created Runtime instance
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const runtime = await snapshot.restore({
|
|
128
|
+
* credits_limit: 200
|
|
129
|
+
* });
|
|
130
|
+
* await runtime.waitUntilReady();
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
restore(config?: any): Promise<any>;
|
|
134
|
+
/**
|
|
135
|
+
* Get raw snapshot data object with latest information.
|
|
136
|
+
*
|
|
137
|
+
* This method ensures the returned data includes the most recent information
|
|
138
|
+
* by refreshing from the API before returning.
|
|
139
|
+
*
|
|
140
|
+
* @returns Promise resolving to raw snapshot data
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const latestData = await snapshot.toJSON();
|
|
145
|
+
* console.log('Current status:', latestData.status);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
toJSON(): Promise<RuntimeSnapshot>;
|
|
149
|
+
/**
|
|
150
|
+
* String representation of the snapshot.
|
|
151
|
+
*
|
|
152
|
+
* @returns String representation for logging/debugging
|
|
153
|
+
*/
|
|
154
|
+
toString(): string;
|
|
155
|
+
}
|
|
156
|
+
export type { RuntimeSnapshot };
|