@sandbox-kit/daytona 0.1.0 → 0.1.2
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 +66 -31
- package/dist/checks/provider_checks.js +62 -75
- package/dist/config/provider_config.d.ts +1 -2
- package/dist/config/provider_config.js +9 -18
- package/dist/daytona.js +10 -10
- package/dist/errors.d.ts +10 -1
- package/dist/errors.js +35 -6
- package/dist/mappings/mappings.d.ts +1 -2
- package/dist/mappings/mappings.js +11 -13
- package/dist/mappings/provider_mappings.js +122 -97
- package/package.json +15 -3
- package/dist/mappings.d.ts +0 -8
- package/dist/mappings.js +0 -332
- package/dist/provider.checks.gen.d.ts +0 -3
- package/dist/provider.checks.gen.js +0 -91
- package/dist/provider.config.gen.d.ts +0 -5
- package/dist/provider.config.gen.js +0 -36
- package/dist/provider.errors.gen.d.ts +0 -3
- package/dist/provider.errors.gen.js +0 -78
- package/dist/provider.gen.d.ts +0 -14
- package/dist/provider.gen.js +0 -11
- package/dist/provider.mappings.gen.d.ts +0 -12
- package/dist/provider.mappings.gen.js +0 -275
- package/dist/provider_checks.d.ts +0 -3
- package/dist/provider_checks.js +0 -137
- package/dist/provider_config.d.ts +0 -5
- package/dist/provider_config.js +0 -49
- package/dist/provider_mappings.d.ts +0 -15
- package/dist/provider_mappings.js +0 -274
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
|
|
2
|
-
// source: kit/providers/daytona/v1/provider.proto + specs/providers/daytona.yaml
|
|
3
|
-
import { durationMs } from "@bufbuild/protobuf/wkt";
|
|
4
|
-
import { ErrorKind, PolicyMode, sandboxError } from "@sandbox-kit/sandbox";
|
|
5
|
-
export function validateProviderCreate(request) {
|
|
6
|
-
const value0_0 = request.runtime;
|
|
7
|
-
if (value0_0 !== undefined) {
|
|
8
|
-
const value0 = value0_0.language;
|
|
9
|
-
if (value0 !== undefined) {
|
|
10
|
-
if (value0 !== "python" && value0 !== "javascript" && value0 !== "typescript")
|
|
11
|
-
fail(ErrorKind.Unsupported, "runtime.language", "runtime.language is outside supported values");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const value1_0 = request.network;
|
|
15
|
-
if (value1_0 !== undefined) {
|
|
16
|
-
const value1 = value1_0.outboundProxyUrl;
|
|
17
|
-
if (value1 !== undefined) {
|
|
18
|
-
if (!validHttpUrl(value1))
|
|
19
|
-
fail(ErrorKind.InvalidArgument, "network.outboundProxyUrl", "network.outbound_proxy_url is outside supported values");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const value2_0 = request.network;
|
|
23
|
-
if (value2_0 !== undefined) {
|
|
24
|
-
const value2_1 = value2_0.outboundCidrs;
|
|
25
|
-
if (value2_1 !== undefined) {
|
|
26
|
-
for (const value2 of value2_1.entries ?? []) {
|
|
27
|
-
if (!validCidr(value2))
|
|
28
|
-
fail(ErrorKind.InvalidArgument, "network.outboundCidrs.entries", "network.outbound_cidrs.entries is outside supported values");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const value3_0 = request.network;
|
|
33
|
-
if (value3_0 !== undefined) {
|
|
34
|
-
const value3_1 = value3_0.outboundDomains;
|
|
35
|
-
if (value3_1 !== undefined) {
|
|
36
|
-
for (const value3 of value3_1.entries ?? []) {
|
|
37
|
-
if (!validDomain(value3))
|
|
38
|
-
fail(ErrorKind.InvalidArgument, "network.outboundDomains.entries", "network.outbound_domains.entries is outside supported values");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const value4_0 = request.security;
|
|
43
|
-
if (value4_0 !== undefined) {
|
|
44
|
-
for (const item4_1 of value4_0.secrets ?? []) {
|
|
45
|
-
const value4 = item4_1.environmentVariable;
|
|
46
|
-
if (value4 !== undefined) {
|
|
47
|
-
if (!validEnvName(value4))
|
|
48
|
-
fail(ErrorKind.InvalidArgument, "security.secrets.environmentVariable", "security.secrets.environment_variable is outside supported values");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (delayed(request.lifetime?.idleStop) && delayed(request.lifetime?.idlePause))
|
|
53
|
-
invalid("lifetime", "incompatible lifetime policies");
|
|
54
|
-
if (delayed(request.lifetime?.idlePause) && request.lifetime?.ephemeral === true)
|
|
55
|
-
invalid("lifetime", "incompatible lifetime policies");
|
|
56
|
-
if (delayed(request.lifetime?.idlePause) && immediate(request.lifetime?.stoppedDelete))
|
|
57
|
-
invalid("lifetime", "incompatible lifetime policies");
|
|
58
|
-
if (delayed(request.lifetime?.stoppedDelete) && request.lifetime?.ephemeral === true)
|
|
59
|
-
invalid("lifetime", "incompatible lifetime policies");
|
|
60
|
-
if (delayed(request.lifetime?.stoppedArchive) && request.lifetime?.ephemeral === true)
|
|
61
|
-
invalid("lifetime", "incompatible lifetime policies");
|
|
62
|
-
}
|
|
63
|
-
function delayed(policy) { return (policy?.mode ?? PolicyMode.Default) === PolicyMode.After && policy?.after !== undefined && durationMs(policy.after) > 0; }
|
|
64
|
-
function immediate(policy) { return (policy?.mode ?? PolicyMode.Default) === PolicyMode.After && policy?.after !== undefined && durationMs(policy.after) === 0; }
|
|
65
|
-
function validEnvName(value) { return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value); }
|
|
66
|
-
function validAbsolutePath(value) { return value.startsWith("/"); }
|
|
67
|
-
function validHttpUrl(value) { try {
|
|
68
|
-
const parsed = new URL(value);
|
|
69
|
-
return parsed.hostname !== "" && (parsed.protocol === "http:" || parsed.protocol === "https:");
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
return false;
|
|
73
|
-
} }
|
|
74
|
-
function validDomain(value) { const domain = value.startsWith("*.") ? value.slice(2) : value; return domain.length <= 253 && /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.?$/i.test(domain); }
|
|
75
|
-
function validCidr(value) { const separator = value.lastIndexOf("/"); if (separator <= 0)
|
|
76
|
-
return false; const address = value.slice(0, separator); const prefix = Number(value.slice(separator + 1)); if (!Number.isInteger(prefix))
|
|
77
|
-
return false; return address.includes(":") ? prefix >= 0 && prefix <= 128 && validIpv6(address) : prefix >= 0 && prefix <= 32 && validIpv4(address); }
|
|
78
|
-
function validIpv4(value) { const parts = value.split("."); return parts.length === 4 && parts.every((part) => /^(0|[1-9][0-9]{0,2})$/.test(part) && Number(part) <= 255); }
|
|
79
|
-
function validIpv6(value) { if ((value.match(/::/g)?.length ?? 0) > 1)
|
|
80
|
-
return false; const halves = value.split("::"); if (halves.length > 2)
|
|
81
|
-
return false; const count = (part) => { if (part === "")
|
|
82
|
-
return 0; const groups = part.split(":"); let total = 0; for (const group of groups) {
|
|
83
|
-
if (/^[0-9a-f]{1,4}$/i.test(group))
|
|
84
|
-
total++;
|
|
85
|
-
else if (validIpv4(group))
|
|
86
|
-
total += 2;
|
|
87
|
-
else
|
|
88
|
-
return undefined;
|
|
89
|
-
} return total; }; const left = count(halves[0] ?? ""); const right = count(halves[1] ?? ""); return left !== undefined && right !== undefined && (halves.length === 2 ? left + right < 8 : left === 8); }
|
|
90
|
-
function invalid(field, message) { fail(ErrorKind.InvalidArgument, field, message); }
|
|
91
|
-
function fail(kind, field, message) { throw sandboxError({ kind, provider: "daytona", operation: "create", field, message: "sandbox-kit daytona: " + message }); }
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { DaytonaConfig as NativeClientConfig } from "@daytona/sdk";
|
|
2
|
-
import { type ConfigWire } from "@sandbox-kit/sandbox";
|
|
3
|
-
export type Environment = Readonly<Record<string, string | undefined>>;
|
|
4
|
-
export declare function mapGeneratedClientConfig(config: ConfigWire, environment?: Environment): NativeClientConfig;
|
|
5
|
-
//# sourceMappingURL=provider.config.gen.d.ts.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
|
|
2
|
-
// source: kit/providers/daytona/v1/provider.proto + specs/providers/daytona.yaml
|
|
3
|
-
import { ErrorKind, sandboxError, validateConfig } from "@sandbox-kit/sandbox";
|
|
4
|
-
import { mapAPIKeyCredentials, mapBearerAuth, mapClientSettings, mapScope } from "./provider.mappings.gen.js";
|
|
5
|
-
export function mapGeneratedClientConfig(config, environment = environmentVariables()) {
|
|
6
|
-
let source = config;
|
|
7
|
-
if (source.endpoint === undefined)
|
|
8
|
-
source = { ...source, endpoint: environment.DAYTONA_API_URL ?? environment.DAYTONA_SERVER_URL ?? "https://app.daytona.io/api" };
|
|
9
|
-
validateConfig(source, "daytona", "initialize");
|
|
10
|
-
const target = mapClientSettings(source, "initialize");
|
|
11
|
-
if (source.scope !== undefined) {
|
|
12
|
-
const mapped = mapScope(source.scope, "initialize");
|
|
13
|
-
Object.assign(target, mapped);
|
|
14
|
-
if (source.scope.appName !== undefined)
|
|
15
|
-
unsupported("scope.appName", "unsupported client configuration field");
|
|
16
|
-
if (source.scope.environment !== undefined)
|
|
17
|
-
unsupported("scope.environment", "unsupported client configuration field");
|
|
18
|
-
if (source.scope.projectId !== undefined)
|
|
19
|
-
unsupported("scope.projectId", "unsupported client configuration field");
|
|
20
|
-
}
|
|
21
|
-
const credentials = source.auth?.credentials;
|
|
22
|
-
if (credentials?.case === "apiKey") {
|
|
23
|
-
const mapped = mapAPIKeyCredentials(credentials.value, "initialize");
|
|
24
|
-
Object.assign(target, mapped);
|
|
25
|
-
}
|
|
26
|
-
else if (credentials?.case === "bearerToken") {
|
|
27
|
-
const mapped = mapBearerAuth(credentials.value, "initialize");
|
|
28
|
-
Object.assign(target, mapped);
|
|
29
|
-
}
|
|
30
|
-
else if (credentials?.case !== undefined) {
|
|
31
|
-
unsupported("auth", "unsupported authentication mode");
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
}
|
|
35
|
-
function environmentVariables() { return globalThis.process?.env ?? {}; }
|
|
36
|
-
function unsupported(field, message) { throw sandboxError({ kind: ErrorKind.Unsupported, provider: "daytona", operation: "initialize", field, message: "sandbox-kit daytona: " + message }); }
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
|
|
2
|
-
// source: kit/providers/daytona/v1/provider.proto + specs/providers/daytona.yaml
|
|
3
|
-
import { DaytonaError } from "@daytona/sdk";
|
|
4
|
-
import { ErrorKind, SandboxError, sandboxError } from "@sandbox-kit/sandbox";
|
|
5
|
-
export function mapDaytonaError(error, operation) {
|
|
6
|
-
if (error instanceof SandboxError)
|
|
7
|
-
return error;
|
|
8
|
-
if (error instanceof DOMException && error.name === "AbortError")
|
|
9
|
-
return create(ErrorKind.Canceled, error, operation);
|
|
10
|
-
if (error instanceof DOMException && error.name === "TimeoutError")
|
|
11
|
-
return create(ErrorKind.Timeout, error, operation);
|
|
12
|
-
let kind = ErrorKind.Unknown;
|
|
13
|
-
let statusCode;
|
|
14
|
-
let providerCode;
|
|
15
|
-
let providerSource;
|
|
16
|
-
if (error instanceof DaytonaError) {
|
|
17
|
-
statusCode = error.statusCode;
|
|
18
|
-
providerCode = error.code;
|
|
19
|
-
providerSource = error.source;
|
|
20
|
-
if (kind === ErrorKind.Unknown)
|
|
21
|
-
switch (error.code) {
|
|
22
|
-
case "SANDBOX_SPOT_EVICTED":
|
|
23
|
-
kind = ErrorKind.Unavailable;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
if (kind === ErrorKind.Unknown)
|
|
27
|
-
switch (error.statusCode) {
|
|
28
|
-
case 400:
|
|
29
|
-
kind = ErrorKind.InvalidArgument;
|
|
30
|
-
break;
|
|
31
|
-
case 401:
|
|
32
|
-
kind = ErrorKind.Authentication;
|
|
33
|
-
break;
|
|
34
|
-
case 403:
|
|
35
|
-
kind = ErrorKind.PermissionDenied;
|
|
36
|
-
break;
|
|
37
|
-
case 404:
|
|
38
|
-
kind = ErrorKind.NotFound;
|
|
39
|
-
break;
|
|
40
|
-
case 408:
|
|
41
|
-
kind = ErrorKind.Timeout;
|
|
42
|
-
break;
|
|
43
|
-
case 409:
|
|
44
|
-
kind = ErrorKind.Conflict;
|
|
45
|
-
break;
|
|
46
|
-
case 410:
|
|
47
|
-
kind = ErrorKind.NotFound;
|
|
48
|
-
break;
|
|
49
|
-
case 412:
|
|
50
|
-
kind = ErrorKind.FailedPrecondition;
|
|
51
|
-
break;
|
|
52
|
-
case 422:
|
|
53
|
-
kind = ErrorKind.InvalidArgument;
|
|
54
|
-
break;
|
|
55
|
-
case 429:
|
|
56
|
-
kind = ErrorKind.RateLimited;
|
|
57
|
-
break;
|
|
58
|
-
case 500:
|
|
59
|
-
kind = ErrorKind.Internal;
|
|
60
|
-
break;
|
|
61
|
-
case 502:
|
|
62
|
-
kind = ErrorKind.Unavailable;
|
|
63
|
-
break;
|
|
64
|
-
case 503:
|
|
65
|
-
kind = ErrorKind.Unavailable;
|
|
66
|
-
break;
|
|
67
|
-
case 504:
|
|
68
|
-
kind = ErrorKind.Timeout;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
if (kind === ErrorKind.Unknown && error.statusCode === 0 && !error.code)
|
|
72
|
-
kind = ErrorKind.Unavailable;
|
|
73
|
-
}
|
|
74
|
-
return create(kind, error, operation, statusCode, providerCode, providerSource);
|
|
75
|
-
}
|
|
76
|
-
function create(kind, error, operation, statusCode, providerCode, providerSource) {
|
|
77
|
-
return sandboxError({ kind, provider: "daytona", operation, field: "", message: error instanceof Error ? error.message : "sandbox-kit daytona: provider operation failed", ...(statusCode === undefined ? {} : { statusCode }), ...(providerCode === undefined ? {} : { providerCode }), ...(providerSource === undefined ? {} : { providerSource }) }, error);
|
|
78
|
-
}
|
package/dist/provider.gen.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Backend, ConfigWire, CreateOptionsWire, CreateResult, OperationOptions, Provider } from "@sandbox-kit/sandbox";
|
|
2
|
-
export declare const providerName: "daytona";
|
|
3
|
-
/** @internal Shared generated provider identity wiring. */
|
|
4
|
-
export declare abstract class ProviderBase implements Provider {
|
|
5
|
-
readonly name: "daytona";
|
|
6
|
-
abstract initialize(config: ConfigWire): Backend;
|
|
7
|
-
}
|
|
8
|
-
/** @internal Shared generated backend identity and required operation surface. */
|
|
9
|
-
export declare abstract class BackendBase implements Backend {
|
|
10
|
-
readonly name: "daytona";
|
|
11
|
-
abstract create(request: CreateOptionsWire, options: OperationOptions): Promise<CreateResult>;
|
|
12
|
-
abstract close(options: OperationOptions): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=provider.gen.d.ts.map
|
package/dist/provider.gen.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
|
|
2
|
-
// source: kit/providers/daytona/v1/provider.proto + specs/providers/daytona.yaml
|
|
3
|
-
export const providerName = "daytona";
|
|
4
|
-
/** @internal Shared generated provider identity wiring. */
|
|
5
|
-
export class ProviderBase {
|
|
6
|
-
name = providerName;
|
|
7
|
-
}
|
|
8
|
-
/** @internal Shared generated backend identity and required operation surface. */
|
|
9
|
-
export class BackendBase {
|
|
10
|
-
name = providerName;
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type APIKeyCredentials, type BearerTokenCredentials, type ConfigWire, type CreateOptionsWire, type LifetimePolicy, type Resources, type SandboxInfo, type Scope } from "@sandbox-kit/sandbox";
|
|
2
|
-
import type { CreateSandboxBaseParams as NativeCreateSandboxBaseParams, DaytonaConfig as NativeDaytonaConfig, Resources as NativeResources, Sandbox as NativeSandbox } from "@daytona/sdk";
|
|
3
|
-
export declare function mapLifetimePolicies(source: LifetimePolicy | undefined, operation?: string): NativeCreateSandboxBaseParams;
|
|
4
|
-
export declare function mapCommonCreateFields(source: CreateOptionsWire | undefined, operation?: string): NativeCreateSandboxBaseParams;
|
|
5
|
-
export declare function mapResources(source: Resources | undefined, operation?: string): NativeResources;
|
|
6
|
-
export declare function mapSandboxInfo(source: NativeSandbox | undefined, operation?: string): Partial<SandboxInfo>;
|
|
7
|
-
export declare function mapAllocatedResources(source: NativeSandbox | undefined, operation?: string): Partial<Resources>;
|
|
8
|
-
export declare function mapClientSettings(source: ConfigWire | undefined, operation?: string): NativeDaytonaConfig;
|
|
9
|
-
export declare function mapAPIKeyCredentials(source: APIKeyCredentials | undefined, operation?: string): NativeDaytonaConfig;
|
|
10
|
-
export declare function mapBearerAuth(source: BearerTokenCredentials | undefined, operation?: string): NativeDaytonaConfig;
|
|
11
|
-
export declare function mapScope(source: Scope | undefined, operation?: string): NativeDaytonaConfig;
|
|
12
|
-
//# sourceMappingURL=provider.mappings.gen.d.ts.map
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
// Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
|
|
2
|
-
// source: kit/providers/daytona/v1/provider.proto + specs/providers/daytona.yaml
|
|
3
|
-
import { durationMs } from "@bufbuild/protobuf/wkt";
|
|
4
|
-
import { ErrorKind, PolicyMode, ValueOrigin, sandboxError } from "@sandbox-kit/sandbox";
|
|
5
|
-
export function mapLifetimePolicies(source, operation = "create") {
|
|
6
|
-
const target = {};
|
|
7
|
-
if (source === undefined)
|
|
8
|
-
return target;
|
|
9
|
-
if (source.idleStop !== undefined) {
|
|
10
|
-
const policy = source.idleStop;
|
|
11
|
-
const mode = policy.mode ?? PolicyMode.Default;
|
|
12
|
-
if (mode === PolicyMode.Disabled) {
|
|
13
|
-
target.autoStopInterval = 0;
|
|
14
|
-
}
|
|
15
|
-
else if (mode === PolicyMode.After) {
|
|
16
|
-
if (policy.after === undefined)
|
|
17
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.idle_stop", "duration is required", operation);
|
|
18
|
-
const afterMs = durationMs(policy.after);
|
|
19
|
-
if (afterMs === 0)
|
|
20
|
-
mappingError(ErrorKind.Unsupported, "lifetime.idle_stop", "immediate action is not representable", operation);
|
|
21
|
-
if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
|
|
22
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.idle_stop", "delay cannot be represented in whole minutes", operation);
|
|
23
|
-
const minutes = afterMs / 60_000;
|
|
24
|
-
target.autoStopInterval = minutes;
|
|
25
|
-
}
|
|
26
|
-
else if (mode !== PolicyMode.Default) {
|
|
27
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.idle_stop", "unknown policy mode", operation);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (source.idlePause !== undefined) {
|
|
31
|
-
const policy = source.idlePause;
|
|
32
|
-
const mode = policy.mode ?? PolicyMode.Default;
|
|
33
|
-
if (mode === PolicyMode.Disabled) {
|
|
34
|
-
target.autoPauseInterval = 0;
|
|
35
|
-
}
|
|
36
|
-
else if (mode === PolicyMode.After) {
|
|
37
|
-
if (policy.after === undefined)
|
|
38
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.idle_pause", "duration is required", operation);
|
|
39
|
-
const afterMs = durationMs(policy.after);
|
|
40
|
-
if (afterMs === 0)
|
|
41
|
-
mappingError(ErrorKind.Unsupported, "lifetime.idle_pause", "immediate action is not representable", operation);
|
|
42
|
-
if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
|
|
43
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.idle_pause", "delay cannot be represented in whole minutes", operation);
|
|
44
|
-
const minutes = afterMs / 60_000;
|
|
45
|
-
target.autoPauseInterval = minutes;
|
|
46
|
-
}
|
|
47
|
-
else if (mode !== PolicyMode.Default) {
|
|
48
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.idle_pause", "unknown policy mode", operation);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (source.stoppedArchive !== undefined) {
|
|
52
|
-
const policy = source.stoppedArchive;
|
|
53
|
-
const mode = policy.mode ?? PolicyMode.Default;
|
|
54
|
-
if (mode === PolicyMode.Disabled) {
|
|
55
|
-
mappingError(ErrorKind.Unsupported, "lifetime.stopped_archive", "explicit disabling is not representable", operation);
|
|
56
|
-
}
|
|
57
|
-
else if (mode === PolicyMode.After) {
|
|
58
|
-
if (policy.after === undefined)
|
|
59
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "duration is required", operation);
|
|
60
|
-
const afterMs = durationMs(policy.after);
|
|
61
|
-
if (afterMs === 0)
|
|
62
|
-
mappingError(ErrorKind.Unsupported, "lifetime.stopped_archive", "immediate action is not representable", operation);
|
|
63
|
-
if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
|
|
64
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "delay cannot be represented in whole minutes", operation);
|
|
65
|
-
const minutes = afterMs / 60_000;
|
|
66
|
-
if (minutes > 43200)
|
|
67
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "delay exceeds documented maximum", operation);
|
|
68
|
-
target.autoArchiveInterval = minutes;
|
|
69
|
-
}
|
|
70
|
-
else if (mode !== PolicyMode.Default) {
|
|
71
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "unknown policy mode", operation);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (source.stoppedDelete !== undefined) {
|
|
75
|
-
const policy = source.stoppedDelete;
|
|
76
|
-
const mode = policy.mode ?? PolicyMode.Default;
|
|
77
|
-
if (mode === PolicyMode.Disabled) {
|
|
78
|
-
mappingError(ErrorKind.Unsupported, "lifetime.stopped_delete", "explicit disabling is not representable", operation);
|
|
79
|
-
}
|
|
80
|
-
else if (mode === PolicyMode.After) {
|
|
81
|
-
if (policy.after === undefined)
|
|
82
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_delete", "duration is required", operation);
|
|
83
|
-
const afterMs = durationMs(policy.after);
|
|
84
|
-
if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
|
|
85
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_delete", "delay cannot be represented in whole minutes", operation);
|
|
86
|
-
const minutes = afterMs / 60_000;
|
|
87
|
-
target.autoDeleteInterval = minutes;
|
|
88
|
-
}
|
|
89
|
-
else if (mode !== PolicyMode.Default) {
|
|
90
|
-
mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_delete", "unknown policy mode", operation);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return target;
|
|
94
|
-
}
|
|
95
|
-
export function mapCommonCreateFields(source, operation = "create") {
|
|
96
|
-
const target = {};
|
|
97
|
-
if (source === undefined)
|
|
98
|
-
return target;
|
|
99
|
-
{
|
|
100
|
-
if (source.name !== undefined) {
|
|
101
|
-
const value = source.name;
|
|
102
|
-
target.name = value;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
{
|
|
106
|
-
if (source.environment !== undefined) {
|
|
107
|
-
const value = source.environment;
|
|
108
|
-
target.envVars = { ...value };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
{
|
|
112
|
-
if (source.labels !== undefined) {
|
|
113
|
-
const value = source.labels;
|
|
114
|
-
target.labels = { ...value };
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return target;
|
|
118
|
-
}
|
|
119
|
-
export function mapResources(source, operation = "create") {
|
|
120
|
-
const target = {};
|
|
121
|
-
if (source === undefined)
|
|
122
|
-
return target;
|
|
123
|
-
{
|
|
124
|
-
if (source.cpuCores !== undefined) {
|
|
125
|
-
const value = source.cpuCores;
|
|
126
|
-
if (!Number.isInteger(value) || value > 2147483647)
|
|
127
|
-
mappingError(ErrorKind.InvalidArgument, "resources.cpu_cores", "cpu_cores cannot be represented", operation);
|
|
128
|
-
target.cpu = Number(value);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
{
|
|
132
|
-
if (source.memoryMib !== undefined) {
|
|
133
|
-
const value = source.memoryMib;
|
|
134
|
-
if (value % 1024n !== 0n || value / 1024n > 2147483647n)
|
|
135
|
-
mappingError(ErrorKind.InvalidArgument, "resources.memory_mib", "memory_mib cannot be represented", operation);
|
|
136
|
-
target.memory = Number(value / 1024n);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
{
|
|
140
|
-
if (source.diskMib !== undefined) {
|
|
141
|
-
const value = source.diskMib;
|
|
142
|
-
if (value % 1024n !== 0n || value / 1024n > 2147483647n)
|
|
143
|
-
mappingError(ErrorKind.InvalidArgument, "resources.disk_mib", "disk_mib cannot be represented", operation);
|
|
144
|
-
target.disk = Number(value / 1024n);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return target;
|
|
148
|
-
}
|
|
149
|
-
export function mapSandboxInfo(source, operation = "create") {
|
|
150
|
-
const target = {};
|
|
151
|
-
if (source === undefined)
|
|
152
|
-
return target;
|
|
153
|
-
const origins = {};
|
|
154
|
-
target.origins = origins;
|
|
155
|
-
{
|
|
156
|
-
if (source.id !== undefined) {
|
|
157
|
-
const value = source.id;
|
|
158
|
-
target.id = value;
|
|
159
|
-
origins["id"] = ValueOrigin.Provider;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
{
|
|
163
|
-
if (source.name !== undefined) {
|
|
164
|
-
const value = source.name;
|
|
165
|
-
target.name = value;
|
|
166
|
-
origins["name"] = ValueOrigin.Provider;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
{
|
|
170
|
-
if (source.state !== undefined) {
|
|
171
|
-
const value = source.state;
|
|
172
|
-
target.providerState = String(value);
|
|
173
|
-
origins["provider_state"] = ValueOrigin.Provider;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
{
|
|
177
|
-
if (source.target !== undefined) {
|
|
178
|
-
const value = source.target;
|
|
179
|
-
target.region = value;
|
|
180
|
-
origins["region"] = ValueOrigin.Provider;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
{
|
|
184
|
-
if (source.labels !== undefined) {
|
|
185
|
-
const value = source.labels;
|
|
186
|
-
target.labels = { ...value };
|
|
187
|
-
origins["labels"] = ValueOrigin.Provider;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
target.provider = "daytona";
|
|
191
|
-
return target;
|
|
192
|
-
}
|
|
193
|
-
export function mapAllocatedResources(source, operation = "create") {
|
|
194
|
-
const target = {};
|
|
195
|
-
if (source === undefined)
|
|
196
|
-
return target;
|
|
197
|
-
if (!((source.cpu ?? 0) > 0 && (source.memory ?? 0) > 0 && (source.disk ?? 0) > 0))
|
|
198
|
-
return target;
|
|
199
|
-
{
|
|
200
|
-
if (source.cpu !== undefined) {
|
|
201
|
-
const value = source.cpu;
|
|
202
|
-
target.cpuCores = Number(value);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
{
|
|
206
|
-
if (source.memory !== undefined) {
|
|
207
|
-
const value = source.memory;
|
|
208
|
-
if (!Number.isSafeInteger(value) || value < 0)
|
|
209
|
-
mappingError(ErrorKind.InvalidResponse, "memory", "memory cannot be represented", operation);
|
|
210
|
-
target.memoryMib = BigInt(value) * 1024n;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
{
|
|
214
|
-
if (source.disk !== undefined) {
|
|
215
|
-
const value = source.disk;
|
|
216
|
-
if (!Number.isSafeInteger(value) || value < 0)
|
|
217
|
-
mappingError(ErrorKind.InvalidResponse, "disk", "disk cannot be represented", operation);
|
|
218
|
-
target.diskMib = BigInt(value) * 1024n;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return target;
|
|
222
|
-
}
|
|
223
|
-
export function mapClientSettings(source, operation = "initialize") {
|
|
224
|
-
const target = {};
|
|
225
|
-
if (source === undefined)
|
|
226
|
-
return target;
|
|
227
|
-
{
|
|
228
|
-
if (source.endpoint !== undefined) {
|
|
229
|
-
const value = source.endpoint;
|
|
230
|
-
target.apiUrl = value;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
{
|
|
234
|
-
if (source.region !== undefined) {
|
|
235
|
-
const value = source.region;
|
|
236
|
-
target.target = value;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return target;
|
|
240
|
-
}
|
|
241
|
-
export function mapAPIKeyCredentials(source, operation = "initialize") {
|
|
242
|
-
const target = {};
|
|
243
|
-
if (source === undefined)
|
|
244
|
-
return target;
|
|
245
|
-
{
|
|
246
|
-
const value = source.key;
|
|
247
|
-
target.apiKey = value;
|
|
248
|
-
}
|
|
249
|
-
return target;
|
|
250
|
-
}
|
|
251
|
-
export function mapBearerAuth(source, operation = "initialize") {
|
|
252
|
-
const target = {};
|
|
253
|
-
if (source === undefined)
|
|
254
|
-
return target;
|
|
255
|
-
{
|
|
256
|
-
const value = source.token;
|
|
257
|
-
target.jwtToken = value;
|
|
258
|
-
}
|
|
259
|
-
return target;
|
|
260
|
-
}
|
|
261
|
-
export function mapScope(source, operation = "initialize") {
|
|
262
|
-
const target = {};
|
|
263
|
-
if (source === undefined)
|
|
264
|
-
return target;
|
|
265
|
-
{
|
|
266
|
-
if (source.organizationId !== undefined) {
|
|
267
|
-
const value = source.organizationId;
|
|
268
|
-
target.organizationId = value;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return target;
|
|
272
|
-
}
|
|
273
|
-
function mappingError(kind, field, message, operation) {
|
|
274
|
-
throw sandboxError({ kind, provider: "daytona", operation, field, message: "sandbox-kit daytona: " + message });
|
|
275
|
-
}
|