@roit/roit-data-firestore 1.0.11 → 1.2.0
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/.github/workflows/deploy.yml +78 -0
- package/package.json +55 -55
- package/dist/cache/CacheResolver.d.ts +0 -15
- package/dist/cache/CacheResolver.js +0 -88
- package/dist/cache/providers/CacheProvider.d.ts +0 -6
- package/dist/cache/providers/CacheProvider.js +0 -2
- package/dist/cache/providers/InMemoryCacheProvider.d.ts +0 -8
- package/dist/cache/providers/InMemoryCacheProvider.js +0 -46
- package/dist/cache/providers/RedisCacheProvider.d.ts +0 -18
- package/dist/cache/providers/RedisCacheProvider.js +0 -117
- package/dist/cache/providers/index.d.ts +0 -2
- package/dist/cache/providers/index.js +0 -5
- package/dist/config/BaseRepository.d.ts +0 -38
- package/dist/config/BaseRepository.js +0 -70
- package/dist/config/ClassCollectionMap.d.ts +0 -7
- package/dist/config/ClassCollectionMap.js +0 -16
- package/dist/config/ClassMethodQueryMap.d.ts +0 -11
- package/dist/config/ClassMethodQueryMap.js +0 -31
- package/dist/config/FirestoreInstance.d.ts +0 -7
- package/dist/config/FirestoreInstance.js +0 -31
- package/dist/config/ReadonlyRepository.d.ts +0 -9
- package/dist/config/ReadonlyRepository.js +0 -46
- package/dist/decorators/Cacheable.d.ts +0 -2
- package/dist/decorators/Cacheable.js +0 -11
- package/dist/decorators/Query.d.ts +0 -6
- package/dist/decorators/Query.js +0 -19
- package/dist/decorators/Repository.d.ts +0 -2
- package/dist/decorators/Repository.js +0 -39
- package/dist/emulator/FirestoreEmuator.d.ts +0 -1
- package/dist/emulator/FirestoreEmuator.js +0 -26
- package/dist/exception/RepositoryBusinessException.d.ts +0 -4
- package/dist/exception/RepositoryBusinessException.js +0 -10
- package/dist/exception/RepositoryException.d.ts +0 -14
- package/dist/exception/RepositoryException.js +0 -23
- package/dist/exception/RepositorySystemException.d.ts +0 -4
- package/dist/exception/RepositorySystemException.js +0 -10
- package/dist/exception/RepositoryValidationException.d.ts +0 -5
- package/dist/exception/RepositoryValidationException.js +0 -10
- package/dist/exception/handle/ValidatorDataHandle.d.ts +0 -6
- package/dist/exception/handle/ValidatorDataHandle.js +0 -56
- package/dist/firestore-read-audit/FirestoreReadAuditResolver.d.ts +0 -10
- package/dist/firestore-read-audit/FirestoreReadAuditResolver.js +0 -50
- package/dist/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.d.ts +0 -13
- package/dist/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.js +0 -111
- package/dist/firestore-read-audit/providers/FirestoreReadAuditProvider.d.ts +0 -4
- package/dist/firestore-read-audit/providers/FirestoreReadAuditProvider.js +0 -2
- package/dist/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.d.ts +0 -9
- package/dist/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.js +0 -59
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -35
- package/dist/model/CacheProviders.d.ts +0 -4
- package/dist/model/CacheProviders.js +0 -8
- package/dist/model/CacheableOptions.d.ts +0 -13
- package/dist/model/CacheableOptions.js +0 -20
- package/dist/model/MQuery.d.ts +0 -23
- package/dist/model/MQuery.js +0 -27
- package/dist/model/Paging.d.ts +0 -7
- package/dist/model/Paging.js +0 -12
- package/dist/model/PersistFirestoreReadProps.d.ts +0 -19
- package/dist/model/PersistFirestoreReadProps.js +0 -2
- package/dist/model/QueryPredicate.d.ts +0 -6
- package/dist/model/QueryPredicate.js +0 -6
- package/dist/model/QueryResult.d.ts +0 -4
- package/dist/model/QueryResult.js +0 -6
- package/dist/model/RepositoryOptions.d.ts +0 -13
- package/dist/model/RepositoryOptions.js +0 -12
- package/dist/model/index.d.ts +0 -7
- package/dist/model/index.js +0 -19
- package/dist/platform/PlatformTools.d.ts +0 -3
- package/dist/platform/PlatformTools.js +0 -46
- package/dist/query/ManualQueryHelper.d.ts +0 -9
- package/dist/query/ManualQueryHelper.js +0 -126
- package/dist/query/QueryCreatorConfig.d.ts +0 -9
- package/dist/query/QueryCreatorConfig.js +0 -40
- package/dist/query/QueryPredicateFunctionTransform.d.ts +0 -10
- package/dist/query/QueryPredicateFunctionTransform.js +0 -87
- package/dist/query/TransformMethodFromQuery.d.ts +0 -6
- package/dist/query/TransformMethodFromQuery.js +0 -38
- package/dist/query/operator/CreateFunction.d.ts +0 -13
- package/dist/query/operator/CreateFunction.js +0 -307
- package/dist/query/operator/OperatorMap.d.ts +0 -1
- package/dist/query/operator/OperatorMap.js +0 -62
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/util/EnvironmentUtil.d.ts +0 -3
- package/dist/util/EnvironmentUtil.js +0 -10
- package/dist/util/TemplateLoading.d.ts +0 -4
- package/dist/util/TemplateLoading.js +0 -30
- package/dist/util/TtlBuilderUtil.d.ts +0 -3
- package/dist/util/TtlBuilderUtil.js +0 -21
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Versioning & deploy
|
|
2
|
+
on:
|
|
3
|
+
pull_request_target:
|
|
4
|
+
branches:
|
|
5
|
+
- master
|
|
6
|
+
types:
|
|
7
|
+
- closed
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
version:
|
|
11
|
+
if: github.event.pull_request.merged == true
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
outputs:
|
|
14
|
+
NEW_TAG: ${{ steps.version.outputs.version }}
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v2
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
|
|
21
|
+
- name: config user
|
|
22
|
+
run: |
|
|
23
|
+
git config user.email "devops@roit.com.br"
|
|
24
|
+
git config user.name "Squad DevOps"
|
|
25
|
+
|
|
26
|
+
- name: Version
|
|
27
|
+
uses: paulhatch/semantic-version@v5.3.0
|
|
28
|
+
id: version
|
|
29
|
+
with:
|
|
30
|
+
tag_prefix: "v"
|
|
31
|
+
major_pattern: "(MAJOR)"
|
|
32
|
+
minor_pattern: "(MINOR)"
|
|
33
|
+
|
|
34
|
+
- uses: jossef/action-set-json-field@v2.1
|
|
35
|
+
with:
|
|
36
|
+
file: package.json
|
|
37
|
+
field: version
|
|
38
|
+
value: ${{ steps.version.outputs.version }}
|
|
39
|
+
|
|
40
|
+
- name: updated package & add tag
|
|
41
|
+
run: |
|
|
42
|
+
echo "$NEW_TAG"
|
|
43
|
+
git add package.json
|
|
44
|
+
git commit -m "chore(update-package): update version in package to $NEW_TAG"
|
|
45
|
+
git push origin master
|
|
46
|
+
git tag -a $NEW_TAG -m "new version $NEW_TAG"
|
|
47
|
+
git push origin $NEW_TAG
|
|
48
|
+
env:
|
|
49
|
+
NEW_TAG: v${{ steps.version.outputs.version }}
|
|
50
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
51
|
+
|
|
52
|
+
- name: Create Release
|
|
53
|
+
id: create_release
|
|
54
|
+
uses: actions/create-release@v1
|
|
55
|
+
env:
|
|
56
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
57
|
+
NEW_TAG: v${{ steps.version.outputs.version }}
|
|
58
|
+
with:
|
|
59
|
+
tag_name: ${{ env.NEW_TAG }}
|
|
60
|
+
release_name: ${{ env.NEW_TAG }}
|
|
61
|
+
body: |
|
|
62
|
+
release create from actions
|
|
63
|
+
build:
|
|
64
|
+
needs: version
|
|
65
|
+
runs-on: ubuntu-latest
|
|
66
|
+
steps:
|
|
67
|
+
- uses: actions/checkout@v2
|
|
68
|
+
with:
|
|
69
|
+
ref: v${{ needs.version.outputs.NEW_TAG }}
|
|
70
|
+
- run: jq '.version' package.json
|
|
71
|
+
- uses: actions/setup-node@v3
|
|
72
|
+
with:
|
|
73
|
+
node-version: '18.x'
|
|
74
|
+
registry-url: 'https://registry.npmjs.org'
|
|
75
|
+
- run: npm ci
|
|
76
|
+
- run: npm publish
|
|
77
|
+
env:
|
|
78
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/package.json
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
"name": "@roit/roit-data-firestore",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "src/index.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc --incremental -p tsconfig.build.json",
|
|
8
|
+
"deploy": "npm run build && npm test && npm publish --access public --scope=roit",
|
|
9
|
+
"test": "jest --passWithNoTests"
|
|
10
|
+
},
|
|
11
|
+
"author": "Author",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@google-cloud/bigquery": "6.0.3",
|
|
14
|
+
"@google-cloud/pubsub": "3.3.0",
|
|
15
|
+
"@types/jest": "^27.0.2",
|
|
16
|
+
"@types/node": "^6.0.46",
|
|
17
|
+
"@types/shelljs": "^0.8.9",
|
|
18
|
+
"@types/uuid": "^8.3.1",
|
|
19
|
+
"jest": "^27.3.1",
|
|
20
|
+
"redis": "4.0.6",
|
|
21
|
+
"ts-jest": "^27.0.7",
|
|
22
|
+
"ts-node": "^8.3.0",
|
|
23
|
+
"typescript": "4.4.4"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@google-cloud/firestore": "6.5.0",
|
|
27
|
+
"@roit/roit-date": "1.10.5",
|
|
28
|
+
"class-validator": "0.14.0",
|
|
29
|
+
"class-validator-jsonschema": "5.0.0",
|
|
30
|
+
"date-fns": "2.30.0",
|
|
31
|
+
"firebase": "^9.2.0",
|
|
32
|
+
"node-cache": "5.1.2",
|
|
33
|
+
"reflect-metadata": "0.1.13",
|
|
34
|
+
"roit-environment": "1.1.2",
|
|
35
|
+
"shelljs": "^0.8.4",
|
|
36
|
+
"uuid": "^8.3.2"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/roitinnovation/roit-data-firestore.git"
|
|
41
|
+
},
|
|
42
|
+
"jest": {
|
|
43
|
+
"moduleFileExtensions": [
|
|
44
|
+
"js",
|
|
45
|
+
"json",
|
|
46
|
+
"ts"
|
|
47
|
+
],
|
|
48
|
+
"rootDir": ".",
|
|
49
|
+
"testRegex": ".(spec|test).ts$",
|
|
50
|
+
"transform": {
|
|
51
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
10
52
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"@types/node": "^6.0.46",
|
|
17
|
-
"@types/shelljs": "^0.8.9",
|
|
18
|
-
"@types/uuid": "^8.3.1",
|
|
19
|
-
"jest": "^27.3.1",
|
|
20
|
-
"redis": "4.0.6",
|
|
21
|
-
"ts-jest": "^27.0.7",
|
|
22
|
-
"ts-node": "^8.3.0",
|
|
23
|
-
"typescript": "4.4.4"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@google-cloud/firestore": "6.5.0",
|
|
27
|
-
"@roit/roit-date": "1.10.5",
|
|
28
|
-
"class-validator": "0.14.0",
|
|
29
|
-
"class-validator-jsonschema": "5.0.0",
|
|
30
|
-
"date-fns": "2.30.0",
|
|
31
|
-
"firebase": "^9.2.0",
|
|
32
|
-
"node-cache": "5.1.2",
|
|
33
|
-
"reflect-metadata": "0.1.13",
|
|
34
|
-
"roit-environment": "1.1.2",
|
|
35
|
-
"shelljs": "^0.8.4",
|
|
36
|
-
"uuid": "^8.3.2"
|
|
37
|
-
},
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/roitinnovation/roit-data-firestore.git"
|
|
41
|
-
},
|
|
42
|
-
"jest": {
|
|
43
|
-
"moduleFileExtensions": [
|
|
44
|
-
"js",
|
|
45
|
-
"json",
|
|
46
|
-
"ts"
|
|
47
|
-
],
|
|
48
|
-
"rootDir": ".",
|
|
49
|
-
"testRegex": ".(spec|test).ts$",
|
|
50
|
-
"transform": {
|
|
51
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
52
|
-
},
|
|
53
|
-
"coverageDirectory": "../coverage",
|
|
54
|
-
"testEnvironment": "node"
|
|
55
|
-
},
|
|
56
|
-
"keywords": []
|
|
57
|
-
}
|
|
53
|
+
"coverageDirectory": "../coverage",
|
|
54
|
+
"testEnvironment": "node"
|
|
55
|
+
},
|
|
56
|
+
"keywords": []
|
|
57
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CacheableOptions } from "../model/CacheableOptions";
|
|
2
|
-
export declare class CacheResolver {
|
|
3
|
-
private static instance;
|
|
4
|
-
private repositorys;
|
|
5
|
-
private providersImplMap;
|
|
6
|
-
private cacheProvider;
|
|
7
|
-
private constructor();
|
|
8
|
-
static getInstance(): CacheResolver;
|
|
9
|
-
addRepository(repository: string, option?: CacheableOptions): void;
|
|
10
|
-
private buildKey;
|
|
11
|
-
buildRepositoryKey(repositoryClassName: string): string;
|
|
12
|
-
getCacheResult(repositoryClassName: string, methodSignature: string, ...paramValue: any[]): Promise<any | null | any[]>;
|
|
13
|
-
revokeCacheFromRepository(repositoryClassName: string): Promise<void>;
|
|
14
|
-
cacheResult(repositoryClassName: string, methodSignature: string, valueToCache: any, ...paramValue: any[]): Promise<boolean>;
|
|
15
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CacheResolver = void 0;
|
|
13
|
-
const CacheableOptions_1 = require("../model/CacheableOptions");
|
|
14
|
-
const providers_1 = require("./providers");
|
|
15
|
-
const roit_environment_1 = require("roit-environment");
|
|
16
|
-
const RedisCacheProvider_1 = require("./providers/RedisCacheProvider");
|
|
17
|
-
const CacheProviders_1 = require("../model/CacheProviders");
|
|
18
|
-
class CacheResolver {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.repositorys = new Map;
|
|
21
|
-
this.providersImplMap = new Map;
|
|
22
|
-
this.providersImplMap.set(CacheProviders_1.CacheProviders.LOCAL, providers_1.InMemoryCacheProvider);
|
|
23
|
-
this.providersImplMap.set(CacheProviders_1.CacheProviders.REDIS, RedisCacheProvider_1.RedisCacheProvider);
|
|
24
|
-
}
|
|
25
|
-
static getInstance() {
|
|
26
|
-
return this.instance;
|
|
27
|
-
}
|
|
28
|
-
addRepository(repository, option) {
|
|
29
|
-
const options = option || new CacheableOptions_1.CacheableOptions;
|
|
30
|
-
const implementation = options.cacheProvider || CacheProviders_1.CacheProviders.LOCAL;
|
|
31
|
-
const providerImpl = this.providersImplMap.get(implementation);
|
|
32
|
-
this.cacheProvider = new providerImpl();
|
|
33
|
-
this.repositorys.set(repository, options);
|
|
34
|
-
}
|
|
35
|
-
buildKey(repositoryClassName, methodSignature, ...paramValue) {
|
|
36
|
-
return `${roit_environment_1.Environment.currentEnv()}:${repositoryClassName}:${methodSignature}:${paramValue.join(',')}`;
|
|
37
|
-
}
|
|
38
|
-
buildRepositoryKey(repositoryClassName) {
|
|
39
|
-
return `${roit_environment_1.Environment.currentEnv()}:${repositoryClassName}`;
|
|
40
|
-
}
|
|
41
|
-
getCacheResult(repositoryClassName, methodSignature, ...paramValue) {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
if (!this.repositorys.get(repositoryClassName)) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const key = this.buildKey(repositoryClassName, methodSignature, paramValue);
|
|
47
|
-
return this.cacheProvider.getCacheResult(key);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
revokeCacheFromRepository(repositoryClassName) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const key = this.buildRepositoryKey(repositoryClassName);
|
|
53
|
-
if (!this.repositorys.get(repositoryClassName)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const keys = yield this.cacheProvider.getKeys(`${key}`);
|
|
57
|
-
if (keys && Array.isArray(keys)) {
|
|
58
|
-
for (const key of keys) {
|
|
59
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
60
|
-
console.debug('[DEBUG] Caching >', `Removing key: ${key}`);
|
|
61
|
-
}
|
|
62
|
-
yield this.cacheProvider.delete(key);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
yield this.cacheProvider.delete(key);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
cacheResult(repositoryClassName, methodSignature, valueToCache, ...paramValue) {
|
|
69
|
-
var _a, _b, _c;
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const option = this.repositorys.get(repositoryClassName);
|
|
72
|
-
if (option) {
|
|
73
|
-
const key = this.buildKey(repositoryClassName, methodSignature, paramValue);
|
|
74
|
-
const excludesMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.excludesMethods) && ((_a = option === null || option === void 0 ? void 0 : option.excludesMethods) === null || _a === void 0 ? void 0 : _a.find(me => me == methodSignature));
|
|
75
|
-
const notIncludeOnlyMethod = Array.isArray(option === null || option === void 0 ? void 0 : option.includeOnlyMethods) && ((_b = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _b === void 0 ? void 0 : _b.length) > 0 && ((_c = option === null || option === void 0 ? void 0 : option.includeOnlyMethods) === null || _c === void 0 ? void 0 : _c.find(me => me == methodSignature)) == undefined;
|
|
76
|
-
const notContainResult = (option === null || option === void 0 ? void 0 : option.cacheOnlyContainResults) ? ((Array.isArray(valueToCache) && valueToCache.length == 0) || !valueToCache) : false;
|
|
77
|
-
if (excludesMethod || notIncludeOnlyMethod || notContainResult) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
yield this.cacheProvider.saveCacheResult(key, valueToCache, option.cacheExpiresInSeconds);
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.CacheResolver = CacheResolver;
|
|
88
|
-
CacheResolver.instance = new CacheResolver;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export interface CacheProvider {
|
|
2
|
-
getCacheResult(key: string): Promise<any | null | any[]>;
|
|
3
|
-
getKeys(query: string): Promise<string[]>;
|
|
4
|
-
saveCacheResult(key: string, valueToCache: any, ttl: number | undefined): Promise<void>;
|
|
5
|
-
delete(key: string): Promise<void>;
|
|
6
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CacheProvider } from "./CacheProvider";
|
|
2
|
-
export declare class InMemoryCacheProvider implements CacheProvider {
|
|
3
|
-
private cache;
|
|
4
|
-
getCacheResult(key: string): Promise<any | null>;
|
|
5
|
-
getKeys(query: string): Promise<string[]>;
|
|
6
|
-
saveCacheResult(key: string, valueToCache: any, ttl: number): Promise<void>;
|
|
7
|
-
delete(key: string): Promise<void>;
|
|
8
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.InMemoryCacheProvider = void 0;
|
|
7
|
-
const roit_environment_1 = require("roit-environment");
|
|
8
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
-
class InMemoryCacheProvider {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.cache = new node_cache_1.default();
|
|
12
|
-
}
|
|
13
|
-
getCacheResult(key) {
|
|
14
|
-
const result = this.cache.get(key);
|
|
15
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
16
|
-
if (result) {
|
|
17
|
-
console.debug('[DEBUG] Memory Caching >', `Return value in cache from key: ${key}`);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
console.log("[DEBUG] Memory Caching > ", `Key [${key}] is not found in the cache`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return Promise.resolve(result);
|
|
24
|
-
}
|
|
25
|
-
getKeys(query) {
|
|
26
|
-
try {
|
|
27
|
-
return Promise.resolve(this.cache.keys().filter(key => key.includes(query)));
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
console.log(`[DEBUG] Memory Caching > Error when getting KEYS with query: ${query}, error: ${error}`);
|
|
31
|
-
}
|
|
32
|
-
return Promise.resolve([]);
|
|
33
|
-
}
|
|
34
|
-
saveCacheResult(key, valueToCache, ttl) {
|
|
35
|
-
this.cache.set(key, valueToCache, ttl || 0);
|
|
36
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
37
|
-
console.debug('[DEBUG] Memory Caching >', `Storage cache from key: ${key}`);
|
|
38
|
-
}
|
|
39
|
-
return Promise.resolve();
|
|
40
|
-
}
|
|
41
|
-
delete(key) {
|
|
42
|
-
this.cache.del(key);
|
|
43
|
-
return Promise.resolve();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.InMemoryCacheProvider = InMemoryCacheProvider;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { CacheProvider } from "./CacheProvider";
|
|
2
|
-
export declare class RedisCacheProvider implements CacheProvider {
|
|
3
|
-
/**
|
|
4
|
-
* Redis module instance loaded dynamically.
|
|
5
|
-
*/
|
|
6
|
-
private redis;
|
|
7
|
-
/**
|
|
8
|
-
* Connected redis client.
|
|
9
|
-
*/
|
|
10
|
-
private client;
|
|
11
|
-
private isRedisReady;
|
|
12
|
-
constructor();
|
|
13
|
-
getKeys(query: string): Promise<string[]>;
|
|
14
|
-
getCacheResult(key: string): Promise<any | null>;
|
|
15
|
-
saveCacheResult(key: string, valueToCache: any, ttl: number | undefined): Promise<void>;
|
|
16
|
-
delete(key: string): Promise<void>;
|
|
17
|
-
private loadRedis;
|
|
18
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RedisCacheProvider = void 0;
|
|
13
|
-
const roit_environment_1 = require("roit-environment");
|
|
14
|
-
const PlatformTools_1 = require("../../platform/PlatformTools");
|
|
15
|
-
class RedisCacheProvider {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.isRedisReady = false;
|
|
18
|
-
if (!this.redis) {
|
|
19
|
-
const url = roit_environment_1.Environment.getProperty('firestore.cache.redisUrl');
|
|
20
|
-
if (!url) {
|
|
21
|
-
console.error(`[ERROR] Redis Caching > environtment variable "firestore.cache.redisUrl" was not found!`);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const isJest = typeof jest !== 'undefined';
|
|
25
|
-
if (isJest) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
this.redis = this.loadRedis();
|
|
29
|
-
this.client = this.redis.createClient({ url });
|
|
30
|
-
this.client.on('error', (err) => {
|
|
31
|
-
this.isRedisReady = false;
|
|
32
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
33
|
-
console.warn('[WARN] Redis error', err);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
this.client.on('ready', () => {
|
|
37
|
-
this.isRedisReady = true;
|
|
38
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
39
|
-
console.log('[DEBUG] Redis Caching > Redis is ready');
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
this.client.connect();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
getKeys(query) {
|
|
46
|
-
try {
|
|
47
|
-
if (this.isRedisReady) {
|
|
48
|
-
return this.client.KEYS(`*${query}*`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.log(`[DEBUG] Redis Caching > Error when getting KEYS with query: ${query}, error: ${error}`);
|
|
53
|
-
}
|
|
54
|
-
return Promise.resolve([]);
|
|
55
|
-
}
|
|
56
|
-
getCacheResult(key) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
try {
|
|
59
|
-
if (this.isRedisReady) {
|
|
60
|
-
const result = yield this.client.get(key);
|
|
61
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
62
|
-
if (result) {
|
|
63
|
-
console.debug('[DEBUG] Redis Caching >', `Return value in cache from key: ${key}`);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
console.log("[DEBUG] Redis Caching > ", `Key [${key}] is not found in the cache`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (result) {
|
|
70
|
-
return JSON.parse(result);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
saveCacheResult(key, valueToCache, ttl) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
if (this.isRedisReady) {
|
|
82
|
-
try {
|
|
83
|
-
yield this.client.set(key, JSON.stringify(valueToCache), {
|
|
84
|
-
EX: ttl || 0
|
|
85
|
-
});
|
|
86
|
-
if (Boolean(roit_environment_1.Environment.getProperty('firestore.debug'))) {
|
|
87
|
-
console.debug('[DEBUG] Caching >', `Storage cache from key: ${key}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
console.log(`[DEBUG] Redis Caching > Error when saving cache. Key: ${key}, value: ${valueToCache}, error: ${error}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
delete(key) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
try {
|
|
99
|
-
if (this.isRedisReady) {
|
|
100
|
-
yield this.client.del(key);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
console.log(`[DEBUG] Redis Caching > Error when deleting key from redis. ${key}`);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
loadRedis() {
|
|
109
|
-
try {
|
|
110
|
-
return PlatformTools_1.PlatformTools.load("redis");
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
throw new Error(`Cannot use cache because redis is not installed. Please run "npm i redis@4.0.6 --save-exact".`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.RedisCacheProvider = RedisCacheProvider;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryCacheProvider = void 0;
|
|
4
|
-
var InMemoryCacheProvider_1 = require("./InMemoryCacheProvider");
|
|
5
|
-
Object.defineProperty(exports, "InMemoryCacheProvider", { enumerable: true, get: function () { return InMemoryCacheProvider_1.InMemoryCacheProvider; } });
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { QueryResult } from "../model";
|
|
2
|
-
import { Config } from '../model/MQuery';
|
|
3
|
-
import { Paging } from "../model/Paging";
|
|
4
|
-
export declare abstract class BaseRepository<T> {
|
|
5
|
-
/**
|
|
6
|
-
* FindAll
|
|
7
|
-
* Get all available records in the collection
|
|
8
|
-
* @param paging
|
|
9
|
-
*/
|
|
10
|
-
findAll: (paging?: Paging) => Promise<T[]>;
|
|
11
|
-
/**
|
|
12
|
-
* FindById
|
|
13
|
-
* Get registe
|
|
14
|
-
*/
|
|
15
|
-
findById: (id: Required<string>) => Promise<T | undefined>;
|
|
16
|
-
create: (item: T | Array<T>) => Promise<Array<T>>;
|
|
17
|
-
update: (items: T | Array<T>) => Promise<Array<T>>;
|
|
18
|
-
createOrUpdate: (items: T | Array<T>) => Promise<Array<T>>;
|
|
19
|
-
/**
|
|
20
|
-
* Update partial data
|
|
21
|
-
*/
|
|
22
|
-
updatePartial: (id: Required<string>, itemPartial: Partial<T>) => Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Delete Row or Rows in bath
|
|
25
|
-
* @param id
|
|
26
|
-
*/
|
|
27
|
-
delete: (id: Required<string> | Array<string>) => Promise<Array<string>>;
|
|
28
|
-
/**
|
|
29
|
-
* Distributed counters
|
|
30
|
-
* https://firebase.google.com/docs/firestore/solutions/counters#web
|
|
31
|
-
*
|
|
32
|
-
* @param field field from increment
|
|
33
|
-
* @param increment value increment, default value 1
|
|
34
|
-
*/
|
|
35
|
-
incrementField: (id: Required<string>, field: Required<string>, increment?: number) => Promise<void>;
|
|
36
|
-
query(config: Config): Promise<T[]>;
|
|
37
|
-
queryPaginated(config: Config): Promise<QueryResult<T>>;
|
|
38
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.BaseRepository = void 0;
|
|
22
|
-
const Query_1 = require("../decorators/Query");
|
|
23
|
-
const ManualQueryHelper_1 = require("../query/ManualQueryHelper");
|
|
24
|
-
class BaseRepository {
|
|
25
|
-
query(config) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const className = this.constructor.prototype.constructor.name;
|
|
28
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
queryPaginated(config) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const className = this.constructor.prototype.constructor.name;
|
|
34
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
__decorate([
|
|
39
|
-
(0, Query_1.Query)(),
|
|
40
|
-
__metadata("design:type", Function)
|
|
41
|
-
], BaseRepository.prototype, "findAll", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
(0, Query_1.Query)(),
|
|
44
|
-
__metadata("design:type", Function)
|
|
45
|
-
], BaseRepository.prototype, "findById", void 0);
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, Query_1.Query)(),
|
|
48
|
-
__metadata("design:type", Function)
|
|
49
|
-
], BaseRepository.prototype, "create", void 0);
|
|
50
|
-
__decorate([
|
|
51
|
-
(0, Query_1.Query)(),
|
|
52
|
-
__metadata("design:type", Function)
|
|
53
|
-
], BaseRepository.prototype, "update", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
(0, Query_1.Query)(),
|
|
56
|
-
__metadata("design:type", Function)
|
|
57
|
-
], BaseRepository.prototype, "createOrUpdate", void 0);
|
|
58
|
-
__decorate([
|
|
59
|
-
(0, Query_1.Query)(),
|
|
60
|
-
__metadata("design:type", Function)
|
|
61
|
-
], BaseRepository.prototype, "updatePartial", void 0);
|
|
62
|
-
__decorate([
|
|
63
|
-
(0, Query_1.Query)(),
|
|
64
|
-
__metadata("design:type", Function)
|
|
65
|
-
], BaseRepository.prototype, "delete", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
(0, Query_1.Query)(),
|
|
68
|
-
__metadata("design:type", Function)
|
|
69
|
-
], BaseRepository.prototype, "incrementField", void 0);
|
|
70
|
-
exports.BaseRepository = BaseRepository;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClassCollectionMap = void 0;
|
|
4
|
-
class ClassCollectionMap {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.classMap = new Map;
|
|
7
|
-
}
|
|
8
|
-
register(className, collection) {
|
|
9
|
-
this.classMap.set(className, collection);
|
|
10
|
-
}
|
|
11
|
-
static getInstance() {
|
|
12
|
-
return this.instance;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.ClassCollectionMap = ClassCollectionMap;
|
|
16
|
-
ClassCollectionMap.instance = new ClassCollectionMap;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { QueryOptions } from '../decorators/Query';
|
|
2
|
-
export declare class ClassMethodQueryMap {
|
|
3
|
-
private static instance;
|
|
4
|
-
private collectionMap;
|
|
5
|
-
private queryConfig;
|
|
6
|
-
constructor();
|
|
7
|
-
register(className: string, methodSignature: string, options?: QueryOptions): void;
|
|
8
|
-
get(className: string): Array<string> | undefined;
|
|
9
|
-
getMethodConfig(className: string, methodSignature: string): QueryOptions | undefined;
|
|
10
|
-
static getInstance(): ClassMethodQueryMap;
|
|
11
|
-
}
|