@strapi/core 5.0.0-beta.2 → 5.0.0-beta.3
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 +30 -34
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +134 -206
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +124 -196
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/config-loader.d.ts.map +1 -1
- package/dist/configuration/config-loader.js +1 -0
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/config-loader.mjs +1 -0
- package/dist/configuration/config-loader.mjs.map +1 -1
- package/dist/configuration/get-dirs.d.ts +10 -0
- package/dist/configuration/get-dirs.d.ts.map +1 -0
- package/dist/{utils → configuration}/get-dirs.js +3 -2
- package/dist/configuration/get-dirs.js.map +1 -0
- package/dist/{utils → configuration}/get-dirs.mjs +3 -2
- package/dist/configuration/get-dirs.mjs.map +1 -0
- package/dist/configuration/index.d.ts +4 -7
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +6 -4
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +5 -4
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/core-api/service/collection-type.d.ts +4 -4
- package/dist/core-api/service/collection-type.d.ts.map +1 -1
- package/dist/core-api/service/collection-type.js +14 -5
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs +14 -5
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/single-type.d.ts.map +1 -1
- package/dist/core-api/service/single-type.js +8 -2
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs +8 -2
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/ee/index.d.ts +2 -0
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/admin.js +0 -1
- package/dist/loaders/admin.js.map +1 -1
- package/dist/loaders/admin.mjs +0 -1
- package/dist/loaders/admin.mjs.map +1 -1
- package/dist/loaders/index.d.ts.map +1 -1
- package/dist/loaders/index.js +0 -2
- package/dist/loaders/index.js.map +1 -1
- package/dist/loaders/index.mjs +0 -2
- package/dist/loaders/index.mjs.map +1 -1
- package/dist/middlewares/body.d.ts +2 -2
- package/dist/middlewares/body.d.ts.map +1 -1
- package/dist/middlewares/body.js +4 -4
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/body.mjs +4 -4
- package/dist/middlewares/body.mjs.map +1 -1
- package/dist/middlewares/public.js +1 -1
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/public.mjs +1 -1
- package/dist/middlewares/public.mjs.map +1 -1
- package/dist/providers/admin.d.ts +3 -0
- package/dist/providers/admin.d.ts.map +1 -0
- package/dist/providers/admin.js +20 -0
- package/dist/providers/admin.js.map +1 -0
- package/dist/providers/admin.mjs +21 -0
- package/dist/providers/admin.mjs.map +1 -0
- package/dist/providers/coreStore.d.ts +3 -0
- package/dist/providers/coreStore.d.ts.map +1 -0
- package/dist/providers/coreStore.js +11 -0
- package/dist/providers/coreStore.js.map +1 -0
- package/dist/providers/coreStore.mjs +12 -0
- package/dist/providers/coreStore.mjs.map +1 -0
- package/dist/providers/cron.d.ts +3 -0
- package/dist/providers/cron.d.ts.map +1 -0
- package/dist/providers/cron.js +20 -0
- package/dist/providers/cron.js.map +1 -0
- package/dist/providers/cron.mjs +21 -0
- package/dist/providers/cron.mjs.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +11 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +11 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/providers/provider.d.ts +9 -0
- package/dist/providers/provider.d.ts.map +1 -0
- package/dist/providers/provider.js +5 -0
- package/dist/providers/provider.js.map +1 -0
- package/dist/providers/provider.mjs +5 -0
- package/dist/providers/provider.mjs.map +1 -0
- package/dist/providers/registries.d.ts +3 -0
- package/dist/providers/registries.d.ts.map +1 -0
- package/dist/providers/registries.js +33 -0
- package/dist/providers/registries.js.map +1 -0
- package/dist/providers/registries.mjs +34 -0
- package/dist/providers/registries.mjs.map +1 -0
- package/dist/providers/telemetry.d.ts +3 -0
- package/dist/providers/telemetry.d.ts.map +1 -0
- package/dist/providers/telemetry.js +19 -0
- package/dist/providers/telemetry.js.map +1 -0
- package/dist/providers/telemetry.mjs +20 -0
- package/dist/providers/telemetry.mjs.map +1 -0
- package/dist/providers/webhooks.d.ts +3 -0
- package/dist/providers/webhooks.d.ts.map +1 -0
- package/dist/providers/webhooks.js +30 -0
- package/dist/providers/webhooks.js.map +1 -0
- package/dist/providers/webhooks.mjs +31 -0
- package/dist/providers/webhooks.mjs.map +1 -0
- package/dist/registries/index.d.ts +0 -1
- package/dist/registries/index.d.ts.map +1 -1
- package/dist/services/config.d.ts +3 -0
- package/dist/services/config.d.ts.map +1 -0
- package/dist/{registries → services}/config.js +11 -7
- package/dist/services/config.js.map +1 -0
- package/dist/{registries → services}/config.mjs +10 -7
- package/dist/services/config.mjs.map +1 -0
- package/dist/services/document-service/attributes/index.d.ts.map +1 -0
- package/dist/services/document-service/attributes/index.js.map +1 -0
- package/dist/services/document-service/attributes/index.mjs.map +1 -0
- package/dist/services/document-service/attributes/transforms.d.ts.map +1 -0
- package/dist/services/document-service/attributes/transforms.js.map +1 -0
- package/dist/services/document-service/attributes/transforms.mjs.map +1 -0
- package/dist/services/document-service/common.d.ts +1 -1
- package/dist/services/document-service/common.d.ts.map +1 -1
- package/dist/services/document-service/common.js.map +1 -1
- package/dist/services/document-service/common.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +97 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/{entity-service → document-service}/components.js +21 -27
- package/dist/services/document-service/components.js.map +1 -0
- package/dist/services/{entity-service → document-service}/components.mjs +21 -27
- package/dist/services/document-service/components.mjs.map +1 -0
- package/dist/services/document-service/entries.d.ts +8 -0
- package/dist/services/document-service/entries.d.ts.map +1 -0
- package/dist/services/document-service/entries.js +62 -0
- package/dist/services/document-service/entries.js.map +1 -0
- package/dist/services/document-service/entries.mjs +62 -0
- package/dist/services/document-service/entries.mjs.map +1 -0
- package/dist/services/document-service/index.d.ts +0 -2
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js +10 -1
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +10 -1
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.d.ts +4 -1
- package/dist/services/document-service/middlewares/middleware-manager.d.ts.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.js +8 -5
- package/dist/services/document-service/middlewares/middleware-manager.js.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.mjs +8 -5
- package/dist/services/document-service/middlewares/middleware-manager.mjs.map +1 -1
- package/dist/services/document-service/params.d.ts +7 -1
- package/dist/services/document-service/params.d.ts.map +1 -1
- package/dist/services/document-service/params.js.map +1 -0
- package/dist/services/document-service/params.mjs.map +1 -0
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +73 -104
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +57 -88
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/query.d.ts +5 -0
- package/dist/services/document-service/transform/query.d.ts.map +1 -0
- package/dist/services/document-service/transform/query.js +9 -0
- package/dist/services/document-service/transform/query.js.map +1 -0
- package/dist/services/document-service/transform/query.mjs +9 -0
- package/dist/services/document-service/transform/query.mjs.map +1 -0
- package/dist/services/entity-service/index.d.ts.map +1 -1
- package/dist/services/entity-service/index.js +11 -4
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs +11 -4
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/reloader.d.ts +7 -0
- package/dist/services/reloader.d.ts.map +1 -0
- package/dist/services/reloader.js +36 -0
- package/dist/services/reloader.js.map +1 -0
- package/dist/services/reloader.mjs +36 -0
- package/dist/services/reloader.mjs.map +1 -0
- package/dist/services/server/register-routes.js +1 -1
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +1 -1
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +1 -1
- package/dist/services/webhook-store.d.ts.map +1 -1
- package/dist/services/webhook-store.js +5 -6
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +5 -6
- package/dist/services/webhook-store.mjs.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/resolve-working-dirs.d.ts +19 -0
- package/dist/utils/resolve-working-dirs.d.ts.map +1 -0
- package/dist/utils/resolve-working-dirs.js +13 -0
- package/dist/utils/resolve-working-dirs.js.map +1 -0
- package/dist/utils/resolve-working-dirs.mjs +11 -0
- package/dist/utils/resolve-working-dirs.mjs.map +1 -0
- package/dist/utils/update-notifier/index.d.ts +1 -6
- package/dist/utils/update-notifier/index.d.ts.map +1 -1
- package/dist/utils/update-notifier/index.js +11 -14
- package/dist/utils/update-notifier/index.js.map +1 -1
- package/dist/utils/update-notifier/index.mjs +11 -14
- package/dist/utils/update-notifier/index.mjs.map +1 -1
- package/package.json +20 -20
- package/dist/registries/config.d.ts +0 -4
- package/dist/registries/config.d.ts.map +0 -1
- package/dist/registries/config.js.map +0 -1
- package/dist/registries/config.mjs.map +0 -1
- package/dist/services/entity-service/attributes/index.d.ts.map +0 -1
- package/dist/services/entity-service/attributes/index.js.map +0 -1
- package/dist/services/entity-service/attributes/index.mjs.map +0 -1
- package/dist/services/entity-service/attributes/transforms.d.ts.map +0 -1
- package/dist/services/entity-service/attributes/transforms.js.map +0 -1
- package/dist/services/entity-service/attributes/transforms.mjs.map +0 -1
- package/dist/services/entity-service/components.d.ts +0 -95
- package/dist/services/entity-service/components.d.ts.map +0 -1
- package/dist/services/entity-service/components.js.map +0 -1
- package/dist/services/entity-service/components.mjs.map +0 -1
- package/dist/services/entity-service/params.d.ts +0 -8
- package/dist/services/entity-service/params.d.ts.map +0 -1
- package/dist/services/entity-service/params.js.map +0 -1
- package/dist/services/entity-service/params.mjs.map +0 -1
- package/dist/utils/get-dirs.d.ts +0 -9
- package/dist/utils/get-dirs.d.ts.map +0 -1
- package/dist/utils/get-dirs.js.map +0 -1
- package/dist/utils/get-dirs.mjs.map +0 -1
- /package/dist/services/{entity-service → document-service}/attributes/index.d.ts +0 -0
- /package/dist/services/{entity-service → document-service}/attributes/index.js +0 -0
- /package/dist/services/{entity-service → document-service}/attributes/index.mjs +0 -0
- /package/dist/services/{entity-service → document-service}/attributes/transforms.d.ts +0 -0
- /package/dist/services/{entity-service → document-service}/attributes/transforms.js +0 -0
- /package/dist/services/{entity-service → document-service}/attributes/transforms.mjs +0 -0
- /package/dist/services/{entity-service → document-service}/params.js +0 -0
- /package/dist/services/{entity-service → document-service}/params.mjs +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transforms.js","sources":["../../../../src/services/document-service/attributes/transforms.ts"],"sourcesContent":["import { getOr, toNumber, isString } from 'lodash/fp';\nimport type { Schema } from '@strapi/types';\nimport bcrypt from 'bcryptjs';\n\ntype Transforms = {\n [TKind in Schema.Attribute.Kind]?: (\n value: unknown,\n context: {\n attribute: Schema.Attribute.AnyAttribute;\n attributeName: string;\n }\n ) => any;\n};\n\nconst transforms: Transforms = {\n password(value, context) {\n const { attribute } = context;\n\n if (attribute.type !== 'password') {\n throw new Error('Invalid attribute type');\n }\n\n if (!isString(value) && !(value instanceof Buffer)) {\n return value;\n }\n\n const rounds = toNumber(getOr(10, 'encryption.rounds', attribute));\n\n return bcrypt.hashSync(value.toString(), rounds);\n },\n};\n\nexport default transforms;\n"],"names":["isString","toNumber","getOr","bcrypt"],"mappings":";;;;;AAcA,MAAM,aAAyB;AAAA,EAC7B,SAAS,OAAO,SAAS;AACjB,UAAA,EAAE,UAAc,IAAA;AAElB,QAAA,UAAU,SAAS,YAAY;AAC3B,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,QAAI,CAACA,EAAS,SAAA,KAAK,KAAK,EAAE,iBAAiB,SAAS;AAC3C,aAAA;AAAA,IACT;AAEA,UAAM,SAASC,EAAAA,SAASC,EAAA,MAAM,IAAI,qBAAqB,SAAS,CAAC;AAEjE,WAAOC,gBAAAA,QAAO,SAAS,MAAM,YAAY,MAAM;AAAA,EACjD;AACF;;"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transforms.mjs","sources":["../../../../src/services/document-service/attributes/transforms.ts"],"sourcesContent":["import { getOr, toNumber, isString } from 'lodash/fp';\nimport type { Schema } from '@strapi/types';\nimport bcrypt from 'bcryptjs';\n\ntype Transforms = {\n [TKind in Schema.Attribute.Kind]?: (\n value: unknown,\n context: {\n attribute: Schema.Attribute.AnyAttribute;\n attributeName: string;\n }\n ) => any;\n};\n\nconst transforms: Transforms = {\n password(value, context) {\n const { attribute } = context;\n\n if (attribute.type !== 'password') {\n throw new Error('Invalid attribute type');\n }\n\n if (!isString(value) && !(value instanceof Buffer)) {\n return value;\n }\n\n const rounds = toNumber(getOr(10, 'encryption.rounds', attribute));\n\n return bcrypt.hashSync(value.toString(), rounds);\n },\n};\n\nexport default transforms;\n"],"names":[],"mappings":";;AAcA,MAAM,aAAyB;AAAA,EAC7B,SAAS,OAAO,SAAS;AACjB,UAAA,EAAE,UAAc,IAAA;AAElB,QAAA,UAAU,SAAS,YAAY;AAC3B,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,QAAI,CAAC,SAAS,KAAK,KAAK,EAAE,iBAAiB,SAAS;AAC3C,aAAA;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,MAAM,IAAI,qBAAqB,SAAS,CAAC;AAEjE,WAAO,OAAO,SAAS,MAAM,YAAY,MAAM;AAAA,EACjD;AACF;"}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { UID, Modules } from '@strapi/types';
|
2
|
-
export type RepositoryFactoryMethod = <
|
2
|
+
export type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(uid: TContentTypeUID) => Modules.Documents.ServiceInstance<TContentTypeUID>;
|
3
3
|
export declare const wrapInTransaction: (fn: (...args: any) => any) => (...args: any[]) => Promise<any>;
|
4
4
|
//# sourceMappingURL=common.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAAG,CAAC,
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAAG,CAAC,eAAe,SAAS,GAAG,CAAC,WAAW,EAC5E,GAAG,EAAE,eAAe,KACjB,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,iBAAiB,iBAAkB,GAAG,KAAK,GAAG,eACxC,GAAG,EAAE,iBACvB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"common.js","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <
|
1
|
+
{"version":3,"file":"common.js","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(\n uid: TContentTypeUID\n) => Modules.Documents.ServiceInstance<TContentTypeUID>;\n\nexport const wrapInTransaction = (fn: (...args: any) => any) => {\n return (...args: any[]) => strapi.db.transaction?.(() => fn(...args));\n};\n"],"names":[],"mappings":";;AAMa,MAAA,oBAAoB,CAAC,OAA8B;AACvD,SAAA,IAAI,SAAgB,OAAO,GAAG,cAAc,MAAM,GAAG,GAAG,IAAI,CAAC;AACtE;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"common.mjs","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <
|
1
|
+
{"version":3,"file":"common.mjs","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(\n uid: TContentTypeUID\n) => Modules.Documents.ServiceInstance<TContentTypeUID>;\n\nexport const wrapInTransaction = (fn: (...args: any) => any) => {\n return (...args: any[]) => strapi.db.transaction?.(() => fn(...args));\n};\n"],"names":[],"mappings":"AAMa,MAAA,oBAAoB,CAAC,OAA8B;AACvD,SAAA,IAAI,SAAgB,OAAO,GAAG,cAAc,MAAM,GAAG,GAAG,IAAI,CAAC;AACtE;"}
|
@@ -1,2 +1,98 @@
|
|
1
|
-
|
1
|
+
import type { Struct, Utils, UID, Schema, Data, Modules } from '@strapi/types';
|
2
|
+
type LoadedComponents<TUID extends UID.Schema> = Data.Entity<TUID, Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>>;
|
3
|
+
type SingleComponentValue = Schema.Attribute.ComponentValue<UID.Component, false>;
|
4
|
+
type RepeatableComponentValue = Schema.Attribute.ComponentValue<UID.Component, true>;
|
5
|
+
type ComponentValue = SingleComponentValue | RepeatableComponentValue;
|
6
|
+
type DynamicZoneValue = Schema.Attribute.DynamicZoneValue<UID.Component[]>;
|
7
|
+
type ComponentBody = {
|
8
|
+
[key: string]: ComponentValue | DynamicZoneValue;
|
9
|
+
};
|
10
|
+
declare function omitComponentData(contentType: Struct.ContentTypeSchema, data: Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>): Partial<Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>>;
|
11
|
+
declare function omitComponentData(contentType: Struct.ComponentSchema, data: Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>): Partial<Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>>;
|
12
|
+
declare const createComponents: <TUID extends UID.Schema, TData extends Modules.EntityService.Params.Data.Input<TUID>>(uid: TUID, data: TData) => Promise<ComponentBody>;
|
13
|
+
declare const getComponents: <TUID extends UID.Schema>(uid: TUID, entity: {
|
14
|
+
id: Modules.EntityService.Params.Attribute.ID;
|
15
|
+
}) => Promise<LoadedComponents<TUID>>;
|
16
|
+
declare const updateComponents: <TUID extends UID.Schema, TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>>(uid: TUID, entityToUpdate: {
|
17
|
+
id: Modules.EntityService.Params.Attribute.ID;
|
18
|
+
}, data: TData) => Promise<ComponentBody>;
|
19
|
+
declare const deleteComponents: <TUID extends UID.Schema, TEntity extends Data.Entity<TUID, Extract<keyof Schema.Attributes<TUID>, string>>>(uid: TUID, entityToDelete: TEntity, { loadComponents }?: {
|
20
|
+
loadComponents?: boolean | undefined;
|
21
|
+
}) => Promise<void>;
|
22
|
+
declare const deleteComponent: <TUID extends `${string}.${string}`>(uid: TUID, componentToDelete: {
|
23
|
+
id: Data.ID;
|
24
|
+
} & Pick<{ [TAttributeName in Extract<keyof Schema.Attributes<TUID>, string>]?: Utils.If<Utils.IsTrue<Utils.IsTrue<Utils.Extends<{
|
25
|
+
biginteger: Schema.Attribute.GetBigIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
26
|
+
boolean: Schema.Attribute.GetBooleanValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
27
|
+
blocks: Schema.Attribute.GetBlocksValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
28
|
+
decimal: Schema.Attribute.GetDecimalValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
29
|
+
enumeration: Schema.Attribute.GetEnumerationValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
30
|
+
email: Schema.Attribute.GetEmailValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
31
|
+
float: Schema.Attribute.GetFloatValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
32
|
+
integer: Schema.Attribute.GetIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
33
|
+
json: Schema.Attribute.GetJsonValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
34
|
+
password: Schema.Attribute.GetPasswordValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
35
|
+
richtext: Schema.Attribute.GetRichTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
36
|
+
string: Schema.Attribute.GetStringValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
37
|
+
text: Schema.Attribute.GetTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
38
|
+
uid: Schema.Attribute.GetUIDValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
39
|
+
date: Schema.Attribute.GetDateValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
40
|
+
datetime: Schema.Attribute.GetDateTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
41
|
+
time: Schema.Attribute.GetTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
42
|
+
timestamp: Schema.Attribute.GetTimestampValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
43
|
+
component: Schema.Attribute.GetComponentValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
44
|
+
dynamiczone: Schema.Attribute.GetDynamicZoneValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
45
|
+
media: Schema.Attribute.GetMediaValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
46
|
+
relation: Schema.Attribute.GetRelationValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
47
|
+
}[Schema.Attribute.TypeOf<Schema.AttributeByName<TUID, TAttributeName>>], never>> | Utils.IsTrue<Utils.Extends<never, {
|
48
|
+
biginteger: Schema.Attribute.GetBigIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
49
|
+
boolean: Schema.Attribute.GetBooleanValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
50
|
+
blocks: Schema.Attribute.GetBlocksValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
51
|
+
decimal: Schema.Attribute.GetDecimalValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
52
|
+
enumeration: Schema.Attribute.GetEnumerationValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
53
|
+
email: Schema.Attribute.GetEmailValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
54
|
+
float: Schema.Attribute.GetFloatValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
55
|
+
integer: Schema.Attribute.GetIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
56
|
+
json: Schema.Attribute.GetJsonValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
57
|
+
password: Schema.Attribute.GetPasswordValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
58
|
+
richtext: Schema.Attribute.GetRichTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
59
|
+
string: Schema.Attribute.GetStringValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
60
|
+
text: Schema.Attribute.GetTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
61
|
+
uid: Schema.Attribute.GetUIDValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
62
|
+
date: Schema.Attribute.GetDateValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
63
|
+
datetime: Schema.Attribute.GetDateTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
64
|
+
time: Schema.Attribute.GetTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
65
|
+
timestamp: Schema.Attribute.GetTimestampValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
66
|
+
component: Schema.Attribute.GetComponentValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
67
|
+
dynamiczone: Schema.Attribute.GetDynamicZoneValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
68
|
+
media: Schema.Attribute.GetMediaValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
69
|
+
relation: Schema.Attribute.GetRelationValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
70
|
+
}[Schema.Attribute.TypeOf<Schema.AttributeByName<TUID, TAttributeName>>]>>>, unknown, {
|
71
|
+
biginteger: Schema.Attribute.GetBigIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
72
|
+
boolean: Schema.Attribute.GetBooleanValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
73
|
+
blocks: Schema.Attribute.GetBlocksValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
74
|
+
decimal: Schema.Attribute.GetDecimalValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
75
|
+
enumeration: Schema.Attribute.GetEnumerationValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
76
|
+
email: Schema.Attribute.GetEmailValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
77
|
+
float: Schema.Attribute.GetFloatValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
78
|
+
integer: Schema.Attribute.GetIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
79
|
+
json: Schema.Attribute.GetJsonValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
80
|
+
password: Schema.Attribute.GetPasswordValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
81
|
+
richtext: Schema.Attribute.GetRichTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
82
|
+
string: Schema.Attribute.GetStringValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
83
|
+
text: Schema.Attribute.GetTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
84
|
+
uid: Schema.Attribute.GetUIDValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
85
|
+
date: Schema.Attribute.GetDateValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
86
|
+
datetime: Schema.Attribute.GetDateTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
87
|
+
time: Schema.Attribute.GetTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
88
|
+
timestamp: Schema.Attribute.GetTimestampValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
89
|
+
component: Schema.Attribute.GetComponentValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
90
|
+
dynamiczone: Schema.Attribute.GetDynamicZoneValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
91
|
+
media: Schema.Attribute.GetMediaValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
92
|
+
relation: Schema.Attribute.GetRelationValue<Schema.AttributeByName<TUID, TAttributeName>>;
|
93
|
+
}[Schema.Attribute.TypeOf<Schema.AttributeByName<TUID, TAttributeName>>]> | null | undefined; }, Extract<keyof Schema.Attributes<TUID>, string>>) => Promise<void>;
|
94
|
+
declare const assignComponentData: <TUID extends UID.ContentType>(data: Modules.EntityService.Params.Data.Input<TUID>, componentData: ComponentBody, { contentType, }: {
|
95
|
+
contentType: Schema.ContentType<TUID>;
|
96
|
+
}) => Partial<Modules.EntityService.Params.Data.Input<UID.ContentType>> & ComponentBody;
|
97
|
+
export { omitComponentData, assignComponentData, getComponents, createComponents, updateComponents, deleteComponents, deleteComponent, };
|
2
98
|
//# sourceMappingURL=components.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/components.ts"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../src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,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,GAC3E,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAoBnF,QAAA,MAAM,gBAAgB,0IAmGrB,CAAC;AAEF,QAAA,MAAM,aAAa,+CAET;IAAE,EAAE,EAAE,QAAQ,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAA;CAAE,oCAS1D,CAAC;AAMF,QAAA,MAAM,gBAAgB,6HAKJ;IAAE,EAAE,EAAE,QAAQ,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAA;CAAE,wCA2ElE,CAAC;AAkGF,QAAA,MAAM,gBAAgB;;mBAyCrB,CAAC;AA8DF,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kKAMpB,CAAC;AAEF,QAAA,MAAM,mBAAmB,qGAER,aAAa;;uFAQ7B,CAAC;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,CAAC"}
|
@@ -5,7 +5,6 @@ const _ = require("lodash/fp");
|
|
5
5
|
const strapiUtils = require("@strapi/utils");
|
6
6
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
7
7
|
const ___default = /* @__PURE__ */ _interopDefault(_$1);
|
8
|
-
const isDialectMySQL = () => strapi.db?.dialect.client === "mysql";
|
9
8
|
function omitComponentData(contentType, data) {
|
10
9
|
const { attributes } = contentType;
|
11
10
|
const componentAttributes = Object.keys(attributes).filter(
|
@@ -34,8 +33,7 @@ const createComponents = async (uid, data) => {
|
|
34
33
|
}
|
35
34
|
const components = await strapiUtils.async.map(
|
36
35
|
componentValue,
|
37
|
-
(value) => createComponent(componentUID, value)
|
38
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
36
|
+
(value) => createComponent(componentUID, value)
|
39
37
|
);
|
40
38
|
componentBody[attributeName] = components.map(({ id }) => {
|
41
39
|
return {
|
@@ -78,8 +76,7 @@ const createComponents = async (uid, data) => {
|
|
78
76
|
};
|
79
77
|
componentBody[attributeName] = await strapiUtils.async.map(
|
80
78
|
dynamiczoneValues,
|
81
|
-
createDynamicZoneComponents
|
82
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
79
|
+
createDynamicZoneComponents
|
83
80
|
);
|
84
81
|
continue;
|
85
82
|
}
|
@@ -111,8 +108,7 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
|
111
108
|
}
|
112
109
|
const components = await strapiUtils.async.map(
|
113
110
|
componentValue,
|
114
|
-
(value) => updateOrCreateComponent(componentUID, value)
|
115
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
111
|
+
(value) => updateOrCreateComponent(componentUID, value)
|
116
112
|
);
|
117
113
|
componentBody[attributeName] = components.filter(___default.default.negate(___default.default.isNil)).map(({ id }) => {
|
118
114
|
return {
|
@@ -139,20 +135,16 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
|
139
135
|
if (!Array.isArray(dynamiczoneValues)) {
|
140
136
|
throw new Error("Expected an array to create repeatable component");
|
141
137
|
}
|
142
|
-
componentBody[attributeName] = await strapiUtils.async.map(
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
};
|
153
|
-
},
|
154
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
155
|
-
);
|
138
|
+
componentBody[attributeName] = await strapiUtils.async.map(dynamiczoneValues, async (value) => {
|
139
|
+
const { id } = await updateOrCreateComponent(value.__component, value);
|
140
|
+
return {
|
141
|
+
id,
|
142
|
+
__component: value.__component,
|
143
|
+
__pivot: {
|
144
|
+
field: attributeName
|
145
|
+
}
|
146
|
+
};
|
147
|
+
});
|
156
148
|
}
|
157
149
|
}
|
158
150
|
return componentBody;
|
@@ -234,16 +226,12 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
|
|
234
226
|
const { component: componentUID } = attribute;
|
235
227
|
await strapiUtils.async.map(
|
236
228
|
___default.default.castArray(value),
|
237
|
-
(subValue) => deleteComponent(componentUID, subValue)
|
238
|
-
{
|
239
|
-
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
|
240
|
-
}
|
229
|
+
(subValue) => deleteComponent(componentUID, subValue)
|
241
230
|
);
|
242
231
|
} else {
|
243
232
|
await strapiUtils.async.map(
|
244
233
|
___default.default.castArray(value),
|
245
|
-
(subValue) => deleteComponent(subValue.__component, subValue)
|
246
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
234
|
+
(subValue) => deleteComponent(subValue.__component, subValue)
|
247
235
|
);
|
248
236
|
}
|
249
237
|
continue;
|
@@ -286,6 +274,12 @@ const deleteComponent = async (uid, componentToDelete) => {
|
|
286
274
|
await deleteComponents(uid, componentToDelete);
|
287
275
|
await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });
|
288
276
|
};
|
277
|
+
const assignComponentData = (data, componentData, {
|
278
|
+
contentType
|
279
|
+
}) => {
|
280
|
+
return Object.assign(omitComponentData(contentType, data), componentData);
|
281
|
+
};
|
282
|
+
exports.assignComponentData = assignComponentData;
|
289
283
|
exports.createComponents = createComponents;
|
290
284
|
exports.deleteComponent = deleteComponent;
|
291
285
|
exports.deleteComponents = deleteComponents;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../src/services/document-service/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { has, omit, pipe, assign } from 'lodash/fp';\nimport type { Struct, Utils, UID, Schema, Data, Modules } from '@strapi/types';\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype SingleComponentValue = Schema.Attribute.ComponentValue<UID.Component, false>;\ntype RepeatableComponentValue = Schema.Attribute.ComponentValue<UID.Component, true>;\n\ntype ComponentValue = SingleComponentValue | RepeatableComponentValue;\n\ntype DynamicZoneValue = Schema.Attribute.DynamicZoneValue<UID.Component[]>;\n\ntype ComponentBody = {\n [key: string]: ComponentValue | DynamicZoneValue;\n};\n\nfunction omitComponentData(\n contentType: Struct.ContentTypeSchema,\n data: Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>>;\nfunction omitComponentData(\n contentType: Struct.ComponentSchema,\n data: Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>>;\nfunction omitComponentData(\n contentType: Struct.Schema,\n data: Modules.EntityService.Params.Data.Input<\n Struct.ContentTypeSchema['uid'] | Struct.ComponentSchema['uid']\n >\n): Partial<\n Modules.EntityService.Params.Data.Input<\n Struct.ContentTypeSchema['uid'] | Struct.ComponentSchema['uid']\n >\n> {\n const { attributes } = contentType;\n const componentAttributes = Object.keys(attributes).filter((attributeName) =>\n contentTypesUtils.isComponentAttribute(attributes[attributeName])\n );\n\n return omit(componentAttributes, data);\n}\n\n// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer\nconst createComponents = async <\n TUID extends UID.Schema,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n>(\n uid: TUID,\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData];\n\n if (componentValue === null) {\n continue;\n }\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n createComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await createComponent(\n componentUID,\n componentValue as Modules.EntityService.Params.Data.Input<UID.Component>\n );\n\n componentBody[attributeName] = {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Modules.EntityService.Params.Attribute.GetValue<Schema.Attribute.DynamicZone>;\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const createDynamicZoneComponents = async (\n value: Utils.Array.Values<typeof dynamiczoneValues>\n ) => {\n const { id } = await createComponent(value.__component, value);\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n };\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n createDynamicZoneComponents\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst getComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entity: { id: Modules.EntityService.Params.Attribute.ID }\n): Promise<LoadedComponents<TUID>> => {\n const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));\n\n if (_.isEmpty(componentAttributes)) {\n return {} as LoadedComponents<TUID>;\n }\n\n return strapi.db.query(uid).load(entity, componentAttributes) as Promise<LoadedComponents<TUID>>;\n};\n\n/*\n delete old components\n create or update\n*/\nconst updateComponents = async <\n TUID extends UID.Schema,\n TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>,\n>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n for (const attributeName of Object.keys(attributes)) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData] as ComponentValue;\n\n await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n updateOrCreateComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await updateOrCreateComponent(componentUID, componentValue);\n componentBody[attributeName] = component && {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[attributeName as keyof TData] as DynamicZoneValue;\n\n await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(dynamiczoneValues, async (value: any) => {\n const { id } = await updateOrCreateComponent(value.__component, value);\n\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n });\n }\n }\n\n return componentBody;\n};\n\nconst pickStringifiedId = ({\n id,\n}: {\n id: Modules.EntityService.Params.Attribute.ID;\n}): Modules.EntityService.Params.Attribute.ID & string => {\n if (typeof id === 'string') {\n return id;\n }\n\n return `${id}`;\n};\n\nconst deleteOldComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n componentUID: UID.Component,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n componentValue: ComponentValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as ComponentValue;\n\n const idsToKeep = _.castArray(componentValue).filter(has('id')).map(pickStringifiedId);\n const allIds = _.castArray(previousValue).filter(has('id')).map(pickStringifiedId);\n\n idsToKeep.forEach((id) => {\n if (!allIds.includes(id)) {\n throw new errors.ApplicationError(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n }\n });\n\n const idsToDelete = _.difference(allIds, idsToKeep);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n await deleteComponent(componentUID, { id: idToDelete });\n }\n }\n};\n\nconst deleteOldDZComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n dynamiczoneValues: DynamicZoneValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as DynamicZoneValue;\n\n const idsToKeep = _.castArray(dynamiczoneValues)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n const allIds = _.castArray(previousValue)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n idsToKeep.forEach(({ id, __component }) => {\n if (!allIds.find((el) => el.id === id && el.__component === __component)) {\n const err = new Error(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n\n Object.assign(err, { status: 400 });\n throw err;\n }\n });\n\n type IdsToDelete = DynamicZoneValue;\n\n const idsToDelete = allIds.reduce((acc, { id, __component }) => {\n if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {\n acc.push({ id, __component });\n }\n\n return acc;\n }, [] as IdsToDelete);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n const { id, __component } = idToDelete;\n await deleteComponent(__component, { id });\n }\n }\n};\n\nconst deleteComponents = async <TUID extends UID.Schema, TEntity extends Data.Entity<TUID>>(\n uid: TUID,\n entityToDelete: TEntity,\n { loadComponents = true } = {}\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (attribute.type === 'component' || attribute.type === 'dynamiczone') {\n let value;\n if (loadComponents) {\n value = await strapi.db.query(uid).load(entityToDelete, attributeName);\n } else {\n value = entityToDelete[attributeName as keyof TEntity];\n }\n\n if (!value) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID } = attribute;\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(componentUID, subValue)\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(subValue.__component, subValue)\n );\n }\n\n continue;\n }\n }\n};\n\n/** *************************\n Component queries\n************************** */\n\n// components can have nested compos so this must be recursive\nconst createComponent = async <TUID extends UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid);\n\n const componentData = await createComponents(uid, data);\n const transform = pipe(\n // Make sure we don't save the component with a pre-defined ID\n omit('id'),\n // Remove the component data from the original data object ...\n (payload) => omitComponentData(model, payload),\n // ... and assign the newly created component instead\n assign(componentData)\n );\n\n return strapi.db.query(uid).create({ data: transform(data) });\n};\n\n// components can have nested compos so this must be recursive\nconst updateComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid);\n\n const componentData = await updateComponents(uid, componentToUpdate, data);\n\n return strapi.db.query(uid).update({\n where: {\n id: componentToUpdate.id,\n },\n data: Object.assign(omitComponentData(model, data), componentData),\n });\n};\n\nconst updateOrCreateComponent = <TUID extends UID.Component>(\n componentUID: TUID,\n value: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n if (value === null) {\n return null;\n }\n\n // update\n if ('id' in value && typeof value.id !== 'undefined') {\n // TODO: verify the compo is associated with the entity\n return updateComponent(componentUID, { id: value.id }, value);\n }\n\n // create\n return createComponent(componentUID, value);\n};\n\nconst deleteComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToDelete: Data.Component<TUID>\n) => {\n await deleteComponents(uid, componentToDelete);\n await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });\n};\n\nconst assignComponentData = <TUID extends UID.ContentType>(\n data: Modules.EntityService.Params.Data.Input<TUID>,\n componentData: ComponentBody,\n {\n contentType,\n }: {\n contentType: Schema.ContentType<TUID>;\n }\n) => {\n return Object.assign(omitComponentData(contentType, data), componentData);\n};\n\nexport {\n omitComponentData,\n assignComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n};\n"],"names":["contentTypesUtils","omit","has","async","_","errors","pipe","assign"],"mappings":";;;;;;;AA6BA,SAAS,kBACP,aACA,MAOA;AACM,QAAA,EAAE,WAAe,IAAA;AACvB,QAAM,sBAAsB,OAAO,KAAK,UAAU,EAAE;AAAA,IAAO,CAAC,kBAC1DA,YAAA,aAAkB,qBAAqB,WAAW,aAAa,CAAC;AAAA,EAAA;AAG3D,SAAAC,EAAA,KAAK,qBAAqB,IAAI;AACvC;AAGM,MAAA,mBAAmB,OAIvB,KACA,SACG;AACH,QAAM,EAAE,aAAa,OAAO,OAAO,SAAS,GAAG;AAE/C,QAAM,gBAA+B,CAAA;AAE/B,QAA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;;;;;;;;"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import _ from "lodash";
|
2
2
|
import { omit, has, pipe, assign } from "lodash/fp";
|
3
3
|
import { contentTypes, async, errors } from "@strapi/utils";
|
4
|
-
const isDialectMySQL = () => strapi.db?.dialect.client === "mysql";
|
5
4
|
function omitComponentData(contentType, data) {
|
6
5
|
const { attributes } = contentType;
|
7
6
|
const componentAttributes = Object.keys(attributes).filter(
|
@@ -30,8 +29,7 @@ const createComponents = async (uid, data) => {
|
|
30
29
|
}
|
31
30
|
const components = await async.map(
|
32
31
|
componentValue,
|
33
|
-
(value) => createComponent(componentUID, value)
|
34
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
32
|
+
(value) => createComponent(componentUID, value)
|
35
33
|
);
|
36
34
|
componentBody[attributeName] = components.map(({ id }) => {
|
37
35
|
return {
|
@@ -74,8 +72,7 @@ const createComponents = async (uid, data) => {
|
|
74
72
|
};
|
75
73
|
componentBody[attributeName] = await async.map(
|
76
74
|
dynamiczoneValues,
|
77
|
-
createDynamicZoneComponents
|
78
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
75
|
+
createDynamicZoneComponents
|
79
76
|
);
|
80
77
|
continue;
|
81
78
|
}
|
@@ -107,8 +104,7 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
|
107
104
|
}
|
108
105
|
const components = await async.map(
|
109
106
|
componentValue,
|
110
|
-
(value) => updateOrCreateComponent(componentUID, value)
|
111
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
107
|
+
(value) => updateOrCreateComponent(componentUID, value)
|
112
108
|
);
|
113
109
|
componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {
|
114
110
|
return {
|
@@ -135,20 +131,16 @@ const updateComponents = async (uid, entityToUpdate, data) => {
|
|
135
131
|
if (!Array.isArray(dynamiczoneValues)) {
|
136
132
|
throw new Error("Expected an array to create repeatable component");
|
137
133
|
}
|
138
|
-
componentBody[attributeName] = await async.map(
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
};
|
149
|
-
},
|
150
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
151
|
-
);
|
134
|
+
componentBody[attributeName] = await async.map(dynamiczoneValues, async (value) => {
|
135
|
+
const { id } = await updateOrCreateComponent(value.__component, value);
|
136
|
+
return {
|
137
|
+
id,
|
138
|
+
__component: value.__component,
|
139
|
+
__pivot: {
|
140
|
+
field: attributeName
|
141
|
+
}
|
142
|
+
};
|
143
|
+
});
|
152
144
|
}
|
153
145
|
}
|
154
146
|
return componentBody;
|
@@ -230,16 +222,12 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
|
|
230
222
|
const { component: componentUID } = attribute;
|
231
223
|
await async.map(
|
232
224
|
_.castArray(value),
|
233
|
-
(subValue) => deleteComponent(componentUID, subValue)
|
234
|
-
{
|
235
|
-
concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity
|
236
|
-
}
|
225
|
+
(subValue) => deleteComponent(componentUID, subValue)
|
237
226
|
);
|
238
227
|
} else {
|
239
228
|
await async.map(
|
240
229
|
_.castArray(value),
|
241
|
-
(subValue) => deleteComponent(subValue.__component, subValue)
|
242
|
-
{ concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }
|
230
|
+
(subValue) => deleteComponent(subValue.__component, subValue)
|
243
231
|
);
|
244
232
|
}
|
245
233
|
continue;
|
@@ -282,7 +270,13 @@ const deleteComponent = async (uid, componentToDelete) => {
|
|
282
270
|
await deleteComponents(uid, componentToDelete);
|
283
271
|
await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });
|
284
272
|
};
|
273
|
+
const assignComponentData = (data, componentData, {
|
274
|
+
contentType
|
275
|
+
}) => {
|
276
|
+
return Object.assign(omitComponentData(contentType, data), componentData);
|
277
|
+
};
|
285
278
|
export {
|
279
|
+
assignComponentData,
|
286
280
|
createComponents,
|
287
281
|
deleteComponent,
|
288
282
|
deleteComponents,
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"components.mjs","sources":["../../../src/services/document-service/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { has, omit, pipe, assign } from 'lodash/fp';\nimport type { Struct, Utils, UID, Schema, Data, Modules } from '@strapi/types';\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype SingleComponentValue = Schema.Attribute.ComponentValue<UID.Component, false>;\ntype RepeatableComponentValue = Schema.Attribute.ComponentValue<UID.Component, true>;\n\ntype ComponentValue = SingleComponentValue | RepeatableComponentValue;\n\ntype DynamicZoneValue = Schema.Attribute.DynamicZoneValue<UID.Component[]>;\n\ntype ComponentBody = {\n [key: string]: ComponentValue | DynamicZoneValue;\n};\n\nfunction omitComponentData(\n contentType: Struct.ContentTypeSchema,\n data: Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>>;\nfunction omitComponentData(\n contentType: Struct.ComponentSchema,\n data: Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>>;\nfunction omitComponentData(\n contentType: Struct.Schema,\n data: Modules.EntityService.Params.Data.Input<\n Struct.ContentTypeSchema['uid'] | Struct.ComponentSchema['uid']\n >\n): Partial<\n Modules.EntityService.Params.Data.Input<\n Struct.ContentTypeSchema['uid'] | Struct.ComponentSchema['uid']\n >\n> {\n const { attributes } = contentType;\n const componentAttributes = Object.keys(attributes).filter((attributeName) =>\n contentTypesUtils.isComponentAttribute(attributes[attributeName])\n );\n\n return omit(componentAttributes, data);\n}\n\n// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer\nconst createComponents = async <\n TUID extends UID.Schema,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n>(\n uid: TUID,\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData];\n\n if (componentValue === null) {\n continue;\n }\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n createComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await createComponent(\n componentUID,\n componentValue as Modules.EntityService.Params.Data.Input<UID.Component>\n );\n\n componentBody[attributeName] = {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Modules.EntityService.Params.Attribute.GetValue<Schema.Attribute.DynamicZone>;\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const createDynamicZoneComponents = async (\n value: Utils.Array.Values<typeof dynamiczoneValues>\n ) => {\n const { id } = await createComponent(value.__component, value);\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n };\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n createDynamicZoneComponents\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst getComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entity: { id: Modules.EntityService.Params.Attribute.ID }\n): Promise<LoadedComponents<TUID>> => {\n const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));\n\n if (_.isEmpty(componentAttributes)) {\n return {} as LoadedComponents<TUID>;\n }\n\n return strapi.db.query(uid).load(entity, componentAttributes) as Promise<LoadedComponents<TUID>>;\n};\n\n/*\n delete old components\n create or update\n*/\nconst updateComponents = async <\n TUID extends UID.Schema,\n TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>,\n>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n for (const attributeName of Object.keys(attributes)) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData] as ComponentValue;\n\n await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n updateOrCreateComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await updateOrCreateComponent(componentUID, componentValue);\n componentBody[attributeName] = component && {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[attributeName as keyof TData] as DynamicZoneValue;\n\n await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(dynamiczoneValues, async (value: any) => {\n const { id } = await updateOrCreateComponent(value.__component, value);\n\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n });\n }\n }\n\n return componentBody;\n};\n\nconst pickStringifiedId = ({\n id,\n}: {\n id: Modules.EntityService.Params.Attribute.ID;\n}): Modules.EntityService.Params.Attribute.ID & string => {\n if (typeof id === 'string') {\n return id;\n }\n\n return `${id}`;\n};\n\nconst deleteOldComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n componentUID: UID.Component,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n componentValue: ComponentValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as ComponentValue;\n\n const idsToKeep = _.castArray(componentValue).filter(has('id')).map(pickStringifiedId);\n const allIds = _.castArray(previousValue).filter(has('id')).map(pickStringifiedId);\n\n idsToKeep.forEach((id) => {\n if (!allIds.includes(id)) {\n throw new errors.ApplicationError(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n }\n });\n\n const idsToDelete = _.difference(allIds, idsToKeep);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n await deleteComponent(componentUID, { id: idToDelete });\n }\n }\n};\n\nconst deleteOldDZComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n dynamiczoneValues: DynamicZoneValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as DynamicZoneValue;\n\n const idsToKeep = _.castArray(dynamiczoneValues)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n const allIds = _.castArray(previousValue)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n idsToKeep.forEach(({ id, __component }) => {\n if (!allIds.find((el) => el.id === id && el.__component === __component)) {\n const err = new Error(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n\n Object.assign(err, { status: 400 });\n throw err;\n }\n });\n\n type IdsToDelete = DynamicZoneValue;\n\n const idsToDelete = allIds.reduce((acc, { id, __component }) => {\n if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {\n acc.push({ id, __component });\n }\n\n return acc;\n }, [] as IdsToDelete);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n const { id, __component } = idToDelete;\n await deleteComponent(__component, { id });\n }\n }\n};\n\nconst deleteComponents = async <TUID extends UID.Schema, TEntity extends Data.Entity<TUID>>(\n uid: TUID,\n entityToDelete: TEntity,\n { loadComponents = true } = {}\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (attribute.type === 'component' || attribute.type === 'dynamiczone') {\n let value;\n if (loadComponents) {\n value = await strapi.db.query(uid).load(entityToDelete, attributeName);\n } else {\n value = entityToDelete[attributeName as keyof TEntity];\n }\n\n if (!value) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID } = attribute;\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(componentUID, subValue)\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(subValue.__component, subValue)\n );\n }\n\n continue;\n }\n }\n};\n\n/** *************************\n Component queries\n************************** */\n\n// components can have nested compos so this must be recursive\nconst createComponent = async <TUID extends UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid);\n\n const componentData = await createComponents(uid, data);\n const transform = pipe(\n // Make sure we don't save the component with a pre-defined ID\n omit('id'),\n // Remove the component data from the original data object ...\n (payload) => omitComponentData(model, payload),\n // ... and assign the newly created component instead\n assign(componentData)\n );\n\n return strapi.db.query(uid).create({ data: transform(data) });\n};\n\n// components can have nested compos so this must be recursive\nconst updateComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid);\n\n const componentData = await updateComponents(uid, componentToUpdate, data);\n\n return strapi.db.query(uid).update({\n where: {\n id: componentToUpdate.id,\n },\n data: Object.assign(omitComponentData(model, data), componentData),\n });\n};\n\nconst updateOrCreateComponent = <TUID extends UID.Component>(\n componentUID: TUID,\n value: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n if (value === null) {\n return null;\n }\n\n // update\n if ('id' in value && typeof value.id !== 'undefined') {\n // TODO: verify the compo is associated with the entity\n return updateComponent(componentUID, { id: value.id }, value);\n }\n\n // create\n return createComponent(componentUID, value);\n};\n\nconst deleteComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToDelete: Data.Component<TUID>\n) => {\n await deleteComponents(uid, componentToDelete);\n await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });\n};\n\nconst assignComponentData = <TUID extends UID.ContentType>(\n data: Modules.EntityService.Params.Data.Input<TUID>,\n componentData: ComponentBody,\n {\n contentType,\n }: {\n contentType: Schema.ContentType<TUID>;\n }\n) => {\n return Object.assign(omitComponentData(contentType, data), componentData);\n};\n\nexport {\n omitComponentData,\n assignComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n};\n"],"names":["contentTypesUtils"],"mappings":";;;AA6BA,SAAS,kBACP,aACA,MAOA;AACM,QAAA,EAAE,WAAe,IAAA;AACvB,QAAM,sBAAsB,OAAO,KAAK,UAAU,EAAE;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aAAa,IAAI,GAAG,aAAa;AAC1E;"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { UID } from '@strapi/types';
|
2
|
+
declare const createEntriesService: (uid: UID.ContentType) => {
|
3
|
+
create: (params?: any) => Promise<any>;
|
4
|
+
delete: (id: number) => Promise<void>;
|
5
|
+
update: (entryToUpdate: any, params?: any) => Promise<any>;
|
6
|
+
};
|
7
|
+
export { createEntriesService };
|
8
|
+
//# sourceMappingURL=entries.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAUzC,QAAA,MAAM,oBAAoB,QAAS,IAAI,WAAW;;iBA+BjB,MAAM;4BAQK,GAAG;CA8B9C,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const components = require("./components.js");
|
4
|
+
const idTransform = require("./transform/id-transform.js");
|
5
|
+
const query = require("./transform/query.js");
|
6
|
+
const params = require("./params.js");
|
7
|
+
const index$1 = require("./attributes/index.js");
|
8
|
+
const index = require("../entity-validator/index.js");
|
9
|
+
const createEntriesService = (uid) => {
|
10
|
+
const contentType = strapi.contentType(uid);
|
11
|
+
async function createEntry(params$1 = {}) {
|
12
|
+
const { data, ...restParams } = await idTransform.transformParamsDocumentId(uid, params$1);
|
13
|
+
const query$1 = query.transformParamsToQuery(uid, params.pickSelectionParams(restParams));
|
14
|
+
if (!data) {
|
15
|
+
throw new Error("Create requires data attribute");
|
16
|
+
}
|
17
|
+
const validData = await index.validateEntityCreation(contentType, data, {
|
18
|
+
// Note: publishedAt value will always be set when DP is disabled
|
19
|
+
isDraft: !params$1?.data?.publishedAt,
|
20
|
+
locale: params$1?.locale
|
21
|
+
});
|
22
|
+
const componentData = await components.createComponents(uid, validData);
|
23
|
+
const dataWithComponents = components.assignComponentData(validData, componentData, {
|
24
|
+
contentType
|
25
|
+
});
|
26
|
+
const entryData = index$1.applyTransforms(dataWithComponents, { contentType });
|
27
|
+
const doc = await strapi.db.query(uid).create({ ...query$1, data: entryData });
|
28
|
+
return doc;
|
29
|
+
}
|
30
|
+
async function deleteEntry(id) {
|
31
|
+
const componentsToDelete = await components.getComponents(uid, { id });
|
32
|
+
await strapi.db.query(uid).delete({ where: { id } });
|
33
|
+
await components.deleteComponents(uid, componentsToDelete, { loadComponents: false });
|
34
|
+
}
|
35
|
+
async function updateEntry(entryToUpdate, params$1 = {}) {
|
36
|
+
const { data, ...restParams } = await idTransform.transformParamsDocumentId(uid, params$1);
|
37
|
+
const query$1 = query.transformParamsToQuery(uid, params.pickSelectionParams(restParams));
|
38
|
+
const validData = await index.validateEntityUpdate(
|
39
|
+
contentType,
|
40
|
+
data,
|
41
|
+
{
|
42
|
+
isDraft: !params$1?.data?.publishedAt,
|
43
|
+
// Always update the draft version
|
44
|
+
locale: params$1?.locale
|
45
|
+
},
|
46
|
+
entryToUpdate
|
47
|
+
);
|
48
|
+
const componentData = await components.updateComponents(uid, entryToUpdate, validData);
|
49
|
+
const dataWithComponents = components.assignComponentData(validData, componentData, {
|
50
|
+
contentType
|
51
|
+
});
|
52
|
+
const entryData = index$1.applyTransforms(dataWithComponents, { contentType });
|
53
|
+
return strapi.db.query(uid).update({ ...query$1, where: { id: entryToUpdate.id }, data: entryData });
|
54
|
+
}
|
55
|
+
return {
|
56
|
+
create: createEntry,
|
57
|
+
delete: deleteEntry,
|
58
|
+
update: updateEntry
|
59
|
+
};
|
60
|
+
};
|
61
|
+
exports.createEntriesService = createEntriesService;
|
62
|
+
//# sourceMappingURL=entries.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"entries.js","sources":["../../../src/services/document-service/entries.ts"],"sourcesContent":["import type { UID } from '@strapi/types';\n\nimport * as components from './components';\n\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { transformParamsToQuery } from './transform/query';\nimport { pickSelectionParams } from './params';\nimport { applyTransforms } from './attributes';\nimport entityValidator from '../entity-validator';\n\nconst createEntriesService = (uid: UID.ContentType) => {\n const contentType = strapi.contentType(uid);\n\n async function createEntry(params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n // Validation\n if (!data) {\n throw new Error('Create requires data attribute');\n }\n\n const validData = await entityValidator.validateEntityCreation(contentType, data, {\n // Note: publishedAt value will always be set when DP is disabled\n isDraft: !params?.data?.publishedAt,\n locale: params?.locale,\n });\n\n // Component handling\n const componentData = await components.createComponents(uid, validData);\n const dataWithComponents = components.assignComponentData(validData, componentData, {\n contentType,\n });\n const entryData = applyTransforms(dataWithComponents, { contentType });\n\n const doc = await strapi.db.query(uid).create({ ...query, data: entryData });\n\n return doc;\n }\n\n async function deleteEntry(id: number) {\n const componentsToDelete = await components.getComponents(uid, { id });\n\n await strapi.db.query(uid).delete({ where: { id } });\n\n await components.deleteComponents(uid, componentsToDelete as any, { loadComponents: false });\n }\n\n async function updateEntry(entryToUpdate: any, params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n const validData = await entityValidator.validateEntityUpdate(\n contentType,\n data,\n {\n isDraft: !params?.data?.publishedAt, // Always update the draft version\n locale: params?.locale,\n },\n entryToUpdate\n );\n // Component handling\n const componentData = await components.updateComponents(uid, entryToUpdate, validData as any);\n const dataWithComponents = components.assignComponentData(validData, componentData, {\n contentType,\n });\n const entryData = applyTransforms(dataWithComponents, { contentType });\n\n return strapi.db\n .query(uid)\n .update({ ...query, where: { id: entryToUpdate.id }, data: entryData });\n }\n\n return {\n create: createEntry,\n delete: deleteEntry,\n update: updateEntry,\n };\n};\n\nexport { createEntriesService };\n"],"names":["params","transformParamsDocumentId","query","transformParamsToQuery","pickSelectionParams","entityValidator","components.createComponents","components.assignComponentData","applyTransforms","components.getComponents","components.deleteComponents","components.updateComponents"],"mappings":";;;;;;;;AAUM,MAAA,uBAAuB,CAAC,QAAyB;AAC/C,QAAA,cAAc,OAAO,YAAY,GAAG;AAE3B,iBAAA,YAAYA,WAAS,IAAW;AACvC,UAAA,EAAE,MAAM,GAAG,WAAA,IAAe,MAAMC,sCAA0B,KAAKD,QAAM;AAE3E,UAAME,UAAQC,MAAAA,uBAAuB,KAAKC,OAAAA,oBAAoB,UAAU,CAAQ;AAGhF,QAAI,CAAC,MAAM;AACH,YAAA,IAAI,MAAM,gCAAgC;AAAA,IAClD;AAEA,UAAM,YAAY,MAAMC,MAAgB,uBAAuB,aAAa,MAAM;AAAA;AAAA,MAEhF,SAAS,CAACL,UAAQ,MAAM;AAAA,MACxB,QAAQA,UAAQ;AAAA,IAAA,CACjB;AAGD,UAAM,gBAAgB,MAAMM,WAAAA,iBAA4B,KAAK,SAAS;AACtE,UAAM,qBAAqBC,WAAAA,oBAA+B,WAAW,eAAe;AAAA,MAClF;AAAA,IAAA,CACD;AACD,UAAM,YAAYC,QAAA,gBAAgB,oBAAoB,EAAE,YAAa,CAAA;AAErE,UAAM,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,EAAE,OAAO,EAAE,GAAGN,SAAO,MAAM,UAAW,CAAA;AAEpE,WAAA;AAAA,EACT;AAEA,iBAAe,YAAY,IAAY;AACrC,UAAM,qBAAqB,MAAMO,yBAAyB,KAAK,EAAE,GAAI,CAAA;AAE/D,UAAA,OAAO,GAAG,MAAM,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAA,CAAG;AAEnD,UAAMC,WAAAA,iBAA4B,KAAK,oBAA2B,EAAE,gBAAgB,OAAO;AAAA,EAC7F;AAEA,iBAAe,YAAY,eAAoBV,WAAS,IAAW;AAC3D,UAAA,EAAE,MAAM,GAAG,WAAA,IAAe,MAAMC,sCAA0B,KAAKD,QAAM;AAC3E,UAAME,UAAQC,MAAAA,uBAAuB,KAAKC,OAAAA,oBAAoB,UAAU,CAAQ;AAE1E,UAAA,YAAY,MAAMC,MAAgB;AAAA,MACtC;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,CAACL,UAAQ,MAAM;AAAA;AAAA,QACxB,QAAQA,UAAQ;AAAA,MAClB;AAAA,MACA;AAAA,IAAA;AAGF,UAAM,gBAAgB,MAAMW,WAA4B,iBAAA,KAAK,eAAe,SAAgB;AAC5F,UAAM,qBAAqBJ,WAAAA,oBAA+B,WAAW,eAAe;AAAA,MAClF;AAAA,IAAA,CACD;AACD,UAAM,YAAYC,QAAA,gBAAgB,oBAAoB,EAAE,YAAa,CAAA;AAErE,WAAO,OAAO,GACX,MAAM,GAAG,EACT,OAAO,EAAE,GAAGN,SAAO,OAAO,EAAE,IAAI,cAAc,GAAM,GAAA,MAAM,WAAW;AAAA,EAC1E;AAEO,SAAA;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA;AAEZ;;"}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { createComponents, assignComponentData, getComponents, deleteComponents, updateComponents } from "./components.mjs";
|
2
|
+
import { transformParamsDocumentId as curriedTransformParamsDocumentId } from "./transform/id-transform.mjs";
|
3
|
+
import { transformParamsToQuery } from "./transform/query.mjs";
|
4
|
+
import { pickSelectionParams } from "./params.mjs";
|
5
|
+
import { applyTransforms } from "./attributes/index.mjs";
|
6
|
+
import entityValidator from "../entity-validator/index.mjs";
|
7
|
+
const createEntriesService = (uid) => {
|
8
|
+
const contentType = strapi.contentType(uid);
|
9
|
+
async function createEntry(params = {}) {
|
10
|
+
const { data, ...restParams } = await curriedTransformParamsDocumentId(uid, params);
|
11
|
+
const query = transformParamsToQuery(uid, pickSelectionParams(restParams));
|
12
|
+
if (!data) {
|
13
|
+
throw new Error("Create requires data attribute");
|
14
|
+
}
|
15
|
+
const validData = await entityValidator.validateEntityCreation(contentType, data, {
|
16
|
+
// Note: publishedAt value will always be set when DP is disabled
|
17
|
+
isDraft: !params?.data?.publishedAt,
|
18
|
+
locale: params?.locale
|
19
|
+
});
|
20
|
+
const componentData = await createComponents(uid, validData);
|
21
|
+
const dataWithComponents = assignComponentData(validData, componentData, {
|
22
|
+
contentType
|
23
|
+
});
|
24
|
+
const entryData = applyTransforms(dataWithComponents, { contentType });
|
25
|
+
const doc = await strapi.db.query(uid).create({ ...query, data: entryData });
|
26
|
+
return doc;
|
27
|
+
}
|
28
|
+
async function deleteEntry(id) {
|
29
|
+
const componentsToDelete = await getComponents(uid, { id });
|
30
|
+
await strapi.db.query(uid).delete({ where: { id } });
|
31
|
+
await deleteComponents(uid, componentsToDelete, { loadComponents: false });
|
32
|
+
}
|
33
|
+
async function updateEntry(entryToUpdate, params = {}) {
|
34
|
+
const { data, ...restParams } = await curriedTransformParamsDocumentId(uid, params);
|
35
|
+
const query = transformParamsToQuery(uid, pickSelectionParams(restParams));
|
36
|
+
const validData = await entityValidator.validateEntityUpdate(
|
37
|
+
contentType,
|
38
|
+
data,
|
39
|
+
{
|
40
|
+
isDraft: !params?.data?.publishedAt,
|
41
|
+
// Always update the draft version
|
42
|
+
locale: params?.locale
|
43
|
+
},
|
44
|
+
entryToUpdate
|
45
|
+
);
|
46
|
+
const componentData = await updateComponents(uid, entryToUpdate, validData);
|
47
|
+
const dataWithComponents = assignComponentData(validData, componentData, {
|
48
|
+
contentType
|
49
|
+
});
|
50
|
+
const entryData = applyTransforms(dataWithComponents, { contentType });
|
51
|
+
return strapi.db.query(uid).update({ ...query, where: { id: entryToUpdate.id }, data: entryData });
|
52
|
+
}
|
53
|
+
return {
|
54
|
+
create: createEntry,
|
55
|
+
delete: deleteEntry,
|
56
|
+
update: updateEntry
|
57
|
+
};
|
58
|
+
};
|
59
|
+
export {
|
60
|
+
createEntriesService
|
61
|
+
};
|
62
|
+
//# sourceMappingURL=entries.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"entries.mjs","sources":["../../../src/services/document-service/entries.ts"],"sourcesContent":["import type { UID } from '@strapi/types';\n\nimport * as components from './components';\n\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { transformParamsToQuery } from './transform/query';\nimport { pickSelectionParams } from './params';\nimport { applyTransforms } from './attributes';\nimport entityValidator from '../entity-validator';\n\nconst createEntriesService = (uid: UID.ContentType) => {\n const contentType = strapi.contentType(uid);\n\n async function createEntry(params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n // Validation\n if (!data) {\n throw new Error('Create requires data attribute');\n }\n\n const validData = await entityValidator.validateEntityCreation(contentType, data, {\n // Note: publishedAt value will always be set when DP is disabled\n isDraft: !params?.data?.publishedAt,\n locale: params?.locale,\n });\n\n // Component handling\n const componentData = await components.createComponents(uid, validData);\n const dataWithComponents = components.assignComponentData(validData, componentData, {\n contentType,\n });\n const entryData = applyTransforms(dataWithComponents, { contentType });\n\n const doc = await strapi.db.query(uid).create({ ...query, data: entryData });\n\n return doc;\n }\n\n async function deleteEntry(id: number) {\n const componentsToDelete = await components.getComponents(uid, { id });\n\n await strapi.db.query(uid).delete({ where: { id } });\n\n await components.deleteComponents(uid, componentsToDelete as any, { loadComponents: false });\n }\n\n async function updateEntry(entryToUpdate: any, params = {} as any) {\n const { data, ...restParams } = await transformParamsDocumentId(uid, params);\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams) as any); // select / populate\n\n const validData = await entityValidator.validateEntityUpdate(\n contentType,\n data,\n {\n isDraft: !params?.data?.publishedAt, // Always update the draft version\n locale: params?.locale,\n },\n entryToUpdate\n );\n // Component handling\n const componentData = await components.updateComponents(uid, entryToUpdate, validData as any);\n const dataWithComponents = components.assignComponentData(validData, componentData, {\n contentType,\n });\n const entryData = applyTransforms(dataWithComponents, { contentType });\n\n return strapi.db\n .query(uid)\n .update({ ...query, where: { id: entryToUpdate.id }, data: entryData });\n }\n\n return {\n create: createEntry,\n delete: deleteEntry,\n update: updateEntry,\n };\n};\n\nexport { createEntriesService };\n"],"names":["transformParamsDocumentId","components.createComponents","components.assignComponentData","components.getComponents","components.deleteComponents","components.updateComponents"],"mappings":";;;;;;AAUM,MAAA,uBAAuB,CAAC,QAAyB;AAC/C,QAAA,cAAc,OAAO,YAAY,GAAG;AAE3B,iBAAA,YAAY,SAAS,IAAW;AACvC,UAAA,EAAE,MAAM,GAAG,WAAA,IAAe,MAAMA,iCAA0B,KAAK,MAAM;AAE3E,UAAM,QAAQ,uBAAuB,KAAK,oBAAoB,UAAU,CAAQ;AAGhF,QAAI,CAAC,MAAM;AACH,YAAA,IAAI,MAAM,gCAAgC;AAAA,IAClD;AAEA,UAAM,YAAY,MAAM,gBAAgB,uBAAuB,aAAa,MAAM;AAAA;AAAA,MAEhF,SAAS,CAAC,QAAQ,MAAM;AAAA,MACxB,QAAQ,QAAQ;AAAA,IAAA,CACjB;AAGD,UAAM,gBAAgB,MAAMC,iBAA4B,KAAK,SAAS;AACtE,UAAM,qBAAqBC,oBAA+B,WAAW,eAAe;AAAA,MAClF;AAAA,IAAA,CACD;AACD,UAAM,YAAY,gBAAgB,oBAAoB,EAAE,YAAa,CAAA;AAErE,UAAM,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,MAAM,UAAW,CAAA;AAEpE,WAAA;AAAA,EACT;AAEA,iBAAe,YAAY,IAAY;AACrC,UAAM,qBAAqB,MAAMC,cAAyB,KAAK,EAAE,GAAI,CAAA;AAE/D,UAAA,OAAO,GAAG,MAAM,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAA,CAAG;AAEnD,UAAMC,iBAA4B,KAAK,oBAA2B,EAAE,gBAAgB,OAAO;AAAA,EAC7F;AAEA,iBAAe,YAAY,eAAoB,SAAS,IAAW;AAC3D,UAAA,EAAE,MAAM,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