payload 3.0.0-beta.68 → 3.0.0-beta.69
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/auth/baseFields/email.js +1 -1
- package/dist/auth/baseFields/email.js.map +1 -1
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js +1 -0
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/dataloader.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +2 -0
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +4 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/migrations/getPredefinedMigration.d.ts.map +1 -1
- package/dist/database/migrations/getPredefinedMigration.js +5 -2
- package/dist/database/migrations/getPredefinedMigration.js.map +1 -1
- package/dist/exports/components/utilities.d.ts +2 -0
- package/dist/exports/components/utilities.d.ts.map +1 -0
- package/dist/exports/components/utilities.js +2 -0
- package/dist/exports/components/utilities.js.map +1 -0
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/types.d.ts +1 -0
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/uploads/cropImage.d.ts +4 -1
- package/dist/uploads/cropImage.d.ts.map +1 -1
- package/dist/uploads/cropImage.js +8 -2
- package/dist/uploads/cropImage.js.map +1 -1
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +12 -3
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/imageResizer.d.ts +3 -1
- package/dist/uploads/imageResizer.d.ts.map +1 -1
- package/dist/uploads/imageResizer.js +15 -4
- package/dist/uploads/imageResizer.js.map +1 -1
- package/dist/uploads/optionallyAppendMetadata.d.ts +12 -0
- package/dist/uploads/optionallyAppendMetadata.d.ts.map +1 -0
- package/dist/uploads/optionallyAppendMetadata.js +15 -0
- package/dist/uploads/optionallyAppendMetadata.js.map +1 -0
- package/dist/uploads/types.d.ts +12 -0
- 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 +105 -72
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/createLocalReq.d.ts.map +1 -1
- package/dist/utilities/createLocalReq.js +2 -1
- package/dist/utilities/createLocalReq.js.map +1 -1
- package/dist/versions/enforceMaxVersions.d.ts.map +1 -1
- package/dist/versions/enforceMaxVersions.js +2 -0
- package/dist/versions/enforceMaxVersions.js.map +1 -1
- package/dist/versions/saveVersion.d.ts.map +1 -1
- package/dist/versions/saveVersion.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { Auth } from '../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Generates the JSON Schema for database configuration\n *\n * @example { db: idType: string }\n */\nfunction generateDbEntitySchema(config: SanitizedConfig): JSONSchema4 {\n const defaultIDType: JSONSchema4 =\n config.db?.defaultIDType === 'number' ? { type: 'number' } : { type: 'string' }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n defaultIDType,\n },\n required: ['defaultIDType'],\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema })\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\nconst fieldType: JSONSchema4 = {\n type: 'string',\n required: false,\n}\nconst generateAuthFieldTypes = (\n loginWithUsername: Auth['loginWithUsername'],\n withPassword = false,\n): JSONSchema4 => {\n const passwordField = {\n password: fieldType,\n }\n\n if (loginWithUsername) {\n if (loginWithUsername.allowEmailLogin) {\n return {\n additionalProperties: false,\n oneOf: [\n {\n additionalProperties: false,\n properties: { email: fieldType, ...(withPassword ? { password: fieldType } : {}) },\n required: ['email', ...(withPassword ? ['password'] : [])],\n },\n {\n additionalProperties: false,\n properties: { username: fieldType, ...(withPassword ? { password: fieldType } : {}) },\n required: ['username', ...(withPassword ? ['password'] : [])],\n },\n ],\n }\n }\n\n return {\n additionalProperties: false,\n properties: {\n username: fieldType,\n ...(withPassword ? { password: fieldType } : {}),\n },\n required: ['username', ...(withPassword ? ['password'] : [])],\n }\n }\n\n return {\n additionalProperties: false,\n properties: {\n email: fieldType,\n ...(withPassword ? { password: fieldType } : {}),\n },\n required: ['email', ...(withPassword ? ['password'] : [])],\n }\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const loginWithUsername = config.auth?.loginWithUsername\n const generatedFields: JSONSchema4 = generateAuthFieldTypes(loginWithUsername)\n const generatedFieldsWithPassword: JSONSchema4 = generateAuthFieldTypes(loginWithUsername, true)\n\n const properties: JSONSchema4['properties'] = {\n forgotPassword: generatedFields,\n login: generatedFieldsWithPassword,\n registerFirstUser: generatedFieldsWithPassword,\n unlock: generatedFields,\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`,\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\n ...entityDefinitions,\n ...Object.fromEntries(interfaceNameDefinitions),\n ...authOperationDefinitions,\n },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n auth: generateAuthOperationSchemas(config.collections),\n collections: generateEntitySchemas(config.collections || []),\n db: generateDbEntitySchema(config),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth', 'db'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","length","Map","from","entityToJSONSchema","incomingEntity","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateAuthFieldTypes","loginWithUsername","withPassword","passwordField","password","allowEmailLogin","email","username","authCollectionToOperationsJSONSchema","generatedFields","generatedFieldsWithPassword","forgotPassword","login","registerFirstUser","unlock","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAQrB,SAASE,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,4BAA2B;AACxE,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,yBAAyB,QAAQ,iCAAgC;AAE1E,MAAMC,kBAAkB,CAACC;IACvB,MAAMC,gBAAgBC,QAAQF,OAAOG,SAASH,OAAOG,OAAOC;IAC5D,IAAIH,eAAe,OAAO;IAE1B,MAAMI,mBAAmB,cAAcL,SAASA,MAAMM,QAAQ,KAAK;IACnE,IAAIZ,iBAAiBM,UAAUK,kBAAkB,OAAO;IAExD,wDAAwD;IACxD,IAAI,YAAYL,SAASA,MAAMO,IAAI,KAAK,SAAS;QAC/C,OAAOP,MAAMQ,MAAM,CAACC,IAAI,CAAC,CAACC,WAAaX,gBAAgBW;IACzD;IAEA,oEAAoE;IACpE,IAAIV,MAAMO,IAAI,KAAK,QAAQ;QACzB,OAAOP,MAAMW,IAAI,CAACF,IAAI,CAAC,CAACG;YACtB,IAAI,UAAUA,KAAK;gBACjB,OAAOA,IAAIJ,MAAM,CAACC,IAAI,CAAC,CAACC,WAAaX,gBAAgBW;YACvD;YACA,OAAO;QACT;IACF;IAEA,OAAO;AACT;AAEA,SAASG,iBAAiBC,OAAiB;IACz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E,OAAOvG;IACT,GACA;QAAEe,MAAM,CAAC;IAAE;IAGf,IAAIyB,aAA0B;QAC5BrC,sBAAsB;QACtBqG,aAAa;YACX,GAAGJ,iBAAiB;YACpB,GAAGhG,OAAO6B,WAAW,CAACH,yBAAyB;YAC/C,GAAGwE,wBAAwB;QAC7B;QACA,wJAAwJ;QACxJrH,MAAM;QACNa,YAAY;YACViB,MAAMkF,6BAA6B7E,OAAO8E,WAAW;YACrDA,aAAatG,sBAAsBwB,OAAO8E,WAAW,IAAI,EAAE;YAC3D5E,IAAIH,uBAAuBC;YAC3BiF,SAASzG,sBAAsBwB,OAAOiF,OAAO,IAAI,EAAE;YACnD3F,QAAQJ,4BAA4Bc,OAAOb,YAAY;YACvDkG,MAAM5F,0BAA0BO,OAAO8E,WAAW;QACpD;QACAlH,UAAU;YAAC;YAAQ;YAAU;YAAe;YAAW;YAAQ;SAAK;QACpEyF,OAAO;IACT;IAEA,IAAIrD,QAAQsD,YAAYjC,QAAQ0B,QAAQ;QACtC,KAAK,MAAM1B,UAAUrB,OAAOsD,UAAU,CAACjC,MAAM,CAAE;YAC7CD,aAAaC,OAAO;gBAAED;YAAW;QACnC;IACF;IAEA,OAAOA;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/configToJSONSchema.ts"],"sourcesContent":["import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'\n\nimport pluralize from 'pluralize'\nconst { singular } = pluralize\n\nimport type { Auth } from '../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { Field, FieldAffectingData, Option } from '../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\n\nimport { MissingEditorProp } from '../errors/MissingEditorProp.js'\nimport { fieldAffectsData, tabHasName } from '../fields/config/types.js'\nimport { deepCopyObject } from './deepCopyObject.js'\nimport { toWords } from './formatLabels.js'\nimport { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'\n\nconst fieldIsRequired = (field: Field) => {\n const isConditional = Boolean(field?.admin && field?.admin?.condition)\n if (isConditional) return false\n\n const isMarkedRequired = 'required' in field && field.required === true\n if (fieldAffectsData(field) && isMarkedRequired) return true\n\n // if any subfields are required, this field is required\n if ('fields' in field && field.type !== 'array') {\n return field.fields.some((subField) => fieldIsRequired(subField))\n }\n\n // if any tab subfields have required fields, this field is required\n if (field.type === 'tabs') {\n return field.tabs.some((tab) => {\n if ('name' in tab) {\n return tab.fields.some((subField) => fieldIsRequired(subField))\n }\n return false\n })\n }\n\n return false\n}\n\nfunction buildOptionEnums(options: Option[]): string[] {\n return options.map((option) => {\n if (typeof option === 'object' && 'value' in option) {\n return option.value\n }\n\n return option\n })\n}\n\nfunction generateEntitySchemas(\n entities: (SanitizedCollectionConfig | SanitizedGlobalConfig)[],\n): JSONSchema4 {\n const properties = [...entities].reduce((acc, { slug }) => {\n acc[slug] = {\n $ref: `#/definitions/${slug}`,\n }\n\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\nfunction generateLocaleEntitySchemas(localization: SanitizedConfig['localization']): JSONSchema4 {\n if (localization && 'locales' in localization && localization?.locales) {\n const localesFromConfig = localization?.locales\n\n const locales = [...localesFromConfig].map((locale) => {\n return locale.code\n }, [])\n\n return {\n type: 'string',\n enum: locales,\n }\n }\n\n return {\n type: 'null',\n }\n}\n\nfunction generateAuthEntitySchemas(entities: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties: JSONSchema4[] = [...entities]\n .filter(({ auth }) => Boolean(auth))\n .map(({ slug }) => {\n return {\n allOf: [\n { $ref: `#/definitions/${slug}` },\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n collection: { type: 'string', enum: [slug] },\n },\n required: ['collection'],\n },\n ],\n }\n }, {})\n\n return {\n oneOf: properties,\n }\n}\n\n/**\n * Generates the JSON Schema for database configuration\n *\n * @example { db: idType: string }\n */\nfunction generateDbEntitySchema(config: SanitizedConfig): JSONSchema4 {\n const defaultIDType: JSONSchema4 =\n config.db?.defaultIDType === 'number' ? { type: 'number' } : { type: 'string' }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n defaultIDType,\n },\n required: ['defaultIDType'],\n }\n}\n\n/**\n * Returns a JSON Schema Type with 'null' added if the field is not required.\n */\nexport function withNullableJSONSchemaType(\n fieldType: JSONSchema4TypeName,\n isRequired: boolean,\n): JSONSchema4TypeName | JSONSchema4TypeName[] {\n const fieldTypes = [fieldType]\n if (isRequired) return fieldType\n fieldTypes.push('null')\n return fieldTypes\n}\n\nexport function fieldsToJSONSchema(\n /**\n * Used for relationship fields, to determine whether to use a string or number type for the ID.\n * While there is a default ID field type set by the db adapter, they can differ on a collection-level\n * if they have custom ID fields.\n */\n collectionIDFieldTypes: { [key: string]: 'number' | 'string' },\n fields: Field[],\n /**\n * Allows you to define new top-level interfaces that can be re-used in the output schema.\n */\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n config?: SanitizedConfig,\n): {\n properties: {\n [k: string]: JSONSchema4\n }\n required: string[]\n} {\n const requiredFieldNames = new Set<string>()\n\n return {\n properties: Object.fromEntries(\n fields.reduce((fieldSchemas, field) => {\n const isRequired = fieldAffectsData(field) && fieldIsRequired(field)\n if (isRequired) requiredFieldNames.add(field.name)\n\n let fieldSchema: JSONSchema4\n\n switch (field.type) {\n case 'text':\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'string' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n }\n break\n case 'textarea':\n case 'code':\n case 'email':\n case 'date': {\n fieldSchema = { type: withNullableJSONSchemaType('string', isRequired) }\n break\n }\n\n case 'number': {\n if (field.hasMany === true) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: { type: 'number' },\n }\n } else {\n fieldSchema = { type: withNullableJSONSchemaType('number', isRequired) }\n }\n break\n }\n\n case 'checkbox': {\n fieldSchema = { type: withNullableJSONSchemaType('boolean', isRequired) }\n break\n }\n\n case 'json': {\n fieldSchema = field.jsonSchema?.schema || {\n type: ['object', 'array', 'string', 'number', 'boolean', 'null'],\n }\n break\n }\n\n case 'richText': {\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n if (field.editor.outputSchema) {\n fieldSchema = field.editor.outputSchema({\n collectionIDFieldTypes,\n config,\n field,\n interfaceNameDefinitions,\n isRequired,\n })\n } else {\n // Maintain backwards compatibility with existing rich text editors\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n },\n }\n }\n\n break\n }\n\n case 'radio': {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: buildOptionEnums(field.options),\n }\n\n break\n }\n\n case 'select': {\n const optionEnums = buildOptionEnums(field.options)\n\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'string',\n enum: optionEnums,\n },\n }\n } else {\n fieldSchema = {\n type: withNullableJSONSchemaType('string', isRequired),\n enum: optionEnums,\n }\n }\n\n break\n }\n\n case 'point': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: [\n {\n type: 'number',\n },\n {\n type: 'number',\n },\n ],\n maxItems: 2,\n minItems: 2,\n }\n break\n }\n\n case 'relationship': {\n if (Array.isArray(field.relationTo)) {\n if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n },\n }\n } else {\n fieldSchema = {\n oneOf: field.relationTo.map((relation) => {\n return {\n type: withNullableJSONSchemaType('object', isRequired),\n additionalProperties: false,\n properties: {\n relationTo: {\n const: relation,\n },\n value: {\n oneOf: [\n {\n type: collectionIDFieldTypes[relation],\n },\n {\n $ref: `#/definitions/${relation}`,\n },\n ],\n },\n },\n required: ['value', 'relationTo'],\n }\n }),\n }\n }\n } else if (field.hasMany) {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n },\n }\n } else {\n fieldSchema = {\n oneOf: [\n {\n type: withNullableJSONSchemaType(\n collectionIDFieldTypes[field.relationTo],\n isRequired,\n ),\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n }\n\n break\n }\n\n case 'upload': {\n fieldSchema = {\n oneOf: [\n {\n type: collectionIDFieldTypes[field.relationTo],\n },\n {\n $ref: `#/definitions/${field.relationTo}`,\n },\n ],\n }\n if (!isRequired) fieldSchema.oneOf.push({ type: 'null' })\n break\n }\n\n case 'blocks': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n oneOf: field.blocks.map((block) => {\n const blockFieldSchemas = fieldsToJSONSchema(\n collectionIDFieldTypes,\n block.fields,\n interfaceNameDefinitions,\n config,\n )\n\n const blockSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...blockFieldSchemas.properties,\n blockType: {\n const: block.slug,\n },\n },\n required: ['blockType', ...blockFieldSchemas.required],\n }\n\n if (block.interfaceName) {\n interfaceNameDefinitions.set(block.interfaceName, blockSchema)\n\n return {\n $ref: `#/definitions/${block.interfaceName}`,\n }\n }\n\n return blockSchema\n }),\n },\n }\n break\n }\n\n case 'array': {\n fieldSchema = {\n type: withNullableJSONSchemaType('array', isRequired),\n items: {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n },\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n case 'row':\n case 'collapsible': {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n )\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n break\n }\n\n case 'tabs': {\n field.tabs.forEach((tab) => {\n const childSchema = fieldsToJSONSchema(\n collectionIDFieldTypes,\n tab.fields,\n interfaceNameDefinitions,\n config,\n )\n if (tabHasName(tab)) {\n // could have interface\n fieldSchemas.set(tab.name, {\n type: 'object',\n additionalProperties: false,\n ...childSchema,\n })\n\n // If the named tab has any required fields then we mark this as required otherwise it should be optional\n const hasRequiredFields = tab.fields.some((subField) => fieldIsRequired(subField))\n\n if (hasRequiredFields) {\n requiredFieldNames.add(tab.name)\n }\n } else {\n Object.entries(childSchema.properties).forEach(([propName, propSchema]) => {\n fieldSchemas.set(propName, propSchema)\n })\n childSchema.required.forEach((propName) => {\n requiredFieldNames.add(propName)\n })\n }\n })\n break\n }\n\n case 'group': {\n fieldSchema = {\n type: 'object',\n additionalProperties: false,\n ...fieldsToJSONSchema(\n collectionIDFieldTypes,\n field.fields,\n interfaceNameDefinitions,\n config,\n ),\n }\n\n if (field.interfaceName) {\n interfaceNameDefinitions.set(field.interfaceName, fieldSchema)\n\n fieldSchema = {\n $ref: `#/definitions/${field.interfaceName}`,\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if ('typescriptSchema' in field && field?.typescriptSchema?.length) {\n for (const schema of field.typescriptSchema) {\n fieldSchema = schema({ jsonSchema: fieldSchema })\n }\n }\n\n if (fieldSchema && fieldAffectsData(field)) {\n fieldSchemas.set(field.name, fieldSchema)\n }\n\n return fieldSchemas\n }, new Map<string, JSONSchema4>()),\n ),\n required: Array.from(requiredFieldNames),\n }\n}\n\n// This function is part of the public API and is exported through payload/utilities\nexport function entityToJSONSchema(\n config: SanitizedConfig,\n incomingEntity: SanitizedCollectionConfig | SanitizedGlobalConfig,\n interfaceNameDefinitions: Map<string, JSONSchema4>,\n defaultIDType: 'number' | 'text',\n): JSONSchema4 {\n const entity: SanitizedCollectionConfig | SanitizedGlobalConfig = deepCopyObject(incomingEntity)\n const title = entity.typescript?.interface\n ? entity.typescript.interface\n : singular(toWords(entity.slug, true))\n\n const idField: FieldAffectingData = { name: 'id', type: defaultIDType as 'text', required: true }\n const customIdField = entity.fields.find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n ) as FieldAffectingData\n\n if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {\n customIdField.required = true\n } else {\n entity.fields.unshift(idField)\n }\n\n // mark timestamp fields required\n if ('timestamps' in entity && entity.timestamps !== false) {\n entity.fields = entity.fields.map((field) => {\n if (fieldAffectsData(field) && (field.name === 'createdAt' || field.name === 'updatedAt')) {\n return {\n ...field,\n required: true,\n }\n }\n return field\n })\n }\n\n if ('auth' in entity && entity.auth && !entity.auth?.disableLocalStrategy) {\n entity.fields.push({\n name: 'password',\n type: 'text',\n })\n }\n\n // Used for relationship fields, to determine whether to use a string or number type for the ID.\n const collectionIDFieldTypes = getCollectionIDFieldTypes({ config, defaultIDType })\n\n return {\n type: 'object',\n additionalProperties: false,\n title,\n ...fieldsToJSONSchema(collectionIDFieldTypes, entity.fields, interfaceNameDefinitions, config),\n }\n}\n\nconst fieldType: JSONSchema4 = {\n type: 'string',\n required: false,\n}\nconst generateAuthFieldTypes = ({\n type,\n loginWithUsername,\n}: {\n loginWithUsername: Auth['loginWithUsername']\n type: 'forgotOrUnlock' | 'login' | 'register'\n}): JSONSchema4 => {\n const emailAuthFields = {\n additionalProperties: false,\n properties: { email: fieldType },\n required: ['email'],\n }\n const usernameAuthFields = {\n additionalProperties: false,\n properties: { username: fieldType },\n required: ['username'],\n }\n\n if (['login', 'register'].includes(type)) {\n emailAuthFields.properties['password'] = fieldType\n emailAuthFields.required.push('password')\n usernameAuthFields.properties['password'] = fieldType\n usernameAuthFields.required.push('password')\n }\n\n if (loginWithUsername) {\n switch (type) {\n case 'login': {\n if (loginWithUsername.allowEmailLogin) {\n // allow username or email and require password for login\n return {\n additionalProperties: false,\n oneOf: [emailAuthFields, usernameAuthFields],\n }\n } else {\n // allow only username and password for login\n return usernameAuthFields\n }\n }\n\n case 'register': {\n if (loginWithUsername.requireEmail) {\n // require username, email and password for registration\n return {\n additionalProperties: false,\n properties: {\n ...usernameAuthFields.properties,\n ...emailAuthFields.properties,\n },\n required: [...usernameAuthFields.required, ...emailAuthFields.required],\n }\n } else if (loginWithUsername.allowEmailLogin) {\n // allow both but only require username for registration\n return {\n additionalProperties: false,\n properties: {\n ...usernameAuthFields.properties,\n ...emailAuthFields.properties,\n },\n required: usernameAuthFields.required,\n }\n } else {\n // require only username and password for registration\n return usernameAuthFields\n }\n }\n\n case 'forgotOrUnlock': {\n if (loginWithUsername.allowEmailLogin) {\n // allow email or username for unlock/forgot-password\n return {\n additionalProperties: false,\n oneOf: [emailAuthFields, usernameAuthFields],\n }\n } else {\n // allow only username for unlock/forgot-password\n return usernameAuthFields\n }\n }\n }\n }\n\n // default email (and password for login/register)\n return emailAuthFields\n}\n\nexport function authCollectionToOperationsJSONSchema(\n config: SanitizedCollectionConfig,\n): JSONSchema4 {\n const loginWithUsername = config.auth?.loginWithUsername\n const loginUserFields: JSONSchema4 = generateAuthFieldTypes({ type: 'login', loginWithUsername })\n const forgotOrUnlockUserFields: JSONSchema4 = generateAuthFieldTypes({\n type: 'forgotOrUnlock',\n loginWithUsername,\n })\n const registerUserFields: JSONSchema4 = generateAuthFieldTypes({\n type: 'register',\n loginWithUsername,\n })\n\n const properties: JSONSchema4['properties'] = {\n forgotPassword: forgotOrUnlockUserFields,\n login: loginUserFields,\n registerFirstUser: registerUserFields,\n unlock: forgotOrUnlockUserFields,\n }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`,\n }\n}\n\nfunction generateAuthOperationSchemas(collections: SanitizedCollectionConfig[]): JSONSchema4 {\n const properties = collections.reduce((acc, collection) => {\n if (collection.auth) {\n acc[collection.slug] = {\n $ref: `#/definitions/auth/${collection.slug}`,\n }\n }\n return acc\n }, {})\n\n return {\n type: 'object',\n additionalProperties: false,\n properties,\n required: Object.keys(properties),\n }\n}\n\n/**\n * This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.\n */\nexport function configToJSONSchema(\n config: SanitizedConfig,\n defaultIDType?: 'number' | 'text',\n): JSONSchema4 {\n // a mutable Map to store custom top-level `interfaceName` types. Fields with an `interfaceName` property will be moved to the top-level definitions here\n const interfaceNameDefinitions: Map<string, JSONSchema4> = new Map()\n\n // Collections and Globals have to be moved to the top-level definitions as well. Reason: The top-level type will be the `Config` type - we don't want all collection and global\n // types to be inlined inside the `Config` type\n const entityDefinitions: { [k: string]: JSONSchema4 } = [\n ...config.globals,\n ...config.collections,\n ].reduce((acc, entity) => {\n acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType)\n return acc\n }, {})\n\n const authOperationDefinitions = [...config.collections]\n .filter(({ auth }) => Boolean(auth))\n .reduce(\n (acc, authCollection) => {\n acc.auth[authCollection.slug] = authCollectionToOperationsJSONSchema(authCollection)\n return acc\n },\n { auth: {} },\n )\n\n let jsonSchema: JSONSchema4 = {\n additionalProperties: false,\n definitions: {\n ...entityDefinitions,\n ...Object.fromEntries(interfaceNameDefinitions),\n ...authOperationDefinitions,\n },\n // These properties here will be very simple, as all the complexity is in the definitions. These are just the properties for the top-level `Config` type\n type: 'object',\n properties: {\n auth: generateAuthOperationSchemas(config.collections),\n collections: generateEntitySchemas(config.collections || []),\n db: generateDbEntitySchema(config),\n globals: generateEntitySchemas(config.globals || []),\n locale: generateLocaleEntitySchemas(config.localization),\n user: generateAuthEntitySchemas(config.collections),\n },\n required: ['user', 'locale', 'collections', 'globals', 'auth', 'db'],\n title: 'Config',\n }\n\n if (config?.typescript?.schema?.length) {\n for (const schema of config.typescript.schema) {\n jsonSchema = schema({ jsonSchema })\n }\n }\n\n return jsonSchema\n}\n"],"names":["pluralize","singular","MissingEditorProp","fieldAffectsData","tabHasName","deepCopyObject","toWords","getCollectionIDFieldTypes","fieldIsRequired","field","isConditional","Boolean","admin","condition","isMarkedRequired","required","type","fields","some","subField","tabs","tab","buildOptionEnums","options","map","option","value","generateEntitySchemas","entities","properties","reduce","acc","slug","$ref","additionalProperties","Object","keys","generateLocaleEntitySchemas","localization","locales","localesFromConfig","locale","code","enum","generateAuthEntitySchemas","filter","auth","allOf","collection","oneOf","generateDbEntitySchema","config","defaultIDType","db","withNullableJSONSchemaType","fieldType","isRequired","fieldTypes","push","fieldsToJSONSchema","collectionIDFieldTypes","interfaceNameDefinitions","requiredFieldNames","Set","fromEntries","fieldSchemas","add","name","fieldSchema","hasMany","items","jsonSchema","schema","editor","Error","outputSchema","optionEnums","maxItems","minItems","Array","isArray","relationTo","relation","const","blocks","block","blockFieldSchemas","blockSchema","blockType","interfaceName","set","childSchema","entries","forEach","propName","propSchema","hasRequiredFields","typescriptSchema","length","Map","from","entityToJSONSchema","incomingEntity","entity","title","typescript","interface","idField","customIdField","find","unshift","timestamps","disableLocalStrategy","generateAuthFieldTypes","loginWithUsername","emailAuthFields","email","usernameAuthFields","username","includes","allowEmailLogin","requireEmail","authCollectionToOperationsJSONSchema","loginUserFields","forgotOrUnlockUserFields","registerUserFields","forgotPassword","login","registerFirstUser","unlock","generateAuthOperationSchemas","collections","configToJSONSchema","entityDefinitions","globals","authOperationDefinitions","authCollection","definitions","user"],"mappings":"AAEA,OAAOA,eAAe,YAAW;AACjC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;AAQrB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c,EAAE,MAAM,mBAAmB,CAAA;AAsDvD,KAAK,cAAc,GAAG,CACpB,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,cAAc,CAAC,CAAA;AAC5B,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"createLocalReq.d.ts","sourceRoot":"","sources":["../../src/utilities/createLocalReq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAsDvD,KAAK,cAAc,GAAG,CACpB,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,cAAc,CAAC,CAAA;AAC5B,eAAO,MAAM,cAAc,EAAE,cAuC5B,CAAA"}
|
|
@@ -49,7 +49,8 @@ export const createLocalReq = async ({ context, fallbackLocale, locale: localeAr
|
|
|
49
49
|
if (payload.config?.localization) {
|
|
50
50
|
const locale = localeArg === '*' ? 'all' : localeArg;
|
|
51
51
|
const defaultLocale = payload.config.localization.defaultLocale;
|
|
52
|
-
|
|
52
|
+
const localeCandidate = locale || req?.locale || req?.query?.locale;
|
|
53
|
+
req.locale = localeCandidate && typeof localeCandidate === 'string' ? localeCandidate : defaultLocale;
|
|
53
54
|
const fallbackLocaleFromConfig = payload.config.localization.locales.find(({ code })=>req.locale === code)?.fallbackLocale;
|
|
54
55
|
if (typeof fallbackLocale !== 'undefined') {
|
|
55
56
|
req.fallbackLocale = fallbackLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/createLocalReq.ts"],"sourcesContent":["import type { User } from '../auth/types.js'\nimport type { Payload, RequestContext } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { getDataLoader } from '../collections/dataloader.js'\nimport { getLocalI18n } from '../translations/getLocalI18n.js'\n\nfunction getRequestContext(\n req: PayloadRequest = { context: null } as PayloadRequest,\n context: RequestContext = {},\n): RequestContext {\n if (req.context) {\n if (Object.keys(req.context).length === 0 && req.context.constructor === Object) {\n // if req.context is `{}` avoid unnecessary spread\n return context\n } else {\n return { ...req.context, ...context }\n }\n } else {\n return context\n }\n}\n\nconst attachFakeURLProperties = (req: PayloadRequest) => {\n /**\n * *NOTE*\n * If no URL is provided, the local API was called directly outside\n * the context of a request. Therefore we create a fake URL object.\n * `ts-expect-error` is used below for properties that are 'read-only'\n * since they do not exist yet we can safely ignore the error.\n */\n let urlObject\n\n function getURLObject() {\n if (urlObject) return urlObject\n const urlToUse = req?.url || req.payload.config?.serverURL || 'http://localhost'\n try {\n urlObject = new URL(urlToUse)\n } catch (error) {\n urlObject = new URL('http://localhost')\n }\n\n return urlObject\n }\n\n if (!req.host) req.host = getURLObject().host\n if (!req.protocol) req.protocol = getURLObject().protocol\n if (!req.pathname) req.pathname = getURLObject().pathname\n // @ts-expect-error\n if (!req.searchParams) req.searchParams = getURLObject().searchParams\n // @ts-expect-error\n if (!req.origin) req.origin = getURLObject().origin\n // @ts-expect-error\n if (!req?.url) req.url = getURLObject().href\n}\n\ntype CreateLocalReq = (\n options: {\n context?: RequestContext\n fallbackLocale?: string\n locale?: string\n req?: PayloadRequest\n user?: User\n },\n payload: Payload,\n) => Promise<PayloadRequest>\nexport const createLocalReq: CreateLocalReq = async (\n { context, fallbackLocale, locale: localeArg, req = {} as PayloadRequest, user },\n payload,\n) => {\n if (payload.config?.localization) {\n const locale = localeArg === '*' ? 'all' : localeArg\n const defaultLocale = payload.config.localization.defaultLocale\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/createLocalReq.ts"],"sourcesContent":["import type { User } from '../auth/types.js'\nimport type { Payload, RequestContext } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { getDataLoader } from '../collections/dataloader.js'\nimport { getLocalI18n } from '../translations/getLocalI18n.js'\n\nfunction getRequestContext(\n req: PayloadRequest = { context: null } as PayloadRequest,\n context: RequestContext = {},\n): RequestContext {\n if (req.context) {\n if (Object.keys(req.context).length === 0 && req.context.constructor === Object) {\n // if req.context is `{}` avoid unnecessary spread\n return context\n } else {\n return { ...req.context, ...context }\n }\n } else {\n return context\n }\n}\n\nconst attachFakeURLProperties = (req: PayloadRequest) => {\n /**\n * *NOTE*\n * If no URL is provided, the local API was called directly outside\n * the context of a request. Therefore we create a fake URL object.\n * `ts-expect-error` is used below for properties that are 'read-only'\n * since they do not exist yet we can safely ignore the error.\n */\n let urlObject\n\n function getURLObject() {\n if (urlObject) return urlObject\n const urlToUse = req?.url || req.payload.config?.serverURL || 'http://localhost'\n try {\n urlObject = new URL(urlToUse)\n } catch (error) {\n urlObject = new URL('http://localhost')\n }\n\n return urlObject\n }\n\n if (!req.host) req.host = getURLObject().host\n if (!req.protocol) req.protocol = getURLObject().protocol\n if (!req.pathname) req.pathname = getURLObject().pathname\n // @ts-expect-error\n if (!req.searchParams) req.searchParams = getURLObject().searchParams\n // @ts-expect-error\n if (!req.origin) req.origin = getURLObject().origin\n // @ts-expect-error\n if (!req?.url) req.url = getURLObject().href\n}\n\ntype CreateLocalReq = (\n options: {\n context?: RequestContext\n fallbackLocale?: string\n locale?: string\n req?: PayloadRequest\n user?: User\n },\n payload: Payload,\n) => Promise<PayloadRequest>\nexport const createLocalReq: CreateLocalReq = async (\n { context, fallbackLocale, locale: localeArg, req = {} as PayloadRequest, user },\n payload,\n) => {\n if (payload.config?.localization) {\n const locale = localeArg === '*' ? 'all' : localeArg\n const defaultLocale = payload.config.localization.defaultLocale\n const localeCandidate = locale || req?.locale || req?.query?.locale\n req.locale =\n localeCandidate && typeof localeCandidate === 'string' ? localeCandidate : defaultLocale\n const fallbackLocaleFromConfig = payload.config.localization.locales.find(\n ({ code }) => req.locale === code,\n )?.fallbackLocale\n if (typeof fallbackLocale !== 'undefined') {\n req.fallbackLocale = fallbackLocale\n } else if (typeof req?.fallbackLocale === 'undefined') {\n req.fallbackLocale = fallbackLocaleFromConfig || defaultLocale\n }\n }\n\n const i18n =\n req?.i18n ||\n (await getLocalI18n({ config: payload.config, language: payload.config.i18n.fallbackLanguage }))\n\n // @ts-expect-error\n if (!req.headers) req.headers = new Headers()\n req.context = getRequestContext(req, context)\n req.payloadAPI = req?.payloadAPI || 'local'\n req.payload = payload\n req.i18n = i18n\n req.t = i18n.t\n req.user = user || req?.user || null\n req.payloadDataLoader = req?.payloadDataLoader || getDataLoader(req)\n req.routeParams = req?.routeParams || {}\n req.query = req?.query || {}\n\n attachFakeURLProperties(req)\n\n return req\n}\n"],"names":["getDataLoader","getLocalI18n","getRequestContext","req","context","Object","keys","length","constructor","attachFakeURLProperties","urlObject","getURLObject","urlToUse","url","payload","config","serverURL","URL","error","host","protocol","pathname","searchParams","origin","href","createLocalReq","fallbackLocale","locale","localeArg","user","localization","defaultLocale","localeCandidate","query","fallbackLocaleFromConfig","locales","find","code","i18n","language","fallbackLanguage","headers","Headers","payloadAPI","t","payloadDataLoader","routeParams"],"mappings":"AAIA,SAASA,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,YAAY,QAAQ,kCAAiC;AAE9D,SAASC,kBACPC,MAAsB;IAAEC,SAAS;AAAK,CAAmB,EACzDA,UAA0B,CAAC,CAAC;IAE5B,IAAID,IAAIC,OAAO,EAAE;QACf,IAAIC,OA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"version":3,"file":"enforceMaxVersions.d.ts","sourceRoot":"","sources":["../../src/versions/enforceMaxVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAS,MAAM,mBAAmB,CAAA;AAEvE,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,yBAAyB,CAAA;IACtC,MAAM,CAAC,EAAE,qBAAqB,CAAA;IAC9B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,kBAAkB,mDAO5B,IAAI,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"enforceMaxVersions.d.ts","sourceRoot":"","sources":["../../src/versions/enforceMaxVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAS,MAAM,mBAAmB,CAAA;AAEvE,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,yBAAyB,CAAA;IACtC,MAAM,CAAC,EAAE,qBAAqB,CAAA;IAC9B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,kBAAkB,mDAO5B,IAAI,KAAG,OAAO,CAAC,IAAI,CA8DrB,CAAA"}
|
|
@@ -10,6 +10,7 @@ export const enforceMaxVersions = async ({ id, collection, global, max, payload,
|
|
|
10
10
|
};
|
|
11
11
|
const query = await payload.db.findVersions({
|
|
12
12
|
collection: collection.slug,
|
|
13
|
+
limit: 1,
|
|
13
14
|
pagination: false,
|
|
14
15
|
req,
|
|
15
16
|
skip: max,
|
|
@@ -20,6 +21,7 @@ export const enforceMaxVersions = async ({ id, collection, global, max, payload,
|
|
|
20
21
|
} else if (global) {
|
|
21
22
|
const query = await payload.db.findGlobalVersions({
|
|
22
23
|
global: global.slug,
|
|
24
|
+
limit: 1,
|
|
23
25
|
pagination: false,
|
|
24
26
|
req,
|
|
25
27
|
skip: max,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/versions/enforceMaxVersions.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { Payload, PayloadRequest, Where } from '../types/index.js'\n\ntype Args = {\n collection?: SanitizedCollectionConfig\n global?: SanitizedGlobalConfig\n id?: number | string\n max: number\n payload: Payload\n req?: PayloadRequest\n}\n\nexport const enforceMaxVersions = async ({\n id,\n collection,\n global,\n max,\n payload,\n req,\n}: Args): Promise<void> => {\n const entityType = collection ? 'collection' : 'global'\n const slug = collection ? collection.slug : global?.slug\n\n try {\n const where: Where = {}\n let oldestAllowedDoc\n\n if (collection) {\n where.parent = {\n equals: id,\n }\n\n const query = await payload.db.findVersions({\n collection: collection.slug,\n pagination: false,\n req,\n skip: max,\n sort: '-updatedAt',\n where,\n })\n\n ;[oldestAllowedDoc] = query.docs\n } else if (global) {\n const query = await payload.db.findGlobalVersions({\n global: global.slug,\n pagination: false,\n req,\n skip: max,\n sort: '-updatedAt',\n where,\n })\n\n ;[oldestAllowedDoc] = query.docs\n }\n\n if (oldestAllowedDoc?.updatedAt) {\n const deleteQuery: Where = {\n updatedAt: {\n less_than_equal: oldestAllowedDoc.updatedAt,\n },\n }\n\n if (collection) {\n deleteQuery.parent = {\n equals: id,\n }\n }\n\n await payload.db.deleteVersions({\n collection: slug,\n req,\n where: deleteQuery,\n })\n }\n } catch (err) {\n payload.logger.error(\n `There was an error cleaning up old versions for the ${entityType} ${slug}`,\n )\n }\n}\n"],"names":["enforceMaxVersions","id","collection","global","max","payload","req","entityType","slug","where","oldestAllowedDoc","parent","equals","query","db","findVersions","pagination","skip","sort","docs","findGlobalVersions","updatedAt","deleteQuery","less_than_equal","deleteVersions","err","logger","error"],"mappings":"AAaA,OAAO,MAAMA,qBAAqB,OAAO,EACvCC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,GAAG,EACHC,OAAO,EACPC,GAAG,EACE;IACL,MAAMC,aAAaL,aAAa,eAAe;IAC/C,MAAMM,OAAON,aAAaA,WAAWM,IAAI,GAAGL,QAAQK;IAEpD,IAAI;QACF,MAAMC,QAAe,CAAC;QACtB,IAAIC;QAEJ,IAAIR,YAAY;YACdO,MAAME,MAAM,GAAG;gBACbC,QAAQX;YACV;YAEA,MAAMY,QAAQ,MAAMR,QAAQS,EAAE,CAACC,YAAY,CAAC;gBAC1Cb,YAAYA,WAAWM,IAAI;gBAC3BQ,YAAY;
|
|
1
|
+
{"version":3,"sources":["../../src/versions/enforceMaxVersions.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { Payload, PayloadRequest, Where } from '../types/index.js'\n\ntype Args = {\n collection?: SanitizedCollectionConfig\n global?: SanitizedGlobalConfig\n id?: number | string\n max: number\n payload: Payload\n req?: PayloadRequest\n}\n\nexport const enforceMaxVersions = async ({\n id,\n collection,\n global,\n max,\n payload,\n req,\n}: Args): Promise<void> => {\n const entityType = collection ? 'collection' : 'global'\n const slug = collection ? collection.slug : global?.slug\n\n try {\n const where: Where = {}\n let oldestAllowedDoc\n\n if (collection) {\n where.parent = {\n equals: id,\n }\n\n const query = await payload.db.findVersions({\n collection: collection.slug,\n limit: 1,\n pagination: false,\n req,\n skip: max,\n sort: '-updatedAt',\n where,\n })\n\n ;[oldestAllowedDoc] = query.docs\n } else if (global) {\n const query = await payload.db.findGlobalVersions({\n global: global.slug,\n limit: 1,\n pagination: false,\n req,\n skip: max,\n sort: '-updatedAt',\n where,\n })\n\n ;[oldestAllowedDoc] = query.docs\n }\n\n if (oldestAllowedDoc?.updatedAt) {\n const deleteQuery: Where = {\n updatedAt: {\n less_than_equal: oldestAllowedDoc.updatedAt,\n },\n }\n\n if (collection) {\n deleteQuery.parent = {\n equals: id,\n }\n }\n\n await payload.db.deleteVersions({\n collection: slug,\n req,\n where: deleteQuery,\n })\n }\n } catch (err) {\n payload.logger.error(\n `There was an error cleaning up old versions for the ${entityType} ${slug}`,\n )\n }\n}\n"],"names":["enforceMaxVersions","id","collection","global","max","payload","req","entityType","slug","where","oldestAllowedDoc","parent","equals","query","db","findVersions","limit","pagination","skip","sort","docs","findGlobalVersions","updatedAt","deleteQuery","less_than_equal","deleteVersions","err","logger","error"],"mappings":"AAaA,OAAO,MAAMA,qBAAqB,OAAO,EACvCC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,GAAG,EACHC,OAAO,EACPC,GAAG,EACE;IACL,MAAMC,aAAaL,aAAa,eAAe;IAC/C,MAAMM,OAAON,aAAaA,WAAWM,IAAI,GAAGL,QAAQK;IAEpD,IAAI;QACF,MAAMC,QAAe,CAAC;QACtB,IAAIC;QAEJ,IAAIR,YAAY;YACdO,MAAME,MAAM,GAAG;gBACbC,QAAQX;YACV;YAEA,MAAMY,QAAQ,MAAMR,QAAQS,EAAE,CAACC,YAAY,CAAC;gBAC1Cb,YAAYA,WAAWM,IAAI;gBAC3BQ,OAAO;gBACPC,YAAY;gBACZX;gBACAY,MAAMd;gBACNe,MAAM;gBACNV;YACF;YAEC,CAACC,iBAAiB,GAAGG,MAAMO,IAAI;QAClC,OAAO,IAAIjB,QAAQ;YACjB,MAAMU,QAAQ,MAAMR,QAAQS,EAAE,CAACO,kBAAkB,CAAC;gBAChDlB,QAAQA,OAAOK,IAAI;gBACnBQ,OAAO;gBACPC,YAAY;gBACZX;gBACAY,MAAMd;gBACNe,MAAM;gBACNV;YACF;YAEC,CAACC,iBAAiB,GAAGG,MAAMO,IAAI;QAClC;QAEA,IAAIV,kBAAkBY,WAAW;YAC/B,MAAMC,cAAqB;gBACzBD,WAAW;oBACTE,iBAAiBd,iBAAiBY,SAAS;gBAC7C;YACF;YAEA,IAAIpB,YAAY;gBACdqB,YAAYZ,MAAM,GAAG;oBACnBC,QAAQX;gBACV;YACF;YAEA,MAAMI,QAAQS,EAAE,CAACW,cAAc,CAAC;gBAC9BvB,YAAYM;gBACZF;gBACAG,OAAOc;YACT;QACF;IACF,EAAE,OAAOG,KAAK;QACZrB,QAAQsB,MAAM,CAACC,KAAK,CAClB,CAAC,oDAAoD,EAAErB,WAAW,CAAC,EAAEC,KAAK,CAAC;IAE/E;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveVersion.d.ts","sourceRoot":"","sources":["../../src/versions/saveVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"saveVersion.d.ts","sourceRoot":"","sources":["../../src/versions/saveVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAMvD,KAAK,IAAI,GAAG;IACV,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,yBAAyB,CAAA;IACtC,cAAc,EAAE,GAAG,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,qBAAqB,CAAA;IAC9B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,WAAW,oFASrB,IAAI,KAAG,OAAO,CAAC,UAAU,CAmI3B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/versions/saveVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { Payload } from '../index.js'
|
|
1
|
+
{"version":3,"sources":["../../src/versions/saveVersion.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { Payload } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { deepCopyObjectSimple } from '../index.js'\nimport sanitizeInternalFields from '../utilities/sanitizeInternalFields.js'\nimport { enforceMaxVersions } from './enforceMaxVersions.js'\n\ntype Args = {\n autosave?: boolean\n collection?: SanitizedCollectionConfig\n docWithLocales: any\n draft?: boolean\n global?: SanitizedGlobalConfig\n id?: number | string\n payload: Payload\n req?: PayloadRequest\n}\n\nexport const saveVersion = async ({\n id,\n autosave,\n collection,\n docWithLocales: doc,\n draft,\n global,\n payload,\n req,\n}: Args): Promise<TypeWithID> => {\n let result\n let createNewVersion = true\n const now = new Date().toISOString()\n const versionData = deepCopyObjectSimple(doc)\n if (draft) versionData._status = 'draft'\n if (versionData._id) delete versionData._id\n\n try {\n if (autosave) {\n let docs\n const findVersionArgs = {\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n }\n if (collection) {\n ;({ docs } = await payload.db.findVersions({\n ...findVersionArgs,\n collection: collection.slug,\n req,\n where: {\n parent: {\n equals: id,\n },\n },\n }))\n } else {\n ;({ docs } = await payload.db.findGlobalVersions({\n ...findVersionArgs,\n global: global.slug,\n req,\n }))\n }\n const [latestVersion] = docs\n\n // overwrite the latest version if it's set to autosave\n if (latestVersion?.autosave === true) {\n createNewVersion = false\n\n const data: Record<string, unknown> = {\n createdAt: new Date(latestVersion.createdAt).toISOString(),\n updatedAt: draft ? now : new Date(doc.updatedAt).toISOString(),\n version: versionData,\n }\n\n const updateVersionArgs = {\n id: latestVersion.id,\n req,\n versionData: data as TypeWithID,\n }\n\n if (collection) {\n result = await payload.db.updateVersion({\n ...updateVersionArgs,\n collection: collection.slug,\n req,\n })\n } else {\n result = await payload.db.updateGlobalVersion({\n ...updateVersionArgs,\n global: global.slug,\n req,\n })\n }\n }\n }\n\n if (createNewVersion) {\n if (collection) {\n result = await payload.db.createVersion({\n autosave: Boolean(autosave),\n collectionSlug: collection.slug,\n createdAt: doc?.createdAt ? new Date(doc.createdAt).toISOString() : now,\n parent: collection ? id : undefined,\n req,\n updatedAt: draft ? now : new Date(doc.updatedAt).toISOString(),\n versionData,\n })\n }\n\n if (global) {\n result = await payload.db.createGlobalVersion({\n autosave: Boolean(autosave),\n createdAt: doc?.createdAt ? new Date(doc.createdAt).toISOString() : now,\n globalSlug: global.slug,\n parent: collection ? id : undefined,\n req,\n updatedAt: draft ? now : new Date(doc.updatedAt).toISOString(),\n versionData,\n })\n }\n }\n } catch (err) {\n let errorMessage: string\n\n if (collection)\n errorMessage = `There was an error while saving a version for the ${collection.labels.singular} with ID ${id}.`\n if (global)\n errorMessage = `There was an error while saving a version for the global ${global.label}.`\n payload.logger.error(errorMessage)\n payload.logger.error(err)\n return\n }\n\n let max = 100\n\n if (collection && typeof collection.versions.maxPerDoc === 'number')\n max = collection.versions.maxPerDoc\n if (global && typeof global.versions.max === 'number') max = global.versions.max\n\n if (createNewVersion && max > 0) {\n await enforceMaxVersions({\n id,\n collection,\n global,\n max,\n payload,\n req,\n })\n }\n\n let createdVersion = result.version\n createdVersion.createdAt = result.createdAt\n createdVersion.updatedAt = result.updatedAt\n\n createdVersion = sanitizeInternalFields(createdVersion)\n createdVersion.id = result.parent\n\n return createdVersion\n}\n"],"names":["deepCopyObjectSimple","sanitizeInternalFields","enforceMaxVersions","saveVersion","id","autosave","collection","docWithLocales","doc","draft","global","payload","req","result","createNewVersion","now","Date","toISOString","versionData","_status","_id","docs","findVersionArgs","limit","pagination","sort","db","findVersions","slug","where","parent","equals","findGlobalVersions","latestVersion","data","createdAt","updatedAt","version","updateVersionArgs","updateVersion","updateGlobalVersion","createVersion","Boolean","collectionSlug","undefined","createGlobalVersion","globalSlug","err","errorMessage","labels","singular","label","logger","error","max","versions","maxPerDoc","createdVersion"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,cAAa;AAClD,OAAOC,4BAA4B,yCAAwC;AAC3E,SAASC,kBAAkB,QAAQ,0BAAyB;AAa5D,OAAO,MAAMC,cAAc,OAAO,EAChCC,EAAE,EACFC,QAAQ,EACRC,UAAU,EACVC,gBAAgBC,GAAG,EACnBC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,GAAG,EACE;IACL,IAAIC;IACJ,IAAIC,mBAAmB;IACvB,MAAMC,MAAM,IAAIC,OAAOC,WAAW;IAClC,MAAMC,cAAclB,qBAAqBQ;IACzC,IAAIC,OAAOS,YAAYC,OAAO,GAAG;IACjC,IAAID,YAAYE,GAAG,EAAE,OAAOF,YAAYE,GAAG;IAE3C,IAAI;QACF,IAAIf,UAAU;YACZ,IAAIgB;YACJ,MAAMC,kBAAkB;gBACtBC,OAAO;gBACPC,YAAY;gBACZZ;gBACAa,MAAM;YACR;YACA,IAAInB,YAAY;gBACZ,CAAA,EAAEe,IAAI,EAAE,GAAG,MAAMV,QAAQe,EAAE,CAACC,YAAY,CAAC;oBACzC,GAAGL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AGvB,OAAOuB,SAAS;IAE3CqB,iBAAiBxD,uBAAuBwD;IACxCA,eAAerD,EAAE,GAAGS,OAAOiB,MAAM;IAEjC,OAAO2B;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.69",
|
|
4
4
|
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin panel",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"scmp": "2.1.0",
|
|
97
97
|
"ts-essentials": "7.0.3",
|
|
98
98
|
"uuid": "10.0.0",
|
|
99
|
-
"@payloadcms/translations": "3.0.0-beta.
|
|
99
|
+
"@payloadcms/translations": "3.0.0-beta.69"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@hyrious/esbuild-plugin-commonjs": "^0.2.4",
|