@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,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credits model for the Datalayer SDK.
|
|
3
|
+
*
|
|
4
|
+
* @module client/models/Credits
|
|
5
|
+
*/
|
|
6
|
+
import type { CreditsInfo, CreditReservation } from '../../api/iam/usage';
|
|
7
|
+
/**
|
|
8
|
+
* Credits model representing user's available credits and usage.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const credits = await sdk.getCredits();
|
|
13
|
+
* console.log(`Available: ${credits.available}`);
|
|
14
|
+
* console.log(`Quota: ${credits.quota || 'unlimited'}`);
|
|
15
|
+
*
|
|
16
|
+
* // Calculate maximum runtime for an environment
|
|
17
|
+
* const maxMinutes = credits.calculateMaxRuntimeMinutes(environment.burningRate);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class Credits {
|
|
21
|
+
/** @internal */
|
|
22
|
+
_data: CreditsInfo;
|
|
23
|
+
private _reservations;
|
|
24
|
+
constructor(data: CreditsInfo, reservations?: CreditReservation[]);
|
|
25
|
+
/**
|
|
26
|
+
* Available credits for the user.
|
|
27
|
+
*/
|
|
28
|
+
get available(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Credit quota for the user.
|
|
31
|
+
* Returns null if unlimited.
|
|
32
|
+
*/
|
|
33
|
+
get quota(): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Last update timestamp.
|
|
36
|
+
*/
|
|
37
|
+
get lastUpdate(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Active credit reservations.
|
|
40
|
+
*/
|
|
41
|
+
get reservations(): CreditReservation[];
|
|
42
|
+
/**
|
|
43
|
+
* Total reserved credits across all reservations.
|
|
44
|
+
*/
|
|
45
|
+
get totalReserved(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Net available credits (available minus reserved).
|
|
48
|
+
*/
|
|
49
|
+
get netAvailable(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Get runtime reservations (reservations that start with 'runtime-').
|
|
52
|
+
*/
|
|
53
|
+
get runtimeReservations(): CreditReservation[];
|
|
54
|
+
/**
|
|
55
|
+
* Check if there are any active runtime reservations.
|
|
56
|
+
*/
|
|
57
|
+
get hasActiveRuntimes(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Calculate maximum runtime in minutes based on environment burning rate.
|
|
60
|
+
*
|
|
61
|
+
* @param burningRate - Credits consumed per hour
|
|
62
|
+
* @returns Maximum runtime in minutes
|
|
63
|
+
*/
|
|
64
|
+
calculateMaxRuntimeMinutes(burningRate: number): number;
|
|
65
|
+
/**
|
|
66
|
+
* Calculate credits needed for runtime duration.
|
|
67
|
+
*
|
|
68
|
+
* @param minutes - Runtime duration in minutes
|
|
69
|
+
* @param burningRate - Credits consumed per hour
|
|
70
|
+
* @returns Credits needed
|
|
71
|
+
*/
|
|
72
|
+
calculateCreditsFromMinutes(minutes: number, burningRate: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Check if user has enough credits for runtime.
|
|
75
|
+
*
|
|
76
|
+
* @param minutes - Runtime duration in minutes
|
|
77
|
+
* @param burningRate - Credits consumed per hour
|
|
78
|
+
* @returns True if user has enough credits
|
|
79
|
+
*/
|
|
80
|
+
hasEnoughCreditsForRuntime(minutes: number, burningRate: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Convert to JSON representation.
|
|
83
|
+
*/
|
|
84
|
+
toJSON(): CreditsInfo & {
|
|
85
|
+
reservations: CreditReservation[];
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* String representation of credits.
|
|
89
|
+
*/
|
|
90
|
+
toString(): string;
|
|
91
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
import { validateJSON } from '../../api/utils/validation';
|
|
6
|
+
/**
|
|
7
|
+
* Credits model representing user's available credits and usage.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const credits = await sdk.getCredits();
|
|
12
|
+
* console.log(`Available: ${credits.available}`);
|
|
13
|
+
* console.log(`Quota: ${credits.quota || 'unlimited'}`);
|
|
14
|
+
*
|
|
15
|
+
* // Calculate maximum runtime for an environment
|
|
16
|
+
* const maxMinutes = credits.calculateMaxRuntimeMinutes(environment.burningRate);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class Credits {
|
|
20
|
+
/** @internal */
|
|
21
|
+
_data;
|
|
22
|
+
_reservations;
|
|
23
|
+
constructor(data, reservations = []) {
|
|
24
|
+
this._data = data;
|
|
25
|
+
this._reservations = reservations;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Available credits for the user.
|
|
29
|
+
*/
|
|
30
|
+
get available() {
|
|
31
|
+
return this._data.credits;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Credit quota for the user.
|
|
35
|
+
* Returns null if unlimited.
|
|
36
|
+
*/
|
|
37
|
+
get quota() {
|
|
38
|
+
return this._data.quota;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Last update timestamp.
|
|
42
|
+
*/
|
|
43
|
+
get lastUpdate() {
|
|
44
|
+
return this._data.last_update;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Active credit reservations.
|
|
48
|
+
*/
|
|
49
|
+
get reservations() {
|
|
50
|
+
return [...this._reservations];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Total reserved credits across all reservations.
|
|
54
|
+
*/
|
|
55
|
+
get totalReserved() {
|
|
56
|
+
return this._reservations.reduce((sum, r) => sum + r.credits, 0);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Net available credits (available minus reserved).
|
|
60
|
+
*/
|
|
61
|
+
get netAvailable() {
|
|
62
|
+
return Math.max(0, this.available - this.totalReserved);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get runtime reservations (reservations that start with 'runtime-').
|
|
66
|
+
*/
|
|
67
|
+
get runtimeReservations() {
|
|
68
|
+
return this._reservations.filter(r => r.id.startsWith('runtime-'));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if there are any active runtime reservations.
|
|
72
|
+
*/
|
|
73
|
+
get hasActiveRuntimes() {
|
|
74
|
+
return this.runtimeReservations.length > 0;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Calculate maximum runtime in minutes based on environment burning rate.
|
|
78
|
+
*
|
|
79
|
+
* @param burningRate - Credits consumed per hour
|
|
80
|
+
* @returns Maximum runtime in minutes
|
|
81
|
+
*/
|
|
82
|
+
calculateMaxRuntimeMinutes(burningRate) {
|
|
83
|
+
if (burningRate <= 0)
|
|
84
|
+
return 0;
|
|
85
|
+
const burningRatePerMinute = burningRate * 60;
|
|
86
|
+
return Math.floor(this.netAvailable / burningRatePerMinute);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Calculate credits needed for runtime duration.
|
|
90
|
+
*
|
|
91
|
+
* @param minutes - Runtime duration in minutes
|
|
92
|
+
* @param burningRate - Credits consumed per hour
|
|
93
|
+
* @returns Credits needed
|
|
94
|
+
*/
|
|
95
|
+
calculateCreditsFromMinutes(minutes, burningRate) {
|
|
96
|
+
const burningRatePerMinute = burningRate * 60;
|
|
97
|
+
return minutes * burningRatePerMinute;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if user has enough credits for runtime.
|
|
101
|
+
*
|
|
102
|
+
* @param minutes - Runtime duration in minutes
|
|
103
|
+
* @param burningRate - Credits consumed per hour
|
|
104
|
+
* @returns True if user has enough credits
|
|
105
|
+
*/
|
|
106
|
+
hasEnoughCreditsForRuntime(minutes, burningRate) {
|
|
107
|
+
const creditsNeeded = this.calculateCreditsFromMinutes(minutes, burningRate);
|
|
108
|
+
return this.netAvailable >= creditsNeeded;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Convert to JSON representation.
|
|
112
|
+
*/
|
|
113
|
+
toJSON() {
|
|
114
|
+
// FIXME
|
|
115
|
+
const obj = {
|
|
116
|
+
...this._data,
|
|
117
|
+
reservations: this._reservations,
|
|
118
|
+
};
|
|
119
|
+
validateJSON(obj, 'Credits');
|
|
120
|
+
return obj;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* String representation of credits.
|
|
124
|
+
*/
|
|
125
|
+
toString() {
|
|
126
|
+
const quotaStr = this.quota !== null ? ` of ${this.quota}` : '';
|
|
127
|
+
const reservedStr = this.totalReserved > 0 ? ` (${this.totalReserved} reserved)` : '';
|
|
128
|
+
return `Credits: ${this.available}${quotaStr}${reservedStr}`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment domain model for the Datalayer SDK.
|
|
3
|
+
*
|
|
4
|
+
* @module client/models/Environment
|
|
5
|
+
*/
|
|
6
|
+
import type { Environment as EnvironmentData } from '../../api/types/runtimes';
|
|
7
|
+
import type { DatalayerClient } from '../index';
|
|
8
|
+
/**
|
|
9
|
+
* Stable public interface for Environment data.
|
|
10
|
+
* This is the contract that SDK consumers can rely on.
|
|
11
|
+
* The raw API may change, but this interface remains stable.
|
|
12
|
+
*/
|
|
13
|
+
export interface EnvironmentJSON {
|
|
14
|
+
/** Human-readable title for the environment */
|
|
15
|
+
title: string;
|
|
16
|
+
/** Unique name identifier for the environment */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Credits consumed per hour for this environment */
|
|
19
|
+
burningRate: number;
|
|
20
|
+
/** Description of the environment (contains HTML markup) */
|
|
21
|
+
description: string;
|
|
22
|
+
/** Rich description of the environment (contains HTML markup) */
|
|
23
|
+
richDescription: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Environment domain model that wraps API responses with convenient methods.
|
|
27
|
+
* Provides information about available computational environments.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const environments = await sdk.listEnvironments();
|
|
32
|
+
* const aiEnv = environments.find(env => env.name === 'ai-env');
|
|
33
|
+
* console.log(aiEnv.title); // "AI Environment"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class Environment {
|
|
37
|
+
/** @internal */
|
|
38
|
+
_data: EnvironmentData;
|
|
39
|
+
/**
|
|
40
|
+
* Create an Environment instance.
|
|
41
|
+
*
|
|
42
|
+
* @param data - Environment data from API
|
|
43
|
+
* @param _sdk - SDK instance (not currently used but kept for consistency)
|
|
44
|
+
*/
|
|
45
|
+
constructor(data: EnvironmentData, _sdk: DatalayerClient);
|
|
46
|
+
/** Human-readable title for the environment (e.g., 'AI Environment', 'Python CPU Environment'). */
|
|
47
|
+
get title(): string;
|
|
48
|
+
/** Unique name identifier for the environment (e.g., 'ai-env', 'python-cpu-env'). */
|
|
49
|
+
get name(): string;
|
|
50
|
+
/** Credits consumed per hour for this environment. */
|
|
51
|
+
get burningRate(): number;
|
|
52
|
+
/** Rich description of the environment (contains HTML markup). */
|
|
53
|
+
get richDescription(): string;
|
|
54
|
+
/** Clean description without HTML tags. */
|
|
55
|
+
get description(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Get environment data in camelCase format.
|
|
58
|
+
* Returns only the core fields that consumers need.
|
|
59
|
+
* This provides a stable interface regardless of API changes.
|
|
60
|
+
*
|
|
61
|
+
* @returns Core environment data with camelCase properties
|
|
62
|
+
*/
|
|
63
|
+
toJSON(): EnvironmentJSON;
|
|
64
|
+
/**
|
|
65
|
+
* Get the raw environment data exactly as received from the API.
|
|
66
|
+
* This preserves the original snake_case naming from the API response.
|
|
67
|
+
*
|
|
68
|
+
* @returns Raw environment data from API
|
|
69
|
+
*/
|
|
70
|
+
rawData(): EnvironmentData;
|
|
71
|
+
/** String representation of the environment. */
|
|
72
|
+
toString(): string;
|
|
73
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
import { validateJSON } from '../../api/utils/validation';
|
|
6
|
+
/**
|
|
7
|
+
* Environment domain model that wraps API responses with convenient methods.
|
|
8
|
+
* Provides information about available computational environments.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const environments = await sdk.listEnvironments();
|
|
13
|
+
* const aiEnv = environments.find(env => env.name === 'ai-env');
|
|
14
|
+
* console.log(aiEnv.title); // "AI Environment"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class Environment {
|
|
18
|
+
/** @internal */
|
|
19
|
+
_data;
|
|
20
|
+
/**
|
|
21
|
+
* Create an Environment instance.
|
|
22
|
+
*
|
|
23
|
+
* @param data - Environment data from API
|
|
24
|
+
* @param _sdk - SDK instance (not currently used but kept for consistency)
|
|
25
|
+
*/
|
|
26
|
+
constructor(data, _sdk) {
|
|
27
|
+
this._data = data;
|
|
28
|
+
// SDK instance not currently used but kept for future extensibility
|
|
29
|
+
}
|
|
30
|
+
// ========================================================================
|
|
31
|
+
// Properties
|
|
32
|
+
// ========================================================================
|
|
33
|
+
/** Human-readable title for the environment (e.g., 'AI Environment', 'Python CPU Environment'). */
|
|
34
|
+
get title() {
|
|
35
|
+
return this._data.title;
|
|
36
|
+
}
|
|
37
|
+
/** Unique name identifier for the environment (e.g., 'ai-env', 'python-cpu-env'). */
|
|
38
|
+
get name() {
|
|
39
|
+
return this._data.name;
|
|
40
|
+
}
|
|
41
|
+
/** Credits consumed per hour for this environment. */
|
|
42
|
+
get burningRate() {
|
|
43
|
+
return this._data.burning_rate;
|
|
44
|
+
}
|
|
45
|
+
/** Rich description of the environment (contains HTML markup). */
|
|
46
|
+
get richDescription() {
|
|
47
|
+
return this._data.description;
|
|
48
|
+
}
|
|
49
|
+
/** Clean description without HTML tags. */
|
|
50
|
+
get description() {
|
|
51
|
+
// Simple HTML tag removal
|
|
52
|
+
return this._data.description.replace(/<[^>]*>/g, '').trim();
|
|
53
|
+
}
|
|
54
|
+
// ========================================================================
|
|
55
|
+
// Utility Methods
|
|
56
|
+
// ========================================================================
|
|
57
|
+
/**
|
|
58
|
+
* Get environment data in camelCase format.
|
|
59
|
+
* Returns only the core fields that consumers need.
|
|
60
|
+
* This provides a stable interface regardless of API changes.
|
|
61
|
+
*
|
|
62
|
+
* @returns Core environment data with camelCase properties
|
|
63
|
+
*/
|
|
64
|
+
toJSON() {
|
|
65
|
+
const obj = {
|
|
66
|
+
title: this.title,
|
|
67
|
+
name: this.name,
|
|
68
|
+
burningRate: this.burningRate,
|
|
69
|
+
description: this.description,
|
|
70
|
+
richDescription: this.richDescription,
|
|
71
|
+
};
|
|
72
|
+
validateJSON(obj, 'Environment');
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the raw environment data exactly as received from the API.
|
|
77
|
+
* This preserves the original snake_case naming from the API response.
|
|
78
|
+
*
|
|
79
|
+
* @returns Raw environment data from API
|
|
80
|
+
*/
|
|
81
|
+
rawData() {
|
|
82
|
+
return this._data;
|
|
83
|
+
}
|
|
84
|
+
/** String representation of the environment. */
|
|
85
|
+
toString() {
|
|
86
|
+
return `Environment(${this.name}, ${this.title})`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a health check response from a Datalayer service.
|
|
3
|
+
* Provides standardized health status information across all services.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HealthCheck {
|
|
6
|
+
healthy: boolean;
|
|
7
|
+
status: string;
|
|
8
|
+
responseTime: number;
|
|
9
|
+
errors: string[];
|
|
10
|
+
timestamp: Date;
|
|
11
|
+
/**
|
|
12
|
+
* Create a HealthCheck instance.
|
|
13
|
+
* @param data - The health check data
|
|
14
|
+
* @param sdk - Reference to the SDK instance (unused but kept for consistency)
|
|
15
|
+
*/
|
|
16
|
+
constructor(data: any, sdk: any);
|
|
17
|
+
/**
|
|
18
|
+
* Check if the service is healthy.
|
|
19
|
+
* @returns True if the service is healthy
|
|
20
|
+
*/
|
|
21
|
+
isHealthy(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get the service status.
|
|
24
|
+
* @returns The status string
|
|
25
|
+
*/
|
|
26
|
+
getStatus(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get the response time in milliseconds.
|
|
29
|
+
* @returns The response time
|
|
30
|
+
*/
|
|
31
|
+
getResponseTime(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Get any errors reported during the health check.
|
|
34
|
+
* @returns Array of error messages
|
|
35
|
+
*/
|
|
36
|
+
getErrors(): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Get the timestamp of the health check.
|
|
39
|
+
* @returns The timestamp
|
|
40
|
+
*/
|
|
41
|
+
getTimestamp(): Date;
|
|
42
|
+
/**
|
|
43
|
+
* Check if there are any errors.
|
|
44
|
+
* @returns True if there are errors
|
|
45
|
+
*/
|
|
46
|
+
hasErrors(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Get a human-readable summary of the health check.
|
|
49
|
+
* @returns Summary string
|
|
50
|
+
*/
|
|
51
|
+
getSummary(): string;
|
|
52
|
+
/**
|
|
53
|
+
* Convert to a plain object.
|
|
54
|
+
* @returns Plain object representation
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): Promise<HealthCheckJSON>;
|
|
57
|
+
/**
|
|
58
|
+
* Get a string representation.
|
|
59
|
+
* @returns String representation
|
|
60
|
+
*/
|
|
61
|
+
toString(): string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* JSON representation of a HealthCheck.
|
|
65
|
+
*/
|
|
66
|
+
export interface HealthCheckJSON {
|
|
67
|
+
healthy: boolean;
|
|
68
|
+
status: string;
|
|
69
|
+
responseTime: number;
|
|
70
|
+
errors: string[];
|
|
71
|
+
timestamp: string;
|
|
72
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
import { validateJSON } from '../../api/utils/validation';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a health check response from a Datalayer service.
|
|
8
|
+
* Provides standardized health status information across all services.
|
|
9
|
+
*/
|
|
10
|
+
export class HealthCheck {
|
|
11
|
+
// Properties
|
|
12
|
+
healthy;
|
|
13
|
+
status;
|
|
14
|
+
responseTime;
|
|
15
|
+
errors;
|
|
16
|
+
timestamp;
|
|
17
|
+
/**
|
|
18
|
+
* Create a HealthCheck instance.
|
|
19
|
+
* @param data - The health check data
|
|
20
|
+
* @param sdk - Reference to the SDK instance (unused but kept for consistency)
|
|
21
|
+
*/
|
|
22
|
+
constructor(data, sdk) {
|
|
23
|
+
// Initialize properties
|
|
24
|
+
this.healthy = data.healthy || false;
|
|
25
|
+
this.status = data.status || 'unknown';
|
|
26
|
+
this.responseTime = data.responseTime || 0;
|
|
27
|
+
this.errors = data.errors || [];
|
|
28
|
+
this.timestamp = data.timestamp ? new Date(data.timestamp) : new Date();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check if the service is healthy.
|
|
32
|
+
* @returns True if the service is healthy
|
|
33
|
+
*/
|
|
34
|
+
isHealthy() {
|
|
35
|
+
return this.healthy;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the service status.
|
|
39
|
+
* @returns The status string
|
|
40
|
+
*/
|
|
41
|
+
getStatus() {
|
|
42
|
+
return this.status;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the response time in milliseconds.
|
|
46
|
+
* @returns The response time
|
|
47
|
+
*/
|
|
48
|
+
getResponseTime() {
|
|
49
|
+
return this.responseTime;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get any errors reported during the health check.
|
|
53
|
+
* @returns Array of error messages
|
|
54
|
+
*/
|
|
55
|
+
getErrors() {
|
|
56
|
+
return this.errors;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the timestamp of the health check.
|
|
60
|
+
* @returns The timestamp
|
|
61
|
+
*/
|
|
62
|
+
getTimestamp() {
|
|
63
|
+
return this.timestamp;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if there are any errors.
|
|
67
|
+
* @returns True if there are errors
|
|
68
|
+
*/
|
|
69
|
+
hasErrors() {
|
|
70
|
+
return this.errors.length > 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get a human-readable summary of the health check.
|
|
74
|
+
* @returns Summary string
|
|
75
|
+
*/
|
|
76
|
+
getSummary() {
|
|
77
|
+
if (this.healthy) {
|
|
78
|
+
return `Service is healthy (${this.responseTime}ms response time)`;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const errorCount = this.errors.length;
|
|
82
|
+
return `Service is unhealthy: ${this.status} (${errorCount} error${errorCount !== 1 ? 's' : ''})`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convert to a plain object.
|
|
87
|
+
* @returns Plain object representation
|
|
88
|
+
*/
|
|
89
|
+
async toJSON() {
|
|
90
|
+
const obj = {
|
|
91
|
+
healthy: this.healthy,
|
|
92
|
+
status: this.status,
|
|
93
|
+
responseTime: this.responseTime,
|
|
94
|
+
errors: this.errors,
|
|
95
|
+
timestamp: this.timestamp.toISOString(),
|
|
96
|
+
};
|
|
97
|
+
validateJSON(obj, 'HealthCheck');
|
|
98
|
+
return obj;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get a string representation.
|
|
102
|
+
* @returns String representation
|
|
103
|
+
*/
|
|
104
|
+
toString() {
|
|
105
|
+
return `HealthCheck(${this.status}, healthy=${this.healthy}, responseTime=${this.responseTime}ms)`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DatalayerClient } from '../index';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for all Datalayer content items.
|
|
4
|
+
* Provides common functionality for content management including lifecycle tracking.
|
|
5
|
+
*
|
|
6
|
+
* @template TData - Raw data type from API
|
|
7
|
+
* @template TUpdateRequest - Update request type for API
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class Item<TData> {
|
|
10
|
+
protected _data: TData;
|
|
11
|
+
private _sdk;
|
|
12
|
+
private _deleted;
|
|
13
|
+
/**
|
|
14
|
+
* Create an Item instance.
|
|
15
|
+
* @param data - Item data from API
|
|
16
|
+
* @param sdk - SDK instance
|
|
17
|
+
*/
|
|
18
|
+
constructor(data: TData, sdk: DatalayerClient);
|
|
19
|
+
/** Check if this item has been deleted. */
|
|
20
|
+
get isDeleted(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if this item has been deleted and throw error if so.
|
|
23
|
+
* @throws Error if deleted
|
|
24
|
+
*/
|
|
25
|
+
protected _checkDeleted(): void;
|
|
26
|
+
/** Item ID. */
|
|
27
|
+
get id(): string;
|
|
28
|
+
/** Unique identifier for the item. */
|
|
29
|
+
get uid(): string;
|
|
30
|
+
/** Parent space ID. */
|
|
31
|
+
get spaceId(): string;
|
|
32
|
+
/** Owner user ID. */
|
|
33
|
+
get ownerId(): string;
|
|
34
|
+
/** When the item was created. */
|
|
35
|
+
get createdAt(): Date;
|
|
36
|
+
/** The cached update time. */
|
|
37
|
+
get updatedAt(): Date;
|
|
38
|
+
/** Get the item type identifier. */
|
|
39
|
+
abstract get type(): string;
|
|
40
|
+
/** The cached name. */
|
|
41
|
+
abstract get name(): string;
|
|
42
|
+
/** Get the current name from API. */
|
|
43
|
+
abstract getName(): Promise<string>;
|
|
44
|
+
/** The cached content. */
|
|
45
|
+
abstract get content(): any;
|
|
46
|
+
/** Get when the item was last updated from API. */
|
|
47
|
+
abstract getUpdatedAt(): Promise<Date>;
|
|
48
|
+
/** Update the item. */
|
|
49
|
+
abstract update(...args: any[]): Promise<this>;
|
|
50
|
+
/**
|
|
51
|
+
* Delete this item permanently.
|
|
52
|
+
* After deletion, all subsequent method calls will throw errors.
|
|
53
|
+
*/
|
|
54
|
+
delete(): Promise<void>;
|
|
55
|
+
/** Get the document content from API. */
|
|
56
|
+
getContent(): Promise<any>;
|
|
57
|
+
/** Get raw item data object. */
|
|
58
|
+
rawData(): TData;
|
|
59
|
+
/** Convert to JSON representation - must be implemented by subclasses. */
|
|
60
|
+
abstract toJSON(): any;
|
|
61
|
+
/** String representation of the item. */
|
|
62
|
+
toString(): string;
|
|
63
|
+
/** Get SDK token for API calls. */
|
|
64
|
+
protected _getToken(): string;
|
|
65
|
+
/** Get spacer API URL for API calls. */
|
|
66
|
+
protected _getSpacerRunUrl(): string;
|
|
67
|
+
/** Update internal data after API call. */
|
|
68
|
+
protected _updateData(newData: TData): void;
|
|
69
|
+
}
|