@nu-art/thunderstorm-backend 0.400.5

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 (111) hide show
  1. package/_entity/app-config/ModuleBE_AppConfigAPI.d.ts +9 -0
  2. package/_entity/app-config/ModuleBE_AppConfigAPI.js +20 -0
  3. package/_entity/app-config/ModuleBE_AppConfigDB.d.ts +27 -0
  4. package/_entity/app-config/ModuleBE_AppConfigDB.js +91 -0
  5. package/_entity/app-config/index.d.ts +2 -0
  6. package/_entity/app-config/index.js +2 -0
  7. package/_entity/app-config/module-pack.d.ts +2 -0
  8. package/_entity/app-config/module-pack.js +3 -0
  9. package/_entity/backup-doc/ModuleBE_BackupDocDB.d.ts +52 -0
  10. package/_entity/backup-doc/ModuleBE_BackupDocDB.js +350 -0
  11. package/_entity/backup-doc/ModuleBE_BackupScheduler.d.ts +7 -0
  12. package/_entity/backup-doc/ModuleBE_BackupScheduler.js +14 -0
  13. package/_entity/backup-doc/index.d.ts +3 -0
  14. package/_entity/backup-doc/index.js +3 -0
  15. package/_entity/backup-doc/module-pack.d.ts +2 -0
  16. package/_entity/backup-doc/module-pack.js +3 -0
  17. package/_entity/editable-test/ModuleBE_EditableTestDB.d.ts +8 -0
  18. package/_entity/editable-test/ModuleBE_EditableTestDB.js +8 -0
  19. package/_entity/editable-test/index.d.ts +1 -0
  20. package/_entity/editable-test/index.js +1 -0
  21. package/_entity/editable-test/module-pack.d.ts +1 -0
  22. package/_entity/editable-test/module-pack.js +3 -0
  23. package/_entity.d.ts +3 -0
  24. package/_entity.js +3 -0
  25. package/core/BaseStorm.d.ts +17 -0
  26. package/core/BaseStorm.js +77 -0
  27. package/core/Storm.d.ts +15 -0
  28. package/core/Storm.js +93 -0
  29. package/core/db-def.d.ts +10 -0
  30. package/core/db-def.js +11 -0
  31. package/core/default-storm.d.ts +3 -0
  32. package/core/default-storm.js +30 -0
  33. package/core/storm-modulepack.d.ts +3 -0
  34. package/core/storm-modulepack.js +20 -0
  35. package/core/typed-api.d.ts +7 -0
  36. package/core/typed-api.js +46 -0
  37. package/exceptions.d.ts +1 -0
  38. package/exceptions.js +21 -0
  39. package/index.d.ts +27 -0
  40. package/index.js +48 -0
  41. package/modules/CleanupScheduler.d.ts +14 -0
  42. package/modules/CleanupScheduler.js +50 -0
  43. package/modules/ModuleBE_APIs.d.ts +11 -0
  44. package/modules/ModuleBE_APIs.js +19 -0
  45. package/modules/ModuleBE_CSVParser.d.ts +9 -0
  46. package/modules/ModuleBE_CSVParser.js +50 -0
  47. package/modules/ModuleBE_ForceUpgrade.d.ts +21 -0
  48. package/modules/ModuleBE_ForceUpgrade.js +70 -0
  49. package/modules/ModuleBE_ServerInfo.d.ts +20 -0
  50. package/modules/ModuleBE_ServerInfo.js +76 -0
  51. package/modules/_imports.d.ts +6 -0
  52. package/modules/_imports.js +26 -0
  53. package/modules/_tdb/service-accounts.d.ts +19 -0
  54. package/modules/_tdb/service-accounts.js +2 -0
  55. package/modules/action-processor/Action_SetupProject.d.ts +9 -0
  56. package/modules/action-processor/Action_SetupProject.js +23 -0
  57. package/modules/action-processor/ModuleBE_ActionProcessor.d.ts +11 -0
  58. package/modules/action-processor/ModuleBE_ActionProcessor.js +67 -0
  59. package/modules/action-processor/types.d.ts +10 -0
  60. package/modules/action-processor/types.js +1 -0
  61. package/modules/archiving/ModuleBE_Archiving.d.ts +119 -0
  62. package/modules/archiving/ModuleBE_Archiving.js +236 -0
  63. package/modules/collection-actions/ModuleBE_CollectionActions.d.ts +12 -0
  64. package/modules/collection-actions/ModuleBE_CollectionActions.js +69 -0
  65. package/modules/collection-actions/dispatcher.d.ts +7 -0
  66. package/modules/collection-actions/dispatcher.js +2 -0
  67. package/modules/db-api-gen/ModuleBE_BaseApi.d.ts +16 -0
  68. package/modules/db-api-gen/ModuleBE_BaseApi.js +74 -0
  69. package/modules/db-api-gen/ModuleBE_BaseDB.d.ts +78 -0
  70. package/modules/db-api-gen/ModuleBE_BaseDB.js +298 -0
  71. package/modules/http/AxiosHttpModule.d.ts +25 -0
  72. package/modules/http/AxiosHttpModule.js +132 -0
  73. package/modules/http/types.d.ts +6 -0
  74. package/modules/http/types.js +1 -0
  75. package/modules/proxy/ModuleBE_RemoteProxy.d.ts +35 -0
  76. package/modules/proxy/ModuleBE_RemoteProxy.js +86 -0
  77. package/modules/proxy/RemoteProxyCaller.d.ts +19 -0
  78. package/modules/proxy/RemoteProxyCaller.js +82 -0
  79. package/modules/proxy/assert-secret-middleware.d.ts +2 -0
  80. package/modules/proxy/assert-secret-middleware.js +24 -0
  81. package/modules/server/HeaderKey.d.ts +8 -0
  82. package/modules/server/HeaderKey.js +41 -0
  83. package/modules/server/HttpServer.d.ts +41 -0
  84. package/modules/server/HttpServer.js +223 -0
  85. package/modules/server/consts.d.ts +13 -0
  86. package/modules/server/consts.js +9 -0
  87. package/modules/server/route-resolvers/RouteResolver_Dummy.d.ts +7 -0
  88. package/modules/server/route-resolvers/RouteResolver_Dummy.js +34 -0
  89. package/modules/server/route-resolvers/RouteResolver_ModulePath.d.ts +22 -0
  90. package/modules/server/route-resolvers/RouteResolver_ModulePath.js +84 -0
  91. package/modules/server/route-resolvers/index.d.ts +7 -0
  92. package/modules/server/route-resolvers/index.js +21 -0
  93. package/modules/server/server-api.d.ts +85 -0
  94. package/modules/server/server-api.js +362 -0
  95. package/modules/server/server-errors.d.ts +4 -0
  96. package/modules/server/server-errors.js +79 -0
  97. package/modules/sync-env/ModuleBE_SyncEnv.d.ts +36 -0
  98. package/modules/sync-env/ModuleBE_SyncEnv.js +212 -0
  99. package/modules/sync-manager/ModuleBE_SyncManager.d.ts +63 -0
  100. package/modules/sync-manager/ModuleBE_SyncManager.js +254 -0
  101. package/package.json +104 -0
  102. package/shared.d.ts +1 -0
  103. package/shared.js +21 -0
  104. package/test/StormTest.d.ts +23 -0
  105. package/test/StormTest.js +49 -0
  106. package/utils/file.d.ts +2 -0
  107. package/utils/file.js +29 -0
  108. package/utils/promisify-request.d.ts +3 -0
  109. package/utils/promisify-request.js +33 -0
  110. package/utils/types.d.ts +11 -0
  111. package/utils/types.js +21 -0
@@ -0,0 +1,17 @@
1
+ import { Module, ModuleManager, TS_Object } from '@nu-art/ts-common';
2
+ export type StormConfig = {
3
+ envKey: string;
4
+ pathToDefaultConfig: string;
5
+ pathToEnvOverrideConfig: string;
6
+ };
7
+ export declare abstract class BaseStorm extends ModuleManager {
8
+ protected innerConfig: StormConfig;
9
+ private override;
10
+ readonly isDebug = false;
11
+ constructor(config: StormConfig | string);
12
+ getEnvironment(): string;
13
+ setOverride(override: TS_Object): void;
14
+ protected resolveConfig: () => Promise<void>;
15
+ getEnvConfigRef<Config>(module: Module<Config>): import("@nu-art/firebase-backend").FirebaseRef<Config>;
16
+ getGlobalEnvConfigRef(): import("@nu-art/firebase-backend").FirebaseRef<TS_Object>;
17
+ }
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ import { merge, ModuleManager } from '@nu-art/ts-common';
22
+ import { ModuleBE_Firebase } from '@nu-art/firebase-backend';
23
+ export class BaseStorm extends ModuleManager {
24
+ innerConfig;
25
+ override = {};
26
+ isDebug = false;
27
+ constructor(config) {
28
+ super();
29
+ if (typeof config === 'string')
30
+ this.innerConfig = {
31
+ envKey: config,
32
+ pathToDefaultConfig: `_config/default.json`,
33
+ pathToEnvOverrideConfig: `_config/${config}.json`,
34
+ };
35
+ else
36
+ this.innerConfig = config;
37
+ }
38
+ getEnvironment() {
39
+ return this.innerConfig.envKey;
40
+ }
41
+ setOverride(override) {
42
+ this.override = override;
43
+ }
44
+ resolveConfig = async () => {
45
+ const database = ModuleBE_Firebase.createAdminSession().getDatabase();
46
+ this.logInfo(`LOADING RTDB FROM: ${database.getUrl()}`);
47
+ let initialized = 0;
48
+ const listener = (resolve) => (snapshot) => {
49
+ if (initialized >= 2) {
50
+ this.logWarning('CONFIGURATION HAS CHANGED... KILLING PROCESS!!!');
51
+ process.exit(2);
52
+ }
53
+ resolve(snapshot || {});
54
+ initialized++;
55
+ };
56
+ const defaultPromise = new Promise((resolve) => {
57
+ this.logInfo(`Loading default config from: ${database.getUrl()}${this.innerConfig.pathToDefaultConfig}`);
58
+ database.listen(`/${this.innerConfig.pathToDefaultConfig}`, listener(resolve));
59
+ });
60
+ const envPromise = new Promise((resolve) => {
61
+ this.logInfo(`Loading env override config from: ${database.getUrl()}${this.innerConfig.pathToEnvOverrideConfig}`);
62
+ database.listen(`/${this.innerConfig.pathToEnvOverrideConfig}`, listener(resolve));
63
+ });
64
+ const [defaultConfig, overrideConfig] = await Promise.all([
65
+ defaultPromise,
66
+ envPromise
67
+ ]);
68
+ const merge1 = merge(defaultConfig, overrideConfig);
69
+ this.setConfig(merge(merge1, this.override) || {});
70
+ };
71
+ getEnvConfigRef(module) {
72
+ return ModuleBE_Firebase.createAdminSession().getDatabase().ref(`/${this.innerConfig.pathToEnvOverrideConfig}/${module.getName()}`);
73
+ }
74
+ getGlobalEnvConfigRef() {
75
+ return ModuleBE_Firebase.createAdminSession().getDatabase().ref(`/${this.innerConfig.pathToEnvOverrideConfig}`);
76
+ }
77
+ }
@@ -0,0 +1,15 @@
1
+ import { StormConfig, BaseStorm } from './BaseStorm.js';
2
+ import { HttpRoute, RouteResolver } from '../modules/server/route-resolvers/index.js';
3
+ export declare class Storm extends BaseStorm {
4
+ private routeResolver;
5
+ private functions;
6
+ constructor(config: StormConfig | string);
7
+ init(): this;
8
+ setInitialRouteResolver(routeResolver: RouteResolver): this;
9
+ startServer(onStarted?: () => Promise<void>): any;
10
+ getRoutes(): HttpRoute[];
11
+ build(onStarted?: () => Promise<void>): any;
12
+ private startServerImpl;
13
+ static getInstance(): Storm;
14
+ getConfig(): any;
15
+ }
package/core/Storm.js ADDED
@@ -0,0 +1,93 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ import { BeLogged, LogClient_Function, LogClient_Terminal, LogLevel } from '@nu-art/ts-common';
22
+ import { Firebase_ExpressFunction } from '@nu-art/firebase-backend';
23
+ import { BaseStorm } from './BaseStorm.js';
24
+ import { HttpServer } from '../modules/server/HttpServer.js';
25
+ import { ModuleBE_BaseFunction, ModuleBE_Firebase } from '@nu-art/firebase-backend';
26
+ import { ServerApi } from '../modules/server/server-api.js';
27
+ const modules = [
28
+ HttpServer,
29
+ ModuleBE_Firebase,
30
+ ];
31
+ export class Storm extends BaseStorm {
32
+ routeResolver;
33
+ functions = [];
34
+ constructor(config) {
35
+ super(config);
36
+ BeLogged.addClient(process.env.GCLOUD_PROJECT && process.env.FUNCTIONS_EMULATOR ? LogClient_Terminal : LogClient_Function);
37
+ this.addModulePack(modules);
38
+ this.setMinLevel(LogLevel.Info);
39
+ }
40
+ init() {
41
+ ServerApi.isDebug = this.config.isDebug === true;
42
+ super.init();
43
+ this.routeResolver.resolveApi();
44
+ if (this.config.printRoutes === true)
45
+ this.routeResolver.printRoutes();
46
+ return this;
47
+ }
48
+ setInitialRouteResolver(routeResolver) {
49
+ this.routeResolver = routeResolver;
50
+ return this;
51
+ }
52
+ startServer(onStarted) {
53
+ const modulesAsFunction = this.modules.filter((module) => {
54
+ const b = module instanceof ModuleBE_BaseFunction;
55
+ // console.log(`${module.getName()} function ${b}`)
56
+ return b;
57
+ });
58
+ this.functions = [new Firebase_ExpressFunction(HttpServer.getExpress()), ...modulesAsFunction];
59
+ this.startServerImpl(onStarted)
60
+ .then(() => this.logInfo('Server Started!!'))
61
+ .catch(reason => {
62
+ this.logError('failed to launch server', reason);
63
+ throw reason;
64
+ });
65
+ return this.functions.reduce((toRet, _function) => {
66
+ toRet[_function.getName()] = _function.getFunction();
67
+ return toRet;
68
+ }, {});
69
+ }
70
+ getRoutes() {
71
+ return this.routeResolver.resolveRoutes();
72
+ }
73
+ build(onStarted) {
74
+ return this.startServer(onStarted);
75
+ }
76
+ async startServerImpl(onStarted) {
77
+ const label = 'Resolving Config';
78
+ console.time(label);
79
+ await this.resolveConfig();
80
+ console.timeEnd(label);
81
+ this.init();
82
+ await HttpServer.startServer();
83
+ const functions = await Promise.all(this.functions.map(moduleAsFunction => moduleAsFunction.onFunctionReady()));
84
+ await onStarted?.();
85
+ return functions;
86
+ }
87
+ static getInstance() {
88
+ return Storm.instance;
89
+ }
90
+ getConfig() {
91
+ return this.config;
92
+ }
93
+ }
@@ -0,0 +1,10 @@
1
+ import { DBDef_V3, DBProto } from '@nu-art/ts-common';
2
+ export type DBApiBEConfig<Proto extends DBProto<any>> = {
3
+ uniqueKeys: Proto['uniqueKeys'];
4
+ itemName: string;
5
+ versions: Proto['versions'];
6
+ TTL: number;
7
+ lastUpdatedTTL: number;
8
+ lockKeys?: Proto['lockKeys'];
9
+ };
10
+ export declare const getModuleBEConfig: <Proto extends DBProto<any, any, any>>(dbDef: DBDef_V3<Proto>) => DBApiBEConfig<Proto>;
package/core/db-def.js ADDED
@@ -0,0 +1,11 @@
1
+ import { Const_UniqueKeys, Day, Hour } from '@nu-art/ts-common';
2
+ export const getModuleBEConfig = (dbDef) => {
3
+ return {
4
+ versions: dbDef.versions,
5
+ lockKeys: dbDef.lockKeys,
6
+ uniqueKeys: dbDef.uniqueKeys || Const_UniqueKeys,
7
+ itemName: dbDef.entityName,
8
+ TTL: dbDef.TTL || Hour * 2,
9
+ lastUpdatedTTL: dbDef.lastUpdatedTTL || Day,
10
+ };
11
+ };
@@ -0,0 +1,3 @@
1
+ import { Storm } from './Storm.js';
2
+ import { StormConfig } from './BaseStorm.js';
3
+ export declare function createStorm(config: StormConfig | string): Storm;
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ import { ModuleBE_Firebase } from '@nu-art/firebase-backend';
22
+ import { HttpServer } from '../modules/server/HttpServer.js';
23
+ import { Storm } from './Storm.js';
24
+ const modules = [
25
+ HttpServer,
26
+ ModuleBE_Firebase,
27
+ ];
28
+ export function createStorm(config) {
29
+ return new Storm(config).addModulePack(modules);
30
+ }
@@ -0,0 +1,3 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ export declare const ModulePack_ThunderstormBE: Module[];
3
+ export declare const ModulePackBE_Thunderstorm: Module<any, any, import("@nu-art/ts-common").Validator<any> | import("@nu-art/ts-common").TypeValidator<any>>[];
@@ -0,0 +1,20 @@
1
+ import { ModuleBE_SyncManager } from '../modules/sync-manager/ModuleBE_SyncManager.js';
2
+ import { ModuleBE_APIs } from '../modules/ModuleBE_APIs.js';
3
+ import { ModuleBE_SyncEnv } from '../modules/sync-env/ModuleBE_SyncEnv.js';
4
+ import { ModuleBE_ActionProcessor } from '../modules/action-processor/ModuleBE_ActionProcessor.js';
5
+ import { ModuleBE_ServerInfo } from '../modules/ModuleBE_ServerInfo.js';
6
+ import { ModulePackBE_AppConfigDB } from '../_entity/app-config/index.js';
7
+ import { ModulePackBE_BackupDocDB } from '../_entity/backup-doc/index.js';
8
+ import { ModuleBE_CollectionActions } from '../modules/collection-actions/ModuleBE_CollectionActions.js';
9
+ export const ModulePack_ThunderstormBE = [
10
+ ModuleBE_ServerInfo,
11
+ ModuleBE_SyncManager,
12
+ ModuleBE_APIs,
13
+ ModuleBE_SyncEnv,
14
+ ModuleBE_ActionProcessor,
15
+ ModuleBE_CollectionActions,
16
+ // ...ModulePackBE_EditableTest,
17
+ ...ModulePackBE_AppConfigDB,
18
+ ...ModulePackBE_BackupDocDB,
19
+ ];
20
+ export const ModulePackBE_Thunderstorm = ModulePack_ThunderstormBE;
@@ -0,0 +1,7 @@
1
+ import { _ServerBodyApi, _ServerQueryApi } from '../modules/server/server-api.js';
2
+ import { ApiDef, BaseHttpRequest, BodyApi, HttpMethod_Body, HttpMethod_Query, QueryApi } from '@nu-art/thunderstorm-shared';
3
+ import { ServerApi_Middleware } from '../utils/types.js';
4
+ export declare function createQueryServerApi<API extends QueryApi<any, any, any, any, HttpMethod_Query>>(apiDef: ApiDef<API>, action: (params: API['P']) => Promise<API['R']>, ...middleware: ServerApi_Middleware[]): _ServerQueryApi<API>;
5
+ export declare function createBodyServerApi<API extends BodyApi<any, any, any, any, HttpMethod_Body>>(apiDef: ApiDef<API>, action: (body: API['B']) => Promise<API['R']>, ...middleware: ServerApi_Middleware[]): _ServerBodyApi<API>;
6
+ export declare function apiWithQueryAxios<API extends QueryApi<any, any>>(apiDef: ApiDef<API>, onCompleted?: (response: API['R'], params: API['P'], request: BaseHttpRequest<API>) => Promise<any>, onError?: (errorResponse: any, input: API['P'] | API['B'], request: BaseHttpRequest<API>) => Promise<any>): (params: API["P"]) => BaseHttpRequest<API>;
7
+ export declare function apiWithBodyAxios<API extends BodyApi<any, any, any, any, HttpMethod_Body>>(apiDef: ApiDef<API>, onCompleted?: (response: API['R'], body: API['B'], request: BaseHttpRequest<API>) => Promise<any>, onError?: (errorResponse: any, input: API['P'] | API['B'], request: BaseHttpRequest<API>) => Promise<any>): (body: API["B"]) => BaseHttpRequest<API>;
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ import { AxiosHttpModule } from '../modules/http/AxiosHttpModule.js';
22
+ import { _ServerBodyApi, _ServerQueryApi } from '../modules/server/server-api.js';
23
+ export function createQueryServerApi(apiDef, action, ...middleware) {
24
+ return new _ServerQueryApi(apiDef, action).setMiddlewares(...middleware);
25
+ }
26
+ export function createBodyServerApi(apiDef, action, ...middleware) {
27
+ return new _ServerBodyApi(apiDef, action).setMiddlewares(...middleware);
28
+ }
29
+ export function apiWithQueryAxios(apiDef, onCompleted, onError) {
30
+ return (params) => {
31
+ return AxiosHttpModule
32
+ .createRequest(apiDef)
33
+ .setUrlParams(params)
34
+ .setOnError(onError)
35
+ .setOnCompleted(onCompleted);
36
+ };
37
+ }
38
+ export function apiWithBodyAxios(apiDef, onCompleted, onError) {
39
+ return (body) => {
40
+ return AxiosHttpModule
41
+ .createRequest(apiDef)
42
+ .setBodyAsJson(body)
43
+ .setOnError(onError)
44
+ .setOnCompleted(onCompleted);
45
+ };
46
+ }
@@ -0,0 +1 @@
1
+ export {};
package/exceptions.js ADDED
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ export {};
package/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ export * from './modules/proxy/RemoteProxyCaller.js';
2
+ export * from './modules/proxy/ModuleBE_RemoteProxy.js';
3
+ export * from './modules/CleanupScheduler.js';
4
+ export * from './modules/ModuleBE_APIs.js';
5
+ export * from './modules/action-processor/ModuleBE_ActionProcessor.js';
6
+ export * from './modules/action-processor/types.js';
7
+ export * from './modules/server/server-errors.js';
8
+ export * from './modules/server/server-api.js';
9
+ export * from './modules/server/HeaderKey.js';
10
+ export * from './modules/server/HttpServer.js';
11
+ export * from './modules/server/route-resolvers/index.js';
12
+ export * from './modules/http/AxiosHttpModule.js';
13
+ export * from './modules/http/types.js';
14
+ export * from './modules/ModuleBE_ForceUpgrade.js';
15
+ export * from './modules/ModuleBE_ServerInfo.js';
16
+ export * from './utils/promisify-request.js';
17
+ export * from './utils/types.js';
18
+ export * from './utils/file.js';
19
+ export * from './core/Storm.js';
20
+ export * from './core/typed-api.js';
21
+ export * from './core/db-def.js';
22
+ export * from './modules/archiving/ModuleBE_Archiving.js';
23
+ export * from './modules/sync-env/ModuleBE_SyncEnv.js';
24
+ export * from './modules/sync-manager/ModuleBE_SyncManager.js';
25
+ export * from './modules/db-api-gen/ModuleBE_BaseDB.js';
26
+ export * from './modules/db-api-gen/ModuleBE_BaseApi.js';
27
+ export * from './_entity.js';
package/index.js ADDED
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ export * from './modules/proxy/RemoteProxyCaller.js';
22
+ export * from './modules/proxy/ModuleBE_RemoteProxy.js';
23
+ export * from './modules/CleanupScheduler.js';
24
+ export * from './modules/ModuleBE_APIs.js';
25
+ export * from './modules/action-processor/ModuleBE_ActionProcessor.js';
26
+ export * from './modules/action-processor/types.js';
27
+ export * from './modules/server/server-errors.js';
28
+ export * from './modules/server/server-api.js';
29
+ export * from './modules/server/HeaderKey.js';
30
+ export * from './modules/server/HttpServer.js';
31
+ export * from './modules/server/route-resolvers/index.js';
32
+ export * from './modules/http/AxiosHttpModule.js';
33
+ export * from './modules/http/types.js';
34
+ export * from './modules/ModuleBE_ForceUpgrade.js';
35
+ export * from './modules/ModuleBE_ServerInfo.js';
36
+ export * from './utils/promisify-request.js';
37
+ export * from './utils/types.js';
38
+ export * from './utils/file.js';
39
+ export * from './core/Storm.js';
40
+ export * from './core/typed-api.js';
41
+ // from db-api-generator
42
+ export * from './core/db-def.js';
43
+ export * from './modules/archiving/ModuleBE_Archiving.js';
44
+ export * from './modules/sync-env/ModuleBE_SyncEnv.js';
45
+ export * from './modules/sync-manager/ModuleBE_SyncManager.js';
46
+ export * from './modules/db-api-gen/ModuleBE_BaseDB.js';
47
+ export * from './modules/db-api-gen/ModuleBE_BaseApi.js';
48
+ export * from './_entity.js';
@@ -0,0 +1,14 @@
1
+ import { ModuleBE_FirebaseScheduler } from '@nu-art/firebase-backend';
2
+ export type CleanupDetails = {
3
+ cleanup: () => Promise<void>;
4
+ interval: number;
5
+ moduleKey: string;
6
+ };
7
+ export interface OnCleanupSchedulerAct {
8
+ __onCleanupSchedulerAct: () => CleanupDetails;
9
+ }
10
+ export declare class CleanupScheduler_Class extends ModuleBE_FirebaseScheduler {
11
+ constructor();
12
+ onScheduledEvent: () => Promise<any>;
13
+ }
14
+ export declare const CleanupScheduler: CleanupScheduler_Class;
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Thunderstorm is a full web app framework!
3
+ *
4
+ * Typescript & Express backend infrastructure that natively runs on firebase function
5
+ * Typescript & React frontend infrastructure
6
+ *
7
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ import { currentTimeMillis, Dispatcher } from '@nu-art/ts-common';
22
+ import { ModuleBE_Firebase } from '@nu-art/firebase-backend/ModuleBE_Firebase';
23
+ import { ModuleBE_FirebaseScheduler } from '@nu-art/firebase-backend';
24
+ const dispatch_onCleanupSchedulerAct = new Dispatcher('__onCleanupSchedulerAct');
25
+ export class CleanupScheduler_Class extends ModuleBE_FirebaseScheduler {
26
+ constructor() {
27
+ super();
28
+ this.setSchedule('every 1 hours');
29
+ }
30
+ onScheduledEvent = async () => {
31
+ const cleanupStatusCollection = ModuleBE_Firebase.createAdminSession().getFirestore().getCollection('cleanup-status', ['moduleKey']);
32
+ const cleanups = dispatch_onCleanupSchedulerAct.dispatchModule();
33
+ await Promise.all(cleanups.map(async (cleanupItem) => {
34
+ const doc = await cleanupStatusCollection.queryUnique({ where: { moduleKey: cleanupItem.moduleKey } });
35
+ if (doc && doc.timestamp + cleanupItem.interval > currentTimeMillis())
36
+ return;
37
+ try {
38
+ await cleanupItem.cleanup();
39
+ await cleanupStatusCollection.upsert({
40
+ timestamp: currentTimeMillis(),
41
+ moduleKey: cleanupItem.moduleKey
42
+ });
43
+ }
44
+ catch (e) {
45
+ this.logWarning(`cleanup of ${cleanupItem.moduleKey} has failed with error '${e}'`);
46
+ }
47
+ }));
48
+ };
49
+ }
50
+ export const CleanupScheduler = new CleanupScheduler_Class();
@@ -0,0 +1,11 @@
1
+ import { Module } from '@nu-art/ts-common/core/module';
2
+ import { ServerApi } from './server/server-api.js';
3
+ import { TestResetListener } from '@nu-art/ts-common/testing/types';
4
+ export declare class ModuleBE_APIs_Class extends Module implements TestResetListener {
5
+ private readonly routes;
6
+ __resetForTests(): Promise<void>;
7
+ addRoutes: (apis: ServerApi<any>[]) => void;
8
+ useRoutes: () => ServerApi<any>[];
9
+ }
10
+ export declare const ModuleBE_APIs: ModuleBE_APIs_Class;
11
+ export declare const addRoutes: (apis: ServerApi<any>[]) => void;
@@ -0,0 +1,19 @@
1
+ import { Module } from '@nu-art/ts-common/core/module';
2
+ import { MUSTNeverHappenException } from '@nu-art/ts-common';
3
+ export class ModuleBE_APIs_Class extends Module {
4
+ routes = [];
5
+ async __resetForTests() {
6
+ this.logWarning('__resetForTests');
7
+ this.routes.length = 0;
8
+ }
9
+ addRoutes = (apis) => {
10
+ apis.forEach(api => {
11
+ if (this.routes.find(_api => _api.apiDef.path === api.apiDef.path))
12
+ throw new MUSTNeverHappenException(`There is more than one API with the path '${api.apiDef.path}'!!!`);
13
+ this.routes.push(api);
14
+ });
15
+ };
16
+ useRoutes = () => this.routes;
17
+ }
18
+ export const ModuleBE_APIs = new ModuleBE_APIs_Class();
19
+ export const addRoutes = (apis) => ModuleBE_APIs.addRoutes(apis);
@@ -0,0 +1,9 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import * as Papa from 'papaparse';
3
+ import { Transform } from 'stream';
4
+ declare class ModuleBE_CSVParser_Class extends Module {
5
+ getTransform_FromCSV: (config?: Papa.ParseConfig) => Transform;
6
+ getTransform_ToCSV: (config?: Papa.UnparseConfig) => Transform;
7
+ }
8
+ export declare const ModuleBE_CSVParser: ModuleBE_CSVParser_Class;
9
+ export {};
@@ -0,0 +1,50 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import * as Papa from 'papaparse';
3
+ import { Transform } from 'stream';
4
+ class ModuleBE_CSVParser_Class extends Module {
5
+ getTransform_FromCSV = (config) => new TransformFromCSV(config);
6
+ getTransform_ToCSV = (config) => new TransformToCSV(config);
7
+ }
8
+ export const ModuleBE_CSVParser = new ModuleBE_CSVParser_Class();
9
+ class TransformFromCSV extends Transform {
10
+ config;
11
+ constructor(config) {
12
+ super({ objectMode: true });
13
+ this.config = {
14
+ header: true,
15
+ ...config
16
+ };
17
+ }
18
+ _transform(chunk, encoding, callback) {
19
+ Papa.parse(chunk.toString(), {
20
+ ...this.config,
21
+ error: (error) => callback(error),
22
+ complete: (results) => {
23
+ results.data.forEach(row => this.push(row));
24
+ callback();
25
+ }
26
+ });
27
+ }
28
+ }
29
+ class TransformToCSV extends Transform {
30
+ config;
31
+ firstChunk;
32
+ constructor(config) {
33
+ super({ objectMode: true });
34
+ this.firstChunk = true;
35
+ this.config = {
36
+ header: true,
37
+ ...config,
38
+ };
39
+ }
40
+ _transform(chunk, encoding, callback) {
41
+ const data = Array.isArray(chunk) ? chunk : [chunk];
42
+ const parsed = Papa.unparse(data, this.config);
43
+ this.push(parsed);
44
+ if (this.firstChunk) {
45
+ this.firstChunk = false;
46
+ this.config.header = false;
47
+ }
48
+ callback();
49
+ }
50
+ }
@@ -0,0 +1,21 @@
1
+ import { Module } from '@nu-art/ts-common';
2
+ import { Browser, UpgradeRequired } from '@nu-art/thunderstorm-shared';
3
+ import { ServerApi_Middleware } from '../utils/types.js';
4
+ type VersionConfig = {
5
+ regexp: {
6
+ [K in Browser]: string;
7
+ };
8
+ browser: {
9
+ [K in Browser]: string;
10
+ };
11
+ app: string;
12
+ };
13
+ declare class ModuleBE_ForceUpgrade_Class extends Module<VersionConfig> {
14
+ static readonly Middleware: ServerApi_Middleware;
15
+ constructor();
16
+ init(): void;
17
+ compareVersion(): UpgradeRequired;
18
+ assertVersion(): Promise<void>;
19
+ }
20
+ export declare const ModuleBE_ForceUpgrade: ModuleBE_ForceUpgrade_Class;
21
+ export {};