very-express 0.6.9-alpha → 0.6.11-alpha

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.
Files changed (29) hide show
  1. package/.github/copilot-instructions.md +0 -1
  2. package/dist/index.js +103 -93
  3. package/dist/templates/_middlewares/tsoaAuthentication.ts +3 -3
  4. package/dist/templates/_routes/oauth/OAuthRouteFactory.ts +1 -1
  5. package/dist/templates/_services/MongooseRepositoryAdapter.ts +2 -3
  6. package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +75 -14
  7. package/dist/templates/_services/VexDbConnector.ts +10 -13
  8. package/dist/templates/_services/VexSystem.ts +5 -5
  9. package/dist/templates/_services/auth/JWTService.ts +20 -21
  10. package/dist/templates/_services/oauth/OAuthProfileMap.ts +6 -6
  11. package/dist/templates/_services/oauth/OAuthStrategyService.ts +8 -8
  12. package/dist/templates/_types/{IVexRepository.ts → vex/VexRepository.ts} +10 -6
  13. package/dist/templates/_types/vex/VexRequest.ts +34 -0
  14. package/dist/templates/_types/{VexResponseError.ts → vex/VexResErr.ts} +9 -5
  15. package/dist/templates/_types/{VexResponse.ts → vex/VexResOk.ts} +9 -5
  16. package/dist/templates/_types/vex/VexResponse.ts +12 -0
  17. package/dist/templates/_types/vex/index.ts +6 -0
  18. package/dist/templates/_utils/common.ts +4 -4
  19. package/dist/templates/_utils/hash.ts +2 -2
  20. package/dist/templates/jsonSchema/User.json +0 -6
  21. package/dist/templates/root/public/js/login.js +2 -2
  22. package/dist/templates/root/public/js/mytokens.js +7 -7
  23. package/dist/templates/root/public/js/refreshtokens.js +20 -20
  24. package/dist/templates/root/scripts/oacg-fix.js +83 -0
  25. package/package.json +3 -4
  26. package/vex.config.json +1 -1
  27. package/dist/templates/_types/VexRequest.ts +0 -11
  28. package/dist/templates/_types/responseObject.ts +0 -7
  29. package/scripts/bump-version.js +0 -87
@@ -2,7 +2,7 @@
2
2
  document.addEventListener("DOMContentLoaded", function () {
3
3
  // add event listener to login button
4
4
  document.querySelector("#localLoginBtn").addEventListener("click", function () {
5
- // call api /auth/local
5
+ // call /api/auth/local
6
6
  fetch("/api/auth/local", {
7
7
  method: "POST",
8
8
  headers: {
@@ -35,7 +35,7 @@ document.addEventListener("DOMContentLoaded", function () {
35
35
  });
36
36
 
37
37
  document.querySelector("#localRegisterBtn").addEventListener("click", function () {
38
- // call api /auth/register
38
+ // call /api/auth/register
39
39
  fetch("/api/auth/register", {
40
40
  method: "POST",
41
41
  headers: {
@@ -1,11 +1,11 @@
1
1
  let jsonData = {};
2
2
 
3
3
  document.addEventListener("DOMContentLoaded", function () {
4
- jsonData = {
5
- accessToken: localStorage.getItem("accessToken"),
6
- accessTokenIndex: localStorage.getItem("accessTokenIndex"),
7
- refreshToken: localStorage.getItem("refreshToken"),
8
- refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
9
- };
10
- document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
4
+ jsonData = {
5
+ accessToken: localStorage.getItem("accessToken"),
6
+ accessTokenIndex: localStorage.getItem("accessTokenIndex"),
7
+ refreshToken: localStorage.getItem("refreshToken"),
8
+ refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
9
+ };
10
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
11
11
  });
@@ -1,23 +1,23 @@
1
1
  document.addEventListener("DOMContentLoaded", function () {
2
- jsonPayload = {
3
- refreshToken: localStorage.getItem("refreshToken"),
4
- refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
5
- };
2
+ jsonPayload = {
3
+ refreshToken: localStorage.getItem("refreshToken"),
4
+ refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
5
+ };
6
6
 
7
- fetch("/api/auth/refresh", {
8
- method: "POST",
9
- body: JSON.stringify(jsonPayload),
10
- headers: {
11
- "Content-Type": "application/json",
12
- "Accept": "application/json",
13
- "Authorization": "Bearer " + localStorage.getItem("accessToken"),
14
- "X-Auth-Index": localStorage.getItem("accessTokenIndex")
15
- }
16
- })
17
- .then(res => res.json())
18
- .then((response) => {
19
- localStorage.setItem("accessToken", response.accessToken);
20
- localStorage.setItem("accessTokenIndex", response.accessTokenIndex);
21
- document.querySelector("#tokenData").innerHTML = JSON.stringify(response, null, 2);
22
- });
7
+ fetch("/api/auth/refresh", {
8
+ method: "POST",
9
+ body: JSON.stringify(jsonPayload),
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ "Accept": "application/json",
13
+ "Authorization": "Bearer " + localStorage.getItem("accessToken"),
14
+ "X-Auth-Index": localStorage.getItem("accessTokenIndex")
15
+ }
16
+ })
17
+ .then(res => res.json())
18
+ .then((response) => {
19
+ localStorage.setItem("accessToken", response.accessToken);
20
+ localStorage.setItem("accessTokenIndex", response.accessTokenIndex);
21
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(response, null, 2);
22
+ });
23
23
  });
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Fix openapi-generated filter types to allow primitives, based on swagger schema info.
4
+
5
+ import { readdirSync, readFileSync, writeFileSync } from 'fs';
6
+ import { join, dirname } from 'path';
7
+ import { fileURLToPath } from 'url';
8
+
9
+ const __dir = dirname(fileURLToPath(import.meta.url));
10
+ const modelsDir = join(__dir, '../src/api-client/models');
11
+ const swaggerPath = join(__dir, '../../api/src/openapi/swagger.json');
12
+
13
+ const swagger = JSON.parse(readFileSync(swaggerPath, 'utf8'));
14
+ const schemas = swagger?.components?.schemas ?? {};
15
+
16
+ function primitiveTypeFromSwaggerProp(prop) {
17
+ if (!prop?.anyOf) return null;
18
+ const primitive = prop.anyOf.find(s => s.type && !s['$ref']);
19
+ if (!primitive) return null;
20
+ if (primitive.type === 'boolean') return 'boolean';
21
+ if (primitive.type === 'number' || primitive.type === 'integer') return 'number';
22
+ return 'string';
23
+ }
24
+
25
+ function primitiveTypeFromTsTypeName(tsType, swaggerEntityName, fieldKey) {
26
+ if (tsType === 'FieldFilterBoolean') return 'boolean';
27
+ if (tsType === 'FieldFilterNumber') return 'number';
28
+ if (tsType === 'FieldFilterString') return 'string';
29
+ if (/^FieldFilter[A-Z]/.test(tsType)) return 'string';
30
+ if (swaggerEntityName && fieldKey && schemas[swaggerEntityName]?.properties) {
31
+ const swaggerKey = fieldKey === 'id' ? '_id' : fieldKey;
32
+ const prop = schemas[swaggerEntityName].properties[swaggerKey];
33
+ if (prop) return primitiveTypeFromSwaggerProp(prop);
34
+ }
35
+ return null;
36
+ }
37
+
38
+ // Field-level: FieldFilterBoolean, FilterAreaActive, FilterAreaCountryCode, etc.
39
+ const FIELD_FILTER_RE = /^(FieldFilter[A-Z]|Filter[A-Z][a-z]+[A-Z])[a-zA-Z]*\.ts$/;
40
+ // Top-level aggregates: FilterArea, FilterClient, FilterJob, etc.
41
+ const TOP_FILTER_RE = /^Filter([A-Z][a-zA-Z]+)\.ts$/;
42
+
43
+ const NULL_CHECK = ' if (value == null) {\n return value;\n }';
44
+ const PRIMITIVE_GUARD = '\n // patch: pass primitives unchanged\n if (typeof value !== \'object\') return value;';
45
+
46
+ let stats = { fieldPatched: 0, topPatched: 0, skipped: 0 };
47
+
48
+ // Pass 1: patch field-level ToJSONTyped / FromJSONTyped
49
+ for (const file of readdirSync(modelsDir)) {
50
+ if (!FIELD_FILTER_RE.test(file)) continue;
51
+ const filePath = join(modelsDir, file);
52
+ let src = readFileSync(filePath, 'utf8');
53
+ if (src.includes('// patch:') || !src.includes(NULL_CHECK)) { stats.skipped++; continue; }
54
+ src = src.replaceAll(NULL_CHECK, NULL_CHECK + PRIMITIVE_GUARD);
55
+ writeFileSync(filePath, src, 'utf8');
56
+ console.log('[patch] field v ' + file);
57
+ stats.fieldPatched++;
58
+ }
59
+
60
+ // Pass 2: patch top-level filter interface property types
61
+ for (const file of readdirSync(modelsDir)) {
62
+ const match = TOP_FILTER_RE.exec(file);
63
+ if (!match) continue;
64
+ const filePath = join(modelsDir, file);
65
+ let src = readFileSync(filePath, 'utf8');
66
+ if (src.includes('// patch:')) { stats.skipped++; continue; }
67
+ const swaggerEntityName = file.replace('.ts', '');
68
+ // Match: ` fieldName?: SomeType;` — skip $or/$and lines
69
+ const PROP_RE = /^( {4}(?!\$or|\$and)(\w+)\?:\s*)([A-Za-z]+)(;)$/gm;
70
+ let modified = false;
71
+ const patched = src.replace(PROP_RE, (line, prefix, fieldKey, tsType, semi) => {
72
+ const primitive = primitiveTypeFromTsTypeName(tsType, swaggerEntityName, fieldKey);
73
+ if (!primitive || line.includes(' | ' + primitive)) return line;
74
+ modified = true;
75
+ return prefix + tsType + ' | ' + primitive + semi;
76
+ });
77
+ if (!modified) { stats.skipped++; continue; }
78
+ writeFileSync(filePath, patched, 'utf8');
79
+ console.log('[patch] top v ' + file);
80
+ stats.topPatched++;
81
+ }
82
+
83
+ console.log('\n[patch-filter-types] Done. Field: ' + stats.fieldPatched + ', Top: ' + stats.topPatched + ', Skipped: ' + stats.skipped);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.6.9-alpha",
3
+ "version": "0.6.11-alpha",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "Justin26l",
6
6
  "license": "MIT",
@@ -14,9 +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 lint",
18
- "postversion": "npm run compile",
19
- "v": "node scripts/bump-version.js"
17
+ "preversion": "npm run lint && npm run compile",
18
+ "postversion": "git tag v$(node -p \"require('./package.json').version\") && git push --tags && git push"
20
19
  },
21
20
  "keywords": [
22
21
  "jsonSchema",
package/vex.config.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "localAuth": true,
16
16
  "useHttpOnlyCookieToken": true,
17
17
  "oauthProviders": {
18
- "google": true,
18
+ "google": false,
19
19
  "github": false
20
20
  }
21
21
  },
@@ -1,11 +0,0 @@
1
- // {{headerComment}}
2
-
3
- export type Select = string[];
4
- export type Filter = Record<string, unknown>;
5
- export type Join = string[];
6
-
7
- export default interface VexRequest {
8
- select?: Select;
9
- filter?: Filter;
10
- join?: Join;
11
- };
@@ -1,7 +0,0 @@
1
- // {{headerComment}}
2
- export interface responseObject<T>{
3
- ret_code : number,
4
- ret_msg : string,
5
- ret_time?: number,
6
- result: T,
7
- }
@@ -1,87 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { execSync } from 'child_process';
5
-
6
- function bumpVersion(mode, devNum, major, minor, patch) {
7
- let newVersion;
8
- if (mode === 'dev') {
9
- if (devNum) {
10
- newVersion = `${major}.${minor}.${patch}-dev${parseInt(devNum) + 1}`;
11
- } else {
12
- newVersion = `${major}.${minor}.${patch}-dev1`;
13
- }
14
- } else if (mode === 'patch') {
15
- patch += 1;
16
- newVersion = `${major}.${minor}.${patch}`;
17
- } else if (mode === 'minor') {
18
- minor += 1;
19
- patch = 0;
20
- newVersion = `${major}.${minor}.${patch}`;
21
- } else if (mode === 'major') {
22
- major += 1;
23
- minor = 0;
24
- patch = 0;
25
- newVersion = `${major}.${minor}.${patch}`;
26
- } else {
27
- console.error('\x1b[31m', `Invalid version mode "${mode}", no version applied`);
28
- process.exit(0);
29
- };
30
- return newVersion;
31
- };
32
-
33
- function main() {
34
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
35
- const pkgPath = path.resolve(__dirname, '../package.json');
36
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
37
-
38
- const mode = process.env.npm_config_version_type || process.argv[2] || 'none';
39
-
40
- const versionMatch = pkg.version.match(/^(\d+)\.(\d+)\.(\d+)(-dev(\d+))?$/);
41
- if (!versionMatch) {
42
- console.error('\x1b[31m', `Invalid version "${pkg.version}", Version must be in the form x.y.z or x.y.z-devN, no version applied`);
43
- process.exit(0);
44
- };
45
-
46
- let [_, major, minor, patch, devFull, devNum] = versionMatch;
47
- major = parseInt(major);
48
- minor = parseInt(minor);
49
- patch = parseInt(patch);
50
-
51
- // Run preversion
52
- if (pkg.scripts && pkg.scripts.preversion) {
53
- try {
54
- execSync(pkg.scripts.preversion, { stdio: 'inherit' });
55
- } catch (e) {
56
- console.warn('preversion script failed:', e.message);
57
- process.exit(1);
58
- }
59
- };
60
-
61
- // Bump version
62
- const newVersion = bumpVersion(mode, devNum, major, minor, patch);
63
- pkg.version = newVersion;
64
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + '\n');
65
- console.log(`Bumped version (${mode}) to`, newVersion);
66
-
67
- // Run postversion
68
- if (pkg.scripts && pkg.scripts.postversion) {
69
- try {
70
- execSync(pkg.scripts.postversion, { stdio: 'inherit' });
71
- } catch (e) {
72
- console.warn('postversion script failed:', e.message);
73
- process.exit(1);
74
- }
75
- };
76
-
77
- // Add git tag for versioning
78
- try {
79
- execSync(`git commit -am "v${newVersion}"`);
80
- execSync(`git tag v${newVersion}`);
81
- console.log(`Created git tag v${newVersion}`);
82
- } catch (e) {
83
- console.warn('Failed to create git tag:', e.message);
84
- }
85
- };
86
-
87
- main();