@adaptivestone/framework 5.0.0-beta.16 → 5.0.0-beta.17

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 5.0.0-beta.17
2
+
3
+ [NEW] add GenerateTypes command
4
+
1
5
  ### 5.0.0-beta.16
2
6
 
3
7
  [UPDATE] update deps
@@ -1,7 +1,12 @@
1
- import AbstractCommand from '../modules/AbstractCommand.ts';
1
+ import AbstractCommand from '@adaptivestone/framework/modules/AbstractCommand.js';
2
2
  declare class GenerateTypes extends AbstractCommand {
3
3
  static get description(): string;
4
+ getTypesContent(): Promise<string>;
4
5
  static isShouldInitModels: boolean;
5
6
  run(): Promise<boolean>;
7
+ static getTemplate(configs: Map<string, any>, modelPaths: {
8
+ file: string;
9
+ path: string;
10
+ }[]): string;
6
11
  }
7
12
  export default GenerateTypes;
@@ -1,13 +1,46 @@
1
- import AbstractCommand from "../modules/AbstractCommand.js";
1
+ import AbstractCommand from '@adaptivestone/framework/modules/AbstractCommand.js';
2
+ import * as url from 'url';
3
+ import fs from 'node:fs/promises';
2
4
  class GenerateTypes extends AbstractCommand {
3
5
  static get description() {
4
6
  return 'Gererates TypeScript types';
5
7
  }
8
+ async getTypesContent() {
9
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
10
+ const content = await fs.readFile(`${__dirname}/../../../src/types/types.ts`, 'utf8');
11
+ return content;
12
+ }
6
13
  static isShouldInitModels = false;
7
14
  async run() {
8
- console.log(this.app.internalFilesCache);
15
+ const template = GenerateTypes.getTemplate(this.app.internalFilesCache.configs, this.app.internalFilesCache.modelPaths);
16
+ await fs.writeFile(`${process.cwd()}/genTypes.d.ts`, template);
17
+ console.log('TypeScript types generated successfully at genTypes.d.ts');
9
18
  return Promise.resolve(true);
10
19
  }
20
+ static getTemplate(configs, modelPaths) {
21
+ const dir = process.cwd();
22
+ const configTypes = Array.from(configs)
23
+ .map((config) => {
24
+ return ` getConfig(configName: '${config[0]}'): ${JSON.stringify(config[1], null, 6)};`;
25
+ })
26
+ .join('\n');
27
+ const modelTypes = modelPaths
28
+ .map((modelPath) => {
29
+ const path = modelPath.path.replace(dir, '.');
30
+ return ` getModel(modelName: '${modelPath.file}'): import('${path}').default['mongooseModel']`;
31
+ })
32
+ .join('\n');
33
+ return `
34
+ import type {} from '@adaptivestone/framework/server.js';
35
+
36
+ declare module '@adaptivestone/framework/server.js' {
37
+ export interface IApp {
38
+ ${configTypes}
39
+ ${modelTypes}
40
+ }
41
+ }
42
+ `;
43
+ }
11
44
  }
12
45
  export default GenerateTypes;
13
46
  //# sourceMappingURL=GenerateTypes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateTypes.js","sourceRoot":"","sources":["../../src/commands/GenerateTypes.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,+BAA+B,CAAC;AAE5D,MAAM,aAAc,SAAQ,eAAe;IACzC,MAAM,KAAK,WAAW;QACpB,OAAO,4BAA4B,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,kBAAkB,GAAG,KAAK,CAAC;IAElC,KAAK,CAAC,GAAG;QACP,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACzC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;;AAGH,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"GenerateTypes.js","sourceRoot":"","sources":["../../src/commands/GenerateTypes.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,qDAAqD,CAAC;AAClF,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAElC,MAAM,aAAc,SAAQ,eAAe;IACzC,MAAM,KAAK,WAAW;QACpB,OAAO,4BAA4B,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,S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AAE,GAAG,CAAC,CAAC;YAC9C,OAAO,4BAA4B,SAAS,CAAC,IAAI,eAAe,IAAI,6BAA6B,CAAC;QACpG,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO;;;;;QAKH,WAAW;QACX,UAAU;;;CAGjB,CAAC;IACA,CAAC;;AAGH,eAAe,aAAa,CAAC"}
package/genTypes.d.ts ADDED
@@ -0,0 +1,100 @@
1
+
2
+ import type {} from '@adaptivestone/framework/server.js';
3
+
4
+ declare module '@adaptivestone/framework/server.js' {
5
+ export interface IApp {
6
+ getConfig(configName: 'auth'): {
7
+ "hashRounds": 64,
8
+ "isAuthWithVefificationFlow": true
9
+ };
10
+ getConfig(configName: 'http'): {
11
+ "port": "3300",
12
+ "hostname": "0.0.0.0",
13
+ "corsDomains": [
14
+ "http://localhost:3000"
15
+ ],
16
+ "myDomain": "http://localhost:3300",
17
+ "siteDomain": "http://localhost:3000"
18
+ };
19
+ getConfig(configName: 'i18n'): {
20
+ "enabled": true,
21
+ "preload": [
22
+ "en",
23
+ "ru"
24
+ ],
25
+ "supportedLngs": [
26
+ "en",
27
+ "ru"
28
+ ],
29
+ "fallbackLng": "en",
30
+ "saveMissing": false,
31
+ "debug": false,
32
+ "lookupQuerystring": "lng"
33
+ };
34
+ getConfig(configName: 'ipDetector'): {
35
+ "headers": [
36
+ "X-Forwarded-For"
37
+ ],
38
+ "trustedProxy": [
39
+ "169.254.0.0/16",
40
+ "fe80::/10",
41
+ "127.0.0.1/8",
42
+ "::1/128",
43
+ "10.0.0.0/8",
44
+ "172.16.0.0/12",
45
+ "192.168.0.0/16",
46
+ "fc00::/7"
47
+ ]
48
+ };
49
+ getConfig(configName: 'log'): {
50
+ "transports": [
51
+ {
52
+ "transport": "winston-transport-sentry-node",
53
+ "transportOptions": {
54
+ "sentry": {
55
+ "dsn": ""
56
+ },
57
+ "level": "info"
58
+ },
59
+ "enable": false
60
+ },
61
+ {
62
+ "transport": "console",
63
+ "transportOptions": {
64
+ "level": "silly",
65
+ "timestamp": true
66
+ },
67
+ "enable": true
68
+ }
69
+ ]
70
+ };
71
+ getConfig(configName: 'mongo'): {
72
+ "connectionString": "mongodb://localhost/andrey_framework_dev"
73
+ };
74
+ getConfig(configName: 'rateLimiter'): {
75
+ "limiterOptions": {
76
+ "points": 10,
77
+ "duration": 60
78
+ },
79
+ "driver": "memory",
80
+ "consumePoints": 1,
81
+ "consumeKeyComponents": {
82
+ "ip": true,
83
+ "route": true,
84
+ "user": true,
85
+ "request": []
86
+ }
87
+ };
88
+ getConfig(configName: 'redis'): {
89
+ "url": "redis://localhost",
90
+ "namespace": "main"
91
+ };
92
+ getConfig(configName: 'validate'): {
93
+ "controllerValidationAbortEarly": true
94
+ };
95
+ getModel(modelName: 'Lock'): import('./src/models/Lock.ts').default['mongooseModel']
96
+ getModel(modelName: 'Migration'): import('./src/models/Migration.ts').default['mongooseModel']
97
+ getModel(modelName: 'Sequence'): import('./src/models/Sequence.ts').default['mongooseModel']
98
+ getModel(modelName: 'User'): import('./src/models/User.ts').default['mongooseModel']
99
+ }
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-beta.16",
3
+ "version": "5.0.0-beta.17",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "type": "module",
6
6
  "engines": {