@payloadcms/db-mongodb 3.0.0-canary.78bbed6 → 3.0.0-canary.79ab53e
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/connect.d.ts.map +1 -1
- package/dist/connect.js +7 -3
- package/dist/connect.js.map +1 -1
- package/dist/createGlobal.js +1 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.js +1 -1
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.js +1 -1
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.js +1 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +1 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/init.js +3 -3
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +1 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +3 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +1 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +7 -4
- package/dist/models/buildSchema.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 +18 -10
- package/dist/queries/buildSearchParams.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 +3 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +18 -6
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.js +1 -1
- 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 +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateOne.js +1 -1
- package/dist/updateOne.js.map +1 -1
- 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/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/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -3
- package/dist/withSession.js.map +1 -1
- package/package.json +7 -5
| @@ -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\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: 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    }\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    }\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: 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, 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\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: mongoose.Schema.Types.Mixed,\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: mongoose.Schema.Types.Mixed,\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    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 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\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: mongoose.Schema.Types.Mixed,\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: mongoose.Schema.Types.Mixed,\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\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","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","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","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","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;;;CAGC,GACD,MAAMC,qBAAqB,CAACC,QAC1B,OAAOA,MAAMC,YAAY,KAAK,eAAe,OAAOD,MAAMC,YAAY,KAAK,aACvED,MAAMC,YAAY,GAClBC;AAEN,MAAMC,mBAAmB,CAACH,OAA2BI;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,SAASV,mBAAmBC;QAC5BU,OAAOV,MAAMU,KAAK,IAAK,CAACL,iBAAiBL,MAAMW,MAAM,IAAKJ,uBAAuB;QACjFK,UAAU;QACVD,QAAQ,AAAC,CAACN,iBAAiBL,MAAMW,MAAM,IAAK;IAC9C;IAEA,IACEH,OAAOG,MAAM,IACZX,CAAAA,MAAMa,SAAS,IACdP,iBACCX,iBAAiBK,UAChBA,MAAMc,IAAI,KAAK,WACfd,MAAMc,IAAI,KAAK,SACfd,MAAMY,QAAQ,KAAK,IAAI,GAC3B;QACAJ,OAAOO,MAAM,GAAG;IAClB;IAEA,IAAIf,MAAMgB,MAAM,EAAE;QAChBR,OAAOQ,MAAM,GAAG;IAClB;IAEA,OAAOR;AACT;AAEA,MAAMS,iBAA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,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEiD;QAChB;IACF;AACF;AAEA,eAAe1D,YAAW"}
         | 
| 1 | 
            +
            {"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n  ArrayField,\n  Block,\n  BlocksField,\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  TextareaField,\n  TextField,\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\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  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    }\n\n    schema.add({\n      [field.name]: localizeSchema(field, baseSchema, config.localization),\n    })\n  },\n  blocks: (\n    field: BlocksField,\n    schema: Schema,\n    config: SanitizedConfig,\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, 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: 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, 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') {\n          return option.value\n        }\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\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: mongoose.Schema.Types.Mixed,\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: mongoose.Schema.Types.Mixed,\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    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') {\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        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 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\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: mongoose.Schema.Types.Mixed,\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: mongoose.Schema.Types.Mixed,\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"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","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","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","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","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;;;CAGC,GACD,MAAMC,qBAAqB,CAACC,QAC1B,OAAOA,MAAMC,YAAY,KAAK,eAAe,OAAOD,MAAMC,YAAY,KAAK,aACvED,MAAMC,YAAY,GAClBC;AAEN,MAAMC,mBAAmB,CAACH,OAA2BI;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,SAASV,mBAAmBC;QAC5BU,OAAOV,MAAMU,KAAK,IAAK,CAACL,iBAAiBL,MAAMW,MA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W,CAAC;gBACrC;YACF;YAEA,IAAIrC,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF,OAAO;YACLsF,iBAAiB;gBACf,GAAGnF,iBAAiBH,OAAOI,mBAAmB;gBAC9CU,MAAMpB,SAAS+C,MAAM,CAAC8B,KAAK,CAACC,KAAK;gBACjCgB,KAAKxF,MAAMqF,UAAU;YACvB;YAEA,IAAIrF,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF;QAEAQ,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEiD;QAChB;IACF;AACF"}
         | 
| @@ -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
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n  collectionSlug?: string\n  versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n  globalSlug?: string\n  locale?: string\n  payload: Payload\n  where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\ | 
| 1 | 
            +
            {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n  collectionSlug?: string\n  versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n  globalSlug?: string\n  locale?: string\n  payload: Payload\n  where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\nexport const getBuildQueryPlugin = ({\n  collectionSlug,\n  versionsFields,\n}: GetBuildQueryPluginArgs = {}) => {\n  return function buildQueryPlugin(schema) {\n    const modifiedSchema = schema\n    async function buildQuery({\n      globalSlug,\n      locale,\n      payload,\n      where,\n    }: BuildQueryArgs): Promise<Record<string, unknown>> {\n      let fields = versionsFields\n      if (!fields) {\n        if (globalSlug) {\n          const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n          fields = globalConfig.fields\n        }\n        if (collectionSlug) {\n          const collectionConfig = payload.collections[collectionSlug].config\n          fields = collectionConfig.fields\n        }\n      }\n      const errors = []\n      const result = await parseParams({\n        collectionSlug,\n        fields,\n        globalSlug,\n        locale,\n        payload,\n        where,\n      })\n\n      if (errors.length > 0) {\n        throw new QueryError(errors)\n      }\n\n      return result\n    }\n    modifiedSchema.statics.buildQuery = buildQuery\n  }\n}\n"],"names":["QueryError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","collectionConfig","collections","errors","result","length","statics"],"mappings":"AAEA,SAASA,UAAU,QAAQ,UAAS;AAEpC,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,cAAc,EACdC,cAAc,EACU,GAAG,CAAC,CAAC;IAC7B,OAAO,SAASC,iBAAiBC,MAAM;QACrC,MAAMC,iBAAiBD;QACvB,eAAeE,WAAW,EACxBC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAAST;YACb,IAAI,CAACS,QAAQ;gBACX,IAAIJ,YAAY;oBACd,MAAMK,eAAeH,QAAQI,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAST;oBACxEI,SAASC,aAAaD,MAAM;gBAC9B;gBACA,IAAIV,gBAAgB;oBAClB,MAAMgB,mBAAmBR,QAAQS,WAAW,CAACjB,eAAe,CAACa,MAAM;oBACnEH,SAASM,iBAAiBN,MAAM;gBAClC;YACF;YACA,MAAMQ,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMrB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIS,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIvB,WAAWqB;YACvB;YAEA,OAAOC;QACT;QACAf,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF,EAAC"}
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAepE,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC, | 
| 1 | 
            +
            {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAepE,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CA8NvB"}
         | 
| @@ -14,7 +14,9 @@ const subQueryOptions = { | |
| 14 14 | 
             
             */ export async function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, payload, val }) {
         | 
| 15 15 | 
             
                // Replace GraphQL nested field double underscore formatting
         | 
| 16 16 | 
             
                let sanitizedPath = incomingPath.replace(/__/g, '.');
         | 
| 17 | 
            -
                if (sanitizedPath === 'id')  | 
| 17 | 
            +
                if (sanitizedPath === 'id') {
         | 
| 18 | 
            +
                    sanitizedPath = '_id';
         | 
| 19 | 
            +
                }
         | 
| 18 20 | 
             
                let paths = [];
         | 
| 19 21 | 
             
                let hasCustomID = false;
         | 
| 20 22 | 
             
                if (sanitizedPath === '_id') {
         | 
| @@ -52,9 +54,11 @@ const subQueryOptions = { | |
| 52 54 | 
             
                        path,
         | 
| 53 55 | 
             
                        val
         | 
| 54 56 | 
             
                    });
         | 
| 55 | 
            -
                    if (rawQuery)  | 
| 56 | 
            -
                         | 
| 57 | 
            -
             | 
| 57 | 
            +
                    if (rawQuery) {
         | 
| 58 | 
            +
                        return {
         | 
| 59 | 
            +
                            value: rawQuery
         | 
| 60 | 
            +
                        };
         | 
| 61 | 
            +
                    }
         | 
| 58 62 | 
             
                    // If there are multiple collections to search through,
         | 
| 59 63 | 
             
                    // Recursively build up a list of query constraints
         | 
| 60 64 | 
             
                    if (paths.length > 1) {
         | 
| @@ -133,7 +137,9 @@ const subQueryOptions = { | |
| 133 137 | 
             
                        if (field.type === 'relationship' || field.type === 'upload') {
         | 
| 134 138 | 
             
                            let hasNumberIDRelation;
         | 
| 135 139 | 
             
                            let multiIDCondition = '$or';
         | 
| 136 | 
            -
                            if (operatorKey === '$ne')  | 
| 140 | 
            +
                            if (operatorKey === '$ne') {
         | 
| 141 | 
            +
                                multiIDCondition = '$and';
         | 
| 142 | 
            +
                            }
         | 
| 137 143 | 
             
                            const result = {
         | 
| 138 144 | 
             
                                value: {
         | 
| 139 145 | 
             
                                    [multiIDCondition]: [
         | 
| @@ -161,11 +167,13 @@ const subQueryOptions = { | |
| 161 167 | 
             
                                            hasNumberIDRelation = true;
         | 
| 162 168 | 
             
                                        }
         | 
| 163 169 | 
             
                                    });
         | 
| 164 | 
            -
                                    if (hasNumberIDRelation)  | 
| 165 | 
            -
                                        [ | 
| 166 | 
            -
                                            [ | 
| 167 | 
            -
             | 
| 168 | 
            -
             | 
| 170 | 
            +
                                    if (hasNumberIDRelation) {
         | 
| 171 | 
            +
                                        result.value[multiIDCondition].push({
         | 
| 172 | 
            +
                                            [path]: {
         | 
| 173 | 
            +
                                                [operatorKey]: parseFloat(formattedValue)
         | 
| 174 | 
            +
                                            }
         | 
| 175 | 
            +
                                        });
         | 
| 176 | 
            +
                                    }
         | 
| 169 177 | 
             
                                }
         | 
| 170 178 | 
             
                            }
         | 
| 171 179 | 
             
                            if (result.value[multiIDCondition].length > 1) {
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Field, Operator, PathToQuery, Payload } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n  ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\ntype SearchParam = {\n  path?: string\n  rawQuery?: unknown\n  value?: unknown\n}\n\nconst subQueryOptions = {\n  lean: true,\n  limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n  collectionSlug,\n  fields,\n  globalSlug,\n  incomingPath,\n  locale,\n  operator,\n  payload,\n  val,\n}: {\n  collectionSlug?: string\n  fields: Field[]\n  globalSlug?: string\n  incomingPath: string\n  locale?: string\n  operator: string\n  payload: Payload\n  val: unknown\n}): Promise<SearchParam> {\n  // Replace GraphQL nested field double underscore formatting\n  let sanitizedPath = incomingPath.replace(/__/g, '.')\n  if (sanitizedPath === 'id') sanitizedPath = '_id'\n\n  let paths: PathToQuery[] = []\n\n  let hasCustomID = false\n\n  if (sanitizedPath === '_id') {\n    const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n    let idFieldType: 'number' | 'text' = 'text'\n\n    if (customIDFieldType) {\n      idFieldType = customIDFieldType\n      hasCustomID = true\n    }\n\n    paths.push({\n      collectionSlug,\n      complete: true,\n      field: {\n        name: 'id',\n        type: idFieldType,\n      } as Field,\n      path: '_id',\n    })\n  } else {\n    paths = await getLocalizedPaths({\n      collectionSlug,\n      fields,\n      globalSlug,\n      incomingPath: sanitizedPath,\n      locale,\n      payload,\n    })\n  }\n\n  const [{ field, path }] = paths\n\n  if (path) {\n    const {\n      operator: formattedOperator,\n      rawQuery,\n      val: formattedValue,\n    } = sanitizeQueryValue({\n      field,\n      hasCustomID,\n      operator,\n      path,\n      val,\n    })\n\n    if (rawQuery) return { value: rawQuery }\n\n    // If there are multiple collections to search through,\n    // Recursively build up a list of query constraints\n    if (paths.length > 1) {\n      // Remove top collection and reverse array\n      // to work backwards from top\n      const pathsToQuery = paths.slice(1).reverse()\n\n      const initialRelationshipQuery = {\n        value: {},\n      } as SearchParam\n\n      const relationshipQuery = await pathsToQuery.reduce(\n        async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n          const priorQueryResult = await priorQuery\n\n          const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n          // On the \"deepest\" collection,\n          // Search on the value passed through the query\n          if (i === 0) {\n            const subQuery = await SubModel.buildQuery({\n              locale,\n              payload,\n              where: {\n                [subPath]: {\n                  [formattedOperator]: val,\n                },\n              },\n            })\n\n            const result = await SubModel.find(subQuery, subQueryOptions)\n\n            const $in: unknown[] = []\n\n            result.forEach((doc) => {\n              const stringID = doc._id.toString()\n              $in.push(stringID)\n\n              if (mongoose.Types.ObjectId.isValid(stringID)) {\n                $in.push(doc._id)\n              }\n            })\n\n            if (pathsToQuery.length === 1) {\n              return {\n                path,\n                value: { $in },\n              }\n            }\n\n            const nextSubPath = pathsToQuery[i + 1].path\n\n            return {\n              value: { [nextSubPath]: { $in } },\n            }\n          }\n\n          const subQuery = priorQueryResult.value\n          const result = await SubModel.find(subQuery, subQueryOptions)\n\n          const $in = result.map((doc) => doc._id.toString())\n\n          // If it is the last recursion\n          // then pass through the search param\n          if (i + 1 === pathsToQuery.length) {\n            return {\n              path,\n              value: { $in },\n            }\n          }\n\n          return {\n            value: {\n              _id: { $in },\n            },\n          }\n        },\n        Promise.resolve(initialRelationshipQuery),\n      )\n\n      return relationshipQuery\n    }\n\n    if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n      const operatorKey = operatorMap[formattedOperator]\n\n      if (field.type === 'relationship' || field.type === 'upload') {\n        let hasNumberIDRelation\n        let multiIDCondition = '$or'\n        if (operatorKey === '$ne') multiIDCondition = '$and'\n\n        const result = {\n          value: {\n            [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n          },\n        }\n\n        if (typeof formattedValue === 'string') {\n          if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n            result.value[multiIDCondition].push({\n              [path]: { [operatorKey]: ObjectId(formattedValue) },\n            })\n          } else {\n            ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n              (relationTo) => {\n                const isRelatedToCustomNumberID =\n                  payload.collections[relationTo]?.customIDType === 'number'\n\n                if (isRelatedToCustomNumberID) {\n                  hasNumberIDRelation = true\n                }\n              },\n            )\n\n            if (hasNumberIDRelation)\n              result.value[multiIDCondition].push({\n                [path]: { [operatorKey]: parseFloat(formattedValue) },\n              })\n          }\n        }\n\n        if (result.value[multiIDCondition].length > 1) {\n          return result\n        }\n      }\n\n      if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n        const words = formattedValue.split(' ')\n\n        const result = {\n          value: {\n            $and: words.map((word) => ({\n              [path]: {\n                $options: 'i',\n                $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n              },\n            })),\n          },\n        }\n\n        return result\n      }\n\n      // Some operators like 'near' need to define a full query\n      // so if there is no operator key, just return the value\n      if (!operatorKey) {\n        return {\n          path,\n          value: formattedValue,\n        }\n      }\n\n      return {\n        path,\n        value: { [operatorKey]: formattedValue },\n      }\n    }\n  }\n  return undefined\n}\n"],"names":["ObjectIdImport","mongoose","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","ObjectId","default","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","Types","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex","undefined"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,MAAMC,WAAYN,eAAeO,OAAO,IACtCP;AAQF,MAAMQ,kBAA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oBACJ;gBACF;gBAEA,IAAImB,OAAOlB,KAAK,CAACmC,iBAAiB,CAAClC,MAAM,GAAG,GAAG;oBAC7C,OAAOiB;gBACT;YACF;YAEA,IAAIrB,sBAAsB,UAAU,OAAOE,mBAAmB,UAAU;gBACtE,MAAM0C,QAAQ1C,eAAe2C,KAAK,CAAC;gBAEnC,MAAMxB,SAAS;oBACblB,OAAO;wBACL2C,MAAMF,MAAMZ,GAAG,CAAC,CAACe,OAAU,CAAA;gCACzB,CAAChD,KAAK,EAAE;oCACNiD,UAAU;oCACVC,QAAQF,KAAK5D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOkC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLrC;oBACAI,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLH;gBACAI,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOgD;AACT"}
         | 
| 1 | 
            +
            {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { Field, Operator, PathToQuery, Payload } from 'payload'\n\nimport ObjectIdImport from 'bson-objectid'\nimport mongoose from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\nconst ObjectId = (ObjectIdImport.default ||\n  ObjectIdImport) as unknown as typeof ObjectIdImport.default\n\ntype SearchParam = {\n  path?: string\n  rawQuery?: unknown\n  value?: unknown\n}\n\nconst subQueryOptions = {\n  lean: true,\n  limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n  collectionSlug,\n  fields,\n  globalSlug,\n  incomingPath,\n  locale,\n  operator,\n  payload,\n  val,\n}: {\n  collectionSlug?: string\n  fields: Field[]\n  globalSlug?: string\n  incomingPath: string\n  locale?: string\n  operator: string\n  payload: Payload\n  val: unknown\n}): Promise<SearchParam> {\n  // Replace GraphQL nested field double underscore formatting\n  let sanitizedPath = incomingPath.replace(/__/g, '.')\n  if (sanitizedPath === 'id') {\n    sanitizedPath = '_id'\n  }\n\n  let paths: PathToQuery[] = []\n\n  let hasCustomID = false\n\n  if (sanitizedPath === '_id') {\n    const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n    let idFieldType: 'number' | 'text' = 'text'\n\n    if (customIDFieldType) {\n      idFieldType = customIDFieldType\n      hasCustomID = true\n    }\n\n    paths.push({\n      collectionSlug,\n      complete: true,\n      field: {\n        name: 'id',\n        type: idFieldType,\n      } as Field,\n      path: '_id',\n    })\n  } else {\n    paths = await getLocalizedPaths({\n      collectionSlug,\n      fields,\n      globalSlug,\n      incomingPath: sanitizedPath,\n      locale,\n      payload,\n    })\n  }\n\n  const [{ field, path }] = paths\n\n  if (path) {\n    const {\n      operator: formattedOperator,\n      rawQuery,\n      val: formattedValue,\n    } = sanitizeQueryValue({\n      field,\n      hasCustomID,\n      operator,\n      path,\n      val,\n    })\n\n    if (rawQuery) {\n      return { value: rawQuery }\n    }\n\n    // If there are multiple collections to search through,\n    // Recursively build up a list of query constraints\n    if (paths.length > 1) {\n      // Remove top collection and reverse array\n      // to work backwards from top\n      const pathsToQuery = paths.slice(1).reverse()\n\n      const initialRelationshipQuery = {\n        value: {},\n      } as SearchParam\n\n      const relationshipQuery = await pathsToQuery.reduce(\n        async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n          const priorQueryResult = await priorQuery\n\n          const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n          // On the \"deepest\" collection,\n          // Search on the value passed through the query\n          if (i === 0) {\n            const subQuery = await SubModel.buildQuery({\n              locale,\n              payload,\n              where: {\n                [subPath]: {\n                  [formattedOperator]: val,\n                },\n              },\n            })\n\n            const result = await SubModel.find(subQuery, subQueryOptions)\n\n            const $in: unknown[] = []\n\n            result.forEach((doc) => {\n              const stringID = doc._id.toString()\n              $in.push(stringID)\n\n              if (mongoose.Types.ObjectId.isValid(stringID)) {\n                $in.push(doc._id)\n              }\n            })\n\n            if (pathsToQuery.length === 1) {\n              return {\n                path,\n                value: { $in },\n              }\n            }\n\n            const nextSubPath = pathsToQuery[i + 1].path\n\n            return {\n              value: { [nextSubPath]: { $in } },\n            }\n          }\n\n          const subQuery = priorQueryResult.value\n          const result = await SubModel.find(subQuery, subQueryOptions)\n\n          const $in = result.map((doc) => doc._id.toString())\n\n          // If it is the last recursion\n          // then pass through the search param\n          if (i + 1 === pathsToQuery.length) {\n            return {\n              path,\n              value: { $in },\n            }\n          }\n\n          return {\n            value: {\n              _id: { $in },\n            },\n          }\n        },\n        Promise.resolve(initialRelationshipQuery),\n      )\n\n      return relationshipQuery\n    }\n\n    if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n      const operatorKey = operatorMap[formattedOperator]\n\n      if (field.type === 'relationship' || field.type === 'upload') {\n        let hasNumberIDRelation\n        let multiIDCondition = '$or'\n        if (operatorKey === '$ne') {\n          multiIDCondition = '$and'\n        }\n\n        const result = {\n          value: {\n            [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n          },\n        }\n\n        if (typeof formattedValue === 'string') {\n          if (mongoose.Types.ObjectId.isValid(formattedValue)) {\n            result.value[multiIDCondition].push({\n              [path]: { [operatorKey]: ObjectId(formattedValue) },\n            })\n          } else {\n            ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n              (relationTo) => {\n                const isRelatedToCustomNumberID =\n                  payload.collections[relationTo]?.customIDType === 'number'\n\n                if (isRelatedToCustomNumberID) {\n                  hasNumberIDRelation = true\n                }\n              },\n            )\n\n            if (hasNumberIDRelation) {\n              result.value[multiIDCondition].push({\n                [path]: { [operatorKey]: parseFloat(formattedValue) },\n              })\n            }\n          }\n        }\n\n        if (result.value[multiIDCondition].length > 1) {\n          return result\n        }\n      }\n\n      if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n        const words = formattedValue.split(' ')\n\n        const result = {\n          value: {\n            $and: words.map((word) => ({\n              [path]: {\n                $options: 'i',\n                $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n              },\n            })),\n          },\n        }\n\n        return result\n      }\n\n      // Some operators like 'near' need to define a full query\n      // so if there is no operator key, just return the value\n      if (!operatorKey) {\n        return {\n          path,\n          value: formattedValue,\n        }\n      }\n\n      return {\n        path,\n        value: { [operatorKey]: formattedValue },\n      }\n    }\n  }\n  return undefined\n}\n"],"names":["ObjectIdImport","mongoose","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","ObjectId","default","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","Types","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex","undefined"],"mappings":"AAEA,OAAOA,oBAAoB,gBAAe;AAC1C,OAAOC,cAAc,WAAU;AAC/B,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,MAAMC,WAAYN,eAAeO,OAAO,IACtCP;AAQF,MAAMQ,kBAAkB;IACtBC,MAAM;IACNC,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACN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iBAAiB,CAAClC,MAAM,GAAG,GAAG;oBAC7C,OAAOiB;gBACT;YACF;YAEA,IAAIrB,sBAAsB,UAAU,OAAOE,mBAAmB,UAAU;gBACtE,MAAM0C,QAAQ1C,eAAe2C,KAAK,CAAC;gBAEnC,MAAMxB,SAAS;oBACblB,OAAO;wBACL2C,MAAMF,MAAMZ,GAAG,CAAC,CAACe,OAAU,CAAA;gCACzB,CAAChD,KAAK,EAAE;oCACNiD,UAAU;oCACVC,QAAQF,KAAK5D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOkC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACe,aAAa;gBAChB,OAAO;oBACLrC;oBACAI,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLH;gBACAI,OAAO;oBAAE,CAACiC,YAAY,EAAElC;gBAAe;YACzC;QACF;IACF;IACA,OAAOgD;AACT"}
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n  beforeAll(async () => {\n    config = await sanitizeConfig({\n      localization: {\n        defaultLocale: 'en',\n        fallback: true,\n        locales: ['en', 'es'],\n      },\n    } as Config)\n  })\n  it('passes through a non-localized sort property',  | 
| 1 | 
            +
            {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n  beforeAll(async () => {\n    config = await sanitizeConfig({\n      localization: {\n        defaultLocale: 'en',\n        fallback: true,\n        locales: ['en', 'es'],\n      },\n    } as Config)\n  })\n  it('passes through a non-localized sort property', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          name: 'title',\n          type: 'text',\n        },\n      ],\n      locale: 'en',\n      segments: ['title'],\n    })\n\n    expect(result).toStrictEqual('title')\n  })\n\n  it('properly localizes an un-localized sort property', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          name: 'title',\n          type: 'text',\n          localized: true,\n        },\n      ],\n      locale: 'en',\n      segments: ['title'],\n    })\n\n    expect(result).toStrictEqual('title.en')\n  })\n\n  it('keeps specifically asked-for localized sort properties', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          name: 'title',\n          type: 'text',\n          localized: true,\n        },\n      ],\n      locale: 'en',\n      segments: ['title', 'es'],\n    })\n\n    expect(result).toStrictEqual('title.es')\n  })\n\n  it('properly localizes nested sort properties', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          name: 'group',\n          type: 'group',\n          fields: [\n            {\n              name: 'title',\n              type: 'text',\n              localized: true,\n            },\n          ],\n        },\n      ],\n      locale: 'en',\n      segments: ['group', 'title'],\n    })\n\n    expect(result).toStrictEqual('group.title.en')\n  })\n\n  it('keeps requested locale with nested sort properties', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          name: 'group',\n          type: 'group',\n          fields: [\n            {\n              name: 'title',\n              type: 'text',\n              localized: true,\n            },\n          ],\n        },\n      ],\n      locale: 'en',\n      segments: ['group', 'title', 'es'],\n    })\n\n    expect(result).toStrictEqual('group.title.es')\n  })\n\n  it('properly localizes field within row', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          type: 'row',\n          fields: [\n            {\n              name: 'title',\n              type: 'text',\n              localized: true,\n            },\n          ],\n        },\n      ],\n      locale: 'en',\n      segments: ['title'],\n    })\n\n    expect(result).toStrictEqual('title.en')\n  })\n\n  it('properly localizes field within named tab', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          type: 'tabs',\n          tabs: [\n            {\n              name: 'tab',\n              fields: [\n                {\n                  name: 'title',\n                  type: 'text',\n                  localized: true,\n                },\n              ],\n            },\n          ],\n        },\n      ],\n      locale: 'en',\n      segments: ['tab', 'title'],\n    })\n\n    expect(result).toStrictEqual('tab.title.en')\n  })\n\n  it('properly localizes field within unnamed tab', () => {\n    const result = getLocalizedSortProperty({\n      config,\n      fields: [\n        {\n          type: 'tabs',\n          tabs: [\n            {\n              fields: [\n                {\n                  name: 'title',\n                  type: 'text',\n                  localized: true,\n                },\n              ],\n              label: 'Tab',\n            },\n          ],\n        },\n      ],\n      locale: 'en',\n      segments: ['title'],\n    })\n\n    expect(result).toStrictEqual('title.en')\n  })\n})\n"],"names":["sanitizeConfig","getLocalizedSortProperty","config","describe","beforeAll","localization","defaultLocale","fallback","locales","it","result","fields","name","type","locale","segments","expect","toStrictEqual","localized","tabs","label"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAExC,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJC,SAAS,+BAA+B;IACtCC,UAAU;QACRF,SAAS,MAAMF,eAAe;YAC5BK,cAAc;gBACZC,eAAe;gBACfC,UAAU;gBACVC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;IACF;IACAC,GAAG,gDAAgD;QACjD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,oDAAoD;QACrD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNK,WAAW;gBACb;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,C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NK,WAAW;gCACb;6BACD;wBACH;qBACD;gBACH;aACD;YACDJ,QAAQ;YACRC,UAAU;gBAAC;gBAAO;aAAQ;QAC5B;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;IAEAR,GAAG,+CAA+C;QAChD,MAAMC,SAAST,yBAAyB;YACtCC;YACAS,QAAQ;gBACN;oBACEE,MAAM;oBACNM,MAAM;wBACJ;4BACER,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNK,WAAW;gCACb;6BACD;4BACDE,OAAO;wBACT;qBACD;gBACH;aACD;YACDN,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAC,OAAON,QAAQO,aAAa,CAAC;IAC/B;AACF"}
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQ9D,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC, | 
| 1 | 
            +
            {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQ9D,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA4DnC"}
         | 
| @@ -23,7 +23,9 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale, | |
| 23 23 | 
             
                                payload,
         | 
| 24 24 | 
             
                                where: condition
         | 
| 25 25 | 
             
                            });
         | 
| 26 | 
            -
                            if (builtConditions.length > 0)  | 
| 26 | 
            +
                            if (builtConditions.length > 0) {
         | 
| 27 | 
            +
                                result[conditionOperator] = builtConditions;
         | 
| 28 | 
            +
                            }
         | 
| 27 29 | 
             
                        } else {
         | 
| 28 30 | 
             
                            // It's a path - and there can be multiple comparisons on a single path.
         | 
| 29 31 | 
             
                            // For example - title like 'test' and title not equal to 'tester'
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n  collectionSlug,\n  fields,\n  globalSlug,\n  locale,\n  payload,\n  where,\n}: {\n  collectionSlug?: string\n  fields: Field[]\n  globalSlug?: string\n  locale: string\n  payload: Payload\n  where: Where\n}): Promise<Record<string, unknown>> {\n  let result = {} as FilterQuery<any>\n\n  if (typeof where === 'object') {\n    // We need to determine if the whereKey is an AND, OR, or a schema path\n    for (const relationOrPath of Object.keys(where)) {\n      const condition = where[relationOrPath]\n      let conditionOperator: '$and' | '$or'\n      if (relationOrPath.toLowerCase() === 'and') {\n        conditionOperator = '$and'\n      } else if (relationOrPath.toLowerCase() === 'or') {\n        conditionOperator = '$or'\n      }\n      if (Array.isArray(condition)) {\n        const builtConditions = await buildAndOrConditions({\n          collectionSlug,\n          fields,\n          globalSlug,\n          locale,\n          payload,\n          where: condition,\n        })\n        if (builtConditions.length > 0) result[conditionOperator] = builtConditions\n      } else {\n        // It's a path - and there can be multiple comparisons on a single path.\n        // For example - title like 'test' and title not equal to 'tester'\n        // So we need to loop on keys again here to handle each operator independently\n        const pathOperators = where[relationOrPath]\n        if (typeof pathOperators === 'object') {\n          for (const operator of Object.keys(pathOperators)) {\n            if (validOperators.includes(operator as Operator)) {\n              const searchParam = await buildSearchParam({\n                collectionSlug,\n                fields,\n                globalSlug,\n                incomingPath: relationOrPath,\n                locale,\n                operator,\n                payload,\n                val: pathOperators[operator],\n              })\n\n              if (searchParam?.value && searchParam?.path) {\n                result = {\n                  ...result,\n                  [searchParam.path]: searchParam.value,\n                }\n              } else if (typeof searchParam?.value === 'object') {\n                result = deepMergeWithCombinedArrays(result, searchParam.value)\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n\n  return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG, | 
| 1 | 
            +
            {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n  collectionSlug,\n  fields,\n  globalSlug,\n  locale,\n  payload,\n  where,\n}: {\n  collectionSlug?: string\n  fields: Field[]\n  globalSlug?: string\n  locale: string\n  payload: Payload\n  where: Where\n}): Promise<Record<string, unknown>> {\n  let result = {} as FilterQuery<any>\n\n  if (typeof where === 'object') {\n    // We need to determine if the whereKey is an AND, OR, or a schema path\n    for (const relationOrPath of Object.keys(where)) {\n      const condition = where[relationOrPath]\n      let conditionOperator: '$and' | '$or'\n      if (relationOrPath.toLowerCase() === 'and') {\n        conditionOperator = '$and'\n      } else if (relationOrPath.toLowerCase() === 'or') {\n        conditionOperator = '$or'\n      }\n      if (Array.isArray(condition)) {\n        const builtConditions = await buildAndOrConditions({\n          collectionSlug,\n          fields,\n          globalSlug,\n          locale,\n          payload,\n          where: condition,\n        })\n        if (builtConditions.length > 0) {\n          result[conditionOperator] = builtConditions\n        }\n      } else {\n        // It's a path - and there can be multiple comparisons on a single path.\n        // For example - title like 'test' and title not equal to 'tester'\n        // So we need to loop on keys again here to handle each operator independently\n        const pathOperators = where[relationOrPath]\n        if (typeof pathOperators === 'object') {\n          for (const operator of Object.keys(pathOperators)) {\n            if (validOperators.includes(operator as Operator)) {\n              const searchParam = await buildSearchParam({\n                collectionSlug,\n                fields,\n                globalSlug,\n                incomingPath: relationOrPath,\n                locale,\n                operator,\n                payload,\n                val: pathOperators[operator],\n              })\n\n              if (searchParam?.value && searchParam?.path) {\n                result = {\n                  ...result,\n                  [searchParam.path]: searchParam.value,\n                }\n              } else if (typeof searchParam?.value === 'object') {\n                result = deepMergeWithCombinedArrays(result, searchParam.value)\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n\n  return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAG;oBAC9BV,MAAM,CAACK,kBAAkB,GAAGI;gBAC9B;YACF,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAIrB,eAAeuB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMtB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAmB,cAAcd;gCACdJ;gCACAe;gCACAd;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASX,4BAA4BW,QAAQc,YAAYG,KAAK;4BAChE;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOjB;AACT"}
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKhD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA; | 
| 1 | 
            +
            {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKhD,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,KAAK,GAAG,UAAU,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAED,eAAO,MAAM,kBAAkB,iDAM5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CA2Kd,CAAA"}
         | 
| @@ -26,8 +26,12 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })= | |
| 26 26 | 
             
                }
         | 
| 27 27 | 
             
                // Cast incoming values as proper searchable types
         | 
| 28 28 | 
             
                if (field.type === 'checkbox' && typeof val === 'string') {
         | 
| 29 | 
            -
                    if (val.toLowerCase() === 'true')  | 
| 30 | 
            -
             | 
| 29 | 
            +
                    if (val.toLowerCase() === 'true') {
         | 
| 30 | 
            +
                        formattedValue = true;
         | 
| 31 | 
            +
                    }
         | 
| 32 | 
            +
                    if (val.toLowerCase() === 'false') {
         | 
| 33 | 
            +
                        formattedValue = false;
         | 
| 34 | 
            +
                    }
         | 
| 31 35 | 
             
                }
         | 
| 32 36 | 
             
                if ([
         | 
| 33 37 | 
             
                    'all',
         | 
| @@ -79,9 +83,13 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })= | |
| 79 83 | 
             
                            const newValues = [
         | 
| 80 84 | 
             
                                inVal
         | 
| 81 85 | 
             
                            ];
         | 
| 82 | 
            -
                            if (mongoose.Types.ObjectId.isValid(inVal))  | 
| 86 | 
            +
                            if (mongoose.Types.ObjectId.isValid(inVal)) {
         | 
| 87 | 
            +
                                newValues.push(new mongoose.Types.ObjectId(inVal));
         | 
| 88 | 
            +
                            }
         | 
| 83 89 | 
             
                            const parsedNumber = parseFloat(inVal);
         | 
| 84 | 
            -
                            if (!Number.isNaN(parsedNumber))  | 
| 90 | 
            +
                            if (!Number.isNaN(parsedNumber)) {
         | 
| 91 | 
            +
                                newValues.push(parsedNumber);
         | 
| 92 | 
            +
                            }
         | 
| 85 93 | 
             
                            return [
         | 
| 86 94 | 
             
                                ...formattedValues,
         | 
| 87 95 | 
             
                                ...newValues
         | 
| @@ -113,8 +121,12 @@ export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })= | |
| 113 121 | 
             
                                ]
         | 
| 114 122 | 
             
                            }
         | 
| 115 123 | 
             
                        };
         | 
| 116 | 
            -
                        if (maxDistance)  | 
| 117 | 
            -
             | 
| 124 | 
            +
                        if (maxDistance) {
         | 
| 125 | 
            +
                            formattedValue.$maxDistance = parseFloat(maxDistance);
         | 
| 126 | 
            +
                        }
         | 
| 127 | 
            +
                        if (minDistance) {
         | 
| 128 | 
            +
                            formattedValue.$minDistance = parseFloat(minDistance);
         | 
| 129 | 
            +
                        }
         | 
| 118 130 | 
             
                    }
         | 
| 119 131 | 
             
                }
         | 
| 120 132 | 
             
                if (operator === 'within' || operator === 'intersects') {
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n  field: Field | TabAsField\n  hasCustomID: boolean\n  operator: string\n  path: string\n  val: any\n}\n\nexport const sanitizeQueryValue = ({\n  field,\n  hasCustomID,\n  operator,\n  path,\n  val,\n}: SanitizeQueryValueArgs): {\n  operator?: string\n  rawQuery?: unknown\n  val?: unknown\n} => {\n  let formattedValue = val\n  let formattedOperator = operator\n\n  // Disregard invalid _ids\n  if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {\n    if (!hasCustomID) {\n      const isValid = mongoose.Types.ObjectId.isValid(val)\n\n      if (!isValid) {\n        return { operator: formattedOperator, val: undefined }\n      }\n    }\n\n    if (field.type === 'number') {\n      const parsedNumber = parseFloat(val)\n\n      if (Number.isNaN(parsedNumber)) {\n        return { operator: formattedOperator, val: undefined }\n      }\n    }\n  }\n\n  // Cast incoming values as proper searchable types\n  if (field.type === 'checkbox' && typeof val === 'string') {\n    if (val.toLowerCase() === 'true') formattedValue = true\n    if (val.toLowerCase() === 'false') formattedValue = false\n  }\n\n  if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n    formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n    if (field.type === 'number') {\n      formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n    }\n  }\n\n  if (field.type === 'number' && typeof formattedValue === 'string') {\n    formattedValue = Number(val)\n  }\n\n  if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n    formattedValue = new Date(val)\n    if (Number.isNaN(Date.parse(formattedValue))) {\n      return undefined\n    }\n  }\n\n  if (['relationship', 'upload'].includes(field.type)) {\n    if (val === 'null') {\n      formattedValue = null\n    }\n\n    // Object equality requires the value to be the first key in the object that is being queried.\n    if (\n      operator === 'equals' &&\n      formattedValue &&\n      typeof formattedValue === 'object' &&\n      formattedValue.value &&\n      formattedValue.relationTo\n    ) {\n      return {\n        rawQuery: {\n          $and: [\n            { [`${path}.value`]: { $eq: formattedValue.value } },\n            { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n          ],\n        },\n      }\n    }\n\n    if (operator === 'in' && Array.isArray(formattedValue)) {\n      formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n        const newValues = [inVal]\n        if (mongoose.Types.ObjectId.isValid(inVal))\n          newValues.push(new mongoose.Types.ObjectId(inVal))\n\n        const parsedNumber = parseFloat(inVal)\n        if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber)\n\n        return [...formattedValues, ...newValues]\n      }, [])\n    }\n  }\n\n  // Set up specific formatting necessary by operators\n\n  if (operator === 'near') {\n    let lng\n    let lat\n    let maxDistance\n    let minDistance\n\n    if (Array.isArray(formattedValue)) {\n      ;[lng, lat, maxDistance, minDistance] = formattedValue\n    }\n\n    if (typeof formattedValue === 'string') {\n      ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n    }\n\n    if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n      formattedValue = undefined\n    } else {\n      formattedValue = {\n        $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n      }\n\n      if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance)\n      if (minDistance) formattedValue.$minDistance = parseFloat(minDistance)\n    }\n  }\n\n  if (operator === 'within' || operator === 'intersects') {\n    formattedValue = {\n      $geometry: formattedValue,\n    }\n  }\n\n  if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n    if (operator === 'contains') {\n      formattedValue = {\n        $options: 'i',\n        $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n      }\n    }\n  }\n\n  if (\n    (path === '_id' || path === 'parent') &&\n    operator === 'like' &&\n    formattedValue.length === 24 &&\n    !hasCustomID\n  ) {\n    formattedOperator = 'equals'\n  }\n\n  if (operator === 'exists') {\n    formattedValue = formattedValue === 'true' || formattedValue === true\n\n    // Clearable fields\n    if (['relationship', 'select', 'upload'].includes(field.type)) {\n      if (formattedValue) {\n        return {\n          rawQuery: {\n            $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n          },\n        }\n      } else {\n        return {\n          rawQuery: {\n            $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n          },\n        }\n      }\n    }\n  }\n\n  return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["mongoose","createArrayFromCommaDelineated","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","ObjectId","undefined","type","parsedNumber","parseFloat","Number","isNaN","toLowerCase","includes","map","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","Array","isArray","reduce","formattedValues","inVal","newValues","push","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,SAAS,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,KAAKC,MAAM,KAAK,GAAG;QAC5E,IAAI,CAACP,aAAa;YAChB,MAAMQ,UAAUZ,SAASa,KAAK,CAACC,QAAQ,CAACF,OAAO,CAACL;YAEhD,IAAI,CAACK,SAAS;gBACZ,OAAO;oBAAEP,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;QAEA,IAAIZ,MAAMa,IAAI,KAAK,UAAU;YAC3B,MAAMC,eAAeC,WAAWX;YAEhC,IAAIY,OAAOC,KAAK,CAACH,eAAe;gBAC9B,OAAO;oBAAEZ,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;IACF;IAEA,kDAAkD;IAClD,IAAIZ,MAAMa,IAAI,KAAK,cAAc,OAAOT,QAAQ,UAAU;QACxD,IAAIA,IAAIc,WAAW,OAAO, | 
| 1 | 
            +
            {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n  field: Field | TabAsField\n  hasCustomID: boolean\n  operator: string\n  path: string\n  val: any\n}\n\nexport const sanitizeQueryValue = ({\n  field,\n  hasCustomID,\n  operator,\n  path,\n  val,\n}: SanitizeQueryValueArgs): {\n  operator?: string\n  rawQuery?: unknown\n  val?: unknown\n} => {\n  let formattedValue = val\n  let formattedOperator = operator\n\n  // Disregard invalid _ids\n  if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {\n    if (!hasCustomID) {\n      const isValid = mongoose.Types.ObjectId.isValid(val)\n\n      if (!isValid) {\n        return { operator: formattedOperator, val: undefined }\n      }\n    }\n\n    if (field.type === 'number') {\n      const parsedNumber = parseFloat(val)\n\n      if (Number.isNaN(parsedNumber)) {\n        return { operator: formattedOperator, val: undefined }\n      }\n    }\n  }\n\n  // Cast incoming values as proper searchable types\n  if (field.type === 'checkbox' && typeof val === 'string') {\n    if (val.toLowerCase() === 'true') {\n      formattedValue = true\n    }\n    if (val.toLowerCase() === 'false') {\n      formattedValue = false\n    }\n  }\n\n  if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n    formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n    if (field.type === 'number') {\n      formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n    }\n  }\n\n  if (field.type === 'number' && typeof formattedValue === 'string') {\n    formattedValue = Number(val)\n  }\n\n  if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n    formattedValue = new Date(val)\n    if (Number.isNaN(Date.parse(formattedValue))) {\n      return undefined\n    }\n  }\n\n  if (['relationship', 'upload'].includes(field.type)) {\n    if (val === 'null') {\n      formattedValue = null\n    }\n\n    // Object equality requires the value to be the first key in the object that is being queried.\n    if (\n      operator === 'equals' &&\n      formattedValue &&\n      typeof formattedValue === 'object' &&\n      formattedValue.value &&\n      formattedValue.relationTo\n    ) {\n      return {\n        rawQuery: {\n          $and: [\n            { [`${path}.value`]: { $eq: formattedValue.value } },\n            { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n          ],\n        },\n      }\n    }\n\n    if (operator === 'in' && Array.isArray(formattedValue)) {\n      formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n        const newValues = [inVal]\n        if (mongoose.Types.ObjectId.isValid(inVal)) {\n          newValues.push(new mongoose.Types.ObjectId(inVal))\n        }\n\n        const parsedNumber = parseFloat(inVal)\n        if (!Number.isNaN(parsedNumber)) {\n          newValues.push(parsedNumber)\n        }\n\n        return [...formattedValues, ...newValues]\n      }, [])\n    }\n  }\n\n  // Set up specific formatting necessary by operators\n\n  if (operator === 'near') {\n    let lng\n    let lat\n    let maxDistance\n    let minDistance\n\n    if (Array.isArray(formattedValue)) {\n      ;[lng, lat, maxDistance, minDistance] = formattedValue\n    }\n\n    if (typeof formattedValue === 'string') {\n      ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n    }\n\n    if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n      formattedValue = undefined\n    } else {\n      formattedValue = {\n        $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n      }\n\n      if (maxDistance) {\n        formattedValue.$maxDistance = parseFloat(maxDistance)\n      }\n      if (minDistance) {\n        formattedValue.$minDistance = parseFloat(minDistance)\n      }\n    }\n  }\n\n  if (operator === 'within' || operator === 'intersects') {\n    formattedValue = {\n      $geometry: formattedValue,\n    }\n  }\n\n  if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n    if (operator === 'contains') {\n      formattedValue = {\n        $options: 'i',\n        $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n      }\n    }\n  }\n\n  if (\n    (path === '_id' || path === 'parent') &&\n    operator === 'like' &&\n    formattedValue.length === 24 &&\n    !hasCustomID\n  ) {\n    formattedOperator = 'equals'\n  }\n\n  if (operator === 'exists') {\n    formattedValue = formattedValue === 'true' || formattedValue === true\n\n    // Clearable fields\n    if (['relationship', 'select', 'upload'].includes(field.type)) {\n      if (formattedValue) {\n        return {\n          rawQuery: {\n            $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n          },\n        }\n      } else {\n        return {\n          rawQuery: {\n            $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n          },\n        }\n      }\n    }\n  }\n\n  return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["mongoose","createArrayFromCommaDelineated","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","ObjectId","undefined","type","parsedNumber","parseFloat","Number","isNaN","toLowerCase","includes","map","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","Array","isArray","reduce","formattedValues","inVal","newValues","push","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,SAAS,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,KAAKC,MAAM,KAAK,GAAG;QAC5E,IAAI,CAACP,aAAa;YAChB,MAAMQ,UAAUZ,SAASa,KAAK,CAACC,QAAQ,CAACF,OAAO,CAACL;YAEhD,IAAI,CAACK,SAAS;gBACZ,OAAO;oBAAEP,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;QAEA,IA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BACflC,eAAesC,YAAY,GAAG5B,WAAWwB;YAC3C;QACF;IACF;IAEA,IAAIrC,aAAa,YAAYA,aAAa,cAAc;QACtDG,iBAAiB;YACfmC,WAAWnC;QACb;IACF;IAEA,IAAIF,SAAS,SAAUA,SAAS,SAASF,eAAeD,MAAMa,IAAI,KAAK,QAAS;QAC9E,IAAIX,aAAa,YAAY;YAC3BG,iBAAiB;gBACfuC,UAAU;gBACVC,QAAQxC,eAAeyC,OAAO,CAAC,uBAAuB;YACxD;QACF;IACF;IAEA,IACE,AAAC3C,CAAAA,SAAS,SAASA,SAAS,QAAO,KACnCD,aAAa,UACbG,eAAeG,MAAM,KAAK,MAC1B,CAACP,aACD;QACAK,oBAAoB;IACtB;IAEA,IAAIJ,aAAa,UAAU;QACzBG,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACc,QAAQ,CAACnB,MAAMa,IAAI,GAAG;YAC7D,IAAIR,gBAAgB;gBAClB,OAAO;oBACLqB,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACxB,KAAK,EAAE;oCAAE4C,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAE6C,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLtB,UAAU;wBACRuB,KAAK;4BAAC;gCAAE,CAAC9C,KAAK,EAAE;oCAAE4C,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAEyB,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAE1B,UAAUI;QAAmBF,KAAKC;IAAe;AAC5D,EAAC"}
         | 
    
        package/dist/queryDrafts.js
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            import { combineQueries, flattenWhereToOperators } from 'payload';
         | 
| 2 2 | 
             
            import { buildSortParam } from './queries/buildSortParam.js';
         | 
| 3 | 
            -
            import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
         | 
| 3 | 
            +
            import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
         | 
| 4 4 | 
             
            import { withSession } from './withSession.js';
         | 
| 5 5 | 
             
            export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
         | 
| 6 6 | 
             
                const VersionModel = this.versions[collection];
         | 
    
        package/dist/queryDrafts.js.map
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n  this: MongooseAdapter,\n  { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n  const VersionModel = this.versions[collection]\n  const collectionConfig = this.payload.collections[collection].config\n  const options = await withSession(this, req)\n\n  let hasNearConstraint\n  let sort\n\n  if (where) {\n    const constraints = flattenWhereToOperators(where)\n    hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n  }\n\n  if (!hasNearConstraint) {\n    sort = buildSortParam({\n      config: this.payload.config,\n      fields: collectionConfig.fields,\n      locale,\n      sort: sortArg || collectionConfig.defaultSort,\n      timestamps: true,\n    })\n  }\n\n  const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n  const versionQuery = await VersionModel.buildQuery({\n    locale,\n    payload: this.payload,\n    where: combinedWhere,\n  })\n\n  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n  const useEstimatedCount =\n    hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n  const paginationOptions: PaginateOptions = {\n    forceCountFn: hasNearConstraint,\n    lean: true,\n    leanWithId: true,\n    options,\n    page,\n    pagination,\n    sort,\n    useEstimatedCount,\n  }\n\n  if (this.collation) {\n    const defaultLocale = 'en'\n    paginationOptions.collation = {\n      locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n      ...this.collation,\n    }\n  }\n\n  if (\n    !useEstimatedCount &&\n    Object.keys(versionQuery).length === 0 &&\n    this.disableIndexHints !== true\n  ) {\n    // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n    // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n    // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n    // the correct indexed field\n    paginationOptions.useCustomCountFn = () => {\n      return Promise.resolve(\n        VersionModel.countDocuments(versionQuery, {\n          hint: { _id: 1 },\n        }),\n      )\n    }\n  }\n\n  if (limit > 0) {\n    paginationOptions.limit = limit\n    // limit must also be set here, it's ignored when pagination is false\n    paginationOptions.options.limit = limit\n  }\n\n  const result = await VersionModel.paginate(versionQuery, paginationOptions)\n  const docs = JSON.parse(JSON.stringify(result.docs))\n\n  return {\n    ...result,\n    docs: docs.map((doc) => {\n      doc = {\n        _id: doc.parent,\n        id: doc.parent,\n        ...doc.version,\n        createdAt: doc.createdAt,\n        updatedAt: doc.updatedAt,\n      }\n\n      return sanitizeInternalFields(doc)\n    }),\n  }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D, | 
| 1 | 
            +
            {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n  this: MongooseAdapter,\n  { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n  const VersionModel = this.versions[collection]\n  const collectionConfig = this.payload.collections[collection].config\n  const options = await withSession(this, req)\n\n  let hasNearConstraint\n  let sort\n\n  if (where) {\n    const constraints = flattenWhereToOperators(where)\n    hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n  }\n\n  if (!hasNearConstraint) {\n    sort = buildSortParam({\n      config: this.payload.config,\n      fields: collectionConfig.fields,\n      locale,\n      sort: sortArg || collectionConfig.defaultSort,\n      timestamps: true,\n    })\n  }\n\n  const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n  const versionQuery = await VersionModel.buildQuery({\n    locale,\n    payload: this.payload,\n    where: combinedWhere,\n  })\n\n  // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n  const useEstimatedCount =\n    hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n  const paginationOptions: PaginateOptions = {\n    forceCountFn: hasNearConstraint,\n    lean: true,\n    leanWithId: true,\n    options,\n    page,\n    pagination,\n    sort,\n    useEstimatedCount,\n  }\n\n  if (this.collation) {\n    const defaultLocale = 'en'\n    paginationOptions.collation = {\n      locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n      ...this.collation,\n    }\n  }\n\n  if (\n    !useEstimatedCount &&\n    Object.keys(versionQuery).length === 0 &&\n    this.disableIndexHints !== true\n  ) {\n    // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n    // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n    // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n    // the correct indexed field\n    paginationOptions.useCustomCountFn = () => {\n      return Promise.resolve(\n        VersionModel.countDocuments(versionQuery, {\n          hint: { _id: 1 },\n        }),\n      )\n    }\n  }\n\n  if (limit > 0) {\n    paginationOptions.limit = limit\n    // limit must also be set here, it's ignored when pagination is false\n    paginationOptions.options.limit = limit\n  }\n\n  const result = await VersionModel.paginate(versionQuery, paginationOptions)\n  const docs = JSON.parse(JSON.stringify(result.docs))\n\n  return {\n    ...result,\n    docs: docs.map((doc) => {\n      doc = {\n        _id: doc.parent,\n        id: doc.parent,\n        ...doc.version,\n        createdAt: doc.createdAt,\n        updatedAt: doc.updatedAt,\n      }\n\n      return sanitizeInternalFields(doc)\n    }),\n  }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAAS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AAG;YAC5BnC,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASoC;YAChE,GAAG,IAAI,CAACD,SAAS;QACnB;IACF;IAEA,IACE,CAACN,qBACDX,OAAOC,IAAI,CAACQ,cAAcG,MAAM,KAAK,KACrC,IAAI,CAACO,iBAAiB,KAAK,MAC3B;QACA,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBjC,aAAakC,cAAc,CAACd,cAAc;gBACxCe,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,QAAQ,GAAG;QACbgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBlB,OAAO,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM6C,SAAS,MAAMrC,aAAasC,QAAQ,CAAClB,cAAcI;IACzD,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO7D,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA; | 
| 1 | 
            +
            {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAS/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
         | 
| @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            import { APIError } from 'payload';
         | 
| 2 2 | 
             
            import { v4 as uuid } from 'uuid';
         | 
| 3 | 
            +
            // Needs await to fulfill the interface
         | 
| 4 | 
            +
            // eslint-disable-next-line @typescript-eslint/require-await
         | 
| 3 5 | 
             
            export const beginTransaction = async function beginTransaction(options) {
         | 
| 4 6 | 
             
                if (!this.connection) {
         | 
| 5 7 | 
             
                    throw new APIError('beginTransaction called while no connection to the database exists');
         |