very-express 0.7.5 → 0.7.6
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.
|
@@ -23,28 +23,32 @@ export class TypeOrmRepositoryAdapter<T extends ObjectLiteral> implements VexRep
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** Merge caller filter with ownership filter. Ownership always wins. */
|
|
26
|
-
private mergeFilter(callerFilter: Filter<T>): Record<string, unknown> {
|
|
27
|
-
const mapped = this.mapOperators(callerFilter)
|
|
26
|
+
private mergeFilter(callerFilter: Filter<T>): Record<string, unknown> | Array<Record<string, unknown>> {
|
|
27
|
+
const mapped = this.mapOperators(callerFilter);
|
|
28
28
|
const ownership = this.getOwnershipFilter();
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
if (mapped instanceof Array) {
|
|
31
|
+
return mapped.map(branch => ({ ...branch, ...ownership }));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return { ...mapped, ...ownership };
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
private mapOperators(filter: Filter<T>): Record<string, unknown> {
|
|
38
|
+
private mapOperators(filter: Filter<T>): Record<string, unknown> | Array<Record<string, unknown>> {
|
|
33
39
|
if (!filter || typeof filter !== "object") return {};
|
|
34
40
|
// if (Array.isArray(filter)) return filter.map(f => this.mapOperators(f));
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
let out: Record<string, unknown> | Array<Record<string, unknown>> = {};
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
else if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
44
|
+
if( filter["$or"] && Array.isArray(filter["$or"])) {
|
|
45
|
+
out = [];
|
|
46
|
+
out.push(...filter["$or"].map(v => this.mapOperators(v) as Record<string, unknown>));
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const [key, val] of Object.entries(filter)) {
|
|
51
|
+
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
48
52
|
// Common mongo-like operators supported in JSON payloads
|
|
49
53
|
const oval = val as FieldOperators;
|
|
50
54
|
|
|
@@ -3,7 +3,7 @@ import { Request, Response, NextFunction } from "express";
|
|
|
3
3
|
import { DataSource, EntityTarget, ObjectLiteral } from "typeorm";
|
|
4
4
|
import mongoose from "mongoose";
|
|
5
5
|
// import { Document } from "mongoose";
|
|
6
|
-
import { sqlMigrations } from "../_models/sqlMigration.gen";
|
|
6
|
+
// import { sqlMigrations } from "../_models/sqlMigration.gen";
|
|
7
7
|
import { VexRepository } from "../_types/vex";
|
|
8
8
|
import { TypeOrmRepositoryAdapter } from "./TypeOrmRepositoryAdapter.gen";
|
|
9
9
|
// import { MongooseRepositoryAdapter } from "./MongooseRepositoryAdapter.gen";
|
|
@@ -70,7 +70,7 @@ export class VexDbConnector {
|
|
|
70
70
|
.then(() => {
|
|
71
71
|
this.dataSource = ds;
|
|
72
72
|
utils.log.infoSql("TypeORM DataSource initialized");
|
|
73
|
-
this.runSqlMigrations(ds);
|
|
73
|
+
// this.runSqlMigrations(ds);
|
|
74
74
|
})
|
|
75
75
|
.catch((err) => {
|
|
76
76
|
utils.log.errorSql(`Failed to initialize TypeORM, retrying in ${retryTime}s`, err);
|
|
@@ -81,22 +81,22 @@ export class VexDbConnector {
|
|
|
81
81
|
connectWithRetry(10);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
private async runSqlMigrations(ds: DataSource): Promise<void> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
84
|
+
// private async runSqlMigrations(ds: DataSource): Promise<void> {
|
|
85
|
+
// if (!sqlMigrations.length) return;
|
|
86
|
+
// const runner = ds.createQueryRunner();
|
|
87
|
+
// await runner.connect();
|
|
88
|
+
// try {
|
|
89
|
+
// for (const sql of sqlMigrations) {
|
|
90
|
+
// utils.log.infoSql(`Applying migration: ${sql}`);
|
|
91
|
+
// await runner.query(sql);
|
|
92
|
+
// }
|
|
93
|
+
// utils.log.infoSql(`${sqlMigrations.length} migrations applied`);
|
|
94
|
+
// } catch (err) {
|
|
95
|
+
// utils.log.errorSql("SQL migration failed", err);
|
|
96
|
+
// } finally {
|
|
97
|
+
// await runner.release();
|
|
98
|
+
// }
|
|
99
|
+
// }
|
|
100
100
|
|
|
101
101
|
closeSql(): void {
|
|
102
102
|
if (this.dataSource?.isInitialized) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "very-express",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
|
|
5
5
|
"author": "Justin26l",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"build": "npm run lint && npm run compile",
|
|
15
15
|
"lint": "eslint ./src --ext .ts --fix",
|
|
16
16
|
"compile": "node ./scripts/build.js && node ./scripts/copyTsTemplates.js",
|
|
17
|
-
"preversion": "npm run
|
|
18
|
-
"postversion": "
|
|
17
|
+
"preversion": "npm run build",
|
|
18
|
+
"postversion": "git add . && git commit -m 'lint' && git push && git push --tags"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"jsonSchema",
|