@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
@@ -0,0 +1,234 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import * as users from '../../api/spacer/users';
6
+ import * as items from '../../api/spacer/items';
7
+ import * as notebooks from '../../api/spacer/notebooks';
8
+ import * as lexicals from '../../api/spacer/lexicals';
9
+ import { Notebook } from './Notebook';
10
+ import { Lexical } from './Lexical';
11
+ import { ItemTypes } from '../constants';
12
+ import { convertSpaceItemsToModels } from '../utils/spacerUtils';
13
+ import { validateJSON } from '../../api/utils/validation';
14
+ /**
15
+ * Space domain model that wraps API responses with convenient methods.
16
+ * Provides workspace management with data refresh and content creation operations.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const space = spaces[0];
21
+ * const items = await space.getItems();
22
+ * const notebook = await space.createNotebook({ name: 'Analysis' });
23
+ * ```
24
+ */
25
+ export class Space {
26
+ _data;
27
+ _sdk;
28
+ _items = null;
29
+ _deleted = false;
30
+ /**
31
+ * Create a Space instance.
32
+ *
33
+ * @param data - Space data from API
34
+ * @param sdk - SDK instance
35
+ */
36
+ constructor(data, sdk) {
37
+ this._data = data;
38
+ this._sdk = sdk;
39
+ }
40
+ // ========================================================================
41
+ // Helper Methods
42
+ // ========================================================================
43
+ /**
44
+ * Check if this space has been deleted and throw error if so.
45
+ * @throws Error if deleted
46
+ */
47
+ _checkDeleted() {
48
+ if (this._deleted) {
49
+ throw new Error(`Space ${this._data.uid} has been deleted and no longer exists`);
50
+ }
51
+ }
52
+ /**
53
+ * Refresh space data from the API by fetching user's spaces.
54
+ */
55
+ async refresh() {
56
+ const token = this._sdk.getToken();
57
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
58
+ const response = await users.getMySpaces(token, spacerRunUrl);
59
+ const freshSpace = response.spaces.find(s => s.uid === this.uid);
60
+ if (freshSpace) {
61
+ this._data = freshSpace;
62
+ }
63
+ }
64
+ // ========================================================================
65
+ // Static Properties (set at creation, never change)
66
+ // ========================================================================
67
+ /** Unique identifier for the space. */
68
+ get uid() {
69
+ this._checkDeleted();
70
+ return this._data.uid;
71
+ }
72
+ /** URL-friendly handle for the space. */
73
+ get handle() {
74
+ this._checkDeleted();
75
+ return this._data.handle_s;
76
+ }
77
+ /** Space variant type. */
78
+ get variant() {
79
+ this._checkDeleted();
80
+ return this._data.variant_s;
81
+ }
82
+ /**
83
+ * The name of the space.
84
+ */
85
+ get name() {
86
+ return this._data.name_t;
87
+ }
88
+ /**
89
+ * The description of the space.
90
+ */
91
+ get description() {
92
+ return this._data.description_t;
93
+ }
94
+ // ========================================================================
95
+ // Space-specific Methods
96
+ // ========================================================================
97
+ /**
98
+ * Helper method to create items in this space.
99
+ *
100
+ * @param itemType - Type of item to create
101
+ * @param data - Creation configuration
102
+ * @returns Created model instance
103
+ * @internal
104
+ */
105
+ async _createItem(data) {
106
+ this._checkDeleted();
107
+ // Get necessary configuration from SDK
108
+ const token = this._sdk.getToken();
109
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
110
+ if (data.type === ItemTypes.NOTEBOOK) {
111
+ const requestData = {
112
+ spaceId: this.uid,
113
+ name: data.name,
114
+ description: data.description,
115
+ notebookType: data.type,
116
+ file: data.file,
117
+ };
118
+ const response = await notebooks.createNotebook(token, requestData, spacerRunUrl);
119
+ if (!response.notebook) {
120
+ throw new Error('Failed to create notebook: No notebook returned');
121
+ }
122
+ else {
123
+ return new Notebook(response.notebook, this._sdk);
124
+ }
125
+ }
126
+ else if (data.type === ItemTypes.LEXICAL) {
127
+ const requestData = {
128
+ spaceId: this.uid,
129
+ name: data.name,
130
+ description: data.description,
131
+ documentType: data.type,
132
+ file: data.file,
133
+ };
134
+ const response = await lexicals.createLexical(token, requestData, spacerRunUrl);
135
+ if (!response.document) {
136
+ throw new Error('Failed to create lexical document: No document returned');
137
+ }
138
+ else {
139
+ return new Lexical(response.document, this._sdk);
140
+ }
141
+ }
142
+ else {
143
+ throw new Error(`Unsupported item type: ${data.type}`);
144
+ }
145
+ }
146
+ /**
147
+ * Get all items in this space as model instances.
148
+ *
149
+ * @returns Array of Notebook and Lexical model instances
150
+ */
151
+ async getItems() {
152
+ this._checkDeleted();
153
+ const token = this._sdk.getToken();
154
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
155
+ const response = await items.getSpaceItems(token, this.uid, spacerRunUrl);
156
+ // Use shared utility function to convert items to model instances
157
+ this._items = convertSpaceItemsToModels(response.items || [], this._sdk);
158
+ return this._items;
159
+ }
160
+ /**
161
+ * Create a new notebook in this space.
162
+ *
163
+ * @param data - Notebook creation configuration
164
+ * @returns Created Notebook instance
165
+ */
166
+ async createNotebook(data) {
167
+ return this._createItem({
168
+ name: data.name,
169
+ type: ItemTypes.NOTEBOOK,
170
+ description: data.description,
171
+ file: data.file,
172
+ });
173
+ }
174
+ /**
175
+ * Create a new lexical document in this space.
176
+ *
177
+ * @param data - Lexical creation configuration
178
+ * @returns Created Lexical instance
179
+ */
180
+ async createLexical(data) {
181
+ return this._createItem({
182
+ name: data.name,
183
+ type: ItemTypes.LEXICAL,
184
+ description: data.description,
185
+ file: data.file,
186
+ });
187
+ }
188
+ // ========================================================================
189
+ // Utility Methods
190
+ // ========================================================================
191
+ /**
192
+ * Get raw space data object.
193
+ * Returns cached data without refreshing.
194
+ *
195
+ * @returns Raw space data object
196
+ */
197
+ /**
198
+ * Get space data in camelCase format.
199
+ * Returns only the core fields that consumers need.
200
+ * This provides a stable interface regardless of API changes.
201
+ *
202
+ * @returns Core space data with camelCase properties
203
+ */
204
+ toJSON() {
205
+ this._checkDeleted();
206
+ const obj = {
207
+ uid: this.uid,
208
+ name: this.name,
209
+ description: this.description,
210
+ variant: this.variant,
211
+ handle: this.handle,
212
+ items: this._data.items
213
+ ? convertSpaceItemsToModels(this._data.items, this._sdk).map(item => item.toJSON())
214
+ : [],
215
+ };
216
+ validateJSON(obj, 'Space');
217
+ return obj;
218
+ }
219
+ /**
220
+ * Get the raw space data exactly as received from the API.
221
+ * This preserves the original snake_case naming from the API response.
222
+ *
223
+ * @returns Raw space data from API
224
+ */
225
+ rawData() {
226
+ this._checkDeleted();
227
+ return this._data;
228
+ }
229
+ /** String representation of the space. */
230
+ toString() {
231
+ this._checkDeleted();
232
+ return `Space(${this.uid}, ${this.name})`;
233
+ }
234
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * User model for the Datalayer SDK with rich functionality.
3
+ *
4
+ * @module client/models/User
5
+ */
6
+ import type { User as UserData } from '../../api/types/iam';
7
+ import type { DatalayerClient } from '../index';
8
+ export interface UserJSON {
9
+ /** uuid for the user */
10
+ id: string;
11
+ /** ulid for the user */
12
+ uid: string;
13
+ /** First name of the user */
14
+ firstName: string;
15
+ /** Last name of the user */
16
+ lastName: string;
17
+ /** Display name of the user */
18
+ displayName: string;
19
+ /** Email address of the user */
20
+ email: string;
21
+ /** Description of the user */
22
+ handle: string;
23
+ /** URL to the user's avatar image */
24
+ avatarUrl: string;
25
+ }
26
+ /**
27
+ * User model representing a Datalayer platform user.
28
+ * Provides rich functionality for accessing user data and authentication providers.
29
+ */
30
+ export declare class User {
31
+ protected _data: UserData;
32
+ /**
33
+ * Create a User instance.
34
+ *
35
+ * @param data - User data from API
36
+ * @param sdk - SDK instance (currently unused but kept for compatibility)
37
+ */
38
+ constructor(data: UserData, sdk?: DatalayerClient);
39
+ get id(): string;
40
+ get uid(): string;
41
+ get email(): string;
42
+ get handle(): string;
43
+ get firstName(): string;
44
+ get lastName(): string;
45
+ get displayName(): string;
46
+ get avatarUrl(): string;
47
+ /**
48
+ * Get user data in camelCase format.
49
+ * Returns only the core fields that consumers need.
50
+ * This provides a stable interface regardless of API changes.
51
+ *
52
+ * @returns Core user data with camelCase properties
53
+ */
54
+ toJSON(): UserJSON;
55
+ /**
56
+ * Get the raw user data exactly as received from the API.
57
+ * This preserves the original snake_case naming from the API response.
58
+ *
59
+ * @returns Raw user data from API
60
+ */
61
+ rawData(): UserData;
62
+ /** String representation of the user. */
63
+ toString(): string;
64
+ }
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { validateJSON } from '../../api/utils/validation';
6
+ /**
7
+ * User model representing a Datalayer platform user.
8
+ * Provides rich functionality for accessing user data and authentication providers.
9
+ */
10
+ export class User {
11
+ _data;
12
+ /**
13
+ * Create a User instance.
14
+ *
15
+ * @param data - User data from API
16
+ * @param sdk - SDK instance (currently unused but kept for compatibility)
17
+ */
18
+ constructor(data, sdk) {
19
+ this._data = data;
20
+ }
21
+ // Basic properties
22
+ get id() {
23
+ return this._data.id;
24
+ }
25
+ get uid() {
26
+ return this._data.uid;
27
+ }
28
+ get email() {
29
+ return this._data.email_s;
30
+ }
31
+ get handle() {
32
+ return this._data.handle_s;
33
+ }
34
+ get firstName() {
35
+ return this._data.first_name_t;
36
+ }
37
+ get lastName() {
38
+ return this._data.last_name_t;
39
+ }
40
+ get displayName() {
41
+ return `${this.firstName} ${this.lastName}`.trim();
42
+ }
43
+ get avatarUrl() {
44
+ return this._data.avatar_url_s;
45
+ }
46
+ // ========================================================================
47
+ // Utility Methods
48
+ // ========================================================================
49
+ /**
50
+ * Get user data in camelCase format.
51
+ * Returns only the core fields that consumers need.
52
+ * This provides a stable interface regardless of API changes.
53
+ *
54
+ * @returns Core user data with camelCase properties
55
+ */
56
+ toJSON() {
57
+ const obj = {
58
+ id: this.id,
59
+ uid: this.uid,
60
+ firstName: this.firstName,
61
+ lastName: this.lastName,
62
+ displayName: this.displayName,
63
+ email: this.email,
64
+ handle: this.handle,
65
+ avatarUrl: this.avatarUrl,
66
+ };
67
+ validateJSON(obj, 'User');
68
+ return obj;
69
+ }
70
+ /**
71
+ * Get the raw user data exactly as received from the API.
72
+ * This preserves the original snake_case naming from the API response.
73
+ *
74
+ * @returns Raw user data from API
75
+ */
76
+ rawData() {
77
+ return this._data;
78
+ }
79
+ /** String representation of the user. */
80
+ toString() {
81
+ return `User(${this.uid}, ${this.displayName})`;
82
+ }
83
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Domain model classes for the Datalayer SDK.
3
+ * These models wrap API responses with convenient methods and state management.
4
+ *
5
+ * @module client/models
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const runtime = await sdk.createRuntime(config);
10
+ * const snapshot = await runtime.createSnapshot('checkpoint');
11
+ * ```
12
+ */
13
+ export { Environment } from './Environment';
14
+ export { Item } from './Item';
15
+ export { Runtime } from './Runtime';
16
+ export { Snapshot } from './Snapshot';
17
+ export { Notebook } from './Notebook';
18
+ export { Lexical } from './Lexical';
19
+ export { Space } from './Space';
20
+ export { Credits } from './Credits';
21
+ export type { EnvironmentJSON } from './Environment';
22
+ export type { RuntimeJSON } from './Runtime';
23
+ export type { SnapshotJSON } from './Snapshot';
24
+ export type { SpaceJSON } from './Space';
25
+ export type { NotebookJSON } from './Notebook';
26
+ export type { LexicalJSON } from './Lexical';
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * Domain model classes for the Datalayer SDK.
7
+ * These models wrap API responses with convenient methods and state management.
8
+ *
9
+ * @module client/models
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const runtime = await sdk.createRuntime(config);
14
+ * const snapshot = await runtime.createSnapshot('checkpoint');
15
+ * ```
16
+ */
17
+ // Export domain model classes
18
+ export { Environment } from './Environment';
19
+ export { Item } from './Item';
20
+ export { Runtime } from './Runtime';
21
+ export { Snapshot } from './Snapshot';
22
+ export { Notebook } from './Notebook';
23
+ export { Lexical } from './Lexical';
24
+ export { Space } from './Space';
25
+ export { Credits } from './Credits';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * TypeScript mixin utilities for composing the DatalayerClient class.
3
+ * @module client/utils/mixins
4
+ */
5
+ /** Type for a constructor function that can be used in mixins. */
6
+ export type Constructor<T = {}> = new (...args: any[]) => T;
7
+ /**
8
+ * Apply mixins to a base class.
9
+ * @param derivedCtor - The base class to extend
10
+ * @param constructors - Array of mixin classes to apply
11
+ */
12
+ export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
@@ -4,36 +4,8 @@
4
4
  */
5
5
  /**
6
6
  * Apply mixins to a base class.
7
- *
8
- * This utility function enables multiple inheritance-like behavior in TypeScript
9
- * by copying properties and methods from mixin classes to the target class.
10
- *
11
7
  * @param derivedCtor - The base class to extend
12
8
  * @param constructors - Array of mixin classes to apply
13
- *
14
- * @example
15
- * ```typescript
16
- * class Base {
17
- * baseMethod() { return 'base'; }
18
- * }
19
- *
20
- * class MixinA {
21
- * mixinAMethod() { return 'A'; }
22
- * }
23
- *
24
- * class MixinB {
25
- * mixinBMethod() { return 'B'; }
26
- * }
27
- *
28
- * interface Combined extends Base, MixinA, MixinB {}
29
- * class Combined extends Base {}
30
- * applyMixins(Combined, [MixinA, MixinB]);
31
- *
32
- * const instance = new Combined();
33
- * instance.baseMethod(); // 'base'
34
- * instance.mixinAMethod(); // 'A'
35
- * instance.mixinBMethod(); // 'B'
36
- * ```
37
9
  */
38
10
  export function applyMixins(derivedCtor, constructors) {
39
11
  constructors.forEach(baseCtor => {
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Utility functions for Spacer-related operations to avoid code duplication.
3
+ * @module client/utils/spacerUtils
4
+ */
5
+ import type { GetSpaceItemsResponse } from '../../api/types/spacer';
6
+ import type { DatalayerClient } from '../index';
7
+ import { Notebook } from '../models/Notebook';
8
+ import { Lexical } from '../models/Lexical';
9
+ /**
10
+ * Convert raw space items from API response to model instances.
11
+ * This utility function is shared between Space.getItems() and SpacerMixin.getSpaceItems()
12
+ * to avoid code duplication.
13
+ *
14
+ * @param response - Raw API response containing space items
15
+ * @param sdk - SDK instance to pass to model constructors
16
+ * @returns Array of Notebook and Lexical model instances
17
+ */
18
+ export declare function convertSpaceItemsToModels(items: GetSpaceItemsResponse['items'], sdk: DatalayerClient): (Notebook | Lexical)[];
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { Notebook } from '../models/Notebook';
6
+ import { Lexical } from '../models/Lexical';
7
+ import { ItemTypes } from '../constants';
8
+ /**
9
+ * Convert raw space items from API response to model instances.
10
+ * This utility function is shared between Space.getItems() and SpacerMixin.getSpaceItems()
11
+ * to avoid code duplication.
12
+ *
13
+ * @param response - Raw API response containing space items
14
+ * @param sdk - SDK instance to pass to model constructors
15
+ * @returns Array of Notebook and Lexical model instances
16
+ */
17
+ export function convertSpaceItemsToModels(items, sdk) {
18
+ const modelItems = [];
19
+ for (const item of items) {
20
+ // Check various possible type fields
21
+ const itemType = item.type_s;
22
+ // Only include notebooks and lexicals
23
+ if (itemType === ItemTypes.NOTEBOOK) {
24
+ modelItems.push(new Notebook(item, sdk));
25
+ }
26
+ else if (itemType === ItemTypes.LEXICAL) {
27
+ modelItems.push(new Lexical(item, sdk));
28
+ }
29
+ // Skip everything else (exercises, cells, etc.)
30
+ }
31
+ return modelItems;
32
+ }
@@ -1,9 +1,14 @@
1
1
  type IFetchSessionId = {
2
2
  url: string;
3
3
  token?: string;
4
+ /**
5
+ * Custom fetch function to use instead of global fetch.
6
+ * Useful for proxying requests in environments with CORS restrictions (e.g., VS Code webviews).
7
+ */
8
+ fetchFn?: typeof fetch;
4
9
  };
5
10
  /**
6
11
  * Fetch the session ID of a collaborative documents from Datalayer.
7
12
  */
8
- export declare function requestDatalayerCollaborationSessionId({ url, token, }: IFetchSessionId): Promise<string>;
13
+ export declare function requestDatalayerCollaborationSessionId({ url, token, fetchFn, }: IFetchSessionId): Promise<string>;
9
14
  export {};
@@ -5,14 +5,14 @@
5
5
  /**
6
6
  * Fetch the session ID of a collaborative documents from Datalayer.
7
7
  */
8
- export async function requestDatalayerCollaborationSessionId({ url, token, }) {
8
+ export async function requestDatalayerCollaborationSessionId({ url, token, fetchFn = fetch, }) {
9
9
  const headers = {
10
10
  Accept: 'application/json',
11
11
  };
12
12
  if (token) {
13
13
  headers['Authorization'] = `Bearer ${token}`;
14
14
  }
15
- const response = await fetch(url, {
15
+ const response = await fetchFn(url, {
16
16
  method: 'GET',
17
17
  headers,
18
18
  credentials: token ? 'include' : 'omit',
@@ -19,6 +19,11 @@ export interface IDatalayerCollaborationConfig {
19
19
  * Authentication token (optional, uses config from store if not provided)
20
20
  */
21
21
  token?: string;
22
+ /**
23
+ * Custom fetch function to use for HTTP requests.
24
+ * Useful for proxying requests in environments with CORS restrictions (e.g., VS Code webviews).
25
+ */
26
+ fetchFn?: typeof fetch;
22
27
  }
23
28
  /**
24
29
  * Datalayer collaboration provider
@@ -14,7 +14,6 @@ var CollaborationStatus;
14
14
  CollaborationStatus["Error"] = "error";
15
15
  })(CollaborationStatus || (CollaborationStatus = {}));
16
16
  import { requestDatalayerCollaborationSessionId } from './DatalayerCollaboration';
17
- import { coreStore } from '../state/substates/CoreState';
18
17
  /**
19
18
  * Datalayer collaboration provider
20
19
  *
@@ -64,24 +63,26 @@ export class DatalayerCollaborationProvider {
64
63
  }
65
64
  this.setStatus(CollaborationStatus.Connecting);
66
65
  try {
67
- // Get configuration from store or use provided config
68
- const { configuration } = coreStore.getState();
69
- const runUrl = this._config.runUrl ?? configuration?.runUrl;
70
- const token = this._config.token ?? configuration?.token;
66
+ // Use ONLY explicitly provided configuration
67
+ // NO fallback to coreStore - if config is wrong, we want to fail fast
68
+ // This is critical for VS Code extension where config must come from settings
69
+ const runUrl = this._config.runUrl;
70
+ const token = this._config.token;
71
71
  if (!runUrl) {
72
- throw new Error('Datalayer runUrl is not configured');
72
+ throw new Error('Datalayer runUrl is not configured - must be explicitly provided in DatalayerCollaborationProvider config');
73
73
  }
74
74
  if (!token) {
75
- throw new Error('Datalayer token is not configured');
75
+ throw new Error('Datalayer token is not configured - must be explicitly provided in DatalayerCollaborationProvider config');
76
76
  }
77
77
  const { ydoc, awareness } = sharedModel;
78
- // Build WebSocket URL
78
+ // Build URLs.
79
79
  const documentURL = URLExt.join(runUrl, '/api/spacer/v1/documents');
80
- const wsUrl = documentURL.replace(/^http/, 'ws');
80
+ const wsUrl = URLExt.join(runUrl, '/api/spacer/v1/documents/ws').replace(/^http/, 'ws');
81
81
  // Request collaboration session from Datalayer
82
82
  const sessionId = await requestDatalayerCollaborationSessionId({
83
83
  url: URLExt.join(documentURL, documentId),
84
84
  token,
85
+ fetchFn: this._config.fetchFn,
85
86
  });
86
87
  // Create WebSocket provider
87
88
  this._provider = new WebsocketProvider(wsUrl, documentId, ydoc, {
@@ -1,4 +1,4 @@
1
- import type { IRemoteServicesManager } from '../../sdk/stateful/runtimes';
1
+ import type { IRemoteServicesManager } from '../../stateful/runtimes';
2
2
  type ICreditsIndicatorProps = {
3
3
  /**
4
4
  * Kernel service manager
@@ -8,7 +8,7 @@ import { Dialog } from '@primer/react/experimental';
8
8
  import { nullTranslator } from '@jupyterlab/translation';
9
9
  import { JSONExt } from '@lumino/coreutils';
10
10
  import { KernelExecutor } from '@datalayer/jupyter-react';
11
- import { RuntimeSnippetsFacade } from '../../sdk/stateful/jupyter';
11
+ import { RuntimeSnippetsFacade } from '../../stateful/jupyter';
12
12
  import { RuntimeCellVariables } from './RuntimeCellVariables';
13
13
  /**
14
14
  * Dialog to define the runtime cell variables to transfer
@@ -1,5 +1,5 @@
1
1
  import type { IMarkdownParser, IRenderMime } from '@jupyterlab/rendermime';
2
- import type { IRemoteServicesManager } from '../../sdk/stateful/runtimes';
2
+ import type { IRemoteServicesManager } from '../../stateful/runtimes';
3
3
  import type { IRuntimeSnapshot, IRuntimeDesc } from '../../models';
4
4
  /**
5
5
  * {@link RuntimeLauncherDialog} properties.
@@ -2,7 +2,7 @@ import { ReactElement, ReactNode } from 'react';
2
2
  import { ISessionContext } from '@jupyterlab/apputils';
3
3
  import { ITranslator } from '@jupyterlab/translation';
4
4
  import { IRuntimeDesc } from '../../models';
5
- import { IMultiServiceManager } from '../../sdk/stateful/runtimes';
5
+ import { IMultiServiceManager } from '../../stateful/runtimes';
6
6
  type IDisplayMode = 'menu' | 'radio';
7
7
  /**
8
8
  * {@link RuntimePickerBase} properties
@@ -12,7 +12,7 @@ import { Box } from '@datalayer/primer-addons';
12
12
  import { CpuIcon } from '@primer/octicons-react';
13
13
  import { BrowserIcon, LaptopSimpleIcon } from '@datalayer/icons-react';
14
14
  import { CreditsIndicator } from '../../components/progress';
15
- import { isRuntimeRemote, } from '../../sdk/stateful/runtimes';
15
+ import { isRuntimeRemote } from '../../stateful/runtimes';
16
16
  import { getGroupedRuntimeDescs } from './RuntimeUtils';
17
17
  /**
18
18
  * Maximal runtime display name length after which it is trimmed.