payload 3.72.0-canary.2 → 3.72.0-canary.3
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/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +19 -4
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/endpoints/create.d.ts.map +1 -1
- package/dist/collections/endpoints/create.js +2 -1
- package/dist/collections/endpoints/create.js.map +1 -1
- package/dist/collections/endpoints/update.d.ts.map +1 -1
- package/dist/collections/endpoints/update.js +3 -1
- package/dist/collections/endpoints/update.js.map +1 -1
- package/dist/collections/endpoints/updateByID.d.ts.map +1 -1
- package/dist/collections/endpoints/updateByID.js +4 -2
- package/dist/collections/endpoints/updateByID.js.map +1 -1
- package/dist/collections/operations/create.d.ts +1 -0
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +23 -3
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +10 -1
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/local/create.d.ts +4 -0
- package/dist/collections/operations/local/create.d.ts.map +1 -1
- package/dist/collections/operations/local/create.js +2 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +12 -0
- package/dist/collections/operations/local/update.d.ts.map +1 -1
- package/dist/collections/operations/local/update.js +3 -1
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/update.d.ts +2 -0
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +4 -3
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts +2 -0
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +4 -3
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts +4 -3
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +81 -31
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/types.d.ts +16 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/migrations/templates/localizeStatus.d.ts +10 -0
- package/dist/database/migrations/templates/localizeStatus.d.ts.map +1 -0
- package/dist/database/migrations/templates/localizeStatus.js +54 -0
- package/dist/database/migrations/templates/localizeStatus.js.map +1 -0
- package/dist/exports/migrations.d.ts +19 -0
- package/dist/exports/migrations.d.ts.map +1 -0
- package/dist/exports/migrations.js +19 -0
- package/dist/exports/migrations.js.map +1 -0
- package/dist/exports/shared.d.ts +1 -1
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +1 -1
- package/dist/exports/shared.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +11 -1
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/endpoints/update.d.ts.map +1 -1
- package/dist/globals/endpoints/update.js +5 -1
- package/dist/globals/endpoints/update.js.map +1 -1
- package/dist/globals/operations/findOne.d.ts.map +1 -1
- package/dist/globals/operations/findOne.js +9 -1
- package/dist/globals/operations/findOne.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts +10 -0
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js +4 -2
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/globals/operations/update.d.ts +2 -0
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +63 -15
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.bundled.d.ts +102 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utilities/getVersionsConfig.d.ts +4 -0
- package/dist/utilities/getVersionsConfig.d.ts.map +1 -1
- package/dist/utilities/getVersionsConfig.js +7 -2
- package/dist/utilities/getVersionsConfig.js.map +1 -1
- package/dist/utilities/mergeLocalizedData.d.ts +20 -0
- package/dist/utilities/mergeLocalizedData.d.ts.map +1 -0
- package/dist/utilities/mergeLocalizedData.js +277 -0
- package/dist/utilities/mergeLocalizedData.js.map +1 -0
- package/dist/utilities/mergeLocalizedData.spec.js +784 -0
- package/dist/utilities/mergeLocalizedData.spec.js.map +1 -0
- package/dist/utilities/miniChalk.d.ts +15 -0
- package/dist/utilities/miniChalk.d.ts.map +1 -0
- package/dist/utilities/miniChalk.js +34 -0
- package/dist/utilities/miniChalk.js.map +1 -0
- package/dist/utilities/parseParams/index.d.ts +24 -20
- package/dist/utilities/parseParams/index.d.ts.map +1 -1
- package/dist/utilities/parseParams/index.js.map +1 -1
- package/dist/utilities/traverseForLocalizedFields.d.ts +3 -0
- package/dist/utilities/traverseForLocalizedFields.d.ts.map +1 -0
- package/dist/utilities/traverseForLocalizedFields.js +41 -0
- package/dist/utilities/traverseForLocalizedFields.js.map +1 -0
- package/dist/versions/baseFields.d.ts +3 -1
- package/dist/versions/baseFields.d.ts.map +1 -1
- package/dist/versions/baseFields.js +16 -15
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js +28 -2
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
- package/dist/versions/migrations/localizeStatus/index.d.ts +12 -0
- package/dist/versions/migrations/localizeStatus/index.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/index.js +33 -0
- package/dist/versions/migrations/localizeStatus/index.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.d.ts +9 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.js +112 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.d.ts +8 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.js +8 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.d.ts +9 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.js +220 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/shared.d.ts +59 -0
- package/dist/versions/migrations/localizeStatus/shared.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/shared.js +122 -0
- package/dist/versions/migrations/localizeStatus/shared.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/down.d.ts +11 -0
- package/dist/versions/migrations/localizeStatus/sql/down.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/down.js +213 -0
- package/dist/versions/migrations/localizeStatus/sql/down.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/index.d.ts +8 -0
- package/dist/versions/migrations/localizeStatus/sql/index.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/index.js +8 -0
- package/dist/versions/migrations/localizeStatus/sql/index.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts +13 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js +51 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts +13 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js +54 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/up.d.ts +11 -0
- package/dist/versions/migrations/localizeStatus/sql/up.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/up.js +277 -0
- package/dist/versions/migrations/localizeStatus/sql/up.js.map +1 -0
- package/dist/versions/saveSnapshot.d.ts.map +1 -1
- package/dist/versions/saveSnapshot.js +0 -1
- package/dist/versions/saveSnapshot.js.map +1 -1
- package/dist/versions/saveVersion.js +0 -3
- package/dist/versions/saveVersion.js.map +1 -1
- package/dist/versions/types.d.ts +18 -0
- package/dist/versions/types.d.ts.map +1 -1
- package/dist/versions/types.js.map +1 -1
- package/package.json +8 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EAG1B,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EAG1B,MAAM,YAAY,CAAA;AAyBnB,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,wBAC1D,MAAM,EAAE,KAC7B,OAAO,CAAC,yBAAyB,CAgRnC,CAAA"}
|
|
@@ -8,6 +8,8 @@ import { uploadCollectionEndpoints } from '../../uploads/endpoints/index.js';
|
|
|
8
8
|
import { getBaseUploadFields } from '../../uploads/getBaseFields.js';
|
|
9
9
|
import { flattenAllFields } from '../../utilities/flattenAllFields.js';
|
|
10
10
|
import { formatLabels } from '../../utilities/formatLabels.js';
|
|
11
|
+
import { miniChalk } from '../../utilities/miniChalk.js';
|
|
12
|
+
import { traverseForLocalizedFields } from '../../utilities/traverseForLocalizedFields.js';
|
|
11
13
|
import { baseVersionFields } from '../../versions/baseFields.js';
|
|
12
14
|
import { versionDefaults } from '../../versions/defaults.js';
|
|
13
15
|
import { defaultCollectionEndpoints } from '../endpoints/index.js';
|
|
@@ -124,15 +126,15 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
124
126
|
singular: sanitized.labels?.singular || defaultLabels.singular
|
|
125
127
|
};
|
|
126
128
|
if (sanitized.versions) {
|
|
129
|
+
if (sanitized.timestamps === false) {
|
|
130
|
+
throw new TimestampsRequired(collection);
|
|
131
|
+
}
|
|
127
132
|
if (sanitized.versions === true) {
|
|
128
133
|
sanitized.versions = {
|
|
129
134
|
drafts: false,
|
|
130
135
|
maxPerDoc: 100
|
|
131
136
|
};
|
|
132
137
|
}
|
|
133
|
-
if (sanitized.timestamps === false) {
|
|
134
|
-
throw new TimestampsRequired(collection);
|
|
135
|
-
}
|
|
136
138
|
sanitized.versions.maxPerDoc = typeof sanitized.versions.maxPerDoc === 'number' ? sanitized.versions.maxPerDoc : 100;
|
|
137
139
|
if (sanitized.versions.drafts) {
|
|
138
140
|
if (sanitized.versions.drafts === true) {
|
|
@@ -141,6 +143,17 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
141
143
|
validate: false
|
|
142
144
|
};
|
|
143
145
|
}
|
|
146
|
+
const hasLocalizedFields = traverseForLocalizedFields(sanitized.fields);
|
|
147
|
+
if (config.localization) {
|
|
148
|
+
if (hasLocalizedFields && sanitized.versions.drafts.localizeStatus === undefined) {
|
|
149
|
+
sanitized.versions.drafts.localizeStatus = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// TODO v4: remove this sanitization check, should not need to enable the experimental flag
|
|
153
|
+
if (sanitized.versions.drafts.localizeStatus && !config.experimental?.localizeStatus) {
|
|
154
|
+
sanitized.versions.drafts.localizeStatus = false;
|
|
155
|
+
console.log(miniChalk.yellowBold(`Warning: "localizeStatus" for drafts is an experimental feature. To enable, set "experimental.localizeStatus" to true in your Payload config.`));
|
|
156
|
+
}
|
|
144
157
|
if (sanitized.versions.drafts.autosave === true) {
|
|
145
158
|
sanitized.versions.drafts.autosave = {
|
|
146
159
|
interval: versionDefaults.autosaveInterval
|
|
@@ -149,7 +162,9 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
149
162
|
if (sanitized.versions.drafts.validate === undefined) {
|
|
150
163
|
sanitized.versions.drafts.validate = false;
|
|
151
164
|
}
|
|
152
|
-
sanitized.fields = mergeBaseFields(sanitized.fields, baseVersionFields
|
|
165
|
+
sanitized.fields = mergeBaseFields(sanitized.fields, baseVersionFields({
|
|
166
|
+
localized: sanitized.versions.drafts.localizeStatus ?? false
|
|
167
|
+
}));
|
|
153
168
|
}
|
|
154
169
|
} else {
|
|
155
170
|
delete sanitized.versions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/sanitize.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from '../../config/types.js'\nimport type {\n CollectionConfig,\n SanitizedCollectionConfig,\n SanitizedJoin,\n SanitizedJoins,\n} from './types.js'\n\nimport { authCollectionEndpoints } from '../../auth/endpoints/index.js'\nimport { getBaseAuthFields } from '../../auth/getAuthFields.js'\nimport { TimestampsRequired } from '../../errors/TimestampsRequired.js'\nimport { sanitizeFields } from '../../fields/config/sanitize.js'\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport { mergeBaseFields } from '../../fields/mergeBaseFields.js'\nimport { uploadCollectionEndpoints } from '../../uploads/endpoints/index.js'\nimport { getBaseUploadFields } from '../../uploads/getBaseFields.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nimport { formatLabels } from '../../utilities/formatLabels.js'\nimport { baseVersionFields } from '../../versions/baseFields.js'\nimport { versionDefaults } from '../../versions/defaults.js'\nimport { defaultCollectionEndpoints } from '../endpoints/index.js'\nimport {\n addDefaultsToAuthConfig,\n addDefaultsToCollectionConfig,\n addDefaultsToLoginWithUsernameConfig,\n} from './defaults.js'\nimport { sanitizeCompoundIndexes } from './sanitizeCompoundIndexes.js'\nimport { validateUseAsTitle } from './useAsTitle.js'\n\nexport const sanitizeCollection = async (\n config: Config,\n collection: CollectionConfig,\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>,\n _validRelationships?: string[],\n): Promise<SanitizedCollectionConfig> => {\n if (collection._sanitized) {\n return collection as SanitizedCollectionConfig\n }\n\n collection._sanitized = true\n\n // /////////////////////////////////\n // Make copy of collection config\n // /////////////////////////////////\n\n const sanitized: CollectionConfig = addDefaultsToCollectionConfig(collection)\n\n // /////////////////////////////////\n // Sanitize fields\n // /////////////////////////////////\n\n const validRelationships = _validRelationships ?? config.collections!.map((c) => c.slug) ?? []\n\n const joins: SanitizedJoins = {}\n\n const polymorphicJoins: SanitizedJoin[] = []\n\n sanitized.fields = await sanitizeFields({\n collectionConfig: sanitized,\n config,\n fields: sanitized.fields,\n joinPath: '',\n joins,\n parentIsLocalized: false,\n polymorphicJoins,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n if (sanitized.endpoints !== false) {\n if (!sanitized.endpoints) {\n sanitized.endpoints = []\n }\n\n if (sanitized.auth) {\n for (const endpoint of authCollectionEndpoints) {\n sanitized.endpoints.push(endpoint)\n }\n }\n\n if (sanitized.upload) {\n for (const endpoint of uploadCollectionEndpoints) {\n sanitized.endpoints.push(endpoint)\n }\n }\n\n for (const endpoint of defaultCollectionEndpoints) {\n sanitized.endpoints.push(endpoint)\n }\n }\n\n if (sanitized.timestamps !== false) {\n // add default timestamps fields only as needed\n let hasUpdatedAt: boolean | null = null\n let hasCreatedAt: boolean | null = null\n let hasDeletedAt: boolean | null = null\n\n sanitized.fields.some((field) => {\n if (fieldAffectsData(field)) {\n if (field.name === 'updatedAt') {\n hasUpdatedAt = true\n }\n\n if (field.name === 'createdAt') {\n hasCreatedAt = true\n }\n\n if (field.name === 'deletedAt') {\n hasDeletedAt = true\n }\n }\n\n return hasCreatedAt && hasUpdatedAt && (!sanitized.trash || hasDeletedAt)\n })\n\n if (!hasUpdatedAt) {\n sanitized.fields.push({\n name: 'updatedAt',\n type: 'date',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n label: ({ t }) => t('general:updatedAt'),\n })\n }\n\n if (!hasCreatedAt) {\n sanitized.fields.push({\n name: 'createdAt',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n // The default sort for list view is createdAt. Thus, enabling indexing by default, is a major performance improvement, especially for large or a large amount of collections.\n type: 'date',\n index: true,\n label: ({ t }) => t('general:createdAt'),\n })\n }\n\n if (sanitized.trash && !hasDeletedAt) {\n sanitized.fields.push({\n name: 'deletedAt',\n type: 'date',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n label: ({ t }) => t('general:deletedAt'),\n })\n }\n }\n\n const defaultLabels = formatLabels(sanitized.slug)\n\n sanitized.labels = {\n plural: sanitized.labels?.plural || defaultLabels.plural,\n singular: sanitized.labels?.singular || defaultLabels.singular,\n }\n\n if (sanitized.versions) {\n if (sanitized.versions === true) {\n sanitized.versions = { drafts: false, maxPerDoc: 100 }\n }\n\n if (sanitized.timestamps === false) {\n throw new TimestampsRequired(collection)\n }\n\n sanitized.versions.maxPerDoc =\n typeof sanitized.versions.maxPerDoc === 'number' ? sanitized.versions.maxPerDoc : 100\n\n if (sanitized.versions.drafts) {\n if (sanitized.versions.drafts === true) {\n sanitized.versions.drafts = {\n autosave: false,\n validate: false,\n }\n }\n\n if (sanitized.versions.drafts.autosave === true) {\n sanitized.versions.drafts.autosave = {\n interval: versionDefaults.autosaveInterval,\n }\n }\n\n if (sanitized.versions.drafts.validate === undefined) {\n sanitized.versions.drafts.validate = false\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, baseVersionFields)\n }\n } else {\n delete sanitized.versions\n }\n\n if (sanitized.folders === true) {\n sanitized.folders = {\n browseByFolder: true,\n }\n } else if (sanitized.folders) {\n sanitized.folders.browseByFolder = sanitized.folders.browseByFolder ?? true\n }\n\n if (sanitized.upload) {\n if (sanitized.upload === true) {\n sanitized.upload = {}\n }\n\n sanitized.upload.cacheTags = sanitized.upload?.cacheTags ?? true\n sanitized.upload.bulkUpload = sanitized.upload?.bulkUpload ?? true\n sanitized.upload.staticDir = sanitized.upload.staticDir || sanitized.slug\n sanitized.admin!.useAsTitle =\n sanitized.admin?.useAsTitle && sanitized.admin.useAsTitle !== 'id'\n ? sanitized.admin.useAsTitle\n : 'filename'\n\n const uploadFields = getBaseUploadFields({\n collection: sanitized,\n config,\n })\n\n sanitized.fields = mergeBaseFields(sanitized.fields, uploadFields)\n }\n\n if (sanitized.auth) {\n sanitized.auth = addDefaultsToAuthConfig(\n typeof sanitized.auth === 'boolean' ? {} : sanitized.auth,\n )\n\n // disable duplicate for auth enabled collections by default\n sanitized.disableDuplicate = sanitized.disableDuplicate ?? true\n\n if (sanitized.auth.loginWithUsername) {\n if (sanitized.auth.loginWithUsername === true) {\n sanitized.auth.loginWithUsername = addDefaultsToLoginWithUsernameConfig({})\n } else {\n const loginWithUsernameWithDefaults = addDefaultsToLoginWithUsernameConfig(\n sanitized.auth.loginWithUsername,\n )\n\n // if allowEmailLogin is false, requireUsername must be true\n if (loginWithUsernameWithDefaults.allowEmailLogin === false) {\n loginWithUsernameWithDefaults.requireUsername = true\n }\n sanitized.auth.loginWithUsername = loginWithUsernameWithDefaults\n }\n } else {\n sanitized.auth.loginWithUsername = false\n }\n\n if (!collection?.admin?.useAsTitle) {\n sanitized.admin!.useAsTitle = sanitized.auth.loginWithUsername ? 'username' : 'email'\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, getBaseAuthFields(sanitized.auth))\n }\n\n if (collection?.admin?.pagination?.limits?.length) {\n sanitized.admin!.pagination!.limits = collection.admin.pagination.limits\n }\n\n validateUseAsTitle(sanitized)\n\n const sanitizedConfig = sanitized as SanitizedCollectionConfig\n\n sanitizedConfig.joins = joins\n sanitizedConfig.polymorphicJoins = polymorphicJoins\n\n sanitizedConfig.flattenedFields = flattenAllFields({ fields: sanitizedConfig.fields })\n\n sanitizedConfig.sanitizedIndexes = sanitizeCompoundIndexes({\n fields: sanitizedConfig.flattenedFields,\n indexes: sanitizedConfig.indexes,\n })\n\n return sanitizedConfig\n}\n"],"names":["authCollectionEndpoints","getBaseAuthFields","TimestampsRequired","sanitizeFields","fieldAffectsData","mergeBaseFields","uploadCollectionEndpoints","getBaseUploadFields","flattenAllFields","formatLabels","baseVersionFields","versionDefaults","defaultCollectionEndpoints","addDefaultsToAuthConfig","addDefaultsToCollectionConfig","addDefaultsToLoginWithUsernameConfig","sanitizeCompoundIndexes","validateUseAsTitle","sanitizeCollection","config","collection","richTextSanitizationPromises","_validRelationships","_sanitized","sanitized","validRelationships","collections","map","c","slug","joins","polymorphicJoins","fields","collectionConfig","joinPath","parentIsLocalized","endpoints","auth","endpoint","push","upload","timestamps","hasUpdatedAt","hasCreatedAt","hasDeletedAt","some","field","name","trash","type","admin","disableBulkEdit","hidden","index","label","t","defaultLabels","labels","plural","singular","versions","drafts","maxPerDoc","autosave","validate","interval","autosaveInterval","undefined","folders","browseByFolder","cacheTags","bulkUpload","staticDir","useAsTitle","uploadFields","disableDuplicate","loginWithUsername","loginWithUsernameWithDefaults","allowEmailLogin","requireUsername","pagination","limits","length","sanitizedConfig","flattenedFields","sanitizedIndexes","indexes"],"mappings":"AAQA,SAASA,uBAAuB,QAAQ,gCAA+B;AACvE,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,cAAc,QAAQ,kCAAiC;AAChE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,eAAe,QAAQ,k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BAC7CpD,UAAUa,IAAI,CAACuC,iBAAiB,GAAG7D,qCAAqC,CAAC;YAC3E,OAAO;gBACL,MAAM8D,gCAAgC9D,qCACpCS,UAAUa,IAAI,CAACuC,iBAAiB;gBAGlC,4DAA4D;gBAC5D,IAAIC,8BAA8BC,eAAe,KAAK,OAAO;oBAC3DD,8BAA8BE,eAAe,GAAG;gBAClD;gBACAvD,UAAUa,IAAI,CAACuC,iBAAiB,GAAGC;YACrC;QACF,OAAO;YACLrD,UAAUa,IAAI,CAACuC,iBAAiB,GAAG;QACrC;QAEA,IAAI,CAACxD,YAAY8B,OAAOuB,YAAY;YAClCjD,UAAU0B,KAAK,CAAEuB,UAAU,GAAGjD,UAAUa,IAAI,CAACuC,iBAAiB,GAAG,aAAa;QAChF;QAEApD,UAAUQ,MAAM,GAAG3B,gBAAgBmB,UAAUQ,MAAM,EAAE/B,kBAAkBuB,UAAUa,IAAI;IACvF;IAEA,IAAIjB,YAAY8B,OAAO8B,YAAYC,QAAQC,QAAQ;QACjD1D,UAAU0B,KAAK,CAAE8B,UAAU,CAAEC,MAAM,GAAG7D,WAAW8B,KAAK,CAAC8B,UAAU,CAACC,MAAM;IAC1E;IAEAhE,mBAAmBO;IAEnB,MAAM2D,kBAAkB3D;IAExB2D,gBAAgBrD,KAAK,GAAGA;IACxBqD,gBAAgBpD,gBAAgB,GAAGA;IAEnCoD,gBAAgBC,eAAe,GAAG5E,iBAAiB;QAAEwB,QAAQmD,gBAAgBnD,MAAM;IAAC;IAEpFmD,gBAAgBE,gBAAgB,GAAGrE,wBAAwB;QACzDgB,QAAQmD,gBAAgBC,eAAe;QACvCE,SAASH,gBAAgBG,OAAO;IAClC;IAEA,OAAOH;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/sanitize.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from '../../config/types.js'\nimport type {\n CollectionConfig,\n SanitizedCollectionConfig,\n SanitizedJoin,\n SanitizedJoins,\n} from './types.js'\n\nimport { authCollectionEndpoints } from '../../auth/endpoints/index.js'\nimport { getBaseAuthFields } from '../../auth/getAuthFields.js'\nimport { TimestampsRequired } from '../../errors/TimestampsRequired.js'\nimport { sanitizeFields } from '../../fields/config/sanitize.js'\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport { mergeBaseFields } from '../../fields/mergeBaseFields.js'\nimport { uploadCollectionEndpoints } from '../../uploads/endpoints/index.js'\nimport { getBaseUploadFields } from '../../uploads/getBaseFields.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nimport { formatLabels } from '../../utilities/formatLabels.js'\nimport { miniChalk } from '../../utilities/miniChalk.js'\nimport { traverseForLocalizedFields } from '../../utilities/traverseForLocalizedFields.js'\nimport { baseVersionFields } from '../../versions/baseFields.js'\nimport { versionDefaults } from '../../versions/defaults.js'\nimport { defaultCollectionEndpoints } from '../endpoints/index.js'\nimport {\n addDefaultsToAuthConfig,\n addDefaultsToCollectionConfig,\n addDefaultsToLoginWithUsernameConfig,\n} from './defaults.js'\nimport { sanitizeCompoundIndexes } from './sanitizeCompoundIndexes.js'\nimport { validateUseAsTitle } from './useAsTitle.js'\n\nexport const sanitizeCollection = async (\n config: Config,\n collection: CollectionConfig,\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>,\n _validRelationships?: string[],\n): Promise<SanitizedCollectionConfig> => {\n if (collection._sanitized) {\n return collection as SanitizedCollectionConfig\n }\n\n collection._sanitized = true\n\n // /////////////////////////////////\n // Make copy of collection config\n // /////////////////////////////////\n\n const sanitized: CollectionConfig = addDefaultsToCollectionConfig(collection)\n\n // /////////////////////////////////\n // Sanitize fields\n // /////////////////////////////////\n\n const validRelationships = _validRelationships ?? config.collections!.map((c) => c.slug) ?? []\n\n const joins: SanitizedJoins = {}\n\n const polymorphicJoins: SanitizedJoin[] = []\n\n sanitized.fields = await sanitizeFields({\n collectionConfig: sanitized,\n config,\n fields: sanitized.fields,\n joinPath: '',\n joins,\n parentIsLocalized: false,\n polymorphicJoins,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n if (sanitized.endpoints !== false) {\n if (!sanitized.endpoints) {\n sanitized.endpoints = []\n }\n\n if (sanitized.auth) {\n for (const endpoint of authCollectionEndpoints) {\n sanitized.endpoints.push(endpoint)\n }\n }\n\n if (sanitized.upload) {\n for (const endpoint of uploadCollectionEndpoints) {\n sanitized.endpoints.push(endpoint)\n }\n }\n\n for (const endpoint of defaultCollectionEndpoints) {\n sanitized.endpoints.push(endpoint)\n }\n }\n\n if (sanitized.timestamps !== false) {\n // add default timestamps fields only as needed\n let hasUpdatedAt: boolean | null = null\n let hasCreatedAt: boolean | null = null\n let hasDeletedAt: boolean | null = null\n\n sanitized.fields.some((field) => {\n if (fieldAffectsData(field)) {\n if (field.name === 'updatedAt') {\n hasUpdatedAt = true\n }\n\n if (field.name === 'createdAt') {\n hasCreatedAt = true\n }\n\n if (field.name === 'deletedAt') {\n hasDeletedAt = true\n }\n }\n\n return hasCreatedAt && hasUpdatedAt && (!sanitized.trash || hasDeletedAt)\n })\n\n if (!hasUpdatedAt) {\n sanitized.fields.push({\n name: 'updatedAt',\n type: 'date',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n label: ({ t }) => t('general:updatedAt'),\n })\n }\n\n if (!hasCreatedAt) {\n sanitized.fields.push({\n name: 'createdAt',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n // The default sort for list view is createdAt. Thus, enabling indexing by default, is a major performance improvement, especially for large or a large amount of collections.\n type: 'date',\n index: true,\n label: ({ t }) => t('general:createdAt'),\n })\n }\n\n if (sanitized.trash && !hasDeletedAt) {\n sanitized.fields.push({\n name: 'deletedAt',\n type: 'date',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n label: ({ t }) => t('general:deletedAt'),\n })\n }\n }\n\n const defaultLabels = formatLabels(sanitized.slug)\n\n sanitized.labels = {\n plural: sanitized.labels?.plural || defaultLabels.plural,\n singular: sanitized.labels?.singular || defaultLabels.singular,\n }\n\n if (sanitized.versions) {\n if (sanitized.timestamps === false) {\n throw new TimestampsRequired(collection)\n }\n\n if (sanitized.versions === true) {\n sanitized.versions = {\n drafts: false,\n maxPerDoc: 100,\n }\n }\n\n sanitized.versions.maxPerDoc =\n typeof sanitized.versions.maxPerDoc === 'number' ? sanitized.versions.maxPerDoc : 100\n\n if (sanitized.versions.drafts) {\n if (sanitized.versions.drafts === true) {\n sanitized.versions.drafts = {\n autosave: false,\n validate: false,\n }\n }\n\n const hasLocalizedFields = traverseForLocalizedFields(sanitized.fields)\n\n if (config.localization) {\n if (hasLocalizedFields && sanitized.versions.drafts.localizeStatus === undefined) {\n sanitized.versions.drafts.localizeStatus = false\n }\n }\n\n // TODO v4: remove this sanitization check, should not need to enable the experimental flag\n if (sanitized.versions.drafts.localizeStatus && !config.experimental?.localizeStatus) {\n sanitized.versions.drafts.localizeStatus = false\n console.log(\n miniChalk.yellowBold(\n `Warning: \"localizeStatus\" for drafts is an experimental feature. To enable, set \"experimental.localizeStatus\" to true in your Payload config.`,\n ),\n )\n }\n\n if (sanitized.versions.drafts.autosave === true) {\n sanitized.versions.drafts.autosave = {\n interval: versionDefaults.autosaveInterval,\n }\n }\n\n if (sanitized.versions.drafts.validate === undefined) {\n sanitized.versions.drafts.validate = false\n }\n\n sanitized.fields = mergeBaseFields(\n sanitized.fields,\n baseVersionFields({\n localized: sanitized.versions.drafts.localizeStatus ?? false,\n }),\n )\n }\n } else {\n delete sanitized.versions\n }\n\n if (sanitized.folders === true) {\n sanitized.folders = {\n browseByFolder: true,\n }\n } else if (sanitized.folders) {\n sanitized.folders.browseByFolder = sanitized.folders.browseByFolder ?? true\n }\n\n if (sanitized.upload) {\n if (sanitized.upload === true) {\n sanitized.upload = {}\n }\n\n sanitized.upload.cacheTags = sanitized.upload?.cacheTags ?? true\n sanitized.upload.bulkUpload = sanitized.upload?.bulkUpload ?? true\n sanitized.upload.staticDir = sanitized.upload.staticDir || sanitized.slug\n sanitized.admin!.useAsTitle =\n sanitized.admin?.useAsTitle && sanitized.admin.useAsTitle !== 'id'\n ? sanitized.admin.useAsTitle\n : 'filename'\n\n const uploadFields = getBaseUploadFields({\n collection: sanitized,\n config,\n })\n\n sanitized.fields = mergeBaseFields(sanitized.fields, uploadFields)\n }\n\n if (sanitized.auth) {\n sanitized.auth = addDefaultsToAuthConfig(\n typeof sanitized.auth === 'boolean' ? {} : sanitized.auth,\n )\n\n // disable duplicate for auth enabled collections by default\n sanitized.disableDuplicate = sanitized.disableDuplicate ?? true\n\n if (sanitized.auth.loginWithUsername) {\n if (sanitized.auth.loginWithUsername === true) {\n sanitized.auth.loginWithUsername = addDefaultsToLoginWithUsernameConfig({})\n } else {\n const loginWithUsernameWithDefaults = addDefaultsToLoginWithUsernameConfig(\n sanitized.auth.loginWithUsername,\n )\n\n // if allowEmailLogin is false, requireUsername must be true\n if (loginWithUsernameWithDefaults.allowEmailLogin === false) {\n loginWithUsernameWithDefaults.requireUsername = true\n }\n sanitized.auth.loginWithUsername = loginWithUsernameWithDefaults\n }\n } else {\n sanitized.auth.loginWithUsername = false\n }\n\n if (!collection?.admin?.useAsTitle) {\n sanitized.admin!.useAsTitle = sanitized.auth.loginWithUsername ? 'username' : 'email'\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, getBaseAuthFields(sanitized.auth))\n }\n\n if (collection?.admin?.pagination?.limits?.length) {\n sanitized.admin!.pagination!.limits = collection.admin.pagination.limits\n }\n\n validateUseAsTitle(sanitized)\n\n const sanitizedConfig = sanitized as SanitizedCollectionConfig\n\n sanitizedConfig.joins = joins\n sanitizedConfig.polymorphicJoins = polymorphicJoins\n\n sanitizedConfig.flattenedFields = flattenAllFields({ fields: sanitizedConfig.fields })\n\n sanitizedConfig.sanitizedIndexes = sanitizeCompoundIndexes({\n fields: sanitizedConfig.flattenedFields,\n indexes: sanitizedConfig.indexes,\n })\n\n return sanitizedConfig\n}\n"],"names":["authCollectionEndpoints","getBaseAuthFields","TimestampsRequired","sanitizeFields","fieldAffectsData","mergeBaseFields","uploadCollectionEndpoints","getBaseUploadFields","flattenAllFields","formatLabels","miniChalk","traverseForLocalizedFields","baseVersionFields","versionDefaults","defaultCollectionEndpoints","addDefaultsToAuthConfig","addDefaultsToCollectionConfig","addDefaultsToLoginWithUsernameConfig","sanitizeCompoundIndexes","validateUseAsTitle","sanitizeCollection","config","collection","richTextSanitizationPromises","_validRelationships","_sanitized","sanitized","validRelationships","collections","map","c","slug","joins","polymorphicJoins","fields","collectionConfig","joinPath","parentIsLocalized","endpoints","auth","endpoint","push","upload","timestamps","hasUpdatedAt","hasCreatedAt","hasDeletedAt","some","field","name","trash","type","admin","disableBulkEdit","hidden","index","label","t","defaultLabels","labels","plural","singular","versions","drafts","maxPerDoc","autosave","validate","hasLocalizedFields","localization","localizeStatus","undefined","experimental","console","log","yellowBold","interval","autosaveInterval","localized","folders","browseByFolder","cacheTags","bulkUpload","staticDir","useAsTitle","uploadFields","disableDuplicate","loginWithUsername","loginWithUsernameWithDefaults","allowEmailLogin","requireUsername","pagination","limits","length","sanitizedConfig","flattenedFields","sanitizedIndexes","indexes"],"mappings":"AAQA,SAASA,uBAAuB,QAAQ,gCAA+B;AACvE,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,cAAc,QAAQ,kCAAiC;AAChE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,eAAe,QAAQ,kCAAiC;AACjE,SAASC,yBAAyB,QAAQ,mCAAkC;AAC5E,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,YAAY,QAAQ,kCAAiC;AAC9D,SAASC,SAAS,QAAQ,+BAA8B;AACxD,SAASC,0BAA0B,QAAQ,gDAA+C;AAC1F,SAASC,iBA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B,GAAGA;IAEnC4D,gBAAgBC,eAAe,GAAGtF,iBAAiB;QAAE0B,QAAQ2D,gBAAgB3D,MAAM;IAAC;IAEpF2D,gBAAgBE,gBAAgB,GAAG7E,wBAAwB;QACzDgB,QAAQ2D,gBAAgBC,eAAe;QACvCE,SAASH,gBAAgBG,OAAO;IAClC;IAEA,OAAOH;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,aAAa,EAAE,cAmC3B,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { parseParams } from '../../utilities/parseParams/index.js';
|
|
|
6
6
|
import { createOperation } from '../operations/create.js';
|
|
7
7
|
export const createHandler = async (req)=>{
|
|
8
8
|
const collection = getRequestCollection(req);
|
|
9
|
-
const { autosave, depth, draft, populate, select } = parseParams(req.query);
|
|
9
|
+
const { autosave, depth, draft, populate, publishAllLocales, select } = parseParams(req.query);
|
|
10
10
|
const publishSpecificLocale = req.query.publishSpecificLocale;
|
|
11
11
|
const doc = await createOperation({
|
|
12
12
|
autosave,
|
|
@@ -15,6 +15,7 @@ export const createHandler = async (req)=>{
|
|
|
15
15
|
depth,
|
|
16
16
|
draft,
|
|
17
17
|
populate,
|
|
18
|
+
publishAllLocales,
|
|
18
19
|
publishSpecificLocale,
|
|
19
20
|
req,
|
|
20
21
|
select
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/endpoints/create.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollection } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { parseParams } from '../../utilities/parseParams/index.js'\nimport { createOperation } from '../operations/create.js'\n\nexport const createHandler: PayloadHandler = async (req) => {\n const collection = getRequestCollection(req)\n\n const { autosave, depth, draft, populate, select } = parseParams(req.query)\n\n const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined\n\n const doc = await createOperation({\n autosave,\n collection,\n data: req.data!,\n depth,\n draft,\n populate,\n publishSpecificLocale,\n req,\n select,\n })\n\n return Response.json(\n {\n doc,\n message: req.t('general:successfullyCreated', {\n label: getTranslation(collection.config.labels.singular, req.i18n),\n }),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.CREATED,\n },\n )\n}\n"],"names":["getTranslation","status","httpStatus","getRequestCollection","headersWithCors","parseParams","createOperation","createHandler","req","collection","autosave","depth","draft","populate","select","query","publishSpecificLocale","doc","data","Response","json","message","t","label","config","labels","singular","i18n","headers","Headers","CREATED"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,WAAW,QAAQ,uCAAsC;AAClE,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,MAAMC,aAAaN,qBAAqBK;IAExC,MAAM,EAAEE,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/endpoints/create.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollection } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { parseParams } from '../../utilities/parseParams/index.js'\nimport { createOperation } from '../operations/create.js'\n\nexport const createHandler: PayloadHandler = async (req) => {\n const collection = getRequestCollection(req)\n\n const { autosave, depth, draft, populate, publishAllLocales, select } = parseParams(req.query)\n\n const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined\n\n const doc = await createOperation({\n autosave,\n collection,\n data: req.data!,\n depth,\n draft,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n req,\n select,\n })\n\n return Response.json(\n {\n doc,\n message: req.t('general:successfullyCreated', {\n label: getTranslation(collection.config.labels.singular, req.i18n),\n }),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.CREATED,\n },\n )\n}\n"],"names":["getTranslation","status","httpStatus","getRequestCollection","headersWithCors","parseParams","createOperation","createHandler","req","collection","autosave","depth","draft","populate","publishAllLocales","select","query","publishSpecificLocale","doc","data","Response","json","message","t","label","config","labels","singular","i18n","headers","Headers","CREATED"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,WAAW,QAAQ,uCAAsC;AAClE,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,MAAMC,aAAaN,qBAAqBK;IAExC,MAAM,EAAEE,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,iBAAiB,EAAEC,MAAM,EAAE,GAAGV,YAAYG,IAAIQ,KAAK;IAE7F,MAAMC,wBAAwBT,IAAIQ,KAAK,CAACC,qBAAqB;IAE7D,MAAMC,MAAM,MAAMZ,gBAAgB;QAChCI;QACAD;QACAU,MAAMX,IAAIW,IAAI;QACdR;QACAC;QACAC;QACAC;QACAG;QACAT;QACAO;IACF;IAEA,OAAOK,SAASC,IAAI,CAClB;QACEH;QACAI,SAASd,IAAIe,CAAC,CAAC,+BAA+B;YAC5CC,OAAOxB,eAAeS,WAAWgB,MAAM,CAACC,MAAM,CAACC,QAAQ,EAAEnB,IAAIoB,IAAI;QACnE;IACF,GACA;QACEC,SAASzB,gBAAgB;YACvByB,SAAS,IAAIC;YACbtB;QACF;QACAP,QAAQC,WAAW6B,OAAO;IAC5B;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/update.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/update.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,aAAa,EAAE,cAsF3B,CAAA"}
|
|
@@ -6,7 +6,7 @@ import { parseParams } from '../../utilities/parseParams/index.js';
|
|
|
6
6
|
import { updateOperation } from '../operations/update.js';
|
|
7
7
|
export const updateHandler = async (req)=>{
|
|
8
8
|
const collection = getRequestCollection(req);
|
|
9
|
-
const { depth, draft, limit, overrideLock, populate, select, sort, trash, where } = parseParams(req.query);
|
|
9
|
+
const { depth, draft, limit, overrideLock, populate, publishAllLocales, select, sort, trash, unpublishAllLocales, where } = parseParams(req.query);
|
|
10
10
|
const result = await updateOperation({
|
|
11
11
|
collection,
|
|
12
12
|
data: req.data,
|
|
@@ -15,10 +15,12 @@ export const updateHandler = async (req)=>{
|
|
|
15
15
|
limit,
|
|
16
16
|
overrideLock: overrideLock ?? false,
|
|
17
17
|
populate,
|
|
18
|
+
publishAllLocales,
|
|
18
19
|
req,
|
|
19
20
|
select,
|
|
20
21
|
sort,
|
|
21
22
|
trash,
|
|
23
|
+
unpublishAllLocales,
|
|
22
24
|
where: where
|
|
23
25
|
});
|
|
24
26
|
const headers = headersWithCors({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/endpoints/update.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollection } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { parseParams } from '../../utilities/parseParams/index.js'\nimport { updateOperation } from '../operations/update.js'\n\nexport const updateHandler: PayloadHandler = async (req) => {\n const collection = getRequestCollection(req)\n\n const {
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/endpoints/update.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollection } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { parseParams } from '../../utilities/parseParams/index.js'\nimport { updateOperation } from '../operations/update.js'\n\nexport const updateHandler: PayloadHandler = async (req) => {\n const collection = getRequestCollection(req)\n\n const {\n depth,\n draft,\n limit,\n overrideLock,\n populate,\n publishAllLocales,\n select,\n sort,\n trash,\n unpublishAllLocales,\n where,\n } = parseParams(req.query)\n\n const result = await updateOperation({\n collection,\n data: req.data!,\n depth,\n draft,\n limit,\n overrideLock: overrideLock ?? false,\n populate,\n publishAllLocales,\n req,\n select,\n sort,\n trash,\n unpublishAllLocales,\n where: where!,\n })\n\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n if (result.errors.length === 0) {\n const message = req.t('general:updatedCountSuccessfully', {\n count: result.docs.length,\n label: getTranslation(\n collection.config.labels[result.docs.length === 1 ? 'singular' : 'plural'],\n req.i18n,\n ),\n })\n\n return Response.json(\n {\n ...result,\n message,\n },\n {\n headers,\n status: httpStatus.OK,\n },\n )\n }\n\n result.errors = result.errors.map((error) =>\n error.isPublic\n ? error\n : {\n ...error,\n message: 'Something went wrong.',\n },\n )\n\n const total = result.docs.length + result.errors.length\n const message = req.t('error:unableToUpdateCount', {\n count: result.errors.length,\n label: getTranslation(collection.config.labels[total === 1 ? 'singular' : 'plural'], req.i18n),\n total,\n })\n\n return Response.json(\n {\n ...result,\n message,\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n}\n"],"names":["getTranslation","status","httpStatus","getRequestCollection","headersWithCors","parseParams","updateOperation","updateHandler","req","collection","depth","draft","limit","overrideLock","populate","publishAllLocales","select","sort","trash","unpublishAllLocales","where","query","result","data","headers","Headers","errors","length","message","t","count","docs","label","config","labels","i18n","Response","json","OK","map","error","isPublic","total","BAD_REQUEST"],"mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,WAAW,QAAQ,uCAAsC;AAClE,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,MAAMC,aAAaN,qBAAqBK;IAExC,MAAM,EACJE,KAAK,EACLC,KAAK,EACLC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,iBAAiB,EACjBC,MAAM,EACNC,IAAI,EACJC,KAAK,EACLC,mBAAmB,EACnBC,KAAK,EACN,GAAGf,YAAYG,IAAIa,KAAK;IAEzB,MAAMC,SAAS,MAAMhB,gBAAgB;QACnCG;QACAc,MAAMf,IAAIe,IAAI;QACdb;QACAC;QACAC;QACAC,cAAcA,gBAAgB;QAC9BC;QACAC;QACAP;QACAQ;QACAC;QACAC;QACAC;QACAC,OAAOA;IACT;IAEA,MAAMI,UAAUpB,gBAAgB;QAC9BoB,SAAS,IAAIC;QACbjB;IACF;IAEA,IAAIc,OAAOI,MAAM,CAACC,MAAM,KAAK,GAAG;QAC9B,MAAMC,UAAUpB,IAAIqB,CAAC,CAAC,oCAAoC;YACxDC,OAAOR,OAAOS,IAAI,CAACJ,MAAM;YACzBK,OAAOhC,eACLS,WAAWwB,MAAM,CAACC,MAAM,CAACZ,OAAOS,IAAI,CAACJ,MAAM,KAAK,IAAI,aAAa,SAAS,EAC1EnB,IAAI2B,IAAI;QAEZ;QAEA,OAAOC,SAASC,IAAI,CAClB;YACE,GAAGf,MAAM;YACTM;QACF,GACA;YACEJ;YACAvB,QAAQC,WAAWoC,EAAE;QACvB;IAEJ;IAEAhB,OAAOI,MAAM,GAAGJ,OAAOI,MAAM,CAACa,GAAG,CAAC,CAACC,QACjCA,MAAMC,QAAQ,GACVD,QACA;YACE,GAAGA,KAAK;YACRZ,SAAS;QACX;IAGN,MAAMc,QAAQpB,OAAOS,IAAI,CAACJ,MAAM,GAAGL,OAAOI,MAAM,CAACC,MAAM;IACvD,MAAMC,UAAUpB,IAAIqB,CAAC,CAAC,6BAA6B;QACjDC,OAAOR,OAAOI,MAAM,CAACC,MAAM;QAC3BK,OAAOhC,eAAeS,WAAWwB,MAAM,CAACC,MAAM,CAACQ,UAAU,IAAI,aAAa,SAAS,EAAElC,IAAI2B,IAAI;QAC7FO;IACF;IAEA,OAAON,SAASC,IAAI,CAClB;QACE,GAAGf,MAAM;QACTM;IACF,GACA;QACEJ;QACAvB,QAAQC,WAAWyC,WAAW;IAChC;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateByID.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/updateByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"updateByID.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/updateByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,iBAAiB,EAAE,cAuD/B,CAAA"}
|
|
@@ -5,7 +5,7 @@ import { parseParams } from '../../utilities/parseParams/index.js';
|
|
|
5
5
|
import { updateByIDOperation } from '../operations/updateByID.js';
|
|
6
6
|
export const updateByIDHandler = async (req)=>{
|
|
7
7
|
const { id, collection } = getRequestCollectionWithID(req);
|
|
8
|
-
const { autosave, depth, draft, overrideLock, populate, publishSpecificLocale, select, trash } = parseParams(req.query);
|
|
8
|
+
const { autosave, depth, draft, overrideLock, populate, publishAllLocales, publishSpecificLocale, select, trash, unpublishAllLocales } = parseParams(req.query);
|
|
9
9
|
const doc = await updateByIDOperation({
|
|
10
10
|
id,
|
|
11
11
|
autosave,
|
|
@@ -15,10 +15,12 @@ export const updateByIDHandler = async (req)=>{
|
|
|
15
15
|
draft,
|
|
16
16
|
overrideLock: overrideLock ?? false,
|
|
17
17
|
populate,
|
|
18
|
+
publishAllLocales,
|
|
18
19
|
publishSpecificLocale,
|
|
19
20
|
req,
|
|
20
21
|
select,
|
|
21
|
-
trash
|
|
22
|
+
trash,
|
|
23
|
+
unpublishAllLocales
|
|
22
24
|
});
|
|
23
25
|
let message = req.t('general:updatedSuccessfully');
|
|
24
26
|
if (draft) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/endpoints/updateByID.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { parseParams } from '../../utilities/parseParams/index.js'\nimport { updateByIDOperation } from '../operations/updateByID.js'\n\nexport const updateByIDHandler: PayloadHandler = async (req) => {\n const { id, collection } = getRequestCollectionWithID(req)\n\n const {
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/endpoints/updateByID.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { parseParams } from '../../utilities/parseParams/index.js'\nimport { updateByIDOperation } from '../operations/updateByID.js'\n\nexport const updateByIDHandler: PayloadHandler = async (req) => {\n const { id, collection } = getRequestCollectionWithID(req)\n\n const {\n autosave,\n depth,\n draft,\n overrideLock,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n select,\n trash,\n unpublishAllLocales,\n } = parseParams(req.query)\n\n const doc = await updateByIDOperation({\n id,\n autosave,\n collection,\n data: req.data!,\n depth,\n draft,\n overrideLock: overrideLock ?? false,\n populate,\n publishAllLocales,\n publishSpecificLocale,\n req,\n select,\n trash,\n unpublishAllLocales,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) {\n message = req.t('version:draftSavedSuccessfully')\n }\n if (autosave) {\n message = req.t('version:autosavedSuccessfully')\n }\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","parseParams","updateByIDOperation","updateByIDHandler","req","id","collection","autosave","depth","draft","overrideLock","populate","publishAllLocales","publishSpecificLocale","select","trash","unpublishAllLocales","query","doc","data","message","t","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,WAAW,QAAQ,uCAAsC;AAClE,SAASC,mBAAmB,QAAQ,8BAA6B;AAEjE,OAAO,MAAMC,oBAAoC,OAAOC;IACtD,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAE,GAAGP,2BAA2BK;IAEtD,MAAM,EACJG,QAAQ,EACRC,KAAK,EACLC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,iBAAiB,EACjBC,qBAAqB,EACrBC,MAAM,EACNC,KAAK,EACLC,mBAAmB,EACpB,GAAGf,YAAYG,IAAIa,KAAK;IAEzB,MAAMC,MAAM,MAAMhB,oBAAoB;QACpCG;QACAE;QACAD;QACAa,MAAMf,IAAIe,IAAI;QACdX;QACAC;QACAC,cAAcA,gBAAgB;QAC9BC;QACAC;QACAC;QACAT;QACAU;QACAC;QACAC;IACF;IAEA,IAAII,UAAUhB,IAAIiB,CAAC,CAAC;IAEpB,IAAIZ,OAAO;QACTW,UAAUhB,IAAIiB,CAAC,CAAC;IAClB;IACA,IAAId,UAAU;QACZa,UAAUhB,IAAIiB,CAAC,CAAC;IAClB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEL;QACAE;IACF,GACA;QACEI,SAASxB,gBAAgB;YACvBwB,SAAS,IAAIC;YACbrB;QACF;QACAP,QAAQC,WAAW4B,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -13,6 +13,7 @@ export type Arguments<TSlug extends CollectionSlug> = {
|
|
|
13
13
|
overrideAccess?: boolean;
|
|
14
14
|
overwriteExistingFiles?: boolean;
|
|
15
15
|
populate?: PopulateType;
|
|
16
|
+
publishAllLocales?: boolean;
|
|
16
17
|
publishSpecificLocale?: string;
|
|
17
18
|
req: PayloadRequest;
|
|
18
19
|
select?: SelectType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/create.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,gBAAgB,CAAA;AAChE,OAAO,KAAK,EAEV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EACV,sBAAsB,EACtB,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;
|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6B,CAAC,KAAK,EAAE,OAAO,CAAC,CA0XvD,CAAA"}
|
|
@@ -13,7 +13,7 @@ import { generateFileData } from '../../uploads/generateFileData.js';
|
|
|
13
13
|
import { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js';
|
|
14
14
|
import { uploadFiles } from '../../uploads/uploadFiles.js';
|
|
15
15
|
import { commitTransaction } from '../../utilities/commitTransaction.js';
|
|
16
|
-
import { hasDraftsEnabled, hasDraftValidationEnabled } from '../../utilities/getVersionsConfig.js';
|
|
16
|
+
import { hasDraftsEnabled, hasDraftValidationEnabled, hasLocalizeStatusEnabled } from '../../utilities/getVersionsConfig.js';
|
|
17
17
|
import { initTransaction } from '../../utilities/initTransaction.js';
|
|
18
18
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
19
19
|
import { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js';
|
|
@@ -42,9 +42,13 @@ export const createOperation = async (incomingArgs)=>{
|
|
|
42
42
|
if (args.publishSpecificLocale) {
|
|
43
43
|
args.req.locale = args.publishSpecificLocale;
|
|
44
44
|
}
|
|
45
|
-
const { autosave = false, collection: { config: collectionConfig }, collection, depth, disableVerificationEmail, draft = false, duplicateFromID, overrideAccess, overwriteExistingFiles = false, populate, publishSpecificLocale, req: { fallbackLocale, locale, payload, payload: { config } }, req, select: incomingSelect, selectedLocales, showHiddenFields } = args;
|
|
45
|
+
const { autosave = false, collection: { config: collectionConfig }, collection, depth, disableVerificationEmail, draft = false, duplicateFromID, overrideAccess, overwriteExistingFiles = false, populate, publishAllLocales: publishAllLocalesArg, publishSpecificLocale, req: { fallbackLocale, locale, payload, payload: { config } }, req, select: incomingSelect, selectedLocales, showHiddenFields } = args;
|
|
46
46
|
let { data } = args;
|
|
47
|
-
const
|
|
47
|
+
const publishAllLocales = !draft && (publishAllLocalesArg ?? (hasLocalizeStatusEnabled(collectionConfig) ? false : true));
|
|
48
|
+
const isSavingDraft = Boolean(draft && hasDraftsEnabled(collectionConfig) && !publishAllLocales);
|
|
49
|
+
if (isSavingDraft) {
|
|
50
|
+
data._status = 'draft';
|
|
51
|
+
}
|
|
48
52
|
let duplicatedFromDocWithLocales = {};
|
|
49
53
|
let duplicatedFromDoc = {};
|
|
50
54
|
if (duplicateFromID) {
|
|
@@ -141,6 +145,22 @@ export const createOperation = async (incomingArgs)=>{
|
|
|
141
145
|
req,
|
|
142
146
|
skipValidation: isSavingDraft && !hasDraftValidationEnabled(collectionConfig)
|
|
143
147
|
});
|
|
148
|
+
if (config.localization && collectionConfig.versions && collectionConfig.versions.drafts && collectionConfig.versions.drafts.localizeStatus && publishAllLocales) {
|
|
149
|
+
let accessibleLocaleCodes = config.localization.localeCodes;
|
|
150
|
+
if (config.localization.filterAvailableLocales) {
|
|
151
|
+
const filteredLocales = await config.localization.filterAvailableLocales({
|
|
152
|
+
locales: config.localization.locales,
|
|
153
|
+
req
|
|
154
|
+
});
|
|
155
|
+
accessibleLocaleCodes = filteredLocales.map((locale)=>typeof locale === 'string' ? locale : locale.code);
|
|
156
|
+
}
|
|
157
|
+
if (typeof resultWithLocales._status !== 'object' || resultWithLocales._status === null) {
|
|
158
|
+
resultWithLocales._status = {};
|
|
159
|
+
}
|
|
160
|
+
for (const localeCode of accessibleLocaleCodes){
|
|
161
|
+
resultWithLocales._status[localeCode] = 'published';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
144
164
|
// /////////////////////////////////////
|
|
145
165
|
// Write files to local storage
|
|
146
166
|
// /////////////////////////////////////
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { CollectionSlug, JsonObject } from '../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { saveVersion } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { hasDraftsEnabled, hasDraftValidationEnabled } from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n selectedLocales?: string[]\n showHiddenFields?: boolean\n}\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'create',\n })\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n selectedLocales,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const isSavingDraft = Boolean(draft && hasDraftsEnabled(collectionConfig))\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: isSavingDraft,\n overrideAccess,\n req,\n selectedLocales,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !isSavingDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation: isSavingDraft && !hasDraftValidationEnabled(collectionConfig),\n })\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n returning: false,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","saveVersion","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","hasDraftsEnabled","hasDraftValidationEnabled","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","buildAfterOperation","buildBeforeOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overrideAccess","overwriteExistingFiles","populate","fallbackLocale","payload","select","incomingSelect","selectedLocales","showHiddenFields","isSavingDraft","Boolean","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","context","doc","global","hooks","length","hook","resultWithLocales","docWithLocales","skipValidation","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","versions","returning","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAiB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3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U;YACZJ,WAAW;YACXyD;QACF;QAEA,MAAMjF,gBAAgB;YAAE4B;YAAkBT;YAAQH;QAAI;QAEtD,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMZ,kBAAkBc;QAC1B;QAEA,OAAOiE;IACT,EAAE,OAAOQ,OAAgB;QACvB,MAAMnF,gBAAgBO,KAAKG,GAAG;QAC9B,MAAMyE;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { CollectionSlug, JsonObject } from '../../index.js'\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { saveVersion } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport {\n hasDraftsEnabled,\n hasDraftValidationEnabled,\n hasLocalizeStatusEnabled,\n} from '../../utilities/getVersionsConfig.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishAllLocales?: boolean\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n selectedLocales?: string[]\n showHiddenFields?: boolean\n}\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'create',\n })\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishAllLocales: publishAllLocalesArg,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n selectedLocales,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const publishAllLocales =\n !draft &&\n (publishAllLocalesArg ?? (hasLocalizeStatusEnabled(collectionConfig) ? false : true))\n const isSavingDraft = Boolean(draft && hasDraftsEnabled(collectionConfig) && !publishAllLocales)\n\n if (isSavingDraft) {\n data._status = 'draft'\n }\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: isSavingDraft,\n overrideAccess,\n req,\n selectedLocales,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !isSavingDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation: isSavingDraft && !hasDraftValidationEnabled(collectionConfig),\n })\n\n if (\n config.localization &&\n collectionConfig.versions &&\n collectionConfig.versions.drafts &&\n collectionConfig.versions.drafts.localizeStatus &&\n publishAllLocales\n ) {\n let accessibleLocaleCodes = config.localization.localeCodes\n\n if (config.localization.filterAvailableLocales) {\n const filteredLocales = await config.localization.filterAvailableLocales({\n locales: config.localization.locales,\n req,\n })\n accessibleLocaleCodes = filteredLocales.map((locale) =>\n typeof locale === 'string' ? locale : locale.code,\n )\n }\n\n if (typeof resultWithLocales._status !== 'object' || resultWithLocales._status === null) {\n resultWithLocales._status = {}\n }\n\n for (const localeCode of accessibleLocaleCodes) {\n resultWithLocales._status[localeCode] = 'published'\n }\n }\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n returning: false,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","saveVersion","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","hasDraftsEnabled","hasDraftValidationEnabled","hasLocalizeStatusEnabled","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","buildAfterOperation","buildBeforeOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overrideAccess","overwriteExistingFiles","populate","publishAllLocales","publishAllLocalesArg","fallbackLocale","payload","select","incomingSelect","selectedLocales","showHiddenFields","isSavingDraft","Boolean","_status","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","context","doc","global","hooks","length","hook","resultWithLocales","docWithLocales","skipValidation","localization","versions","drafts","localizeStatus","accessibleLocaleCodes","localeCodes","filterAvailableLocales","filteredLocales","locales","map","code","localeCode","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","returning","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAiB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAAS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AAG;QAC9B,MAAMuF;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findByID.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EAEV,wBAAwB,EAEzB,MAAM,oBAAoB,CAAA;AAO3B,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAA;
|
|
1
|
+
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findByID.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EAEV,wBAAwB,EAEzB,MAAM,oBAAoB,CAAA;AAO3B,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAA;AAYrF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAA;AAErD,eAAO,MAAM,iBAAiB,GAC5B,KAAK,SAAS,cAAc,EAC5B,cAAc,SAAS,OAAO,EAC9B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,YAAY,KACzB,OAAO,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CA0R3F,CAAA"}
|
|
@@ -7,6 +7,7 @@ import { afterRead } from '../../fields/hooks/afterRead/index.js';
|
|
|
7
7
|
import { validateQueryPaths } from '../../index.js';
|
|
8
8
|
import { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js';
|
|
9
9
|
import { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js';
|
|
10
|
+
import { getSelectMode } from '../../utilities/getSelectMode.js';
|
|
10
11
|
import { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js';
|
|
11
12
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
12
13
|
import { sanitizeSelect } from '../../utilities/sanitizeSelect.js';
|
|
@@ -78,6 +79,14 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
78
79
|
// /////////////////////////////////////
|
|
79
80
|
// Find by ID
|
|
80
81
|
// /////////////////////////////////////
|
|
82
|
+
let dbSelect = select;
|
|
83
|
+
if (collectionConfig.versions?.drafts && replaceWithVersion && select && getSelectMode(select) === 'include') {
|
|
84
|
+
dbSelect = {
|
|
85
|
+
...select,
|
|
86
|
+
createdAt: true,
|
|
87
|
+
updatedAt: true
|
|
88
|
+
};
|
|
89
|
+
}
|
|
81
90
|
const findOneArgs = {
|
|
82
91
|
collection: collectionConfig.slug,
|
|
83
92
|
draftsEnabled: replaceWithVersion,
|
|
@@ -86,7 +95,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
86
95
|
req: {
|
|
87
96
|
transactionID: req.transactionID
|
|
88
97
|
},
|
|
89
|
-
select,
|
|
98
|
+
select: dbSelect,
|
|
90
99
|
where: fullWhere
|
|
91
100
|
};
|
|
92
101
|
if (!findOneArgs.where?.and?.[0]?.id) {
|