@akashnetwork/chain-sdk 1.0.0-alpha.30 → 1.0.0-alpha.31
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/dist/cjs/bla.cjs +7 -0
- package/dist/cjs/bla.cjs.map +7 -0
- package/dist/cjs/generated/createNodeSDK.cjs +95 -76
- package/dist/cjs/generated/createNodeSDK.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/bme/v1/params.cjs +18 -2
- package/dist/cjs/generated/protos/akash/bme/v1/params.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/bme/v1/types.cjs +65 -2
- package/dist/cjs/generated/protos/akash/bme/v1/types.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/deployment/v1/deployment.cjs +68 -2
- package/dist/cjs/generated/protos/akash/deployment/v1/deployment.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/deployment/v1beta4/deploymentmsg.cjs +17 -2
- package/dist/cjs/generated/protos/akash/deployment/v1beta4/deploymentmsg.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/discovery/v1/akash.cjs +64 -2
- package/dist/cjs/generated/protos/akash/discovery/v1/akash.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/discovery/v1/client_info.cjs +150 -1
- package/dist/cjs/generated/protos/akash/discovery/v1/client_info.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/discovery/v1/service.cjs +115 -0
- package/dist/cjs/generated/protos/akash/discovery/v1/service.cjs.map +7 -0
- package/dist/cjs/generated/protos/akash/discovery/v1/service_akash.cjs +39 -0
- package/dist/cjs/generated/protos/akash/discovery/v1/service_akash.cjs.map +7 -0
- package/dist/cjs/generated/protos/akash/market/v1/event.cjs +93 -0
- package/dist/cjs/generated/protos/akash/market/v1/event.cjs.map +3 -3
- package/dist/cjs/generated/protos/akash/market/v1/lease.cjs +32 -2
- package/dist/cjs/generated/protos/akash/market/v1/lease.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/market/v1/reclamation.cjs +138 -0
- package/dist/cjs/generated/protos/akash/market/v1/reclamation.cjs.map +7 -0
- package/dist/cjs/generated/protos/akash/market/v1beta5/bid.cjs +25 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/bid.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/bidmsg.cjs +18 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/bidmsg.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/leasemsg.cjs +103 -0
- package/dist/cjs/generated/protos/akash/market/v1beta5/leasemsg.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/order.cjs +18 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/order.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/params.cjs +39 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/params.cjs.map +2 -2
- package/dist/cjs/generated/protos/akash/market/v1beta5/service_akash.cjs +8 -0
- package/dist/cjs/generated/protos/akash/market/v1beta5/service_akash.cjs.map +2 -2
- package/dist/cjs/generated/protos/index.akash.v1.cjs +9 -0
- package/dist/cjs/generated/protos/index.akash.v1.cjs.map +2 -2
- package/dist/cjs/generated/protos/index.akash.v1beta5.cjs +2 -0
- package/dist/cjs/generated/protos/index.akash.v1beta5.cjs.map +2 -2
- package/dist/cjs/network/config.cjs +3 -7
- package/dist/cjs/network/config.cjs.map +2 -2
- package/dist/cjs/sdk/provider/auth/jwt/types.cjs.map +1 -1
- package/dist/cjs/sdk/provider/auth/jwt/validateJwtPayload.cjs +1058 -1259
- package/dist/cjs/sdk/provider/auth/jwt/validateJwtPayload.cjs.map +2 -2
- package/dist/cjs/sdl/index.cjs +0 -4
- package/dist/cjs/sdl/index.cjs.map +2 -2
- package/dist/cjs/sdl/manifest/generateManifest.cjs +2 -3
- package/dist/cjs/sdl/manifest/generateManifest.cjs.map +2 -2
- package/dist/cjs/sdl/validateSDL/validateSDL.cjs +4 -36
- package/dist/cjs/sdl/validateSDL/validateSDL.cjs.map +2 -2
- package/dist/cjs/sdl/validateSDL/validateSDLInput.cjs +49 -50
- package/dist/cjs/sdl/validateSDL/validateSDLInput.cjs.map +2 -2
- package/dist/cjs/test.cjs +2 -0
- package/dist/cjs/test.cjs.map +7 -0
- package/dist/esm/{chunk-JAPXWQ3D.js → chunk-7XWZXYD2.js} +2 -2
- package/dist/esm/{chunk-5RTSSO7K.js → chunk-B7H4H62Z.js} +3 -3
- package/dist/esm/chunk-E4KEMLL4.js +413 -0
- package/dist/esm/chunk-E4KEMLL4.js.map +7 -0
- package/dist/esm/{chunk-H5WUFEMM.js → chunk-EG6EVQGI.js} +23 -5
- package/dist/esm/chunk-EG6EVQGI.js.map +7 -0
- package/dist/esm/{chunk-5YIS3XNX.js → chunk-EXKSXOV2.js} +2 -2
- package/dist/esm/{chunk-TXQ2BR6G.js → chunk-IFAXXMON.js} +126 -5
- package/dist/esm/chunk-IFAXXMON.js.map +7 -0
- package/dist/esm/chunk-IMR6WS6F.js +93 -0
- package/dist/esm/chunk-IMR6WS6F.js.map +7 -0
- package/dist/esm/{chunk-LKYHOABO.js → chunk-IPOIF4A2.js} +170 -37
- package/dist/esm/chunk-IPOIF4A2.js.map +7 -0
- package/dist/esm/{chunk-PFJG3V3A.js → chunk-ITPLCNJB.js} +84 -5
- package/dist/esm/chunk-ITPLCNJB.js.map +7 -0
- package/dist/esm/{chunk-YSOG5YCI.js → chunk-KM336UKV.js} +1203 -2125
- package/dist/esm/chunk-KM336UKV.js.map +7 -0
- package/dist/esm/{chunk-KFWTFROT.js → chunk-M5SAGBGR.js} +42 -3
- package/dist/esm/chunk-M5SAGBGR.js.map +7 -0
- package/dist/esm/{chunk-OHAEKHAC.js → chunk-NPGGO3JN.js} +37 -55
- package/dist/esm/chunk-NPGGO3JN.js.map +7 -0
- package/dist/esm/{chunk-HDAINZXA.js → chunk-RKOP2GYL.js} +50 -7
- package/dist/esm/chunk-RKOP2GYL.js.map +7 -0
- package/dist/esm/{chunk-VZZ4GN23.js → chunk-T5PKT4I6.js} +6 -4
- package/dist/esm/{chunk-VZZ4GN23.js.map → chunk-T5PKT4I6.js.map} +1 -1
- package/dist/esm/{chunk-B4MMOAAO.js → chunk-WI3EWXXI.js} +2 -2
- package/dist/esm/generated/protos/index.akash.v1.js +180 -182
- package/dist/esm/generated/protos/index.akash.v1.js.map +4 -4
- package/dist/esm/generated/protos/index.akash.v1beta1.js +7 -7
- package/dist/esm/generated/protos/index.akash.v1beta4.js +6 -4
- package/dist/esm/generated/protos/index.akash.v1beta5.js +10 -4
- package/dist/esm/generated/protos/index.akash.v1beta5.js.map +1 -1
- package/dist/esm/generated/protos/index.akash.v2.js +6 -6
- package/dist/esm/generated/protos/index.provider.akash.v1.js +16 -15
- package/dist/esm/index.js +10 -12
- package/dist/esm/index.web.js +9 -11
- package/dist/esm/{query_akash-3UBRLLRZ.js → query_akash-3IY2DKPB.js} +3 -3
- package/dist/esm/{query_akash-CKZRI7R6.js → query_akash-OKZLG4MG.js} +5 -3
- package/dist/esm/{query_akash-CKZRI7R6.js.map → query_akash-OKZLG4MG.js.map} +1 -1
- package/dist/esm/{query_akash-3LAHGVQJ.js → query_akash-ZITEPCYB.js} +6 -4
- package/dist/esm/{query_akash-3LAHGVQJ.js.map → query_akash-ZITEPCYB.js.map} +1 -1
- package/dist/esm/{service_akash-UFTUJDPM.js → service_akash-2CH5FJ4J.js} +3 -3
- package/dist/esm/{service_akash-5JSE44LJ.js → service_akash-BLDT6YCO.js} +5 -3
- package/dist/esm/{service_akash-5JSE44LJ.js.map → service_akash-BLDT6YCO.js.map} +1 -1
- package/dist/esm/{service_akash-QEN5EQUY.js → service_akash-DZETPXWM.js} +15 -4
- package/dist/esm/service_akash-DZETPXWM.js.map +7 -0
- package/dist/esm/service_akash-K7FWCKUQ.js +25 -0
- package/dist/esm/service_akash-K7FWCKUQ.js.map +7 -0
- package/dist/esm/{service_akash-FI6WXDZP.js → service_akash-VOFSDZEK.js} +4 -3
- package/dist/esm/{service_akash-FI6WXDZP.js.map → service_akash-VOFSDZEK.js.map} +1 -1
- package/dist/sdl-schema.yaml +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/bla.d.ts +1 -0
- package/dist/types/generated/createNodeSDK.d.ts +30 -0
- package/dist/types/generated/protos/akash/bme/v1/params.d.ts +5 -0
- package/dist/types/generated/protos/akash/bme/v1/types.d.ts +19 -1
- package/dist/types/generated/protos/akash/deployment/v1/deployment.d.ts +15 -0
- package/dist/types/generated/protos/akash/deployment/v1beta4/deploymentmsg.d.ts +6 -1
- package/dist/types/generated/protos/akash/discovery/v1/akash.d.ts +16 -2
- package/dist/types/generated/protos/akash/discovery/v1/client_info.d.ts +18 -0
- package/dist/types/generated/protos/akash/discovery/v1/service.d.ts +12 -0
- package/dist/types/generated/protos/akash/discovery/v1/service_akash.d.ts +13 -0
- package/dist/types/generated/protos/akash/market/v1/event.d.ts +11 -0
- package/dist/types/generated/protos/akash/market/v1/lease.d.ts +8 -0
- package/dist/types/generated/protos/akash/market/v1/reclamation.d.ts +22 -0
- package/dist/types/generated/protos/akash/market/v1beta5/bid.d.ts +3 -0
- package/dist/types/generated/protos/akash/market/v1beta5/bidmsg.d.ts +7 -0
- package/dist/types/generated/protos/akash/market/v1beta5/leasemsg.d.ts +12 -0
- package/dist/types/generated/protos/akash/market/v1beta5/order.d.ts +6 -0
- package/dist/types/generated/protos/akash/market/v1beta5/params.d.ts +5 -0
- package/dist/types/generated/protos/akash/market/v1beta5/service_akash.d.ts +7 -1
- package/dist/types/generated/protos/index.akash.v1.d.ts +5 -3
- package/dist/types/generated/protos/index.akash.v1beta5.d.ts +1 -1
- package/dist/types/network/config.d.ts +4 -5
- package/dist/types/sdk/chain/createChainNodeSDK.d.ts +6 -0
- package/dist/types/sdk/chain/createChainNodeWebSDK.d.ts +6 -0
- package/dist/types/sdk/chain/helpers.d.ts +1 -1
- package/dist/types/sdk/provider/auth/jwt/types.d.ts +4 -58
- package/dist/types/sdk/provider/auth/jwt/validateJwtPayload.d.ts +273 -225
- package/dist/types/sdl/index.d.ts +0 -2
- package/dist/types/sdl/manifest/generateManifest.d.ts +1 -2
- package/dist/types/sdl/validateSDL/validateSDL.d.ts +2 -3
- package/dist/types/sdl/validateSDL/validateSDLInput.d.ts +5 -5
- package/dist/types/test.d.ts +1 -0
- package/package.json +13 -15
- package/dist/cjs/sdl/SDL/SDL.cjs +0 -718
- package/dist/cjs/sdl/SDL/SDL.cjs.map +0 -7
- package/dist/cjs/sdl/SDL/SdlValidationError.cjs +0 -46
- package/dist/cjs/sdl/SDL/SdlValidationError.cjs.map +0 -7
- package/dist/esm/chunk-H5WUFEMM.js.map +0 -7
- package/dist/esm/chunk-HDAINZXA.js.map +0 -7
- package/dist/esm/chunk-KFWTFROT.js.map +0 -7
- package/dist/esm/chunk-LKYHOABO.js.map +0 -7
- package/dist/esm/chunk-OHAEKHAC.js.map +0 -7
- package/dist/esm/chunk-PFJG3V3A.js.map +0 -7
- package/dist/esm/chunk-TXQ2BR6G.js.map +0 -7
- package/dist/esm/chunk-YSOG5YCI.js.map +0 -7
- package/dist/esm/service_akash-QEN5EQUY.js.map +0 -7
- package/dist/types/sdl/SDL/SDL.d.ts +0 -439
- package/dist/types/sdl/SDL/SdlValidationError.d.ts +0 -18
- /package/dist/esm/{chunk-JAPXWQ3D.js.map → chunk-7XWZXYD2.js.map} +0 -0
- /package/dist/esm/{chunk-5RTSSO7K.js.map → chunk-B7H4H62Z.js.map} +0 -0
- /package/dist/esm/{chunk-5YIS3XNX.js.map → chunk-EXKSXOV2.js.map} +0 -0
- /package/dist/esm/{chunk-B4MMOAAO.js.map → chunk-WI3EWXXI.js.map} +0 -0
- /package/dist/esm/{query_akash-3UBRLLRZ.js.map → query_akash-3IY2DKPB.js.map} +0 -0
- /package/dist/esm/{service_akash-UFTUJDPM.js.map → service_akash-2CH5FJ4J.js.map} +0 -0
package/dist/cjs/sdl/SDL/SDL.cjs
DELETED
|
@@ -1,718 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __typeError = (msg) => {
|
|
9
|
-
throw TypeError(msg);
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
33
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
34
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
35
|
-
var SDL_exports = {};
|
|
36
|
-
__export(SDL_exports, {
|
|
37
|
-
SDL: () => SDL
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(SDL_exports);
|
|
40
|
-
var import_js_yaml = __toESM(require("js-yaml"), 1);
|
|
41
|
-
var import_json_stable_stringify = __toESM(require("json-stable-stringify"), 1);
|
|
42
|
-
var import_config = require("../../network/config.cjs");
|
|
43
|
-
var import_sizes = require("../sizes.cjs");
|
|
44
|
-
var import_validateSDL = require("../validateSDL/validateSDL.cjs");
|
|
45
|
-
var import_SdlValidationError = require("./SdlValidationError.cjs");
|
|
46
|
-
var _SDL_instances, escapeHtml_fn;
|
|
47
|
-
const Endpoint_SHARED_HTTP = 0;
|
|
48
|
-
const Endpoint_RANDOM_PORT = 1;
|
|
49
|
-
const Endpoint_LEASED_IP = 2;
|
|
50
|
-
function isArray(obj) {
|
|
51
|
-
return Array.isArray(obj);
|
|
52
|
-
}
|
|
53
|
-
function isString(str) {
|
|
54
|
-
return typeof str === "string";
|
|
55
|
-
}
|
|
56
|
-
const _SDL = class _SDL {
|
|
57
|
-
constructor(data, version = "beta2", networkId = import_config.MAINNET_ID) {
|
|
58
|
-
this.data = data;
|
|
59
|
-
this.version = version;
|
|
60
|
-
__privateAdd(this, _SDL_instances);
|
|
61
|
-
const errors = (0, import_validateSDL.validateSDL)(data, networkId);
|
|
62
|
-
if (errors) throw new import_SdlValidationError.SdlValidationError(errors[0].message);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Creates an SDL instance from a YAML string.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} yaml - The YAML string containing the SDL definition.
|
|
68
|
-
* @param {NetworkVersion} [version="beta3"] - The SDL version (beta2 or beta3).
|
|
69
|
-
* @param {NetworkId} [networkId=MAINNET_ID] - The network ID to validate against.
|
|
70
|
-
* @returns {SDL} An instance of the SDL class.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```ts
|
|
74
|
-
* const yaml = `
|
|
75
|
-
* version: "2.0"
|
|
76
|
-
* services:
|
|
77
|
-
* web:
|
|
78
|
-
* image: nginx
|
|
79
|
-
* expose:
|
|
80
|
-
* - port: 80
|
|
81
|
-
* as: 80
|
|
82
|
-
* to:
|
|
83
|
-
* - global: true
|
|
84
|
-
* `;
|
|
85
|
-
* const sdl = SDL.fromString(yaml);
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
static fromString(yaml, version = "beta3", networkId = import_config.MAINNET_ID) {
|
|
89
|
-
const data = import_js_yaml.default.load(yaml);
|
|
90
|
-
return new _SDL(data, version, networkId);
|
|
91
|
-
}
|
|
92
|
-
services() {
|
|
93
|
-
if (this.data) {
|
|
94
|
-
return this.data.services;
|
|
95
|
-
}
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
deployments() {
|
|
99
|
-
if (this.data) {
|
|
100
|
-
return this.data.deployment;
|
|
101
|
-
}
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
profiles() {
|
|
105
|
-
if (this.data) {
|
|
106
|
-
return this.data.profiles;
|
|
107
|
-
}
|
|
108
|
-
return {};
|
|
109
|
-
}
|
|
110
|
-
placements() {
|
|
111
|
-
const { placement } = this.data.profiles;
|
|
112
|
-
return placement || {};
|
|
113
|
-
}
|
|
114
|
-
serviceNames() {
|
|
115
|
-
const names = this.data ? Object.keys(this.data.services) : [];
|
|
116
|
-
return names;
|
|
117
|
-
}
|
|
118
|
-
deploymentsByPlacement(placement) {
|
|
119
|
-
const deployments = this.data ? this.data.deployment : [];
|
|
120
|
-
return Object.entries(deployments).filter(({ 1: deployment }) => Object.prototype.hasOwnProperty.call(deployment, placement));
|
|
121
|
-
}
|
|
122
|
-
resourceUnit(val, asString) {
|
|
123
|
-
return asString ? { val: `${(0, import_sizes.convertResourceString)(val)}` } : { val: (0, import_sizes.convertResourceString)(val) };
|
|
124
|
-
}
|
|
125
|
-
resourceValue(value, asString) {
|
|
126
|
-
if (value === null) {
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
129
|
-
const strVal = value.toString();
|
|
130
|
-
const encoder = new TextEncoder();
|
|
131
|
-
return asString ? strVal : encoder.encode(strVal);
|
|
132
|
-
}
|
|
133
|
-
serviceResourceCpu(resource) {
|
|
134
|
-
const units = isString(resource.units) ? (0, import_sizes.convertCpuResourceString)(resource.units) : resource.units * 1e3;
|
|
135
|
-
return resource.attributes ? {
|
|
136
|
-
units: { val: `${units}` },
|
|
137
|
-
attributes: this.serviceResourceAttributes(resource.attributes)
|
|
138
|
-
} : {
|
|
139
|
-
units: { val: `${units}` }
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
serviceResourceMemory(resource, asString) {
|
|
143
|
-
const key = asString ? "quantity" : "size";
|
|
144
|
-
return resource.attributes ? {
|
|
145
|
-
[key]: this.resourceUnit(resource.size, asString),
|
|
146
|
-
attributes: this.serviceResourceAttributes(resource.attributes)
|
|
147
|
-
} : {
|
|
148
|
-
[key]: this.resourceUnit(resource.size, asString)
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
serviceResourceStorage(resource, asString) {
|
|
152
|
-
const key = asString ? "quantity" : "size";
|
|
153
|
-
const storage = isArray(resource) ? resource : [resource];
|
|
154
|
-
return storage.map(
|
|
155
|
-
(storage2) => storage2.attributes ? {
|
|
156
|
-
name: storage2.name || "default",
|
|
157
|
-
[key]: this.resourceUnit(storage2.size, asString),
|
|
158
|
-
attributes: this.serviceResourceStorageAttributes(storage2.attributes)
|
|
159
|
-
} : {
|
|
160
|
-
name: storage2.name || "default",
|
|
161
|
-
[key]: this.resourceUnit(storage2.size, asString)
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
serviceResourceAttributes(attributes) {
|
|
166
|
-
return attributes && Object.keys(attributes).sort().map((key) => ({ key, value: attributes[key].toString() }));
|
|
167
|
-
}
|
|
168
|
-
serviceResourceStorageAttributes(attributes) {
|
|
169
|
-
if (!attributes) return void 0;
|
|
170
|
-
const pairs = Object.keys(attributes).map((key) => ({ key, value: attributes[key].toString() }));
|
|
171
|
-
if (attributes.class === "ram" && !("persistent" in attributes)) {
|
|
172
|
-
pairs.push({ key: "persistent", value: "false" });
|
|
173
|
-
}
|
|
174
|
-
pairs.sort((a, b) => a.key.localeCompare(b.key));
|
|
175
|
-
return pairs;
|
|
176
|
-
}
|
|
177
|
-
serviceResourceGpu(resource, asString) {
|
|
178
|
-
const value = resource?.units || 0;
|
|
179
|
-
const numVal = isString(value) ? Buffer.from(value, "ascii") : value;
|
|
180
|
-
const strVal = !isString(value) ? value.toString() : value;
|
|
181
|
-
return resource?.attributes ? {
|
|
182
|
-
units: asString ? { val: strVal } : { val: numVal },
|
|
183
|
-
attributes: this.transformGpuAttributes(resource?.attributes)
|
|
184
|
-
} : {
|
|
185
|
-
units: asString ? { val: strVal } : { val: numVal }
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
v2ServiceResourceEndpoints(service) {
|
|
189
|
-
const endpointSequenceNumbers = this.computeEndpointSequenceNumbers(this.data);
|
|
190
|
-
const endpoints = service.expose.flatMap(
|
|
191
|
-
(expose) => expose.to ? expose.to.filter((to) => to.global && to.ip?.length > 0).map((to) => ({
|
|
192
|
-
kind: Endpoint_LEASED_IP,
|
|
193
|
-
sequence_number: endpointSequenceNumbers[to.ip] || 0
|
|
194
|
-
})) : []
|
|
195
|
-
);
|
|
196
|
-
return endpoints.length > 0 ? endpoints : null;
|
|
197
|
-
}
|
|
198
|
-
v3ServiceResourceEndpoints(service) {
|
|
199
|
-
const endpointSequenceNumbers = this.computeEndpointSequenceNumbers(this.data);
|
|
200
|
-
const endpoints = service.expose.flatMap(
|
|
201
|
-
(expose) => expose.to ? expose.to.filter((to) => to.global).flatMap((to) => {
|
|
202
|
-
const exposeSpec = {
|
|
203
|
-
port: expose.port,
|
|
204
|
-
externalPort: expose.as || 0,
|
|
205
|
-
proto: this.parseServiceProto(expose.proto),
|
|
206
|
-
global: !!to.global
|
|
207
|
-
};
|
|
208
|
-
const kind = this.exposeShouldBeIngress(exposeSpec) ? Endpoint_SHARED_HTTP : Endpoint_RANDOM_PORT;
|
|
209
|
-
const defaultEp = kind !== 0 ? { kind, sequence_number: 0 } : { sequence_number: 0 };
|
|
210
|
-
const leasedEp = to.ip?.length > 0 ? {
|
|
211
|
-
kind: Endpoint_LEASED_IP,
|
|
212
|
-
sequence_number: endpointSequenceNumbers[to.ip] || 0
|
|
213
|
-
} : void 0;
|
|
214
|
-
return leasedEp ? [defaultEp, leasedEp] : [defaultEp];
|
|
215
|
-
}) : []
|
|
216
|
-
);
|
|
217
|
-
return endpoints;
|
|
218
|
-
}
|
|
219
|
-
serviceResourcesBeta2(profile, service, asString = false) {
|
|
220
|
-
return {
|
|
221
|
-
cpu: this.serviceResourceCpu(profile.resources.cpu),
|
|
222
|
-
memory: this.serviceResourceMemory(profile.resources.memory, asString),
|
|
223
|
-
storage: this.serviceResourceStorage(profile.resources.storage, asString),
|
|
224
|
-
endpoints: this.v2ServiceResourceEndpoints(service)
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
serviceResourcesBeta3(id, profile, service, asString = false) {
|
|
228
|
-
return {
|
|
229
|
-
id,
|
|
230
|
-
cpu: this.serviceResourceCpu(profile.resources.cpu),
|
|
231
|
-
memory: this.serviceResourceMemory(profile.resources.memory, asString),
|
|
232
|
-
storage: this.serviceResourceStorage(profile.resources.storage, asString),
|
|
233
|
-
gpu: this.serviceResourceGpu(profile.resources.gpu, asString),
|
|
234
|
-
endpoints: this.v3ServiceResourceEndpoints(service)
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Parses the service protocol.
|
|
239
|
-
*
|
|
240
|
-
* @param proto - The protocol string (e.g., "TCP", "UDP").
|
|
241
|
-
* @returns The parsed protocol.
|
|
242
|
-
* @throws Will throw an error if the protocol is unsupported.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```ts
|
|
246
|
-
* const protocol = SDL.parseServiceProto("TCP");
|
|
247
|
-
* // protocol is "TCP"
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
parseServiceProto(proto) {
|
|
251
|
-
const raw = proto?.toUpperCase() || "TCP";
|
|
252
|
-
if (raw === "TCP" || raw === "UDP") return raw;
|
|
253
|
-
throw new import_SdlValidationError.SdlValidationError(`Unsupported service protocol: "${proto}". Supported protocols are "TCP" and "UDP".`);
|
|
254
|
-
}
|
|
255
|
-
manifestExposeService(to) {
|
|
256
|
-
return to.service || "";
|
|
257
|
-
}
|
|
258
|
-
manifestExposeGlobal(to) {
|
|
259
|
-
return to.global || false;
|
|
260
|
-
}
|
|
261
|
-
manifestExposeHosts(expose) {
|
|
262
|
-
return expose.accept || null;
|
|
263
|
-
}
|
|
264
|
-
v2HttpOptions(http_options) {
|
|
265
|
-
const defaults = {
|
|
266
|
-
MaxBodySize: 1048576,
|
|
267
|
-
ReadTimeout: 6e4,
|
|
268
|
-
SendTimeout: 6e4,
|
|
269
|
-
NextTries: 3,
|
|
270
|
-
NextTimeout: 0,
|
|
271
|
-
NextCases: ["error", "timeout"]
|
|
272
|
-
};
|
|
273
|
-
if (!http_options) {
|
|
274
|
-
return { ...defaults };
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
MaxBodySize: http_options.max_body_size || defaults.MaxBodySize,
|
|
278
|
-
ReadTimeout: http_options.read_timeout || defaults.ReadTimeout,
|
|
279
|
-
SendTimeout: http_options.send_timeout || defaults.SendTimeout,
|
|
280
|
-
NextTries: http_options.next_tries || defaults.NextTries,
|
|
281
|
-
NextTimeout: http_options.next_timeout || defaults.NextTimeout,
|
|
282
|
-
NextCases: http_options.next_cases || defaults.NextCases
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
v3HttpOptions(http_options) {
|
|
286
|
-
const defaults = {
|
|
287
|
-
maxBodySize: 1048576,
|
|
288
|
-
readTimeout: 6e4,
|
|
289
|
-
sendTimeout: 6e4,
|
|
290
|
-
nextTries: 3,
|
|
291
|
-
nextTimeout: 0,
|
|
292
|
-
nextCases: ["error", "timeout"]
|
|
293
|
-
};
|
|
294
|
-
if (!http_options) {
|
|
295
|
-
return { ...defaults };
|
|
296
|
-
}
|
|
297
|
-
return {
|
|
298
|
-
maxBodySize: http_options.max_body_size || defaults.maxBodySize,
|
|
299
|
-
readTimeout: http_options.read_timeout || defaults.readTimeout,
|
|
300
|
-
sendTimeout: http_options.send_timeout || defaults.sendTimeout,
|
|
301
|
-
nextTries: http_options.next_tries || defaults.nextTries,
|
|
302
|
-
nextTimeout: http_options.next_timeout || defaults.nextTimeout,
|
|
303
|
-
nextCases: http_options.next_cases || defaults.nextCases
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
v2ManifestExposeHttpOptions(expose) {
|
|
307
|
-
return this.v2HttpOptions(expose.http_options);
|
|
308
|
-
}
|
|
309
|
-
v3ManifestExposeHttpOptions(expose) {
|
|
310
|
-
return this.v3HttpOptions(expose.http_options);
|
|
311
|
-
}
|
|
312
|
-
v2ManifestExpose(service) {
|
|
313
|
-
const endpointSequenceNumbers = this.computeEndpointSequenceNumbers(this.data);
|
|
314
|
-
return service.expose.flatMap(
|
|
315
|
-
(expose) => expose.to ? expose.to.map((to) => ({
|
|
316
|
-
Port: expose.port,
|
|
317
|
-
ExternalPort: expose.as || 0,
|
|
318
|
-
Proto: this.parseServiceProto(expose.proto),
|
|
319
|
-
Service: this.manifestExposeService(to),
|
|
320
|
-
Global: this.manifestExposeGlobal(to),
|
|
321
|
-
Hosts: this.manifestExposeHosts(expose),
|
|
322
|
-
HTTPOptions: this.v2ManifestExposeHttpOptions(expose),
|
|
323
|
-
IP: to.ip || "",
|
|
324
|
-
EndpointSequenceNumber: endpointSequenceNumbers[to.ip] || 0
|
|
325
|
-
})) : []
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
v3ManifestExpose(service) {
|
|
329
|
-
const endpointSequenceNumbers = this.computeEndpointSequenceNumbers(this.data);
|
|
330
|
-
return service.expose.flatMap(
|
|
331
|
-
(expose) => expose.to ? expose.to.map((to) => ({
|
|
332
|
-
port: expose.port,
|
|
333
|
-
externalPort: expose.as || 0,
|
|
334
|
-
proto: this.parseServiceProto(expose.proto),
|
|
335
|
-
service: this.manifestExposeService(to),
|
|
336
|
-
global: this.manifestExposeGlobal(to),
|
|
337
|
-
hosts: this.manifestExposeHosts(expose),
|
|
338
|
-
httpOptions: this.v3ManifestExposeHttpOptions(expose),
|
|
339
|
-
ip: to.ip || "",
|
|
340
|
-
endpointSequenceNumber: endpointSequenceNumbers[to.ip] || 0
|
|
341
|
-
})) : []
|
|
342
|
-
).sort((a, b) => {
|
|
343
|
-
if (a.service != b.service) return a.service.localeCompare(b.service);
|
|
344
|
-
if (a.port != b.port) return a.port - b.port;
|
|
345
|
-
if (a.proto != b.proto) return a.proto.localeCompare(b.proto);
|
|
346
|
-
if (a.global != b.global) return a.global ? -1 : 1;
|
|
347
|
-
return 0;
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
v2ManifestServiceParams(params) {
|
|
351
|
-
return {
|
|
352
|
-
Storage: Object.keys(params?.storage ?? {}).map((name) => {
|
|
353
|
-
if (!params?.storage) throw new Error("Storage is undefined");
|
|
354
|
-
return {
|
|
355
|
-
name,
|
|
356
|
-
mount: params.storage[name].mount,
|
|
357
|
-
readOnly: params.storage[name].readOnly || false
|
|
358
|
-
};
|
|
359
|
-
}),
|
|
360
|
-
...params?.permissions ? { Permissions: params.permissions } : {}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
v3ManifestServiceParams(params) {
|
|
364
|
-
if (params === void 0 || Object.keys(params).length === 0) {
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
const res = {
|
|
368
|
-
storage: params.storage && Object.keys(params.storage).length > 0 ? Object.keys(params.storage).map((name) => ({
|
|
369
|
-
name,
|
|
370
|
-
mount: params.storage[name]?.mount,
|
|
371
|
-
readOnly: params.storage[name]?.readOnly || false
|
|
372
|
-
})) : null
|
|
373
|
-
};
|
|
374
|
-
if (params.permissions) {
|
|
375
|
-
res.permissions = params.permissions;
|
|
376
|
-
}
|
|
377
|
-
return res;
|
|
378
|
-
}
|
|
379
|
-
v2ManifestService(placement, name, asString) {
|
|
380
|
-
const service = this.data.services[name];
|
|
381
|
-
const deployment = this.data.deployment[name];
|
|
382
|
-
const profile = this.data.profiles.compute[deployment[placement].profile];
|
|
383
|
-
const manifestService = {
|
|
384
|
-
Name: name,
|
|
385
|
-
Image: service.image,
|
|
386
|
-
Command: service.command || null,
|
|
387
|
-
Args: service.args || null,
|
|
388
|
-
Env: service.env || null,
|
|
389
|
-
Resources: this.serviceResourcesBeta2(profile, service, asString),
|
|
390
|
-
Count: deployment[placement].count,
|
|
391
|
-
Expose: this.v2ManifestExpose(service)
|
|
392
|
-
};
|
|
393
|
-
if (service.params) {
|
|
394
|
-
manifestService.params = this.v2ManifestServiceParams(service.params);
|
|
395
|
-
}
|
|
396
|
-
return manifestService;
|
|
397
|
-
}
|
|
398
|
-
v3ManifestService(id, placement, name, asString) {
|
|
399
|
-
const service = this.data.services[name];
|
|
400
|
-
const deployment = this.data.deployment[name];
|
|
401
|
-
const profile = this.data.profiles.compute[deployment[placement].profile];
|
|
402
|
-
const credentials = service.credentials || null;
|
|
403
|
-
if (credentials && !credentials.email) {
|
|
404
|
-
credentials.email = "";
|
|
405
|
-
}
|
|
406
|
-
const manifestService = {
|
|
407
|
-
name,
|
|
408
|
-
image: service.image,
|
|
409
|
-
command: service.command || null,
|
|
410
|
-
args: service.args || null,
|
|
411
|
-
env: service.env || null,
|
|
412
|
-
resources: this.serviceResourcesBeta3(id, profile, service, asString),
|
|
413
|
-
count: deployment[placement].count,
|
|
414
|
-
expose: this.v3ManifestExpose(service),
|
|
415
|
-
params: this.v3ManifestServiceParams(service.params),
|
|
416
|
-
credentials
|
|
417
|
-
};
|
|
418
|
-
if (!manifestService.params) {
|
|
419
|
-
delete manifestService.params;
|
|
420
|
-
}
|
|
421
|
-
return manifestService;
|
|
422
|
-
}
|
|
423
|
-
v2Manifest(asString = false) {
|
|
424
|
-
return Object.keys(this.placements()).map((name) => ({
|
|
425
|
-
Name: name,
|
|
426
|
-
Services: this.deploymentsByPlacement(name).map(([service]) => this.v2ManifestService(name, service, asString))
|
|
427
|
-
}));
|
|
428
|
-
}
|
|
429
|
-
v3Manifest(asString = false) {
|
|
430
|
-
const groups = this.v3Groups();
|
|
431
|
-
const serviceId = (pIdx, sIdx) => groups[pIdx].resources[sIdx].resource.id;
|
|
432
|
-
return Object.keys(this.placements()).map((name, pIdx) => ({
|
|
433
|
-
name,
|
|
434
|
-
services: this.deploymentsByPlacement(name).sort(([a], [b]) => a.localeCompare(b)).map(([service], idx) => this.v3ManifestService(serviceId(pIdx, idx), name, service, asString))
|
|
435
|
-
}));
|
|
436
|
-
}
|
|
437
|
-
manifest(asString = false) {
|
|
438
|
-
return this.version === "beta2" ? this.v2Manifest(asString) : this.v3Manifest(asString);
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Computes the endpoint sequence numbers for the given SDL.
|
|
442
|
-
*
|
|
443
|
-
* @param sdl - The SDL data.
|
|
444
|
-
* @returns An object mapping IPs to their sequence numbers.
|
|
445
|
-
*
|
|
446
|
-
* @example
|
|
447
|
-
* ```ts
|
|
448
|
-
* const sequenceNumbers = sdl.computeEndpointSequenceNumbers(sdlData);
|
|
449
|
-
* // sequenceNumbers might be { "192.168.1.1": 1, "192.168.1.2": 2 }
|
|
450
|
-
* ```
|
|
451
|
-
*/
|
|
452
|
-
computeEndpointSequenceNumbers(sdl) {
|
|
453
|
-
return Object.fromEntries(
|
|
454
|
-
Object.values(sdl.services).flatMap(
|
|
455
|
-
(service) => service.expose?.flatMap(
|
|
456
|
-
(expose) => expose.to ? expose.to.filter((to) => to.global && to.ip?.length > 0).map((to) => to.ip).sort().map((ip, index) => [ip, index + 1]) : []
|
|
457
|
-
) ?? []
|
|
458
|
-
)
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
resourceUnitCpu(computeResources, asString) {
|
|
462
|
-
const attributes = computeResources.cpu.attributes;
|
|
463
|
-
const cpu = isString(computeResources.cpu.units) ? (0, import_sizes.convertCpuResourceString)(computeResources.cpu.units) : computeResources.cpu.units * 1e3;
|
|
464
|
-
return {
|
|
465
|
-
units: { val: this.resourceValue(cpu, asString) },
|
|
466
|
-
attributes: attributes && Object.entries(attributes).sort(([k0], [k1]) => k0.localeCompare(k1)).map(([key, value]) => ({
|
|
467
|
-
key,
|
|
468
|
-
value: value.toString()
|
|
469
|
-
}))
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
resourceUnitMemory(computeResources, asString) {
|
|
473
|
-
const attributes = computeResources.memory.attributes;
|
|
474
|
-
return {
|
|
475
|
-
quantity: {
|
|
476
|
-
val: this.resourceValue((0, import_sizes.convertResourceString)(computeResources.memory.size), asString)
|
|
477
|
-
},
|
|
478
|
-
attributes: attributes && Object.entries(attributes).sort(([k0], [k1]) => k0.localeCompare(k1)).map(([key, value]) => ({
|
|
479
|
-
key,
|
|
480
|
-
value: value.toString()
|
|
481
|
-
}))
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
resourceUnitStorage(computeResources, asString) {
|
|
485
|
-
const storages = isArray(computeResources.storage) ? computeResources.storage : [computeResources.storage];
|
|
486
|
-
return storages.map((storage) => ({
|
|
487
|
-
name: storage.name || "default",
|
|
488
|
-
quantity: {
|
|
489
|
-
val: this.resourceValue((0, import_sizes.convertResourceString)(storage.size), asString)
|
|
490
|
-
},
|
|
491
|
-
attributes: this.serviceResourceStorageAttributes(storage.attributes)
|
|
492
|
-
}));
|
|
493
|
-
}
|
|
494
|
-
transformGpuAttributes(attributes) {
|
|
495
|
-
return Object.entries(attributes.vendor).flatMap(
|
|
496
|
-
([vendor, models]) => models ? models.map((model) => {
|
|
497
|
-
let key = `vendor/${vendor}/model/${model.model}`;
|
|
498
|
-
if (model.ram) {
|
|
499
|
-
key += `/ram/${model.ram}`;
|
|
500
|
-
}
|
|
501
|
-
if (model.interface) {
|
|
502
|
-
key += `/interface/${model.interface}`;
|
|
503
|
-
}
|
|
504
|
-
return {
|
|
505
|
-
key,
|
|
506
|
-
value: "true"
|
|
507
|
-
};
|
|
508
|
-
}) : [
|
|
509
|
-
{
|
|
510
|
-
key: `vendor/${vendor}/model/*`,
|
|
511
|
-
value: "true"
|
|
512
|
-
}
|
|
513
|
-
]
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
resourceUnitGpu(computeResources, asString) {
|
|
517
|
-
const attributes = computeResources.gpu?.attributes;
|
|
518
|
-
const units = computeResources.gpu?.units || "0";
|
|
519
|
-
const gpu = isString(units) ? parseInt(units) : units;
|
|
520
|
-
return {
|
|
521
|
-
units: { val: this.resourceValue(gpu, asString) },
|
|
522
|
-
attributes: attributes && this.transformGpuAttributes(attributes)
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
groupResourceUnits(resource, asString) {
|
|
526
|
-
if (!resource) return {};
|
|
527
|
-
const units = {
|
|
528
|
-
endpoints: null
|
|
529
|
-
};
|
|
530
|
-
if (resource.cpu) {
|
|
531
|
-
units.cpu = this.resourceUnitCpu(resource, asString);
|
|
532
|
-
}
|
|
533
|
-
if (resource.memory) {
|
|
534
|
-
units.memory = this.resourceUnitMemory(resource, asString);
|
|
535
|
-
}
|
|
536
|
-
if (resource.storage) {
|
|
537
|
-
units.storage = this.resourceUnitStorage(resource, asString);
|
|
538
|
-
}
|
|
539
|
-
if (this.version === "beta3") {
|
|
540
|
-
units.gpu = this.resourceUnitGpu(resource, asString);
|
|
541
|
-
}
|
|
542
|
-
return units;
|
|
543
|
-
}
|
|
544
|
-
exposeShouldBeIngress(expose) {
|
|
545
|
-
const externalPort = expose.externalPort === 0 ? expose.port : expose.externalPort;
|
|
546
|
-
return expose.global && expose.proto === "TCP" && externalPort === 80;
|
|
547
|
-
}
|
|
548
|
-
groups() {
|
|
549
|
-
return this.version === "beta2" ? this.v2Groups() : this.v3Groups();
|
|
550
|
-
}
|
|
551
|
-
v3Groups() {
|
|
552
|
-
const groups = /* @__PURE__ */ new Map();
|
|
553
|
-
const services = Object.entries(this.data.services).sort(([a], [b]) => a.localeCompare(b));
|
|
554
|
-
for (const [svcName, service] of services) {
|
|
555
|
-
for (const [placementName, svcdepl] of Object.entries(this.data.deployment[svcName])) {
|
|
556
|
-
const compute = this.data.profiles.compute[svcdepl.profile];
|
|
557
|
-
const infra = this.data.profiles.placement[placementName];
|
|
558
|
-
const pricing = infra.pricing[svcdepl.profile];
|
|
559
|
-
const price = {
|
|
560
|
-
...pricing,
|
|
561
|
-
amount: pricing.amount?.toString()
|
|
562
|
-
};
|
|
563
|
-
let group = groups.get(placementName);
|
|
564
|
-
if (!group) {
|
|
565
|
-
const attributes = infra.attributes ? Object.entries(infra.attributes).map(([key, value]) => ({
|
|
566
|
-
key,
|
|
567
|
-
value
|
|
568
|
-
})) : [];
|
|
569
|
-
attributes.sort((a, b) => a.key.localeCompare(b.key));
|
|
570
|
-
group = {
|
|
571
|
-
dgroup: {
|
|
572
|
-
name: placementName,
|
|
573
|
-
resources: [],
|
|
574
|
-
requirements: {
|
|
575
|
-
attributes,
|
|
576
|
-
signedBy: {
|
|
577
|
-
allOf: infra.signedBy?.allOf || [],
|
|
578
|
-
anyOf: infra.signedBy?.anyOf || []
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
boundComputes: {}
|
|
583
|
-
};
|
|
584
|
-
groups.set(placementName, group);
|
|
585
|
-
}
|
|
586
|
-
if (!group.boundComputes[placementName]) {
|
|
587
|
-
group.boundComputes[placementName] = {};
|
|
588
|
-
}
|
|
589
|
-
const location = group.boundComputes[placementName][svcdepl.profile];
|
|
590
|
-
if (!location) {
|
|
591
|
-
const res = this.groupResourceUnits(compute.resources, false);
|
|
592
|
-
res.endpoints = this.v3ServiceResourceEndpoints(service);
|
|
593
|
-
const resID = group.dgroup.resources.length > 0 ? group.dgroup.resources.length + 1 : 1;
|
|
594
|
-
res.id = resID;
|
|
595
|
-
group.dgroup.resources.push({
|
|
596
|
-
resource: res,
|
|
597
|
-
price,
|
|
598
|
-
count: svcdepl.count
|
|
599
|
-
});
|
|
600
|
-
group.boundComputes[placementName][svcdepl.profile] = group.dgroup.resources.length - 1;
|
|
601
|
-
} else {
|
|
602
|
-
const endpoints = this.v3ServiceResourceEndpoints(service);
|
|
603
|
-
group.dgroup.resources[location].count += svcdepl.count;
|
|
604
|
-
group.dgroup.resources[location].endpoints += endpoints;
|
|
605
|
-
group.dgroup.resources[location].endpoints.sort();
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
const names = [...groups.keys()].sort();
|
|
610
|
-
return names.map((name) => groups.get(name)).map((group) => group ? group.dgroup : {});
|
|
611
|
-
}
|
|
612
|
-
v2Groups() {
|
|
613
|
-
const yamlJson = this.data;
|
|
614
|
-
const ipEndpointNames = this.computeEndpointSequenceNumbers(yamlJson);
|
|
615
|
-
const groups = {};
|
|
616
|
-
Object.keys(yamlJson.services).forEach((svcName) => {
|
|
617
|
-
const svc = yamlJson.services[svcName];
|
|
618
|
-
const depl = yamlJson.deployment[svcName];
|
|
619
|
-
Object.keys(depl).forEach((placementName) => {
|
|
620
|
-
const svcdepl = depl[placementName];
|
|
621
|
-
const compute = yamlJson.profiles.compute[svcdepl.profile];
|
|
622
|
-
const infra = yamlJson.profiles.placement[placementName];
|
|
623
|
-
const pricing = infra.pricing[svcdepl.profile];
|
|
624
|
-
const price = {
|
|
625
|
-
...pricing,
|
|
626
|
-
amount: pricing.amount.toString()
|
|
627
|
-
};
|
|
628
|
-
let group = groups[placementName];
|
|
629
|
-
if (!group) {
|
|
630
|
-
group = {
|
|
631
|
-
name: placementName,
|
|
632
|
-
requirements: {
|
|
633
|
-
attributes: infra.attributes ? Object.entries(infra.attributes).map(([key, value]) => ({
|
|
634
|
-
key,
|
|
635
|
-
value
|
|
636
|
-
})) : [],
|
|
637
|
-
signedBy: {
|
|
638
|
-
allOf: infra.signedBy?.allOf || [],
|
|
639
|
-
anyOf: infra.signedBy?.anyOf || []
|
|
640
|
-
}
|
|
641
|
-
},
|
|
642
|
-
resources: []
|
|
643
|
-
};
|
|
644
|
-
if (group.requirements.attributes) {
|
|
645
|
-
group.requirements.attributes = group.requirements.attributes.sort((a, b) => a.key < b.key);
|
|
646
|
-
}
|
|
647
|
-
groups[group.name] = group;
|
|
648
|
-
}
|
|
649
|
-
const resources = {
|
|
650
|
-
resources: this.groupResourceUnits(compute.resources, false),
|
|
651
|
-
// Changed resources => unit
|
|
652
|
-
price,
|
|
653
|
-
count: svcdepl.count
|
|
654
|
-
};
|
|
655
|
-
const endpoints = [];
|
|
656
|
-
svc?.expose?.forEach((expose) => {
|
|
657
|
-
expose?.to?.filter((to) => to.global).forEach((to) => {
|
|
658
|
-
const exposeSpec = {
|
|
659
|
-
port: expose.port,
|
|
660
|
-
externalPort: expose.as || 0,
|
|
661
|
-
proto: this.parseServiceProto(expose.proto),
|
|
662
|
-
global: !!to.global
|
|
663
|
-
};
|
|
664
|
-
if (to.ip?.length > 0) {
|
|
665
|
-
const seqNo = ipEndpointNames[to.ip];
|
|
666
|
-
endpoints.push({
|
|
667
|
-
kind: Endpoint_LEASED_IP,
|
|
668
|
-
sequence_number: seqNo
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
const kind = this.exposeShouldBeIngress(exposeSpec) ? Endpoint_SHARED_HTTP : Endpoint_RANDOM_PORT;
|
|
672
|
-
endpoints.push({ kind, sequence_number: 0 });
|
|
673
|
-
});
|
|
674
|
-
});
|
|
675
|
-
resources.resources.endpoints = endpoints;
|
|
676
|
-
group.resources.push(resources);
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
return Object.keys(groups).sort((a, b) => a < b ? 1 : 0).map((name) => groups[name]);
|
|
680
|
-
}
|
|
681
|
-
manifestSortedJSON() {
|
|
682
|
-
const manifest = this.manifest(true);
|
|
683
|
-
let jsonStr = JSON.stringify(manifest);
|
|
684
|
-
if (jsonStr) {
|
|
685
|
-
jsonStr = jsonStr.replaceAll('"quantity":{"val', '"size":{"val');
|
|
686
|
-
}
|
|
687
|
-
return __privateMethod(this, _SDL_instances, escapeHtml_fn).call(this, (0, import_json_stable_stringify.default)(JSON.parse(jsonStr)) || "");
|
|
688
|
-
}
|
|
689
|
-
async manifestVersion() {
|
|
690
|
-
const jsonStr = this.manifestSortedJSON();
|
|
691
|
-
const enc = new TextEncoder();
|
|
692
|
-
const sortedBytes = enc.encode(jsonStr);
|
|
693
|
-
const sum = await crypto.subtle.digest("SHA-256", sortedBytes);
|
|
694
|
-
return new Uint8Array(sum);
|
|
695
|
-
}
|
|
696
|
-
manifestSorted() {
|
|
697
|
-
const sorted = this.manifestSortedJSON();
|
|
698
|
-
return JSON.parse(sorted);
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
_SDL_instances = new WeakSet();
|
|
702
|
-
/**
|
|
703
|
-
* Escapes HTML characters in a string.
|
|
704
|
-
*
|
|
705
|
-
* @param raw - The raw string to escape.
|
|
706
|
-
* @returns The escaped string.
|
|
707
|
-
*
|
|
708
|
-
* @example
|
|
709
|
-
* ```ts
|
|
710
|
-
* const escaped = sdl.escapeHtml("<div>Hello</div>");
|
|
711
|
-
* // escaped is "\\u003cdiv\\u003eHello\\u003c/div\\u003e"
|
|
712
|
-
* ```
|
|
713
|
-
*/
|
|
714
|
-
escapeHtml_fn = function(raw) {
|
|
715
|
-
return raw.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
716
|
-
};
|
|
717
|
-
let SDL = _SDL;
|
|
718
|
-
//# sourceMappingURL=SDL.cjs.map
|