@postxl/generator 0.24.1 → 0.25.0

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.
@@ -134,7 +134,7 @@ function generateScalarFieldExample({ field, model, index, mode, }) {
134
134
  if (hasExample) {
135
135
  return `${example}`;
136
136
  }
137
- switch (field.type) {
137
+ switch (field.schemaType) {
138
138
  case 'BigInt':
139
139
  case 'Int':
140
140
  return generateMockInteger();
@@ -193,7 +193,7 @@ export type FieldCore = {
193
193
  /**
194
194
  * The type of the field as it appears in the schema (e.g. `Int`, `Float`, `String`).
195
195
  */
196
- type: string;
196
+ schemaType: string;
197
197
  /**
198
198
  * Validation rule for the field.
199
199
  */
@@ -33,7 +33,7 @@ function getZodTypeDefinition(field) {
33
33
  return `date()`;
34
34
  }
35
35
  case 'number': {
36
- switch (field.type) {
36
+ switch (field.schemaType) {
37
37
  case 'Int':
38
38
  case 'BigInt':
39
39
  return `number().int()`;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns a string of JSDoc comments from an array of lines.
3
+ */
4
+ export declare function convertToJsDocComments(comments: string[]): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToJsDocComments = void 0;
4
+ /**
5
+ * Returns a string of JSDoc comments from an array of lines.
6
+ */
7
+ function convertToJsDocComments(comments) {
8
+ return comments
9
+ .filter((c) => c !== '')
10
+ .map((c) => `\n * ${c}`)
11
+ .join('');
12
+ }
13
+ exports.convertToJsDocComments = convertToJsDocComments;
@@ -105,7 +105,7 @@ function parseModel({ dmmfModel, enums, models, config, }) {
105
105
  isRequired: dmmfField.isRequired,
106
106
  attributes,
107
107
  schemaConfig: config,
108
- type: dmmfField.type,
108
+ schemaType: dmmfField.type,
109
109
  };
110
110
  // NOTE: We mark scalar fields which are used in relations as relation fields by Purple Schema standards.
111
111
  if (dmmfField.name in relations) {
@@ -117,7 +117,7 @@ function parseModel({ dmmfModel, enums, models, config, }) {
117
117
  return Object.assign(Object.assign({ kind: 'relation' }, shared), { relatedModelBacklinkFieldName: refField.name, typeName: Types.toTypeName(dmmfField.type), unbrandedTypeName: getTsTypeForId(dmmfField), relationToModel: refModel });
118
118
  }
119
119
  if (dmmfField.isId) {
120
- return Object.assign(Object.assign({ kind: 'id' }, shared), { isUnique: isUniqueField(dmmfField), isGenerated: isAutoIncrementField(dmmfField), unbrandedTypeName: getTsTypeForId(dmmfField), model: core });
120
+ return Object.assign(Object.assign({ kind: 'id' }, shared), { isUnique: isUniqueField(dmmfField), isGenerated: isAutoIncrementField(dmmfField) || isUUIDField(dmmfField), unbrandedTypeName: getTsTypeForId(dmmfField), model: core });
121
121
  }
122
122
  if (dmmfField.kind === 'scalar') {
123
123
  let validation = undefined;
@@ -201,6 +201,10 @@ function isAutoIncrementField(fieldDmmf) {
201
201
  const d = fieldDmmf.default;
202
202
  return d !== undefined && !!d.name && d.name === 'autoincrement';
203
203
  }
204
+ function isUUIDField(fieldDmmf) {
205
+ const d = fieldDmmf.default;
206
+ return d !== undefined && !!d.name && d.name === 'cuid';
207
+ }
204
208
  function isUniqueField(fieldRaw) {
205
209
  return fieldRaw.isUnique && fieldRaw.type === 'String';
206
210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {
@@ -46,11 +46,9 @@
46
46
  "build": "tsc -p tsconfig.build.json",
47
47
  "prepublish": "tsc -p tsconfig.build.json",
48
48
  "dev": "tsc -p tsconfig.build.json -w",
49
- "test": "jest",
49
+ "test": "./scripts/test.sh",
50
+ "test:jest": "jest",
50
51
  "test:watch": "jest --watch",
51
- "test:types": "tsc --noEmit",
52
- "testgen:simple": "cd ./tests/schemas/simple/ && prisma generate",
53
- "testgen:mca": "cd ./tests/schemas/mca/ && prisma generate",
54
- "testgen:la": "cd ./tests/schemas/la/ && prisma generate"
52
+ "test:types": "tsc --noEmit"
55
53
  }
56
54
  }