@ruiapp/rapid-core 0.5.11 → 0.5.12
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/dist/facilities/cache/CacheFacilityTypes.d.ts +4 -2
- package/dist/facilities/cache/MemoryCache.d.ts +3 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +80 -45
- package/dist/utilities/entityUtility.d.ts +1 -0
- package/package.json +1 -1
- package/src/facilities/cache/CacheFacilityTypes.ts +4 -2
- package/src/facilities/cache/CacheFactory.ts +2 -2
- package/src/facilities/cache/MemoryCache.ts +37 -21
- package/src/index.ts +3 -0
- package/src/utilities/entityUtility.ts +18 -0
|
@@ -7,8 +7,10 @@ export interface CacheProvider {
|
|
|
7
7
|
createCache: (server: IRpdServer) => Promise<Cache>;
|
|
8
8
|
}
|
|
9
9
|
export interface Cache {
|
|
10
|
-
set: (key: string, value:
|
|
11
|
-
|
|
10
|
+
set: (key: string, value: string, options?: SetValueOptions) => Promise<void>;
|
|
11
|
+
setObject: (key: string, value: Record<string, any>, options?: SetValueOptions) => Promise<void>;
|
|
12
|
+
get: (key: string) => Promise<string | null>;
|
|
13
|
+
getObject: (key: string) => Promise<Record<string, any> | null>;
|
|
12
14
|
del: (key: string) => Promise<void>;
|
|
13
15
|
}
|
|
14
16
|
export interface SetValueOptions {
|
|
@@ -4,7 +4,9 @@ export type MemoryCacheItem<TValue = any> = {
|
|
|
4
4
|
expireAt: number;
|
|
5
5
|
};
|
|
6
6
|
export default class MemoryCache implements Cache {
|
|
7
|
-
set(key: string, value:
|
|
7
|
+
set(key: string, value: string, options?: SetValueOptions): Promise<void>;
|
|
8
|
+
setObject(key: string, value: Record<string, any>, options?: SetValueOptions): Promise<void>;
|
|
8
9
|
get(key: string): Promise<any>;
|
|
10
|
+
getObject(key: string): Promise<any>;
|
|
9
11
|
del(key: string): Promise<void>;
|
|
10
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export * from "./core/routeContext";
|
|
|
6
6
|
export * from "./core/server";
|
|
7
7
|
export * from "./core/http-types";
|
|
8
8
|
export * from "./core/actionHandler";
|
|
9
|
+
export * from "./utilities/accessControlUtility";
|
|
10
|
+
export * from "./utilities/entityUtility";
|
|
9
11
|
export * from "./utilities/jwtUtility";
|
|
12
|
+
export * from "./utilities/timeUtility";
|
|
10
13
|
export * from "./deno-std/http/cookie";
|
|
11
14
|
export { mapDbRowToEntity } from "./dataAccess/entityMapper";
|
|
12
15
|
export * as bootstrapApplicationConfig from "./bootstrapApplicationConfig";
|
package/dist/index.js
CHANGED
|
@@ -2509,6 +2509,9 @@ function getEntityPartChanges(server, model, before, after) {
|
|
|
2509
2509
|
return null;
|
|
2510
2510
|
}
|
|
2511
2511
|
|
|
2512
|
+
function getNowString() {
|
|
2513
|
+
return dayjs__default["default"]().format("YYYY-MM-DD HH:mm:ss.SSS");
|
|
2514
|
+
}
|
|
2512
2515
|
function getNowStringWithTimezone() {
|
|
2513
2516
|
return dayjs__default["default"]().format("YYYY-MM-DD HH:mm:ss.SSSZ");
|
|
2514
2517
|
}
|
|
@@ -4511,6 +4514,46 @@ class RapidServer {
|
|
|
4511
4514
|
}
|
|
4512
4515
|
}
|
|
4513
4516
|
|
|
4517
|
+
function isAccessAllowed(policy, allowedActions) {
|
|
4518
|
+
let isAnyCheckPassed = true;
|
|
4519
|
+
let isAllCheckPassed = true;
|
|
4520
|
+
if (policy.any) {
|
|
4521
|
+
isAnyCheckPassed = false;
|
|
4522
|
+
for (const action of policy.any) {
|
|
4523
|
+
if (lodash.find(allowedActions, (item) => item === action) != null) {
|
|
4524
|
+
isAnyCheckPassed = true;
|
|
4525
|
+
break;
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
}
|
|
4529
|
+
if (policy.all) {
|
|
4530
|
+
isAllCheckPassed = true;
|
|
4531
|
+
for (const action of policy.all) {
|
|
4532
|
+
if (lodash.find(allowedActions, (item) => item === action) == null) {
|
|
4533
|
+
isAnyCheckPassed = false;
|
|
4534
|
+
break;
|
|
4535
|
+
}
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
return isAnyCheckPassed && isAllCheckPassed;
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
function getEntityRelationTargetId(entity, propName, targetColumnName) {
|
|
4542
|
+
if (!entity) {
|
|
4543
|
+
throw new Error(`"entity" parameter is required.`);
|
|
4544
|
+
}
|
|
4545
|
+
let targetId = entity[propName];
|
|
4546
|
+
if (!targetId && targetColumnName) {
|
|
4547
|
+
targetId = entity[targetColumnName];
|
|
4548
|
+
}
|
|
4549
|
+
if (lodash.isObject(targetId)) {
|
|
4550
|
+
return targetId.id;
|
|
4551
|
+
}
|
|
4552
|
+
else {
|
|
4553
|
+
return targetId;
|
|
4554
|
+
}
|
|
4555
|
+
}
|
|
4556
|
+
|
|
4514
4557
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
4515
4558
|
// This module is browser compatible.
|
|
4516
4559
|
/**
|
|
@@ -4655,29 +4698,41 @@ async function generateJwtSecretKey() {
|
|
|
4655
4698
|
}
|
|
4656
4699
|
|
|
4657
4700
|
const values = new Map();
|
|
4701
|
+
async function set(key, value, options) {
|
|
4702
|
+
let expireAt = -1;
|
|
4703
|
+
if (options && options.ttl > 0) {
|
|
4704
|
+
expireAt = new Date().valueOf() + options.ttl;
|
|
4705
|
+
}
|
|
4706
|
+
const cacheItem = {
|
|
4707
|
+
value,
|
|
4708
|
+
expireAt,
|
|
4709
|
+
};
|
|
4710
|
+
values.set(key, cacheItem);
|
|
4711
|
+
}
|
|
4712
|
+
async function get(key) {
|
|
4713
|
+
const cacheItem = values.get(key);
|
|
4714
|
+
if (cacheItem) {
|
|
4715
|
+
if (cacheItem.expireAt === -1) {
|
|
4716
|
+
return cacheItem.value;
|
|
4717
|
+
}
|
|
4718
|
+
if (cacheItem.expireAt >= new Date().valueOf()) {
|
|
4719
|
+
return cacheItem.value;
|
|
4720
|
+
}
|
|
4721
|
+
}
|
|
4722
|
+
return undefined;
|
|
4723
|
+
}
|
|
4658
4724
|
class MemoryCache {
|
|
4659
4725
|
async set(key, value, options) {
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
const cacheItem = {
|
|
4665
|
-
value,
|
|
4666
|
-
expireAt,
|
|
4667
|
-
};
|
|
4668
|
-
values.set(key, cacheItem);
|
|
4726
|
+
await set(key, value, options);
|
|
4727
|
+
}
|
|
4728
|
+
async setObject(key, value, options) {
|
|
4729
|
+
await set(key, value, options);
|
|
4669
4730
|
}
|
|
4670
4731
|
async get(key) {
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
}
|
|
4676
|
-
if (cacheItem.expireAt >= new Date().valueOf()) {
|
|
4677
|
-
return cacheItem.value;
|
|
4678
|
-
}
|
|
4679
|
-
}
|
|
4680
|
-
return undefined;
|
|
4732
|
+
return get(key);
|
|
4733
|
+
}
|
|
4734
|
+
async getObject(key) {
|
|
4735
|
+
return get(key);
|
|
4681
4736
|
}
|
|
4682
4737
|
async del(key) {
|
|
4683
4738
|
values.delete(key);
|
|
@@ -4699,9 +4754,9 @@ class CacheFactory {
|
|
|
4699
4754
|
#providers;
|
|
4700
4755
|
constructor(config) {
|
|
4701
4756
|
this.name = "cache";
|
|
4702
|
-
const
|
|
4757
|
+
const memoryCacheProvider = new MemoryCacheProvider();
|
|
4703
4758
|
this.#providers = new Map();
|
|
4704
|
-
this.#providers.set(
|
|
4759
|
+
this.#providers.set(memoryCacheProvider.providerName, memoryCacheProvider);
|
|
4705
4760
|
for (const provider of config.providers) {
|
|
4706
4761
|
this.#providers.set(provider.providerName, provider);
|
|
4707
4762
|
}
|
|
@@ -8591,30 +8646,6 @@ function getStateMachineCode(model, property) {
|
|
|
8591
8646
|
}
|
|
8592
8647
|
}
|
|
8593
8648
|
|
|
8594
|
-
function isAccessAllowed(policy, allowedActions) {
|
|
8595
|
-
let isAnyCheckPassed = true;
|
|
8596
|
-
let isAllCheckPassed = true;
|
|
8597
|
-
if (policy.any) {
|
|
8598
|
-
isAnyCheckPassed = false;
|
|
8599
|
-
for (const action of policy.any) {
|
|
8600
|
-
if (lodash.find(allowedActions, (item) => item === action) != null) {
|
|
8601
|
-
isAnyCheckPassed = true;
|
|
8602
|
-
break;
|
|
8603
|
-
}
|
|
8604
|
-
}
|
|
8605
|
-
}
|
|
8606
|
-
if (policy.all) {
|
|
8607
|
-
isAllCheckPassed = true;
|
|
8608
|
-
for (const action of policy.all) {
|
|
8609
|
-
if (lodash.find(allowedActions, (item) => item === action) == null) {
|
|
8610
|
-
isAnyCheckPassed = false;
|
|
8611
|
-
break;
|
|
8612
|
-
}
|
|
8613
|
-
}
|
|
8614
|
-
}
|
|
8615
|
-
return isAnyCheckPassed && isAllCheckPassed;
|
|
8616
|
-
}
|
|
8617
|
-
|
|
8618
8649
|
class EntityAccessControlPlugin {
|
|
8619
8650
|
constructor() { }
|
|
8620
8651
|
get code() {
|
|
@@ -8762,7 +8793,11 @@ exports.decodeJwt = decodeJwt;
|
|
|
8762
8793
|
exports.deleteCookie = deleteCookie;
|
|
8763
8794
|
exports.generateJwtSecretKey = generateJwtSecretKey;
|
|
8764
8795
|
exports.getCookies = getCookies;
|
|
8796
|
+
exports.getEntityRelationTargetId = getEntityRelationTargetId;
|
|
8797
|
+
exports.getNowString = getNowString;
|
|
8798
|
+
exports.getNowStringWithTimezone = getNowStringWithTimezone;
|
|
8765
8799
|
exports.getSetCookies = getSetCookies;
|
|
8800
|
+
exports.isAccessAllowed = isAccessAllowed;
|
|
8766
8801
|
exports.mapDbRowToEntity = mapDbRowToEntity;
|
|
8767
8802
|
exports.setCookie = setCookie;
|
|
8768
8803
|
exports.verifyJwt = verifyJwt;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEntityRelationTargetId(entity: Record<string, any>, propName: string, targetColumnName?: string): number;
|
package/package.json
CHANGED
|
@@ -10,8 +10,10 @@ export interface CacheProvider {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface Cache {
|
|
13
|
-
set: (key: string, value:
|
|
14
|
-
|
|
13
|
+
set: (key: string, value: string, options?: SetValueOptions) => Promise<void>;
|
|
14
|
+
setObject: (key: string, value: Record<string, any>, options?: SetValueOptions) => Promise<void>;
|
|
15
|
+
get: (key: string) => Promise<string | null>;
|
|
16
|
+
getObject: (key: string) => Promise<Record<string, any> | null>;
|
|
15
17
|
del: (key: string) => Promise<void>;
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -10,10 +10,10 @@ export default class CacheFactory implements FacilityFactory<Cache, CreateCacheF
|
|
|
10
10
|
constructor(config: CacheFactoryConfig) {
|
|
11
11
|
this.name = "cache";
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const memoryCacheProvider = new MemoryCacheProvider();
|
|
14
14
|
|
|
15
15
|
this.#providers = new Map();
|
|
16
|
-
this.#providers.set(
|
|
16
|
+
this.#providers.set(memoryCacheProvider.providerName, memoryCacheProvider);
|
|
17
17
|
|
|
18
18
|
for (const provider of config.providers) {
|
|
19
19
|
this.#providers.set(provider.providerName, provider);
|
|
@@ -7,33 +7,49 @@ export type MemoryCacheItem<TValue = any> = {
|
|
|
7
7
|
|
|
8
8
|
const values: Map<string, MemoryCacheItem> = new Map();
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
async function set(key: string, value: any, options?: SetValueOptions) {
|
|
11
|
+
let expireAt = -1;
|
|
12
|
+
if (options && options.ttl > 0) {
|
|
13
|
+
expireAt = new Date().valueOf() + options.ttl;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const cacheItem = {
|
|
17
|
+
value,
|
|
18
|
+
expireAt,
|
|
19
|
+
};
|
|
20
|
+
values.set(key, cacheItem);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function get(key: string) {
|
|
24
|
+
const cacheItem = values.get(key);
|
|
25
|
+
if (cacheItem) {
|
|
26
|
+
if (cacheItem.expireAt === -1) {
|
|
27
|
+
return cacheItem.value;
|
|
15
28
|
}
|
|
16
29
|
|
|
17
|
-
|
|
18
|
-
value
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
if (cacheItem.expireAt >= new Date().valueOf()) {
|
|
31
|
+
return cacheItem.value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default class MemoryCache implements Cache {
|
|
39
|
+
async set(key: string, value: string, options?: SetValueOptions) {
|
|
40
|
+
await set(key, value, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async setObject(key: string, value: Record<string, any>, options?: SetValueOptions) {
|
|
44
|
+
await set(key, value, options);
|
|
22
45
|
}
|
|
23
46
|
|
|
24
47
|
async get(key: string) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (cacheItem.expireAt === -1) {
|
|
28
|
-
return cacheItem.value;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (cacheItem.expireAt >= new Date().valueOf()) {
|
|
32
|
-
return cacheItem.value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
48
|
+
return get(key);
|
|
49
|
+
}
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
async getObject(key: string) {
|
|
52
|
+
return get(key);
|
|
37
53
|
}
|
|
38
54
|
|
|
39
55
|
async del(key: string) {
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,10 @@ export * from "./core/server";
|
|
|
11
11
|
export * from "./core/http-types";
|
|
12
12
|
export * from "./core/actionHandler";
|
|
13
13
|
|
|
14
|
+
export * from "./utilities/accessControlUtility";
|
|
15
|
+
export * from "./utilities/entityUtility";
|
|
14
16
|
export * from "./utilities/jwtUtility";
|
|
17
|
+
export * from "./utilities/timeUtility";
|
|
15
18
|
|
|
16
19
|
export * from "./deno-std/http/cookie";
|
|
17
20
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isObject } from "lodash";
|
|
2
|
+
|
|
3
|
+
export function getEntityRelationTargetId(entity: Record<string, any>, propName: string, targetColumnName?: string) {
|
|
4
|
+
if (!entity) {
|
|
5
|
+
throw new Error(`"entity" parameter is required.`);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let targetId: number | { id?: number } = entity[propName];
|
|
9
|
+
if (!targetId && targetColumnName) {
|
|
10
|
+
targetId = entity[targetColumnName];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (isObject(targetId)) {
|
|
14
|
+
return targetId.id;
|
|
15
|
+
} else {
|
|
16
|
+
return targetId;
|
|
17
|
+
}
|
|
18
|
+
}
|