@postxl/generator 0.0.22 → 0.0.23

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.
@@ -22,17 +22,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.generateDeleteModalModelComponent = exports.generateEditModalModelComponent = exports.generateModelCreateModalComponent = void 0;
30
- const assert_never_1 = __importDefault(require("assert-never"));
31
27
  const serializer_1 = require("../../../lib/serializer");
32
28
  const StringUtils = __importStar(require("../../../lib/utils/string"));
33
29
  const meta_1 = require("../../../lib/meta");
34
30
  const fields_1 = require("../../../lib/schema/fields");
35
31
  const imports_1 = require("../../../lib/imports");
32
+ const types_1 = require("../../../lib/types");
36
33
  /**
37
34
  * Utility generator that creates a create modal component for a given model.
38
35
  */
@@ -163,7 +160,7 @@ export const ${components.modals.editComponentName} = ({
163
160
  case 'scalar':
164
161
  return `${getFormikFieldName(field.name)}: data.${field.name},`;
165
162
  default:
166
- (0, assert_never_1.default)(field);
163
+ throw new types_1.ExhaustiveSwitchCheck(field);
167
164
  }
168
165
  })
169
166
  .join('\n')}
@@ -372,7 +369,7 @@ function getFormInputFields({ model, nullable }) {
372
369
  }
373
370
  break;
374
371
  default:
375
- (0, assert_never_1.default)(field);
372
+ throw new types_1.ExhaustiveSwitchCheck(field);
376
373
  }
377
374
  }
378
375
  return form.print();
@@ -452,7 +449,7 @@ function getFormFieldComponents({ model }) {
452
449
  break;
453
450
  }
454
451
  default:
455
- (0, assert_never_1.default)(field);
452
+ throw new types_1.ExhaustiveSwitchCheck(field);
456
453
  }
457
454
  }
458
455
  return form.print();
@@ -510,7 +507,7 @@ function getFormikMutationData({ model: { fields }, includeId }) {
510
507
  }
511
508
  return `${field.name}: values.${formikFieldName}?.id ? values.${formikFieldName}!.id : null,`;
512
509
  default:
513
- (0, assert_never_1.default)(field);
510
+ throw new types_1.ExhaustiveSwitchCheck(field);
514
511
  }
515
512
  })
516
513
  .join('\n');
@@ -1,5 +1,5 @@
1
- import { Model, SchemaConfig } from '../../lib/schema/schema';
2
1
  import { ModelMetaData } from '../../lib/meta';
2
+ import { Model, SchemaConfig } from '../../lib/schema/schema';
3
3
  /**
4
4
  * Creates a seed file for a given model.
5
5
  */
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.generateSeeds = exports.generateSeedModel = void 0;
7
4
  const faker_1 = require("@faker-js/faker");
8
- const assert_never_1 = __importDefault(require("assert-never"));
9
- const serializer_1 = require("../../lib/serializer");
10
- const string_1 = require("../../lib/utils/string");
5
+ const imports_1 = require("../../lib/imports");
11
6
  const meta_1 = require("../../lib/meta");
12
7
  const fields_1 = require("../../lib/schema/fields");
13
- const imports_1 = require("../../lib/imports");
8
+ const serializer_1 = require("../../lib/serializer");
9
+ const types_1 = require("../../lib/types");
10
+ const string_1 = require("../../lib/utils/string");
14
11
  /**
15
12
  * Creates a seed file for a given model.
16
13
  */
@@ -95,7 +92,7 @@ function generateFieldData({ field, model, index, exampleMode, }) {
95
92
  case 'enum':
96
93
  return generateFieldDataEnum({ field });
97
94
  default:
98
- (0, assert_never_1.default)(field);
95
+ throw new types_1.ExhaustiveSwitchCheck(field);
99
96
  }
100
97
  }
101
98
  function generateFieldDataId({ field, model, index }) {
@@ -121,18 +118,20 @@ function generateFieldDataScalar({ field, model, index, exampleMode, }) {
121
118
  function getFieldExample({ field, model, index, exampleMode, }) {
122
119
  if (exampleMode.mode === 'NoExamples')
123
120
  return { hasExample: false, example: undefined };
124
- if (!field.attributes.examples || field.attributes.examples.length === 0)
121
+ if (!field.attributes.examples || field.attributes.examples.length === 0) {
125
122
  return { hasExample: false, example: undefined };
126
- if (exampleMode.mode === 'Permutations') {
127
- const example = faker_1.faker.helpers.arrayElement(field.attributes.examples);
128
- return { hasExample: true, example };
129
123
  }
130
- else if (exampleMode.mode === 'Tuples') {
131
- const example = field.attributes.examples[index % field.attributes.examples.length];
132
- return { hasExample: true, example };
133
- }
134
- else {
135
- (0, assert_never_1.default)(exampleMode);
124
+ switch (exampleMode.mode) {
125
+ case 'Permutations': {
126
+ const example = faker_1.faker.helpers.arrayElement(field.attributes.examples);
127
+ return { hasExample: true, example };
128
+ }
129
+ case 'Tuples': {
130
+ const example = field.attributes.examples[index % field.attributes.examples.length];
131
+ return { hasExample: true, example };
132
+ }
133
+ default:
134
+ throw new types_1.ExhaustiveSwitchCheck(exampleMode);
136
135
  }
137
136
  }
138
137
  function generateFieldDataString({ field, model, index }) {
@@ -1,5 +1,5 @@
1
- import { Model } from '../../lib/schema/schema';
2
1
  import { ModelMetaData } from '../../lib/meta';
2
+ import { Model } from '../../lib/schema/schema';
3
3
  /**
4
4
  * Generates a stub definition file for a given model.
5
5
  */
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.generateStub = void 0;
7
- const assert_never_1 = __importDefault(require("assert-never"));
4
+ const imports_1 = require("../../lib/imports");
8
5
  const meta_1 = require("../../lib/meta");
9
6
  const fields_1 = require("../../lib/schema/fields");
10
- const imports_1 = require("../../lib/imports");
7
+ const types_1 = require("../../lib/types");
11
8
  /**
12
9
  * Generates a stub definition file for a given model.
13
10
  */
@@ -67,7 +64,7 @@ function getAssigmentStatementModel({ fields }) {
67
64
  case 'enum':
68
65
  return `${f.name}: "${f.enumerator.values[0]}"`;
69
66
  default:
70
- (0, assert_never_1.default)(f);
67
+ throw new types_1.ExhaustiveSwitchCheck(f);
71
68
  }
72
69
  })
73
70
  .join(',\n');
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.generateModelTypes = void 0;
7
- const assert_never_1 = __importDefault(require("assert-never"));
4
+ const imports_1 = require("../../lib/imports");
8
5
  const meta_1 = require("../../lib/meta");
9
6
  const fields_1 = require("../../lib/schema/fields");
10
7
  const zod_1 = require("../../lib/schema/zod");
11
- const imports_1 = require("../../lib/imports");
8
+ const types_1 = require("../../lib/types");
12
9
  /**
13
10
  * Generates types for a given model.
14
11
  */
@@ -111,6 +108,6 @@ function getFieldType(f) {
111
108
  case 'scalar':
112
109
  return f.typeName;
113
110
  default:
114
- (0, assert_never_1.default)(f);
111
+ throw new types_1.ExhaustiveSwitchCheck(f);
115
112
  }
116
113
  }
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getZodDecoderDefinition = void 0;
7
- const assert_never_1 = __importDefault(require("assert-never"));
8
4
  const meta_1 = require("../meta");
5
+ const types_1 = require("../types");
9
6
  /**
10
7
  * Returns the string defining the zod decoder for a given field.
11
8
  */
@@ -39,6 +36,6 @@ function getZodTypeDefinition(field) {
39
36
  case 'relation':
40
37
  return `${field.unbrandedTypeName}()`;
41
38
  default:
42
- (0, assert_never_1.default)(field);
39
+ throw new types_1.ExhaustiveSwitchCheck(field);
43
40
  }
44
41
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Makes a type check that is only valid when all cases of a switch
3
+ * statement have been convered.
4
+ */
5
+ export declare class ExhaustiveSwitchCheck extends Error {
6
+ constructor(val: never);
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExhaustiveSwitchCheck = void 0;
4
+ /**
5
+ * Makes a type check that is only valid when all cases of a switch
6
+ * statement have been convered.
7
+ */
8
+ class ExhaustiveSwitchCheck extends Error {
9
+ constructor(val) {
10
+ super(`Unreachable case: ${JSON.stringify(val)}`);
11
+ }
12
+ }
13
+ exports.ExhaustiveSwitchCheck = ExhaustiveSwitchCheck;