@datalayer/core 0.0.9 → 0.0.11

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 (199) hide show
  1. package/lib/__tests__/shared/cleanup-shared.d.ts +4 -0
  2. package/lib/__tests__/shared/cleanup-shared.js +228 -0
  3. package/lib/__tests__/shared/test-config.d.ts +51 -0
  4. package/lib/__tests__/shared/test-config.js +110 -0
  5. package/lib/__tests__/shared/test-constants.d.ts +66 -0
  6. package/lib/__tests__/shared/test-constants.js +79 -0
  7. package/lib/api/DatalayerApi.d.ts +1 -1
  8. package/lib/api/DatalayerApi.js +73 -42
  9. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +1 -0
  10. package/lib/api/__tests__/iam.authentication.integration.test.js +247 -0
  11. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +1 -0
  12. package/lib/api/__tests__/iam.healthz.integration.test.js +63 -0
  13. package/lib/api/__tests__/iam.profile.integration.test.d.ts +1 -0
  14. package/lib/api/__tests__/iam.profile.integration.test.js +252 -0
  15. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +1 -0
  16. package/lib/api/__tests__/runtimes.environments.integration.test.js +122 -0
  17. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +1 -0
  18. package/lib/api/__tests__/runtimes.healthz.integration.test.js +50 -0
  19. package/lib/api/__tests__/runtimes.integration.test.d.ts +1 -0
  20. package/lib/api/__tests__/runtimes.integration.test.js +369 -0
  21. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +1 -0
  22. package/lib/api/__tests__/spacer.healthz.integration.test.js +50 -0
  23. package/lib/api/__tests__/spacer.integration.test.d.ts +1 -0
  24. package/lib/api/__tests__/spacer.integration.test.js +519 -0
  25. package/lib/api/constants.d.ts +19 -0
  26. package/lib/api/constants.js +23 -0
  27. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +1 -0
  28. package/lib/api/iam/__tests__/authentication.unit.test.js +63 -0
  29. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +1 -0
  30. package/lib/api/iam/__tests__/healthz.unit.test.js +60 -0
  31. package/lib/api/iam/__tests__/profile.unit.test.d.ts +1 -0
  32. package/lib/api/iam/__tests__/profile.unit.test.js +57 -0
  33. package/lib/api/iam/authentication.d.ts +40 -0
  34. package/lib/api/iam/authentication.js +128 -0
  35. package/lib/api/iam/healthz.d.ts +15 -0
  36. package/lib/api/iam/healthz.js +43 -0
  37. package/lib/api/iam/index.d.ts +12 -0
  38. package/lib/api/iam/index.js +17 -0
  39. package/lib/api/iam/profile.d.ts +15 -0
  40. package/lib/api/iam/profile.js +41 -0
  41. package/lib/api/index.d.ts +20 -3
  42. package/lib/api/index.js +22 -3
  43. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +1 -0
  44. package/lib/api/runtimes/__tests__/environments.unit.test.js +77 -0
  45. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +1 -0
  46. package/lib/api/runtimes/__tests__/healthz.unit.test.js +57 -0
  47. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +1 -0
  48. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +139 -0
  49. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +1 -0
  50. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +96 -0
  51. package/lib/api/runtimes/environments.d.ts +9 -0
  52. package/lib/api/runtimes/environments.js +28 -0
  53. package/lib/api/runtimes/healthz.d.ts +25 -0
  54. package/lib/api/runtimes/healthz.js +43 -0
  55. package/lib/api/runtimes/index.d.ts +10 -5
  56. package/lib/api/runtimes/index.js +10 -5
  57. package/lib/api/runtimes/runtimes.d.ts +54 -0
  58. package/lib/api/runtimes/runtimes.js +169 -0
  59. package/lib/api/runtimes/snapshots.d.ts +34 -21
  60. package/lib/api/runtimes/snapshots.js +69 -138
  61. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +1 -0
  62. package/lib/api/spacer/__tests__/healthz.unit.test.js +57 -0
  63. package/lib/api/spacer/__tests__/items.unit.test.d.ts +1 -0
  64. package/lib/api/spacer/__tests__/items.unit.test.js +165 -0
  65. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +1 -0
  66. package/lib/api/spacer/__tests__/lexicals.unit.test.js +323 -0
  67. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +1 -0
  68. package/lib/api/spacer/__tests__/notebooks.unit.test.js +224 -0
  69. package/lib/api/spacer/__tests__/users.unit.test.d.ts +1 -0
  70. package/lib/api/spacer/__tests__/users.unit.test.js +132 -0
  71. package/lib/api/spacer/healthz.d.ts +25 -0
  72. package/lib/api/spacer/healthz.js +43 -0
  73. package/lib/api/spacer/index.d.ts +13 -0
  74. package/lib/api/spacer/index.js +17 -0
  75. package/lib/api/spacer/items.d.ts +17 -0
  76. package/lib/api/spacer/items.js +40 -0
  77. package/lib/api/spacer/lexicals.d.ts +26 -0
  78. package/lib/api/spacer/lexicals.js +74 -0
  79. package/lib/api/spacer/notebooks.d.ts +26 -0
  80. package/lib/api/spacer/notebooks.js +74 -0
  81. package/lib/api/spacer/spaces.d.ts +9 -0
  82. package/lib/api/spacer/spaces.js +29 -0
  83. package/lib/api/spacer/users.d.ts +9 -0
  84. package/lib/api/spacer/users.js +28 -0
  85. package/lib/api/types/iam.d.ts +180 -0
  86. package/lib/api/types/index.d.ts +32 -0
  87. package/lib/api/types/index.js +36 -0
  88. package/lib/api/types/runtimes.d.ts +235 -0
  89. package/lib/api/types/runtimes.js +5 -0
  90. package/lib/api/types/spacer.d.ts +271 -0
  91. package/lib/api/types/spacer.js +5 -0
  92. package/lib/api/utils/__tests__/validation.test.d.ts +1 -0
  93. package/lib/api/utils/__tests__/validation.test.js +109 -0
  94. package/lib/api/utils/validation.d.ts +24 -0
  95. package/lib/api/utils/validation.js +133 -0
  96. package/lib/components/display/JupyterDialog.js +4 -8
  97. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  98. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +2 -2
  99. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  100. package/lib/components/runtimes/RuntimeLauncherDialog.js +5 -2
  101. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  102. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  103. package/lib/components/runtimes/RuntimePickerCell.js +2 -1
  104. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  105. package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
  106. package/lib/components/runtimes/RuntimeSimplePicker.js +2 -1
  107. package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
  108. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  109. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  110. package/lib/components/snapshots/RuntimeSnapshotMenu.js +2 -2
  111. package/lib/components/snippets/SnippetDialog.js +1 -1
  112. package/lib/components/storage/ContentsBrowser.js +2 -2
  113. package/lib/components/tables/DataTable.js +2 -1
  114. package/lib/hooks/useDatalayer.d.ts +1 -1
  115. package/lib/hooks/useDatalayer.js +1 -1
  116. package/lib/hooks/useIAM.js +1 -1
  117. package/lib/hooks/useRuntimes.js +1 -1
  118. package/lib/index.d.ts +9 -0
  119. package/lib/index.js +10 -0
  120. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +1 -0
  121. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +110 -0
  122. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +1 -0
  123. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +179 -0
  124. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +1 -0
  125. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +376 -0
  126. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +1 -0
  127. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +276 -0
  128. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +1 -0
  129. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +361 -0
  130. package/lib/sdk/client/base.d.ts +88 -0
  131. package/lib/sdk/client/base.js +112 -0
  132. package/lib/sdk/client/index.d.ts +192 -0
  133. package/lib/sdk/client/index.js +128 -0
  134. package/lib/sdk/client/mixins/HealthMixin.d.ts +100 -0
  135. package/lib/sdk/client/mixins/HealthMixin.js +133 -0
  136. package/lib/sdk/client/mixins/IAMMixin.d.ts +59 -0
  137. package/lib/sdk/client/mixins/IAMMixin.js +83 -0
  138. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +134 -0
  139. package/lib/sdk/client/mixins/RuntimesMixin.js +221 -0
  140. package/lib/sdk/client/mixins/SpacerMixin.d.ts +184 -0
  141. package/lib/sdk/client/mixins/SpacerMixin.js +278 -0
  142. package/lib/sdk/client/models/Lexical.d.ts +156 -0
  143. package/lib/sdk/client/models/Lexical.js +275 -0
  144. package/lib/sdk/client/models/Notebook.d.ts +174 -0
  145. package/lib/sdk/client/models/Notebook.js +311 -0
  146. package/lib/sdk/client/models/Runtime.d.ts +221 -0
  147. package/lib/sdk/client/models/Runtime.js +341 -0
  148. package/lib/sdk/client/models/Snapshot.d.ts +156 -0
  149. package/lib/sdk/client/models/Snapshot.js +244 -0
  150. package/lib/sdk/client/models/Space.d.ts +182 -0
  151. package/lib/sdk/client/models/Space.js +276 -0
  152. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +1 -0
  153. package/lib/sdk/client/models/__tests__/Lexical.test.js +288 -0
  154. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +1 -0
  155. package/lib/sdk/client/models/__tests__/Notebook.test.js +206 -0
  156. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +1 -0
  157. package/lib/sdk/client/models/__tests__/Runtime.test.js +133 -0
  158. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +1 -0
  159. package/lib/sdk/client/models/__tests__/Snapshot.test.js +244 -0
  160. package/lib/sdk/client/models/__tests__/Space.test.d.ts +1 -0
  161. package/lib/sdk/client/models/__tests__/Space.test.js +334 -0
  162. package/lib/sdk/client/models/index.d.ts +30 -0
  163. package/lib/sdk/client/models/index.js +30 -0
  164. package/lib/sdk/client/utils/mixins.d.ts +42 -0
  165. package/lib/sdk/client/utils/mixins.js +47 -0
  166. package/lib/sdk/index.d.ts +26 -0
  167. package/lib/sdk/index.js +32 -0
  168. package/lib/sdk/stateful/index.d.ts +3 -0
  169. package/lib/sdk/stateful/index.js +7 -0
  170. package/lib/{api → sdk/stateful}/runtimes/actions.d.ts +1 -1
  171. package/lib/{api → sdk/stateful}/runtimes/actions.js +3 -3
  172. package/lib/{api → sdk/stateful}/runtimes/apis.d.ts +1 -1
  173. package/lib/sdk/stateful/runtimes/apis.js +5 -0
  174. package/lib/sdk/stateful/runtimes/index.d.ts +5 -0
  175. package/lib/sdk/stateful/runtimes/index.js +9 -0
  176. package/lib/sdk/stateful/runtimes/snapshots.d.ts +25 -0
  177. package/lib/sdk/stateful/runtimes/snapshots.js +150 -0
  178. package/lib/services/DatalayerServiceManager.js +1 -1
  179. package/lib/state/substates/IAMState.js +1 -1
  180. package/lib/state/substates/RuntimesState.d.ts +1 -1
  181. package/lib/state/substates/RuntimesState.js +1 -1
  182. package/lib/state/substates/SurveysState.js +1 -1
  183. package/lib/test-setup.js +1 -0
  184. package/package.json +19 -9
  185. /package/lib/api/{runtimes/apis.js → types/iam.js} +0 -0
  186. /package/lib/{api → sdk/stateful}/jupyter/exec/Python.d.ts +0 -0
  187. /package/lib/{api → sdk/stateful}/jupyter/exec/Python.js +0 -0
  188. /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.d.ts +0 -0
  189. /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.js +0 -0
  190. /package/lib/{api → sdk/stateful}/jupyter/exec/index.d.ts +0 -0
  191. /package/lib/{api → sdk/stateful}/jupyter/exec/index.js +0 -0
  192. /package/lib/{api → sdk/stateful}/jupyter/index.d.ts +0 -0
  193. /package/lib/{api → sdk/stateful}/jupyter/index.js +0 -0
  194. /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.d.ts +0 -0
  195. /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.js +0 -0
  196. /package/lib/{api → sdk/stateful}/runtimes/settings.d.ts +0 -0
  197. /package/lib/{api → sdk/stateful}/runtimes/settings.js +0 -0
  198. /package/lib/{api → sdk/stateful}/runtimes/utils.d.ts +0 -0
  199. /package/lib/{api → sdk/stateful}/runtimes/utils.js +0 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @module sdk/client/utils/mixins
3
+ * @description TypeScript mixin utilities for composing the DatalayerSDK class.
4
+ */
5
+ /**
6
+ * Type for a constructor function that can be used in mixins.
7
+ */
8
+ export type Constructor<T = {}> = new (...args: any[]) => T;
9
+ /**
10
+ * Apply mixins to a base class.
11
+ *
12
+ * This utility function enables multiple inheritance-like behavior in TypeScript
13
+ * by copying properties and methods from mixin classes to the target class.
14
+ *
15
+ * @param derivedCtor - The base class to extend
16
+ * @param constructors - Array of mixin classes to apply
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * class Base {
21
+ * baseMethod() { return 'base'; }
22
+ * }
23
+ *
24
+ * class MixinA {
25
+ * mixinAMethod() { return 'A'; }
26
+ * }
27
+ *
28
+ * class MixinB {
29
+ * mixinBMethod() { return 'B'; }
30
+ * }
31
+ *
32
+ * interface Combined extends Base, MixinA, MixinB {}
33
+ * class Combined extends Base {}
34
+ * applyMixins(Combined, [MixinA, MixinB]);
35
+ *
36
+ * const instance = new Combined();
37
+ * instance.baseMethod(); // 'base'
38
+ * instance.mixinAMethod(); // 'A'
39
+ * instance.mixinBMethod(); // 'B'
40
+ * ```
41
+ */
42
+ export declare function applyMixins(derivedCtor: any, constructors: any[]): void;
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
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
+ * @param derivedCtor - The base class to extend
12
+ * @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
+ */
38
+ export function applyMixins(derivedCtor, constructors) {
39
+ constructors.forEach(baseCtor => {
40
+ Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
41
+ if (name !== 'constructor') {
42
+ Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
43
+ Object.create(null));
44
+ }
45
+ });
46
+ });
47
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module sdk
3
+ * @description Main SDK entry point for the Datalayer platform.
4
+ *
5
+ * This module provides the unified DatalayerSDK class with a flat, intuitive API
6
+ * for all Datalayer platform services. The SDK uses TypeScript mixins to provide
7
+ * excellent discoverability and ease of use.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { DatalayerSDK } from '@datalayer/core/sdk';
12
+ *
13
+ * const sdk = new DatalayerSDK({
14
+ * token: 'your-api-token',
15
+ * baseUrl: 'https://prod1.datalayer.run'
16
+ * });
17
+ *
18
+ * // Flat, intuitive API - all methods directly accessible
19
+ * const user = await sdk.whoami();
20
+ * const environments = await sdk.listEnvironments();
21
+ * const runtime = await sdk.createRuntime(config);
22
+ * const notebook = await sdk.createNotebook(data);
23
+ * ```
24
+ */
25
+ export { DatalayerSDK, type DatalayerSDKConfig } from './client';
26
+ export * from './stateful';
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module sdk
7
+ * @description Main SDK entry point for the Datalayer platform.
8
+ *
9
+ * This module provides the unified DatalayerSDK class with a flat, intuitive API
10
+ * for all Datalayer platform services. The SDK uses TypeScript mixins to provide
11
+ * excellent discoverability and ease of use.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { DatalayerSDK } from '@datalayer/core/sdk';
16
+ *
17
+ * const sdk = new DatalayerSDK({
18
+ * token: 'your-api-token',
19
+ * baseUrl: 'https://prod1.datalayer.run'
20
+ * });
21
+ *
22
+ * // Flat, intuitive API - all methods directly accessible
23
+ * const user = await sdk.whoami();
24
+ * const environments = await sdk.listEnvironments();
25
+ * const runtime = await sdk.createRuntime(config);
26
+ * const notebook = await sdk.createNotebook(data);
27
+ * ```
28
+ */
29
+ // Export the main SDK class with flat API
30
+ export { DatalayerSDK } from './client';
31
+ // Export stateful modules for advanced use cases
32
+ export * from './stateful';
@@ -0,0 +1,3 @@
1
+ export * from './jupyter';
2
+ export * from './runtimes';
3
+ export * from '../../api/DatalayerApi';
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ export * from './jupyter';
6
+ export * from './runtimes';
7
+ export * from '../../api/DatalayerApi';
@@ -1,5 +1,5 @@
1
1
  import { IRuntimeOptions } from '..';
2
- import type { IRuntimeSnapshot, IDatalayerEnvironment, IRuntimePod } from '../../models';
2
+ import type { IRuntimeSnapshot, IDatalayerEnvironment, IRuntimePod } from '../../../models';
3
3
  /**
4
4
  * Get available Environments.
5
5
  */
@@ -9,9 +9,9 @@ import { URLExt } from '@jupyterlab/coreutils';
9
9
  import { PromiseDelegate } from '@lumino/coreutils';
10
10
  import { Upload } from 'tus-js-client';
11
11
  import { requestDatalayerAPI, } from '..';
12
- import { asRuntimeSnapshot } from '../../models';
13
- import { iamStore, runtimesStore } from '../../state';
14
- import { sleep } from '../../utils';
12
+ import { asRuntimeSnapshot } from '../../../models';
13
+ import { iamStore, runtimesStore } from '../../../state';
14
+ import { sleep } from '../../../utils';
15
15
  /**
16
16
  * Get available Environments.
17
17
  */
@@ -5,7 +5,7 @@ import { ISessionContext } from '@jupyterlab/apputils';
5
5
  import { ServiceManager, Kernel, ServerConnection } from '@jupyterlab/services';
6
6
  import { IDisposable } from '@lumino/disposable';
7
7
  import { ISignal } from '@lumino/signaling';
8
- import type { IRuntimeSnapshot, IRuntimeCapabilities, IRuntimeModel, IDatalayerEnvironment, IRuntimeType, IRuntimeLocation } from '../../models';
8
+ import type { IRuntimeSnapshot, IRuntimeCapabilities, IRuntimeModel, IDatalayerEnvironment, IRuntimeType, IRuntimeLocation } from '../../../models';
9
9
  /**
10
10
  * Abstract interface for the Datalayer session context.
11
11
  * It extends the JupyterLab session context
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './actions';
2
+ export * from './apis';
3
+ export * from './settings';
4
+ export * from './snapshots';
5
+ export * from './utils';
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ export * from './actions';
6
+ export * from './apis';
7
+ export * from './settings';
8
+ export * from './snapshots';
9
+ export * from './utils';
@@ -0,0 +1,25 @@
1
+ import { Kernel } from '@jupyterlab/services';
2
+ type Props = {
3
+ connection: Kernel.IKernelConnection;
4
+ metadata: {
5
+ filename: string;
6
+ [key: string]: string;
7
+ };
8
+ onUploadProgress?: (bytesUploaded: number, bytesTotal: number) => void;
9
+ };
10
+ /**
11
+ * Snapshot a runtime through the frontend and upload it to the cloud.
12
+ *
13
+ * Note: You should use this only for browser runtimes.
14
+ */
15
+ export declare function createRuntimeSnapshot(props: Props): Promise<void>;
16
+ /**
17
+ * Load a snapshot within a browser kernel.
18
+ *
19
+ * Note: You should use this only for browser kernels.
20
+ */
21
+ export declare function loadBrowserRuntimeSnapshot({ connection, id, }: {
22
+ connection: Kernel.IKernelConnection;
23
+ id: string;
24
+ }): Promise<void>;
25
+ export {};
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { KernelExecutor } from '@datalayer/jupyter-react';
6
+ import { createRuntimeSnapshotDownloadURL, uploadRuntimeSnapshot } from '.';
7
+ /**
8
+ * Snapshot a runtime through the frontend and upload it to the cloud.
9
+ *
10
+ * Note: You should use this only for browser runtimes.
11
+ */
12
+ export async function createRuntimeSnapshot(props) {
13
+ const { connection, metadata, onUploadProgress } = props;
14
+ const dump = await new KernelExecutor({ connection }).execute(GET_RUNTIME_SNAPSHOT_SNIPPET, {
15
+ storeHistory: false,
16
+ });
17
+ const serializedData = (dump.get(0)?.data['application/vnd.jupyter.stdout'] ??
18
+ '');
19
+ // Convert the data to blob.
20
+ const bytes = base64ToBytes(serializedData);
21
+ const file = new Blob([bytes.buffer]);
22
+ return uploadRuntimeSnapshot({
23
+ file,
24
+ metadata,
25
+ onProgress: onUploadProgress,
26
+ });
27
+ }
28
+ function base64ToBytes(base64) {
29
+ // Taken from https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa#unicode_strings
30
+ const binString = atob(base64);
31
+ // @ts-expect-error TypeScript does not like this
32
+ return Uint8Array.from(binString, m => m.codePointAt(0));
33
+ }
34
+ /**
35
+ * Load a snapshot within a browser kernel.
36
+ *
37
+ * Note: You should use this only for browser kernels.
38
+ */
39
+ export async function loadBrowserRuntimeSnapshot({ connection, id, }) {
40
+ const downloadURL = createRuntimeSnapshotDownloadURL(id);
41
+ const response = await fetch(downloadURL);
42
+ const buffer = await response.arrayBuffer();
43
+ const base64 = bytesToBase64(new Uint8Array(buffer));
44
+ await new KernelExecutor({
45
+ connection,
46
+ }).execute(getLoadRuntimeSnapshotSnippet(base64), {
47
+ storeHistory: false,
48
+ silent: true,
49
+ });
50
+ }
51
+ function bytesToBase64(bytes) {
52
+ // Taken from https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa#unicode_strings
53
+ const binString = Array.from(bytes, byte => String.fromCodePoint(byte)).join('');
54
+ return btoa(binString);
55
+ }
56
+ const GET_RUNTIME_SNAPSHOT_SNIPPET = `def _create_snapshot():
57
+ import logging
58
+ import os
59
+ import pickle
60
+ from base64 import encodebytes
61
+ from tempfile import TemporaryFile
62
+ from types import BuiltinFunctionType, BuiltinMethodType, FunctionType, MethodType, MethodWrapperType, ModuleType, TracebackType
63
+
64
+ # print(pickle.DEFAULT_PROTOCOL)
65
+
66
+ class NotFound:
67
+ pass
68
+
69
+ missing = NotFound()
70
+
71
+ FORBIDDEN_TYPES = [type, BuiltinFunctionType, BuiltinMethodType, FunctionType, MethodType, MethodWrapperType, ModuleType, TracebackType, NotFound]
72
+ try:
73
+ from IPython.core.autocall import ExitAutocall
74
+ from IPython.core.interactiveshell import InteractiveShell
75
+ FORBIDDEN_TYPES.extend([ExitAutocall, InteractiveShell])
76
+ except ImportError:
77
+ pass
78
+ exclude = tuple(FORBIDDEN_TYPES)
79
+
80
+ all = frozenset(filter(lambda n: not n.startswith("_"), globals()))
81
+
82
+ line_separator = bytes(os.linesep, "utf-8")
83
+ with TemporaryFile() as dump:
84
+ for _n in all:
85
+ _v = globals().get(_n, missing)
86
+
87
+ if not (
88
+ isinstance(_v, exclude) or
89
+ # Special IPython variables
90
+ (_n == "In" and isinstance(_v, list)) or
91
+ (_n == "Out" and isinstance(_v, dict))
92
+ ):
93
+ try:
94
+ dumped_n = _n.encode("utf-8") + line_separator + pickle.dumps(_v) + line_separator + b"\\x00" + line_separator
95
+ dump.write(dumped_n)
96
+ except BaseException as e:
97
+ logging.warning("Failed to dump variable [%s ([%s])].", _n, type(_v).__qualname__, exc_info=e)
98
+ else:
99
+ logging.debug("Variable [%s] dumped", _n)
100
+
101
+ dump.seek(0)
102
+ print(encodebytes(dump.read()).decode("ascii"))
103
+
104
+ _create_snapshot()
105
+ del _create_snapshot
106
+ `;
107
+ function getLoadRuntimeSnapshotSnippet(content) {
108
+ return `async def _load_snapshot():
109
+ import os
110
+ import logging
111
+ import platform
112
+ import pickle
113
+ from base64 import decodebytes
114
+ is_pyodide = platform.node() == "emscripten"
115
+
116
+ snapshot = decodebytes("${content}".encode("ascii"))
117
+ line_sep = bytes(os.linesep, "utf-8")
118
+ variable_separator = b"\\x00" + line_sep
119
+ name = b""
120
+ value = b""
121
+ for line in snapshot.splitlines():
122
+ line += line_sep
123
+ if line == variable_separator:
124
+ name_s = name.strip().decode("utf-8")
125
+ try:
126
+ try:
127
+ globals()[name_s] = pickle.loads(value)
128
+ except ModuleNotFoundError as m:
129
+ if is_pyodide:
130
+ import micropip
131
+ logging.info(f'Installing %s...', m.name)
132
+ await micropip.install(m.name)
133
+ globals()[name_s] = pickle.loads(value)
134
+ else:
135
+ raise m
136
+ except BaseException as e:
137
+ logging.warning("Failed to load variable [%s].", name_s, exc_info=e)
138
+ else:
139
+ logging.debug("Variable [%s] loaded", name_s)
140
+
141
+ name = b""
142
+ value = b""
143
+ else:
144
+ if not name:
145
+ name = line
146
+ else:
147
+ value += line
148
+ await _load_snapshot()
149
+ del _load_snapshot`;
150
+ }
@@ -5,7 +5,7 @@
5
5
  import { ServerConnection, ServiceManager } from '@jupyterlab/services';
6
6
  import { coreStore } from '../state/substates/CoreState';
7
7
  import { DEFAULT_DATALAYER_CONFIG } from '../config/Configuration';
8
- import { createRuntime } from '../api/runtimes/actions';
8
+ import { createRuntime } from '../sdk/stateful/runtimes/actions';
9
9
  /**
10
10
  * Creates a ServiceManager configured for Datalayer.
11
11
  *
@@ -7,7 +7,7 @@ import { useStore } from 'zustand';
7
7
  import { createStore } from 'zustand/vanilla';
8
8
  import { ANONYMOUS_USER_TOKEN, ANONYMOUS_USER, asUser, IAMProvidersSpecs, } from '../../models';
9
9
  import { getStoredToken, getStoredUser, loadRefreshTokenFromCookie, storeToken, storeUser, } from '../storage';
10
- import { requestDatalayerAPI } from '../../api';
10
+ import { requestDatalayerAPI, } from '../../api/DatalayerApi';
11
11
  import { getCookie, setCookie, deleteCookie } from '../../utils';
12
12
  import { coreStore } from './CoreState';
13
13
  /**
@@ -1,4 +1,4 @@
1
- import type { IMultiServiceManager } from '../../api';
1
+ import type { IMultiServiceManager } from '../../sdk/stateful/runtimes';
2
2
  import type { IRuntimesConfiguration } from '../../config';
3
3
  import type { IRuntimePod, IRuntimeSnapshot, IRuntimeModel } from '../../models';
4
4
  /**
@@ -6,7 +6,7 @@ import { useStore } from 'zustand';
6
6
  import { createStore } from 'zustand/vanilla';
7
7
  import { JSONExt } from '@lumino/coreutils';
8
8
  import { Poll } from '@lumino/polling';
9
- import { getRuntimes } from '../../api';
9
+ import { getRuntimes } from '../../sdk/stateful/runtimes';
10
10
  import { coreStore } from './CoreState';
11
11
  import { iamStore } from './IAMState';
12
12
  /**
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { createStore } from 'zustand/vanilla';
6
6
  import { useStore } from 'zustand';
7
- import { requestDatalayerAPI } from '../../api';
7
+ import { requestDatalayerAPI, } from '../../api/DatalayerApi';
8
8
  import { asSurvey, } from '../../models';
9
9
  import { coreStore } from './CoreState';
10
10
  import { iamStore } from './IAMState';
package/lib/test-setup.js CHANGED
@@ -6,6 +6,7 @@
6
6
  // Add any global test configuration here
7
7
  // Define webpack globals that are expected by some dependencies
8
8
  global.__webpack_public_path__ = '';
9
+ // Native FormData and fetch should work in Node.js 20+
9
10
  // Define other globals that might be needed
10
11
  global.global = globalThis;
11
12
  // Mock DragEvent and other DOM APIs not available in jsdom
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/core",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  ".",
@@ -47,16 +47,21 @@
47
47
  "dev": "vite",
48
48
  "build": "gulp resources-to-lib && tsc -b && vite build",
49
49
  "build:lib": "gulp resources-to-lib && tsc -b",
50
+ "build:types": "tsc -b",
50
51
  "build:nextjs": "npm run build --workspace=nextjs-notebook-example",
51
- "build:electron": "npm run build --workspace=@datalayer/electron-example",
52
+ "build:electron": "npm run build --workspace=@datalayer/desktop",
52
53
  "build:examples": "npm run build:nextjs && npm run build:electron",
53
54
  "build:all": "npm run build && npm run build:examples",
54
55
  "lint": "eslint . --quiet",
55
56
  "lint:fix": "eslint . --fix",
56
57
  "lint:all": "npm run lint && npm run lint --workspaces --if-present",
58
+ "lint:fix:all": "npm run lint:fix && npm run lint:fix --workspaces --if-present",
57
59
  "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,json,md}\" \"examples/**/*.{js,jsx,ts,tsx,css,json,md,mjs}\"",
58
60
  "format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,json,md}\" \"examples/**/*.{js,jsx,ts,tsx,css,json,md,mjs}\"",
61
+ "format:fix": "npm run format",
59
62
  "format:all": "npm run format && npm run format --workspaces --if-present",
63
+ "format:check:all": "npm run format:check && npm run format:check --workspaces --if-present",
64
+ "format:fix:all": "npm run format:all",
60
65
  "type-check": "tsc --noEmit",
61
66
  "type-check:all": "npm run type-check && npm run type-check --workspaces --if-present",
62
67
  "check": "npm run format:check && npm run lint:all && npm run type-check:all",
@@ -64,17 +69,20 @@
64
69
  "preview": "vite preview",
65
70
  "start": "vite",
66
71
  "clean": "rimraf lib tsconfig.tsbuildinfo",
67
- "test": "vitest run --project=unit",
68
- "test:watch": "vitest --project=unit",
69
- "test:ui": "vitest --ui --project=unit",
70
- "test:coverage": "vitest run --coverage --project=unit",
71
- "test:storybook": "vitest run --project=storybook",
72
+ "test": "vitest run --project=unit --project=general",
73
+ "test:watch": "vitest --project=unit --project=general",
74
+ "test:ui": "vitest --ui --project=unit --project=general",
75
+ "test:coverage": "vitest run --coverage --project=unit --project=general",
76
+ "test:unit": "vitest run --project=unit",
77
+ "test:integration": "vitest run --project=integration",
78
+ "test:all": "vitest run",
72
79
  "storybook": "storybook dev -p 6006",
73
80
  "build-storybook": "storybook build",
74
81
  "typedoc": "typedoc --options typedoc.json --out docs/docs/typescript_api",
75
82
  "watch:lib": "run-p 'watch:lib:*'",
76
83
  "watch:lib:res": "gulp resources-to-lib-watch",
77
- "watch:lib:src": "tsc -b -w",
84
+ "watch:lib:src": "echo 'Type checking moved to separate command. Use npm run type-check:watch'",
85
+ "type-check:watch": "tsc -b -w --noEmit",
78
86
  "example": "vite --config vite.examples.config.ts",
79
87
  "example:nextjs": "npm run dev --workspace=nextjs-notebook-example",
80
88
  "example:electron": "cd examples/electron && npm run dev",
@@ -128,7 +136,6 @@
128
136
  "devDependencies": {
129
137
  "@chromatic-com/storybook": "^4.1.0",
130
138
  "@eslint/js": "^9.29.0",
131
- "react-router-dom": "^6.22.3",
132
139
  "@storybook/addon-a11y": "^9.1.1",
133
140
  "@storybook/addon-docs": "^9.1.1",
134
141
  "@storybook/addon-onboarding": "^9.1.1",
@@ -141,7 +148,9 @@
141
148
  "@vitejs/plugin-react": "^4.5.2",
142
149
  "@vitest/browser": "^3.2.4",
143
150
  "@vitest/coverage-v8": "^3.2.4",
151
+ "abort-controller": "^3.0.0",
144
152
  "crypto-browserify": "^3.12.1",
153
+ "dotenv": "^17.2.2",
145
154
  "eslint": "^9.29.0",
146
155
  "eslint-config-prettier": "^10.1.8",
147
156
  "eslint-plugin-prettier": "^5.5.4",
@@ -160,6 +169,7 @@
160
169
  "npm-run-all": "^4.1.5",
161
170
  "playwright": "^1.53.2",
162
171
  "prettier": "^3.6.2",
172
+ "react-router-dom": "^6.22.3",
163
173
  "rimraf": "^6.0.1",
164
174
  "storybook": "^9.1.1",
165
175
  "typedoc-plugin-markdown": "^4.0.0",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes