payload 1.11.6 → 1.11.8
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/components/forms/Form/fieldReducer.js +0 -4
- package/dist/admin/components/forms/Form/fieldReducer.js.map +1 -1
- package/dist/admin/components/forms/field-types/Array/index.js +4 -6
- package/dist/admin/components/forms/field-types/Array/index.js.map +1 -1
- package/dist/admin/components/forms/field-types/Blocks/index.js +2 -4
- package/dist/admin/components/forms/field-types/Blocks/index.js.map +1 -1
- package/dist/admin/components/forms/useField/index.js +1 -3
- package/dist/admin/components/forms/useField/index.js.map +1 -1
- package/dist/auth/operations/forgotPassword.js +2 -1
- package/dist/auth/operations/forgotPassword.js.map +1 -1
- package/dist/auth/operations/local/forgotPassword.js +2 -0
- package/dist/auth/operations/local/forgotPassword.js.map +1 -1
- package/dist/auth/operations/local/login.js +2 -0
- package/dist/auth/operations/local/login.js.map +1 -1
- package/dist/auth/operations/local/resetPassword.js +2 -0
- package/dist/auth/operations/local/resetPassword.js.map +1 -1
- package/dist/auth/operations/local/unlock.js +2 -0
- package/dist/auth/operations/local/unlock.js.map +1 -1
- package/dist/auth/operations/login.js +5 -0
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/logout.js +1 -0
- package/dist/auth/operations/logout.js.map +1 -1
- package/dist/auth/operations/me.js +1 -0
- package/dist/auth/operations/me.js.map +1 -1
- package/dist/auth/operations/refresh.js +2 -0
- package/dist/auth/operations/refresh.js.map +1 -1
- package/dist/collections/config/types.d.ts +17 -3
- package/dist/collections/graphql/init.js +2 -0
- package/dist/collections/graphql/init.js.map +1 -1
- package/dist/collections/operations/create.js +9 -0
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/delete.js +5 -0
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/deleteByID.js +5 -1
- package/dist/collections/operations/deleteByID.js.map +1 -1
- package/dist/collections/operations/find.js +4 -2
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/findByID.js +4 -0
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/findVersionByID.js +3 -0
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/findVersions.js +3 -2
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/collections/operations/local/create.d.ts +5 -1
- package/dist/collections/operations/local/create.js +3 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/delete.d.ts +6 -0
- package/dist/collections/operations/local/delete.js +3 -1
- package/dist/collections/operations/local/delete.js.map +1 -1
- package/dist/collections/operations/local/find.d.ts +5 -1
- package/dist/collections/operations/local/find.js +3 -1
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +5 -1
- package/dist/collections/operations/local/findByID.js +3 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/collections/operations/local/findVersionByID.d.ts +6 -1
- package/dist/collections/operations/local/findVersionByID.js +3 -1
- package/dist/collections/operations/local/findVersionByID.js.map +1 -1
- package/dist/collections/operations/local/findVersions.d.ts +6 -0
- package/dist/collections/operations/local/findVersions.js +3 -1
- package/dist/collections/operations/local/findVersions.js.map +1 -1
- package/dist/collections/operations/local/restoreVersion.d.ts +6 -0
- package/dist/collections/operations/local/restoreVersion.js +3 -1
- package/dist/collections/operations/local/restoreVersion.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +5 -0
- package/dist/collections/operations/local/update.js +3 -1
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/restoreVersion.js +4 -0
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/update.js +10 -0
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.js +10 -0
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/database/combineQueries.d.ts +2 -0
- package/dist/database/combineQueries.js +18 -0
- package/dist/database/combineQueries.js.map +1 -0
- package/dist/database/createAdapter.d.ts +3 -0
- package/dist/database/createAdapter.js +32 -0
- package/dist/database/createAdapter.js.map +1 -0
- package/dist/database/flattenWhereToOperators.d.ts +3 -0
- package/dist/database/flattenWhereToOperators.js +22 -0
- package/dist/database/flattenWhereToOperators.js.map +1 -0
- package/dist/database/getLocalizedPaths.d.ts +12 -0
- package/dist/database/getLocalizedPaths.js +122 -0
- package/dist/database/getLocalizedPaths.js.map +1 -0
- package/dist/database/migrations/createMigration.d.ts +2 -0
- package/dist/database/migrations/createMigration.js +26 -0
- package/dist/database/migrations/createMigration.js.map +1 -0
- package/dist/database/migrations/getMigrations.d.ts +8 -0
- package/dist/database/migrations/getMigrations.js +19 -0
- package/dist/database/migrations/getMigrations.js.map +1 -0
- package/dist/database/migrations/migrate.d.ts +2 -0
- package/dist/database/migrations/migrate.js +45 -0
- package/dist/database/migrations/migrate.js.map +1 -0
- package/dist/database/migrations/migrateDown.d.ts +2 -0
- package/dist/database/migrations/migrateDown.js +50 -0
- package/dist/database/migrations/migrateDown.js.map +1 -0
- package/dist/database/migrations/migrateRefresh.d.ts +5 -0
- package/dist/database/migrations/migrateRefresh.js +48 -0
- package/dist/database/migrations/migrateRefresh.js.map +1 -0
- package/dist/database/migrations/migrateReset.d.ts +2 -0
- package/dist/database/migrations/migrateReset.js +46 -0
- package/dist/database/migrations/migrateReset.js.map +1 -0
- package/dist/database/migrations/migrateStatus.d.ts +2 -0
- package/dist/database/migrations/migrateStatus.js +33 -0
- package/dist/database/migrations/migrateStatus.js.map +1 -0
- package/dist/database/migrations/migrationTemplate.d.ts +1 -0
- package/dist/database/migrations/migrationTemplate.js +15 -0
- package/dist/database/migrations/migrationTemplate.js.map +1 -0
- package/dist/database/migrations/migrationsCollection.d.ts +2 -0
- package/dist/database/migrations/migrationsCollection.js +41 -0
- package/dist/database/migrations/migrationsCollection.js.map +1 -0
- package/dist/database/migrations/readMigrationFiles.d.ts +8 -0
- package/dist/database/migrations/readMigrationFiles.js +30 -0
- package/dist/database/migrations/readMigrationFiles.js.map +1 -0
- package/dist/database/queryValidation/types.d.ts +20 -0
- package/dist/database/queryValidation/types.js +5 -0
- package/dist/database/queryValidation/types.js.map +1 -0
- package/dist/database/queryValidation/validateQueryPaths.d.ts +23 -0
- package/dist/database/queryValidation/validateQueryPaths.js +62 -0
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -0
- package/dist/database/queryValidation/validateSearchParams.d.ts +25 -0
- package/dist/database/queryValidation/validateSearchParams.js +133 -0
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -0
- package/dist/database/transaction.d.ts +2 -0
- package/dist/database/transaction.js +15 -0
- package/dist/database/transaction.js.map +1 -0
- package/dist/database/types.d.ts +279 -0
- package/dist/database/types.js +3 -0
- package/dist/database/types.js.map +1 -0
- package/dist/express/middleware/defaultPayload.d.ts +4 -0
- package/dist/express/middleware/defaultPayload.js +9 -0
- package/dist/express/middleware/defaultPayload.js.map +1 -0
- package/dist/express/middleware/errorHandler.js +2 -2
- package/dist/express/middleware/errorHandler.js.map +1 -1
- package/dist/express/middleware/index.js +2 -0
- package/dist/express/middleware/index.js.map +1 -1
- package/dist/express/setRequestContext.d.ts +6 -0
- package/dist/express/setRequestContext.js +22 -0
- package/dist/express/setRequestContext.js.map +1 -0
- package/dist/express/types.d.ts +14 -1
- package/dist/fields/config/types.d.ts +2 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterChange/index.d.ts +3 -2
- package/dist/fields/hooks/afterChange/index.js +2 -1
- package/dist/fields/hooks/afterChange/index.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.d.ts +3 -2
- package/dist/fields/hooks/afterChange/promise.js +8 -1
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts +3 -2
- package/dist/fields/hooks/afterChange/traverseFields.js +2 -1
- package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +2 -1
- package/dist/fields/hooks/afterRead/index.js +2 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +3 -2
- package/dist/fields/hooks/afterRead/promise.js +11 -1
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +3 -2
- package/dist/fields/hooks/afterRead/traverseFields.js +2 -1
- package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts +3 -2
- package/dist/fields/hooks/beforeChange/index.js +2 -1
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts +3 -2
- package/dist/fields/hooks/beforeChange/promise.js +8 -1
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +3 -2
- package/dist/fields/hooks/beforeChange/traverseFields.js +2 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.d.ts +3 -2
- package/dist/fields/hooks/beforeValidate/index.js +2 -1
- package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts +3 -2
- package/dist/fields/hooks/beforeValidate/promise.js +8 -1
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +3 -2
- package/dist/fields/hooks/beforeValidate/traverseFields.js +2 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
- package/dist/globals/operations/findOne.js +1 -0
- package/dist/globals/operations/findOne.js.map +1 -1
- package/dist/globals/operations/findVersionByID.js +1 -0
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/dist/globals/operations/findVersions.js +1 -0
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/globals/operations/local/findOne.js +2 -0
- package/dist/globals/operations/local/findOne.js.map +1 -1
- package/dist/globals/operations/local/findVersionByID.js +2 -0
- package/dist/globals/operations/local/findVersionByID.js.map +1 -1
- package/dist/globals/operations/local/findVersions.js +2 -0
- package/dist/globals/operations/local/findVersions.js.map +1 -1
- package/dist/globals/operations/local/restoreVersion.js +2 -0
- package/dist/globals/operations/local/restoreVersion.js.map +1 -1
- package/dist/globals/operations/local/update.js +2 -0
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/globals/operations/restoreVersion.js +2 -0
- package/dist/globals/operations/restoreVersion.js.map +1 -1
- package/dist/globals/operations/update.js +5 -0
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/graphql/errorHandler.js +1 -1
- package/dist/graphql/errorHandler.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js.map +1 -1
- package/dist/payload.d.ts +2 -0
- package/dist/payload.js.map +1 -1
- package/dist/uploads/generateFileData.js +2 -2
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/imageResizer.js +1 -1
- package/dist/uploads/imageResizer.js.map +1 -1
- package/docs/hooks/context.mdx +127 -0
- package/docs/local-api/overview.mdx +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readMigrationFiles = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Read the migration files from disk
|
|
11
|
+
*/
|
|
12
|
+
const readMigrationFiles = async ({ payload, }) => {
|
|
13
|
+
if (!fs_1.default.existsSync(payload.db.migrationDir))
|
|
14
|
+
return [];
|
|
15
|
+
const files = fs_1.default
|
|
16
|
+
.readdirSync(payload.db.migrationDir)
|
|
17
|
+
.sort()
|
|
18
|
+
.map((file) => {
|
|
19
|
+
return path_1.default.resolve(payload.db.migrationDir, file);
|
|
20
|
+
});
|
|
21
|
+
return files.map((filePath) => {
|
|
22
|
+
var _a;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-dynamic-require
|
|
24
|
+
const migration = require(filePath);
|
|
25
|
+
migration.name = (_a = path_1.default.basename(filePath).split('.')) === null || _a === void 0 ? void 0 : _a[0];
|
|
26
|
+
return migration;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
exports.readMigrationFiles = readMigrationFiles;
|
|
30
|
+
//# sourceMappingURL=readMigrationFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readMigrationFiles.js","sourceRoot":"","sources":["../../../src/database/migrations/readMigrationFiles.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB;;GAEG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,OAAO,GAGR,EAAwB,EAAE;IACzB,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC;QAAE,OAAO,EAAE,CAAC;IAEvD,MAAM,KAAK,GAAG,YAAE;SACb,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC;SACpC,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,OAAO,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACL,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;;QAC5B,wFAAwF;QACxF,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAc,CAAC;QACjD,SAAS,CAAC,IAAI,GAAG,MAAA,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,0CAAG,CAAC,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAnBW,QAAA,kBAAkB,sBAmB7B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CollectionPermission, GlobalPermission } from '../../auth';
|
|
2
|
+
import { Field, FieldAffectingData, TabAsField, UIField } from '../../fields/config/types';
|
|
3
|
+
export declare const validOperators: string[];
|
|
4
|
+
export type EntityPolicies = {
|
|
5
|
+
collections?: {
|
|
6
|
+
[collectionSlug: string]: CollectionPermission;
|
|
7
|
+
};
|
|
8
|
+
globals?: {
|
|
9
|
+
[globalSlug: string]: GlobalPermission;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type PathToQuery = {
|
|
13
|
+
complete: boolean;
|
|
14
|
+
collectionSlug?: string;
|
|
15
|
+
globalSlug?: string;
|
|
16
|
+
path: string;
|
|
17
|
+
field: Field | TabAsField;
|
|
18
|
+
fields?: (FieldAffectingData | UIField | TabAsField)[];
|
|
19
|
+
invalid?: boolean;
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validOperators = void 0;
|
|
4
|
+
exports.validOperators = ['like', 'contains', 'in', 'all', 'not_in', 'greater_than_equal', 'greater_than', 'less_than_equal', 'less_than', 'not_equals', 'equals', 'exists', 'near'];
|
|
5
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/database/queryValidation/types.ts"],"names":[],"mappings":";;;AAGa,QAAA,cAAc,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PayloadRequest, Where } from '../../types';
|
|
2
|
+
import { SanitizedCollectionConfig } from '../../collections/config/types';
|
|
3
|
+
import { SanitizedGlobalConfig } from '../../globals/config/types';
|
|
4
|
+
import { Field } from '../../fields/config/types';
|
|
5
|
+
import { EntityPolicies } from './types';
|
|
6
|
+
type Args = {
|
|
7
|
+
where: Where;
|
|
8
|
+
errors?: {
|
|
9
|
+
path: string;
|
|
10
|
+
}[];
|
|
11
|
+
policies?: EntityPolicies;
|
|
12
|
+
req: PayloadRequest;
|
|
13
|
+
versionFields?: Field[];
|
|
14
|
+
overrideAccess: boolean;
|
|
15
|
+
} & ({
|
|
16
|
+
collectionConfig: SanitizedCollectionConfig;
|
|
17
|
+
globalConfig?: never | undefined;
|
|
18
|
+
} | {
|
|
19
|
+
globalConfig: SanitizedGlobalConfig;
|
|
20
|
+
collectionConfig?: never | undefined;
|
|
21
|
+
});
|
|
22
|
+
export declare function validateQueryPaths({ where, collectionConfig, globalConfig, errors, policies, versionFields, req, overrideAccess, }: Args): Promise<void>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateQueryPaths = void 0;
|
|
7
|
+
const QueryError_1 = __importDefault(require("../../errors/QueryError"));
|
|
8
|
+
const flattenTopLevelFields_1 = __importDefault(require("../../utilities/flattenTopLevelFields"));
|
|
9
|
+
const validateSearchParams_1 = require("./validateSearchParams");
|
|
10
|
+
const deepCopyObject_1 = __importDefault(require("../../utilities/deepCopyObject"));
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const flattenWhere = (query) => Object.entries(query).reduce((flattenedConstraints, [key, val]) => {
|
|
13
|
+
if ((key === 'and' || key === 'or') && Array.isArray(val)) {
|
|
14
|
+
return [
|
|
15
|
+
...flattenedConstraints,
|
|
16
|
+
...val.map((subVal) => flattenWhere(subVal)),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
...flattenedConstraints,
|
|
21
|
+
{ [key]: val },
|
|
22
|
+
];
|
|
23
|
+
}, []);
|
|
24
|
+
async function validateQueryPaths({ where, collectionConfig, globalConfig, errors = [], policies = {
|
|
25
|
+
collections: {},
|
|
26
|
+
globals: {},
|
|
27
|
+
}, versionFields, req, overrideAccess, }) {
|
|
28
|
+
const fields = (0, flattenTopLevelFields_1.default)(versionFields || (globalConfig || collectionConfig).fields);
|
|
29
|
+
if (typeof where === 'object') {
|
|
30
|
+
// const flattenedWhere = flattenWhere(where);
|
|
31
|
+
const whereFields = flattenWhere(where);
|
|
32
|
+
// We need to determine if the whereKey is an AND, OR, or a schema path
|
|
33
|
+
const promises = [];
|
|
34
|
+
whereFields.map(async (constraint) => {
|
|
35
|
+
Object.keys(constraint).map(async (path) => {
|
|
36
|
+
Object.entries(constraint[path]).map(async ([operator, val]) => {
|
|
37
|
+
if (types_1.validOperators.includes(operator)) {
|
|
38
|
+
promises.push((0, validateSearchParams_1.validateSearchParam)({
|
|
39
|
+
collectionConfig: (0, deepCopyObject_1.default)(collectionConfig),
|
|
40
|
+
globalConfig: (0, deepCopyObject_1.default)(globalConfig),
|
|
41
|
+
fields: fields,
|
|
42
|
+
versionFields,
|
|
43
|
+
errors,
|
|
44
|
+
policies,
|
|
45
|
+
req,
|
|
46
|
+
path,
|
|
47
|
+
val,
|
|
48
|
+
operator,
|
|
49
|
+
overrideAccess,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
await Promise.all(promises);
|
|
56
|
+
if (errors.length > 0) {
|
|
57
|
+
throw new QueryError_1.default(errors);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.validateQueryPaths = validateQueryPaths;
|
|
62
|
+
//# sourceMappingURL=validateQueryPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateQueryPaths.js","sourceRoot":"","sources":["../../../src/database/queryValidation/validateQueryPaths.ts"],"names":[],"mappings":";;;;;;AAGA,yEAAiD;AAGjD,kGAAkE;AAElE,iEAA6D;AAC7D,oFAA4D;AAC5D,mCAAyD;AAEzD,MAAM,YAAY,GAAG,CAAC,KAAY,EAAgB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;IACrH,IAAI,CAAC,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACzD,OAAO;YACL,GAAG,oBAAoB;YACvB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;SAC7C,CAAC;KACH;IAED,OAAO;QACL,GAAG,oBAAoB;QACvB,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE;KACf,CAAC;AACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AAgBA,KAAK,UAAU,kBAAkB,CAAC,EACvC,KAAK,EACL,gBAAgB,EAChB,YAAY,EACZ,MAAM,GAAG,EAAE,EACX,QAAQ,GAAG;IACT,WAAW,EAAE,EAAE;IACf,OAAO,EAAE,EAAE;CACZ,EACD,aAAa,EACb,GAAG,EACH,cAAc,GACT;IACL,MAAM,MAAM,GAAG,IAAA,+BAAa,EAAC,aAAa,IAAI,CAAC,YAAY,IAAI,gBAAgB,CAAC,CAAC,MAAM,CAAyB,CAAC;IACjH,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,8CAA8C;QAC9C,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QACxC,uEAAuE;QACvE,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YACnC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACzC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,EAAE;oBAC7D,IAAI,sBAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;wBACrC,QAAQ,CAAC,IAAI,CAAC,IAAA,0CAAmB,EAAC;4BAChC,gBAAgB,EAAE,IAAA,wBAAc,EAAC,gBAAgB,CAAC;4BAClD,YAAY,EAAE,IAAA,wBAAc,EAAC,YAAY,CAAC;4BAC1C,MAAM,EAAG,MAAkB;4BAC3B,aAAa;4BACb,MAAM;4BACN,QAAQ;4BACR,GAAG;4BACH,IAAI;4BACJ,GAAG;4BACH,QAAQ;4BACR,cAAc;yBACf,CAAC,CAAC,CAAC;qBACL;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACrB,MAAM,IAAI,oBAAU,CAAC,MAAM,CAAC,CAAC;SAC9B;KACF;AACH,CAAC;AA7CD,gDA6CC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Field } from '../../fields/config/types';
|
|
2
|
+
import { PayloadRequest } from '../../express/types';
|
|
3
|
+
import { SanitizedCollectionConfig } from '../../collections/config/types';
|
|
4
|
+
import { SanitizedGlobalConfig } from '../../globals/config/types';
|
|
5
|
+
import { EntityPolicies } from './types';
|
|
6
|
+
type Args = {
|
|
7
|
+
fields: Field[];
|
|
8
|
+
path: string;
|
|
9
|
+
val: unknown;
|
|
10
|
+
operator: string;
|
|
11
|
+
req: PayloadRequest;
|
|
12
|
+
errors: {
|
|
13
|
+
path: string;
|
|
14
|
+
}[];
|
|
15
|
+
policies: EntityPolicies;
|
|
16
|
+
collectionConfig?: SanitizedCollectionConfig;
|
|
17
|
+
globalConfig?: SanitizedGlobalConfig;
|
|
18
|
+
versionFields?: Field[];
|
|
19
|
+
overrideAccess: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Validate the Payload key / value / operator
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateSearchParam({ fields, path: incomingPath, versionFields, val, operator, collectionConfig, globalConfig, errors, req, policies, overrideAccess, }: Args): Promise<void>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSearchParam = void 0;
|
|
4
|
+
const types_1 = require("../../fields/config/types");
|
|
5
|
+
const getEntityPolicies_1 = require("../../utilities/getEntityPolicies");
|
|
6
|
+
const validateQueryPaths_1 = require("./validateQueryPaths");
|
|
7
|
+
const getLocalizedPaths_1 = require("../getLocalizedPaths");
|
|
8
|
+
/**
|
|
9
|
+
* Validate the Payload key / value / operator
|
|
10
|
+
*/
|
|
11
|
+
async function validateSearchParam({ fields, path: incomingPath, versionFields, val, operator, collectionConfig, globalConfig, errors, req, policies, overrideAccess, }) {
|
|
12
|
+
// Replace GraphQL nested field double underscore formatting
|
|
13
|
+
let sanitizedPath;
|
|
14
|
+
if (incomingPath === '_id') {
|
|
15
|
+
sanitizedPath = 'id';
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
sanitizedPath = incomingPath.replace(/__/gi, '.');
|
|
19
|
+
}
|
|
20
|
+
let paths = [];
|
|
21
|
+
const { slug } = (collectionConfig || globalConfig);
|
|
22
|
+
if (globalConfig && !policies.globals[slug]) {
|
|
23
|
+
// eslint-disable-next-line no-param-reassign
|
|
24
|
+
globalConfig.fields = fields;
|
|
25
|
+
// eslint-disable-next-line no-param-reassign
|
|
26
|
+
policies.globals[slug] = await (0, getEntityPolicies_1.getEntityPolicies)({
|
|
27
|
+
req,
|
|
28
|
+
entity: globalConfig,
|
|
29
|
+
operations: ['read'],
|
|
30
|
+
type: 'global',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (sanitizedPath !== 'id') {
|
|
34
|
+
paths = await (0, getLocalizedPaths_1.getLocalizedPaths)({
|
|
35
|
+
payload: req.payload,
|
|
36
|
+
locale: req.locale,
|
|
37
|
+
collectionSlug: collectionConfig === null || collectionConfig === void 0 ? void 0 : collectionConfig.slug,
|
|
38
|
+
globalSlug: globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.slug,
|
|
39
|
+
fields,
|
|
40
|
+
incomingPath: sanitizedPath,
|
|
41
|
+
overrideAccess,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const promises = [];
|
|
45
|
+
promises.push(...paths.map(async ({ path, field, invalid, collectionSlug }, i) => {
|
|
46
|
+
var _a;
|
|
47
|
+
if (invalid) {
|
|
48
|
+
errors.push({ path });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!overrideAccess && (0, types_1.fieldAffectsData)(field)) {
|
|
52
|
+
if (collectionSlug) {
|
|
53
|
+
if (!policies.collections[collectionSlug]) {
|
|
54
|
+
// eslint-disable-next-line no-param-reassign
|
|
55
|
+
policies.collections[collectionSlug] = await (0, getEntityPolicies_1.getEntityPolicies)({
|
|
56
|
+
req,
|
|
57
|
+
entity: req.payload.collections[collectionSlug].config,
|
|
58
|
+
operations: ['read'],
|
|
59
|
+
type: 'collection',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (['salt', 'hash'].includes(incomingPath) && collectionConfig.auth && !((_a = collectionConfig.auth) === null || _a === void 0 ? void 0 : _a.disableLocalStrategy)) {
|
|
63
|
+
errors.push({ path: incomingPath });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let fieldAccess;
|
|
67
|
+
let fieldPath = path;
|
|
68
|
+
// remove locale from end of path
|
|
69
|
+
if (path.endsWith(req.locale)) {
|
|
70
|
+
fieldPath = path.slice(0, -(req.locale.length + 1));
|
|
71
|
+
}
|
|
72
|
+
// remove ".value" from ends of polymorphic relationship paths
|
|
73
|
+
if (field.type === 'relationship' && Array.isArray(field.relationTo)) {
|
|
74
|
+
fieldPath = fieldPath.replace('.value', '');
|
|
75
|
+
}
|
|
76
|
+
const entityType = globalConfig ? 'globals' : 'collections';
|
|
77
|
+
const entitySlug = collectionSlug || globalConfig.slug;
|
|
78
|
+
const segments = fieldPath.split('.');
|
|
79
|
+
if (versionFields) {
|
|
80
|
+
if (fieldPath === 'parent' || fieldPath === 'version') {
|
|
81
|
+
fieldAccess = policies[entityType][entitySlug].read.permission;
|
|
82
|
+
}
|
|
83
|
+
else if (segments[0] === 'parent' || segments[0] === 'version') {
|
|
84
|
+
fieldAccess = policies[entityType][entitySlug].read.permission;
|
|
85
|
+
segments.shift();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
fieldAccess = policies[entityType][entitySlug].fields;
|
|
90
|
+
segments.forEach((segment, pathIndex) => {
|
|
91
|
+
if (pathIndex === segments.length - 1) {
|
|
92
|
+
fieldAccess = fieldAccess[segment];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
fieldAccess = fieldAccess[segment].fields;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
fieldAccess = fieldAccess.read.permission;
|
|
99
|
+
}
|
|
100
|
+
if (!fieldAccess) {
|
|
101
|
+
errors.push({ path: fieldPath });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (i > 1) {
|
|
105
|
+
// Remove top collection and reverse array
|
|
106
|
+
// to work backwards from top
|
|
107
|
+
const pathsToQuery = paths.slice(1)
|
|
108
|
+
.reverse();
|
|
109
|
+
pathsToQuery.forEach(({ path: subPath, collectionSlug: pathCollectionSlug, }, pathToQueryIndex) => {
|
|
110
|
+
// On the "deepest" collection,
|
|
111
|
+
// validate query of the relationship
|
|
112
|
+
if (pathToQueryIndex === 0) {
|
|
113
|
+
promises.push((0, validateQueryPaths_1.validateQueryPaths)({
|
|
114
|
+
collectionConfig: req.payload.collections[pathCollectionSlug].config,
|
|
115
|
+
globalConfig: undefined,
|
|
116
|
+
where: {
|
|
117
|
+
[subPath]: {
|
|
118
|
+
[operator]: val,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
errors,
|
|
122
|
+
policies,
|
|
123
|
+
req,
|
|
124
|
+
overrideAccess,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
await Promise.all(promises);
|
|
131
|
+
}
|
|
132
|
+
exports.validateSearchParam = validateSearchParam;
|
|
133
|
+
//# sourceMappingURL=validateSearchParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateSearchParams.js","sourceRoot":"","sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"names":[],"mappings":";;;AAAA,qDAAoE;AAEpE,yEAAsE;AAGtE,6DAA0D;AAE1D,4DAAyD;AAgBzD;;GAEG;AACI,KAAK,UAAU,mBAAmB,CAAC,EACxC,MAAM,EACN,IAAI,EAAE,YAAY,EAClB,aAAa,EACb,GAAG,EACH,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,GAAG,EACH,QAAQ,EACR,cAAc,GACT;IACL,4DAA4D;IAC5D,IAAI,aAAa,CAAC;IAClB,IAAI,YAAY,KAAK,KAAK,EAAE;QAC1B,aAAa,GAAG,IAAI,CAAC;KACtB;SAAM;QACL,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE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AAO,EACb,cAAc,EAAE,kBAAkB,GACnC,EAAE,gBAAgB,EAAE,EAAE;gBACrB,+BAA+B;gBAC/B,qCAAqC;gBACrC,IAAI,gBAAgB,KAAK,CAAC,EAAE;oBAC1B,QAAQ,CAAC,IAAI,CAAC,IAAA,uCAAkB,EAAC;wBAC/B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,MAAM;wBACpE,YAAY,EAAE,SAAS;wBACvB,KAAK,EAAE;4BACL,CAAC,OAAO,CAAC,EAAE;gCACT,CAAC,QAAQ,CAAC,EAAE,GAAG;6BAChB;yBACF;wBACD,MAAM;wBACN,QAAQ;wBACR,GAAG;wBACH,cAAc;qBACf,CAAC,CAAC,CAAC;iBACL;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC,CAAC;IACJ,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AA1ID,kDA0IC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transaction = void 0;
|
|
4
|
+
const transaction = async function transaction(callback, options) {
|
|
5
|
+
const id = await this.beginTransaction(options);
|
|
6
|
+
try {
|
|
7
|
+
await callback();
|
|
8
|
+
await this.commitTransaction(id);
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
await this.rollbackTransaction(id);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
exports.transaction = transaction;
|
|
15
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/database/transaction.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAgB,KAAK,UAAU,WAAW,CAChE,QAAgC,EAChC,OAAO;IAEP,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,IAAI;QACF,MAAM,QAAQ,EAAE,CAAC;QACjB,MAAM,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;KAClC;IAAC,OAAO,GAAY,EAAE;QACrB,MAAM,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC;KACpC;AACH,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
2
|
+
import type { TypeWithID } from '../collections/config/types';
|
|
3
|
+
import type { TypeWithID as GlobalsTypeWithID } from '../globals/config/types';
|
|
4
|
+
import type { Payload } from '../payload';
|
|
5
|
+
import type { Document, PayloadRequest, Where } from '../types';
|
|
6
|
+
import type { TypeWithVersion } from '../versions/types';
|
|
7
|
+
export interface DatabaseAdapter {
|
|
8
|
+
/**
|
|
9
|
+
* reference to the instance of payload
|
|
10
|
+
*/
|
|
11
|
+
payload: Payload;
|
|
12
|
+
/**
|
|
13
|
+
* Open the connection to the database
|
|
14
|
+
*/
|
|
15
|
+
connect?: Connect;
|
|
16
|
+
/**
|
|
17
|
+
* Perform startup tasks required to interact with the database such as building Schema and models
|
|
18
|
+
*/
|
|
19
|
+
init?: Init;
|
|
20
|
+
/**
|
|
21
|
+
* Terminate the connection with the database
|
|
22
|
+
*/
|
|
23
|
+
destroy?: Destroy;
|
|
24
|
+
/**
|
|
25
|
+
* Used to alias server only modules or make other changes to webpack configuration
|
|
26
|
+
*/
|
|
27
|
+
webpack?: Webpack;
|
|
28
|
+
/**
|
|
29
|
+
* Path to read and write migration files from
|
|
30
|
+
*/
|
|
31
|
+
migrationDir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Output a migration file
|
|
34
|
+
*/
|
|
35
|
+
createMigration: (CreateMigrationArgs: any) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Run any migration up functions that have not yet been performed and update the status
|
|
38
|
+
*/
|
|
39
|
+
migrate: () => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Read the current state of migrations and output the result to show which have been run
|
|
42
|
+
*/
|
|
43
|
+
migrateStatus: () => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Run any migration down functions that have been performed
|
|
46
|
+
*/
|
|
47
|
+
migrateDown: () => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Run all migration down functions before running up
|
|
50
|
+
*/
|
|
51
|
+
migrateRefresh: () => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Run all migrate down functions
|
|
54
|
+
*/
|
|
55
|
+
migrateReset: () => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Drop the current database and run all migrate up functions
|
|
58
|
+
*/
|
|
59
|
+
migrateFresh: () => Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* assign the transaction to use when making queries, defaults to the last started transaction
|
|
62
|
+
*/
|
|
63
|
+
useTransaction?: (id: string | number) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Perform many database interactions in a single, all-or-nothing operation.
|
|
66
|
+
*/
|
|
67
|
+
transaction?: Transaction;
|
|
68
|
+
/**
|
|
69
|
+
* Start a transaction, requiring commitTransaction() to be called for any changes to be made.
|
|
70
|
+
* @returns an identifier for the transaction or null if one cannot be established
|
|
71
|
+
*/
|
|
72
|
+
beginTransaction?: BeginTransaction;
|
|
73
|
+
/**
|
|
74
|
+
* Abort any changes since the start of the transaction.
|
|
75
|
+
*/
|
|
76
|
+
rollbackTransaction?: RollbackTransaction;
|
|
77
|
+
/**
|
|
78
|
+
* Persist the changes made since the start of the transaction.
|
|
79
|
+
*/
|
|
80
|
+
commitTransaction?: CommitTransaction;
|
|
81
|
+
queryDrafts: QueryDrafts;
|
|
82
|
+
find: <T = TypeWithID>(args: FindArgs) => Promise<PaginatedDocs<T>>;
|
|
83
|
+
findOne: FindOne;
|
|
84
|
+
create: Create;
|
|
85
|
+
updateOne: UpdateOne;
|
|
86
|
+
deleteOne: DeleteOne;
|
|
87
|
+
deleteMany: DeleteMany;
|
|
88
|
+
findGlobal: FindGlobal;
|
|
89
|
+
createGlobal: CreateGlobal;
|
|
90
|
+
updateGlobal: UpdateGlobal;
|
|
91
|
+
findVersions: FindVersions;
|
|
92
|
+
findGlobalVersions: FindGlobalVersions;
|
|
93
|
+
createVersion: CreateVersion;
|
|
94
|
+
updateVersion: UpdateVersion;
|
|
95
|
+
deleteVersions: DeleteVersions;
|
|
96
|
+
}
|
|
97
|
+
export type Init = (payload: Payload) => Promise<void>;
|
|
98
|
+
export type Connect = (payload: Payload) => Promise<void>;
|
|
99
|
+
export type Destroy = (payload: Payload) => Promise<void>;
|
|
100
|
+
export type Webpack = (config: Configuration) => Configuration;
|
|
101
|
+
export type CreateMigrationArgs = {
|
|
102
|
+
payload: Payload;
|
|
103
|
+
migrationDir: string;
|
|
104
|
+
migrationName: string;
|
|
105
|
+
};
|
|
106
|
+
export type CreateMigration = (args: CreateMigrationArgs) => Promise<void>;
|
|
107
|
+
export type Transaction = (callback: () => Promise<void>, options?: Record<string, unknown>) => Promise<void>;
|
|
108
|
+
export type BeginTransaction = (options?: Record<string, unknown>) => Promise<number | string | null>;
|
|
109
|
+
export type RollbackTransaction = (id: string | number) => Promise<void>;
|
|
110
|
+
export type CommitTransaction = (id: string | number) => Promise<void>;
|
|
111
|
+
export type QueryDraftsArgs = {
|
|
112
|
+
collection: string;
|
|
113
|
+
where?: Where;
|
|
114
|
+
page?: number;
|
|
115
|
+
limit?: number;
|
|
116
|
+
pagination?: boolean;
|
|
117
|
+
sort?: string;
|
|
118
|
+
locale?: string;
|
|
119
|
+
req?: PayloadRequest;
|
|
120
|
+
};
|
|
121
|
+
export type QueryDrafts = <T = TypeWithID>(args: QueryDraftsArgs) => Promise<PaginatedDocs<T>>;
|
|
122
|
+
export type FindOneArgs = {
|
|
123
|
+
collection: string;
|
|
124
|
+
where?: Where;
|
|
125
|
+
locale?: string;
|
|
126
|
+
req?: PayloadRequest;
|
|
127
|
+
};
|
|
128
|
+
export type FindOne = <T = TypeWithID>(args: FindOneArgs) => Promise<T | null>;
|
|
129
|
+
export type FindArgs = {
|
|
130
|
+
collection: string;
|
|
131
|
+
where?: Where;
|
|
132
|
+
page?: number;
|
|
133
|
+
skip?: number;
|
|
134
|
+
versions?: boolean;
|
|
135
|
+
/** Setting limit to 1 is equal to the previous Model.findOne(). Setting limit to 0 disables the limit */
|
|
136
|
+
limit?: number;
|
|
137
|
+
pagination?: boolean;
|
|
138
|
+
sort?: string;
|
|
139
|
+
locale?: string;
|
|
140
|
+
req?: PayloadRequest;
|
|
141
|
+
};
|
|
142
|
+
export type Find = <T = TypeWithID>(args: FindArgs) => Promise<PaginatedDocs<T>>;
|
|
143
|
+
export type FindVersionsArgs = {
|
|
144
|
+
collection: string;
|
|
145
|
+
where?: Where;
|
|
146
|
+
page?: number;
|
|
147
|
+
skip?: number;
|
|
148
|
+
versions?: boolean;
|
|
149
|
+
limit?: number;
|
|
150
|
+
pagination?: boolean;
|
|
151
|
+
sort?: string;
|
|
152
|
+
locale?: string;
|
|
153
|
+
req?: PayloadRequest;
|
|
154
|
+
};
|
|
155
|
+
export type FindVersions = <T = TypeWithID>(args: FindVersionsArgs) => Promise<PaginatedDocs<TypeWithVersion<T>>>;
|
|
156
|
+
export type FindGlobalVersionsArgs = {
|
|
157
|
+
global: string;
|
|
158
|
+
where?: Where;
|
|
159
|
+
page?: number;
|
|
160
|
+
skip?: number;
|
|
161
|
+
versions?: boolean;
|
|
162
|
+
limit?: number;
|
|
163
|
+
pagination?: boolean;
|
|
164
|
+
sort?: string;
|
|
165
|
+
locale?: string;
|
|
166
|
+
req?: PayloadRequest;
|
|
167
|
+
};
|
|
168
|
+
export type FindGlobalArgs = {
|
|
169
|
+
slug: string;
|
|
170
|
+
locale?: string;
|
|
171
|
+
where?: Where;
|
|
172
|
+
req?: PayloadRequest;
|
|
173
|
+
};
|
|
174
|
+
export type FindGlobal = <T extends GlobalsTypeWithID = any>(args: FindGlobalArgs) => Promise<T>;
|
|
175
|
+
export type CreateGlobalArgs<T extends GlobalsTypeWithID = any> = {
|
|
176
|
+
slug: string;
|
|
177
|
+
data: T;
|
|
178
|
+
req?: PayloadRequest;
|
|
179
|
+
};
|
|
180
|
+
export type CreateGlobal = <T extends GlobalsTypeWithID = any>(args: CreateGlobalArgs<T>) => Promise<T>;
|
|
181
|
+
export type UpdateGlobalArgs<T extends GlobalsTypeWithID = any> = {
|
|
182
|
+
slug: string;
|
|
183
|
+
data: T;
|
|
184
|
+
req?: PayloadRequest;
|
|
185
|
+
};
|
|
186
|
+
export type UpdateGlobal = <T extends GlobalsTypeWithID = any>(args: UpdateGlobalArgs<T>) => Promise<T>;
|
|
187
|
+
export type FindGlobalVersions = <T = TypeWithID>(args: FindGlobalVersionsArgs) => Promise<PaginatedDocs<TypeWithVersion<T>>>;
|
|
188
|
+
export type DeleteVersionsArgs = {
|
|
189
|
+
collection: string;
|
|
190
|
+
where: Where;
|
|
191
|
+
locale?: string;
|
|
192
|
+
sort?: {
|
|
193
|
+
[key: string]: string;
|
|
194
|
+
};
|
|
195
|
+
req?: PayloadRequest;
|
|
196
|
+
};
|
|
197
|
+
export type CreateVersionArgs<T = TypeWithID> = {
|
|
198
|
+
collectionSlug: string;
|
|
199
|
+
/** ID of the parent document for which the version should be created for */
|
|
200
|
+
parent: string | number;
|
|
201
|
+
versionData: T;
|
|
202
|
+
autosave: boolean;
|
|
203
|
+
createdAt: string;
|
|
204
|
+
updatedAt: string;
|
|
205
|
+
req?: PayloadRequest;
|
|
206
|
+
};
|
|
207
|
+
export type CreateVersion = <T = TypeWithID>(args: CreateVersionArgs<T>) => Promise<TypeWithVersion<T>>;
|
|
208
|
+
export type DeleteVersions = (args: DeleteVersionsArgs) => Promise<void>;
|
|
209
|
+
export type UpdateVersionArgs<T = TypeWithID> = {
|
|
210
|
+
collectionSlug: string;
|
|
211
|
+
where: Where;
|
|
212
|
+
locale?: string;
|
|
213
|
+
versionData: T;
|
|
214
|
+
req?: PayloadRequest;
|
|
215
|
+
};
|
|
216
|
+
export type UpdateVersion = <T = TypeWithID>(args: UpdateVersionArgs<T>) => Promise<TypeWithVersion<T>>;
|
|
217
|
+
export type CreateArgs = {
|
|
218
|
+
collection: string;
|
|
219
|
+
data: Record<string, unknown>;
|
|
220
|
+
draft?: boolean;
|
|
221
|
+
locale?: string;
|
|
222
|
+
req?: PayloadRequest;
|
|
223
|
+
};
|
|
224
|
+
export type Create = (args: CreateArgs) => Promise<Document>;
|
|
225
|
+
export type UpdateArgs = {
|
|
226
|
+
collection: string;
|
|
227
|
+
data: Record<string, unknown>;
|
|
228
|
+
where: Where;
|
|
229
|
+
draft?: boolean;
|
|
230
|
+
locale?: string;
|
|
231
|
+
req?: PayloadRequest;
|
|
232
|
+
};
|
|
233
|
+
export type Update = (args: UpdateArgs) => Promise<Document>;
|
|
234
|
+
export type UpdateOneArgs = {
|
|
235
|
+
collection: string;
|
|
236
|
+
data: Record<string, unknown>;
|
|
237
|
+
where: Where;
|
|
238
|
+
draft?: boolean;
|
|
239
|
+
locale?: string;
|
|
240
|
+
req?: PayloadRequest;
|
|
241
|
+
};
|
|
242
|
+
export type UpdateOne = (args: UpdateOneArgs) => Promise<Document>;
|
|
243
|
+
export type DeleteOneArgs = {
|
|
244
|
+
collection: string;
|
|
245
|
+
where: Where;
|
|
246
|
+
req?: PayloadRequest;
|
|
247
|
+
};
|
|
248
|
+
export type DeleteOne = (args: DeleteOneArgs) => Promise<Document>;
|
|
249
|
+
export type DeleteManyArgs = {
|
|
250
|
+
collection: string;
|
|
251
|
+
where: Where;
|
|
252
|
+
req?: PayloadRequest;
|
|
253
|
+
};
|
|
254
|
+
export type DeleteMany = (args: DeleteManyArgs) => Promise<void>;
|
|
255
|
+
export type Migration = MigrationData & {
|
|
256
|
+
up: ({ payload }: {
|
|
257
|
+
payload: any;
|
|
258
|
+
}) => Promise<boolean>;
|
|
259
|
+
down: ({ payload }: {
|
|
260
|
+
payload: any;
|
|
261
|
+
}) => Promise<boolean>;
|
|
262
|
+
};
|
|
263
|
+
export type MigrationData = {
|
|
264
|
+
id: string;
|
|
265
|
+
name: string;
|
|
266
|
+
batch: number;
|
|
267
|
+
};
|
|
268
|
+
export type PaginatedDocs<T = any> = {
|
|
269
|
+
docs: T[];
|
|
270
|
+
totalDocs: number;
|
|
271
|
+
limit: number;
|
|
272
|
+
totalPages: number;
|
|
273
|
+
page?: number;
|
|
274
|
+
pagingCounter: number;
|
|
275
|
+
hasPrevPage: boolean;
|
|
276
|
+
hasNextPage: boolean;
|
|
277
|
+
prevPage?: number | null | undefined;
|
|
278
|
+
nextPage?: number | null | undefined;
|
|
279
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const setRequestContext_1 = require("../setRequestContext");
|
|
4
|
+
function defaultPayload(req, res, next) {
|
|
5
|
+
(0, setRequestContext_1.setRequestContext)(req);
|
|
6
|
+
next();
|
|
7
|
+
}
|
|
8
|
+
exports.default = defaultPayload;
|
|
9
|
+
//# sourceMappingURL=defaultPayload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultPayload.js","sourceRoot":"","sources":["../../../src/express/middleware/defaultPayload.ts"],"names":[],"mappings":";;AAEA,4DAAyD;AAEzD,SAAS,cAAc,CAAC,GAAmB,EAAE,GAAa,EAAE,IAAkB;IAC5E,IAAA,qCAAiB,EAAC,GAAG,CAAC,CAAC;IACvB,IAAI,EAAE,CAAC;AACT,CAAC;AAED,kBAAe,cAAc,CAAC"}
|