rads-db 0.1.13 → 0.1.14
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/index.cjs +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -0
- package/integrations/lib.cjs +27 -8
- package/integrations/lib.mjs +19 -3
- package/integrations/node.cjs +6 -1
- package/integrations/node.mjs +6 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,8 @@ function getZodSchema(zodSchemas, schema, key) {
|
|
|
39
39
|
}
|
|
40
40
|
function getFieldZodSchema(zodSchemas, schema, field, shouldBeLazy) {
|
|
41
41
|
let fieldSchema = getFieldZodSchemaBase(zodSchemas, schema, field, shouldBeLazy);
|
|
42
|
+
if (field.isArray)
|
|
43
|
+
fieldSchema = fieldSchema.array();
|
|
42
44
|
if (!field.isRequired)
|
|
43
45
|
fieldSchema = fieldSchema.optional();
|
|
44
46
|
if (field.defaultValue !== void 0)
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,8 @@ function getZodSchema(zodSchemas, schema, key) {
|
|
|
32
32
|
}
|
|
33
33
|
function getFieldZodSchema(zodSchemas, schema, field, shouldBeLazy) {
|
|
34
34
|
let fieldSchema = getFieldZodSchemaBase(zodSchemas, schema, field, shouldBeLazy);
|
|
35
|
+
if (field.isArray)
|
|
36
|
+
fieldSchema = fieldSchema.array();
|
|
35
37
|
if (!field.isRequired)
|
|
36
38
|
fieldSchema = fieldSchema.optional();
|
|
37
39
|
if (field.defaultValue !== void 0)
|
package/integrations/lib.cjs
CHANGED
|
@@ -130,26 +130,41 @@ function parseClassMember(node, ctx) {
|
|
|
130
130
|
const defaultValue = defaultValueDescription?.value;
|
|
131
131
|
const isRequired = !!node.exclamationToken || !!defaultValueDescription;
|
|
132
132
|
const comment = node.jsDoc?.[0]?.comment;
|
|
133
|
-
|
|
133
|
+
let type = node.type?.getText(ctx.sourceFile) ?? defaultValueDescription?.type;
|
|
134
|
+
let isArray = false;
|
|
135
|
+
if (type?.endsWith("[]")) {
|
|
136
|
+
type = type.slice(0, -2);
|
|
137
|
+
isArray = true;
|
|
138
|
+
}
|
|
134
139
|
if (!type) throw new Error(`Cannot detect property type: '${node.getText(ctx.sourceFile)}'`);
|
|
135
140
|
if (!supportedPrimitiveTypes.includes(type) && !ctx.typesMap[type]) throw new Error(`Unexpected property type: '${type}'`);
|
|
136
141
|
if (defaultValueDescription) {
|
|
137
|
-
|
|
138
|
-
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
139
|
-
}
|
|
140
|
-
const enumValues = ctx.typesMap[type]?.enumValues;
|
|
141
|
-
if (enumValues && enumValues.includes(defaultValue)) {
|
|
142
|
-
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
143
|
-
}
|
|
142
|
+
verifyDefaultValueType(isArray, defaultValueDescription, type, supportedPrimitiveTypes, ctx);
|
|
144
143
|
}
|
|
145
144
|
return {
|
|
146
145
|
type,
|
|
147
146
|
defaultValue,
|
|
148
147
|
name,
|
|
149
148
|
isRequired,
|
|
149
|
+
isArray,
|
|
150
150
|
comment
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
+
function verifyDefaultValueType(isArray, defaultValueDescription, type, supportedPrimitiveTypes, ctx) {
|
|
154
|
+
if (isArray) {
|
|
155
|
+
if (defaultValueDescription.type !== "array") {
|
|
156
|
+
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
if (supportedPrimitiveTypes.includes(type) && defaultValueDescription.type !== type) {
|
|
160
|
+
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
161
|
+
}
|
|
162
|
+
const enumValues = ctx.typesMap[type]?.enumValues;
|
|
163
|
+
if (enumValues && enumValues.includes(defaultValueDescription.value)) {
|
|
164
|
+
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
153
168
|
function parseDecorator(decoratorNode, ctx) {
|
|
154
169
|
const expr = decoratorNode.expression;
|
|
155
170
|
if (expr.kind !== _typescript.SyntaxKind.CallExpression) throw new Error(`Unexpected decorator format: "${expr.getText(ctx.sourceFile)}"`);
|
|
@@ -189,6 +204,10 @@ function parseLiteralNode(expr, ctx) {
|
|
|
189
204
|
type: "object",
|
|
190
205
|
value: parseObjectLiteral(expr, ctx)
|
|
191
206
|
};
|
|
207
|
+
if (expr.kind === _typescript.SyntaxKind.ArrayLiteralExpression) return {
|
|
208
|
+
type: "array",
|
|
209
|
+
value: []
|
|
210
|
+
};
|
|
192
211
|
throw new Error(`Unexpected property expression: "${expr.getText(ctx.sourceFile)}"`);
|
|
193
212
|
}
|
|
194
213
|
function parseObjectLiteral(arg, ctx) {
|
package/integrations/lib.mjs
CHANGED
|
@@ -95,21 +95,35 @@ function parseClassMember(node, ctx) {
|
|
|
95
95
|
const defaultValue = defaultValueDescription?.value;
|
|
96
96
|
const isRequired = !!node.exclamationToken || !!defaultValueDescription;
|
|
97
97
|
const comment = node.jsDoc?.[0]?.comment;
|
|
98
|
-
|
|
98
|
+
let type = node.type?.getText(ctx.sourceFile) ?? defaultValueDescription?.type;
|
|
99
|
+
let isArray = false;
|
|
100
|
+
if (type?.endsWith("[]")) {
|
|
101
|
+
type = type.slice(0, -2);
|
|
102
|
+
isArray = true;
|
|
103
|
+
}
|
|
99
104
|
if (!type)
|
|
100
105
|
throw new Error(`Cannot detect property type: '${node.getText(ctx.sourceFile)}'`);
|
|
101
106
|
if (!supportedPrimitiveTypes.includes(type) && !ctx.typesMap[type])
|
|
102
107
|
throw new Error(`Unexpected property type: '${type}'`);
|
|
103
108
|
if (defaultValueDescription) {
|
|
109
|
+
verifyDefaultValueType(isArray, defaultValueDescription, type, supportedPrimitiveTypes, ctx);
|
|
110
|
+
}
|
|
111
|
+
return { type, defaultValue, name, isRequired, isArray, comment };
|
|
112
|
+
}
|
|
113
|
+
function verifyDefaultValueType(isArray, defaultValueDescription, type, supportedPrimitiveTypes, ctx) {
|
|
114
|
+
if (isArray) {
|
|
115
|
+
if (defaultValueDescription.type !== "array") {
|
|
116
|
+
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
104
119
|
if (supportedPrimitiveTypes.includes(type) && defaultValueDescription.type !== type) {
|
|
105
120
|
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
106
121
|
}
|
|
107
122
|
const enumValues = ctx.typesMap[type]?.enumValues;
|
|
108
|
-
if (enumValues && enumValues.includes(
|
|
123
|
+
if (enumValues && enumValues.includes(defaultValueDescription.value)) {
|
|
109
124
|
throw new Error(`Default value type is different from field type: '${type}'`);
|
|
110
125
|
}
|
|
111
126
|
}
|
|
112
|
-
return { type, defaultValue, name, isRequired, comment };
|
|
113
127
|
}
|
|
114
128
|
function parseDecorator(decoratorNode, ctx) {
|
|
115
129
|
const expr = decoratorNode.expression;
|
|
@@ -142,6 +156,8 @@ function parseLiteralNode(expr, ctx) {
|
|
|
142
156
|
return { type: "number", value: Number.parseFloat(expr.text) };
|
|
143
157
|
if (expr.kind === SyntaxKind.ObjectLiteralExpression)
|
|
144
158
|
return { type: "object", value: parseObjectLiteral(expr, ctx) };
|
|
159
|
+
if (expr.kind === SyntaxKind.ArrayLiteralExpression)
|
|
160
|
+
return { type: "array", value: [] };
|
|
145
161
|
throw new Error(`Unexpected property expression: "${expr.getText(ctx.sourceFile)}"`);
|
|
146
162
|
}
|
|
147
163
|
function parseObjectLiteral(arg, ctx) {
|
package/integrations/node.cjs
CHANGED
|
@@ -123,7 +123,7 @@ function getWhereFieldsFor(schema, type, fieldKey) {
|
|
|
123
123
|
const fieldTypeName = field.type;
|
|
124
124
|
let whereTypeName = fieldTypeName;
|
|
125
125
|
const fieldType = schema[fieldTypeName];
|
|
126
|
-
|
|
126
|
+
let result = getWhereFieldsForInner(schema, type, fieldKey);
|
|
127
127
|
if (fieldType) {
|
|
128
128
|
if (fieldType?.decorators?.entity) {
|
|
129
129
|
whereTypeName = `{ id?: string, id_in?: string[] }`;
|
|
@@ -132,6 +132,11 @@ function getWhereFieldsFor(schema, type, fieldKey) {
|
|
|
132
132
|
} else {
|
|
133
133
|
result.unshift(`${name}_in?: ${whereTypeName}[]`);
|
|
134
134
|
}
|
|
135
|
+
if (field.isArray) {
|
|
136
|
+
result = [];
|
|
137
|
+
result.unshift(`${name}_contains?: ${whereTypeName}`);
|
|
138
|
+
result.unshift(`${name}_isEmpty?: boolean`);
|
|
139
|
+
}
|
|
135
140
|
if (!field.isRequired) {
|
|
136
141
|
result.unshift(`${name}_isNull?: boolean`);
|
|
137
142
|
}
|
package/integrations/node.mjs
CHANGED
|
@@ -124,7 +124,7 @@ function getWhereFieldsFor(schema, type, fieldKey) {
|
|
|
124
124
|
const fieldTypeName = field.type;
|
|
125
125
|
let whereTypeName = fieldTypeName;
|
|
126
126
|
const fieldType = schema[fieldTypeName];
|
|
127
|
-
|
|
127
|
+
let result = getWhereFieldsForInner(schema, type, fieldKey);
|
|
128
128
|
if (fieldType) {
|
|
129
129
|
if (fieldType?.decorators?.entity) {
|
|
130
130
|
whereTypeName = `{ id?: string, id_in?: string[] }`;
|
|
@@ -134,6 +134,11 @@ function getWhereFieldsFor(schema, type, fieldKey) {
|
|
|
134
134
|
} else {
|
|
135
135
|
result.unshift(`${name}_in?: ${whereTypeName}[]`);
|
|
136
136
|
}
|
|
137
|
+
if (field.isArray) {
|
|
138
|
+
result = [];
|
|
139
|
+
result.unshift(`${name}_contains?: ${whereTypeName}`);
|
|
140
|
+
result.unshift(`${name}_isEmpty?: boolean`);
|
|
141
|
+
}
|
|
137
142
|
if (!field.isRequired) {
|
|
138
143
|
result.unshift(`${name}_isNull?: boolean`);
|
|
139
144
|
}
|