@nu-art/thunderstorm-shared 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 (93) hide show
  1. package/BaseHttpModule.d.ts +28 -0
  2. package/BaseHttpModule.js +56 -0
  3. package/BaseHttpRequest.d.ts +70 -0
  4. package/BaseHttpRequest.js +261 -0
  5. package/_entity/app-config/api-def.d.ts +10 -0
  6. package/_entity/app-config/api-def.js +6 -0
  7. package/_entity/app-config/db-def.d.ts +3 -0
  8. package/_entity/app-config/db-def.js +20 -0
  9. package/_entity/app-config/index.d.ts +3 -0
  10. package/_entity/app-config/index.js +4 -0
  11. package/_entity/app-config/types.d.ts +16 -0
  12. package/_entity/app-config/types.js +1 -0
  13. package/_entity/backup-doc/api-def.d.ts +17 -0
  14. package/_entity/backup-doc/api-def.js +7 -0
  15. package/_entity/backup-doc/db-def.d.ts +3 -0
  16. package/_entity/backup-doc/db-def.js +30 -0
  17. package/_entity/backup-doc/index.d.ts +3 -0
  18. package/_entity/backup-doc/index.js +4 -0
  19. package/_entity/backup-doc/types.d.ts +45 -0
  20. package/_entity/backup-doc/types.js +1 -0
  21. package/_entity/deleted-doc/api-def.d.ts +7 -0
  22. package/_entity/deleted-doc/api-def.js +3 -0
  23. package/_entity/deleted-doc/db-def.d.ts +3 -0
  24. package/_entity/deleted-doc/db-def.js +20 -0
  25. package/_entity/deleted-doc/index.d.ts +3 -0
  26. package/_entity/deleted-doc/index.js +4 -0
  27. package/_entity/deleted-doc/types.d.ts +17 -0
  28. package/_entity/deleted-doc/types.js +1 -0
  29. package/_entity/editable-test/api-def.d.ts +7 -0
  30. package/_entity/editable-test/api-def.js +3 -0
  31. package/_entity/editable-test/db-def.d.ts +3 -0
  32. package/_entity/editable-test/db-def.js +24 -0
  33. package/_entity/editable-test/index.d.ts +3 -0
  34. package/_entity/editable-test/index.js +4 -0
  35. package/_entity/editable-test/types.d.ts +18 -0
  36. package/_entity/editable-test/types.js +1 -0
  37. package/_entity.d.ts +4 -0
  38. package/_entity.js +4 -0
  39. package/action-processor/apis.d.ts +17 -0
  40. package/action-processor/apis.js +8 -0
  41. package/action-processor/index.d.ts +1 -0
  42. package/action-processor/index.js +1 -0
  43. package/archiving/apis.d.ts +22 -0
  44. package/archiving/apis.js +8 -0
  45. package/archiving/index.d.ts +1 -0
  46. package/archiving/index.js +1 -0
  47. package/base64-tools.d.ts +3 -0
  48. package/base64-tools.js +30 -0
  49. package/collection-actions/api-def.d.ts +39 -0
  50. package/collection-actions/api-def.js +10 -0
  51. package/collection-actions/index.d.ts +2 -0
  52. package/collection-actions/index.js +2 -0
  53. package/collection-actions/types.d.ts +13 -0
  54. package/collection-actions/types.js +1 -0
  55. package/consts.d.ts +12 -0
  56. package/consts.js +41 -0
  57. package/db-api-gen/apiV1.d.ts +42 -0
  58. package/db-api-gen/apiV1.js +51 -0
  59. package/db-api-gen/apiV2.d.ts +42 -0
  60. package/db-api-gen/apiV2.js +51 -0
  61. package/db-api-gen/apiV3.d.ts +42 -0
  62. package/db-api-gen/apiV3.js +51 -0
  63. package/force-upgrade.d.ts +16 -0
  64. package/force-upgrade.js +33 -0
  65. package/headers.d.ts +10 -0
  66. package/headers.js +10 -0
  67. package/index.d.ts +15 -0
  68. package/index.js +36 -0
  69. package/no-auth-listener.d.ts +6 -0
  70. package/no-auth-listener.js +2 -0
  71. package/package.json +101 -0
  72. package/request-types.d.ts +16 -0
  73. package/request-types.js +30 -0
  74. package/route-tools.d.ts +1 -0
  75. package/route-tools.js +3 -0
  76. package/server-info/api.d.ts +15 -0
  77. package/server-info/api.js +7 -0
  78. package/server-info/consts.d.ts +7 -0
  79. package/server-info/consts.js +18 -0
  80. package/server-info/index.d.ts +3 -0
  81. package/server-info/index.js +3 -0
  82. package/server-info/types.d.ts +6 -0
  83. package/server-info/types.js +1 -0
  84. package/sync-env/apis.d.ts +40 -0
  85. package/sync-env/apis.js +12 -0
  86. package/sync-env/index.d.ts +1 -0
  87. package/sync-env/index.js +1 -0
  88. package/sync-manager/apis.d.ts +16 -0
  89. package/sync-manager/apis.js +7 -0
  90. package/sync-manager/types.d.ts +27 -0
  91. package/sync-manager/types.js +3 -0
  92. package/types.d.ts +79 -0
  93. package/types.js +31 -0
@@ -0,0 +1,16 @@
1
+ import { ApiDef, ApiDefResolver, QueryApi } from './types.js';
2
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
3
+ export declare const HeaderKey_AppVersion = "x-app-version";
4
+ export declare const HeaderKey_BrowserType = "x-browser-type";
5
+ export declare const HeaderKey_UserAgent = "user-agent";
6
+ export type UpgradeRequired = ResponseError<'upgrade-required', {
7
+ browser: boolean;
8
+ app: boolean;
9
+ }>;
10
+ export declare const ApiDef_AssertAppVersion: ApiDef<QueryApi<UpgradeRequired>>;
11
+ export type ApiStruct_ForceUpgrade = {
12
+ v1: {
13
+ assertAppVersion: QueryApi<UpgradeRequired>;
14
+ };
15
+ };
16
+ export declare const ApiDef_ForceUpgrade: ApiDefResolver<ApiStruct_ForceUpgrade>;
@@ -0,0 +1,33 @@
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 { HttpMethod } from './types.js';
22
+ export const HeaderKey_AppVersion = 'x-app-version';
23
+ export const HeaderKey_BrowserType = 'x-browser-type';
24
+ export const HeaderKey_UserAgent = 'user-agent';
25
+ export const ApiDef_AssertAppVersion = {
26
+ method: HttpMethod.GET,
27
+ path: 'assert-app-version',
28
+ };
29
+ export const ApiDef_ForceUpgrade = {
30
+ v1: {
31
+ assertAppVersion: { method: HttpMethod.GET, path: 'assert-app-version' }
32
+ }
33
+ };
package/headers.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const HeaderKey_Origin = "Origin";
2
+ export declare const HeaderKey_Authorization = "Authorization";
3
+ export declare const HeaderKey_TabId = "tab-id";
4
+ export declare const HeaderKey_DeviceId = "device-id";
5
+ export declare const HeaderKey_Application = "x-application";
6
+ export declare const HeaderKey_Email = "x-email";
7
+ export declare const HeaderKey_ContentType = "Content-Type";
8
+ export declare const HeaderKey_AcceptEncoding = "Accept-Encoding";
9
+ export declare const HeaderKey_ContentEncoding = "Content-Encoding";
10
+ export declare const ResponseHeaderKey_JWTToken = "X-Auth-Token";
package/headers.js ADDED
@@ -0,0 +1,10 @@
1
+ export const HeaderKey_Origin = 'Origin';
2
+ export const HeaderKey_Authorization = 'Authorization';
3
+ export const HeaderKey_TabId = 'tab-id';
4
+ export const HeaderKey_DeviceId = 'device-id';
5
+ export const HeaderKey_Application = 'x-application';
6
+ export const HeaderKey_Email = 'x-email';
7
+ export const HeaderKey_ContentType = 'Content-Type';
8
+ export const HeaderKey_AcceptEncoding = 'Accept-Encoding';
9
+ export const HeaderKey_ContentEncoding = 'Content-Encoding';
10
+ export const ResponseHeaderKey_JWTToken = 'X-Auth-Token';
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from './types.js';
2
+ export * from './request-types.js';
3
+ export * from './force-upgrade.js';
4
+ export * from './consts.js';
5
+ export * from './server-info/index.js';
6
+ export * from './BaseHttpRequest.js';
7
+ export * from './BaseHttpModule.js';
8
+ export * from './db-api-gen/apiV1.js';
9
+ export * from './db-api-gen/apiV2.js';
10
+ export * from './db-api-gen/apiV3.js';
11
+ export * from './sync-env/index.js';
12
+ export * from './archiving/index.js';
13
+ export * from './_entity.js';
14
+ export * from './headers.js';
15
+ export * from './collection-actions/index.js';
package/index.js ADDED
@@ -0,0 +1,36 @@
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 './types.js';
22
+ export * from './request-types.js';
23
+ export * from './force-upgrade.js';
24
+ export * from './consts.js';
25
+ export * from './server-info/index.js';
26
+ export * from './BaseHttpRequest.js';
27
+ export * from './BaseHttpModule.js';
28
+ //db-api-generator
29
+ export * from './db-api-gen/apiV1.js';
30
+ export * from './db-api-gen/apiV2.js';
31
+ export * from './db-api-gen/apiV3.js';
32
+ export * from './sync-env/index.js';
33
+ export * from './archiving/index.js';
34
+ export * from './_entity.js';
35
+ export * from './headers.js';
36
+ export * from './collection-actions/index.js';
@@ -0,0 +1,6 @@
1
+ import { BaseHttpRequest } from './BaseHttpRequest.js';
2
+ import { Dispatcher } from '@nu-art/ts-common';
3
+ export interface OnAuthRequiredListener {
4
+ __onAuthRequiredListener(request?: BaseHttpRequest<any>): void;
5
+ }
6
+ export declare const dispatcher_onAuthRequired: Dispatcher<OnAuthRequiredListener, "__onAuthRequiredListener", [request?: BaseHttpRequest<any> | undefined], void>;
@@ -0,0 +1,2 @@
1
+ import { Dispatcher } from '@nu-art/ts-common';
2
+ export const dispatcher_onAuthRequired = new Dispatcher('__onAuthRequiredListener');
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@nu-art/thunderstorm-shared",
3
+ "version": "0.400.5",
4
+ "description": "Thunderstorm Shared",
5
+ "keywords": [
6
+ "TacB0sS",
7
+ "express",
8
+ "infra",
9
+ "nu-art",
10
+ "thunderstorm",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/nu-art-js/thunderstorm",
14
+ "bugs": {
15
+ "url": "https://github.com/nu-art-js/thunderstorm/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+ssh://git@github.com:nu-art-js/thunderstorm.git"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "author": "TacB0sS",
23
+ "scripts": {
24
+ "build": "tsc"
25
+ },
26
+ "contributors": [
27
+ {
28
+ "name": "TacB0sS"
29
+ },
30
+ {
31
+ "name": "Cipher",
32
+ "url": "https://www.linkedin.com/in/itay-leybovich-470b87229/"
33
+ }
34
+ ],
35
+ "publishConfig": {
36
+ "directory": "dist",
37
+ "linkDirectory": true
38
+ },
39
+ "dependencies": {
40
+ "@nu-art/firebase-shared": "0.400.5",
41
+ "@nu-art/ts-common": "0.400.5",
42
+ "@nu-art/ts-styles": "0.400.5",
43
+ "firebase": "^11.9.0",
44
+ "firebase-admin": "13.4.0",
45
+ "firebase-functions": "6.3.2",
46
+ "react": "^18.0.0",
47
+ "react-dom": "^18.0.0",
48
+ "react-router-dom": "^6.9.0",
49
+ "abort-controller": "^3.0.0",
50
+ "util": "^0.12.4",
51
+ "axios": "^1.13.1",
52
+ "browserify-zlib": "^0.2.0",
53
+ "buffer": "^6.0.3",
54
+ "crypto-browserify": "^3.12.0",
55
+ "express": "^4.18.2",
56
+ "request": "^2.88.0",
57
+ "stream-browserify": "^3.0.0",
58
+ "body-parser": "^1.19.0",
59
+ "compression": "^1.7.4",
60
+ "csstype": "^3.0.0",
61
+ "history": "^4.9.0",
62
+ "moment": "^2.29.4",
63
+ "qs": "^6.6.0",
64
+ "cors": "^2.8.5",
65
+ "react-window": "^1.8.8",
66
+ "react-virtualized-auto-sizer": "^1.0.12",
67
+ "pako": "^2.1.0",
68
+ "papaparse": "^5.4.1"
69
+ },
70
+ "devDependencies": {
71
+ "@types/papaparse": "^5.3.14",
72
+ "@types/pako": "^2.0.0",
73
+ "@types/cors": "^2.8.17",
74
+ "@types/react": "^18.0.0",
75
+ "@types/react-dom": "^18.0.0",
76
+ "@types/react-router": "^5.1.20",
77
+ "@types/react-router-dom": "^5.3.3",
78
+ "@types/compression": "^1.7.0",
79
+ "@types/express": "^4.17.17",
80
+ "@types/history": "^4.7.2",
81
+ "@types/request": "^2.48.1",
82
+ "@types/chrome": "^0.0.202",
83
+ "@types/react-window": "^1.8.5",
84
+ "@types/react-virtualized-auto-sizer": "^1.0.1"
85
+ },
86
+ "unitConfig": {
87
+ "type": "typescript-lib"
88
+ },
89
+ "type": "module",
90
+ "exports": {
91
+ ".": {
92
+ "types": "./index.d.ts",
93
+ "import": "./index.js"
94
+ },
95
+ "./*": {
96
+ "types": "./*.d.ts",
97
+ "import": "./*.js"
98
+ },
99
+ "./styles": "./styles.scss"
100
+ }
101
+ }
@@ -0,0 +1,16 @@
1
+ import { ApiErrorResponse, ResponseError } from '@nu-art/ts-common/core/exceptions/types';
2
+ import { CustomException } from '@nu-art/ts-common';
3
+ export declare class HttpException<E extends ResponseError = ResponseError> extends CustomException {
4
+ responseCode: number;
5
+ errorResponse?: ApiErrorResponse<E>;
6
+ constructor(responseCode: number, url: string, errorResponse?: ApiErrorResponse<E>);
7
+ }
8
+ export type TS_Progress = {
9
+ readonly lengthComputable: boolean;
10
+ readonly loaded: number;
11
+ readonly target: any;
12
+ readonly total: number;
13
+ };
14
+ export interface OnRequestListener {
15
+ __onRequestCompleted: (key: string, success: boolean, requestData?: any) => void;
16
+ }
@@ -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 { CustomException } from '@nu-art/ts-common';
22
+ export class HttpException extends CustomException {
23
+ responseCode;
24
+ errorResponse;
25
+ constructor(responseCode, url, errorResponse) {
26
+ super(HttpException, `${responseCode} - ${url}`);
27
+ this.responseCode = responseCode;
28
+ this.errorResponse = errorResponse;
29
+ }
30
+ }
@@ -0,0 +1 @@
1
+ export declare const trimStartingForwardSlash: (path: string) => string;
package/route-tools.js ADDED
@@ -0,0 +1,3 @@
1
+ export const trimStartingForwardSlash = (path) => {
2
+ return path.startsWith('/') ? path.substring(1) : path;
3
+ };
@@ -0,0 +1,15 @@
1
+ import { ApiDefResolver, QueryApi } from '../types.js';
2
+ import { BasicServerInfo } from './types.js';
3
+ export type Response_ServerInfo = BasicServerInfo & {
4
+ status: {
5
+ firestore: string;
6
+ firebase: string;
7
+ };
8
+ };
9
+ export type ApiStruct_ServerInfo = {
10
+ v1: {
11
+ getServerInfo: QueryApi<Response_ServerInfo>;
12
+ updateServerInfoState: QueryApi<void>;
13
+ };
14
+ };
15
+ export declare const ApiDef_ServerInfo: ApiDefResolver<ApiStruct_ServerInfo>;
@@ -0,0 +1,7 @@
1
+ import { HttpMethod } from '../types.js';
2
+ export const ApiDef_ServerInfo = {
3
+ v1: {
4
+ getServerInfo: { method: HttpMethod.GET, path: 'v1/server-info' },
5
+ updateServerInfoState: { method: HttpMethod.GET, path: 'v1/update-server-info' }
6
+ }
7
+ };
@@ -0,0 +1,7 @@
1
+ export declare const Default_ServerInfoNodePath = "/state/ModuleBE_ServerInfo/serverInfo";
2
+ /**
3
+ * Translates the version '1.2.3' into 100020003 numeric value for indexing purposes.
4
+ */
5
+ export declare const versionStringToNumeric: (version: string) => number;
6
+ export declare const Const_OK = "OK";
7
+ export declare const Const_ERROR = "ERROR";
@@ -0,0 +1,18 @@
1
+ import { BadImplementationException } from '@nu-art/ts-common';
2
+ export const Default_ServerInfoNodePath = '/state/ModuleBE_ServerInfo/serverInfo';
3
+ /**
4
+ * Translates the version '1.2.3' into 100020003 numeric value for indexing purposes.
5
+ */
6
+ export const versionStringToNumeric = (version) => {
7
+ return version.split('.').reduce((result, current) => {
8
+ const value = parseInt(current);
9
+ if (Number.isNaN(value))
10
+ throw new BadImplementationException(`Received version ${version} can't be converted into a number. 'parseInt(${current})' returns NaN!!!`);
11
+ if (result > 0)
12
+ result *= 10000;
13
+ result += value;
14
+ return result;
15
+ }, 0);
16
+ };
17
+ export const Const_OK = 'OK';
18
+ export const Const_ERROR = 'ERROR';
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './api.js';
3
+ export * from './consts.js';
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './api.js';
3
+ export * from './consts.js';
@@ -0,0 +1,6 @@
1
+ export type BasicServerInfo = {
2
+ version: string;
3
+ environment: string;
4
+ bucketName: string;
5
+ };
6
+ export type ServerInfoFirebaseState = BasicServerInfo;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { UniqueId } from '@nu-art/ts-common';
2
+ import { ApiDefResolver, BodyApi, QueryApi } from '../types.js';
3
+ import { BackupMetaData } from '../_entity.js';
4
+ export type Request_FetchFromEnv = {
5
+ backupId: string;
6
+ env: string;
7
+ chunkSize: number;
8
+ selectedModules: string[];
9
+ cleanSync?: boolean;
10
+ };
11
+ export type Request_FetchFirebaseBackup = {
12
+ backupId: UniqueId;
13
+ env: string;
14
+ };
15
+ export type Request_GetMetadata = {
16
+ backupId: UniqueId;
17
+ env: string;
18
+ };
19
+ export type Response_FetchBackupMetadata = BackupMetaData & {
20
+ remoteCollectionNames: string[];
21
+ };
22
+ export type ApiStruct_SyncEnv = {
23
+ vv1: {
24
+ getLatestBackup: QueryApi<{
25
+ latestBackupId: string;
26
+ }>;
27
+ syncToEnv: BodyApi<any, {
28
+ env: 'dev' | 'prod';
29
+ moduleName: string;
30
+ items: any[];
31
+ }>;
32
+ syncFromEnvBackup: BodyApi<any, Request_FetchFromEnv>;
33
+ createBackup: QueryApi<{
34
+ pathToBackup: string;
35
+ } | undefined>;
36
+ fetchBackupMetadata: QueryApi<Response_FetchBackupMetadata, Request_GetMetadata>;
37
+ syncFirebaseFromBackup: QueryApi<any, Request_FetchFirebaseBackup>;
38
+ };
39
+ };
40
+ export declare const ApiDef_SyncEnv: ApiDefResolver<ApiStruct_SyncEnv>;
@@ -0,0 +1,12 @@
1
+ import { Minute } from '@nu-art/ts-common';
2
+ import { HttpMethod } from '../types.js';
3
+ export const ApiDef_SyncEnv = {
4
+ vv1: {
5
+ getLatestBackup: { method: HttpMethod.GET, path: 'v1/sync-env/get-last-backup-id' },
6
+ syncToEnv: { method: HttpMethod.POST, path: 'v1/sync-env/sync-to-env', timeout: 5 * Minute },
7
+ syncFromEnvBackup: { method: HttpMethod.POST, path: 'v1/sync-env/fetch-from-env-v2', timeout: 5 * Minute },
8
+ createBackup: { method: HttpMethod.GET, path: 'v1/sync-env/create-backup-v2', timeout: 5 * Minute },
9
+ fetchBackupMetadata: { method: HttpMethod.GET, path: 'v1/sync-env/fetch-backup-metadata', timeout: 5 * Minute },
10
+ syncFirebaseFromBackup: { method: HttpMethod.GET, path: 'v1/sync-env/fetch-firebase-backup', timeout: 5 * Minute }
11
+ }
12
+ };
@@ -0,0 +1 @@
1
+ export * from './apis.js';
@@ -0,0 +1 @@
1
+ export * from './apis.js';
@@ -0,0 +1,16 @@
1
+ import { ApiDefResolver, BodyApi } from '../types.js';
2
+ import { DeltaSyncModule, FullSyncModule, NoNeedToSyncModule, SyncDbData } from './types.js';
3
+ export type SyncManagerAPI_SmartSync = {
4
+ request: {
5
+ modules: SyncDbData[];
6
+ };
7
+ response: {
8
+ modules: (NoNeedToSyncModule | DeltaSyncModule | FullSyncModule)[];
9
+ };
10
+ };
11
+ export type ApiStruct_SyncManager = {
12
+ v1: {
13
+ smartSync: BodyApi<SyncManagerAPI_SmartSync['response'], SyncManagerAPI_SmartSync['request']>;
14
+ };
15
+ };
16
+ export declare const ApiDef_SyncManager: ApiDefResolver<ApiStruct_SyncManager>;
@@ -0,0 +1,7 @@
1
+ import { HttpMethod } from '../types.js';
2
+ import { Minute } from '@nu-art/ts-common';
3
+ export const ApiDef_SyncManager = {
4
+ v1: {
5
+ smartSync: { method: HttpMethod.POST, path: 'v1/db-api/smart-sync', timeout: Minute },
6
+ }
7
+ };
@@ -0,0 +1,27 @@
1
+ import { DB_Object, TypedMap } from '@nu-art/ts-common';
2
+ export type LastUpdated = {
3
+ lastUpdated: number;
4
+ oldestDeleted?: number;
5
+ };
6
+ export type SyncDataFirebaseState = TypedMap<LastUpdated>;
7
+ export type Response_DBSync<DBType extends DB_Object> = {
8
+ toUpdate: DBType[];
9
+ toDelete: DB_Object[];
10
+ };
11
+ export type SyncDbData = {
12
+ dbKey: string;
13
+ lastUpdated: number;
14
+ };
15
+ export declare const SmartSync_UpToDateSync: "up-to-date";
16
+ export declare const SmartSync_DeltaSync: "delta-sync";
17
+ export declare const SmartSync_FullSync: "full";
18
+ export type NoNeedToSyncModule = SyncDbData & {
19
+ sync: typeof SmartSync_UpToDateSync;
20
+ };
21
+ export type DeltaSyncModule = SyncDbData & {
22
+ sync: typeof SmartSync_DeltaSync;
23
+ items: Response_DBSync<any>;
24
+ };
25
+ export type FullSyncModule = SyncDbData & {
26
+ sync: typeof SmartSync_FullSync;
27
+ };
@@ -0,0 +1,3 @@
1
+ export const SmartSync_UpToDateSync = 'up-to-date';
2
+ export const SmartSync_DeltaSync = 'delta-sync';
3
+ export const SmartSync_FullSync = 'full';
package/types.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { BaseHttpRequest } from './BaseHttpRequest.js';
2
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
3
+ import { DBDef_V3 } from '@nu-art/ts-common';
4
+ export declare enum HttpMethod {
5
+ ALL = "all",
6
+ POST = "post",
7
+ GET = "get",
8
+ PATCH = "patch",
9
+ DELETE = "delete",
10
+ PUT = "put",
11
+ OPTIONS = "options",
12
+ HEAD = "head"
13
+ }
14
+ export type HttpMethod_Query = 'get' | 'delete';
15
+ export type HttpMethod_Body = 'post' | 'put' | 'patch';
16
+ export type HttpMethod_Empty = 'options' | 'head';
17
+ export type QueryParams = {
18
+ [key: string]: string | number | undefined;
19
+ };
20
+ export type UrlQueryParams = {
21
+ [key: string]: string | undefined;
22
+ };
23
+ /**
24
+ * P - Params
25
+ * B - Body
26
+ * R - Response
27
+ * M - Method
28
+ * IP - Input Params
29
+ * IB - Input Body
30
+ */
31
+ export type TypedApi<M extends string, R, B, P extends QueryParams | undefined, IB = B, IP = P, E extends ResponseError = ResponseError> = {
32
+ M: M;
33
+ R: R;
34
+ B: B;
35
+ P: P;
36
+ IP: IP;
37
+ IB: IB;
38
+ E: E;
39
+ Body: B;
40
+ };
41
+ export type BodyApi<R, B, IB = B, E extends ResponseError = ResponseError, M extends HttpMethod_Body = HttpMethod.POST, P extends QueryParams = never> = TypedApi<M, R, B, P, IB, P, E>;
42
+ export type QueryApi<R, P extends QueryParams | undefined = QueryParams, E extends ResponseError = ResponseError, IP = P, M extends HttpMethod_Query = HttpMethod.GET, B = never> = TypedApi<M, R, B, P, B, IP, E>;
43
+ export type EmptyApi<R, M extends HttpMethod_Empty, E extends ResponseError = ResponseError, P extends QueryParams = never, B = never> = TypedApi<M, R, B, P, B, P, E>;
44
+ export type ApiDef<API extends TypedApi<any, any, any, any, any>> = {
45
+ method: API['M'];
46
+ fullUrl?: string;
47
+ baseUrl?: string;
48
+ path: string;
49
+ timeout?: number;
50
+ errors?: API['E']['type'];
51
+ };
52
+ export type ApiStruct = {
53
+ [k: string]: (TypedApi<any, any, any, any, any> | ApiStruct);
54
+ };
55
+ export type ApiDefResolver<API_Struct extends ApiStruct> = API_Struct extends TypedApi<any, any, any, any, any> ? ApiDef<API_Struct> : API_Struct extends ApiStruct ? ApiDefRouter<API_Struct> : never;
56
+ export type ApiDefRouter<API_Struct extends ApiStruct> = {
57
+ [P in keyof API_Struct]: ApiDefResolver<API_Struct[P]>;
58
+ };
59
+ export type ApiDefCaller<API_Struct extends ApiStruct> = API_Struct extends TypedApi<any, any, any, any, any> ? ApiCaller<API_Struct> : API_Struct extends ApiStruct ? ApiCallerRouter<API_Struct> : never;
60
+ export type ApiCallerRouter<API_Struct extends ApiStruct> = {
61
+ [P in keyof API_Struct]: ApiDefCaller<API_Struct[P]>;
62
+ };
63
+ export type ApiCaller_Query<API extends QueryApi<any, any, any, any, HttpMethod_Query>> = API['IP'] extends undefined ? () => BaseHttpRequest<API> : (query: API['IP']) => BaseHttpRequest<API>;
64
+ export type ApiCaller_Body<API extends BodyApi<any, any, any, any, HttpMethod_Body>> = API['IB'] extends undefined ? () => BaseHttpRequest<API> : (query: API['IB']) => BaseHttpRequest<API>;
65
+ export type ApiCaller_Any<API extends TypedApi<any, any, any, any, any>> = (body: API['IB'], query: API['IP']) => BaseHttpRequest<API>;
66
+ export type ApiCaller<API> = API extends QueryApi<any, any, any, any, HttpMethod_Query> ? ApiCaller_Query<API> : API extends BodyApi<any, any, any, any, HttpMethod_Body> ? ApiCaller_Body<API> : API extends TypedApi<any, any, any, any, any> ? ApiCaller_Any<API> : never;
67
+ export type DBModuleType = {
68
+ dbDef?: DBDef_V3<any>;
69
+ };
70
+ export type ApiModule = {
71
+ dbModule?: DBModuleType;
72
+ apiDef?: {
73
+ [name: string]: {
74
+ [name: string]: {
75
+ path: string;
76
+ };
77
+ };
78
+ };
79
+ };
package/types.js ADDED
@@ -0,0 +1,31 @@
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 var HttpMethod;
22
+ (function (HttpMethod) {
23
+ HttpMethod["ALL"] = "all";
24
+ HttpMethod["POST"] = "post";
25
+ HttpMethod["GET"] = "get";
26
+ HttpMethod["PATCH"] = "patch";
27
+ HttpMethod["DELETE"] = "delete";
28
+ HttpMethod["PUT"] = "put";
29
+ HttpMethod["OPTIONS"] = "options";
30
+ HttpMethod["HEAD"] = "head";
31
+ })(HttpMethod || (HttpMethod = {}));