@datalayer/core 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +2 -2
  2. package/lib/api/DatalayerApi.d.ts +38 -26
  3. package/lib/api/DatalayerApi.js +52 -13
  4. package/lib/api/iam/authentication.d.ts +9 -8
  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 +18 -0
  15. package/lib/api/iam/usage.js +39 -0
  16. package/lib/api/index.d.ts +6 -6
  17. package/lib/api/index.js +6 -7
  18. package/lib/api/runtimes/environments.d.ts +2 -2
  19. package/lib/api/runtimes/environments.js +3 -2
  20. package/lib/api/runtimes/healthz.d.ts +3 -13
  21. package/lib/api/runtimes/healthz.js +4 -3
  22. package/lib/api/runtimes/index.d.ts +3 -2
  23. package/lib/api/runtimes/index.js +3 -2
  24. package/lib/api/runtimes/runtimes.d.ts +4 -4
  25. package/lib/api/runtimes/runtimes.js +17 -6
  26. package/lib/api/runtimes/snapshots.d.ts +4 -4
  27. package/lib/api/runtimes/snapshots.js +3 -2
  28. package/lib/api/spacer/documents.d.ts +12 -0
  29. package/lib/api/spacer/documents.js +43 -0
  30. package/lib/api/spacer/healthz.d.ts +3 -13
  31. package/lib/api/spacer/healthz.js +4 -3
  32. package/lib/api/spacer/index.d.ts +4 -2
  33. package/lib/api/spacer/index.js +4 -2
  34. package/lib/api/spacer/items.d.ts +9 -1
  35. package/lib/api/spacer/items.js +17 -2
  36. package/lib/api/spacer/lexicals.d.ts +1 -1
  37. package/lib/api/spacer/lexicals.js +3 -2
  38. package/lib/api/spacer/notebooks.d.ts +1 -1
  39. package/lib/api/spacer/notebooks.js +3 -2
  40. package/lib/api/spacer/spaces.d.ts +1 -1
  41. package/lib/api/spacer/spaces.js +3 -2
  42. package/lib/api/spacer/users.d.ts +1 -1
  43. package/lib/api/spacer/users.js +3 -2
  44. package/lib/api/utils/validation.d.ts +24 -1
  45. package/lib/api/utils/validation.js +62 -1
  46. package/lib/client/base.d.ts +75 -0
  47. package/lib/client/base.js +199 -0
  48. package/lib/client/constants.d.ts +22 -0
  49. package/lib/client/constants.js +22 -0
  50. package/lib/client/index.d.ts +108 -0
  51. package/lib/client/index.js +79 -0
  52. package/lib/client/mixins/IAMMixin.d.ts +54 -0
  53. package/lib/client/mixins/IAMMixin.js +181 -0
  54. package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
  55. package/lib/client/mixins/RuntimesMixin.js +229 -0
  56. package/lib/client/mixins/SpacerMixin.d.ts +111 -0
  57. package/lib/client/mixins/SpacerMixin.js +340 -0
  58. package/lib/client/utils/mixins.d.ts +12 -0
  59. package/lib/{sdk/client → client}/utils/mixins.js +0 -28
  60. package/lib/client/utils/spacerUtils.d.ts +18 -0
  61. package/lib/client/utils/spacerUtils.js +32 -0
  62. package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
  63. package/lib/collaboration/DatalayerCollaboration.js +2 -2
  64. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
  65. package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
  66. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  67. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  68. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  69. package/lib/components/runtimes/RuntimeLauncherDialog.js +2 -2
  70. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  71. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  72. package/lib/components/runtimes/RuntimePickerCell.js +3 -3
  73. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  74. package/lib/components/runtimes/RuntimePickerNotebook.js +2 -2
  75. package/lib/components/runtimes/RuntimeTransfer.d.ts +2 -2
  76. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  77. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  78. package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
  79. package/lib/config/Configuration.d.ts +8 -0
  80. package/lib/hooks/useDatalayer.js +1 -1
  81. package/lib/hooks/useRuntimes.js +1 -1
  82. package/lib/hooks/useToast.js +1 -1
  83. package/lib/index.d.ts +2 -3
  84. package/lib/index.js +4 -3
  85. package/lib/models/Common.d.ts +64 -0
  86. package/lib/models/CreditsDTO.d.ts +124 -0
  87. package/lib/models/CreditsDTO.js +135 -0
  88. package/lib/models/Environment.d.ts +1 -1
  89. package/lib/models/EnvironmentDTO.d.ts +125 -0
  90. package/lib/models/EnvironmentDTO.js +88 -0
  91. package/lib/models/HealthCheck.d.ts +72 -0
  92. package/lib/models/HealthCheck.js +107 -0
  93. package/lib/{api/types/iam.d.ts → models/IAM.d.ts} +15 -78
  94. package/lib/models/ItemDTO.d.ts +74 -0
  95. package/lib/models/ItemDTO.js +186 -0
  96. package/lib/models/LexicalDTO.d.ts +155 -0
  97. package/lib/models/LexicalDTO.js +157 -0
  98. package/lib/models/NotebookDTO.d.ts +96 -0
  99. package/lib/models/NotebookDTO.js +153 -0
  100. package/lib/models/Profile.d.ts +65 -0
  101. package/lib/models/RuntimeDTO.d.ts +191 -0
  102. package/lib/models/RuntimeDTO.js +204 -0
  103. package/lib/models/RuntimeSnapshotDTO.d.ts +173 -0
  104. package/lib/models/RuntimeSnapshotDTO.js +139 -0
  105. package/lib/models/SpaceDTO.d.ts +280 -0
  106. package/lib/models/SpaceDTO.js +239 -0
  107. package/lib/models/UserDTO.d.ts +86 -0
  108. package/lib/models/UserDTO.js +84 -0
  109. package/lib/models/index.d.ts +45 -4
  110. package/lib/models/index.js +45 -4
  111. package/lib/sdk/index.d.ts +5 -4
  112. package/lib/sdk/index.js +6 -5
  113. package/lib/services/DatalayerServiceManager.js +1 -1
  114. package/lib/state/substates/CoreState.js +2 -0
  115. package/lib/state/substates/RuntimesState.d.ts +1 -1
  116. package/lib/state/substates/RuntimesState.js +1 -1
  117. package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
  118. package/lib/{sdk/stateful → stateful}/index.js +1 -1
  119. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
  120. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
  121. package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
  122. package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
  123. package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
  124. package/package.json +13 -10
  125. package/lib/__tests__/hooks.test.d.ts +0 -1
  126. package/lib/__tests__/hooks.test.js +0 -19
  127. package/lib/__tests__/index.test.d.ts +0 -1
  128. package/lib/__tests__/index.test.js +0 -27
  129. package/lib/__tests__/integration.test.d.ts +0 -1
  130. package/lib/__tests__/integration.test.js +0 -57
  131. package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
  132. package/lib/__tests__/shared/cleanup-shared.js +0 -228
  133. package/lib/__tests__/shared/test-config.d.ts +0 -51
  134. package/lib/__tests__/shared/test-config.js +0 -110
  135. package/lib/__tests__/shared/test-constants.d.ts +0 -66
  136. package/lib/__tests__/shared/test-constants.js +0 -79
  137. package/lib/__tests__/utils.test.d.ts +0 -1
  138. package/lib/__tests__/utils.test.js +0 -59
  139. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
  140. package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
  141. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
  142. package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
  143. package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
  144. package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
  145. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
  146. package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
  147. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
  148. package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
  149. package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
  150. package/lib/api/__tests__/runtimes.integration.test.js +0 -369
  151. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
  152. package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
  153. package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
  154. package/lib/api/__tests__/spacer.integration.test.js +0 -519
  155. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
  156. package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
  157. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
  158. package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
  159. package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
  160. package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
  161. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
  162. package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
  163. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
  164. package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
  165. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
  166. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
  167. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
  168. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
  169. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
  170. package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
  171. package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
  172. package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
  173. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
  174. package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
  175. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
  176. package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
  177. package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
  178. package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
  179. package/lib/api/types/index.d.ts +0 -32
  180. package/lib/api/types/index.js +0 -36
  181. package/lib/api/types/runtimes.d.ts +0 -235
  182. package/lib/api/types/spacer.d.ts +0 -271
  183. package/lib/api/types/spacer.js +0 -5
  184. package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
  185. package/lib/api/utils/__tests__/validation.test.js +0 -109
  186. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
  187. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
  188. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
  189. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
  190. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
  191. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
  192. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
  193. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
  194. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
  195. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
  196. package/lib/sdk/client/base.d.ts +0 -88
  197. package/lib/sdk/client/base.js +0 -112
  198. package/lib/sdk/client/index.d.ts +0 -192
  199. package/lib/sdk/client/index.js +0 -128
  200. package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
  201. package/lib/sdk/client/mixins/HealthMixin.js +0 -133
  202. package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
  203. package/lib/sdk/client/mixins/IAMMixin.js +0 -83
  204. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
  205. package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
  206. package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
  207. package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
  208. package/lib/sdk/client/models/Lexical.d.ts +0 -156
  209. package/lib/sdk/client/models/Lexical.js +0 -275
  210. package/lib/sdk/client/models/Notebook.d.ts +0 -174
  211. package/lib/sdk/client/models/Notebook.js +0 -311
  212. package/lib/sdk/client/models/Runtime.d.ts +0 -221
  213. package/lib/sdk/client/models/Runtime.js +0 -341
  214. package/lib/sdk/client/models/Snapshot.d.ts +0 -156
  215. package/lib/sdk/client/models/Snapshot.js +0 -244
  216. package/lib/sdk/client/models/Space.d.ts +0 -182
  217. package/lib/sdk/client/models/Space.js +0 -276
  218. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
  219. package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
  220. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
  221. package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
  222. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
  223. package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
  224. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
  225. package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
  226. package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
  227. package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
  228. package/lib/sdk/client/models/index.d.ts +0 -30
  229. package/lib/sdk/client/models/index.js +0 -30
  230. package/lib/sdk/client/utils/mixins.d.ts +0 -42
  231. /package/lib/{api/types/iam.js → models/Common.js} +0 -0
  232. /package/lib/{api/types/runtimes.js → models/IAM.js} +0 -0
  233. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
  234. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
  235. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
  236. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
  237. /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
  238. /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
  239. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
  240. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
  241. /package/lib/{sdk/stateful → stateful}/runtimes/apis.js +0 -0
  242. /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
  243. /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
  244. /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
  245. /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
  246. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
  247. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
  248. /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
  249. /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
@@ -0,0 +1,186 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import * as items from '../api/spacer/items';
6
+ /**
7
+ * Abstract base class for all Datalayer content items.
8
+ * Provides common functionality for content management including lifecycle tracking.
9
+ *
10
+ * @template TData - Raw data type from API
11
+ * @template TUpdateRequest - Update request type for API
12
+ */
13
+ export class ItemDTO {
14
+ _data;
15
+ _sdk;
16
+ _deleted = false;
17
+ /**
18
+ * Create an Item instance.
19
+ * @param data - Item data from API
20
+ * @param sdk - SDK instance
21
+ */
22
+ constructor(data, sdk) {
23
+ this._data = data;
24
+ this._sdk = sdk;
25
+ }
26
+ // ========================================================================
27
+ // Deletion State Management
28
+ // ========================================================================
29
+ /** Check if this item has been deleted. */
30
+ get isDeleted() {
31
+ return this._deleted;
32
+ }
33
+ /**
34
+ * Check if this item has been deleted and throw error if so.
35
+ * @throws Error if deleted
36
+ */
37
+ _checkDeleted() {
38
+ if (this._deleted) {
39
+ throw new Error(`${this.constructor.name} ${this._data.id} has been deleted and no longer exists`);
40
+ }
41
+ }
42
+ // ========================================================================
43
+ // Static Properties (set at creation, never change)
44
+ // ========================================================================
45
+ /** Item ID. */
46
+ get id() {
47
+ this._checkDeleted();
48
+ return this._data.id;
49
+ }
50
+ /** Unique identifier for the item. */
51
+ get uid() {
52
+ this._checkDeleted();
53
+ return this._data.uid;
54
+ }
55
+ /** Parent space ID. */
56
+ get spaceId() {
57
+ this._checkDeleted();
58
+ // Try the direct field first (if API provides it)
59
+ if (this._data.space_id) {
60
+ return this._data.space_id;
61
+ }
62
+ // Extract from s3_path_s if available: "datalayer.app/SPACE_ID/..."
63
+ const s3Path = this._data.s3_path_s;
64
+ if (s3Path && typeof s3Path === 'string') {
65
+ const match = s3Path.match(/^datalayer\.app\/([^/]+)\//);
66
+ if (match) {
67
+ return match[1];
68
+ }
69
+ }
70
+ // Fallback to empty string if no space ID can be determined
71
+ return '';
72
+ }
73
+ /** Owner user ID. */
74
+ get ownerId() {
75
+ this._checkDeleted();
76
+ return (this._data.owner_id || this._data.creator_uid || '');
77
+ }
78
+ /** When the item was created. */
79
+ get createdAt() {
80
+ this._checkDeleted();
81
+ const dateStr = this._data.creation_ts_dt || this._data.created_at;
82
+ if (!dateStr) {
83
+ throw new Error(`No creation timestamp available for ${this.constructor.name.toLowerCase()}`);
84
+ }
85
+ return new Date(dateStr);
86
+ }
87
+ /** The cached update time. */
88
+ get updatedAt() {
89
+ this._checkDeleted();
90
+ const dateStr = this._data.last_update_ts_dt ||
91
+ this._data.updated_at ||
92
+ this._data.creation_ts_dt ||
93
+ this._data.created_at;
94
+ if (!dateStr) {
95
+ throw new Error(`No update timestamp available for ${this.constructor.name.toLowerCase()}`);
96
+ }
97
+ return new Date(dateStr);
98
+ }
99
+ // ========================================================================
100
+ // Action Methods
101
+ // ========================================================================
102
+ /**
103
+ * Delete this item permanently.
104
+ * After deletion, all subsequent method calls will throw errors.
105
+ */
106
+ async delete() {
107
+ this._checkDeleted();
108
+ const token = this._sdk.getToken();
109
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
110
+ await items.deleteItem(token, this.uid, spacerRunUrl);
111
+ this._deleted = true;
112
+ }
113
+ /** Get the document content from API. */
114
+ async getContent() {
115
+ this._checkDeleted();
116
+ // First try: CDN URL (fastest)
117
+ const cdnUrl = this._data.cdn_url_s;
118
+ if (cdnUrl) {
119
+ try {
120
+ const response = await fetch(cdnUrl);
121
+ if (!response.ok) {
122
+ throw new Error('Failed to fetch content from CDN');
123
+ }
124
+ const data = await response.json();
125
+ if (data.content !== undefined && data.content !== null) {
126
+ return data.content;
127
+ }
128
+ }
129
+ catch (error) {
130
+ console.error('Error fetching content from CDN:', error);
131
+ }
132
+ }
133
+ // Second try: Check if content is already loaded
134
+ const cachedContent = this.content;
135
+ if (cachedContent !== undefined && cachedContent !== null) {
136
+ return cachedContent;
137
+ }
138
+ // Third try: Fetch full item details from API
139
+ try {
140
+ const token = this._sdk.getToken();
141
+ const spacerRunUrl = this._sdk.getSpacerRunUrl();
142
+ const response = await items.getItem(token, this.uid, spacerRunUrl);
143
+ // Update internal data with full item details
144
+ if (response.success && response.item) {
145
+ this._data = response.item;
146
+ const freshContent = this.content;
147
+ if (freshContent !== undefined && freshContent !== null) {
148
+ return freshContent;
149
+ }
150
+ }
151
+ }
152
+ catch (error) {
153
+ console.error('Error fetching full item details:', error);
154
+ }
155
+ 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.`);
156
+ }
157
+ // ========================================================================
158
+ // Utility Methods
159
+ // ========================================================================
160
+ /** Get raw item data object. */
161
+ rawData() {
162
+ this._checkDeleted();
163
+ return this._data;
164
+ }
165
+ /** String representation of the item. */
166
+ toString() {
167
+ this._checkDeleted();
168
+ const name = this.name || 'Unnamed';
169
+ return `${this.constructor.name}(${this.id}, ${name})`;
170
+ }
171
+ // ========================================================================
172
+ // Protected Helper Methods
173
+ // ========================================================================
174
+ /** Get SDK token for API calls. */
175
+ _getToken() {
176
+ return this._sdk.getToken();
177
+ }
178
+ /** Get spacer API URL for API calls. */
179
+ _getSpacerRunUrl() {
180
+ return this._sdk.getSpacerRunUrl();
181
+ }
182
+ /** Update internal data after API call. */
183
+ _updateData(newData) {
184
+ this._data = newData;
185
+ }
186
+ }
@@ -0,0 +1,155 @@
1
+ import type { DatalayerClient } from '../index';
2
+ import { ItemDTO } from './ItemDTO';
3
+ /**
4
+ * Represents a Lexical document (rich text editor)
5
+ * @interface Lexical
6
+ */
7
+ export interface LexicalData {
8
+ id: string;
9
+ uid: string;
10
+ name?: string;
11
+ name_t?: string;
12
+ content?: any;
13
+ space_id?: string;
14
+ owner_id?: string;
15
+ creator_uid?: string;
16
+ creator_handle_s?: string;
17
+ created_at?: string;
18
+ creation_ts_dt?: string;
19
+ updated_at?: string;
20
+ last_update_ts_dt?: string;
21
+ cdn_url_s: string;
22
+ type_s?: string;
23
+ public_b?: boolean;
24
+ description_t?: string;
25
+ document_name_s?: string;
26
+ document_extension_s: string;
27
+ document_format_s?: string;
28
+ content_length_i?: number;
29
+ content_type_s?: string;
30
+ mime_type_s?: string;
31
+ s3_path_s?: string;
32
+ s3_url_s?: string;
33
+ model_s?: string;
34
+ }
35
+ /**
36
+ * Request payload for creating a Lexical document
37
+ * @interface CreateLexicalRequest
38
+ */
39
+ export interface CreateLexicalRequest {
40
+ spaceId: string;
41
+ documentType: string;
42
+ name: string;
43
+ description: string;
44
+ file?: File | Blob;
45
+ }
46
+ /**
47
+ * Response from creating a Lexical document
48
+ * @interface CreateLexicalResponse
49
+ */
50
+ export interface CreateLexicalResponse {
51
+ success: boolean;
52
+ message: string;
53
+ document?: LexicalData;
54
+ }
55
+ /**
56
+ * Response from getting a Lexical document
57
+ * @interface GetLexicalResponse
58
+ */
59
+ export interface GetLexicalResponse {
60
+ success: boolean;
61
+ message: string;
62
+ document?: LexicalData;
63
+ }
64
+ /**
65
+ * Request payload for updating a Lexical document
66
+ * @interface UpdateLexicalRequest
67
+ */
68
+ export interface UpdateLexicalRequest {
69
+ name?: string;
70
+ description?: string;
71
+ }
72
+ /**
73
+ * Response from updating a Lexical document
74
+ * @interface UpdateLexicalResponse
75
+ */
76
+ export interface UpdateLexicalResponse {
77
+ success: boolean;
78
+ message: string;
79
+ document: LexicalData;
80
+ }
81
+ /**
82
+ * Stable public interface for Lexical data.
83
+ * This is the contract that SDK consumers can rely on.
84
+ * The raw API may change, but this interface remains stable.
85
+ */
86
+ export interface LexicalJSON {
87
+ /** Unique identifier for the lexical document */
88
+ uid: string;
89
+ /** Unique identifier for the lexical document */
90
+ id: string;
91
+ /** Name of the lexical document */
92
+ name: string;
93
+ /** Description of the lexical document */
94
+ description: string;
95
+ /** Type of lexical document */
96
+ type: string;
97
+ /** File extension of the lexical document */
98
+ extension: string;
99
+ /** ISO 8601 timestamp when the document was created */
100
+ createdAt: string;
101
+ /** ISO 8601 timestamp when the document was last updated */
102
+ updatedAt: string;
103
+ /** CDN URL for accessing the document */
104
+ cdnUrl: string;
105
+ }
106
+ /**
107
+ * Lexical domain model that extends the base Item class.
108
+ * Provides lexical document functionality for managing rich text documents.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const lexical = await sdk.createLexical(formData);
113
+ * await lexical.update({ name: 'Updated Documentation' });
114
+ * ```
115
+ */
116
+ export declare class LexicalDTO extends ItemDTO<LexicalData> {
117
+ /**
118
+ * Create a Lexical instance.
119
+ *
120
+ * @param data - Lexical data from API
121
+ * @param sdk - SDK instance
122
+ */
123
+ constructor(data: LexicalData, sdk: DatalayerClient);
124
+ /** Document type identifier. */
125
+ get type(): string;
126
+ /** The cached name of the document. */
127
+ get name(): string;
128
+ /** Get the current name of the document from API. */
129
+ getName(): Promise<string>;
130
+ /** The cached content. */
131
+ get content(): any;
132
+ /** Description of the lexical document. */
133
+ get description(): string;
134
+ /** Get the document extension. */
135
+ get extension(): string;
136
+ /** Get when the document was last updated from API. */
137
+ getUpdatedAt(): Promise<Date>;
138
+ /** Update the document. */
139
+ update(name?: string, description?: string): Promise<this>;
140
+ /**
141
+ * Get lexical document data in camelCase format.
142
+ * Returns only the core fields that consumers need.
143
+ * This provides a stable interface regardless of API changes.
144
+ *
145
+ * @returns Core lexical data with camelCase properties
146
+ */
147
+ toJSON(): LexicalJSON;
148
+ /**
149
+ * Get the raw lexical data exactly as received from the API.
150
+ * This preserves the original snake_case naming from the API response.
151
+ *
152
+ * @returns Raw lexical data from API
153
+ */
154
+ rawData(): LexicalData;
155
+ }
@@ -0,0 +1,157 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * Lexical domain model for the Datalayer SDK.
7
+ *
8
+ * @module models/LexicalDTO
9
+ */
10
+ import * as lexicals from '../api/spacer/lexicals';
11
+ import { ItemTypes } from '../client';
12
+ import { ItemDTO } from './ItemDTO';
13
+ import { validateJSON } from '../api/utils/validation';
14
+ /**
15
+ * Lexical domain model that extends the base Item class.
16
+ * Provides lexical document functionality for managing rich text documents.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const lexical = await sdk.createLexical(formData);
21
+ * await lexical.update({ name: 'Updated Documentation' });
22
+ * ```
23
+ */
24
+ export class LexicalDTO extends ItemDTO {
25
+ /**
26
+ * Create a Lexical instance.
27
+ *
28
+ * @param data - Lexical data from API
29
+ * @param sdk - SDK instance
30
+ */
31
+ constructor(data, sdk) {
32
+ super(data, sdk);
33
+ }
34
+ // ========================================================================
35
+ // Abstract Method Implementations
36
+ // ========================================================================
37
+ /** Document type identifier. */
38
+ get type() {
39
+ this._checkDeleted();
40
+ return ItemTypes.LEXICAL;
41
+ }
42
+ /** The cached name of the document. */
43
+ get name() {
44
+ this._checkDeleted();
45
+ return this._data.name_t || this._data.name || '';
46
+ }
47
+ /** Get the current name of the document from API. */
48
+ async getName() {
49
+ this._checkDeleted();
50
+ const token = this._getToken();
51
+ const spacerRunUrl = this._getSpacerRunUrl();
52
+ const response = await lexicals.getLexical(token, this.uid, spacerRunUrl);
53
+ if (response.document) {
54
+ this._updateData(response.document);
55
+ return response.document.name_t || response.document.name || '';
56
+ }
57
+ return this.name;
58
+ }
59
+ /** The cached content. */
60
+ get content() {
61
+ this._checkDeleted();
62
+ if (!this._data.content && this._data.model_s) {
63
+ try {
64
+ return JSON.parse(this._data.model_s);
65
+ }
66
+ catch {
67
+ return this._data.model_s;
68
+ }
69
+ }
70
+ return this._data.content;
71
+ }
72
+ /** Description of the lexical document. */
73
+ get description() {
74
+ this._checkDeleted();
75
+ return this._data.description_t || '';
76
+ }
77
+ /** Get the document extension. */
78
+ get extension() {
79
+ this._checkDeleted();
80
+ const ext = this._data.document_extension_s;
81
+ return ext ? (ext.startsWith('.') ? ext : `.${ext}`) : '.lexical';
82
+ }
83
+ /** Get when the document was last updated from API. */
84
+ async getUpdatedAt() {
85
+ this._checkDeleted();
86
+ const token = this._getToken();
87
+ const spacerRunUrl = this._getSpacerRunUrl();
88
+ const response = await lexicals.getLexical(token, this.uid, spacerRunUrl);
89
+ if (response.document) {
90
+ this._updateData(response.document);
91
+ const dateStr = response.document.last_update_ts_dt ||
92
+ response.document.updated_at ||
93
+ response.document.creation_ts_dt ||
94
+ response.document.created_at;
95
+ if (!dateStr) {
96
+ throw new Error('No timestamp available for lexical document');
97
+ }
98
+ return new Date(dateStr);
99
+ }
100
+ const dateStr = this._data.last_update_ts_dt ||
101
+ this._data.updated_at ||
102
+ this._data.creation_ts_dt ||
103
+ this._data.created_at;
104
+ if (!dateStr) {
105
+ throw new Error('No timestamp available for lexical document');
106
+ }
107
+ return new Date(dateStr);
108
+ }
109
+ /** Update the document. */
110
+ async update(name, description) {
111
+ // FIXME: check if both are needed, and use the existing values if only one provided
112
+ this._checkDeleted();
113
+ const token = this._getToken();
114
+ const spacerRunUrl = this._getSpacerRunUrl();
115
+ const updateData = {};
116
+ if (name !== undefined)
117
+ updateData.name = name;
118
+ if (description !== undefined)
119
+ updateData.description = description;
120
+ const response = await lexicals.updateLexical(token, this.uid, updateData, spacerRunUrl);
121
+ this._updateData(response.document);
122
+ return this;
123
+ }
124
+ /**
125
+ * Get lexical document data in camelCase format.
126
+ * Returns only the core fields that consumers need.
127
+ * This provides a stable interface regardless of API changes.
128
+ *
129
+ * @returns Core lexical data with camelCase properties
130
+ */
131
+ toJSON() {
132
+ this._checkDeleted();
133
+ const obj = {
134
+ uid: this.uid,
135
+ id: this.id,
136
+ name: this.name,
137
+ description: this.description,
138
+ type: this.type,
139
+ extension: this.extension,
140
+ createdAt: this.createdAt.toDateString(),
141
+ updatedAt: this.updatedAt.toDateString(),
142
+ cdnUrl: this._data.cdn_url_s,
143
+ };
144
+ validateJSON(obj, 'Lexical');
145
+ return obj;
146
+ }
147
+ /**
148
+ * Get the raw lexical data exactly as received from the API.
149
+ * This preserves the original snake_case naming from the API response.
150
+ *
151
+ * @returns Raw lexical data from API
152
+ */
153
+ rawData() {
154
+ this._checkDeleted();
155
+ return this._data;
156
+ }
157
+ }
@@ -0,0 +1,96 @@
1
+ import type { DatalayerClient } from '../index';
2
+ import { ItemDTO } from './ItemDTO';
3
+ /**
4
+ * Represents a Jupyter notebook document
5
+ * @interface NotebookData
6
+ */
7
+ export interface NotebookData {
8
+ id: string;
9
+ uid: string;
10
+ name_t: string;
11
+ description_t: string;
12
+ type_s: string;
13
+ notebook_extension_s: string;
14
+ s3_path_s: string;
15
+ s3_url_s: string;
16
+ cdn_url_s: string;
17
+ }
18
+ /**
19
+ * Stable public interface for Notebook data.
20
+ * This is the contract that SDK consumers can rely on.
21
+ * The raw API may change, but this interface remains stable.
22
+ */
23
+ export interface NotebookJSON {
24
+ /** uuid of the notebook */
25
+ id: string;
26
+ /** ulid for of the notebook */
27
+ uid: string;
28
+ /** Name of the notebook */
29
+ name: string;
30
+ /** Description of the notebook */
31
+ description: string;
32
+ /** Type of notebook */
33
+ type: string;
34
+ /** File extension of the notebook */
35
+ extension: string;
36
+ /** CDN URL for accessing the notebook */
37
+ cdnUrl: string;
38
+ }
39
+ /**
40
+ * Notebook domain model that extends the base Item class.
41
+ * Provides notebook-specific functionality for managing Jupyter notebooks.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const notebook = await sdk.createNotebook(formData);
46
+ * const kernelSpec = await notebook.getKernelSpec();
47
+ * ```
48
+ */
49
+ export declare class NotebookDTO extends ItemDTO<NotebookData> {
50
+ /**
51
+ * Create a Notebook instance.
52
+ *
53
+ * @param data - Notebook data from API
54
+ * @param sdk - SDK instance
55
+ */
56
+ constructor(data: NotebookData, sdk: DatalayerClient);
57
+ /** Document type identifier. */
58
+ get type(): string;
59
+ /** The cached name of the notebook. */
60
+ get name(): string;
61
+ /** The cached content. */
62
+ get content(): any;
63
+ /** Get the current name from API. */
64
+ getName(): Promise<string>;
65
+ /** Get when the notebook was last updated from API. */
66
+ getUpdatedAt(): Promise<Date>;
67
+ /** Update the notebook. */
68
+ update(name?: string, description?: string): Promise<this>;
69
+ /** File path within the space. */
70
+ get path(): string;
71
+ /** Version number. */
72
+ get version(): number;
73
+ /** Notebook metadata. */
74
+ get metadata(): Record<string, any>;
75
+ /** Kernel specification (cached). */
76
+ get kernelSpec(): any;
77
+ /** Description of the notebook. */
78
+ get description(): string;
79
+ /** Get the notebook extension. */
80
+ get extension(): string;
81
+ /**
82
+ * Get notebook data in camelCase format.
83
+ * Returns only the core fields that consumers need.
84
+ * This provides a stable interface regardless of API changes.
85
+ *
86
+ * @returns Core notebook data with camelCase properties
87
+ */
88
+ toJSON(): NotebookJSON;
89
+ /**
90
+ * Get the raw notebook data exactly as received from the API.
91
+ * This preserves the original snake_case naming from the API response.
92
+ *
93
+ * @returns Raw notebook data from API
94
+ */
95
+ rawData(): NotebookData;
96
+ }