@technicity/data-service-generator 0.8.0 → 0.8.3
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 +59 -19
- package/dist/runtime/IRuntime.d.ts +1 -0
- package/dist/runtime/RuntimeKSQL.d.ts +1 -0
- package/dist/runtime/RuntimeKSQL.js +3 -0
- package/dist/runtime/RuntimeMSSQL.d.ts +1 -0
- package/dist/runtime/RuntimeMSSQL.js +3 -0
- package/dist/runtime/RuntimeMySQL.d.ts +1 -0
- package/dist/runtime/RuntimeMySQL.js +3 -0
- package/dist/runtime/lib/MSSQL.d.ts +1 -0
- package/dist/runtime/lib/MSSQL.js +3 -0
- package/dist/runtime/lib/MySQL.d.ts +1 -0
- package/dist/runtime/lib/MySQL.js +3 -0
- package/package.json +4 -2
|
@@ -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"));
|
|
@@ -116,7 +117,7 @@ async function generate(input) {
|
|
|
116
117
|
const sdkOutputPath = path.join(outdir, "sdk-ts");
|
|
117
118
|
const nccVersion = "^0.33.0";
|
|
118
119
|
child_process.execSync("npm i", { cwd: tmpDirPath, stdio: "inherit" });
|
|
119
|
-
child_process.execSync(`npx
|
|
120
|
+
child_process.execSync(`npm_config_yes=true npx -p @vercel/ncc@${nccVersion} ncc build ./${sdkFilename} -o ${tmpBuildOutputPath} -e ./artifacts`, { cwd: tmpDirPath, stdio: "inherit" });
|
|
120
121
|
// TODO: workaround for artifacts.js not being output by ncc
|
|
121
122
|
fs.writeFileSync(path.join(tmpBuildOutputPath, "artifacts.js"), artifactsSource
|
|
122
123
|
.replace("export const artifacts: IArtifacts = ", "module.exports.artifacts = ")
|
|
@@ -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;
|
|
@@ -223,6 +228,10 @@ async function getSDKSource(input, specialCaseUuidColumn, supplementClientOpts)
|
|
|
223
228
|
return this.runtime.$queryRaw(sql, values);
|
|
224
229
|
}
|
|
225
230
|
|
|
231
|
+
async $shutdown() {
|
|
232
|
+
return this.runtime.$shutdown();
|
|
233
|
+
}
|
|
234
|
+
|
|
226
235
|
${(await Promise.all(input.flatMap(async (x) => {
|
|
227
236
|
let findOnes = [];
|
|
228
237
|
const primaryColumn = await getPrimaryColumn(x.table);
|
|
@@ -834,6 +843,37 @@ async function getJSONSchemaOrderBy(table, name) {
|
|
|
834
843
|
oneOf: [_schema, { type: "array", items: _schema }],
|
|
835
844
|
};
|
|
836
845
|
}
|
|
846
|
+
function getTypeTypesIndex(data) {
|
|
847
|
+
function getExport(name) {
|
|
848
|
+
return `export type { ${name} } from "./${name}";`;
|
|
849
|
+
}
|
|
850
|
+
let set = new Set();
|
|
851
|
+
for (let d of data) {
|
|
852
|
+
for (let k of [
|
|
853
|
+
"typeFieldsName",
|
|
854
|
+
"typeReturnBaseName",
|
|
855
|
+
"typeWhereName",
|
|
856
|
+
"typeOrderByName",
|
|
857
|
+
"typeDataName",
|
|
858
|
+
]) {
|
|
859
|
+
const str = d[k];
|
|
860
|
+
if (str) {
|
|
861
|
+
set.add(str);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
let src = `export type { ${[
|
|
866
|
+
"Paginate",
|
|
867
|
+
"ListPaginated",
|
|
868
|
+
"TUpdateOperationsString",
|
|
869
|
+
"TUpdateOperationsNumber",
|
|
870
|
+
].join(",")} } from "./_shared";\n\n`;
|
|
871
|
+
let arr = Array.from(set).sort();
|
|
872
|
+
for (let x of arr) {
|
|
873
|
+
src += getExport(x);
|
|
874
|
+
}
|
|
875
|
+
return prettier.format(src, { parser: "typescript" });
|
|
876
|
+
}
|
|
837
877
|
function getTypeShared() {
|
|
838
878
|
const src = `export type Paginate = {
|
|
839
879
|
first: number;
|
|
@@ -4,6 +4,7 @@ export interface IRuntime {
|
|
|
4
4
|
$use: (middleware: TMiddleware) => void;
|
|
5
5
|
$whereNeedsProcessing(where: any): boolean;
|
|
6
6
|
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<any>;
|
|
7
|
+
$shutdown(): Promise<void>;
|
|
7
8
|
}
|
|
8
9
|
export declare type TResolveParams = {
|
|
9
10
|
resource: string;
|
|
@@ -14,5 +14,6 @@ export declare class RuntimeKSQL implements IRuntime {
|
|
|
14
14
|
$use(middleware: TMiddleware): Promise<void>;
|
|
15
15
|
$whereNeedsProcessing(where: any): boolean;
|
|
16
16
|
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
17
|
+
$shutdown(): Promise<void>;
|
|
17
18
|
}
|
|
18
19
|
export {};
|
|
@@ -57,6 +57,9 @@ class RuntimeKSQL {
|
|
|
57
57
|
async $prepareWhere(artifacts, table, data) {
|
|
58
58
|
return (0, shared_1._prepareWhere)(artifacts, table, data, __classPrivateFieldGet(this, _RuntimeKSQL_dbCall, "f").bind(this), __classPrivateFieldGet(this, _RuntimeKSQL_formatQuery, "f").bind(this));
|
|
59
59
|
}
|
|
60
|
+
async $shutdown() {
|
|
61
|
+
// Nothing to do here, I think
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
exports.RuntimeKSQL = RuntimeKSQL;
|
|
62
65
|
_RuntimeKSQL_ksql = new WeakMap(), _RuntimeKSQL_middlewareHandler = new WeakMap(), _RuntimeKSQL_dbCall = new WeakMap(), _RuntimeKSQL_formatQuery = new WeakMap(), _RuntimeKSQL_getBaseTableName = new WeakMap(), _RuntimeKSQL_getMaterializedViewName = new WeakMap(), _RuntimeKSQL_doNotUseMaterializedViews = new WeakMap();
|
|
@@ -12,6 +12,7 @@ export declare class RuntimeMSSQL implements IRuntime {
|
|
|
12
12
|
$use(middleware: TMiddleware): Promise<void>;
|
|
13
13
|
$whereNeedsProcessing(where: any): boolean;
|
|
14
14
|
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
15
|
+
$shutdown(): Promise<void>;
|
|
15
16
|
private dbCall;
|
|
16
17
|
private formatQuery;
|
|
17
18
|
private beginTransaction;
|
|
@@ -41,6 +41,9 @@ class RuntimeMSSQL {
|
|
|
41
41
|
async $prepareWhere(artifacts, table, data) {
|
|
42
42
|
return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
|
|
43
43
|
}
|
|
44
|
+
async $shutdown() {
|
|
45
|
+
await __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").closePool();
|
|
46
|
+
}
|
|
44
47
|
async dbCall(q) {
|
|
45
48
|
return __classPrivateFieldGet(this, _RuntimeMSSQL_mssqlClient, "f").dbCall(q);
|
|
46
49
|
}
|
|
@@ -11,6 +11,7 @@ export declare class RuntimeMySQL implements IRuntime {
|
|
|
11
11
|
$use(middleware: TMiddleware): Promise<void>;
|
|
12
12
|
$whereNeedsProcessing(where: any): boolean;
|
|
13
13
|
$prepareWhere(artifacts: IArtifacts, table: string, data: any): Promise<{}>;
|
|
14
|
+
$shutdown(): Promise<void>;
|
|
14
15
|
private dbCall;
|
|
15
16
|
private formatQuery;
|
|
16
17
|
private beginTransaction;
|
|
@@ -78,6 +78,9 @@ class RuntimeMySQL {
|
|
|
78
78
|
async $prepareWhere(artifacts, table, data) {
|
|
79
79
|
return (0, shared_1._prepareWhere)(artifacts, table, data, this.dbCall.bind(this), this.formatQuery.bind(this));
|
|
80
80
|
}
|
|
81
|
+
async $shutdown() {
|
|
82
|
+
await __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").endPool();
|
|
83
|
+
}
|
|
81
84
|
dbCall(q) {
|
|
82
85
|
return __classPrivateFieldGet(this, _RuntimeMySQL_mysqlClient, "f").query(q);
|
|
83
86
|
}
|
|
@@ -65,6 +65,9 @@ class MSSQL {
|
|
|
65
65
|
.catch(handleError),
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
async closePool() {
|
|
69
|
+
await __classPrivateFieldGet(this, _MSSQL_pool, "f").close();
|
|
70
|
+
}
|
|
68
71
|
}
|
|
69
72
|
exports.MSSQL = MSSQL;
|
|
70
73
|
_MSSQL_pool = new WeakMap(), _MSSQL_poolConnect = new WeakMap(), _MSSQL_typeCast = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@technicity/data-service-generator",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"compile": "rm -rf dist && tsc",
|
|
10
10
|
"create-database": "env-cmd node ./test/mysql/create-database.js && env-cmd node ./test/mysql8/create-database.js && env-cmd node ./test/mssql/create-database.js",
|
|
11
11
|
"generate": "npm run compile && npm run create-database && env-cmd node ./test/mysql/generate.js && env-cmd node ./test/mysql8/generate.js && env-cmd node ./test/mssql/generate.js",
|
|
12
|
-
"test": "npm run generate && env-cmd mocha ./test/addNullFallbacks.test.js && env-cmd mocha ./test/stringifyWhere.test.js &&
|
|
12
|
+
"test": "npm run generate && env-cmd mocha ./test/addNullFallbacks.test.js && env-cmd mocha ./test/stringifyWhere.test.js && npm run test:sdk",
|
|
13
|
+
"test:sdk": "env-cmd mocha ./test/test.js",
|
|
14
|
+
"test:only": "npm run create-database && npm run test:sdk"
|
|
13
15
|
},
|
|
14
16
|
"dependencies": {
|
|
15
17
|
"bluebird": "^3.7.2",
|