nestjs-trpc 1.3.0 → 1.3.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.util.d.ts","sourceRoot":"","sources":["../../lib/utils/type.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAErG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAKjE;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,0BAA0B,GAAG,MAAM,CAarF;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC7C,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACb,MAAM,
|
|
1
|
+
{"version":3,"file":"type.util.d.ts","sourceRoot":"","sources":["../../lib/utils/type.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAErG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAKjE;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,0BAA0B,GAAG,MAAM,CAarF;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAC7C,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACb,MAAM,CA2FR"}
|
package/dist/utils/type.util.js
CHANGED
|
@@ -24,7 +24,7 @@ function flattenZodSchema(node, importsMap, sourceFile, schema) {
|
|
|
24
24
|
if (ts_morph_1.Node.isIdentifier(node)) {
|
|
25
25
|
const identifierName = node.getText();
|
|
26
26
|
const identifierDeclaration = sourceFile.getVariableDeclaration(identifierName);
|
|
27
|
-
if (identifierDeclaration) {
|
|
27
|
+
if (identifierDeclaration != null) {
|
|
28
28
|
const identifierInitializer = identifierDeclaration.getInitializer();
|
|
29
29
|
if (identifierInitializer != null) {
|
|
30
30
|
const identifierSchema = flattenZodSchema(identifierInitializer, importsMap, sourceFile, identifierInitializer.getText());
|
|
@@ -58,6 +58,12 @@ function flattenZodSchema(node, importsMap, sourceFile, schema) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
else if (ts_morph_1.Node.isCallExpression(node)) {
|
|
61
|
+
const expression = node.getExpression();
|
|
62
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(expression) && !expression.getText().startsWith("z")) {
|
|
63
|
+
const baseSchema = flattenZodSchema(expression, importsMap, sourceFile, expression.getText());
|
|
64
|
+
const propertyName = expression.getName();
|
|
65
|
+
schema = schema.replace(expression.getText(), `${baseSchema}.${propertyName}`);
|
|
66
|
+
}
|
|
61
67
|
for (const arg of node.getArguments()) {
|
|
62
68
|
const argText = arg.getText();
|
|
63
69
|
schema = schema.replace(argText, flattenZodSchema(arg, importsMap, sourceFile, argText));
|
package/lib/utils/type.util.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Node, SourceFile, Type } from 'ts-morph';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ProcedureGeneratorMetadata,
|
|
4
|
+
SourceFileImportsMap,
|
|
5
|
+
} from '../interfaces/generator.interface';
|
|
3
6
|
|
|
4
7
|
export function findCtxOutProperty(type: Type): string | undefined {
|
|
5
8
|
const typeText = type.getText();
|
|
@@ -8,9 +11,13 @@ export function findCtxOutProperty(type: Type): string | undefined {
|
|
|
8
11
|
return ctxOutMatch ? ctxOutMatch[1].trim() : undefined;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
export function generateProcedureString(
|
|
14
|
+
export function generateProcedureString(
|
|
15
|
+
procedure: ProcedureGeneratorMetadata,
|
|
16
|
+
): string {
|
|
12
17
|
const { name, decorators } = procedure;
|
|
13
|
-
const decorator = decorators.find(
|
|
18
|
+
const decorator = decorators.find(
|
|
19
|
+
(d) => d.name === 'Mutation' || d.name === 'Query',
|
|
20
|
+
);
|
|
14
21
|
|
|
15
22
|
if (!decorator) {
|
|
16
23
|
return '';
|
|
@@ -31,25 +38,26 @@ export function flattenZodSchema(
|
|
|
31
38
|
): string {
|
|
32
39
|
if (Node.isIdentifier(node)) {
|
|
33
40
|
const identifierName = node.getText();
|
|
34
|
-
const identifierDeclaration =
|
|
41
|
+
const identifierDeclaration =
|
|
42
|
+
sourceFile.getVariableDeclaration(identifierName);
|
|
35
43
|
|
|
36
|
-
if (identifierDeclaration) {
|
|
44
|
+
if (identifierDeclaration != null) {
|
|
37
45
|
const identifierInitializer = identifierDeclaration.getInitializer();
|
|
38
46
|
|
|
39
|
-
if(identifierInitializer != null) {
|
|
47
|
+
if (identifierInitializer != null) {
|
|
40
48
|
const identifierSchema = flattenZodSchema(
|
|
41
49
|
identifierInitializer,
|
|
42
50
|
importsMap,
|
|
43
51
|
sourceFile,
|
|
44
52
|
identifierInitializer.getText(),
|
|
45
53
|
);
|
|
46
|
-
|
|
54
|
+
|
|
47
55
|
schema = schema.replace(identifierName, identifierSchema);
|
|
48
56
|
}
|
|
49
57
|
} else if (importsMap.has(identifierName)) {
|
|
50
58
|
const importedIdentifier = importsMap.get(identifierName);
|
|
51
59
|
|
|
52
|
-
if(importedIdentifier != null) {
|
|
60
|
+
if (importedIdentifier != null) {
|
|
53
61
|
const { initializer } = importedIdentifier;
|
|
54
62
|
const identifierSchema = flattenZodSchema(
|
|
55
63
|
initializer,
|
|
@@ -57,10 +65,9 @@ export function flattenZodSchema(
|
|
|
57
65
|
importedIdentifier.sourceFile,
|
|
58
66
|
initializer.getText(),
|
|
59
67
|
);
|
|
60
|
-
|
|
68
|
+
|
|
61
69
|
schema = schema.replace(identifierName, identifierSchema);
|
|
62
70
|
}
|
|
63
|
-
|
|
64
71
|
}
|
|
65
72
|
} else if (Node.isObjectLiteralExpression(node)) {
|
|
66
73
|
for (const property of node.getProperties()) {
|
|
@@ -68,7 +75,7 @@ export function flattenZodSchema(
|
|
|
68
75
|
const propertyText = property.getText();
|
|
69
76
|
const propertyInitializer = property.getInitializer();
|
|
70
77
|
|
|
71
|
-
if(
|
|
78
|
+
if (propertyInitializer != null) {
|
|
72
79
|
schema = schema.replace(
|
|
73
80
|
propertyText,
|
|
74
81
|
flattenZodSchema(
|
|
@@ -90,6 +97,23 @@ export function flattenZodSchema(
|
|
|
90
97
|
);
|
|
91
98
|
}
|
|
92
99
|
} else if (Node.isCallExpression(node)) {
|
|
100
|
+
const expression = node.getExpression();
|
|
101
|
+
if (
|
|
102
|
+
Node.isPropertyAccessExpression(expression) &&
|
|
103
|
+
!expression.getText().startsWith('z')
|
|
104
|
+
) {
|
|
105
|
+
const baseSchema = flattenZodSchema(
|
|
106
|
+
expression,
|
|
107
|
+
importsMap,
|
|
108
|
+
sourceFile,
|
|
109
|
+
expression.getText(),
|
|
110
|
+
);
|
|
111
|
+
const propertyName = expression.getName();
|
|
112
|
+
schema = schema.replace(
|
|
113
|
+
expression.getText(),
|
|
114
|
+
`${baseSchema}.${propertyName}`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
93
117
|
for (const arg of node.getArguments()) {
|
|
94
118
|
const argText = arg.getText();
|
|
95
119
|
schema = schema.replace(
|
|
@@ -107,4 +131,4 @@ export function flattenZodSchema(
|
|
|
107
131
|
}
|
|
108
132
|
|
|
109
133
|
return schema;
|
|
110
|
-
}
|
|
134
|
+
}
|