@datalayer/core 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +2 -2
  2. package/lib/api/DatalayerApi.d.ts +38 -26
  3. package/lib/api/DatalayerApi.js +35 -8
  4. package/lib/api/iam/authentication.d.ts +8 -7
  5. package/lib/api/iam/authentication.js +14 -15
  6. package/lib/api/iam/healthz.d.ts +3 -2
  7. package/lib/api/iam/healthz.js +5 -3
  8. package/lib/api/iam/index.d.ts +9 -4
  9. package/lib/api/iam/index.js +9 -4
  10. package/lib/api/iam/oauth2.d.ts +115 -0
  11. package/lib/api/iam/oauth2.js +309 -0
  12. package/lib/api/iam/profile.d.ts +8 -1
  13. package/lib/api/iam/profile.js +17 -2
  14. package/lib/api/iam/usage.d.ts +56 -0
  15. package/lib/api/iam/usage.js +39 -0
  16. package/lib/api/index.d.ts +6 -5
  17. package/lib/api/index.js +6 -5
  18. package/lib/api/runtimes/environments.js +3 -2
  19. package/lib/api/runtimes/healthz.d.ts +3 -13
  20. package/lib/api/runtimes/healthz.js +4 -3
  21. package/lib/api/runtimes/index.d.ts +3 -2
  22. package/lib/api/runtimes/index.js +3 -2
  23. package/lib/api/runtimes/runtimes.js +17 -6
  24. package/lib/api/runtimes/snapshots.js +3 -2
  25. package/lib/api/spacer/documents.d.ts +12 -0
  26. package/lib/api/spacer/documents.js +43 -0
  27. package/lib/api/spacer/healthz.d.ts +3 -13
  28. package/lib/api/spacer/healthz.js +4 -3
  29. package/lib/api/spacer/index.d.ts +4 -2
  30. package/lib/api/spacer/index.js +4 -2
  31. package/lib/api/spacer/items.d.ts +9 -1
  32. package/lib/api/spacer/items.js +17 -2
  33. package/lib/api/spacer/lexicals.js +3 -2
  34. package/lib/api/spacer/notebooks.js +3 -2
  35. package/lib/api/spacer/spaces.js +3 -2
  36. package/lib/api/spacer/users.js +3 -2
  37. package/lib/api/types/common.d.ts +64 -0
  38. package/lib/api/types/iam.d.ts +88 -65
  39. package/lib/api/types/index.d.ts +4 -2
  40. package/lib/api/types/index.js +4 -2
  41. package/lib/api/types/runtimes.d.ts +9 -39
  42. package/lib/api/types/spacer.d.ts +37 -65
  43. package/lib/api/utils/validation.d.ts +24 -1
  44. package/lib/api/utils/validation.js +62 -1
  45. package/lib/client/base.d.ts +75 -0
  46. package/lib/client/base.js +199 -0
  47. package/lib/client/constants.d.ts +22 -0
  48. package/lib/client/constants.js +22 -0
  49. package/lib/client/index.d.ts +108 -0
  50. package/lib/client/index.js +79 -0
  51. package/lib/client/mixins/IAMMixin.d.ts +54 -0
  52. package/lib/client/mixins/IAMMixin.js +181 -0
  53. package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
  54. package/lib/client/mixins/RuntimesMixin.js +229 -0
  55. package/lib/client/mixins/SpacerMixin.d.ts +111 -0
  56. package/lib/client/mixins/SpacerMixin.js +340 -0
  57. package/lib/client/models/Credits.d.ts +91 -0
  58. package/lib/client/models/Credits.js +130 -0
  59. package/lib/client/models/Environment.d.ts +73 -0
  60. package/lib/client/models/Environment.js +88 -0
  61. package/lib/client/models/HealthCheck.d.ts +72 -0
  62. package/lib/client/models/HealthCheck.js +107 -0
  63. package/lib/client/models/Item.d.ts +69 -0
  64. package/lib/client/models/Item.js +191 -0
  65. package/lib/client/models/Lexical.d.ts +83 -0
  66. package/lib/client/models/Lexical.js +152 -0
  67. package/lib/client/models/Notebook.d.ts +87 -0
  68. package/lib/client/models/Notebook.js +153 -0
  69. package/lib/client/models/Runtime.d.ts +122 -0
  70. package/lib/client/models/Runtime.js +204 -0
  71. package/lib/client/models/Snapshot.d.ts +92 -0
  72. package/lib/client/models/Snapshot.js +139 -0
  73. package/lib/client/models/Space.d.ts +135 -0
  74. package/lib/client/models/Space.js +234 -0
  75. package/lib/client/models/User.d.ts +64 -0
  76. package/lib/client/models/User.js +83 -0
  77. package/lib/client/models/index.d.ts +26 -0
  78. package/lib/client/models/index.js +25 -0
  79. package/lib/client/utils/mixins.d.ts +12 -0
  80. package/lib/{sdk/client → client}/utils/mixins.js +0 -28
  81. package/lib/client/utils/spacerUtils.d.ts +18 -0
  82. package/lib/client/utils/spacerUtils.js +32 -0
  83. package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
  84. package/lib/collaboration/DatalayerCollaboration.js +2 -2
  85. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
  86. package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
  87. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  88. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  89. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  90. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  91. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  92. package/lib/components/runtimes/RuntimePickerCell.js +2 -2
  93. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  94. package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
  95. package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
  96. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  97. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  98. package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
  99. package/lib/config/Configuration.d.ts +8 -0
  100. package/lib/hooks/useDatalayer.js +1 -1
  101. package/lib/hooks/useRuntimes.js +1 -1
  102. package/lib/hooks/useToast.js +1 -1
  103. package/lib/index.d.ts +2 -2
  104. package/lib/index.js +4 -2
  105. package/lib/sdk/index.d.ts +5 -4
  106. package/lib/sdk/index.js +6 -5
  107. package/lib/services/DatalayerServiceManager.js +1 -1
  108. package/lib/state/substates/CoreState.js +2 -0
  109. package/lib/state/substates/RuntimesState.d.ts +1 -1
  110. package/lib/state/substates/RuntimesState.js +1 -1
  111. package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
  112. package/lib/{sdk/stateful → stateful}/index.js +1 -1
  113. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
  114. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
  115. package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
  116. package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
  117. package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
  118. package/lib/stateful/runtimes/apis.js +5 -0
  119. package/package.json +12 -10
  120. package/lib/__tests__/hooks.test.d.ts +0 -1
  121. package/lib/__tests__/hooks.test.js +0 -19
  122. package/lib/__tests__/index.test.d.ts +0 -1
  123. package/lib/__tests__/index.test.js +0 -27
  124. package/lib/__tests__/integration.test.d.ts +0 -1
  125. package/lib/__tests__/integration.test.js +0 -57
  126. package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
  127. package/lib/__tests__/shared/cleanup-shared.js +0 -228
  128. package/lib/__tests__/shared/test-config.d.ts +0 -51
  129. package/lib/__tests__/shared/test-config.js +0 -110
  130. package/lib/__tests__/shared/test-constants.d.ts +0 -66
  131. package/lib/__tests__/shared/test-constants.js +0 -79
  132. package/lib/__tests__/utils.test.d.ts +0 -1
  133. package/lib/__tests__/utils.test.js +0 -59
  134. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
  135. package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
  136. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
  137. package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
  138. package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
  139. package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
  140. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
  141. package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
  142. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
  143. package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
  144. package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
  145. package/lib/api/__tests__/runtimes.integration.test.js +0 -369
  146. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
  147. package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
  148. package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
  149. package/lib/api/__tests__/spacer.integration.test.js +0 -519
  150. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
  151. package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
  152. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
  153. package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
  154. package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
  155. package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
  156. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
  157. package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
  158. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
  159. package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
  160. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
  161. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
  162. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
  163. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
  164. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
  165. package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
  166. package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
  167. package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
  168. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
  169. package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
  170. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
  171. package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
  172. package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
  173. package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
  174. package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
  175. package/lib/api/utils/__tests__/validation.test.js +0 -109
  176. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
  177. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
  178. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
  179. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
  180. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
  181. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
  182. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
  183. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
  184. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
  185. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
  186. package/lib/sdk/client/base.d.ts +0 -88
  187. package/lib/sdk/client/base.js +0 -112
  188. package/lib/sdk/client/index.d.ts +0 -192
  189. package/lib/sdk/client/index.js +0 -128
  190. package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
  191. package/lib/sdk/client/mixins/HealthMixin.js +0 -133
  192. package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
  193. package/lib/sdk/client/mixins/IAMMixin.js +0 -83
  194. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
  195. package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
  196. package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
  197. package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
  198. package/lib/sdk/client/models/Lexical.d.ts +0 -156
  199. package/lib/sdk/client/models/Lexical.js +0 -275
  200. package/lib/sdk/client/models/Notebook.d.ts +0 -174
  201. package/lib/sdk/client/models/Notebook.js +0 -311
  202. package/lib/sdk/client/models/Runtime.d.ts +0 -221
  203. package/lib/sdk/client/models/Runtime.js +0 -341
  204. package/lib/sdk/client/models/Snapshot.d.ts +0 -156
  205. package/lib/sdk/client/models/Snapshot.js +0 -244
  206. package/lib/sdk/client/models/Space.d.ts +0 -182
  207. package/lib/sdk/client/models/Space.js +0 -276
  208. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
  209. package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
  210. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
  211. package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
  212. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
  213. package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
  214. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
  215. package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
  216. package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
  217. package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
  218. package/lib/sdk/client/models/index.d.ts +0 -30
  219. package/lib/sdk/client/models/index.js +0 -30
  220. package/lib/sdk/client/utils/mixins.d.ts +0 -42
  221. /package/lib/{sdk/stateful/runtimes/apis.js → api/types/common.js} +0 -0
  222. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
  223. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
  224. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
  225. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
  226. /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
  227. /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
  228. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
  229. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
  230. /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
  231. /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
  232. /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
  233. /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
  234. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
  235. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
  236. /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
  237. /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
@@ -1,244 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import { snapshots } from '../../../api/runtimes';
6
- /**
7
- * Snapshot domain model that wraps API responses with convenient methods.
8
- *
9
- * Provides a rich, object-oriented interface for managing runtime snapshots
10
- * with automatic data refresh and lifecycle operations.
11
- *
12
- * @example
13
- * ```typescript
14
- * const snapshot = await runtime.createSnapshot('my-checkpoint', 'Before changes');
15
- *
16
- * // Static properties - instant access
17
- * console.log(snapshot.uid);
18
- * console.log(snapshot.environment);
19
- *
20
- * // Dynamic data - always fresh from API
21
- * const currentStatus = await snapshot.getStatus();
22
- * const size = await snapshot.getSize();
23
- *
24
- * // Delete snapshot
25
- * await snapshot.delete();
26
- *
27
- * // Restore runtime from snapshot
28
- * const runtime = await snapshot.restore();
29
- * ```
30
- */
31
- export class Snapshot {
32
- _data;
33
- _sdk;
34
- _deleted = false;
35
- /**
36
- * Create a Snapshot instance.
37
- *
38
- * @param data - Raw snapshot data from API
39
- * @param sdk - DatalayerSDK instance for making API calls
40
- */
41
- constructor(data, sdk) {
42
- this._data = data;
43
- this._sdk = sdk;
44
- }
45
- // ========================================================================
46
- // Helper Methods
47
- // ========================================================================
48
- /**
49
- * Check if this snapshot has been deleted and throw error if so.
50
- * @throws Error if the snapshot has been deleted
51
- */
52
- _checkDeleted() {
53
- if (this._deleted) {
54
- throw new Error(`Snapshot ${this._data.uid} has been deleted and no longer exists`);
55
- }
56
- }
57
- // ========================================================================
58
- // Static Properties (set at creation, never change)
59
- // ========================================================================
60
- /**
61
- * Unique identifier for the snapshot.
62
- */
63
- get uid() {
64
- this._checkDeleted();
65
- return this._data.uid;
66
- }
67
- /**
68
- * Name of the snapshot.
69
- */
70
- get name() {
71
- this._checkDeleted();
72
- return this._data.name;
73
- }
74
- /**
75
- * Description of the snapshot.
76
- */
77
- get description() {
78
- this._checkDeleted();
79
- return this._data.description || '';
80
- }
81
- /**
82
- * Name of the environment used by the runtime.
83
- */
84
- get environment() {
85
- this._checkDeleted();
86
- return this._data.environment;
87
- }
88
- /**
89
- * Format of the snapshot.
90
- */
91
- get format() {
92
- this._checkDeleted();
93
- return this._data.format || '';
94
- }
95
- /**
96
- * Format version of the snapshot.
97
- */
98
- get formatVersion() {
99
- this._checkDeleted();
100
- return this._data.format_version || '';
101
- }
102
- /**
103
- * Snapshot metadata.
104
- */
105
- get metadata() {
106
- this._checkDeleted();
107
- return this._data.metadata || {};
108
- }
109
- /**
110
- * When the snapshot was last updated.
111
- */
112
- get updatedAt() {
113
- this._checkDeleted();
114
- return new Date(this._data.updated_at);
115
- }
116
- // ========================================================================
117
- // Dynamic Methods (always fetch fresh data and update internal state)
118
- // ========================================================================
119
- /**
120
- * Get the current status of the snapshot.
121
- *
122
- * This method always fetches fresh data from the API and updates
123
- * the internal data to keep everything in sync.
124
- *
125
- * @returns Promise resolving to current snapshot status
126
- * @throws Error if the snapshot has been deleted
127
- */
128
- async getStatus() {
129
- this._checkDeleted();
130
- const token = this._sdk.getToken();
131
- const runtimesRunUrl = this._sdk.getRuntimesRunUrl();
132
- const response = await snapshots.getSnapshot(token, this.uid, runtimesRunUrl);
133
- if (response.snapshot) {
134
- this._data = response.snapshot;
135
- }
136
- return this._data.status || 'unknown';
137
- }
138
- /**
139
- * Get the current size of the snapshot.
140
- *
141
- * @returns Promise resolving to snapshot size in bytes
142
- */
143
- async getSize() {
144
- this._checkDeleted();
145
- const token = this._sdk.getToken();
146
- const runtimesRunUrl = this._sdk.getRuntimesRunUrl();
147
- const response = await snapshots.getSnapshot(token, this.uid, runtimesRunUrl);
148
- if (response.snapshot) {
149
- this._data = response.snapshot;
150
- }
151
- return this._data.size || 0;
152
- }
153
- /**
154
- * Get the latest metadata of the snapshot.
155
- *
156
- * @returns Promise resolving to snapshot metadata
157
- */
158
- async getLatestMetadata() {
159
- this._checkDeleted();
160
- const token = this._sdk.getToken();
161
- const runtimesRunUrl = this._sdk.getRuntimesRunUrl();
162
- const response = await snapshots.getSnapshot(token, this.uid, runtimesRunUrl);
163
- if (response.snapshot) {
164
- this._data = response.snapshot;
165
- }
166
- return this._data.metadata || {};
167
- }
168
- // ========================================================================
169
- // Action Methods
170
- // ========================================================================
171
- /**
172
- * Delete this snapshot permanently.
173
- *
174
- * After deletion, this object will be marked as deleted and subsequent
175
- * calls to dynamic methods will throw errors.
176
- *
177
- * @example
178
- * ```typescript
179
- * await snapshot.delete();
180
- * console.log('Snapshot deleted');
181
- * // snapshot.getStatus() will now throw an error
182
- * ```
183
- */
184
- async delete() {
185
- this._checkDeleted();
186
- const token = this._sdk.getToken();
187
- const runtimesRunUrl = this._sdk.getRuntimesRunUrl();
188
- await snapshots.deleteSnapshot(token, this.uid, runtimesRunUrl);
189
- this._deleted = true;
190
- }
191
- /**
192
- * Create a runtime from this snapshot (restore functionality).
193
- *
194
- * @param config - Optional runtime configuration to override defaults
195
- * @returns Promise resolving to created Runtime instance
196
- *
197
- * @example
198
- * ```typescript
199
- * const runtime = await snapshot.restore({
200
- * credits_limit: 200
201
- * });
202
- * await runtime.waitUntilReady();
203
- * ```
204
- */
205
- async restore(config) {
206
- this._checkDeleted();
207
- return await this._sdk.createRuntime({
208
- environment_name: this.environment,
209
- from_snapshot: this.uid,
210
- ...config,
211
- });
212
- }
213
- // ========================================================================
214
- // Utility Methods
215
- // ========================================================================
216
- /**
217
- * Get raw snapshot data object with latest information.
218
- *
219
- * This method ensures the returned data includes the most recent information
220
- * by refreshing from the API before returning.
221
- *
222
- * @returns Promise resolving to raw snapshot data
223
- *
224
- * @example
225
- * ```typescript
226
- * const latestData = await snapshot.toJSON();
227
- * console.log('Current status:', latestData.status);
228
- * ```
229
- */
230
- async toJSON() {
231
- this._checkDeleted();
232
- await this.getStatus(); // This updates internal data
233
- return this._data;
234
- }
235
- /**
236
- * String representation of the snapshot.
237
- *
238
- * @returns String representation for logging/debugging
239
- */
240
- toString() {
241
- this._checkDeleted();
242
- return `Snapshot(${this.uid}, ${this.name})`;
243
- }
244
- }
@@ -1,182 +0,0 @@
1
- /**
2
- * @module sdk/client/models/Space
3
- * @description Space domain model for the Datalayer SDK.
4
- *
5
- * This model provides a rich, object-oriented interface for working with
6
- * workspace spaces, including item management and content creation.
7
- */
8
- import type { Space as SpaceData, SpaceItem } from '../../../api/types/spacer';
9
- import type { DatalayerSDK } from '../index';
10
- import { Notebook } from './Notebook';
11
- import { Lexical } from './Lexical';
12
- /**
13
- * Space domain model that wraps API responses with convenient methods.
14
- *
15
- * Provides a rich, object-oriented interface for managing workspace spaces
16
- * with automatic data refresh and content creation operations.
17
- *
18
- * @example
19
- * ```typescript
20
- * const spaces = await sdk.getMySpaces();
21
- * const space = spaces[0];
22
- *
23
- * // Static properties - instant access
24
- * console.log(space.uid);
25
- * console.log(space.visibility);
26
- *
27
- * // Dynamic data - always fresh from API
28
- * const currentName = await space.getName();
29
- * const items = await space.getItems();
30
- *
31
- * // Create content in this space
32
- * const notebook = await space.createNotebook(formData);
33
- * const lexical = await space.createLexical(formData);
34
- * ```
35
- */
36
- export declare class Space {
37
- protected _data: SpaceData;
38
- private _sdk;
39
- private _deleted;
40
- /**
41
- * Create a Space instance.
42
- *
43
- * @param data - Raw space data from API
44
- * @param sdk - DatalayerSDK instance for making API calls
45
- */
46
- constructor(data: SpaceData, sdk: DatalayerSDK);
47
- /**
48
- * Check if this space has been deleted and throw error if so.
49
- * @throws Error if the space has been deleted
50
- */
51
- private _checkDeleted;
52
- /**
53
- * Refresh space data from the API by fetching user's spaces.
54
- * Since there's no individual GET endpoint, we fetch from the list.
55
- */
56
- private _refreshData;
57
- /**
58
- * Unique identifier for the space.
59
- */
60
- get uid(): string;
61
- /**
62
- * Space ID (optional for backward compatibility).
63
- */
64
- get id(): string;
65
- /**
66
- * Owner user ID.
67
- */
68
- get ownerId(): string;
69
- /**
70
- * Organization ID.
71
- */
72
- get organizationId(): string;
73
- /**
74
- * When the space was created.
75
- * Note: May not be available for all spaces depending on API response.
76
- */
77
- get createdAt(): Date | null;
78
- /**
79
- * Space visibility setting.
80
- */
81
- get visibility(): string;
82
- /**
83
- * URL-friendly handle for the space.
84
- */
85
- get handle(): string;
86
- /**
87
- * Space variant type.
88
- */
89
- get variant(): string;
90
- /**
91
- * Get the current name of the space.
92
- *
93
- * This method always fetches fresh data from the API and updates
94
- * the internal data to keep everything in sync.
95
- *
96
- * @returns Promise resolving to current space name
97
- * @throws Error if the space has been deleted
98
- */
99
- getName(): Promise<string>;
100
- /**
101
- * Get the current description of the space.
102
- *
103
- * @returns Promise resolving to space description
104
- */
105
- getDescription(): Promise<string>;
106
- /**
107
- * Get when the space was last updated.
108
- *
109
- * @returns Promise resolving to last update time
110
- */
111
- getUpdatedAt(): Promise<Date | null>;
112
- /**
113
- * Get all items in this space.
114
- *
115
- * @returns Promise resolving to array of space items
116
- *
117
- * @example
118
- * ```typescript
119
- * const items = await space.getItems();
120
- * items.forEach(item => {
121
- * console.log(`${item.name} (${item.type})`);
122
- * });
123
- * ```
124
- */
125
- getItems(): Promise<SpaceItem[]>;
126
- /**
127
- * Create a new notebook in this space.
128
- *
129
- * @param formData - Notebook creation form data
130
- * @returns Promise resolving to created Notebook instance
131
- *
132
- * @example
133
- * ```typescript
134
- * const formData = new FormData();
135
- * formData.append('name', 'Analysis Notebook');
136
- * formData.append('notebookType', 'jupyter');
137
- *
138
- * const notebook = await space.createNotebook(formData);
139
- * console.log('Created:', notebook.name);
140
- * ```
141
- */
142
- createNotebook(formData: FormData): Promise<Notebook>;
143
- /**
144
- * Create a new lexical document in this space.
145
- *
146
- * @param formData - Lexical creation form data
147
- * @returns Promise resolving to created Lexical instance
148
- *
149
- * @example
150
- * ```typescript
151
- * const formData = new FormData();
152
- * formData.append('name', 'Project Documentation');
153
- * formData.append('documentType', 'lexical');
154
- *
155
- * const lexical = await space.createLexical(formData);
156
- * console.log('Created:', lexical.name);
157
- * ```
158
- */
159
- createLexical(formData: FormData): Promise<Lexical>;
160
- /**
161
- * Get raw space data object with latest information.
162
- *
163
- * This method ensures the returned data includes the most recent information
164
- * by refreshing from the API before returning.
165
- *
166
- * @returns Promise resolving to raw space data
167
- *
168
- * @example
169
- * ```typescript
170
- * const latestData = await space.toJSON();
171
- * console.log('Current name:', latestData.name);
172
- * ```
173
- */
174
- toJSON(): Promise<SpaceData>;
175
- /**
176
- * String representation of the space.
177
- *
178
- * @returns String representation for logging/debugging
179
- */
180
- toString(): string;
181
- }
182
- export type { SpaceData };
@@ -1,276 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import { users, items } from '../../../api/spacer';
6
- /**
7
- * Space domain model that wraps API responses with convenient methods.
8
- *
9
- * Provides a rich, object-oriented interface for managing workspace spaces
10
- * with automatic data refresh and content creation operations.
11
- *
12
- * @example
13
- * ```typescript
14
- * const spaces = await sdk.getMySpaces();
15
- * const space = spaces[0];
16
- *
17
- * // Static properties - instant access
18
- * console.log(space.uid);
19
- * console.log(space.visibility);
20
- *
21
- * // Dynamic data - always fresh from API
22
- * const currentName = await space.getName();
23
- * const items = await space.getItems();
24
- *
25
- * // Create content in this space
26
- * const notebook = await space.createNotebook(formData);
27
- * const lexical = await space.createLexical(formData);
28
- * ```
29
- */
30
- export class Space {
31
- _data;
32
- _sdk;
33
- _deleted = false;
34
- /**
35
- * Create a Space instance.
36
- *
37
- * @param data - Raw space data from API
38
- * @param sdk - DatalayerSDK instance for making API calls
39
- */
40
- constructor(data, sdk) {
41
- this._data = data;
42
- this._sdk = sdk;
43
- }
44
- // ========================================================================
45
- // Helper Methods
46
- // ========================================================================
47
- /**
48
- * Check if this space has been deleted and throw error if so.
49
- * @throws Error if the space has been deleted
50
- */
51
- _checkDeleted() {
52
- if (this._deleted) {
53
- throw new Error(`Space ${this._data.uid} has been deleted and no longer exists`);
54
- }
55
- }
56
- /**
57
- * Refresh space data from the API by fetching user's spaces.
58
- * Since there's no individual GET endpoint, we fetch from the list.
59
- */
60
- async _refreshData() {
61
- const token = this._sdk.getToken();
62
- const spacerRunUrl = this._sdk.getSpacerRunUrl();
63
- const response = await users.getMySpaces(token, spacerRunUrl);
64
- const freshSpace = response.spaces.find(s => s.uid === this.uid);
65
- if (freshSpace) {
66
- this._data = freshSpace;
67
- }
68
- }
69
- // ========================================================================
70
- // Static Properties (set at creation, never change)
71
- // ========================================================================
72
- /**
73
- * Unique identifier for the space.
74
- */
75
- get uid() {
76
- this._checkDeleted();
77
- return this._data.uid;
78
- }
79
- /**
80
- * Space ID (optional for backward compatibility).
81
- */
82
- get id() {
83
- this._checkDeleted();
84
- return this._data.id || this._data.uid;
85
- }
86
- /**
87
- * Owner user ID.
88
- */
89
- get ownerId() {
90
- this._checkDeleted();
91
- return this._data.owner_id || '';
92
- }
93
- /**
94
- * Organization ID.
95
- */
96
- get organizationId() {
97
- this._checkDeleted();
98
- return this._data.organization_id || '';
99
- }
100
- /**
101
- * When the space was created.
102
- * Note: May not be available for all spaces depending on API response.
103
- */
104
- get createdAt() {
105
- this._checkDeleted();
106
- const dateStr = this._data.creation_ts_dt || this._data.created_at;
107
- if (!dateStr) {
108
- return null; // Some spaces don't have timestamps
109
- }
110
- return new Date(dateStr);
111
- }
112
- /**
113
- * Space visibility setting.
114
- */
115
- get visibility() {
116
- this._checkDeleted();
117
- return this._data.visibility || 'private';
118
- }
119
- /**
120
- * URL-friendly handle for the space.
121
- */
122
- get handle() {
123
- this._checkDeleted();
124
- return this._data.handle_s || '';
125
- }
126
- /**
127
- * Space variant type.
128
- */
129
- get variant() {
130
- this._checkDeleted();
131
- return this._data.variant_s || '';
132
- }
133
- // ========================================================================
134
- // Dynamic Methods (always fetch fresh data and update internal state)
135
- // ========================================================================
136
- /**
137
- * Get the current name of the space.
138
- *
139
- * This method always fetches fresh data from the API and updates
140
- * the internal data to keep everything in sync.
141
- *
142
- * @returns Promise resolving to current space name
143
- * @throws Error if the space has been deleted
144
- */
145
- async getName() {
146
- this._checkDeleted();
147
- await this._refreshData();
148
- return this._data.name || this._data.name_t || '';
149
- }
150
- /**
151
- * Get the current description of the space.
152
- *
153
- * @returns Promise resolving to space description
154
- */
155
- async getDescription() {
156
- this._checkDeleted();
157
- await this._refreshData();
158
- return this._data.description || this._data.description_t || '';
159
- }
160
- /**
161
- * Get when the space was last updated.
162
- *
163
- * @returns Promise resolving to last update time
164
- */
165
- async getUpdatedAt() {
166
- this._checkDeleted();
167
- await this._refreshData();
168
- const dateStr = this._data.last_update_ts_dt ||
169
- this._data.updated_at ||
170
- this._data.creation_ts_dt ||
171
- this._data.created_at;
172
- if (!dateStr) {
173
- return null; // Some spaces don't have timestamps
174
- }
175
- return new Date(dateStr);
176
- }
177
- // ========================================================================
178
- // Space-specific Methods
179
- // ========================================================================
180
- /**
181
- * Get all items in this space.
182
- *
183
- * @returns Promise resolving to array of space items
184
- *
185
- * @example
186
- * ```typescript
187
- * const items = await space.getItems();
188
- * items.forEach(item => {
189
- * console.log(`${item.name} (${item.type})`);
190
- * });
191
- * ```
192
- */
193
- async getItems() {
194
- this._checkDeleted();
195
- const token = this._sdk.getToken();
196
- const spacerRunUrl = this._sdk.getSpacerRunUrl();
197
- const response = await items.getSpaceItems(token, this.uid, spacerRunUrl);
198
- return response.items;
199
- }
200
- /**
201
- * Create a new notebook in this space.
202
- *
203
- * @param formData - Notebook creation form data
204
- * @returns Promise resolving to created Notebook instance
205
- *
206
- * @example
207
- * ```typescript
208
- * const formData = new FormData();
209
- * formData.append('name', 'Analysis Notebook');
210
- * formData.append('notebookType', 'jupyter');
211
- *
212
- * const notebook = await space.createNotebook(formData);
213
- * console.log('Created:', notebook.name);
214
- * ```
215
- */
216
- async createNotebook(formData) {
217
- this._checkDeleted();
218
- // Ensure spaceId is set in the form data
219
- formData.set('spaceId', this.uid);
220
- return await this._sdk.createNotebook(formData);
221
- }
222
- /**
223
- * Create a new lexical document in this space.
224
- *
225
- * @param formData - Lexical creation form data
226
- * @returns Promise resolving to created Lexical instance
227
- *
228
- * @example
229
- * ```typescript
230
- * const formData = new FormData();
231
- * formData.append('name', 'Project Documentation');
232
- * formData.append('documentType', 'lexical');
233
- *
234
- * const lexical = await space.createLexical(formData);
235
- * console.log('Created:', lexical.name);
236
- * ```
237
- */
238
- async createLexical(formData) {
239
- this._checkDeleted();
240
- // Ensure spaceId is set in the form data
241
- formData.set('spaceId', this.uid);
242
- return await this._sdk.createLexical(formData);
243
- }
244
- // ========================================================================
245
- // Utility Methods
246
- // ========================================================================
247
- /**
248
- * Get raw space data object with latest information.
249
- *
250
- * This method ensures the returned data includes the most recent information
251
- * by refreshing from the API before returning.
252
- *
253
- * @returns Promise resolving to raw space data
254
- *
255
- * @example
256
- * ```typescript
257
- * const latestData = await space.toJSON();
258
- * console.log('Current name:', latestData.name);
259
- * ```
260
- */
261
- async toJSON() {
262
- this._checkDeleted();
263
- await this._refreshData();
264
- return this._data;
265
- }
266
- /**
267
- * String representation of the space.
268
- *
269
- * @returns String representation for logging/debugging
270
- */
271
- toString() {
272
- this._checkDeleted();
273
- const name = this._data.name || this._data.name_t || 'Unnamed';
274
- return `Space(${this.uid}, ${name})`;
275
- }
276
- }
@@ -1 +0,0 @@
1
- export {};