@payloadcms/db-mongodb 3.0.0-canary.b750ebf → 3.0.0-canary.b8c9483
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +17 -3
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -1
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +40 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +40 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +10 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +10 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +13 -4
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +8 -6
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +31 -9
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +11 -3
- package/dist/deleteOne.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +4 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +34 -4
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +9 -3
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +17 -5
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +27 -3
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +16 -4
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +64 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +20 -18
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -3
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +19 -7
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +2 -2
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +6 -6
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -3
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +190 -74
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +29 -18
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +26 -17
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +7 -5
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +3 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +263 -37
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +36 -8
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +18 -4
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +19 -4
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +18 -4
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +18 -3
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +15 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +18 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +159 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.js +171 -0
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.js +2 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/withSession.d.ts +1 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -3
- package/dist/withSession.js.map +1 -1
- package/license.md +22 -0
- package/package.json +24 -12
- package/dist/queries/mock.js +0 -2
- package/dist/queries/mock.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SanitizedLocalizationConfig,\n SelectField,\n Tab,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: SanitizedLocalizationConfig | false,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nconst buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlockField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n },\n coordinates: {\n type: [Number],\n default: field.defaultValue || undefined,\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany ? { type: [localeSchema], default: undefined } : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n}\n\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","tabHasName","formatBaseSchema","field","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","default","undefined","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","defaultValue","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AA+BA,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,UAAU,QACL,iBAAgB;AAiBvB,MAAMC,mBAAmB,CAACC,OAA2BC;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,OAAON,MAAMM,KAAK,IAAK,CAACJ,iBAAiBF,MAAMO,MAAM,IAAKH,uBAAuB;QACjFI,UAAU;QACVD,QAAQ,AAAC,CAACL,iBAAiBF,MAAMO,MAAM,IAAK;IAC9C;IAEA,IACEF,OAAOE,MAAM,IACZP,CAAAA,MAAMS,SAAS,IACdN,iBACCR,iBAAiBK,UAChBA,MAAMU,IAAI,KAAK,WACfV,MAAMU,IAAI,KAAK,SACfV,MAAMQ,QAAQ,KAAK,IAAI,GAC3B;QACAH,OAAOM,MAAM,GAAG;IAClB;IAEA,IAAIX,MAAMY,MAAM,EAAE;QAChBP,OAAOO,MAAM,GAAG;IAClB;IAEA,OAAOP;AACT;AAEA,MAAMQ,iBAAiB,CACrBC,QACAT,QACAU;IAEA,IAAInB,iBAAiBkB,WAAWC,gBAAgBC,MAAMC,OAAO,CAACF,aAAaG,OAAO,GAAG;QACnF,OAAO;YACLR,MAAMK,aAAaI,WAAW,CAACC,MAAM,CACnC,CAACC,cAAcC,SAAY,CAAA;oBACzB,GAAGD,YAAY;oBACf,CAACC,OAAO,EAAEjB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GA;QACnC;QAEA9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAgF,UAAU,CACR/F,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YAAE,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAAES,MAAMyB;QAAO;QAElF9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAiF,QAAQ,CACNhG,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMhB,SAAS2C,MAAM,CAACgC,KAAK,CAACC,KAAK;YACjCiB,KAAKvF,MAAMoF,UAAU;QACvB;QAEA/E,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;AACF;AAEA,eAAeS,YAAW"}
|
1
|
+
{"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\n\nimport mongoose from 'mongoose'\nimport {\n type ArrayField,\n type Block,\n type BlocksField,\n type CheckboxField,\n type CodeField,\n type CollapsibleField,\n type DateField,\n type EmailField,\n type Field,\n type FieldAffectingData,\n type GroupField,\n type JSONField,\n type NonPresentationalField,\n type NumberField,\n type Payload,\n type PointField,\n type RadioField,\n type RelationshipField,\n type RichTextField,\n type RowField,\n type SanitizedLocalizationConfig,\n type SelectField,\n type Tab,\n type TabsField,\n type TextareaField,\n type TextField,\n type UploadField,\n} from 'payload'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldIsVirtual,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\n/**\n * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema\n * @param field\n */\nconst formatDefaultValue = (field: FieldAffectingData) =>\n typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function'\n ? field.defaultValue\n : undefined\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n default: formatDefaultValue(field),\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: false | SanitizedLocalizationConfig,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nexport const buildSchema = (\n payload: Payload,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (fieldIsVirtual(field)) {\n return\n }\n\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, payload, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(payload, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n blocks: (\n field: BlocksField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, payload.config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, payload, buildSchemaOptions)\n }\n })\n\n if (field.localized && payload.config.localization) {\n payload.config.localization.localeCodes.forEach((localeCode) => {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n if (fieldIsVirtual(subField)) {\n return\n }\n\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, payload, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(payload, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n ...(typeof field.defaultValue !== 'undefined' && {\n default: 'Point',\n }),\n },\n coordinates: {\n type: [Number],\n default: formatDefaultValue(field),\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && payload.config.localization) {\n payload.config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') {\n return option.value\n }\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n const valueType = getRelationshipValueType(field, payload)\n\n if (field.localized && payload.config.localization) {\n schemaToReturn = {\n type: payload.config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: valueType,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: valueType,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: valueType,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: valueType,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n if (fieldIsVirtual(subField)) {\n return\n }\n\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, payload, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') {\n return option.value\n }\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n payload.config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n if (fieldIsVirtual(tab)) {\n return\n }\n const baseSchema = {\n type: buildSchema(payload, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, payload.config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n if (fieldIsVirtual(subField)) {\n return\n }\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, payload, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, payload.config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n payload: Payload,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n const valueType = getRelationshipValueType(field, payload)\n\n if (field.localized && payload.config.localization) {\n schemaToReturn = {\n type: payload.config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: valueType,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: valueType,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: valueType,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: valueType,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n}\n\nconst getRelationshipValueType = (field: RelationshipField | UploadField, payload: Payload) => {\n if (typeof field.relationTo === 'string') {\n const { customIDType } = payload.collections[field.relationTo]\n\n if (!customIDType) {\n return mongoose.Schema.Types.ObjectId\n }\n\n if (customIDType === 'number') {\n return mongoose.Schema.Types.Number\n }\n\n return mongoose.Schema.Types.String\n }\n\n // has custom id relationTo\n if (\n field.relationTo.some((relationTo) => {\n return !!payload.collections[relationTo].customIDType\n })\n ) {\n return mongoose.Schema.Types.Mixed\n }\n\n return mongoose.Schema.Types.ObjectId\n}\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","fieldIsVirtual","tabHasName","formatDefaultValue","field","defaultValue","undefined","formatBaseSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","default","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","payload","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","add","config","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","valueType","getRelationshipValueType","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload","customIDType","collections","ObjectId","some"],"mappings":"AAEA,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E,SAASV,mBAAmBC;gBAC9B;YACF;QACF;QAEAQ,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEkD;QAChB;IACF;AACF;AAEA,MAAME,2BAA2B,CAACzF,OAAwC6B;IACxE,IAAI,OAAO7B,MAAMsF,UAAU,KAAK,UAAU;QACxC,MAAM,EAAEe,YAAY,EAAE,GAAGxE,QAAQyE,WAAW,CAACtG,MAAMsF,UAAU,CAAC;QAE9D,IAAI,CAACe,cAAc;YACjB,OAAO5G,SAASgD,MAAM,CAAC+B,KAAK,CAAC+B,QAAQ;QACvC;QAEA,IAAIF,iBAAiB,UAAU;YAC7B,OAAO5G,SAASgD,MAAM,CAAC+B,KAAK,CAAClC,MAAM;QACrC;QAEA,OAAO7C,SAASgD,MAAM,CAAC+B,KAAK,CAACjC,MAAM;IACrC;IAEA,2BAA2B;IAC3B,IACEvC,MAAMsF,UAAU,CAACkB,IAAI,CAAC,CAAClB;QACrB,OAAO,CAAC,CAACzD,QAAQyE,WAAW,CAAChB,WAAW,CAACe,YAAY;IACvD,IACA;QACA,OAAO5G,SAASgD,MAAM,CAAC+B,KAAK,CAACC,KAAK;IACpC;IAEA,OAAOhF,SAASgD,MAAM,CAAC+B,KAAK,CAAC+B,QAAQ;AACvC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"migrateRelationshipsV2_V3.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAS,cAAc,EAAmB,MAAM,SAAS,CAAA;AAmGrE,wBAAsB,yBAAyB,CAAC,EAC9C,SAAS,EACT,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4EhB"}
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
|
2
|
+
import { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js';
|
3
|
+
import { withSession } from '../withSession.js';
|
4
|
+
const migrateModelWithBatching = async ({ batchSize, config, fields, Model, session })=>{
|
5
|
+
let hasNext = true;
|
6
|
+
let skip = 0;
|
7
|
+
while(hasNext){
|
8
|
+
const docs = await Model.find({}, {}, {
|
9
|
+
lean: true,
|
10
|
+
limit: batchSize + 1,
|
11
|
+
session,
|
12
|
+
skip
|
13
|
+
});
|
14
|
+
if (docs.length === 0) {
|
15
|
+
break;
|
16
|
+
}
|
17
|
+
hasNext = docs.length > batchSize;
|
18
|
+
if (hasNext) {
|
19
|
+
docs.pop();
|
20
|
+
}
|
21
|
+
for (const doc of docs){
|
22
|
+
sanitizeRelationshipIDs({
|
23
|
+
config,
|
24
|
+
data: doc,
|
25
|
+
fields
|
26
|
+
});
|
27
|
+
}
|
28
|
+
await Model.collection.bulkWrite(docs.map((doc)=>({
|
29
|
+
updateOne: {
|
30
|
+
filter: {
|
31
|
+
_id: doc._id
|
32
|
+
},
|
33
|
+
update: {
|
34
|
+
$set: doc
|
35
|
+
}
|
36
|
+
}
|
37
|
+
})), {
|
38
|
+
session
|
39
|
+
});
|
40
|
+
skip += batchSize;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
const hasRelationshipOrUploadField = ({ fields })=>{
|
44
|
+
for (const field of fields){
|
45
|
+
if (field.type === 'relationship' || field.type === 'upload') {
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
if ('fields' in field) {
|
49
|
+
if (hasRelationshipOrUploadField({
|
50
|
+
fields: field.fields
|
51
|
+
})) {
|
52
|
+
return true;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
if ('blocks' in field) {
|
56
|
+
for (const block of field.blocks){
|
57
|
+
if (hasRelationshipOrUploadField({
|
58
|
+
fields: block.fields
|
59
|
+
})) {
|
60
|
+
return true;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
if ('tabs' in field) {
|
65
|
+
for (const tab of field.tabs){
|
66
|
+
if (hasRelationshipOrUploadField({
|
67
|
+
fields: tab.fields
|
68
|
+
})) {
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return false;
|
75
|
+
};
|
76
|
+
export async function migrateRelationshipsV2_V3({ batchSize, req }) {
|
77
|
+
const { payload } = req;
|
78
|
+
const db = payload.db;
|
79
|
+
const config = payload.config;
|
80
|
+
const { session } = await withSession(db, req);
|
81
|
+
for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)){
|
82
|
+
payload.logger.info(`Migrating collection "${collection.slug}"`);
|
83
|
+
await migrateModelWithBatching({
|
84
|
+
batchSize,
|
85
|
+
config,
|
86
|
+
fields: collection.fields,
|
87
|
+
Model: db.collections[collection.slug],
|
88
|
+
session
|
89
|
+
});
|
90
|
+
payload.logger.info(`Migrated collection "${collection.slug}"`);
|
91
|
+
if (collection.versions) {
|
92
|
+
payload.logger.info(`Migrating collection versions "${collection.slug}"`);
|
93
|
+
await migrateModelWithBatching({
|
94
|
+
batchSize,
|
95
|
+
config,
|
96
|
+
fields: buildVersionCollectionFields(config, collection),
|
97
|
+
Model: db.versions[collection.slug],
|
98
|
+
session
|
99
|
+
});
|
100
|
+
payload.logger.info(`Migrated collection versions "${collection.slug}"`);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
const { globals: GlobalsModel } = db;
|
104
|
+
for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)){
|
105
|
+
payload.logger.info(`Migrating global "${global.slug}"`);
|
106
|
+
const doc = await GlobalsModel.findOne({
|
107
|
+
globalType: {
|
108
|
+
$eq: global.slug
|
109
|
+
}
|
110
|
+
}, {}, {
|
111
|
+
lean: true,
|
112
|
+
session
|
113
|
+
});
|
114
|
+
sanitizeRelationshipIDs({
|
115
|
+
config,
|
116
|
+
data: doc,
|
117
|
+
fields: global.fields
|
118
|
+
});
|
119
|
+
await GlobalsModel.collection.updateOne({
|
120
|
+
globalType: global.slug
|
121
|
+
}, {
|
122
|
+
$set: doc
|
123
|
+
}, {
|
124
|
+
session
|
125
|
+
});
|
126
|
+
payload.logger.info(`Migrated global "${global.slug}"`);
|
127
|
+
if (global.versions) {
|
128
|
+
payload.logger.info(`Migrating global versions "${global.slug}"`);
|
129
|
+
await migrateModelWithBatching({
|
130
|
+
batchSize,
|
131
|
+
config,
|
132
|
+
fields: buildVersionGlobalFields(config, global),
|
133
|
+
Model: db.versions[global.slug],
|
134
|
+
session
|
135
|
+
});
|
136
|
+
payload.logger.info(`Migrated global versions "${global.slug}"`);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
//# sourceMappingURL=migrateRelationshipsV2_V3.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"sourcesContent":["import type { ClientSession, Model } from 'mongoose'\nimport type { Field, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from '../withSession.js'\n\nconst migrateModelWithBatching = async ({\n batchSize,\n config,\n fields,\n Model,\n session,\n}: {\n batchSize: number\n config: SanitizedConfig\n fields: Field[]\n Model: Model<any>\n session: ClientSession\n}): Promise<void> => {\n let hasNext = true\n let skip = 0\n\n while (hasNext) {\n const docs = await Model.find(\n {},\n {},\n {\n lean: true,\n limit: batchSize + 1,\n session,\n skip,\n },\n )\n\n if (docs.length === 0) {\n break\n }\n\n hasNext = docs.length > batchSize\n\n if (hasNext) {\n docs.pop()\n }\n\n for (const doc of docs) {\n sanitizeRelationshipIDs({ config, data: doc, fields })\n }\n\n await Model.collection.bulkWrite(\n docs.map((doc) => ({\n updateOne: {\n filter: { _id: doc._id },\n update: {\n $set: doc,\n },\n },\n })),\n { session },\n )\n\n skip += batchSize\n }\n}\n\nconst hasRelationshipOrUploadField = ({ fields }: { fields: Field[] }): boolean => {\n for (const field of fields) {\n if (field.type === 'relationship' || field.type === 'upload') {\n return true\n }\n\n if ('fields' in field) {\n if (hasRelationshipOrUploadField({ fields: field.fields })) {\n return true\n }\n }\n\n if ('blocks' in field) {\n for (const block of field.blocks) {\n if (hasRelationshipOrUploadField({ fields: block.fields })) {\n return true\n }\n }\n }\n\n if ('tabs' in field) {\n for (const tab of field.tabs) {\n if (hasRelationshipOrUploadField({ fields: tab.fields })) {\n return true\n }\n }\n }\n }\n\n return false\n}\n\nexport async function migrateRelationshipsV2_V3({\n batchSize,\n req,\n}: {\n batchSize: number\n req: PayloadRequest\n}): Promise<void> {\n const { payload } = req\n const db = payload.db as MongooseAdapter\n const config = payload.config\n\n const { session } = await withSession(db, req)\n\n for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)) {\n payload.logger.info(`Migrating collection \"${collection.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: collection.fields,\n Model: db.collections[collection.slug],\n session,\n })\n\n payload.logger.info(`Migrated collection \"${collection.slug}\"`)\n\n if (collection.versions) {\n payload.logger.info(`Migrating collection versions \"${collection.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: buildVersionCollectionFields(config, collection),\n Model: db.versions[collection.slug],\n session,\n })\n\n payload.logger.info(`Migrated collection versions \"${collection.slug}\"`)\n }\n }\n\n const { globals: GlobalsModel } = db\n\n for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)) {\n payload.logger.info(`Migrating global \"${global.slug}\"`)\n\n const doc = await GlobalsModel.findOne<Record<string, unknown>>(\n {\n globalType: {\n $eq: global.slug,\n },\n },\n {},\n { lean: true, session },\n )\n\n sanitizeRelationshipIDs({ config, data: doc, fields: global.fields })\n\n await GlobalsModel.collection.updateOne(\n {\n globalType: global.slug,\n },\n { $set: doc },\n { session },\n )\n\n payload.logger.info(`Migrated global \"${global.slug}\"`)\n\n if (global.versions) {\n payload.logger.info(`Migrating global versions \"${global.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: buildVersionGlobalFields(config, global),\n Model: db.versions[global.slug],\n session,\n })\n\n payload.logger.info(`Migrated global versions \"${global.slug}\"`)\n }\n }\n}\n"],"names":["buildVersionCollectionFields","buildVersionGlobalFields","sanitizeRelationshipIDs","withSession","migrateModelWithBatching","batchSize","config","fields","Model","session","hasNext","skip","docs","find","lean","limit","length","pop","doc","data","collection","bulkWrite","map","updateOne","filter","_id","update","$set","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","db","collections","logger","info","slug","versions","globals","GlobalsModel","global","findOne","globalType","$eq"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAIhF,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,oBAAmB;AAE/C,MAAMC,2BAA2B,OAAO,EACtCC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,OAAO,EAOR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX,MAAOD,QAAS;QACd,MAAME,OAAO,MAAMJ,MAAMK,IAAI,CAC3B,CAAC,GACD,CAAC,GACD;YACEC,MAAM;YACNC,OAAOV,YAAY;YACnBI;YACAE;QACF;QAGF,IAAIC,KAAKI,MAAM,KAAK,GAAG;YACrB;QACF;QAEAN,UAAUE,KAAKI,MAAM,GAAGX;QAExB,IAAIK,SAAS;YACXE,KAAKK,GAAG;QACV;QAEA,KAAK,MAAMC,OAAON,KAAM;YACtBV,wBAAwB;gBAAEI;gBAAQa,MAAMD;gBAAKX;YAAO;QACtD;QAEA,MAAMC,MAAMY,UAAU,CAACC,SAAS,CAC9BT,KAAKU,GAAG,CAAC,CAACJ,MAAS,CAAA;gBACjBK,WAAW;oBACTC,QAAQ;wBAAEC,KAAKP,IAAIO,GAAG;oBAAC;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,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,2BAA2B,EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;YAEhE,MAAMtC,yBAAyB;gBAC7BC;gBACAC;gBACAC,QAAQN,yBAAyBK,QAAQwC;gBACzCtC,OAAO8B,GAAGK,QAAQ,CAACG,OAAOJ,IAAI,CAAC;gBAC/BjC;YACF;YAEA4B,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;QACjE;IACF;AACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"migrateVersionsV1_V2.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateVersionsV1_V2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,SAAS,CAAA;AAMtD,wBAAsB,oBAAoB,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,iBAgC1E"}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { withSession } from '../withSession.js';
|
2
|
+
export async function migrateVersionsV1_V2({ req }) {
|
3
|
+
const { payload } = req;
|
4
|
+
const { session } = await withSession(payload.db, req);
|
5
|
+
// For each collection
|
6
|
+
for (const { slug, versions } of payload.config.collections){
|
7
|
+
if (versions?.drafts) {
|
8
|
+
await migrateCollectionDocs({
|
9
|
+
slug,
|
10
|
+
payload,
|
11
|
+
session
|
12
|
+
});
|
13
|
+
payload.logger.info(`Migrated the "${slug}" collection.`);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
// For each global
|
17
|
+
for (const { slug, versions } of payload.config.globals){
|
18
|
+
if (versions) {
|
19
|
+
const VersionsModel = payload.db.versions[slug];
|
20
|
+
await VersionsModel.findOneAndUpdate({}, {
|
21
|
+
latest: true
|
22
|
+
}, {
|
23
|
+
session,
|
24
|
+
sort: {
|
25
|
+
updatedAt: -1
|
26
|
+
}
|
27
|
+
}).exec();
|
28
|
+
payload.logger.info(`Migrated the "${slug}" global.`);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
async function migrateCollectionDocs({ slug, docsAtATime = 100, payload, session }) {
|
33
|
+
const VersionsModel = payload.db.versions[slug];
|
34
|
+
const remainingDocs = await VersionsModel.aggregate([
|
35
|
+
// Sort so that newest are first
|
36
|
+
{
|
37
|
+
$sort: {
|
38
|
+
updatedAt: -1
|
39
|
+
}
|
40
|
+
},
|
41
|
+
// Group by parent ID
|
42
|
+
// take the $first of each
|
43
|
+
{
|
44
|
+
$group: {
|
45
|
+
_id: '$parent',
|
46
|
+
_versionID: {
|
47
|
+
$first: '$_id'
|
48
|
+
},
|
49
|
+
createdAt: {
|
50
|
+
$first: '$createdAt'
|
51
|
+
},
|
52
|
+
latest: {
|
53
|
+
$first: '$latest'
|
54
|
+
},
|
55
|
+
updatedAt: {
|
56
|
+
$first: '$updatedAt'
|
57
|
+
},
|
58
|
+
version: {
|
59
|
+
$first: '$version'
|
60
|
+
}
|
61
|
+
}
|
62
|
+
},
|
63
|
+
{
|
64
|
+
$match: {
|
65
|
+
latest: {
|
66
|
+
$eq: null
|
67
|
+
}
|
68
|
+
}
|
69
|
+
},
|
70
|
+
{
|
71
|
+
$limit: docsAtATime
|
72
|
+
}
|
73
|
+
], {
|
74
|
+
allowDiskUse: true,
|
75
|
+
session
|
76
|
+
}).exec();
|
77
|
+
if (!remainingDocs || remainingDocs.length === 0) {
|
78
|
+
const newVersions = await VersionsModel.find({
|
79
|
+
latest: {
|
80
|
+
$eq: true
|
81
|
+
}
|
82
|
+
}, undefined, {
|
83
|
+
session
|
84
|
+
});
|
85
|
+
if (newVersions?.length) {
|
86
|
+
payload.logger.info(`Migrated ${newVersions.length} documents in the "${slug}" versions collection.`);
|
87
|
+
}
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
const remainingDocIds = remainingDocs.map((doc)=>doc._versionID);
|
91
|
+
await VersionsModel.updateMany({
|
92
|
+
_id: {
|
93
|
+
$in: remainingDocIds
|
94
|
+
}
|
95
|
+
}, {
|
96
|
+
latest: true
|
97
|
+
}, {
|
98
|
+
session
|
99
|
+
});
|
100
|
+
await migrateCollectionDocs({
|
101
|
+
slug,
|
102
|
+
payload,
|
103
|
+
session
|
104
|
+
});
|
105
|
+
}
|
106
|
+
|
107
|
+
//# sourceMappingURL=migrateVersionsV1_V2.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateVersionsV1_V2.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { withSession } from '../withSession.js'\n\nexport async function migrateVersionsV1_V2({ req }: { req: PayloadRequest }) {\n const { payload } = req\n\n const { session } = await withSession(payload.db as MongooseAdapter, req)\n\n // For each collection\n\n for (const { slug, versions } of payload.config.collections) {\n if (versions?.drafts) {\n await migrateCollectionDocs({ slug, payload, session })\n\n payload.logger.info(`Migrated the \"${slug}\" collection.`)\n }\n }\n\n // For each global\n for (const { slug, versions } of payload.config.globals) {\n if (versions) {\n const VersionsModel = payload.db.versions[slug]\n\n await VersionsModel.findOneAndUpdate(\n {},\n { latest: true },\n {\n session,\n sort: { updatedAt: -1 },\n },\n ).exec()\n\n payload.logger.info(`Migrated the \"${slug}\" global.`)\n }\n }\n}\n\nasync function migrateCollectionDocs({\n slug,\n docsAtATime = 100,\n payload,\n session,\n}: {\n docsAtATime?: number\n payload: Payload\n session: ClientSession\n slug: string\n}) {\n const VersionsModel = payload.db.versions[slug]\n const remainingDocs = await VersionsModel.aggregate(\n [\n // Sort so that newest are first\n {\n $sort: {\n updatedAt: -1,\n },\n },\n // Group by parent ID\n // take the $first of each\n {\n $group: {\n _id: '$parent',\n _versionID: { $first: '$_id' },\n createdAt: { $first: '$createdAt' },\n latest: { $first: '$latest' },\n updatedAt: { $first: '$updatedAt' },\n version: { $first: '$version' },\n },\n },\n {\n $match: {\n latest: { $eq: null },\n },\n },\n {\n $limit: docsAtATime,\n },\n ],\n {\n allowDiskUse: true,\n session,\n },\n ).exec()\n\n if (!remainingDocs || remainingDocs.length === 0) {\n const newVersions = await VersionsModel.find(\n {\n latest: {\n $eq: true,\n },\n },\n undefined,\n { session },\n )\n\n if (newVersions?.length) {\n payload.logger.info(\n `Migrated ${newVersions.length} documents in the \"${slug}\" versions collection.`,\n )\n }\n\n return\n }\n\n const remainingDocIds = remainingDocs.map((doc) => doc._versionID)\n\n await VersionsModel.updateMany(\n {\n _id: {\n $in: remainingDocIds,\n },\n },\n {\n latest: true,\n },\n {\n session,\n },\n )\n\n await migrateCollectionDocs({ slug, payload, session })\n}\n"],"names":["withSession","migrateVersionsV1_V2","req","payload","session","db","slug","versions","config","collections","drafts","migrateCollectionDocs","logger","info","globals","VersionsModel","findOneAndUpdate","latest","sort","updatedAt","exec","docsAtATime","remainingDocs","aggregate","$sort","$group","_id","_versionID","$first","createdAt","version","$match","$eq","$limit","allowDiskUse","length","newVersions","find","undefined","remainingDocIds","map","doc","updateMany","$in"],"mappings":"AAKA,SAASA,WAAW,QAAQ,oBAAmB;AAE/C,OAAO,eAAeC,qBAAqB,EAAEC,GAAG,EAA2B;IACzE,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,OAAO,EAAE,GAAG,MAAMJ,YAAYG,QAAQE,EAAE,EAAqBH;IAErE,sBAAsB;IAEtB,KAAK,MAAM,EAAEI,IAAI,EAAEC,QAAQ,EAAE,IAAIJ,QAAQK,MAAM,CAACC,WAAW,CAAE;QAC3D,IAAIF,UAAUG,QAAQ;YACpB,MAAMC,sBAAsB;gBAAEL;gBAAMH;gBAASC;YAAQ;YAErDD,QAAQS,MAAM,CAACC,IAAI,CAAC,CAAC,cAAc,EAAEP,KAAK,aAAa,CAAC;QAC1D;IACF;IAEA,kBAAkB;IAClB,KAAK,MAAM,EAAEA,IAAI,EAAEC,QAAQ,EAAE,IAAIJ,QA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AC,SAAS,EAAEuB,YAAYD,MAAM,CAAC,mBAAmB,EAAE7B,KAAK,sBAAsB,CAAC;QAEpF;QAEA;IACF;IAEA,MAAMiC,kBAAkBjB,cAAckB,GAAG,CAAC,CAACC,MAAQA,IAAId,UAAU;IAEjE,MAAMZ,cAAc2B,UAAU,CAC5B;QACEhB,KAAK;YACHiB,KAAKJ;QACP;IACF,GACA;QACEtB,QAAQ;IACV,GACA;QACEb;IACF;IAGF,MAAMO,sBAAsB;QAAEL;QAAMH;QAASC;IAAQ;AACvD"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
declare const imports = "import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'";
|
2
|
+
declare const upSQL = " await migrateRelationshipsV2_V3({\n batchSize: 100,\n req,\n })\n";
|
3
|
+
export { imports, upSQL };
|
4
|
+
//# sourceMappingURL=relationships-v2-v3.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"relationships-v2-v3.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,uFAAuF,CAAA;AACpG,QAAA,MAAM,KAAK,8FAIV,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const imports = `import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'`;
|
2
|
+
const upSQL = ` await migrateRelationshipsV2_V3({
|
3
|
+
batchSize: 100,
|
4
|
+
req,
|
5
|
+
})
|
6
|
+
`;
|
7
|
+
export { imports, upSQL };
|
8
|
+
|
9
|
+
//# sourceMappingURL=relationships-v2-v3.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"sourcesContent":["const imports = `import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateRelationshipsV2_V3({\n batchSize: 100,\n req,\n })\n`\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,kFAAkF,CAAC;AACpG,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"versions-v1-v2.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/versions-v1-v2.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,kFAAkF,CAAA;AAC/F,QAAA,MAAM,KAAK,gEAGV,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
@@ -1,98 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
// Sort so that newest are first
|
6
|
-
{
|
7
|
-
$sort: {
|
8
|
-
updatedAt: -1,
|
9
|
-
},
|
10
|
-
},
|
11
|
-
// Group by parent ID
|
12
|
-
// take the $first of each
|
13
|
-
{
|
14
|
-
$group: {
|
15
|
-
_id: '$parent',
|
16
|
-
_versionID: { $first: '$_id' },
|
17
|
-
createdAt: { $first: '$createdAt' },
|
18
|
-
latest: { $first: '$latest' },
|
19
|
-
updatedAt: { $first: '$updatedAt' },
|
20
|
-
version: { $first: '$version' },
|
21
|
-
},
|
22
|
-
},
|
23
|
-
{
|
24
|
-
$match: {
|
25
|
-
latest: { $eq: null },
|
26
|
-
},
|
27
|
-
},
|
28
|
-
{
|
29
|
-
$limit: docsAtATime,
|
30
|
-
},
|
31
|
-
],
|
32
|
-
{
|
33
|
-
allowDiskUse: true,
|
34
|
-
},
|
35
|
-
).exec()
|
36
|
-
|
37
|
-
if (!remainingDocs || remainingDocs.length === 0) {
|
38
|
-
const newVersions = await VersionsModel.find({
|
39
|
-
latest: {
|
40
|
-
$eq: true,
|
41
|
-
},
|
42
|
-
})
|
43
|
-
|
44
|
-
if (newVersions?.length) {
|
45
|
-
payload.logger.info(
|
46
|
-
\`Migrated \${newVersions.length} documents in the "\${slug}" versions collection.\`,
|
47
|
-
)
|
48
|
-
}
|
49
|
-
|
50
|
-
return
|
51
|
-
}
|
52
|
-
|
53
|
-
const remainingDocIds = remainingDocs.map((doc) => doc._versionID)
|
54
|
-
|
55
|
-
await VersionsModel.updateMany(
|
56
|
-
{
|
57
|
-
_id: {
|
58
|
-
$in: remainingDocIds,
|
59
|
-
},
|
60
|
-
},
|
61
|
-
{
|
62
|
-
latest: true,
|
63
|
-
},
|
64
|
-
)
|
65
|
-
|
66
|
-
await migrateCollectionDocs(slug)
|
67
|
-
}
|
68
|
-
|
69
|
-
// For each collection
|
70
|
-
await Promise.all(
|
71
|
-
payload.config.collections.map(async ({ slug, versions }) => {
|
72
|
-
if (versions?.drafts) {
|
73
|
-
return migrateCollectionDocs(slug)
|
74
|
-
}
|
75
|
-
}),
|
76
|
-
)
|
77
|
-
|
78
|
-
// For each global
|
79
|
-
await Promise.all(
|
80
|
-
payload.config.globals.map(async ({ slug, versions }) => {
|
81
|
-
if (versions) {
|
82
|
-
const VersionsModel = payload.db.versions[slug]
|
83
|
-
|
84
|
-
await VersionsModel.findOneAndUpdate(
|
85
|
-
{},
|
86
|
-
{ latest: true },
|
87
|
-
{
|
88
|
-
sort: { updatedAt: -1 },
|
89
|
-
},
|
90
|
-
).exec()
|
91
|
-
|
92
|
-
payload.logger.info(\`Migrated the "\${slug}" global.\`)
|
93
|
-
}
|
94
|
-
}),
|
95
|
-
)
|
1
|
+
const imports = `import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'`;
|
2
|
+
const upSQL = ` await migrateVersionsV1_V2({
|
3
|
+
req,
|
4
|
+
})
|
96
5
|
`;
|
6
|
+
export { imports, upSQL };
|
97
7
|
|
98
8
|
//# sourceMappingURL=versions-v1-v2.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/predefinedMigrations/versions-v1-v2.
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/versions-v1-v2.ts"],"sourcesContent":["const imports = `import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateVersionsV1_V2({\n req,\n })\n`\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,6EAA6E,CAAC;AAC/F,MAAMC,QAAQ,CAAC;;;AAGf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE"}
|
@@ -9,6 +9,6 @@ export type BuildQueryArgs = {
|
|
9
9
|
payload: Payload;
|
10
10
|
where: Where;
|
11
11
|
};
|
12
|
-
declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
13
|
-
export
|
12
|
+
export declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields, }?: GetBuildQueryPluginArgs) => (schema: any) => void;
|
13
|
+
export {};
|
14
14
|
//# sourceMappingURL=buildQuery.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,
|
1
|
+
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,eAAO,MAAM,mBAAmB,yCAG7B,uBAAuB,0BAsCzB,CAAA"}
|
@@ -2,7 +2,7 @@ import { QueryError } from 'payload';
|
|
2
2
|
import { parseParams } from './parseParams.js';
|
3
3
|
// This plugin asynchronously builds a list of Mongoose query constraints
|
4
4
|
// which can then be used in subsequent Mongoose queries.
|
5
|
-
const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
5
|
+
export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
6
6
|
return function buildQueryPlugin(schema) {
|
7
7
|
const modifiedSchema = schema;
|
8
8
|
async function buildQuery({ globalSlug, locale, payload, where }) {
|
@@ -34,6 +34,5 @@ const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
|
|
34
34
|
modifiedSchema.statics.buildQuery = buildQuery;
|
35
35
|
};
|
36
36
|
};
|
37
|
-
export default getBuildQueryPlugin;
|
38
37
|
|
39
38
|
//# sourceMappingURL=buildQuery.js.map
|