@strapi/data-transfer 5.47.1 → 5.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/directory/providers/destination/index.d.ts +1 -1
- package/dist/directory/providers/destination/index.d.ts.map +1 -1
- package/dist/directory/providers/destination/index.js.map +1 -1
- package/dist/directory/providers/destination/index.mjs.map +1 -1
- package/dist/directory/providers/source/index.d.ts +1 -1
- package/dist/directory/providers/source/index.d.ts.map +1 -1
- package/dist/directory/providers/source/index.js.map +1 -1
- package/dist/directory/providers/source/index.mjs.map +1 -1
- package/dist/engine/index.d.ts +1 -1
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/index.mjs.map +1 -1
- package/dist/engine/validation/provider.d.ts +1 -1
- package/dist/engine/validation/provider.d.ts.map +1 -1
- package/dist/engine/validation/provider.js.map +1 -1
- package/dist/engine/validation/provider.mjs.map +1 -1
- package/dist/errors/providers.d.ts +1 -1
- package/dist/errors/providers.d.ts.map +1 -1
- package/dist/errors/providers.js.map +1 -1
- package/dist/errors/providers.mjs.map +1 -1
- package/dist/file/providers/destination/index.d.ts +1 -1
- package/dist/file/providers/destination/index.d.ts.map +1 -1
- package/dist/file/providers/destination/index.js.map +1 -1
- package/dist/file/providers/destination/index.mjs.map +1 -1
- package/dist/file/providers/source/index.d.ts +1 -1
- package/dist/file/providers/source/index.d.ts.map +1 -1
- package/dist/file/providers/source/index.js.map +1 -1
- package/dist/file/providers/source/index.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts +9 -4
- package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/assets-destination-writable.js +67 -49
- package/dist/strapi/providers/local-destination/assets-destination-writable.js.map +1 -1
- package/dist/strapi/providers/local-destination/assets-destination-writable.mjs +67 -49
- package/dist/strapi/providers/local-destination/assets-destination-writable.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/index.d.ts +1 -1
- package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/index.js.map +1 -1
- package/dist/strapi/providers/local-destination/index.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js +13 -25
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +14 -26
- package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -4
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +0 -4
- package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.js +22 -3
- package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.mjs +22 -3
- package/dist/strapi/providers/local-destination/strategies/restore/links.mjs.map +1 -1
- package/dist/strapi/providers/local-source/assets.d.ts +1 -1
- package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/assets.js.map +1 -1
- package/dist/strapi/providers/local-source/assets.mjs.map +1 -1
- package/dist/strapi/providers/local-source/configuration.js.map +1 -1
- package/dist/strapi/providers/local-source/configuration.mjs.map +1 -1
- package/dist/strapi/providers/local-source/entities.d.ts +3 -1
- package/dist/strapi/providers/local-source/entities.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/entities.js +7 -3
- package/dist/strapi/providers/local-source/entities.js.map +1 -1
- package/dist/strapi/providers/local-source/entities.mjs +7 -3
- package/dist/strapi/providers/local-source/entities.mjs.map +1 -1
- package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts +1 -1
- package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/estimate-asset-totals.js.map +1 -1
- package/dist/strapi/providers/local-source/estimate-asset-totals.mjs.map +1 -1
- package/dist/strapi/providers/local-source/index.d.ts +2 -2
- package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
- package/dist/strapi/providers/local-source/index.js +6 -1
- package/dist/strapi/providers/local-source/index.js.map +1 -1
- package/dist/strapi/providers/local-source/index.mjs +6 -1
- package/dist/strapi/providers/local-source/index.mjs.map +1 -1
- package/dist/strapi/providers/local-source/links.js.map +1 -1
- package/dist/strapi/providers/local-source/links.mjs.map +1 -1
- package/dist/strapi/providers/remote-destination/index.d.ts +2 -2
- package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -1
- package/dist/strapi/providers/remote-destination/index.js +24 -3
- package/dist/strapi/providers/remote-destination/index.js.map +1 -1
- package/dist/strapi/providers/remote-destination/index.mjs +25 -4
- package/dist/strapi/providers/remote-destination/index.mjs.map +1 -1
- package/dist/strapi/providers/remote-source/index.d.ts +2 -2
- package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
- package/dist/strapi/providers/remote-source/index.js.map +1 -1
- package/dist/strapi/providers/remote-source/index.mjs.map +1 -1
- package/dist/strapi/providers/utils.d.ts +2 -2
- package/dist/strapi/providers/utils.d.ts.map +1 -1
- package/dist/strapi/providers/utils.js.map +1 -1
- package/dist/strapi/providers/utils.mjs.map +1 -1
- package/dist/strapi/queries/link.d.ts +1 -1
- package/dist/strapi/queries/link.d.ts.map +1 -1
- package/dist/strapi/queries/link.js.map +1 -1
- package/dist/strapi/queries/link.mjs.map +1 -1
- package/dist/strapi/remote/flows/index.d.ts +1 -1
- package/dist/strapi/remote/flows/index.d.ts.map +1 -1
- package/dist/strapi/remote/flows/index.js.map +1 -1
- package/dist/strapi/remote/flows/index.mjs.map +1 -1
- package/dist/strapi/remote/handlers/pull.d.ts +1 -1
- package/dist/strapi/remote/handlers/pull.d.ts.map +1 -1
- package/dist/strapi/remote/handlers/pull.js +3 -3
- package/dist/strapi/remote/handlers/pull.js.map +1 -1
- package/dist/strapi/remote/handlers/pull.mjs +3 -3
- package/dist/strapi/remote/handlers/pull.mjs.map +1 -1
- package/dist/strapi/remote/handlers/push.d.ts +1 -1
- package/dist/strapi/remote/handlers/push.d.ts.map +1 -1
- package/dist/strapi/remote/handlers/push.js +7 -1
- package/dist/strapi/remote/handlers/push.js.map +1 -1
- package/dist/strapi/remote/handlers/push.mjs +7 -1
- package/dist/strapi/remote/handlers/push.mjs.map +1 -1
- package/dist/strapi/remote/handlers/utils.d.ts +1 -1
- package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
- package/dist/strapi/remote/handlers/utils.js.map +1 -1
- package/dist/strapi/remote/handlers/utils.mjs.map +1 -1
- package/dist/types/common-entities.d.ts +152 -0
- package/dist/types/common-entities.d.ts.map +1 -0
- package/dist/types/encryption.d.ts +11 -0
- package/dist/types/encryption.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/providers.d.ts +50 -0
- package/dist/types/providers.d.ts.map +1 -0
- package/dist/types/remote/index.d.ts +2 -0
- package/dist/types/remote/index.d.ts.map +1 -0
- package/dist/types/remote/protocol/auth.d.ts +5 -0
- package/dist/types/remote/protocol/auth.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/commands.d.ts +37 -0
- package/dist/types/remote/protocol/client/commands.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/index.d.ts +9 -0
- package/dist/types/remote/protocol/client/index.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/transfer/action.d.ts +5 -0
- package/dist/types/remote/protocol/client/transfer/action.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/transfer/index.d.ts +12 -0
- package/dist/types/remote/protocol/client/transfer/index.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/transfer/pull.d.ts +25 -0
- package/dist/types/remote/protocol/client/transfer/pull.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/transfer/push.d.ts +29 -0
- package/dist/types/remote/protocol/client/transfer/push.d.ts.map +1 -0
- package/dist/types/remote/protocol/client/transfer/utils.d.ts +49 -0
- package/dist/types/remote/protocol/client/transfer/utils.d.ts.map +1 -0
- package/dist/types/remote/protocol/index.d.ts +4 -0
- package/dist/types/remote/protocol/index.d.ts.map +1 -0
- package/dist/types/remote/protocol/server/error.d.ts +18 -0
- package/dist/types/remote/protocol/server/error.d.ts.map +1 -0
- package/dist/types/remote/protocol/server/index.d.ts +3 -0
- package/dist/types/remote/protocol/server/index.d.ts.map +1 -0
- package/dist/types/remote/protocol/server/messaging.d.ts +37 -0
- package/dist/types/remote/protocol/server/messaging.d.ts.map +1 -0
- package/dist/types/transfer-engine.d.ts +149 -0
- package/dist/types/transfer-engine.d.ts.map +1 -0
- package/dist/types/utils.d.ts +83 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/utils/components.d.ts +21 -1
- package/dist/utils/components.d.ts.map +1 -1
- package/dist/utils/components.js +69 -21
- package/dist/utils/components.js.map +1 -1
- package/dist/utils/components.mjs +70 -22
- package/dist/utils/components.mjs.map +1 -1
- package/dist/utils/encryption/decrypt.d.ts +1 -1
- package/dist/utils/encryption/decrypt.d.ts.map +1 -1
- package/dist/utils/encryption/decrypt.js.map +1 -1
- package/dist/utils/encryption/decrypt.mjs.map +1 -1
- package/dist/utils/encryption/encrypt.d.ts +1 -1
- package/dist/utils/encryption/encrypt.d.ts.map +1 -1
- package/dist/utils/encryption/encrypt.js.map +1 -1
- package/dist/utils/encryption/encrypt.mjs.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/middleware.d.ts +1 -1
- package/dist/utils/middleware.d.ts.map +1 -1
- package/dist/utils/middleware.js.map +1 -1
- package/dist/utils/middleware.mjs.map +1 -1
- package/dist/utils/transaction.d.ts +1 -1
- package/dist/utils/transaction.d.ts.map +1 -1
- package/dist/utils/transaction.js.map +1 -1
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/transfer-asset-chunk.d.ts +22 -0
- package/dist/utils/transfer-asset-chunk.d.ts.map +1 -1
- package/dist/utils/transfer-asset-chunk.js +25 -0
- package/dist/utils/transfer-asset-chunk.js.map +1 -1
- package/dist/utils/transfer-asset-chunk.mjs +25 -1
- package/dist/utils/transfer-asset-chunk.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../src/utils/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { get, has, omit, pipe, assign } from 'lodash/fp';\n\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\nimport type { Modules, UID, Data, Utils, Schema, Core } from '@strapi/types';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype ComponentValue = Schema.Attribute.Value<\n Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true>\n>;\n\ntype ComponentBody = {\n [key: string]: Schema.Attribute.Value<\n | Schema.Attribute.Component<UID.Component, false>\n | Schema.Attribute.Component<UID.Component, true>\n | Schema.Attribute.DynamicZone\n >;\n};\n\nconst isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';\n\nfunction omitComponentData(\n contentType: Schema.ContentType,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;\nfunction omitComponentData(\n contentType: Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;\nfunction omitComponentData(\n contentType: Schema.ContentType | Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n): Partial<\n Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\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 = (await async.map(\n componentValue,\n (value: any) => createComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.Component>;\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 = (await async.map(\n componentValue,\n (value: any) => updateOrCreateComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n dynamiczoneValues,\n 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\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: Schema.Attribute.Value<Schema.Attribute.Component>\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: Schema.Attribute.Value<Schema.Attribute.DynamicZone>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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 = Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n _.castArray(value),\n (subValue: any) => deleteComponent(componentUID, subValue),\n {\n concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,\n }\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(subValue.__component, subValue),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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 = UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\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) as Schema.Component;\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\n/**\n * Resolve the component UID of an entity's attribute based\n * on a given path (components & dynamic zones only)\n */\nconst resolveComponentUID = ({\n paths,\n strapi,\n data,\n contentType,\n}: {\n paths: string[];\n strapi: Core.Strapi;\n data: any;\n contentType: Schema.ContentType;\n}): UID.Schema | undefined => {\n let value: unknown = data;\n let cType:\n | Schema.ContentType\n | Schema.Component\n | ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;\n for (const path of paths) {\n value = get(path, value);\n\n // Needed when the value of cType should be computed\n // based on the next value (eg: dynamic zones)\n if (typeof cType === 'function') {\n cType = cType(value);\n }\n\n if (path in cType.attributes) {\n const attribute: Schema.Attribute.AnyAttribute = cType.attributes[path];\n\n if (attribute.type === 'component') {\n cType = strapi.getModel(attribute.component);\n }\n\n if (attribute.type === 'dynamiczone') {\n cType = ({ __component }: { __component: UID.Component }) => strapi.getModel(__component);\n }\n }\n }\n\n if ('uid' in cType) {\n return cType.uid;\n }\n\n return undefined;\n};\n\nexport {\n omitComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n resolveComponentUID,\n};\n"],"names":["isDialectMySQL","strapi","db","dialect","client","omitComponentData","contentType","data","attributes","componentAttributes","Object","keys","filter","attributeName","contentTypesUtils","isComponentAttribute","omit","createComponents","uid","getModel","componentBody","attributeNames","attribute","has","type","component","componentUID","repeatable","componentValue","Array","isArray","Error","components","async","map","value","createComponent","concurrency","inTransaction","Infinity","id","__pivot","field","component_type","dynamiczoneValues","createDynamicZoneComponents","__component","getComponents","entity","getComponentAttributes","_","isEmpty","query","load","deleteComponents","entityToDelete","loadComponents","castArray","subValue","deleteComponent","model","componentData","transform","pipe","payload","assign","create","componentToDelete","delete","where","resolveComponentUID","paths","cType","path","get","undefined"],"mappings":";;;;;;AAuBA,MAAMA,iBAAiB,IAAMC,MAAAA,CAAOC,EAAE,EAAEC,QAAQC,MAAAA,KAAW,OAAA;AAU3D,SAASC,iBAAAA,CACPC,WAAkD,EAClDC,IAAkG,EAAA;IAIlG,MAAM,EAAEC,UAAU,EAAE,GAAGF,WAAAA;AACvB,IAAA,MAAMG,mBAAAA,GAAsBC,MAAAA,CAAOC,IAAI,CAACH,YAAYI,MAAM,CAAC,CAACC,aAAAA,GAC1DC,kBAAAA,CAAkBC,oBAAoB,CAACP,UAAU,CAACK,aAAAA,CAAc,CAAA,CAAA;AAGlE,IAAA,OAAOG,QAAKP,mBAAAA,EAAqBF,IAAAA,CAAAA;AACnC;AAEA;AACA,MAAMU,gBAAAA,GAAmB,OAIvBC,GAAAA,EACAX,IAAAA,GAAAA;IAEA,MAAM,EAAEC,aAAa,EAAE,EAAE,GAAGP,MAAAA,CAAOkB,QAAQ,CAACD,GAAAA,CAAAA;AAE5C,IAAA,MAAME,gBAA+B,EAAC;IAEtC,MAAMC,cAAAA,GAAiBX,MAAAA,CAAOC,IAAI,CAACH,UAAAA,CAAAA;IAEnC,KAAK,MAAMK,iBAAiBQ,cAAAA,CAAgB;QAC1C,MAAMC,SAAAA,GAAYd,U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;;;;"}
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../src/utils/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { get, has, omit, pipe, assign } from 'lodash/fp';\n\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\nimport type { Modules, UID, Data, Utils, Schema, Core } from '@strapi/types';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype ComponentValue = Schema.Attribute.Value<\n Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true>\n>;\n\ntype ComponentBody = {\n [key: string]: Schema.Attribute.Value<\n | Schema.Attribute.Component<UID.Component, false>\n | Schema.Attribute.Component<UID.Component, true>\n | Schema.Attribute.DynamicZone\n >;\n};\n\nconst isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';\n\nfunction omitComponentData(\n contentType: Schema.ContentType,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;\nfunction omitComponentData(\n contentType: Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;\nfunction omitComponentData(\n contentType: Schema.ContentType | Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n): Partial<\n Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\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 = (await async.map(\n componentValue,\n (value: any) => createComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.Component>;\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 = (await async.map(\n componentValue,\n (value: any) => updateOrCreateComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n dynamiczoneValues,\n 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\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: Schema.Attribute.Value<Schema.Attribute.Component>\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: Schema.Attribute.Value<Schema.Attribute.DynamicZone>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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 = Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n _.castArray(value),\n (subValue: any) => deleteComponent(componentUID, subValue),\n {\n concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,\n }\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(subValue.__component, subValue),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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 = UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\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) as Schema.Component;\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\ninterface IComponentIdMapping {\n uid: UID.Component;\n oldID: number;\n newID: number;\n}\n\n/**\n * Walk the source data and the newly created entity in parallel and collect\n * the [old ID, new ID] couple of every component instance found in both trees\n * (components & dynamic zones, including nested ones).\n *\n * Unlike a JSON diff, couples are also collected when the ID did not change,\n * so the result is an exhaustive map of every component instance that was\n * re-created with the entity.\n */\nconst collectComponentIdMappings = ({\n data,\n created,\n schema,\n strapi,\n}: {\n data: any;\n created: any;\n schema: Schema.Schema;\n strapi: Core.Strapi;\n}): IComponentIdMapping[] => {\n const mappings: IComponentIdMapping[] = [];\n\n const visitComponent = (uid: UID.Component, oldValue: any, newValue: any) => {\n if (!_.isObjectLike(oldValue) || !_.isObjectLike(newValue)) {\n return;\n }\n\n if (typeof oldValue.id === 'number' && typeof newValue.id === 'number') {\n mappings.push({ uid, oldID: oldValue.id, newID: newValue.id });\n }\n\n const componentSchema = strapi.getModel(uid);\n\n // Collect nested components & dynamic zones\n if (componentSchema) {\n visitSchema(componentSchema, oldValue, newValue);\n }\n };\n\n const visitSchema = (currentSchema: Schema.Schema, oldData: any, newData: any) => {\n if (!_.isObjectLike(oldData) || !_.isObjectLike(newData)) {\n return;\n }\n\n const { attributes = {} } = currentSchema;\n\n for (const [attributeName, attribute] of Object.entries(attributes)) {\n const oldValue = oldData[attributeName];\n const newValue = newData[attributeName];\n\n if (_.isNil(oldValue) || _.isNil(newValue)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n if (repeatable === true) {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n // Components are created (and thus populated back) in the same\n // order as the source data, pair them by index\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n visitComponent(componentUID, oldValue[i], newValue[i]);\n }\n } else {\n visitComponent(componentUID, oldValue, newValue);\n }\n }\n\n if (attribute.type === 'dynamiczone') {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n const oldItem = oldValue[i];\n const newItem = newValue[i];\n const componentUID = oldItem?.__component;\n\n // Both items must reference the same dynamic zone component for the\n // ID couple to be meaningful\n if (!componentUID || (newItem?.__component && newItem.__component !== componentUID)) {\n continue;\n }\n\n visitComponent(componentUID, oldItem, newItem);\n }\n }\n }\n };\n\n visitSchema(schema, data, created);\n\n return mappings;\n};\n\n/**\n * Resolve the component UID of an entity's attribute based\n * on a given path (components & dynamic zones only)\n */\nconst resolveComponentUID = ({\n paths,\n strapi,\n data,\n contentType,\n}: {\n paths: string[];\n strapi: Core.Strapi;\n data: any;\n contentType: Schema.ContentType;\n}): UID.Schema | undefined => {\n let value: unknown = data;\n let cType:\n | Schema.ContentType\n | Schema.Component\n | ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;\n for (const path of paths) {\n value = get(path, value);\n\n // Needed when the value of cType should be computed\n // based on the next value (eg: dynamic zones)\n if (typeof cType === 'function') {\n cType = cType(value);\n }\n\n if (path in cType.attributes) {\n const attribute: Schema.Attribute.AnyAttribute = cType.attributes[path];\n\n if (attribute.type === 'component') {\n cType = strapi.getModel(attribute.component);\n }\n\n if (attribute.type === 'dynamiczone') {\n cType = ({ __component }: { __component: UID.Component }) => strapi.getModel(__component);\n }\n }\n }\n\n if ('uid' in cType) {\n return cType.uid;\n }\n\n return undefined;\n};\n\nexport {\n omitComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n collectComponentIdMappings,\n resolveComponentUID,\n};\n"],"names":["isDialectMySQL","strapi","db","dialect","client","omitComponentData","contentType","data","attributes","componentAttributes","Object","keys","filter","attributeName","contentTypesUtils","isComponentAttribute","omit","createComponents","uid","getModel","componentBody","attributeNames","attribute","has","type","component","componentUID","repeatable","componentValue","Array","isArray","Error","components","async","map","value","createComponent","concurrency","inTransaction","Infinity","id","__pivot","field","component_type","dynamiczoneValues","createDynamicZoneComponents","__component","getComponents","entity","getComponentAttributes","_","isEmpty","query","load","deleteComponents","entityToDelete","loadComponents","castArray","subValue","deleteComponent","model","componentData","transform","pipe","payload","assign","create","componentToDelete","delete","where","collectComponentIdMappings","created","schema","mappings","visitComponent","oldValue","newValue","isObjectLike","push","oldID","newID","componentSchema","visitSchema","currentSchema","oldData","newData","entries","isNil","length","Math","min","i","oldItem","newItem"],"mappings":";;;;;;AAuBA,MAAMA,iBAAiB,IAAMC,MAAAA,CAAOC,EAAE,EAAEC,QAAQC,MAAAA,KAAW,OAAA;AAU3D,SAASC,iBAAAA,CACPC,WAAkD,EAClDC,IAAkG,EAAA;IAIlG,MAAM,EAAEC,UAAU,EAAE,GAAGF,WAAAA;AACvB,IAAA,MAAMG,mBAAAA,GAAsBC,MAAAA,CAAOC,IAAI,CAACH,YAAYI,MAAM,CAAC,CAACC,aAAAA,GAC1DC,kBAAAA,CAAkBC,oBAAoB,CAACP,UAAU,CAACK,aAAAA,CAAc,CAAA,CAAA;AAGlE,IAAA,OAAOG,QAAKP,mBAAAA,EAAqBF,IAAAA,CAAAA;AACnC;AAEA;AACA,MAAMU,gBAAAA,GAAmB,OAIvBC,GAAAA,EACAX,IAAAA,GAAAA;IAEA,MAAM,EAAEC,aAAa,EAAE,EAAE,GAAGP,MAAAA,CAAOkB,QAAQ,CAACD,GAAAA,CAAAA;AAE5C,IAAA,MAAME,gBAA+B,EAAC;IAEtC,MAAMC,cAAAA,GAAiBX,MAAAA,CAAOC,IAAI,CAACH,UAAAA,CAAAA;IAEnC,KAAK,MAAMK,iBAAiBQ,cAAAA,CAAgB;QAC1C,MAAMC,SAAAA,GAAYd,UAAU,CAACK,aAAAA,CAAc;QAE3C,IAAI,CAACU,OAAIV,aAAAA,EAAeN,IAAAA,CAAAA,IAAS,CAACO,kBAAAA,CAAkBC,oBAAoB,CAACO,SAAAA,CAAAA,EAAY;AACnF,YAAA;AACF,QAAA;QAEA,IAAIA,SAAAA,CAAUE,I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AA,IAAK,IAAIG,CAAAA,GAAI,CAAA,EAAGA,CAAAA,GAAIH,MAAAA,EAAQG,KAAK,CAAA,CAAG;oBAClC,MAAMC,OAAAA,GAAUjB,QAAQ,CAACgB,CAAAA,CAAE;oBAC3B,MAAME,OAAAA,GAAUjB,QAAQ,CAACe,CAAAA,CAAE;AAC3B,oBAAA,MAAMjE,eAAekE,OAAAA,EAAS9C,WAAAA;;;AAI9B,oBAAA,IAAI,CAACpB,YAAAA,IAAiBmE,OAAAA,EAAS/C,eAAe+C,OAAAA,CAAQ/C,WAAW,KAAKpB,YAAAA,EAAe;AACnF,wBAAA;AACF,oBAAA;AAEAgD,oBAAAA,cAAAA,CAAehD,cAAckE,OAAAA,EAASC,OAAAA,CAAAA;AACxC,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;AAEAX,IAAAA,WAAAA,CAAYV,QAAQjE,IAAAA,EAAMgE,OAAAA,CAAAA;IAE1B,OAAOE,QAAAA;AACT;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import {
|
|
2
|
+
import { has, pipe, omit, assign } from 'lodash/fp';
|
|
3
3
|
import { async, contentTypes } from '@strapi/utils';
|
|
4
4
|
|
|
5
5
|
const isDialectMySQL = ()=>strapi.db?.dialect.client === 'mysql';
|
|
@@ -139,33 +139,81 @@ const deleteComponent = async (uid, componentToDelete)=>{
|
|
|
139
139
|
});
|
|
140
140
|
};
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
142
|
+
* Walk the source data and the newly created entity in parallel and collect
|
|
143
|
+
* the [old ID, new ID] couple of every component instance found in both trees
|
|
144
|
+
* (components & dynamic zones, including nested ones).
|
|
145
|
+
*
|
|
146
|
+
* Unlike a JSON diff, couples are also collected when the ID did not change,
|
|
147
|
+
* so the result is an exhaustive map of every component instance that was
|
|
148
|
+
* re-created with the entity.
|
|
149
|
+
*/ const collectComponentIdMappings = ({ data, created, schema, strapi: strapi1 })=>{
|
|
150
|
+
const mappings = [];
|
|
151
|
+
const visitComponent = (uid, oldValue, newValue)=>{
|
|
152
|
+
if (!_.isObjectLike(oldValue) || !_.isObjectLike(newValue)) {
|
|
153
|
+
return;
|
|
153
154
|
}
|
|
154
|
-
if (
|
|
155
|
-
|
|
155
|
+
if (typeof oldValue.id === 'number' && typeof newValue.id === 'number') {
|
|
156
|
+
mappings.push({
|
|
157
|
+
uid,
|
|
158
|
+
oldID: oldValue.id,
|
|
159
|
+
newID: newValue.id
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const componentSchema = strapi1.getModel(uid);
|
|
163
|
+
// Collect nested components & dynamic zones
|
|
164
|
+
if (componentSchema) {
|
|
165
|
+
visitSchema(componentSchema, oldValue, newValue);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const visitSchema = (currentSchema, oldData, newData)=>{
|
|
169
|
+
if (!_.isObjectLike(oldData) || !_.isObjectLike(newData)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const { attributes = {} } = currentSchema;
|
|
173
|
+
for (const [attributeName, attribute] of Object.entries(attributes)){
|
|
174
|
+
const oldValue = oldData[attributeName];
|
|
175
|
+
const newValue = newData[attributeName];
|
|
176
|
+
if (_.isNil(oldValue) || _.isNil(newValue)) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
156
179
|
if (attribute.type === 'component') {
|
|
157
|
-
|
|
180
|
+
const { component: componentUID, repeatable = false } = attribute;
|
|
181
|
+
if (repeatable === true) {
|
|
182
|
+
if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
// Components are created (and thus populated back) in the same
|
|
186
|
+
// order as the source data, pair them by index
|
|
187
|
+
const length = Math.min(oldValue.length, newValue.length);
|
|
188
|
+
for(let i = 0; i < length; i += 1){
|
|
189
|
+
visitComponent(componentUID, oldValue[i], newValue[i]);
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
visitComponent(componentUID, oldValue, newValue);
|
|
193
|
+
}
|
|
158
194
|
}
|
|
159
195
|
if (attribute.type === 'dynamiczone') {
|
|
160
|
-
|
|
196
|
+
if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const length = Math.min(oldValue.length, newValue.length);
|
|
200
|
+
for(let i = 0; i < length; i += 1){
|
|
201
|
+
const oldItem = oldValue[i];
|
|
202
|
+
const newItem = newValue[i];
|
|
203
|
+
const componentUID = oldItem?.__component;
|
|
204
|
+
// Both items must reference the same dynamic zone component for the
|
|
205
|
+
// ID couple to be meaningful
|
|
206
|
+
if (!componentUID || newItem?.__component && newItem.__component !== componentUID) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
visitComponent(componentUID, oldItem, newItem);
|
|
210
|
+
}
|
|
161
211
|
}
|
|
162
212
|
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
return undefined;
|
|
213
|
+
};
|
|
214
|
+
visitSchema(schema, data, created);
|
|
215
|
+
return mappings;
|
|
168
216
|
};
|
|
169
217
|
|
|
170
|
-
export { createComponents, deleteComponent, deleteComponents, getComponents, omitComponentData
|
|
218
|
+
export { collectComponentIdMappings, createComponents, deleteComponent, deleteComponents, getComponents, omitComponentData };
|
|
171
219
|
//# sourceMappingURL=components.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.mjs","sources":["../../src/utils/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { get, has, omit, pipe, assign } from 'lodash/fp';\n\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\nimport type { Modules, UID, Data, Utils, Schema, Core } from '@strapi/types';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype ComponentValue = Schema.Attribute.Value<\n Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true>\n>;\n\ntype ComponentBody = {\n [key: string]: Schema.Attribute.Value<\n | Schema.Attribute.Component<UID.Component, false>\n | Schema.Attribute.Component<UID.Component, true>\n | Schema.Attribute.DynamicZone\n >;\n};\n\nconst isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';\n\nfunction omitComponentData(\n contentType: Schema.ContentType,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;\nfunction omitComponentData(\n contentType: Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;\nfunction omitComponentData(\n contentType: Schema.ContentType | Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n): Partial<\n Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\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 = (await async.map(\n componentValue,\n (value: any) => createComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.Component>;\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 = (await async.map(\n componentValue,\n (value: any) => updateOrCreateComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n dynamiczoneValues,\n 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\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: Schema.Attribute.Value<Schema.Attribute.Component>\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: Schema.Attribute.Value<Schema.Attribute.DynamicZone>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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 = Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n _.castArray(value),\n (subValue: any) => deleteComponent(componentUID, subValue),\n {\n concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,\n }\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(subValue.__component, subValue),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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 = UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\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) as Schema.Component;\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\n/**\n * Resolve the component UID of an entity's attribute based\n * on a given path (components & dynamic zones only)\n */\nconst resolveComponentUID = ({\n paths,\n strapi,\n data,\n contentType,\n}: {\n paths: string[];\n strapi: Core.Strapi;\n data: any;\n contentType: Schema.ContentType;\n}): UID.Schema | undefined => {\n let value: unknown = data;\n let cType:\n | Schema.ContentType\n | Schema.Component\n | ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;\n for (const path of paths) {\n value = get(path, value);\n\n // Needed when the value of cType should be computed\n // based on the next value (eg: dynamic zones)\n if (typeof cType === 'function') {\n cType = cType(value);\n }\n\n if (path in cType.attributes) {\n const attribute: Schema.Attribute.AnyAttribute = cType.attributes[path];\n\n if (attribute.type === 'component') {\n cType = strapi.getModel(attribute.component);\n }\n\n if (attribute.type === 'dynamiczone') {\n cType = ({ __component }: { __component: UID.Component }) => strapi.getModel(__component);\n }\n }\n }\n\n if ('uid' in cType) {\n return cType.uid;\n }\n\n return undefined;\n};\n\nexport {\n omitComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n resolveComponentUID,\n};\n"],"names":["isDialectMySQL","strapi","db","dialect","client","omitComponentData","contentType","data","attributes","componentAttributes","Object","keys","filter","attributeName","contentTypesUtils","isComponentAttribute","omit","createComponents","uid","getModel","componentBody","attributeNames","attribute","has","type","component","componentUID","repeatable","componentValue","Array","isArray","Error","components","async","map","value","createComponent","concurrency","inTransaction","Infinity","id","__pivot","field","component_type","dynamiczoneValues","createDynamicZoneComponents","__component","getComponents","entity","getComponentAttributes","_","isEmpty","query","load","deleteComponents","entityToDelete","loadComponents","castArray","subValue","deleteComponent","model","componentData","transform","pipe","payload","assign","create","componentToDelete","delete","where","resolveComponentUID","paths","cType","path","get","undefined"],"mappings":";;;;AAuBA,MAAMA,iBAAiB,IAAMC,MAAAA,CAAOC,EAAE,EAAEC,QAAQC,MAAAA,KAAW,OAAA;AAU3D,SAASC,iBAAAA,CACPC,WAAkD,EAClDC,IAAkG,EAAA;IAIlG,MAAM,EAAEC,UAAU,EAAE,GAAGF,WAAAA;AACvB,IAAA,MAAMG,mBAAAA,GAAsBC,MAAAA,CAAOC,IAAI,CAACH,YAAYI,MAAM,CAAC,CAACC,aAAAA,GAC1DC,YAAAA,CAAkBC,oBAAoB,CAACP,UAAU,C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,WAAA,EAAa;AAClCgD,gBAAAA,KAAAA,GAAQvE,OAAAA,CAAOkB,QAAQ,CAACG,SAAAA,CAAUG,SAAS,CAAA;AAC7C,YAAA;YAEA,IAAIH,SAAAA,CAAUE,IAAI,KAAK,aAAA,EAAe;AACpCgD,gBAAAA,KAAAA,GAAQ,CAAC,EAAE1B,WAAW,EAAkC,GAAK7C,OAAAA,CAAOkB,QAAQ,CAAC2B,WAAAA,CAAAA;AAC/E,YAAA;AACF,QAAA;AACF,IAAA;AAEA,IAAA,IAAI,SAAS0B,KAAAA,EAAO;AAClB,QAAA,OAAOA,MAAMtD,GAAG;AAClB,IAAA;IAEA,OAAOyD,SAAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"components.mjs","sources":["../../src/utils/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { get, has, omit, pipe, assign } from 'lodash/fp';\n\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\nimport type { Modules, UID, Data, Utils, Schema, Core } from '@strapi/types';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype ComponentValue = Schema.Attribute.Value<\n Schema.Attribute.Component<UID.Component, false> | Schema.Attribute.Component<UID.Component, true>\n>;\n\ntype ComponentBody = {\n [key: string]: Schema.Attribute.Value<\n | Schema.Attribute.Component<UID.Component, false>\n | Schema.Attribute.Component<UID.Component, true>\n | Schema.Attribute.DynamicZone\n >;\n};\n\nconst isDialectMySQL = () => strapi.db?.dialect.client === 'mysql';\n\nfunction omitComponentData(\n contentType: Schema.ContentType,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.ContentType['uid']>>;\nfunction omitComponentData(\n contentType: Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.Component['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Schema.Component['uid']>>;\nfunction omitComponentData(\n contentType: Schema.ContentType | Schema.Component,\n data: Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\n): Partial<\n Modules.EntityService.Params.Data.Input<Schema.ContentType['uid'] | Schema.Component['uid']>\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 = (await async.map(\n componentValue,\n (value: any) => createComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.Component>;\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 = (await async.map(\n componentValue,\n (value: any) => updateOrCreateComponent(componentUID, value),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n )) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\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\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n dynamiczoneValues,\n 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 { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\n );\n\n continue;\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: Schema.Attribute.Value<Schema.Attribute.Component>\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: Schema.Attribute.Value<Schema.Attribute.DynamicZone>\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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 = Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\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(\n _.castArray(value),\n (subValue: any) => deleteComponent(componentUID, subValue),\n {\n concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity,\n }\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(\n _.castArray(value),\n (subValue: any) => deleteComponent(subValue.__component, subValue),\n { concurrency: isDialectMySQL() && !strapi.db?.inTransaction() ? 1 : Infinity }\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 = UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid) as Schema.Component;\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) as Schema.Component;\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\ninterface IComponentIdMapping {\n uid: UID.Component;\n oldID: number;\n newID: number;\n}\n\n/**\n * Walk the source data and the newly created entity in parallel and collect\n * the [old ID, new ID] couple of every component instance found in both trees\n * (components & dynamic zones, including nested ones).\n *\n * Unlike a JSON diff, couples are also collected when the ID did not change,\n * so the result is an exhaustive map of every component instance that was\n * re-created with the entity.\n */\nconst collectComponentIdMappings = ({\n data,\n created,\n schema,\n strapi,\n}: {\n data: any;\n created: any;\n schema: Schema.Schema;\n strapi: Core.Strapi;\n}): IComponentIdMapping[] => {\n const mappings: IComponentIdMapping[] = [];\n\n const visitComponent = (uid: UID.Component, oldValue: any, newValue: any) => {\n if (!_.isObjectLike(oldValue) || !_.isObjectLike(newValue)) {\n return;\n }\n\n if (typeof oldValue.id === 'number' && typeof newValue.id === 'number') {\n mappings.push({ uid, oldID: oldValue.id, newID: newValue.id });\n }\n\n const componentSchema = strapi.getModel(uid);\n\n // Collect nested components & dynamic zones\n if (componentSchema) {\n visitSchema(componentSchema, oldValue, newValue);\n }\n };\n\n const visitSchema = (currentSchema: Schema.Schema, oldData: any, newData: any) => {\n if (!_.isObjectLike(oldData) || !_.isObjectLike(newData)) {\n return;\n }\n\n const { attributes = {} } = currentSchema;\n\n for (const [attributeName, attribute] of Object.entries(attributes)) {\n const oldValue = oldData[attributeName];\n const newValue = newData[attributeName];\n\n if (_.isNil(oldValue) || _.isNil(newValue)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n if (repeatable === true) {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n // Components are created (and thus populated back) in the same\n // order as the source data, pair them by index\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n visitComponent(componentUID, oldValue[i], newValue[i]);\n }\n } else {\n visitComponent(componentUID, oldValue, newValue);\n }\n }\n\n if (attribute.type === 'dynamiczone') {\n if (!Array.isArray(oldValue) || !Array.isArray(newValue)) {\n continue;\n }\n\n const length = Math.min(oldValue.length, newValue.length);\n\n for (let i = 0; i < length; i += 1) {\n const oldItem = oldValue[i];\n const newItem = newValue[i];\n const componentUID = oldItem?.__component;\n\n // Both items must reference the same dynamic zone component for the\n // ID couple to be meaningful\n if (!componentUID || (newItem?.__component && newItem.__component !== componentUID)) {\n continue;\n }\n\n visitComponent(componentUID, oldItem, newItem);\n }\n }\n }\n };\n\n visitSchema(schema, data, created);\n\n return mappings;\n};\n\n/**\n * Resolve the component UID of an entity's attribute based\n * on a given path (components & dynamic zones only)\n */\nconst resolveComponentUID = ({\n paths,\n strapi,\n data,\n contentType,\n}: {\n paths: string[];\n strapi: Core.Strapi;\n data: any;\n contentType: Schema.ContentType;\n}): UID.Schema | undefined => {\n let value: unknown = data;\n let cType:\n | Schema.ContentType\n | Schema.Component\n | ((...opts: any[]) => Schema.ContentType | Schema.Component) = contentType;\n for (const path of paths) {\n value = get(path, value);\n\n // Needed when the value of cType should be computed\n // based on the next value (eg: dynamic zones)\n if (typeof cType === 'function') {\n cType = cType(value);\n }\n\n if (path in cType.attributes) {\n const attribute: Schema.Attribute.AnyAttribute = cType.attributes[path];\n\n if (attribute.type === 'component') {\n cType = strapi.getModel(attribute.component);\n }\n\n if (attribute.type === 'dynamiczone') {\n cType = ({ __component }: { __component: UID.Component }) => strapi.getModel(__component);\n }\n }\n }\n\n if ('uid' in cType) {\n return cType.uid;\n }\n\n return undefined;\n};\n\nexport {\n omitComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n collectComponentIdMappings,\n resolveComponentUID,\n};\n"],"names":["isDialectMySQL","strapi","db","dialect","client","omitComponentData","contentType","data","attributes","componentAttributes","Object","keys","filter","attributeName","contentTypesUtils","isComponentAttribute","omit","createComponents","uid","getModel","componentBody","attributeNames","attribute","has","type","component","componentUID","repeatable","componentValue","Array","isArray","Error","components","async","map","value","createComponent","concurrency","inTransaction","Infinity","id","__pivot","field","component_type","dynamiczoneValues","createDynamicZoneComponents","__component","getComponents","entity","getComponentAttributes","_","isEmpty","query","load","deleteComponents","entityToDelete","loadComponents","castArray","subValue","deleteComponent","model","componentData","transform","pipe","payload","assign","create","componentToDelete","delete","where","collectComponentIdMappings","created","schema","mappings","visitComponent","oldValue","newValue","isObjectLike","push","oldID","newID","componentSchema","visitSchema","currentSchema","oldData","newData","entries","isNil","length","Math","min","i","oldItem","newItem"],"mappings":";;;;AAuBA,MAAMA,iBAAiB,IAAMC,MAAAA,CAAOC,EAAE,EAAEC,QAAQC,MAAAA,KAAW,OAAA;AAU3D,SAASC,iBAAAA,CACPC,WAAkD,EAClDC,IAAkG,EAAA;IAIlG,MAAM,EAAEC,UAAU,EAAE,GAAGF,WAAAA;AACvB,IAAA,MAAMG,mBAAAA,GAAsBC,MAAAA,CAAOC,IAAI,CAACH,YAAYI,MAAM,CAAC,CAACC,aAAAA,GAC1DC,YAAAA,CAAkBC,oBAAoB,CAACP,UAAU,CAACK,aAAAA,CAAc,CAAA,CAAA;AAGlE,IAAA,OAAOG,KAAKP,mBAAAA,EAAqBF,IAAAA,CAAAA;AACnC;AAEA;AACA,MAAMU,gBAAAA,GAAmB,OAIvBC,GAAAA,EACAX,IAAAA,GAAAA;IAEA,MAAM,EAAEC,aAAa,EAAE,EAAE,GA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MAAM,
|
|
1
|
+
{"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../../src/utils/encryption/decrypt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAuD,MAAM,QAAQ,CAAC;AACzF,OAAO,EAAkC,SAAS,EAAE,MAAM,aAAa,CAAC;AAkCxE;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,QAC5B,MAAM,cACA,SAAS,KACnB,UAEF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.js","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Decipheriv, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '
|
|
1
|
+
{"version":3,"file":"decrypt.js","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Decipheriv, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../types';\n\n// different key values depending on algorithm chosen\nconst getDecryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.subarray(16);\n const securityKey: CipherKey = hashedKey.subarray(0, 16);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.subarray(24);\n const securityKey: CipherKey = hashedKey.subarray(0, 24);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.subarray(32);\n const securityKey: CipherKey = hashedKey.subarray(0, 32);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for decryption\n *\n * @param key - The decryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Decipheriv} instance created with the given key & algorithm\n */\nexport const createDecryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Decipheriv => {\n return getDecryptionStrategy(algorithm)(key);\n};\n"],"names":["getDecryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createDecipheriv","aes128","subarray","aes192","aes256","createDecryptionCipher"],"mappings":";;;;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAAA,GAAyB;AAC7B,QAAA,aAAA,CAAA,CAAcC,GAAW,EAAA;YACvB,MAAMC,SAAAA,GAAYC,iBAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;AACtC,YAAA,MAAMG,UAAAA,GAAgC,IAAA;AACtC,YAAA,MAAMC,WAAAA,GAAyBH,SAAAA;YAC/B,OAAOI,uBAAAA,CAAiBP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAClD,QAAA,CAAA;AACAG,QAAAA,MAAAA,CAAAA,CAAON,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,iBAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;YACtC,MAAMG,UAAAA,GAAgCF,SAAAA,CAAUM,QAAQ,CAAC,EAAA,CAAA;AACzD,YAAA,MAAMH,WAAAA,GAAyBH,SAAAA,CAAUM,QAAQ,CAAC,CAAA,EAAG,EAAA,CAAA;YACrD,OAAOF,uBAAAA,CAAiBP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAClD,QAAA,CAAA;AACAK,QAAAA,MAAAA,CAAAA,CAAOR,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,iBAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;YACtC,MAAMG,UAAAA,GAAgCF,SAAAA,CAAUM,QAAQ,CAAC,EAAA,CAAA;AACzD,YAAA,MAAMH,WAAAA,GAAyBH,SAAAA,CAAUM,QAAQ,CAAC,CAAA,EAAG,EAAA,CAAA;YACrD,OAAOF,uBAAAA,CAAiBP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAClD,QAAA,CAAA;AACAM,QAAAA,MAAAA,CAAAA,CAAOT,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,iBAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;YACtC,MAAMG,UAAAA,GAAgCF,SAAAA,CAAUM,QAAQ,CAAC,EAAA,CAAA;AACzD,YAAA,MAAMH,WAAAA,GAAyBH,SAAAA,CAAUM,QAAQ,CAAC,CAAA,EAAG,EAAA,CAAA;YACrD,OAAOF,uBAAAA,CAAiBP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAClD,QAAA;AACF,KAAA;IAEA,OAAOJ,UAAU,CAACD,SAAAA,CAAU;AAC9B,CAAA;AAEA;;;;;;;AAOC,IACM,MAAMY,sBAAAA,GAAyB,CACpCV,GAAAA,EACAF,YAAuB,aAAa,GAAA;AAEpC,IAAA,OAAOD,sBAAsBC,SAAAA,CAAAA,CAAWE,GAAAA,CAAAA;AAC1C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.mjs","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Decipheriv, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '
|
|
1
|
+
{"version":3,"file":"decrypt.mjs","sources":["../../../src/utils/encryption/decrypt.ts"],"sourcesContent":["import { Decipheriv, scryptSync, CipherKey, BinaryLike, createDecipheriv } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../types';\n\n// different key values depending on algorithm chosen\nconst getDecryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.subarray(16);\n const securityKey: CipherKey = hashedKey.subarray(0, 16);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.subarray(24);\n const securityKey: CipherKey = hashedKey.subarray(0, 24);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Decipheriv {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.subarray(32);\n const securityKey: CipherKey = hashedKey.subarray(0, 32);\n return createDecipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for decryption\n *\n * @param key - The decryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Decipheriv} instance created with the given key & algorithm\n */\nexport const createDecryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Decipheriv => {\n return getDecryptionStrategy(algorithm)(key);\n};\n"],"names":["getDecryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createDecipheriv","aes128","subarray","aes192","aes256","createDecryptionCipher"],"mappings":";;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAAA,GAAyB;AAC7B,QAAA,aAAA,CAAA,CAAcC,GAAW,EAAA;YACvB,MAAMC,SAAAA,GAAYC,UAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;A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AAA,CAAAA;AAClD,QAAA;AACF,KAAA;IAEA,OAAOJ,UAAU,CAACD,SAAAA,CAAU;AAC9B,CAAA;AAEA;;;;;;;AAOC,IACM,MAAMY,sBAAAA,GAAyB,CACpCV,GAAAA,EACAF,YAAuB,aAAa,GAAA;AAEpC,IAAA,OAAOD,sBAAsBC,SAAAA,CAAAA,CAAWE,GAAAA,CAAAA;AAC1C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/utils/encryption/encrypt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,QAAQ,EAAqC,MAAM,QAAQ,CAAC;AACrF,OAAO,EAAkC,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/utils/encryption/encrypt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAkB,QAAQ,EAAqC,MAAM,QAAQ,CAAC;AACrF,OAAO,EAAkC,SAAS,EAAE,MAAM,aAAa,CAAC;AAkCxE;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,QAC5B,MAAM,cACA,SAAS,KACnB,QAEF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.js","sources":["../../../src/utils/encryption/encrypt.ts"],"sourcesContent":["import { createCipheriv, Cipheriv, scryptSync, CipherKey, BinaryLike } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '
|
|
1
|
+
{"version":3,"file":"encrypt.js","sources":["../../../src/utils/encryption/encrypt.ts"],"sourcesContent":["import { createCipheriv, Cipheriv, scryptSync, CipherKey, BinaryLike } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../types';\n\n// different key values depending on algorithm chosen\nconst getEncryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.subarray(16);\n const securityKey: CipherKey = hashedKey.subarray(0, 16);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.subarray(24);\n const securityKey: CipherKey = hashedKey.subarray(0, 24);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.subarray(32);\n const securityKey: CipherKey = hashedKey.subarray(0, 32);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for encryption\n *\n * @param key - The encryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipheriv} instance created with the given key & algorithm\n */\nexport const createEncryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipheriv => {\n return getEncryptionStrategy(algorithm)(key);\n};\n"],"names":["getEncryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createCipheriv","aes128","subarray","aes192","aes256","createEncryptionCipher"],"mappings":";;;;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAAA,GAAyB;AAC7B,QAAA,aAAA,CAAA,CAAcC,GAAW,EAAA;YACvB,MAAMC,SAAAA,GAAYC,iBAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;AACtC,YAAA,MAAMG,UAAAA,GAAgC,IAAA;AACtC,YAAA,MAAMC,WAAAA,GAAyBH,SAAAA;YAC/B,OAAOI,qBAAAA,CAAeP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAChD,QAA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AuB,aAAa,GAAA;AAEpC,IAAA,OAAOD,sBAAsBC,SAAAA,CAAAA,CAAWE,GAAAA,CAAAA;AAC1C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encrypt.mjs","sources":["../../../src/utils/encryption/encrypt.ts"],"sourcesContent":["import { createCipheriv, Cipheriv, scryptSync, CipherKey, BinaryLike } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '
|
|
1
|
+
{"version":3,"file":"encrypt.mjs","sources":["../../../src/utils/encryption/encrypt.ts"],"sourcesContent":["import { createCipheriv, Cipheriv, scryptSync, CipherKey, BinaryLike } from 'crypto';\nimport { EncryptionStrategy, Strategies, Algorithm } from '../../types';\n\n// different key values depending on algorithm chosen\nconst getEncryptionStrategy = (algorithm: Algorithm): EncryptionStrategy => {\n const strategies: Strategies = {\n 'aes-128-ecb'(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 16);\n const initVector: BinaryLike | null = null;\n const securityKey: CipherKey = hashedKey;\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes128(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 32);\n const initVector: BinaryLike | null = hashedKey.subarray(16);\n const securityKey: CipherKey = hashedKey.subarray(0, 16);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes192(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 40);\n const initVector: BinaryLike | null = hashedKey.subarray(24);\n const securityKey: CipherKey = hashedKey.subarray(0, 24);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n aes256(key: string): Cipheriv {\n const hashedKey = scryptSync(key, '', 48);\n const initVector: BinaryLike | null = hashedKey.subarray(32);\n const securityKey: CipherKey = hashedKey.subarray(0, 32);\n return createCipheriv(algorithm, securityKey, initVector);\n },\n };\n\n return strategies[algorithm];\n};\n\n/**\n * It creates a cipher instance used for encryption\n *\n * @param key - The encryption key\n * @param algorithm - The algorithm to use to create the Cipher\n *\n * @returns A {@link Cipheriv} instance created with the given key & algorithm\n */\nexport const createEncryptionCipher = (\n key: string,\n algorithm: Algorithm = 'aes-128-ecb'\n): Cipheriv => {\n return getEncryptionStrategy(algorithm)(key);\n};\n"],"names":["getEncryptionStrategy","algorithm","strategies","key","hashedKey","scryptSync","initVector","securityKey","createCipheriv","aes128","subarray","aes192","aes256","createEncryptionCipher"],"mappings":";;AAGA;AACA,MAAMA,wBAAwB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,UAAAA,GAAyB;AAC7B,QAAA,aAAA,CAAA,CAAcC,GAAW,EAAA;YACvB,MAAMC,SAAAA,GAAYC,UAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;AACtC,YAAA,MAAMG,UAAAA,GAAgC,IAAA;AACtC,YAAA,MAAMC,WAAAA,GAAyBH,SAAAA;YAC/B,OAAOI,cAAAA,CAAeP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAChD,QAAA,CAAA;AACAG,QAAAA,MAAAA,CAAAA,CAAON,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,UAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;YACtC,MAAMG,UAAAA,GAAgCF,SAAAA,CAAUM,QAAQ,CAAC,EAAA,CAAA;AACzD,YAAA,MAAMH,WAAAA,GAAyBH,SAAAA,CAAUM,QAAQ,CAAC,CAAA,EAAG,EAAA,CAAA;YACrD,OAAOF,cAAAA,CAAeP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAChD,QAAA,CAAA;AACAK,QAAAA,MAAAA,CAAAA,CAAOR,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,UAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;YACtC,MAAMG,UAAAA,GAAgCF,SAAAA,CAAUM,QAAQ,CAAC,EAAA,CAAA;AACzD,YAAA,MAAMH,WAAAA,GAAyBH,SAAAA,CAAUM,QAAQ,CAAC,CAAA,EAAG,EAAA,CAAA;YACrD,OAAOF,cAAAA,CAAeP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAChD,QAAA,CAAA;AACAM,QAAAA,MAAAA,CAAAA,CAAOT,GAAW,EAAA;YAChB,MAAMC,SAAAA,GAAYC,UAAAA,CAAWF,GAAAA,EAAK,EAAA,EAAI,EAAA,CAAA;YACtC,MAAMG,UAAAA,GAAgCF,SAAAA,CAAUM,QAAQ,CAAC,EAAA,CAAA;AACzD,YAAA,MAAMH,WAAAA,GAAyBH,SAAAA,CAAUM,QAAQ,CAAC,CAAA,EAAG,EAAA,CAAA;YACrD,OAAOF,cAAAA,CAAeP,WAAWM,WAAAA,EAAaD,UAAAA,CAAAA;AAChD,QAAA;AACF,KAAA;IAEA,OAAOJ,UAAU,CAACD,SAAAA,CAAU;AAC9B,CAAA;AAEA;;;;;;;AAOC,IACM,MAAMY,sBAAAA,GAAyB,CACpCV,GAAAA,EACAF,YAAuB,aAAa,GAAA;AAEpC,IAAA,OAAOD,sBAAsBC,SAAAA,CAAAA,CAAWE,GAAAA,CAAAA;AAC1C;;;;"}
|
package/dist/utils/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var diagnostic = require('./diagnostic.js');
|
|
|
14
14
|
|
|
15
15
|
exports.encryption = index;
|
|
16
16
|
exports.createTransferAssetStreamChunk = transferAssetChunk.createTransferAssetStreamChunk;
|
|
17
|
+
exports.createTransferAssetStreamChunkLegacy = transferAssetChunk.createTransferAssetStreamChunkLegacy;
|
|
17
18
|
exports.decodeTransferAssetStreamData = transferAssetChunk.decodeTransferAssetStreamData;
|
|
18
19
|
exports.decodeTransferAssetStreamItem = transferAssetChunk.decodeTransferAssetStreamItem;
|
|
19
20
|
exports.transferAssetStreamChunkByteLength = transferAssetChunk.transferAssetStreamChunkByteLength;
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as index from './encryption/index.mjs';
|
|
2
2
|
export { index as encryption };
|
|
3
|
-
export { createTransferAssetStreamChunk, decodeTransferAssetStreamData, decodeTransferAssetStreamItem, transferAssetStreamChunkByteLength } from './transfer-asset-chunk.mjs';
|
|
3
|
+
export { createTransferAssetStreamChunk, createTransferAssetStreamChunkLegacy, decodeTransferAssetStreamData, decodeTransferAssetStreamItem, transferAssetStreamChunkByteLength } from './transfer-asset-chunk.mjs';
|
|
4
4
|
export { write } from './writable-async-write.mjs';
|
|
5
5
|
import * as stream from './stream.mjs';
|
|
6
6
|
export { stream };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/utils/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/utils/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,eAAO,MAAM,aAAa,eAAsB,CAAC,eAAe,WAAW,CAAC,CAAC,EAAE,KAAG,QAAQ,IAAI,CAQ7F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import { Middleware } from '
|
|
1
|
+
{"version":3,"file":"middleware.js","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import { Middleware } from '../types';\n\nexport const runMiddleware = async <T>(context: T, middlewares: Middleware<T>[]): Promise<void> => {\n if (!middlewares.length) {\n return;\n }\n const cb = middlewares[0];\n await cb(context, async (newContext: T) => {\n await runMiddleware(newContext, middlewares.slice(1));\n });\n};\n"],"names":["runMiddleware","context","middlewares","length","cb","newContext","slice"],"mappings":";;AAEO,MAAMA,aAAAA,GAAgB,OAAUC,OAAAA,EAAYC,WAAAA,GAAAA;IACjD,IAAI,CAACA,WAAAA,CAAYC,MAAM,EAAE;AACvB,QAAA;AACF,IAAA;IACA,MAAMC,EAAAA,GAAKF,WAAW,CAAC,CAAA,CAAE;IACzB,MAAME,EAAAA,CAAGH,SAAS,OAAOI,UAAAA,GAAAA;AACvB,QAAA,MAAML,aAAAA,CAAcK,UAAAA,EAAYH,WAAAA,CAAYI,KAAK,CAAC,CAAA,CAAA,CAAA;AACpD,IAAA,CAAA,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import { Middleware } from '
|
|
1
|
+
{"version":3,"file":"middleware.mjs","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import { Middleware } from '../types';\n\nexport const runMiddleware = async <T>(context: T, middlewares: Middleware<T>[]): Promise<void> => {\n if (!middlewares.length) {\n return;\n }\n const cb = middlewares[0];\n await cb(context, async (newContext: T) => {\n await runMiddleware(newContext, middlewares.slice(1));\n });\n};\n"],"names":["runMiddleware","context","middlewares","length","cb","newContext","slice"],"mappings":"AAEO,MAAMA,aAAAA,GAAgB,OAAUC,OAAAA,EAAYC,WAAAA,GAAAA;IACjD,IAAI,CAACA,WAAAA,CAAYC,MAAM,EAAE;AACvB,QAAA;AACF,IAAA;IACA,MAAMC,EAAAA,GAAKF,WAAW,CAAC,CAAA,CAAE;IACzB,MAAME,EAAAA,CAAGH,SAAS,OAAOI,UAAAA,GAAAA;AACvB,QAAA,MAAML,aAAAA,CAAcK,UAAAA,EAAYH,WAAAA,CAAYI,KAAK,CAAC,CAAA,CAAA,CAAA;AACpD,IAAA,CAAA,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAuB,MAAM,
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAuB,MAAM,gBAAgB,CAAC;AAElE,eAAO,MAAM,iBAAiB,WAAY,KAAK,MAAM,KAAG,WA2FvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sources":["../../src/utils/transaction.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { randomUUID } from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { Transaction, TransactionCallback } from '
|
|
1
|
+
{"version":3,"file":"transaction.js","sources":["../../src/utils/transaction.ts"],"sourcesContent":["import { EventEmitter } from 'events';\nimport { randomUUID } from 'crypto';\nimport type { Core } from '@strapi/types';\n\nimport { Transaction, TransactionCallback } from '../types/utils';\n\nexport const createTransaction = (strapi: Core.Strapi): Transaction => {\n const fns: { fn: TransactionCallback; uuid: string }[] = [];\n\n let done = false;\n let resume: null | (() => void) = null;\n\n const e = new EventEmitter();\n e.on('spawn', (uuid, cb) => {\n fns.push({ fn: cb, uuid });\n resume?.();\n });\n\n e.on('close', () => {\n e.removeAllListeners('rollback');\n e.removeAllListeners('spawn');\n\n done = true;\n resume?.();\n });\n\n strapi.db.transaction(async ({ trx, rollback }) => {\n e.once('rollback', async () => {\n e.removeAllListeners('close');\n e.removeAllListeners('spawn');\n\n try {\n await rollback();\n e.emit('rollback_completed');\n } catch {\n e.emit('rollback_failed');\n } finally {\n done = true;\n resume?.();\n }\n });\n\n while (!done) {\n while (fns.length) {\n const item = fns.shift();\n\n if (item) {\n const { fn, uuid } = item;\n\n try {\n const res = await fn(trx);\n e.emit(uuid, { data: res });\n } catch (error) {\n e.emit(uuid, { error });\n }\n }\n }\n if (!done && !fns.length) {\n // eslint-disable-next-line @typescript-eslint/no-loop-func\n await new Promise<void>((resolve) => {\n resume = resolve;\n });\n }\n }\n });\n\n return {\n async attach<T = undefined>(callback: TransactionCallback): Promise<T | undefined> {\n const uuid = randomUUID();\n e.emit('spawn', uuid, callback);\n return new Promise<T | undefined>((resolve, reject) => {\n e.on(uuid, ({ data, error }) => {\n if (data) {\n resolve(data);\n }\n\n if (error) {\n reject(error);\n }\n resolve(undefined);\n });\n });\n },\n\n end() {\n return e.emit('close');\n },\n\n rollback() {\n return new Promise<boolean>((resolve) => {\n e.emit('rollback');\n\n e.once('rollback_failed', () => resolve(false));\n e.once('rollback_completed', () => resolve(true));\n });\n },\n };\n};\n"],"names":["createTransaction","strapi","fns","done","resume","e","EventEmitter","on","uuid","cb","push","fn","removeAllListeners","db","transaction","trx","rollback","once","emit","length","item","shift","res","data","error","Promise","resolve","attach","callback","randomUUID","reject","undefined","end"],"mappings":";;;;;AAMO,MAAMA,oBAAoB,CAACC,MAAAA,GAAAA;AAChC,IAAA,MAAMC,MAAmD,EAAE;AAE3D,IAAA,IAAIC,IAAAA,GAAO,KAAA;AACX,IAAA,IAAIC,MAAAA,GAA8B,IAAA;AAElC,IAAA,MAAMC,IAAI,IAAIC,mBAAAA,EAAAA;AACdD,IAAAA,CAAAA,CAAEE,EAAE,CAAC,OAAA,EAAS,CAACC,IAAAA,EAAMC,EAAAA,GAAAA;AACnBP,QAAAA,GAAAA,CAAIQ,IAAI,CAAC;YAAEC,EAAAA,EAAIF,EAAAA;AAAID,YAAAA;AAAK,SAAA,CAAA;AACxBJ,QAAAA,MAAAA,IAAAA;AACF,IAAA,CAAA,CAAA;IAEAC,CAAAA,CAAEE,EAAE,CAAC,OAAA,EAAS,IAAA;AACZF,QAAAA,CAAAA,CAAEO,kBAAkB,CAAC,UAAA,CAAA;AACrBP,QAAAA,CAAAA,CAAEO,kBAAkB,CAAC,OAAA,CAAA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