@postxl/generator 0.0.21 → 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.
- package/dist/jest.config.js +17 -0
- package/dist/src/generator.js +0 -0
- package/dist/src/generators/indices/dataservice.generator.js +1 -1
- package/dist/src/generators/indices/testdataservice.generator.js +2 -1
- package/dist/src/generators/models/react.generator/context.generator.js +1 -1
- package/dist/src/generators/models/react.generator/modals.generator.js +5 -8
- package/dist/src/generators/models/route.generator.js +1 -1
- package/dist/src/generators/models/seed.generator.d.ts +1 -1
- package/dist/src/generators/models/seed.generator.js +17 -18
- package/dist/src/generators/models/stub.generator.d.ts +1 -1
- package/dist/src/generators/models/stub.generator.js +3 -6
- package/dist/src/generators/models/types.generator.js +3 -6
- package/dist/src/lib/schema/zod.js +2 -5
- package/dist/src/lib/types.d.ts +7 -0
- package/dist/src/lib/types.js +13 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/CHANGELOG.md +0 -7
- package/changelog.md +0 -115
- package/jest.config.ts +0 -18
- package/tests/attributes.test.ts +0 -91
- package/tests/file.test.ts +0 -32
- package/tests/schemas/la/la.prisma +0 -862
- package/tests/schemas/mca/mca.prisma +0 -528
- package/tests/utils/random.ts +0 -11
- package/tests/vfs.test.ts +0 -92
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// import { pathsToModuleNameMapper } from 'ts-jest'
|
|
4
|
+
// import { compilerOptions } from './tsconfig.json'
|
|
5
|
+
const config = {
|
|
6
|
+
verbose: true,
|
|
7
|
+
// roots: ['<rootDir>/tests', '<rootDir>/src'],
|
|
8
|
+
testEnvironment: 'node',
|
|
9
|
+
transform: {
|
|
10
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
11
|
+
},
|
|
12
|
+
testRegex: '(\\.|/)test\\.tsx?$',
|
|
13
|
+
testPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'],
|
|
14
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
15
|
+
// moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' }),
|
|
16
|
+
};
|
|
17
|
+
exports.default = config;
|
package/dist/src/generator.js
CHANGED
|
File without changes
|
|
@@ -25,7 +25,7 @@ function generateDataService({ models, meta }) {
|
|
|
25
25
|
const isEmptyChecks = mm.map(({ meta }) => `this.${meta.data.dataServiceName}.count() === 0`).join(' &&');
|
|
26
26
|
return `
|
|
27
27
|
import { Injectable } from '@nestjs/common'
|
|
28
|
-
import { mapValues } from '@
|
|
28
|
+
import { mapValues } from '@pxl/common'
|
|
29
29
|
|
|
30
30
|
${imports.generate()}
|
|
31
31
|
|
|
@@ -35,8 +35,9 @@ function generateTestDataService({ meta }) {
|
|
|
35
35
|
from: meta.data.dataMockModuleFilePath,
|
|
36
36
|
});
|
|
37
37
|
return `
|
|
38
|
-
import { ResetService } from '@d2i/common'
|
|
39
38
|
import { Injectable, Logger } from '@nestjs/common'
|
|
39
|
+
|
|
40
|
+
import { ResetService } from '@pxl/common'
|
|
40
41
|
import { DbService } from '@${meta.config.project}/db'
|
|
41
42
|
|
|
42
43
|
${imports.generate()}
|
|
@@ -17,7 +17,7 @@ function generateModelContext({ model, meta }) {
|
|
|
17
17
|
return `
|
|
18
18
|
import React, { useMemo } from 'react'
|
|
19
19
|
|
|
20
|
-
import { createUseContext } from '@lib/
|
|
20
|
+
import { createUseContext } from '@lib/react'
|
|
21
21
|
import { trpc } from '@lib/trpc'
|
|
22
22
|
import { filterMap, mapMap } from '@lib/utils'
|
|
23
23
|
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
510
|
+
throw new types_1.ExhaustiveSwitchCheck(field);
|
|
514
511
|
}
|
|
515
512
|
})
|
|
516
513
|
.join('\n');
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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,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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
throw new types_1.ExhaustiveSwitchCheck(field);
|
|
43
40
|
}
|
|
44
41
|
}
|
|
@@ -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;
|