@commercelayer/cli-core 4.12.0 → 4.12.1
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/lib/cjs/api.js +107 -1
- package/lib/cjs/application.js +36 -1
- package/lib/cjs/color.js +116 -1
- package/lib/cjs/command.js +95 -1
- package/lib/cjs/config.js +182 -1
- package/lib/cjs/filter.js +81 -1
- package/lib/cjs/help.js +103 -5
- package/lib/cjs/index.js +46 -1
- package/lib/cjs/inflector.js +255 -1
- package/lib/cjs/jsonapi.js +38 -1
- package/lib/cjs/output.js +83 -3
- package/lib/cjs/raw.js +49 -1
- package/lib/cjs/schema.js +20 -1
- package/lib/cjs/style.js +39 -1
- package/lib/cjs/symbol.js +28 -1
- package/lib/cjs/text.js +23 -1
- package/lib/cjs/token.js +177 -1
- package/lib/cjs/update.js +22 -4
- package/lib/cjs/util.js +59 -2
- package/lib/esm/api.js +93 -1
- package/lib/esm/application.js +26 -1
- package/lib/esm/color.js +110 -1
- package/lib/esm/command.js +90 -1
- package/lib/esm/config.js +180 -1
- package/lib/esm/filter.js +71 -1
- package/lib/esm/help.js +100 -5
- package/lib/esm/index.js +26 -1
- package/lib/esm/inflector.js +253 -1
- package/lib/esm/jsonapi.js +42 -1
- package/lib/esm/output.js +72 -3
- package/lib/esm/raw.js +42 -1
- package/lib/esm/schema.js +14 -1
- package/lib/esm/style.js +19 -1
- package/lib/esm/symbol.js +25 -1
- package/lib/esm/text.js +13 -1
- package/lib/esm/token.js +166 -1
- package/lib/esm/update.js +16 -4
- package/lib/esm/util.js +51 -2
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -17
package/lib/esm/color.js
CHANGED
|
@@ -1 +1,110 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export const reset = chalk.reset;
|
|
3
|
+
export const visible = chalk.visible;
|
|
4
|
+
export const hidden = chalk.hidden;
|
|
5
|
+
export const red = chalk.red;
|
|
6
|
+
export const redBright = chalk.redBright;
|
|
7
|
+
export const green = chalk.green;
|
|
8
|
+
export const greenBright = chalk.greenBright;
|
|
9
|
+
export const yellow = chalk.yellow;
|
|
10
|
+
export const yellowBright = chalk.yellowBright;
|
|
11
|
+
export const blue = chalk.blue;
|
|
12
|
+
export const blueBright = chalk.blueBright;
|
|
13
|
+
export const white = chalk.white;
|
|
14
|
+
export const whiteBright = chalk.whiteBright;
|
|
15
|
+
export const black = chalk.black;
|
|
16
|
+
export const blackBright = chalk.blackBright;
|
|
17
|
+
export const grey = chalk.grey;
|
|
18
|
+
export const cyan = chalk.cyan;
|
|
19
|
+
export const cyanBright = chalk.cyanBright;
|
|
20
|
+
export const magenta = chalk.magenta;
|
|
21
|
+
export const magentaBright = chalk.magentaBright;
|
|
22
|
+
export const bold = chalk.bold;
|
|
23
|
+
export const dim = chalk.dim;
|
|
24
|
+
export const underline = chalk.underline;
|
|
25
|
+
export const italic = chalk.italic;
|
|
26
|
+
export const bg = {
|
|
27
|
+
white: chalk.bgWhite,
|
|
28
|
+
whiteBright: chalk.bgWhiteBright,
|
|
29
|
+
black: chalk.bgBlack,
|
|
30
|
+
blackBright: chalk.bgBlackBright,
|
|
31
|
+
grey: chalk.bgGrey,
|
|
32
|
+
red: chalk.bgRed,
|
|
33
|
+
redBright: chalk.bgRedBright,
|
|
34
|
+
green: chalk.bgGreen,
|
|
35
|
+
greenBright: chalk.bgGreenBright,
|
|
36
|
+
yellow: chalk.bgYellow,
|
|
37
|
+
yellowBright: chalk.bgYellowBright,
|
|
38
|
+
blue: chalk.bgBlue,
|
|
39
|
+
blueBright: chalk.bgBlueBright,
|
|
40
|
+
magenta: chalk.bgMagenta,
|
|
41
|
+
magentaBright: chalk.bgMagentaBright,
|
|
42
|
+
cyan: chalk.bgCyan,
|
|
43
|
+
cyanBright: chalk.bgCyanBright
|
|
44
|
+
};
|
|
45
|
+
export const style = {
|
|
46
|
+
organization: yellowBright.bold,
|
|
47
|
+
application: yellowBright.bold,
|
|
48
|
+
slug: yellowBright,
|
|
49
|
+
id: bold,
|
|
50
|
+
token: blueBright,
|
|
51
|
+
resource: bold,
|
|
52
|
+
attribute: italic,
|
|
53
|
+
trigger: cyanBright,
|
|
54
|
+
kind: cyanBright,
|
|
55
|
+
live: greenBright,
|
|
56
|
+
test: yellowBright,
|
|
57
|
+
execMode: (mode) => { return (mode === 'live') ? style.live : style.test; },
|
|
58
|
+
success: greenBright,
|
|
59
|
+
warning: yellowBright,
|
|
60
|
+
error: redBright,
|
|
61
|
+
arg: italic,
|
|
62
|
+
flag: italic,
|
|
63
|
+
command: italic,
|
|
64
|
+
value: italic,
|
|
65
|
+
alias: cyanBright,
|
|
66
|
+
plugin: blueBright,
|
|
67
|
+
title: blueBright,
|
|
68
|
+
path: italic,
|
|
69
|
+
datetime: cyanBright,
|
|
70
|
+
number: yellowBright,
|
|
71
|
+
};
|
|
72
|
+
/* Aliases */
|
|
73
|
+
export const type = {
|
|
74
|
+
datetime: style.datetime,
|
|
75
|
+
number: style.number,
|
|
76
|
+
path: style.path
|
|
77
|
+
};
|
|
78
|
+
/* Aliases */
|
|
79
|
+
export const api = {
|
|
80
|
+
organization: style.organization,
|
|
81
|
+
application: style.application,
|
|
82
|
+
slug: style.slug,
|
|
83
|
+
id: style.id,
|
|
84
|
+
token: style.token,
|
|
85
|
+
resource: style.resource,
|
|
86
|
+
attribute: style.attribute,
|
|
87
|
+
trigger: style.trigger,
|
|
88
|
+
kind: style.kind,
|
|
89
|
+
live: style.live,
|
|
90
|
+
test: style.test,
|
|
91
|
+
};
|
|
92
|
+
/* Aliases */
|
|
93
|
+
export const msg = {
|
|
94
|
+
success: style.success,
|
|
95
|
+
warning: style.warning,
|
|
96
|
+
error: style.error,
|
|
97
|
+
};
|
|
98
|
+
/* Aliases */
|
|
99
|
+
export const cli = {
|
|
100
|
+
arg: style.arg,
|
|
101
|
+
flag: style.flag,
|
|
102
|
+
command: style.command,
|
|
103
|
+
value: style.value,
|
|
104
|
+
alias: style.alias,
|
|
105
|
+
plugin: style.plugin
|
|
106
|
+
};
|
|
107
|
+
export const table = {
|
|
108
|
+
header: yellowBright.bold,
|
|
109
|
+
key: blueBright
|
|
110
|
+
};
|
package/lib/esm/command.js
CHANGED
|
@@ -1 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
+
/** Copy command flags excluding a subset */
|
|
3
|
+
const commandFlags = (flags, exclude) => {
|
|
4
|
+
const filteredFlags = Object.assign({}, flags);
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
6
|
+
if (exclude)
|
|
7
|
+
for (const e of exclude)
|
|
8
|
+
delete filteredFlags[e];
|
|
9
|
+
return filteredFlags;
|
|
10
|
+
};
|
|
11
|
+
export { commandFlags };
|
|
12
|
+
const fixValueType = (val) => {
|
|
13
|
+
let v = val;
|
|
14
|
+
if (v === 'null')
|
|
15
|
+
v = null; // null check
|
|
16
|
+
else
|
|
17
|
+
// eslint-disable-next-line eqeqeq
|
|
18
|
+
if (Number(v) == v)
|
|
19
|
+
v = Number(v); // number check
|
|
20
|
+
else
|
|
21
|
+
v = (v === 'true') ? true : (v === 'false') ? false : v; // boolean check
|
|
22
|
+
return v;
|
|
23
|
+
};
|
|
24
|
+
const findLongStringFlag = (args, name) => {
|
|
25
|
+
const flag = name.startsWith('--') ? name : `--${name}`;
|
|
26
|
+
let value;
|
|
27
|
+
const index = args.findIndex(arg => arg.startsWith(flag));
|
|
28
|
+
let single = false;
|
|
29
|
+
if (index > -1) {
|
|
30
|
+
const val = args[index];
|
|
31
|
+
if (val.includes('=')) {
|
|
32
|
+
const vals = val.split('=');
|
|
33
|
+
value = (vals.length === 2) ? vals[1] : '';
|
|
34
|
+
single = true;
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
value = args[index + 1];
|
|
38
|
+
return { value, index, single };
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
return undefined;
|
|
42
|
+
};
|
|
43
|
+
const fixDashedFlagValue = (argv, flag, name, parsed) => {
|
|
44
|
+
const TEMP_PREFIX = '____';
|
|
45
|
+
const name_ = flag.name || name;
|
|
46
|
+
const char_ = flag.char;
|
|
47
|
+
if (!name_ && !char_)
|
|
48
|
+
return argv;
|
|
49
|
+
const n = name_ ? (name_.startsWith('--') ? name_ : `--${name_}`) : undefined;
|
|
50
|
+
const c = char_ ? (flag.char.startsWith('-') ? char_ : `-${char_}`) : undefined;
|
|
51
|
+
let cidIdx = argv.findIndex(a => {
|
|
52
|
+
return ((c && a.startsWith(c)) || (n && a.startsWith(n)));
|
|
53
|
+
});
|
|
54
|
+
if (cidIdx < 0)
|
|
55
|
+
return argv;
|
|
56
|
+
let flagKey = argv[cidIdx];
|
|
57
|
+
let flagValue = '';
|
|
58
|
+
let prefix = '';
|
|
59
|
+
if (c && flagKey.startsWith(c)) {
|
|
60
|
+
flagValue = flagKey.replace(c, '').trim();
|
|
61
|
+
flagKey = c;
|
|
62
|
+
}
|
|
63
|
+
else if (n && flagKey.startsWith(n)) {
|
|
64
|
+
flagValue = flagKey.replace(n, '').trim();
|
|
65
|
+
flagKey = n;
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
return argv;
|
|
69
|
+
if (flagValue.startsWith('=')) {
|
|
70
|
+
flagValue = flagValue.slice(1);
|
|
71
|
+
prefix = flagKey + '=';
|
|
72
|
+
}
|
|
73
|
+
else if (!flagValue)
|
|
74
|
+
flagValue = argv[++cidIdx];
|
|
75
|
+
if (flagValue.startsWith('-') || flagValue.startsWith(TEMP_PREFIX)) {
|
|
76
|
+
const val = flagValue.startsWith(`${TEMP_PREFIX}`) ? flagValue.replace(`${TEMP_PREFIX}`, '') : flagValue.replace('-', `${TEMP_PREFIX}-`);
|
|
77
|
+
argv[cidIdx] = prefix + val;
|
|
78
|
+
if (flagValue.startsWith(TEMP_PREFIX) && parsed) {
|
|
79
|
+
const nameKey = name_ ? name_.replace('--', '') : undefined;
|
|
80
|
+
const parsedFlag = Object.entries(parsed.flags).find(([k, v]) => v === flagValue);
|
|
81
|
+
if (parsedFlag && (!nameKey || nameKey === parsedFlag[0]))
|
|
82
|
+
parsed.flags[parsedFlag[0]] = val;
|
|
83
|
+
const parsedRawFlag = Object.values(parsed.raw).find((f) => (f.type === 'flag') && (f.input === flagValue));
|
|
84
|
+
if (parsedRawFlag && (!nameKey || nameKey === parsedRawFlag.flag))
|
|
85
|
+
parsedRawFlag.input = val;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return argv;
|
|
89
|
+
};
|
|
90
|
+
export { fixValueType, findLongStringFlag, fixDashedFlagValue };
|
package/lib/esm/config.js
CHANGED
|
@@ -1 +1,180 @@
|
|
|
1
|
-
const
|
|
1
|
+
const JOB_STATUSES = [
|
|
2
|
+
'in_progress',
|
|
3
|
+
'pending',
|
|
4
|
+
'completed',
|
|
5
|
+
'interrupted'
|
|
6
|
+
];
|
|
7
|
+
const IMPORT_RESOURCE_TYPES = [
|
|
8
|
+
'addresses',
|
|
9
|
+
'bundles',
|
|
10
|
+
'coupons',
|
|
11
|
+
'customer_addresses',
|
|
12
|
+
'customer_payment_sources',
|
|
13
|
+
'customer_subscriptions',
|
|
14
|
+
'customers',
|
|
15
|
+
'gift_cards',
|
|
16
|
+
'line_items',
|
|
17
|
+
'line_item_options',
|
|
18
|
+
'orders',
|
|
19
|
+
'price_tiers',
|
|
20
|
+
'prices',
|
|
21
|
+
'shipping_categories',
|
|
22
|
+
'sku_lists',
|
|
23
|
+
'sku_list_items',
|
|
24
|
+
'sku_options',
|
|
25
|
+
'skus',
|
|
26
|
+
'stock_items',
|
|
27
|
+
'tags',
|
|
28
|
+
'tax_categories'
|
|
29
|
+
];
|
|
30
|
+
const EXPORT_RESOURCE_TYPES = [
|
|
31
|
+
'addresses',
|
|
32
|
+
'authorizations',
|
|
33
|
+
'bundles',
|
|
34
|
+
'captures',
|
|
35
|
+
'coupons',
|
|
36
|
+
'customer_addresses',
|
|
37
|
+
'customer_subscriptions',
|
|
38
|
+
'customers',
|
|
39
|
+
'gift_cards',
|
|
40
|
+
'line_items',
|
|
41
|
+
'orders',
|
|
42
|
+
'payment_methods',
|
|
43
|
+
'price_tiers',
|
|
44
|
+
'prices',
|
|
45
|
+
'refunds',
|
|
46
|
+
'shipments',
|
|
47
|
+
'shipping_categories',
|
|
48
|
+
'shipping_methods',
|
|
49
|
+
'sku_lists',
|
|
50
|
+
'sku_list_items',
|
|
51
|
+
'sku_options',
|
|
52
|
+
'skus',
|
|
53
|
+
'stock_items',
|
|
54
|
+
'tags',
|
|
55
|
+
'tax_categories',
|
|
56
|
+
'transactions',
|
|
57
|
+
'voids'
|
|
58
|
+
];
|
|
59
|
+
const CLEANUP_RESOURCE_TYPES = [
|
|
60
|
+
'bundles',
|
|
61
|
+
'gift_cards',
|
|
62
|
+
'prices',
|
|
63
|
+
'promotions',
|
|
64
|
+
'sku_lists',
|
|
65
|
+
'sku_options',
|
|
66
|
+
'skus',
|
|
67
|
+
'stock_items'
|
|
68
|
+
];
|
|
69
|
+
const TAG_RESOURCE_TYPES = [
|
|
70
|
+
'addresses',
|
|
71
|
+
'bundles',
|
|
72
|
+
'customers',
|
|
73
|
+
'coupons',
|
|
74
|
+
'gift_cards',
|
|
75
|
+
'line_items',
|
|
76
|
+
'line_item_options',
|
|
77
|
+
'orders',
|
|
78
|
+
'returns',
|
|
79
|
+
'skus',
|
|
80
|
+
'sku_options',
|
|
81
|
+
'promotions',
|
|
82
|
+
'external_promotions',
|
|
83
|
+
'fixed_amount_promotions',
|
|
84
|
+
'fixed_price_promotions',
|
|
85
|
+
'free_gift_promotions',
|
|
86
|
+
'free_shipping_promotions',
|
|
87
|
+
'percentage_discount_promotions'
|
|
88
|
+
];
|
|
89
|
+
const RATE_LIMIT = {
|
|
90
|
+
erl_oauth_limit_live: 30,
|
|
91
|
+
erl_burst_limit_uncachable_live: 50,
|
|
92
|
+
erl_burst_limit_uncachable_test: 25,
|
|
93
|
+
erl_burst_limit_cachable_live: 250,
|
|
94
|
+
erl_burst_limit_cachable_test: 125,
|
|
95
|
+
erl_average_limit_uncachable_live: 200,
|
|
96
|
+
erl_average_limit_uncachable_test: 100,
|
|
97
|
+
erl_average_limit_cachable_live: 1000,
|
|
98
|
+
erl_average_limit_cachable_test: 500
|
|
99
|
+
};
|
|
100
|
+
const config = {
|
|
101
|
+
api: {
|
|
102
|
+
default_domain: 'commercelayer.io',
|
|
103
|
+
default_app_domain: 'commercelayer.app',
|
|
104
|
+
default_stg_domain: 'commercelayer.co',
|
|
105
|
+
token_expiration_mins: 60 * 4, // 4 hours (14400 secs)
|
|
106
|
+
token_encoding_algorithm: 'HS512',
|
|
107
|
+
requests_max_num_burst: RATE_LIMIT.erl_burst_limit_uncachable_live, // 50
|
|
108
|
+
requests_max_num_burst_cacheable: RATE_LIMIT.erl_burst_limit_cachable_live, // 250
|
|
109
|
+
requests_max_num_burst_test: RATE_LIMIT.erl_burst_limit_uncachable_test, // 25
|
|
110
|
+
requests_max_num_burst_test_cacheable: RATE_LIMIT.erl_burst_limit_cachable_test, // 125
|
|
111
|
+
requests_max_num_avg: RATE_LIMIT.erl_average_limit_uncachable_live, // 200
|
|
112
|
+
requests_max_num_avg_cacheable: RATE_LIMIT.erl_average_limit_cachable_live, // 1000
|
|
113
|
+
requests_max_num_avg_test: RATE_LIMIT.erl_average_limit_uncachable_test, // 100
|
|
114
|
+
requests_max_num_avg_test_cacheable: RATE_LIMIT.erl_average_limit_cachable_test, // 500
|
|
115
|
+
requests_max_num_oauth: RATE_LIMIT.erl_oauth_limit_live, // 30
|
|
116
|
+
requests_max_secs_burst: 10,
|
|
117
|
+
requests_max_secs_oauth: 60,
|
|
118
|
+
requests_max_secs_avg: 60,
|
|
119
|
+
page_max_size: 25,
|
|
120
|
+
page_default_size: 10,
|
|
121
|
+
},
|
|
122
|
+
application: {
|
|
123
|
+
kinds: ['integration', 'sales_channel', 'webapp', 'user'],
|
|
124
|
+
login_scopes: ['market', 'stock_location'],
|
|
125
|
+
},
|
|
126
|
+
imports: {
|
|
127
|
+
max_size: 5000,
|
|
128
|
+
statuses: JOB_STATUSES,
|
|
129
|
+
types: IMPORT_RESOURCE_TYPES,
|
|
130
|
+
max_queue_length: 10,
|
|
131
|
+
attachment_expiration: 5
|
|
132
|
+
},
|
|
133
|
+
exports: {
|
|
134
|
+
max_size: 10000,
|
|
135
|
+
statuses: JOB_STATUSES,
|
|
136
|
+
types: EXPORT_RESOURCE_TYPES,
|
|
137
|
+
max_queue_length: 10,
|
|
138
|
+
attachment_expiration: 5
|
|
139
|
+
},
|
|
140
|
+
cleanups: {
|
|
141
|
+
max_size: 10000,
|
|
142
|
+
statuses: JOB_STATUSES,
|
|
143
|
+
types: CLEANUP_RESOURCE_TYPES,
|
|
144
|
+
max_queue_length: 10
|
|
145
|
+
},
|
|
146
|
+
webhooks: {
|
|
147
|
+
retry_number: 5,
|
|
148
|
+
},
|
|
149
|
+
cli: {
|
|
150
|
+
applications: ['integration', 'sales_channel', 'user'],
|
|
151
|
+
},
|
|
152
|
+
doc: {
|
|
153
|
+
core: 'https://docs.commercelayer.io/core/',
|
|
154
|
+
core_api_reference: 'https://docs.commercelayer.io/developers/v/api-reference',
|
|
155
|
+
core_how_tos: 'https://docs.commercelayer.io/core/v/how-tos/',
|
|
156
|
+
core_raste_limits: 'https://docs.commercelayer.io/core/rate-limits',
|
|
157
|
+
core_filtering_data: 'https://docs.commercelayer.io/core/filtering-data#list-of-predicates',
|
|
158
|
+
metrics: 'https://docs.commercelayer.io/metrics/',
|
|
159
|
+
metrics_api_reference: 'https://docs.commercelayer.io/metrics/v/api-reference-m/',
|
|
160
|
+
provisioning: 'https://docs.commercelayer.io/provisioning/',
|
|
161
|
+
provisioning_api_reference: 'https://docs.commercelayer.io/provisioning/v/api-reference-p/',
|
|
162
|
+
imports_resources: 'https://docs.commercelayer.io/api/importing-resources#supported-resources',
|
|
163
|
+
exports_resources: 'https://docs.commercelayer.io/core/exporting-resources#supported-resources',
|
|
164
|
+
cleanups_resources: 'https://docs.commercelayer.io/core/cleaning-resources#supported-resources',
|
|
165
|
+
webhooks_events: 'https://docs.commercelayer.io/api/real-time-webhooks#supported-events',
|
|
166
|
+
tags_resources: 'https://docs.commercelayer.io/core/v/api-reference/tags#taggable-resources'
|
|
167
|
+
},
|
|
168
|
+
tags: {
|
|
169
|
+
max_resource_tags: 10,
|
|
170
|
+
taggable_resources: TAG_RESOURCE_TYPES,
|
|
171
|
+
tag_name_max_length: 25,
|
|
172
|
+
tag_name_pattern: /^[0-9A-Za-z_-]{1,25}$/
|
|
173
|
+
},
|
|
174
|
+
provisioning: {
|
|
175
|
+
default_subdomain: 'provisioning',
|
|
176
|
+
scope: 'provisioning-api',
|
|
177
|
+
applications: ['user']
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
export default config;
|
package/lib/esm/filter.js
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
import
|
|
1
|
+
import config from "./config";
|
|
2
|
+
const FILTERS = [
|
|
3
|
+
{ predicate: '*_eq', description: 'The attribute is equal to the filter value' },
|
|
4
|
+
{ predicate: '*_not_eq', description: 'The attribute is not equal to the filter value' },
|
|
5
|
+
{ predicate: '*_matches', description: 'The attribute matches the filter value with "LIKE" operator' },
|
|
6
|
+
{ predicate: '*_does_not_match', description: 'The attribute does not match the filter value with "LIKE" operator' },
|
|
7
|
+
{ predicate: '*_matches_any', description: 'The attribute matches all of the filter values (comma-separated) with "LIKE" operator' },
|
|
8
|
+
{ predicate: '*_matches_all', description: 'The attribute matches all of the filter values (comma-separated) with "LIKE" operator' },
|
|
9
|
+
{ predicate: '*_does_not_match_any', description: 'The attribute does not match any of the filter values (comma-separated) with "LIKE" operator' },
|
|
10
|
+
{ predicate: '*_does_not_match_all', description: 'The attribute matches none of the filter values (comma-separated) with "LIKE" operator' },
|
|
11
|
+
{ predicate: '*_lt', description: 'The attribute is less than the filter value' },
|
|
12
|
+
{ predicate: '*_lteq', description: 'The attribute is less than or equal to the filter value' },
|
|
13
|
+
{ predicate: '*_gt', description: 'The attribute is greater than the filter value' },
|
|
14
|
+
{ predicate: '*_gteq', description: 'The attribute is greater than or equal to the filter value' },
|
|
15
|
+
{ predicate: '*_present', description: 'The attribute is not null and not empty' },
|
|
16
|
+
{ predicate: '*_blank', description: 'The attribute is null or empty' },
|
|
17
|
+
{ predicate: '*_null', description: 'The attribute is null' },
|
|
18
|
+
{ predicate: '*_not_null', description: 'The attribute is not null' },
|
|
19
|
+
{ predicate: '*_in', description: 'The attribute matches any of the filter values (comma-separated)' },
|
|
20
|
+
{ predicate: '*_not_in', description: 'The attribute matches none of the filter values (comma-separated)' },
|
|
21
|
+
{ predicate: '*_lt_any', description: 'The attribute is less than any of the filter values (comma-separated)' },
|
|
22
|
+
{ predicate: '*_lteq_any', description: 'The attribute is less than or equal to any of the filter values (comma-separated)' },
|
|
23
|
+
{ predicate: '*_gt_any', description: 'The attribute is greater than any of the filter values (comma-separated)' },
|
|
24
|
+
{ predicate: '*_gteq_any', description: 'The attribute is greater than or qual to any of the filter values (comma-separated)' },
|
|
25
|
+
{ predicate: '*_lt_all', description: 'The attribute is less than all of the filter values (comma-separated)' },
|
|
26
|
+
{ predicate: '*_lteq_all', description: 'The attribute is less than or equal to all of the filter values (comma-separated)' },
|
|
27
|
+
{ predicate: '*_gt_all', description: 'The attribute is greater than all of the filter values (comma-separated)' },
|
|
28
|
+
{ predicate: '*_gteq_all', description: 'The attribute is greater or equal to all of the filter values (comma-separated)' },
|
|
29
|
+
{ predicate: '*_not_eq_all', description: 'The attribute is equal to none of the filter values (comma-separated)' },
|
|
30
|
+
{ predicate: '*_start', description: 'The attribute starts with the filter value (comma-separated)' },
|
|
31
|
+
{ predicate: '*_not_start', description: 'The attribute does not start with the filter value (comma-separated)' },
|
|
32
|
+
{ predicate: '*_start_any', description: 'The attribute starts with any of the filter values (comma-separated)' },
|
|
33
|
+
{ predicate: '*_start_all', description: 'The attribute starts with all of the filter values (comma-separated)' },
|
|
34
|
+
{ predicate: '*_not_start_any', description: 'The attribute does not start with any of the filter values (comma-separated)' },
|
|
35
|
+
{ predicate: '*_not_start_all', description: 'The attribute starts with none of the filter values (comma-separated)' },
|
|
36
|
+
{ predicate: '*_end', description: 'The attribute ends with the filter value' },
|
|
37
|
+
{ predicate: '*_not_end', description: 'The attribute does not end with the filter value' },
|
|
38
|
+
{ predicate: '*_end_any', description: 'The attribute ends with any of the filter values (comma-separated)' },
|
|
39
|
+
{ predicate: '*_end_all', description: 'The attribute ends with all of the filter values (comma-separated)' },
|
|
40
|
+
{ predicate: '*_not_end_any', description: 'The attribute does not end with any of the filter values (comma-separated)' },
|
|
41
|
+
{ predicate: '*_not_end_all', description: 'The attribute ends with none of the filter values (comma-separated)' },
|
|
42
|
+
{ predicate: '*_cont', description: 'The attribute contains the filter value' },
|
|
43
|
+
{ predicate: '*_not_cont', description: 'The attribute does not contains the filter value' },
|
|
44
|
+
{ predicate: '*_cont_any', description: 'The attribute contains any of the filter values (comma-separated)' },
|
|
45
|
+
{ predicate: '*_cont_all', description: 'The attribute contains all of the filter values (comma-separated)' },
|
|
46
|
+
{ predicate: '*_not_cont_all', description: 'The attribute contains none of the filter values (comma-separated)' },
|
|
47
|
+
{ predicate: '*_jcont', description: 'The attribute contains a portion of the JSON used as filter value (works with object only)' },
|
|
48
|
+
{ predicate: '*_true', description: 'The attribute is true' },
|
|
49
|
+
{ predicate: '*_false', description: 'The attribute is false' },
|
|
50
|
+
];
|
|
51
|
+
const documentation = config.doc.core_filtering_data;
|
|
52
|
+
const filterList = () => {
|
|
53
|
+
return filters().map(f => f.predicate.replace(/^\*/g, ''));
|
|
54
|
+
};
|
|
55
|
+
const filterAvailable = (filter) => {
|
|
56
|
+
const filter_ = filter.startsWith('_') ? filter : `_${filter}`;
|
|
57
|
+
return filterList().some(f => filter_.endsWith(f));
|
|
58
|
+
};
|
|
59
|
+
const applyFilter = (predicate, ...fields) => {
|
|
60
|
+
if (!filterAvailable(predicate))
|
|
61
|
+
throw new Error('Unknown filter: ' + predicate);
|
|
62
|
+
let out = '';
|
|
63
|
+
for (const f of fields)
|
|
64
|
+
out += (out.length === 0 ? '' : '_or_') + f;
|
|
65
|
+
out += predicate.startsWith('_') ? predicate : `_${predicate}`;
|
|
66
|
+
return out;
|
|
67
|
+
};
|
|
68
|
+
const filters = () => {
|
|
69
|
+
return [...FILTERS];
|
|
70
|
+
};
|
|
71
|
+
export { documentation, filterAvailable as available, filterList as list, applyFilter as apply, filters };
|
package/lib/esm/help.js
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
1
|
-
import{CommandHelp
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CommandHelp, Help } from '@oclif/core';
|
|
2
|
+
import { capitalize } from './text';
|
|
3
|
+
const PRINT_TRACE = false;
|
|
4
|
+
/*
|
|
5
|
+
const indent = (str: string, count = 1): string => {
|
|
6
|
+
return str.replace(/^(?!\s*$)/gm, ' '.repeat(count))
|
|
7
|
+
}
|
|
8
|
+
*/
|
|
9
|
+
// Command formatter class
|
|
10
|
+
class CLICommandHelp extends CommandHelp {
|
|
11
|
+
examples(examples) {
|
|
12
|
+
if (PRINT_TRACE)
|
|
13
|
+
console.log('---------- command.examples');
|
|
14
|
+
return super.examples(examples);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// Global help formatter
|
|
18
|
+
export default class CLIBaseHelp extends Help {
|
|
19
|
+
async showHelp(args) {
|
|
20
|
+
if (PRINT_TRACE)
|
|
21
|
+
console.log('---------- showHelp');
|
|
22
|
+
return super.showHelp(args);
|
|
23
|
+
}
|
|
24
|
+
// display the root help of a CLI
|
|
25
|
+
async showRootHelp() {
|
|
26
|
+
if (PRINT_TRACE)
|
|
27
|
+
console.log('---------- showRootHelp');
|
|
28
|
+
return super.showRootHelp();
|
|
29
|
+
}
|
|
30
|
+
// display help for a topic
|
|
31
|
+
async showTopicHelp(topic) {
|
|
32
|
+
if (PRINT_TRACE)
|
|
33
|
+
console.log('---------- showTopicHelp');
|
|
34
|
+
return super.showTopicHelp(topic);
|
|
35
|
+
}
|
|
36
|
+
// display help for a command
|
|
37
|
+
async showCommandHelp(command) {
|
|
38
|
+
if (PRINT_TRACE)
|
|
39
|
+
console.log('---------- showCommandHelp');
|
|
40
|
+
const name = command.id;
|
|
41
|
+
const depth = name ? name.split(':').length : 1;
|
|
42
|
+
const subTopics = this.sortedTopics.filter((t) => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
43
|
+
const subCommands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
44
|
+
const title = command.description && this.render(command.description).split('\n')[0];
|
|
45
|
+
if (title)
|
|
46
|
+
console.log(`${capitalize(title)}\n`);
|
|
47
|
+
console.log(this.formatCommand(command));
|
|
48
|
+
console.log('');
|
|
49
|
+
if (subTopics.length > 0) {
|
|
50
|
+
console.log(this.formatTopics(subTopics));
|
|
51
|
+
console.log('');
|
|
52
|
+
}
|
|
53
|
+
if (subCommands.length > 0) {
|
|
54
|
+
console.log(this.formatCommands(subCommands));
|
|
55
|
+
console.log('');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// displayed for the root help
|
|
59
|
+
formatRoot() {
|
|
60
|
+
if (PRINT_TRACE)
|
|
61
|
+
console.log('---------- formatRoot');
|
|
62
|
+
return super.formatRoot();
|
|
63
|
+
}
|
|
64
|
+
// the formatting for an individual topic
|
|
65
|
+
formatTopic(topic) {
|
|
66
|
+
if (PRINT_TRACE)
|
|
67
|
+
console.log('---------- formatTopic');
|
|
68
|
+
return super.formatTopic(topic);
|
|
69
|
+
}
|
|
70
|
+
// the formatting for a list of topics
|
|
71
|
+
formatTopics(topics) {
|
|
72
|
+
if (PRINT_TRACE)
|
|
73
|
+
console.log('---------- formatTopics');
|
|
74
|
+
const fixTopics = topics.filter(t => !t.hidden).map(t => {
|
|
75
|
+
t.description = capitalize(t.description);
|
|
76
|
+
return t;
|
|
77
|
+
});
|
|
78
|
+
return super.formatTopics(fixTopics);
|
|
79
|
+
}
|
|
80
|
+
// the formatting for a list of commands
|
|
81
|
+
formatCommands(commands) {
|
|
82
|
+
if (PRINT_TRACE)
|
|
83
|
+
console.log('---------- formatCommands');
|
|
84
|
+
return super.formatCommands(commands).split('\n').map((c) => {
|
|
85
|
+
let noSpaceCount = 0;
|
|
86
|
+
return c.split(' ').map((t) => (((t || '').trim() !== '') && (++noSpaceCount === 2)) ? capitalize(t) : t).join(' ');
|
|
87
|
+
}).join('\n');
|
|
88
|
+
}
|
|
89
|
+
// the formatting for an individual command
|
|
90
|
+
formatCommand(command) {
|
|
91
|
+
if (PRINT_TRACE)
|
|
92
|
+
console.log('---------- formatCommand');
|
|
93
|
+
return super.formatCommand(command);
|
|
94
|
+
}
|
|
95
|
+
getCommandHelpClass(command) {
|
|
96
|
+
if (PRINT_TRACE)
|
|
97
|
+
console.log('---------- getCommandHelpClass');
|
|
98
|
+
return new CLICommandHelp(command, this.config, this.opts);
|
|
99
|
+
}
|
|
100
|
+
}
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as clApi_1 from './api';
|
|
2
|
+
export { clApi_1 as clApi };
|
|
3
|
+
import * as clApplication_1 from './application';
|
|
4
|
+
export { clApplication_1 as clApplication };
|
|
5
|
+
export { default as clConfig } from './config';
|
|
6
|
+
import * as clCommand_1 from './command';
|
|
7
|
+
export { clCommand_1 as clCommand };
|
|
8
|
+
import * as clOutput_1 from './output';
|
|
9
|
+
export { clOutput_1 as clOutput };
|
|
10
|
+
import * as clColor_1 from './color';
|
|
11
|
+
export { clColor_1 as clColor };
|
|
12
|
+
import * as clToken_1 from './token';
|
|
13
|
+
export { clToken_1 as clToken };
|
|
14
|
+
import * as clUpdate_1 from './update';
|
|
15
|
+
export { clUpdate_1 as clUpdate };
|
|
16
|
+
import * as clUtil_1 from './util';
|
|
17
|
+
export { clUtil_1 as clUtil };
|
|
18
|
+
export { default as clHelp } from './help';
|
|
19
|
+
import * as clSchema_1 from './schema';
|
|
20
|
+
export { clSchema_1 as clSchema };
|
|
21
|
+
import * as clText_1 from './text';
|
|
22
|
+
export { clText_1 as clText };
|
|
23
|
+
import * as clSymbol_1 from './symbol';
|
|
24
|
+
export { clSymbol_1 as clSymbol };
|
|
25
|
+
import * as clFilter_1 from './filter';
|
|
26
|
+
export { clFilter_1 as clFilter };
|