diff --git a/src/collections/operations/findByID.ts b/src/collections/operations/findByID.ts index 1412f0c6c4..38773a4a72 100644 --- a/src/collections/operations/findByID.ts +++ b/src/collections/operations/findByID.ts @@ -23,7 +23,7 @@ export type Arguments = { } // eslint-disable-next-line @typescript-eslint/no-explicit-any -async function findByID(incomingArgs: Arguments): Promise { +async function findByID(incomingArgs: Arguments): Promise { let args = incomingArgs; // ///////////////////////////////////// diff --git a/src/collections/operations/local/findByID.ts b/src/collections/operations/local/findByID.ts index bc1a182129..767b585572 100644 --- a/src/collections/operations/local/findByID.ts +++ b/src/collections/operations/local/findByID.ts @@ -1,5 +1,4 @@ import { BaseConfig } from '../../../config/types'; -import { TypeWithID } from '../../config/types'; import { PayloadRequest } from '../../../express/types'; import { Document } from '../../../types'; import findByID from '../findByID'; @@ -7,8 +6,8 @@ import { Payload } from '../../../payload'; import { getDataLoader } from '../../dataloader'; import i18n from '../../../translations/init'; -export type Options = { - collection: keyof Config['collections'] +export type Options = { + collection: T id: string depth?: number currentDepth?: number @@ -23,7 +22,7 @@ export type Options = { } // eslint-disable-next-line @typescript-eslint/no-explicit-any -export default async function findByIDLocal(payload: Payload, options: Options): Promise { +export default async function findByIDLocal(payload: Payload, options: Options): Promise { const { collection: collectionSlug, depth, @@ -53,7 +52,7 @@ export default async function findByIDLocal(payload: if (!req.t) req.t = req.i18n.t; if (!req.payloadDataLoader) req.payloadDataLoader = getDataLoader(req); - return findByID({ + return findByID({ depth, currentDepth, id, diff --git a/src/collections/operations/local/update.ts b/src/collections/operations/local/update.ts index cdb807fd5a..a5140fc067 100644 --- a/src/collections/operations/local/update.ts +++ b/src/collections/operations/local/update.ts @@ -6,11 +6,12 @@ import { PayloadRequest } from '../../../express/types'; import { getDataLoader } from '../../dataloader'; import { File } from '../../../uploads/types'; import i18nInit from '../../../translations/init'; +import { BaseConfig } from '../../../config/types'; -export type Options = { - collection: string +export type Options = { + collection: Slug id: string | number - data: Partial + data: Config['collections'][Slug] depth?: number locale?: string fallbackLocale?: string @@ -24,7 +25,7 @@ export type Options = { autosave?: boolean } -export default async function updateLocal(payload: Payload, options: Options): Promise { +export default async function updateLocal(payload: Payload, options: Options): Promise { const { collection: collectionSlug, depth, @@ -75,5 +76,5 @@ export default async function updateLocal(payload: Payload, options: Op req, }; - return update(args); + return update(args); } diff --git a/src/collections/operations/update.ts b/src/collections/operations/update.ts index 095081e3c7..3a201121b8 100644 --- a/src/collections/operations/update.ts +++ b/src/collections/operations/update.ts @@ -1,4 +1,5 @@ import httpStatus from 'http-status'; +import { BaseConfig } from '../../config/types'; import { Where, Document } from '../../types'; import { Collection } from '../config/types'; import sanitizeInternalFields from '../../utilities/sanitizeInternalFields'; @@ -18,11 +19,11 @@ import { afterRead } from '../../fields/hooks/afterRead'; import { generateFileData } from '../../uploads/generateFileData'; import { getLatestCollectionVersion } from '../../versions/getLatestCollectionVersion'; -export type Arguments = { +export type Arguments> = { collection: Collection req: PayloadRequest id: string | number - data: Record + data: T depth?: number disableVerificationEmail?: boolean overrideAccess?: boolean @@ -32,7 +33,9 @@ export type Arguments = { autosave?: boolean } -async function update(incomingArgs: Arguments): Promise { +async function update( + incomingArgs: Arguments, +): Promise { let args = incomingArgs; // ///////////////////////////////////// diff --git a/src/config/types.ts b/src/config/types.ts index 8902566c28..7815f6946e 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -22,10 +22,10 @@ import { User } from '../auth/types'; export interface BaseConfig { collections: { - [slug: string]: Record + [slug: string | number | symbol]: Record } globals: { - [slug: string]: Record + [slug: string | number | symbol]: Record } } @@ -109,7 +109,7 @@ export type InitOptions = { /** * A function that is called immediately following startup that receives the Payload instance as it's only argument. */ - onInit?: (payload: Payload) => Promise | void; + onInit?: (payload: Payload) => Promise | void; /** * Specify options for the built-in Pino logger that Payload uses for internal logging. @@ -541,7 +541,7 @@ export type Config = { /** Send anonymous telemetry data about general usage. */ telemetry?: boolean; /** A function that is called immediately following startup that receives the Payload instance as its only argument. */ - onInit?: (payload: Payload) => Promise | void; + onInit?: (payload: Payload) => Promise | void; }; export type SanitizedConfig = Omit< diff --git a/src/payload.ts b/src/payload.ts index 74d6fc000b..92fe298729 100644 --- a/src/payload.ts +++ b/src/payload.ts @@ -70,7 +70,7 @@ export class Payload { config: SanitizedConfig; collections: { - [slug: string]: Collection; + [slug: string | number | symbol]: Collection; } = {} versions: { @@ -272,9 +272,10 @@ export class Payload { * @param options * @returns document with specified ID */ - findByID = async (options: FindByIDOptions): Promise]> => { + + findByID = async (options: FindByIDOptions): Promise => { const { findByID } = localOperations; - return findByID(this, options); + return findByID(this, options); } /** @@ -282,9 +283,9 @@ export class Payload { * @param options * @returns Updated document */ - update = async (options: UpdateOptions): Promise => { + update = async (options: UpdateOptions): Promise => { const { update } = localOperations; - return update(this, options); + return update(this, options); } delete = async (options: DeleteOptions): Promise => { @@ -355,7 +356,7 @@ if (!cached) { cached = global.payload = { payload: null, promise: null }; } -export const getPayload = async (options: InitOptions): Promise> => { +export const getPayload = async (options: InitOptions): Promise> => { if (cached.payload) { return cached.payload; } diff --git a/test/fields/payload-types.ts b/test/fields/payload-types.ts index 622484aa1a..bb6dc23599 100644 --- a/test/fields/payload-types.ts +++ b/test/fields/payload-types.ts @@ -5,11 +5,31 @@ * and re-run `payload generate:types` to regenerate this file. */ -export interface Config {} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "array-fields". - */ +export interface Config { + collections: { + 'array-fields': ArrayField; + 'block-fields': BlockField; + 'code-fields': CodeField; + 'collapsible-fields': CollapsibleField; + 'conditional-logic': ConditionalLogic; + 'date-fields': DateField; + 'radio-fields': RadioField; + 'group-fields': GroupField; + 'indexed-fields': IndexedField; + 'json-fields': JsonField; + 'number-fields': NumberField; + 'point-fields': PointField; + 'relationship-fields': RelationshipField; + 'rich-text-fields': RichTextField; + 'select-fields': SelectField; + 'tabs-fields': TabsField; + 'text-fields': TextField; + uploads: Upload; + uploads2: Uploads2; + users: User; + }; + globals: {}; +} export interface ArrayField { id: string; items: { @@ -43,10 +63,6 @@ export interface ArrayField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "block-fields". - */ export interface BlockField { id: string; blocks: ( @@ -187,10 +203,6 @@ export interface BlockField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "code-fields". - */ export interface CodeField { id: string; javascript?: string; @@ -201,10 +213,6 @@ export interface CodeField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "collapsible-fields". - */ export interface CollapsibleField { id: string; text: string; @@ -225,10 +233,6 @@ export interface CollapsibleField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "conditional-logic". - */ export interface ConditionalLogic { id: string; text: string; @@ -237,10 +241,6 @@ export interface ConditionalLogic { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "date-fields". - */ export interface DateField { id: string; default: string; @@ -251,20 +251,12 @@ export interface DateField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "radio-fields". - */ export interface RadioField { id: string; radio?: 'one' | 'two' | 'three'; createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "group-fields". - */ export interface GroupField { id: string; group: { @@ -296,10 +288,6 @@ export interface GroupField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "indexed-fields". - */ export interface IndexedField { id: string; text: string; @@ -322,10 +310,6 @@ export interface IndexedField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "json-fields". - */ export interface JsonField { id: string; json?: { @@ -334,10 +318,6 @@ export interface JsonField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "number-fields". - */ export interface NumberField { id: string; number?: number; @@ -351,10 +331,6 @@ export interface NumberField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "point-fields". - */ export interface PointField { id: string; /** @@ -377,10 +353,6 @@ export interface PointField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "relationship-fields". - */ export interface RelationshipField { id: string; relationship: @@ -396,10 +368,6 @@ export interface RelationshipField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "text-fields". - */ export interface TextField { id: string; text: string; @@ -411,10 +379,6 @@ export interface TextField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "rich-text-fields". - */ export interface RichTextField { id: string; title: string; @@ -428,10 +392,6 @@ export interface RichTextField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "select-fields". - */ export interface SelectField { id: string; select?: 'one' | 'two' | 'three'; @@ -443,10 +403,6 @@ export interface SelectField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "tabs-fields". - */ export interface TabsField { id: string; array: { @@ -532,10 +488,6 @@ export interface TabsField { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "uploads". - */ export interface Upload { id: string; text?: string; @@ -549,10 +501,6 @@ export interface Upload { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "uploads2". - */ export interface Uploads2 { id: string; text?: string; @@ -566,10 +514,6 @@ export interface Uploads2 { createdAt: string; updatedAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "users". - */ export interface User { id: string; email?: string;