payload 3.74.0-canary.2 → 3.74.0-internal.8fd38f1
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/strategies/local/authenticate.d.ts.map +1 -1
- package/dist/auth/strategies/local/authenticate.js +2 -3
- package/dist/auth/strategies/local/authenticate.js.map +1 -1
- package/dist/auth/strategies/local/authenticate.spec.js +83 -0
- package/dist/auth/strategies/local/authenticate.spec.js.map +1 -0
- package/dist/collections/endpoints/docAccess.d.ts.map +1 -1
- package/dist/collections/endpoints/docAccess.js +1 -0
- package/dist/collections/endpoints/docAccess.js.map +1 -1
- package/dist/collections/operations/find.js +1 -1
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/local/count.d.ts +2 -6
- package/dist/collections/operations/local/count.d.ts.map +1 -1
- package/dist/collections/operations/local/count.js.map +1 -1
- package/dist/collections/operations/local/countVersions.d.ts +2 -6
- package/dist/collections/operations/local/countVersions.d.ts.map +1 -1
- package/dist/collections/operations/local/countVersions.js.map +1 -1
- package/dist/fields/baseFields/slug/countVersions.d.ts.map +1 -1
- package/dist/fields/baseFields/slug/countVersions.js +0 -2
- package/dist/fields/baseFields/slug/countVersions.js.map +1 -1
- package/dist/globals/endpoints/docAccess.d.ts.map +1 -1
- package/dist/globals/endpoints/docAccess.js +1 -0
- package/dist/globals/endpoints/docAccess.js.map +1 -1
- package/dist/globals/operations/local/countVersions.d.ts +0 -4
- package/dist/globals/operations/local/countVersions.d.ts.map +1 -1
- package/dist/globals/operations/local/countVersions.js.map +1 -1
- package/dist/index.bundled.d.ts +55 -28
- package/dist/index.d.ts +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/authenticate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEtE,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,yBAAyB,sBAA6B,IAAI,KAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CA+B3F,CAAA"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// @ts-strict-ignore
|
|
2
2
|
import crypto from 'crypto';
|
|
3
|
-
// @ts-expect-error - no types available
|
|
4
|
-
import scmp from 'scmp';
|
|
5
3
|
export const authenticateLocalStrategy = async ({ doc, password })=>{
|
|
6
4
|
try {
|
|
7
5
|
const { hash, salt } = doc;
|
|
@@ -11,7 +9,8 @@ export const authenticateLocalStrategy = async ({ doc, password })=>{
|
|
|
11
9
|
if (e) {
|
|
12
10
|
reject(e);
|
|
13
11
|
}
|
|
14
|
-
|
|
12
|
+
const storedHashBuffer = Buffer.from(hash, 'hex');
|
|
13
|
+
if (hashBuffer.length === storedHashBuffer.length && crypto.timingSafeEqual(hashBuffer, storedHashBuffer)) {
|
|
15
14
|
resolve(doc);
|
|
16
15
|
} else {
|
|
17
16
|
reject(new Error('Invalid password'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\n\nimport type { TypeWithID } from '../../../collections/config/types.js'\n\ntype Doc = Record<string, unknown> & TypeWithID\n\ntype Args = {\n doc: Doc\n password: string\n}\n\nexport const authenticateLocalStrategy = async ({ doc, password }: Args): Promise<Doc | null> => {\n try {\n const { hash, salt } = doc\n\n if (typeof salt === 'string' && typeof hash === 'string') {\n const res = await new Promise<Doc | null>((resolve, reject) => {\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer) => {\n if (e) {\n reject(e)\n }\n\n const storedHashBuffer = Buffer.from(hash, 'hex')\n\n if (\n hashBuffer.length === storedHashBuffer.length &&\n crypto.timingSafeEqual(hashBuffer, storedHashBuffer)\n ) {\n resolve(doc)\n } else {\n reject(new Error('Invalid password'))\n }\n })\n })\n\n return res\n }\n\n return null\n } catch (ignore) {\n return null\n }\n}\n"],"names":["crypto","authenticateLocalStrategy","doc","password","hash","salt","res","Promise","resolve","reject","pbkdf2","e","hashBuffer","storedHashBuffer","Buffer","from","length","timingSafeEqual","Error","ignore"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,YAAY,SAAQ;AAW3B,OAAO,MAAMC,4BAA4B,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAQ;IACrE,IAAI;QACF,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGH;QAEvB,IAAI,OAAOG,SAAS,YAAY,OAAOD,SAAS,UAAU;YACxD,MAAME,MAAM,MAAM,IAAIC,QAAoB,CAACC,SAASC;gBAClDT,OAAOU,MAAM,CAACP,UAAUE,MAAM,OAAO,KAAK,UAAU,CAACM,GAAGC;oBACtD,IAAID,GAAG;wBACLF,OAAOE;oBACT;oBAEA,MAAME,mBAAmBC,OAAOC,IAAI,CAACX,MAAM;oBAE3C,IACEQ,WAAWI,MAAM,KAAKH,iBAAiBG,MAAM,IAC7ChB,OAAOiB,eAAe,CAACL,YAAYC,mBACnC;wBACAL,QAAQN;oBACV,OAAO;wBACLO,OAAO,IAAIS,MAAM;oBACnB;gBACF;YACF;YAEA,OAAOZ;QACT;QAEA,OAAO;IACT,EAAE,OAAOa,QAAQ;QACf,OAAO;IACT;AACF,EAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { authenticateLocalStrategy } from './authenticate.js';
|
|
4
|
+
// Helper to generate hash/salt like Payload does
|
|
5
|
+
const generateHashAndSalt = (password)=>{
|
|
6
|
+
const salt = crypto.randomBytes(32).toString('hex');
|
|
7
|
+
const hash = crypto.pbkdf2Sync(password, salt, 25000, 512, 'sha256').toString('hex');
|
|
8
|
+
return {
|
|
9
|
+
hash,
|
|
10
|
+
salt
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
describe('authenticateLocalStrategy', ()=>{
|
|
14
|
+
it('should return doc when password is valid', async ()=>{
|
|
15
|
+
const password = 'test-password';
|
|
16
|
+
const { hash, salt } = generateHashAndSalt(password);
|
|
17
|
+
const doc = {
|
|
18
|
+
id: 1,
|
|
19
|
+
hash,
|
|
20
|
+
salt
|
|
21
|
+
};
|
|
22
|
+
const result = await authenticateLocalStrategy({
|
|
23
|
+
doc,
|
|
24
|
+
password
|
|
25
|
+
});
|
|
26
|
+
expect(result).toEqual(doc);
|
|
27
|
+
});
|
|
28
|
+
it('should return null when password is invalid', async ()=>{
|
|
29
|
+
const { hash, salt } = generateHashAndSalt('correct-password');
|
|
30
|
+
const doc = {
|
|
31
|
+
id: 1,
|
|
32
|
+
hash,
|
|
33
|
+
salt
|
|
34
|
+
};
|
|
35
|
+
const result = await authenticateLocalStrategy({
|
|
36
|
+
doc,
|
|
37
|
+
password: 'wrong-password'
|
|
38
|
+
});
|
|
39
|
+
expect(result).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
it('should return null when salt is missing', async ()=>{
|
|
42
|
+
const { hash } = generateHashAndSalt('test-password');
|
|
43
|
+
const doc = {
|
|
44
|
+
id: 1,
|
|
45
|
+
hash
|
|
46
|
+
};
|
|
47
|
+
const result = await authenticateLocalStrategy({
|
|
48
|
+
doc,
|
|
49
|
+
password: 'test-password'
|
|
50
|
+
});
|
|
51
|
+
expect(result).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
it('should return null when hash is missing', async ()=>{
|
|
54
|
+
const { salt } = generateHashAndSalt('test-password');
|
|
55
|
+
const doc = {
|
|
56
|
+
id: 1,
|
|
57
|
+
salt
|
|
58
|
+
};
|
|
59
|
+
const result = await authenticateLocalStrategy({
|
|
60
|
+
doc,
|
|
61
|
+
password: 'test-password'
|
|
62
|
+
});
|
|
63
|
+
expect(result).toBeNull();
|
|
64
|
+
});
|
|
65
|
+
it('should return null when hash has different length (tampered)', async ()=>{
|
|
66
|
+
const password = 'test-password';
|
|
67
|
+
const { salt } = generateHashAndSalt(password);
|
|
68
|
+
// Truncated hash - different length than expected 512 bytes
|
|
69
|
+
const shortHash = 'abcd1234';
|
|
70
|
+
const doc = {
|
|
71
|
+
id: 1,
|
|
72
|
+
hash: shortHash,
|
|
73
|
+
salt
|
|
74
|
+
};
|
|
75
|
+
const result = await authenticateLocalStrategy({
|
|
76
|
+
doc,
|
|
77
|
+
password
|
|
78
|
+
});
|
|
79
|
+
expect(result).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=authenticate.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.spec.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { authenticateLocalStrategy } from './authenticate.js'\n\n// Helper to generate hash/salt like Payload does\nconst generateHashAndSalt = (password: string): { hash: string; salt: string } => {\n const salt = crypto.randomBytes(32).toString('hex')\n const hash = crypto.pbkdf2Sync(password, salt, 25000, 512, 'sha256').toString('hex')\n return { hash, salt }\n}\n\ndescribe('authenticateLocalStrategy', () => {\n it('should return doc when password is valid', async () => {\n const password = 'test-password'\n const { hash, salt } = generateHashAndSalt(password)\n const doc = { id: 1, hash, salt }\n\n const result = await authenticateLocalStrategy({ doc, password })\n\n expect(result).toEqual(doc)\n })\n\n it('should return null when password is invalid', async () => {\n const { hash, salt } = generateHashAndSalt('correct-password')\n const doc = { id: 1, hash, salt }\n\n const result = await authenticateLocalStrategy({ doc, password: 'wrong-password' })\n\n expect(result).toBeNull()\n })\n\n it('should return null when salt is missing', async () => {\n const { hash } = generateHashAndSalt('test-password')\n const doc = { id: 1, hash }\n\n const result = await authenticateLocalStrategy({ doc, password: 'test-password' })\n\n expect(result).toBeNull()\n })\n\n it('should return null when hash is missing', async () => {\n const { salt } = generateHashAndSalt('test-password')\n const doc = { id: 1, salt }\n\n const result = await authenticateLocalStrategy({ doc, password: 'test-password' })\n\n expect(result).toBeNull()\n })\n\n it('should return null when hash has different length (tampered)', async () => {\n const password = 'test-password'\n const { salt } = generateHashAndSalt(password)\n // Truncated hash - different length than expected 512 bytes\n const shortHash = 'abcd1234'\n const doc = { id: 1, hash: shortHash, salt }\n\n const result = await authenticateLocalStrategy({ doc, password })\n\n expect(result).toBeNull()\n })\n})\n"],"names":["crypto","describe","expect","it","authenticateLocalStrategy","generateHashAndSalt","password","salt","randomBytes","toString","hash","pbkdf2Sync","doc","id","result","toEqual","toBeNull","shortHash"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAE3B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,yBAAyB,QAAQ,oBAAmB;AAE7D,iDAAiD;AACjD,MAAMC,sBAAsB,CAACC;IAC3B,MAAMC,OAAOP,OAAOQ,WAAW,CAAC,IAAIC,QAAQ,CAAC;IAC7C,MAAMC,OAAOV,OAAOW,UAAU,CAACL,UAAUC,MAAM,OAAO,KAAK,UAAUE,QAAQ,CAAC;IAC9E,OAAO;QAAEC;QAAMH;IAAK;AACtB;AAEAN,SAAS,6BAA6B;IACpCE,GAAG,4CAA4C;QAC7C,MAAMG,WAAW;QACjB,MAAM,EAAEI,IAAI,EAAEH,IAAI,EAAE,GAAGF,oBAAoBC;QAC3C,MAAM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EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAM3D,eAAO,MAAM,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/docAccess.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAM3D,eAAO,MAAM,gBAAgB,EAAE,cAiB9B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/endpoints/docAccess.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 { docAccessOperation } from '../operations/docAccess.js'\n\nexport const docAccessHandler: PayloadHandler = async (req) => {\n const { id, collection } = getRequestCollectionWithID(req, { optionalID: true })\n\n const result = await docAccessOperation({\n id,\n collection,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","docAccessOperation","docAccessHandler","req","id","collection","optionalID","result","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,OAAO,MAAMC,mBAAmC,OAAOC;IACrD,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAE,GAAGN,2BAA2BI,KAAK;QAAEG,YAAY;IAAK;IAE9E,MAAMC,SAAS,MAAMN,mBAAmB;QACtCG;QACAC;
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/endpoints/docAccess.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 { docAccessOperation } from '../operations/docAccess.js'\n\nexport const docAccessHandler: PayloadHandler = async (req) => {\n const { id, collection } = getRequestCollectionWithID(req, { optionalID: true })\n\n const result = await docAccessOperation({\n id,\n collection,\n data: req.data,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","docAccessOperation","docAccessHandler","req","id","collection","optionalID","result","data","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,OAAO,MAAMC,mBAAmC,OAAOC;IACrD,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAE,GAAGN,2BAA2BI,KAAK;QAAEG,YAAY;IAAK;IAE9E,MAAMC,SAAS,MAAMN,mBAAmB;QACtCG;QACAC;QACAG,MAAML,IAAIK,IAAI;QACdL;IACF;IAEA,OAAOM,SAASC,IAAI,CAACH,QAAQ;QAC3BI,SAASX,gBAAgB;YACvBW,SAAS,IAAIC;YACbT;QACF;QACAN,QAAQC,WAAWe,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/find.ts"],"sourcesContent":["import type { AccessResult } from '../../config/types.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { CollectionSlug, FindOptions, JoinQuery } from '../../index.js'\nimport type {\n PayloadRequest,\n PopulateType,\n SelectType,\n Sort,\n TransformCollectionWithSelect,\n Where,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.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 { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\nimport { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n includeLockStatus?: boolean\n joins?: JoinQuery\n limit?: number\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n showHiddenFields?: boolean\n sort?: Sort\n trash?: boolean\n where?: Where\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nconst lockDurationDefault = 300 // Default 5 minutes in seconds\n\nexport const findOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<PaginatedDocs<TransformCollectionWithSelect<TSlug, TSelect>>> => {\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 })\n\n const {\n collection: { config: collectionConfig },\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft: draftsEnabled,\n includeLockStatus: includeLockStatusFromArgs,\n joins,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n select: incomingSelect,\n showHiddenFields,\n sort: incomingSort,\n trash = false,\n where,\n } = args\n\n const req = args.req!\n\n const includeLockStatus =\n includeLockStatusFromArgs && req.payload.collections?.[lockedDocumentsCollectionSlug]\n\n const { fallbackLocale, locale, payload } = req\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ disableErrors, req }, collectionConfig.access.read)\n\n // If errors are disabled, and access returns false, return empty results\n if (accessResult === false) {\n return {\n docs: [],\n hasNextPage: false,\n hasPrevPage: false,\n limit: limit!,\n nextPage: null,\n page: 1,\n pagingCounter: 1,\n prevPage: null,\n totalDocs: 0,\n totalPages: 1,\n }\n }\n }\n\n // /////////////////////////////////////\n // Find\n // /////////////////////////////////////\n\n const usePagination = pagination && limit !== 0\n const sanitizedLimit = limit ?? (usePagination ? 10 : 0)\n const sanitizedPage = page || 1\n\n let result: PaginatedDocs<DataFromCollectionSlug<TSlug>>\n\n let fullWhere = combineQueries(where!, accessResult!)\n sanitizeWhereQuery({ fields: collectionConfig.flattenedFields, payload, where: fullWhere })\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n const sort = sanitizeSortQuery({\n fields: collection.config.flattenedFields,\n sort: incomingSort,\n })\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess: overrideAccess!,\n req,\n })\n\n if (hasDraftsEnabled(collectionConfig) && draftsEnabled) {\n fullWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n overrideAccess: overrideAccess!,\n req,\n versionFields: buildVersionCollectionFields(payload.config, collection.config, true),\n where: appendVersionToQueryKey(where),\n })\n\n result = await payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n limit: sanitizedLimit,\n locale: locale!,\n page: sanitizedPage,\n pagination: usePagination,\n req,\n select: getQueryDraftsSelect({ select }),\n sort: getQueryDraftsSort({\n collectionConfig,\n sort,\n }),\n where: fullWhere,\n })\n } else {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where: where!,\n })\n\n result = await payload.db.find<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n draftsEnabled,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n limit: sanitizedLimit,\n locale: locale!,\n page: sanitizedPage,\n pagination,\n req,\n select,\n sort,\n where: fullWhere,\n })\n }\n\n if (includeLockStatus) {\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const now = new Date().getTime()\n\n const lockedDocuments = await payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: sanitizedLimit,\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 in: result.docs.map((doc) => doc.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(now - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n const lockedDocs = Array.isArray(lockedDocuments?.docs) ? lockedDocuments.docs : []\n\n // Filter out stale locks\n const validLockedDocs = lockedDocs.filter((lock) => {\n const lastEditedAt = new Date(lock?.updatedAt).getTime()\n return lastEditedAt + lockDurationInMilliseconds > now\n })\n\n for (const doc of result.docs) {\n const lockedDoc = validLockedDocs.find((lock) => lock?.document?.value === doc.id)\n doc._isLocked = !!lockedDoc\n doc._userEditing = lockedDoc ? lockedDoc?.user?.value : null\n }\n } catch (_err) {\n for (const doc of result.docs) {\n doc._isLocked = false\n doc._userEditing = null\n }\n }\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig?.hooks?.beforeRead?.length) {\n result.docs = await Promise.all(\n result.docs.map(async (doc) => {\n let docRef = doc\n\n for (const hook of collectionConfig.hooks.beforeRead) {\n docRef =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: docRef,\n query: fullWhere,\n req,\n })) || docRef\n }\n\n return docRef\n }),\n )\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.docs = await Promise.all(\n result.docs.map(async (doc) =>\n afterRead<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc,\n draft: draftsEnabled!,\n fallbackLocale: fallbackLocale!,\n findMany: true,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n }),\n ),\n )\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig?.hooks?.afterRead?.length) {\n result.docs = await Promise.all(\n result.docs.map(async (doc) => {\n let docRef = doc\n\n for (const hook of collectionConfig.hooks.afterRead) {\n docRef =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: docRef,\n findMany: true,\n query: fullWhere,\n req,\n })) || doc\n }\n\n return docRef\n }),\n )\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'find',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as PaginatedDocs<TransformCollectionWithSelect<TSlug, TSelect>>\n } catch (error: unknown) {\n await killTransaction(args.req!)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","validateQueryPaths","sanitizeJoinQuery","sanitizeWhereQuery","afterRead","lockedDocumentsCollectionSlug","appendNonTrashedFilter","hasDraftsEnabled","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSelect","getQueryDraftsSort","buildAfterOperation","buildBeforeOperation","sanitizeSortQuery","lockDurationDefault","findOperation","incomingArgs","args","collection","config","operation","collectionConfig","currentDepth","depth","disableErrors","draft","draftsEnabled","includeLockStatus","includeLockStatusFromArgs","joins","limit","overrideAccess","page","pagination","populate","select","incomingSelect","showHiddenFields","sort","incomingSort","trash","where","req","payload","collections","fallbackLocale","locale","fields","flattenedFields","forceSelect","accessResult","access","read","docs","hasNextPage","hasPrevPage","nextPage","pagingCounter","prevPage","totalDocs","totalPages","usePagination","sanitizedLimit","sanitizedPage","result","fullWhere","enableTrash","sanitizedJoins","versionFields","db","queryDrafts","slug","payloadAPI","find","lockDocumentsProp","lockDocuments","lockDuration","duration","lockDurationInMilliseconds","now","Date","getTime","lockedDocuments","and","equals","in","map","doc","id","updatedAt","greater_than","lockedDocs","Array","isArray","validLockedDocs","filter","lock","lastEditedAt","lockedDoc","document","value","_isLocked","_userEditing","user","_err","hooks","beforeRead","length","Promise","all","docRef","hook","context","query","findMany","global","error"],"mappings":"AAiBA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,6BAA6B,QAAQ,mCAAkC;AAChF,SAASC,sBAAsB,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C;QACxC,qBAAqB;QACrB,wCAAwC;QAExC9C,OAAOX,IAAI,GAAG,MAAMuD,QAAQC,GAAG,CAC7B7C,OAAOX,IAAI,CAACiC,GAAG,CAAC,OAAOC,MACrBtF,UAAyC;gBACvCiB,YAAYG;gBACZ2F,SAAStE,IAAIsE,OAAO;gBACpB1F;gBACAC,OAAOA;gBACPgE;gBACA9D,OAAOC;gBACPmB,gBAAgBA;gBAChBqE,UAAU;gBACVC,QAAQ;gBACRrE,QAAQA;gBACRf,gBAAgBA;gBAChBG;gBACAQ;gBACAP;gBACAE,kBAAkBA;YACpB;QAIJ,wCAAwC;QACxC,yBAAyB;QACzB,wCAAwC;QAExC,IAAIhB,kBAAkBoF,OAAOxG,WAAW0G,QAAQ;YAC9C3C,OAAOX,IAAI,GAAG,MAAMuD,QAAQC,GAAG,CAC7B7C,OAAOX,IAAI,CAACiC,GAAG,CAAC,OAAOC;gBACrB,IAAIuB,SAASvB;gBAEb,KAAK,MAAMwB,QAAQ1F,iBAAiBoF,KAAK,CAACxG,SAAS,CAAE;oBACnD6G,SACE,AAAC,MAAMC,KAAK;wBACV7F,YAAYG;wBACZ2F,SAAStE,IAAIsE,OAAO;wBACpBzB,KAAKuB;wBACLI,UAAU;wBACVD,OAAOhD;wBACPvB;oBACF,MAAO6C;gBACX;gBAEA,OAAOuB;YACT;QAEJ;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC9C,SAAS,MAAMrD,oBAAoB;YACjCM;YACAC,YAAYG;YACZD,WAAW;YACX4C;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOoD,OAAgB;QACvB,MAAM/G,gBAAgBY,KAAKyB,GAAG;QAC9B,MAAM0E;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/find.ts"],"sourcesContent":["import type { AccessResult } from '../../config/types.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { CollectionSlug, FindOptions, JoinQuery } from '../../index.js'\nimport type {\n PayloadRequest,\n PopulateType,\n SelectType,\n Sort,\n TransformCollectionWithSelect,\n Where,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { sanitizeJoinQuery } from '../../database/sanitizeJoinQuery.js'\nimport { sanitizeWhereQuery } from '../../database/sanitizeWhereQuery.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.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 { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js'\nimport { buildAfterOperation } from './utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from './utilities/buildBeforeOperation.js'\nimport { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js'\n\nexport type Arguments = {\n collection: Collection\n currentDepth?: number\n depth?: number\n disableErrors?: boolean\n draft?: boolean\n includeLockStatus?: boolean\n joins?: JoinQuery\n limit?: number\n overrideAccess?: boolean\n page?: number\n pagination?: boolean\n populate?: PopulateType\n req?: PayloadRequest\n showHiddenFields?: boolean\n sort?: Sort\n trash?: boolean\n where?: Where\n} & Pick<FindOptions<string, SelectType>, 'select'>\n\nconst lockDurationDefault = 300 // Default 5 minutes in seconds\n\nexport const findOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<PaginatedDocs<TransformCollectionWithSelect<TSlug, TSelect>>> => {\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 })\n\n const {\n collection: { config: collectionConfig },\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft: draftsEnabled,\n includeLockStatus: includeLockStatusFromArgs,\n joins,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n select: incomingSelect,\n showHiddenFields,\n sort: incomingSort,\n trash = false,\n where,\n } = args\n\n const req = args.req!\n\n const includeLockStatus =\n includeLockStatusFromArgs && req.payload.collections?.[lockedDocumentsCollectionSlug]\n\n const { fallbackLocale, locale, payload } = req\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ disableErrors, req }, collectionConfig.access.read)\n\n // If errors are disabled, and access returns false, return empty results\n if (accessResult === false) {\n return {\n docs: [],\n hasNextPage: false,\n hasPrevPage: false,\n limit: limit!,\n nextPage: null,\n page: 1,\n pagingCounter: 1,\n prevPage: null,\n totalDocs: 0,\n totalPages: 1,\n }\n }\n }\n\n // /////////////////////////////////////\n // Find\n // /////////////////////////////////////\n\n const usePagination = pagination && limit !== 0\n const sanitizedLimit = limit ?? (usePagination ? 10 : 0)\n const sanitizedPage = page || 1\n\n let result: PaginatedDocs<DataFromCollectionSlug<TSlug>>\n\n let fullWhere = combineQueries(where!, accessResult!)\n sanitizeWhereQuery({ fields: collectionConfig.flattenedFields, payload, where: fullWhere })\n\n // Exclude trashed documents when trash: false\n fullWhere = appendNonTrashedFilter({\n enableTrash: collectionConfig.trash,\n trash,\n where: fullWhere,\n })\n\n const sort = sanitizeSortQuery({\n fields: collection.config.flattenedFields,\n sort: incomingSort,\n })\n\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess: overrideAccess!,\n req,\n })\n\n if (hasDraftsEnabled(collectionConfig) && draftsEnabled) {\n fullWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n overrideAccess: overrideAccess!,\n req,\n versionFields: buildVersionCollectionFields(payload.config, collection.config, true),\n where: appendVersionToQueryKey(where),\n })\n\n result = await payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n limit: sanitizedLimit,\n locale: locale!,\n page: sanitizedPage,\n pagination: usePagination,\n req,\n select: getQueryDraftsSelect({ select }),\n sort: getQueryDraftsSort({\n collectionConfig,\n sort,\n }),\n where: fullWhere,\n })\n } else {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where: where!,\n })\n\n result = await payload.db.find<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n draftsEnabled,\n joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,\n limit: sanitizedLimit,\n locale: locale!,\n page: sanitizedPage,\n pagination,\n req,\n select,\n sort,\n where: fullWhere,\n })\n }\n\n if (includeLockStatus) {\n try {\n const lockDocumentsProp = collectionConfig?.lockDocuments\n\n const lockDuration =\n typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n const lockDurationInMilliseconds = lockDuration * 1000\n\n const now = new Date().getTime()\n\n const lockedDocuments = await payload.find({\n collection: lockedDocumentsCollectionSlug,\n depth: 1,\n limit: sanitizedLimit,\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 in: result.docs.map((doc) => doc.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(now - lockDurationInMilliseconds),\n },\n },\n ],\n },\n })\n\n const lockedDocs = Array.isArray(lockedDocuments?.docs) ? lockedDocuments.docs : []\n\n // Filter out stale locks\n const validLockedDocs = lockedDocs.filter((lock) => {\n const lastEditedAt = new Date(lock?.updatedAt).getTime()\n return lastEditedAt + lockDurationInMilliseconds > now\n })\n\n for (const doc of result.docs) {\n const lockedDoc = validLockedDocs.find((lock) => lock?.document?.value === doc.id)\n doc._isLocked = !!lockedDoc\n doc._userEditing = lockedDoc ? lockedDoc?.user?.value : null\n }\n } catch (_err) {\n for (const doc of result.docs) {\n doc._isLocked = false\n doc._userEditing = null\n }\n }\n }\n\n // /////////////////////////////////////\n // beforeRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig?.hooks?.beforeRead?.length) {\n result.docs = await Promise.all(\n result.docs.map(async (doc) => {\n let docRef = doc\n\n for (const hook of collectionConfig.hooks.beforeRead) {\n docRef =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: docRef,\n query: fullWhere,\n req,\n })) || docRef\n }\n\n return docRef\n }),\n )\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result.docs = await Promise.all(\n result.docs.map(async (doc) =>\n afterRead<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig,\n context: req.context,\n currentDepth,\n depth: depth!,\n doc,\n draft: draftsEnabled!,\n fallbackLocale: fallbackLocale!,\n findMany: true,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n }),\n ),\n )\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig?.hooks?.afterRead?.length) {\n result.docs = await Promise.all(\n result.docs.map(async (doc) => {\n let docRef = doc\n\n for (const hook of collectionConfig.hooks.afterRead) {\n docRef =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: docRef,\n findMany: true,\n query: fullWhere,\n req,\n })) || docRef\n }\n\n return docRef\n }),\n )\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'find',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result as PaginatedDocs<TransformCollectionWithSelect<TSlug, TSelect>>\n } catch (error: unknown) {\n await killTransaction(args.req!)\n throw error\n }\n}\n"],"names":["executeAccess","combineQueries","validateQueryPaths","sanitizeJoinQuery","sanitizeWhereQuery","afterRead","lockedDocumentsCollectionSlug","appendNonTrashedFilter","hasDraftsEnabled","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSelect","getQueryDraftsSort","buildAfterOperation","buildBeforeOperation","sanitizeSortQuery","lockDurationDefault","findOperation","incomingArgs","args","collection","config","operation","collectionConfig","currentDepth","depth","disableErrors","draft","draftsEnabled","includeLockStatus","includeLockStatusFromArgs","joins","limit","overrideAccess","page","pagination","populate","select","incomingSelect","showHiddenFields","sort","incomingSort","trash","where","req","payload","collections","fallbackLocale","locale","fields","flattenedFields","forceSelect","accessResult","access","read","docs","hasNextPage","hasPrevPage","nextPage","pagingCounter","prevPage","totalDocs","totalPages","usePagination","sanitizedLimit","sanitizedPage","result","fullWhere","enableTrash","sanitizedJoins","versionFields","db","queryDrafts","slug","payloadAPI","find","lockDocumentsProp","lockDocuments","lockDuration","duration","lockDurationInMilliseconds","now","Date","getTime","lockedDocuments","and","equals","in","map","doc","id","updatedAt","greater_than","lockedDocs","Array","isArray","validLockedDocs","filter","lock","lastEditedAt","lockedDoc","document","value","_isLocked","_userEditing","user","_err","hooks","beforeRead","length","Promise","all","docRef","hook","context","query","findMany","global","error"],"mappings":"AAiBA,SAASA,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ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gBY,KAAKyB,GAAG;QAC9B,MAAM0E;IACR;AACF,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
2
2
|
import type { Document, PayloadRequest, Where } from '../../../types/index.js';
|
|
3
|
-
export type
|
|
3
|
+
export type CountOptions<TSlug extends CollectionSlug> = {
|
|
4
4
|
/**
|
|
5
5
|
* the Collection slug to operate against.
|
|
6
6
|
*/
|
|
@@ -12,10 +12,6 @@ export type Options<TSlug extends CollectionSlug> = {
|
|
|
12
12
|
* to determine if it should run or not.
|
|
13
13
|
*/
|
|
14
14
|
context?: RequestContext;
|
|
15
|
-
/**
|
|
16
|
-
* [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
|
|
17
|
-
*/
|
|
18
|
-
depth?: number;
|
|
19
15
|
/**
|
|
20
16
|
* When set to `true`, errors will not be thrown.
|
|
21
17
|
*/
|
|
@@ -53,7 +49,7 @@ export type Options<TSlug extends CollectionSlug> = {
|
|
|
53
49
|
*/
|
|
54
50
|
where?: Where;
|
|
55
51
|
};
|
|
56
|
-
export declare function countLocal<TSlug extends CollectionSlug>(payload: Payload, options:
|
|
52
|
+
export declare function countLocal<TSlug extends CollectionSlug>(payload: Payload, options: CountOptions<TSlug>): Promise<{
|
|
57
53
|
totalDocs: number;
|
|
58
54
|
}>;
|
|
59
55
|
//# sourceMappingURL=count.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/count.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO9E,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/count.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO9E,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,cAAc,IAAI;IACvD;;OAEG;IACH,UAAU,EAAE,KAAK,CAAA;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,wBAAsB,UAAU,CAAC,KAAK,SAAS,cAAc,EAC3D,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,GAC3B,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAyBhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/count.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countOperation } from '../count.js'\n\nexport type
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/count.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countOperation } from '../count.js'\n\nexport type CountOptions<TSlug extends CollectionSlug> = {\n /**\n * the Collection slug to operate against.\n */\n collection: TSlug\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * When set to `true`, errors will not be thrown.\n */\n disableErrors?: boolean\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * When set to `true`, the query will include both normal and trashed documents.\n * To query only trashed documents, pass `trash: true` and combine with a `where` clause filtering by `deletedAt`.\n * By default (`false`), the query will only include normal documents and exclude those with a `deletedAt` field.\n *\n * This argument has no effect unless `trash` is enabled on the collection.\n * @default false\n */\n trash?: boolean\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n /**\n * A filter [query](https://payloadcms.com/docs/queries/overview)\n */\n where?: Where\n}\n\nexport async function countLocal<TSlug extends CollectionSlug>(\n payload: Payload,\n options: CountOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n const {\n collection: collectionSlug,\n disableErrors,\n overrideAccess = true,\n trash = false,\n where,\n } = options\n\n const collection = payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} can't be found. Count Operation.`,\n )\n }\n\n return countOperation<TSlug>({\n collection,\n disableErrors,\n overrideAccess,\n req: await createLocalReq(options as CreateLocalReqOptions, payload),\n trash,\n where,\n })\n}\n"],"names":["APIError","createLocalReq","countOperation","countLocal","payload","options","collection","collectionSlug","disableErrors","overrideAccess","trash","where","collections","String","req"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,cAAa;AAoD5C,OAAO,eAAeC,WACpBC,OAAgB,EAChBC,OAA4B;IAE5B,MAAM,EACJC,YAAYC,cAAc,EAC1BC,aAAa,EACbC,iBAAiB,IAAI,EACrBC,QAAQ,KAAK,EACbC,KAAK,EACN,GAAGN;IAEJ,MAAMC,aAAaF,QAAQQ,WAAW,CAACL,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIN,SACR,CAAC,yBAAyB,EAAEa,OAAON,gBAAgB,iCAAiC,CAAC;IAEzF;IAEA,OAAOL,eAAsB;QAC3BI;QACAE;QACAC;QACAK,KAAK,MAAMb,eAAeI,SAAkCD;QAC5DM;QACAC;IACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js';
|
|
2
2
|
import type { Document, PayloadRequest, Where } from '../../../types/index.js';
|
|
3
|
-
export type
|
|
3
|
+
export type CountVersionsOptions<TSlug extends CollectionSlug> = {
|
|
4
4
|
/**
|
|
5
5
|
* the Collection slug to operate against.
|
|
6
6
|
*/
|
|
@@ -12,10 +12,6 @@ export type Options<TSlug extends CollectionSlug> = {
|
|
|
12
12
|
* to determine if it should run or not.
|
|
13
13
|
*/
|
|
14
14
|
context?: RequestContext;
|
|
15
|
-
/**
|
|
16
|
-
* [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
|
|
17
|
-
*/
|
|
18
|
-
depth?: number;
|
|
19
15
|
/**
|
|
20
16
|
* When set to `true`, errors will not be thrown.
|
|
21
17
|
*/
|
|
@@ -44,7 +40,7 @@ export type Options<TSlug extends CollectionSlug> = {
|
|
|
44
40
|
*/
|
|
45
41
|
where?: Where;
|
|
46
42
|
};
|
|
47
|
-
export declare function countVersionsLocal<TSlug extends CollectionSlug>(payload: Payload, options:
|
|
43
|
+
export declare function countVersionsLocal<TSlug extends CollectionSlug>(payload: Payload, options: CountVersionsOptions<TSlug>): Promise<{
|
|
48
44
|
totalDocs: number;
|
|
49
45
|
}>;
|
|
50
46
|
//# sourceMappingURL=countVersions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO9E,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/local/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC7F,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO9E,MAAM,MAAM,oBAAoB,CAAC,KAAK,SAAS,cAAc,IAAI;IAC/D;;OAEG;IACH,UAAU,EAAE,KAAK,CAAA;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,wBAAsB,kBAAkB,CAAC,KAAK,SAAS,cAAc,EACnE,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACnC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/operations/local/countVersions.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countVersionsOperation } from '../countVersions.js'\n\nexport type
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/local/countVersions.ts"],"sourcesContent":["import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countVersionsOperation } from '../countVersions.js'\n\nexport type CountVersionsOptions<TSlug extends CollectionSlug> = {\n /**\n * the Collection slug to operate against.\n */\n collection: TSlug\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * When set to `true`, errors will not be thrown.\n */\n disableErrors?: boolean\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n /**\n * A filter [query](https://payloadcms.com/docs/queries/overview)\n */\n where?: Where\n}\n\nexport async function countVersionsLocal<TSlug extends CollectionSlug>(\n payload: Payload,\n options: CountVersionsOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n const { collection: collectionSlug, disableErrors, overrideAccess = true, where } = options\n\n const collection = payload.collections[collectionSlug]\n\n if (!collection) {\n throw new APIError(\n `The collection with slug ${String(collectionSlug)} can't be found. Count Versions Operation.`,\n )\n }\n\n return countVersionsOperation<TSlug>({\n collection,\n disableErrors,\n overrideAccess,\n req: await createLocalReq(options as CreateLocalReqOptions, payload),\n where,\n })\n}\n"],"names":["APIError","createLocalReq","countVersionsOperation","countVersionsLocal","payload","options","collection","collectionSlug","disableErrors","overrideAccess","where","collections","String","req"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,sBAAsB,QAAQ,sBAAqB;AA2C5D,OAAO,eAAeC,mBACpBC,OAAgB,EAChBC,OAAoC;IAEpC,MAAM,EAAEC,YAAYC,cAAc,EAAEC,aAAa,EAAEC,iBAAiB,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAEpF,MAAMC,aAAaF,QAAQO,WAAW,CAACJ,eAAe;IAEtD,IAAI,CAACD,YAAY;QACf,MAAM,IAAIN,SACR,CAAC,yBAAyB,EAAEY,OAAOL,gBAAgB,0CAA0C,CAAC;IAElG;IAEA,OAAOL,uBAA8B;QACnCI;QACAE;QACAC;QACAI,KAAK,MAAMZ,eAAeI,SAAkCD;QAC5DM;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../../../../src/fields/baseFields/slug/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAA;AAE1B;;;;GAIG;AACH,eAAO,MAAM,aAAa,SAAgB;IACxC,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../../../../src/fields/baseFields/slug/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAA;AAE1B;;;;GAIG;AACH,eAAO,MAAM,aAAa,SAAgB;IACxC,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,OAAO,CAAC,MAAM,CA8BjB,CAAA"}
|
|
@@ -13,13 +13,11 @@
|
|
|
13
13
|
if (collectionSlug) {
|
|
14
14
|
countFn = ()=>req.payload.countVersions({
|
|
15
15
|
collection: collectionSlug,
|
|
16
|
-
depth: 0,
|
|
17
16
|
where
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
19
|
if (globalSlug) {
|
|
21
20
|
countFn = ()=>req.payload.countGlobalVersions({
|
|
22
|
-
depth: 0,
|
|
23
21
|
global: globalSlug,
|
|
24
22
|
where
|
|
25
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/fields/baseFields/slug/countVersions.ts"],"sourcesContent":["import type {\n CollectionSlug,\n DefaultDocumentIDType,\n GlobalSlug,\n PayloadRequest,\n Where,\n} from '../../../index.js'\n\n/**\n * This is a cross-entity way to count the number of versions for any given document.\n * It will work for both collections and globals.\n * @returns number of versions\n */\nexport const countVersions = async (args: {\n collectionSlug?: CollectionSlug\n globalSlug?: GlobalSlug\n parentID?: DefaultDocumentIDType\n req: PayloadRequest\n}): Promise<number> => {\n const { collectionSlug, globalSlug, parentID, req } = args\n\n let countFn\n\n const where: Where = {\n parent: {\n equals: parentID,\n },\n }\n\n if (collectionSlug) {\n countFn = () =>\n req.payload.countVersions({\n collection: collectionSlug,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/fields/baseFields/slug/countVersions.ts"],"sourcesContent":["import type {\n CollectionSlug,\n DefaultDocumentIDType,\n GlobalSlug,\n PayloadRequest,\n Where,\n} from '../../../index.js'\n\n/**\n * This is a cross-entity way to count the number of versions for any given document.\n * It will work for both collections and globals.\n * @returns number of versions\n */\nexport const countVersions = async (args: {\n collectionSlug?: CollectionSlug\n globalSlug?: GlobalSlug\n parentID?: DefaultDocumentIDType\n req: PayloadRequest\n}): Promise<number> => {\n const { collectionSlug, globalSlug, parentID, req } = args\n\n let countFn\n\n const where: Where = {\n parent: {\n equals: parentID,\n },\n }\n\n if (collectionSlug) {\n countFn = () =>\n req.payload.countVersions({\n collection: collectionSlug,\n where,\n })\n }\n\n if (globalSlug) {\n countFn = () =>\n req.payload.countGlobalVersions({\n global: globalSlug,\n where,\n })\n }\n\n const res = countFn ? (await countFn()?.then((res) => res.totalDocs || 0)) || 0 : 0\n\n return res\n}\n"],"names":["countVersions","args","collectionSlug","globalSlug","parentID","req","countFn","where","parent","equals","payload","collection","countGlobalVersions","global","res","then","totalDocs"],"mappings":"AAQA;;;;CAIC,GACD,OAAO,MAAMA,gBAAgB,OAAOC;IAMlC,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGJ;IAEtD,IAAIK;IAEJ,MAAMC,QAAe;QACnBC,QAAQ;YACNC,QAAQL;QACV;IACF;IAEA,IAAIF,gBAAgB;QAClBI,UAAU,IACRD,IAAIK,OAAO,CAACV,aAAa,CAAC;gBACxBW,YAAYT;gBACZK;YACF;IACJ;IAEA,IAAIJ,YAAY;QACdG,UAAU,IACRD,IAAIK,OAAO,CAACE,mBAAmB,CAAC;gBAC9BC,QAAQV;gBACRI;YACF;IACJ;IAEA,MAAMO,MAAMR,UAAU,AAAC,MAAMA,WAAWS,KAAK,CAACD,MAAQA,IAAIE,SAAS,IAAI,MAAO,IAAI;IAElF,OAAOF;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../src/globals/endpoints/docAccess.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAM3D,eAAO,MAAM,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"docAccess.d.ts","sourceRoot":"","sources":["../../../src/globals/endpoints/docAccess.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAM3D,eAAO,MAAM,gBAAgB,EAAE,cAe9B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/globals/endpoints/docAccess.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestGlobal } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { docAccessOperation } from '../operations/docAccess.js'\n\nexport const docAccessHandler: PayloadHandler = async (req) => {\n const globalConfig = getRequestGlobal(req)\n const result = await docAccessOperation({\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestGlobal","headersWithCors","docAccessOperation","docAccessHandler","req","globalConfig","result","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,OAAO,MAAMC,mBAAmC,OAAOC;IACrD,MAAMC,eAAeL,iBAAiBI;IACtC,MAAME,SAAS,MAAMJ,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../../src/globals/endpoints/docAccess.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestGlobal } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { docAccessOperation } from '../operations/docAccess.js'\n\nexport const docAccessHandler: PayloadHandler = async (req) => {\n const globalConfig = getRequestGlobal(req)\n const result = await docAccessOperation({\n data: req.data,\n globalConfig,\n req,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestGlobal","headersWithCors","docAccessOperation","docAccessHandler","req","globalConfig","result","data","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,OAAO,MAAMC,mBAAmC,OAAOC;IACrD,MAAMC,eAAeL,iBAAiBI;IACtC,MAAME,SAAS,MAAMJ,mBAAmB;QACtCK,MAAMH,IAAIG,IAAI;QACdF;QACAD;IACF;IAEA,OAAOI,SAASC,IAAI,CAACH,QAAQ;QAC3BI,SAAST,gBAAgB;YACvBS,SAAS,IAAIC;YACbP;QACF;QACAN,QAAQC,WAAWa,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -8,10 +8,6 @@ export type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {
|
|
|
8
8
|
* to determine if it should run or not.
|
|
9
9
|
*/
|
|
10
10
|
context?: RequestContext;
|
|
11
|
-
/**
|
|
12
|
-
* [Control auto-population](https://payloadcms.com/docs/queries/depth) of nested relationship and upload fields.
|
|
13
|
-
*/
|
|
14
|
-
depth?: number;
|
|
15
11
|
/**
|
|
16
12
|
* When set to `true`, errors will not be thrown.
|
|
17
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO9E,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,UAAU,IAAI;IACjE;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../../../../src/globals/operations/local/countVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAO9E,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,UAAU,IAAI;IACjE;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,MAAM,EAAE,KAAK,CAAA;IACb;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,wBAAsB,wBAAwB,CAAC,KAAK,SAAS,UAAU,EACrE,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,0BAA0B,CAAC,KAAK,CAAC,GACzC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/globals/operations/local/countVersions.ts"],"sourcesContent":["import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countGlobalVersionsOperation } from '../countGlobalVersions.js'\n\nexport type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../src/globals/operations/local/countVersions.ts"],"sourcesContent":["import type { GlobalSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'\nimport type { Document, PayloadRequest, Where } from '../../../types/index.js'\nimport type { CreateLocalReqOptions } from '../../../utilities/createLocalReq.js'\n\nimport { APIError } from '../../../errors/index.js'\nimport { createLocalReq } from '../../../utilities/createLocalReq.js'\nimport { countGlobalVersionsOperation } from '../countGlobalVersions.js'\n\nexport type CountGlobalVersionsOptions<TSlug extends GlobalSlug> = {\n /**\n * [Context](https://payloadcms.com/docs/hooks/context), which will then be passed to `context` and `req.context`,\n * which can be read by hooks. Useful if you want to pass additional information to the hooks which\n * shouldn't be necessarily part of the document, for example a `triggerBeforeChange` option which can be read by the BeforeChange hook\n * to determine if it should run or not.\n */\n context?: RequestContext\n /**\n * When set to `true`, errors will not be thrown.\n */\n disableErrors?: boolean\n /**\n * the Global slug to operate against.\n */\n global: TSlug\n /**\n * Specify [locale](https://payloadcms.com/docs/configuration/localization) for any returned documents.\n */\n locale?: TypedLocale\n /**\n * Skip access control.\n * Set to `false` if you want to respect Access Control for the operation, for example when fetching data for the front-end.\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The `PayloadRequest` object. You can pass it to thread the current [transaction](https://payloadcms.com/docs/database/transactions), user and locale to the operation.\n * Recommended to pass when using the Local API from hooks, as usually you want to execute the operation within the current transaction.\n */\n req?: Partial<PayloadRequest>\n /**\n * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n */\n user?: Document\n /**\n * A filter [query](https://payloadcms.com/docs/queries/overview)\n */\n where?: Where\n}\n\nexport async function countGlobalVersionsLocal<TSlug extends GlobalSlug>(\n payload: Payload,\n options: CountGlobalVersionsOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n const { disableErrors, global: globalSlug, overrideAccess = true, where } = options\n\n const global = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n if (!global) {\n throw new APIError(\n `The global with slug ${String(globalSlug)} can't be found. Count Global Versions Operation.`,\n )\n }\n\n return countGlobalVersionsOperation<TSlug>({\n disableErrors,\n global,\n overrideAccess,\n req: await createLocalReq(options as CreateLocalReqOptions, payload),\n where,\n })\n}\n"],"names":["APIError","createLocalReq","countGlobalVersionsOperation","countGlobalVersionsLocal","payload","options","disableErrors","global","globalSlug","overrideAccess","where","globals","config","find","slug","String","req"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,4BAA4B,QAAQ,4BAA2B;AA2CxE,OAAO,eAAeC,yBACpBC,OAAgB,EAChBC,OAA0C;IAE1C,MAAM,EAAEC,aAAa,EAAEC,QAAQC,UAAU,EAAEC,iBAAiB,IAAI,EAAEC,KAAK,EAAE,GAAGL;IAE5E,MAAME,SAASH,QAAQO,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASN;IAElE,IAAI,CAACD,QAAQ;QACX,MAAM,IAAIP,SACR,CAAC,qBAAqB,EAAEe,OAAOP,YAAY,iDAAiD,CAAC;IAEjG;IAEA,OAAON,6BAAoC;QACzCI;QACAC;QACAE;QACAO,KAAK,MAAMf,eAAeI,SAAkCD;QAC5DM;IACF;AACF"}
|