@contrail/cli 3.6.0-alpha-8-alpha.694fd70 → 3.6.0-alpha.693d785
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 +45 -151
- package/dist/api/feature-flags.d.ts +3 -0
- package/dist/api/feature-flags.js +29 -0
- package/dist/api/types.d.ts +0 -35
- package/dist/api/types.js +1 -49
- package/dist/api/users.d.ts +1 -0
- package/dist/api/users.js +10 -1
- package/dist/auth/login.d.ts +4 -0
- package/dist/auth/login.js +167 -93
- package/dist/auth/login.spec.js +305 -0
- package/dist/auth/sso.d.ts +36 -0
- package/dist/auth/sso.js +168 -0
- package/dist/auth/sso.spec.js +138 -0
- package/dist/basecommand.d.ts +1 -3
- package/dist/basecommand.js +2 -2
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/config/set.js +1 -1
- package/dist/commands/feature-flags/export.d.ts +19 -0
- package/dist/commands/feature-flags/export.js +66 -0
- package/dist/commands/feature-flags/export.spec.js +109 -0
- package/dist/commands/feature-flags/import.d.ts +42 -0
- package/dist/commands/feature-flags/import.js +191 -0
- package/dist/commands/feature-flags/import.spec.js +194 -0
- package/dist/commands/instance/export.d.ts +9 -0
- package/dist/commands/instance/export.js +18 -3
- package/dist/commands/instance/export.spec.js +32 -0
- package/dist/commands/instance/import.d.ts +3 -0
- package/dist/commands/instance/import.js +5 -0
- package/dist/commands/instance/import.spec.js +4 -0
- package/dist/commands/login.d.ts +12 -0
- package/dist/commands/login.js +25 -0
- package/dist/common.d.ts +1 -3
- package/dist/common.js +1 -13
- package/dist/helpers/config/config.d.ts +5 -4
- package/dist/helpers/config/config.js +10 -12
- package/dist/helpers/file-helpers.d.ts +0 -1
- package/dist/helpers/file-helpers.js +1 -18
- package/dist/logger.js +1 -4
- package/node_modules/@contrail/entity-compare/package.json +3 -6
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
- package/node_modules/@contrail/loader/lib/constants.js +9 -1
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +4 -1
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -3
- package/node_modules/@contrail/sdk/lib/config/config.js +7 -13
- package/node_modules/@contrail/sdk/lib/core/request.js +2 -6
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +1 -3
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -1
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +75 -365
- package/package.json +15 -5
- package/dist/commands/entities/create.d.ts +0 -48
- package/dist/commands/entities/create.js +0 -639
- package/dist/commands/entities/create.spec.js +0 -541
- package/dist/commands/entities/delete.d.ts +0 -19
- package/dist/commands/entities/delete.js +0 -134
- package/dist/commands/entities/get.d.ts +0 -24
- package/dist/commands/entities/get.js +0 -273
- package/dist/commands/entities/grammar.spec.js +0 -80
- package/dist/commands/entities/output.spec.js +0 -72
- package/dist/commands/entities/update.d.ts +0 -31
- package/dist/commands/entities/update.js +0 -157
- package/dist/helpers/entities/assortment-items.d.ts +0 -10
- package/dist/helpers/entities/assortment-items.js +0 -84
- package/dist/helpers/entities/batchFetch.d.ts +0 -8
- package/dist/helpers/entities/batchFetch.js +0 -49
- package/dist/helpers/entities/index.d.ts +0 -3
- package/dist/helpers/entities/index.js +0 -6
- package/dist/helpers/entities/items.d.ts +0 -10
- package/dist/helpers/entities/items.js +0 -102
- package/dist/helpers/entities/project-items.d.ts +0 -3
- package/dist/helpers/entities/project-items.js +0 -65
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +0 -38
- package/dist/helpers/propertySpecifications/dateRanges.js +0 -89
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +0 -95
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -40
- package/dist/helpers/propertySpecifications/propertySpecifications.js +0 -109
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +0 -1
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +0 -373
- package/dist/logger.spec.d.ts +0 -1
- package/dist/logger.spec.js +0 -12
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +0 -31
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +0 -34
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +0 -32
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +0 -117
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +0 -27
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +0 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +0 -72
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +0 -11
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +0 -9
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +0 -54
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +0 -6
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +0 -18
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +0 -209
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -48
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +0 -42
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +0 -12
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +0 -70
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +0 -15
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +0 -241
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -101
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +0 -306
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +0 -9
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +0 -86
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +0 -6
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +0 -5
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -59
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +0 -3
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +0 -3
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +0 -24
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +0 -151
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -26
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +0 -16
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +0 -37
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +0 -12
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +0 -55
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +0 -9
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +0 -74
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +0 -18
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +0 -18
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +0 -98
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +0 -73
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +0 -42
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +0 -217
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +0 -64
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
- /package/dist/{commands/entities/create.spec.d.ts → auth/sso.spec.d.ts} +0 -0
- /package/dist/commands/{entities/grammar.spec.d.ts → feature-flags/export.spec.d.ts} +0 -0
- /package/dist/commands/{entities/output.spec.d.ts → feature-flags/import.spec.d.ts} +0 -0
- /package/dist/{helpers/propertySpecifications/dateRanges.spec.d.ts → commands/instance/export.spec.d.ts} +0 -0
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const core_1 = require("@oclif/core");
|
|
5
|
-
const p_limit_1 = tslib_1.__importDefault(require("p-limit"));
|
|
6
|
-
const basecommand_1 = require("../../basecommand");
|
|
7
|
-
const sdk_1 = require("@contrail/sdk");
|
|
8
|
-
const login_1 = require("../../auth/login");
|
|
9
|
-
const common_1 = require("../../common");
|
|
10
|
-
const file_helpers_1 = require("../../helpers/file-helpers");
|
|
11
|
-
let IS_DRY_RUN = false;
|
|
12
|
-
class DeleteEntity extends basecommand_1.BaseCommand {
|
|
13
|
-
static description = 'Delete entities by id';
|
|
14
|
-
static examples = [
|
|
15
|
-
'contrail entities delete color 123',
|
|
16
|
-
'contrail entities delete color id1 id2 id3',
|
|
17
|
-
'contrail entities delete item -i ids.json',
|
|
18
|
-
];
|
|
19
|
-
static flags = {
|
|
20
|
-
...basecommand_1.BaseCommand.baseFlags,
|
|
21
|
-
dryRun: core_1.Flags.boolean({
|
|
22
|
-
char: 'd',
|
|
23
|
-
description: 'If true, does not delete the entities but simulates the deletion',
|
|
24
|
-
required: false,
|
|
25
|
-
default: false,
|
|
26
|
-
}),
|
|
27
|
-
inputFile: core_1.Flags.string({
|
|
28
|
-
char: 'i',
|
|
29
|
-
description: "A file with a JSON array of objects; only each object's id is used. Deletes every entity in the file.",
|
|
30
|
-
required: false,
|
|
31
|
-
multiple: false,
|
|
32
|
-
}),
|
|
33
|
-
suffix: core_1.Flags.string({
|
|
34
|
-
description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
|
|
35
|
-
required: false,
|
|
36
|
-
}),
|
|
37
|
-
apiVersion: core_1.Flags.string({
|
|
38
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
39
|
-
options: ['1', '2'],
|
|
40
|
-
required: false,
|
|
41
|
-
}),
|
|
42
|
-
};
|
|
43
|
-
static args = {
|
|
44
|
-
entityName: core_1.Args.string({
|
|
45
|
-
description: 'The name of the entity type to delete',
|
|
46
|
-
required: true,
|
|
47
|
-
}),
|
|
48
|
-
ids: core_1.Args.string({
|
|
49
|
-
description: 'One or more entity ids to delete',
|
|
50
|
-
required: false,
|
|
51
|
-
}),
|
|
52
|
-
};
|
|
53
|
-
static strict = false;
|
|
54
|
-
async run() {
|
|
55
|
-
(0, common_1.routeConsoleLogToStderr)();
|
|
56
|
-
await (0, login_1.authUser)();
|
|
57
|
-
const { args, flags, argv } = await this.parse(DeleteEntity);
|
|
58
|
-
const { entityName } = args;
|
|
59
|
-
const { inputFile: inputFilename, suffix, apiVersion } = flags;
|
|
60
|
-
if (flags.dryRun) {
|
|
61
|
-
IS_DRY_RUN = true;
|
|
62
|
-
console.error('Running in dry run mode. No entities will be deleted.');
|
|
63
|
-
}
|
|
64
|
-
const tokens = argv.slice(1);
|
|
65
|
-
const valueTokens = tokens.filter((token) => token.includes('='));
|
|
66
|
-
if (valueTokens.length > 0) {
|
|
67
|
-
this.error(`delete takes no -- values (got: ${valueTokens.join(' ')}); pass ids positionally or use an input file (-i).`);
|
|
68
|
-
}
|
|
69
|
-
const positionalIds = tokens;
|
|
70
|
-
if (inputFilename && positionalIds.length > 0) {
|
|
71
|
-
this.error('You cannot use --inputFile and positional ids together. Please specify one or the other.');
|
|
72
|
-
}
|
|
73
|
-
if (!inputFilename && positionalIds.length === 0) {
|
|
74
|
-
this.error('You must provide one or more ids or an input file (-i) of entities to delete.');
|
|
75
|
-
}
|
|
76
|
-
const jsonInput = inputFilename ? (0, file_helpers_1.parseFileAsJsonArray)(inputFilename) : undefined;
|
|
77
|
-
const rowsWithId = jsonInput?.filter((item) => item.id);
|
|
78
|
-
if (jsonInput && rowsWithId.length < jsonInput.length) {
|
|
79
|
-
console.error(`${jsonInput.length - rowsWithId.length} row(s) without an id were skipped.`);
|
|
80
|
-
}
|
|
81
|
-
const ids = rowsWithId ? rowsWithId.map((item) => item.id) : positionalIds;
|
|
82
|
-
try {
|
|
83
|
-
const response = await deleteEntityByIds(entityName, ids, {
|
|
84
|
-
suffix,
|
|
85
|
-
apiVersion: apiVersion,
|
|
86
|
-
});
|
|
87
|
-
if (IS_DRY_RUN) {
|
|
88
|
-
console.error('simulated deletion of entities:');
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.error('deleted entities:');
|
|
92
|
-
}
|
|
93
|
-
this.log(JSON.stringify(response, null, 2));
|
|
94
|
-
if (response.failed.length > 0) {
|
|
95
|
-
console.error(`${response.failed.length} of ${ids.length} deletes failed.`);
|
|
96
|
-
process.exitCode = 1;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
this.error(`Error deleting entities: ${e.message}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.default = DeleteEntity;
|
|
105
|
-
async function deleteEntityByIds(entityName, ids, routing = {}) {
|
|
106
|
-
const deletedIds = [];
|
|
107
|
-
const notFoundIds = [];
|
|
108
|
-
const failed = [];
|
|
109
|
-
const limit = (0, p_limit_1.default)(10);
|
|
110
|
-
const deletePromises = ids.map((id) => limit(() => deleteEntityById(entityName, id, routing).then((entity) => {
|
|
111
|
-
if (!entity) {
|
|
112
|
-
notFoundIds.push(id);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
deletedIds.push(id);
|
|
116
|
-
}, (error) => {
|
|
117
|
-
if (error.message.includes('not found')) {
|
|
118
|
-
notFoundIds.push(id);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
failed.push({ id, error: (0, common_1.sdkErrorMessage)(error) });
|
|
122
|
-
}
|
|
123
|
-
})));
|
|
124
|
-
await Promise.all(deletePromises);
|
|
125
|
-
return { deletedIds, notFoundIds, failed };
|
|
126
|
-
}
|
|
127
|
-
async function deleteEntityById(entityName, id, routing = {}) {
|
|
128
|
-
const client = new sdk_1.Entities();
|
|
129
|
-
if (IS_DRY_RUN) {
|
|
130
|
-
return client.get({ entityName, id, ignore404: true });
|
|
131
|
-
}
|
|
132
|
-
const { suffix, apiVersion } = routing;
|
|
133
|
-
return client.delete({ entityName, id, ignore404: true, suffix, apiVersion });
|
|
134
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '../../basecommand';
|
|
2
|
-
export default class GetEntity extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
outputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
|
-
propertySlugs: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
-
paginated: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
-
skip: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
-
skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
|
-
take: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
-
relations: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
-
suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
-
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
-
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
|
-
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
-
};
|
|
18
|
-
static args: {
|
|
19
|
-
typePath: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
20
|
-
ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
21
|
-
};
|
|
22
|
-
static strict: boolean;
|
|
23
|
-
run(): Promise<void>;
|
|
24
|
-
}
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
-
const core_1 = require("@oclif/core");
|
|
6
|
-
const basecommand_1 = require("../../basecommand");
|
|
7
|
-
const sdk_1 = require("@contrail/sdk");
|
|
8
|
-
const login_1 = require("../../auth/login");
|
|
9
|
-
const common_1 = require("../../common");
|
|
10
|
-
const types_1 = require("../../api/types");
|
|
11
|
-
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
12
|
-
const batchFetch_1 = require("../../helpers/entities/batchFetch");
|
|
13
|
-
let SHOULD_USE_PAGINATED_FIND = false;
|
|
14
|
-
let MAX_NUMBER_OF_ENTITIES_TO_FETCH = undefined;
|
|
15
|
-
class GetEntity extends basecommand_1.BaseCommand {
|
|
16
|
-
static description = 'Get an entity';
|
|
17
|
-
static examples = [
|
|
18
|
-
'contrail entities get color 123',
|
|
19
|
-
'contrail entities get color id1 id2 id3',
|
|
20
|
-
'contrail entities get color -- id=123',
|
|
21
|
-
'contrail entities get loader-processes -- createdOn=2025-09-15..2025-09-16',
|
|
22
|
-
'contrail entities get orders -- updatedAt=2025-09-15T04:00:00Z..',
|
|
23
|
-
'contrail entities get events -- timestamp=..2025-09-16T23:59:59Z',
|
|
24
|
-
];
|
|
25
|
-
static flags = {
|
|
26
|
-
...basecommand_1.BaseCommand.baseFlags,
|
|
27
|
-
outputFile: core_1.Flags.string({
|
|
28
|
-
char: 'o',
|
|
29
|
-
description: 'File to save the output (optional)',
|
|
30
|
-
required: false,
|
|
31
|
-
}),
|
|
32
|
-
propertySlugs: core_1.Flags.string({
|
|
33
|
-
char: 'p',
|
|
34
|
-
description: 'Comma-separated list of property slugs to include in the output',
|
|
35
|
-
required: false,
|
|
36
|
-
}),
|
|
37
|
-
paginated: core_1.Flags.boolean({
|
|
38
|
-
char: 'P',
|
|
39
|
-
description: 'If true, fetches all entities in a paginated manner',
|
|
40
|
-
required: false,
|
|
41
|
-
default: false,
|
|
42
|
-
}),
|
|
43
|
-
skip: core_1.Flags.integer({
|
|
44
|
-
char: 's',
|
|
45
|
-
description: 'Number of entities to skip (used with paginated fetch)',
|
|
46
|
-
required: false,
|
|
47
|
-
}),
|
|
48
|
-
skipHydrateRelationships: core_1.Flags.boolean({
|
|
49
|
-
char: 'S',
|
|
50
|
-
description: 'Skip hydrating relationships when fetching the entity',
|
|
51
|
-
required: false,
|
|
52
|
-
default: false,
|
|
53
|
-
}),
|
|
54
|
-
take: core_1.Flags.integer({
|
|
55
|
-
char: 't',
|
|
56
|
-
description: 'Number of entities to fetch in a single request (default is 100)',
|
|
57
|
-
required: false,
|
|
58
|
-
default: MAX_NUMBER_OF_ENTITIES_TO_FETCH,
|
|
59
|
-
}),
|
|
60
|
-
relations: core_1.Flags.string({
|
|
61
|
-
char: 'r',
|
|
62
|
-
description: 'Comma-separated list of relations to include in the output',
|
|
63
|
-
required: false,
|
|
64
|
-
}),
|
|
65
|
-
suffix: core_1.Flags.string({
|
|
66
|
-
description: 'Append a sub-route to the entity endpoint (e.g. --suffix=synchronous targets /<entities>/synchronous)',
|
|
67
|
-
required: false,
|
|
68
|
-
}),
|
|
69
|
-
apiVersion: core_1.Flags.string({
|
|
70
|
-
description: 'Api-Version header to send; selects the V1 or V2 variant of the endpoint',
|
|
71
|
-
options: ['1', '2'],
|
|
72
|
-
required: false,
|
|
73
|
-
}),
|
|
74
|
-
};
|
|
75
|
-
static args = {
|
|
76
|
-
typePath: core_1.Args.string({
|
|
77
|
-
description: 'The name of the entity type to fetch',
|
|
78
|
-
required: true,
|
|
79
|
-
}),
|
|
80
|
-
ids: core_1.Args.string({
|
|
81
|
-
description: 'One or more entity ids; shorthand for the id/ids criteria',
|
|
82
|
-
required: false,
|
|
83
|
-
}),
|
|
84
|
-
};
|
|
85
|
-
static strict = false;
|
|
86
|
-
async run() {
|
|
87
|
-
(0, common_1.routeConsoleLogToStderr)();
|
|
88
|
-
await (0, login_1.authUser)();
|
|
89
|
-
const { args, flags, argv } = await this.parse(GetEntity);
|
|
90
|
-
const { typePath } = args;
|
|
91
|
-
const { outputFile, paginated: shouldUsePaginatedFind, propertySlugs, relations: relationString, skip, skipHydrateRelationships, suffix, apiVersion, take, } = flags;
|
|
92
|
-
SHOULD_USE_PAGINATED_FIND = shouldUsePaginatedFind;
|
|
93
|
-
MAX_NUMBER_OF_ENTITIES_TO_FETCH = take;
|
|
94
|
-
if (MAX_NUMBER_OF_ENTITIES_TO_FETCH)
|
|
95
|
-
console.error(`Will limit output to ${MAX_NUMBER_OF_ENTITIES_TO_FETCH} entities.`);
|
|
96
|
-
const { ids: positionalIds, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(argv.slice(1));
|
|
97
|
-
const propertySpecBySlug = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
98
|
-
if (positionalIds.length > 0) {
|
|
99
|
-
if (propertySpecBySlug.has('id') || propertySpecBySlug.has('ids')) {
|
|
100
|
-
this.error('Pass ids positionally or as -- id=/ids= criteria, not both.');
|
|
101
|
-
}
|
|
102
|
-
if (propertySpecBySlug.size > 0) {
|
|
103
|
-
this.error('Positional ids cannot be combined with other -- criteria. Use -- ids= alongside the other criteria instead.');
|
|
104
|
-
}
|
|
105
|
-
if (positionalIds.length === 1) {
|
|
106
|
-
propertySpecBySlug.set('id', positionalIds[0]);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
propertySpecBySlug.set('ids', positionalIds);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const relations = relationString
|
|
113
|
-
? relationString
|
|
114
|
-
.split(',')
|
|
115
|
-
.map((r) => r.trim())
|
|
116
|
-
.filter(Boolean)
|
|
117
|
-
: [];
|
|
118
|
-
const propertySlugsArray = propertySlugs
|
|
119
|
-
? propertySlugs
|
|
120
|
-
.split(',')
|
|
121
|
-
.map((s) => s.trim())
|
|
122
|
-
.filter(Boolean)
|
|
123
|
-
: [];
|
|
124
|
-
try {
|
|
125
|
-
// TODO: Refactor this so it's easier to read. It was partially vibe-coded and Adam
|
|
126
|
-
// thinks it is hard to read. Consider breaking it into smaller functions.
|
|
127
|
-
if (SHOULD_USE_PAGINATED_FIND) {
|
|
128
|
-
const stream = streamPaginatedFind(typePath, {
|
|
129
|
-
criteria: convertPropertySpecIntoCriteria(propertySpecBySlug),
|
|
130
|
-
skipHydrateRelationships,
|
|
131
|
-
skip,
|
|
132
|
-
suffix,
|
|
133
|
-
apiVersion: apiVersion,
|
|
134
|
-
relations,
|
|
135
|
-
propertySlugs: propertySlugsArray,
|
|
136
|
-
});
|
|
137
|
-
const writer = outputFile ? fs_1.default.createWriteStream(outputFile) : process.stdout;
|
|
138
|
-
writer.write('[\n');
|
|
139
|
-
let first = true;
|
|
140
|
-
for await (const entity of stream) {
|
|
141
|
-
if (!first)
|
|
142
|
-
writer.write(',\n');
|
|
143
|
-
writer.write(JSON.stringify(entity, null, 2));
|
|
144
|
-
first = false;
|
|
145
|
-
}
|
|
146
|
-
writer.write('\n]\n');
|
|
147
|
-
if (outputFile)
|
|
148
|
-
console.error(`Output saved to ${outputFile}`);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
const response = await getEntityByTypePath(typePath, propertySpecBySlug, {
|
|
152
|
-
skipHydrateRelationships,
|
|
153
|
-
relations,
|
|
154
|
-
propertySlugs: propertySlugsArray,
|
|
155
|
-
skip,
|
|
156
|
-
suffix,
|
|
157
|
-
apiVersion: apiVersion,
|
|
158
|
-
take,
|
|
159
|
-
});
|
|
160
|
-
if (response === null) {
|
|
161
|
-
this.error(`Entity not found: ${propertySpecBySlug.get('id')}`, { exit: 1 });
|
|
162
|
-
}
|
|
163
|
-
if (outputFile) {
|
|
164
|
-
fs_1.default.writeFileSync(outputFile, JSON.stringify(response, null, 2));
|
|
165
|
-
console.error(`Output saved to ${outputFile}`);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
this.log(JSON.stringify(response, null, 2));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
if (e.message?.startsWith('Entity not found:')) {
|
|
174
|
-
throw e;
|
|
175
|
-
}
|
|
176
|
-
this.error(`Error fetching entity: ${e.message}`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.default = GetEntity;
|
|
181
|
-
async function getEntityByTypePath(typePath, propertySpec, options = {}) {
|
|
182
|
-
const { propertySlugs, relations, skipHydrateRelationships, skip, suffix, apiVersion, take } = options;
|
|
183
|
-
const id = propertySpec?.get('id')?.toString() || undefined;
|
|
184
|
-
const criteria = convertPropertySpecIntoCriteria(propertySpec || new Map());
|
|
185
|
-
const { root: entityName } = (0, types_1.parseTypePath)(typePath);
|
|
186
|
-
if (entityName === 'custom-entity' && !id) {
|
|
187
|
-
criteria.typePath = typePath;
|
|
188
|
-
}
|
|
189
|
-
return find(entityName, {
|
|
190
|
-
id,
|
|
191
|
-
// a missing id returns null (no retries); the command turns it into a clean not-found error
|
|
192
|
-
ignore404: id !== undefined,
|
|
193
|
-
skipHydrateRelationships,
|
|
194
|
-
relations,
|
|
195
|
-
propertySlugs,
|
|
196
|
-
criteria,
|
|
197
|
-
skip,
|
|
198
|
-
suffix,
|
|
199
|
-
apiVersion,
|
|
200
|
-
take,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
function convertPropertySpecIntoCriteria(propertySpec) {
|
|
204
|
-
const criteria = {};
|
|
205
|
-
propertySpec.forEach((value, slug) => {
|
|
206
|
-
criteria[slug] = value;
|
|
207
|
-
});
|
|
208
|
-
return criteria;
|
|
209
|
-
}
|
|
210
|
-
async function find(entityName, options = {}) {
|
|
211
|
-
const client = new sdk_1.Entities();
|
|
212
|
-
const { criteria, id, ignore404, propertySlugs, skipHydrateRelationships, relations, skip, suffix, apiVersion, take, } = options;
|
|
213
|
-
const queryOptions = {
|
|
214
|
-
entityName,
|
|
215
|
-
ignore404,
|
|
216
|
-
skipHydrateRelationships,
|
|
217
|
-
relations,
|
|
218
|
-
skip,
|
|
219
|
-
suffix,
|
|
220
|
-
apiVersion,
|
|
221
|
-
take,
|
|
222
|
-
};
|
|
223
|
-
if (propertySlugs && propertySlugs.length > 0) {
|
|
224
|
-
queryOptions.customParams = { propertySlugs: propertySlugs.join(',') };
|
|
225
|
-
}
|
|
226
|
-
const payload = id ? { id, ...queryOptions } : { criteria, ...queryOptions };
|
|
227
|
-
// a suffix names a specific sub-route and an id names one entity; both always go
|
|
228
|
-
// through the plain client (batch-fetch only understands criteria)
|
|
229
|
-
if ((0, batchFetch_1.canBatchFetchEntity)(entityName) && !suffix && !id) {
|
|
230
|
-
return (0, batchFetch_1.batchFetch)(entityName, payload);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
return client.get(payload);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
async function* streamPaginatedFind(typePath, options = {}) {
|
|
237
|
-
const client = new sdk_1.Entities();
|
|
238
|
-
let nextPageKey = undefined;
|
|
239
|
-
let count = 0;
|
|
240
|
-
const { root: entityName } = (0, types_1.parseTypePath)(typePath);
|
|
241
|
-
while (true) {
|
|
242
|
-
const opts = {
|
|
243
|
-
...options,
|
|
244
|
-
entityName,
|
|
245
|
-
// paginated reads require the V2 response shape unless overridden
|
|
246
|
-
apiVersion: options.apiVersion ?? sdk_1.API_VERSION.V2,
|
|
247
|
-
nextPageKey,
|
|
248
|
-
};
|
|
249
|
-
if (options.propertySlugs?.length > 0) {
|
|
250
|
-
opts.customParams = {
|
|
251
|
-
propertySlugs: options.propertySlugs.join(','),
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
const response = await client.get(opts);
|
|
255
|
-
nextPageKey = response.nextPageKey;
|
|
256
|
-
const results = response.results || [];
|
|
257
|
-
for (const result of results) {
|
|
258
|
-
yield result;
|
|
259
|
-
count++;
|
|
260
|
-
if (MAX_NUMBER_OF_ENTITIES_TO_FETCH && count >= MAX_NUMBER_OF_ENTITIES_TO_FETCH)
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
console.error(`Fetched ${count} entities`);
|
|
264
|
-
if (!nextPageKey || results.length === 0)
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
// Useful for troubleshooting
|
|
269
|
-
function logMemoryUsage(entityCount) {
|
|
270
|
-
const used = process.memoryUsage();
|
|
271
|
-
const toMB = (bytes) => (bytes / 1024 / 1024).toFixed(2);
|
|
272
|
-
console.error(`[${entityCount} entities] Memory Usage → RSS: ${toMB(used.rss)} MB | Heap: ${toMB(used.heapUsed)} MB / ${toMB(used.heapTotal)} MB`);
|
|
273
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const create_1 = tslib_1.__importDefault(require("./create"));
|
|
5
|
-
const get_1 = tslib_1.__importDefault(require("./get"));
|
|
6
|
-
const update_1 = tslib_1.__importDefault(require("./update"));
|
|
7
|
-
const delete_1 = tslib_1.__importDefault(require("./delete"));
|
|
8
|
-
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
9
|
-
describe('entities command grammar: entities <verb> <typePath> [ID...]', () => {
|
|
10
|
-
describe('partitionIdsAndSpecs', () => {
|
|
11
|
-
it('should treat tokens without an equals sign as ids', () => {
|
|
12
|
-
const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['id1', 'id2', 'id3']);
|
|
13
|
-
expect(ids).toEqual(['id1', 'id2', 'id3']);
|
|
14
|
-
expect(specs).toEqual([]);
|
|
15
|
-
});
|
|
16
|
-
it('should treat slug=value tokens as property specifications', () => {
|
|
17
|
-
const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['name=jet', 'hex=000000']);
|
|
18
|
-
expect(ids).toEqual([]);
|
|
19
|
-
expect(specs).toEqual(['name=jet', 'hex=000000']);
|
|
20
|
-
});
|
|
21
|
-
it('should split mixed tokens preserving order within each group', () => {
|
|
22
|
-
const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['id1', 'name=jet', 'id2', 'status=archived']);
|
|
23
|
-
expect(ids).toEqual(['id1', 'id2']);
|
|
24
|
-
expect(specs).toEqual(['name=jet', 'status=archived']);
|
|
25
|
-
});
|
|
26
|
-
it('should not classify malformed specs as ids', () => {
|
|
27
|
-
const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)(['=value']);
|
|
28
|
-
expect(ids).toEqual([]);
|
|
29
|
-
expect(specs).toEqual([]);
|
|
30
|
-
});
|
|
31
|
-
it('should handle empty input', () => {
|
|
32
|
-
const { ids, specs } = (0, propertySpecifications_1.partitionIdsAndSpecs)([]);
|
|
33
|
-
expect(ids).toEqual([]);
|
|
34
|
-
expect(specs).toEqual([]);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('positional id arguments', () => {
|
|
38
|
-
it('should accept variadic positional ids on get', () => {
|
|
39
|
-
expect(get_1.default.strict).toBe(false);
|
|
40
|
-
expect(get_1.default.args.ids).toBeDefined();
|
|
41
|
-
});
|
|
42
|
-
it('should accept variadic positional ids on update with no single id arg', () => {
|
|
43
|
-
expect(update_1.default.strict).toBe(false);
|
|
44
|
-
expect(update_1.default.args.ids).toBeDefined();
|
|
45
|
-
expect(update_1.default.args.id).toBeUndefined();
|
|
46
|
-
});
|
|
47
|
-
it('should accept variadic positional ids on delete with no --id flag', () => {
|
|
48
|
-
expect(delete_1.default.strict).toBe(false);
|
|
49
|
-
expect(delete_1.default.args.ids).toBeDefined();
|
|
50
|
-
expect(delete_1.default.flags.id).toBeUndefined();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('flag alignment across verbs', () => {
|
|
54
|
-
it('should name the input file -i, --inputFile on every verb that accepts one', () => {
|
|
55
|
-
expect(create_1.default.flags.inputFile.char).toBe('i');
|
|
56
|
-
expect(update_1.default.flags.inputFile.char).toBe('i');
|
|
57
|
-
expect(delete_1.default.flags.inputFile.char).toBe('i');
|
|
58
|
-
expect(delete_1.default.flags.input).toBeUndefined();
|
|
59
|
-
});
|
|
60
|
-
it('should map skipHydrateRelationships to -S on every verb', () => {
|
|
61
|
-
expect(create_1.default.flags.skipHydrateRelationships.char).toBe('S');
|
|
62
|
-
expect(get_1.default.flags.skipHydrateRelationships.char).toBe('S');
|
|
63
|
-
expect(update_1.default.flags.skipHydrateRelationships.char).toBe('S');
|
|
64
|
-
});
|
|
65
|
-
it('should keep -s for --skip on get', () => {
|
|
66
|
-
expect(get_1.default.flags.skip.char).toBe('s');
|
|
67
|
-
});
|
|
68
|
-
it('should expose --suffix on every verb to reach entity sub-routes', () => {
|
|
69
|
-
expect(create_1.default.flags.suffix).toBeDefined();
|
|
70
|
-
expect(get_1.default.flags.suffix).toBeDefined();
|
|
71
|
-
expect(update_1.default.flags.suffix).toBeDefined();
|
|
72
|
-
expect(delete_1.default.flags.suffix).toBeDefined();
|
|
73
|
-
});
|
|
74
|
-
it('should expose --apiVersion on every verb, constrained to 1 or 2', () => {
|
|
75
|
-
for (const command of [create_1.default, get_1.default, update_1.default, delete_1.default]) {
|
|
76
|
-
expect(command.flags.apiVersion.options).toEqual(['1', '2']);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const create_1 = require("./create");
|
|
4
|
-
const update_1 = require("./update");
|
|
5
|
-
const fulfilled = (value) => ({ status: 'fulfilled', value });
|
|
6
|
-
const rejected = (message) => ({
|
|
7
|
-
status: 'rejected',
|
|
8
|
-
reason: new Error(message),
|
|
9
|
-
});
|
|
10
|
-
describe('mutation output summaries', () => {
|
|
11
|
-
describe('summarizeSettledCreates', () => {
|
|
12
|
-
it('should put every fulfilled result under created', () => {
|
|
13
|
-
const inputs = [{ name: 'a' }, { name: 'b' }];
|
|
14
|
-
const summary = (0, create_1.summarizeSettledCreates)(inputs, [
|
|
15
|
-
fulfilled({ id: '1', name: 'a' }),
|
|
16
|
-
fulfilled({ id: '2', name: 'b' }),
|
|
17
|
-
]);
|
|
18
|
-
expect(summary.created).toEqual([
|
|
19
|
-
{ id: '1', name: 'a' },
|
|
20
|
-
{ id: '2', name: 'b' },
|
|
21
|
-
]);
|
|
22
|
-
expect(summary.failed).toEqual([]);
|
|
23
|
-
});
|
|
24
|
-
it('should pair each failed input with its error so it can be retried as-is', () => {
|
|
25
|
-
const inputs = [{ itemId: 'itm-1' }, { itemId: 'itm-41x' }, { itemId: 'itm-3' }];
|
|
26
|
-
const summary = (0, create_1.summarizeSettledCreates)(inputs, [
|
|
27
|
-
fulfilled({ id: 'ai-1' }),
|
|
28
|
-
rejected('Item with ID itm-41x does not exist'),
|
|
29
|
-
fulfilled({ id: 'ai-3' }),
|
|
30
|
-
]);
|
|
31
|
-
expect(summary.created).toEqual([{ id: 'ai-1' }, { id: 'ai-3' }]);
|
|
32
|
-
expect(summary.failed).toEqual([
|
|
33
|
-
{ input: { itemId: 'itm-41x' }, error: 'Item with ID itm-41x does not exist' },
|
|
34
|
-
]);
|
|
35
|
-
});
|
|
36
|
-
it('should fall back to details when the SDK error message is empty', () => {
|
|
37
|
-
const sdkError = Object.assign(new Error(''), {
|
|
38
|
-
details: '{"message":"Assortment not found.","statusCode":404}',
|
|
39
|
-
});
|
|
40
|
-
const summary = (0, create_1.summarizeSettledCreates)([{ assortmentId: 'bogus' }], [{ status: 'rejected', reason: sdkError }]);
|
|
41
|
-
expect(summary.failed[0].error).toBe('{"message":"Assortment not found.","statusCode":404}');
|
|
42
|
-
});
|
|
43
|
-
it('should stringify reasons that are not Errors', () => {
|
|
44
|
-
const summary = (0, create_1.summarizeSettledCreates)([{ name: 'a' }], [{ status: 'rejected', reason: 'boom' }]);
|
|
45
|
-
expect(summary.failed).toEqual([{ input: { name: 'a' }, error: 'boom' }]);
|
|
46
|
-
});
|
|
47
|
-
it('should handle empty input', () => {
|
|
48
|
-
expect((0, create_1.summarizeSettledCreates)([], [])).toEqual({ created: [], failed: [] });
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe('summarizeSettledUpdates', () => {
|
|
52
|
-
it('should report updated, failed, and skipped without stopping on failures', () => {
|
|
53
|
-
const inputs = [{ id: 'id1' }, { id: 'id2' }, { id: 'id3' }];
|
|
54
|
-
const summary = (0, update_1.summarizeSettledUpdates)(inputs, [
|
|
55
|
-
fulfilled({ id: 'id1', status: 'archived' }),
|
|
56
|
-
rejected('Entity not found.'),
|
|
57
|
-
fulfilled({ id: 'id3', status: 'archived' }),
|
|
58
|
-
], 2);
|
|
59
|
-
expect(summary.updated).toEqual([
|
|
60
|
-
{ id: 'id1', status: 'archived' },
|
|
61
|
-
{ id: 'id3', status: 'archived' },
|
|
62
|
-
]);
|
|
63
|
-
expect(summary.failed).toEqual([{ id: 'id2', error: 'Entity not found.' }]);
|
|
64
|
-
expect(summary.skipped).toBe(2);
|
|
65
|
-
});
|
|
66
|
-
it('should not report a failed id as updated', () => {
|
|
67
|
-
const summary = (0, update_1.summarizeSettledUpdates)([{ id: 'id1' }], [rejected('boom')], 0);
|
|
68
|
-
expect(summary.updated).toEqual([]);
|
|
69
|
-
expect(summary.failed).toEqual([{ id: 'id1', error: 'boom' }]);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '../../basecommand';
|
|
2
|
-
export default class UpdateEntity extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
-
dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
|
-
inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
-
suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
-
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
-
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
-
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
-
};
|
|
14
|
-
static args: {
|
|
15
|
-
entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
16
|
-
ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
17
|
-
};
|
|
18
|
-
static strict: boolean;
|
|
19
|
-
run(): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export type UpdateSummary = {
|
|
22
|
-
updated: any[];
|
|
23
|
-
failed: {
|
|
24
|
-
id: string;
|
|
25
|
-
error: string;
|
|
26
|
-
}[];
|
|
27
|
-
skipped: number;
|
|
28
|
-
};
|
|
29
|
-
export declare function summarizeSettledUpdates(inputs: {
|
|
30
|
-
id: string;
|
|
31
|
-
}[], settled: PromiseSettledResult<any>[], skipped: number): UpdateSummary;
|