@strapi/core 5.57.0 → 5.59.0
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/Strapi.d.ts +28 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +5 -0
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +5 -0
- package/dist/Strapi.mjs.map +1 -1
- package/dist/ee/entitlements.d.ts +44 -0
- package/dist/ee/entitlements.d.ts.map +1 -0
- package/dist/ee/entitlements.js +54 -0
- package/dist/ee/entitlements.js.map +1 -0
- package/dist/ee/entitlements.mjs +51 -0
- package/dist/ee/entitlements.mjs.map +1 -0
- package/dist/ee/index.d.ts +33 -0
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +70 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +71 -4
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.d.ts +10 -0
- package/dist/ee/license.d.ts.map +1 -1
- package/dist/ee/license.js +25 -1
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +25 -2
- package/dist/ee/license.mjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/apis.d.ts.map +1 -1
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +2 -2
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -2
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/first-published-at.js +1 -1
- package/dist/migrations/first-published-at.js.map +1 -1
- package/dist/migrations/first-published-at.mjs +1 -1
- package/dist/migrations/first-published-at.mjs.map +1 -1
- package/dist/package.json.js +18 -17
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +18 -17
- package/dist/package.json.mjs.map +1 -1
- package/dist/registries/controllers.d.ts.map +1 -1
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/controllers.mjs.map +1 -1
- package/dist/services/content-source-maps.js +6 -6
- package/dist/services/content-source-maps.js.map +1 -1
- package/dist/services/content-source-maps.mjs +6 -6
- package/dist/services/content-source-maps.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +13 -11
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +115 -66
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +116 -67
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/events.d.ts.map +1 -1
- package/dist/services/document-service/events.js +5 -1
- package/dist/services/document-service/events.js.map +1 -1
- package/dist/services/document-service/events.mjs +5 -1
- package/dist/services/document-service/events.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +26 -7
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +27 -8
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/transform/fields.d.ts.map +1 -1
- package/dist/services/document-service/transform/fields.js +7 -1
- package/dist/services/document-service/transform/fields.js.map +1 -1
- package/dist/services/document-service/transform/fields.mjs +7 -1
- package/dist/services/document-service/transform/fields.mjs.map +1 -1
- package/dist/services/document-service/transform/populate.d.ts.map +1 -1
- package/dist/services/document-service/transform/populate.js +8 -1
- package/dist/services/document-service/transform/populate.js.map +1 -1
- package/dist/services/document-service/transform/populate.mjs +8 -1
- package/dist/services/document-service/transform/populate.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts +4 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.js +12 -9
- package/dist/services/document-service/transform/relations/transform/default-locale.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs +12 -10
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.js +10 -4
- package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs +10 -4
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
- package/dist/services/document-service/utils/clone-relations.d.ts +21 -4
- package/dist/services/document-service/utils/clone-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/clone-relations.js +619 -34
- package/dist/services/document-service/utils/clone-relations.js.map +1 -1
- package/dist/services/document-service/utils/clone-relations.mjs +619 -36
- package/dist/services/document-service/utils/clone-relations.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +4 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +1 -10
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +1 -10
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/event-hub.d.ts.map +1 -1
- package/dist/services/event-hub.js +23 -5
- package/dist/services/event-hub.js.map +1 -1
- package/dist/services/event-hub.mjs +23 -5
- package/dist/services/event-hub.mjs.map +1 -1
- package/dist/services/webhook-store.js +2 -2
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +2 -2
- package/dist/services/webhook-store.mjs.map +1 -1
- package/dist/utils/detect-customizations.d.ts +31 -0
- package/dist/utils/detect-customizations.d.ts.map +1 -0
- package/dist/utils/detect-customizations.js +173 -0
- package/dist/utils/detect-customizations.js.map +1 -0
- package/dist/utils/detect-customizations.mjs +165 -0
- package/dist/utils/detect-customizations.mjs.map +1 -0
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +44 -8
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +37 -8
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +5 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +5 -5
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +18 -17
package/dist/utils/fetch.js
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var ProxyAgent = require('undici/lib/dispatcher/proxy-agent.js');
|
|
4
|
+
var Dispatcher1Wrapper = require('undici/lib/dispatcher/dispatcher1-wrapper.js');
|
|
5
|
+
var Dispatcher = require('undici/lib/dispatcher/dispatcher.js');
|
|
6
|
+
var connect = require('undici/lib/api/api-connect.js');
|
|
4
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var ProxyAgent__default = /*#__PURE__*/_interopDefault(ProxyAgent);
|
|
11
|
+
var Dispatcher1Wrapper__default = /*#__PURE__*/_interopDefault(Dispatcher1Wrapper);
|
|
12
|
+
var Dispatcher__default = /*#__PURE__*/_interopDefault(Dispatcher);
|
|
13
|
+
var connect__default = /*#__PURE__*/_interopDefault(connect);
|
|
14
|
+
|
|
15
|
+
var /* eslint-enable import/extensions */ // undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT
|
|
16
|
+
// tunnel used for https targets, so add it here since the main entry is skipped.
|
|
17
|
+
_Dispatcher_prototype;
|
|
18
|
+
(_Dispatcher_prototype = Dispatcher__default.default.prototype).connect ?? (_Dispatcher_prototype.connect = connect__default.default);
|
|
19
|
+
const isStream = (body)=>body instanceof ReadableStream || typeof body === 'object' && body !== null && Symbol.asyncIterator in body;
|
|
20
|
+
// Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated
|
|
21
|
+
// header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.
|
|
22
|
+
// A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.
|
|
23
|
+
// TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed
|
|
24
|
+
const withoutContentLength = (input, init)=>{
|
|
25
|
+
if (isStream(init?.body)) {
|
|
26
|
+
return init;
|
|
27
|
+
}
|
|
28
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
29
|
+
if (!headers.has('content-length')) {
|
|
30
|
+
return init;
|
|
31
|
+
}
|
|
32
|
+
headers.delete('content-length');
|
|
33
|
+
return {
|
|
34
|
+
...init,
|
|
35
|
+
headers
|
|
36
|
+
};
|
|
37
|
+
};
|
|
5
38
|
// Create a wrapper for Node's Fetch API that applies a global proxy
|
|
6
39
|
const createStrapiFetch = (strapi, options)=>{
|
|
7
40
|
const { logs = true } = options ?? {};
|
|
8
41
|
const strapiFetch = (url, options)=>{
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
42
|
+
const { dispatcher } = strapiFetch;
|
|
43
|
+
// Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which
|
|
44
|
+
// differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime
|
|
45
|
+
const fetchOptions = dispatcher ? {
|
|
46
|
+
dispatcher,
|
|
47
|
+
...withoutContentLength(url, options)
|
|
48
|
+
} : options;
|
|
15
49
|
if (logs) {
|
|
16
50
|
strapi.log.debug(`Making request for ${url}`);
|
|
17
51
|
}
|
|
@@ -22,7 +56,9 @@ const createStrapiFetch = (strapi, options)=>{
|
|
|
22
56
|
if (logs) {
|
|
23
57
|
strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);
|
|
24
58
|
}
|
|
25
|
-
|
|
59
|
+
// Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)
|
|
60
|
+
// dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.
|
|
61
|
+
strapiFetch.dispatcher = new Dispatcher1Wrapper__default.default(new ProxyAgent__default.default(proxy));
|
|
26
62
|
}
|
|
27
63
|
return strapiFetch;
|
|
28
64
|
};
|
package/dist/utils/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport
|
|
1
|
+
{"version":3,"file":"fetch.js","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\n// Import undici's dispatchers from their own files: loading undici's main entry replaces the\n// dispatcher of Node's built-in fetch, which then rejects requests that set their own\n// Content-Length on Node 22/24 (https://github.com/nodejs/undici/issues/5500)\n/* eslint-disable import/extensions -- required by the ESM build: undici has no exports map */\nimport ProxyAgent from 'undici/lib/dispatcher/proxy-agent.js';\nimport Dispatcher1Wrapper from 'undici/lib/dispatcher/dispatcher1-wrapper.js';\nimport Dispatcher from 'undici/lib/dispatcher/dispatcher.js';\nimport connect from 'undici/lib/api/api-connect.js';\n/* eslint-enable import/extensions */\n\n// undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT\n// tunnel used for https targets, so add it here since the main entry is skipped.\nDispatcher.prototype.connect ??= connect;\n\n// TODO: once core Node exposes a stable way to create a ProxyAgent we will use that instead of undici\n\ninterface StrapiFetchOptions {\n logs?: boolean;\n}\n\nconst isStream = (body: RequestInit['body']) =>\n body instanceof ReadableStream ||\n (typeof body === 'object' && body !== null && Symbol.asyncIterator in body);\n\n// Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated\n// header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.\n// A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.\n// TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed\nconst withoutContentLength = (\n input: Parameters<Fetch>[0],\n init?: RequestInit\n): RequestInit | undefined => {\n if (isStream(init?.body)) {\n return init;\n }\n\n const headers = new Headers(\n init?.headers ?? (input instanceof Request ? input.headers : undefined)\n );\n\n if (!headers.has('content-length')) {\n return init;\n }\n\n headers.delete('content-length');\n\n return { ...init, headers };\n};\n\n// Create a wrapper for Node's Fetch API that applies a global proxy\nexport const createStrapiFetch = (strapi: Core.Strapi, options?: StrapiFetchOptions): Fetch => {\n const { logs = true } = options ?? {};\n\n const strapiFetch: Fetch = (url, options) => {\n const { dispatcher } = strapiFetch;\n\n // Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which\n // differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime\n const fetchOptions = (\n dispatcher ? { dispatcher, ...withoutContentLength(url, options) } : options\n ) as RequestInit | undefined;\n\n if (logs) {\n strapi.log.debug(`Making request for ${url}`);\n }\n\n return fetch(url, fetchOptions);\n };\n\n const proxy =\n strapi.config.get<ConstructorParameters<typeof ProxyAgent>[0]>('server.proxy.fetch') ||\n strapi.config.get<string>('server.proxy.global');\n\n if (proxy) {\n if (logs) {\n strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);\n }\n // Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)\n // dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.\n strapiFetch.dispatcher = new Dispatcher1Wrapper(new ProxyAgent(proxy));\n }\n\n return strapiFetch;\n};\n\nexport type Fetch = Modules.Fetch.Fetch;\n"],"names":["Dispatcher","prototype","connect","isStream","body","ReadableStream","Symbol","asyncIterator","withoutContentLength","input","init","headers","Headers","Request","undefined","has","delete","createStrapiFetch","strapi","options","logs","strapiFetch","url","dispatcher","fetchOptions","log","debug","fetch","proxy","config","get","info","Dispatcher1Wrapper","ProxyAgent"],"mappings":";;;;;;;;;;;;;;AASA;AAGA;AACAA,qBAAAA;AAAAA,CAAAA,wBAAAA,2BAAAA,CAAWC,SAAS,EAACC,OAAAA,KAArBF,sBAAqBE,OAAAA,GAAYA,wBAAAA,CAAAA;AAQjC,MAAMC,QAAAA,GAAW,CAACC,IAAAA,GAChBA,IAAAA,YAAgBC,cAAAA,IACf,OAAOD,IAAAA,KAAS,QAAA,IAAYA,IAAAA,KAAS,IAAA,IAAQE,MAAAA,CAAOC,aAAa,IAAIH,IAAAA;AAExE;AACA;AACA;AACA;AACA,MAAMI,oBAAAA,GAAuB,CAC3BC,KAAAA,EACAC,IAAAA,GAAAA;IAEA,IAAIP,QAAAA,CAASO,MAAMN,IAAAA,CAAAA,EAAO;QACxB,OAAOM,IAAAA;AACT,IAAA;IAEA,MAAMC,OAAAA,GAAU,IAAIC,OAAAA,CAClBF,IAAAA,EAAMC,OAAAA,KAAYF,KAAAA,YAAiBI,OAAAA,GAAUJ,KAAAA,CAAME,OAAO,GAAGG,SAAQ,CAAA,CAAA;AAGvE,IAAA,IAAI,CAACH,OAAAA,CAAQI,GAAG,CAAC,gBAAA,CAAA,EAAmB;QAClC,OAAOL,IAAAA;AACT,IAAA;AAEAC,IAAAA,OAAAA,CAAQK,MAAM,CAAC,gBAAA,CAAA;IAEf,OAAO;AAAE,QAAA,GAAGN,IAAI;AAAEC,QAAAA;AAAQ,KAAA;AAC5B,CAAA;AAEA;AACO,MAAMM,iBAAAA,GAAoB,CAACC,MAAAA,EAAqBC,OAAAA,GAAAA;AACrD,IAAA,MAAM,EAAEC,IAAAA,GAAO,IAAI,EAAE,GAAGD,WAAW,EAAC;IAEpC,MAAME,WAAAA,GAAqB,CAACC,GAAAA,EAAKH,OAAAA,GAAAA;QAC/B,MAAM,EAAEI,UAAU,EAAE,GAAGF,WAAAA;;;AAIvB,QAAA,MAAMG,eACJD,UAAAA,GAAa;AAAEA,YAAAA,UAAAA;YAAY,GAAGf,oBAAAA,CAAqBc,KAAKH,OAAAA;SAAS,GAAIA,OAAAA;AAGvE,QAAA,IAAIC,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,GAAAA,CAAAA,CAAK,CAAA;AAC9C,QAAA;AAEA,QAAA,OAAOK,MAAML,GAAAA,EAAKE,YAAAA,CAAAA;AACpB,IAAA,CAAA;IAEA,MAAMI,KAAAA,GACJV,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAA8C,oBAAA,CAAA,IAC/DZ,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAAS,qBAAA,CAAA;AAE5B,IAAA,IAAIF,KAAAA,EAAO;AACT,QAAA,IAAIR,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACM,IAAI,CAAC,CAAC,gCAAgC,EAAEH,KAAAA,CAAAA,CAAO,CAAA;AAC5D,QAAA;;;AAGAP,QAAAA,WAAAA,CAAYE,UAAU,GAAG,IAAIS,mCAAAA,CAAmB,IAAIC,2BAAAA,CAAWL,KAAAA,CAAAA,CAAAA;AACjE,IAAA;IAEA,OAAOP,WAAAA;AACT;;;;"}
|
package/dist/utils/fetch.mjs
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ProxyAgent from 'undici/lib/dispatcher/proxy-agent.js';
|
|
2
|
+
import Dispatcher1Wrapper from 'undici/lib/dispatcher/dispatcher1-wrapper.js';
|
|
3
|
+
import Dispatcher from 'undici/lib/dispatcher/dispatcher.js';
|
|
4
|
+
import connect from 'undici/lib/api/api-connect.js';
|
|
2
5
|
|
|
6
|
+
var /* eslint-enable import/extensions */ // undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT
|
|
7
|
+
// tunnel used for https targets, so add it here since the main entry is skipped.
|
|
8
|
+
_Dispatcher_prototype;
|
|
9
|
+
(_Dispatcher_prototype = Dispatcher.prototype).connect ?? (_Dispatcher_prototype.connect = connect);
|
|
10
|
+
const isStream = (body)=>body instanceof ReadableStream || typeof body === 'object' && body !== null && Symbol.asyncIterator in body;
|
|
11
|
+
// Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated
|
|
12
|
+
// header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.
|
|
13
|
+
// A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.
|
|
14
|
+
// TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed
|
|
15
|
+
const withoutContentLength = (input, init)=>{
|
|
16
|
+
if (isStream(init?.body)) {
|
|
17
|
+
return init;
|
|
18
|
+
}
|
|
19
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
20
|
+
if (!headers.has('content-length')) {
|
|
21
|
+
return init;
|
|
22
|
+
}
|
|
23
|
+
headers.delete('content-length');
|
|
24
|
+
return {
|
|
25
|
+
...init,
|
|
26
|
+
headers
|
|
27
|
+
};
|
|
28
|
+
};
|
|
3
29
|
// Create a wrapper for Node's Fetch API that applies a global proxy
|
|
4
30
|
const createStrapiFetch = (strapi, options)=>{
|
|
5
31
|
const { logs = true } = options ?? {};
|
|
6
32
|
const strapiFetch = (url, options)=>{
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
33
|
+
const { dispatcher } = strapiFetch;
|
|
34
|
+
// Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which
|
|
35
|
+
// differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime
|
|
36
|
+
const fetchOptions = dispatcher ? {
|
|
37
|
+
dispatcher,
|
|
38
|
+
...withoutContentLength(url, options)
|
|
39
|
+
} : options;
|
|
13
40
|
if (logs) {
|
|
14
41
|
strapi.log.debug(`Making request for ${url}`);
|
|
15
42
|
}
|
|
@@ -20,7 +47,9 @@ const createStrapiFetch = (strapi, options)=>{
|
|
|
20
47
|
if (logs) {
|
|
21
48
|
strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);
|
|
22
49
|
}
|
|
23
|
-
|
|
50
|
+
// Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)
|
|
51
|
+
// dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.
|
|
52
|
+
strapiFetch.dispatcher = new Dispatcher1Wrapper(new ProxyAgent(proxy));
|
|
24
53
|
}
|
|
25
54
|
return strapiFetch;
|
|
26
55
|
};
|
package/dist/utils/fetch.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.mjs","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport
|
|
1
|
+
{"version":3,"file":"fetch.mjs","sources":["../../src/utils/fetch.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\n// Import undici's dispatchers from their own files: loading undici's main entry replaces the\n// dispatcher of Node's built-in fetch, which then rejects requests that set their own\n// Content-Length on Node 22/24 (https://github.com/nodejs/undici/issues/5500)\n/* eslint-disable import/extensions -- required by the ESM build: undici has no exports map */\nimport ProxyAgent from 'undici/lib/dispatcher/proxy-agent.js';\nimport Dispatcher1Wrapper from 'undici/lib/dispatcher/dispatcher1-wrapper.js';\nimport Dispatcher from 'undici/lib/dispatcher/dispatcher.js';\nimport connect from 'undici/lib/api/api-connect.js';\n/* eslint-enable import/extensions */\n\n// undici's main entry adds connect() to every dispatcher. ProxyAgent needs it to open the CONNECT\n// tunnel used for https targets, so add it here since the main entry is skipped.\nDispatcher.prototype.connect ??= connect;\n\n// TODO: once core Node exposes a stable way to create a ProxyAgent we will use that instead of undici\n\ninterface StrapiFetchOptions {\n logs?: boolean;\n}\n\nconst isStream = (body: RequestInit['body']) =>\n body instanceof ReadableStream ||\n (typeof body === 'object' && body !== null && Symbol.asyncIterator in body);\n\n// Node's built-in fetch adds its own Content-Length, and undici 8 dispatchers reject the duplicated\n// header (https://github.com/nodejs/undici/issues/5500), so drop the caller's one when proxying.\n// A stream body has no length of its own and keeps the header, otherwise it would be sent chunked.\n// TODO: remove once https://github.com/nodejs/undici/pull/5502 is released and installed\nconst withoutContentLength = (\n input: Parameters<Fetch>[0],\n init?: RequestInit\n): RequestInit | undefined => {\n if (isStream(init?.body)) {\n return init;\n }\n\n const headers = new Headers(\n init?.headers ?? (input instanceof Request ? input.headers : undefined)\n );\n\n if (!headers.has('content-length')) {\n return init;\n }\n\n headers.delete('content-length');\n\n return { ...init, headers };\n};\n\n// Create a wrapper for Node's Fetch API that applies a global proxy\nexport const createStrapiFetch = (strapi: Core.Strapi, options?: StrapiFetchOptions): Fetch => {\n const { logs = true } = options ?? {};\n\n const strapiFetch: Fetch = (url, options) => {\n const { dispatcher } = strapiFetch;\n\n // Cast: the global RequestInit types its dispatcher with Node's bundled undici types, which\n // differ from the installed undici version; Dispatcher1Wrapper makes them compatible at runtime\n const fetchOptions = (\n dispatcher ? { dispatcher, ...withoutContentLength(url, options) } : options\n ) as RequestInit | undefined;\n\n if (logs) {\n strapi.log.debug(`Making request for ${url}`);\n }\n\n return fetch(url, fetchOptions);\n };\n\n const proxy =\n strapi.config.get<ConstructorParameters<typeof ProxyAgent>[0]>('server.proxy.fetch') ||\n strapi.config.get<string>('server.proxy.global');\n\n if (proxy) {\n if (logs) {\n strapi.log.info(`Using proxy for Fetch requests: ${proxy}`);\n }\n // Node's built-in fetch runs its own bundled undici, which may still use the legacy (v1)\n // dispatcher handler API that undici 8 removed. Dispatcher1Wrapper bridges both APIs.\n strapiFetch.dispatcher = new Dispatcher1Wrapper(new ProxyAgent(proxy));\n }\n\n return strapiFetch;\n};\n\nexport type Fetch = Modules.Fetch.Fetch;\n"],"names":["Dispatcher","prototype","connect","isStream","body","ReadableStream","Symbol","asyncIterator","withoutContentLength","input","init","headers","Headers","Request","undefined","has","delete","createStrapiFetch","strapi","options","logs","strapiFetch","url","dispatcher","fetchOptions","log","debug","fetch","proxy","config","get","info","Dispatcher1Wrapper","ProxyAgent"],"mappings":";;;;;AASA;AAGA;AACAA,qBAAAA;AAAAA,CAAAA,wBAAAA,UAAAA,CAAWC,SAAS,EAACC,OAAAA,KAArBF,sBAAqBE,OAAAA,GAAYA,OAAAA,CAAAA;AAQjC,MAAMC,QAAAA,GAAW,CAACC,IAAAA,GAChBA,IAAAA,YAAgBC,cAAAA,IACf,OAAOD,IAAAA,KAAS,QAAA,IAAYA,IAAAA,KAAS,IAAA,IAAQE,MAAAA,CAAOC,aAAa,IAAIH,IAAAA;AAExE;AACA;AACA;AACA;AACA,MAAMI,oBAAAA,GAAuB,CAC3BC,KAAAA,EACAC,IAAAA,GAAAA;IAEA,IAAIP,QAAAA,CAASO,MAAMN,IAAAA,CAAAA,EAAO;QACxB,OAAOM,IAAAA;AACT,IAAA;IAEA,MAAMC,OAAAA,GAAU,IAAIC,OAAAA,CAClBF,IAAAA,EAAMC,OAAAA,KAAYF,KAAAA,YAAiBI,OAAAA,GAAUJ,KAAAA,CAAME,OAAO,GAAGG,SAAQ,CAAA,CAAA;AAGvE,IAAA,IAAI,CAACH,OAAAA,CAAQI,GAAG,CAAC,gBAAA,CAAA,EAAmB;QAClC,OAAOL,IAAAA;AACT,IAAA;AAEAC,IAAAA,OAAAA,CAAQK,MAAM,CAAC,gBAAA,CAAA;IAEf,OAAO;AAAE,QAAA,GAAGN,IAAI;AAAEC,QAAAA;AAAQ,KAAA;AAC5B,CAAA;AAEA;AACO,MAAMM,iBAAAA,GAAoB,CAACC,MAAAA,EAAqBC,OAAAA,GAAAA;AACrD,IAAA,MAAM,EAAEC,IAAAA,GAAO,IAAI,EAAE,GAAGD,WAAW,EAAC;IAEpC,MAAME,WAAAA,GAAqB,CAACC,GAAAA,EAAKH,OAAAA,GAAAA;QAC/B,MAAM,EAAEI,UAAU,EAAE,GAAGF,WAAAA;;;AAIvB,QAAA,MAAMG,eACJD,UAAAA,GAAa;AAAEA,YAAAA,UAAAA;YAAY,GAAGf,oBAAAA,CAAqBc,KAAKH,OAAAA;SAAS,GAAIA,OAAAA;AAGvE,QAAA,IAAIC,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACC,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,GAAAA,CAAAA,CAAK,CAAA;AAC9C,QAAA;AAEA,QAAA,OAAOK,MAAML,GAAAA,EAAKE,YAAAA,CAAAA;AACpB,IAAA,CAAA;IAEA,MAAMI,KAAAA,GACJV,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAA8C,oBAAA,CAAA,IAC/DZ,MAAAA,CAAOW,MAAM,CAACC,GAAG,CAAS,qBAAA,CAAA;AAE5B,IAAA,IAAIF,KAAAA,EAAO;AACT,QAAA,IAAIR,IAAAA,EAAM;AACRF,YAAAA,MAAAA,CAAOO,GAAG,CAACM,IAAI,CAAC,CAAC,gCAAgC,EAAEH,KAAAA,CAAAA,CAAO,CAAA;AAC5D,QAAA;;;AAGAP,QAAAA,WAAAA,CAAYE,UAAU,GAAG,IAAIS,kBAAAA,CAAmB,IAAIC,UAAAA,CAAWL,KAAAA,CAAAA,CAAAA;AACjE,IAAA;IAEA,OAAOP,WAAAA;AACT;;;;"}
|
|
@@ -302,6 +302,10 @@ const createCompoLinkModel = (contentType, identifiers)=>{
|
|
|
302
302
|
};
|
|
303
303
|
const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
304
304
|
const models = [];
|
|
305
|
+
const reservedAttributeNames = new Set([
|
|
306
|
+
'document_id',
|
|
307
|
+
identifiers.ID_COLUMN
|
|
308
|
+
]);
|
|
305
309
|
contentTypes.forEach((contentType)=>{
|
|
306
310
|
assert__default.default(contentType.collectionName, 'Content type "collectionName" is required');
|
|
307
311
|
assert__default.default(contentType.modelName, 'Content type "modelName" is required');
|
|
@@ -316,13 +320,9 @@ const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
|
316
320
|
} : {};
|
|
317
321
|
// TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists
|
|
318
322
|
// Prevent user from creating a documentId attribute
|
|
319
|
-
const reservedAttributeNames = [
|
|
320
|
-
'document_id',
|
|
321
|
-
identifiers.ID_COLUMN
|
|
322
|
-
];
|
|
323
323
|
Object.keys(contentType.attributes || {}).forEach((attributeName)=>{
|
|
324
324
|
const snakeCasedAttributeName = ___default.default.snakeCase(attributeName);
|
|
325
|
-
if (reservedAttributeNames.
|
|
325
|
+
if (reservedAttributeNames.has(snakeCasedAttributeName)) {
|
|
326
326
|
throw new Error(`The attribute "${attributeName}" is reserved and cannot be used in a model. Please rename "${contentType.modelName}" attribute "${attributeName}" to something else.`);
|
|
327
327
|
}
|
|
328
328
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","reservedAttributeNames","attributeName","snakeCasedAttributeName","_","snakeCase","includes","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;;;;;;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAA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;AAACtD,wBAAAA,WAAAA,CAAYX,cAAc;AAAE,wBAAA;AAAY,qBAAA,CAAA;;oBAExEkE,OAAAA,EAAS;AAAC,wBAAA,YAAA;AAAc,wBAAA,QAAA;AAAU,wBAAA;AAAc,qBAAA,CAC7C4B,MAAM,CAAC,CAACC,IAAMH,KAAAA,CAAM/C,UAAU,CAACkD,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC7F,IAAAA,GAASF,WAAAA,CAAYgG,aAAa,CAACX,kBAAAA,CAAEC,SAAS,CAACpF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOgB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOjB,MAAAA;AACT;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.js","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n const reservedAttributeNames = new Set(['document_id', identifiers.ID_COLUMN]);\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.has(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","reservedAttributeNames","Set","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","attributeName","snakeCasedAttributeName","_","snakeCase","has","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;;;;;;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA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,CAAYX,cAAc;AAAE,wBAAA;AAAY,qBAAA,CAAA;;oBAExEkE,OAAAA,EAAS;AAAC,wBAAA,YAAA;AAAc,wBAAA,QAAA;AAAU,wBAAA;AAAc,qBAAA,CAC7C6B,MAAM,CAAC,CAACC,IAAMH,KAAAA,CAAMhD,UAAU,CAACmD,CAAAA,CAAE,CAAA,CACjCC,GAAG,CAAC,CAAC9F,IAAAA,GAASF,WAAAA,CAAYiG,aAAa,CAACX,kBAAAA,CAAEC,SAAS,CAACrF,IAAAA,CAAAA,CAAAA;AACzD;AACD,aAAA;AACH,QAAA;AAEAwE,QAAAA,MAAAA,CAAOiB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOlB,MAAAA;AACT;;;;;;;;;;;;;;"}
|
|
@@ -295,6 +295,10 @@ const createCompoLinkModel = (contentType, identifiers)=>{
|
|
|
295
295
|
};
|
|
296
296
|
const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
297
297
|
const models = [];
|
|
298
|
+
const reservedAttributeNames = new Set([
|
|
299
|
+
'document_id',
|
|
300
|
+
identifiers.ID_COLUMN
|
|
301
|
+
]);
|
|
298
302
|
contentTypes.forEach((contentType)=>{
|
|
299
303
|
assert(contentType.collectionName, 'Content type "collectionName" is required');
|
|
300
304
|
assert(contentType.modelName, 'Content type "modelName" is required');
|
|
@@ -309,13 +313,9 @@ const transformContentTypesToModels = (contentTypes, identifiers)=>{
|
|
|
309
313
|
} : {};
|
|
310
314
|
// TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists
|
|
311
315
|
// Prevent user from creating a documentId attribute
|
|
312
|
-
const reservedAttributeNames = [
|
|
313
|
-
'document_id',
|
|
314
|
-
identifiers.ID_COLUMN
|
|
315
|
-
];
|
|
316
316
|
Object.keys(contentType.attributes || {}).forEach((attributeName)=>{
|
|
317
317
|
const snakeCasedAttributeName = _.snakeCase(attributeName);
|
|
318
|
-
if (reservedAttributeNames.
|
|
318
|
+
if (reservedAttributeNames.has(snakeCasedAttributeName)) {
|
|
319
319
|
throw new Error(`The attribute "${attributeName}" is reserved and cannot be used in a model. Please rename "${contentType.modelName}" attribute "${attributeName}" to something else.`);
|
|
320
320
|
}
|
|
321
321
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","reservedAttributeNames","attributeName","snakeCasedAttributeName","_","snakeCase","includes","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAMG,mCAAmC,CAACN,WAAAA,GAAAA;IAC/C,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAM,QAAA;YAAUC,YAAAA,EAAc;AAAM,SAAA;AACtC,QAAA;YAAED,IAAAA,EAAM,IAAA;YAAMC,YAAAA,EAAc;AAAM;AACnC,KAAA,CAAA;AACH;AAEO,MA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,MAAAA,CAAOgB,IAAI,CAACC,KAAAA,CAAAA;AACd,IAAA,CAAA,CAAA;IAEA,OAAOjB,MAAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>> &\n Pick<Model, 'lifecycles'>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n const reservedAttributeNames = new Set(['document_id', identifiers.ID_COLUMN]);\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.has(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n indexes: contentType.indexes as Model['indexes'],\n foreignKeys: contentType.foreignKeys as Model['foreignKeys'],\n lifecycles: contentType?.lifecycles ?? {},\n };\n\n // Document lookups: secondary btree index declared here so syncSchema owns it\n // (instead of DDL in internal migration `5.0.0-06-add-document-id-indexes`, now a no-op).\n // Keep the exact same name/columns schema sync already produced so existing databases\n // see no index diff on upgrade (a rename would orphan the old index, since the schema\n // builder's dropIndex is a silent no-op unless forceMigration is enabled).\n if (contentType.modelType === 'contentType') {\n model.indexes = [\n ...(model.indexes || []),\n {\n name: identifiers.getIndexName([contentType.collectionName, 'documents']),\n // Filter attributes that are not in the schema\n columns: ['documentId', 'locale', 'publishedAt']\n .filter((n) => model.attributes[n])\n .map((name) => identifiers.getColumnName(_.snakeCase(name))),\n },\n ];\n }\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":["getComponentJoinTableName","collectionName","identifiers","getNameFromTokens","name","compressible","shortName","getDzJoinTableName","getComponentJoinColumnEntityName","getComponentJoinColumnInverseName","getComponentTypeColumn","getComponentFkIndexName","contentType","transformAttribute","attribute","type","relation","multiple","target","morphBy","joinTableName","joinColumnEntityName","joinColumnInverseName","compTypeColumn","repeatable","component","joinTable","joinColumn","referencedColumn","ID_COLUMN","inverseJoinColumn","on","field","orderColumnName","ORDER_COLUMN","orderBy","order","pivotColumns","FIELD_COLUMN","morphColumn","idColumn","typeColumn","typeField","transformAttributes","Object","keys","attributes","reduce","attrs","attrName","hasComponentsOrDz","values","some","createDocumentId","createId","createCompoLinkModel","entityId","componentId","fkIndex","singularName","uid","tableName","column","unsigned","defaultTo","indexes","getIndexName","columns","getUniqueIndexName","foreignKeys","referencedColumns","referencedTable","getTableName","onDelete","transformContentTypesToModels","contentTypes","models","reservedAttributeNames","Set","forEach","assert","modelName","documentIdAttribute","modelType","documentId","default","attributeName","snakeCasedAttributeName","_","snakeCase","has","Error","compoLinkModel","push","model","lifecycles","filter","n","map","getColumnName"],"mappings":";;;;AAMA;;;;;;;;;;;AAWC,IAEM,MAAMA,yBAAAA,GAA4B,CAACC,cAAAA,EAAwBC,WAAAA,GAAAA;IAChE,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAME,kBAAAA,GAAqB,CAACN,cAAAA,EAAwBC,WAAAA,GAAAA;IACzD,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAMH,cAAAA;YAAgBI,YAAAA,EAAc;AAAK,SAAA;AAC3C,QAAA;YAAED,IAAAA,EAAM,YAAA;YAAcE,SAAAA,EAAW,MAAA;YAAQD,YAAAA,EAAc;AAAM;AAC9D,KAAA,CAAA;AACH;AAEO,MAAMG,mCAAmC,CAACN,WAAAA,GAAAA;IAC/C,OAAOA,WAAAA,CAAYC,iBAAiB,CAAC;AACnC,QAAA;YAAEC,IAAAA,EAAM,QAAA;YAAUC,YAAAA,EAAc;AAAM,SAAA;AACtC,QAAA;YAAED,IAAAA,EAAM,IAAA;YAAMC,YAAAA,EAAc;AAAM;AACnC,KAAA,CAAA;AACH;AAEO,MAAMI,oCAAoC,CAACP,WAAAA,GAAAA;IAChD,OAAOA,WAAAA,CAAYC,iBAA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,IAAA,CAAA,CAAA;IAEA,OAAOlB,MAAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.59.0",
|
|
4
4
|
"description": "Core of Strapi",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"@casl/ability": "6.7.5",
|
|
61
61
|
"@koa/cors": "5.0.0",
|
|
62
62
|
"@koa/router": "12.0.2",
|
|
63
|
-
"@modelcontextprotocol/node": "2.
|
|
64
|
-
"@modelcontextprotocol/server": "2.
|
|
63
|
+
"@modelcontextprotocol/node": "2.1.1",
|
|
64
|
+
"@modelcontextprotocol/server": "2.3.1",
|
|
65
65
|
"@paralleldrive/cuid2": "2.2.2",
|
|
66
|
-
"@strapi/admin": "5.
|
|
67
|
-
"@strapi/database": "5.
|
|
68
|
-
"@strapi/generators": "5.
|
|
69
|
-
"@strapi/logger": "5.
|
|
70
|
-
"@strapi/openapi": "5.
|
|
71
|
-
"@strapi/permissions": "5.
|
|
72
|
-
"@strapi/types": "5.
|
|
73
|
-
"@strapi/typescript-utils": "5.
|
|
74
|
-
"@strapi/utils": "5.
|
|
66
|
+
"@strapi/admin": "5.59.0",
|
|
67
|
+
"@strapi/database": "5.59.0",
|
|
68
|
+
"@strapi/generators": "5.59.0",
|
|
69
|
+
"@strapi/logger": "5.59.0",
|
|
70
|
+
"@strapi/openapi": "5.59.0",
|
|
71
|
+
"@strapi/permissions": "5.59.0",
|
|
72
|
+
"@strapi/types": "5.59.0",
|
|
73
|
+
"@strapi/typescript-utils": "5.59.0",
|
|
74
|
+
"@strapi/utils": "5.59.0",
|
|
75
75
|
"@vercel/stega": "0.1.2",
|
|
76
76
|
"bcryptjs": "2.4.3",
|
|
77
77
|
"boxen": "5.1.2",
|
|
@@ -113,12 +113,12 @@
|
|
|
113
113
|
"resolve.exports": "2.0.2",
|
|
114
114
|
"semver": "7.7.4",
|
|
115
115
|
"typescript": "5.9.3",
|
|
116
|
-
"undici": "
|
|
116
|
+
"undici": "8.12.1",
|
|
117
117
|
"yup": "0.32.9",
|
|
118
118
|
"zod": "4.4.3"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
|
-
"@modelcontextprotocol/client": "2.
|
|
121
|
+
"@modelcontextprotocol/client": "2.3.1",
|
|
122
122
|
"@swc/core": "1.13.5",
|
|
123
123
|
"@types/bcryptjs": "2.4.3",
|
|
124
124
|
"@types/configstore": "5.0.1",
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"@types/json-logic-js": "2.0.8",
|
|
131
131
|
"@types/koa": "2.15.2",
|
|
132
132
|
"@types/koa-compress": "4.0.3",
|
|
133
|
+
"@types/koa-favicon": "2.1.5",
|
|
133
134
|
"@types/koa-static": "4.0.2",
|
|
134
135
|
"@types/koa__router": "12.0.0",
|
|
135
136
|
"@types/lodash": "^4.14.191",
|
|
@@ -137,12 +138,12 @@
|
|
|
137
138
|
"@types/node": "20.19.41",
|
|
138
139
|
"ajv": "8.20.0",
|
|
139
140
|
"ajv-formats": "3.0.1",
|
|
140
|
-
"eslint-config-custom": "5.
|
|
141
|
+
"eslint-config-custom": "5.59.0",
|
|
141
142
|
"jest": "29.6.0",
|
|
142
143
|
"supertest": "7.2.2",
|
|
143
|
-
"tsconfig": "5.
|
|
144
|
+
"tsconfig": "5.59.0",
|
|
144
145
|
"vitest": "catalog:",
|
|
145
|
-
"vitest-config": "5.
|
|
146
|
+
"vitest-config": "5.59.0"
|
|
146
147
|
},
|
|
147
148
|
"engines": {
|
|
148
149
|
"node": ">=20.0.0 <=26.x.x",
|