@postxl/generator 0.44.1 → 0.44.3
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)
|
|
@@ -18,6 +18,10 @@ export declare const toPascalCase: (str: string) => string;
|
|
|
18
18
|
* Returns a pluralized version of the given string based on the count.
|
|
19
19
|
*/
|
|
20
20
|
export declare const pluralize: (s: string, count?: number) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if the given string is already pluralized.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isPlural: (s: string) => boolean;
|
|
21
25
|
/**
|
|
22
26
|
* Converts each line of a string to a commented line
|
|
23
27
|
*/
|
package/dist/lib/utils/string.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.conjugateNames = exports.commentLines = exports.pluralize = exports.toPascalCase = exports.toCamelCase = exports.capitalize = exports.uncapitalize = void 0;
|
|
3
|
+
exports.conjugateNames = exports.commentLines = exports.isPlural = exports.pluralize = exports.toPascalCase = exports.toCamelCase = exports.capitalize = exports.uncapitalize = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Returns the same string with a lowercase first letter.
|
|
6
6
|
*/
|
|
@@ -47,6 +47,7 @@ const IRREGULAR_PLURALS = Object.entries({
|
|
|
47
47
|
axis: 'axes',
|
|
48
48
|
basis: 'bases',
|
|
49
49
|
child: 'children',
|
|
50
|
+
children: 'children',
|
|
50
51
|
crisis: 'crises',
|
|
51
52
|
criterion: 'criteria',
|
|
52
53
|
data: 'data',
|
|
@@ -64,6 +65,7 @@ const IRREGULAR_PLURALS = Object.entries({
|
|
|
64
65
|
phenomenon: 'phenomena',
|
|
65
66
|
prognosis: 'prognoses',
|
|
66
67
|
radius: 'radii',
|
|
68
|
+
status: 'statuses',
|
|
67
69
|
suffix: 'suffixes',
|
|
68
70
|
syllabus: 'syllabi',
|
|
69
71
|
synopsis: 'synopses',
|
|
@@ -73,14 +75,14 @@ const IRREGULAR_PLURALS = Object.entries({
|
|
|
73
75
|
* Returns a pluralized version of the given string based on the count.
|
|
74
76
|
*/
|
|
75
77
|
const pluralize = (s, count = 2) => {
|
|
76
|
-
// NOTE: If there's one of something we simply use the
|
|
78
|
+
// NOTE: If there's one of something we simply use the singular form.
|
|
77
79
|
if (count === 1) {
|
|
78
80
|
return s;
|
|
79
81
|
}
|
|
80
82
|
// NOTE: For plural forms, we first check whether a word is irregular.
|
|
81
83
|
const lower = s.toLowerCase();
|
|
82
84
|
for (const [singular, plural] of IRREGULAR_PLURALS) {
|
|
83
|
-
// NOTE: We check that items *end with* a given word
|
|
85
|
+
// NOTE: We check that items *end with* a given word because we use combined words
|
|
84
86
|
// like `UserHistory` as input values of this function.
|
|
85
87
|
if (lower.endsWith(singular)) {
|
|
86
88
|
return s.slice(0, -singular.length + 1) + plural.slice(1);
|
|
@@ -100,6 +102,14 @@ const pluralize = (s, count = 2) => {
|
|
|
100
102
|
return s + 's';
|
|
101
103
|
};
|
|
102
104
|
exports.pluralize = pluralize;
|
|
105
|
+
/**
|
|
106
|
+
* Returns true if the given string is already pluralized.
|
|
107
|
+
*/
|
|
108
|
+
const isPlural = (s) => {
|
|
109
|
+
const plural = (0, exports.pluralize)(s);
|
|
110
|
+
return plural === s;
|
|
111
|
+
};
|
|
112
|
+
exports.isPlural = isPlural;
|
|
103
113
|
/**
|
|
104
114
|
* Converts each line of a string to a commented line
|
|
105
115
|
*/
|
package/dist/prisma/parse.js
CHANGED
|
@@ -60,6 +60,9 @@ function isModelNotIgnored(model) {
|
|
|
60
60
|
* Parses the core properties of a model without fields.
|
|
61
61
|
*/
|
|
62
62
|
function parseModelCore({ dmmfModel, config, }) {
|
|
63
|
+
if ((0, string_1.isPlural)(dmmfModel.name)) {
|
|
64
|
+
(0, error_1.throwError)(`Model ${dmmfModel.name} is plural. Please use singular names for models.`);
|
|
65
|
+
}
|
|
63
66
|
const attributes = (0, attributes_1.getModelAttributes)(dmmfModel);
|
|
64
67
|
return {
|
|
65
68
|
name: Types.toModelName((0, string_1.toPascalCase)(dmmfModel.name)),
|