@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,17 @@
1
+ import { DB_Object, DBProto, Proto_DB_Object, UniqueId, VersionsDeclaration } from '@nu-art/ts-common';
2
+ type VersionTypes_DeletedDoc = {
3
+ '1.0.0': DB_DeletedDoc;
4
+ };
5
+ type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_DeletedDoc>;
6
+ type Dependencies = {};
7
+ type UniqueKeys = '_id';
8
+ type GeneratedProps = never;
9
+ type DBKey = '__deleted__docs';
10
+ type Proto = Proto_DB_Object<DB_DeletedDoc, DBKey, GeneratedProps, Versions, UniqueKeys, Dependencies>;
11
+ export type DBProto_DeletedDoc = DBProto<Proto>;
12
+ export type UI_DeletedDoc = DBProto_DeletedDoc['uiType'];
13
+ export type DB_DeletedDoc = DB_Object & {
14
+ __collectionName: string;
15
+ __docId: UniqueId;
16
+ };
17
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ApiDefResolver } from '../../types.js';
2
+ export type RequestType = {};
3
+ export type ResponseType = {};
4
+ export type ApiStruct_EditableTest = {
5
+ _v1: {};
6
+ };
7
+ export declare const ApiDef_EditableTest: ApiDefResolver<ApiStruct_EditableTest>;
@@ -0,0 +1,3 @@
1
+ export const ApiDef_EditableTest = {
2
+ _v1: {}
3
+ };
@@ -0,0 +1,3 @@
1
+ import { DBDef_V3 } from '@nu-art/ts-common';
2
+ import { DBProto_EditableTest } from './types.js';
3
+ export declare const DBDef_EditableTest: DBDef_V3<DBProto_EditableTest>;
@@ -0,0 +1,24 @@
1
+ import { tsValidateString } from '@nu-art/ts-common';
2
+ const Validator_ModifiableProps = {
3
+ 'a': tsValidateString(),
4
+ 'b': tsValidateString(),
5
+ 'c': tsValidateString(),
6
+ 'd': tsValidateString(),
7
+ };
8
+ const Validator_GeneratedProps = {
9
+ //
10
+ };
11
+ export const DBDef_EditableTest = {
12
+ modifiablePropsValidator: Validator_ModifiableProps,
13
+ generatedPropsValidator: Validator_GeneratedProps,
14
+ versions: ['1.0.0'],
15
+ dbKey: 'editable-test',
16
+ entityName: 'editable-test',
17
+ frontend: {
18
+ group: 'test',
19
+ name: 'editable-test',
20
+ },
21
+ backend: {
22
+ name: 'editable-test',
23
+ }
24
+ };
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './db-def.js';
3
+ export * from './api-def.js';
@@ -0,0 +1,4 @@
1
+ // Generated DB Item type: EditableTest
2
+ export * from './types.js';
3
+ export * from './db-def.js';
4
+ export * from './api-def.js';
@@ -0,0 +1,18 @@
1
+ import { DB_Object, DBProto, Proto_DB_Object, VersionsDeclaration } from '@nu-art/ts-common';
2
+ type VersionTypes_EditableTest = {
3
+ '1.0.0': DB_EditableTest;
4
+ };
5
+ type Versions = VersionsDeclaration<['1.0.0'], VersionTypes_EditableTest>;
6
+ type Dependencies = {};
7
+ type UniqueKeys = '_id';
8
+ type GeneratedProps = never;
9
+ type Proto = Proto_DB_Object<DB_EditableTest, 'editable-test', GeneratedProps, Versions, UniqueKeys, Dependencies>;
10
+ export type DBProto_EditableTest = DBProto<Proto>;
11
+ export type UI_EditableTest = DBProto_EditableTest['uiType'];
12
+ export type DB_EditableTest = DB_Object & {
13
+ a: string;
14
+ b: string;
15
+ c: string;
16
+ d: string;
17
+ };
18
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/_entity.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './_entity/app-config/index.js';
2
+ export * from './_entity/backup-doc/index.js';
3
+ export * from './_entity/deleted-doc/index.js';
4
+ export * from './_entity/editable-test/index.js';
package/_entity.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './_entity/app-config/index.js';
2
+ export * from './_entity/backup-doc/index.js';
3
+ export * from './_entity/deleted-doc/index.js';
4
+ export * from './_entity/editable-test/index.js';
@@ -0,0 +1,17 @@
1
+ import { ApiDefResolver, BodyApi, QueryApi } from '../types.js';
2
+ export type Request_ActionToProcess = {
3
+ key: string;
4
+ data?: any;
5
+ };
6
+ export type ActionMetaData = {
7
+ key: string;
8
+ description: string;
9
+ group: string;
10
+ };
11
+ export type ApiStruct_ActionProcessing = {
12
+ vv1: {
13
+ execute: BodyApi<void, Request_ActionToProcess>;
14
+ list: QueryApi<ActionMetaData[]>;
15
+ };
16
+ };
17
+ export declare const ApiDef_ActionProcessing: ApiDefResolver<ApiStruct_ActionProcessing>;
@@ -0,0 +1,8 @@
1
+ import { HttpMethod } from '../types.js';
2
+ import { Minute } from '@nu-art/ts-common';
3
+ export const ApiDef_ActionProcessing = {
4
+ vv1: {
5
+ execute: { method: HttpMethod.POST, path: 'v1/action-processor/execute', timeout: 5 * Minute },
6
+ list: { method: HttpMethod.GET, path: 'v1/action-processor/list' },
7
+ }
8
+ };
@@ -0,0 +1 @@
1
+ export * from './apis.js';
@@ -0,0 +1 @@
1
+ export * from './apis.js';
@@ -0,0 +1,22 @@
1
+ import { DB_Object, UniqueId } from '@nu-art/ts-common';
2
+ import { ApiDefResolver, BodyApi, QueryApi } from '../types.js';
3
+ export type RequestBody_HardDeleteUnique = {
4
+ _id: UniqueId;
5
+ collectionName: string;
6
+ dbInstance?: DB_Object;
7
+ };
8
+ export type RequestQuery_DeleteAll = {
9
+ collectionName: string;
10
+ };
11
+ export type RequestQuery_GetHistory = {
12
+ _id: UniqueId;
13
+ collectionName: string;
14
+ };
15
+ export type ApiStruct_Archiving = {
16
+ vv1: {
17
+ hardDeleteUnique: BodyApi<void, RequestBody_HardDeleteUnique>;
18
+ hardDeleteAll: QueryApi<void, RequestQuery_DeleteAll>;
19
+ getDocumentHistory: QueryApi<DB_Object[], RequestQuery_GetHistory>;
20
+ };
21
+ };
22
+ export declare const ApiDef_Archiving: ApiDefResolver<ApiStruct_Archiving>;
@@ -0,0 +1,8 @@
1
+ import { HttpMethod } from '../types.js';
2
+ export const ApiDef_Archiving = {
3
+ vv1: {
4
+ hardDeleteAll: { method: HttpMethod.GET, path: 'v1/archiving/hard-delete-all' },
5
+ hardDeleteUnique: { method: HttpMethod.POST, path: 'v1/archiving/hard-delete-unique' },
6
+ getDocumentHistory: { method: HttpMethod.GET, path: 'v1/archiving/get-document-history' }
7
+ }
8
+ };
@@ -0,0 +1 @@
1
+ export * from './apis.js';
@@ -0,0 +1 @@
1
+ export * from './apis.js';
@@ -0,0 +1,3 @@
1
+ import { TS_Object } from '@nu-art/ts-common';
2
+ export declare function convertBase64ToObject<T extends TS_Object>(base64: string): T;
3
+ export declare function convertObjectToBase64<T extends TS_Object>(object: T): string;
@@ -0,0 +1,30 @@
1
+ import { StaticLogger } from '@nu-art/ts-common';
2
+ function isBrowser() {
3
+ return typeof window !== 'undefined' && typeof window.atob === 'function';
4
+ }
5
+ export function convertBase64ToObject(base64) {
6
+ try {
7
+ // Check if running in the browser
8
+ const decoded = isBrowser()
9
+ ? window.atob(base64) // Browser: Use `atob`
10
+ : Buffer.from(base64, 'base64').toString('utf-8'); // Node.js: Use `Buffer`
11
+ return JSON.parse(decoded);
12
+ }
13
+ catch (err) {
14
+ StaticLogger.logError(err);
15
+ return {}; // Return an empty object of type T on failure
16
+ }
17
+ }
18
+ export function convertObjectToBase64(object) {
19
+ try {
20
+ // Check if running in the browser
21
+ const string = JSON.stringify(object);
22
+ return isBrowser()
23
+ ? window.btoa(string)
24
+ : Buffer.from(string, 'utf-8').toString('base64');
25
+ }
26
+ catch (err) {
27
+ StaticLogger.logError(err);
28
+ return '';
29
+ }
30
+ }
@@ -0,0 +1,39 @@
1
+ import { UniqueId } from '@nu-art/ts-common';
2
+ import { ApiDefResolver, BodyApi } from '../types.js';
3
+ import { DBEntityDependencies } from './types.js';
4
+ export type CollectionActions_Upgrade = {
5
+ collections: {
6
+ request: {
7
+ dbKeys: string[];
8
+ force?: boolean;
9
+ };
10
+ response: void;
11
+ };
12
+ all: {
13
+ request: {
14
+ force?: boolean;
15
+ };
16
+ response: void;
17
+ };
18
+ };
19
+ export type CollectionActions_Check = {
20
+ usage: {
21
+ request: {
22
+ dbKey: string;
23
+ itemIds: UniqueId[];
24
+ };
25
+ response: {
26
+ dependencies: DBEntityDependencies | undefined;
27
+ };
28
+ };
29
+ };
30
+ export type ApiStruct_CollectionActions = {
31
+ upgrade: {
32
+ collections: BodyApi<CollectionActions_Upgrade['collections']['response'], CollectionActions_Upgrade['collections']['request']>;
33
+ all: BodyApi<CollectionActions_Upgrade['all']['response'], CollectionActions_Upgrade['all']['request']>;
34
+ };
35
+ check: {
36
+ usage: BodyApi<CollectionActions_Check['usage']['response'], CollectionActions_Check['usage']['request']>;
37
+ };
38
+ };
39
+ export declare const ApiDef_CollectionActions: ApiDefResolver<ApiStruct_CollectionActions>;
@@ -0,0 +1,10 @@
1
+ import { HttpMethod } from '../types.js';
2
+ export const ApiDef_CollectionActions = {
3
+ upgrade: {
4
+ collections: { method: HttpMethod.POST, path: 'v1/collection-actions/upgrade/collections' },
5
+ all: { method: HttpMethod.POST, path: 'v1/collection-actions/upgrade/all' },
6
+ },
7
+ check: {
8
+ usage: { method: HttpMethod.POST, path: 'v1/collection-actions/check/usage' },
9
+ }
10
+ };
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export * from './api-def.js';
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export * from './api-def.js';
@@ -0,0 +1,13 @@
1
+ import { UniqueId } from '@nu-art/ts-common';
2
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
3
+ export type DBEntityDependencyResult = {
4
+ [dbKey: string]: UniqueId[];
5
+ };
6
+ export type DBEntityDependencies = {
7
+ dbKey: string;
8
+ dependencyMap: {
9
+ [entityId: UniqueId]: DBEntityDependencyResult;
10
+ };
11
+ };
12
+ export declare const DBEntityDependencyErrorType = "entity-has-dependencies";
13
+ export type DBEntityDependencyError = ResponseError<typeof DBEntityDependencyErrorType, DBEntityDependencies>;
@@ -0,0 +1 @@
1
+ export const DBEntityDependencyErrorType = 'entity-has-dependencies';
package/consts.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export declare const HeaderKey_Env = "x-env";
2
+ export declare const HeaderKey_CurrentPage = "x-current-page";
3
+ export type Browser = 'chrome';
4
+ export declare const DefaultHttpServerConfig: {
5
+ bodyParserLimit: number;
6
+ cors: {
7
+ headers: string[];
8
+ methods: string[];
9
+ responseHeaders: string[];
10
+ };
11
+ host: string;
12
+ };
package/consts.js ADDED
@@ -0,0 +1,41 @@
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 { HeaderKey_Authorization } from './headers.js';
22
+ export const HeaderKey_Env = 'x-env';
23
+ export const HeaderKey_CurrentPage = 'x-current-page';
24
+ export const DefaultHttpServerConfig = {
25
+ 'bodyParserLimit': 200,
26
+ 'cors': {
27
+ 'headers': [
28
+ HeaderKey_Authorization,
29
+ 'x-browser-type',
30
+ 'x-app-version'
31
+ ],
32
+ 'methods': [
33
+ 'GET',
34
+ 'POST'
35
+ ],
36
+ 'responseHeaders': [
37
+ HeaderKey_Authorization
38
+ ]
39
+ },
40
+ 'host': 'localhost'
41
+ };
@@ -0,0 +1,42 @@
1
+ import { FirestoreQuery } from '@nu-art/firebase-shared';
2
+ import { DB_BaseObject, DB_Object, DBDef, IndexKeys, Metadata, PreDB } from '@nu-art/ts-common';
3
+ import { ApiDefResolver, BodyApi, QueryApi, QueryParams } from '../types.js';
4
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
5
+ /**
6
+ * !! Workaround !!
7
+ *
8
+ * there is a typescript bug... should be able to use
9
+ *
10
+ * upsert: BodyApi<DBType, PreDB<DBType>>,
11
+ * patch: BodyApi<DBType, PreDB<DBType>>
12
+ *
13
+ * but something about the type resolution goes wrong and instead of seeing Type<GenericType>, it resolves to Type> which makes no sense
14
+ */
15
+ export type ApiStruct_DBApiGen<DBType extends DB_Object> = {
16
+ v1: {
17
+ query: BodyApi<DBType[], FirestoreQuery<DBType>, FirestoreQuery<DBType> | undefined | {}>;
18
+ queryUnique: QueryApi<DBType, DB_BaseObject, ResponseError<string, any>, string>;
19
+ upsert: BodyApi<DBType, PreDB<DBType>>;
20
+ upsertAll: BodyApi<DBType[], PreDB<DBType>[]>;
21
+ patch: BodyApi<DBType, PreDB<DBType>>;
22
+ delete: QueryApi<DBType, DB_BaseObject>;
23
+ deleteQuery: BodyApi<DBType[], FirestoreQuery<DBType>>;
24
+ deleteAll: QueryApi<void>;
25
+ metadata: QueryApi<Metadata<DBType>>;
26
+ };
27
+ };
28
+ export type ApiStruct_DBApiGenIDB<DBType extends DB_Object, Ks extends keyof DBType> = {
29
+ v1: {
30
+ query: BodyApi<DBType[], FirestoreQuery<DBType>>;
31
+ queryUnique: QueryApi<DBType, QueryParams, ResponseError<string, any>, string | IndexKeys<DBType, Ks>>;
32
+ upsert: BodyApi<DBType, PreDB<DBType>>;
33
+ upsertAll: BodyApi<DBType[], PreDB<DBType>[]>;
34
+ patch: BodyApi<DBType, IndexKeys<DBType, Ks> & Partial<DBType>>;
35
+ delete: QueryApi<DBType, DB_BaseObject>;
36
+ deleteQuery: BodyApi<DBType[], FirestoreQuery<DBType>>;
37
+ deleteAll: QueryApi<DBType[]>;
38
+ metadata: QueryApi<Metadata<DBType>>;
39
+ };
40
+ };
41
+ export declare const DBApiDefGenerator: <DBType extends DB_Object>(dbDef: DBDef<DBType, "_id">) => ApiDefResolver<ApiStruct_DBApiGen<DBType>>;
42
+ export declare const DBApiDefGeneratorIDB: <DBType extends DB_Object, Ks extends keyof DBType>(dbDef: DBDef<DBType, Ks>) => ApiDefResolver<ApiStruct_DBApiGenIDB<DBType, Ks>>;
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Database API Generator is a utility library for Thunderstorm.
3
+ *
4
+ * Given proper configurations it will dynamically generate APIs to your Firestore
5
+ * collections, will assert uniqueness and restrict deletion... and more
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 DBApiDefGenerator = (dbDef) => {
23
+ return {
24
+ v1: {
25
+ query: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/query` },
26
+ queryUnique: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/query-unique` },
27
+ upsert: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/upsert` },
28
+ upsertAll: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/upsert-all` },
29
+ patch: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/patch` },
30
+ delete: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/delete-unique` },
31
+ deleteQuery: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/delete` },
32
+ deleteAll: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/delete-all` },
33
+ metadata: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/metadata` },
34
+ }
35
+ };
36
+ };
37
+ export const DBApiDefGeneratorIDB = (dbDef) => {
38
+ return {
39
+ v1: {
40
+ query: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/query` },
41
+ queryUnique: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/query-unique` },
42
+ upsert: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/upsert` },
43
+ upsertAll: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/upsert-all` },
44
+ patch: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/patch` },
45
+ delete: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/delete-unique` },
46
+ deleteQuery: { method: HttpMethod.POST, path: `v1/${dbDef.dbKey}/delete` },
47
+ deleteAll: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/delete-all` },
48
+ metadata: { method: HttpMethod.GET, path: `v1/${dbDef.dbKey}/metadata` },
49
+ }
50
+ };
51
+ };
@@ -0,0 +1,42 @@
1
+ import { FirestoreQuery } from '@nu-art/firebase-shared';
2
+ import { DB_BaseObject, DB_Object, DBDef, IndexKeys, Metadata, PreDB } from '@nu-art/ts-common';
3
+ import { ApiDefResolver, BodyApi, QueryApi } from '../types.js';
4
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
5
+ /**
6
+ * !! Workaround !!
7
+ *
8
+ * there is a typescript bug... should be able to use
9
+ *
10
+ * upsert: BodyApi<DBType, PreDB<DBType>>,
11
+ * patch: BodyApi<DBType, PreDB<DBType>>
12
+ *
13
+ * but something about the type resolution goes wrong and instead of seeing Type<GenericType>, it resolves to Type> which makes no sense
14
+ */
15
+ export type ApiStruct_DBApiGenV2<DBType extends DB_Object> = {
16
+ v1: {
17
+ query: BodyApi<DBType[], FirestoreQuery<DBType>, FirestoreQuery<DBType> | undefined | {}>;
18
+ queryUnique: QueryApi<DBType, DB_BaseObject, ResponseError<string, any>, string>;
19
+ upsert: BodyApi<DBType, PreDB<DBType>>;
20
+ upsertAll: BodyApi<DBType[], PreDB<DBType>[]>;
21
+ patch: BodyApi<DBType, PreDB<DBType>>;
22
+ delete: QueryApi<DBType, DB_BaseObject>;
23
+ deleteQuery: BodyApi<DBType[], FirestoreQuery<DBType>>;
24
+ deleteAll: QueryApi<void>;
25
+ metadata: QueryApi<Metadata<DBType>>;
26
+ };
27
+ };
28
+ export type ApiStruct_DBApiGenIDBV2<DBType extends DB_Object, Ks extends keyof DBType> = {
29
+ v1: {
30
+ query: BodyApi<DBType[], FirestoreQuery<DBType>>;
31
+ queryUnique: QueryApi<DBType, DB_BaseObject, ResponseError<string, any>, string | IndexKeys<DBType, Ks>>;
32
+ upsert: BodyApi<DBType, PreDB<DBType>>;
33
+ upsertAll: BodyApi<DBType[], PreDB<DBType>[]>;
34
+ patch: BodyApi<DBType, IndexKeys<DBType, Ks> & Partial<DBType>>;
35
+ delete: QueryApi<DBType | undefined, DB_BaseObject>;
36
+ deleteQuery: BodyApi<DBType[], FirestoreQuery<DBType>>;
37
+ deleteAll: QueryApi<DBType[]>;
38
+ metadata: QueryApi<Metadata<DBType>>;
39
+ };
40
+ };
41
+ export declare const DBApiDefGeneratorV2: <DBType extends DB_Object>(dbDef: DBDef<DBType, "_id">, version?: string) => ApiDefResolver<ApiStruct_DBApiGenV2<DBType>>;
42
+ export declare const DBApiDefGeneratorIDBV2: <DBType extends DB_Object, Ks extends keyof DBType>(dbDef: DBDef<DBType, Ks>, version?: string) => ApiDefResolver<ApiStruct_DBApiGenIDBV2<DBType, Ks>>;
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Database API Generator is a utility library for Thunderstorm.
3
+ *
4
+ * Given proper configurations it will dynamically generate APIs to your Firestore
5
+ * collections, will assert uniqueness and restrict deletion... and more
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 DBApiDefGeneratorV2 = (dbDef, version = 'v1') => {
23
+ return {
24
+ v1: {
25
+ query: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/query` },
26
+ queryUnique: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/query-unique` },
27
+ upsert: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert` },
28
+ upsertAll: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert-all` },
29
+ patch: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/patch` },
30
+ delete: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-unique` },
31
+ deleteQuery: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/delete` },
32
+ deleteAll: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-all` },
33
+ metadata: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/metadata` },
34
+ }
35
+ };
36
+ };
37
+ export const DBApiDefGeneratorIDBV2 = (dbDef, version = 'v1') => {
38
+ return {
39
+ v1: {
40
+ query: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/query` },
41
+ queryUnique: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/query-unique` },
42
+ upsert: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert` },
43
+ upsertAll: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert-all` },
44
+ patch: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/patch` },
45
+ delete: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-unique` },
46
+ deleteQuery: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/delete` },
47
+ deleteAll: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-all` },
48
+ metadata: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/metadata` },
49
+ }
50
+ };
51
+ };
@@ -0,0 +1,42 @@
1
+ import { EntityDependencyError, FirestoreQuery } from '@nu-art/firebase-shared';
2
+ import { DB_BaseObject, DBDef_V3, DBProto, IndexKeys, Metadata } from '@nu-art/ts-common';
3
+ import { ApiDefResolver, BodyApi, QueryApi } from '../types.js';
4
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
5
+ /**
6
+ * !! Workaround !!
7
+ *
8
+ * there is a typescript bug... should be able to use
9
+ *
10
+ * upsert: BodyApi<DBType, PreDB<DBType>>,
11
+ * patch: BodyApi<DBType, PreDB<DBType>>
12
+ *
13
+ * but something about the type resolution goes wrong and instead of seeing Type<GenericType>, it resolves to Type> which makes no sense
14
+ */
15
+ export type ApiStruct_DBApiGenV3<Proto extends DBProto<any>> = {
16
+ v1: {
17
+ query: BodyApi<Proto['dbType'][], FirestoreQuery<Proto['dbType']>, FirestoreQuery<Proto['dbType']> | undefined | {}>;
18
+ queryUnique: QueryApi<Proto['dbType'], DB_BaseObject, ResponseError<string, any>, string>;
19
+ upsert: BodyApi<Proto['dbType'], Proto['uiType']>;
20
+ upsertAll: BodyApi<Proto['dbType'][], Proto['uiType'][]>;
21
+ patch: BodyApi<Proto['dbType'], Proto['uiType']>;
22
+ delete: QueryApi<Proto['dbType'], DB_BaseObject>;
23
+ deleteQuery: BodyApi<Proto['dbType'][], FirestoreQuery<Proto['dbType']>>;
24
+ deleteAll: QueryApi<void>;
25
+ metadata: QueryApi<Metadata<Proto['dbType']>>;
26
+ };
27
+ };
28
+ export type ApiStruct_DBApiGenIDBV3<Proto extends DBProto<any>> = {
29
+ v1: {
30
+ query: BodyApi<Proto['dbType'][], FirestoreQuery<Proto['dbType']>>;
31
+ queryUnique: QueryApi<Proto['dbType'], DB_BaseObject, ResponseError<string, any>, string | IndexKeys<Proto['dbType'], keyof Proto['dbType']>>;
32
+ upsert: BodyApi<Proto['dbType'], Proto['uiType']>;
33
+ upsertAll: BodyApi<Proto['dbType'][], Proto['uiType'][]>;
34
+ patch: BodyApi<Proto['dbType'], IndexKeys<Proto['dbType'], keyof Proto['dbType']> & Partial<Proto['dbType']>>;
35
+ delete: QueryApi<Proto['dbType'] | undefined, DB_BaseObject, EntityDependencyError>;
36
+ deleteQuery: BodyApi<Proto['dbType'][], FirestoreQuery<Proto['dbType']>>;
37
+ deleteAll: QueryApi<Proto['dbType'][]>;
38
+ metadata: QueryApi<Metadata<Proto['dbType']>>;
39
+ };
40
+ };
41
+ export declare const DBApiDefGeneratorV3: <Proto extends DBProto<any>>(dbDef: DBDef_V3<Proto>, version?: string) => ApiDefResolver<ApiStruct_DBApiGenV3<Proto>>;
42
+ export declare const DBApiDefGeneratorIDBV3: <Proto extends DBProto<any>>(dbDef: DBDef_V3<Proto>, version?: string) => ApiDefResolver<ApiStruct_DBApiGenIDBV3<Proto>>;
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Database API Generator is a utility library for Thunderstorm.
3
+ *
4
+ * Given proper configurations it will dynamically generate APIs to your Firestore
5
+ * collections, will assert uniqueness and restrict deletion... and more
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 DBApiDefGeneratorV3 = (dbDef, version = 'v1') => {
23
+ return {
24
+ v1: {
25
+ query: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/query`, timeout: 60000 },
26
+ queryUnique: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/query-unique` },
27
+ upsert: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert` },
28
+ upsertAll: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert-all` },
29
+ patch: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/patch` },
30
+ delete: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-unique` },
31
+ deleteQuery: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/delete` },
32
+ deleteAll: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-all` },
33
+ metadata: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/metadata` },
34
+ }
35
+ };
36
+ };
37
+ export const DBApiDefGeneratorIDBV3 = (dbDef, version = 'v1') => {
38
+ return {
39
+ v1: {
40
+ query: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/query`, timeout: 60000 },
41
+ queryUnique: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/query-unique` },
42
+ upsert: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert` },
43
+ upsertAll: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/upsert-all` },
44
+ patch: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/patch` },
45
+ delete: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-unique` },
46
+ deleteQuery: { method: HttpMethod.POST, path: `${version}/${dbDef.dbKey}/delete` },
47
+ deleteAll: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/delete-all` },
48
+ metadata: { method: HttpMethod.GET, path: `${version}/${dbDef.dbKey}/metadata` },
49
+ }
50
+ };
51
+ };