Skip to content

Commit

Permalink
fix(forestadmin-client): bump lru-cache to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Thenkei committed May 31, 2023
1 parent 3a37f51 commit 891e5f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
3 changes: 1 addition & 2 deletions packages/forestadmin-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"eventsource": "2.0.2",
"json-api-serializer": "^2.6.6",
"jsonwebtoken": "^9.0.0",
"lru-cache": "^7.14.1",
"lru-cache": "^9.1.1",
"object-hash": "^3.0.0",
"openid-client": "^5.3.1",
"superagent": "^8.0.6"
Expand All @@ -35,7 +35,6 @@
"@forestadmin/datasource-toolkit": "1.5.0",
"@types/json-api-serializer": "^2.6.3",
"@types/jsonwebtoken": "^9.0.1",
"@types/lru-cache": "^7.10.10",
"@types/superagent": "^4.1.16"
}
}
24 changes: 12 additions & 12 deletions packages/forestadmin-client/src/permissions/rendering-permission.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LruCache from 'lru-cache';
import { LRUCache } from 'lru-cache';

import { hashChartRequest, hashServerCharts } from './hash-chart';
import isSegmentQueryAllowed from './is-segment-query-authorized';
Expand All @@ -23,17 +23,17 @@ export type RenderingPermission = {
};

export default class RenderingPermissionService {
private readonly permissionsByRendering: LruCache<string, RenderingPermission>;
private readonly permissionsByRendering: LRUCache<string, RenderingPermission>;

constructor(
private readonly options: ForestAdminClientOptionsWithDefaults,
private readonly userPermissions: UserPermissionService,
private readonly forestAdminServerInterface: ForestAdminServerInterface,
) {
this.permissionsByRendering = new LruCache({
this.permissionsByRendering = new LRUCache<string, RenderingPermission>({
max: 256,
ttl: this.options.permissionsCacheDurationInSeconds * 1000,
fetchMethod: renderingId => this.loadPermissions(Number(renderingId)),
fetchMethod: async renderingId => this.loadPermissions(Number(renderingId)),
});
}

Expand Down Expand Up @@ -66,10 +66,10 @@ export default class RenderingPermissionService {
userId: number | string;
allowRetry: boolean;
}): Promise<RawTree> {
const [permissions, userInfo]: [RenderingPermission, UserPermissionV4] = await Promise.all([
const [permissions, userInfo] = (await Promise.all([
this.permissionsByRendering.fetch(`${renderingId}`),
this.userPermissions.getUserInfo(userId),
]);
])) as [RenderingPermission, UserPermissionV4];

const collectionPermissions = permissions?.collections?.[collectionName];

Expand Down Expand Up @@ -125,9 +125,9 @@ export default class RenderingPermissionService {
segmentQuery: string;
allowRetry: boolean;
}): Promise<boolean> {
const permissions: RenderingPermission = await this.permissionsByRendering.fetch(
const permissions = (await this.permissionsByRendering.fetch(
`${renderingId}`,
);
)) as RenderingPermission;

const collectionPermissions = permissions?.collections?.[collectionName];

Expand Down Expand Up @@ -210,10 +210,10 @@ export default class RenderingPermissionService {
chartHash: string;
allowRetry: boolean;
}): Promise<boolean> {
const [userInfo, permissions] = await Promise.all([
const [userInfo, permissions] = (await Promise.all([
this.userPermissions.getUserInfo(userId),
this.permissionsByRendering.fetch(`${renderingId}`),
]);
])) as [UserPermissionV4, RenderingPermission];

if (
[PermissionLevel.Admin, PermissionLevel.Developer, PermissionLevel.Editor].includes(
Expand Down Expand Up @@ -266,9 +266,9 @@ export default class RenderingPermissionService {
}

public async getTeam(renderingId: number | string): Promise<Team> {
const permissions: RenderingPermission = await this.permissionsByRendering.fetch(
const permissions = (await this.permissionsByRendering.fetch(
`${renderingId}`,
);
)) as RenderingPermission;

return permissions.team;
}
Expand Down
22 changes: 10 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3562,13 +3562,6 @@
dependencies:
"@types/koa" "*"

"@types/lru-cache@^7.10.10":
version "7.10.10"
resolved "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-7.10.10.tgz"
integrity sha512-nEpVRPWW9EBmx2SCfNn3ClYxPL7IktPX12HhIoSc/H5mMjdeW3+YsXIpseLQ2xF35+OcpwKQbEUw5VtqE4PDNA==
dependencies:
lru-cache "*"

"@types/luxon@^3.2.0":
version "3.2.0"
resolved "https://registry.npmjs.org/@types/luxon/-/luxon-3.2.0.tgz"
Expand Down Expand Up @@ -8585,11 +8578,6 @@ longest-streak@^2.0.0:
resolved "https://registry.npmjs.org/longest-streak/-/longest-streak-2.0.4.tgz"
integrity sha512-vM6rUVCVUJJt33bnmHiZEvr7wPT78ztX7rojL+LW51bHtLh6HTjx84LA5W4+oa6aKEJA7jJu5LR6vQRBpA5DVg==

lru-cache@*, lru-cache@^7.14.0, lru-cache@^7.14.1, lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1:
version "7.14.1"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz"
integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==

lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz"
Expand All @@ -8604,6 +8592,16 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

lru-cache@^7.14.0, lru-cache@^7.14.1, lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1:
version "7.14.1"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz"
integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==

lru-cache@^9.1.1:
version "9.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-9.1.1.tgz#c58a93de58630b688de39ad04ef02ef26f1902f1"
integrity sha512-65/Jky17UwSb0BuB9V+MyDpsOtXKmYwzhyl+cOa9XUiI4uV2Ouy/2voFP3+al0BjZbJgMBD8FojMpAf+Z+qn4A==

lunr@^2.3.9:
version "2.3.9"
resolved "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz"
Expand Down

0 comments on commit 891e5f6

Please sign in to comment.