@postxl/generator 0.73.3 → 0.73.5
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.
|
@@ -18,10 +18,6 @@ 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;
|
|
25
21
|
/**
|
|
26
22
|
* Converts each line of a string to a commented line
|
|
27
23
|
*/
|
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.
|
|
3
|
+
exports.conjugateNames = exports.commentLines = 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
|
*/
|
|
@@ -102,14 +102,6 @@ const pluralize = (s, count = 2) => {
|
|
|
102
102
|
return s + 's';
|
|
103
103
|
};
|
|
104
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;
|
|
113
105
|
/**
|
|
114
106
|
* Converts each line of a string to a commented line
|
|
115
107
|
*/
|
package/dist/prisma/parse.js
CHANGED
|
@@ -34,7 +34,6 @@ const attributes_1 = require("./attributes");
|
|
|
34
34
|
*/
|
|
35
35
|
function parsePrismaSchema({ datamodel: { enums: enumsRaw, models: modelsRaw }, config, }) {
|
|
36
36
|
ensurePXLSystemModelsExist(modelsRaw);
|
|
37
|
-
ensureConsistency({ models: modelsRaw, enums: enumsRaw });
|
|
38
37
|
// NOTE: We preprocess models and enums so that we can populate relationships.
|
|
39
38
|
const models = modelsRaw.map((dmmfModel) => parseModelCore({ dmmfModel, config }));
|
|
40
39
|
const enums = enumsRaw.map((dmmfEnum) => parseEnum({ dmmfEnum, config }));
|
|
@@ -73,56 +72,6 @@ function ensurePXLSystemModelsExist(models) {
|
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Validates:
|
|
78
|
-
* - That there are no duplicate model names
|
|
79
|
-
* - That model names are singular
|
|
80
|
-
* - That model attributes are valid
|
|
81
|
-
* - That field attributes are valid
|
|
82
|
-
* - That enum attributes are valid
|
|
83
|
-
*/
|
|
84
|
-
function ensureConsistency({ models, enums }) {
|
|
85
|
-
const errors = [];
|
|
86
|
-
const modelNames = models.map((m) => m.name);
|
|
87
|
-
const duplicateModelName = modelNames.find((name, i) => modelNames.indexOf(name) !== i);
|
|
88
|
-
if (duplicateModelName) {
|
|
89
|
-
errors.push(`Model ${duplicateModelName} is defined more than once.`);
|
|
90
|
-
}
|
|
91
|
-
for (const model of models) {
|
|
92
|
-
if ((0, string_1.isPlural)(model.name)) {
|
|
93
|
-
errors.push(`Model ${(0, logger_1.highlight)(model.name)} is plural. Please use singular names for models.`);
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
(0, attributes_1.getModelAttributes)(model);
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
errors.push(`Model ${(0, logger_1.highlight)(model.name)} has invalid model attributes: ${(0, error_1.extractError)(e)}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
for (const model of models) {
|
|
103
|
-
for (const field of model.fields) {
|
|
104
|
-
try {
|
|
105
|
-
(0, attributes_1.getFieldAttributes)(field);
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
errors.push(`Model ${(0, logger_1.highlight)(model.name)} has invalid attributes for field ${(0, logger_1.highlight)(field.name)}:
|
|
109
|
-
${(0, error_1.extractError)(e)}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
for (const enumDef of enums) {
|
|
114
|
-
try {
|
|
115
|
-
(0, attributes_1.getEnumAttributes)(enumDef);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
errors.push(`Enum ${(0, logger_1.highlight)(enumDef.name)} has invalid attributes:
|
|
119
|
-
${(0, error_1.extractError)(e)}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (errors.length > 0) {
|
|
123
|
-
(0, error_1.throwError)(`${errors.length} ${(0, string_1.pluralize)('issue', errors.length)} detected in schema:\n * ${errors.join('\n * ')}`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
75
|
function isModelNotIgnored(model) {
|
|
127
76
|
return model !== undefined && !model.attributes.ignore;
|
|
128
77
|
}
|
|
@@ -130,9 +79,6 @@ function isModelNotIgnored(model) {
|
|
|
130
79
|
* Parses the core properties of a model without fields.
|
|
131
80
|
*/
|
|
132
81
|
function parseModelCore({ dmmfModel, config, }) {
|
|
133
|
-
if ((0, string_1.isPlural)(dmmfModel.name)) {
|
|
134
|
-
(0, error_1.throwError)(`Model ${dmmfModel.name} is plural. Please use singular names for models.`);
|
|
135
|
-
}
|
|
136
82
|
const attributes = (0, attributes_1.getModelAttributes)(dmmfModel);
|
|
137
83
|
return {
|
|
138
84
|
name: Types.toModelName((0, string_1.toPascalCase)(dmmfModel.name)),
|