rlz-engine 1.0.24 → 1.0.26
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
|
+
import { cacheLastResult } from './cached';
|
|
3
4
|
const AUTH_ID_KEY = 'AUTH_ID';
|
|
4
5
|
const AUTH_NAME_KEY = 'AUTH_NAME';
|
|
5
6
|
const AUTH_EMAIL_KEY = 'AUTH_EMAIL';
|
|
@@ -8,7 +9,13 @@ localStorage.removeItem(AUTH_ID_KEY);
|
|
|
8
9
|
localStorage.removeItem(AUTH_NAME_KEY);
|
|
9
10
|
localStorage.removeItem(AUTH_EMAIL_KEY);
|
|
10
11
|
localStorage.removeItem(AUTH_TEMP_PASSWORD_KEY);
|
|
11
|
-
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
+
const makeAuthParam = cacheLastResult(function makeAuthParam(id, tempPassword) {
|
|
14
|
+
if (id === null || tempPassword === null) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return { userId: id, tempPassword };
|
|
18
|
+
});
|
|
12
19
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
20
|
export const useAuthState = create()(persist((set, get) => ({
|
|
14
21
|
id: null,
|
|
@@ -17,18 +24,7 @@ export const useAuthState = create()(persist((set, get) => ({
|
|
|
17
24
|
tempPassword: null,
|
|
18
25
|
getAuthParam: () => {
|
|
19
26
|
const { id, tempPassword } = get();
|
|
20
|
-
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
if (id === cachedAuthParam?.userId
|
|
24
|
-
&& tempPassword === cachedAuthParam?.tempPassword) {
|
|
25
|
-
return cachedAuthParam;
|
|
26
|
-
}
|
|
27
|
-
cachedAuthParam = {
|
|
28
|
-
userId: id,
|
|
29
|
-
tempPassword
|
|
30
|
-
};
|
|
31
|
-
return cachedAuthParam;
|
|
27
|
+
return makeAuthParam(id, tempPassword);
|
|
32
28
|
},
|
|
33
29
|
login: (id, name, email, tempPassword) => set({ id, name, email, tempPassword }),
|
|
34
30
|
logout: () => set({ id: null, name: null, email: null, tempPassword: null })
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cacheLastResult<FnT extends (...args: any) => unknown>(fn: FnT): FnT;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export function cacheLastResult(fn) {
|
|
3
|
+
let lastArgs = null;
|
|
4
|
+
let lastResult = undefined;
|
|
5
|
+
return ((...args) => {
|
|
6
|
+
if (lastArgs !== null && lastArgs.every((arg, i) => arg === args[i])) {
|
|
7
|
+
return lastResult;
|
|
8
|
+
}
|
|
9
|
+
lastArgs = args;
|
|
10
|
+
lastResult = fn(...args);
|
|
11
|
+
return lastResult;
|
|
12
|
+
});
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rlz-engine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "Deps and tools for my style of development",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@stylistic/eslint-plugin": "^
|
|
24
|
+
"@stylistic/eslint-plugin": "^4.2.0",
|
|
25
25
|
"@types/luxon": "^3.4.2",
|
|
26
26
|
"@types/node": "^22.10.1",
|
|
27
27
|
"@typescript-eslint/parser": "^8.16.0",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"@emotion/react": "^11.14.0",
|
|
36
36
|
"@emotion/styled": "^11.14.0",
|
|
37
37
|
"@fastify/compress": "^8.0.1",
|
|
38
|
-
"@fastify/cors": "^
|
|
38
|
+
"@fastify/cors": "^11.0.1",
|
|
39
39
|
"@fastify/response-validation": "^3.0.2",
|
|
40
40
|
"@fastify/sensible": "^6.0.1",
|
|
41
41
|
"@fastify/static": "^8.0.3",
|
|
42
42
|
"@fontsource/roboto": "^5.0.12",
|
|
43
|
-
"@mui/icons-material": "^
|
|
44
|
-
"@mui/material": "^
|
|
43
|
+
"@mui/icons-material": "^7.0.2",
|
|
44
|
+
"@mui/material": "^7.0.2",
|
|
45
45
|
"@types/react": "^19.0.2",
|
|
46
46
|
"@types/react-dom": "^19.0.2",
|
|
47
47
|
"@types/react-router-dom": "^5.3.3",
|