@technicity/data-service-generator 0.8.0 → 0.8.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.
- package/dist/generation/generate.js +54 -18
- package/package.json +1 -1
|
@@ -108,6 +108,7 @@ async function generate(input) {
|
|
|
108
108
|
fs.writeFileSync(path.join(typesDirPath, x.typeDataName + ".ts"), x.typeData);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
fs.writeFileSync(path.join(typesDirPath, "index.ts"), getTypeTypesIndex(data));
|
|
111
112
|
fs.writeFileSync(path.join(tmpDirPath, "package.json"), JSON.stringify(packageJSON, null, 2));
|
|
112
113
|
fs.writeFileSync(path.join(tmpDirPath, "tsconfig.json"), JSON.stringify(tsConfigJSON, null, 2));
|
|
113
114
|
fse.copySync(__dirname, path.join(tmpDirPath, "src"));
|
|
@@ -169,26 +170,30 @@ function init(input) {
|
|
|
169
170
|
// It's a bit awkward to put __whereNeedsProcessing, __prepareWhere on the class,
|
|
170
171
|
// but it allows us to share the same database pool, clientOpts, etc.
|
|
171
172
|
async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts) {
|
|
173
|
+
function getTypeImports() {
|
|
174
|
+
let set = new Set();
|
|
175
|
+
for (let d of input) {
|
|
176
|
+
for (let k of [
|
|
177
|
+
"typeFieldsName",
|
|
178
|
+
"typeReturnBaseName",
|
|
179
|
+
"typeWhereName",
|
|
180
|
+
"typeOrderByName",
|
|
181
|
+
"typeDataName",
|
|
182
|
+
]) {
|
|
183
|
+
const str = d[k];
|
|
184
|
+
if (str) {
|
|
185
|
+
set.add(str);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return `import type { ${["Paginate", "ListPaginated"]
|
|
190
|
+
.concat(Array.from(set).sort())
|
|
191
|
+
.join(",\n")} } from "./types";`;
|
|
192
|
+
}
|
|
172
193
|
const src = `import type { IRuntime, TMiddleware, TContext } from "./IRuntime"
|
|
173
194
|
import { artifacts } from "./artifacts";
|
|
174
|
-
|
|
175
|
-
${
|
|
176
|
-
if (x.kind === "getOne") {
|
|
177
|
-
acc += `import type { ${x.typeReturnBaseName} } from "./types/${x.typeReturnBaseName}";`;
|
|
178
|
-
acc += `import type { ${x.typeFieldsName} } from "./types/${x.typeFieldsName}";`;
|
|
179
|
-
}
|
|
180
|
-
if (x.kind === "getList") {
|
|
181
|
-
acc += `import type { ${x.typeWhereName} } from "./types/${x.typeWhereName}";`;
|
|
182
|
-
acc += `import type { ${x.typeOrderByName} } from "./types/${x.typeOrderByName}";`;
|
|
183
|
-
}
|
|
184
|
-
if (x.kind === "postOne") {
|
|
185
|
-
acc += `import type { ${x.typeDataName} } from "./types/${x.typeDataName}";`;
|
|
186
|
-
}
|
|
187
|
-
if (x.kind === "patchOne") {
|
|
188
|
-
acc += `import type { ${x.typeDataName} } from "./types/${x.typeDataName}";`;
|
|
189
|
-
}
|
|
190
|
-
return acc;
|
|
191
|
-
}, "")}
|
|
195
|
+
|
|
196
|
+
${getTypeImports()}
|
|
192
197
|
|
|
193
198
|
export class SDK {
|
|
194
199
|
runtime: IRuntime;
|
|
@@ -834,6 +839,37 @@ async function getJSONSchemaOrderBy(table, name) {
|
|
|
834
839
|
oneOf: [_schema, { type: "array", items: _schema }],
|
|
835
840
|
};
|
|
836
841
|
}
|
|
842
|
+
function getTypeTypesIndex(data) {
|
|
843
|
+
function getExport(name) {
|
|
844
|
+
return `export type { ${name} } from "./${name}";`;
|
|
845
|
+
}
|
|
846
|
+
let set = new Set();
|
|
847
|
+
for (let d of data) {
|
|
848
|
+
for (let k of [
|
|
849
|
+
"typeFieldsName",
|
|
850
|
+
"typeReturnBaseName",
|
|
851
|
+
"typeWhereName",
|
|
852
|
+
"typeOrderByName",
|
|
853
|
+
"typeDataName",
|
|
854
|
+
]) {
|
|
855
|
+
const str = d[k];
|
|
856
|
+
if (str) {
|
|
857
|
+
set.add(str);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
let src = `export type { ${[
|
|
862
|
+
"Paginate",
|
|
863
|
+
"ListPaginated",
|
|
864
|
+
"TUpdateOperationsString",
|
|
865
|
+
"TUpdateOperationsNumber",
|
|
866
|
+
].join(",")} } from "./_shared";\n\n`;
|
|
867
|
+
let arr = Array.from(set).sort();
|
|
868
|
+
for (let x of arr) {
|
|
869
|
+
src += getExport(x);
|
|
870
|
+
}
|
|
871
|
+
return prettier.format(src, { parser: "typescript" });
|
|
872
|
+
}
|
|
837
873
|
function getTypeShared() {
|
|
838
874
|
const src = `export type Paginate = {
|
|
839
875
|
first: number;
|