@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/cjs/filter.js
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
exports.filters = exports.apply = exports.list = exports.available = exports.documentation = void 0;
|
|
7
|
+
const config_1 = __importDefault(require("./config"));
|
|
8
|
+
const FILTERS = [
|
|
9
|
+
{ predicate: '*_eq', description: 'The attribute is equal to the filter value' },
|
|
10
|
+
{ predicate: '*_not_eq', description: 'The attribute is not equal to the filter value' },
|
|
11
|
+
{ predicate: '*_matches', description: 'The attribute matches the filter value with "LIKE" operator' },
|
|
12
|
+
{ predicate: '*_does_not_match', description: 'The attribute does not match the filter value with "LIKE" operator' },
|
|
13
|
+
{ predicate: '*_matches_any', description: 'The attribute matches all of the filter values (comma-separated) with "LIKE" operator' },
|
|
14
|
+
{ predicate: '*_matches_all', description: 'The attribute matches all of the filter values (comma-separated) with "LIKE" operator' },
|
|
15
|
+
{ predicate: '*_does_not_match_any', description: 'The attribute does not match any of the filter values (comma-separated) with "LIKE" operator' },
|
|
16
|
+
{ predicate: '*_does_not_match_all', description: 'The attribute matches none of the filter values (comma-separated) with "LIKE" operator' },
|
|
17
|
+
{ predicate: '*_lt', description: 'The attribute is less than the filter value' },
|
|
18
|
+
{ predicate: '*_lteq', description: 'The attribute is less than or equal to the filter value' },
|
|
19
|
+
{ predicate: '*_gt', description: 'The attribute is greater than the filter value' },
|
|
20
|
+
{ predicate: '*_gteq', description: 'The attribute is greater than or equal to the filter value' },
|
|
21
|
+
{ predicate: '*_present', description: 'The attribute is not null and not empty' },
|
|
22
|
+
{ predicate: '*_blank', description: 'The attribute is null or empty' },
|
|
23
|
+
{ predicate: '*_null', description: 'The attribute is null' },
|
|
24
|
+
{ predicate: '*_not_null', description: 'The attribute is not null' },
|
|
25
|
+
{ predicate: '*_in', description: 'The attribute matches any of the filter values (comma-separated)' },
|
|
26
|
+
{ predicate: '*_not_in', description: 'The attribute matches none of the filter values (comma-separated)' },
|
|
27
|
+
{ predicate: '*_lt_any', description: 'The attribute is less than any of the filter values (comma-separated)' },
|
|
28
|
+
{ predicate: '*_lteq_any', description: 'The attribute is less than or equal to any of the filter values (comma-separated)' },
|
|
29
|
+
{ predicate: '*_gt_any', description: 'The attribute is greater than any of the filter values (comma-separated)' },
|
|
30
|
+
{ predicate: '*_gteq_any', description: 'The attribute is greater than or qual to any of the filter values (comma-separated)' },
|
|
31
|
+
{ predicate: '*_lt_all', description: 'The attribute is less than all of the filter values (comma-separated)' },
|
|
32
|
+
{ predicate: '*_lteq_all', description: 'The attribute is less than or equal to all of the filter values (comma-separated)' },
|
|
33
|
+
{ predicate: '*_gt_all', description: 'The attribute is greater than all of the filter values (comma-separated)' },
|
|
34
|
+
{ predicate: '*_gteq_all', description: 'The attribute is greater or equal to all of the filter values (comma-separated)' },
|
|
35
|
+
{ predicate: '*_not_eq_all', description: 'The attribute is equal to none of the filter values (comma-separated)' },
|
|
36
|
+
{ predicate: '*_start', description: 'The attribute starts with the filter value (comma-separated)' },
|
|
37
|
+
{ predicate: '*_not_start', description: 'The attribute does not start with the filter value (comma-separated)' },
|
|
38
|
+
{ predicate: '*_start_any', description: 'The attribute starts with any of the filter values (comma-separated)' },
|
|
39
|
+
{ predicate: '*_start_all', description: 'The attribute starts with all of the filter values (comma-separated)' },
|
|
40
|
+
{ predicate: '*_not_start_any', description: 'The attribute does not start with any of the filter values (comma-separated)' },
|
|
41
|
+
{ predicate: '*_not_start_all', description: 'The attribute starts with none of the filter values (comma-separated)' },
|
|
42
|
+
{ predicate: '*_end', description: 'The attribute ends with the filter value' },
|
|
43
|
+
{ predicate: '*_not_end', description: 'The attribute does not end with the filter value' },
|
|
44
|
+
{ predicate: '*_end_any', description: 'The attribute ends with any of the filter values (comma-separated)' },
|
|
45
|
+
{ predicate: '*_end_all', description: 'The attribute ends with all of the filter values (comma-separated)' },
|
|
46
|
+
{ predicate: '*_not_end_any', description: 'The attribute does not end with any of the filter values (comma-separated)' },
|
|
47
|
+
{ predicate: '*_not_end_all', description: 'The attribute ends with none of the filter values (comma-separated)' },
|
|
48
|
+
{ predicate: '*_cont', description: 'The attribute contains the filter value' },
|
|
49
|
+
{ predicate: '*_not_cont', description: 'The attribute does not contains the filter value' },
|
|
50
|
+
{ predicate: '*_cont_any', description: 'The attribute contains any of the filter values (comma-separated)' },
|
|
51
|
+
{ predicate: '*_cont_all', description: 'The attribute contains all of the filter values (comma-separated)' },
|
|
52
|
+
{ predicate: '*_not_cont_all', description: 'The attribute contains none of the filter values (comma-separated)' },
|
|
53
|
+
{ predicate: '*_jcont', description: 'The attribute contains a portion of the JSON used as filter value (works with object only)' },
|
|
54
|
+
{ predicate: '*_true', description: 'The attribute is true' },
|
|
55
|
+
{ predicate: '*_false', description: 'The attribute is false' },
|
|
56
|
+
];
|
|
57
|
+
const documentation = config_1.default.doc.core_filtering_data;
|
|
58
|
+
exports.documentation = documentation;
|
|
59
|
+
const filterList = () => {
|
|
60
|
+
return filters().map(f => f.predicate.replace(/^\*/g, ''));
|
|
61
|
+
};
|
|
62
|
+
exports.list = filterList;
|
|
63
|
+
const filterAvailable = (filter) => {
|
|
64
|
+
const filter_ = filter.startsWith('_') ? filter : `_${filter}`;
|
|
65
|
+
return filterList().some(f => filter_.endsWith(f));
|
|
66
|
+
};
|
|
67
|
+
exports.available = filterAvailable;
|
|
68
|
+
const applyFilter = (predicate, ...fields) => {
|
|
69
|
+
if (!filterAvailable(predicate))
|
|
70
|
+
throw new Error('Unknown filter: ' + predicate);
|
|
71
|
+
let out = '';
|
|
72
|
+
for (const f of fields)
|
|
73
|
+
out += (out.length === 0 ? '' : '_or_') + f;
|
|
74
|
+
out += predicate.startsWith('_') ? predicate : `_${predicate}`;
|
|
75
|
+
return out;
|
|
76
|
+
};
|
|
77
|
+
exports.apply = applyFilter;
|
|
78
|
+
const filters = () => {
|
|
79
|
+
return [...FILTERS];
|
|
80
|
+
};
|
|
81
|
+
exports.filters = filters;
|
package/lib/cjs/help.js
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const text_1 = require("./text");
|
|
5
|
+
const PRINT_TRACE = false;
|
|
6
|
+
/*
|
|
7
|
+
const indent = (str: string, count = 1): string => {
|
|
8
|
+
return str.replace(/^(?!\s*$)/gm, ' '.repeat(count))
|
|
9
|
+
}
|
|
10
|
+
*/
|
|
11
|
+
// Command formatter class
|
|
12
|
+
class CLICommandHelp extends core_1.CommandHelp {
|
|
13
|
+
examples(examples) {
|
|
14
|
+
if (PRINT_TRACE)
|
|
15
|
+
console.log('---------- command.examples');
|
|
16
|
+
return super.examples(examples);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Global help formatter
|
|
20
|
+
class CLIBaseHelp extends core_1.Help {
|
|
21
|
+
async showHelp(args) {
|
|
22
|
+
if (PRINT_TRACE)
|
|
23
|
+
console.log('---------- showHelp');
|
|
24
|
+
return super.showHelp(args);
|
|
25
|
+
}
|
|
26
|
+
// display the root help of a CLI
|
|
27
|
+
async showRootHelp() {
|
|
28
|
+
if (PRINT_TRACE)
|
|
29
|
+
console.log('---------- showRootHelp');
|
|
30
|
+
return super.showRootHelp();
|
|
31
|
+
}
|
|
32
|
+
// display help for a topic
|
|
33
|
+
async showTopicHelp(topic) {
|
|
34
|
+
if (PRINT_TRACE)
|
|
35
|
+
console.log('---------- showTopicHelp');
|
|
36
|
+
return super.showTopicHelp(topic);
|
|
37
|
+
}
|
|
38
|
+
// display help for a command
|
|
39
|
+
async showCommandHelp(command) {
|
|
40
|
+
if (PRINT_TRACE)
|
|
41
|
+
console.log('---------- showCommandHelp');
|
|
42
|
+
const name = command.id;
|
|
43
|
+
const depth = name ? name.split(':').length : 1;
|
|
44
|
+
const subTopics = this.sortedTopics.filter((t) => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
45
|
+
const subCommands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
46
|
+
const title = command.description && this.render(command.description).split('\n')[0];
|
|
47
|
+
if (title)
|
|
48
|
+
console.log(`${(0, text_1.capitalize)(title)}\n`);
|
|
49
|
+
console.log(this.formatCommand(command));
|
|
50
|
+
console.log('');
|
|
51
|
+
if (subTopics.length > 0) {
|
|
52
|
+
console.log(this.formatTopics(subTopics));
|
|
53
|
+
console.log('');
|
|
54
|
+
}
|
|
55
|
+
if (subCommands.length > 0) {
|
|
56
|
+
console.log(this.formatCommands(subCommands));
|
|
57
|
+
console.log('');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// displayed for the root help
|
|
61
|
+
formatRoot() {
|
|
62
|
+
if (PRINT_TRACE)
|
|
63
|
+
console.log('---------- formatRoot');
|
|
64
|
+
return super.formatRoot();
|
|
65
|
+
}
|
|
66
|
+
// the formatting for an individual topic
|
|
67
|
+
formatTopic(topic) {
|
|
68
|
+
if (PRINT_TRACE)
|
|
69
|
+
console.log('---------- formatTopic');
|
|
70
|
+
return super.formatTopic(topic);
|
|
71
|
+
}
|
|
72
|
+
// the formatting for a list of topics
|
|
73
|
+
formatTopics(topics) {
|
|
74
|
+
if (PRINT_TRACE)
|
|
75
|
+
console.log('---------- formatTopics');
|
|
76
|
+
const fixTopics = topics.filter(t => !t.hidden).map(t => {
|
|
77
|
+
t.description = (0, text_1.capitalize)(t.description);
|
|
78
|
+
return t;
|
|
79
|
+
});
|
|
80
|
+
return super.formatTopics(fixTopics);
|
|
81
|
+
}
|
|
82
|
+
// the formatting for a list of commands
|
|
83
|
+
formatCommands(commands) {
|
|
84
|
+
if (PRINT_TRACE)
|
|
85
|
+
console.log('---------- formatCommands');
|
|
86
|
+
return super.formatCommands(commands).split('\n').map((c) => {
|
|
87
|
+
let noSpaceCount = 0;
|
|
88
|
+
return c.split(' ').map((t) => (((t || '').trim() !== '') && (++noSpaceCount === 2)) ? (0, text_1.capitalize)(t) : t).join(' ');
|
|
89
|
+
}).join('\n');
|
|
90
|
+
}
|
|
91
|
+
// the formatting for an individual command
|
|
92
|
+
formatCommand(command) {
|
|
93
|
+
if (PRINT_TRACE)
|
|
94
|
+
console.log('---------- formatCommand');
|
|
95
|
+
return super.formatCommand(command);
|
|
96
|
+
}
|
|
97
|
+
getCommandHelpClass(command) {
|
|
98
|
+
if (PRINT_TRACE)
|
|
99
|
+
console.log('---------- getCommandHelpClass');
|
|
100
|
+
return new CLICommandHelp(command, this.config, this.opts);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.default = CLIBaseHelp;
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.clFilter = exports.clSymbol = exports.clText = exports.clSchema = exports.clHelp = exports.clUtil = exports.clUpdate = exports.clToken = exports.clColor = exports.clOutput = exports.clCommand = exports.clConfig = exports.clApplication = exports.clApi = void 0;
|
|
30
|
+
exports.clApi = __importStar(require("./api"));
|
|
31
|
+
exports.clApplication = __importStar(require("./application"));
|
|
32
|
+
var config_1 = require("./config");
|
|
33
|
+
Object.defineProperty(exports, "clConfig", { enumerable: true, get: function () { return __importDefault(config_1).default; } });
|
|
34
|
+
exports.clCommand = __importStar(require("./command"));
|
|
35
|
+
exports.clOutput = __importStar(require("./output"));
|
|
36
|
+
// export * as style from './style'
|
|
37
|
+
exports.clColor = __importStar(require("./color"));
|
|
38
|
+
exports.clToken = __importStar(require("./token"));
|
|
39
|
+
exports.clUpdate = __importStar(require("./update"));
|
|
40
|
+
exports.clUtil = __importStar(require("./util"));
|
|
41
|
+
var help_1 = require("./help");
|
|
42
|
+
Object.defineProperty(exports, "clHelp", { enumerable: true, get: function () { return __importDefault(help_1).default; } });
|
|
43
|
+
exports.clSchema = __importStar(require("./schema"));
|
|
44
|
+
exports.clText = __importStar(require("./text"));
|
|
45
|
+
exports.clSymbol = __importStar(require("./symbol"));
|
|
46
|
+
exports.clFilter = __importStar(require("./filter"));
|
package/lib/cjs/inflector.js
CHANGED
|
@@ -1 +1,255 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _Inflector = {
|
|
4
|
+
uncountableWords: [
|
|
5
|
+
'equipment', 'information', 'rice', 'money', 'species', 'series',
|
|
6
|
+
'fish', 'sheep', 'moose', 'deer', 'news'
|
|
7
|
+
],
|
|
8
|
+
pluralRules: [
|
|
9
|
+
[/(m)an$/gi, '$1en'],
|
|
10
|
+
[/(pe)rson$/gi, '$1ople'],
|
|
11
|
+
[/(child)$/gi, '$1ren'],
|
|
12
|
+
[/^(ox)$/gi, '$1en'],
|
|
13
|
+
[/(ax|test)is$/gi, '$1es'],
|
|
14
|
+
[/(octop|vir)us$/gi, '$1i'],
|
|
15
|
+
[/(alias|status)$/gi, '$1es'],
|
|
16
|
+
[/(bu)s$/gi, '$1ses'],
|
|
17
|
+
[/(buffal|tomat|potat)o$/gi, '$1oes'],
|
|
18
|
+
[/([ti])um$/gi, '$1a'],
|
|
19
|
+
[/sis$/gi, 'ses'],
|
|
20
|
+
[/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],
|
|
21
|
+
[/(hive)$/gi, '$1s'],
|
|
22
|
+
[/([^aeiouy]|qu)y$/gi, '$1ies'],
|
|
23
|
+
[/(x|ch|ss|sh)$/gi, '$1es'],
|
|
24
|
+
[/(matr|vert|ind)ix|ex$/gi, '$1ices'],
|
|
25
|
+
[/([m|l])ouse$/gi, '$1ice'],
|
|
26
|
+
[/(quiz)$/gi, '$1zes'],
|
|
27
|
+
[/s$/gi, 's'],
|
|
28
|
+
[/$/gi, 's']
|
|
29
|
+
],
|
|
30
|
+
singularRules: [
|
|
31
|
+
[/(m)en$/gi, '$1an'],
|
|
32
|
+
[/(pe)ople$/gi, '$1rson'],
|
|
33
|
+
[/(child)ren$/gi, '$1'],
|
|
34
|
+
[/([ti])a$/gi, '$1um'],
|
|
35
|
+
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/gi, '$1$2sis'],
|
|
36
|
+
[/(hive)s$/gi, '$1'],
|
|
37
|
+
[/(tive)s$/gi, '$1'],
|
|
38
|
+
[/(curve)s$/gi, '$1'],
|
|
39
|
+
[/([lr])ves$/gi, '$1f'],
|
|
40
|
+
[/([^fo])ves$/gi, '$1fe'],
|
|
41
|
+
[/([^aeiouy]|qu)ies$/gi, '$1y'],
|
|
42
|
+
[/(s)eries$/gi, '$1eries'],
|
|
43
|
+
[/(m)ovies$/gi, '$1ovie'],
|
|
44
|
+
[/(x|ch|ss|sh)es$/gi, '$1'],
|
|
45
|
+
[/([m|l])ice$/gi, '$1ouse'],
|
|
46
|
+
[/(bus)es$/gi, '$1'],
|
|
47
|
+
[/(o)es$/gi, '$1'],
|
|
48
|
+
[/(shoe)s$/gi, '$1'],
|
|
49
|
+
[/(cris|ax|test)es$/gi, '$1is'],
|
|
50
|
+
[/(octop|vir)i$/gi, '$1us'],
|
|
51
|
+
[/(alias|status)es$/gi, '$1'],
|
|
52
|
+
[/^(ox)en/gi, '$1'],
|
|
53
|
+
[/(vert|ind)ices$/gi, '$1ex'],
|
|
54
|
+
[/(matr)ices$/gi, '$1ix'],
|
|
55
|
+
[/(quiz)zes$/gi, '$1'],
|
|
56
|
+
[/s$/gi, '']
|
|
57
|
+
],
|
|
58
|
+
nonTitlecasedWords: [
|
|
59
|
+
'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
|
|
60
|
+
'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
|
|
61
|
+
'with', 'for'
|
|
62
|
+
],
|
|
63
|
+
idSuffix: /(_ids|_id)$/g,
|
|
64
|
+
underbar: /_/g,
|
|
65
|
+
spaceOrUnderbar: /[ _]/g,
|
|
66
|
+
uppercase: /([A-Z])/g,
|
|
67
|
+
underbarPrefix: /^_/,
|
|
68
|
+
applyRules: function (str, rules, skip, override) {
|
|
69
|
+
if (override) {
|
|
70
|
+
str = override;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const ignore = (skip.includes(str.toLowerCase()));
|
|
74
|
+
if (!ignore) {
|
|
75
|
+
for (let x = 0; x < rules.length; x++) {
|
|
76
|
+
if (str.match(rules[x][0])) {
|
|
77
|
+
str = str.replace(rules[x][0], rules[x][1]);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return str;
|
|
84
|
+
},
|
|
85
|
+
/*
|
|
86
|
+
Inflector.pluralize('person') -> 'people'
|
|
87
|
+
Inflector.pluralize('octopus') -> 'octopi'
|
|
88
|
+
Inflector.pluralize('Hat') -> 'Hats'
|
|
89
|
+
Inflector.pluralize('person', 'guys') -> 'guys'
|
|
90
|
+
*/
|
|
91
|
+
pluralize: function (str, plural) {
|
|
92
|
+
return _Inflector.applyRules(str, _Inflector.pluralRules, _Inflector.uncountableWords, plural);
|
|
93
|
+
},
|
|
94
|
+
/*
|
|
95
|
+
Inflector.singularize('person') -> 'person'
|
|
96
|
+
Inflector.singularize('octopi') -> 'octopus'
|
|
97
|
+
Inflector.singularize('hats') -> 'hat'
|
|
98
|
+
Inflector.singularize('guys', 'person') -> 'person'
|
|
99
|
+
*/
|
|
100
|
+
singularize: function (str, singular) {
|
|
101
|
+
return _Inflector.applyRules(str, _Inflector.singularRules, _Inflector.uncountableWords, singular);
|
|
102
|
+
},
|
|
103
|
+
/*
|
|
104
|
+
Inflector.camelize('message_properties') -> 'MessageProperties'
|
|
105
|
+
Inflector.camelize('message_properties', true) -> 'messageProperties'
|
|
106
|
+
*/
|
|
107
|
+
camelize: function (str, lowFirstLetter) {
|
|
108
|
+
// str = str.toLowerCase()
|
|
109
|
+
const strPath = str.split('/');
|
|
110
|
+
for (let i = 0; i < strPath.length; i++) {
|
|
111
|
+
const strArr = strPath[i].split('_');
|
|
112
|
+
const initX = ((lowFirstLetter && i + 1 === strPath.length) ? (1) : (0));
|
|
113
|
+
for (let x = initX; x < strArr.length; x++) {
|
|
114
|
+
strArr[x] = strArr[x].charAt(0).toUpperCase() + strArr[x].substring(1);
|
|
115
|
+
}
|
|
116
|
+
strPath[i] = strArr.join('');
|
|
117
|
+
}
|
|
118
|
+
str = strPath.join('::');
|
|
119
|
+
// fix
|
|
120
|
+
if (lowFirstLetter) {
|
|
121
|
+
const first = str.charAt(0).toLowerCase();
|
|
122
|
+
const last = str.slice(1);
|
|
123
|
+
str = first + last;
|
|
124
|
+
}
|
|
125
|
+
return str;
|
|
126
|
+
},
|
|
127
|
+
/*
|
|
128
|
+
Inflector.underscore('MessageProperties') -> 'message_properties'
|
|
129
|
+
Inflector.underscore('messageProperties') -> 'message_properties'
|
|
130
|
+
*/
|
|
131
|
+
underscore: function (str) {
|
|
132
|
+
const strPath = str.split('::');
|
|
133
|
+
for (let i = 0; i < strPath.length; i++) {
|
|
134
|
+
strPath[i] = strPath[i].replace(_Inflector.uppercase, '_$1');
|
|
135
|
+
strPath[i] = strPath[i].replace(_Inflector.underbarPrefix, '');
|
|
136
|
+
}
|
|
137
|
+
str = strPath.join('/').toLowerCase();
|
|
138
|
+
return str;
|
|
139
|
+
},
|
|
140
|
+
/*
|
|
141
|
+
Inflector.humanize('message_properties') -> 'Message properties'
|
|
142
|
+
Inflector.humanize('message_properties') -> 'message properties'
|
|
143
|
+
*/
|
|
144
|
+
humanize: function (str, lowFirstLetter) {
|
|
145
|
+
str = str.toLowerCase();
|
|
146
|
+
str = str.replace(_Inflector.idSuffix, '');
|
|
147
|
+
str = str.replace(_Inflector.underbar, ' ');
|
|
148
|
+
if (!lowFirstLetter) {
|
|
149
|
+
str = _Inflector.capitalize(str);
|
|
150
|
+
}
|
|
151
|
+
return str;
|
|
152
|
+
},
|
|
153
|
+
/*
|
|
154
|
+
Inflector.capitalize('message_properties') -> 'Message_properties'
|
|
155
|
+
Inflector.capitalize('message properties') -> 'Message properties'
|
|
156
|
+
*/
|
|
157
|
+
capitalize: function (str) {
|
|
158
|
+
str = str.toLowerCase();
|
|
159
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
160
|
+
return str;
|
|
161
|
+
},
|
|
162
|
+
/*
|
|
163
|
+
Inflector.dasherize('message_properties') -> 'message-properties'
|
|
164
|
+
Inflector.dasherize('message properties') -> 'message-properties'
|
|
165
|
+
*/
|
|
166
|
+
dasherize: function (str) {
|
|
167
|
+
str = str.replace(_Inflector.spaceOrUnderbar, '-');
|
|
168
|
+
return str;
|
|
169
|
+
},
|
|
170
|
+
/*
|
|
171
|
+
Inflector.camel2words('message_properties') -> 'Message Properties'
|
|
172
|
+
Inflector.camel2words('message properties') -> 'Message Properties'
|
|
173
|
+
Inflactor.camel2words('Message_propertyId', true) -> 'Message Properties Id'
|
|
174
|
+
*/
|
|
175
|
+
camel2words: function (str, allFirstUpper) {
|
|
176
|
+
// str = str.toLowerCase()
|
|
177
|
+
if (allFirstUpper) {
|
|
178
|
+
str = _Inflector.camelize(str);
|
|
179
|
+
str = _Inflector.underscore(str);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
str = str.toLowerCase();
|
|
183
|
+
}
|
|
184
|
+
str = str.replace(_Inflector.underbar, ' ');
|
|
185
|
+
const strArr = str.split(' ');
|
|
186
|
+
for (let x = 0; x < strArr.length; x++) {
|
|
187
|
+
const d = strArr[x].split('-');
|
|
188
|
+
for (let i = 0; i < d.length; i++) {
|
|
189
|
+
if (!_Inflector.nonTitlecasedWords.includes(d[i].toLowerCase())) {
|
|
190
|
+
d[i] = _Inflector.capitalize(d[i]);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
strArr[x] = d.join('-');
|
|
194
|
+
}
|
|
195
|
+
str = strArr.join(' ');
|
|
196
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
197
|
+
return str;
|
|
198
|
+
},
|
|
199
|
+
/*
|
|
200
|
+
Inflector.demodulize('Message::Bus::Properties') -> 'Properties'
|
|
201
|
+
*/
|
|
202
|
+
demodulize: function (str) {
|
|
203
|
+
const strArr = str.split('::');
|
|
204
|
+
str = strArr[strArr.length - 1];
|
|
205
|
+
return str;
|
|
206
|
+
},
|
|
207
|
+
/*
|
|
208
|
+
Inflector.tableize('MessageBusProperty') -> 'message_bus_properties'
|
|
209
|
+
*/
|
|
210
|
+
tableize: function (str) {
|
|
211
|
+
str = _Inflector.pluralize(_Inflector.underscore(str));
|
|
212
|
+
return str;
|
|
213
|
+
},
|
|
214
|
+
/*
|
|
215
|
+
Inflector.classify('message_bus_properties') -> 'MessageBusProperty'
|
|
216
|
+
*/
|
|
217
|
+
classify: function (str) {
|
|
218
|
+
str = _Inflector.singularize(_Inflector.camelize(str));
|
|
219
|
+
return str;
|
|
220
|
+
},
|
|
221
|
+
/*
|
|
222
|
+
Inflector.foreignKey('MessageBusProperty') -> 'message_bus_property_id'
|
|
223
|
+
Inflector.foreignKey('MessageBusProperty', true) -> 'message_bus_propertyid'
|
|
224
|
+
*/
|
|
225
|
+
foreignKey: function (str, dropIdUbar) {
|
|
226
|
+
str = _Inflector.underscore(_Inflector.demodulize(str)) + (dropIdUbar ? ('') : ('_')) + 'id';
|
|
227
|
+
return str;
|
|
228
|
+
},
|
|
229
|
+
/*
|
|
230
|
+
Inflector.ordinalize('the 1 pitch') -> 'the 1st pitch'
|
|
231
|
+
*/
|
|
232
|
+
ordinalize: function (str) {
|
|
233
|
+
const strArr = str.split(' ');
|
|
234
|
+
for (let x = 0; x < strArr.length; x++) {
|
|
235
|
+
const i = parseInt(strArr[x]);
|
|
236
|
+
if (Number.isNaN(i)) {
|
|
237
|
+
const ltd = strArr[x].substring(strArr[x].length - 2);
|
|
238
|
+
const ld = strArr[x].substring(strArr[x].length - 1);
|
|
239
|
+
let suf = "th";
|
|
240
|
+
if ((ltd !== "11") && (ltd !== "12") && (ltd !== "13")) {
|
|
241
|
+
if (ld === "1")
|
|
242
|
+
suf = "st";
|
|
243
|
+
else if (ld === "2")
|
|
244
|
+
suf = "nd";
|
|
245
|
+
else if (ld === "3")
|
|
246
|
+
suf = "rd";
|
|
247
|
+
}
|
|
248
|
+
strArr[x] += suf;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
str = strArr.join(' ');
|
|
252
|
+
return str;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
exports.default = _Inflector;
|
package/lib/cjs/jsonapi.js
CHANGED
|
@@ -1 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.denormalize = void 0;
|
|
5
|
+
const findIncluded = (rel, included) => {
|
|
6
|
+
return included.find(inc => {
|
|
7
|
+
return (rel.id === inc.id) && (rel.type === inc.type);
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const denormalizeResource = (res, included) => {
|
|
11
|
+
const resource = Object.assign({ id: res.id, type: res.type }, res.attributes);
|
|
12
|
+
if (res.relationships)
|
|
13
|
+
Object.keys(res.relationships).forEach(key => {
|
|
14
|
+
const rel = res.relationships[key].data;
|
|
15
|
+
if (rel) {
|
|
16
|
+
if (Array.isArray(rel))
|
|
17
|
+
resource[key] = rel.map(r => denormalizeResource(findIncluded(r, included), included));
|
|
18
|
+
else
|
|
19
|
+
resource[key] = denormalizeResource(findIncluded(rel, included), included);
|
|
20
|
+
}
|
|
21
|
+
else if (rel === null)
|
|
22
|
+
resource[key] = null;
|
|
23
|
+
});
|
|
24
|
+
return resource;
|
|
25
|
+
};
|
|
26
|
+
const denormalize = (response) => {
|
|
27
|
+
let denormalizedResponse;
|
|
28
|
+
if (response.links)
|
|
29
|
+
delete response.links;
|
|
30
|
+
const data = response.data;
|
|
31
|
+
const included = response.included;
|
|
32
|
+
if (Array.isArray(data))
|
|
33
|
+
denormalizedResponse = data.map(res => denormalizeResource(res, included));
|
|
34
|
+
else
|
|
35
|
+
denormalizedResponse = denormalizeResource(data, included);
|
|
36
|
+
return denormalizedResponse;
|
|
37
|
+
};
|
|
38
|
+
exports.denormalize = denormalize;
|
package/lib/cjs/output.js
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatError = exports.formatOutput = exports.localeDate = exports.cleanDate = exports.maxLength = exports.center = exports.printCSV = exports.printJSON = exports.printObject = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
/** Print a formatted object */
|
|
7
|
+
const printObject = (obj, options) => {
|
|
8
|
+
return (0, util_1.inspect)(obj, {
|
|
9
|
+
showHidden: false,
|
|
10
|
+
depth: null,
|
|
11
|
+
colors: ((options === null || options === void 0 ? void 0 : options.color) === undefined) ? true : options.color,
|
|
12
|
+
sorted: ((options === null || options === void 0 ? void 0 : options.sort) === undefined) ? false : options === null || options === void 0 ? void 0 : options.sort,
|
|
13
|
+
maxArrayLength: Infinity,
|
|
14
|
+
breakLength: (options === null || options === void 0 ? void 0 : options.width) || 120,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.printObject = printObject;
|
|
18
|
+
/** Print object in JSON format */
|
|
19
|
+
const printJSON = (obj, options) => {
|
|
20
|
+
return JSON.stringify(obj, null, (((options === null || options === void 0 ? void 0 : options.unformatted) || false) ? undefined : ((options === null || options === void 0 ? void 0 : options.tabSize) || 4)));
|
|
21
|
+
};
|
|
22
|
+
exports.printJSON = printJSON;
|
|
23
|
+
/** Print object in CSV format */
|
|
24
|
+
const printCSV = (obj, flags) => {
|
|
25
|
+
if (!obj || (obj.length === 0))
|
|
26
|
+
return '';
|
|
27
|
+
const fields = Object.keys(obj[0]).filter(f => {
|
|
28
|
+
if (['id', 'type'].includes(f))
|
|
29
|
+
return flags === null || flags === void 0 ? void 0 : flags.fields.includes(f);
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
let csv = fields.map(f => f.toUpperCase().replace(/_/g, ' ')).join(';') + '\n';
|
|
33
|
+
obj.forEach((o) => {
|
|
34
|
+
csv += fields.map(f => o[f]).join(';') + '\n';
|
|
35
|
+
});
|
|
36
|
+
return csv;
|
|
37
|
+
};
|
|
38
|
+
exports.printCSV = printCSV;
|
|
39
|
+
/** Center a string in the given width space */
|
|
40
|
+
const center = (str, width) => {
|
|
41
|
+
return str.padStart(str.length + Math.floor((width - str.length) / 2), ' ').padEnd(width, ' ');
|
|
42
|
+
};
|
|
43
|
+
exports.center = center;
|
|
44
|
+
/** Compute longest string in a list of strings */
|
|
45
|
+
const maxLength = (values, field) => {
|
|
46
|
+
return values.reduce((ml, v) => {
|
|
47
|
+
const f = Array.isArray(v[field]) ? v[field].join() : v[field];
|
|
48
|
+
return Math.max(ml, String(f).length);
|
|
49
|
+
}, 0);
|
|
50
|
+
};
|
|
51
|
+
exports.maxLength = maxLength;
|
|
52
|
+
/** Clean ISO string date */
|
|
53
|
+
const cleanDate = (date) => {
|
|
54
|
+
return date.replace('T', ' ').replace('Z', '').substring(0, date.lastIndexOf('.'));
|
|
55
|
+
};
|
|
56
|
+
exports.cleanDate = cleanDate;
|
|
57
|
+
/** Localized string date */
|
|
58
|
+
const localeDate = (date) => {
|
|
59
|
+
if (!date)
|
|
60
|
+
return '';
|
|
61
|
+
return new Date(Date.parse(date)).toLocaleString();
|
|
62
|
+
};
|
|
63
|
+
exports.localeDate = localeDate;
|
|
64
|
+
/** Format aoutput */
|
|
65
|
+
const formatOutput = (output, flags, { color = true } = {}) => {
|
|
66
|
+
if (!output)
|
|
67
|
+
return '';
|
|
68
|
+
if (typeof output === 'string')
|
|
69
|
+
return output;
|
|
70
|
+
if (flags) {
|
|
71
|
+
if (flags.csv)
|
|
72
|
+
return printCSV(output, flags);
|
|
73
|
+
if (flags.json)
|
|
74
|
+
return printJSON(output, { unformatted: flags.unformatted });
|
|
75
|
+
}
|
|
76
|
+
return printObject(output, { color });
|
|
77
|
+
};
|
|
78
|
+
exports.formatOutput = formatOutput;
|
|
79
|
+
/** Format error message */
|
|
80
|
+
const formatError = (error, flags) => {
|
|
81
|
+
return formatOutput(error.errors || error, flags);
|
|
82
|
+
};
|
|
83
|
+
exports.formatError = formatError;
|