payload 3.91.0-internal.6e3dc85 → 3.91.0-internal.c1569dc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/endpoints/refresh.d.ts.map +1 -1
- package/dist/auth/endpoints/refresh.js +4 -6
- package/dist/auth/endpoints/refresh.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +54 -6
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/fields/baseFields/slug/generateSlug.js +3 -3
- package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
- package/dist/fields/baseFields/slug/generateSlug.spec.js +22 -0
- package/dist/fields/baseFields/slug/generateSlug.spec.js.map +1 -0
- package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/findVersionByID.js +4 -3
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/auth/endpoints/refresh.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/auth/endpoints/refresh.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAO3D,eAAO,MAAM,cAAc,EAAE,cAwC5B,CAAA"}
|
|
@@ -14,21 +14,19 @@ export const refreshHandler = async (req)=>{
|
|
|
14
14
|
collection,
|
|
15
15
|
req
|
|
16
16
|
});
|
|
17
|
+
const { refreshedToken, ...resultWithoutToken } = result;
|
|
17
18
|
if (result.setCookie) {
|
|
18
19
|
const cookie = generatePayloadCookie({
|
|
19
20
|
collectionAuthConfig: collection.config.auth,
|
|
20
21
|
cookiePrefix: req.payload.config.cookiePrefix,
|
|
21
|
-
token:
|
|
22
|
+
token: refreshedToken
|
|
22
23
|
});
|
|
23
|
-
if (collection.config.auth.removeTokenFromResponses) {
|
|
24
|
-
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
25
|
-
delete result.refreshedToken;
|
|
26
|
-
}
|
|
27
24
|
headers.set('Set-Cookie', cookie);
|
|
28
25
|
}
|
|
26
|
+
const responseResult = collection.config.auth.removeTokenFromResponses ? resultWithoutToken : result;
|
|
29
27
|
return Response.json({
|
|
30
28
|
message: t('authentication:tokenRefreshSuccessful'),
|
|
31
|
-
...
|
|
29
|
+
...responseResult
|
|
32
30
|
}, {
|
|
33
31
|
headers,
|
|
34
32
|
status: httpStatus.OK
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/endpoints/refresh.ts"],"sourcesContent":["import { 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 { generatePayloadCookie } from '../cookies.js'\nimport { refreshOperation } from '../operations/refresh.js'\n\nexport const refreshHandler: PayloadHandler = async (req) => {\n const collection = getRequestCollection(req)\n const { t } = req\n\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n const result = await refreshOperation({\n collection,\n req,\n })\n\n if (result.setCookie) {\n const cookie = generatePayloadCookie({\n collectionAuthConfig: collection.config.auth,\n cookiePrefix: req.payload.config.cookiePrefix,\n token:
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/endpoints/refresh.ts"],"sourcesContent":["import { 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 { generatePayloadCookie } from '../cookies.js'\nimport { refreshOperation } from '../operations/refresh.js'\n\nexport const refreshHandler: PayloadHandler = async (req) => {\n const collection = getRequestCollection(req)\n const { t } = req\n\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n const result = await refreshOperation({\n collection,\n req,\n })\n\n const { refreshedToken, ...resultWithoutToken } = result\n\n if (result.setCookie) {\n const cookie = generatePayloadCookie({\n collectionAuthConfig: collection.config.auth,\n cookiePrefix: req.payload.config.cookiePrefix,\n token: refreshedToken,\n })\n\n headers.set('Set-Cookie', cookie)\n }\n\n const responseResult = collection.config.auth.removeTokenFromResponses\n ? resultWithoutToken\n : result\n\n return Response.json(\n {\n message: t('authentication:tokenRefreshSuccessful'),\n ...responseResult,\n },\n {\n headers,\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["status","httpStatus","getRequestCollection","headersWithCors","generatePayloadCookie","refreshOperation","refreshHandler","req","collection","t","headers","Headers","result","refreshedToken","resultWithoutToken","setCookie","cookie","collectionAuthConfig","config","auth","cookiePrefix","payload","token","set","responseResult","removeTokenFromResponses","Response","json","message","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,qBAAqB,QAAQ,gBAAe;AACrD,SAASC,gBAAgB,QAAQ,2BAA0B;AAE3D,OAAO,MAAMC,iBAAiC,OAAOC;IACnD,MAAMC,aAAaN,qBAAqBK;IACxC,MAAM,EAAEE,CAAC,EAAE,GAAGF;IAEd,MAAMG,UAAUP,gBAAgB;QAC9BO,SAAS,IAAIC;QACbJ;IACF;IAEA,MAAMK,SAAS,MAAMP,iBAAiB;QACpCG;QACAD;IACF;IAEA,MAAM,EAAEM,cAAc,EAAE,GAAGC,oBAAoB,GAAGF;IAElD,IAAIA,OAAOG,SAAS,EAAE;QACpB,MAAMC,SAASZ,sBAAsB;YACnCa,sBAAsBT,WAAWU,MAAM,CAACC,IAAI;YAC5CC,cAAcb,IAAIc,OAAO,CAACH,MAAM,CAACE,YAAY;YAC7CE,OAAOT;QACT;QAEAH,QAAQa,GAAG,CAAC,cAAcP;IAC5B;IAEA,MAAMQ,iBAAiBhB,WAAWU,MAAM,CAACC,IAAI,CAACM,wBAAwB,GAClEX,qBACAF;IAEJ,OAAOc,SAASC,IAAI,CAClB;QACEC,SAASnB,EAAE;QACX,GAAGe,cAAc;IACnB,GACA;QACEd;QACAV,QAAQC,WAAW4B,EAAE;IACvB;AAEJ,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,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC5E,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,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC5E,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;AAerF,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,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,GACnD,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;AAEjD,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,CAuV3F,CAAA"}
|
|
@@ -11,6 +11,9 @@ import { getSelectMode } from '../../utilities/getSelectMode.js';
|
|
|
11
11
|
import { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js';
|
|
12
12
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
13
13
|
import { sanitizeSelect } from '../../utilities/sanitizeSelect.js';
|
|
14
|
+
import { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js';
|
|
15
|
+
import { appendVersionToQueryKey } from '../../versions/drafts/appendVersionToQueryKey.js';
|
|
16
|
+
import { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js';
|
|
14
17
|
import { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js';
|
|
15
18
|
import { buildAfterOperation } from './utilities/buildAfterOperation.js';
|
|
16
19
|
import { buildBeforeOperation } from './utilities/buildBeforeOperation.js';
|
|
@@ -45,6 +48,10 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
45
48
|
if (accessResult === false) {
|
|
46
49
|
return null;
|
|
47
50
|
}
|
|
51
|
+
const isValidID = typeof id === 'string' && id.length > 0 || typeof id === 'number' && Number.isFinite(id);
|
|
52
|
+
if (!isValidID) {
|
|
53
|
+
throw new NotFound(t);
|
|
54
|
+
}
|
|
48
55
|
const where = {
|
|
49
56
|
id: {
|
|
50
57
|
equals: id
|
|
@@ -80,6 +87,9 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
80
87
|
// /////////////////////////////////////
|
|
81
88
|
// Find by ID
|
|
82
89
|
// /////////////////////////////////////
|
|
90
|
+
const shouldQueryDrafts = !args.data && replaceWithVersion && hasDraftsEnabled(collectionConfig);
|
|
91
|
+
let docFromDB;
|
|
92
|
+
let query = fullWhere;
|
|
83
93
|
let dbSelect = select;
|
|
84
94
|
if (collectionConfig.versions?.drafts && replaceWithVersion && select && getSelectMode(select) === 'include') {
|
|
85
95
|
dbSelect = {
|
|
@@ -99,10 +109,48 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
99
109
|
select: dbSelect,
|
|
100
110
|
where: fullWhere
|
|
101
111
|
};
|
|
102
|
-
if (
|
|
103
|
-
|
|
112
|
+
if (shouldQueryDrafts) {
|
|
113
|
+
query = appendVersionToQueryKey(fullWhere);
|
|
114
|
+
await validateQueryPaths({
|
|
115
|
+
collectionConfig,
|
|
116
|
+
overrideAccess,
|
|
117
|
+
req,
|
|
118
|
+
versionFields: buildVersionCollectionFields(req.payload.config, collectionConfig, true),
|
|
119
|
+
where: appendVersionToQueryKey(where)
|
|
120
|
+
});
|
|
121
|
+
const { docs } = await req.payload.db.queryDrafts({
|
|
122
|
+
collection: collectionConfig.slug,
|
|
123
|
+
joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,
|
|
124
|
+
limit: 1,
|
|
125
|
+
locale: locale,
|
|
126
|
+
pagination: false,
|
|
127
|
+
req,
|
|
128
|
+
select: getQueryDraftsSelect({
|
|
129
|
+
select
|
|
130
|
+
}),
|
|
131
|
+
where: query
|
|
132
|
+
});
|
|
133
|
+
docFromDB = docs[0];
|
|
134
|
+
if (!docFromDB) {
|
|
135
|
+
const { docs: existingVersions } = await req.payload.db.queryDrafts({
|
|
136
|
+
collection: collectionConfig.slug,
|
|
137
|
+
limit: 1,
|
|
138
|
+
locale: locale,
|
|
139
|
+
pagination: false,
|
|
140
|
+
req,
|
|
141
|
+
select: {
|
|
142
|
+
parent: true
|
|
143
|
+
},
|
|
144
|
+
where: appendVersionToQueryKey(where)
|
|
145
|
+
});
|
|
146
|
+
if (!existingVersions[0]) {
|
|
147
|
+
query = fullWhere;
|
|
148
|
+
docFromDB = await req.payload.db.findOne(findOneArgs);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
docFromDB = await req.payload.db.findOne(findOneArgs);
|
|
104
153
|
}
|
|
105
|
-
const docFromDB = await req.payload.db.findOne(findOneArgs);
|
|
106
154
|
if (!docFromDB && !args.data) {
|
|
107
155
|
if (!disableErrors) {
|
|
108
156
|
throw new NotFound(req.t);
|
|
@@ -170,7 +218,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
170
218
|
// /////////////////////////////////////
|
|
171
219
|
// Replace document with draft if available
|
|
172
220
|
// /////////////////////////////////////
|
|
173
|
-
if (replaceWithVersion && hasDraftsEnabled(collectionConfig)) {
|
|
221
|
+
if (!shouldQueryDrafts && replaceWithVersion && hasDraftsEnabled(collectionConfig)) {
|
|
174
222
|
result = await replaceWithDraftIfAvailable({
|
|
175
223
|
accessResult,
|
|
176
224
|
doc: result,
|
|
@@ -191,7 +239,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
191
239
|
context: req.context,
|
|
192
240
|
doc: result,
|
|
193
241
|
overrideAccess,
|
|
194
|
-
query
|
|
242
|
+
query,
|
|
195
243
|
req
|
|
196
244
|
}) || result;
|
|
197
245
|
}
|
|
@@ -226,7 +274,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
226
274
|
context: req.context,
|
|
227
275
|
doc: result,
|
|
228
276
|
overrideAccess,
|
|
229
|
-
query
|
|
277
|
+
query,
|
|
230
278
|
req
|
|
231
279
|
}) || result;
|
|
232
280
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/findByID.ts"],"sourcesContent":["import type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug, FindOptions, JoinQuery } from '../../index.js'\nimport type {\n ApplyDisableErrors,\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n TypeWithID,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead, type AfterReadArgs } from '../../fields/hooks/afterRead/index.js'\nimport { validateQueryPaths } from '../../index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { getSelectMode } from '../../utilities/getSelectMode.js'\nimport { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type FindByIDArgs = {\n collection: Collection\n currentDepth?: number\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n id: number | string\n includeLockStatus?: boolean\n joins?: JoinQuery\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n trash?: boolean\n} & Pick<AfterReadArgs<JsonObject>, 'flattenLocales'> &\n Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findByIDOperation = async <\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: FindByIDArgs,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> => {\n let args = incomingArgs\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'read',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n draft: replaceWithVersion = false,\n flattenLocales,\n includeLockStatus: includeLockStatusFromArgs,\n joins,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale, t },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n } = args\n\n const includeLockStatus =\n includeLockStatusFromArgs && req.payload.collections?.[lockedDocumentsCollectionSlug]\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResult = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.read)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResult === false) {\n return null!\n }\n\n const where = { id: { equals: id } }\n\n let fullWhere = combineQueries(where, accessResult)\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({\n fields: collectionConfig.flattenedFields,\n payload: args.req.payload,\n where: fullWhere,\n })\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess,\n req,\n })\n\n // execute only if there's a custom ID and potentially overwriten access on id\n if (req.payload.collections[collectionConfig.slug]!.customIDType) {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n let dbSelect = select\n\n if (\n collectionConfig.versions?.drafts &&\n replaceWithVersion &&\n select &&\n getSelectMode(select) === 'include'\n ) {\n dbSelect = { ...select, createdAt: true, updatedAt: true }\n }\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n draftsEnabled: replaceWithVersion,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n locale: locale!,\n req: {\n transactionID: req.transactionID,\n } as PayloadRequest,\n select: dbSelect,\n where: fullWhere,\n }\n\n if (!findOneArgs.where?.and?.[0]?.id) {\n throw new NotFound(t)\n }\n\n const docFromDB = await req.payload.db.findOne(findOneArgs)\n\n if (!docFromDB && !args.data) {\n if (!disableErrors) {\n throw new NotFound(req.t)\n }\n return null!\n }\n\n let result: DataFromCollectionSlug<TSlug> =\n (args.data as DataFromCollectionSlug<TSlug>) ?? docFromDB!\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n result = { ...result, collection: collectionConfig.slug }\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n\n if (includeLockStatus && id) {\n let lockStatus: (JsonObject & TypeWithID) | null = null\n\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n 'document.relationTo': {\n equals: collectionConfig.slug,\n },\n },\n {\n 'document.value': {\n equals: id,\n },\n },\n // Query where the lock is newer than the current time minus lock time\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]!\n }\n } catch {\n // swallow error\n }\n\n result._isLocked = !!lockStatus\n result._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (replaceWithVersion && hasDraftsEnabled(collectionConfig)) {\n result = await replaceWithDraftIfAvailable({\n accessResult,\n doc: result,\n entity: collectionConfig,\n entityType: 'collection',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeRead?.length) {\n for (const hook of collectionConfig.hooks.beforeRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n overrideAccess,\n query: findOneArgs.where,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result,\n draft: replaceWithVersion,\n fallbackLocale: fallbackLocale!,\n flattenLocales,\n global: null,\n locale: locale!,\n 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 overrideAccess,\n query: findOneArgs.where,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'findByID',\n overrideAccess,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as ApplyDisableErrors<\n TransformCollectionWithSelect<TSlug, TSelect>,\n TDisableErrors\n >\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","sanitizeJoinQuery","sanitizeWhereQuery","NotFound","afterRead","validateQueryPaths","lockedDocumentsCollectionSlug","appendNonTrashedFilter","getSelectMode","hasDraftsEnabled","killTransaction","sanitizeSelect","replaceWithDraftIfAvailable","buildAfterOperation","buildBeforeOperation","findByIDOperation","incomingArgs","args","collection","config","operation","overrideAccess","id","collectionConfig","currentDepth","depth","disableErrors","draft","replaceWithVersion","flattenLocales","includeLockStatus","includeLockStatusFromArgs","joins","populate","req","fallbackLocale","locale","t","select","incomingSelect","showHiddenFields","trash","payload","collections","fields","flattenedFields","forceSelect","accessResult","access","read","where","equals","fullWhere","enableTrash","sanitizedJoins","slug","customIDType","dbSelect","versions","drafts","createdAt","updatedAt","findOneArgs","draftsEnabled","payloadAPI","transactionID","and","docFromDB","db","findOne","data","result","auth","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","limit","pagination","greater_than","Date","getTime","docs","length","_isLocked","_userEditing","user","value","doc","entity","entityType","hooks","beforeRead","hook","context","query","global","error"],"mappings":"AAiBA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,iBAAiB,QAAQ,sCAAqC;AAC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;gBACnDmE,SACE,AAAC,MAAM2B,KAAK;oBACVhF,YAAYK;oBACZ4E,SAASjE,IAAIiE,OAAO;oBACpBN,KAAKtB;oBACLlD;oBACA+E,OAAOtC,YAAYZ,KAAK;oBACxBhB;gBACF,MAAOqC;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAM1D,oBAAoB;YACjCI;YACAC,YAAYK;YACZH,WAAW;YACXC;YACAkD;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IAIT,EAAE,OAAO+B,OAAgB;QACvB,MAAM5F,gBAAgBO,KAAKiB,GAAG;QAC9B,MAAMoE;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/findByID.ts"],"sourcesContent":["import type { FindOneArgs } from '../../database/types.js'\nimport type { CollectionSlug, FindOptions, JoinQuery } from '../../index.js'\nimport type {\n ApplyDisableErrors,\n JsonObject,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n TypeWithID,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { NotFound } from '../../errors/index.js'\nimport { afterRead, type AfterReadArgs } from '../../fields/hooks/afterRead/index.js'\nimport { validateQueryPaths } from '../../index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { getSelectMode } from '../../utilities/getSelectMode.js'\nimport { hasDraftsEnabled } from '../../utilities/getVersionsConfig.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js'\nimport { appendVersionToQueryKey } from '../../versions/drafts/appendVersionToQueryKey.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\nimport { replaceWithDraftIfAvailable } from '../../versions/drafts/replaceWithDraftIfAvailable.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\n\nexport type FindByIDArgs = {\n collection: Collection\n currentDepth?: number\n /**\n * You may pass the document data directly which will skip the `db.findOne` database query.\n * This is useful if you want to use this endpoint solely for running hooks and populating data.\n */\n data?: Record<string, unknown>\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n id: number | string\n includeLockStatus?: boolean\n joins?: JoinQuery\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n trash?: boolean\n} & Pick<AfterReadArgs<JsonObject>, 'flattenLocales'> &\n Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findByIDOperation = async <\n TSlug extends CollectionSlug,\n TDisableErrors extends boolean,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: FindByIDArgs,\n): Promise<ApplyDisableErrors<TransformCollectionWithSelect<TSlug, TSelect>, TDisableErrors>> => {\n let args = incomingArgs\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'read',\n overrideAccess: args.overrideAccess!,\n })\n\n const {\n id,\n collection: { config: collectionConfig },\n currentDepth,\n depth,\n disableErrors,\n draft: replaceWithVersion = false,\n flattenLocales,\n includeLockStatus: includeLockStatusFromArgs,\n joins,\n overrideAccess = false,\n populate,\n req: { fallbackLocale, locale, t },\n req,\n select: incomingSelect,\n showHiddenFields,\n trash = false,\n } = args\n\n const includeLockStatus =\n includeLockStatusFromArgs && req.payload.collections?.[lockedDocumentsCollectionSlug]\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResult = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, collectionConfig.access.read)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResult === false) {\n return null!\n }\n\n const isValidID =\n (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && Number.isFinite(id))\n\n if (!isValidID) {\n throw new NotFound(t)\n }\n\n const where = { id: { equals: id } }\n\n let fullWhere = combineQueries(where, accessResult)\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n sanitizeWhereQuery({\n fields: collectionConfig.flattenedFields,\n payload: args.req.payload,\n where: fullWhere,\n })\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess,\n req,\n })\n\n // execute only if there's a custom ID and potentially overwriten access on id\n if (req.payload.collections[collectionConfig.slug]!.customIDType) {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n const shouldQueryDrafts = !args.data && replaceWithVersion && hasDraftsEnabled(collectionConfig)\n let docFromDB: DataFromCollectionSlug<TSlug> | null | undefined\n let query = fullWhere\n\n let dbSelect = select\n\n if (\n collectionConfig.versions?.drafts &&\n replaceWithVersion &&\n select &&\n getSelectMode(select) === 'include'\n ) {\n dbSelect = { ...select, createdAt: true, updatedAt: true }\n }\n\n const findOneArgs: FindOneArgs = {\n collection: collectionConfig.slug,\n draftsEnabled: replaceWithVersion,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n locale: locale!,\n req: {\n transactionID: req.transactionID,\n } as PayloadRequest,\n select: dbSelect,\n where: fullWhere,\n }\n\n if (shouldQueryDrafts) {\n query = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n versionFields: buildVersionCollectionFields(req.payload.config, collectionConfig, true),\n where: appendVersionToQueryKey(where),\n })\n\n const { docs } = await req.payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n limit: 1,\n locale: locale!,\n pagination: false,\n req,\n select: getQueryDraftsSelect({ select }),\n where: query,\n })\n\n docFromDB = docs[0]\n\n if (!docFromDB) {\n const { docs: existingVersions } = await req.payload.db.queryDrafts({\n collection: collectionConfig.slug,\n limit: 1,\n locale: locale!,\n pagination: false,\n req,\n select: { parent: true },\n where: appendVersionToQueryKey(where),\n })\n\n if (!existingVersions[0]) {\n query = fullWhere\n docFromDB = await req.payload.db.findOne(findOneArgs)\n }\n }\n } else {\n docFromDB = await req.payload.db.findOne(findOneArgs)\n }\n\n if (!docFromDB && !args.data) {\n if (!disableErrors) {\n throw new NotFound(req.t)\n }\n return null!\n }\n\n let result: DataFromCollectionSlug<TSlug> =\n (args.data as DataFromCollectionSlug<TSlug>) ?? docFromDB!\n\n // /////////////////////////////////////\n // Add collection property for auth collections\n // /////////////////////////////////////\n\n if (collectionConfig.auth) {\n result = { ...result, collection: collectionConfig.slug }\n }\n\n // /////////////////////////////////////\n // Include Lock Status if required\n // /////////////////////////////////////\n\n if (includeLockStatus && id) {\n let lockStatus: (JsonObject & TypeWithID) | null = null\n\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDurationDefault = 300 // Default 5 minutes in seconds\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const lockedDocument = await req.payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n where: {\n and: [\n {\n 'document.relationTo': {\n equals: collectionConfig.slug,\n },\n },\n {\n 'document.value': {\n equals: id,\n },\n },\n // Query where the lock is newer than the current time minus lock time\n {\n updatedAt: {\n greater_than: new Date(new Date().getTime() - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n if (lockedDocument && lockedDocument.docs.length > 0) {\n lockStatus = lockedDocument.docs[0]!\n }\n } catch {\n // swallow error\n }\n\n result._isLocked = !!lockStatus\n result._userEditing = lockStatus?.user?.value ?? null\n }\n\n // /////////////////////////////////////\n // Replace document with draft if available\n // /////////////////////////////////////\n\n if (!shouldQueryDrafts && replaceWithVersion && hasDraftsEnabled(collectionConfig)) {\n result = await replaceWithDraftIfAvailable({\n accessResult,\n doc: result,\n entity: collectionConfig,\n entityType: 'collection',\n overrideAccess,\n req,\n select,\n })\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeRead?.length) {\n for (const hook of collectionConfig.hooks.beforeRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n overrideAccess,\n query,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result,\n draft: replaceWithVersion,\n fallbackLocale: fallbackLocale!,\n flattenLocales,\n global: null,\n locale: locale!,\n 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 overrideAccess,\n query,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'findByID',\n overrideAccess,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as ApplyDisableErrors<\n TransformCollectionWithSelect<TSlug, TSelect>,\n TDisableErrors\n >\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","sanitizeJoinQuery","sanitizeWhereQuery","NotFound","afterRead","validateQueryPaths","lockedDocumentsCollectionSlug","appendNonTrashedFilter","getSelectMode","hasDraftsEnabled","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSelect","replaceWithDraftIfAvailable","buildAfterOperation","buildBeforeOperation","findByIDOperation","incomingArgs","args","collection","config","operation","overrideAccess","id","collectionConfig","currentDepth","depth","disableErrors","draft","replaceWithVersion","flattenLocales","includeLockStatus","includeLockStatusFromArgs","joins","populate","req","fallbackLocale","locale","t","select","incomingSelect","showHiddenFields","trash","payload","collections","fields","flattenedFields","forceSelect","accessResult","access","read","isValidID","length","Number","isFinite","where","equals","fullWhere","enableTrash","sanitizedJoins","slug","customIDType","shouldQueryDrafts","data","docFromDB","query","dbSelect","versions","drafts","createdAt","updatedAt","findOneArgs","draftsEnabled","payloadAPI","transactionID","versionFields","docs","db","queryDrafts","limit","pagination","existingVersions","parent","findOne","result","auth","lockStatus","lockDocumentsProp","lockDocuments","lockDurationDefault","lockDuration","duration","lockDurationInMilliseconds","lockedDocument","find","and","greater_than","Date","getTime","_isLocked","_userEditing","user","value","doc","entity","entityType","hooks","beforeRead","hook","context","global","error"],"mappings":"AAiBA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAA4B,wCAAuC;AACrF,SAASC,kBAAkB,QAAQ,iBAAgB;AACnD,SAASC,6BAA6B,QAAQ,mCAAkC;AAChF,SAASC,sBAAsB,QAAQ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,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAMtE,oBAAoB;YACjCI;YACAC,YAAYK;YACZH,WAAW;YACXC;YACA8D;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IAIT,EAAE,OAAO2B,OAAgB;QACvB,MAAMvG,gBAAgBU,KAAKiB,GAAG;QAC9B,MAAM4E;IACR;AACF,EAAC"}
|
|
@@ -17,7 +17,7 @@ const slugify = ({ customSlugify, data, req, valueToSlugify })=>{
|
|
|
17
17
|
*/ export const generateSlug = ({ slugFieldName, slugify: customSlugify, useAsSlug })=>async ({ collection, data, global, operation, originalDoc, req, value: isChecked })=>{
|
|
18
18
|
if (operation === 'create') {
|
|
19
19
|
if (data) {
|
|
20
|
-
data[slugFieldName] = slugify({
|
|
20
|
+
data[slugFieldName] = await slugify({
|
|
21
21
|
customSlugify,
|
|
22
22
|
data,
|
|
23
23
|
req,
|
|
@@ -36,7 +36,7 @@ const slugify = ({ customSlugify, data, req, valueToSlugify })=>{
|
|
|
36
36
|
if (!hasAutosaveEnabled(collection || global)) {
|
|
37
37
|
// We can generate the slug at this point
|
|
38
38
|
if (data) {
|
|
39
|
-
data[slugFieldName] = slugify({
|
|
39
|
+
data[slugFieldName] = await slugify({
|
|
40
40
|
customSlugify,
|
|
41
41
|
data,
|
|
42
42
|
req,
|
|
@@ -53,7 +53,7 @@ const slugify = ({ customSlugify, data, req, valueToSlugify })=>{
|
|
|
53
53
|
if (data) {
|
|
54
54
|
// If the fallback is an empty string, we want the slug to return to `null`
|
|
55
55
|
// This will ensure that live preview conditions continue to run as expected
|
|
56
|
-
data[slugFieldName] = data?.[useAsSlug] ? slugify({
|
|
56
|
+
data[slugFieldName] = data?.[useAsSlug] ? await slugify({
|
|
57
57
|
customSlugify,
|
|
58
58
|
data,
|
|
59
59
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/baseFields/slug/generateSlug.ts"],"sourcesContent":["import type { PayloadRequest } from '../../../types/index.js'\nimport type { FieldHook } from '../../config/types.js'\nimport type { SlugFieldArgs, Slugify } from './index.js'\n\nimport { hasAutosaveEnabled } from '../../../utilities/getVersionsConfig.js'\nimport { slugify as defaultSlugify } from '../../../utilities/slugify.js'\nimport { countVersions } from './countVersions.js'\n\ntype HookArgs = {\n slugFieldName: NonNullable<SlugFieldArgs['name']>\n} & Pick<SlugFieldArgs, 'slugify'> &\n Required<Pick<SlugFieldArgs, 'useAsSlug'>>\n\nconst slugify = ({\n customSlugify,\n data,\n req,\n valueToSlugify,\n}: {\n customSlugify?: Slugify\n data: Record<string, unknown>\n req: PayloadRequest\n valueToSlugify?: string\n}) => {\n if (customSlugify) {\n return customSlugify({ data, req, valueToSlugify })\n }\n\n return defaultSlugify(valueToSlugify)\n}\n\n/**\n * This is a `BeforeChange` field hook used to auto-generate the `slug` field.\n * See `slugField` for more details.\n */\nexport const generateSlug =\n ({ slugFieldName, slugify: customSlugify, useAsSlug }: HookArgs): FieldHook =>\n async ({ collection, data, global, operation, originalDoc, req, value: isChecked }) => {\n if (operation === 'create') {\n if (data) {\n data[slugFieldName] = slugify({\n customSlugify,\n data,\n req,\n // Ensure user-defined slugs are not overwritten during create\n // Use a generic falsy check here to include empty strings\n valueToSlugify: data?.[slugFieldName] || data?.[useAsSlug],\n })\n }\n\n return Boolean(!data?.[slugFieldName])\n }\n\n if (operation === 'update') {\n // Early return to avoid additional processing\n if (!isChecked) {\n return false\n }\n\n if (!hasAutosaveEnabled(collection || global!)) {\n // We can generate the slug at this point\n if (data) {\n data[slugFieldName] = slugify({\n customSlugify,\n data,\n req,\n valueToSlugify: data?.[useAsSlug],\n })\n }\n\n return Boolean(!data?.[slugFieldName])\n } else {\n // If we're publishing, we can avoid querying as we can safely assume we've exceeded the version threshold (2)\n const isPublishing = data?._status === 'published'\n\n // Ensure the user can take over the generated slug themselves without it ever being overridden back\n const userOverride = data?.[slugFieldName] !== originalDoc?.[slugFieldName]\n\n if (!userOverride) {\n if (data) {\n // If the fallback is an empty string, we want the slug to return to `null`\n // This will ensure that live preview conditions continue to run as expected\n data[slugFieldName] = data?.[useAsSlug]\n ? slugify({\n customSlugify,\n data,\n req,\n valueToSlugify: data?.[useAsSlug],\n })\n : null\n }\n }\n\n if (isPublishing || userOverride) {\n return false\n }\n\n // Important: ensure `countVersions` is not called unnecessarily often\n // That is why this is buried beneath all these conditions\n const versionCount = await countVersions({\n collectionSlug: collection?.slug,\n globalSlug: global?.slug,\n parentID: originalDoc?.id,\n req,\n })\n\n if (versionCount <= 2) {\n return true\n } else {\n return false\n }\n }\n }\n }\n"],"names":["hasAutosaveEnabled","slugify","defaultSlugify","countVersions","customSlugify","data","req","valueToSlugify","generateSlug","slugFieldName","useAsSlug","collection","global","operation","originalDoc","value","isChecked","Boolean","isPublishing","_status","userOverride","versionCount","collectionSlug","slug","globalSlug","parentID","id"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,0CAAyC;AAC5E,SAASC,WAAWC,cAAc,QAAQ,gCAA+B;AACzE,SAASC,aAAa,QAAQ,qBAAoB;AAOlD,MAAMF,UAAU,CAAC,EACfG,aAAa,EACbC,IAAI,EACJC,GAAG,EACHC,cAAc,EAMf;IACC,IAAIH,eAAe;QACjB,OAAOA,cAAc;YAAEC;YAAMC;YAAKC;QAAe;IACnD;IAEA,OAAOL,eAAeK;AACxB;AAEA;;;CAGC,GACD,OAAO,MAAMC,eACX,CAAC,EAAEC,aAAa,EAAER,SAASG,aAAa,EAAEM,SAAS,EAAY,GAC/D,OAAO,EAAEC,UAAU,EAAEN,IAAI,EAAEO,MAAM,EAAEC,SAAS,EAAEC,WAAW,EAAER,GAAG,EAAES,OAAOC,SAAS,EAAE;QAChF,IAAIH,cAAc,UAAU;YAC1B,IAAIR,MAAM;gBACRA,IAAI,CAACI,cAAc,
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/baseFields/slug/generateSlug.ts"],"sourcesContent":["import type { PayloadRequest } from '../../../types/index.js'\nimport type { FieldHook } from '../../config/types.js'\nimport type { SlugFieldArgs, Slugify } from './index.js'\n\nimport { hasAutosaveEnabled } from '../../../utilities/getVersionsConfig.js'\nimport { slugify as defaultSlugify } from '../../../utilities/slugify.js'\nimport { countVersions } from './countVersions.js'\n\ntype HookArgs = {\n slugFieldName: NonNullable<SlugFieldArgs['name']>\n} & Pick<SlugFieldArgs, 'slugify'> &\n Required<Pick<SlugFieldArgs, 'useAsSlug'>>\n\nconst slugify = ({\n customSlugify,\n data,\n req,\n valueToSlugify,\n}: {\n customSlugify?: Slugify\n data: Record<string, unknown>\n req: PayloadRequest\n valueToSlugify?: string\n}) => {\n if (customSlugify) {\n return customSlugify({ data, req, valueToSlugify })\n }\n\n return defaultSlugify(valueToSlugify)\n}\n\n/**\n * This is a `BeforeChange` field hook used to auto-generate the `slug` field.\n * See `slugField` for more details.\n */\nexport const generateSlug =\n ({ slugFieldName, slugify: customSlugify, useAsSlug }: HookArgs): FieldHook =>\n async ({ collection, data, global, operation, originalDoc, req, value: isChecked }) => {\n if (operation === 'create') {\n if (data) {\n data[slugFieldName] = await slugify({\n customSlugify,\n data,\n req,\n // Ensure user-defined slugs are not overwritten during create\n // Use a generic falsy check here to include empty strings\n valueToSlugify: data?.[slugFieldName] || data?.[useAsSlug],\n })\n }\n\n return Boolean(!data?.[slugFieldName])\n }\n\n if (operation === 'update') {\n // Early return to avoid additional processing\n if (!isChecked) {\n return false\n }\n\n if (!hasAutosaveEnabled(collection || global!)) {\n // We can generate the slug at this point\n if (data) {\n data[slugFieldName] = await slugify({\n customSlugify,\n data,\n req,\n valueToSlugify: data?.[useAsSlug],\n })\n }\n\n return Boolean(!data?.[slugFieldName])\n } else {\n // If we're publishing, we can avoid querying as we can safely assume we've exceeded the version threshold (2)\n const isPublishing = data?._status === 'published'\n\n // Ensure the user can take over the generated slug themselves without it ever being overridden back\n const userOverride = data?.[slugFieldName] !== originalDoc?.[slugFieldName]\n\n if (!userOverride) {\n if (data) {\n // If the fallback is an empty string, we want the slug to return to `null`\n // This will ensure that live preview conditions continue to run as expected\n data[slugFieldName] = data?.[useAsSlug]\n ? await slugify({\n customSlugify,\n data,\n req,\n valueToSlugify: data?.[useAsSlug],\n })\n : null\n }\n }\n\n if (isPublishing || userOverride) {\n return false\n }\n\n // Important: ensure `countVersions` is not called unnecessarily often\n // That is why this is buried beneath all these conditions\n const versionCount = await countVersions({\n collectionSlug: collection?.slug,\n globalSlug: global?.slug,\n parentID: originalDoc?.id,\n req,\n })\n\n if (versionCount <= 2) {\n return true\n } else {\n return false\n }\n }\n }\n }\n"],"names":["hasAutosaveEnabled","slugify","defaultSlugify","countVersions","customSlugify","data","req","valueToSlugify","generateSlug","slugFieldName","useAsSlug","collection","global","operation","originalDoc","value","isChecked","Boolean","isPublishing","_status","userOverride","versionCount","collectionSlug","slug","globalSlug","parentID","id"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,0CAAyC;AAC5E,SAASC,WAAWC,cAAc,QAAQ,gCAA+B;AACzE,SAASC,aAAa,QAAQ,qBAAoB;AAOlD,MAAMF,UAAU,CAAC,EACfG,aAAa,EACbC,IAAI,EACJC,GAAG,EACHC,cAAc,EAMf;IACC,IAAIH,eAAe;QACjB,OAAOA,cAAc;YAAEC;YAAMC;YAAKC;QAAe;IACnD;IAEA,OAAOL,eAAeK;AACxB;AAEA;;;CAGC,GACD,OAAO,MAAMC,eACX,CAAC,EAAEC,aAAa,EAAER,SAASG,aAAa,EAAEM,SAAS,EAAY,GAC/D,OAAO,EAAEC,UAAU,EAAEN,IAAI,EAAEO,MAAM,EAAEC,SAAS,EAAEC,WAAW,EAAER,GAAG,EAAES,OAAOC,SAAS,EAAE;QAChF,IAAIH,cAAc,UAAU;YAC1B,IAAIR,MAAM;gBACRA,IAAI,CAACI,cAAc,GAAG,MAAMR,QAAQ;oBAClCG;oBACAC;oBACAC;oBACA,8DAA8D;oBAC9D,0DAA0D;oBAC1DC,gBAAgBF,MAAM,CAACI,cAAc,IAAIJ,MAAM,CAACK,UAAU;gBAC5D;YACF;YAEA,OAAOO,QAAQ,CAACZ,MAAM,CAACI,cAAc;QACvC;QAEA,IAAII,cAAc,UAAU;YAC1B,8CAA8C;YAC9C,IAAI,CAACG,WAAW;gBACd,OAAO;YACT;YAEA,IAAI,CAAChB,mBAAmBW,cAAcC,SAAU;gBAC9C,yCAAyC;gBACzC,IAAIP,MAAM;oBACRA,IAAI,CAACI,cAAc,GAAG,MAAMR,QAAQ;wBAClCG;wBACAC;wBACAC;wBACAC,gBAAgBF,MAAM,CAACK,UAAU;oBACnC;gBACF;gBAEA,OAAOO,QAAQ,CAACZ,MAAM,CAACI,cAAc;YACvC,OAAO;gBACL,8GAA8G;gBAC9G,MAAMS,eAAeb,MAAMc,YAAY;gBAEvC,oGAAoG;gBACpG,MAAMC,eAAef,MAAM,CAACI,cAAc,KAAKK,aAAa,CAACL,cAAc;gBAE3E,IAAI,CAACW,cAAc;oBACjB,IAAIf,MAAM;wBACR,2EAA2E;wBAC3E,4EAA4E;wBAC5EA,IAAI,CAACI,cAAc,GAAGJ,MAAM,CAACK,UAAU,GACnC,MAAMT,QAAQ;4BACZG;4BACAC;4BACAC;4BACAC,gBAAgBF,MAAM,CAACK,UAAU;wBACnC,KACA;oBACN;gBACF;gBAEA,IAAIQ,gBAAgBE,cAAc;oBAChC,OAAO;gBACT;gBAEA,sEAAsE;gBACtE,0DAA0D;gBAC1D,MAAMC,eAAe,MAAMlB,cAAc;oBACvCmB,gBAAgBX,YAAYY;oBAC5BC,YAAYZ,QAAQW;oBACpBE,UAAUX,aAAaY;oBACvBpB;gBACF;gBAEA,IAAIe,gBAAgB,GAAG;oBACrB,OAAO;gBACT,OAAO;oBACL,OAAO;gBACT;YACF;QACF;IACF,EAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { generateSlug } from './generateSlug.js';
|
|
3
|
+
describe('generateSlug', ()=>{
|
|
4
|
+
it('should await a custom async slugify function', async ()=>{
|
|
5
|
+
const data = {
|
|
6
|
+
title: 'Async Slug'
|
|
7
|
+
};
|
|
8
|
+
const hook = generateSlug({
|
|
9
|
+
slugFieldName: 'slug',
|
|
10
|
+
slugify: async ({ valueToSlugify })=>String(valueToSlugify).toLowerCase().replace(' ', '-'),
|
|
11
|
+
useAsSlug: 'title'
|
|
12
|
+
});
|
|
13
|
+
await hook({
|
|
14
|
+
data,
|
|
15
|
+
operation: 'create',
|
|
16
|
+
req: {}
|
|
17
|
+
});
|
|
18
|
+
expect(data.slug).toBe('async-slug');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=generateSlug.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/baseFields/slug/generateSlug.spec.ts"],"sourcesContent":["import type { PayloadRequest } from '../../../types/index.js'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { generateSlug } from './generateSlug.js'\n\ndescribe('generateSlug', () => {\n it('should await a custom async slugify function', async () => {\n const data: Record<string, unknown> = {\n title: 'Async Slug',\n }\n const hook = generateSlug({\n slugFieldName: 'slug',\n slugify: async ({ valueToSlugify }) => String(valueToSlugify).toLowerCase().replace(' ', '-'),\n useAsSlug: 'title',\n })\n\n await hook({\n data,\n operation: 'create',\n req: {} as PayloadRequest,\n } as Parameters<typeof hook>[0])\n\n expect(data.slug).toBe('async-slug')\n })\n})\n"],"names":["describe","expect","it","generateSlug","data","title","hook","slugFieldName","slugify","valueToSlugify","String","toLowerCase","replace","useAsSlug","operation","req","slug","toBe"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,YAAY,QAAQ,oBAAmB;AAEhDH,SAAS,gBAAgB;IACvBE,GAAG,gDAAgD;QACjD,MAAME,OAAgC;YACpCC,OAAO;QACT;QACA,MAAMC,OAAOH,aAAa;YACxBI,eAAe;YACfC,SAAS,OAAO,EAAEC,cAAc,EAAE,GAAKC,OAAOD,gBAAgBE,WAAW,GAAGC,OAAO,CAAC,KAAK;YACzFC,WAAW;QACb;QAEA,MAAMP,KAAK;YACTF;YACAU,WAAW;YACXC,KAAK,CAAC;QACR;QAEAd,OAAOG,KAAKY,IAAI,EAAEC,IAAI,CAAC;IACzB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findVersionByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAA;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAY/D,MAAM,MAAM,SAAS,GAAG;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,EAAE,qBAAqB,CAAA;IACnC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;AAEnD,eAAO,MAAM,wBAAwB,GAAU,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,cACnE,SAAS,KACd,OAAO,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../src/globals/operations/findVersionByID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAA;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAY/D,MAAM,MAAM,SAAS,GAAG;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,YAAY,EAAE,qBAAqB,CAAA;IACnC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;AAEnD,eAAO,MAAM,wBAAwB,GAAU,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,cACnE,SAAS,KACd,OAAO,CAAC,CAAC,CA+IX,CAAA"}
|
|
@@ -22,6 +22,10 @@ export const findVersionByIDOperation = async (args)=>{
|
|
|
22
22
|
if (accessResults === false) {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
+
const isValidID = typeof id === 'string' && id.length > 0 || typeof id === 'number' && Number.isFinite(id);
|
|
26
|
+
if (!isValidID) {
|
|
27
|
+
throw new NotFound(req.t);
|
|
28
|
+
}
|
|
25
29
|
const hasWhereAccess = typeof accessResults === 'object';
|
|
26
30
|
const select = sanitizeSelect({
|
|
27
31
|
fields: buildVersionGlobalFields(payload.config, globalConfig, true),
|
|
@@ -46,9 +50,6 @@ export const findVersionByIDOperation = async (args)=>{
|
|
|
46
50
|
// /////////////////////////////////////
|
|
47
51
|
// Find by ID
|
|
48
52
|
// /////////////////////////////////////
|
|
49
|
-
if (!findGlobalVersionsArgs.where?.and?.[0]?.id) {
|
|
50
|
-
throw new NotFound(req.t);
|
|
51
|
-
}
|
|
52
53
|
const { docs: results } = await payload.db.findGlobalVersions(findGlobalVersionsArgs);
|
|
53
54
|
if (!results || results?.length === 0) {
|
|
54
55
|
if (!disableErrors) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/operations/findVersionByID.ts"],"sourcesContent":["import type { FindOptions } from '../../collections/operations/local/find.js'\nimport type { FindGlobalVersionsArgs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\n\nexport type Arguments = {\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n globalConfig: SanitizedGlobalConfig\n id: number | string\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findVersionByIDOperation = async <T extends TypeWithVersion<T> = any>(\n args: Arguments,\n): Promise<T> => {\n const {\n id,\n currentDepth,\n depth,\n disableErrors,\n globalConfig,\n overrideAccess,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, globalConfig.access.readVersions)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResults === false) {\n return null!\n }\n\n const hasWhereAccess = typeof accessResults === 'object'\n\n const select = sanitizeSelect({\n fields: buildVersionGlobalFields(payload.config, globalConfig, true),\n forceSelect: getQueryDraftsSelect({ select: globalConfig.forceSelect }),\n select: incomingSelect,\n versions: true,\n })\n\n const findGlobalVersionsArgs: FindGlobalVersionsArgs = {\n global: globalConfig.slug,\n limit: 1,\n locale: locale!,\n req,\n select,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/operations/findVersionByID.ts"],"sourcesContent":["import type { FindOptions } from '../../collections/operations/local/find.js'\nimport type { FindGlobalVersionsArgs } from '../../database/types.js'\nimport type { PayloadRequest, PopulateType, SelectType } from '../../types/index.js'\nimport type { TypeWithVersion } from '../../versions/types.js'\nimport type { SanitizedGlobalConfig } from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { Forbidden, NotFound } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { buildVersionGlobalFields } from '../../versions/buildGlobalFields.js'\nimport { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js'\n\nexport type Arguments = {\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n globalConfig: SanitizedGlobalConfig\n id: number | string\n overrideAccess?: boolean\n populate?: PopulateType\n req: PayloadRequest\n showHiddenFields?: boolean\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nexport const findVersionByIDOperation = async <T extends TypeWithVersion<T> = any>(\n args: Arguments,\n): Promise<T> => {\n const {\n id,\n currentDepth,\n depth,\n disableErrors,\n globalConfig,\n overrideAccess,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n try {\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n const accessResults = !overrideAccess\n ? await executeAccess({ id, disableErrors, req }, globalConfig.access.readVersions)\n : true\n\n // If errors are disabled, and access returns false, return null\n if (accessResults === false) {\n return null!\n }\n\n const isValidID =\n (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && Number.isFinite(id))\n\n if (!isValidID) {\n throw new NotFound(req.t)\n }\n\n const hasWhereAccess = typeof accessResults === 'object'\n\n const select = sanitizeSelect({\n fields: buildVersionGlobalFields(payload.config, globalConfig, true),\n forceSelect: getQueryDraftsSelect({ select: globalConfig.forceSelect }),\n select: incomingSelect,\n versions: true,\n })\n\n const findGlobalVersionsArgs: FindGlobalVersionsArgs = {\n global: globalConfig.slug,\n limit: 1,\n locale: locale!,\n req,\n select,\n where: combineQueries({ id: { equals: id } }, accessResults),\n }\n\n // /////////////////////////////////////\n // Find by ID\n // /////////////////////////////////////\n\n const { docs: results } = await payload.db.findGlobalVersions(findGlobalVersionsArgs)\n if (!results || results?.length === 0) {\n if (!disableErrors) {\n if (!hasWhereAccess) {\n throw new NotFound(req.t)\n }\n if (hasWhereAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n return null!\n }\n\n // Clone the result - it may have come back memoized\n let result: any = deepCopyObjectSimple(results[0])\n\n if (!result.version) {\n result.version = {}\n }\n\n // Patch globalType onto version doc\n result.version.globalType = globalConfig.slug\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.beforeRead?.length) {\n for (const hook of globalConfig.hooks.beforeRead) {\n result =\n (await hook({\n context: req.context,\n doc: result.version,\n global: globalConfig,\n overrideAccess,\n req,\n })) || result.version\n }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.version = await afterRead({\n collection: null,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc: result.version,\n draft: undefined!,\n fallbackLocale: fallbackLocale!,\n global: globalConfig,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select: typeof select?.version === 'object' ? select.version : undefined,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Global\n // /////////////////////////////////////\n\n if (globalConfig.hooks?.afterRead?.length) {\n for (const hook of globalConfig.hooks.afterRead) {\n result.version =\n (await hook({\n context: req.context,\n doc: result.version,\n global: globalConfig,\n overrideAccess,\n query: findGlobalVersionsArgs.where,\n req,\n })) || result.version\n }\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","Forbidden","NotFound","afterRead","deepCopyObjectSimple","killTransaction","sanitizeSelect","buildVersionGlobalFields","getQueryDraftsSelect","findVersionByIDOperation","args","id","currentDepth","depth","disableErrors","globalConfig","overrideAccess","populate","req","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","accessResults","access","readVersions","isValidID","length","Number","isFinite","t","hasWhereAccess","fields","config","forceSelect","versions","findGlobalVersionsArgs","global","slug","limit","where","equals","docs","results","db","findGlobalVersions","result","version","globalType","hooks","beforeRead","hook","context","doc","collection","draft","undefined","query","error"],"mappings":"AAMA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,wBAAuB;AAC3D,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,oBAAoB,QAAQ,oCAAmC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,wBAAwB,QAAQ,sCAAqC;AAC9E,SAASC,oBAAoB,QAAQ,gDA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AAK,CAAChD,SAAS,CAAE;gBAC/C6C,OAAOC,OAAO,GACZ,AAAC,MAAMI,KAAK;oBACVC,SAASpC,IAAIoC,OAAO;oBACpBC,KAAKP,OAAOC,OAAO;oBACnBV,QAAQxB;oBACRC;oBACA2C,OAAOrB,uBAAuBI,KAAK;oBACnCxB;gBACF,MAAO8B,OAAOC,OAAO;YACzB;QACF;QAEA,OAAOD;IACT,EAAE,OAAOY,OAAgB;QACvB,MAAMvD,gBAAgBa;QACtB,MAAM0C;IACR;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.91.0-internal.
|
|
3
|
+
"version": "3.91.0-internal.c1569dc",
|
|
4
4
|
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin panel",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"undici": "7.29.0",
|
|
117
117
|
"uuid": "13.0.2",
|
|
118
118
|
"ws": "^8.16.0",
|
|
119
|
-
"@payloadcms/translations": "3.91.0-internal.
|
|
119
|
+
"@payloadcms/translations": "3.91.0-internal.c1569dc"
|
|
120
120
|
},
|
|
121
121
|
"devDependencies": {
|
|
122
122
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|