@commercelayer/cli-core 4.11.4 → 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/filter.js CHANGED
@@ -1 +1,81 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.filters=exports.apply=exports.list=exports.available=exports.documentation=void 0;const config_1=__importDefault(require("./config")),FILTERS=[{predicate:"*_eq",description:"The attribute is equal to the filter value"},{predicate:"*_not_eq",description:"The attribute is not equal to the filter value"},{predicate:"*_matches",description:'The attribute matches the filter value with "LIKE" operator'},{predicate:"*_does_not_match",description:'The attribute does not match the filter value with "LIKE" operator'},{predicate:"*_matches_any",description:'The attribute matches all of the filter values (comma-separated) with "LIKE" operator'},{predicate:"*_matches_all",description:'The attribute matches all of the filter values (comma-separated) with "LIKE" operator'},{predicate:"*_does_not_match_any",description:'The attribute does not match any of the filter values (comma-separated) with "LIKE" operator'},{predicate:"*_does_not_match_all",description:'The attribute matches none of the filter values (comma-separated) with "LIKE" operator'},{predicate:"*_lt",description:"The attribute is less than the filter value"},{predicate:"*_lteq",description:"The attribute is less than or equal to the filter value"},{predicate:"*_gt",description:"The attribute is greater than the filter value"},{predicate:"*_gteq",description:"The attribute is greater than or equal to the filter value"},{predicate:"*_present",description:"The attribute is not null and not empty"},{predicate:"*_blank",description:"The attribute is null or empty"},{predicate:"*_null",description:"The attribute is null"},{predicate:"*_not_null",description:"The attribute is not null"},{predicate:"*_in",description:"The attribute matches any of the filter values (comma-separated)"},{predicate:"*_not_in",description:"The attribute matches none of the filter values (comma-separated)"},{predicate:"*_lt_any",description:"The attribute is less than any of the filter values (comma-separated)"},{predicate:"*_lteq_any",description:"The attribute is less than or equal to any of the filter values (comma-separated)"},{predicate:"*_gt_any",description:"The attribute is greater than any of the filter values (comma-separated)"},{predicate:"*_gteq_any",description:"The attribute is greater than or qual to any of the filter values (comma-separated)"},{predicate:"*_lt_all",description:"The attribute is less than all of the filter values (comma-separated)"},{predicate:"*_lteq_all",description:"The attribute is less than or equal to all of the filter values (comma-separated)"},{predicate:"*_gt_all",description:"The attribute is greater than all of the filter values (comma-separated)"},{predicate:"*_gteq_all",description:"The attribute is greater or equal to all of the filter values (comma-separated)"},{predicate:"*_not_eq_all",description:"The attribute is equal to none of the filter values (comma-separated)"},{predicate:"*_start",description:"The attribute starts with the filter value (comma-separated)"},{predicate:"*_not_start",description:"The attribute does not start with the filter value (comma-separated)"},{predicate:"*_start_any",description:"The attribute starts with any of the filter values (comma-separated)"},{predicate:"*_start_all",description:"The attribute starts with all of the filter values (comma-separated)"},{predicate:"*_not_start_any",description:"The attribute does not start with any of the filter values (comma-separated)"},{predicate:"*_not_start_all",description:"The attribute starts with none of the filter values (comma-separated)"},{predicate:"*_end",description:"The attribute ends with the filter value"},{predicate:"*_not_end",description:"The attribute does not end with the filter value"},{predicate:"*_end_any",description:"The attribute ends with any of the filter values (comma-separated)"},{predicate:"*_end_all",description:"The attribute ends with all of the filter values (comma-separated)"},{predicate:"*_not_end_any",description:"The attribute does not end with any of the filter values (comma-separated)"},{predicate:"*_not_end_all",description:"The attribute ends with none of the filter values (comma-separated)"},{predicate:"*_cont",description:"The attribute contains the filter value"},{predicate:"*_not_cont",description:"The attribute does not contains the filter value"},{predicate:"*_cont_any",description:"The attribute contains any of the filter values (comma-separated)"},{predicate:"*_cont_all",description:"The attribute contains all of the filter values (comma-separated)"},{predicate:"*_not_cont_all",description:"The attribute contains none of the filter values (comma-separated)"},{predicate:"*_jcont",description:"The attribute contains a portion of the JSON used as filter value (works with object only)"},{predicate:"*_true",description:"The attribute is true"},{predicate:"*_false",description:"The attribute is false"}],documentation=config_1.default.doc.core_filtering_data;exports.documentation=documentation;const filterList=()=>filters().map(t=>t.predicate.replace(/^\*/g,""));exports.list=filterList;const filterAvailable=t=>{const a=t.startsWith("_")?t:`_${t}`;return filterList().some(e=>a.endsWith(e))};exports.available=filterAvailable;const applyFilter=(t,...a)=>{if(!filterAvailable(t))throw new Error("Unknown filter: "+t);let e="";for(const i of a)e+=(e.length===0?"":"_or_")+i;return e+=t.startsWith("_")?t:`_${t}`,e};exports.apply=applyFilter;const filters=()=>[...FILTERS];exports.filters=filters;
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";Object.defineProperty(exports,"__esModule",{value:!0});const core_1=require("@oclif/core"),text_1=require("./text"),PRINT_TRACE=!1;class CLICommandHelp extends core_1.CommandHelp{examples(o){return PRINT_TRACE&&console.log("---------- command.examples"),super.examples(o)}}class CLIBaseHelp extends core_1.Help{async showHelp(o){return PRINT_TRACE&&console.log("---------- showHelp"),super.showHelp(o)}async showRootHelp(){return PRINT_TRACE&&console.log("---------- showRootHelp"),super.showRootHelp()}async showTopicHelp(o){return PRINT_TRACE&&console.log("---------- showTopicHelp"),super.showTopicHelp(o)}async showCommandHelp(o){PRINT_TRACE&&console.log("---------- showCommandHelp");const s=o.id,e=s?s.split(":").length:1,t=this.sortedTopics.filter(l=>l.name.startsWith(s+":")&&l.name.split(":").length===e+1),n=this.sortedCommands.filter(l=>l.id.startsWith(s+":")&&l.id.split(":").length===e+1),r=o.description&&this.render(o.description).split(`
2
- `)[0];r&&console.log(`${(0,text_1.capitalize)(r)}
3
- `),console.log(this.formatCommand(o)),console.log(""),t.length>0&&(console.log(this.formatTopics(t)),console.log("")),n.length>0&&(console.log(this.formatCommands(n)),console.log(""))}formatRoot(){return PRINT_TRACE&&console.log("---------- formatRoot"),super.formatRoot()}formatTopic(o){return PRINT_TRACE&&console.log("---------- formatTopic"),super.formatTopic(o)}formatTopics(o){PRINT_TRACE&&console.log("---------- formatTopics");const s=o.filter(e=>!e.hidden).map(e=>(e.description=(0,text_1.capitalize)(e.description),e));return super.formatTopics(s)}formatCommands(o){return PRINT_TRACE&&console.log("---------- formatCommands"),super.formatCommands(o).split(`
4
- `).map(s=>{let e=0;return s.split(" ").map(t=>(t||"").trim()!==""&&++e===2?(0,text_1.capitalize)(t):t).join(" ")}).join(`
5
- `)}formatCommand(o){return PRINT_TRACE&&console.log("---------- formatCommand"),super.formatCommand(o)}getCommandHelpClass(o){return PRINT_TRACE&&console.log("---------- getCommandHelpClass"),new CLICommandHelp(o,this.config,this.opts)}}exports.default=CLIBaseHelp;
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";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){i===void 0&&(i=r);var l=Object.getOwnPropertyDescriptor(t,r);(!l||("get"in l?!t.__esModule:l.writable||l.configurable))&&(l={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,l)}:function(e,t,r,i){i===void 0&&(i=r),e[i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),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,exports.clApi=__importStar(require("./api")),exports.clApplication=__importStar(require("./application"));var config_1=require("./config");Object.defineProperty(exports,"clConfig",{enumerable:!0,get:function(){return __importDefault(config_1).default}}),exports.clCommand=__importStar(require("./command")),exports.clOutput=__importStar(require("./output")),exports.clColor=__importStar(require("./color")),exports.clToken=__importStar(require("./token")),exports.clUpdate=__importStar(require("./update")),exports.clUtil=__importStar(require("./util"));var help_1=require("./help");Object.defineProperty(exports,"clHelp",{enumerable:!0,get:function(){return __importDefault(help_1).default}}),exports.clSchema=__importStar(require("./schema")),exports.clText=__importStar(require("./text")),exports.clSymbol=__importStar(require("./symbol")),exports.clFilter=__importStar(require("./filter"));
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"));
@@ -1 +1,255 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const _Inflector={uncountableWords:["equipment","information","rice","money","species","series","fish","sheep","moose","deer","news"],pluralRules:[[/(m)an$/gi,"$1en"],[/(pe)rson$/gi,"$1ople"],[/(child)$/gi,"$1ren"],[/^(ox)$/gi,"$1en"],[/(ax|test)is$/gi,"$1es"],[/(octop|vir)us$/gi,"$1i"],[/(alias|status)$/gi,"$1es"],[/(bu)s$/gi,"$1ses"],[/(buffal|tomat|potat)o$/gi,"$1oes"],[/([ti])um$/gi,"$1a"],[/sis$/gi,"ses"],[/(?:([^f])fe|([lr])f)$/gi,"$1$2ves"],[/(hive)$/gi,"$1s"],[/([^aeiouy]|qu)y$/gi,"$1ies"],[/(x|ch|ss|sh)$/gi,"$1es"],[/(matr|vert|ind)ix|ex$/gi,"$1ices"],[/([m|l])ouse$/gi,"$1ice"],[/(quiz)$/gi,"$1zes"],[/s$/gi,"s"],[/$/gi,"s"]],singularRules:[[/(m)en$/gi,"$1an"],[/(pe)ople$/gi,"$1rson"],[/(child)ren$/gi,"$1"],[/([ti])a$/gi,"$1um"],[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/gi,"$1$2sis"],[/(hive)s$/gi,"$1"],[/(tive)s$/gi,"$1"],[/(curve)s$/gi,"$1"],[/([lr])ves$/gi,"$1f"],[/([^fo])ves$/gi,"$1fe"],[/([^aeiouy]|qu)ies$/gi,"$1y"],[/(s)eries$/gi,"$1eries"],[/(m)ovies$/gi,"$1ovie"],[/(x|ch|ss|sh)es$/gi,"$1"],[/([m|l])ice$/gi,"$1ouse"],[/(bus)es$/gi,"$1"],[/(o)es$/gi,"$1"],[/(shoe)s$/gi,"$1"],[/(cris|ax|test)es$/gi,"$1is"],[/(octop|vir)i$/gi,"$1us"],[/(alias|status)es$/gi,"$1"],[/^(ox)en/gi,"$1"],[/(vert|ind)ices$/gi,"$1ex"],[/(matr)ices$/gi,"$1ix"],[/(quiz)zes$/gi,"$1"],[/s$/gi,""]],nonTitlecasedWords:["and","or","nor","a","an","the","so","but","to","of","at","by","from","into","on","onto","off","out","in","over","with","for"],idSuffix:/(_ids|_id)$/g,underbar:/_/g,spaceOrUnderbar:/[ _]/g,uppercase:/([A-Z])/g,underbarPrefix:/^_/,applyRules:function(e,i,n,s){if(s)e=s;else if(!n.includes(e.toLowerCase())){for(let r=0;r<i.length;r++)if(e.match(i[r][0])){e=e.replace(i[r][0],i[r][1]);break}}return e},pluralize:function(e,i){return _Inflector.applyRules(e,_Inflector.pluralRules,_Inflector.uncountableWords,i)},singularize:function(e,i){return _Inflector.applyRules(e,_Inflector.singularRules,_Inflector.uncountableWords,i)},camelize:function(e,i){const n=e.split("/");for(let s=0;s<n.length;s++){const o=n[s].split("_"),r=i&&s+1===n.length?1:0;for(let t=r;t<o.length;t++)o[t]=o[t].charAt(0).toUpperCase()+o[t].substring(1);n[s]=o.join("")}if(e=n.join("::"),i){const s=e.charAt(0).toLowerCase(),o=e.slice(1);e=s+o}return e},underscore:function(e){const i=e.split("::");for(let n=0;n<i.length;n++)i[n]=i[n].replace(_Inflector.uppercase,"_$1"),i[n]=i[n].replace(_Inflector.underbarPrefix,"");return e=i.join("/").toLowerCase(),e},humanize:function(e,i){return e=e.toLowerCase(),e=e.replace(_Inflector.idSuffix,""),e=e.replace(_Inflector.underbar," "),i||(e=_Inflector.capitalize(e)),e},capitalize:function(e){return e=e.toLowerCase(),e=e.substring(0,1).toUpperCase()+e.substring(1),e},dasherize:function(e){return e=e.replace(_Inflector.spaceOrUnderbar,"-"),e},camel2words:function(e,i){i?(e=_Inflector.camelize(e),e=_Inflector.underscore(e)):e=e.toLowerCase(),e=e.replace(_Inflector.underbar," ");const n=e.split(" ");for(let s=0;s<n.length;s++){const o=n[s].split("-");for(let r=0;r<o.length;r++)_Inflector.nonTitlecasedWords.includes(o[r].toLowerCase())||(o[r]=_Inflector.capitalize(o[r]));n[s]=o.join("-")}return e=n.join(" "),e=e.substring(0,1).toUpperCase()+e.substring(1),e},demodulize:function(e){const i=e.split("::");return e=i[i.length-1],e},tableize:function(e){return e=_Inflector.pluralize(_Inflector.underscore(e)),e},classify:function(e){return e=_Inflector.singularize(_Inflector.camelize(e)),e},foreignKey:function(e,i){return e=_Inflector.underscore(_Inflector.demodulize(e))+(i?"":"_")+"id",e},ordinalize:function(e){const i=e.split(" ");for(let n=0;n<i.length;n++){const s=parseInt(i[n]);if(Number.isNaN(s)){const o=i[n].substring(i[n].length-2),r=i[n].substring(i[n].length-1);let t="th";o!=="11"&&o!=="12"&&o!=="13"&&(r==="1"?t="st":r==="2"?t="nd":r==="3"&&(t="rd")),i[n]+=t}}return e=i.join(" "),e}};exports.default=_Inflector;
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;
@@ -1 +1,38 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.denormalize=void 0;const findIncluded=(e,i)=>i.find(t=>e.id===t.id&&e.type===t.type),denormalizeResource=(e,i)=>{const t=Object.assign({id:e.id,type:e.type},e.attributes);return e.relationships&&Object.keys(e.relationships).forEach(r=>{const a=e.relationships[r].data;a?Array.isArray(a)?t[r]=a.map(n=>denormalizeResource(findIncluded(n,i),i)):t[r]=denormalizeResource(findIncluded(a,i),i):a===null&&(t[r]=null)}),t},denormalize=e=>{let i;e.links&&delete e.links;const t=e.data,r=e.included;return Array.isArray(t)?i=t.map(a=>denormalizeResource(a,r)):i=denormalizeResource(t,r),i};exports.denormalize=denormalize;
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";Object.defineProperty(exports,"__esModule",{value:!0}),exports.formatError=exports.formatOutput=exports.localeDate=exports.cleanDate=exports.maxLength=exports.center=exports.printCSV=exports.printJSON=exports.printObject=void 0;const util_1=require("util"),printObject=(r,e)=>(0,util_1.inspect)(r,{showHidden:!1,depth:null,colors:e?.color===void 0?!0:e.color,sorted:e?.sort===void 0?!1:e?.sort,maxArrayLength:1/0,breakLength:e?.width||120});exports.printObject=printObject;const printJSON=(r,e)=>JSON.stringify(r,null,e?.unformatted?void 0:e?.tabSize||4);exports.printJSON=printJSON;const printCSV=(r,e)=>{if(!r||r.length===0)return"";const n=Object.keys(r[0]).filter(t=>["id","type"].includes(t)?e?.fields.includes(t):!0);let l=n.map(t=>t.toUpperCase().replace(/_/g," ")).join(";")+`
2
- `;return r.forEach(t=>{l+=n.map(a=>t[a]).join(";")+`
3
- `}),l};exports.printCSV=printCSV;const center=(r,e)=>r.padStart(r.length+Math.floor((e-r.length)/2)," ").padEnd(e," ");exports.center=center;const maxLength=(r,e)=>r.reduce((n,l)=>{const t=Array.isArray(l[e])?l[e].join():l[e];return Math.max(n,String(t).length)},0);exports.maxLength=maxLength;const cleanDate=r=>r.replace("T"," ").replace("Z","").substring(0,r.lastIndexOf("."));exports.cleanDate=cleanDate;const localeDate=r=>r?new Date(Date.parse(r)).toLocaleString():"";exports.localeDate=localeDate;const formatOutput=(r,e,{color:n=!0}={})=>{if(!r)return"";if(typeof r=="string")return r;if(e){if(e.csv)return printCSV(r,e);if(e.json)return printJSON(r,{unformatted:e.unformatted})}return printObject(r,{color:n})};exports.formatOutput=formatOutput;const formatError=(r,e)=>formatOutput(r.errors||r,e);exports.formatError=formatError;
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;