@datalayer/core 0.0.12 → 0.0.14
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/README.md +2 -2
- package/lib/api/DatalayerApi.d.ts +38 -26
- package/lib/api/DatalayerApi.js +52 -13
- package/lib/api/iam/authentication.d.ts +9 -8
- package/lib/api/iam/authentication.js +14 -15
- package/lib/api/iam/healthz.d.ts +3 -2
- package/lib/api/iam/healthz.js +5 -3
- package/lib/api/iam/index.d.ts +9 -4
- package/lib/api/iam/index.js +9 -4
- package/lib/api/iam/oauth2.d.ts +115 -0
- package/lib/api/iam/oauth2.js +309 -0
- package/lib/api/iam/profile.d.ts +8 -1
- package/lib/api/iam/profile.js +17 -2
- package/lib/api/iam/usage.d.ts +18 -0
- package/lib/api/iam/usage.js +39 -0
- package/lib/api/index.d.ts +6 -6
- package/lib/api/index.js +6 -7
- package/lib/api/runtimes/environments.d.ts +2 -2
- package/lib/api/runtimes/environments.js +3 -2
- package/lib/api/runtimes/healthz.d.ts +3 -13
- package/lib/api/runtimes/healthz.js +4 -3
- package/lib/api/runtimes/index.d.ts +3 -2
- package/lib/api/runtimes/index.js +3 -2
- package/lib/api/runtimes/runtimes.d.ts +4 -4
- package/lib/api/runtimes/runtimes.js +17 -6
- package/lib/api/runtimes/snapshots.d.ts +4 -4
- package/lib/api/runtimes/snapshots.js +3 -2
- package/lib/api/spacer/documents.d.ts +12 -0
- package/lib/api/spacer/documents.js +43 -0
- package/lib/api/spacer/healthz.d.ts +3 -13
- package/lib/api/spacer/healthz.js +4 -3
- package/lib/api/spacer/index.d.ts +4 -2
- package/lib/api/spacer/index.js +4 -2
- package/lib/api/spacer/items.d.ts +9 -1
- package/lib/api/spacer/items.js +17 -2
- package/lib/api/spacer/lexicals.d.ts +1 -1
- package/lib/api/spacer/lexicals.js +3 -2
- package/lib/api/spacer/notebooks.d.ts +1 -1
- package/lib/api/spacer/notebooks.js +3 -2
- package/lib/api/spacer/spaces.d.ts +1 -1
- package/lib/api/spacer/spaces.js +3 -2
- package/lib/api/spacer/users.d.ts +1 -1
- package/lib/api/spacer/users.js +3 -2
- package/lib/api/utils/validation.d.ts +24 -1
- package/lib/api/utils/validation.js +62 -1
- package/lib/client/base.d.ts +75 -0
- package/lib/client/base.js +199 -0
- package/lib/client/constants.d.ts +22 -0
- package/lib/client/constants.js +22 -0
- package/lib/client/index.d.ts +108 -0
- package/lib/client/index.js +79 -0
- package/lib/client/mixins/IAMMixin.d.ts +54 -0
- package/lib/client/mixins/IAMMixin.js +181 -0
- package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
- package/lib/client/mixins/RuntimesMixin.js +229 -0
- package/lib/client/mixins/SpacerMixin.d.ts +111 -0
- package/lib/client/mixins/SpacerMixin.js +340 -0
- package/lib/client/utils/mixins.d.ts +12 -0
- package/lib/{sdk/client → client}/utils/mixins.js +0 -28
- package/lib/client/utils/spacerUtils.d.ts +18 -0
- package/lib/client/utils/spacerUtils.js +32 -0
- package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
- package/lib/collaboration/DatalayerCollaboration.js +2 -2
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
- package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
- package/lib/components/progress/CreditsIndicator.d.ts +1 -1
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.js +2 -2
- package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.js +1 -1
- package/lib/components/runtimes/RuntimePickerCell.js +3 -3
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerNotebook.js +2 -2
- package/lib/components/runtimes/RuntimeTransfer.d.ts +2 -2
- package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
- package/lib/config/Configuration.d.ts +8 -0
- package/lib/hooks/useDatalayer.js +1 -1
- package/lib/hooks/useRuntimes.js +1 -1
- package/lib/hooks/useToast.js +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +4 -3
- package/lib/models/Common.d.ts +64 -0
- package/lib/models/CreditsDTO.d.ts +124 -0
- package/lib/models/CreditsDTO.js +135 -0
- package/lib/models/Environment.d.ts +1 -1
- package/lib/models/EnvironmentDTO.d.ts +125 -0
- package/lib/models/EnvironmentDTO.js +88 -0
- package/lib/models/HealthCheck.d.ts +72 -0
- package/lib/models/HealthCheck.js +107 -0
- package/lib/{api/types/iam.d.ts → models/IAM.d.ts} +15 -78
- package/lib/models/ItemDTO.d.ts +74 -0
- package/lib/models/ItemDTO.js +186 -0
- package/lib/models/LexicalDTO.d.ts +155 -0
- package/lib/models/LexicalDTO.js +157 -0
- package/lib/models/NotebookDTO.d.ts +96 -0
- package/lib/models/NotebookDTO.js +153 -0
- package/lib/models/Profile.d.ts +65 -0
- package/lib/models/RuntimeDTO.d.ts +191 -0
- package/lib/models/RuntimeDTO.js +204 -0
- package/lib/models/RuntimeSnapshotDTO.d.ts +173 -0
- package/lib/models/RuntimeSnapshotDTO.js +139 -0
- package/lib/models/SpaceDTO.d.ts +280 -0
- package/lib/models/SpaceDTO.js +239 -0
- package/lib/models/UserDTO.d.ts +86 -0
- package/lib/models/UserDTO.js +84 -0
- package/lib/models/index.d.ts +45 -4
- package/lib/models/index.js +45 -4
- package/lib/sdk/index.d.ts +5 -4
- package/lib/sdk/index.js +6 -5
- package/lib/services/DatalayerServiceManager.js +1 -1
- package/lib/state/substates/CoreState.js +2 -0
- package/lib/state/substates/RuntimesState.d.ts +1 -1
- package/lib/state/substates/RuntimesState.js +1 -1
- package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
- package/lib/{sdk/stateful → stateful}/index.js +1 -1
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
- package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
- package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
- package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
- package/package.json +13 -10
- package/lib/__tests__/hooks.test.d.ts +0 -1
- package/lib/__tests__/hooks.test.js +0 -19
- package/lib/__tests__/index.test.d.ts +0 -1
- package/lib/__tests__/index.test.js +0 -27
- package/lib/__tests__/integration.test.d.ts +0 -1
- package/lib/__tests__/integration.test.js +0 -57
- package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
- package/lib/__tests__/shared/cleanup-shared.js +0 -228
- package/lib/__tests__/shared/test-config.d.ts +0 -51
- package/lib/__tests__/shared/test-config.js +0 -110
- package/lib/__tests__/shared/test-constants.d.ts +0 -66
- package/lib/__tests__/shared/test-constants.js +0 -79
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -59
- package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
- package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
- package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
- package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
- package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.integration.test.js +0 -369
- package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.integration.test.js +0 -519
- package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
- package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
- package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
- package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
- package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
- package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
- package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
- package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
- package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
- package/lib/api/types/index.d.ts +0 -32
- package/lib/api/types/index.js +0 -36
- package/lib/api/types/runtimes.d.ts +0 -235
- package/lib/api/types/spacer.d.ts +0 -271
- package/lib/api/types/spacer.js +0 -5
- package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
- package/lib/api/utils/__tests__/validation.test.js +0 -109
- package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
- package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
- package/lib/sdk/client/base.d.ts +0 -88
- package/lib/sdk/client/base.js +0 -112
- package/lib/sdk/client/index.d.ts +0 -192
- package/lib/sdk/client/index.js +0 -128
- package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
- package/lib/sdk/client/mixins/HealthMixin.js +0 -133
- package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
- package/lib/sdk/client/mixins/IAMMixin.js +0 -83
- package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
- package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
- package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
- package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
- package/lib/sdk/client/models/Lexical.d.ts +0 -156
- package/lib/sdk/client/models/Lexical.js +0 -275
- package/lib/sdk/client/models/Notebook.d.ts +0 -174
- package/lib/sdk/client/models/Notebook.js +0 -311
- package/lib/sdk/client/models/Runtime.d.ts +0 -221
- package/lib/sdk/client/models/Runtime.js +0 -341
- package/lib/sdk/client/models/Snapshot.d.ts +0 -156
- package/lib/sdk/client/models/Snapshot.js +0 -244
- package/lib/sdk/client/models/Space.d.ts +0 -182
- package/lib/sdk/client/models/Space.js +0 -276
- package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
- package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
- package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
- package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
- package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
- package/lib/sdk/client/models/index.d.ts +0 -30
- package/lib/sdk/client/models/index.js +0 -30
- package/lib/sdk/client/utils/mixins.d.ts +0 -42
- /package/lib/{api/types/iam.js → models/Common.js} +0 -0
- /package/lib/{api/types/runtimes.js → models/IAM.js} +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/apis.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
import * as notebooks from '../api/spacer/notebooks';
|
|
6
|
+
import { ItemDTO } from './ItemDTO';
|
|
7
|
+
import { ItemTypes } from '../client/constants';
|
|
8
|
+
import { validateJSON } from '../api/utils/validation';
|
|
9
|
+
/**
|
|
10
|
+
* Notebook domain model that extends the base Item class.
|
|
11
|
+
* Provides notebook-specific functionality for managing Jupyter notebooks.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const notebook = await sdk.createNotebook(formData);
|
|
16
|
+
* const kernelSpec = await notebook.getKernelSpec();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class NotebookDTO extends ItemDTO {
|
|
20
|
+
/**
|
|
21
|
+
* Create a Notebook instance.
|
|
22
|
+
*
|
|
23
|
+
* @param data - Notebook data from API
|
|
24
|
+
* @param sdk - SDK instance
|
|
25
|
+
*/
|
|
26
|
+
constructor(data, sdk) {
|
|
27
|
+
super(data, sdk);
|
|
28
|
+
}
|
|
29
|
+
// ========================================================================
|
|
30
|
+
// Abstract Method Implementations
|
|
31
|
+
// ========================================================================
|
|
32
|
+
/** Document type identifier. */
|
|
33
|
+
get type() {
|
|
34
|
+
this._checkDeleted();
|
|
35
|
+
return ItemTypes.NOTEBOOK;
|
|
36
|
+
}
|
|
37
|
+
/** The cached name of the notebook. */
|
|
38
|
+
get name() {
|
|
39
|
+
this._checkDeleted();
|
|
40
|
+
return (this._data.name_t ||
|
|
41
|
+
this._data.notebook_name_s ||
|
|
42
|
+
this._data.name ||
|
|
43
|
+
'');
|
|
44
|
+
}
|
|
45
|
+
/** The cached content. */
|
|
46
|
+
get content() {
|
|
47
|
+
this._checkDeleted();
|
|
48
|
+
if (!this._data.content && this._data.model_s) {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(this._data.model_s);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return this._data.model_s;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return this._data.content;
|
|
57
|
+
}
|
|
58
|
+
/** Get the current name from API. */
|
|
59
|
+
async getName() {
|
|
60
|
+
this._checkDeleted();
|
|
61
|
+
// For now, return cached value - implement API call if needed
|
|
62
|
+
return this.name;
|
|
63
|
+
}
|
|
64
|
+
/** Get when the notebook was last updated from API. */
|
|
65
|
+
async getUpdatedAt() {
|
|
66
|
+
this._checkDeleted();
|
|
67
|
+
const dateStr = this._data.updated_at || this._data.update_ts_dt;
|
|
68
|
+
if (!dateStr) {
|
|
69
|
+
throw new Error('No update timestamp available for notebook');
|
|
70
|
+
}
|
|
71
|
+
return new Date(dateStr);
|
|
72
|
+
}
|
|
73
|
+
/** Update the notebook. */
|
|
74
|
+
async update(name, description) {
|
|
75
|
+
// FIXME: check if both are needed, and use the existing values if only one provided
|
|
76
|
+
this._checkDeleted();
|
|
77
|
+
const token = this._sdk.getToken();
|
|
78
|
+
const spacerRunUrl = this._sdk.getSpacerRunUrl();
|
|
79
|
+
const updateData = {};
|
|
80
|
+
if (name !== undefined)
|
|
81
|
+
updateData.name = name;
|
|
82
|
+
if (description !== undefined)
|
|
83
|
+
updateData.description = description;
|
|
84
|
+
await notebooks.updateNotebook(token, this.uid, updateData, spacerRunUrl);
|
|
85
|
+
// FIXME: handle partial updates
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
// ========================================================================
|
|
89
|
+
// Notebook-specific Properties
|
|
90
|
+
// ========================================================================
|
|
91
|
+
/** File path within the space. */
|
|
92
|
+
get path() {
|
|
93
|
+
this._checkDeleted();
|
|
94
|
+
return this._data.path || '';
|
|
95
|
+
}
|
|
96
|
+
/** Version number. */
|
|
97
|
+
get version() {
|
|
98
|
+
this._checkDeleted();
|
|
99
|
+
return this._data.version || 0;
|
|
100
|
+
}
|
|
101
|
+
/** Notebook metadata. */
|
|
102
|
+
get metadata() {
|
|
103
|
+
this._checkDeleted();
|
|
104
|
+
return this._data.metadata || {};
|
|
105
|
+
}
|
|
106
|
+
/** Kernel specification (cached). */
|
|
107
|
+
get kernelSpec() {
|
|
108
|
+
this._checkDeleted();
|
|
109
|
+
return this._data.kernel_spec;
|
|
110
|
+
}
|
|
111
|
+
/** Description of the notebook. */
|
|
112
|
+
get description() {
|
|
113
|
+
this._checkDeleted();
|
|
114
|
+
return this._data.description_t || '';
|
|
115
|
+
}
|
|
116
|
+
/** Get the notebook extension. */
|
|
117
|
+
get extension() {
|
|
118
|
+
this._checkDeleted();
|
|
119
|
+
const ext = this._data.notebook_extension_s;
|
|
120
|
+
return ext ? (ext.startsWith('.') ? ext : `.${ext}`) : '.ipynb';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get notebook data in camelCase format.
|
|
124
|
+
* Returns only the core fields that consumers need.
|
|
125
|
+
* This provides a stable interface regardless of API changes.
|
|
126
|
+
*
|
|
127
|
+
* @returns Core notebook data with camelCase properties
|
|
128
|
+
*/
|
|
129
|
+
toJSON() {
|
|
130
|
+
this._checkDeleted();
|
|
131
|
+
const obj = {
|
|
132
|
+
id: this.id,
|
|
133
|
+
uid: this.uid,
|
|
134
|
+
name: this.name,
|
|
135
|
+
description: this.description,
|
|
136
|
+
type: this.type,
|
|
137
|
+
extension: this.extension,
|
|
138
|
+
cdnUrl: this._data.cdn_url_s,
|
|
139
|
+
};
|
|
140
|
+
validateJSON(obj, 'Notebook');
|
|
141
|
+
return obj;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get the raw notebook data exactly as received from the API.
|
|
145
|
+
* This preserves the original snake_case naming from the API response.
|
|
146
|
+
*
|
|
147
|
+
* @returns Raw notebook data from API
|
|
148
|
+
*/
|
|
149
|
+
rawData() {
|
|
150
|
+
this._checkDeleted();
|
|
151
|
+
return this._data;
|
|
152
|
+
}
|
|
153
|
+
}
|
package/lib/models/Profile.d.ts
CHANGED
|
@@ -1 +1,66 @@
|
|
|
1
1
|
export type IProfileType = 'user' | 'organization' | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Represents a user profile in the Datalayer platform
|
|
4
|
+
* @interface Profile
|
|
5
|
+
*/
|
|
6
|
+
export interface Profile {
|
|
7
|
+
/** ISO 8601 timestamp of when the user was created */
|
|
8
|
+
creation_ts_dt: string;
|
|
9
|
+
/** Unique identifier for the user */
|
|
10
|
+
id: string;
|
|
11
|
+
/** ISO 8601 timestamp of when the user requested to join */
|
|
12
|
+
join_request_ts_dt: string | null;
|
|
13
|
+
/** ISO 8601 timestamp of when the user joined */
|
|
14
|
+
join_ts_dt: string;
|
|
15
|
+
/** ISO 8601 timestamp of last update */
|
|
16
|
+
last_update_ts_dt: string;
|
|
17
|
+
/** Origin of the user account */
|
|
18
|
+
origin_s: string;
|
|
19
|
+
/** Type of the record */
|
|
20
|
+
type_s: string;
|
|
21
|
+
/** User ID */
|
|
22
|
+
uid: string;
|
|
23
|
+
/** Email address */
|
|
24
|
+
email_s: string;
|
|
25
|
+
/** First name */
|
|
26
|
+
first_name_t: string;
|
|
27
|
+
/** User handle */
|
|
28
|
+
handle_s: string;
|
|
29
|
+
/** Last name */
|
|
30
|
+
last_name_t: string;
|
|
31
|
+
/** User roles array */
|
|
32
|
+
roles_ss?: string[];
|
|
33
|
+
/** Avatar URL */
|
|
34
|
+
avatar_url_s?: string;
|
|
35
|
+
/** Onboarding state as JSON string */
|
|
36
|
+
onboarding_s?: string;
|
|
37
|
+
/** New password request timestamp */
|
|
38
|
+
new_password_request_ts_dt?: string | null;
|
|
39
|
+
/** New password confirmation timestamp */
|
|
40
|
+
new_password_confirmation_ts_dt?: string | null;
|
|
41
|
+
/** Customer UID */
|
|
42
|
+
customer_uid?: string | null;
|
|
43
|
+
/** Credits customer UID for billing */
|
|
44
|
+
credits_customer_uid?: string | null;
|
|
45
|
+
/** Email unsubscription status */
|
|
46
|
+
unsubscribed_from_outbounds_b?: boolean;
|
|
47
|
+
/** Linked contact UID */
|
|
48
|
+
linked_contact_uid?: string | null;
|
|
49
|
+
/** MFA URL */
|
|
50
|
+
mfa_url_s?: string | null;
|
|
51
|
+
/** MFA secret */
|
|
52
|
+
mfa_secret_s?: string | null;
|
|
53
|
+
/** Email verification token */
|
|
54
|
+
email_token_s?: string | null;
|
|
55
|
+
/** Pending email update */
|
|
56
|
+
email_update_s?: string | null;
|
|
57
|
+
/** IAM providers (nested structure - not typed in detail) */
|
|
58
|
+
iam_providers?: any[];
|
|
59
|
+
/** User settings (nested structure - not typed in detail) */
|
|
60
|
+
settings?: any;
|
|
61
|
+
/** User events (nested structure - not typed in detail) */
|
|
62
|
+
events?: any[];
|
|
63
|
+
/** Allow additional fields that may come from the server */
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
}
|
|
66
|
+
export default Profile;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { DatalayerClient } from '../index';
|
|
2
|
+
import { RuntimeSnapshotDTO } from './RuntimeSnapshotDTO';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a running instance of a computing environment.
|
|
5
|
+
* @interface RuntimeData
|
|
6
|
+
*/
|
|
7
|
+
export interface RuntimeData {
|
|
8
|
+
/** Kubernetes pod name for the runtime instance */
|
|
9
|
+
pod_name: string;
|
|
10
|
+
/** Unique identifier for the runtime */
|
|
11
|
+
uid: string;
|
|
12
|
+
/** Name of the environment this runtime is based on */
|
|
13
|
+
environment_name: string;
|
|
14
|
+
/** Title of the environment for display */
|
|
15
|
+
environment_title: string;
|
|
16
|
+
/** Type of runtime - notebook, terminal, or job */
|
|
17
|
+
type: string;
|
|
18
|
+
/** Credits consumed per second */
|
|
19
|
+
burning_rate: number;
|
|
20
|
+
/** User-friendly name for the runtime */
|
|
21
|
+
given_name: string;
|
|
22
|
+
/** Authentication token for accessing the runtime */
|
|
23
|
+
token: string;
|
|
24
|
+
/** Ingress URL for accessing the runtime */
|
|
25
|
+
ingress: string;
|
|
26
|
+
/** ISO 8601 timestamp of when the runtime started */
|
|
27
|
+
started_at: string;
|
|
28
|
+
/** ISO 8601 timestamp of when the runtime will expire */
|
|
29
|
+
expired_at: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Stable public interface for Runtime data.
|
|
33
|
+
* This is the contract that SDK consumers can rely on.
|
|
34
|
+
* The raw API may change, but this interface remains stable.
|
|
35
|
+
*/
|
|
36
|
+
export interface RuntimeJSON {
|
|
37
|
+
/** ulid for the runtime */
|
|
38
|
+
uid: string;
|
|
39
|
+
/** Kubernetes pod name for the runtime instance */
|
|
40
|
+
podName: string;
|
|
41
|
+
/** User-friendly name for the runtime */
|
|
42
|
+
givenName: string;
|
|
43
|
+
/** Name of the environment this runtime is based on */
|
|
44
|
+
environmentName: string;
|
|
45
|
+
/** Title of the environment for display */
|
|
46
|
+
environmentTitle: string;
|
|
47
|
+
/** Type of runtime - notebook, terminal, or job */
|
|
48
|
+
type: string;
|
|
49
|
+
/** Credits consumed per second */
|
|
50
|
+
burningRate: number;
|
|
51
|
+
/** Credits allocated/available to this runtime */
|
|
52
|
+
ingress: string;
|
|
53
|
+
/** Authentication token for accessing the runtime */
|
|
54
|
+
token: string;
|
|
55
|
+
/** When the runtime was started */
|
|
56
|
+
startedAt: string;
|
|
57
|
+
/** When the runtime will expire */
|
|
58
|
+
expiredAt: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Request payload for creating a new runtime
|
|
62
|
+
* @interface CreateRuntimeRequest
|
|
63
|
+
*/
|
|
64
|
+
export interface CreateRuntimeRequest {
|
|
65
|
+
/** Name of the environment to use */
|
|
66
|
+
environment_name: string;
|
|
67
|
+
/** Type of runtime (e.g., 'notebook', 'terminal', 'job') */
|
|
68
|
+
type?: 'notebook' | 'terminal' | 'job';
|
|
69
|
+
/** Optional given name for the runtime */
|
|
70
|
+
given_name?: string;
|
|
71
|
+
/** Maximum credits this runtime can consume */
|
|
72
|
+
credits_limit?: number;
|
|
73
|
+
/** Optional capabilities for the runtime */
|
|
74
|
+
capabilities?: string[];
|
|
75
|
+
/** Optional source to create runtime from (e.g., snapshot ID) */
|
|
76
|
+
from?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Response from creating a new runtime
|
|
80
|
+
* @interface CreateRuntimeResponse
|
|
81
|
+
*/
|
|
82
|
+
export interface CreateRuntimeResponse {
|
|
83
|
+
/** Whether the request was successful */
|
|
84
|
+
success: boolean;
|
|
85
|
+
/** Response message from the server */
|
|
86
|
+
message: string;
|
|
87
|
+
/** The created runtime instance */
|
|
88
|
+
runtime: RuntimeData;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Response from listing runtimes
|
|
92
|
+
* @interface ListRuntimesResponse
|
|
93
|
+
*/
|
|
94
|
+
export interface ListRuntimesResponse {
|
|
95
|
+
/** Whether the request was successful */
|
|
96
|
+
success: boolean;
|
|
97
|
+
/** Response message from the server */
|
|
98
|
+
message: string;
|
|
99
|
+
/** Array of runtime instances */
|
|
100
|
+
runtimes: RuntimeData[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Runtime domain model that wraps API responses with convenient methods.
|
|
104
|
+
* Provides state management and lifecycle operations for computational runtimes.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const runtime = await sdk.createRuntime({ environment_name: 'python-cpu' });
|
|
109
|
+
* await runtime.waitUntilReady();
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare class RuntimeDTO {
|
|
113
|
+
/** @internal */
|
|
114
|
+
_data: RuntimeData;
|
|
115
|
+
private _sdk;
|
|
116
|
+
private _deleted;
|
|
117
|
+
/**
|
|
118
|
+
* Create a Runtime instance.
|
|
119
|
+
*
|
|
120
|
+
* @param data - Runtime data from API
|
|
121
|
+
* @param sdk - SDK instance
|
|
122
|
+
*/
|
|
123
|
+
constructor(data: RuntimeData, sdk: DatalayerClient);
|
|
124
|
+
/**
|
|
125
|
+
* Check if this runtime has been deleted and throw error if so.
|
|
126
|
+
* @throws Error if deleted
|
|
127
|
+
*/
|
|
128
|
+
private _checkDeleted;
|
|
129
|
+
/** Kubernetes pod name for the runtime instance. */
|
|
130
|
+
get podName(): string;
|
|
131
|
+
/** Unique identifier for the runtime. */
|
|
132
|
+
get uid(): string;
|
|
133
|
+
/** Name of the environment this runtime is based on. */
|
|
134
|
+
get environmentName(): string;
|
|
135
|
+
/** Ingress URL for accessing the runtime. */
|
|
136
|
+
get ingress(): string;
|
|
137
|
+
/** Authentication token for accessing the runtime. */
|
|
138
|
+
get token(): string;
|
|
139
|
+
/** Credits consumed per second. */
|
|
140
|
+
get burningRate(): number;
|
|
141
|
+
/** User-friendly name for the runtime. */
|
|
142
|
+
get givenName(): string;
|
|
143
|
+
/** Type of runtime (notebook, terminal, or job). */
|
|
144
|
+
get type(): string;
|
|
145
|
+
/** When the runtime started. */
|
|
146
|
+
get startedAt(): Date;
|
|
147
|
+
/** When the runtime will expire. */
|
|
148
|
+
get expiredAt(): Date;
|
|
149
|
+
/** Environment title for display. */
|
|
150
|
+
get environmentTitle(): string;
|
|
151
|
+
/**
|
|
152
|
+
* Delete this runtime permanently.
|
|
153
|
+
* After deletion, subsequent calls to dynamic methods will throw errors.
|
|
154
|
+
*/
|
|
155
|
+
delete(): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Update runtime from a snapshot.
|
|
158
|
+
*
|
|
159
|
+
* @param from - Snapshot identifier to restore from
|
|
160
|
+
* @returns Updated Runtime instance
|
|
161
|
+
*/
|
|
162
|
+
update(from: string): Promise<RuntimeDTO>;
|
|
163
|
+
/**
|
|
164
|
+
* Create a snapshot of this runtime.
|
|
165
|
+
*
|
|
166
|
+
* @param name - Name for the snapshot
|
|
167
|
+
* @param description - Optional description
|
|
168
|
+
* @param stop - Whether to stop runtime after snapshotting
|
|
169
|
+
* @returns Created Snapshot instance
|
|
170
|
+
*/
|
|
171
|
+
createSnapshot(name: string, description?: string, stop?: boolean): Promise<RuntimeSnapshotDTO>;
|
|
172
|
+
/**
|
|
173
|
+
* Get runtime data in camelCase format.
|
|
174
|
+
* Returns only the core fields that consumers need.
|
|
175
|
+
* This provides a stable interface regardless of API changes.
|
|
176
|
+
* Returns the current cached state - call getState() first if you need fresh data.
|
|
177
|
+
*
|
|
178
|
+
* @returns Core runtime data with camelCase properties
|
|
179
|
+
*/
|
|
180
|
+
toJSON(): RuntimeJSON;
|
|
181
|
+
/**
|
|
182
|
+
* Get the raw runtime data exactly as received from the API.
|
|
183
|
+
* This preserves the original snake_case naming from the API response.
|
|
184
|
+
* Returns the current cached state - call getState() first if you need fresh data.
|
|
185
|
+
*
|
|
186
|
+
* @returns Raw runtime data from API
|
|
187
|
+
*/
|
|
188
|
+
rawData(): RuntimeData;
|
|
189
|
+
/** String representation of the runtime. */
|
|
190
|
+
toString(): string;
|
|
191
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Runtime domain model for the Datalayer SDK.
|
|
7
|
+
*
|
|
8
|
+
* @module models/RuntimeDTO
|
|
9
|
+
*/
|
|
10
|
+
import { updateRuntime } from '../api/runtimes/runtimes';
|
|
11
|
+
import { validateJSON } from '../api/utils/validation';
|
|
12
|
+
/**
|
|
13
|
+
* Runtime domain model that wraps API responses with convenient methods.
|
|
14
|
+
* Provides state management and lifecycle operations for computational runtimes.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const runtime = await sdk.createRuntime({ environment_name: 'python-cpu' });
|
|
19
|
+
* await runtime.waitUntilReady();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class RuntimeDTO {
|
|
23
|
+
/** @internal */
|
|
24
|
+
_data;
|
|
25
|
+
_sdk;
|
|
26
|
+
_deleted = false;
|
|
27
|
+
/**
|
|
28
|
+
* Create a Runtime instance.
|
|
29
|
+
*
|
|
30
|
+
* @param data - Runtime data from API
|
|
31
|
+
* @param sdk - SDK instance
|
|
32
|
+
*/
|
|
33
|
+
constructor(data, sdk) {
|
|
34
|
+
this._data = data;
|
|
35
|
+
this._sdk = sdk;
|
|
36
|
+
}
|
|
37
|
+
// ========================================================================
|
|
38
|
+
// Helper Methods
|
|
39
|
+
// ========================================================================
|
|
40
|
+
/**
|
|
41
|
+
* Check if this runtime has been deleted and throw error if so.
|
|
42
|
+
* @throws Error if deleted
|
|
43
|
+
*/
|
|
44
|
+
_checkDeleted() {
|
|
45
|
+
if (this._deleted) {
|
|
46
|
+
throw new Error(`Runtime ${this._data.pod_name} has been deleted and no longer exists`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// ========================================================================
|
|
50
|
+
// Static Properties (set at creation, never change)
|
|
51
|
+
// ========================================================================
|
|
52
|
+
/** Kubernetes pod name for the runtime instance. */
|
|
53
|
+
get podName() {
|
|
54
|
+
this._checkDeleted();
|
|
55
|
+
return this._data.pod_name;
|
|
56
|
+
}
|
|
57
|
+
/** Unique identifier for the runtime. */
|
|
58
|
+
get uid() {
|
|
59
|
+
this._checkDeleted();
|
|
60
|
+
return this._data.uid;
|
|
61
|
+
}
|
|
62
|
+
/** Name of the environment this runtime is based on. */
|
|
63
|
+
get environmentName() {
|
|
64
|
+
this._checkDeleted();
|
|
65
|
+
return this._data.environment_name;
|
|
66
|
+
}
|
|
67
|
+
/** Ingress URL for accessing the runtime. */
|
|
68
|
+
get ingress() {
|
|
69
|
+
this._checkDeleted();
|
|
70
|
+
return this._data.ingress;
|
|
71
|
+
}
|
|
72
|
+
/** Authentication token for accessing the runtime. */
|
|
73
|
+
get token() {
|
|
74
|
+
this._checkDeleted();
|
|
75
|
+
return this._data.token;
|
|
76
|
+
}
|
|
77
|
+
/** Credits consumed per second. */
|
|
78
|
+
get burningRate() {
|
|
79
|
+
this._checkDeleted();
|
|
80
|
+
return this._data.burning_rate;
|
|
81
|
+
}
|
|
82
|
+
/** User-friendly name for the runtime. */
|
|
83
|
+
get givenName() {
|
|
84
|
+
this._checkDeleted();
|
|
85
|
+
return this._data.given_name;
|
|
86
|
+
}
|
|
87
|
+
/** Type of runtime (notebook, terminal, or job). */
|
|
88
|
+
get type() {
|
|
89
|
+
this._checkDeleted();
|
|
90
|
+
return this._data.type;
|
|
91
|
+
}
|
|
92
|
+
/** When the runtime started. */
|
|
93
|
+
get startedAt() {
|
|
94
|
+
this._checkDeleted();
|
|
95
|
+
return new Date(Number(this._data.started_at) * 1000);
|
|
96
|
+
}
|
|
97
|
+
/** When the runtime will expire. */
|
|
98
|
+
get expiredAt() {
|
|
99
|
+
this._checkDeleted();
|
|
100
|
+
return new Date(Number(this._data.expired_at) * 1000);
|
|
101
|
+
}
|
|
102
|
+
/** Environment title for display. */
|
|
103
|
+
get environmentTitle() {
|
|
104
|
+
this._checkDeleted();
|
|
105
|
+
return this._data.environment_title || '';
|
|
106
|
+
}
|
|
107
|
+
// ========================================================================
|
|
108
|
+
// Action Methods
|
|
109
|
+
// ========================================================================
|
|
110
|
+
/**
|
|
111
|
+
* Delete this runtime permanently.
|
|
112
|
+
* After deletion, subsequent calls to dynamic methods will throw errors.
|
|
113
|
+
*/
|
|
114
|
+
async delete() {
|
|
115
|
+
await this._sdk.deleteRuntime(this.podName);
|
|
116
|
+
this._deleted = true;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Update runtime from a snapshot.
|
|
120
|
+
*
|
|
121
|
+
* @param from - Snapshot identifier to restore from
|
|
122
|
+
* @returns Updated Runtime instance
|
|
123
|
+
*/
|
|
124
|
+
async update(from) {
|
|
125
|
+
this._checkDeleted();
|
|
126
|
+
const updated = await updateRuntime(this._sdk.getToken(), this.podName, from, this._sdk.getRuntimesRunUrl());
|
|
127
|
+
return new RuntimeDTO(updated, this._sdk);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a snapshot of this runtime.
|
|
131
|
+
*
|
|
132
|
+
* @param name - Name for the snapshot
|
|
133
|
+
* @param description - Optional description
|
|
134
|
+
* @param stop - Whether to stop runtime after snapshotting
|
|
135
|
+
* @returns Created Snapshot instance
|
|
136
|
+
*/
|
|
137
|
+
async createSnapshot(name, description, stop) {
|
|
138
|
+
this._checkDeleted();
|
|
139
|
+
return await this._sdk.createSnapshot(this.podName, name, description, stop);
|
|
140
|
+
}
|
|
141
|
+
// ========================================================================
|
|
142
|
+
// Utility Methods
|
|
143
|
+
// ========================================================================
|
|
144
|
+
/**
|
|
145
|
+
* Get runtime data in camelCase format.
|
|
146
|
+
* Returns only the core fields that consumers need.
|
|
147
|
+
* This provides a stable interface regardless of API changes.
|
|
148
|
+
* Returns the current cached state - call getState() first if you need fresh data.
|
|
149
|
+
*
|
|
150
|
+
* @returns Core runtime data with camelCase properties
|
|
151
|
+
*/
|
|
152
|
+
toJSON() {
|
|
153
|
+
this._checkDeleted();
|
|
154
|
+
// Safely convert dates to ISO strings, handling invalid dates
|
|
155
|
+
const safeToISO = (date) => {
|
|
156
|
+
try {
|
|
157
|
+
const iso = date.toISOString();
|
|
158
|
+
return iso;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// If date is invalid, return empty string or current time
|
|
162
|
+
return new Date().toISOString();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const obj = {
|
|
166
|
+
// Core identifiers
|
|
167
|
+
uid: this.uid,
|
|
168
|
+
podName: this.podName,
|
|
169
|
+
givenName: this.givenName,
|
|
170
|
+
// Environment info
|
|
171
|
+
environmentName: this.environmentName,
|
|
172
|
+
environmentTitle: this.environmentTitle,
|
|
173
|
+
// State and type
|
|
174
|
+
type: this.type,
|
|
175
|
+
// Burning
|
|
176
|
+
burningRate: this.burningRate,
|
|
177
|
+
// URLs and tokens
|
|
178
|
+
// FIXME: Consider renaming? jupyterServerUrl and jupyterServerToken
|
|
179
|
+
ingress: this.ingress,
|
|
180
|
+
token: this.token,
|
|
181
|
+
// Timing
|
|
182
|
+
startedAt: safeToISO(this.startedAt),
|
|
183
|
+
expiredAt: safeToISO(this.expiredAt),
|
|
184
|
+
};
|
|
185
|
+
validateJSON(obj, 'Runtime');
|
|
186
|
+
return obj;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the raw runtime data exactly as received from the API.
|
|
190
|
+
* This preserves the original snake_case naming from the API response.
|
|
191
|
+
* Returns the current cached state - call getState() first if you need fresh data.
|
|
192
|
+
*
|
|
193
|
+
* @returns Raw runtime data from API
|
|
194
|
+
*/
|
|
195
|
+
rawData() {
|
|
196
|
+
this._checkDeleted();
|
|
197
|
+
return this._data;
|
|
198
|
+
}
|
|
199
|
+
/** String representation of the runtime. */
|
|
200
|
+
toString() {
|
|
201
|
+
this._checkDeleted();
|
|
202
|
+
return `Runtime(${this.podName}, ${this.environmentName})`;
|
|
203
|
+
}
|
|
204
|
+
}
|