@exogee/graphweaver-mikroorm 0.1.24 → 0.2.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.
- package/lib/base-resolver/assign.d.ts +1 -1
- package/lib/base-resolver/provider.d.ts +5 -2
- package/lib/base-resolver/provider.js +27 -36
- package/lib/base-resolver/provider.js.map +3 -3
- package/lib/database.d.ts +4 -1
- package/lib/database.js +13 -2
- package/lib/database.js.map +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +2 -2
- package/lib/introspection/files/base-file.d.ts +8 -0
- package/lib/introspection/files/base-file.js +38 -0
- package/lib/introspection/files/base-file.js.map +7 -0
- package/lib/introspection/files/data-entity-file.d.ts +27 -0
- package/lib/introspection/files/data-entity-file.js +324 -0
- package/lib/introspection/files/data-entity-file.js.map +7 -0
- package/lib/introspection/files/data-entity-index-file.d.ts +10 -0
- package/lib/introspection/files/data-entity-index-file.js +61 -0
- package/lib/introspection/files/data-entity-index-file.js.map +7 -0
- package/lib/introspection/files/data-source-index-file.d.ts +8 -0
- package/lib/introspection/files/data-source-index-file.js +44 -0
- package/lib/introspection/files/data-source-index-file.js.map +7 -0
- package/lib/introspection/files/database-file.d.ts +9 -0
- package/lib/introspection/files/database-file.js +75 -0
- package/lib/introspection/files/database-file.js.map +7 -0
- package/lib/introspection/files/index.d.ts +8 -0
- package/lib/introspection/files/index.js +26 -0
- package/lib/introspection/files/index.js.map +7 -0
- package/lib/introspection/files/schema-entity-file.d.ts +25 -0
- package/lib/introspection/files/schema-entity-file.js +239 -0
- package/lib/introspection/files/schema-entity-file.js.map +7 -0
- package/lib/introspection/files/schema-entity-index-file.d.ts +6 -0
- package/lib/introspection/files/schema-entity-index-file.js +44 -0
- package/lib/introspection/files/schema-entity-index-file.js.map +7 -0
- package/lib/introspection/files/schema-index-file.d.ts +8 -0
- package/lib/introspection/files/schema-index-file.js +60 -0
- package/lib/introspection/files/schema-index-file.js.map +7 -0
- package/lib/introspection/files/schema-resolver-file.d.ts +6 -0
- package/lib/introspection/files/schema-resolver-file.js +62 -0
- package/lib/introspection/files/schema-resolver-file.js.map +7 -0
- package/lib/introspection/generate.d.ts +11 -0
- package/lib/introspection/generate.js +215 -0
- package/lib/introspection/generate.js.map +7 -0
- package/lib/introspection/index.d.ts +6 -0
- package/lib/introspection/index.js +30 -0
- package/lib/introspection/index.js.map +7 -0
- package/lib/introspection/utils.d.ts +3 -0
- package/lib/introspection/utils.js +43 -0
- package/lib/introspection/utils.js.map +7 -0
- package/lib/plugins/connect-to-database.js +3 -1
- package/lib/plugins/connect-to-database.js.map +2 -2
- package/package.json +12 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/introspection/files/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './data-entity-file';\nexport * from './data-entity-index-file';\nexport * from './data-source-index-file';\nexport * from './schema-entity-file';\nexport * from './schema-entity-index-file';\nexport * from './schema-index-file';\nexport * from './schema-resolver-file';\nexport * from './database-file';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,+BAAd;AACA,0BAAc,qCADd;AAEA,0BAAc,qCAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,uCAJd;AAKA,0BAAc,gCALd;AAMA,0BAAc,mCANd;AAOA,0BAAc,4BAPd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Dictionary, EntityMetadata, EntityProperty, NamingStrategy, Platform } from '@mikro-orm/core';
|
|
2
|
+
import { BaseFile } from './base-file';
|
|
3
|
+
export declare class SchemaEntityFile extends BaseFile {
|
|
4
|
+
protected readonly meta: EntityMetadata;
|
|
5
|
+
protected readonly namingStrategy: NamingStrategy;
|
|
6
|
+
protected readonly platform: Platform;
|
|
7
|
+
protected readonly coreImports: Set<string>;
|
|
8
|
+
protected readonly scalarImports: Set<string>;
|
|
9
|
+
protected readonly entityImports: Set<string>;
|
|
10
|
+
protected readonly enumImports: Set<string>;
|
|
11
|
+
constructor(meta: EntityMetadata, namingStrategy: NamingStrategy, platform: Platform);
|
|
12
|
+
getBasePath(): string;
|
|
13
|
+
getBaseName(): string;
|
|
14
|
+
generate(): string;
|
|
15
|
+
protected getTypescriptPropertyType(prop: EntityProperty): string;
|
|
16
|
+
protected getPropertyDefinition(prop: EntityProperty): string;
|
|
17
|
+
protected getEnumClassDefinition(enumClassName: string): string;
|
|
18
|
+
private getGraphQLPropertyType;
|
|
19
|
+
private getPropertyDecorator;
|
|
20
|
+
protected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
21
|
+
protected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
22
|
+
protected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
23
|
+
protected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
|
|
24
|
+
protected getDecoratorType(prop: EntityProperty): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var schema_entity_file_exports = {};
|
|
26
|
+
__export(schema_entity_file_exports, {
|
|
27
|
+
SchemaEntityFile: () => SchemaEntityFile
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(schema_entity_file_exports);
|
|
30
|
+
var import_core = require("@mikro-orm/core");
|
|
31
|
+
var import_base_file = require("./base-file");
|
|
32
|
+
var import_utils = require("../utils");
|
|
33
|
+
var import_pluralize = __toESM(require("pluralize"));
|
|
34
|
+
class SchemaEntityFile extends import_base_file.BaseFile {
|
|
35
|
+
constructor(meta, namingStrategy, platform) {
|
|
36
|
+
super(meta, namingStrategy, platform);
|
|
37
|
+
this.meta = meta;
|
|
38
|
+
this.namingStrategy = namingStrategy;
|
|
39
|
+
this.platform = platform;
|
|
40
|
+
this.coreImports = /* @__PURE__ */ new Set();
|
|
41
|
+
this.scalarImports = /* @__PURE__ */ new Set();
|
|
42
|
+
this.entityImports = /* @__PURE__ */ new Set();
|
|
43
|
+
this.enumImports = /* @__PURE__ */ new Set();
|
|
44
|
+
}
|
|
45
|
+
getBasePath() {
|
|
46
|
+
const dirName = (0, import_utils.pascalToKebabCaseString)(this.meta.className);
|
|
47
|
+
return `backend/schema/${dirName}/`;
|
|
48
|
+
}
|
|
49
|
+
getBaseName() {
|
|
50
|
+
return "entity.ts";
|
|
51
|
+
}
|
|
52
|
+
generate() {
|
|
53
|
+
const enumDefinitions = [];
|
|
54
|
+
let classBody = "\n";
|
|
55
|
+
const props = Object.values(this.meta.properties);
|
|
56
|
+
props.forEach((prop) => {
|
|
57
|
+
const decorator = this.getPropertyDecorator(prop);
|
|
58
|
+
const definition = this.getPropertyDefinition(prop);
|
|
59
|
+
if (!classBody.endsWith("\n\n")) {
|
|
60
|
+
classBody += "\n";
|
|
61
|
+
}
|
|
62
|
+
if (["name", "title"].includes(prop.name.toLowerCase())) {
|
|
63
|
+
this.coreImports.add("SummaryField");
|
|
64
|
+
classBody += ` @SummaryField()
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
classBody += decorator;
|
|
68
|
+
classBody += definition;
|
|
69
|
+
if (props[props.length - 1] !== prop)
|
|
70
|
+
classBody += "\n";
|
|
71
|
+
if (prop.enum) {
|
|
72
|
+
const enumClassName = this.namingStrategy.getClassName(
|
|
73
|
+
this.meta.collection + "_" + prop.fieldNames[0],
|
|
74
|
+
"_"
|
|
75
|
+
);
|
|
76
|
+
enumDefinitions.push(this.getEnumClassDefinition(enumClassName));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
let file = "";
|
|
80
|
+
if (enumDefinitions.length) {
|
|
81
|
+
file += enumDefinitions.join("\n");
|
|
82
|
+
file += "\n\n";
|
|
83
|
+
}
|
|
84
|
+
this.coreImports.add("ObjectType");
|
|
85
|
+
file += `@ObjectType(${this.quote(this.meta.className)})
|
|
86
|
+
`;
|
|
87
|
+
this.coreImports.add("GraphQLEntity");
|
|
88
|
+
file += `export class ${this.meta.className} extends GraphQLEntity<Orm${this.meta.className}> {
|
|
89
|
+
`;
|
|
90
|
+
file += ` public dataEntity!: Orm${this.meta.className};`;
|
|
91
|
+
file += `${classBody}}
|
|
92
|
+
`;
|
|
93
|
+
const imports = [
|
|
94
|
+
`import { ${[...this.coreImports].sort().join(", ")} } from '@exogee/graphweaver';`
|
|
95
|
+
];
|
|
96
|
+
if (this.scalarImports.size > 0) {
|
|
97
|
+
imports.push(
|
|
98
|
+
`import { ${[...this.scalarImports].sort().join(", ")} } from '@exogee/graphweaver-scalars';`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);
|
|
102
|
+
entityImports.sort().forEach((entity) => {
|
|
103
|
+
imports.push(`import { ${entity} } from '../${(0, import_utils.pascalToKebabCaseString)(entity)}';`);
|
|
104
|
+
});
|
|
105
|
+
imports.push(
|
|
106
|
+
`import { ${this.enumImports.size > 0 ? [...this.enumImports].sort().join(", ") + ", " : ""}${this.meta.className} as Orm${this.meta.className} } from '../../entities';`
|
|
107
|
+
);
|
|
108
|
+
file = `${imports.join("\n")}
|
|
109
|
+
|
|
110
|
+
${file}`;
|
|
111
|
+
return file;
|
|
112
|
+
}
|
|
113
|
+
getTypescriptPropertyType(prop) {
|
|
114
|
+
if (["jsonb", "json", "any"].includes(prop.columnTypes?.[0])) {
|
|
115
|
+
return `Record<string, unknown>`;
|
|
116
|
+
}
|
|
117
|
+
if (prop.columnTypes?.[0] === "date") {
|
|
118
|
+
return "Date";
|
|
119
|
+
}
|
|
120
|
+
if (prop.type === "unknown") {
|
|
121
|
+
return "string";
|
|
122
|
+
}
|
|
123
|
+
return prop.type;
|
|
124
|
+
}
|
|
125
|
+
getPropertyDefinition(prop) {
|
|
126
|
+
const padding = " ";
|
|
127
|
+
if ([import_core.ReferenceType.ONE_TO_MANY, import_core.ReferenceType.MANY_TO_MANY].includes(prop.reference)) {
|
|
128
|
+
this.entityImports.add(prop.type);
|
|
129
|
+
return `${padding}${prop.name}!: ${prop.type}[];
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
const isEnumOrNonStringDefault = prop.enum || typeof prop.default !== "string";
|
|
133
|
+
const useDefault = prop.default != null && isEnumOrNonStringDefault;
|
|
134
|
+
const optional = prop.nullable ? "?" : useDefault ? "" : "!";
|
|
135
|
+
if (prop.primary) {
|
|
136
|
+
return `${padding}id!: ${this.getTypescriptPropertyType(prop)};`;
|
|
137
|
+
}
|
|
138
|
+
const file = `${prop.name}${optional}: ${this.getTypescriptPropertyType(prop)}`;
|
|
139
|
+
if (!useDefault) {
|
|
140
|
+
return `${padding + file};
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
if (prop.enum && typeof prop.default === "string") {
|
|
144
|
+
return `${padding}${file} = ${prop.type}.${prop.default.toUpperCase()};
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
return `${padding}${prop.name} = ${prop.default};
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
getEnumClassDefinition(enumClassName) {
|
|
151
|
+
this.coreImports.add("registerEnumType");
|
|
152
|
+
this.enumImports.add(enumClassName);
|
|
153
|
+
return `registerEnumType(${enumClassName}, { name: ${this.quote(enumClassName)} });`;
|
|
154
|
+
}
|
|
155
|
+
getGraphQLPropertyType(prop) {
|
|
156
|
+
if (prop.primary) {
|
|
157
|
+
this.coreImports.add("ID");
|
|
158
|
+
return "ID";
|
|
159
|
+
}
|
|
160
|
+
if (prop.type === "Date") {
|
|
161
|
+
this.scalarImports.add("ISODateStringScalar");
|
|
162
|
+
return "ISODateStringScalar";
|
|
163
|
+
}
|
|
164
|
+
if (prop.columnTypes?.[0] === "date") {
|
|
165
|
+
return "Date";
|
|
166
|
+
}
|
|
167
|
+
if (prop.type === "unknown") {
|
|
168
|
+
return "String";
|
|
169
|
+
}
|
|
170
|
+
if (["jsonb", "json", "any"].includes(prop.columnTypes?.[0])) {
|
|
171
|
+
this.scalarImports.add("GraphQLJSON");
|
|
172
|
+
return `GraphQLJSON`;
|
|
173
|
+
}
|
|
174
|
+
if (prop.type.includes("[]")) {
|
|
175
|
+
return `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace("[]", "")}]`;
|
|
176
|
+
}
|
|
177
|
+
if ([import_core.ReferenceType.MANY_TO_MANY, import_core.ReferenceType.ONE_TO_MANY].includes(prop.reference)) {
|
|
178
|
+
return `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace("[]", "")}]`;
|
|
179
|
+
}
|
|
180
|
+
if (prop.pivotTable) {
|
|
181
|
+
return `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1)}]`;
|
|
182
|
+
}
|
|
183
|
+
return prop.type.charAt(0).toUpperCase() + prop.type.slice(1);
|
|
184
|
+
}
|
|
185
|
+
getPropertyDecorator(prop) {
|
|
186
|
+
const padding = " ";
|
|
187
|
+
const options = {};
|
|
188
|
+
let decorator = this.getDecoratorType(prop);
|
|
189
|
+
if (prop.reference === import_core.ReferenceType.MANY_TO_MANY) {
|
|
190
|
+
this.getManyToManyDecoratorOptions(options, prop);
|
|
191
|
+
} else if (prop.reference === import_core.ReferenceType.ONE_TO_MANY) {
|
|
192
|
+
this.getOneToManyDecoratorOptions(options, prop);
|
|
193
|
+
} else if (prop.reference !== import_core.ReferenceType.SCALAR) {
|
|
194
|
+
this.getForeignKeyDecoratorOptions(options, prop);
|
|
195
|
+
}
|
|
196
|
+
this.getCommonDecoratorOptions(options, prop);
|
|
197
|
+
decorator = [decorator].map((d) => padding + d).join("\n");
|
|
198
|
+
if (!import_core.Utils.hasObjectKeys(options)) {
|
|
199
|
+
return `${decorator}(() => ${this.getGraphQLPropertyType(prop)})
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
return `${decorator}(() => ${this.getGraphQLPropertyType(prop)}, { ${Object.entries(options).map(([opt, val]) => `${opt}: ${val}`).join(", ")} })
|
|
203
|
+
`;
|
|
204
|
+
}
|
|
205
|
+
getCommonDecoratorOptions(options, prop) {
|
|
206
|
+
if (prop.nullable && !prop.mappedBy) {
|
|
207
|
+
options.nullable = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
getManyToManyDecoratorOptions(options, prop) {
|
|
211
|
+
this.entityImports.add(prop.type);
|
|
212
|
+
options.relatedField = this.quote((0, import_pluralize.default)((0, import_utils.pascalToCamelCaseString)(this.meta.className)));
|
|
213
|
+
}
|
|
214
|
+
getOneToManyDecoratorOptions(options, prop) {
|
|
215
|
+
this.entityImports.add(prop.type);
|
|
216
|
+
options.relatedField = this.quote(prop.mappedBy);
|
|
217
|
+
}
|
|
218
|
+
getForeignKeyDecoratorOptions(options, prop) {
|
|
219
|
+
this.entityImports.add(prop.type);
|
|
220
|
+
options.id = `(entity) => entity.${prop.name}?.id`;
|
|
221
|
+
}
|
|
222
|
+
getDecoratorType(prop) {
|
|
223
|
+
if ([import_core.ReferenceType.ONE_TO_ONE, import_core.ReferenceType.MANY_TO_ONE].includes(prop.reference)) {
|
|
224
|
+
this.coreImports.add("RelationshipField");
|
|
225
|
+
return `@RelationshipField<${this.meta.className}>`;
|
|
226
|
+
}
|
|
227
|
+
if ([import_core.ReferenceType.ONE_TO_MANY, import_core.ReferenceType.MANY_TO_MANY].includes(prop.reference)) {
|
|
228
|
+
this.coreImports.add("RelationshipField");
|
|
229
|
+
return `@RelationshipField<${prop.type}>`;
|
|
230
|
+
}
|
|
231
|
+
this.coreImports.add("Field");
|
|
232
|
+
return "@Field";
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
SchemaEntityFile
|
|
238
|
+
});
|
|
239
|
+
//# sourceMappingURL=schema-entity-file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/introspection/files/schema-entity-file.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n\tDictionary,\n\tEntityMetadata,\n\tEntityProperty,\n\tNamingStrategy,\n\tPlatform,\n} from '@mikro-orm/core';\nimport { ReferenceType, Utils } from '@mikro-orm/core';\n\nimport { BaseFile } from './base-file';\nimport { pascalToCamelCaseString, pascalToKebabCaseString } from '../utils';\nimport pluralize from 'pluralize';\n\nexport class SchemaEntityFile extends BaseFile {\n\tprotected readonly coreImports = new Set<string>();\n\tprotected readonly scalarImports = new Set<string>();\n\tprotected readonly entityImports = new Set<string>();\n\tprotected readonly enumImports = new Set<string>();\n\n\tconstructor(\n\t\tprotected readonly meta: EntityMetadata,\n\t\tprotected readonly namingStrategy: NamingStrategy,\n\t\tprotected readonly platform: Platform\n\t) {\n\t\tsuper(meta, namingStrategy, platform);\n\t}\n\n\tgetBasePath() {\n\t\tconst dirName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `backend/schema/${dirName}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'entity.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst enumDefinitions: string[] = [];\n\t\tlet classBody = '\\n';\n\t\tconst props = Object.values(this.meta.properties);\n\t\tprops.forEach((prop) => {\n\t\t\tconst decorator = this.getPropertyDecorator(prop);\n\t\t\tconst definition = this.getPropertyDefinition(prop);\n\n\t\t\tif (!classBody.endsWith('\\n\\n')) {\n\t\t\t\tclassBody += '\\n';\n\t\t\t}\n\n\t\t\t// Add a summary field if we have a name or title attribute\n\t\t\tif (['name', 'title'].includes(prop.name.toLowerCase())) {\n\t\t\t\tthis.coreImports.add('SummaryField');\n\t\t\t\tclassBody += `\\t@SummaryField()\\n`;\n\t\t\t}\n\t\t\tclassBody += decorator;\n\t\t\tclassBody += definition;\n\n\t\t\tif (props[props.length - 1] !== prop) classBody += '\\n';\n\n\t\t\tif (prop.enum) {\n\t\t\t\tconst enumClassName = this.namingStrategy.getClassName(\n\t\t\t\t\tthis.meta.collection + '_' + prop.fieldNames[0],\n\t\t\t\t\t'_'\n\t\t\t\t);\n\t\t\t\tenumDefinitions.push(this.getEnumClassDefinition(enumClassName));\n\t\t\t}\n\t\t});\n\n\t\tlet file = '';\n\n\t\tif (enumDefinitions.length) {\n\t\t\tfile += enumDefinitions.join('\\n');\n\t\t\tfile += '\\n\\n';\n\t\t}\n\n\t\tthis.coreImports.add('ObjectType');\n\t\tfile += `@ObjectType(${this.quote(this.meta.className)})\\n`;\n\n\t\tthis.coreImports.add('GraphQLEntity');\n\t\tfile += `export class ${this.meta.className} extends GraphQLEntity<Orm${this.meta.className}> {\\n`;\n\t\tfile += `\\tpublic dataEntity!: Orm${this.meta.className};`;\n\n\t\tfile += `${classBody}}\\n`;\n\t\tconst imports = [\n\t\t\t`import { ${[...this.coreImports].sort().join(', ')} } from '@exogee/graphweaver';`,\n\t\t];\n\n\t\tif (this.scalarImports.size > 0) {\n\t\t\timports.push(\n\t\t\t\t`import { ${[...this.scalarImports]\n\t\t\t\t\t.sort()\n\t\t\t\t\t.join(', ')} } from '@exogee/graphweaver-scalars';`\n\t\t\t);\n\t\t}\n\n\t\tconst entityImports = [...this.entityImports].filter((e) => e !== this.meta.className);\n\t\tentityImports.sort().forEach((entity) => {\n\t\t\timports.push(`import { ${entity} } from '../${pascalToKebabCaseString(entity)}';`);\n\t\t});\n\n\t\timports.push(\n\t\t\t`import { ${this.enumImports.size > 0 ? [...this.enumImports].sort().join(', ') + ', ' : ''}${\n\t\t\t\tthis.meta.className\n\t\t\t} as Orm${this.meta.className} } from '../../entities';`\n\t\t);\n\n\t\tfile = `${imports.join('\\n')}\\n\\n${file}`;\n\n\t\treturn file;\n\t}\n\n\tprotected getTypescriptPropertyType(prop: EntityProperty): string {\n\t\tif (['jsonb', 'json', 'any'].includes(prop.columnTypes?.[0])) {\n\t\t\treturn `Record<string, unknown>`;\n\t\t}\n\n\t\tif (prop.columnTypes?.[0] === 'date') {\n\t\t\treturn 'Date';\n\t\t}\n\n\t\tif (prop.type === 'unknown') {\n\t\t\t//fallback to string if unknown\n\t\t\treturn 'string';\n\t\t}\n\n\t\treturn prop.type;\n\t}\n\n\tprotected getPropertyDefinition(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\n\t\tif ([ReferenceType.ONE_TO_MANY, ReferenceType.MANY_TO_MANY].includes(prop.reference)) {\n\t\t\tthis.entityImports.add(prop.type);\n\t\t\treturn `${padding}${prop.name}!: ${prop.type}[];\\n`;\n\t\t}\n\n\t\t// string defaults are usually things like SQL functions, but can be also enums, for that `useDefault` should be true\n\t\tconst isEnumOrNonStringDefault = prop.enum || typeof prop.default !== 'string';\n\t\tconst useDefault = prop.default != null && isEnumOrNonStringDefault;\n\t\tconst optional = prop.nullable ? '?' : useDefault ? '' : '!';\n\n\t\tif (prop.primary) {\n\t\t\treturn `${padding}id!: ${this.getTypescriptPropertyType(prop)};`;\n\t\t}\n\n\t\tconst file = `${prop.name}${optional}: ${this.getTypescriptPropertyType(prop)}`;\n\n\t\tif (!useDefault) {\n\t\t\treturn `${padding + file};\\n`;\n\t\t}\n\n\t\tif (prop.enum && typeof prop.default === 'string') {\n\t\t\treturn `${padding}${file} = ${prop.type}.${prop.default.toUpperCase()};\\n`;\n\t\t}\n\n\t\treturn `${padding}${prop.name} = ${prop.default};\\n`;\n\t}\n\n\tprotected getEnumClassDefinition(enumClassName: string): string {\n\t\tthis.coreImports.add('registerEnumType');\n\t\tthis.enumImports.add(enumClassName);\n\t\treturn `registerEnumType(${enumClassName}, { name: ${this.quote(enumClassName)} });`;\n\t}\n\n\tprivate getGraphQLPropertyType(prop: EntityProperty): string {\n\t\tif (prop.primary) {\n\t\t\tthis.coreImports.add('ID');\n\t\t\treturn 'ID';\n\t\t}\n\n\t\tif (prop.type === 'Date') {\n\t\t\tthis.scalarImports.add('ISODateStringScalar');\n\t\t\treturn 'ISODateStringScalar';\n\t\t}\n\n\t\tif (prop.columnTypes?.[0] === 'date') {\n\t\t\treturn 'Date';\n\t\t}\n\n\t\tif (prop.type === 'unknown') {\n\t\t\treturn 'String';\n\t\t}\n\n\t\tif (['jsonb', 'json', 'any'].includes(prop.columnTypes?.[0])) {\n\t\t\tthis.scalarImports.add('GraphQLJSON');\n\t\t\treturn `GraphQLJSON`;\n\t\t}\n\n\t\tif (prop.type.includes('[]')) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif ([ReferenceType.MANY_TO_MANY, ReferenceType.ONE_TO_MANY].includes(prop.reference)) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1).replace('[]', '')}]`;\n\t\t}\n\n\t\tif (prop.pivotTable) {\n\t\t\treturn `[${prop.type.charAt(0).toUpperCase() + prop.type.slice(1)}]`;\n\t\t}\n\n\t\treturn prop.type.charAt(0).toUpperCase() + prop.type.slice(1);\n\t}\n\n\tprivate getPropertyDecorator(prop: EntityProperty): string {\n\t\tconst padding = '\\t';\n\t\tconst options = {} as Dictionary;\n\t\tlet decorator = this.getDecoratorType(prop);\n\n\t\tif (prop.reference === ReferenceType.MANY_TO_MANY) {\n\t\t\tthis.getManyToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.reference === ReferenceType.ONE_TO_MANY) {\n\t\t\tthis.getOneToManyDecoratorOptions(options, prop);\n\t\t} else if (prop.reference !== ReferenceType.SCALAR) {\n\t\t\tthis.getForeignKeyDecoratorOptions(options, prop);\n\t\t}\n\n\t\tthis.getCommonDecoratorOptions(options, prop);\n\t\tdecorator = [decorator].map((d) => padding + d).join('\\n');\n\n\t\tif (!Utils.hasObjectKeys(options)) {\n\t\t\treturn `${decorator}(() => ${this.getGraphQLPropertyType(prop)})\\n`;\n\t\t}\n\n\t\treturn `${decorator}(() => ${this.getGraphQLPropertyType(prop)}, { ${Object.entries(options)\n\t\t\t.map(([opt, val]) => `${opt}: ${val}`)\n\t\t\t.join(', ')} })\\n`;\n\t}\n\n\tprotected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void {\n\t\tif (prop.nullable && !prop.mappedBy) {\n\t\t\toptions.nullable = true;\n\t\t}\n\t}\n\n\tprotected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.relatedField = this.quote(pluralize(pascalToCamelCaseString(this.meta.className)));\n\t}\n\n\tprotected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.relatedField = this.quote(prop.mappedBy);\n\t}\n\n\tprotected getForeignKeyDecoratorOptions(options: Dictionary, prop: EntityProperty) {\n\t\tthis.entityImports.add(prop.type);\n\t\toptions.id = `(entity) => entity.${prop.name}?.id`;\n\t}\n\n\tprotected getDecoratorType(prop: EntityProperty): string {\n\t\tif ([ReferenceType.ONE_TO_ONE, ReferenceType.MANY_TO_ONE].includes(prop.reference)) {\n\t\t\tthis.coreImports.add('RelationshipField');\n\t\t\treturn `@RelationshipField<${this.meta.className}>`;\n\t\t}\n\n\t\tif ([ReferenceType.ONE_TO_MANY, ReferenceType.MANY_TO_MANY].includes(prop.reference)) {\n\t\t\tthis.coreImports.add('RelationshipField');\n\t\t\treturn `@RelationshipField<${prop.type}>`;\n\t\t}\n\n\t\tthis.coreImports.add('Field');\n\t\treturn '@Field';\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,kBAAqC;AAErC,uBAAyB;AACzB,mBAAiE;AACjE,uBAAsB;AAEf,MAAM,yBAAyB,0BAAS;AAAA,EAM9C,YACoB,MACA,gBACA,UAClB;AACD,UAAM,MAAM,gBAAgB,QAAQ;AAJjB;AACA;AACA;AARpB,SAAmB,cAAc,oBAAI,IAAY;AACjD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,gBAAgB,oBAAI,IAAY;AACnD,SAAmB,cAAc,oBAAI,IAAY;AAAA,EAQjD;AAAA,EAEA,cAAc;AACb,UAAM,cAAU,sCAAwB,KAAK,KAAK,SAAS;AAC3D,WAAO,kBAAkB;AAAA,EAC1B;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,kBAA4B,CAAC;AACnC,QAAI,YAAY;AAChB,UAAM,QAAQ,OAAO,OAAO,KAAK,KAAK,UAAU;AAChD,UAAM,QAAQ,CAAC,SAAS;AACvB,YAAM,YAAY,KAAK,qBAAqB,IAAI;AAChD,YAAM,aAAa,KAAK,sBAAsB,IAAI;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AI;AAChC,YAAQ,KAAK,sBAAsB,KAAK;AAAA,EACzC;AAAA,EAEU,iBAAiB,MAA8B;AACxD,QAAI,CAAC,0BAAc,YAAY,0BAAc,WAAW,EAAE,SAAS,KAAK,SAAS,GAAG;AACnF,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK,KAAK;AAAA,IACxC;AAEA,QAAI,CAAC,0BAAc,aAAa,0BAAc,YAAY,EAAE,SAAS,KAAK,SAAS,GAAG;AACrF,WAAK,YAAY,IAAI,mBAAmB;AACxC,aAAO,sBAAsB,KAAK;AAAA,IACnC;AAEA,SAAK,YAAY,IAAI,OAAO;AAC5B,WAAO;AAAA,EACR;AACD;",
|
|
6
|
+
"names": ["pluralize"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var schema_entity_index_file_exports = {};
|
|
20
|
+
__export(schema_entity_index_file_exports, {
|
|
21
|
+
SchemaEntityIndexFile: () => SchemaEntityIndexFile
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(schema_entity_index_file_exports);
|
|
24
|
+
var import_utils = require("../utils");
|
|
25
|
+
var import_base_file = require("./base-file");
|
|
26
|
+
class SchemaEntityIndexFile extends import_base_file.BaseFile {
|
|
27
|
+
getBasePath() {
|
|
28
|
+
const dirName = (0, import_utils.pascalToKebabCaseString)(this.meta.className);
|
|
29
|
+
return `backend/schema/${dirName}/`;
|
|
30
|
+
}
|
|
31
|
+
getBaseName() {
|
|
32
|
+
return "index.ts";
|
|
33
|
+
}
|
|
34
|
+
generate() {
|
|
35
|
+
const exports = [`export * from './entity';`, `export * from './resolver';`];
|
|
36
|
+
return `${exports.join("\n")}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
SchemaEntityIndexFile
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=schema-entity-index-file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/introspection/files/schema-entity-index-file.ts"],
|
|
4
|
+
"sourcesContent": ["import { pascalToKebabCaseString } from '../utils';\nimport { BaseFile } from './base-file';\n\nexport class SchemaEntityIndexFile extends BaseFile {\n\tgetBasePath() {\n\t\tconst dirName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `backend/schema/${dirName}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst exports = [`export * from './entity';`, `export * from './resolver';`];\n\n\t\treturn `${exports.join('\\n')}\\n`;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwC;AACxC,uBAAyB;AAElB,MAAM,8BAA8B,0BAAS;AAAA,EACnD,cAAc;AACb,UAAM,cAAU,sCAAwB,KAAK,KAAK,SAAS;AAC3D,WAAO,kBAAkB;AAAA,EAC1B;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,UAAU,CAAC,6BAA6B,6BAA6B;AAE3E,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAC5B;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EntityMetadata } from '@mikro-orm/core';
|
|
2
|
+
export declare class SchemaIndexFile {
|
|
3
|
+
protected readonly metadata: EntityMetadata<any>[];
|
|
4
|
+
constructor(metadata: EntityMetadata<any>[]);
|
|
5
|
+
getBasePath(): string;
|
|
6
|
+
getBaseName(): string;
|
|
7
|
+
generate(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var schema_index_file_exports = {};
|
|
20
|
+
__export(schema_index_file_exports, {
|
|
21
|
+
SchemaIndexFile: () => SchemaIndexFile
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(schema_index_file_exports);
|
|
24
|
+
class SchemaIndexFile {
|
|
25
|
+
constructor(metadata) {
|
|
26
|
+
this.metadata = metadata;
|
|
27
|
+
}
|
|
28
|
+
getBasePath() {
|
|
29
|
+
return `backend/schema`;
|
|
30
|
+
}
|
|
31
|
+
getBaseName() {
|
|
32
|
+
return "index.ts";
|
|
33
|
+
}
|
|
34
|
+
generate() {
|
|
35
|
+
let file = "export const resolvers = [\n";
|
|
36
|
+
const padding = " ";
|
|
37
|
+
const imports = [];
|
|
38
|
+
const exports = [];
|
|
39
|
+
for (const meta of this.metadata) {
|
|
40
|
+
if (!meta.pivotTable) {
|
|
41
|
+
const filename = meta.className.replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
42
|
+
exports.push(`export * from './${filename}';`);
|
|
43
|
+
imports.push(`import { ${meta.className}Resolver } from './${filename}';`);
|
|
44
|
+
file += `${padding}${meta.className}Resolver,
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
file += "];\n";
|
|
49
|
+
return `${imports.join("\n")}
|
|
50
|
+
|
|
51
|
+
${exports.join("\n")}
|
|
52
|
+
|
|
53
|
+
${file}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
SchemaIndexFile
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=schema-index-file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/introspection/files/schema-index-file.ts"],
|
|
4
|
+
"sourcesContent": ["import { EntityMetadata } from '@mikro-orm/core';\n\nexport class SchemaIndexFile {\n\tconstructor(protected readonly metadata: EntityMetadata<any>[]) {}\n\n\tgetBasePath() {\n\t\treturn `backend/schema`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'index.ts';\n\t}\n\n\tgenerate(): string {\n\t\tlet file = 'export const resolvers = [\\n';\n\t\tconst padding = '\\t';\n\t\tconst imports: string[] = [];\n\t\tconst exports: string[] = [];\n\n\t\tfor (const meta of this.metadata) {\n\t\t\tif (!meta.pivotTable) {\n\t\t\t\tconst filename = meta.className.replace(/([a-z0\u20139])([A-Z])/g, '$1-$2').toLowerCase();\n\t\t\t\texports.push(`export * from './${filename}';`);\n\t\t\t\timports.push(`import { ${meta.className}Resolver } from './${filename}';`);\n\t\t\t\tfile += `${padding}${meta.className}Resolver,\\n`;\n\t\t\t}\n\t\t}\n\n\t\tfile += '];\\n';\n\n\t\treturn `${imports.join('\\n')}\\n\\n${exports.join('\\n')}\\n\\n${file}`;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,gBAAgB;AAAA,EAC5B,YAA+B,UAAiC;AAAjC;AAAA,EAAkC;AAAA,EAEjE,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,QAAI,OAAO;AACX,UAAM,UAAU;AAChB,UAAM,UAAoB,CAAC;AAC3B,UAAM,UAAoB,CAAC;AAE3B,eAAW,QAAQ,KAAK,UAAU;AACjC,UAAI,CAAC,KAAK,YAAY;AACrB,cAAM,WAAW,KAAK,UAAU,QAAQ,sBAAsB,OAAO,EAAE,YAAY;AACnF,gBAAQ,KAAK,oBAAoB,YAAY;AAC7C,gBAAQ,KAAK,YAAY,KAAK,+BAA+B,YAAY;AACzE,gBAAQ,GAAG,UAAU,KAAK;AAAA;AAAA,MAC3B;AAAA,IACD;AAEA,YAAQ;AAER,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ;AAAA,EAC7D;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var schema_resolver_file_exports = {};
|
|
20
|
+
__export(schema_resolver_file_exports, {
|
|
21
|
+
SchemaResolverFile: () => SchemaResolverFile
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(schema_resolver_file_exports);
|
|
24
|
+
var import_utils = require("../utils");
|
|
25
|
+
var import_base_file = require("./base-file");
|
|
26
|
+
class SchemaResolverFile extends import_base_file.BaseFile {
|
|
27
|
+
getBasePath() {
|
|
28
|
+
const dirName = (0, import_utils.pascalToKebabCaseString)(this.meta.className);
|
|
29
|
+
return `backend/schema/${dirName}/`;
|
|
30
|
+
}
|
|
31
|
+
getBaseName() {
|
|
32
|
+
return "resolver.ts";
|
|
33
|
+
}
|
|
34
|
+
generate() {
|
|
35
|
+
const padding = " ";
|
|
36
|
+
let file = `@Resolver((of) => ${this.meta.className})
|
|
37
|
+
`;
|
|
38
|
+
file += `export class ${this.meta.className}Resolver extends createBaseResolver<${this.meta.className}, Orm${this.meta.className}>(
|
|
39
|
+
`;
|
|
40
|
+
file += `${padding}${this.meta.className},
|
|
41
|
+
`;
|
|
42
|
+
file += `${padding}new MikroBackendProvider(Orm${this.meta.className}, connection)
|
|
43
|
+
`;
|
|
44
|
+
file += `) {}
|
|
45
|
+
`;
|
|
46
|
+
const imports = [
|
|
47
|
+
`import { createBaseResolver, Resolver } from '@exogee/graphweaver';`,
|
|
48
|
+
`import { MikroBackendProvider } from '@exogee/graphweaver-mikroorm';`,
|
|
49
|
+
`import { ${this.meta.className} } from './entity';`,
|
|
50
|
+
`import { ${this.meta.className} as Orm${this.meta.className} } from '../../entities';`,
|
|
51
|
+
`import { connection } from '../../database';`
|
|
52
|
+
];
|
|
53
|
+
return `${imports.join("\n")}
|
|
54
|
+
|
|
55
|
+
${file}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
SchemaResolverFile
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=schema-resolver-file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/introspection/files/schema-resolver-file.ts"],
|
|
4
|
+
"sourcesContent": ["import { pascalToKebabCaseString } from '../utils';\nimport { BaseFile } from './base-file';\n\nexport class SchemaResolverFile extends BaseFile {\n\tgetBasePath() {\n\t\tconst dirName = pascalToKebabCaseString(this.meta.className);\n\t\treturn `backend/schema/${dirName}/`;\n\t}\n\n\tgetBaseName() {\n\t\treturn 'resolver.ts';\n\t}\n\n\tgenerate(): string {\n\t\tconst padding = '\\t';\n\n\t\tlet file = `@Resolver((of) => ${this.meta.className})\\n`;\n\t\tfile += `export class ${this.meta.className}Resolver extends createBaseResolver<${this.meta.className}, Orm${this.meta.className}>(\\n`;\n\t\tfile += `${padding}${this.meta.className},\\n`;\n\t\tfile += `${padding}new MikroBackendProvider(Orm${this.meta.className}, connection)\\n`;\n\t\tfile += `) {}\\n`;\n\n\t\tconst imports = [\n\t\t\t`import { createBaseResolver, Resolver } from '@exogee/graphweaver';`,\n\t\t\t`import { MikroBackendProvider } from '@exogee/graphweaver-mikroorm';`,\n\t\t\t`import { ${this.meta.className} } from './entity';`,\n\t\t\t`import { ${this.meta.className} as Orm${this.meta.className} } from '../../entities';`,\n\t\t\t`import { connection } from '../../database';`,\n\t\t];\n\n\t\treturn `${imports.join('\\n')}\\n\\n${file}`;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwC;AACxC,uBAAyB;AAElB,MAAM,2BAA2B,0BAAS;AAAA,EAChD,cAAc;AACb,UAAM,cAAU,sCAAwB,KAAK,KAAK,SAAS;AAC3D,WAAO,kBAAkB;AAAA,EAC1B;AAAA,EAEA,cAAc;AACb,WAAO;AAAA,EACR;AAAA,EAEA,WAAmB;AAClB,UAAM,UAAU;AAEhB,QAAI,OAAO,qBAAqB,KAAK,KAAK;AAAA;AAC1C,YAAQ,gBAAgB,KAAK,KAAK,gDAAgD,KAAK,KAAK,iBAAiB,KAAK,KAAK;AAAA;AACvH,YAAQ,GAAG,UAAU,KAAK,KAAK;AAAA;AAC/B,YAAQ,GAAG,sCAAsC,KAAK,KAAK;AAAA;AAC3D,YAAQ;AAAA;AAER,UAAM,UAAU;AAAA,MACf;AAAA,MACA;AAAA,MACA,YAAY,KAAK,KAAK;AAAA,MACtB,YAAY,KAAK,KAAK,mBAAmB,KAAK,KAAK;AAAA,MACnD;AAAA,IACD;AAEA,WAAO,GAAG,QAAQ,KAAK,IAAI;AAAA;AAAA,EAAQ;AAAA,EACpC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectionOptions, DatabaseType } from '../database';
|
|
2
|
+
export declare class IntrospectionError extends Error {
|
|
3
|
+
protected title: string;
|
|
4
|
+
protected type: string;
|
|
5
|
+
constructor(title?: string, message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const generate: (databaseType: DatabaseType, options: ConnectionOptions) => Promise<{
|
|
8
|
+
path: string;
|
|
9
|
+
name: string;
|
|
10
|
+
contents: string;
|
|
11
|
+
}[]>;
|