@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,191 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * Abstract base class for all Datalayer content items.
7
+ *
8
+ * @module client/models/Item
9
+ */
10
+ import * as items from '../../api/spacer/items';
11
+ /**
12
+ * Abstract base class for all Datalayer content items.
13
+ * Provides common functionality for content management including lifecycle tracking.
14
+ *
15
+ * @template TData - Raw data type from API
16
+ * @template TUpdateRequest - Update request type for API
17
+ */
18
+ export class Item {
19
+ _data;
20
+ _sdk;
21
+ _deleted = false;
22
+ /**
23
+ * Create an Item instance.
24
+ * @param data - Item data from API
25
+ * @param sdk - SDK instance
26
+ */
27
+ constructor(data, sdk) {
28
+ this._data = data;
29
+ this._sdk = sdk;
30
+ }
31
+ // ========================================================================
32
+ // Deletion State Management
33
+ // ========================================================================
34
+ /** Check if this item has been deleted. */
35
+ get isDeleted() {
36
+ return this._deleted;
37
+ }
38
+ /**
39
+ * Check if this item has been deleted and throw error if so.
40
+ * @throws Error if deleted
41
+ */
42
+ _checkDeleted() {
43
+ if (this._deleted) {
44
+ throw new Error(`${this.constructor.name} ${this._data.id} has been deleted and no longer exists`);
45
+ }
46
+ }
47
+ // ========================================================================
48
+ // Static Properties (set at creation, never change)
49
+ // ========================================================================
50
+ /** Item ID. */
51
+ get id() {
52
+ this._checkDeleted();
53
+ return this._data.id;
54
+ }
55
+ /** Unique identifier for the item. */
56
+ get uid() {
57
+ this._checkDeleted();
58
+ return this._data.uid;
59
+ }
60
+ /** Parent space ID. */
61
+ get spaceId() {
62
+ this._checkDeleted();
63
+ // Try the direct field first (if API provides it)
64
+ if (this._data.space_id) {
65
+ return this._data.space_id;
66
+ }
67
+ // Extract from s3_path_s if available: "datalayer.app/SPACE_ID/..."
68
+ const s3Path = this._data.s3_path_s;
69
+ if (s3Path && typeof s3Path === 'string') {
70
+ const match = s3Path.match(/^datalayer\.app\/([^/]+)\//);
71
+ if (match) {
72
+ return match[1];
73
+ }
74
+ }
75
+ // Fallback to empty string if no space ID can be determined
76
+ return '';
77
+ }
78
+ /** Owner user ID. */
79
+ get ownerId() {
80
+ this._checkDeleted();
81
+ return (this._data.owner_id || this._data.creator_uid || '');
82
+ }
83
+ /** When the item was created. */
84
+ get createdAt() {
85
+ this._checkDeleted();
86
+ const dateStr = this._data.creation_ts_dt || this._data.created_at;
87
+ if (!dateStr) {
88
+ throw new Error(`No creation timestamp available for ${this.constructor.name.toLowerCase()}`);
89
+ }
90
+ return new Date(dateStr);
91
+ }
92
+ /** The cached update time. */
93
+ get updatedAt() {
94
+ this._checkDeleted();
95
+ const dateStr = this._data.last_update_ts_dt ||
96
+ this._data.updated_at ||
97
+ this._data.creation_ts_dt ||
98
+ this._data.created_at;
99
+ if (!dateStr) {
100
+ throw new Error(`No update timestamp available for ${this.constructor.name.toLowerCase()}`);
101
+ }
102
+ return new Date(dateStr);
103
+ }
104
+ // ========================================================================
105
+ // Action Methods
106
+ // ========================================================================
107
+ /**
108
+ * Delete this item permanently.
109
+ * After deletion, all subsequent method calls will throw errors.
110
+ */
111
+ async delete() {
112
+ this._checkDeleted();
113
+ const token = this._sdk.getToken();
114
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
115
+ await items.deleteItem(token, this.uid, spacerRunUrl);
116
+ this._deleted = true;
117
+ }
118
+ /** Get the document content from API. */
119
+ async getContent() {
120
+ this._checkDeleted();
121
+ // First try: CDN URL (fastest)
122
+ const cdnUrl = this._data.cdn_url_s;
123
+ if (cdnUrl) {
124
+ try {
125
+ const response = await fetch(cdnUrl);
126
+ if (!response.ok) {
127
+ throw new Error('Failed to fetch content from CDN');
128
+ }
129
+ const data = await response.json();
130
+ if (data.content !== undefined && data.content !== null) {
131
+ return data.content;
132
+ }
133
+ }
134
+ catch (error) {
135
+ console.error('Error fetching content from CDN:', error);
136
+ }
137
+ }
138
+ // Second try: Check if content is already loaded
139
+ const cachedContent = this.content;
140
+ if (cachedContent !== undefined && cachedContent !== null) {
141
+ return cachedContent;
142
+ }
143
+ // Third try: Fetch full item details from API
144
+ try {
145
+ const token = this._sdk.getToken();
146
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
147
+ const response = await items.getItem(token, this.uid, spacerRunUrl);
148
+ // Update internal data with full item details
149
+ if (response.success && response.item) {
150
+ this._data = response.item;
151
+ const freshContent = this.content;
152
+ if (freshContent !== undefined && freshContent !== null) {
153
+ return freshContent;
154
+ }
155
+ }
156
+ }
157
+ catch (error) {
158
+ console.error('Error fetching full item details:', error);
159
+ }
160
+ throw new Error(`Content is not available for item ${this.uid}. The item may not have been fully loaded or the content is not yet available.`);
161
+ }
162
+ // ========================================================================
163
+ // Utility Methods
164
+ // ========================================================================
165
+ /** Get raw item data object. */
166
+ rawData() {
167
+ this._checkDeleted();
168
+ return this._data;
169
+ }
170
+ /** String representation of the item. */
171
+ toString() {
172
+ this._checkDeleted();
173
+ const name = this.name || 'Unnamed';
174
+ return `${this.constructor.name}(${this.id}, ${name})`;
175
+ }
176
+ // ========================================================================
177
+ // Protected Helper Methods
178
+ // ========================================================================
179
+ /** Get SDK token for API calls. */
180
+ _getToken() {
181
+ return this._sdk.getToken();
182
+ }
183
+ /** Get spacer API URL for API calls. */
184
+ _getSpacerRunUrl() {
185
+ return this._sdk.getSpacerRunUrl();
186
+ }
187
+ /** Update internal data after API call. */
188
+ _updateData(newData) {
189
+ this._data = newData;
190
+ }
191
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Lexical domain model for the Datalayer SDK.
3
+ *
4
+ * @module client/models/Lexical
5
+ */
6
+ import type { Lexical as LexicalData } from '../../api/types/spacer';
7
+ import type { DatalayerClient } from '../index';
8
+ import { Item } from './Item';
9
+ /**
10
+ * Stable public interface for Lexical data.
11
+ * This is the contract that SDK consumers can rely on.
12
+ * The raw API may change, but this interface remains stable.
13
+ */
14
+ export interface LexicalJSON {
15
+ /** Unique identifier for the lexical document */
16
+ uid: string;
17
+ /** Unique identifier for the lexical document */
18
+ id: string;
19
+ /** Name of the lexical document */
20
+ name: string;
21
+ /** Description of the lexical document */
22
+ description: string;
23
+ /** Type of lexical document */
24
+ type: string;
25
+ /** File extension of the lexical document */
26
+ extension: string;
27
+ /** ISO 8601 timestamp when the document was created */
28
+ createdAt: string;
29
+ /** ISO 8601 timestamp when the document was last updated */
30
+ updatedAt: string;
31
+ /** CDN URL for accessing the document */
32
+ cdnUrl: string;
33
+ }
34
+ /**
35
+ * Lexical domain model that extends the base Item class.
36
+ * Provides lexical document functionality for managing rich text documents.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const lexical = await sdk.createLexical(formData);
41
+ * await lexical.update({ name: 'Updated Documentation' });
42
+ * ```
43
+ */
44
+ export declare class Lexical extends Item<LexicalData> {
45
+ /**
46
+ * Create a Lexical instance.
47
+ *
48
+ * @param data - Lexical data from API
49
+ * @param sdk - SDK instance
50
+ */
51
+ constructor(data: LexicalData, sdk: DatalayerClient);
52
+ /** Document type identifier. */
53
+ get type(): string;
54
+ /** The cached name of the document. */
55
+ get name(): string;
56
+ /** Get the current name of the document from API. */
57
+ getName(): Promise<string>;
58
+ /** The cached content. */
59
+ get content(): any;
60
+ /** Description of the lexical document. */
61
+ get description(): string;
62
+ /** Get the document extension. */
63
+ get extension(): string;
64
+ /** Get when the document was last updated from API. */
65
+ getUpdatedAt(): Promise<Date>;
66
+ /** Update the document. */
67
+ update(name?: string, description?: string): Promise<this>;
68
+ /**
69
+ * Get lexical document data in camelCase format.
70
+ * Returns only the core fields that consumers need.
71
+ * This provides a stable interface regardless of API changes.
72
+ *
73
+ * @returns Core lexical data with camelCase properties
74
+ */
75
+ toJSON(): LexicalJSON;
76
+ /**
77
+ * Get the raw lexical data exactly as received from the API.
78
+ * This preserves the original snake_case naming from the API response.
79
+ *
80
+ * @returns Raw lexical data from API
81
+ */
82
+ rawData(): LexicalData;
83
+ }
@@ -0,0 +1,152 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import * as lexicals from '../../api/spacer/lexicals';
6
+ import { Item } from './Item';
7
+ import { ItemTypes } from '../constants';
8
+ import { validateJSON } from '../../api/utils/validation';
9
+ /**
10
+ * Lexical domain model that extends the base Item class.
11
+ * Provides lexical document functionality for managing rich text documents.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const lexical = await sdk.createLexical(formData);
16
+ * await lexical.update({ name: 'Updated Documentation' });
17
+ * ```
18
+ */
19
+ export class Lexical extends Item {
20
+ /**
21
+ * Create a Lexical instance.
22
+ *
23
+ * @param data - Lexical 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.LEXICAL;
36
+ }
37
+ /** The cached name of the document. */
38
+ get name() {
39
+ this._checkDeleted();
40
+ return this._data.name_t || this._data.name || '';
41
+ }
42
+ /** Get the current name of the document from API. */
43
+ async getName() {
44
+ this._checkDeleted();
45
+ const token = this._getToken();
46
+ const spacerRunUrl = this._getSpacerRunUrl();
47
+ const response = await lexicals.getLexical(token, this.uid, spacerRunUrl);
48
+ if (response.document) {
49
+ this._updateData(response.document);
50
+ return response.document.name_t || response.document.name || '';
51
+ }
52
+ return this.name;
53
+ }
54
+ /** The cached content. */
55
+ get content() {
56
+ this._checkDeleted();
57
+ if (!this._data.content && this._data.model_s) {
58
+ try {
59
+ return JSON.parse(this._data.model_s);
60
+ }
61
+ catch {
62
+ return this._data.model_s;
63
+ }
64
+ }
65
+ return this._data.content;
66
+ }
67
+ /** Description of the lexical document. */
68
+ get description() {
69
+ this._checkDeleted();
70
+ return this._data.description_t || '';
71
+ }
72
+ /** Get the document extension. */
73
+ get extension() {
74
+ this._checkDeleted();
75
+ const ext = this._data.document_extension_s;
76
+ return ext ? (ext.startsWith('.') ? ext : `.${ext}`) : '.lexical';
77
+ }
78
+ /** Get when the document was last updated from API. */
79
+ async getUpdatedAt() {
80
+ this._checkDeleted();
81
+ const token = this._getToken();
82
+ const spacerRunUrl = this._getSpacerRunUrl();
83
+ const response = await lexicals.getLexical(token, this.uid, spacerRunUrl);
84
+ if (response.document) {
85
+ this._updateData(response.document);
86
+ const dateStr = response.document.last_update_ts_dt ||
87
+ response.document.updated_at ||
88
+ response.document.creation_ts_dt ||
89
+ response.document.created_at;
90
+ if (!dateStr) {
91
+ throw new Error('No timestamp available for lexical document');
92
+ }
93
+ return new Date(dateStr);
94
+ }
95
+ const dateStr = this._data.last_update_ts_dt ||
96
+ this._data.updated_at ||
97
+ this._data.creation_ts_dt ||
98
+ this._data.created_at;
99
+ if (!dateStr) {
100
+ throw new Error('No timestamp available for lexical document');
101
+ }
102
+ return new Date(dateStr);
103
+ }
104
+ /** Update the document. */
105
+ async update(name, description) {
106
+ // FIXME: check if both are needed, and use the existing values if only one provided
107
+ this._checkDeleted();
108
+ const token = this._getToken();
109
+ const spacerRunUrl = this._getSpacerRunUrl();
110
+ const updateData = {};
111
+ if (name !== undefined)
112
+ updateData.name = name;
113
+ if (description !== undefined)
114
+ updateData.description = description;
115
+ const response = await lexicals.updateLexical(token, this.uid, updateData, spacerRunUrl);
116
+ this._updateData(response.document);
117
+ return this;
118
+ }
119
+ /**
120
+ * Get lexical document data in camelCase format.
121
+ * Returns only the core fields that consumers need.
122
+ * This provides a stable interface regardless of API changes.
123
+ *
124
+ * @returns Core lexical data with camelCase properties
125
+ */
126
+ toJSON() {
127
+ this._checkDeleted();
128
+ const obj = {
129
+ uid: this.uid,
130
+ id: this.id,
131
+ name: this.name,
132
+ description: this.description,
133
+ type: this.type,
134
+ extension: this.extension,
135
+ createdAt: this.createdAt.toDateString(),
136
+ updatedAt: this.updatedAt.toDateString(),
137
+ cdnUrl: this._data.cdn_url_s,
138
+ };
139
+ validateJSON(obj, 'Lexical');
140
+ return obj;
141
+ }
142
+ /**
143
+ * Get the raw lexical data exactly as received from the API.
144
+ * This preserves the original snake_case naming from the API response.
145
+ *
146
+ * @returns Raw lexical data from API
147
+ */
148
+ rawData() {
149
+ this._checkDeleted();
150
+ return this._data;
151
+ }
152
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Notebook domain model for the Datalayer SDK.
3
+ *
4
+ * @module client/models/Notebook
5
+ */
6
+ import type { Notebook as NotebookData } from '../../api/types/spacer';
7
+ import type { DatalayerClient } from '../index';
8
+ import { Item } from './Item';
9
+ /**
10
+ * Stable public interface for Notebook data.
11
+ * This is the contract that SDK consumers can rely on.
12
+ * The raw API may change, but this interface remains stable.
13
+ */
14
+ export interface NotebookJSON {
15
+ /** uuid of the notebook */
16
+ id: string;
17
+ /** ulid for of the notebook */
18
+ uid: string;
19
+ /** Name of the notebook */
20
+ name: string;
21
+ /** Description of the notebook */
22
+ description: string;
23
+ /** Type of notebook */
24
+ type: string;
25
+ /** File extension of the notebook */
26
+ extension: string;
27
+ /** CDN URL for accessing the notebook */
28
+ cdnUrl: string;
29
+ }
30
+ /**
31
+ * Notebook domain model that extends the base Item class.
32
+ * Provides notebook-specific functionality for managing Jupyter notebooks.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const notebook = await sdk.createNotebook(formData);
37
+ * const kernelSpec = await notebook.getKernelSpec();
38
+ * ```
39
+ */
40
+ export declare class Notebook extends Item<NotebookData> {
41
+ /**
42
+ * Create a Notebook instance.
43
+ *
44
+ * @param data - Notebook data from API
45
+ * @param sdk - SDK instance
46
+ */
47
+ constructor(data: NotebookData, sdk: DatalayerClient);
48
+ /** Document type identifier. */
49
+ get type(): string;
50
+ /** The cached name of the notebook. */
51
+ get name(): string;
52
+ /** The cached content. */
53
+ get content(): any;
54
+ /** Get the current name from API. */
55
+ getName(): Promise<string>;
56
+ /** Get when the notebook was last updated from API. */
57
+ getUpdatedAt(): Promise<Date>;
58
+ /** Update the notebook. */
59
+ update(name?: string, description?: string): Promise<this>;
60
+ /** File path within the space. */
61
+ get path(): string;
62
+ /** Version number. */
63
+ get version(): number;
64
+ /** Notebook metadata. */
65
+ get metadata(): Record<string, any>;
66
+ /** Kernel specification (cached). */
67
+ get kernelSpec(): any;
68
+ /** Description of the notebook. */
69
+ get description(): string;
70
+ /** Get the notebook extension. */
71
+ get extension(): string;
72
+ /**
73
+ * Get notebook data in camelCase format.
74
+ * Returns only the core fields that consumers need.
75
+ * This provides a stable interface regardless of API changes.
76
+ *
77
+ * @returns Core notebook data with camelCase properties
78
+ */
79
+ toJSON(): NotebookJSON;
80
+ /**
81
+ * Get the raw notebook data exactly as received from the API.
82
+ * This preserves the original snake_case naming from the API response.
83
+ *
84
+ * @returns Raw notebook data from API
85
+ */
86
+ rawData(): NotebookData;
87
+ }
@@ -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 { Item } from './Item';
7
+ import { ItemTypes } from '../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 Notebook extends Item {
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
+ }