@akinon/next 1.21.0-rc.0 → 1.21.0-rc.1
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/CHANGELOG.md +7 -0
- package/bin/pz-install-plugins.js +0 -0
- package/bin/pz-install-theme.js +0 -0
- package/bin/pz-postbuild.js +0 -0
- package/bin/pz-postdev.js +0 -0
- package/bin/pz-postinstall.js +0 -0
- package/bin/pz-poststart.js +0 -0
- package/bin/pz-prebuild.js +0 -0
- package/bin/pz-predev.js +0 -0
- package/bin/pz-prestart.js +0 -0
- package/lib/cache.ts +55 -27
- package/package.json +5 -4
- package/with-pz-config.js +1 -1
package/CHANGELOG.md
CHANGED
|
File without changes
|
package/bin/pz-install-theme.js
CHANGED
|
File without changes
|
package/bin/pz-postbuild.js
CHANGED
|
File without changes
|
package/bin/pz-postdev.js
CHANGED
|
File without changes
|
package/bin/pz-postinstall.js
CHANGED
|
File without changes
|
package/bin/pz-poststart.js
CHANGED
|
File without changes
|
package/bin/pz-prebuild.js
CHANGED
|
File without changes
|
package/bin/pz-predev.js
CHANGED
|
File without changes
|
package/bin/pz-prestart.js
CHANGED
|
File without changes
|
package/lib/cache.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createPool, Pool } from 'generic-pool';
|
|
1
2
|
import { RedisClientType } from 'redis';
|
|
2
3
|
import Settings from 'settings';
|
|
3
4
|
import { CacheOptions } from '../types';
|
|
@@ -64,21 +65,38 @@ export class Cache {
|
|
|
64
65
|
);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
static
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
static clientPool: Pool<RedisClientType> = createPool(
|
|
69
|
+
{
|
|
70
|
+
create: async () => {
|
|
71
|
+
const { createClient } = await import('redis');
|
|
72
|
+
const redisUrl = `redis://${process.env.CACHE_HOST}:${
|
|
73
|
+
process.env.CACHE_PORT
|
|
74
|
+
}/${process.env.CACHE_BUCKET ?? '0'}`;
|
|
75
|
+
|
|
76
|
+
const client: RedisClientType = createClient({
|
|
77
|
+
url: redisUrl
|
|
78
|
+
});
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
client.on('error', (error) => {
|
|
81
|
+
logger.error('Redis client error', { redisUrl, error });
|
|
82
|
+
});
|
|
76
83
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
await client.connect();
|
|
85
|
+
|
|
86
|
+
return client;
|
|
87
|
+
},
|
|
88
|
+
destroy: async (client: RedisClientType) => {
|
|
89
|
+
await client.disconnect();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
max: 500,
|
|
94
|
+
min: 2
|
|
95
|
+
}
|
|
96
|
+
);
|
|
80
97
|
|
|
81
|
-
|
|
98
|
+
static async getClient() {
|
|
99
|
+
return await Cache.clientPool.acquire();
|
|
82
100
|
}
|
|
83
101
|
|
|
84
102
|
static async get(key: string) {
|
|
@@ -87,39 +105,49 @@ export class Cache {
|
|
|
87
105
|
|
|
88
106
|
try {
|
|
89
107
|
client = await Cache.getClient();
|
|
90
|
-
await client.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
const response = await client.get(key);
|
|
109
|
+
if (response) {
|
|
110
|
+
value = JSON.parse(response);
|
|
111
|
+
} else {
|
|
112
|
+
value = null;
|
|
113
|
+
}
|
|
114
|
+
logger.debug('Redis get success', { key, value });
|
|
95
115
|
} catch (error) {
|
|
96
116
|
logger.error('Redis get error', { key, error });
|
|
117
|
+
value = null;
|
|
97
118
|
} finally {
|
|
98
|
-
|
|
119
|
+
if (client) {
|
|
120
|
+
await Cache.clientPool.release(client);
|
|
121
|
+
}
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
return value;
|
|
102
125
|
}
|
|
103
126
|
|
|
104
|
-
static async set(key: string, value:
|
|
127
|
+
static async set(key: string, value: any, expire?: number) {
|
|
105
128
|
let success = false;
|
|
106
129
|
let client;
|
|
107
130
|
|
|
108
131
|
try {
|
|
109
132
|
client = await Cache.getClient();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
EX: expire
|
|
113
|
-
});
|
|
133
|
+
const serializedValue =
|
|
134
|
+
typeof value === 'object' ? JSON.stringify(value) : value;
|
|
114
135
|
|
|
115
|
-
|
|
136
|
+
if (expire) {
|
|
137
|
+
await client.set(key, serializedValue, { EX: expire });
|
|
138
|
+
} else {
|
|
139
|
+
await client.set(key, serializedValue);
|
|
140
|
+
}
|
|
116
141
|
|
|
117
|
-
|
|
118
|
-
logger.
|
|
142
|
+
success = true;
|
|
143
|
+
logger.debug('Redis set success', { key, value });
|
|
119
144
|
} catch (error) {
|
|
120
145
|
logger.error('Redis set error', { key, error });
|
|
146
|
+
success = false;
|
|
121
147
|
} finally {
|
|
122
|
-
|
|
148
|
+
if (client) {
|
|
149
|
+
await Cache.clientPool.release(client);
|
|
150
|
+
}
|
|
123
151
|
}
|
|
124
152
|
|
|
125
153
|
return success;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/next",
|
|
3
3
|
"description": "Core package for Project Zero Next",
|
|
4
|
-
"version": "1.21.0-rc.
|
|
4
|
+
"version": "1.21.0-rc.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"pz-postdev": "bin/pz-postdev.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@opentelemetry/sdk-node": "0.46.0",
|
|
18
17
|
"@opentelemetry/exporter-trace-otlp-http": "0.46.0",
|
|
19
18
|
"@opentelemetry/resources": "1.19.0",
|
|
20
|
-
"@opentelemetry/
|
|
19
|
+
"@opentelemetry/sdk-node": "0.46.0",
|
|
21
20
|
"@opentelemetry/sdk-trace-node": "1.19.0",
|
|
21
|
+
"@opentelemetry/semantic-conventions": "1.19.0",
|
|
22
22
|
"@reduxjs/toolkit": "1.9.7",
|
|
23
23
|
"cross-spawn": "7.0.3",
|
|
24
|
+
"generic-pool": "3.9.0",
|
|
24
25
|
"react-redux": "8.1.3",
|
|
25
26
|
"react-string-replace": "1.1.1",
|
|
26
27
|
"redis": "4.5.1",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
32
33
|
"@typescript-eslint/parser": "6.7.4",
|
|
33
34
|
"eslint": "^8.14.0",
|
|
34
|
-
"@akinon/eslint-plugin-projectzero": "1.21.0-rc.
|
|
35
|
+
"@akinon/eslint-plugin-projectzero": "1.21.0-rc.1",
|
|
35
36
|
"eslint-config-prettier": "8.5.0"
|
|
36
37
|
}
|
|
37
38
|
}
|
package/with-pz-config.js
CHANGED
|
@@ -3,7 +3,7 @@ const deepMerge = require('./utils/deep-merge');
|
|
|
3
3
|
|
|
4
4
|
/** @type {import('next').NextConfig} */
|
|
5
5
|
const defaultConfig = {
|
|
6
|
-
experimental: {
|
|
6
|
+
experimental: { instrumentationHook: true },
|
|
7
7
|
reactStrictMode: true,
|
|
8
8
|
transpilePackages: ['@akinon/next', ...pzPlugins.map((p) => `@akinon/${p}`)],
|
|
9
9
|
skipTrailingSlashRedirect: true,
|