@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.
- package/README.md +2 -2
- package/lib/api/DatalayerApi.d.ts +38 -26
- package/lib/api/DatalayerApi.js +35 -8
- package/lib/api/iam/authentication.d.ts +8 -7
- package/lib/api/iam/authentication.js +14 -15
- package/lib/api/iam/healthz.d.ts +3 -2
- package/lib/api/iam/healthz.js +5 -3
- package/lib/api/iam/index.d.ts +9 -4
- package/lib/api/iam/index.js +9 -4
- package/lib/api/iam/oauth2.d.ts +115 -0
- package/lib/api/iam/oauth2.js +309 -0
- package/lib/api/iam/profile.d.ts +8 -1
- package/lib/api/iam/profile.js +17 -2
- package/lib/api/iam/usage.d.ts +56 -0
- package/lib/api/iam/usage.js +39 -0
- package/lib/api/index.d.ts +6 -5
- package/lib/api/index.js +6 -5
- package/lib/api/runtimes/environments.js +3 -2
- package/lib/api/runtimes/healthz.d.ts +3 -13
- package/lib/api/runtimes/healthz.js +4 -3
- package/lib/api/runtimes/index.d.ts +3 -2
- package/lib/api/runtimes/index.js +3 -2
- package/lib/api/runtimes/runtimes.js +17 -6
- package/lib/api/runtimes/snapshots.js +3 -2
- package/lib/api/spacer/documents.d.ts +12 -0
- package/lib/api/spacer/documents.js +43 -0
- package/lib/api/spacer/healthz.d.ts +3 -13
- package/lib/api/spacer/healthz.js +4 -3
- package/lib/api/spacer/index.d.ts +4 -2
- package/lib/api/spacer/index.js +4 -2
- package/lib/api/spacer/items.d.ts +9 -1
- package/lib/api/spacer/items.js +17 -2
- package/lib/api/spacer/lexicals.js +3 -2
- package/lib/api/spacer/notebooks.js +3 -2
- package/lib/api/spacer/spaces.js +3 -2
- package/lib/api/spacer/users.js +3 -2
- package/lib/api/types/common.d.ts +64 -0
- package/lib/api/types/iam.d.ts +88 -65
- package/lib/api/types/index.d.ts +4 -2
- package/lib/api/types/index.js +4 -2
- package/lib/api/types/runtimes.d.ts +9 -39
- package/lib/api/types/spacer.d.ts +37 -65
- package/lib/api/utils/validation.d.ts +24 -1
- package/lib/api/utils/validation.js +62 -1
- package/lib/client/base.d.ts +75 -0
- package/lib/client/base.js +199 -0
- package/lib/client/constants.d.ts +22 -0
- package/lib/client/constants.js +22 -0
- package/lib/client/index.d.ts +108 -0
- package/lib/client/index.js +79 -0
- package/lib/client/mixins/IAMMixin.d.ts +54 -0
- package/lib/client/mixins/IAMMixin.js +181 -0
- package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
- package/lib/client/mixins/RuntimesMixin.js +229 -0
- package/lib/client/mixins/SpacerMixin.d.ts +111 -0
- package/lib/client/mixins/SpacerMixin.js +340 -0
- package/lib/client/models/Credits.d.ts +91 -0
- package/lib/client/models/Credits.js +130 -0
- package/lib/client/models/Environment.d.ts +73 -0
- package/lib/client/models/Environment.js +88 -0
- package/lib/client/models/HealthCheck.d.ts +72 -0
- package/lib/client/models/HealthCheck.js +107 -0
- package/lib/client/models/Item.d.ts +69 -0
- package/lib/client/models/Item.js +191 -0
- package/lib/client/models/Lexical.d.ts +83 -0
- package/lib/client/models/Lexical.js +152 -0
- package/lib/client/models/Notebook.d.ts +87 -0
- package/lib/client/models/Notebook.js +153 -0
- package/lib/client/models/Runtime.d.ts +122 -0
- package/lib/client/models/Runtime.js +204 -0
- package/lib/client/models/Snapshot.d.ts +92 -0
- package/lib/client/models/Snapshot.js +139 -0
- package/lib/client/models/Space.d.ts +135 -0
- package/lib/client/models/Space.js +234 -0
- package/lib/client/models/User.d.ts +64 -0
- package/lib/client/models/User.js +83 -0
- package/lib/client/models/index.d.ts +26 -0
- package/lib/client/models/index.js +25 -0
- package/lib/client/utils/mixins.d.ts +12 -0
- package/lib/{sdk/client → client}/utils/mixins.js +0 -28
- package/lib/client/utils/spacerUtils.d.ts +18 -0
- package/lib/client/utils/spacerUtils.js +32 -0
- package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
- package/lib/collaboration/DatalayerCollaboration.js +2 -2
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
- package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
- package/lib/components/progress/CreditsIndicator.d.ts +1 -1
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.js +1 -1
- package/lib/components/runtimes/RuntimePickerCell.js +2 -2
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
- package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
- package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
- package/lib/config/Configuration.d.ts +8 -0
- package/lib/hooks/useDatalayer.js +1 -1
- package/lib/hooks/useRuntimes.js +1 -1
- package/lib/hooks/useToast.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +4 -2
- package/lib/sdk/index.d.ts +5 -4
- package/lib/sdk/index.js +6 -5
- package/lib/services/DatalayerServiceManager.js +1 -1
- package/lib/state/substates/CoreState.js +2 -0
- package/lib/state/substates/RuntimesState.d.ts +1 -1
- package/lib/state/substates/RuntimesState.js +1 -1
- package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
- package/lib/{sdk/stateful → stateful}/index.js +1 -1
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
- package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
- package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
- package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
- package/lib/stateful/runtimes/apis.js +5 -0
- package/package.json +12 -10
- package/lib/__tests__/hooks.test.d.ts +0 -1
- package/lib/__tests__/hooks.test.js +0 -19
- package/lib/__tests__/index.test.d.ts +0 -1
- package/lib/__tests__/index.test.js +0 -27
- package/lib/__tests__/integration.test.d.ts +0 -1
- package/lib/__tests__/integration.test.js +0 -57
- package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
- package/lib/__tests__/shared/cleanup-shared.js +0 -228
- package/lib/__tests__/shared/test-config.d.ts +0 -51
- package/lib/__tests__/shared/test-config.js +0 -110
- package/lib/__tests__/shared/test-constants.d.ts +0 -66
- package/lib/__tests__/shared/test-constants.js +0 -79
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -59
- package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
- package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
- package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
- package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
- package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.integration.test.js +0 -369
- package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.integration.test.js +0 -519
- package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
- package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
- package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
- package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
- package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
- package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
- package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
- package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
- package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
- package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
- package/lib/api/utils/__tests__/validation.test.js +0 -109
- package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
- package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
- package/lib/sdk/client/base.d.ts +0 -88
- package/lib/sdk/client/base.js +0 -112
- package/lib/sdk/client/index.d.ts +0 -192
- package/lib/sdk/client/index.js +0 -128
- package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
- package/lib/sdk/client/mixins/HealthMixin.js +0 -133
- package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
- package/lib/sdk/client/mixins/IAMMixin.js +0 -83
- package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
- package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
- package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
- package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
- package/lib/sdk/client/models/Lexical.d.ts +0 -156
- package/lib/sdk/client/models/Lexical.js +0 -275
- package/lib/sdk/client/models/Notebook.d.ts +0 -174
- package/lib/sdk/client/models/Notebook.js +0 -311
- package/lib/sdk/client/models/Runtime.d.ts +0 -221
- package/lib/sdk/client/models/Runtime.js +0 -341
- package/lib/sdk/client/models/Snapshot.d.ts +0 -156
- package/lib/sdk/client/models/Snapshot.js +0 -244
- package/lib/sdk/client/models/Space.d.ts +0 -182
- package/lib/sdk/client/models/Space.js +0 -276
- package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
- package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
- package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
- package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
- package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
- package/lib/sdk/client/models/index.d.ts +0 -30
- package/lib/sdk/client/models/index.js +0 -30
- package/lib/sdk/client/utils/mixins.d.ts +0 -42
- /package/lib/{sdk/stateful/runtimes/apis.js → api/types/common.js} +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main Datalayer Client with intuitive mixin-based API.
|
|
3
|
+
* Provides unified, flat API for all Datalayer platform services through TypeScript mixins.
|
|
4
|
+
*
|
|
5
|
+
* @module client
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const client = new DatalayerClient({
|
|
10
|
+
* token: 'your-api-token'
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const user = await client.whoami();
|
|
14
|
+
* const runtime = await client.createRuntime(config);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import { DatalayerClientBase, type DatalayerClientConfig, type SDKHandlers } from './base';
|
|
18
|
+
import type { User } from './models/User';
|
|
19
|
+
import type { Credits } from './models/Credits';
|
|
20
|
+
import type { Environment } from './models/Environment';
|
|
21
|
+
import type { Runtime } from './models/Runtime';
|
|
22
|
+
import type { Snapshot } from './models/Snapshot';
|
|
23
|
+
import type { Space } from './models/Space';
|
|
24
|
+
import type { Notebook } from './models/Notebook';
|
|
25
|
+
import type { Lexical } from './models/Lexical';
|
|
26
|
+
import type { HealthCheck } from './models/HealthCheck';
|
|
27
|
+
declare const DatalayerClientWithMixins: typeof DatalayerClientBase;
|
|
28
|
+
/**
|
|
29
|
+
* Main Datalayer Client providing unified access to all platform services.
|
|
30
|
+
* Uses TypeScript mixins to provide a flat, discoverable API.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const client = new DatalayerClient({
|
|
35
|
+
* token: 'your-token'
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const user = await client.whoami();
|
|
39
|
+
* const runtime = await client.createRuntime({
|
|
40
|
+
* environment_name: 'python-cpu-env',
|
|
41
|
+
* credits_limit: 100
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class DatalayerClient extends DatalayerClientWithMixins {
|
|
46
|
+
/**
|
|
47
|
+
* Create a DatalayerClient instance.
|
|
48
|
+
*
|
|
49
|
+
* @param config - Client configuration options
|
|
50
|
+
*/
|
|
51
|
+
constructor(config: DatalayerClientConfig);
|
|
52
|
+
}
|
|
53
|
+
export type { DatalayerClientConfig, SDKHandlers };
|
|
54
|
+
export { DatalayerClientBase };
|
|
55
|
+
export { User } from './models/User';
|
|
56
|
+
export type { UserJSON } from './models/User';
|
|
57
|
+
export { Runtime } from './models/Runtime';
|
|
58
|
+
export type { RuntimeJSON } from './models/Runtime';
|
|
59
|
+
export { Environment } from './models/Environment';
|
|
60
|
+
export type { EnvironmentJSON } from './models/Environment';
|
|
61
|
+
export { Snapshot } from './models/Snapshot';
|
|
62
|
+
export { Space } from './models/Space';
|
|
63
|
+
export { Notebook } from './models/Notebook';
|
|
64
|
+
export { Lexical } from './models/Lexical';
|
|
65
|
+
export { Credits } from './models/Credits';
|
|
66
|
+
export { Item } from './models/Item';
|
|
67
|
+
export { HealthCheck } from './models/HealthCheck';
|
|
68
|
+
export type { HealthCheckJSON } from './models/HealthCheck';
|
|
69
|
+
export { ItemTypes } from './constants';
|
|
70
|
+
export type { ItemType } from './constants';
|
|
71
|
+
export interface DatalayerClient {
|
|
72
|
+
getToken(): string | undefined;
|
|
73
|
+
setToken(token: string): Promise<void>;
|
|
74
|
+
whoami(): Promise<User>;
|
|
75
|
+
login(token: string): Promise<User>;
|
|
76
|
+
logout(): Promise<void>;
|
|
77
|
+
getCredits(): Promise<Credits>;
|
|
78
|
+
calculateMaxRuntimeMinutes(availableCredits: number, burningRate: number): number;
|
|
79
|
+
calculateCreditsRequired(minutes: number, burningRate: number): number;
|
|
80
|
+
checkIAMHealth(): Promise<HealthCheck>;
|
|
81
|
+
listEnvironments(): Promise<Environment[]>;
|
|
82
|
+
ensureRuntime(environmentName?: string, creditsLimit?: number, waitForReady?: boolean, maxWaitTime?: number, reuseExisting?: boolean, snapshotId?: string): Promise<Runtime>;
|
|
83
|
+
createRuntime(environmentName: string, type: 'notebook' | 'terminal' | 'job', givenName: string, minutesLimit: number, fromSnapshotId?: string): Promise<Runtime>;
|
|
84
|
+
listRuntimes(): Promise<Runtime[]>;
|
|
85
|
+
getRuntime(podName: string): Promise<Runtime>;
|
|
86
|
+
deleteRuntime(podName: string): Promise<void>;
|
|
87
|
+
terminateAllRuntimes(): Promise<PromiseSettledResult<void>[]>;
|
|
88
|
+
createSnapshot(podName: string, name: string, description: string, stop?: boolean): Promise<Snapshot>;
|
|
89
|
+
listSnapshots(): Promise<Snapshot[]>;
|
|
90
|
+
getSnapshot(id: string): Promise<Snapshot>;
|
|
91
|
+
deleteSnapshot(id: string): Promise<void>;
|
|
92
|
+
checkRuntimesHealth(): Promise<HealthCheck>;
|
|
93
|
+
getMySpaces(): Promise<Space[]>;
|
|
94
|
+
createSpace(name: string, description: string, variant: string, spaceHandle: string, organizationId: string, seedSpaceId: string, isPublic: boolean): Promise<Space>;
|
|
95
|
+
createNotebook(spaceId: string, name: string, description: string, file?: File | Blob): Promise<Notebook>;
|
|
96
|
+
getNotebook(id: string): Promise<Notebook>;
|
|
97
|
+
updateNotebook(id: string, name?: string, description?: string): Promise<Notebook>;
|
|
98
|
+
createLexical(spaceId: string, name: string, description: string, file?: File | Blob): Promise<Lexical>;
|
|
99
|
+
getLexical(id: string): Promise<Lexical>;
|
|
100
|
+
updateLexical(id: string, name?: string, description?: string): Promise<Lexical>;
|
|
101
|
+
getSpaceItems(spaceId: string): Promise<(Notebook | Lexical)[]>;
|
|
102
|
+
getSpaceItem(itemId: string): Promise<Notebook | Lexical>;
|
|
103
|
+
deleteSpaceItem(itemId: string): Promise<void>;
|
|
104
|
+
getCollaborationSessionId(documentId: string): Promise<string>;
|
|
105
|
+
getContent(itemId: string): Promise<any>;
|
|
106
|
+
checkSpacerHealth(): Promise<HealthCheck>;
|
|
107
|
+
calculateCreditsFromMinutes(minutes: number, burningRate: number): number;
|
|
108
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Main Datalayer Client with intuitive mixin-based API.
|
|
7
|
+
* Provides unified, flat API for all Datalayer platform services through TypeScript mixins.
|
|
8
|
+
*
|
|
9
|
+
* @module client
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const client = new DatalayerClient({
|
|
14
|
+
* token: 'your-api-token'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const user = await client.whoami();
|
|
18
|
+
* const runtime = await client.createRuntime(config);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import { DatalayerClientBase, } from './base';
|
|
22
|
+
import { IAMMixin } from './mixins/IAMMixin';
|
|
23
|
+
import { RuntimesMixin } from './mixins/RuntimesMixin';
|
|
24
|
+
import { SpacerMixin } from './mixins/SpacerMixin';
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to compose mixins in a more readable way.
|
|
27
|
+
* Applies mixins in the order provided.
|
|
28
|
+
*
|
|
29
|
+
* @param mixins - Array of mixin functions to apply
|
|
30
|
+
* @returns The composed class with all mixins applied
|
|
31
|
+
*/
|
|
32
|
+
function composeMixins(...mixins) {
|
|
33
|
+
return mixins.reduce((base, mixin) => mixin(base), DatalayerClientBase);
|
|
34
|
+
}
|
|
35
|
+
// Apply mixins to the base class using the helper
|
|
36
|
+
const DatalayerClientWithMixins = composeMixins(IAMMixin, RuntimesMixin, SpacerMixin);
|
|
37
|
+
/**
|
|
38
|
+
* Main Datalayer Client providing unified access to all platform services.
|
|
39
|
+
* Uses TypeScript mixins to provide a flat, discoverable API.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const client = new DatalayerClient({
|
|
44
|
+
* token: 'your-token'
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* const user = await client.whoami();
|
|
48
|
+
* const runtime = await client.createRuntime({
|
|
49
|
+
* environment_name: 'python-cpu-env',
|
|
50
|
+
* credits_limit: 100
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export class DatalayerClient extends DatalayerClientWithMixins {
|
|
55
|
+
/**
|
|
56
|
+
* Create a DatalayerClient instance.
|
|
57
|
+
*
|
|
58
|
+
* @param config - Client configuration options
|
|
59
|
+
*/
|
|
60
|
+
constructor(config) {
|
|
61
|
+
super(config);
|
|
62
|
+
// Wrap all methods with handlers if configured
|
|
63
|
+
this.wrapAllMethods();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export { DatalayerClientBase };
|
|
67
|
+
// Export models for use by consumers
|
|
68
|
+
export { User } from './models/User';
|
|
69
|
+
export { Runtime } from './models/Runtime';
|
|
70
|
+
export { Environment } from './models/Environment';
|
|
71
|
+
export { Snapshot } from './models/Snapshot';
|
|
72
|
+
export { Space } from './models/Space';
|
|
73
|
+
export { Notebook } from './models/Notebook';
|
|
74
|
+
export { Lexical } from './models/Lexical';
|
|
75
|
+
export { Credits } from './models/Credits';
|
|
76
|
+
export { Item } from './models/Item';
|
|
77
|
+
export { HealthCheck } from './models/HealthCheck';
|
|
78
|
+
// Export constants
|
|
79
|
+
export { ItemTypes } from './constants';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Constructor } from '../utils/mixins';
|
|
2
|
+
import { User } from '../models/User';
|
|
3
|
+
import { Credits } from '../models/Credits';
|
|
4
|
+
import { HealthCheck } from '../models/HealthCheck';
|
|
5
|
+
/** IAM mixin providing authentication and user management. */
|
|
6
|
+
export declare function IAMMixin<TBase extends Constructor>(Base: TBase): {
|
|
7
|
+
new (...args: any[]): {
|
|
8
|
+
currentUserCache?: User;
|
|
9
|
+
/**
|
|
10
|
+
* Get the current user's profile information.
|
|
11
|
+
* @returns User model instance
|
|
12
|
+
*/
|
|
13
|
+
whoami(): Promise<User>;
|
|
14
|
+
/**
|
|
15
|
+
* Authenticate the user with a token.
|
|
16
|
+
* @param token - Authentication token
|
|
17
|
+
* @returns User object on successful login
|
|
18
|
+
* @throws Error if token is invalid
|
|
19
|
+
*/
|
|
20
|
+
login(token: string): Promise<User>;
|
|
21
|
+
/** Log out the current user. */
|
|
22
|
+
logout(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the current user's available credits and usage information.
|
|
25
|
+
* @returns Credits model instance
|
|
26
|
+
*/
|
|
27
|
+
getCredits(): Promise<Credits>;
|
|
28
|
+
/**
|
|
29
|
+
* Calculate the maximum runtime duration in minutes based on available credits and burning rate.
|
|
30
|
+
* @param availableCredits - The amount of credits available
|
|
31
|
+
* @param burningRate - The burning rate per second for the environment
|
|
32
|
+
* @returns Maximum runtime duration in minutes
|
|
33
|
+
*/
|
|
34
|
+
calculateMaxRuntimeMinutes(availableCredits: number, burningRate: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Calculate the credits required for a given runtime duration.
|
|
37
|
+
* @param minutes - Runtime duration in minutes
|
|
38
|
+
* @param burningRate - The burning rate per second for the environment
|
|
39
|
+
* @returns Credits required (rounded up to nearest integer)
|
|
40
|
+
*/
|
|
41
|
+
calculateCreditsRequired(minutes: number, burningRate: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Calculate the burning rate per minute from the per-second rate.
|
|
44
|
+
* @param burningRatePerSecond - The burning rate per second
|
|
45
|
+
* @returns Burning rate per minute
|
|
46
|
+
*/
|
|
47
|
+
calculateBurningRatePerMinute(burningRatePerSecond: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Check the health status of the IAM service.
|
|
50
|
+
* @returns Health check model instance
|
|
51
|
+
*/
|
|
52
|
+
checkIAMHealth(): Promise<HealthCheck>;
|
|
53
|
+
};
|
|
54
|
+
} & TBase;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* IAM mixin providing authentication and user management functionality.
|
|
7
|
+
* @module client/mixins/IAMMixin
|
|
8
|
+
*/
|
|
9
|
+
import * as authentication from '../../api/iam/authentication';
|
|
10
|
+
import * as profile from '../../api/iam/profile';
|
|
11
|
+
import * as usage from '../../api/iam/usage';
|
|
12
|
+
import { User } from '../models/User';
|
|
13
|
+
import { Credits } from '../models/Credits';
|
|
14
|
+
import { HealthCheck } from '../models/HealthCheck';
|
|
15
|
+
/** IAM mixin providing authentication and user management. */
|
|
16
|
+
export function IAMMixin(Base) {
|
|
17
|
+
return class extends Base {
|
|
18
|
+
// Cache for current user
|
|
19
|
+
currentUserCache;
|
|
20
|
+
/**
|
|
21
|
+
* Get the current user's profile information.
|
|
22
|
+
* @returns User model instance
|
|
23
|
+
*/
|
|
24
|
+
async whoami() {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const token = this.getToken();
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
const iamRunUrl = this.getIamRunUrl();
|
|
29
|
+
const response = await profile.whoami(token, iamRunUrl);
|
|
30
|
+
// Handle the whoami response format
|
|
31
|
+
let userData;
|
|
32
|
+
if (!response) {
|
|
33
|
+
throw new Error(`No response from profile.whoami API`);
|
|
34
|
+
}
|
|
35
|
+
// Check if response has the expected wrapper structure with profile
|
|
36
|
+
if (response.profile) {
|
|
37
|
+
// Transform the API response to match the User model's expected data structure
|
|
38
|
+
// Note: whoami returns fields with suffixes like _s, _t
|
|
39
|
+
userData = {
|
|
40
|
+
id: response.profile.id,
|
|
41
|
+
uid: response.profile.uid,
|
|
42
|
+
// User model expects fields with suffixes from API types
|
|
43
|
+
handle_s: response.profile.handle_s || response.profile.handle,
|
|
44
|
+
email_s: response.profile.email_s || response.profile.email,
|
|
45
|
+
first_name_t: response.profile.first_name_t || response.profile.first_name || '',
|
|
46
|
+
last_name_t: response.profile.last_name_t || response.profile.last_name || '',
|
|
47
|
+
// Use avatar_url_s if available, otherwise leave undefined for fallback
|
|
48
|
+
avatar_url_s: response.profile.avatar_url_s || response.profile.avatar_url,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Fallback for unexpected format
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`Unexpected response format from profile.whoami API: ${JSON.stringify(response)}`);
|
|
54
|
+
}
|
|
55
|
+
// Create new User instance (User model is immutable, no update method)
|
|
56
|
+
this.currentUserCache = new User(userData, this);
|
|
57
|
+
return this.currentUserCache;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Authenticate the user with a token.
|
|
61
|
+
* @param token - Authentication token
|
|
62
|
+
* @returns User object on successful login
|
|
63
|
+
* @throws Error if token is invalid
|
|
64
|
+
*/
|
|
65
|
+
async login(token) {
|
|
66
|
+
// For token-based login, we simply set the token and verify it works
|
|
67
|
+
await this.setToken(token);
|
|
68
|
+
// Verify the token by calling whoami
|
|
69
|
+
try {
|
|
70
|
+
const user = await this.whoami();
|
|
71
|
+
return user;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// Clear the invalid token
|
|
75
|
+
await this.setToken('');
|
|
76
|
+
throw new Error(`Invalid token: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Log out the current user. */
|
|
80
|
+
async logout() {
|
|
81
|
+
const token = this.getToken();
|
|
82
|
+
const iamRunUrl = this.getIamRunUrl();
|
|
83
|
+
await authentication.logout(token, iamRunUrl);
|
|
84
|
+
// Clear the token from the SDK and cached user
|
|
85
|
+
this.setToken('');
|
|
86
|
+
this.currentUserCache = undefined;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the current user's available credits and usage information.
|
|
90
|
+
* @returns Credits model instance
|
|
91
|
+
*/
|
|
92
|
+
async getCredits() {
|
|
93
|
+
const token = this.getToken();
|
|
94
|
+
const iamRunUrl = this.getIamRunUrl();
|
|
95
|
+
const response = await usage.getCredits(token, iamRunUrl);
|
|
96
|
+
if (!response || !response.credits) {
|
|
97
|
+
throw new Error('Invalid response from credits API');
|
|
98
|
+
}
|
|
99
|
+
return new Credits(response.credits, response.reservations || []);
|
|
100
|
+
}
|
|
101
|
+
// ========================================================================
|
|
102
|
+
// Credits Calculation Utilities
|
|
103
|
+
// ========================================================================
|
|
104
|
+
/**
|
|
105
|
+
* Calculate the maximum runtime duration in minutes based on available credits and burning rate.
|
|
106
|
+
* @param availableCredits - The amount of credits available
|
|
107
|
+
* @param burningRate - The burning rate per second for the environment
|
|
108
|
+
* @returns Maximum runtime duration in minutes
|
|
109
|
+
*/
|
|
110
|
+
calculateMaxRuntimeMinutes(availableCredits, burningRate) {
|
|
111
|
+
if (!burningRate || burningRate <= 0)
|
|
112
|
+
return 0;
|
|
113
|
+
const burningRatePerMinute = burningRate * 60;
|
|
114
|
+
return Math.floor(availableCredits / burningRatePerMinute);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Calculate the credits required for a given runtime duration.
|
|
118
|
+
* @param minutes - Runtime duration in minutes
|
|
119
|
+
* @param burningRate - The burning rate per second for the environment
|
|
120
|
+
* @returns Credits required (rounded up to nearest integer)
|
|
121
|
+
*/
|
|
122
|
+
calculateCreditsRequired(minutes, burningRate) {
|
|
123
|
+
if (!burningRate || burningRate <= 0 || !minutes || minutes <= 0)
|
|
124
|
+
return 0;
|
|
125
|
+
return Math.ceil(minutes * this.calculateBurningRatePerMinute(burningRate));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Calculate the burning rate per minute from the per-second rate.
|
|
129
|
+
* @param burningRatePerSecond - The burning rate per second
|
|
130
|
+
* @returns Burning rate per minute
|
|
131
|
+
*/
|
|
132
|
+
calculateBurningRatePerMinute(burningRatePerSecond) {
|
|
133
|
+
return burningRatePerSecond * 60;
|
|
134
|
+
}
|
|
135
|
+
// ========================================================================
|
|
136
|
+
// Service Health Checks
|
|
137
|
+
// ========================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Check the health status of the IAM service.
|
|
140
|
+
* @returns Health check model instance
|
|
141
|
+
*/
|
|
142
|
+
async checkIAMHealth() {
|
|
143
|
+
const startTime = Date.now();
|
|
144
|
+
const errors = [];
|
|
145
|
+
let status = 'unknown';
|
|
146
|
+
let healthy = false;
|
|
147
|
+
try {
|
|
148
|
+
// Test basic connectivity and authentication by getting user profile
|
|
149
|
+
const user = await this.whoami();
|
|
150
|
+
const responseTime = Date.now() - startTime;
|
|
151
|
+
if (user && user.uid) {
|
|
152
|
+
healthy = true;
|
|
153
|
+
status = 'operational';
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
status = 'degraded';
|
|
157
|
+
errors.push('Unexpected response format from profile endpoint');
|
|
158
|
+
}
|
|
159
|
+
return new HealthCheck({
|
|
160
|
+
healthy,
|
|
161
|
+
status,
|
|
162
|
+
responseTime,
|
|
163
|
+
errors,
|
|
164
|
+
timestamp: new Date(),
|
|
165
|
+
}, this);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
const responseTime = Date.now() - startTime;
|
|
169
|
+
status = 'down';
|
|
170
|
+
errors.push(`Service unreachable: ${error}`);
|
|
171
|
+
return new HealthCheck({
|
|
172
|
+
healthy: false,
|
|
173
|
+
status,
|
|
174
|
+
responseTime,
|
|
175
|
+
errors,
|
|
176
|
+
timestamp: new Date(),
|
|
177
|
+
}, this);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Constructor } from '../utils/mixins';
|
|
2
|
+
import { Environment } from '../models/Environment';
|
|
3
|
+
import { Runtime } from '../models/Runtime';
|
|
4
|
+
import { Snapshot } from '../models/Snapshot';
|
|
5
|
+
import { HealthCheck } from '../models/HealthCheck';
|
|
6
|
+
/** Options for ensuring a runtime is available. */
|
|
7
|
+
export interface EnsureRuntimeOptions {
|
|
8
|
+
/** Name of the environment to use */
|
|
9
|
+
environmentName?: string;
|
|
10
|
+
/** Maximum credits to allocate */
|
|
11
|
+
creditsLimit?: number;
|
|
12
|
+
/** Whether to wait for runtime to be ready */
|
|
13
|
+
waitForReady?: boolean;
|
|
14
|
+
/** Maximum time to wait for ready state (ms) */
|
|
15
|
+
maxWaitTime?: number;
|
|
16
|
+
/** Whether to reuse existing suitable runtime */
|
|
17
|
+
reuseExisting?: boolean;
|
|
18
|
+
/** Snapshot ID to create runtime from */
|
|
19
|
+
snapshotId?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Runtimes mixin providing computational environment and runtime management. */
|
|
22
|
+
export declare function RuntimesMixin<TBase extends Constructor>(Base: TBase): {
|
|
23
|
+
new (...args: any[]): {
|
|
24
|
+
_extractRuntimePodName(runtimePodNameOrInstance: string | Runtime): string;
|
|
25
|
+
_extractSnapshotId(snapshotIdOrInstance: string | Snapshot): string;
|
|
26
|
+
/**
|
|
27
|
+
* List all available computational environments.
|
|
28
|
+
* @returns Array of Environment model instances
|
|
29
|
+
*/
|
|
30
|
+
listEnvironments(): Promise<Environment[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new computational runtime.
|
|
33
|
+
* @param environmentName - Name of the environment to use
|
|
34
|
+
* @param type - Type of runtime
|
|
35
|
+
* @param givenName - User-friendly name for the runtime
|
|
36
|
+
* @param creditsLimit - Credits limit
|
|
37
|
+
* @returns Created runtime
|
|
38
|
+
*/
|
|
39
|
+
createRuntime(environmentName: string, type: "notebook" | "terminal" | "job", givenName: string, minutesLimit: number, fromSnapshotId?: string): Promise<Runtime>;
|
|
40
|
+
/**
|
|
41
|
+
* List all runtimes.
|
|
42
|
+
* @returns Array of runtimes
|
|
43
|
+
*/
|
|
44
|
+
listRuntimes(): Promise<Runtime[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Get details for a specific runtime by pod name.
|
|
47
|
+
* @param podName - Runtime pod name
|
|
48
|
+
* @returns Runtime details
|
|
49
|
+
*/
|
|
50
|
+
getRuntime(podName: string): Promise<Runtime>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete a runtime permanently.
|
|
53
|
+
* @param podName - Runtime pod name
|
|
54
|
+
*/
|
|
55
|
+
deleteRuntime(podName: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Terminate all runtimes.
|
|
58
|
+
* Lists all runtimes and deletes them in parallel.
|
|
59
|
+
* @returns Array of results for each deletion (fulfilled or rejected)
|
|
60
|
+
*/
|
|
61
|
+
terminateAllRuntimes(): Promise<PromiseSettledResult<void>[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Create a snapshot of a runtime.
|
|
64
|
+
* @param podName - Pod name of the runtime to snapshot
|
|
65
|
+
* @param name - Name for the snapshot
|
|
66
|
+
* @param description - Description of the snapshot
|
|
67
|
+
* @param stop - Whether to stop the runtime after creating snapshot (defaults to false)
|
|
68
|
+
* @returns Created snapshot
|
|
69
|
+
*/
|
|
70
|
+
createSnapshot(podName: string, name: string, description: string, stop?: boolean): Promise<Snapshot>;
|
|
71
|
+
/**
|
|
72
|
+
* List all runtime snapshots.
|
|
73
|
+
* @returns Array of snapshots
|
|
74
|
+
*/
|
|
75
|
+
listSnapshots(): Promise<Snapshot[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Get details for a specific snapshot by ID.
|
|
78
|
+
* @param id - Snapshot ID
|
|
79
|
+
* @returns Snapshot details
|
|
80
|
+
*/
|
|
81
|
+
getSnapshot(id: string): Promise<Snapshot>;
|
|
82
|
+
/**
|
|
83
|
+
* Delete a snapshot permanently.
|
|
84
|
+
* @param id - Snapshot ID
|
|
85
|
+
*/
|
|
86
|
+
deleteSnapshot(id: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Check the health status of the Runtimes service.
|
|
89
|
+
* @returns Health check result with status and response time
|
|
90
|
+
*/
|
|
91
|
+
checkRuntimesHealth(): Promise<HealthCheck>;
|
|
92
|
+
};
|
|
93
|
+
} & TBase;
|