@directus/api 21.0.0 → 21.0.2
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/cache.d.ts +2 -2
- package/dist/cache.js +2 -2
- package/dist/middleware/respond.js +1 -0
- package/dist/request/is-denied-ip.js +7 -1
- package/dist/utils/get-schema.js +19 -24
- package/package.json +12 -12
package/dist/cache.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare function clearSystemCache(opts?: {
|
|
|
13
13
|
}): Promise<void>;
|
|
14
14
|
export declare function setSystemCache(key: string, value: any, ttl?: number): Promise<void>;
|
|
15
15
|
export declare function getSystemCache(key: string): Promise<Record<string, any>>;
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function
|
|
16
|
+
export declare function setLocalSchemaCache(schema: SchemaOverview): Promise<void>;
|
|
17
|
+
export declare function getLocalSchemaCache(): Promise<SchemaOverview | undefined>;
|
|
18
18
|
export declare function setCacheValue(cache: Keyv, key: string, value: Record<string, any> | Record<string, any>[], ttl?: number): Promise<void>;
|
|
19
19
|
export declare function getCacheValue(cache: Keyv, key: string): Promise<any>;
|
package/dist/cache.js
CHANGED
|
@@ -72,11 +72,11 @@ export async function getSystemCache(key) {
|
|
|
72
72
|
const { systemCache } = getCache();
|
|
73
73
|
return await getCacheValue(systemCache, key);
|
|
74
74
|
}
|
|
75
|
-
export async function
|
|
75
|
+
export async function setLocalSchemaCache(schema) {
|
|
76
76
|
const { localSchemaCache } = getCache();
|
|
77
77
|
await localSchemaCache.set('schema', schema);
|
|
78
78
|
}
|
|
79
|
-
export async function
|
|
79
|
+
export async function getLocalSchemaCache() {
|
|
80
80
|
const { localSchemaCache } = getCache();
|
|
81
81
|
return await localSchemaCache.get('schema');
|
|
82
82
|
}
|
|
@@ -20,6 +20,7 @@ export const respond = asyncHandler(async (req, res) => {
|
|
|
20
20
|
exceedsMaxSize = valueSize > maxSize;
|
|
21
21
|
}
|
|
22
22
|
if ((req.method.toLowerCase() === 'get' || req.originalUrl?.startsWith('/graphql')) &&
|
|
23
|
+
req.originalUrl?.startsWith('/auth') === false &&
|
|
23
24
|
env['CACHE_ENABLED'] === true &&
|
|
24
25
|
cache &&
|
|
25
26
|
!req.sanitizedQuery.export &&
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEnv } from '@directus/env';
|
|
2
|
+
import { matches } from 'ip-matching';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import { useLogger } from '../logger/index.js';
|
|
4
5
|
import { ipInNetworks } from '../utils/ip-in-networks.js';
|
|
@@ -24,8 +25,13 @@ export function isDeniedIp(ip) {
|
|
|
24
25
|
if (!networkInfo)
|
|
25
26
|
continue;
|
|
26
27
|
for (const info of networkInfo) {
|
|
27
|
-
if (info.
|
|
28
|
+
if (info.internal && info.cidr) {
|
|
29
|
+
if (matches(ip, info.cidr))
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
else if (info.address === ip) {
|
|
28
33
|
return true;
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
}
|
package/dist/utils/get-schema.js
CHANGED
|
@@ -4,7 +4,7 @@ import { systemCollectionRows } from '@directus/system-data';
|
|
|
4
4
|
import { parseJSON, toArray } from '@directus/utils';
|
|
5
5
|
import { mapValues } from 'lodash-es';
|
|
6
6
|
import { useBus } from '../bus/index.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getLocalSchemaCache, setLocalSchemaCache } from '../cache.js';
|
|
8
8
|
import { ALIAS_TYPES } from '../constants.js';
|
|
9
9
|
import getDatabase from '../database/index.js';
|
|
10
10
|
import { useLock } from '../lock/index.js';
|
|
@@ -22,7 +22,7 @@ export async function getSchema(options, attempt = 0) {
|
|
|
22
22
|
const schemaInspector = createInspector(database);
|
|
23
23
|
return await getDatabaseSchema(database, schemaInspector);
|
|
24
24
|
}
|
|
25
|
-
const cached = await
|
|
25
|
+
const cached = await getLocalSchemaCache();
|
|
26
26
|
if (cached) {
|
|
27
27
|
return cached;
|
|
28
28
|
}
|
|
@@ -40,39 +40,34 @@ export async function getSchema(options, attempt = 0) {
|
|
|
40
40
|
const currentProcessShouldHandleOperation = processId === 1;
|
|
41
41
|
if (currentProcessShouldHandleOperation === false) {
|
|
42
42
|
logger.trace('Schema cache is prepared in another process, waiting for result.');
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
bus.subscribe(messageKey, callback);
|
|
50
|
-
async function callback() {
|
|
51
|
-
try {
|
|
52
|
-
if (timeout)
|
|
53
|
-
clearTimeout(timeout);
|
|
54
|
-
const schema = await getSchema(options, attempt + 1);
|
|
55
|
-
resolve(schema);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
reject(error);
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
bus.unsubscribe(messageKey, callback);
|
|
43
|
+
const timeout = new Promise((_, reject) => setTimeout(reject, env['CACHE_SCHEMA_SYNC_TIMEOUT']));
|
|
44
|
+
const subscription = new Promise((resolve, reject) => {
|
|
45
|
+
bus.subscribe(messageKey, busListener).catch(reject);
|
|
46
|
+
function busListener(options) {
|
|
47
|
+
if (options.schema === null) {
|
|
48
|
+
return reject();
|
|
62
49
|
}
|
|
50
|
+
cleanup();
|
|
51
|
+
setLocalSchemaCache(options.schema).catch(reject);
|
|
52
|
+
resolve(options.schema);
|
|
53
|
+
}
|
|
54
|
+
function cleanup() {
|
|
55
|
+
bus.unsubscribe(messageKey, busListener).catch(reject);
|
|
63
56
|
}
|
|
64
57
|
});
|
|
58
|
+
return Promise.race([timeout, subscription]).catch(() => getSchema(options, attempt + 1));
|
|
65
59
|
}
|
|
60
|
+
let schema = null;
|
|
66
61
|
try {
|
|
67
62
|
const database = options?.database || getDatabase();
|
|
68
63
|
const schemaInspector = createInspector(database);
|
|
69
|
-
|
|
70
|
-
await
|
|
64
|
+
schema = await getDatabaseSchema(database, schemaInspector);
|
|
65
|
+
await setLocalSchemaCache(schema);
|
|
71
66
|
return schema;
|
|
72
67
|
}
|
|
73
68
|
finally {
|
|
69
|
+
await bus.publish(messageKey, { schema });
|
|
74
70
|
await lock.delete(lockKey);
|
|
75
|
-
bus.publish(messageKey, { ready: true });
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
async function getDatabaseSchema(database, schemaInspector) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/api",
|
|
3
|
-
"version": "21.0.
|
|
3
|
+
"version": "21.0.2",
|
|
4
4
|
"description": "Directus is a real-time API and App dashboard for managing SQL database content",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"directus",
|
|
@@ -149,29 +149,29 @@
|
|
|
149
149
|
"ws": "8.18.0",
|
|
150
150
|
"zod": "3.23.8",
|
|
151
151
|
"zod-validation-error": "3.3.0",
|
|
152
|
-
"@directus/app": "12.2.2",
|
|
153
|
-
"@directus/errors": "0.4.0",
|
|
154
152
|
"@directus/constants": "11.0.4",
|
|
155
|
-
"@directus/env": "1.3.
|
|
153
|
+
"@directus/env": "1.3.2",
|
|
156
154
|
"@directus/extensions": "1.0.10",
|
|
157
155
|
"@directus/extensions-registry": "1.0.10",
|
|
156
|
+
"@directus/app": "12.2.3",
|
|
158
157
|
"@directus/extensions-sdk": "11.0.10",
|
|
159
158
|
"@directus/format-title": "10.1.2",
|
|
160
|
-
"@directus/
|
|
159
|
+
"@directus/errors": "0.4.0",
|
|
160
|
+
"@directus/memory": "1.0.12",
|
|
161
161
|
"@directus/pressure": "1.0.22",
|
|
162
162
|
"@directus/schema": "11.0.4",
|
|
163
|
-
"@directus/specs": "10.2.11",
|
|
164
163
|
"@directus/storage": "10.1.0",
|
|
165
|
-
"@directus/
|
|
164
|
+
"@directus/specs": "10.2.11",
|
|
166
165
|
"@directus/storage-driver-azure": "10.0.24",
|
|
167
166
|
"@directus/storage-driver-gcs": "10.0.25",
|
|
167
|
+
"@directus/storage-driver-cloudinary": "10.0.24",
|
|
168
|
+
"@directus/storage-driver-s3": "10.1.1",
|
|
168
169
|
"@directus/storage-driver-local": "10.1.0",
|
|
169
170
|
"@directus/storage-driver-supabase": "1.0.16",
|
|
170
|
-
"@directus/storage-driver-s3": "10.1.1",
|
|
171
|
-
"@directus/utils": "11.0.11",
|
|
172
|
-
"@directus/validation": "0.0.19",
|
|
173
171
|
"@directus/system-data": "1.1.1",
|
|
174
|
-
"directus": "
|
|
172
|
+
"@directus/utils": "11.0.11",
|
|
173
|
+
"directus": "10.13.4",
|
|
174
|
+
"@directus/validation": "0.0.19"
|
|
175
175
|
},
|
|
176
176
|
"devDependencies": {
|
|
177
177
|
"@ngneat/falso": "7.2.0",
|
|
@@ -212,8 +212,8 @@
|
|
|
212
212
|
"knex-mock-client": "2.0.1",
|
|
213
213
|
"typescript": "5.4.5",
|
|
214
214
|
"vitest": "1.5.3",
|
|
215
|
-
"@directus/tsconfig": "1.0.1",
|
|
216
215
|
"@directus/random": "0.2.8",
|
|
216
|
+
"@directus/tsconfig": "1.0.1",
|
|
217
217
|
"@directus/types": "11.2.1"
|
|
218
218
|
},
|
|
219
219
|
"optionalDependencies": {
|