payload 3.35.0-internal.b3d367c → 3.35.1
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/admin/forms/Diff.d.ts +3 -10
- package/dist/admin/forms/Diff.d.ts.map +1 -1
- package/dist/admin/forms/Diff.js.map +1 -1
- package/dist/collections/config/useAsTitle.js +3 -3
- package/dist/collections/config/useAsTitle.js.map +1 -1
- package/dist/collections/operations/find.d.ts.map +1 -1
- package/dist/collections/operations/find.js +6 -1
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +6 -1
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/utilities/sanitizeSortQuery.d.ts +9 -0
- package/dist/collections/operations/utilities/sanitizeSortQuery.d.ts.map +1 -0
- package/dist/collections/operations/utilities/sanitizeSortQuery.js +42 -0
- package/dist/collections/operations/utilities/sanitizeSortQuery.js.map +1 -0
- package/dist/config/orderable/index.d.ts.map +1 -1
- package/dist/config/orderable/index.js +1 -4
- package/dist/config/orderable/index.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js +30 -20
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.d.ts +3 -2
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js +11 -6
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/fields/config/types.d.ts +9 -4
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +16 -0
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/virtualFieldPopulationPromise.d.ts +16 -0
- package/dist/fields/hooks/afterRead/virtualFieldPopulationPromise.d.ts.map +1 -0
- package/dist/fields/hooks/afterRead/virtualFieldPopulationPromise.js +92 -0
- package/dist/fields/hooks/afterRead/virtualFieldPopulationPromise.js.map +1 -0
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +1 -0
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/query-presets/access.d.ts.map +1 -1
- package/dist/query-presets/access.js +6 -0
- package/dist/query-presets/access.js.map +1 -1
- package/dist/query-presets/constraints.js +1 -1
- package/dist/query-presets/constraints.js.map +1 -1
- package/dist/query-presets/types.d.ts +1 -1
- package/dist/query-presets/types.d.ts.map +1 -1
- package/dist/query-presets/types.js.map +1 -1
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +4 -1
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/package.json +2 -2
|
@@ -20,8 +20,6 @@ export type VersionField = {
|
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* Taken from react-diff-viewer-continued
|
|
23
|
-
*
|
|
24
|
-
* @deprecated remove in 4.0 - react-diff-viewer-continued is no longer a dependency
|
|
25
23
|
*/
|
|
26
24
|
export declare enum DiffMethod {
|
|
27
25
|
CHARS = "diffChars",
|
|
@@ -36,13 +34,10 @@ export declare enum DiffMethod {
|
|
|
36
34
|
export type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalType = ClientField> = {
|
|
37
35
|
baseVersionField: BaseVersionField;
|
|
38
36
|
/**
|
|
39
|
-
* Field value from the version being compared
|
|
37
|
+
* Field value from the version being compared
|
|
40
38
|
*/
|
|
41
39
|
comparisonValue: unknown;
|
|
42
|
-
|
|
43
|
-
* @deprecated remove in 4.0. react-diff-viewer-continued is no longer a dependency
|
|
44
|
-
*/
|
|
45
|
-
diffMethod: any;
|
|
40
|
+
diffMethod: DiffMethod;
|
|
46
41
|
field: TClientField;
|
|
47
42
|
fieldPermissions: {
|
|
48
43
|
[key: string]: SanitizedFieldPermissions;
|
|
@@ -51,11 +46,9 @@ export type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalTyp
|
|
|
51
46
|
* If this field is localized, this will be the locale of the field
|
|
52
47
|
*/
|
|
53
48
|
locale?: string;
|
|
54
|
-
nestingLevel?: number;
|
|
55
49
|
parentIsLocalized: boolean;
|
|
56
50
|
/**
|
|
57
|
-
* Field value from the version
|
|
58
|
-
*
|
|
51
|
+
* Field value from the current version
|
|
59
52
|
*/
|
|
60
53
|
versionValue: unknown;
|
|
61
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diff.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAA;AACvF,OAAO,KAAK,EACV,2BAA2B,EAC3B,cAAc,EACd,yBAAyB,EACzB,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAEvB,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,YAAY,EAAE,CAAA;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,GAAG,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAEtB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACjC,MAAM,EAAE,YAAY,EAAE,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,YAAY,EAAE,EAAE,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,UAAU,EAAE,CAAA;IACnB,IAAI,EAAE,UAAU,CAAA;CAC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ff.ts"],"sourcesContent":["// @ts-strict-ignore\n\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport type { ClientField, Field, FieldTypes, Tab } from '../../fields/config/types.js'\nimport type {\n ClientFieldWithOptionalType,\n PayloadRequest,\n SanitizedFieldPermissions,\n TypedLocale,\n} from '../../index.js'\n\nexport type VersionTab = {\n fields: VersionField[]\n name?: string\n} & Pick<Tab, 'label'>\n\nexport type BaseVersionField = {\n CustomComponent?: React.ReactNode\n fields: VersionField[]\n path: string\n rows?: VersionField[][]\n schemaPath: string\n tabs?: VersionTab[]\n type: FieldTypes\n}\n\nexport type VersionField = {\n field?: BaseVersionField\n fieldByLocale?: Record<TypedLocale, BaseVersionField>\n}\n\n/**\n * Taken from react-diff-viewer-continued\n
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/forms/Diff.ts"],"sourcesContent":["// @ts-strict-ignore\n\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport type { ClientField, Field, FieldTypes, Tab } from '../../fields/config/types.js'\nimport type {\n ClientFieldWithOptionalType,\n PayloadRequest,\n SanitizedFieldPermissions,\n TypedLocale,\n} from '../../index.js'\n\nexport type VersionTab = {\n fields: VersionField[]\n name?: string\n} & Pick<Tab, 'label'>\n\nexport type BaseVersionField = {\n CustomComponent?: React.ReactNode\n fields: VersionField[]\n path: string\n rows?: VersionField[][]\n schemaPath: string\n tabs?: VersionTab[]\n type: FieldTypes\n}\n\nexport type VersionField = {\n field?: BaseVersionField\n fieldByLocale?: Record<TypedLocale, BaseVersionField>\n}\n\n/**\n * Taken from react-diff-viewer-continued\n */\nexport declare enum DiffMethod {\n CHARS = 'diffChars',\n CSS = 'diffCss',\n JSON = 'diffJson',\n LINES = 'diffLines',\n SENTENCES = 'diffSentences',\n TRIMMED_LINES = 'diffTrimmedLines',\n WORDS = 'diffWords',\n WORDS_WITH_SPACE = 'diffWordsWithSpace',\n}\n\nexport type FieldDiffClientProps<TClientField extends ClientFieldWithOptionalType = ClientField> = {\n baseVersionField: BaseVersionField\n /**\n * Field value from the version being compared\n */\n comparisonValue: unknown\n diffMethod: DiffMethod\n field: TClientField\n fieldPermissions:\n | {\n [key: string]: SanitizedFieldPermissions\n }\n | true\n /**\n * If this field is localized, this will be the locale of the field\n */\n locale?: string\n parentIsLocalized: boolean\n /**\n * Field value from the current version\n */\n versionValue: unknown\n}\n\nexport type FieldDiffServerProps<\n TField extends Field = Field,\n TClientField extends ClientFieldWithOptionalType = ClientField,\n> = {\n clientField: TClientField\n field: TField\n i18n: I18nClient\n req: PayloadRequest\n selectedLocales: string[]\n} & Omit<FieldDiffClientProps, 'field'>\n\nexport type FieldDiffClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDiffClientProps<TFieldClient>>\n\nexport type FieldDiffServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDiffServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAAA,oBAAoB;AAqFpB,WAGyE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InvalidConfiguration } from '../../errors/InvalidConfiguration.js';
|
|
2
|
-
import { fieldAffectsData
|
|
2
|
+
import { fieldAffectsData } from '../../fields/config/types.js';
|
|
3
3
|
import flattenFields from '../../utilities/flattenTopLevelFields.js';
|
|
4
4
|
/**
|
|
5
5
|
* Validate useAsTitle for collections.
|
|
@@ -23,8 +23,8 @@ import flattenFields from '../../utilities/flattenTopLevelFields.js';
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
} else {
|
|
26
|
-
if (useAsTitleField &&
|
|
27
|
-
throw new InvalidConfiguration(`The field "${config.admin.useAsTitle}" specified in "admin.useAsTitle" in the collection "${config.slug}" is virtual. A virtual field
|
|
26
|
+
if (useAsTitleField && 'virtual' in useAsTitleField && useAsTitleField.virtual === true) {
|
|
27
|
+
throw new InvalidConfiguration(`The field "${config.admin.useAsTitle}" specified in "admin.useAsTitle" in the collection "${config.slug}" is virtual. A virtual field can be used as the title only when linked to a relationship field.`);
|
|
28
28
|
}
|
|
29
29
|
if (!useAsTitleField) {
|
|
30
30
|
throw new InvalidConfiguration(`The field "${config.admin.useAsTitle}" specified in "admin.useAsTitle" does not exist in the collection "${config.slug}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/useAsTitle.ts"],"sourcesContent":["import type { CollectionConfig } from '../../index.js'\n\nimport { InvalidConfiguration } from '../../errors/InvalidConfiguration.js'\nimport { fieldAffectsData, fieldIsVirtual } from '../../fields/config/types.js'\nimport flattenFields from '../../utilities/flattenTopLevelFields.js'\n\n/**\n * Validate useAsTitle for collections.\n */\nexport const validateUseAsTitle = (config: CollectionConfig) => {\n if (config.admin?.useAsTitle?.includes('.')) {\n throw new InvalidConfiguration(\n `\"useAsTitle\" cannot be a nested field. Please specify a top-level field in the collection \"${config.slug}\"`,\n )\n }\n\n if (config?.admin && config.admin?.useAsTitle && config.admin.useAsTitle !== 'id') {\n const fields = flattenFields(config.fields)\n const useAsTitleField = fields.find((field) => {\n if (fieldAffectsData(field) && config.admin) {\n return field.name === config.admin.useAsTitle\n }\n return false\n })\n\n // If auth is enabled then we don't need to\n if (config.auth) {\n if (config.admin.useAsTitle !== 'email') {\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n } else {\n if (useAsTitleField &&
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/useAsTitle.ts"],"sourcesContent":["import type { CollectionConfig } from '../../index.js'\n\nimport { InvalidConfiguration } from '../../errors/InvalidConfiguration.js'\nimport { fieldAffectsData, fieldIsVirtual } from '../../fields/config/types.js'\nimport flattenFields from '../../utilities/flattenTopLevelFields.js'\n\n/**\n * Validate useAsTitle for collections.\n */\nexport const validateUseAsTitle = (config: CollectionConfig) => {\n if (config.admin?.useAsTitle?.includes('.')) {\n throw new InvalidConfiguration(\n `\"useAsTitle\" cannot be a nested field. Please specify a top-level field in the collection \"${config.slug}\"`,\n )\n }\n\n if (config?.admin && config.admin?.useAsTitle && config.admin.useAsTitle !== 'id') {\n const fields = flattenFields(config.fields)\n const useAsTitleField = fields.find((field) => {\n if (fieldAffectsData(field) && config.admin) {\n return field.name === config.admin.useAsTitle\n }\n return false\n })\n\n // If auth is enabled then we don't need to\n if (config.auth) {\n if (config.admin.useAsTitle !== 'email') {\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n } else {\n if (useAsTitleField && 'virtual' in useAsTitleField && useAsTitleField.virtual === true) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" in the collection \"${config.slug}\" is virtual. A virtual field can be used as the title only when linked to a relationship field.`,\n )\n }\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","flattenFields","validateUseAsTitle","config","admin","useAsTitle","includes","slug","fields","useAsTitleField","find","field","name","auth","virtual"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,gBAAgB,QAAwB,+BAA8B;AAC/E,OAAOC,mBAAmB,2CAA0C;AAEpE;;CAEC,GACD,OAAO,MAAMC,qBAAqB,CAACC;IACjC,IAAIA,OAAOC,KAAK,EAAEC,YAAYC,SAAS,MAAM;QAC3C,MAAM,IAAIP,qBACR,CAAC,2FAA2F,EAAEI,OAAOI,IAAI,CAAC,CAAC,CAAC;IAEhH;IAEA,IAAIJ,QAAQC,SAASD,OAAOC,KAAK,EAAEC,cAAcF,OAAOC,KAAK,CAACC,UAAU,KAAK,MAAM;QACjF,MAAMG,SAASP,cAAcE,OAAOK,MAAM;QAC1C,MAAMC,kBAAkBD,OAAOE,IAAI,CAAC,CAACC;YACnC,IAAIX,iBAAiBW,UAAUR,OAAOC,KAAK,EAAE;gBAC3C,OAAOO,MAAMC,IAAI,KAAKT,OAAOC,KAAK,CAACC,UAAU;YAC/C;YACA,OAAO;QACT;QAEA,2CAA2C;QAC3C,IAAIF,OAAOU,IAAI,EAAE;YACf,IAAIV,OAAOC,KAAK,CAACC,UAAU,KAAK,SAAS;gBACvC,IAAI,CAACI,iBAAiB;oBACpB,MAAM,IAAIV,qBACR,CAAC,WAAW,EAAEI,OAAOC,KAAK,CAACC,UAAU,CAAC,oEAAoE,EAAEF,OAAOI,IAAI,CAAC,CAAC,CAAC;gBAE9H;YACF;QACF,OAAO;YACL,IAAIE,mBAAmB,aAAaA,mBAAmBA,gBAAgBK,OAAO,KAAK,MAAM;gBACvF,MAAM,IAAIf,qBACR,CAAC,WAAW,EAAEI,OAAOC,KAAK,CAACC,UAAU,CAAC,qDAAqD,EAAEF,OAAOI,IAAI,CAAC,gGAAgG,CAAC;YAE9M;YACA,IAAI,CAACE,iBAAiB;gBACpB,MAAM,IAAIV,qBACR,CAAC,WAAW,EAAEI,OAAOC,KAAK,CAACC,UAAU,CAAC,oEAAoE,EAAEF,OAAOI,IAAI,CAAC,CAAC,CAAC;YAE9H;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/find.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,6BAA6B,EAC7B,KAAK,EACN,MAAM,sBAAsB,CAAA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tB,OAAO,CAAC,aAAa,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAgTtE,CAAA"}
|
|
@@ -11,6 +11,7 @@ import { buildVersionCollectionFields } from '../../versions/buildCollectionFiel
|
|
|
11
11
|
import { appendVersionToQueryKey } from '../../versions/drafts/appendVersionToQueryKey.js';
|
|
12
12
|
import { getQueryDraftsSelect } from '../../versions/drafts/getQueryDraftsSelect.js';
|
|
13
13
|
import { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js';
|
|
14
|
+
import { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js';
|
|
14
15
|
import { buildAfterOperation } from './utils.js';
|
|
15
16
|
const lockDurationDefault = 300 // Default 5 minutes in seconds
|
|
16
17
|
;
|
|
@@ -31,7 +32,7 @@ export const findOperation = async (incomingArgs)=>{
|
|
|
31
32
|
}) || args;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
const { collection: { config: collectionConfig }, collection, currentDepth, depth, disableErrors, draft: draftsEnabled, includeLockStatus, joins, limit, overrideAccess, page, pagination = true, populate, req: { fallbackLocale, locale, payload }, req, select: incomingSelect, showHiddenFields, sort, where } = args;
|
|
35
|
+
const { collection: { config: collectionConfig }, collection, currentDepth, depth, disableErrors, draft: draftsEnabled, includeLockStatus, joins, limit, overrideAccess, page, pagination = true, populate, req: { fallbackLocale, locale, payload }, req, select: incomingSelect, showHiddenFields, sort: incomingSort, where } = args;
|
|
35
36
|
const select = sanitizeSelect({
|
|
36
37
|
forceSelect: collectionConfig.forceSelect,
|
|
37
38
|
select: incomingSelect
|
|
@@ -69,6 +70,10 @@ export const findOperation = async (incomingArgs)=>{
|
|
|
69
70
|
const sanitizedPage = page || 1;
|
|
70
71
|
let result;
|
|
71
72
|
let fullWhere = combineQueries(where, accessResult);
|
|
73
|
+
const sort = sanitizeSortQuery({
|
|
74
|
+
fields: collection.config.flattenedFields,
|
|
75
|
+
sort: incomingSort
|
|
76
|
+
});
|
|
72
77
|
const sanitizedJoins = await sanitizeJoinQuery({
|
|
73
78
|
collectionConfig,
|
|
74
79
|
joins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/find.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { AccessResult } from '../../config/types.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { CollectionSlug, 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 { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.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 './utils.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 select?: SelectType\n showHiddenFields?: boolean\n sort?: Sort\n where?: Where\n}\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 if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'read',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft: draftsEnabled,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select: incomingSelect,\n showHiddenFields,\n sort,\n where,\n } = args\n\n const select = sanitizeSelect({\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,\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\n const sanitizedJoins = await sanitizeJoinQuery({\n collectionConfig,\n joins,\n overrideAccess,\n req,\n })\n\n if (collectionConfig.versions?.drafts && draftsEnabled) {\n fullWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n 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,\n page: sanitizedPage,\n pagination: usePagination,\n req,\n select: getQueryDraftsSelect({ select }),\n sort: getQueryDraftsSort({ collectionConfig, sort }),\n where: fullWhere,\n })\n } else {\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n 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,\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,\n doc,\n draft: draftsEnabled,\n fallbackLocale,\n findMany: true,\n global: null,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n 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","afterRead","lockedDocumentsCollectionSlug","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSelect","getQueryDraftsSort","buildAfterOperation","lockDurationDefault","findOperation","incomingArgs","args","collection","config","hooks","beforeOperation","length","hook","context","req","operation","collectionConfig","currentDepth","depth","disableErrors","draft","draftsEnabled","includeLockStatus","joins","limit","overrideAccess","page","pagination","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","sort","where","forceSelect","accessResult","access","read","docs","hasNextPage","hasPrevPage","nextPage","pagingCounter","prevPage","totalDocs","totalPages","usePagination","sanitizedLimit","sanitizedPage","result","fullWhere","sanitizedJoins","versions","drafts","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","beforeRead","Promise","all","docRef","query","findMany","global","error"],"mappings":"AAAA,oBAAoB;AAkBpB,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,6BAA6B,QAAQ,mCAAkC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,4BAA4B,QAAQ,0CAAyC;AACtF,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,mBAAmB,QAAQ,aAAY;AAsBhD,MAAMC,sBAAsB,IAAI,+BAA+B;;AAE/D,OAAO,MAAMC,gBAAgB,OAI3BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;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X;gBAEA,OAAOqB;YACT;QAEJ;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC7C,SAAS,MAAMlD,oBAAoB;YACjCI;YACAC,YAAYS;YACZD,WAAW;YACXqC;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOiD,OAAgB;QACvB,MAAMzG,gBAAgBU,KAAKQ,GAAG;QAC9B,MAAMuF;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/find.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { AccessResult } from '../../config/types.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { CollectionSlug, 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 { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { lockedDocumentsCollectionSlug } from '../../locked-documents/config.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 { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js'\nimport { buildAfterOperation } from './utils.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 select?: SelectType\n showHiddenFields?: boolean\n sort?: Sort\n where?: Where\n}\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 if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'read',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft: draftsEnabled,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination = true,\n populate,\n req: { fallbackLocale, locale, payload },\n req,\n select: incomingSelect,\n showHiddenFields,\n sort: incomingSort,\n where,\n } = args\n\n const select = sanitizeSelect({\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,\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\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,\n req,\n })\n\n if (collectionConfig.versions?.drafts && draftsEnabled) {\n fullWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n 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,\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,\n req,\n 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,\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,\n doc,\n draft: draftsEnabled,\n fallbackLocale,\n findMany: true,\n global: null,\n locale,\n overrideAccess,\n populate,\n req,\n select,\n 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","afterRead","lockedDocumentsCollectionSlug","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSelect","getQueryDraftsSort","sanitizeSortQuery","buildAfterOperation","lockDurationDefault","findOperation","incomingArgs","args","collection","config","hooks","beforeOperation","length","hook","context","req","operation","collectionConfig","currentDepth","depth","disableErrors","draft","draftsEnabled","includeLockStatus","joins","limit","overrideAccess","page","pagination","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","sort","incomingSort","where","forceSelect","accessResult","access","read","docs","hasNextPage","hasPrevPage","nextPage","pagingCounter","prevPage","totalDocs","totalPages","usePagination","sanitizedLimit","sanitizedPage","result","fullWhere","fields","flattenedFields","sanitizedJoins","versions","drafts","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","beforeRead","Promise","all","docRef","query","findMany","global","error"],"mappings":"AAAA,oBAAoB;AAkBpB,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,6BAA6B,QAAQ,mC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UAAU;gBACVC,QAAQ;gBACRzE;gBACAL;gBACAG;gBACAd;gBACAkB;gBACAE;YACF;QAIJ,wCAAwC;QACxC,yBAAyB;QACzB,wCAAwC;QAExC,IAAIlB,kBAAkBP,OAAOhB,WAAWkB,QAAQ;YAC9C0C,OAAOX,IAAI,GAAG,MAAMwD,QAAQC,GAAG,CAC7B9C,OAAOX,IAAI,CAACoC,GAAG,CAAC,OAAOC;gBACrB,IAAIqB,SAASrB;gBAEb,KAAK,MAAMnE,QAAQI,iBAAiBP,KAAK,CAAChB,SAAS,CAAE;oBACnD2G,SACE,AAAC,MAAMxF,KAAK;wBACVL,YAAYS;wBACZH,SAASC,IAAID,OAAO;wBACpBkE,KAAKqB;wBACLE,UAAU;wBACVD,OAAO/C;wBACPxC;oBACF,MAAOiE;gBACX;gBAEA,OAAOqB;YACT;QAEJ;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC/C,SAAS,MAAMnD,oBAAoB;YACjCI;YACAC,YAAYS;YACZD,WAAW;YACXsC;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOmD,OAAgB;QACvB,MAAM7G,gBAAgBW,KAAKQ,GAAG;QAC9B,MAAM0F;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/update.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAKhD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EAEV,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAM3B,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,gBAAgB,CAAA;
|
|
1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K,CAAC,KAC7B,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAqN7C,CAAA"}
|
|
@@ -14,6 +14,7 @@ import { sanitizeSelect } from '../../utilities/sanitizeSelect.js';
|
|
|
14
14
|
import { buildVersionCollectionFields } from '../../versions/buildCollectionFields.js';
|
|
15
15
|
import { appendVersionToQueryKey } from '../../versions/drafts/appendVersionToQueryKey.js';
|
|
16
16
|
import { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js';
|
|
17
|
+
import { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js';
|
|
17
18
|
import { updateDocument } from './utilities/update.js';
|
|
18
19
|
import { buildAfterOperation } from './utils.js';
|
|
19
20
|
export const updateOperation = async (incomingArgs)=>{
|
|
@@ -34,7 +35,7 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
34
35
|
}) || args;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
const { collection: { config: collectionConfig }, collection, depth, draft: draftArg = false, limit = 0, overrideAccess, overrideLock, overwriteExistingFiles = false, populate, publishSpecificLocale, req: { fallbackLocale, locale, payload: { config }, payload }, req, select: incomingSelect, showHiddenFields, sort, where } = args;
|
|
38
|
+
const { collection: { config: collectionConfig }, collection, depth, draft: draftArg = false, limit = 0, overrideAccess, overrideLock, overwriteExistingFiles = false, populate, publishSpecificLocale, req: { fallbackLocale, locale, payload: { config }, payload }, req, select: incomingSelect, showHiddenFields, sort: incomingSort, where } = args;
|
|
38
39
|
if (!where) {
|
|
39
40
|
throw new APIError("Missing 'where' query of documents to update.", httpStatus.BAD_REQUEST);
|
|
40
41
|
}
|
|
@@ -59,6 +60,10 @@ export const updateOperation = async (incomingArgs)=>{
|
|
|
59
60
|
// Retrieve documents
|
|
60
61
|
// /////////////////////////////////////
|
|
61
62
|
const fullWhere = combineQueries(where, accessResult);
|
|
63
|
+
const sort = sanitizeSortQuery({
|
|
64
|
+
fields: collection.config.flattenedFields,
|
|
65
|
+
sort: incomingSort
|
|
66
|
+
});
|
|
62
67
|
let docs;
|
|
63
68
|
if (collectionConfig.versions?.drafts && shouldSaveDraft) {
|
|
64
69
|
const versionsWhere = appendVersionToQueryKey(fullWhere);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/update.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { DeepPartial } from 'ts-essentials'\n\nimport { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\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 { APIError } from '../../errors/index.js'\nimport { type CollectionSlug, deepCopyObjectSimple } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.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 { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js'\nimport { updateDocument } from './utilities/update.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n limit?: number\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n /**\n * Sort the documents, can be a string or an array of strings\n * @example '-createdAt' // Sort DESC by createdAt\n * @example ['group', '-createdAt'] // sort by 2 fields, ASC group and DESC createdAt\n */\n sort?: Sort\n where: Where\n}\n\nexport const updateOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'update',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n limit = 0,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n sort,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to update.\", httpStatus.BAD_REQUEST)\n }\n\n const { data: bulkUpdateData } = args\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.update)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n const fullWhere = combineQueries(where, accessResult)\n\n let docs\n\n if (collectionConfig.versions?.drafts && shouldSaveDraft) {\n const versionsWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n overrideAccess,\n req,\n versionFields: buildVersionCollectionFields(payload.config, collection.config, true),\n where: appendVersionToQueryKey(where),\n })\n\n const query = await payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n limit,\n locale,\n pagination: false,\n req,\n sort: getQueryDraftsSort({ collectionConfig, sort }),\n where: versionsWhere,\n })\n\n docs = query.docs\n } else {\n const query = await payload.db.find({\n collection: collectionConfig.slug,\n limit,\n locale,\n pagination: false,\n req,\n sort,\n where: fullWhere,\n })\n\n docs = query.docs\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data: bulkUpdateData,\n operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n const errors = []\n\n const promises = docs.map(async (docWithLocales) => {\n const { id } = docWithLocales\n\n try {\n const select = sanitizeSelect({\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // ///////////////////////////////////////////////\n // Update document, runs all document level hooks\n // ///////////////////////////////////////////////\n const updatedDoc = await updateDocument({\n id,\n accessResults: accessResult,\n autosave: false,\n collectionConfig,\n config,\n data: deepCopyObjectSimple(data),\n depth,\n docWithLocales,\n draftArg,\n fallbackLocale,\n filesToUpload,\n locale,\n overrideAccess,\n overrideLock,\n payload,\n populate,\n publishSpecificLocale,\n req,\n select,\n showHiddenFields,\n })\n\n return updatedDoc\n } catch (error) {\n errors.push({\n id,\n message: error.message,\n })\n }\n return null\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n const awaitedDocs = await Promise.all(promises)\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'update',\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","APIError","deepCopyObjectSimple","generateFileData","unlinkTempFiles","commitTransaction","initTransaction","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSort","updateDocument","buildAfterOperation","updateOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","length","hook","context","operation","collectionConfig","depth","draft","draftArg","limit","overrideAccess","overrideLock","overwriteExistingFiles","populate","publishSpecificLocale","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","sort","where","BAD_REQUEST","data","bulkUpdateData","shouldSaveDraft","Boolean","versions","drafts","accessResult","access","update","fullWhere","docs","versionsWhere","versionFields","query","db","queryDrafts","slug","pagination","find","files","filesToUpload","throwOnMissingFile","errors","promises","map","docWithLocales","id","forceSelect","updatedDoc","accessResults","autosave","error","push","message","awaitedDocs","Promise","all","result","filter"],"mappings":"AAAA,oBAAoB;AAGpB,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAA8BC,oBAAoB,QAAQ,iBAAgB;AAC1E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,4BAA4B,QAAQ,0CAAyC;AACtF,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,cAAc,QAAQ,wBAAu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MAAM,EAAEC,EAAE,EAAE,GAAGD;YAEf,IAAI;gBACF,MAAM/B,SAASjC,eAAe;oBAC5BkE,aAAa9C,iBAAiB8C,WAAW;oBACzCjC,QAAQC;gBACV;gBAEA,kDAAkD;gBAClD,iDAAiD;gBACjD,kDAAkD;gBAClD,MAAMiC,aAAa,MAAM/D,eAAe;oBACtC6D;oBACAG,eAAevB;oBACfwB,UAAU;oBACVjD;oBACAP;oBACA0B,MAAM7C,qBAAqB6C;oBAC3BlB;oBACA2C;oBACAzC;oBACAO;oBACA6B;oBACA5B;oBACAN;oBACAC;oBACAM;oBACAJ;oBACAC;oBACAlB;oBACAsB;oBACAE;gBACF;gBAEA,OAAOgC;YACT,EAAE,OAAOG,OAAO;gBACdT,OAAOU,IAAI,CAAC;oBACVN;oBACAO,SAASF,MAAME,OAAO;gBACxB;YACF;YACA,OAAO;QACT;QAEA,MAAM5E,gBAAgB;YACpBwB;YACAP;YACAF;QACF;QAEA,MAAM8D,cAAc,MAAMC,QAAQC,GAAG,CAACb;QAEtC,IAAIc,SAAS;YACX3B,MAAMwB,YAAYI,MAAM,CAACnC;YACzBmB;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCe,SAAS,MAAMvE,oBAAoB;YACjCG;YACAI,YAAYQ;YACZD,WAAW;YACXyD;QACF;QAEA,IAAInE,cAAc;YAChB,MAAMZ,kBAAkBc;QAC1B;QAEA,OAAOiE;IACT,EAAE,OAAON,OAAgB;QACvB,MAAMvE,gBAAgBS,KAAKG,GAAG;QAC9B,MAAM2D;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/update.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { DeepPartial } from 'ts-essentials'\n\nimport { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { PayloadRequest, PopulateType, SelectType, Sort, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\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 { APIError } from '../../errors/index.js'\nimport { type CollectionSlug, deepCopyObjectSimple } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.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 { getQueryDraftsSort } from '../../versions/drafts/getQueryDraftsSort.js'\nimport { sanitizeSortQuery } from './utilities/sanitizeSortQuery.js'\nimport { updateDocument } from './utilities/update.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n limit?: number\n overrideAccess?: boolean\n overrideLock?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n /**\n * Sort the documents, can be a string or an array of strings\n * @example '-createdAt' // Sort DESC by createdAt\n * @example ['group', '-createdAt'] // sort by 2 fields, ASC group and DESC createdAt\n */\n sort?: Sort\n where: Where\n}\n\nexport const updateOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'update',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n collection,\n depth,\n draft: draftArg = false,\n limit = 0,\n overrideAccess,\n overrideLock,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n sort: incomingSort,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to update.\", httpStatus.BAD_REQUEST)\n }\n\n const { data: bulkUpdateData } = args\n const shouldSaveDraft = Boolean(draftArg && collectionConfig.versions.drafts)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.update)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess,\n req,\n where,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n const fullWhere = combineQueries(where, accessResult)\n\n const sort = sanitizeSortQuery({\n fields: collection.config.flattenedFields,\n sort: incomingSort,\n })\n\n let docs\n\n if (collectionConfig.versions?.drafts && shouldSaveDraft) {\n const versionsWhere = appendVersionToQueryKey(fullWhere)\n\n await validateQueryPaths({\n collectionConfig: collection.config,\n overrideAccess,\n req,\n versionFields: buildVersionCollectionFields(payload.config, collection.config, true),\n where: appendVersionToQueryKey(where),\n })\n\n const query = await payload.db.queryDrafts<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n limit,\n locale,\n pagination: false,\n req,\n sort: getQueryDraftsSort({ collectionConfig, sort }),\n where: versionsWhere,\n })\n\n docs = query.docs\n } else {\n const query = await payload.db.find({\n collection: collectionConfig.slug,\n limit,\n locale,\n pagination: false,\n req,\n sort,\n where: fullWhere,\n })\n\n docs = query.docs\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data: bulkUpdateData,\n operation: 'update',\n overwriteExistingFiles,\n req,\n throwOnMissingFile: false,\n })\n\n const errors = []\n\n const promises = docs.map(async (docWithLocales) => {\n const { id } = docWithLocales\n\n try {\n const select = sanitizeSelect({\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // ///////////////////////////////////////////////\n // Update document, runs all document level hooks\n // ///////////////////////////////////////////////\n const updatedDoc = await updateDocument({\n id,\n accessResults: accessResult,\n autosave: false,\n collectionConfig,\n config,\n data: deepCopyObjectSimple(data),\n depth,\n docWithLocales,\n draftArg,\n fallbackLocale,\n filesToUpload,\n locale,\n overrideAccess,\n overrideLock,\n payload,\n populate,\n publishSpecificLocale,\n req,\n select,\n showHiddenFields,\n })\n\n return updatedDoc\n } catch (error) {\n errors.push({\n id,\n message: error.message,\n })\n }\n return null\n })\n\n await unlinkTempFiles({\n collectionConfig,\n config,\n req,\n })\n\n const awaitedDocs = await Promise.all(promises)\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'update',\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","APIError","deepCopyObjectSimple","generateFileData","unlinkTempFiles","commitTransaction","initTransaction","killTransaction","sanitizeSelect","buildVersionCollectionFields","appendVersionToQueryKey","getQueryDraftsSort","sanitizeSortQuery","updateDocument","buildAfterOperation","updateOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","length","hook","context","operation","collectionConfig","depth","draft","draftArg","limit","overrideAccess","overrideLock","overwriteExistingFiles","populate","publishSpecificLocale","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","sort","incomingSort","where","BAD_REQUEST","data","bulkUpdateData","shouldSaveDraft","Boolean","versions","drafts","accessResult","access","update","fullWhere","fields","flattenedFields","docs","versionsWhere","versionFields","query","db","queryDrafts","slug","pagination","find","files","filesToUpload","throwOnMissingFile","errors","promises","map","docWithLocales","id","forceSelect","updatedDoc","accessResults","autosave","error","push","message","awaitedDocs","Promise","all","result","filter"],"mappings":"AAAA,oBAAoB;AAGpB,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAA8BC,oBAAoB,QAAQ,iBAAgB;AAC1E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,4BAA4B,QAAQ,0CAAyC;AACtF,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,mBAAmB,QAAQ,aAAY;AA2BhD,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMb,gBAAgBW,KAAKG,GAAG;QAEhF,wCAAwC;QACxC,+BAA+B;QAC/B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QC;gBACV;gBAEA,kDAAkD;gBAClD,iDAAiD;gBACjD,kDAAkD;gBAClD,MAAMoC,aAAa,MAAMlE,eAAe;oBACtCgE;oBACAG,eAAezB;oBACf0B,UAAU;oBACVpD;oBACAP;oBACA2B,MAAM/C,qBAAqB+C;oBAC3BnB;oBACA8C;oBACA5C;oBACAO;oBACAgC;oBACA/B;oBACAN;oBACAC;oBACAM;oBACAJ;oBACAC;oBACAlB;oBACAsB;oBACAE;gBACF;gBAEA,OAAOmC;YACT,EAAE,OAAOG,OAAO;gBACdT,OAAOU,IAAI,CAAC;oBACVN;oBACAO,SAASF,MAAME,OAAO;gBACxB;YACF;YACA,OAAO;QACT;QAEA,MAAMhF,gBAAgB;YACpByB;YACAP;YACAF;QACF;QAEA,MAAMiE,cAAc,MAAMC,QAAQC,GAAG,CAACb;QAEtC,IAAIc,SAAS;YACX3B,MAAMwB,YAAYI,MAAM,CAACrC;YACzBqB;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCe,SAAS,MAAM1E,oBAAoB;YACjCG;YACAI,YAAYQ;YACZD,WAAW;YACX4D;QACF;QAEA,IAAItE,cAAc;YAChB,MAAMb,kBAAkBe;QAC1B;QAEA,OAAOoE;IACT,EAAE,OAAON,OAAgB;QACvB,MAAM3E,gBAAgBU,KAAKG,GAAG;QAC9B,MAAM8D;IACR;AACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FlattenedField } from '../../../fields/config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sanitizes the sort parameter, for example virtual fields linked to relationships are replaced with the full path.
|
|
4
|
+
*/
|
|
5
|
+
export declare const sanitizeSortQuery: ({ fields, sort, }: {
|
|
6
|
+
fields: FlattenedField[];
|
|
7
|
+
sort?: string | string[];
|
|
8
|
+
}) => string | string[] | undefined;
|
|
9
|
+
//# sourceMappingURL=sanitizeSortQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeSortQuery.d.ts","sourceRoot":"","sources":["../../../../src/collections/operations/utilities/sanitizeSortQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AA+BrE;;GAEG;AACH,eAAO,MAAM,iBAAiB,sBAG3B;IACD,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACzB,KAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAUvB,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const sanitizeSort = ({ fields, sort })=>{
|
|
2
|
+
let sortProperty = sort;
|
|
3
|
+
let desc = false;
|
|
4
|
+
if (sort.indexOf('-') === 0) {
|
|
5
|
+
desc = true;
|
|
6
|
+
sortProperty = sortProperty.substring(1);
|
|
7
|
+
}
|
|
8
|
+
const segments = sortProperty.split('.');
|
|
9
|
+
for (const segment of segments){
|
|
10
|
+
const field = fields.find((each)=>each.name === segment);
|
|
11
|
+
if (!field) {
|
|
12
|
+
return sort;
|
|
13
|
+
}
|
|
14
|
+
if ('fields' in field) {
|
|
15
|
+
fields = field.flattenedFields;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if ('virtual' in field && typeof field.virtual === 'string') {
|
|
19
|
+
return `${desc ? '-' : ''}${field.virtual}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return sort;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Sanitizes the sort parameter, for example virtual fields linked to relationships are replaced with the full path.
|
|
26
|
+
*/ export const sanitizeSortQuery = ({ fields, sort })=>{
|
|
27
|
+
if (!sort) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(sort)) {
|
|
31
|
+
return sort.map((sort)=>sanitizeSort({
|
|
32
|
+
fields,
|
|
33
|
+
sort
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
return sanitizeSort({
|
|
37
|
+
fields,
|
|
38
|
+
sort
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=sanitizeSortQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/operations/utilities/sanitizeSortQuery.ts"],"sourcesContent":["import type { FlattenedField } from '../../../fields/config/types.js'\n\nconst sanitizeSort = ({ fields, sort }: { fields: FlattenedField[]; sort: string }): string => {\n let sortProperty = sort\n let desc = false\n if (sort.indexOf('-') === 0) {\n desc = true\n sortProperty = sortProperty.substring(1)\n }\n\n const segments = sortProperty.split('.')\n\n for (const segment of segments) {\n const field = fields.find((each) => each.name === segment)\n if (!field) {\n return sort\n }\n\n if ('fields' in field) {\n fields = field.flattenedFields\n continue\n }\n\n if ('virtual' in field && typeof field.virtual === 'string') {\n return `${desc ? '-' : ''}${field.virtual}`\n }\n }\n\n return sort\n}\n\n/**\n * Sanitizes the sort parameter, for example virtual fields linked to relationships are replaced with the full path.\n */\nexport const sanitizeSortQuery = ({\n fields,\n sort,\n}: {\n fields: FlattenedField[]\n sort?: string | string[]\n}): string | string[] | undefined => {\n if (!sort) {\n return undefined\n }\n\n if (Array.isArray(sort)) {\n return sort.map((sort) => sanitizeSort({ fields, sort }))\n }\n\n return sanitizeSort({ fields, sort })\n}\n"],"names":["sanitizeSort","fields","sort","sortProperty","desc","indexOf","substring","segments","split","segment","field","find","each","name","flattenedFields","virtual","sanitizeSortQuery","undefined","Array","isArray","map"],"mappings":"AAEA,MAAMA,eAAe,CAAC,EAAEC,MAAM,EAAEC,IAAI,EAA8C;IAChF,IAAIC,eAAeD;IACnB,IAAIE,OAAO;IACX,IAAIF,KAAKG,OAAO,CAAC,SAAS,GAAG;QAC3BD,OAAO;QACPD,eAAeA,aAAaG,SAAS,CAAC;IACxC;IAEA,MAAMC,WAAWJ,aAAaK,KAAK,CAAC;IAEpC,KAAK,MAAMC,WA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GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF,CAAA;AAED,eAAO,MAAM,oBAAoB,WAAY,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/orderable/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAE3F,OAAO,KAAK,EAA4B,eAAe,EAAE,MAAM,aAAa,CAAA;AAM5E;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,WAAY,eAAe,SAkDrD,CAAA;AAED,eAAO,MAAM,yBAAyB,eACxB,gBAAgB,uBACP,MAAM,EAAE,SAiE9B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAA;IAChC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAA;QACV,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF,CAAA;AAED,eAAO,MAAM,oBAAoB,WAAY,eAAe,SA8H3D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/orderable/index.ts"],"sourcesContent":["import type { BeforeChangeHook, CollectionConfig } from '../../collections/config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { Endpoint, PayloadHandler, SanitizedConfig } from '../types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { traverseFields } from '../../utilities/traverseFields.js'\nimport { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js'\n\n/**\n * This function creates:\n * - N fields per collection, named `_order` or `_<collection>_<joinField>_order`\n * - 1 hook per collection\n * - 1 endpoint per app\n *\n * Also, if collection.defaultSort or joinField.defaultSort is not set, it will be set to the orderable field.\n */\nexport const setupOrderable = (config: SanitizedConfig) => {\n const fieldsToAdd = new Map<CollectionConfig, string[]>()\n\n config.collections.forEach((collection) => {\n if (collection.orderable) {\n const currentFields = fieldsToAdd.get(collection) || []\n fieldsToAdd.set(collection, [...currentFields, '_order'])\n collection.defaultSort = collection.defaultSort ?? '_order'\n }\n\n traverseFields({\n callback: ({ field, parentRef, ref }) => {\n if (field.type === 'array' || field.type === 'blocks') {\n return false\n }\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}`\n }\n if (field.type === 'join' && field.orderable === true) {\n if (Array.isArray(field.collection)) {\n throw new Error('Orderable joins must target a single collection')\n }\n const relationshipCollection = config.collections.find((c) => c.slug === field.collection)\n if (!relationshipCollection) {\n return false\n }\n field.defaultSort = field.defaultSort ?? `_${field.collection}_${field.name}_order`\n const currentFields = fieldsToAdd.get(relationshipCollection) || []\n // @ts-expect-error ref is untyped\n const prefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n fieldsToAdd.set(relationshipCollection, [\n ...currentFields,\n `_${field.collection}_${prefix}${field.name}_order`,\n ])\n }\n },\n fields: collection.fields,\n })\n })\n\n Array.from(fieldsToAdd.entries()).forEach(([collection, orderableFields]) => {\n addOrderableFieldsAndHook(collection, orderableFields)\n })\n\n if (fieldsToAdd.size > 0) {\n addOrderableEndpoint(config)\n }\n}\n\nexport const addOrderableFieldsAndHook = (\n collection: CollectionConfig,\n orderableFieldNames: string[],\n) => {\n // 1. Add field\n orderableFieldNames.forEach((orderableFieldName) => {\n const orderField: Field = {\n name: orderableFieldName,\n type: 'text',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n readOnly: true,\n },\n index: true,\n required: true,\n // override the schema to make order fields optional for payload.create()\n typescriptSchema: [\n () => ({\n type: 'string',\n required: false,\n }),\n ],\n unique: true,\n }\n\n collection.fields.unshift(orderField)\n })\n\n // 2. Add hook\n if (!collection.hooks) {\n collection.hooks = {}\n }\n if (!collection.hooks.beforeChange) {\n collection.hooks.beforeChange = []\n }\n\n const orderBeforeChangeHook: BeforeChangeHook = async ({ data, originalDoc, req }) => {\n for (const orderableFieldName of orderableFieldNames) {\n if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {\n const lastDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n select: { [orderableFieldName]: true },\n sort: `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n exists: true,\n },\n },\n })\n\n const lastOrderValue = lastDoc.docs[0]?.[orderableFieldName] || null\n data[orderableFieldName] = generateKeyBetween(lastOrderValue, null)\n }\n }\n\n return data\n }\n\n collection.hooks.beforeChange.push(orderBeforeChangeHook)\n}\n\n/**\n * The body of the reorder endpoint.\n * @internal\n */\nexport type OrderableEndpointBody = {\n collectionSlug: string\n docsToMove: string[]\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: string\n }\n}\n\nexport const addOrderableEndpoint = (config: SanitizedConfig) => {\n // 3. Add endpoint\n const reorderHandler: PayloadHandler = async (req) => {\n const body = (await req.json?.()) as OrderableEndpointBody\n\n const { collectionSlug, docsToMove, newKeyWillBe, orderableFieldName, target } = body\n\n if (!Array.isArray(docsToMove) || docsToMove.length === 0) {\n return new Response(JSON.stringify({ error: 'docsToMove must be a non-empty array' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (\n typeof target !== 'object' ||\n typeof target.id === 'undefined' ||\n typeof target.key !== 'string'\n ) {\n return new Response(JSON.stringify({ error: 'target must be an object with id and key' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (newKeyWillBe !== 'greater' && newKeyWillBe !== 'less') {\n return new Response(JSON.stringify({ error: 'newKeyWillBe must be \"greater\" or \"less\"' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n const collection = config.collections.find((c) => c.slug === collectionSlug)\n if (!collection) {\n return new Response(JSON.stringify({ error: `Collection ${collectionSlug} not found` }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (typeof orderableFieldName !== 'string') {\n return new Response(JSON.stringify({ error: 'orderableFieldName must be a string' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n // Prevent reordering if user doesn't have editing permissions\n if (collection.access?.update) {\n await executeAccess(\n {\n // Currently only one doc can be moved at a time. We should review this if we want to allow\n // multiple docs to be moved at once in the future.\n id: docsToMove[0],\n data: {},\n req,\n },\n collection.access.update,\n )\n }\n\n const targetId = target.id\n let targetKey = target.key\n\n // If targetKey = pending, we need to find its current key.\n // This can only happen if the user reorders rows quickly with a slow connection.\n if (targetKey === 'pending') {\n const beforeDoc = await req.payload.findByID({\n id: targetId,\n collection: collection.slug,\n depth: 0,\n select: { [orderableFieldName]: true },\n })\n targetKey = beforeDoc?.[orderableFieldName] || null\n }\n\n // The reason the endpoint does not receive this docId as an argument is that there\n // are situations where the user may not see or know what the next or previous one is. For\n // example, access control restrictions, if docBefore is the last one on the page, etc.\n const adjacentDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: { [orderableFieldName]: true },\n sort: newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n [newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: targetKey,\n },\n },\n })\n const adjacentDocKey = adjacentDoc.docs?.[0]?.[orderableFieldName] || null\n\n // Currently N (= docsToMove.length) is always 1. Maybe in the future we will\n // allow dragging and reordering multiple documents at once via the UI.\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length)\n\n // Update each document with its new order value\n for (const [index, id] of docsToMove.entries()) {\n await req.payload.update({\n id,\n collection: collection.slug,\n data: {\n [orderableFieldName]: orderValues[index],\n },\n depth: 0,\n req,\n select: { id: true },\n })\n }\n\n return new Response(JSON.stringify({ orderValues, success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n const reorderEndpoint: Endpoint = {\n handler: reorderHandler,\n method: 'post',\n path: '/reorder',\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n config.endpoints.push(reorderEndpoint)\n}\n"],"names":["executeAccess","traverseFields","generateKeyBetween","generateNKeysBetween","setupOrderable","config","fieldsToAdd","Map","collections","forEach","collection","orderable","currentFields","get","set","defaultSort","callback","field","parentRef","ref","type","parentPrefix","prefix","name","Array","isArray","Error","relationshipCollection","find","c","slug","fields","from","entries","orderableFields","addOrderableFieldsAndHook","size","addOrderableEndpoint","orderableFieldNames","orderableFieldName","orderField","admin","disableBulkEdit","disabled","disableListColumn","disableListFilter","hidden","readOnly","index","required","typescriptSchema","unique","unshift","hooks","beforeChange","orderBeforeChangeHook","data","originalDoc","req","lastDoc","payload","depth","limit","pagination","select","sort","where","exists","lastOrderValue","docs","push","reorderHandler","body","json","collectionSlug","docsToMove","newKeyWillBe","target","length","Response","JSON","stringify","error","headers","status","id","key","access","update","targetId","targetKey","beforeDoc","findByID","adjacentDoc","adjacentDocKey","orderValues","success","reorderEndpoint","handler","method","path","endpoints"],"mappings":"AAIA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,2BAA0B;AAEnF;;;;;;;CAOC,GACD,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAMC,cAAc,IAAIC;IAExBF,OAAOG,WAAW,CAACC,OAAO,CAAC,CAACC;QAC1B,IAAIA,WAAWC,SAAS,EAAE;YACxB,MAAMC,gBAAgBN,YAAYO,GAAG,CAACH,eAAe,EAAE;YACvDJ,YAAYQ,GAAG,CAACJ,YAAY;mBAAIE;gBAAe;aAAS;Y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AmB,EAAE;YAAK;YACrC0B,MAAMW,iBAAiB,YAAYrC,qBAAqB,CAAC,CAAC,EAAEA,oBAAoB;YAChF2B,OAAO;gBACL,CAAC3B,mBAAmB,EAAE;oBACpB,CAACqC,iBAAiB,YAAY,iBAAiB,YAAY,EAAEc;gBAC/D;YACF;QACF;QACA,MAAMI,iBAAiBD,YAAYxB,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC9B,mBAAmB,IAAI;QAEtE,6EAA6E;QAC7E,uEAAuE;QACvE,MAAMwD,cACJnB,iBAAiB,YACbzE,qBAAqBuF,WAAWI,gBAAgBnB,WAAWG,MAAM,IACjE3E,qBAAqB2F,gBAAgBJ,WAAWf,WAAWG,MAAM;QAEvE,gDAAgD;QAChD,KAAK,MAAM,CAAC9B,OAAOqC,GAAG,IAAIV,WAAW1C,OAAO,GAAI;YAC9C,MAAMyB,IAAIE,OAAO,CAAC4B,MAAM,CAAC;gBACvBH;gBACA3E,YAAYA,WAAWoB,IAAI;gBAC3B0B,MAAM;oBACJ,CAACjB,mBAAmB,EAAEwD,WAAW,CAAC/C,MAAM;gBAC1C;gBACAa,OAAO;gBACPH;gBACAM,QAAQ;oBAAEqB,IAAI;gBAAK;YACrB;QACF;QAEA,OAAO,IAAIN,SAASC,KAAKC,SAAS,CAAC;YAAEc;YAAaC,SAAS;QAAK,IAAI;YAClEb,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,QAAQ;QACV;IACF;IAEA,MAAMa,kBAA4B;QAChCC,SAAS3B;QACT4B,QAAQ;QACRC,MAAM;IACR;IAEA,IAAI,CAAC/F,OAAOgG,SAAS,EAAE;QACrBhG,OAAOgG,SAAS,GAAG,EAAE;IACvB;IACAhG,OAAOgG,SAAS,CAAC/B,IAAI,CAAC2B;AACxB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/config/orderable/index.ts"],"sourcesContent":["import type { BeforeChangeHook, CollectionConfig } from '../../collections/config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { Endpoint, PayloadHandler, SanitizedConfig } from '../types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { traverseFields } from '../../utilities/traverseFields.js'\nimport { generateKeyBetween, generateNKeysBetween } from './fractional-indexing.js'\n\n/**\n * This function creates:\n * - N fields per collection, named `_order` or `_<collection>_<joinField>_order`\n * - 1 hook per collection\n * - 1 endpoint per app\n *\n * Also, if collection.defaultSort or joinField.defaultSort is not set, it will be set to the orderable field.\n */\nexport const setupOrderable = (config: SanitizedConfig) => {\n const fieldsToAdd = new Map<CollectionConfig, string[]>()\n\n config.collections.forEach((collection) => {\n if (collection.orderable) {\n const currentFields = fieldsToAdd.get(collection) || []\n fieldsToAdd.set(collection, [...currentFields, '_order'])\n collection.defaultSort = collection.defaultSort ?? '_order'\n }\n\n traverseFields({\n callback: ({ field, parentRef, ref }) => {\n if (field.type === 'array' || field.type === 'blocks') {\n return false\n }\n if (field.type === 'group' || field.type === 'tab') {\n // @ts-expect-error ref is untyped\n const parentPrefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n // @ts-expect-error ref is untyped\n ref.prefix = `${parentPrefix}${field.name}`\n }\n if (field.type === 'join' && field.orderable === true) {\n if (Array.isArray(field.collection)) {\n throw new Error('Orderable joins must target a single collection')\n }\n const relationshipCollection = config.collections.find((c) => c.slug === field.collection)\n if (!relationshipCollection) {\n return false\n }\n field.defaultSort = field.defaultSort ?? `_${field.collection}_${field.name}_order`\n const currentFields = fieldsToAdd.get(relationshipCollection) || []\n // @ts-expect-error ref is untyped\n const prefix = parentRef?.prefix ? `${parentRef.prefix}_` : ''\n fieldsToAdd.set(relationshipCollection, [\n ...currentFields,\n `_${field.collection}_${prefix}${field.name}_order`,\n ])\n }\n },\n fields: collection.fields,\n })\n })\n\n Array.from(fieldsToAdd.entries()).forEach(([collection, orderableFields]) => {\n addOrderableFieldsAndHook(collection, orderableFields)\n })\n\n if (fieldsToAdd.size > 0) {\n addOrderableEndpoint(config)\n }\n}\n\nexport const addOrderableFieldsAndHook = (\n collection: CollectionConfig,\n orderableFieldNames: string[],\n) => {\n // 1. Add field\n orderableFieldNames.forEach((orderableFieldName) => {\n const orderField: Field = {\n name: orderableFieldName,\n type: 'text',\n admin: {\n disableBulkEdit: true,\n disabled: true,\n disableListColumn: true,\n disableListFilter: true,\n hidden: true,\n readOnly: true,\n },\n index: true,\n required: true,\n // override the schema to make order fields optional for payload.create()\n typescriptSchema: [\n () => ({\n type: 'string',\n required: false,\n }),\n ],\n unique: true,\n }\n\n collection.fields.unshift(orderField)\n })\n\n // 2. Add hook\n if (!collection.hooks) {\n collection.hooks = {}\n }\n if (!collection.hooks.beforeChange) {\n collection.hooks.beforeChange = []\n }\n\n const orderBeforeChangeHook: BeforeChangeHook = async ({ data, originalDoc, req }) => {\n for (const orderableFieldName of orderableFieldNames) {\n if (!data[orderableFieldName] && !originalDoc?.[orderableFieldName]) {\n const lastDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n select: { [orderableFieldName]: true },\n sort: `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n exists: true,\n },\n },\n })\n\n const lastOrderValue = lastDoc.docs[0]?.[orderableFieldName] || null\n data[orderableFieldName] = generateKeyBetween(lastOrderValue, null)\n }\n }\n\n return data\n }\n\n collection.hooks.beforeChange.push(orderBeforeChangeHook)\n}\n\n/**\n * The body of the reorder endpoint.\n * @internal\n */\nexport type OrderableEndpointBody = {\n collectionSlug: string\n docsToMove: string[]\n newKeyWillBe: 'greater' | 'less'\n orderableFieldName: string\n target: {\n id: string\n key: string\n }\n}\n\nexport const addOrderableEndpoint = (config: SanitizedConfig) => {\n // 3. Add endpoint\n const reorderHandler: PayloadHandler = async (req) => {\n const body = (await req.json?.()) as OrderableEndpointBody\n\n const { collectionSlug, docsToMove, newKeyWillBe, orderableFieldName, target } = body\n\n if (!Array.isArray(docsToMove) || docsToMove.length === 0) {\n return new Response(JSON.stringify({ error: 'docsToMove must be a non-empty array' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (\n typeof target !== 'object' ||\n typeof target.id === 'undefined' ||\n typeof target.key !== 'string'\n ) {\n return new Response(JSON.stringify({ error: 'target must be an object with id and key' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (newKeyWillBe !== 'greater' && newKeyWillBe !== 'less') {\n return new Response(JSON.stringify({ error: 'newKeyWillBe must be \"greater\" or \"less\"' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n const collection = config.collections.find((c) => c.slug === collectionSlug)\n if (!collection) {\n return new Response(JSON.stringify({ error: `Collection ${collectionSlug} not found` }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n if (typeof orderableFieldName !== 'string') {\n return new Response(JSON.stringify({ error: 'orderableFieldName must be a string' }), {\n headers: { 'Content-Type': 'application/json' },\n status: 400,\n })\n }\n\n // Prevent reordering if user doesn't have editing permissions\n if (collection.access?.update) {\n await executeAccess(\n {\n // Currently only one doc can be moved at a time. We should review this if we want to allow\n // multiple docs to be moved at once in the future.\n id: docsToMove[0],\n data: {},\n req,\n },\n collection.access.update,\n )\n }\n\n const targetId = target.id\n let targetKey = target.key\n\n // If targetKey = pending, we need to find its current key.\n // This can only happen if the user reorders rows quickly with a slow connection.\n if (targetKey === 'pending') {\n const beforeDoc = await req.payload.findByID({\n id: targetId,\n collection: collection.slug,\n depth: 0,\n select: { [orderableFieldName]: true },\n })\n targetKey = beforeDoc?.[orderableFieldName] || null\n }\n\n // The reason the endpoint does not receive this docId as an argument is that there\n // are situations where the user may not see or know what the next or previous one is. For\n // example, access control restrictions, if docBefore is the last one on the page, etc.\n const adjacentDoc = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n select: { [orderableFieldName]: true },\n sort: newKeyWillBe === 'greater' ? orderableFieldName : `-${orderableFieldName}`,\n where: {\n [orderableFieldName]: {\n [newKeyWillBe === 'greater' ? 'greater_than' : 'less_than']: targetKey,\n },\n },\n })\n const adjacentDocKey = adjacentDoc.docs?.[0]?.[orderableFieldName] || null\n\n // Currently N (= docsToMove.length) is always 1. Maybe in the future we will\n // allow dragging and reordering multiple documents at once via the UI.\n const orderValues =\n newKeyWillBe === 'greater'\n ? generateNKeysBetween(targetKey, adjacentDocKey, docsToMove.length)\n : generateNKeysBetween(adjacentDocKey, targetKey, docsToMove.length)\n\n // Update each document with its new order value\n for (const [index, id] of docsToMove.entries()) {\n await req.payload.update({\n id,\n collection: collection.slug,\n data: {\n [orderableFieldName]: orderValues[index],\n },\n depth: 0,\n req,\n })\n }\n\n return new Response(JSON.stringify({ orderValues, success: true }), {\n headers: { 'Content-Type': 'application/json' },\n status: 200,\n })\n }\n\n const reorderEndpoint: Endpoint = {\n handler: reorderHandler,\n method: 'post',\n path: '/reorder',\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n config.endpoints.push(reorderEndpoint)\n}\n"],"names":["executeAccess","traverseFields","generateKeyBetween","generateNKeysBetween","setupOrderable","config","fieldsToAdd","Map","collections","forEach","collection","orderable","currentFields","get","set","defaultSort","callback","field","parentRef","ref","type","parentPrefix","prefix","name","Array","isArray","Error","relationshipCollection","find","c","slug","fields","from","entries","orderableFields","addOrderableFieldsAndHook","size","addOrderableEndpoint","orderableFieldNames","orderableFieldName","orderField","admin","disableBulkEdit","disabled","disableListColumn","disableListFilter","hidden","readOnly","index","required","typescriptSchema","unique","unshift","hooks","beforeChange","orderBeforeChangeHook","data","originalDoc","req","lastDoc","payload","depth","limit","pagination","select","sort","where","exists","lastOrderValue","docs","push","reorderHandler","body","json","collectionSlug","docsToMove","newKeyWillBe","target","length","Response","JSON","stringify","error","headers","status","id","key","access","update","targetId","targetKey","beforeDoc","findByID","adjacentDoc","adjacentDocKey","orderValues","success","reorderEndpoint","handler","method","path","endpoints"],"mappings":"AAIA,OAAOA,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,kB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;IACR;IAEA,IAAI,CAAC/F,OAAOgG,SAAS,EAAE;QACrBhG,OAAOgG,SAAS,GAAG,EAAE;IACvB;IACAhG,OAAOgG,SAAS,CAAC/B,IAAI,CAAC2B;AACxB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateQueryPaths.d.ts","sourceRoot":"","sources":["../../../src/database/queryValidation/validateQueryPaths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAY,cAAc,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAA;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC3B,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,aAAa,CAAC,EAAE,cAAc,EAAE,CAAA;IAChC,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,CACA;IACE,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,YAAY,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CACjC,GACD;IACE,gBAAgB,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IACpC,YAAY,EAAE,qBAAqB,CAAA;CACpC,CACJ,CAAA;
|
|
1
|
+
{"version":3,"file":"validateQueryPaths.d.ts","sourceRoot":"","sources":["../../../src/database/queryValidation/validateQueryPaths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAY,cAAc,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAA;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC3B,cAAc,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,aAAa,CAAC,EAAE,cAAc,EAAE,CAAA;IAChC,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,CACA;IACE,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,YAAY,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CACjC,GACD;IACE,gBAAgB,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IACpC,YAAY,EAAE,qBAAqB,CAAA;CACpC,CACJ,CAAA;AAED,wBAAsB,kBAAkB,CAAC,EACvC,gBAAgB,EAChB,MAAW,EACX,YAAY,EACZ,cAAc,EACd,QAGC,EACD,eAAe,EACf,GAAG,EACH,aAAa,EACb,KAAK,GACN,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAoEtB"}
|