@postxl/generator 0.44.0 → 0.44.2
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.
|
@@ -220,6 +220,7 @@ exports.generateMockRepository = generateMockRepository;
|
|
|
220
220
|
function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, imports, blocks, }) {
|
|
221
221
|
const methodTypeSignatures = getRepositoryMethodsTypeSignatures({ model, meta });
|
|
222
222
|
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_InMemoryOnly({ model, meta, imports });
|
|
223
|
+
imports.addImport({ from: (0, types_1.toPath)('@pxl/common'), items: ['removeUndefinedProperties'].map(types_1.toFunctionName) });
|
|
223
224
|
return {
|
|
224
225
|
constructorCode: '',
|
|
225
226
|
userRepositorySpecificBlocks,
|
|
@@ -347,7 +348,7 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, imports, blocks
|
|
|
347
348
|
|
|
348
349
|
${blocks.uniqueStringFieldsBlocks.updateCode.join('\n')}
|
|
349
350
|
|
|
350
|
-
const newItem = await Promise.resolve({ ...existingItem, ...item })
|
|
351
|
+
const newItem = await Promise.resolve({ ...existingItem, ...removeUndefinedProperties(item) })
|
|
351
352
|
${model.updatedAtField ? `newItem.${model.updatedAtField.name} = new Date()` : ''}
|
|
352
353
|
|
|
353
354
|
this.remove(existingItem)
|
package/dist/lib/utils/string.js
CHANGED
|
@@ -40,7 +40,7 @@ const toPascalCase = (str) => {
|
|
|
40
40
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
41
41
|
};
|
|
42
42
|
exports.toPascalCase = toPascalCase;
|
|
43
|
-
const
|
|
43
|
+
const IRREGULAR_PLURALS = Object.entries({
|
|
44
44
|
alumnus: 'alumni',
|
|
45
45
|
analysis: 'analyses',
|
|
46
46
|
appendix: 'appendices',
|
|
@@ -68,14 +68,24 @@ const irregularPlurals = {
|
|
|
68
68
|
syllabus: 'syllabi',
|
|
69
69
|
synopsis: 'synopses',
|
|
70
70
|
thesis: 'theses',
|
|
71
|
-
};
|
|
71
|
+
});
|
|
72
72
|
/**
|
|
73
73
|
* Returns a pluralized version of the given string based on the count.
|
|
74
74
|
*/
|
|
75
75
|
const pluralize = (s, count = 2) => {
|
|
76
|
+
// NOTE: If there's one of something we simply use the singluar form.
|
|
76
77
|
if (count === 1) {
|
|
77
78
|
return s;
|
|
78
79
|
}
|
|
80
|
+
// NOTE: For plural forms, we first check whether a word is irregular.
|
|
81
|
+
const lower = s.toLowerCase();
|
|
82
|
+
for (const [singular, plural] of IRREGULAR_PLURALS) {
|
|
83
|
+
// NOTE: We check that items *end with* a given word becase we use combined words
|
|
84
|
+
// like `UserHistory` as input values of this function.
|
|
85
|
+
if (lower.endsWith(singular)) {
|
|
86
|
+
return s.slice(0, -singular.length + 1) + plural.slice(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
79
89
|
if (s.endsWith('y') &&
|
|
80
90
|
!s.endsWith('ay') &&
|
|
81
91
|
!s.endsWith('ey') &&
|
|
@@ -87,13 +97,6 @@ const pluralize = (s, count = 2) => {
|
|
|
87
97
|
if (s.endsWith('s')) {
|
|
88
98
|
return s;
|
|
89
99
|
}
|
|
90
|
-
//check if word ends with any irregular plurals
|
|
91
|
-
const lower = s.toLowerCase();
|
|
92
|
-
for (const [irregularPlural, irregularSingular] of Object.entries(irregularPlurals)) {
|
|
93
|
-
if (lower.endsWith(irregularPlural)) {
|
|
94
|
-
return s.slice(0, -irregularPlural.length + 1) + irregularSingular.slice(1);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
100
|
return s + 's';
|
|
98
101
|
};
|
|
99
102
|
exports.pluralize = pluralize;
|