@prismicio/client 7.21.5 → 7.21.6-canary.529a352
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/Client.cjs +19 -20
- package/dist/Client.cjs.map +1 -1
- package/dist/Client.d.cts +5 -12
- package/dist/Client.d.cts.map +1 -1
- package/dist/Client.d.ts +5 -12
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +8 -9
- package/dist/Client.js.map +1 -1
- package/dist/Migration.cjs +18 -19
- package/dist/Migration.cjs.map +1 -1
- package/dist/Migration.d.cts +0 -1
- package/dist/Migration.d.cts.map +1 -1
- package/dist/Migration.d.ts +0 -1
- package/dist/Migration.d.ts.map +1 -1
- package/dist/Migration.js +11 -12
- package/dist/Migration.js.map +1 -1
- package/dist/WriteClient.cjs +17 -21
- package/dist/WriteClient.cjs.map +1 -1
- package/dist/WriteClient.d.cts +0 -1
- package/dist/WriteClient.d.cts.map +1 -1
- package/dist/WriteClient.d.ts +0 -1
- package/dist/WriteClient.d.ts.map +1 -1
- package/dist/WriteClient.js +10 -14
- package/dist/WriteClient.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +13 -0
- package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.js} +4 -5
- package/dist/buildQueryURL.cjs +4 -5
- package/dist/buildQueryURL.cjs.map +1 -1
- package/dist/buildQueryURL.d.cts.map +1 -1
- package/dist/buildQueryURL.d.ts.map +1 -1
- package/dist/buildQueryURL.js +2 -3
- package/dist/buildQueryURL.js.map +1 -1
- package/dist/cookie.cjs +7 -9
- package/dist/cookie.cjs.map +1 -1
- package/dist/cookie.d.cts.map +1 -1
- package/dist/cookie.d.ts.map +1 -1
- package/dist/cookie.js +3 -4
- package/dist/cookie.js.map +1 -1
- package/dist/createClient.cjs +2 -3
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.cts +0 -1
- package/dist/createClient.d.cts.map +1 -1
- package/dist/createClient.d.ts +0 -1
- package/dist/createClient.d.ts.map +1 -1
- package/dist/createClient.js +1 -2
- package/dist/createClient.js.map +1 -1
- package/dist/createMigration.cjs +2 -3
- package/dist/createMigration.cjs.map +1 -1
- package/dist/createMigration.d.cts +0 -1
- package/dist/createMigration.d.cts.map +1 -1
- package/dist/createMigration.d.ts +0 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +1 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createWriteClient.cjs +2 -3
- package/dist/createWriteClient.cjs.map +1 -1
- package/dist/createWriteClient.d.cts +0 -1
- package/dist/createWriteClient.d.cts.map +1 -1
- package/dist/createWriteClient.d.ts +0 -1
- package/dist/createWriteClient.d.ts.map +1 -1
- package/dist/createWriteClient.js +1 -2
- package/dist/createWriteClient.js.map +1 -1
- package/dist/errors.cjs +1 -2
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/filter.cjs +1 -2
- package/dist/filter.cjs.map +1 -1
- package/dist/filter.d.cts.map +1 -1
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +1 -1
- package/dist/getGraphQLEndpoint.cjs +3 -4
- package/dist/getGraphQLEndpoint.cjs.map +1 -1
- package/dist/getGraphQLEndpoint.d.cts.map +1 -1
- package/dist/getGraphQLEndpoint.d.ts.map +1 -1
- package/dist/getGraphQLEndpoint.js +1 -2
- package/dist/getGraphQLEndpoint.js.map +1 -1
- package/dist/getRepositoryEndpoint.cjs +3 -4
- package/dist/getRepositoryEndpoint.cjs.map +1 -1
- package/dist/getRepositoryEndpoint.d.cts.map +1 -1
- package/dist/getRepositoryEndpoint.d.ts.map +1 -1
- package/dist/getRepositoryEndpoint.js +1 -2
- package/dist/getRepositoryEndpoint.js.map +1 -1
- package/dist/getRepositoryName.cjs +2 -3
- package/dist/getRepositoryName.cjs.map +1 -1
- package/dist/getRepositoryName.d.cts.map +1 -1
- package/dist/getRepositoryName.d.ts.map +1 -1
- package/dist/getRepositoryName.js +1 -2
- package/dist/getRepositoryName.js.map +1 -1
- package/dist/getToolbarSrc.cjs +3 -4
- package/dist/getToolbarSrc.cjs.map +1 -1
- package/dist/getToolbarSrc.d.cts.map +1 -1
- package/dist/getToolbarSrc.d.ts.map +1 -1
- package/dist/getToolbarSrc.js +1 -2
- package/dist/getToolbarSrc.js.map +1 -1
- package/dist/helpers/asDate.cjs +1 -2
- package/dist/helpers/asDate.cjs.map +1 -1
- package/dist/helpers/asDate.d.cts +0 -1
- package/dist/helpers/asDate.d.cts.map +1 -1
- package/dist/helpers/asDate.d.ts +0 -1
- package/dist/helpers/asDate.d.ts.map +1 -1
- package/dist/helpers/asDate.js +1 -1
- package/dist/helpers/asHTML.cjs +5 -6
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.cts +0 -1
- package/dist/helpers/asHTML.d.cts.map +1 -1
- package/dist/helpers/asHTML.d.ts +0 -1
- package/dist/helpers/asHTML.d.ts.map +1 -1
- package/dist/helpers/asHTML.js +1 -2
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.cjs +3 -4
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.cts +0 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.cts.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +0 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.js +2 -3
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
- package/dist/helpers/asImageSrc.cjs +2 -3
- package/dist/helpers/asImageSrc.cjs.map +1 -1
- package/dist/helpers/asImageSrc.d.cts +0 -1
- package/dist/helpers/asImageSrc.d.cts.map +1 -1
- package/dist/helpers/asImageSrc.d.ts +0 -1
- package/dist/helpers/asImageSrc.d.ts.map +1 -1
- package/dist/helpers/asImageSrc.js +1 -2
- package/dist/helpers/asImageSrc.js.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs +4 -5
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.cts +0 -1
- package/dist/helpers/asImageWidthSrcSet.d.cts.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +0 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.js +3 -4
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLink.cjs +3 -4
- package/dist/helpers/asLink.cjs.map +1 -1
- package/dist/helpers/asLink.d.cts +0 -1
- package/dist/helpers/asLink.d.cts.map +1 -1
- package/dist/helpers/asLink.d.ts +0 -1
- package/dist/helpers/asLink.d.ts.map +1 -1
- package/dist/helpers/asLink.js +1 -2
- package/dist/helpers/asLink.js.map +1 -1
- package/dist/helpers/asLinkAttrs.cjs +4 -5
- package/dist/helpers/asLinkAttrs.cjs.map +1 -1
- package/dist/helpers/asLinkAttrs.d.cts.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts.map +1 -1
- package/dist/helpers/asLinkAttrs.js +1 -2
- package/dist/helpers/asLinkAttrs.js.map +1 -1
- package/dist/helpers/asText.cjs +4 -5
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.d.cts +0 -1
- package/dist/helpers/asText.d.cts.map +1 -1
- package/dist/helpers/asText.d.ts +0 -1
- package/dist/helpers/asText.d.ts.map +1 -1
- package/dist/helpers/asText.js +5 -6
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/documentToLinkField.cjs +2 -3
- package/dist/helpers/documentToLinkField.cjs.map +1 -1
- package/dist/helpers/documentToLinkField.d.cts.map +1 -1
- package/dist/helpers/documentToLinkField.d.ts.map +1 -1
- package/dist/helpers/documentToLinkField.js +1 -2
- package/dist/helpers/documentToLinkField.js.map +1 -1
- package/dist/helpers/isFilled.cjs +11 -13
- package/dist/helpers/isFilled.cjs.map +1 -1
- package/dist/helpers/isFilled.d.cts.map +1 -1
- package/dist/helpers/isFilled.d.ts.map +1 -1
- package/dist/helpers/isFilled.js +7 -8
- package/dist/helpers/isFilled.js.map +1 -1
- package/dist/helpers/mapSliceZone.cjs +1 -2
- package/dist/helpers/mapSliceZone.cjs.map +1 -1
- package/dist/helpers/mapSliceZone.d.cts +0 -1
- package/dist/helpers/mapSliceZone.d.cts.map +1 -1
- package/dist/helpers/mapSliceZone.d.ts +0 -1
- package/dist/helpers/mapSliceZone.d.ts.map +1 -1
- package/dist/helpers/mapSliceZone.js +1 -1
- package/dist/index.cjs +49 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs +1 -2
- package/dist/isRepositoryEndpoint.cjs.map +1 -1
- package/dist/isRepositoryEndpoint.d.cts.map +1 -1
- package/dist/isRepositoryEndpoint.d.ts.map +1 -1
- package/dist/isRepositoryEndpoint.js +1 -1
- package/dist/isRepositoryName.cjs +1 -2
- package/dist/isRepositoryName.cjs.map +1 -1
- package/dist/isRepositoryName.d.cts.map +1 -1
- package/dist/isRepositoryName.d.ts.map +1 -1
- package/dist/isRepositoryName.js +1 -1
- package/dist/lib/devMsg.cjs +2 -3
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js +1 -2
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/escapeHTML.cjs +1 -2
- package/dist/lib/escapeHTML.cjs.map +1 -1
- package/dist/lib/escapeHTML.js +1 -1
- package/dist/lib/getOptionalLinkProperties.cjs +1 -2
- package/dist/lib/getOptionalLinkProperties.cjs.map +1 -1
- package/dist/lib/getOptionalLinkProperties.js +1 -1
- package/dist/lib/getOptionalLinkProperties.js.map +1 -1
- package/dist/lib/getPreviewCookie.cjs +3 -4
- package/dist/lib/getPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPreviewCookie.js +3 -4
- package/dist/lib/getPreviewCookie.js.map +1 -1
- package/dist/lib/isInternalURL.cjs +1 -2
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js +1 -1
- package/dist/lib/isMigrationValue.cjs +6 -7
- package/dist/lib/isMigrationValue.cjs.map +1 -1
- package/dist/lib/isMigrationValue.js +1 -2
- package/dist/lib/isMigrationValue.js.map +1 -1
- package/dist/lib/isValue.cjs +3 -4
- package/dist/lib/isValue.cjs.map +1 -1
- package/dist/lib/isValue.js +1 -2
- package/dist/lib/isValue.js.map +1 -1
- package/dist/lib/pLimit.cjs +1 -2
- package/dist/lib/pLimit.cjs.map +1 -1
- package/dist/lib/pLimit.js +1 -1
- package/dist/lib/pLimit.js.map +1 -1
- package/dist/lib/request.cjs +19 -6
- package/dist/lib/request.cjs.map +1 -1
- package/dist/lib/request.d.cts +0 -1
- package/dist/lib/request.d.cts.map +1 -1
- package/dist/lib/request.d.ts +0 -1
- package/dist/lib/request.d.ts.map +1 -1
- package/dist/lib/request.js +18 -5
- package/dist/lib/request.js.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.cjs +18 -19
- package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -1
- package/dist/lib/resolveMigrationDocumentData.js +11 -12
- package/dist/lib/resolveMigrationDocumentData.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +4 -5
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.js +1 -2
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/lib/throttledWarn.cjs +1 -2
- package/dist/lib/throttledWarn.cjs.map +1 -1
- package/dist/lib/throttledWarn.js +1 -1
- package/dist/lib/throttledWarn.js.map +1 -1
- package/dist/lib/validateAssetMetadata.cjs +2 -3
- package/dist/lib/validateAssetMetadata.cjs.map +1 -1
- package/dist/lib/validateAssetMetadata.js +1 -2
- package/dist/lib/validateAssetMetadata.js.map +1 -1
- package/dist/package.cjs +12 -13
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +2 -2
- package/dist/package.js.map +1 -1
- package/dist/richtext/asText.cjs +1 -2
- package/dist/richtext/asText.cjs.map +1 -1
- package/dist/richtext/asText.d.cts +0 -1
- package/dist/richtext/asText.d.cts.map +1 -1
- package/dist/richtext/asText.d.ts +0 -1
- package/dist/richtext/asText.d.ts.map +1 -1
- package/dist/richtext/asText.js +1 -1
- package/dist/richtext/asTree.cjs +2 -3
- package/dist/richtext/asTree.cjs.map +1 -1
- package/dist/richtext/asTree.d.cts +0 -1
- package/dist/richtext/asTree.d.cts.map +1 -1
- package/dist/richtext/asTree.d.ts +0 -1
- package/dist/richtext/asTree.d.ts.map +1 -1
- package/dist/richtext/asTree.js +1 -2
- package/dist/richtext/asTree.js.map +1 -1
- package/dist/richtext/composeSerializers.cjs +1 -2
- package/dist/richtext/composeSerializers.cjs.map +1 -1
- package/dist/richtext/composeSerializers.d.cts +0 -1
- package/dist/richtext/composeSerializers.d.cts.map +1 -1
- package/dist/richtext/composeSerializers.d.ts +0 -1
- package/dist/richtext/composeSerializers.d.ts.map +1 -1
- package/dist/richtext/composeSerializers.js +1 -1
- package/dist/richtext/serialize.cjs +2 -3
- package/dist/richtext/serialize.cjs.map +1 -1
- package/dist/richtext/serialize.d.cts +0 -1
- package/dist/richtext/serialize.d.cts.map +1 -1
- package/dist/richtext/serialize.d.ts +0 -1
- package/dist/richtext/serialize.d.ts.map +1 -1
- package/dist/richtext/serialize.js +1 -2
- package/dist/richtext/serialize.js.map +1 -1
- package/dist/richtext/types.cjs +2 -3
- package/dist/richtext/types.cjs.map +1 -1
- package/dist/richtext/types.d.cts +0 -1
- package/dist/richtext/types.d.cts.map +1 -1
- package/dist/richtext/types.d.ts +0 -1
- package/dist/richtext/types.d.ts.map +1 -1
- package/dist/richtext/types.js +1 -2
- package/dist/richtext/types.js.map +1 -1
- package/dist/richtext/wrapMapSerializer.cjs +2 -3
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.cts +0 -1
- package/dist/richtext/wrapMapSerializer.d.cts.map +1 -1
- package/dist/richtext/wrapMapSerializer.d.ts +0 -1
- package/dist/richtext/wrapMapSerializer.d.ts.map +1 -1
- package/dist/richtext/wrapMapSerializer.js +1 -2
- package/dist/richtext/wrapMapSerializer.js.map +1 -1
- package/dist/richtext.cjs +8 -8
- package/dist/richtext.js +1 -2
- package/dist/types/api/asset/asset.d.cts +0 -1
- package/dist/types/api/asset/asset.d.cts.map +1 -1
- package/dist/types/api/asset/asset.d.ts +0 -1
- package/dist/types/api/asset/asset.d.ts.map +1 -1
- package/dist/types/api/asset/tag.d.cts.map +1 -1
- package/dist/types/api/asset/tag.d.ts.map +1 -1
- package/dist/types/api/integration.d.cts +0 -1
- package/dist/types/api/integration.d.cts.map +1 -1
- package/dist/types/api/integration.d.ts +0 -1
- package/dist/types/api/integration.d.ts.map +1 -1
- package/dist/types/api/query.d.cts +0 -1
- package/dist/types/api/query.d.cts.map +1 -1
- package/dist/types/api/query.d.ts +0 -1
- package/dist/types/api/query.d.ts.map +1 -1
- package/dist/types/api/ref.d.cts.map +1 -1
- package/dist/types/api/ref.d.ts.map +1 -1
- package/dist/types/api/release.d.cts +0 -1
- package/dist/types/api/release.d.cts.map +1 -1
- package/dist/types/api/release.d.ts +0 -1
- package/dist/types/api/release.d.ts.map +1 -1
- package/dist/types/api/repository.d.cts +0 -1
- package/dist/types/api/repository.d.cts.map +1 -1
- package/dist/types/api/repository.d.ts +0 -1
- package/dist/types/api/repository.d.ts.map +1 -1
- package/dist/types/api/tags.d.cts.map +1 -1
- package/dist/types/api/tags.d.ts.map +1 -1
- package/dist/types/migration/Asset.cjs +1 -2
- package/dist/types/migration/Asset.cjs.map +1 -1
- package/dist/types/migration/Asset.d.cts +0 -1
- package/dist/types/migration/Asset.d.cts.map +1 -1
- package/dist/types/migration/Asset.d.ts +0 -1
- package/dist/types/migration/Asset.d.ts.map +1 -1
- package/dist/types/migration/Asset.js +1 -1
- package/dist/types/migration/ContentRelationship.d.cts.map +1 -1
- package/dist/types/migration/ContentRelationship.d.ts.map +1 -1
- package/dist/types/migration/Document.cjs +1 -2
- package/dist/types/migration/Document.cjs.map +1 -1
- package/dist/types/migration/Document.d.cts +0 -1
- package/dist/types/migration/Document.d.cts.map +1 -1
- package/dist/types/migration/Document.d.ts +0 -1
- package/dist/types/migration/Document.d.ts.map +1 -1
- package/dist/types/migration/Document.js +1 -1
- package/dist/types/migration/Document.js.map +1 -1
- package/dist/types/model/boolean.d.cts +0 -1
- package/dist/types/model/boolean.d.cts.map +1 -1
- package/dist/types/model/boolean.d.ts +0 -1
- package/dist/types/model/boolean.d.ts.map +1 -1
- package/dist/types/model/color.d.cts +0 -1
- package/dist/types/model/color.d.cts.map +1 -1
- package/dist/types/model/color.d.ts +0 -1
- package/dist/types/model/color.d.ts.map +1 -1
- package/dist/types/model/contentRelationship.d.cts +0 -1
- package/dist/types/model/contentRelationship.d.cts.map +1 -1
- package/dist/types/model/contentRelationship.d.ts +0 -1
- package/dist/types/model/contentRelationship.d.ts.map +1 -1
- package/dist/types/model/customType.d.cts +0 -1
- package/dist/types/model/customType.d.cts.map +1 -1
- package/dist/types/model/customType.d.ts +0 -1
- package/dist/types/model/customType.d.ts.map +1 -1
- package/dist/types/model/date.d.cts +0 -1
- package/dist/types/model/date.d.cts.map +1 -1
- package/dist/types/model/date.d.ts +0 -1
- package/dist/types/model/date.d.ts.map +1 -1
- package/dist/types/model/embed.d.cts +0 -1
- package/dist/types/model/embed.d.cts.map +1 -1
- package/dist/types/model/embed.d.ts +0 -1
- package/dist/types/model/embed.d.ts.map +1 -1
- package/dist/types/model/geoPoint.d.cts +0 -1
- package/dist/types/model/geoPoint.d.cts.map +1 -1
- package/dist/types/model/geoPoint.d.ts +0 -1
- package/dist/types/model/geoPoint.d.ts.map +1 -1
- package/dist/types/model/group.d.cts +0 -1
- package/dist/types/model/group.d.cts.map +1 -1
- package/dist/types/model/group.d.ts +0 -1
- package/dist/types/model/group.d.ts.map +1 -1
- package/dist/types/model/image.d.cts +0 -1
- package/dist/types/model/image.d.cts.map +1 -1
- package/dist/types/model/image.d.ts +0 -1
- package/dist/types/model/image.d.ts.map +1 -1
- package/dist/types/model/integration.d.cts +0 -1
- package/dist/types/model/integration.d.cts.map +1 -1
- package/dist/types/model/integration.d.ts +0 -1
- package/dist/types/model/integration.d.ts.map +1 -1
- package/dist/types/model/keyText.d.cts +0 -1
- package/dist/types/model/keyText.d.cts.map +1 -1
- package/dist/types/model/keyText.d.ts +0 -1
- package/dist/types/model/keyText.d.ts.map +1 -1
- package/dist/types/model/link.cjs +1 -2
- package/dist/types/model/link.cjs.map +1 -1
- package/dist/types/model/link.d.cts +0 -1
- package/dist/types/model/link.d.cts.map +1 -1
- package/dist/types/model/link.d.ts +0 -1
- package/dist/types/model/link.d.ts.map +1 -1
- package/dist/types/model/link.js +1 -1
- package/dist/types/model/linkToMedia.d.cts +0 -1
- package/dist/types/model/linkToMedia.d.cts.map +1 -1
- package/dist/types/model/linkToMedia.d.ts +0 -1
- package/dist/types/model/linkToMedia.d.ts.map +1 -1
- package/dist/types/model/number.d.cts +0 -1
- package/dist/types/model/number.d.cts.map +1 -1
- package/dist/types/model/number.d.ts +0 -1
- package/dist/types/model/number.d.ts.map +1 -1
- package/dist/types/model/range.d.cts +0 -1
- package/dist/types/model/range.d.cts.map +1 -1
- package/dist/types/model/range.d.ts +0 -1
- package/dist/types/model/range.d.ts.map +1 -1
- package/dist/types/model/richText.d.cts +0 -1
- package/dist/types/model/richText.d.cts.map +1 -1
- package/dist/types/model/richText.d.ts +0 -1
- package/dist/types/model/richText.d.ts.map +1 -1
- package/dist/types/model/select.d.cts +0 -1
- package/dist/types/model/select.d.cts.map +1 -1
- package/dist/types/model/select.d.ts +0 -1
- package/dist/types/model/select.d.ts.map +1 -1
- package/dist/types/model/separator.d.cts +0 -1
- package/dist/types/model/separator.d.cts.map +1 -1
- package/dist/types/model/separator.d.ts +0 -1
- package/dist/types/model/separator.d.ts.map +1 -1
- package/dist/types/model/sharedSlice.d.cts +0 -1
- package/dist/types/model/sharedSlice.d.cts.map +1 -1
- package/dist/types/model/sharedSlice.d.ts +0 -1
- package/dist/types/model/sharedSlice.d.ts.map +1 -1
- package/dist/types/model/sharedSliceVariation.d.cts +0 -1
- package/dist/types/model/sharedSliceVariation.d.cts.map +1 -1
- package/dist/types/model/sharedSliceVariation.d.ts +0 -1
- package/dist/types/model/sharedSliceVariation.d.ts.map +1 -1
- package/dist/types/model/slice.cjs +1 -2
- package/dist/types/model/slice.cjs.map +1 -1
- package/dist/types/model/slice.d.cts +0 -1
- package/dist/types/model/slice.d.cts.map +1 -1
- package/dist/types/model/slice.d.ts +0 -1
- package/dist/types/model/slice.d.ts.map +1 -1
- package/dist/types/model/slice.js +1 -1
- package/dist/types/model/sliceZone.cjs +1 -2
- package/dist/types/model/sliceZone.cjs.map +1 -1
- package/dist/types/model/sliceZone.d.cts +0 -1
- package/dist/types/model/sliceZone.d.cts.map +1 -1
- package/dist/types/model/sliceZone.d.ts +0 -1
- package/dist/types/model/sliceZone.d.ts.map +1 -1
- package/dist/types/model/sliceZone.js +1 -1
- package/dist/types/model/table.d.cts +0 -1
- package/dist/types/model/table.d.cts.map +1 -1
- package/dist/types/model/table.d.ts +0 -1
- package/dist/types/model/table.d.ts.map +1 -1
- package/dist/types/model/timestamp.d.cts +0 -1
- package/dist/types/model/timestamp.d.cts.map +1 -1
- package/dist/types/model/timestamp.d.ts +0 -1
- package/dist/types/model/timestamp.d.ts.map +1 -1
- package/dist/types/model/title.d.cts +0 -1
- package/dist/types/model/title.d.cts.map +1 -1
- package/dist/types/model/title.d.ts +0 -1
- package/dist/types/model/title.d.ts.map +1 -1
- package/dist/types/model/types.cjs +1 -2
- package/dist/types/model/types.cjs.map +1 -1
- package/dist/types/model/types.d.cts +0 -1
- package/dist/types/model/types.d.cts.map +1 -1
- package/dist/types/model/types.d.ts +0 -1
- package/dist/types/model/types.d.ts.map +1 -1
- package/dist/types/model/types.js +1 -1
- package/dist/types/model/uid.d.cts +0 -1
- package/dist/types/model/uid.d.cts.map +1 -1
- package/dist/types/model/uid.d.ts +0 -1
- package/dist/types/model/uid.d.ts.map +1 -1
- package/dist/types/value/boolean.d.cts.map +1 -1
- package/dist/types/value/boolean.d.ts.map +1 -1
- package/dist/types/value/color.d.cts +0 -1
- package/dist/types/value/color.d.cts.map +1 -1
- package/dist/types/value/color.d.ts +0 -1
- package/dist/types/value/color.d.ts.map +1 -1
- package/dist/types/value/contentRelationship.d.cts +0 -1
- package/dist/types/value/contentRelationship.d.cts.map +1 -1
- package/dist/types/value/contentRelationship.d.ts +0 -1
- package/dist/types/value/contentRelationship.d.ts.map +1 -1
- package/dist/types/value/date.d.cts +0 -1
- package/dist/types/value/date.d.cts.map +1 -1
- package/dist/types/value/date.d.ts +0 -1
- package/dist/types/value/date.d.ts.map +1 -1
- package/dist/types/value/document.d.cts +0 -1
- package/dist/types/value/document.d.cts.map +1 -1
- package/dist/types/value/document.d.ts +0 -1
- package/dist/types/value/document.d.ts.map +1 -1
- package/dist/types/value/embed.cjs +1 -2
- package/dist/types/value/embed.cjs.map +1 -1
- package/dist/types/value/embed.d.cts +0 -1
- package/dist/types/value/embed.d.cts.map +1 -1
- package/dist/types/value/embed.d.ts +0 -1
- package/dist/types/value/embed.d.ts.map +1 -1
- package/dist/types/value/embed.js +1 -1
- package/dist/types/value/geoPoint.d.cts +0 -1
- package/dist/types/value/geoPoint.d.cts.map +1 -1
- package/dist/types/value/geoPoint.d.ts +0 -1
- package/dist/types/value/geoPoint.d.ts.map +1 -1
- package/dist/types/value/group.d.cts +0 -1
- package/dist/types/value/group.d.cts.map +1 -1
- package/dist/types/value/group.d.ts +0 -1
- package/dist/types/value/group.d.ts.map +1 -1
- package/dist/types/value/image.d.cts +0 -1
- package/dist/types/value/image.d.cts.map +1 -1
- package/dist/types/value/image.d.ts +0 -1
- package/dist/types/value/image.d.ts.map +1 -1
- package/dist/types/value/integration.d.cts +0 -1
- package/dist/types/value/integration.d.cts.map +1 -1
- package/dist/types/value/integration.d.ts +0 -1
- package/dist/types/value/integration.d.ts.map +1 -1
- package/dist/types/value/keyText.d.cts +0 -1
- package/dist/types/value/keyText.d.cts.map +1 -1
- package/dist/types/value/keyText.d.ts +0 -1
- package/dist/types/value/keyText.d.ts.map +1 -1
- package/dist/types/value/link.cjs +1 -2
- package/dist/types/value/link.cjs.map +1 -1
- package/dist/types/value/link.d.cts +0 -1
- package/dist/types/value/link.d.cts.map +1 -1
- package/dist/types/value/link.d.ts +0 -1
- package/dist/types/value/link.d.ts.map +1 -1
- package/dist/types/value/link.js +1 -1
- package/dist/types/value/linkToMedia.d.cts +0 -1
- package/dist/types/value/linkToMedia.d.cts.map +1 -1
- package/dist/types/value/linkToMedia.d.ts +0 -1
- package/dist/types/value/linkToMedia.d.ts.map +1 -1
- package/dist/types/value/number.d.cts +0 -1
- package/dist/types/value/number.d.cts.map +1 -1
- package/dist/types/value/number.d.ts +0 -1
- package/dist/types/value/number.d.ts.map +1 -1
- package/dist/types/value/richText.cjs +1 -2
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.d.cts +0 -1
- package/dist/types/value/richText.d.cts.map +1 -1
- package/dist/types/value/richText.d.ts +0 -1
- package/dist/types/value/richText.d.ts.map +1 -1
- package/dist/types/value/richText.js +1 -1
- package/dist/types/value/select.d.cts +0 -1
- package/dist/types/value/select.d.cts.map +1 -1
- package/dist/types/value/select.d.ts +0 -1
- package/dist/types/value/select.d.ts.map +1 -1
- package/dist/types/value/sharedSlice.d.cts +0 -1
- package/dist/types/value/sharedSlice.d.cts.map +1 -1
- package/dist/types/value/sharedSlice.d.ts +0 -1
- package/dist/types/value/sharedSlice.d.ts.map +1 -1
- package/dist/types/value/sharedSliceVariation.d.cts +0 -1
- package/dist/types/value/sharedSliceVariation.d.cts.map +1 -1
- package/dist/types/value/sharedSliceVariation.d.ts +0 -1
- package/dist/types/value/sharedSliceVariation.d.ts.map +1 -1
- package/dist/types/value/slice.d.cts +0 -1
- package/dist/types/value/slice.d.cts.map +1 -1
- package/dist/types/value/slice.d.ts +0 -1
- package/dist/types/value/slice.d.ts.map +1 -1
- package/dist/types/value/sliceZone.d.cts +0 -1
- package/dist/types/value/sliceZone.d.cts.map +1 -1
- package/dist/types/value/sliceZone.d.ts +0 -1
- package/dist/types/value/sliceZone.d.ts.map +1 -1
- package/dist/types/value/table.d.cts +0 -1
- package/dist/types/value/table.d.cts.map +1 -1
- package/dist/types/value/table.d.ts +0 -1
- package/dist/types/value/table.d.ts.map +1 -1
- package/dist/types/value/timestamp.d.cts +0 -1
- package/dist/types/value/timestamp.d.cts.map +1 -1
- package/dist/types/value/timestamp.d.ts +0 -1
- package/dist/types/value/timestamp.d.ts.map +1 -1
- package/dist/types/value/title.d.cts +0 -1
- package/dist/types/value/title.d.cts.map +1 -1
- package/dist/types/value/title.d.ts +0 -1
- package/dist/types/value/title.d.ts.map +1 -1
- package/dist/types/value/types.d.cts +0 -1
- package/dist/types/value/types.d.cts.map +1 -1
- package/dist/types/value/types.d.ts +0 -1
- package/dist/types/value/types.d.ts.map +1 -1
- package/dist/types/webhook/apiUpdate.d.cts +0 -1
- package/dist/types/webhook/apiUpdate.d.cts.map +1 -1
- package/dist/types/webhook/apiUpdate.d.ts +0 -1
- package/dist/types/webhook/apiUpdate.d.ts.map +1 -1
- package/dist/types/webhook/testTrigger.d.cts +0 -1
- package/dist/types/webhook/testTrigger.d.cts.map +1 -1
- package/dist/types/webhook/testTrigger.d.ts +0 -1
- package/dist/types/webhook/testTrigger.d.ts.map +1 -1
- package/dist/types/webhook/types.cjs +1 -2
- package/dist/types/webhook/types.cjs.map +1 -1
- package/dist/types/webhook/types.d.cts.map +1 -1
- package/dist/types/webhook/types.d.ts.map +1 -1
- package/dist/types/webhook/types.js +1 -1
- package/package.json +12 -12
- package/src/helpers/asImageWidthSrcSet.ts +1 -0
- package/src/lib/request.ts +29 -7
- package/dist/_virtual/rolldown_runtime.js +0 -13
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
const require_richText = require(
|
|
2
|
-
const require_link = require(
|
|
3
|
-
const require_Asset = require(
|
|
4
|
-
const require_Document = require(
|
|
5
|
-
const require_isFilled = require(
|
|
6
|
-
const require_isMigrationValue = require(
|
|
7
|
-
const require_getOptionalLinkProperties = require(
|
|
8
|
-
|
|
1
|
+
const require_richText = require("../types/value/richText.cjs");
|
|
2
|
+
const require_link = require("../types/value/link.cjs");
|
|
3
|
+
const require_Asset = require("../types/migration/Asset.cjs");
|
|
4
|
+
const require_Document = require("../types/migration/Document.cjs");
|
|
5
|
+
const require_isFilled = require("../helpers/isFilled.cjs");
|
|
6
|
+
const require_isMigrationValue = require("./isMigrationValue.cjs");
|
|
7
|
+
const require_getOptionalLinkProperties = require("./getOptionalLinkProperties.cjs");
|
|
9
8
|
//#region src/lib/resolveMigrationDocumentData.ts
|
|
10
9
|
/**
|
|
11
10
|
* Resolves a migration content relationship to a content relationship field.
|
|
@@ -46,9 +45,9 @@ async function resolveMigrationContentRelationship(relation) {
|
|
|
46
45
|
*
|
|
47
46
|
* @returns Resolved image field.
|
|
48
47
|
*/
|
|
49
|
-
const resolveMigrationImage = (image
|
|
48
|
+
const resolveMigrationImage = (image, migration, withThumbnails) => {
|
|
50
49
|
var _migration$_assets$ge;
|
|
51
|
-
const { id: master
|
|
50
|
+
const { id: master, ...thumbnails } = image instanceof require_Asset.PrismicMigrationAsset ? { id: image } : image;
|
|
52
51
|
const asset = (_migration$_assets$ge = migration._assets.get(master.config.id)) === null || _migration$_assets$ge === void 0 ? void 0 : _migration$_assets$ge.asset;
|
|
53
52
|
const maybeInitialField = master.originalField;
|
|
54
53
|
if (asset) {
|
|
@@ -89,12 +88,12 @@ const resolveMigrationImage = (image$1, migration, withThumbnails) => {
|
|
|
89
88
|
*
|
|
90
89
|
* @returns Resolved rich text image node.
|
|
91
90
|
*/
|
|
92
|
-
const resolveMigrationRTImageNode = async (rtImageNode
|
|
93
|
-
const image
|
|
94
|
-
if (image
|
|
95
|
-
const linkTo = await resolveMigrationDocumentData(rtImageNode
|
|
91
|
+
const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
|
|
92
|
+
const image = resolveMigrationImage(rtImageNode.id, migration);
|
|
93
|
+
if (image) {
|
|
94
|
+
const linkTo = await resolveMigrationDocumentData(rtImageNode.linkTo, migration);
|
|
96
95
|
return {
|
|
97
|
-
...image
|
|
96
|
+
...image,
|
|
98
97
|
type: require_richText.RichTextNodeType.image,
|
|
99
98
|
linkTo: require_isFilled.link(linkTo) ? linkTo : void 0
|
|
100
99
|
};
|
|
@@ -108,10 +107,10 @@ const resolveMigrationRTImageNode = async (rtImageNode$1, migration) => {
|
|
|
108
107
|
*
|
|
109
108
|
* @returns Resolved link to media field.
|
|
110
109
|
*/
|
|
111
|
-
const resolveMigrationLinkToMedia = (linkToMedia
|
|
110
|
+
const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
|
|
112
111
|
var _migration$_assets$ge2;
|
|
113
|
-
const asset = (_migration$_assets$ge2 = migration._assets.get(linkToMedia
|
|
114
|
-
const optionalLinkProperties = require_getOptionalLinkProperties.getOptionalLinkProperties(linkToMedia
|
|
112
|
+
const asset = (_migration$_assets$ge2 = migration._assets.get(linkToMedia.id.config.id)) === null || _migration$_assets$ge2 === void 0 ? void 0 : _migration$_assets$ge2.asset;
|
|
113
|
+
const optionalLinkProperties = require_getOptionalLinkProperties.getOptionalLinkProperties(linkToMedia);
|
|
115
114
|
if (asset) return {
|
|
116
115
|
...optionalLinkProperties,
|
|
117
116
|
id: asset.id,
|
|
@@ -149,8 +148,8 @@ async function resolveMigrationDocumentData(input, migration) {
|
|
|
149
148
|
}
|
|
150
149
|
return input;
|
|
151
150
|
}
|
|
152
|
-
|
|
153
151
|
//#endregion
|
|
154
152
|
exports.resolveMigrationContentRelationship = resolveMigrationContentRelationship;
|
|
155
153
|
exports.resolveMigrationDocumentData = resolveMigrationDocumentData;
|
|
154
|
+
|
|
156
155
|
//# sourceMappingURL=resolveMigrationDocumentData.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveMigrationDocumentData.cjs","names":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","image","PrismicMigrationAsset","dimensions: FilledImageFieldImage[\"dimensions\"]","edit: FilledImageFieldImage[\"edit\"]","resolvedThumbnails: Record<string, FilledImageFieldImage>","rtImageNode","RichTextNodeType","linkToMedia","res: Record<PropertyKey, unknown>"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,eAAsB,oCACrB,UACsE;AACtE,KAAI,OAAO,aAAa,WACvB,QAAO,oCAAoC,MAAM,UAAU,CAAC;A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OAAO,MAAM,6BAChB,MAAM,MACN,UACA;AAGF,SAAO;;AAIR,QAAO"}
|
|
1
|
+
{"version":3,"file":"resolveMigrationDocumentData.cjs","names":["PrismicMigrationDocument","LinkType","getOptionalLinkProperties","PrismicMigrationAsset","RichTextNodeType"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,eAAsB,oCACrB,UACsE;AACtE,KAAI,OAAO,aAAa,WACvB,QAAO,oCAAoC,MAAM,UAAU,CAAC;AAG7D,KAAI,oBAAoBA,iBAAAA,yBACvB,QAAO,SAAS,SAAS,KACtB;EAAE,WAAWC,aAAAA,SAAS;EAAU,IAAI,SAAS,SAAS;EAAI,GAC1D,EAAE,WAAWA,aAAAA,SAAS,KAAK;CAG/B,MAAM,yBACL,YAAY,eAAe,WACxBC,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AC;AAGjE,SAAO,IAAI,OAAO,QAAQ;;AAG3B,KAAI,SAAS,OAAO,UAAU,UAAU;EACvC,MAAM,MAAoC,EAAE;AAE5C,OAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAM,6BAChB,MAAM,MACN,UACA;AAGF,SAAO;;AAIR,QAAO"}
|
|
@@ -5,7 +5,6 @@ import { PrismicMigrationDocument } from "../types/migration/Document.js";
|
|
|
5
5
|
import { link } from "../helpers/isFilled.js";
|
|
6
6
|
import { contentRelationship, image, linkToMedia, rtImageNode } from "./isMigrationValue.js";
|
|
7
7
|
import { getOptionalLinkProperties } from "./getOptionalLinkProperties.js";
|
|
8
|
-
|
|
9
8
|
//#region src/lib/resolveMigrationDocumentData.ts
|
|
10
9
|
/**
|
|
11
10
|
* Resolves a migration content relationship to a content relationship field.
|
|
@@ -46,9 +45,9 @@ async function resolveMigrationContentRelationship(relation) {
|
|
|
46
45
|
*
|
|
47
46
|
* @returns Resolved image field.
|
|
48
47
|
*/
|
|
49
|
-
const resolveMigrationImage = (image
|
|
48
|
+
const resolveMigrationImage = (image, migration, withThumbnails) => {
|
|
50
49
|
var _migration$_assets$ge;
|
|
51
|
-
const { id: master
|
|
50
|
+
const { id: master, ...thumbnails } = image instanceof PrismicMigrationAsset ? { id: image } : image;
|
|
52
51
|
const asset = (_migration$_assets$ge = migration._assets.get(master.config.id)) === null || _migration$_assets$ge === void 0 ? void 0 : _migration$_assets$ge.asset;
|
|
53
52
|
const maybeInitialField = master.originalField;
|
|
54
53
|
if (asset) {
|
|
@@ -89,12 +88,12 @@ const resolveMigrationImage = (image$1, migration, withThumbnails) => {
|
|
|
89
88
|
*
|
|
90
89
|
* @returns Resolved rich text image node.
|
|
91
90
|
*/
|
|
92
|
-
const resolveMigrationRTImageNode = async (rtImageNode
|
|
93
|
-
const image
|
|
94
|
-
if (image
|
|
95
|
-
const linkTo = await resolveMigrationDocumentData(rtImageNode
|
|
91
|
+
const resolveMigrationRTImageNode = async (rtImageNode, migration) => {
|
|
92
|
+
const image = resolveMigrationImage(rtImageNode.id, migration);
|
|
93
|
+
if (image) {
|
|
94
|
+
const linkTo = await resolveMigrationDocumentData(rtImageNode.linkTo, migration);
|
|
96
95
|
return {
|
|
97
|
-
...image
|
|
96
|
+
...image,
|
|
98
97
|
type: RichTextNodeType.image,
|
|
99
98
|
linkTo: link(linkTo) ? linkTo : void 0
|
|
100
99
|
};
|
|
@@ -108,10 +107,10 @@ const resolveMigrationRTImageNode = async (rtImageNode$1, migration) => {
|
|
|
108
107
|
*
|
|
109
108
|
* @returns Resolved link to media field.
|
|
110
109
|
*/
|
|
111
|
-
const resolveMigrationLinkToMedia = (linkToMedia
|
|
110
|
+
const resolveMigrationLinkToMedia = (linkToMedia, migration) => {
|
|
112
111
|
var _migration$_assets$ge2;
|
|
113
|
-
const asset = (_migration$_assets$ge2 = migration._assets.get(linkToMedia
|
|
114
|
-
const optionalLinkProperties = getOptionalLinkProperties(linkToMedia
|
|
112
|
+
const asset = (_migration$_assets$ge2 = migration._assets.get(linkToMedia.id.config.id)) === null || _migration$_assets$ge2 === void 0 ? void 0 : _migration$_assets$ge2.asset;
|
|
113
|
+
const optionalLinkProperties = getOptionalLinkProperties(linkToMedia);
|
|
115
114
|
if (asset) return {
|
|
116
115
|
...optionalLinkProperties,
|
|
117
116
|
id: asset.id,
|
|
@@ -149,7 +148,7 @@ async function resolveMigrationDocumentData(input, migration) {
|
|
|
149
148
|
}
|
|
150
149
|
return input;
|
|
151
150
|
}
|
|
152
|
-
|
|
153
151
|
//#endregion
|
|
154
152
|
export { resolveMigrationContentRelationship, resolveMigrationDocumentData };
|
|
153
|
+
|
|
155
154
|
//# sourceMappingURL=resolveMigrationDocumentData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveMigrationDocumentData.js","names":["isMigration.contentRelationship","image","dimensions: FilledImageFieldImage[\"dimensions\"]","edit: FilledImageFieldImage[\"edit\"]","resolvedThumbnails: Record<string, FilledImageFieldImage>","rtImageNode","isFilled.link","linkToMedia","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode","res: Record<PropertyKey, unknown>"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,eAAsB,oCACrB,UACsE;AACtE,KAAI,OAAO,aAAa,WACvB,QAAO,oCAAoC,MAAM,UAAU,CAAC;AAG7D,KAAI,oBAAoB,yBACvB,QAAO,SAAS,SAAS,KACtB;EAAE,WAAW,SAAS;EAAU,IAAI,SAAS,SAAS;EAAI,GAC1D,EAAE,WAAW,SAAS,KAAK;CAG/B,MAAM,yBACL,YAAY,eAAe,WACxB,0BAA0B,SAAS,GACnC;AAEJ,KAAI,UAAU;AACb,MACCA,oBAAgC,SAAS,GAAG,IAC5C,OAAO,SAAS,OAAO,SAEvB,QAAO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J;GACH,MAAM,iBAAiB;GACvB,QAAQK,KAAc,OAAO,GAAG,SAAS;GACzC;;;;;;;;;;;AAYH,MAAa,+BACZ,eACA,cAC+B;;CAC/B,MAAM,kCAAQ,UAAU,QAAQ,IAAIC,cAAY,GAAG,OAAO,GAAG,kFAAE;CAC/D,MAAM,yBAAyB,0BAA0BA,cAAY;AAErE,KAAI,MACH,QAAO;EACN,GAAG;EACH,IAAI,MAAM;EACV,WAAW,SAAS;EACpB;AAGF,QAAO;EACN,GAAG;EACH,WAAW,SAAS;EACpB;;;;;;;;;;;AAYF,eAAsB,6BACrB,OACA,WACmB;AAEnB,KAAIP,oBAAgC,MAAM,CACzC,QAAO,oCAAoC,MAAM;AAGlD,KAAIQ,MAAkB,MAAM,CAC3B,QAAO,sBAAsB,OAAO,WAAW,KAAK;AAGrD,KAAIC,YAAwB,MAAM,CACjC,QAAO,4BAA4B,OAAO,UAAU;AAGrD,KAAIC,YAAwB,MAAM,CACjC,QAAO,4BAA4B,OAAO,UAAU;AAGrD,KAAI,OAAO,UAAU,WACpB,QAAO,MAAM,6BAA6B,MAAM,OAAO,EAAE,UAAU;AAIpE,KAAI,MAAM,QAAQ,MAAM,EAAE;EACzB,MAAM,MAAM,EAAE;AAEd,OAAK,MAAM,WAAW,MACrB,KAAI,KAAK,MAAM,6BAA6B,SAAS,UAAU,CAAC;AAGjE,SAAO,IAAI,OAAO,QAAQ;;AAG3B,KAAI,SAAS,OAAO,UAAU,UAAU;EACvC,MAAMC,MAAoC,EAAE;AAE5C,OAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAM,6BAChB,MAAM,MACN,UACA;AAGF,SAAO;;AAIR,QAAO"}
|
|
1
|
+
{"version":3,"file":"resolveMigrationDocumentData.js","names":["isMigration.contentRelationship","isFilled.link","isMigration.image","isMigration.linkToMedia","isMigration.rtImageNode"],"sources":["../../src/lib/resolveMigrationDocumentData.ts"],"sourcesContent":["import type { MigrationLinkToMediaField } from \"../types/migration/Asset\"\nimport {\n\ttype MigrationImage,\n\ttype MigrationLinkToMedia,\n\ttype MigrationRTImageNode,\n\tPrismicMigrationAsset,\n} from \"../types/migration/Asset\"\nimport type {\n\tMigrationContentRelationship,\n\tMigrationContentRelationshipField,\n} from \"../types/migration/ContentRelationship\"\nimport { PrismicMigrationDocument } from \"../types/migration/Document\"\nimport type { MaybeLink } from \"../types/migration/Link\"\nimport type { FilledImageFieldImage } from \"../types/value/image\"\nimport type { LinkField, OptionalLinkProperties } from \"../types/value/link\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTImageNode } from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\nimport * as isFilled from \"../helpers/isFilled\"\nimport type { Migration } from \"../Migration\"\n\nimport * as isMigration from \"./isMigrationValue\"\nimport { getOptionalLinkProperties } from \"./getOptionalLinkProperties\"\n\n/**\n * Resolves a migration content relationship to a content relationship field.\n *\n * @param relation - Content relationship to resolve.\n *\n * @returns Resolved content relationship field.\n */\nexport async function resolveMigrationContentRelationship(\n\trelation: MaybeLink<MigrationContentRelationship>,\n): Promise<MigrationContentRelationshipField & OptionalLinkProperties> {\n\tif (typeof relation === \"function\") {\n\t\treturn resolveMigrationContentRelationship(await relation())\n\t}\n\n\tif (relation instanceof PrismicMigrationDocument) {\n\t\treturn relation.document.id\n\t\t\t? { link_type: LinkType.Document, id: relation.document.id }\n\t\t\t: { link_type: LinkType.Any }\n\t}\n\n\tconst optionalLinkProperties =\n\t\trelation && \"link_type\" in relation\n\t\t\t? getOptionalLinkProperties(relation)\n\t\t\t: undefined\n\n\tif (relation) {\n\t\tif (\n\t\t\tisMigration.contentRelationship(relation.id) ||\n\t\t\ttypeof relation.id !== \"string\"\n\t\t) {\n\t\t\treturn {\n\t\t\t\t...optionalLinkProperties,\n\t\t\t\t...(await resolveMigrationContentRelationship(relation.id)),\n\t\t\t}\n\t\t}\n\n\t\t// This is only called when resolveMigrationContentRelationship recursively\n\t\t// calls itself from the statement above and the resolved content relation\n\t\t// is a Prismic document value.\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tlink_type: LinkType.Document,\n\t\t\tid: relation.id,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration image to an image field.\n *\n * @param migrationAsset - Asset to resolve.\n * @param migration - Migration instance.\n * @param withThumbnails - Whether to include thumbnails.\n *\n * @returns Resolved image field.\n */\nexport const resolveMigrationImage = (\n\timage: MigrationImage,\n\tmigration: Migration,\n\twithThumbnails?: boolean,\n): FilledImageFieldImage | undefined => {\n\tconst { id: master, ...thumbnails } =\n\t\timage instanceof PrismicMigrationAsset ? { id: image } : image\n\n\tconst asset = migration._assets.get(master.config.id)?.asset\n\tconst maybeInitialField = master.originalField\n\n\tif (asset) {\n\t\tconst parameters = (maybeInitialField?.url || asset.url).split(\"?\")[1]\n\t\tconst url = `${asset.url.split(\"?\")[0]}${parameters ? `?${parameters}` : \"\"}`\n\t\tconst dimensions: FilledImageFieldImage[\"dimensions\"] = {\n\t\t\twidth: asset.width!,\n\t\t\theight: asset.height!,\n\t\t}\n\t\tconst edit: FilledImageFieldImage[\"edit\"] =\n\t\t\tmaybeInitialField && \"edit\" in maybeInitialField\n\t\t\t\t? maybeInitialField?.edit\n\t\t\t\t: { x: 0, y: 0, zoom: 1, background: \"transparent\" }\n\n\t\t// We give priority to the asset's specific alt text, then the image's general alt text\n\t\tconst alt = master.config.alt || asset.alt || null\n\n\t\tconst resolvedThumbnails: Record<string, FilledImageFieldImage> = {}\n\t\tif (withThumbnails) {\n\t\t\tfor (const [name, thumbnail] of Object.entries(thumbnails)) {\n\t\t\t\tconst resolvedThumbnail = resolveMigrationImage(thumbnail, migration)\n\t\t\t\tif (resolvedThumbnail) {\n\t\t\t\t\tresolvedThumbnails[name] = resolvedThumbnail\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tid: asset.id,\n\t\t\turl,\n\t\t\tdimensions,\n\t\t\tedit,\n\t\t\talt: alt,\n\t\t\tcopyright: asset.credits || null,\n\t\t\t...resolvedThumbnails,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration rich text image node to a regular rich text image node.\n *\n * @param rtImageNode - Migration rich text image node to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved rich text image node.\n */\nexport const resolveMigrationRTImageNode = async (\n\trtImageNode: MigrationRTImageNode,\n\tmigration: Migration,\n): Promise<RTImageNode | undefined> => {\n\tconst image = resolveMigrationImage(rtImageNode.id, migration)\n\n\tif (image) {\n\t\tconst linkTo = (await resolveMigrationDocumentData(\n\t\t\trtImageNode.linkTo,\n\t\t\tmigration,\n\t\t)) as LinkField\n\n\t\treturn {\n\t\t\t...image,\n\t\t\ttype: RichTextNodeType.image,\n\t\t\tlinkTo: isFilled.link(linkTo) ? linkTo : undefined,\n\t\t}\n\t}\n}\n\n/**\n * Resolves a migration link to media to a regular link to media field.\n *\n * @param linkToMedia - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved link to media field.\n */\nexport const resolveMigrationLinkToMedia = (\n\tlinkToMedia: MaybeLink<MigrationLinkToMedia>,\n\tmigration: Migration,\n): MigrationLinkToMediaField => {\n\tconst asset = migration._assets.get(linkToMedia.id.config.id)?.asset\n\tconst optionalLinkProperties = getOptionalLinkProperties(linkToMedia)\n\n\tif (asset) {\n\t\treturn {\n\t\t\t...optionalLinkProperties,\n\t\t\tid: asset.id,\n\t\t\tlink_type: LinkType.Media,\n\t\t}\n\t}\n\n\treturn {\n\t\t...optionalLinkProperties,\n\t\tlink_type: LinkType.Any,\n\t}\n}\n\n/**\n * Resolves a migration document data to actual data ready to be sent to the\n * Migration API.\n *\n * @param input - Migration link to media to resolve.\n * @param migration - Migration instance.\n *\n * @returns Resolved data.\n */\nexport async function resolveMigrationDocumentData(\n\tinput: unknown,\n\tmigration: Migration,\n): Promise<unknown> {\n\t// Migration fields\n\tif (isMigration.contentRelationship(input)) {\n\t\treturn resolveMigrationContentRelationship(input)\n\t}\n\n\tif (isMigration.image(input)) {\n\t\treturn resolveMigrationImage(input, migration, true)\n\t}\n\n\tif (isMigration.linkToMedia(input)) {\n\t\treturn resolveMigrationLinkToMedia(input, migration)\n\t}\n\n\tif (isMigration.rtImageNode(input)) {\n\t\treturn resolveMigrationRTImageNode(input, migration)\n\t}\n\n\tif (typeof input === \"function\") {\n\t\treturn await resolveMigrationDocumentData(await input(), migration)\n\t}\n\n\t// Object traversing\n\tif (Array.isArray(input)) {\n\t\tconst res = []\n\n\t\tfor (const element of input) {\n\t\t\tres.push(await resolveMigrationDocumentData(element, migration))\n\t\t}\n\n\t\treturn res.filter(Boolean)\n\t}\n\n\tif (input && typeof input === \"object\") {\n\t\tconst res: Record<PropertyKey, unknown> = {}\n\n\t\tfor (const key in input) {\n\t\t\tres[key] = await resolveMigrationDocumentData(\n\t\t\t\tinput[key as keyof typeof input],\n\t\t\t\tmigration,\n\t\t\t)\n\t\t}\n\n\t\treturn res\n\t}\n\n\t// Primitives\n\treturn input\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,eAAsB,oCACrB,UACsE;AACtE,KAAI,OAAO,aAAa,WACvB,QAAO,oCAAoC,MAAM,UAAU,CAAC;AAG7D,KAAI,oBAAoB,yBACvB,QAAO,SAAS,SAAS,KACtB;EAAE,WAAW,SAAS;EAAU,IAAI,SAAS,SAAS;EAAI,GAC1D,EAAE,WAAW,SAAS,KAAK;CAG/B,MAAM,yBACL,YAAY,eAAe,WACxB,0BAA0B,SAAS,GACnC,KAAA;AAEJ,KAAI,UAAU;AACb,MACCA,oBAAgC,SAAS,GAAG,IAC5C,OAAO,SAAS,OAAO,SAEvB,QAAO;GACN,GAAG;GACH,GAAI,MAAM,oCAAoC,SAAS,GAAG;GAC1D;AAMF,SAAO;GACN,GAAG;GACH,WAAW,SAAS;GACpB,IAAI,SAAS;GACb;;AAGF,QAAO;EACN,GAAG;EACH,WAAW,SAAS;EACpB;;;;;;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AG,SAAS,KAAA;GACzC;;;;;;;;;;;AAYH,MAAa,+BACZ,aACA,cAC+B;;CAC/B,MAAM,SAAA,yBAAQ,UAAU,QAAQ,IAAI,YAAY,GAAG,OAAO,GAAG,MAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAE;CAC/D,MAAM,yBAAyB,0BAA0B,YAAY;AAErE,KAAI,MACH,QAAO;EACN,GAAG;EACH,IAAI,MAAM;EACV,WAAW,SAAS;EACpB;AAGF,QAAO;EACN,GAAG;EACH,WAAW,SAAS;EACpB;;;;;;;;;;;AAYF,eAAsB,6BACrB,OACA,WACmB;AAEnB,KAAID,oBAAgC,MAAM,CACzC,QAAO,oCAAoC,MAAM;AAGlD,KAAIE,MAAkB,MAAM,CAC3B,QAAO,sBAAsB,OAAO,WAAW,KAAK;AAGrD,KAAIC,YAAwB,MAAM,CACjC,QAAO,4BAA4B,OAAO,UAAU;AAGrD,KAAIC,YAAwB,MAAM,CACjC,QAAO,4BAA4B,OAAO,UAAU;AAGrD,KAAI,OAAO,UAAU,WACpB,QAAO,MAAM,6BAA6B,MAAM,OAAO,EAAE,UAAU;AAIpE,KAAI,MAAM,QAAQ,MAAM,EAAE;EACzB,MAAM,MAAM,EAAE;AAEd,OAAK,MAAM,WAAW,MACrB,KAAI,KAAK,MAAM,6BAA6B,SAAS,UAAU,CAAC;AAGjE,SAAO,IAAI,OAAO,QAAQ;;AAG3B,KAAI,SAAS,OAAO,UAAU,UAAU;EACvC,MAAM,MAAoC,EAAE;AAE5C,OAAK,MAAM,OAAO,MACjB,KAAI,OAAO,MAAM,6BAChB,MAAM,MACN,UACA;AAGF,SAAO;;AAIR,QAAO"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const require_link = require(
|
|
2
|
-
const require_asLink = require(
|
|
3
|
-
const require_escapeHTML = require(
|
|
4
|
-
|
|
1
|
+
const require_link = require("../types/value/link.cjs");
|
|
2
|
+
const require_asLink = require("../helpers/asLink.cjs");
|
|
3
|
+
const require_escapeHTML = require("./escapeHTML.cjs");
|
|
5
4
|
//#region src/lib/serializerHelpers.ts
|
|
6
5
|
const formatAttributes = (node, attributes) => {
|
|
7
6
|
const _attributes = { ...attributes };
|
|
@@ -84,7 +83,6 @@ const serializeSpan = () => {
|
|
|
84
83
|
return text ? require_escapeHTML.escapeHTML(text).replace(/\n/g, "<br />") : "";
|
|
85
84
|
};
|
|
86
85
|
};
|
|
87
|
-
|
|
88
86
|
//#endregion
|
|
89
87
|
exports.serializeEmbed = serializeEmbed;
|
|
90
88
|
exports.serializeHyperlink = serializeHyperlink;
|
|
@@ -92,4 +90,5 @@ exports.serializeImage = serializeImage;
|
|
|
92
90
|
exports.serializePreFormatted = serializePreFormatted;
|
|
93
91
|
exports.serializeSpan = serializeSpan;
|
|
94
92
|
exports.serializeStandardTag = serializeStandardTag;
|
|
93
|
+
|
|
95
94
|
//# sourceMappingURL=serializerHelpers.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializerHelpers.cjs","names":["escapeHTML","LinkType","asLink"],"sources":["../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\n\nimport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\n\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Respect `ltr` and `rtl` direction\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\t_attributes.dir = node.direction\n\t}\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializerHelpers.cjs","names":["escapeHTML","LinkType","asLink"],"sources":["../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\n\nimport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\n\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Respect `ltr` and `rtl` direction\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\t_attributes.dir = node.direction\n\t}\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"mappings":";;;;AAcA,MAAM,oBAAoB,MAAiB,eAAmC;CAC7E,MAAM,cAAc,EAAE,GAAG,YAAY;AAGrC,KAAI,eAAe,QAAQ,KAAK,cAAc,MAC7C,aAAY,MAAM,KAAK;AAIxB,KAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,MACvD,aAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,MAAM,GAAG,KAAK,KAAK,UAClC,KAAK,KAAK;CAGd,MAAM,SAAS,EAAE;AAEjB,MAAK,MAAM,OAAO,aAAa;EAC9B,MAAM,QAAQ,YAAY;AAE1B,MAAI,MACH,KAAI,OAAO,UAAU,UACpB,QAAO,KAAK,IAAI;MAEhB,QAAO,KAAK,GAAG,IAAI,IAAIA,mBAAAA,WAAW,MAAM,CAAC,GAAG;;AAM/C,KAAI,OAAO,OACV,QAAO,QAAQ,GAAG;AAGnB,QAAO,OAAO,KAAK,IAAI;;AAGxB,MAAM,wBACL,0BACgB;AAChB,QAAO,yBAAyB,OAAO,0BAA0B,aAC9D,wBACA,EAAE;;AAGN,MAAa,wBAGZ,KACA,0BAC6D;CAC7D,MAAM,oBAAoB,qBAAqB,sBAAsB;AAErE,UAAS,EAAE,MAAM,eAAe;AAC/B,SAAO,IAAI,MAAM,iBAChB,MACA,kBACA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AAA,OAAO,KAAK,MAAM,EAAE,cAAc,CAAC;WAC3C,KAAK,KAAK,cAAcD,aAAAA,SAAS,MAC3C,YAAW,OAAO,KAAK,KAAK;AAG7B,SAAO,KAAK,iBAAiB,MAAM,WAAW,CAAC,GAAG,SAAS;;;AAI7D,MAAa,sBAER;AACJ,SAAQ,EAAE,WAAmB;AAC5B,SAAO,OAAOD,mBAAAA,WAAW,KAAK,CAAC,QAAQ,OAAO,SAAS,GAAG"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LinkType } from "../types/value/link.js";
|
|
2
2
|
import { asLink } from "../helpers/asLink.js";
|
|
3
3
|
import { escapeHTML } from "./escapeHTML.js";
|
|
4
|
-
|
|
5
4
|
//#region src/lib/serializerHelpers.ts
|
|
6
5
|
const formatAttributes = (node, attributes) => {
|
|
7
6
|
const _attributes = { ...attributes };
|
|
@@ -84,7 +83,7 @@ const serializeSpan = () => {
|
|
|
84
83
|
return text ? escapeHTML(text).replace(/\n/g, "<br />") : "";
|
|
85
84
|
};
|
|
86
85
|
};
|
|
87
|
-
|
|
88
86
|
//#endregion
|
|
89
87
|
export { serializeEmbed, serializeHyperlink, serializeImage, serializePreFormatted, serializeSpan, serializeStandardTag };
|
|
88
|
+
|
|
90
89
|
//# sourceMappingURL=serializerHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializerHelpers.js","names":[],"sources":["../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\n\nimport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\n\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Respect `ltr` and `rtl` direction\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\t_attributes.dir = node.direction\n\t}\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializerHelpers.js","names":[],"sources":["../../src/lib/serializerHelpers.ts"],"sourcesContent":["import type { RichTextMapSerializer } from \"../richtext/types\"\nimport { LinkType } from \"../types/value/link\"\nimport type { RTAnyNode } from \"../types/value/richText\"\n\nimport type {\n\tHTMLRichTextMapSerializer,\n\tHTMLStrictRichTextMapSerializer,\n} from \"../helpers/asHTML\"\nimport type { LinkResolverFunction } from \"../helpers/asLink\"\nimport { asLink } from \"../helpers/asLink\"\n\nimport { escapeHTML } from \"./escapeHTML\"\n\ntype Attributes = Record<string, string | boolean | null | undefined>\nconst formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {\n\tconst _attributes = { ...attributes }\n\n\t// Respect `ltr` and `rtl` direction\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\t_attributes.dir = node.direction\n\t}\n\n\t// Add label to attributes\n\tif (\"data\" in node && \"label\" in node.data && node.data.label) {\n\t\t_attributes.class = _attributes.class\n\t\t\t? `${_attributes.class} ${node.data.label}`\n\t\t\t: node.data.label\n\t}\n\n\tconst result = []\n\n\tfor (const key in _attributes) {\n\t\tconst value = _attributes[key]\n\n\t\tif (value) {\n\t\t\tif (typeof value === \"boolean\") {\n\t\t\t\tresult.push(key)\n\t\t\t} else {\n\t\t\t\tresult.push(`${key}=\"${escapeHTML(value)}\"`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Add a space at the beginning if there's any result\n\tif (result.length) {\n\t\tresult.unshift(\"\")\n\t}\n\n\treturn result.join(\" \")\n}\n\nconst getGeneralAttributes = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[keyof HTMLRichTextMapSerializer],\n): Attributes => {\n\treturn serializerOrShorthand && typeof serializerOrShorthand !== \"function\"\n\t\t? serializerOrShorthand\n\t\t: {}\n}\n\nexport const serializeStandardTag = <\n\tBlockType extends keyof RichTextMapSerializer<string>,\n>(\n\ttag: string,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[BlockType],\n): NonNullable<HTMLStrictRichTextMapSerializer[BlockType]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn (({ node, children }) => {\n\t\treturn `<${tag}${formatAttributes(\n\t\t\tnode,\n\t\t\tgeneralAttributes,\n\t\t)}>${children}</${tag}>`\n\t}) as NonNullable<HTMLStrictRichTextMapSerializer[BlockType]>\n}\n\nexport const serializePreFormatted = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"preformatted\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"preformatted\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\treturn `<pre${formatAttributes(node, generalAttributes)}>${escapeHTML(\n\t\t\tnode.text,\n\t\t)}</pre>`\n\t}\n}\n\nexport const serializeImage = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"image\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"image\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\tsrc: node.url,\n\t\t\talt: node.alt,\n\t\t\tcopyright: node.copyright,\n\t\t}\n\n\t\tlet imageTag = `<img${formatAttributes(node, attributes)} />`\n\n\t\t// If the image has a link, we wrap it with an anchor tag\n\t\tif (node.linkTo) {\n\t\t\timageTag = serializeHyperlink(linkResolver)({\n\t\t\t\ttype: \"hyperlink\",\n\t\t\t\tnode: {\n\t\t\t\t\ttype: \"hyperlink\",\n\t\t\t\t\tdata: node.linkTo,\n\t\t\t\t\tstart: 0,\n\t\t\t\t\tend: 0,\n\t\t\t\t},\n\t\t\t\ttext: \"\",\n\t\t\t\tchildren: imageTag,\n\t\t\t\tkey: \"\",\n\t\t\t})!\n\t\t}\n\n\t\treturn `<p class=\"block-img\">${imageTag}</p>`\n\t}\n}\n\nexport const serializeEmbed = (\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"embed\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"embed\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node }) => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t\t[\"data-oembed\"]: node.oembed.embed_url,\n\t\t\t[\"data-oembed-type\"]: node.oembed.type,\n\t\t\t[\"data-oembed-provider\"]: node.oembed.provider_name,\n\t\t}\n\n\t\treturn `<div${formatAttributes(node, attributes)}>${node.oembed.html}</div>`\n\t}\n}\n\nexport const serializeHyperlink = (\n\tlinkResolver:\n\t\t| LinkResolverFunction<string | null | undefined>\n\t\t| undefined\n\t\t| null,\n\tserializerOrShorthand?: HTMLRichTextMapSerializer[\"hyperlink\"],\n): NonNullable<HTMLStrictRichTextMapSerializer[\"hyperlink\"]> => {\n\tconst generalAttributes = getGeneralAttributes(serializerOrShorthand)\n\n\treturn ({ node, children }): string => {\n\t\tconst attributes = {\n\t\t\t...generalAttributes,\n\t\t}\n\n\t\tif (node.data.link_type === LinkType.Web) {\n\t\t\tattributes.href = node.data.url\n\t\t\tattributes.target = node.data.target\n\t\t\tattributes.rel = \"noopener noreferrer\"\n\t\t} else if (node.data.link_type === LinkType.Document) {\n\t\t\tattributes.href = asLink(node.data, { linkResolver })\n\t\t} else if (node.data.link_type === LinkType.Media) {\n\t\t\tattributes.href = node.data.url\n\t\t}\n\n\t\treturn `<a${formatAttributes(node, attributes)}>${children}</a>`\n\t}\n}\n\nexport const serializeSpan = (): NonNullable<\n\tHTMLStrictRichTextMapSerializer[\"span\"]\n> => {\n\treturn ({ text }): string => {\n\t\treturn text ? escapeHTML(text).replace(/\\n/g, \"<br />\") : \"\"\n\t}\n}\n"],"mappings":";;;;AAcA,MAAM,oBAAoB,MAAiB,eAAmC;CAC7E,MAAM,cAAc,EAAE,GAAG,YAAY;AAGrC,KAAI,eAAe,QAAQ,KAAK,cAAc,MAC7C,aAAY,MAAM,KAAK;AAIxB,KAAI,UAAU,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,MACvD,aAAY,QAAQ,YAAY,QAC7B,GAAG,YAAY,MAAM,GAAG,KAAK,KAAK,UAClC,KAAK,KAAK;CAGd,MAAM,SAAS,EAAE;AAEjB,MAAK,MAAM,OAAO,aAAa;EAC9B,MAAM,QAAQ,YAAY;AAE1B,MAAI,MACH,KAAI,OAAO,UAAU,UACpB,QAAO,KAAK,IAAI;MAEhB,QAAO,KAAK,GAAG,IAAI,IAAI,WAAW,MAAM,CAAC,GAAG;;AAM/C,KAAI,OAAO,OACV,QAAO,QAAQ,GAAG;AAGnB,QAAO,OAAO,KAAK,IAAI;;AAGxB,MAAM,wBACL,0BACgB;AAChB,QAAO,yBAA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KAAK,cAAc,SAAS,KAAK;AACzC,cAAW,OAAO,KAAK,KAAK;AAC5B,cAAW,SAAS,KAAK,KAAK;AAC9B,cAAW,MAAM;aACP,KAAK,KAAK,cAAc,SAAS,SAC3C,YAAW,OAAO,OAAO,KAAK,MAAM,EAAE,cAAc,CAAC;WAC3C,KAAK,KAAK,cAAc,SAAS,MAC3C,YAAW,OAAO,KAAK,KAAK;AAG7B,SAAO,KAAK,iBAAiB,MAAM,WAAW,CAAC,GAAG,SAAS;;;AAI7D,MAAa,sBAER;AACJ,SAAQ,EAAE,WAAmB;AAC5B,SAAO,OAAO,WAAW,KAAK,CAAC,QAAQ,OAAO,SAAS,GAAG"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/lib/throttledWarn.ts
|
|
3
2
|
const THROTTLE_THRESHOLD_MS = 5e3;
|
|
4
3
|
let lastMessage;
|
|
@@ -21,7 +20,7 @@ const throttledWarn = (message) => {
|
|
|
21
20
|
lastMessage = message;
|
|
22
21
|
console.warn(message);
|
|
23
22
|
};
|
|
24
|
-
|
|
25
23
|
//#endregion
|
|
26
24
|
exports.throttledWarn = throttledWarn;
|
|
25
|
+
|
|
27
26
|
//# sourceMappingURL=throttledWarn.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttledWarn.cjs","names":[
|
|
1
|
+
{"version":3,"file":"throttledWarn.cjs","names":[],"sources":["../../src/lib/throttledWarn.ts"],"sourcesContent":["const THROTTLE_THRESHOLD_MS = 5000\n\nlet lastMessage: string | undefined\nlet lastCalledAt = 0\n\n/**\n * Logs a warning. If the message is identical the immediate previous logged\n * message and that message was logged within 5 seconds of the current call, the\n * log is ignored. This throttle behavior prevents identical messages from\n * flooding the console.\n *\n * @param message - A message to log.\n * @param config - Configuration for the log.\n */\nexport const throttledWarn = (message: string): void => {\n\tif (\n\t\tmessage === lastMessage &&\n\t\tDate.now() - lastCalledAt < THROTTLE_THRESHOLD_MS\n\t) {\n\t\tlastCalledAt = Date.now()\n\n\t\treturn\n\t}\n\n\tlastCalledAt = Date.now()\n\tlastMessage = message\n\n\tconsole.warn(message)\n}\n"],"mappings":";AAAA,MAAM,wBAAwB;AAE9B,IAAI;AACJ,IAAI,eAAe;;;;;;;;;;AAWnB,MAAa,iBAAiB,YAA0B;AACvD,KACC,YAAY,eACZ,KAAK,KAAK,GAAG,eAAe,uBAC3B;AACD,iBAAe,KAAK,KAAK;AAEzB;;AAGD,gBAAe,KAAK,KAAK;AACzB,eAAc;AAEd,SAAQ,KAAK,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttledWarn.js","names":[
|
|
1
|
+
{"version":3,"file":"throttledWarn.js","names":[],"sources":["../../src/lib/throttledWarn.ts"],"sourcesContent":["const THROTTLE_THRESHOLD_MS = 5000\n\nlet lastMessage: string | undefined\nlet lastCalledAt = 0\n\n/**\n * Logs a warning. If the message is identical the immediate previous logged\n * message and that message was logged within 5 seconds of the current call, the\n * log is ignored. This throttle behavior prevents identical messages from\n * flooding the console.\n *\n * @param message - A message to log.\n * @param config - Configuration for the log.\n */\nexport const throttledWarn = (message: string): void => {\n\tif (\n\t\tmessage === lastMessage &&\n\t\tDate.now() - lastCalledAt < THROTTLE_THRESHOLD_MS\n\t) {\n\t\tlastCalledAt = Date.now()\n\n\t\treturn\n\t}\n\n\tlastCalledAt = Date.now()\n\tlastMessage = message\n\n\tconsole.warn(message)\n}\n"],"mappings":";AAAA,MAAM,wBAAwB;AAE9B,IAAI;AACJ,IAAI,eAAe;;;;;;;;;;AAWnB,MAAa,iBAAiB,YAA0B;AACvD,KACC,YAAY,eACZ,KAAK,KAAK,GAAG,eAAe,uBAC3B;AACD,iBAAe,KAAK,KAAK;AAEzB;;AAGD,gBAAe,KAAK,KAAK;AACzB,eAAc;AAEd,SAAQ,KAAK,QAAQ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const require_errors = require(
|
|
2
|
-
|
|
1
|
+
const require_errors = require("../errors.cjs");
|
|
3
2
|
//#region src/lib/validateAssetMetadata.ts
|
|
4
3
|
/**
|
|
5
4
|
* Max length for asset notes accepted by the API.
|
|
@@ -42,7 +41,7 @@ const validateAssetMetadata = ({ notes, credits, alt, tags }) => {
|
|
|
42
41
|
tags
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
|
|
46
44
|
//#endregion
|
|
47
45
|
exports.validateAssetMetadata = validateAssetMetadata;
|
|
46
|
+
|
|
48
47
|
//# sourceMappingURL=validateAssetMetadata.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateAssetMetadata.cjs","names":["
|
|
1
|
+
{"version":3,"file":"validateAssetMetadata.cjs","names":["PrismicError"],"sources":["../../src/lib/validateAssetMetadata.ts"],"sourcesContent":["import { PrismicError } from \"../errors\"\n\nimport type { CreateAssetParams } from \"../WriteClient\"\n\n/**\n * Max length for asset notes accepted by the API.\n */\nconst ASSET_NOTES_MAX_LENGTH = 500\n\n/**\n * Max length for asset credits accepted by the API.\n */\nconst ASSET_CREDITS_MAX_LENGTH = 500\n\n/**\n * Max length for asset alt text accepted by the API.\n */\nconst ASSET_ALT_MAX_LENGTH = 500\n\n/**\n * Min length for asset tags accepted by the API.\n */\nconst ASSET_TAG_MIN_LENGTH = 3\n\n/**\n * Max length for asset tags accepted by the API.\n */\nconst ASSET_TAG_MAX_LENGTH = 20\n\n/**\n * Validates an asset's metadata, throwing an error if any of the metadata are\n * invalid.\n *\n * @param assetMetadata - The asset metadata to validate.\n *\n * @internal\n */\nexport const validateAssetMetadata = ({\n\tnotes,\n\tcredits,\n\talt,\n\ttags,\n}: CreateAssetParams): void => {\n\tconst errors: string[] = []\n\n\tif (notes && notes.length > ASSET_NOTES_MAX_LENGTH) {\n\t\terrors.push(\n\t\t\t`\\`notes\\` must be at most ${ASSET_NOTES_MAX_LENGTH} characters`,\n\t\t)\n\t}\n\n\tif (credits && credits.length > ASSET_CREDITS_MAX_LENGTH) {\n\t\terrors.push(\n\t\t\t`\\`credits\\` must be at most ${ASSET_CREDITS_MAX_LENGTH} characters`,\n\t\t)\n\t}\n\n\tif (alt && alt.length > ASSET_ALT_MAX_LENGTH) {\n\t\terrors.push(`\\`alt\\` must be at most ${ASSET_ALT_MAX_LENGTH} characters`)\n\t}\n\n\tif (\n\t\ttags &&\n\t\ttags.length &&\n\t\ttags.some(\n\t\t\t(tag) =>\n\t\t\t\ttag.length < ASSET_TAG_MIN_LENGTH || tag.length > ASSET_TAG_MAX_LENGTH,\n\t\t)\n\t) {\n\t\terrors.push(\n\t\t\t`tags must be at least 3 characters long and 20 characters at most`,\n\t\t)\n\t}\n\n\tif (errors.length) {\n\t\tthrow new PrismicError(\n\t\t\t`Errors validating asset metadata: ${errors.join(\", \")}`,\n\t\t\tundefined,\n\t\t\t{ notes, credits, alt, tags },\n\t\t)\n\t}\n}\n"],"mappings":";;;;;AAOA,MAAM,yBAAyB;;;;AAK/B,MAAM,2BAA2B;;;;AAKjC,MAAM,uBAAuB;;;;AAK7B,MAAM,uBAAuB;;;;AAK7B,MAAM,uBAAuB;;;;;;;;;AAU7B,MAAa,yBAAyB,EACrC,OACA,SACA,KACA,WAC8B;CAC9B,MAAM,SAAmB,EAAE;AAE3B,KAAI,SAAS,MAAM,SAAS,uBAC3B,QAAO,KACN,6BAA6B,uBAAuB,aACpD;AAGF,KAAI,WAAW,QAAQ,SAAS,yBAC/B,QAAO,KACN,+BAA+B,yBAAyB,aACxD;AAGF,KAAI,OAAO,IAAI,SAAS,qBACvB,QAAO,KAAK,2BAA2B,qBAAqB,aAAa;AAG1E,KACC,QACA,KAAK,UACL,KAAK,MACH,QACA,IAAI,SAAS,wBAAwB,IAAI,SAAS,qBACnD,CAED,QAAO,KACN,oEACA;AAGF,KAAI,OAAO,OACV,OAAM,IAAIA,eAAAA,aACT,qCAAqC,OAAO,KAAK,KAAK,IACtD,KAAA,GACA;EAAE;EAAO;EAAS;EAAK;EAAM,CAC7B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PrismicError } from "../errors.js";
|
|
2
|
-
|
|
3
2
|
//#region src/lib/validateAssetMetadata.ts
|
|
4
3
|
/**
|
|
5
4
|
* Max length for asset notes accepted by the API.
|
|
@@ -42,7 +41,7 @@ const validateAssetMetadata = ({ notes, credits, alt, tags }) => {
|
|
|
42
41
|
tags
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
|
|
46
44
|
//#endregion
|
|
47
45
|
export { validateAssetMetadata };
|
|
46
|
+
|
|
48
47
|
//# sourceMappingURL=validateAssetMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateAssetMetadata.js","names":[
|
|
1
|
+
{"version":3,"file":"validateAssetMetadata.js","names":[],"sources":["../../src/lib/validateAssetMetadata.ts"],"sourcesContent":["import { PrismicError } from \"../errors\"\n\nimport type { CreateAssetParams } from \"../WriteClient\"\n\n/**\n * Max length for asset notes accepted by the API.\n */\nconst ASSET_NOTES_MAX_LENGTH = 500\n\n/**\n * Max length for asset credits accepted by the API.\n */\nconst ASSET_CREDITS_MAX_LENGTH = 500\n\n/**\n * Max length for asset alt text accepted by the API.\n */\nconst ASSET_ALT_MAX_LENGTH = 500\n\n/**\n * Min length for asset tags accepted by the API.\n */\nconst ASSET_TAG_MIN_LENGTH = 3\n\n/**\n * Max length for asset tags accepted by the API.\n */\nconst ASSET_TAG_MAX_LENGTH = 20\n\n/**\n * Validates an asset's metadata, throwing an error if any of the metadata are\n * invalid.\n *\n * @param assetMetadata - The asset metadata to validate.\n *\n * @internal\n */\nexport const validateAssetMetadata = ({\n\tnotes,\n\tcredits,\n\talt,\n\ttags,\n}: CreateAssetParams): void => {\n\tconst errors: string[] = []\n\n\tif (notes && notes.length > ASSET_NOTES_MAX_LENGTH) {\n\t\terrors.push(\n\t\t\t`\\`notes\\` must be at most ${ASSET_NOTES_MAX_LENGTH} characters`,\n\t\t)\n\t}\n\n\tif (credits && credits.length > ASSET_CREDITS_MAX_LENGTH) {\n\t\terrors.push(\n\t\t\t`\\`credits\\` must be at most ${ASSET_CREDITS_MAX_LENGTH} characters`,\n\t\t)\n\t}\n\n\tif (alt && alt.length > ASSET_ALT_MAX_LENGTH) {\n\t\terrors.push(`\\`alt\\` must be at most ${ASSET_ALT_MAX_LENGTH} characters`)\n\t}\n\n\tif (\n\t\ttags &&\n\t\ttags.length &&\n\t\ttags.some(\n\t\t\t(tag) =>\n\t\t\t\ttag.length < ASSET_TAG_MIN_LENGTH || tag.length > ASSET_TAG_MAX_LENGTH,\n\t\t)\n\t) {\n\t\terrors.push(\n\t\t\t`tags must be at least 3 characters long and 20 characters at most`,\n\t\t)\n\t}\n\n\tif (errors.length) {\n\t\tthrow new PrismicError(\n\t\t\t`Errors validating asset metadata: ${errors.join(\", \")}`,\n\t\t\tundefined,\n\t\t\t{ notes, credits, alt, tags },\n\t\t)\n\t}\n}\n"],"mappings":";;;;;AAOA,MAAM,yBAAyB;;;;AAK/B,MAAM,2BAA2B;;;;AAKjC,MAAM,uBAAuB;;;;AAK7B,MAAM,uBAAuB;;;;AAK7B,MAAM,uBAAuB;;;;;;;;;AAU7B,MAAa,yBAAyB,EACrC,OACA,SACA,KACA,WAC8B;CAC9B,MAAM,SAAmB,EAAE;AAE3B,KAAI,SAAS,MAAM,SAAS,uBAC3B,QAAO,KACN,6BAA6B,uBAAuB,aACpD;AAGF,KAAI,WAAW,QAAQ,SAAS,yBAC/B,QAAO,KACN,+BAA+B,yBAAyB,aACxD;AAGF,KAAI,OAAO,IAAI,SAAS,qBACvB,QAAO,KAAK,2BAA2B,qBAAqB,aAAa;AAG1E,KACC,QACA,KAAK,UACL,KAAK,MACH,QACA,IAAI,SAAS,wBAAwB,IAAI,SAAS,qBACnD,CAED,QAAO,KACN,oEACA;AAGF,KAAI,OAAO,OACV,OAAM,IAAI,aACT,qCAAqC,OAAO,KAAK,KAAK,IACtD,KAAA,GACA;EAAE;EAAO;EAAS;EAAK;EAAM,CAC7B"}
|
package/dist/package.cjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
1
|
//#region package.json
|
|
3
2
|
var name = "@prismicio/client";
|
|
4
|
-
var version = "7.21.
|
|
5
|
-
|
|
3
|
+
var version = "7.21.6-canary.529a352";
|
|
6
4
|
//#endregion
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Object.defineProperty(exports, "name", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return name;
|
|
9
|
+
}
|
|
12
10
|
});
|
|
13
|
-
Object.defineProperty(exports,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
Object.defineProperty(exports, "version", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return version;
|
|
15
|
+
}
|
|
18
16
|
});
|
|
17
|
+
|
|
19
18
|
//# sourceMappingURL=package.cjs.map
|
package/dist/package.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/package.js
CHANGED
package/dist/package.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/richtext/asText.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/richtext/asText.ts
|
|
3
2
|
/**
|
|
4
3
|
* Converts a rich text field to a plain text string.
|
|
@@ -15,7 +14,7 @@ const asText = (richTextField, separator = " ") => {
|
|
|
15
14
|
for (let i = 0; i < richTextField.length; i++) if ("text" in richTextField[i]) result += (result ? separator : "") + richTextField[i].text;
|
|
16
15
|
return result;
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
//#endregion
|
|
20
18
|
exports.asText = asText;
|
|
19
|
+
|
|
21
20
|
//# sourceMappingURL=asText.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asText.cjs","names":[],"sources":["../../src/richtext/asText.ts"],"sourcesContent":["import type { RTTextNode, RichTextField } from \"../types/value/richText\"\n\n/**\n * Converts a rich text field to a plain text string.\n *\n * @param richTextField - A rich text field from Prismic.\n * @param separator - Separator used to join each element. Defaults to a space.\n *\n * @returns Plain text equivalent of the rich text field.\n *\n * @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const asText = (\n\trichTextField: RichTextField,\n\tseparator = \" \",\n): string => {\n\tlet result = \"\"\n\n\tfor (let i = 0; i < richTextField.length; i++) {\n\t\tif (\"text\" in richTextField[i]) {\n\t\t\tresult +=\n\t\t\t\t(result ? separator : \"\") + (richTextField[i] as RTTextNode).text\n\t\t}\n\t}\n\n\treturn result\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"asText.cjs","names":[],"sources":["../../src/richtext/asText.ts"],"sourcesContent":["import type { RTTextNode, RichTextField } from \"../types/value/richText\"\n\n/**\n * Converts a rich text field to a plain text string.\n *\n * @param richTextField - A rich text field from Prismic.\n * @param separator - Separator used to join each element. Defaults to a space.\n *\n * @returns Plain text equivalent of the rich text field.\n *\n * @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const asText = (\n\trichTextField: RichTextField,\n\tseparator = \" \",\n): string => {\n\tlet result = \"\"\n\n\tfor (let i = 0; i < richTextField.length; i++) {\n\t\tif (\"text\" in richTextField[i]) {\n\t\t\tresult +=\n\t\t\t\t(result ? separator : \"\") + (richTextField[i] as RTTextNode).text\n\t\t}\n\t}\n\n\treturn result\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,UACZ,eACA,YAAY,QACA;CACZ,IAAI,SAAS;AAEb,MAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,IACzC,KAAI,UAAU,cAAc,GAC3B,YACE,SAAS,YAAY,MAAO,cAAc,GAAkB;AAIhE,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asText.d.cts","names":[],"sources":["../../src/richtext/asText.ts"],"
|
|
1
|
+
{"version":3,"file":"asText.d.cts","names":[],"sources":["../../src/richtext/asText.ts"],"mappings":";;;;;AAYA;;;;;;;;cAAa,MAAA,GACZ,aAAA,EAAe,aAAA,EACf,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asText.d.ts","names":[],"sources":["../../src/richtext/asText.ts"],"
|
|
1
|
+
{"version":3,"file":"asText.d.ts","names":[],"sources":["../../src/richtext/asText.ts"],"mappings":";;;;;AAYA;;;;;;;;cAAa,MAAA,GACZ,aAAA,EAAe,aAAA,EACf,SAAA"}
|
package/dist/richtext/asText.js
CHANGED
|
@@ -14,7 +14,7 @@ const asText = (richTextField, separator = " ") => {
|
|
|
14
14
|
for (let i = 0; i < richTextField.length; i++) if ("text" in richTextField[i]) result += (result ? separator : "") + richTextField[i].text;
|
|
15
15
|
return result;
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
//#endregion
|
|
19
18
|
export { asText };
|
|
19
|
+
|
|
20
20
|
//# sourceMappingURL=asText.js.map
|