@nu-art/firebase-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.
package/consts.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const _EmptyQuery: Readonly<{
2
+ where: {};
3
+ }>;
4
+ export declare const maxBatch = 500;
package/consts.js ADDED
@@ -0,0 +1,2 @@
1
+ export const _EmptyQuery = Object.freeze({ where: {} });
2
+ export const maxBatch = 500;
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './consts.js';
2
+ export * from './types.js';
3
+ export * from './utils.js';
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './consts.js';
2
+ export * from './types.js';
3
+ export * from './utils.js';
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@nu-art/firebase-shared",
3
+ "version": "0.400.5",
4
+ "description": "Storm - Express & Typescript based backend framework Shared",
5
+ "keywords": [
6
+ "TacB0sS",
7
+ "infra",
8
+ "nu-art",
9
+ "storm",
10
+ "thunderstorm",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/nu-art-js/firebase",
14
+ "bugs": {
15
+ "url": "https://github.com/nu-art-js/firebase/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+ssh://git@github.com:nu-art-js/firebase.git"
20
+ },
21
+ "publishConfig": {
22
+ "directory": "dist",
23
+ "linkDirectory": true
24
+ },
25
+ "license": "Apache-2.0",
26
+ "author": "TacB0sS",
27
+ "files": [
28
+ "**/*"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc",
32
+ "run-tests": "firebase emulators:exec \"npm run test\"",
33
+ "test": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files '**/*.ts' src/test/firestore-v2/__test.ts",
34
+ "rtv2": "firebase emulators:exec \"npm run test-v2\"",
35
+ "test-v2": "ts-mocha -w -p src/test/tsconfig.json --timeout 0 --inspect=8107 --watch-files '**/*.ts' src/test/firestore-v2/__test.ts"
36
+ },
37
+ "dependencies": {
38
+ "@nu-art/ts-common": "0.400.5",
39
+ "@google-cloud/common": "^5.0.2",
40
+ "@google-cloud/storage": "^7.15.0",
41
+ "@google-cloud/firestore": "^7.11.0",
42
+ "google-auth-library": "^10.0.0",
43
+ "express": "^4.18.2",
44
+ "firebase": "^11.9.0",
45
+ "firebase-admin": "13.4.0",
46
+ "firebase-functions": "6.3.2",
47
+ "ws": "^8.13.0",
48
+ "http-proxy": "1.18.1",
49
+ "url": "0.11.3"
50
+ },
51
+ "devDependencies": {
52
+ "@types/compression": "^1.0.1",
53
+ "@types/chai": "^4.3.4",
54
+ "@types/mocha": "^10.0.1",
55
+ "@types/http-proxy": "1.17.14",
56
+ "teeny-request": "~7.2.0",
57
+ "@types/ws": "^8.5.5"
58
+ },
59
+ "unitConfig": {
60
+ "type": "typescript-lib"
61
+ },
62
+ "type": "module",
63
+ "exports": {
64
+ ".": {
65
+ "types": "./index.d.ts",
66
+ "import": "./index.js"
67
+ },
68
+ "./*": {
69
+ "types": "./*.d.ts",
70
+ "import": "./*.js"
71
+ }
72
+ }
73
+ }
package/types.d.ts ADDED
@@ -0,0 +1,105 @@
1
+ import { MandatoryKeys, RequireOptionals, TS_Object, UniqueId } from '@nu-art/ts-common';
2
+ import { ResponseError } from '@nu-art/ts-common/core/exceptions/types';
3
+ /**
4
+ * Test test
5
+ * token: pah
6
+ */
7
+ export type Firebase_Message = {
8
+ token?: string;
9
+ topic?: string;
10
+ condition?: string;
11
+ };
12
+ export interface Firebase_Messaging {
13
+ send(message: Firebase_Message, dryRun?: boolean): Promise<string>;
14
+ }
15
+ export type FirebaseConfig = {
16
+ id: string;
17
+ projectId: string;
18
+ apiKey: string;
19
+ authDomain: string;
20
+ databaseURL?: string;
21
+ storageBucket?: string;
22
+ messagingSenderId: string;
23
+ local?: boolean;
24
+ };
25
+ type Comparator = 'in' | 'array-contains' | 'array-contains-any' | '>' | '>=' | '<' | '<=' | '==';
26
+ export type QueryComparator<T> = {
27
+ $ac: T extends (infer I)[] ? I : never;
28
+ } | {
29
+ $aca: T extends (infer I)[] ? I[] : never;
30
+ } | {
31
+ $nin: T extends (any)[] ? never : T[];
32
+ } | {
33
+ $in: T extends (any)[] ? never : T[];
34
+ } | {
35
+ $gt: number;
36
+ } | {
37
+ $gte: number;
38
+ } | {
39
+ $lt: number;
40
+ } | {
41
+ $lte: number;
42
+ } | {
43
+ $eq: number;
44
+ } | {
45
+ $neq: T;
46
+ };
47
+ export declare const ComparatorMap: {
48
+ [k in keyof QueryComparator<any>]: Comparator;
49
+ };
50
+ export type FilterKeys<T extends TS_Object> = MandatoryKeys<T, string | number>[];
51
+ export type FirestoreType_OrderByDirection = 'desc' | 'asc';
52
+ export type WhereValue<Value> = QueryComparator<Value> | (Value extends TS_Object ? Clause_Where<Value> : Value | [Value]);
53
+ export type Clause_Where<T extends TS_Object> = {
54
+ [P in keyof T]?: WhereValue<T[P]>;
55
+ };
56
+ export type Clause_OrderBy<T extends TS_Object> = [{
57
+ key: keyof T;
58
+ order: FirestoreType_OrderByDirection;
59
+ }];
60
+ export type Clause_Select<T extends TS_Object, K extends keyof T = keyof T> = K[];
61
+ export type FirestoreQuery<T extends TS_Object> = RequireOptionals<FirestoreQueryImpl<T>>;
62
+ export type FirestoreQueryImpl<T extends TS_Object> = {
63
+ select?: Clause_Select<T>;
64
+ orderBy?: Clause_OrderBy<T>;
65
+ where?: Clause_Where<T>;
66
+ withDeleted?: boolean;
67
+ limit?: number | {
68
+ page?: number;
69
+ itemsCount: number;
70
+ };
71
+ };
72
+ export type FirebaseProjectCollections = {
73
+ projectId: string;
74
+ collections: string[];
75
+ };
76
+ /**
77
+ * Only for MemKey_DeletedDocs
78
+ */
79
+ export type PotentialDependenciesToDelete<Type extends string = string> = {
80
+ dbKey: Type;
81
+ ids: string[];
82
+ };
83
+ export type DB_EntityDependency<Type extends string = string> = {
84
+ collectionKey: Type;
85
+ conflictingIds: string[];
86
+ };
87
+ export type EntityRef = {
88
+ dbKey: string;
89
+ id: UniqueId;
90
+ };
91
+ export type EntityRefs = {
92
+ dbKey: string;
93
+ ids: UniqueId[];
94
+ };
95
+ export type Conflict = {
96
+ target: EntityRef;
97
+ conflicts: EntityRefs;
98
+ };
99
+ export type DB_EntityDependencyV2 = {
100
+ originalItemsToDelete: EntityRef[];
101
+ issues: Conflict[];
102
+ };
103
+ export type EntityDependencyError = ResponseError<'has-dependencies', DB_EntityDependencyV2[]>;
104
+ export type MultiWriteOperation = 'create' | 'set' | 'update' | 'delete';
105
+ export {};
package/types.js ADDED
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Firebase is a simpler Typescript wrapper to all of firebase services.
3
+ *
4
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ export const ComparatorMap = {
19
+ $nin: 'not-in',
20
+ $in: 'in',
21
+ $ac: 'array-contains',
22
+ $aca: 'array-contains-any',
23
+ $gt: '>',
24
+ $gte: '>=',
25
+ $lt: '<',
26
+ $lte: '<=',
27
+ $eq: '==',
28
+ $neq: '!=',
29
+ };
package/utils.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { DB_Object, PreDB } from "@nu-art/ts-common";
2
+ export declare const composeDbObjectUniqueId: <T extends PreDB<DB_Object>, K extends (keyof T)[]>(item: T, keys: K) => string;
package/utils.js ADDED
@@ -0,0 +1,9 @@
1
+ import { __stringify, exists, md5, MUSTNeverHappenException } from "@nu-art/ts-common";
2
+ export const composeDbObjectUniqueId = (item, keys) => {
3
+ const _unique = keys.reduce((aggregatedValues, _key) => {
4
+ if (!exists(item[_key]))
5
+ throw new MUSTNeverHappenException(`Unique key missing from db item!\nkey: ${_key}\nitem:${__stringify(item, true)}`);
6
+ return aggregatedValues + String(item[_key]);
7
+ }, '');
8
+ return md5(_unique);
9
+ };