payload 4.0.0-beta.7 → 4.0.0-beta.8
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/admin/forms/Form.d.ts +5 -0
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/admin/functions/index.d.ts +2 -0
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/getRequestLocale.d.ts +3 -1
- package/dist/admin/getRequestLocale.d.ts.map +1 -1
- package/dist/admin/getRequestLocale.js +12 -1
- package/dist/admin/getRequestLocale.js.map +1 -1
- package/dist/admin/initAdminContext.d.ts.map +1 -1
- package/dist/admin/initAdminContext.js +2 -1
- package/dist/admin/initAdminContext.js.map +1 -1
- package/dist/auth/extractJWT.d.ts +7 -0
- package/dist/auth/extractJWT.d.ts.map +1 -1
- package/dist/auth/extractJWT.js +5 -8
- package/dist/auth/extractJWT.js.map +1 -1
- package/dist/auth/redeemRefreshToken.d.ts +8 -1
- package/dist/auth/redeemRefreshToken.d.ts.map +1 -1
- package/dist/auth/redeemRefreshToken.js +1 -5
- package/dist/auth/redeemRefreshToken.js.map +1 -1
- package/dist/cli/commands/collections/deleteDocuments.d.ts.map +1 -1
- package/dist/cli/commands/collections/deleteDocuments.js +3 -1
- package/dist/cli/commands/collections/deleteDocuments.js.map +1 -1
- package/dist/collections/operations/inputSchemas.d.ts +6 -0
- package/dist/collections/operations/inputSchemas.d.ts.map +1 -1
- package/dist/collections/operations/inputSchemas.js +1 -0
- package/dist/collections/operations/inputSchemas.js.map +1 -1
- package/dist/collections/operations/renameFile.d.ts.map +1 -1
- package/dist/collections/operations/renameFile.js +34 -0
- package/dist/collections/operations/renameFile.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +40 -19
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/config/types.d.ts +5 -7
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/exports/build-config.d.ts.map +1 -1
- package/dist/exports/build-config.js +0 -2
- package/dist/exports/build-config.js.map +1 -1
- package/dist/exports/internal.d.ts +1 -0
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +1 -0
- package/dist/exports/internal.js.map +1 -1
- package/dist/exports/shared.d.ts +6 -3
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +6 -3
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/config/reservedFieldNames.d.ts.map +1 -1
- package/dist/fields/config/reservedFieldNames.js +2 -1
- package/dist/fields/config/reservedFieldNames.js.map +1 -1
- package/dist/fields/config/types.d.ts +8 -1
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/getFallbackValue.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/getFallbackValue.js +3 -2
- package/dist/fields/hooks/beforeValidate/getFallbackValue.js.map +1 -1
- package/dist/fields/validateJSONSchema.js +1 -1
- package/dist/fields/validateJSONSchema.js.map +1 -1
- package/dist/hierarchy/getInitialTreeData.js +1 -1
- package/dist/hierarchy/getInitialTreeData.js.map +1 -1
- package/dist/index.bundled.d.ts +155 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/uploads/copyTempFileForDocument.d.ts +9 -0
- package/dist/uploads/copyTempFileForDocument.d.ts.map +1 -0
- package/dist/uploads/copyTempFileForDocument.js +15 -0
- package/dist/uploads/copyTempFileForDocument.js.map +1 -0
- package/dist/uploads/createSharedClientUploadDownload.d.ts +12 -0
- package/dist/uploads/createSharedClientUploadDownload.d.ts.map +1 -0
- package/dist/uploads/createSharedClientUploadDownload.js +36 -0
- package/dist/uploads/createSharedClientUploadDownload.js.map +1 -0
- package/dist/uploads/fileVersioning/storedFiles.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/storedFiles.js +9 -1
- package/dist/uploads/fileVersioning/storedFiles.js.map +1 -1
- package/dist/uploads/formatFileMeta.d.ts +12 -0
- package/dist/uploads/formatFileMeta.d.ts.map +1 -0
- package/dist/uploads/formatFileMeta.js +14 -0
- package/dist/uploads/formatFileMeta.js.map +1 -0
- package/dist/uploads/generateFileData.d.ts +8 -1
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +469 -97
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getBaseFields.d.ts.map +1 -1
- package/dist/uploads/getBaseFields.js +44 -2
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/getFileContentRequirement.d.ts +9 -8
- package/dist/uploads/getFileContentRequirement.d.ts.map +1 -1
- package/dist/uploads/getFileContentRequirement.js +10 -6
- package/dist/uploads/getFileContentRequirement.js.map +1 -1
- package/dist/uploads/getFileFromUploadInstructions.d.ts +10 -0
- package/dist/uploads/getFileFromUploadInstructions.d.ts.map +1 -1
- package/dist/uploads/getFileFromUploadInstructions.js +59 -36
- package/dist/uploads/getFileFromUploadInstructions.js.map +1 -1
- package/dist/uploads/getSafeFilename.d.ts +4 -0
- package/dist/uploads/getSafeFilename.d.ts.map +1 -1
- package/dist/uploads/getSafeFilename.js +17 -3
- package/dist/uploads/getSafeFilename.js.map +1 -1
- package/dist/uploads/isOriginalFileRequest.d.ts +3 -1
- package/dist/uploads/isOriginalFileRequest.d.ts.map +1 -1
- package/dist/uploads/isOriginalFileRequest.js +6 -4
- package/dist/uploads/isOriginalFileRequest.js.map +1 -1
- package/dist/uploads/isRequestTimeFile.d.ts +13 -0
- package/dist/uploads/isRequestTimeFile.d.ts.map +1 -0
- package/dist/uploads/isRequestTimeFile.js +9 -0
- package/dist/uploads/isRequestTimeFile.js.map +1 -0
- package/dist/uploads/registerUploadVariants.d.ts +20 -0
- package/dist/uploads/registerUploadVariants.d.ts.map +1 -0
- package/dist/uploads/registerUploadVariants.js +93 -0
- package/dist/uploads/registerUploadVariants.js.map +1 -0
- package/dist/uploads/sanitizeUploadData.d.ts.map +1 -1
- package/dist/uploads/sanitizeUploadData.js +3 -0
- package/dist/uploads/sanitizeUploadData.js.map +1 -1
- package/dist/uploads/transformState/cropUnits.d.ts +21 -0
- package/dist/uploads/transformState/cropUnits.d.ts.map +1 -0
- package/dist/uploads/transformState/cropUnits.js +23 -0
- package/dist/uploads/transformState/cropUnits.js.map +1 -0
- package/dist/uploads/transformState/getChangedTransformKeys.d.ts +6 -0
- package/dist/uploads/transformState/getChangedTransformKeys.d.ts.map +1 -0
- package/dist/uploads/transformState/getChangedTransformKeys.js +12 -0
- package/dist/uploads/transformState/getChangedTransformKeys.js.map +1 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.d.ts +15 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.d.ts.map +1 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.js +28 -0
- package/dist/uploads/transformState/getTransformKeyCoverageErrors.js.map +1 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.d.ts +24 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.d.ts.map +1 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.js +32 -0
- package/dist/uploads/transformState/planPersistedDefaultStages.js.map +1 -0
- package/dist/uploads/transformState/planUpload.d.ts +95 -0
- package/dist/uploads/transformState/planUpload.d.ts.map +1 -0
- package/dist/uploads/transformState/planUpload.js +198 -0
- package/dist/uploads/transformState/planUpload.js.map +1 -0
- package/dist/uploads/transformState/resolveUploadEdits.d.ts +91 -0
- package/dist/uploads/transformState/resolveUploadEdits.d.ts.map +1 -0
- package/dist/uploads/transformState/resolveUploadEdits.js +397 -0
- package/dist/uploads/transformState/resolveUploadEdits.js.map +1 -0
- package/dist/uploads/transformState/transformKeyClaims.d.ts +14 -0
- package/dist/uploads/transformState/transformKeyClaims.d.ts.map +1 -0
- package/dist/uploads/transformState/transformKeyClaims.js +15 -0
- package/dist/uploads/transformState/transformKeyClaims.js.map +1 -0
- package/dist/uploads/transformState/transformStateSchema.d.ts +8 -0
- package/dist/uploads/transformState/transformStateSchema.d.ts.map +1 -0
- package/dist/uploads/transformState/transformStateSchema.js +155 -0
- package/dist/uploads/transformState/transformStateSchema.js.map +1 -0
- package/dist/uploads/transformState/validateTransformState.d.ts +15 -0
- package/dist/uploads/transformState/validateTransformState.d.ts.map +1 -0
- package/dist/uploads/transformState/validateTransformState.js +34 -0
- package/dist/uploads/transformState/validateTransformState.js.map +1 -0
- package/dist/uploads/transformers/createFileSource.d.ts +9 -0
- package/dist/uploads/transformers/createFileSource.d.ts.map +1 -0
- package/dist/uploads/transformers/createFileSource.js +58 -0
- package/dist/uploads/transformers/createFileSource.js.map +1 -0
- package/dist/uploads/transformers/createLazySourceGetter.d.ts +3 -1
- package/dist/uploads/transformers/createLazySourceGetter.d.ts.map +1 -1
- package/dist/uploads/transformers/createLazySourceGetter.js +2 -2
- package/dist/uploads/transformers/createLazySourceGetter.js.map +1 -1
- package/dist/uploads/transformers/getSourceFileResponse.d.ts +3 -1
- package/dist/uploads/transformers/getSourceFileResponse.d.ts.map +1 -1
- package/dist/uploads/transformers/getSourceFileResponse.js +2 -1
- package/dist/uploads/transformers/getSourceFileResponse.js.map +1 -1
- package/dist/uploads/transformers/handleDynamicFileRequest.d.ts +3 -2
- package/dist/uploads/transformers/handleDynamicFileRequest.d.ts.map +1 -1
- package/dist/uploads/transformers/handleDynamicFileRequest.js +146 -38
- package/dist/uploads/transformers/handleDynamicFileRequest.js.map +1 -1
- package/dist/uploads/transformers/planTransformerPipeline.d.ts +11 -1
- package/dist/uploads/transformers/planTransformerPipeline.d.ts.map +1 -1
- package/dist/uploads/transformers/planTransformerPipeline.js +28 -6
- package/dist/uploads/transformers/planTransformerPipeline.js.map +1 -1
- package/dist/uploads/transformers/resolveUploadDocument.d.ts +10 -3
- package/dist/uploads/transformers/resolveUploadDocument.d.ts.map +1 -1
- package/dist/uploads/transformers/resolveUploadDocument.js +18 -7
- package/dist/uploads/transformers/resolveUploadDocument.js.map +1 -1
- package/dist/uploads/transformers/transformUploadFile.d.ts +18 -7
- package/dist/uploads/transformers/transformUploadFile.d.ts.map +1 -1
- package/dist/uploads/transformers/transformUploadFile.js +96 -12
- package/dist/uploads/transformers/transformUploadFile.js.map +1 -1
- package/dist/uploads/transformers/types.d.ts +89 -3
- package/dist/uploads/transformers/types.d.ts.map +1 -1
- package/dist/uploads/transformers/types.js.map +1 -1
- package/dist/uploads/types.d.ts +7 -1
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +14 -3
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/createPayloadRequestFromWebRequest.d.ts +12 -1
- package/dist/utilities/createPayloadRequestFromWebRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequestFromWebRequest.js +9 -3
- package/dist/utilities/createPayloadRequestFromWebRequest.js.map +1 -1
- package/dist/utilities/deepFreeze.d.ts +6 -0
- package/dist/utilities/deepFreeze.d.ts.map +1 -0
- package/dist/utilities/deepFreeze.js +14 -0
- package/dist/utilities/deepFreeze.js.map +1 -0
- package/dist/utilities/getDataByPath.d.ts.map +1 -1
- package/dist/utilities/getDataByPath.js +6 -9
- package/dist/utilities/getDataByPath.js.map +1 -1
- package/dist/utilities/getDataFromFormState.d.ts +10 -0
- package/dist/utilities/getDataFromFormState.d.ts.map +1 -0
- package/dist/utilities/getDataFromFormState.js +40 -0
- package/dist/utilities/getDataFromFormState.js.map +1 -0
- package/dist/utilities/getDateOnlyComparison.d.ts +27 -0
- package/dist/utilities/getDateOnlyComparison.d.ts.map +1 -0
- package/dist/utilities/getDateOnlyComparison.js +162 -0
- package/dist/utilities/getDateOnlyComparison.js.map +1 -0
- package/dist/utilities/getSiblingDataFromFormState.d.ts +8 -0
- package/dist/utilities/getSiblingDataFromFormState.d.ts.map +1 -0
- package/dist/utilities/{getSiblingData.js → getSiblingDataFromFormState.js} +11 -8
- package/dist/utilities/getSiblingDataFromFormState.js.map +1 -0
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +10 -2
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/utilities/telemetry/featureInfo/getFeatureInfo.d.ts.map +1 -1
- package/dist/utilities/telemetry/featureInfo/getFeatureInfo.js +41 -7
- package/dist/utilities/telemetry/featureInfo/getFeatureInfo.js.map +1 -1
- package/dist/utilities/telemetry/featureInfo/types.d.ts +4 -1
- package/dist/utilities/telemetry/featureInfo/types.d.ts.map +1 -1
- package/dist/utilities/telemetry/featureInfo/types.js.map +1 -1
- package/dist/utilities/telemetry/index.d.ts +3 -5
- package/dist/utilities/telemetry/index.d.ts.map +1 -1
- package/dist/utilities/telemetry/index.js +14 -3
- package/dist/utilities/telemetry/index.js.map +1 -1
- package/dist/utilities/telemetry/widgetType.d.ts +6 -0
- package/dist/utilities/telemetry/widgetType.d.ts.map +1 -0
- package/dist/utilities/telemetry/widgetType.js +33 -0
- package/dist/utilities/telemetry/widgetType.js.map +1 -0
- package/dist/utilities/transformPointDataToPayload.d.ts.map +1 -1
- package/dist/utilities/transformPointDataToPayload.js +15 -1
- package/dist/utilities/transformPointDataToPayload.js.map +1 -1
- package/dist/utilities/unflatten.d.ts +17 -0
- package/dist/utilities/unflatten.d.ts.map +1 -1
- package/dist/utilities/unflatten.js +10 -4
- package/dist/utilities/unflatten.js.map +1 -1
- package/package.json +2 -2
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts +0 -3
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts.map +0 -1
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js +0 -20
- package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js.map +0 -1
- package/dist/utilities/getSiblingData.d.ts +0 -3
- package/dist/utilities/getSiblingData.d.ts.map +0 -1
- package/dist/utilities/getSiblingData.js.map +0 -1
- package/dist/utilities/reduceFieldsToValues.d.ts +0 -10
- package/dist/utilities/reduceFieldsToValues.d.ts.map +0 -1
- package/dist/utilities/reduceFieldsToValues.js +0 -24
- package/dist/utilities/reduceFieldsToValues.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/uploads/transformState/transformStateSchema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nconst nonNegativeInteger: JSONSchema4 = { type: 'integer', minimum: 0 }\nconst positiveInteger: JSONSchema4 = { type: 'integer', minimum: 1 }\nconst percentage: JSONSchema4 = { type: 'number', maximum: 100, minimum: 0 }\n\nconst strictObject = (\n schema: Pick<JSONSchema4, 'description' | 'properties' | 'required'>,\n): JSONSchema4 => ({ type: 'object', additionalProperties: false, ...schema })\n\n/**\n * Shapes for the built-in `_transforms` keys. Any other key is allowed and owned by the\n * transformer that reads it.\n */\nexport const transformStateObjectSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: true,\n properties: {\n clip: strictObject({\n description: 'Time range on the original, in milliseconds. Start inclusive, end exclusive.',\n properties: { endMs: positiveInteger, startMs: nonNegativeInteger },\n required: ['startMs', 'endMs'],\n }),\n crop: strictObject({\n description: 'Rectangle in original-file pixels, applied before resize and encoding.',\n properties: {\n height: positiveInteger,\n width: positiveInteger,\n x: nonNegativeInteger,\n y: nonNegativeInteger,\n },\n required: ['x', 'y', 'width', 'height'],\n }),\n encoding: {\n type: 'object',\n description: 'Encoding settings for the output format. Does not select the format.',\n },\n flip: strictObject({\n description: 'Mirror the image on one or both axes.',\n properties: { horizontal: { type: 'boolean' }, vertical: { type: 'boolean' } },\n }),\n focalPoint: strictObject({\n description: 'Preferred point as percentages of the original, from 0 to 100.',\n properties: { x: percentage, y: percentage },\n required: ['x', 'y'],\n }),\n metadataPolicy: strictObject({\n description: 'Keep or remove metadata embedded in the output file.',\n properties: { mode: { type: 'string', enum: ['preserve', 'strip'] } },\n required: ['mode'],\n }),\n pageRange: strictObject({\n description: 'One-based, inclusive page range on the original document.',\n properties: { endPage: positiveInteger, startPage: positiveInteger },\n required: ['startPage', 'endPage'],\n }),\n posterFrame: strictObject({\n description: 'Video frame to use as the poster, in milliseconds on the original.',\n properties: { timestampMs: nonNegativeInteger },\n required: ['timestampMs'],\n }),\n resize: strictObject({\n description: 'Target size for visual media.',\n properties: {\n fit: { type: 'string', enum: ['contain', 'cover', 'fill', 'inside', 'outside'] },\n height: positiveInteger,\n width: positiveInteger,\n withoutEnlargement: { type: 'boolean' },\n },\n }),\n rotate: strictObject({\n description: 'Clockwise rotation in degrees.',\n properties: { angle: { type: 'number' } },\n required: ['angle'],\n }),\n },\n}\n\nexport const transformStateSchema: JSONSchema4 = {\n anyOf: [transformStateObjectSchema, { type: 'null' }],\n}\n"],"names":["nonNegativeInteger","type","minimum","positiveInteger","percentage","maximum","strictObject","schema","additionalProperties","transformStateObjectSchema","properties","clip","description","endMs","startMs","required","crop","height","width","x","y","encoding","flip","horizontal","vertical","focalPoint","metadataPolicy","mode","enum","pageRange","endPage","startPage","posterFrame","timestampMs","resize","fit","withoutEnlargement","rotate","angle","transformStateSchema","anyOf"],"mappings":"AAEA,MAAMA,qBAAkC;IAAEC,MAAM;IAAWC,SAAS;AAAE;AACtE,MAAMC,kBAA+B;IAAEF,MAAM;IAAWC,SAAS;AAAE;AACnE,MAAME,aAA0B;IAAEH,MAAM;IAAUI,SAAS;IAAKH,SAAS;AAAE;AAE3E,MAAMI,eAAe,CACnBC,SACiB,CAAA;QAAEN,MAAM;QAAUO,sBAAsB;QAAO,GAAGD,MAAM;IAAC,CAAA;AAE5E;;;CAGC,GACD,OAAO,MAAME,6BAA0C;IACrDR,MAAM;IACNO,sBAAsB;IACtBE,YAAY;QACVC,MAAML,aAAa;YACjBM,aAAa;YACbF,YAAY;gBAAEG,OAAOV;gBAAiBW,SAASd;YAAmB;YAClEe,UAAU;gBAAC;gBAAW;aAAQ;QAChC;QACAC,MAAMV,aAAa;YACjBM,aAAa;YACbF,YAAY;gBACVO,QAAQd;gBACRe,OAAOf;gBACPgB,GAAGnB;gBACHoB,GAAGpB;YACL;YACAe,UAAU;gBAAC;gBAAK;gBAAK;gBAAS;aAAS;QACzC;QACAM,UAAU;YACRpB,MAAM;YACNW,aAAa;QACf;QACAU,MAAMhB,aAAa;YACjBM,aAAa;YACbF,YAAY;gBAAEa,YAAY;oBAAEtB,MAAM;gBAAU;gBAAGuB,UAAU;oBAAEvB,MAAM;gBAAU;YAAE;QAC/E;QACAwB,YAAYnB,aAAa;YACvBM,aAAa;YACbF,YAAY;gBAAES,GAAGf;gBAAYgB,GAAGhB;YAAW;YAC3CW,UAAU;gBAAC;gBAAK;aAAI;QACtB;QACAW,gBAAgBpB,aAAa;YAC3BM,aAAa;YACbF,YAAY;gBAAEiB,MAAM;oBAAE1B,MAAM;oBAAU2B,MAAM;wBAAC;wBAAY;qBAAQ;gBAAC;YAAE;YACpEb,UAAU;gBAAC;aAAO;QACpB;QACAc,WAAWvB,aAAa;YACtBM,aAAa;YACbF,YAAY;gBAAEoB,SAAS3B;gBAAiB4B,WAAW5B;YAAgB;YACnEY,UAAU;gBAAC;gBAAa;aAAU;QACpC;QACAiB,aAAa1B,aAAa;YACxBM,aAAa;YACbF,YAAY;gBAAEuB,aAAajC;YAAmB;YAC9Ce,UAAU;gBAAC;aAAc;QAC3B;QACAmB,QAAQ5B,aAAa;YACnBM,aAAa;YACbF,YAAY;gBACVyB,KAAK;oBAAElC,MAAM;oBAAU2B,MAAM;wBAAC;wBAAW;wBAAS;wBAAQ;wBAAU;qBAAU;gBAAC;gBAC/EX,QAAQd;gBACRe,OAAOf;gBACPiC,oBAAoB;oBAAEnC,MAAM;gBAAU;YACxC;QACF;QACAoC,QAAQ/B,aAAa;YACnBM,aAAa;YACbF,YAAY;gBAAE4B,OAAO;oBAAErC,MAAM;gBAAS;YAAE;YACxCc,UAAU;gBAAC;aAAQ;QACrB;IACF;AACF,EAAC;AAED,OAAO,MAAMwB,uBAAoC;IAC/CC,OAAO;QAAC/B;QAA4B;YAAER,MAAM;QAAO;KAAE;AACvD,EAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Validate } from '../../fields/config/types.js';
|
|
2
|
+
type Dimensions = {
|
|
3
|
+
height?: null | number;
|
|
4
|
+
width?: null | number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Checks `_transforms` against its schema, then checks the crop against the original's size.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTransformStateError({ original, value, }: {
|
|
10
|
+
original?: Dimensions | null;
|
|
11
|
+
value: unknown;
|
|
12
|
+
}): Promise<string | undefined>;
|
|
13
|
+
export declare const validateTransformState: Validate;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=validateTransformState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTransformState.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformState/validateTransformState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAK5D,KAAK,UAAU,GAAG;IAAE,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAA;AAEnE;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC5B,KAAK,EAAE,OAAO,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B9B;AAED,eAAO,MAAM,sBAAsB,EAAE,QAIxB,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { validateJSONSchema } from '#validateJSONSchema';
|
|
2
|
+
import { transformStateObjectSchema } from './transformStateSchema.js';
|
|
3
|
+
/**
|
|
4
|
+
* Checks `_transforms` against its schema, then checks the crop against the original's size.
|
|
5
|
+
*/ export async function getTransformStateError({ original, value }) {
|
|
6
|
+
if (value === null || value === undefined) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
// `null` returned above, so check the object schema directly: its errors name the failing key.
|
|
10
|
+
const schemaResult = await validateJSONSchema({
|
|
11
|
+
jsonSchema: {
|
|
12
|
+
fileMatch: [
|
|
13
|
+
'payload://upload-transforms'
|
|
14
|
+
],
|
|
15
|
+
schema: transformStateObjectSchema,
|
|
16
|
+
uri: 'payload://upload-transforms'
|
|
17
|
+
},
|
|
18
|
+
value
|
|
19
|
+
});
|
|
20
|
+
if (schemaResult !== true) {
|
|
21
|
+
return schemaResult;
|
|
22
|
+
}
|
|
23
|
+
const crop = value.crop;
|
|
24
|
+
if (crop && original?.width && original?.height && (crop.x + crop.width > original.width || crop.y + crop.height > original.height)) {
|
|
25
|
+
return `crop: must fit inside the original (${original.width} x ${original.height})`;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
export const validateTransformState = async (value, { data })=>await getTransformStateError({
|
|
30
|
+
original: data?.original,
|
|
31
|
+
value
|
|
32
|
+
}) ?? true;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=validateTransformState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/uploads/transformState/validateTransformState.ts"],"sourcesContent":["import { validateJSONSchema } from '#validateJSONSchema'\n\nimport type { Validate } from '../../fields/config/types.js'\nimport type { PixelCrop } from './cropUnits.js'\n\nimport { transformStateObjectSchema } from './transformStateSchema.js'\n\ntype Dimensions = { height?: null | number; width?: null | number }\n\n/**\n * Checks `_transforms` against its schema, then checks the crop against the original's size.\n */\nexport async function getTransformStateError({\n original,\n value,\n}: {\n original?: Dimensions | null\n value: unknown\n}): Promise<string | undefined> {\n if (value === null || value === undefined) {\n return undefined\n }\n\n // `null` returned above, so check the object schema directly: its errors name the failing key.\n const schemaResult = await validateJSONSchema({\n jsonSchema: {\n fileMatch: ['payload://upload-transforms'],\n schema: transformStateObjectSchema,\n uri: 'payload://upload-transforms',\n },\n value,\n })\n\n if (schemaResult !== true) {\n return schemaResult\n }\n\n const crop = (value as { crop?: PixelCrop }).crop\n\n if (\n crop &&\n original?.width &&\n original?.height &&\n (crop.x + crop.width > original.width || crop.y + crop.height > original.height)\n ) {\n return `crop: must fit inside the original (${original.width} x ${original.height})`\n }\n\n return undefined\n}\n\nexport const validateTransformState: Validate = async (value, { data }) =>\n (await getTransformStateError({\n original: (data as { original?: Dimensions })?.original,\n value,\n })) ?? true\n"],"names":["validateJSONSchema","transformStateObjectSchema","getTransformStateError","original","value","undefined","schemaResult","jsonSchema","fileMatch","schema","uri","crop","width","height","x","y","validateTransformState","data"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,sBAAqB;AAKxD,SAASC,0BAA0B,QAAQ,4BAA2B;AAItE;;CAEC,GACD,OAAO,eAAeC,uBAAuB,EAC3CC,QAAQ,EACRC,KAAK,EAIN;IACC,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAOA;IACT;IAEA,+FAA+F;IAC/F,MAAMC,eAAe,MAAMN,mBAAmB;QAC5CO,YAAY;YACVC,WAAW;gBAAC;aAA8B;YAC1CC,QAAQR;YACRS,KAAK;QACP;QACAN;IACF;IAEA,IAAIE,iBAAiB,MAAM;QACzB,OAAOA;IACT;IAEA,MAAMK,OAAO,AAACP,MAA+BO,IAAI;IAEjD,IACEA,QACAR,UAAUS,SACVT,UAAUU,UACTF,CAAAA,KAAKG,CAAC,GAAGH,KAAKC,KAAK,GAAGT,SAASS,KAAK,IAAID,KAAKI,CAAC,GAAGJ,KAAKE,MAAM,GAAGV,SAASU,MAAM,AAAD,GAC9E;QACA,OAAO,CAAC,oCAAoC,EAAEV,SAASS,KAAK,CAAC,GAAG,EAAET,SAASU,MAAM,CAAC,CAAC,CAAC;IACtF;IAEA,OAAOR;AACT;AAEA,OAAO,MAAMW,yBAAmC,OAAOZ,OAAO,EAAEa,IAAI,EAAE,GACpE,AAAC,MAAMf,uBAAuB;QAC5BC,UAAWc,MAAoCd;QAC/CC;IACF,MAAO,KAAI"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FileSource } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a lazy `FileSource` from a web `File`, either in memory or backed by a temp file
|
|
4
|
+
* through `openAsBlob`. No bytes are read until a method is called.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createFileSource({ file }: {
|
|
7
|
+
file: File;
|
|
8
|
+
}): FileSource;
|
|
9
|
+
//# sourceMappingURL=createFileSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileSource.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/createFileSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI5C;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG,UAAU,CA0BrE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TransformerContractError } from '../../errors/TransformerContractError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a lazy `FileSource` from a web `File`, either in memory or backed by a temp file
|
|
4
|
+
* through `openAsBlob`. No bytes are read until a method is called.
|
|
5
|
+
*/ export function createFileSource({ file }) {
|
|
6
|
+
return {
|
|
7
|
+
filename: file.name,
|
|
8
|
+
mimeType: file.type,
|
|
9
|
+
readFileBytes: async ({ numberOfBytes, signal, startByte })=>{
|
|
10
|
+
const range = resolveByteRange({
|
|
11
|
+
numberOfBytes,
|
|
12
|
+
sizeInBytes: file.size,
|
|
13
|
+
startByte
|
|
14
|
+
});
|
|
15
|
+
signal?.throwIfAborted();
|
|
16
|
+
const bytes = await file.slice(range.startByte, range.endByte).arrayBuffer();
|
|
17
|
+
signal?.throwIfAborted();
|
|
18
|
+
return new Uint8Array(bytes);
|
|
19
|
+
},
|
|
20
|
+
sizeInBytes: file.size,
|
|
21
|
+
// Async so that a bad range rejects, like the other read, instead of throwing.
|
|
22
|
+
// oxlint-disable-next-line typescript/require-await
|
|
23
|
+
streamFile: async ({ numberOfBytes, signal, startByte = 0 } = {})=>{
|
|
24
|
+
const range = resolveByteRange({
|
|
25
|
+
numberOfBytes,
|
|
26
|
+
sizeInBytes: file.size,
|
|
27
|
+
startByte
|
|
28
|
+
});
|
|
29
|
+
signal?.throwIfAborted();
|
|
30
|
+
const stream = file.slice(range.startByte, range.endByte).stream();
|
|
31
|
+
// Piping with a signal errors the stream and cancels the file read when it aborts.
|
|
32
|
+
return signal ? stream.pipeThrough(new TransformStream(), {
|
|
33
|
+
signal
|
|
34
|
+
}) : stream;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks a requested range against the file size. An omitted `numberOfBytes` means "to the end",
|
|
40
|
+
* and a range that runs past the end stops there, so a fixed-size header read works on any file.
|
|
41
|
+
*/ function resolveByteRange({ numberOfBytes, sizeInBytes, startByte }) {
|
|
42
|
+
if (!Number.isSafeInteger(startByte) || startByte < 0) {
|
|
43
|
+
throw new TransformerContractError('startByte must be a non-negative integer.');
|
|
44
|
+
}
|
|
45
|
+
if (numberOfBytes !== undefined && (!Number.isSafeInteger(numberOfBytes) || numberOfBytes < 1)) {
|
|
46
|
+
throw new TransformerContractError('numberOfBytes must be a positive integer.');
|
|
47
|
+
}
|
|
48
|
+
if (startByte > sizeInBytes) {
|
|
49
|
+
throw new TransformerContractError(`startByte ${startByte} is past the end of the file (${sizeInBytes} bytes).`);
|
|
50
|
+
}
|
|
51
|
+
const endByte = numberOfBytes === undefined ? sizeInBytes : Math.min(startByte + numberOfBytes, sizeInBytes);
|
|
52
|
+
return {
|
|
53
|
+
endByte,
|
|
54
|
+
startByte
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=createFileSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/uploads/transformers/createFileSource.ts"],"sourcesContent":["import type { FileSource } from './types.js'\n\nimport { TransformerContractError } from '../../errors/TransformerContractError.js'\n\n/**\n * Creates a lazy `FileSource` from a web `File`, either in memory or backed by a temp file\n * through `openAsBlob`. No bytes are read until a method is called.\n */\nexport function createFileSource({ file }: { file: File }): FileSource {\n return {\n filename: file.name,\n mimeType: file.type,\n readFileBytes: async ({ numberOfBytes, signal, startByte }) => {\n const range = resolveByteRange({ numberOfBytes, sizeInBytes: file.size, startByte })\n signal?.throwIfAborted()\n\n const bytes = await file.slice(range.startByte, range.endByte).arrayBuffer()\n signal?.throwIfAborted()\n\n return new Uint8Array(bytes)\n },\n sizeInBytes: file.size,\n // Async so that a bad range rejects, like the other read, instead of throwing.\n // oxlint-disable-next-line typescript/require-await\n streamFile: async ({ numberOfBytes, signal, startByte = 0 } = {}) => {\n const range = resolveByteRange({ numberOfBytes, sizeInBytes: file.size, startByte })\n signal?.throwIfAborted()\n\n const stream = file.slice(range.startByte, range.endByte).stream()\n\n // Piping with a signal errors the stream and cancels the file read when it aborts.\n return signal ? stream.pipeThrough(new TransformStream(), { signal }) : stream\n },\n }\n}\n\n/**\n * Checks a requested range against the file size. An omitted `numberOfBytes` means \"to the end\",\n * and a range that runs past the end stops there, so a fixed-size header read works on any file.\n */\nfunction resolveByteRange({\n numberOfBytes,\n sizeInBytes,\n startByte,\n}: {\n numberOfBytes?: number\n sizeInBytes: number\n startByte: number\n}): { endByte: number; startByte: number } {\n if (!Number.isSafeInteger(startByte) || startByte < 0) {\n throw new TransformerContractError('startByte must be a non-negative integer.')\n }\n\n if (numberOfBytes !== undefined && (!Number.isSafeInteger(numberOfBytes) || numberOfBytes < 1)) {\n throw new TransformerContractError('numberOfBytes must be a positive integer.')\n }\n\n if (startByte > sizeInBytes) {\n throw new TransformerContractError(\n `startByte ${startByte} is past the end of the file (${sizeInBytes} bytes).`,\n )\n }\n\n const endByte =\n numberOfBytes === undefined ? sizeInBytes : Math.min(startByte + numberOfBytes, sizeInBytes)\n\n return { endByte, startByte }\n}\n"],"names":["TransformerContractError","createFileSource","file","filename","name","mimeType","type","readFileBytes","numberOfBytes","signal","startByte","range","resolveByteRange","sizeInBytes","size","throwIfAborted","bytes","slice","endByte","arrayBuffer","Uint8Array","streamFile","stream","pipeThrough","TransformStream","Number","isSafeInteger","undefined","Math","min"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,2CAA0C;AAEnF;;;CAGC,GACD,OAAO,SAASC,iBAAiB,EAAEC,IAAI,EAAkB;IACvD,OAAO;QACLC,UAAUD,KAAKE,IAAI;QACnBC,UAAUH,KAAKI,IAAI;QACnBC,eAAe,OAAO,EAAEC,aAAa,EAAEC,MAAM,EAAEC,SAAS,EAAE;YACxD,MAAMC,QAAQC,iBAAiB;gBAAEJ;gBAAeK,aAAaX,KAAKY,IAAI;gBAAEJ;YAAU;YAClFD,QAAQM;YAER,MAAMC,QAAQ,MAAMd,KAAKe,KAAK,CAACN,MAAMD,SAAS,EAAEC,MAAMO,OAAO,EAAEC,WAAW;YAC1EV,QAAQM;YAER,OAAO,IAAIK,WAAWJ;QACxB;QACAH,aAAaX,KAAKY,IAAI;QACtB,+EAA+E;QAC/E,oDAAoD;QACpDO,YAAY,OAAO,EAAEb,aAAa,EAAEC,MAAM,EAAEC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC;YAC9D,MAAMC,QAAQC,iBAAiB;gBAAEJ;gBAAeK,aAAaX,KAAKY,IAAI;gBAAEJ;YAAU;YAClFD,QAAQM;YAER,MAAMO,SAASpB,KAAKe,KAAK,CAACN,MAAMD,SAAS,EAAEC,MAAMO,OAAO,EAAEI,MAAM;YAEhE,mFAAmF;YACnF,OAAOb,SAASa,OAAOC,WAAW,CAAC,IAAIC,mBAAmB;gBAAEf;YAAO,KAAKa;QAC1E;IACF;AACF;AAEA;;;CAGC,GACD,SAASV,iBAAiB,EACxBJ,aAAa,EACbK,WAAW,EACXH,SAAS,EAKV;IACC,IAAI,CAACe,OAAOC,aAAa,CAAChB,cAAcA,YAAY,GAAG;QACrD,MAAM,IAAIV,yBAAyB;IACrC;IAEA,IAAIQ,kBAAkBmB,aAAc,CAAA,CAACF,OAAOC,aAAa,CAAClB,kBAAkBA,gBAAgB,CAAA,GAAI;QAC9F,MAAM,IAAIR,yBAAyB;IACrC;IAEA,IAAIU,YAAYG,aAAa;QAC3B,MAAM,IAAIb,yBACR,CAAC,UAAU,EAAEU,UAAU,8BAA8B,EAAEG,YAAY,QAAQ,CAAC;IAEhF;IAEA,MAAMK,UACJV,kBAAkBmB,YAAYd,cAAce,KAAKC,GAAG,CAACnB,YAAYF,eAAeK;IAElF,OAAO;QAAEK;QAASR;IAAU;AAC9B"}
|
|
@@ -9,7 +9,9 @@ export type LazySourceGetter = {
|
|
|
9
9
|
* or after it has rejected. Deliberately doesn't memoize a reusable `Response`,
|
|
10
10
|
* since the underlying body is normally a single-use stream.
|
|
11
11
|
*/
|
|
12
|
-
export declare function createLazySourceGetter({ retrieve, }: {
|
|
12
|
+
export declare function createLazySourceGetter({ getterName, retrieve, }: {
|
|
13
|
+
/** The getter's name in the error for a second call. */
|
|
14
|
+
getterName?: 'getOriginalFile' | 'getSourceFile';
|
|
13
15
|
retrieve: () => Promise<Response>;
|
|
14
16
|
}): LazySourceGetter;
|
|
15
17
|
//# sourceMappingURL=createLazySourceGetter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLazySourceGetter.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/createLazySourceGetter.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5B,SAAS,EAAE,MAAM,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClC,GAAG,gBAAgB,CAiBnB"}
|
|
1
|
+
{"version":3,"file":"createLazySourceGetter.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/createLazySourceGetter.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5B,SAAS,EAAE,MAAM,OAAO,CAAA;CACzB,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,UAA4B,EAC5B,QAAQ,GACT,EAAE;IACD,wDAAwD;IACxD,UAAU,CAAC,EAAE,iBAAiB,GAAG,eAAe,CAAA;IAChD,QAAQ,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClC,GAAG,gBAAgB,CAiBnB"}
|
|
@@ -5,12 +5,12 @@ import { TransformerContractError } from '../../errors/TransformerContractError.
|
|
|
5
5
|
* `TransformerContractError` — including while the first call is still pending,
|
|
6
6
|
* or after it has rejected. Deliberately doesn't memoize a reusable `Response`,
|
|
7
7
|
* since the underlying body is normally a single-use stream.
|
|
8
|
-
*/ export function createLazySourceGetter({ retrieve }) {
|
|
8
|
+
*/ export function createLazySourceGetter({ getterName = 'getSourceFile', retrieve }) {
|
|
9
9
|
let wasCalled = false;
|
|
10
10
|
return {
|
|
11
11
|
get: async ()=>{
|
|
12
12
|
if (wasCalled) {
|
|
13
|
-
throw new TransformerContractError(
|
|
13
|
+
throw new TransformerContractError(`A transformer stage attempted to call ${getterName} more than once.`);
|
|
14
14
|
}
|
|
15
15
|
wasCalled = true;
|
|
16
16
|
return retrieve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/uploads/transformers/createLazySourceGetter.ts"],"sourcesContent":["import { TransformerContractError } from '../../errors/TransformerContractError.js'\n\nexport type LazySourceGetter = {\n get: () => Promise<Response>\n wasCalled: () => boolean\n}\n\n/**\n * Wraps a source-retrieval function so it runs at most once: the first `get()`\n * call performs the retrieval, and every later call rejects with a\n * `TransformerContractError` — including while the first call is still pending,\n * or after it has rejected. Deliberately doesn't memoize a reusable `Response`,\n * since the underlying body is normally a single-use stream.\n */\nexport function createLazySourceGetter({\n retrieve,\n}: {\n retrieve: () => Promise<Response>\n}): LazySourceGetter {\n let wasCalled = false\n\n return {\n get: async () => {\n if (wasCalled) {\n throw new TransformerContractError(\n
|
|
1
|
+
{"version":3,"sources":["../../../src/uploads/transformers/createLazySourceGetter.ts"],"sourcesContent":["import { TransformerContractError } from '../../errors/TransformerContractError.js'\n\nexport type LazySourceGetter = {\n get: () => Promise<Response>\n wasCalled: () => boolean\n}\n\n/**\n * Wraps a source-retrieval function so it runs at most once: the first `get()`\n * call performs the retrieval, and every later call rejects with a\n * `TransformerContractError` — including while the first call is still pending,\n * or after it has rejected. Deliberately doesn't memoize a reusable `Response`,\n * since the underlying body is normally a single-use stream.\n */\nexport function createLazySourceGetter({\n getterName = 'getSourceFile',\n retrieve,\n}: {\n /** The getter's name in the error for a second call. */\n getterName?: 'getOriginalFile' | 'getSourceFile'\n retrieve: () => Promise<Response>\n}): LazySourceGetter {\n let wasCalled = false\n\n return {\n get: async () => {\n if (wasCalled) {\n throw new TransformerContractError(\n `A transformer stage attempted to call ${getterName} more than once.`,\n )\n }\n\n wasCalled = true\n\n return retrieve()\n },\n wasCalled: () => wasCalled,\n }\n}\n"],"names":["TransformerContractError","createLazySourceGetter","getterName","retrieve","wasCalled","get"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,2CAA0C;AAOnF;;;;;;CAMC,GACD,OAAO,SAASC,uBAAuB,EACrCC,aAAa,eAAe,EAC5BC,QAAQ,EAKT;IACC,IAAIC,YAAY;IAEhB,OAAO;QACLC,KAAK;YACH,IAAID,WAAW;gBACb,MAAM,IAAIJ,yBACR,CAAC,sCAAsC,EAAEE,WAAW,gBAAgB,CAAC;YAEzE;YAEAE,YAAY;YAEZ,OAAOD;QACT;QACAC,WAAW,IAAMA;IACnB;AACF"}
|
|
@@ -6,10 +6,12 @@ import type { ResolvedUploadDocument } from './resolveUploadDocument.js';
|
|
|
6
6
|
* `getSourceFile` getter. A thin wrapper over the same handler-loop/local-fs
|
|
7
7
|
* logic the ordinary `read` endpoint uses, called with `operation: 'transform'`.
|
|
8
8
|
*/
|
|
9
|
-
export declare function getSourceFileResponse({ collection, document, filename, prefix, req, }: {
|
|
9
|
+
export declare function getSourceFileResponse({ collection, document, filename, isOriginal, prefix, req, }: {
|
|
10
10
|
collection: Collection;
|
|
11
11
|
document: ResolvedUploadDocument;
|
|
12
12
|
filename: string;
|
|
13
|
+
/** Asks for the original when it shares a name with the main file. */
|
|
14
|
+
isOriginal?: boolean;
|
|
13
15
|
prefix?: string;
|
|
14
16
|
req: PayloadRequest;
|
|
15
17
|
}): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceFileResponse.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/getSourceFileResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAIxE;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,sBAAsB,CAAA;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"getSourceFileResponse.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/getSourceFileResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAIxE;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,sBAAsB,CAAA;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,sEAAsE;IACtE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAUpB"}
|
|
@@ -3,11 +3,12 @@ import { retrieveFileResponse } from '../endpoints/getFile.js';
|
|
|
3
3
|
* Payload's internal source-retrieval used by a request transformer's lazy
|
|
4
4
|
* `getSourceFile` getter. A thin wrapper over the same handler-loop/local-fs
|
|
5
5
|
* logic the ordinary `read` endpoint uses, called with `operation: 'transform'`.
|
|
6
|
-
*/ export async function getSourceFileResponse({ collection, document, filename, prefix, req }) {
|
|
6
|
+
*/ export async function getSourceFileResponse({ collection, document, filename, isOriginal, prefix, req }) {
|
|
7
7
|
return retrieveFileResponse({
|
|
8
8
|
collection,
|
|
9
9
|
doc: document,
|
|
10
10
|
filename,
|
|
11
|
+
isOriginal,
|
|
11
12
|
operation: 'transform',
|
|
12
13
|
prefix,
|
|
13
14
|
req
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/uploads/transformers/getSourceFileResponse.ts"],"sourcesContent":["import type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { ResolvedUploadDocument } from './resolveUploadDocument.js'\n\nimport { retrieveFileResponse } from '../endpoints/getFile.js'\n\n/**\n * Payload's internal source-retrieval used by a request transformer's lazy\n * `getSourceFile` getter. A thin wrapper over the same handler-loop/local-fs\n * logic the ordinary `read` endpoint uses, called with `operation: 'transform'`.\n */\nexport async function getSourceFileResponse({\n collection,\n document,\n filename,\n prefix,\n req,\n}: {\n collection: Collection\n document: ResolvedUploadDocument\n filename: string\n prefix?: string\n req: PayloadRequest\n}): Promise<Response> {\n return retrieveFileResponse({\n collection,\n doc: document,\n filename,\n operation: 'transform',\n prefix,\n req,\n })\n}\n"],"names":["retrieveFileResponse","getSourceFileResponse","collection","document","filename","prefix","req","doc","operation"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,0BAAyB;AAE9D;;;;CAIC,GACD,OAAO,eAAeC,sBAAsB,EAC1CC,UAAU,EACVC,QAAQ,EACRC,QAAQ,EACRC,MAAM,EACNC,GAAG,
|
|
1
|
+
{"version":3,"sources":["../../../src/uploads/transformers/getSourceFileResponse.ts"],"sourcesContent":["import type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { ResolvedUploadDocument } from './resolveUploadDocument.js'\n\nimport { retrieveFileResponse } from '../endpoints/getFile.js'\n\n/**\n * Payload's internal source-retrieval used by a request transformer's lazy\n * `getSourceFile` getter. A thin wrapper over the same handler-loop/local-fs\n * logic the ordinary `read` endpoint uses, called with `operation: 'transform'`.\n */\nexport async function getSourceFileResponse({\n collection,\n document,\n filename,\n isOriginal,\n prefix,\n req,\n}: {\n collection: Collection\n document: ResolvedUploadDocument\n filename: string\n /** Asks for the original when it shares a name with the main file. */\n isOriginal?: boolean\n prefix?: string\n req: PayloadRequest\n}): Promise<Response> {\n return retrieveFileResponse({\n collection,\n doc: document,\n filename,\n isOriginal,\n operation: 'transform',\n prefix,\n req,\n })\n}\n"],"names":["retrieveFileResponse","getSourceFileResponse","collection","document","filename","isOriginal","prefix","req","doc","operation"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,0BAAyB;AAE9D;;;;CAIC,GACD,OAAO,eAAeC,sBAAsB,EAC1CC,UAAU,EACVC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,MAAM,EACNC,GAAG,EASJ;IACC,OAAOP,qBAAqB;QAC1BE;QACAM,KAAKL;QACLC;QACAC;QACAI,WAAW;QACXH;QACAC;IACF;AACF"}
|
|
@@ -4,8 +4,9 @@ import type { PayloadRequest } from '../../types/index.js';
|
|
|
4
4
|
* Orchestrates a dynamic file request end to end: resolve the document, plan the
|
|
5
5
|
* request-capable transformer pipeline from the requested file's authoritative
|
|
6
6
|
* MIME type (the primary file or the matched image size), enforce
|
|
7
|
-
* transform-aware read access, then run every eligible transformer
|
|
8
|
-
*
|
|
7
|
+
* transform-aware read access, then run every eligible transformer against a lazily-fetched
|
|
8
|
+
* source: first the stages that apply the saved `_transforms` (only when no default file is
|
|
9
|
+
* stored), then the stages that apply the request, each phase in declaration order. Called from `getFileHandler` only when at
|
|
9
10
|
* least one transformer is configured — the zero-transformer path never reaches
|
|
10
11
|
* this function.
|
|
11
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleDynamicFileRequest.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/handleDynamicFileRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"handleDynamicFileRequest.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformers/handleDynamicFileRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAyB1D;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,UAAU,EACV,QAAQ,EACR,UAAU,EAAE,eAAe,EAC3B,MAAM,EACN,GAAG,GACJ,EAAE;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqKpB"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { APIError } from '../../errors/APIError.js';
|
|
1
2
|
import { Forbidden } from '../../errors/Forbidden.js';
|
|
2
3
|
import { NotFound } from '../../errors/NotFound.js';
|
|
3
4
|
import { TransformerContractError } from '../../errors/TransformerContractError.js';
|
|
5
|
+
import { deepCopyObject } from '../../utilities/deepCopyObject.js';
|
|
6
|
+
import { deepFreeze } from '../../utilities/deepFreeze.js';
|
|
7
|
+
import { httpStatus } from '../../utilities/httpStatus.js';
|
|
4
8
|
import { checkFileAccess } from '../checkFileAccess.js';
|
|
5
9
|
import { retrieveFileResponse } from '../endpoints/getFile.js';
|
|
6
10
|
import { isOriginalFileRequest } from '../isOriginalFileRequest.js';
|
|
11
|
+
import { isRequestTimeFile } from '../isRequestTimeFile.js';
|
|
12
|
+
import { planPersistedDefaultStages } from '../transformState/planPersistedDefaultStages.js';
|
|
7
13
|
import { createLazySourceGetter } from './createLazySourceGetter.js';
|
|
8
14
|
import { finalizeFileResponse } from './finalizeFileResponse.js';
|
|
9
15
|
import { getSourceFileResponse } from './getSourceFileResponse.js';
|
|
@@ -14,8 +20,9 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
14
20
|
* Orchestrates a dynamic file request end to end: resolve the document, plan the
|
|
15
21
|
* request-capable transformer pipeline from the requested file's authoritative
|
|
16
22
|
* MIME type (the primary file or the matched image size), enforce
|
|
17
|
-
* transform-aware read access, then run every eligible transformer
|
|
18
|
-
*
|
|
23
|
+
* transform-aware read access, then run every eligible transformer against a lazily-fetched
|
|
24
|
+
* source: first the stages that apply the saved `_transforms` (only when no default file is
|
|
25
|
+
* stored), then the stages that apply the request, each phase in declaration order. Called from `getFileHandler` only when at
|
|
19
26
|
* least one transformer is configured — the zero-transformer path never reaches
|
|
20
27
|
* this function.
|
|
21
28
|
*/ export async function handleDynamicFileRequest({ collection, filename, isOriginal: isOriginalParam, prefix, req }) {
|
|
@@ -51,9 +58,13 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
51
58
|
filename,
|
|
52
59
|
isOriginal: isOriginalParam
|
|
53
60
|
});
|
|
54
|
-
// Without transform params, a stored file is served as it is, with no transformer.
|
|
61
|
+
// Without transform params, a stored file is served as it is, with no transformer. A default
|
|
62
|
+
// file built at request time shares the original's name, but is not the original.
|
|
55
63
|
const hasNoTransformParams = req.searchParams?.size === 0;
|
|
56
|
-
|
|
64
|
+
const isStoredOriginalName = resolvedDocument.original?.filename === filename && !isRequestTimeFile({
|
|
65
|
+
entry: resolvedDocument
|
|
66
|
+
});
|
|
67
|
+
if (isOriginalRequest || isStoredOriginalName && hasNoTransformParams) {
|
|
57
68
|
const permittedDocument = await withFileTransformAccessContext({
|
|
58
69
|
callback: ()=>checkFileAccess({
|
|
59
70
|
collection,
|
|
@@ -73,7 +84,7 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
73
84
|
req
|
|
74
85
|
});
|
|
75
86
|
}
|
|
76
|
-
const { document, pipeline } = await authorizeDocument({
|
|
87
|
+
const { document, documentSnapshot, pipeline } = await authorizeDocument({
|
|
77
88
|
collection,
|
|
78
89
|
filename,
|
|
79
90
|
prefix,
|
|
@@ -84,11 +95,22 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
84
95
|
document,
|
|
85
96
|
filename
|
|
86
97
|
});
|
|
98
|
+
// A file built at request time has no object, so its stages start from the original.
|
|
99
|
+
const { isBuiltAtRequest } = requestedFile;
|
|
100
|
+
// The original can share the main file's name, so it is asked for by role, not by name.
|
|
101
|
+
const originalFile = {
|
|
102
|
+
filename: document.original?.filename ?? document.filename,
|
|
103
|
+
isOriginal: Boolean(document.original?.filename)
|
|
104
|
+
};
|
|
105
|
+
const storedFile = isBuiltAtRequest ? originalFile : {
|
|
106
|
+
filename,
|
|
107
|
+
isOriginal: false
|
|
108
|
+
};
|
|
87
109
|
const source = createLazySourceGetter({
|
|
88
110
|
retrieve: ()=>getSourceFileResponse({
|
|
111
|
+
...storedFile,
|
|
89
112
|
collection,
|
|
90
113
|
document,
|
|
91
|
-
filename,
|
|
92
114
|
prefix,
|
|
93
115
|
req
|
|
94
116
|
})
|
|
@@ -102,39 +124,64 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
102
124
|
handedOutBodyControllers.get(response)?.abort();
|
|
103
125
|
handedOutBodyControllers.delete(response);
|
|
104
126
|
};
|
|
127
|
+
// A file with no stored object has nothing to serve. Its source is the original, which must not
|
|
128
|
+
// be served in its place, and a request stage must not start from the original either.
|
|
129
|
+
const assertDefaultFileBuilt = ()=>{
|
|
130
|
+
if (isBuiltAtRequest && !currentResponse) {
|
|
131
|
+
throw new TransformerContractError(`No transformer built "${requestedFile.filename}", which has no stored file. A stage that applies its saved transforms must return a response.`);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
105
134
|
try {
|
|
106
|
-
for (const transformer of pipeline){
|
|
135
|
+
for (const { options, purpose, transformer } of pipeline){
|
|
136
|
+
if (purpose === 'request-override') {
|
|
137
|
+
assertDefaultFileBuilt();
|
|
138
|
+
}
|
|
107
139
|
const previousResponse = currentResponse;
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
140
|
+
const handedOutResponses = [];
|
|
141
|
+
const stageSource = createHandedOutGetter({
|
|
142
|
+
getterName: 'getSourceFile',
|
|
143
|
+
handedOutBodyControllers,
|
|
144
|
+
handedOutResponses,
|
|
145
|
+
retrieve: async ()=>currentResponse ?? await source.get()
|
|
146
|
+
});
|
|
147
|
+
const stageOriginal = createHandedOutGetter({
|
|
148
|
+
getterName: 'getOriginalFile',
|
|
149
|
+
handedOutBodyControllers,
|
|
150
|
+
handedOutResponses,
|
|
151
|
+
retrieve: ()=>getSourceFileResponse({
|
|
152
|
+
...originalFile,
|
|
153
|
+
collection,
|
|
154
|
+
document,
|
|
155
|
+
prefix,
|
|
156
|
+
req
|
|
157
|
+
})
|
|
119
158
|
});
|
|
120
159
|
const result = await transformer.handleRequest({
|
|
121
160
|
collectionSlug: collection.config.slug,
|
|
161
|
+
doc: documentSnapshot,
|
|
122
162
|
documentID: document.id,
|
|
123
163
|
filename: requestedFile.filename,
|
|
164
|
+
getOriginalFile: stageOriginal.get,
|
|
124
165
|
getSourceFile: stageSource.get,
|
|
125
166
|
mimeType: requestedFile.mimeType,
|
|
126
|
-
|
|
167
|
+
options,
|
|
168
|
+
originalDoc: documentSnapshot,
|
|
169
|
+
req,
|
|
170
|
+
variantName: requestedFile.variantName
|
|
127
171
|
});
|
|
128
172
|
if (result.response) {
|
|
129
|
-
if (
|
|
130
|
-
await discardResponse(handedOutResponse);
|
|
131
|
-
} else if (!handedOutResponse && previousResponse && result.response !== previousResponse) {
|
|
173
|
+
if (!stageSource.wasCalled() && previousResponse && result.response !== previousResponse) {
|
|
132
174
|
await discardResponse(previousResponse);
|
|
133
175
|
}
|
|
134
176
|
currentResponse = result.response;
|
|
135
177
|
} else if (stageSource.wasCalled()) {
|
|
136
178
|
throw new TransformerContractError('A transformer that consumes its source must return a response.');
|
|
137
179
|
}
|
|
180
|
+
for (const handedOutResponse of handedOutResponses){
|
|
181
|
+
if (handedOutResponse !== result.response) {
|
|
182
|
+
await discardResponse(handedOutResponse);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
138
185
|
if (result.status === 'complete') {
|
|
139
186
|
return finalizeFileResponse({
|
|
140
187
|
collection,
|
|
@@ -143,6 +190,7 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
143
190
|
});
|
|
144
191
|
}
|
|
145
192
|
}
|
|
193
|
+
assertDefaultFileBuilt();
|
|
146
194
|
} catch (err) {
|
|
147
195
|
req.payload.logger.error({
|
|
148
196
|
err,
|
|
@@ -161,16 +209,34 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
161
209
|
response: currentResponse
|
|
162
210
|
});
|
|
163
211
|
}
|
|
164
|
-
// No transformer produced a response — serve the
|
|
165
|
-
//
|
|
212
|
+
// No transformer produced a response — serve the stored file through the normal path
|
|
213
|
+
// (Range/ETag/redirect support, existing `modifyResponseHeaders` order).
|
|
166
214
|
return retrieveFileResponse({
|
|
215
|
+
...storedFile,
|
|
167
216
|
collection,
|
|
168
217
|
doc: document,
|
|
169
|
-
filename,
|
|
170
218
|
prefix,
|
|
171
219
|
req
|
|
172
220
|
});
|
|
173
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* A single-use getter for one stage. Each response it hands out gets its own abort controller, so
|
|
224
|
+
* the pipeline can close the body later even when the stage locked it with a reader.
|
|
225
|
+
*/ function createHandedOutGetter({ getterName, handedOutBodyControllers, handedOutResponses, retrieve }) {
|
|
226
|
+
return createLazySourceGetter({
|
|
227
|
+
getterName,
|
|
228
|
+
retrieve: async ()=>{
|
|
229
|
+
const handedOutBodyController = new AbortController();
|
|
230
|
+
const handedOutResponse = withAbortableBody({
|
|
231
|
+
response: await retrieve(),
|
|
232
|
+
signal: handedOutBodyController.signal
|
|
233
|
+
});
|
|
234
|
+
handedOutBodyControllers.set(handedOutResponse, handedOutBodyController);
|
|
235
|
+
handedOutResponses.push(handedOutResponse);
|
|
236
|
+
return handedOutResponse;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
174
240
|
/**
|
|
175
241
|
* Re-wraps `response` so its body can be cancelled through `signal`, closing the underlying
|
|
176
242
|
* source stream (file handle, storage connection) regardless of who holds a reader on it.
|
|
@@ -208,21 +274,58 @@ import { withFileTransformAccessContext } from './withFileTransformAccessContext
|
|
|
208
274
|
// A clean-up failure must not replace the pipeline result or error.
|
|
209
275
|
}
|
|
210
276
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Plans the saved-state phase, when the requested file is not stored, then the request phase. Fails
|
|
279
|
+
* before any file is read when a saved key that must run has no saved-state stage, or two.
|
|
280
|
+
*/ async function planRequestPipeline({ collection, document, documentSnapshot, filename, req }) {
|
|
281
|
+
const requestedFile = getRequestedFile({
|
|
282
|
+
document,
|
|
283
|
+
filename
|
|
284
|
+
});
|
|
285
|
+
const purposes = requestedFile.isBuiltAtRequest ? [
|
|
286
|
+
'persisted-default',
|
|
287
|
+
'request-override'
|
|
288
|
+
] : [
|
|
289
|
+
'request-override'
|
|
290
|
+
];
|
|
291
|
+
const pipeline = [];
|
|
292
|
+
for (const purpose of purposes){
|
|
293
|
+
const planArgs = {
|
|
214
294
|
collectionSlug: collection.config.slug,
|
|
295
|
+
doc: documentSnapshot,
|
|
215
296
|
documentID: document.id,
|
|
216
|
-
mimeType:
|
|
217
|
-
document,
|
|
218
|
-
filename
|
|
219
|
-
}).mimeType,
|
|
220
|
-
operation: 'request',
|
|
297
|
+
mimeType: requestedFile.mimeType,
|
|
221
298
|
req
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
299
|
+
};
|
|
300
|
+
let plan;
|
|
301
|
+
if (purpose === 'persisted-default') {
|
|
302
|
+
const { coverageErrors, plan: persistedDefaultPlan } = await planPersistedDefaultStages({
|
|
303
|
+
...planArgs,
|
|
304
|
+
transforms: document._transforms
|
|
305
|
+
});
|
|
306
|
+
if (coverageErrors.length > 0) {
|
|
307
|
+
throw new APIError(`Cannot apply the saved transforms. ${coverageErrors.map(({ message, path })=>`${path}: ${message}`).join(' ')}`, httpStatus.INTERNAL_SERVER_ERROR);
|
|
308
|
+
}
|
|
309
|
+
plan = persistedDefaultPlan;
|
|
310
|
+
} else {
|
|
311
|
+
plan = await planTransformerPipeline({
|
|
312
|
+
args: {
|
|
313
|
+
...planArgs,
|
|
314
|
+
operation: 'request',
|
|
315
|
+
originalDoc: documentSnapshot,
|
|
316
|
+
purpose
|
|
317
|
+
},
|
|
318
|
+
capability: 'handleRequest',
|
|
319
|
+
transformers: req.payload.config.upload.transformers
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
pipeline.push(...plan.pipeline.map((transformer)=>({
|
|
323
|
+
options: plan.options.get(transformer),
|
|
324
|
+
purpose,
|
|
325
|
+
transformer
|
|
326
|
+
})));
|
|
327
|
+
}
|
|
328
|
+
return pipeline;
|
|
226
329
|
}
|
|
227
330
|
/**
|
|
228
331
|
* Decides which document is served and which pipeline runs, checking read access
|
|
@@ -290,13 +393,17 @@ function planRequestPipeline({ collection, document, filename, req }) {
|
|
|
290
393
|
throw new Forbidden(req.t);
|
|
291
394
|
}
|
|
292
395
|
const document = access.document && access.document.id !== resolvedDocument.id ? access.document : resolvedDocument;
|
|
396
|
+
const documentSnapshot = deepFreeze(deepCopyObject(document));
|
|
293
397
|
const pipeline = await planRequestPipeline({
|
|
294
398
|
collection,
|
|
295
399
|
document,
|
|
400
|
+
documentSnapshot,
|
|
296
401
|
filename,
|
|
297
402
|
req
|
|
298
403
|
});
|
|
299
|
-
|
|
404
|
+
// Only the request's own parameters make it a transform. Applying the saved state is an ordinary
|
|
405
|
+
// read of the saved file.
|
|
406
|
+
const isTransform = pipeline.some(({ purpose })=>purpose === 'request-override');
|
|
300
407
|
if (isTransform !== isTransformAccess) {
|
|
301
408
|
const requiredAccess = await checkAccess({
|
|
302
409
|
isTransform
|
|
@@ -307,6 +414,7 @@ function planRequestPipeline({ collection, document, filename, req }) {
|
|
|
307
414
|
}
|
|
308
415
|
return {
|
|
309
416
|
document,
|
|
417
|
+
documentSnapshot,
|
|
310
418
|
pipeline
|
|
311
419
|
};
|
|
312
420
|
}
|