@quantum-hub/qhubctl 1.0.0
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/LICENSE +201 -0
- package/README.md +41 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +15 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +12 -0
- package/dist/client/kqh/apis/ServicePlatformApplicationsApi.d.ts +89 -0
- package/dist/client/kqh/apis/ServicePlatformApplicationsApi.js +259 -0
- package/dist/client/kqh/apis/ServicePlatformDashboardApi.d.ts +44 -0
- package/dist/client/kqh/apis/ServicePlatformDashboardApi.js +143 -0
- package/dist/client/kqh/apis/ServicePlatformDataPoolsApi.d.ts +133 -0
- package/dist/client/kqh/apis/ServicePlatformDataPoolsApi.js +410 -0
- package/dist/client/kqh/apis/ServicePlatformJobsApi.d.ts +101 -0
- package/dist/client/kqh/apis/ServicePlatformJobsApi.js +298 -0
- package/dist/client/kqh/apis/ServicePlatformMarketplaceApi.d.ts +48 -0
- package/dist/client/kqh/apis/ServicePlatformMarketplaceApi.js +152 -0
- package/dist/client/kqh/apis/ServicePlatformMeteringAPIApi.d.ts +29 -0
- package/dist/client/kqh/apis/ServicePlatformMeteringAPIApi.js +90 -0
- package/dist/client/kqh/apis/ServicePlatformServicesApi.d.ts +501 -0
- package/dist/client/kqh/apis/ServicePlatformServicesApi.js +1509 -0
- package/dist/client/kqh/apis/ServicePlatformSubscriptionsApi.d.ts +66 -0
- package/dist/client/kqh/apis/ServicePlatformSubscriptionsApi.js +194 -0
- package/dist/client/kqh/apis/TaxonomiesApi.d.ts +90 -0
- package/dist/client/kqh/apis/TaxonomiesApi.js +309 -0
- package/dist/client/kqh/apis/index.d.ts +9 -0
- package/dist/client/kqh/apis/index.js +27 -0
- package/dist/client/kqh/index.d.ts +3 -0
- package/dist/client/kqh/index.js +21 -0
- package/dist/client/kqh/models/AccessTokenDto.d.ts +81 -0
- package/dist/client/kqh/models/AccessTokenDto.js +66 -0
- package/dist/client/kqh/models/AmountMajorDto.d.ts +37 -0
- package/dist/client/kqh/models/AmountMajorDto.js +46 -0
- package/dist/client/kqh/models/ApiDto.d.ts +144 -0
- package/dist/client/kqh/models/ApiDto.js +99 -0
- package/dist/client/kqh/models/ApiOverviewDto.d.ts +119 -0
- package/dist/client/kqh/models/ApiOverviewDto.js +90 -0
- package/dist/client/kqh/models/ApplicationDto.d.ts +64 -0
- package/dist/client/kqh/models/ApplicationDto.js +60 -0
- package/dist/client/kqh/models/BuildJobDto.d.ts +75 -0
- package/dist/client/kqh/models/BuildJobDto.js +71 -0
- package/dist/client/kqh/models/CpuConfiguration.d.ts +38 -0
- package/dist/client/kqh/models/CpuConfiguration.js +49 -0
- package/dist/client/kqh/models/CreateApplicationRequest.d.ts +31 -0
- package/dist/client/kqh/models/CreateApplicationRequest.js +44 -0
- package/dist/client/kqh/models/CreateDataPoolRequest.d.ts +31 -0
- package/dist/client/kqh/models/CreateDataPoolRequest.js +46 -0
- package/dist/client/kqh/models/CreateExternalServicePricingPlanRequest.d.ts +46 -0
- package/dist/client/kqh/models/CreateExternalServicePricingPlanRequest.js +57 -0
- package/dist/client/kqh/models/CreateJobRequest.d.ts +62 -0
- package/dist/client/kqh/models/CreateJobRequest.js +57 -0
- package/dist/client/kqh/models/CreateManagedServicePricingPlanRequest.d.ts +73 -0
- package/dist/client/kqh/models/CreateManagedServicePricingPlanRequest.js +79 -0
- package/dist/client/kqh/models/CreateProductRequest.d.ts +43 -0
- package/dist/client/kqh/models/CreateProductRequest.js +52 -0
- package/dist/client/kqh/models/CreateSubscriptionRequest.d.ts +37 -0
- package/dist/client/kqh/models/CreateSubscriptionRequest.js +50 -0
- package/dist/client/kqh/models/CreateWorkflowServiceRequest.d.ts +37 -0
- package/dist/client/kqh/models/CreateWorkflowServiceRequest.js +48 -0
- package/dist/client/kqh/models/DataPoolDto.d.ts +166 -0
- package/dist/client/kqh/models/DataPoolDto.js +105 -0
- package/dist/client/kqh/models/DataPoolRef.d.ts +43 -0
- package/dist/client/kqh/models/DataPoolRef.js +48 -0
- package/dist/client/kqh/models/DataSourceDescriptorDto.d.ts +89 -0
- package/dist/client/kqh/models/DataSourceDescriptorDto.js +69 -0
- package/dist/client/kqh/models/FileDto.d.ts +73 -0
- package/dist/client/kqh/models/FileDto.js +51 -0
- package/dist/client/kqh/models/FileSource.d.ts +26 -0
- package/dist/client/kqh/models/FileSource.js +34 -0
- package/dist/client/kqh/models/GpuConfiguration.d.ts +49 -0
- package/dist/client/kqh/models/GpuConfiguration.js +60 -0
- package/dist/client/kqh/models/JobDto.d.ts +117 -0
- package/dist/client/kqh/models/JobDto.js +82 -0
- package/dist/client/kqh/models/JobOverviewDto.d.ts +74 -0
- package/dist/client/kqh/models/JobOverviewDto.js +67 -0
- package/dist/client/kqh/models/MemoryConfiguration.d.ts +38 -0
- package/dist/client/kqh/models/MemoryConfiguration.js +49 -0
- package/dist/client/kqh/models/MeteringRequest.d.ts +43 -0
- package/dist/client/kqh/models/MeteringRequest.js +48 -0
- package/dist/client/kqh/models/MeteringResponse.d.ts +49 -0
- package/dist/client/kqh/models/MeteringResponse.js +50 -0
- package/dist/client/kqh/models/MonthAmountDto.d.ts +51 -0
- package/dist/client/kqh/models/MonthAmountDto.js +52 -0
- package/dist/client/kqh/models/OwnerDto.d.ts +67 -0
- package/dist/client/kqh/models/OwnerDto.js +56 -0
- package/dist/client/kqh/models/PageDataPoolDto.d.ts +94 -0
- package/dist/client/kqh/models/PageDataPoolDto.js +67 -0
- package/dist/client/kqh/models/PageableObject.d.ts +62 -0
- package/dist/client/kqh/models/PageableObject.js +55 -0
- package/dist/client/kqh/models/PricingPlanDto.d.ts +52 -0
- package/dist/client/kqh/models/PricingPlanDto.js +57 -0
- package/dist/client/kqh/models/ProductAmountDto.d.ts +38 -0
- package/dist/client/kqh/models/ProductAmountDto.js +47 -0
- package/dist/client/kqh/models/ProductDto.d.ts +83 -0
- package/dist/client/kqh/models/ProductDto.js +76 -0
- package/dist/client/kqh/models/ProductGroupDto.d.ts +45 -0
- package/dist/client/kqh/models/ProductGroupDto.js +50 -0
- package/dist/client/kqh/models/ProductUsageDto.d.ts +61 -0
- package/dist/client/kqh/models/ProductUsageDto.js +54 -0
- package/dist/client/kqh/models/RegistrySource.d.ts +52 -0
- package/dist/client/kqh/models/RegistrySource.js +55 -0
- package/dist/client/kqh/models/RepositorySource.d.ts +32 -0
- package/dist/client/kqh/models/RepositorySource.js +47 -0
- package/dist/client/kqh/models/ResourceConfiguration.d.ts +31 -0
- package/dist/client/kqh/models/ResourceConfiguration.js +58 -0
- package/dist/client/kqh/models/ReviewDto.d.ts +51 -0
- package/dist/client/kqh/models/ReviewDto.js +56 -0
- package/dist/client/kqh/models/RuntimeConfiguration.d.ts +53 -0
- package/dist/client/kqh/models/RuntimeConfiguration.js +56 -0
- package/dist/client/kqh/models/ServiceDefinitionCommand.d.ts +39 -0
- package/dist/client/kqh/models/ServiceDefinitionCommand.js +52 -0
- package/dist/client/kqh/models/ServiceDefinitionDto.d.ts +180 -0
- package/dist/client/kqh/models/ServiceDefinitionDto.js +108 -0
- package/dist/client/kqh/models/ServiceDefinitionDtoSource.d.ts +23 -0
- package/dist/client/kqh/models/ServiceDefinitionDtoSource.js +54 -0
- package/dist/client/kqh/models/ServiceDefinitionOverviewDto.d.ts +79 -0
- package/dist/client/kqh/models/ServiceDefinitionOverviewDto.js +71 -0
- package/dist/client/kqh/models/ServiceDto.d.ts +59 -0
- package/dist/client/kqh/models/ServiceDto.js +59 -0
- package/dist/client/kqh/models/ServiceExecutionConsumerDto.d.ts +67 -0
- package/dist/client/kqh/models/ServiceExecutionConsumerDto.js +64 -0
- package/dist/client/kqh/models/ServiceExecutionDto.d.ts +49 -0
- package/dist/client/kqh/models/ServiceExecutionDto.js +50 -0
- package/dist/client/kqh/models/ServiceOverviewDto.d.ts +115 -0
- package/dist/client/kqh/models/ServiceOverviewDto.js +92 -0
- package/dist/client/kqh/models/ServiceSource.d.ts +31 -0
- package/dist/client/kqh/models/ServiceSource.js +58 -0
- package/dist/client/kqh/models/SortObject.d.ts +43 -0
- package/dist/client/kqh/models/SortObject.js +48 -0
- package/dist/client/kqh/models/SubscriptionDto.d.ts +58 -0
- package/dist/client/kqh/models/SubscriptionDto.js +55 -0
- package/dist/client/kqh/models/TaxonomyElement.d.ts +43 -0
- package/dist/client/kqh/models/TaxonomyElement.js +48 -0
- package/dist/client/kqh/models/UpdateDataPoolRequest.d.ts +109 -0
- package/dist/client/kqh/models/UpdateDataPoolRequest.js +72 -0
- package/dist/client/kqh/models/UpdateResourceConfigurationRequest.d.ts +23 -0
- package/dist/client/kqh/models/UpdateResourceConfigurationRequest.js +54 -0
- package/dist/client/kqh/models/UpdateVersionRequest.d.ts +44 -0
- package/dist/client/kqh/models/UpdateVersionRequest.js +49 -0
- package/dist/client/kqh/models/UpdateWorkflowServiceRequest.d.ts +31 -0
- package/dist/client/kqh/models/UpdateWorkflowServiceRequest.js +44 -0
- package/dist/client/kqh/models/ValidationResult.d.ts +52 -0
- package/dist/client/kqh/models/ValidationResult.js +57 -0
- package/dist/client/kqh/models/index.d.ts +57 -0
- package/dist/client/kqh/models/index.js +75 -0
- package/dist/client/kqh/runtime.d.ts +181 -0
- package/dist/client/kqh/runtime.js +340 -0
- package/dist/client/users/apis/AuthenticationApi.d.ts +31 -0
- package/dist/client/users/apis/AuthenticationApi.js +83 -0
- package/dist/client/users/apis/ExpertsApi.d.ts +44 -0
- package/dist/client/users/apis/ExpertsApi.js +112 -0
- package/dist/client/users/apis/SearchApi.d.ts +46 -0
- package/dist/client/users/apis/SearchApi.js +134 -0
- package/dist/client/users/apis/UserSettingsApi.d.ts +139 -0
- package/dist/client/users/apis/UserSettingsApi.js +417 -0
- package/dist/client/users/apis/UserSettingsPersonalAccessTokensApi.d.ts +64 -0
- package/dist/client/users/apis/UserSettingsPersonalAccessTokensApi.js +184 -0
- package/dist/client/users/apis/UsersApi.d.ts +70 -0
- package/dist/client/users/apis/UsersApi.js +170 -0
- package/dist/client/users/apis/index.d.ts +6 -0
- package/dist/client/users/apis/index.js +24 -0
- package/dist/client/users/index.d.ts +3 -0
- package/dist/client/users/index.js +21 -0
- package/dist/client/users/models/AccessTokenCreateRequest.d.ts +51 -0
- package/dist/client/users/models/AccessTokenCreateRequest.js +60 -0
- package/dist/client/users/models/AccessTokenDto.d.ts +75 -0
- package/dist/client/users/models/AccessTokenDto.js +68 -0
- package/dist/client/users/models/AccessTokensResponse.d.ts +38 -0
- package/dist/client/users/models/AccessTokensResponse.js +47 -0
- package/dist/client/users/models/DefaultAccessTokenResponse.d.ts +31 -0
- package/dist/client/users/models/DefaultAccessTokenResponse.js +44 -0
- package/dist/client/users/models/Language.d.ts +31 -0
- package/dist/client/users/models/Language.js +44 -0
- package/dist/client/users/models/PageUserDto.d.ts +94 -0
- package/dist/client/users/models/PageUserDto.js +67 -0
- package/dist/client/users/models/Pageable.d.ts +43 -0
- package/dist/client/users/models/Pageable.js +48 -0
- package/dist/client/users/models/PageableObject.d.ts +62 -0
- package/dist/client/users/models/PageableObject.js +55 -0
- package/dist/client/users/models/PersonalAccessTokenPrincipal.d.ts +38 -0
- package/dist/client/users/models/PersonalAccessTokenPrincipal.js +47 -0
- package/dist/client/users/models/Skill.d.ts +31 -0
- package/dist/client/users/models/Skill.js +44 -0
- package/dist/client/users/models/SortObject.d.ts +43 -0
- package/dist/client/users/models/SortObject.js +48 -0
- package/dist/client/users/models/UpdateUserRequest.d.ts +61 -0
- package/dist/client/users/models/UpdateUserRequest.js +54 -0
- package/dist/client/users/models/UserDto.d.ts +111 -0
- package/dist/client/users/models/UserDto.js +72 -0
- package/dist/client/users/models/UserOverviewDto.d.ts +67 -0
- package/dist/client/users/models/UserOverviewDto.js +56 -0
- package/dist/client/users/models/index.d.ts +14 -0
- package/dist/client/users/models/index.js +32 -0
- package/dist/client/users/runtime.d.ts +181 -0
- package/dist/client/users/runtime.js +340 -0
- package/dist/commands/compress/index.d.ts +6 -0
- package/dist/commands/compress/index.js +31 -0
- package/dist/commands/datapool/upload.d.ts +23 -0
- package/dist/commands/datapool/upload.js +266 -0
- package/dist/commands/get-context/index.d.ts +6 -0
- package/dist/commands/get-context/index.js +13 -0
- package/dist/commands/init/index.d.ts +10 -0
- package/dist/commands/init/index.js +81 -0
- package/dist/commands/list-contexts/index.d.ts +9 -0
- package/dist/commands/list-contexts/index.js +36 -0
- package/dist/commands/login/index.d.ts +10 -0
- package/dist/commands/login/index.js +68 -0
- package/dist/commands/logout/index.d.ts +6 -0
- package/dist/commands/logout/index.js +21 -0
- package/dist/commands/openapi/index.d.ts +26 -0
- package/dist/commands/openapi/index.js +313 -0
- package/dist/commands/run/index.d.ts +18 -0
- package/dist/commands/run/index.js +155 -0
- package/dist/commands/serve/index.d.ts +13 -0
- package/dist/commands/serve/index.js +93 -0
- package/dist/commands/services/index.d.ts +14 -0
- package/dist/commands/services/index.js +71 -0
- package/dist/commands/set-context/index.d.ts +17 -0
- package/dist/commands/set-context/index.js +69 -0
- package/dist/commands/up/index.d.ts +19 -0
- package/dist/commands/up/index.js +196 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/lib/command.d.ts +6 -0
- package/dist/lib/command.js +21 -0
- package/dist/lib/debug.d.ts +1 -0
- package/dist/lib/debug.js +5 -0
- package/dist/lib/entrypoint-resolver.d.ts +52 -0
- package/dist/lib/entrypoint-resolver.js +125 -0
- package/dist/lib/error.d.ts +1 -0
- package/dist/lib/error.js +20 -0
- package/dist/lib/fetch.d.ts +7 -0
- package/dist/lib/fetch.js +43 -0
- package/dist/lib/init-user-input.d.ts +18 -0
- package/dist/lib/init-user-input.js +87 -0
- package/dist/lib/random-name.d.ts +1 -0
- package/dist/lib/random-name.js +161 -0
- package/dist/lib/random-string.d.ts +1 -0
- package/dist/lib/random-string.js +12 -0
- package/dist/lib/repository.d.ts +3 -0
- package/dist/lib/repository.js +51 -0
- package/dist/lib/stream-to-blob.d.ts +2 -0
- package/dist/lib/stream-to-blob.js +27 -0
- package/dist/lib/up/get-description.d.ts +1 -0
- package/dist/lib/up/get-description.js +29 -0
- package/dist/lib/up/ignore.d.ts +1 -0
- package/dist/lib/up/ignore.js +21 -0
- package/dist/lib/up/zip.d.ts +1 -0
- package/dist/lib/up/zip.js +40 -0
- package/dist/model/account.d.ts +5 -0
- package/dist/model/account.js +2 -0
- package/dist/model/command.d.ts +12 -0
- package/dist/model/command.js +55 -0
- package/dist/model/managed-service-config.d.ts +28 -0
- package/dist/model/managed-service-config.js +16 -0
- package/dist/model/user-config.d.ts +22 -0
- package/dist/model/user-config.js +8 -0
- package/dist/service/auth-service.d.ts +9 -0
- package/dist/service/auth-service.js +38 -0
- package/dist/service/command-service.d.ts +9 -0
- package/dist/service/command-service.js +14 -0
- package/dist/service/quantum-hub-service.d.ts +24 -0
- package/dist/service/quantum-hub-service.js +222 -0
- package/dist/service/service-config-service.d.ts +3 -0
- package/dist/service/service-config-service.js +26 -0
- package/dist/service/user-config-service.d.ts +3 -0
- package/dist/service/user-config-service.js +26 -0
- package/dist/service/user-service.d.ts +9 -0
- package/dist/service/user-service.js +35 -0
- package/oclif.manifest.json +530 -0
- package/package.json +107 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const tty_table_1 = __importDefault(require("tty-table"));
|
|
8
|
+
const command_1 = require("../../model/command");
|
|
9
|
+
const quantum_hub_service_1 = __importDefault(require("../../service/quantum-hub-service"));
|
|
10
|
+
class Services extends command_1.AuthenticatedCommand {
|
|
11
|
+
static description = 'List all services of the current context.';
|
|
12
|
+
static examples = [
|
|
13
|
+
'$ qhubctl services',
|
|
14
|
+
'$ qhubctl services --json',
|
|
15
|
+
'$ qhubctl services --name "my-service"',
|
|
16
|
+
'$ qhubctl services --name "my-service" --json',
|
|
17
|
+
'$ qhubctl services --json --all',
|
|
18
|
+
];
|
|
19
|
+
static flags = {
|
|
20
|
+
json: core_1.Flags.boolean({
|
|
21
|
+
description: 'output in JSON format',
|
|
22
|
+
default: false,
|
|
23
|
+
}),
|
|
24
|
+
name: core_1.Flags.string({
|
|
25
|
+
description: 'filter services by name (case-insensitive full match)',
|
|
26
|
+
required: false,
|
|
27
|
+
}),
|
|
28
|
+
all: core_1.Flags.boolean({
|
|
29
|
+
description: 'display all service properties (only available with --json)',
|
|
30
|
+
default: false,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
quantumHubService;
|
|
34
|
+
async init() {
|
|
35
|
+
const { flags } = await this.parse(Services);
|
|
36
|
+
await super.init(!flags.json);
|
|
37
|
+
this.quantumHubService = new quantum_hub_service_1.default(this, this.config, this.userConfig);
|
|
38
|
+
}
|
|
39
|
+
async run() {
|
|
40
|
+
const { flags } = await this.parse(Services);
|
|
41
|
+
// Validate flag combinations
|
|
42
|
+
if (flags.all && !flags.json) {
|
|
43
|
+
core_1.ux.warn('The --all flag can only be used with --json output. Continuing without --all.');
|
|
44
|
+
}
|
|
45
|
+
core_1.ux.action.start('Loading services');
|
|
46
|
+
let services = await this.quantumHubService.getServices();
|
|
47
|
+
core_1.ux.action.stop('Done');
|
|
48
|
+
// Filter by name if provided
|
|
49
|
+
if (flags.name) {
|
|
50
|
+
const nameFilter = flags.name.toLowerCase();
|
|
51
|
+
services = services.filter(service => service.name?.toLowerCase() === nameFilter);
|
|
52
|
+
}
|
|
53
|
+
const tableData = services
|
|
54
|
+
.map(service => ({ id: service.id, name: service.name }));
|
|
55
|
+
if (flags.json) {
|
|
56
|
+
core_1.ux.stdout(JSON.stringify(flags.all ? services : tableData, null, 2));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const header = [
|
|
60
|
+
{ value: "id", alias: "ID", align: "left" },
|
|
61
|
+
{ value: "name", alias: "Name", align: "left" },
|
|
62
|
+
];
|
|
63
|
+
const t = (0, tty_table_1.default)(header, tableData);
|
|
64
|
+
const contextName = this.userConfig.context?.displayName;
|
|
65
|
+
const filterInfo = flags.name ? ` (filtered by name: "${flags.name}")` : '';
|
|
66
|
+
core_1.ux.stdout(`Available services for ${contextName}${filterInfo}:`);
|
|
67
|
+
core_1.ux.stdout(t.render());
|
|
68
|
+
core_1.ux.stdout();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = Services;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Account from '../../model/account';
|
|
2
|
+
import { AuthenticatedCommand } from '../../model/command';
|
|
3
|
+
import QuantumHubService from '../../service/quantum-hub-service';
|
|
4
|
+
export default class SetContext extends AuthenticatedCommand {
|
|
5
|
+
static args: {
|
|
6
|
+
contextId: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
7
|
+
};
|
|
8
|
+
static description: string;
|
|
9
|
+
static examples: string[];
|
|
10
|
+
quantumHubService: QuantumHubService;
|
|
11
|
+
getPromptOptions(accounts: Account[]): {
|
|
12
|
+
name: string;
|
|
13
|
+
value: Account;
|
|
14
|
+
}[];
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
run(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
+
const command_1 = require("../../model/command");
|
|
9
|
+
const quantum_hub_service_1 = __importDefault(require("../../service/quantum-hub-service"));
|
|
10
|
+
const user_config_service_1 = require("../../service/user-config-service");
|
|
11
|
+
class SetContext extends command_1.AuthenticatedCommand {
|
|
12
|
+
static args = {
|
|
13
|
+
contextId: core_1.Args.string(),
|
|
14
|
+
};
|
|
15
|
+
static description = 'Set the current context, i.e., the personal or organization account you are currently working with.';
|
|
16
|
+
static examples = [
|
|
17
|
+
'$ qhubctl set-context',
|
|
18
|
+
'$ qhubctl set-context <context-id>',
|
|
19
|
+
];
|
|
20
|
+
quantumHubService;
|
|
21
|
+
getPromptOptions(accounts) {
|
|
22
|
+
const options = [];
|
|
23
|
+
for (const account of accounts) {
|
|
24
|
+
options.push({
|
|
25
|
+
name: account.isOrganization ? `${account.displayName} (Organization)` : account.displayName,
|
|
26
|
+
value: account,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return options;
|
|
30
|
+
}
|
|
31
|
+
async init() {
|
|
32
|
+
await super.init();
|
|
33
|
+
this.quantumHubService = new quantum_hub_service_1.default(this, this.config, this.userConfig);
|
|
34
|
+
}
|
|
35
|
+
async run() {
|
|
36
|
+
const { args } = await this.parse(SetContext);
|
|
37
|
+
const { contextId } = args;
|
|
38
|
+
let selectedContext;
|
|
39
|
+
if (!contextId) {
|
|
40
|
+
core_1.ux.action.start('Loading available contexts');
|
|
41
|
+
}
|
|
42
|
+
const accounts = await this.quantumHubService.getAccounts();
|
|
43
|
+
if (!contextId) {
|
|
44
|
+
core_1.ux.action.stop('Done');
|
|
45
|
+
}
|
|
46
|
+
if (contextId) {
|
|
47
|
+
selectedContext = accounts.find(account => account.id === contextId);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const response = await inquirer_1.default.prompt({
|
|
51
|
+
choices: this.getPromptOptions(accounts),
|
|
52
|
+
message: 'Choose a context',
|
|
53
|
+
name: 'context',
|
|
54
|
+
type: 'list',
|
|
55
|
+
});
|
|
56
|
+
selectedContext = response.context;
|
|
57
|
+
}
|
|
58
|
+
if (!selectedContext) {
|
|
59
|
+
this.error(`Context with id "${contextId}" not found.`);
|
|
60
|
+
}
|
|
61
|
+
const userConfig = {
|
|
62
|
+
...this.userConfig,
|
|
63
|
+
context: selectedContext,
|
|
64
|
+
};
|
|
65
|
+
(0, user_config_service_1.writeUserConfig)(this.config.configDir, userConfig);
|
|
66
|
+
core_1.ux.stdout(`Switched to context "${selectedContext?.displayName}".`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.default = SetContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AuthenticatedCommand } from '../../model/command';
|
|
2
|
+
import QuantumHubService from '../../service/quantum-hub-service';
|
|
3
|
+
export default class Up extends AuthenticatedCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
silent: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
'no-save-id': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
qhubService: QuantumHubService;
|
|
12
|
+
getOpenapi(): Promise<Blob | undefined>;
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
private buildServiceJob;
|
|
16
|
+
private checkIfServiceExistsInPlatform;
|
|
17
|
+
private createService;
|
|
18
|
+
private updateService;
|
|
19
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
7
|
+
const core_1 = require("@oclif/core");
|
|
8
|
+
const async_wait_until_1 = require("async-wait-until");
|
|
9
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const kqh_1 = require("../../client/kqh");
|
|
12
|
+
const stream_to_blob_1 = require("../../lib/stream-to-blob");
|
|
13
|
+
const get_description_1 = require("../../lib/up/get-description");
|
|
14
|
+
const zip_1 = require("../../lib/up/zip");
|
|
15
|
+
const command_1 = require("../../model/command");
|
|
16
|
+
const quantum_hub_service_1 = __importDefault(require("../../service/quantum-hub-service"));
|
|
17
|
+
const service_config_service_1 = require("../../service/service-config-service");
|
|
18
|
+
class Up extends command_1.AuthenticatedCommand {
|
|
19
|
+
static description = 'Creates or updates a service';
|
|
20
|
+
static examples = [
|
|
21
|
+
'$ qhubctl up',
|
|
22
|
+
'$ qhubctl up --no-save-id',
|
|
23
|
+
'$ qhubctl up --name "my-custom-service-name"',
|
|
24
|
+
'$ qhubctl up --name "test-service" --no-save-id',
|
|
25
|
+
];
|
|
26
|
+
static flags = {
|
|
27
|
+
silent: core_1.Flags.boolean({
|
|
28
|
+
description: 'Suppresses all outputs, helpful when executed in a CI/CD pipeline.',
|
|
29
|
+
required: false,
|
|
30
|
+
}),
|
|
31
|
+
'no-save-id': core_1.Flags.boolean({
|
|
32
|
+
description: 'Prevents storing the created service ID in qhub.json file.',
|
|
33
|
+
required: false,
|
|
34
|
+
}),
|
|
35
|
+
name: core_1.Flags.string({
|
|
36
|
+
description: 'Override the service name from qhub.json with a custom name.',
|
|
37
|
+
required: false,
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
qhubService;
|
|
41
|
+
async getOpenapi() {
|
|
42
|
+
const openapiYamlPath = node_path_1.default.join(process.cwd(), 'openapi.yaml');
|
|
43
|
+
const openapiYmlPath = node_path_1.default.join(process.cwd(), 'openapi.yml');
|
|
44
|
+
let openapi = undefined;
|
|
45
|
+
if (node_fs_1.default.existsSync(openapiYamlPath)) {
|
|
46
|
+
openapi = node_fs_1.default.createReadStream(openapiYamlPath, 'utf8');
|
|
47
|
+
}
|
|
48
|
+
else if (node_fs_1.default.existsSync(openapiYmlPath)) {
|
|
49
|
+
openapi = node_fs_1.default.createReadStream(openapiYmlPath, 'utf8');
|
|
50
|
+
}
|
|
51
|
+
if (openapi) {
|
|
52
|
+
return (0, stream_to_blob_1.streamToBlob)(openapi);
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
async init() {
|
|
57
|
+
await super.init();
|
|
58
|
+
this.qhubService = new quantum_hub_service_1.default(this, this.config, this.userConfig);
|
|
59
|
+
}
|
|
60
|
+
async run() {
|
|
61
|
+
const { flags } = await this.parse(Up);
|
|
62
|
+
const serviceConfig = (0, service_config_service_1.readServiceConfig)(process.cwd());
|
|
63
|
+
let createNewService = true;
|
|
64
|
+
const silentMode = flags.silent;
|
|
65
|
+
if (!('descriptionFile' in serviceConfig)) {
|
|
66
|
+
core_1.ux.stdout('Warning: Since version 2.14.0, the "description" property in qhub.json has changed to "descriptionFile".\nFor more information, visit: https://docs.hub.kipu-quantum.com/qhub-json-reference.html\n');
|
|
67
|
+
}
|
|
68
|
+
const deprecatedOpenapiFile = node_path_1.default.join(process.cwd(), 'openapi-spec.yml');
|
|
69
|
+
if (node_fs_1.default.existsSync(deprecatedOpenapiFile)) {
|
|
70
|
+
core_1.ux.warn('You are having the deprecated file "openapi-spec.yml" in your project. Please consider renaming it to "openapi.yaml".');
|
|
71
|
+
}
|
|
72
|
+
// if service already exists we update it
|
|
73
|
+
const serviceExistsInPlatform = await this.checkIfServiceExistsInPlatform(serviceConfig);
|
|
74
|
+
if (serviceConfig.serviceId && !serviceExistsInPlatform) {
|
|
75
|
+
core_1.ux.stdout(`We could not find a service with id '${serviceConfig.serviceId}' in the current context!`);
|
|
76
|
+
createNewService = await (0, prompts_1.confirm)({ message: 'Do you want to create a new service?' });
|
|
77
|
+
if (!createNewService) {
|
|
78
|
+
this.exit();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const serviceFiles = {
|
|
82
|
+
openapi: await this.getOpenapi(),
|
|
83
|
+
descriptionText: await (0, get_description_1.getDescriptionText)(process.cwd()),
|
|
84
|
+
sourceCode: await (0, zip_1.zipProjectFolder)('./'),
|
|
85
|
+
};
|
|
86
|
+
const service = serviceExistsInPlatform ?
|
|
87
|
+
await this.updateService(serviceConfig, serviceFiles, silentMode) :
|
|
88
|
+
await this.createService(serviceConfig, serviceFiles, silentMode, flags['no-save-id'], flags.name);
|
|
89
|
+
const serviceDefinition = service && service.serviceDefinitions && service.serviceDefinitions[0];
|
|
90
|
+
if (!serviceDefinition) {
|
|
91
|
+
this.error('Service definition not found');
|
|
92
|
+
}
|
|
93
|
+
const buildJob = await this.buildServiceJob(service, serviceDefinition, silentMode);
|
|
94
|
+
if (buildJob && buildJob.status === kqh_1.BuildJobDtoStatusEnum.Success) {
|
|
95
|
+
const msg = `Service ${serviceExistsInPlatform ? 'updated' : 'created'} \u{1F680}`;
|
|
96
|
+
if (silentMode) {
|
|
97
|
+
core_1.ux.stdout(msg);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
core_1.ux.action.stop(msg);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (buildJob && buildJob.status === kqh_1.BuildJobDtoStatusEnum.Failure) {
|
|
104
|
+
const { validationResult } = buildJob;
|
|
105
|
+
let reason = 'Failed creating service';
|
|
106
|
+
if (validationResult?.state === kqh_1.ValidationResultStateEnum.Error && validationResult.summary) {
|
|
107
|
+
reason = `${reason}: ${validationResult.summary}`;
|
|
108
|
+
}
|
|
109
|
+
if (silentMode) {
|
|
110
|
+
core_1.ux.stdout(reason);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
core_1.ux.action.stop(reason);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const msg = 'Still pending, please check the platform UI to determine the status';
|
|
118
|
+
if (silentMode) {
|
|
119
|
+
core_1.ux.stdout(msg);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
core_1.ux.action.stop(msg);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this.exit();
|
|
126
|
+
}
|
|
127
|
+
async buildServiceJob(service, serviceDefinition, silentMode) {
|
|
128
|
+
let buildJob;
|
|
129
|
+
try {
|
|
130
|
+
await (0, async_wait_until_1.waitUntil)(async () => {
|
|
131
|
+
buildJob = await this.qhubService.getBuildJob(service, serviceDefinition);
|
|
132
|
+
if (!silentMode) {
|
|
133
|
+
if (buildJob.step === kqh_1.BuildJobDtoStepEnum.BuildImage) {
|
|
134
|
+
core_1.ux.action.start('Building Image (1/2)');
|
|
135
|
+
}
|
|
136
|
+
else if (buildJob.step === kqh_1.BuildJobDtoStepEnum.PushImage) {
|
|
137
|
+
core_1.ux.action.start('Pushing Image (2/2)');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return buildJob.status === kqh_1.BuildJobDtoStatusEnum.Success || buildJob.status === kqh_1.BuildJobDtoStatusEnum.Failure;
|
|
141
|
+
}, {
|
|
142
|
+
intervalBetweenAttempts: 5000, // every 5 seconds
|
|
143
|
+
timeout: silentMode ? 60 * 60 * 1000 : 20 * 60 * 1000, // silent mode: 60 minutes, normal: 20 minutes
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
this.error('Error while waiting for the build job to finish: ' + error);
|
|
148
|
+
}
|
|
149
|
+
return buildJob;
|
|
150
|
+
}
|
|
151
|
+
async checkIfServiceExistsInPlatform(serviceConfig) {
|
|
152
|
+
if (serviceConfig.serviceId) {
|
|
153
|
+
try {
|
|
154
|
+
await this.qhubService.getService(serviceConfig.serviceId);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
async createService(serviceConfig, files, silentMode, noSaveId = false, customName) {
|
|
164
|
+
if (!silentMode) {
|
|
165
|
+
core_1.ux.action.start('Creating service');
|
|
166
|
+
}
|
|
167
|
+
// Override the service name if custom name is provided
|
|
168
|
+
const configToUse = { ...serviceConfig };
|
|
169
|
+
if (customName) {
|
|
170
|
+
configToUse.name = customName;
|
|
171
|
+
}
|
|
172
|
+
const service = await this.qhubService.createService(configToUse, files.sourceCode, files.openapi);
|
|
173
|
+
// Always set the service ID temporarily for subsequent operations
|
|
174
|
+
serviceConfig.serviceId = service?.id;
|
|
175
|
+
// Only persist to file if not using no-save-id flag
|
|
176
|
+
if (!noSaveId) {
|
|
177
|
+
(0, service_config_service_1.writeServiceConfig)(process.cwd(), serviceConfig);
|
|
178
|
+
}
|
|
179
|
+
// update description separately when creating a new service
|
|
180
|
+
if (files.descriptionText) {
|
|
181
|
+
await this.qhubService.updateDescription(serviceConfig, files.descriptionText);
|
|
182
|
+
}
|
|
183
|
+
// make sure we update the OpenAPI description if it exists
|
|
184
|
+
if (files.openapi) {
|
|
185
|
+
await this.qhubService.updateOpenapi(serviceConfig, files.openapi);
|
|
186
|
+
}
|
|
187
|
+
return service;
|
|
188
|
+
}
|
|
189
|
+
async updateService(serviceConfig, files, silentMode) {
|
|
190
|
+
if (!silentMode) {
|
|
191
|
+
core_1.ux.action.start('Updating service');
|
|
192
|
+
}
|
|
193
|
+
return this.qhubService.updateService(serviceConfig, files.descriptionText, files.sourceCode, files.openapi);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.default = Up;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from '@oclif/core';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeCommand = exports.executeAsyncCommand = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const executeAsyncCommand = async (command) => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
(0, node_child_process_1.exec)(command, (error, stdout, stderr) => {
|
|
8
|
+
if (error) {
|
|
9
|
+
reject(error);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
resolve({ stderr, stdout });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.executeAsyncCommand = executeAsyncCommand;
|
|
18
|
+
const executeCommand = (command, stdioOption) => {
|
|
19
|
+
(0, node_child_process_1.execSync)(`${command}`, { stdio: stdioOption ?? 'inherit' });
|
|
20
|
+
};
|
|
21
|
+
exports.executeCommand = executeCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debugEnabled: () => boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface EntrypointOptions {
|
|
2
|
+
entrypoint?: string;
|
|
3
|
+
package?: string;
|
|
4
|
+
method?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class EntrypointResolver {
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the entrypoint string from various flag combinations.
|
|
9
|
+
* Defaults to "src.program:run" if no flags are provided.
|
|
10
|
+
*
|
|
11
|
+
* @param entryPoint - The CLI flags containing entrypoint options
|
|
12
|
+
* @returns The resolved entrypoint string in format "package.module:function"
|
|
13
|
+
*/
|
|
14
|
+
static resolveEntrypoint(entryPoint: EntrypointOptions): string;
|
|
15
|
+
/**
|
|
16
|
+
* Validates an entrypoint string to ensure it follows the Python entry point specification.
|
|
17
|
+
* Supports formats:
|
|
18
|
+
* - `importable.module:function` (simple function)
|
|
19
|
+
* - `importable.module:Class.method` (class method)
|
|
20
|
+
*
|
|
21
|
+
* @param entrypoint - The entrypoint string to validate
|
|
22
|
+
* @throws Error if the entrypoint format is invalid
|
|
23
|
+
*/
|
|
24
|
+
static validateEntrypoint(entrypoint: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Validates a Python module path according to Python identifier rules.
|
|
27
|
+
*/
|
|
28
|
+
private static validateModulePath;
|
|
29
|
+
/**
|
|
30
|
+
* Validates a Python object path (function or Class.method).
|
|
31
|
+
*/
|
|
32
|
+
private static validateObjectPath;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a string is a valid Python identifier.
|
|
35
|
+
* Python identifiers must start with letter or underscore, and contain only letters, numbers, underscores.
|
|
36
|
+
*/
|
|
37
|
+
private static isValidPythonIdentifier;
|
|
38
|
+
/**
|
|
39
|
+
* Extracts the package path from an entrypoint string.
|
|
40
|
+
*
|
|
41
|
+
* @param entrypoint - The entrypoint string
|
|
42
|
+
* @returns The package path portion
|
|
43
|
+
*/
|
|
44
|
+
static extractPackagePath(entrypoint: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts the method name from an entrypoint string.
|
|
47
|
+
*
|
|
48
|
+
* @param entrypoint - The entrypoint string
|
|
49
|
+
* @returns The method name portion
|
|
50
|
+
*/
|
|
51
|
+
static extractMethod(entrypoint: string): string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntrypointResolver = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
class EntrypointResolver {
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the entrypoint string from various flag combinations.
|
|
8
|
+
* Defaults to "src.program:run" if no flags are provided.
|
|
9
|
+
*
|
|
10
|
+
* @param entryPoint - The CLI flags containing entrypoint options
|
|
11
|
+
* @returns The resolved entrypoint string in format "package.module:function"
|
|
12
|
+
*/
|
|
13
|
+
static resolveEntrypoint(entryPoint) {
|
|
14
|
+
// If entrypoint flag is provided, use it directly (format: "package.module:function")
|
|
15
|
+
if (entryPoint.entrypoint) {
|
|
16
|
+
this.validateEntrypoint(entryPoint.entrypoint);
|
|
17
|
+
return entryPoint.entrypoint;
|
|
18
|
+
}
|
|
19
|
+
// If package and/or method flags are provided, construct the entrypoint
|
|
20
|
+
const packagePath = entryPoint.package || 'src.program';
|
|
21
|
+
const method = entryPoint.method || 'run';
|
|
22
|
+
const entrypoint = `${packagePath}:${method}`;
|
|
23
|
+
this.validateEntrypoint(entrypoint);
|
|
24
|
+
return entrypoint;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates an entrypoint string to ensure it follows the Python entry point specification.
|
|
28
|
+
* Supports formats:
|
|
29
|
+
* - `importable.module:function` (simple function)
|
|
30
|
+
* - `importable.module:Class.method` (class method)
|
|
31
|
+
*
|
|
32
|
+
* @param entrypoint - The entrypoint string to validate
|
|
33
|
+
* @throws Error if the entrypoint format is invalid
|
|
34
|
+
*/
|
|
35
|
+
static validateEntrypoint(entrypoint) {
|
|
36
|
+
if (!entrypoint) {
|
|
37
|
+
throw new Error('Entrypoint cannot be empty');
|
|
38
|
+
}
|
|
39
|
+
const parts = entrypoint.split(':');
|
|
40
|
+
if (parts.length !== 2) {
|
|
41
|
+
throw new Error(`Invalid entrypoint format: "${entrypoint}". ` +
|
|
42
|
+
'Must contain exactly one colon separating module and object reference');
|
|
43
|
+
}
|
|
44
|
+
const [modulePath, objectPath] = parts;
|
|
45
|
+
// Check for empty parts first
|
|
46
|
+
if (!modulePath || !objectPath) {
|
|
47
|
+
throw new Error(`Invalid entrypoint format: "${entrypoint}". ` +
|
|
48
|
+
'Expected format: "package.module:function" or "package.module:Class.method"');
|
|
49
|
+
}
|
|
50
|
+
// Validate module path (importable.module)
|
|
51
|
+
this.validateModulePath(modulePath, entrypoint);
|
|
52
|
+
// Validate object path (function or Class.method)
|
|
53
|
+
this.validateObjectPath(objectPath, entrypoint);
|
|
54
|
+
// Warn if object path starts with underscore (private methods/classes)
|
|
55
|
+
if (objectPath.startsWith('_')) {
|
|
56
|
+
core_1.ux.warn(`Object "${objectPath}" starts with underscore. Make sure this is intended for a private object.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validates a Python module path according to Python identifier rules.
|
|
61
|
+
*/
|
|
62
|
+
static validateModulePath(modulePath, fullEntrypoint) {
|
|
63
|
+
// Check for leading/trailing dots or consecutive dots
|
|
64
|
+
if (modulePath.startsWith('.') || modulePath.endsWith('.')) {
|
|
65
|
+
throw new Error(`Invalid module path in entrypoint: "${modulePath}". ` +
|
|
66
|
+
'Module path should not start or end with dots.');
|
|
67
|
+
}
|
|
68
|
+
if (modulePath.includes('..')) {
|
|
69
|
+
throw new Error(`Invalid module path in entrypoint: "${modulePath}". ` +
|
|
70
|
+
'Module path should not contain consecutive dots.');
|
|
71
|
+
}
|
|
72
|
+
// Split by dots and validate each identifier
|
|
73
|
+
const moduleIdentifiers = modulePath.split('.');
|
|
74
|
+
for (const identifier of moduleIdentifiers) {
|
|
75
|
+
if (!this.isValidPythonIdentifier(identifier)) {
|
|
76
|
+
throw new Error(`Invalid entrypoint format: "${fullEntrypoint}". ` +
|
|
77
|
+
`"${identifier}" is not a valid Python identifier in module path.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validates a Python object path (function or Class.method).
|
|
83
|
+
*/
|
|
84
|
+
static validateObjectPath(objectPath, fullEntrypoint) {
|
|
85
|
+
// Split by dots and validate each identifier
|
|
86
|
+
const objectIdentifiers = objectPath.split('.');
|
|
87
|
+
for (const identifier of objectIdentifiers) {
|
|
88
|
+
if (!this.isValidPythonIdentifier(identifier)) {
|
|
89
|
+
throw new Error(`Invalid entrypoint format: "${fullEntrypoint}". ` +
|
|
90
|
+
`"${identifier}" is not a valid Python identifier in object path.`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Checks if a string is a valid Python identifier.
|
|
96
|
+
* Python identifiers must start with letter or underscore, and contain only letters, numbers, underscores.
|
|
97
|
+
*/
|
|
98
|
+
static isValidPythonIdentifier(identifier) {
|
|
99
|
+
if (!identifier)
|
|
100
|
+
return false;
|
|
101
|
+
// [a-zA-Z0-9_] == \w
|
|
102
|
+
return /^[a-zA-Z_]\w*$/.test(identifier);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Extracts the package path from an entrypoint string.
|
|
106
|
+
*
|
|
107
|
+
* @param entrypoint - The entrypoint string
|
|
108
|
+
* @returns The package path portion
|
|
109
|
+
*/
|
|
110
|
+
static extractPackagePath(entrypoint) {
|
|
111
|
+
this.validateEntrypoint(entrypoint);
|
|
112
|
+
return entrypoint.split(':')[0];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extracts the method name from an entrypoint string.
|
|
116
|
+
*
|
|
117
|
+
* @param entrypoint - The entrypoint string
|
|
118
|
+
* @returns The method name portion
|
|
119
|
+
*/
|
|
120
|
+
static extractMethod(entrypoint) {
|
|
121
|
+
this.validateEntrypoint(entrypoint);
|
|
122
|
+
return entrypoint.split(':')[1];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.EntrypointResolver = EntrypointResolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const handleError: (error: unknown) => Promise<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleError = void 0;
|
|
4
|
+
const kqh_1 = require("../client/kqh");
|
|
5
|
+
const debug_1 = require("./debug");
|
|
6
|
+
const fetch_1 = require("./fetch");
|
|
7
|
+
const handleError = async (error) => {
|
|
8
|
+
if (error instanceof kqh_1.ResponseError) {
|
|
9
|
+
return (0, fetch_1.getErrorMessage)(error.response);
|
|
10
|
+
}
|
|
11
|
+
if (error instanceof kqh_1.FetchError) {
|
|
12
|
+
const errorMessage = error.cause ? error.cause.message : error.message;
|
|
13
|
+
return `Internal error occurred, please try again later (${errorMessage})`;
|
|
14
|
+
}
|
|
15
|
+
if ((0, debug_1.debugEnabled)()) {
|
|
16
|
+
console.error(JSON.stringify(error));
|
|
17
|
+
}
|
|
18
|
+
return 'Internal error occurred, please contact your KQH administrator';
|
|
19
|
+
};
|
|
20
|
+
exports.handleError = handleError;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class PlatformError extends Error {
|
|
2
|
+
response: Response;
|
|
3
|
+
constructor(response: Response);
|
|
4
|
+
getErrorMessage(): Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
export declare const fetchOrThrow: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
export declare const getErrorMessage: (response: Response) => Promise<string>;
|