diff --git a/.changeset/soft-pigs-applaud.md b/.changeset/soft-pigs-applaud.md new file mode 100644 index 0000000000..24efd0dd4f --- /dev/null +++ b/.changeset/soft-pigs-applaud.md @@ -0,0 +1,5 @@ +--- +"@directus/sdk": patch +--- + +Fixed SDK compatibility with TypeScript 5.4 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 87a30dc05c..32180490ee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,10 +16,10 @@ importers: version: link:packages/release-notes-generator '@typescript-eslint/eslint-plugin': specifier: 7.1.1 - version: 7.1.1(@typescript-eslint/parser@7.1.1)(eslint@8.57.0)(typescript@5.3.3) + version: 7.1.1(@typescript-eslint/parser@7.1.1)(eslint@8.57.0)(typescript@5.4.5) '@typescript-eslint/parser': specifier: 7.1.1 - version: 7.1.1(eslint@8.57.0)(typescript@5.3.3) + version: 7.1.1(eslint@8.57.0)(typescript@5.4.5) eslint: specifier: 8.57.0 version: 8.57.0 @@ -2049,10 +2049,10 @@ importers: version: 2.6.11 tsup: specifier: 8.0.2 - version: 8.0.2(typescript@5.3.3) + version: 8.0.2(typescript@5.4.5) typescript: - specifier: 5.3.3 - version: 5.3.3 + specifier: 5.4.5 + version: 5.4.5 vitest: specifier: 1.3.1 version: 1.3.1(happy-dom@13.10.1)(sass@1.75.0) @@ -7942,7 +7942,7 @@ packages: '@types/node': 18.19.26 dev: true - /@typescript-eslint/eslint-plugin@7.1.1(@typescript-eslint/parser@7.1.1)(eslint@8.57.0)(typescript@5.3.3): + /@typescript-eslint/eslint-plugin@7.1.1(@typescript-eslint/parser@7.1.1)(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-zioDz623d0RHNhvx0eesUmGfIjzrk18nSBC8xewepKXbBvN/7c1qImV7Hg8TI1URTxKax7/zxfxj3Uph8Chcuw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7954,10 +7954,10 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 7.1.1(eslint@8.57.0)(typescript@5.3.3) + '@typescript-eslint/parser': 7.1.1(eslint@8.57.0)(typescript@5.4.5) '@typescript-eslint/scope-manager': 7.1.1 - '@typescript-eslint/type-utils': 7.1.1(eslint@8.57.0)(typescript@5.3.3) - '@typescript-eslint/utils': 7.1.1(eslint@8.57.0)(typescript@5.3.3) + '@typescript-eslint/type-utils': 7.1.1(eslint@8.57.0)(typescript@5.4.5) + '@typescript-eslint/utils': 7.1.1(eslint@8.57.0)(typescript@5.4.5) '@typescript-eslint/visitor-keys': 7.1.1 debug: 4.3.4 eslint: 8.57.0 @@ -7965,13 +7965,13 @@ packages: ignore: 5.3.1 natural-compare: 1.4.0 semver: 7.6.0 - ts-api-utils: 1.0.3(typescript@5.3.3) - typescript: 5.3.3 + ts-api-utils: 1.0.3(typescript@5.4.5) + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser@7.1.1(eslint@8.57.0)(typescript@5.3.3): + /@typescript-eslint/parser@7.1.1(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-ZWUFyL0z04R1nAEgr9e79YtV5LbafdOtN7yapNbn1ansMyaegl2D4bL7vHoJ4HPSc4CaLwuCVas8CVuneKzplQ==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7983,11 +7983,11 @@ packages: dependencies: '@typescript-eslint/scope-manager': 7.1.1 '@typescript-eslint/types': 7.1.1 - '@typescript-eslint/typescript-estree': 7.1.1(typescript@5.3.3) + '@typescript-eslint/typescript-estree': 7.1.1(typescript@5.4.5) '@typescript-eslint/visitor-keys': 7.1.1 debug: 4.3.4 eslint: 8.57.0 - typescript: 5.3.3 + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true @@ -8000,7 +8000,7 @@ packages: '@typescript-eslint/visitor-keys': 7.1.1 dev: true - /@typescript-eslint/type-utils@7.1.1(eslint@8.57.0)(typescript@5.3.3): + /@typescript-eslint/type-utils@7.1.1(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-5r4RKze6XHEEhlZnJtR3GYeCh1IueUHdbrukV2KSlLXaTjuSfeVF8mZUVPLovidCuZfbVjfhi4c0DNSa/Rdg5g==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -8010,12 +8010,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 7.1.1(typescript@5.3.3) - '@typescript-eslint/utils': 7.1.1(eslint@8.57.0)(typescript@5.3.3) + '@typescript-eslint/typescript-estree': 7.1.1(typescript@5.4.5) + '@typescript-eslint/utils': 7.1.1(eslint@8.57.0)(typescript@5.4.5) debug: 4.3.4 eslint: 8.57.0 - ts-api-utils: 1.0.3(typescript@5.3.3) - typescript: 5.3.3 + ts-api-utils: 1.0.3(typescript@5.4.5) + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true @@ -8025,7 +8025,7 @@ packages: engines: {node: ^16.0.0 || >=18.0.0} dev: true - /@typescript-eslint/typescript-estree@7.1.1(typescript@5.3.3): + /@typescript-eslint/typescript-estree@7.1.1(typescript@5.4.5): resolution: {integrity: sha512-9ZOncVSfr+sMXVxxca2OJOPagRwT0u/UHikM2Rd6L/aB+kL/QAuTnsv6MeXtjzCJYb8PzrXarypSGIPx3Jemxw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -8041,13 +8041,13 @@ packages: is-glob: 4.0.3 minimatch: 9.0.3 semver: 7.6.0 - ts-api-utils: 1.0.3(typescript@5.3.3) - typescript: 5.3.3 + ts-api-utils: 1.0.3(typescript@5.4.5) + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@7.1.1(eslint@8.57.0)(typescript@5.3.3): + /@typescript-eslint/utils@7.1.1(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-thOXM89xA03xAE0lW7alstvnyoBUbBX38YtY+zAUcpRPcq9EIhXPuJ0YTv948MbzmKh6e1AUszn5cBFK49Umqg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -8058,7 +8058,7 @@ packages: '@types/semver': 7.5.8 '@typescript-eslint/scope-manager': 7.1.1 '@typescript-eslint/types': 7.1.1 - '@typescript-eslint/typescript-estree': 7.1.1(typescript@5.3.3) + '@typescript-eslint/typescript-estree': 7.1.1(typescript@5.4.5) eslint: 8.57.0 semver: 7.6.0 transitivePeerDependencies: @@ -17851,6 +17851,9 @@ packages: /sqlite3@5.1.7: resolution: {integrity: sha512-GGIyOiFaG+TUra3JIfkI/zGP8yZYLPQ0pl1bH+ODjiX57sPhrLU5sQJn1y9bDKZUFYkX1crlrPfSYt0BKKdkog==} requiresBuild: true + peerDependenciesMeta: + node-gyp: + optional: true dependencies: bindings: 1.5.0 node-addon-api: 7.0.0 @@ -18686,13 +18689,13 @@ packages: resolution: {integrity: sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==} dev: true - /ts-api-utils@1.0.3(typescript@5.3.3): + /ts-api-utils@1.0.3(typescript@5.4.5): resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} engines: {node: '>=16.13.0'} peerDependencies: typescript: '>=4.2.0' dependencies: - typescript: 5.3.3 + typescript: 5.4.5 dev: true /ts-interface-checker@0.1.13: @@ -18758,6 +18761,45 @@ packages: - ts-node dev: true + /tsup@8.0.2(typescript@5.4.5): + resolution: {integrity: sha512-NY8xtQXdH7hDUAZwcQdY/Vzlw9johQsaqf7iwZ6g1DOUlFYQ5/AtVAjTvihhEyeRlGo4dLRVHtrRaL35M1daqQ==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + '@microsoft/api-extractor': ^7.36.0 + '@swc/core': ^1 + postcss: ^8.4.12 + typescript: '>=4.5.0' + peerDependenciesMeta: + '@microsoft/api-extractor': + optional: true + '@swc/core': + optional: true + postcss: + optional: true + typescript: + optional: true + dependencies: + bundle-require: 4.0.2(esbuild@0.19.12) + cac: 6.7.14 + chokidar: 3.6.0 + debug: 4.3.4 + esbuild: 0.19.12 + execa: 5.1.1 + globby: 11.1.0 + joycon: 3.1.1 + postcss-load-config: 4.0.2 + resolve-from: 5.0.0 + rollup: 4.12.0 + source-map: 0.8.0-beta.0 + sucrase: 3.35.0 + tree-kill: 1.2.2 + typescript: 5.4.5 + transitivePeerDependencies: + - supports-color + - ts-node + dev: true + /tsx@4.7.1: resolution: {integrity: sha512-8d6VuibXHtlN5E3zFkgY8u4DX7Y3Z27zvvPKVmLon/D4AjuKzarkUBTLDBgj9iTQ0hg5xM7c/mYiRVM+HETf0g==} engines: {node: '>=18.0.0'} @@ -18968,6 +19010,12 @@ packages: hasBin: true dev: true + /typescript@5.4.5: + resolution: {integrity: sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==} + engines: {node: '>=14.17'} + hasBin: true + dev: true + /typical@2.6.1: resolution: {integrity: sha512-ofhi8kjIje6npGozTip9Fr8iecmYfEbS06i0JnIg+rh51KakryWF4+jX8lLKZVhy6N+ID45WYSFCxPOdTWCzNg==} dev: true diff --git a/sdk/package.json b/sdk/package.json index f5cd5bd8da..6fd344b5d5 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -34,7 +34,7 @@ "@directus/tsconfig": "workspace:*", "@types/node-fetch": "2.6.11", "tsup": "8.0.2", - "typescript": "5.3.3", + "typescript": "5.4.5", "vitest": "1.3.1" }, "engines": { diff --git a/sdk/src/auth/composable.ts b/sdk/src/auth/composable.ts index 93c46be3ee..79edd46856 100644 --- a/sdk/src/auth/composable.ts +++ b/sdk/src/auth/composable.ts @@ -32,7 +32,7 @@ const MAX_INT32 = 2 ** 31 - 1; * @returns A Directus authentication client. */ export const authentication = (mode: AuthenticationMode = 'cookie', config: Partial = {}) => { - return (client: DirectusClient): AuthenticationClient => { + return (client: DirectusClient): AuthenticationClient => { const authConfig = { ...defaultConfigValues, ...config }; let refreshPromise: Promise | null = null; let refreshTimeout: ReturnType | null = null; diff --git a/sdk/src/auth/static.ts b/sdk/src/auth/static.ts index e5dfdbd7ae..2c72b2fd0d 100644 --- a/sdk/src/auth/static.ts +++ b/sdk/src/auth/static.ts @@ -9,7 +9,7 @@ import type { StaticTokenClient } from './types.js'; * @returns A Directus static token client. */ export const staticToken = (access_token: string) => { - return (_client: DirectusClient): StaticTokenClient => { + return (_client: DirectusClient): StaticTokenClient => { let token: string | null = access_token ?? null; return { async getToken() { diff --git a/sdk/src/auth/types.ts b/sdk/src/auth/types.ts index a841e565d4..f5660e41a4 100644 --- a/sdk/src/auth/types.ts +++ b/sdk/src/auth/types.ts @@ -28,7 +28,7 @@ export interface AuthenticationConfig { storage?: AuthenticationStorage; } -export interface AuthenticationClient<_Schema extends object> { +export interface AuthenticationClient<_Schema> { login(email: string, password: string, options?: LoginOptions): Promise; refresh(): Promise; logout(): Promise; @@ -39,7 +39,7 @@ export interface AuthenticationClient<_Schema extends object> { setToken(access_token: string | null): void; } -export interface StaticTokenClient<_Schema extends object> { +export interface StaticTokenClient<_Schema> { getToken(): Promise; setToken(access_token: string | null): void; } diff --git a/sdk/src/client.ts b/sdk/src/client.ts index 4df55edd53..2716a45a86 100644 --- a/sdk/src/client.ts +++ b/sdk/src/client.ts @@ -18,10 +18,7 @@ const defaultGlobals: ClientGlobals = { * * @returns A Directus client. */ -export const createDirectus = ( - url: string, - options: ClientOptions = {}, -): DirectusClient => { +export const createDirectus = (url: string, options: ClientOptions = {}): DirectusClient => { const globals = options.globals ? { ...defaultGlobals, ...options.globals } : defaultGlobals; return { globals, diff --git a/sdk/src/graphql/composable.ts b/sdk/src/graphql/composable.ts index 4e2b4929b0..d78b5e6612 100644 --- a/sdk/src/graphql/composable.ts +++ b/sdk/src/graphql/composable.ts @@ -12,7 +12,7 @@ const defaultConfigValues: GraphqlConfig = {}; * @returns A Directus GraphQL client. */ export const graphql = (config: Partial = {}) => { - return (client: DirectusClient): GraphqlClient => { + return (client: DirectusClient): GraphqlClient => { const gqlConfig = { ...defaultConfigValues, ...config }; return { async query>( diff --git a/sdk/src/graphql/types.ts b/sdk/src/graphql/types.ts index 7206f44981..19766dbb2d 100644 --- a/sdk/src/graphql/types.ts +++ b/sdk/src/graphql/types.ts @@ -1,4 +1,4 @@ -export interface GraphqlClient<_Schema extends object> { +export interface GraphqlClient<_Schema> { query>( query: string, variables?: Record, @@ -10,6 +10,6 @@ export interface GraphqlConfig { credentials?: RequestCredentials; } -export type GqlResult = { +export type GqlResult = { [Key in Collection]: Schema[Collection][]; }; diff --git a/sdk/src/realtime/composable.ts b/sdk/src/realtime/composable.ts index 86fb59614a..5841ddb5a3 100644 --- a/sdk/src/realtime/composable.ts +++ b/sdk/src/realtime/composable.ts @@ -18,7 +18,7 @@ import { auth } from './commands/auth.js'; import type { AuthenticationClient } from '../auth/types.js'; import type { ConsoleInterface, WebSocketInterface } from '../index.js'; -type AuthWSClient = WebSocketClient & AuthenticationClient; +type AuthWSClient = WebSocketClient & AuthenticationClient; const defaultRealTimeConfig: WebSocketConfig = { authMode: 'handshake', @@ -38,7 +38,7 @@ const defaultRealTimeConfig: WebSocketConfig = { * @returns A Directus realtime client. */ export function realtime(config: WebSocketConfig = {}) { - return (client: DirectusClient) => { + return (client: DirectusClient) => { config = { ...defaultRealTimeConfig, ...config }; let uid = generateUid(); diff --git a/sdk/src/realtime/types.ts b/sdk/src/realtime/types.ts index a74db06ce2..47bc44b712 100644 --- a/sdk/src/realtime/types.ts +++ b/sdk/src/realtime/types.ts @@ -16,7 +16,7 @@ export interface WebSocketConfig { url?: string; } -export interface SubscribeOptions { +export interface SubscribeOptions { event?: SubscriptionOptionsEvents; query?: Query; uid?: string; @@ -26,7 +26,7 @@ export type WebSocketEvents = 'open' | 'close' | 'error' | 'message'; export type RemoveEventHandler = () => void; export type WebSocketEventHandler = (this: WebSocketInterface, ev: Event | CloseEvent | any) => any; -export interface WebSocketClient { +export interface WebSocketClient { connect(): Promise; disconnect(): void; onWebSocket(event: 'open', callback: (this: WebSocketInterface, ev: Event) => any): RemoveEventHandler; @@ -69,7 +69,7 @@ export type SubscriptionOptionsEvents = 'create' | 'update' | 'delete'; export type SubscriptionEvents = 'init' | SubscriptionOptionsEvents; export type SubscriptionOutput< - Schema extends object, + Schema, Collection extends keyof Schema, TQuery extends Query | undefined, Events extends SubscriptionEvents, diff --git a/sdk/src/rest/commands/auth/login.ts b/sdk/src/rest/commands/auth/login.ts index c9b222d595..d565b4f751 100644 --- a/sdk/src/rest/commands/auth/login.ts +++ b/sdk/src/rest/commands/auth/login.ts @@ -12,11 +12,7 @@ import { getAuthEndpoint } from '../../utils/get-auth-endpoint.js'; * @returns Authentication data. */ export const login = - ( - email: string, - password: string, - options: LoginOptions = {}, - ): RestCommand => + (email: string, password: string, options: LoginOptions = {}): RestCommand => () => { const path = getAuthEndpoint(options.provider); const data: Record = { email, password }; diff --git a/sdk/src/rest/commands/auth/logout.ts b/sdk/src/rest/commands/auth/logout.ts index cf02ba51ca..a894a4f001 100644 --- a/sdk/src/rest/commands/auth/logout.ts +++ b/sdk/src/rest/commands/auth/logout.ts @@ -10,7 +10,7 @@ import type { RestCommand } from '../../types.js'; * @returns Empty body. */ export const logout = - (refresh_token?: string, mode: AuthenticationMode = 'cookie'): RestCommand => + (refresh_token?: string, mode: AuthenticationMode = 'cookie'): RestCommand => () => ({ path: '/auth/logout', method: 'POST', diff --git a/sdk/src/rest/commands/auth/password-request.ts b/sdk/src/rest/commands/auth/password-request.ts index 012d92e515..8ae568e715 100644 --- a/sdk/src/rest/commands/auth/password-request.ts +++ b/sdk/src/rest/commands/auth/password-request.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @returns Empty body. */ export const passwordRequest = - (email: string, reset_url?: string): RestCommand => + (email: string, reset_url?: string): RestCommand => () => ({ path: '/auth/password/request', method: 'POST', diff --git a/sdk/src/rest/commands/auth/password-reset.ts b/sdk/src/rest/commands/auth/password-reset.ts index 155829dc78..e2b3084f25 100644 --- a/sdk/src/rest/commands/auth/password-reset.ts +++ b/sdk/src/rest/commands/auth/password-reset.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @returns Empty body. */ export const passwordReset = - (token: string, password: string): RestCommand => + (token: string, password: string): RestCommand => () => ({ path: '/auth/password/reset', method: 'POST', diff --git a/sdk/src/rest/commands/auth/providers.ts b/sdk/src/rest/commands/auth/providers.ts index c431159ea0..c1d0cb4a68 100644 --- a/sdk/src/rest/commands/auth/providers.ts +++ b/sdk/src/rest/commands/auth/providers.ts @@ -12,7 +12,7 @@ export interface ReadProviderOutput { * @returns Array of configured auth providers. */ export const readProviders = - (sessionOnly = false): RestCommand => + (sessionOnly = false): RestCommand => () => ({ path: sessionOnly ? '/auth?sessionOnly' : '/auth', method: 'GET', diff --git a/sdk/src/rest/commands/auth/refresh.ts b/sdk/src/rest/commands/auth/refresh.ts index d339ed0434..51358d21ba 100644 --- a/sdk/src/rest/commands/auth/refresh.ts +++ b/sdk/src/rest/commands/auth/refresh.ts @@ -10,10 +10,7 @@ import type { RestCommand } from '../../types.js'; * @returns The new access and refresh tokens for the session. */ export const refresh = - ( - mode: AuthenticationMode = 'cookie', - refresh_token?: string, - ): RestCommand => + (mode: AuthenticationMode = 'cookie', refresh_token?: string): RestCommand => () => ({ path: '/auth/refresh', method: 'POST', diff --git a/sdk/src/rest/commands/create/activity.ts b/sdk/src/rest/commands/create/activity.ts index 106189ba5e..c0613e3b02 100644 --- a/sdk/src/rest/commands/create/activity.ts +++ b/sdk/src/rest/commands/create/activity.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateActivityOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusActivity, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateActivityOutput< * @returns Returns the activity object of the created comment. */ export const createComment = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/collections.ts b/sdk/src/rest/commands/create/collections.ts index 28b0fd40f4..88bdcfa6a4 100644 --- a/sdk/src/rest/commands/create/collections.ts +++ b/sdk/src/rest/commands/create/collections.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, NestedPartial, Query } from '../../../types/inde import type { RestCommand } from '../../types.js'; export type CreateCollectionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusCollection, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateCollectionOutput< * @returns The collection object for the collection created in this request. */ export const createCollection = - >>( + >>( item: NestedPartial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/dashboards.ts b/sdk/src/rest/commands/create/dashboards.ts index 1b02922fc7..f3ff7a3a46 100644 --- a/sdk/src/rest/commands/create/dashboards.ts +++ b/sdk/src/rest/commands/create/dashboards.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateDashboardOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusDashboard, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateDashboardOutput< * @returns Returns the dashboard object for the created dashboards. */ export const createDashboards = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createDashboards = * @returns Returns the dashboard object for the created dashboard. */ export const createDashboard = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/fields.ts b/sdk/src/rest/commands/create/fields.ts index d4b6cb48f5..ef693cd4d9 100644 --- a/sdk/src/rest/commands/create/fields.ts +++ b/sdk/src/rest/commands/create/fields.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, NestedPartial, Query } from '../../../types/inde import type { RestCommand } from '../../types.js'; export type CreateFieldOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusField, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type CreateFieldOutput< * @returns The field object for the created field. */ export const createField = - >>( + >>( collection: keyof Schema, item: NestedPartial>, query?: TQuery, diff --git a/sdk/src/rest/commands/create/files.ts b/sdk/src/rest/commands/create/files.ts index 32f077927d..dde311d22e 100644 --- a/sdk/src/rest/commands/create/files.ts +++ b/sdk/src/rest/commands/create/files.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateFileOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFile, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateFileOutput< * @returns Returns the file object for the uploaded file, or an array of file objects if multiple files were uploaded at once. */ export const uploadFiles = - >>( + >>( data: FormData, query?: TQuery, ): RestCommand, Schema> => @@ -39,7 +39,7 @@ export const uploadFiles = * @returns Returns the file object for the imported file. */ export const importFile = - >>( + >>( url: string, data: Partial> = {}, query?: TQuery, diff --git a/sdk/src/rest/commands/create/flows.ts b/sdk/src/rest/commands/create/flows.ts index 9d0124be25..74f3a4260f 100644 --- a/sdk/src/rest/commands/create/flows.ts +++ b/sdk/src/rest/commands/create/flows.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateFlowOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFlow, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateFlowOutput< * @returns Returns the flow object for the created flow. */ export const createFlows = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createFlows = * @returns Returns the flow object for the created flow. */ export const createFlow = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/folders.ts b/sdk/src/rest/commands/create/folders.ts index b2117846f9..ef515a7e34 100644 --- a/sdk/src/rest/commands/create/folders.ts +++ b/sdk/src/rest/commands/create/folders.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateFolderOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFolder, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateFolderOutput< * @returns Returns the folder object of the folder that was created. */ export const createFolders = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createFolders = * @returns Returns the folder object of the folder that was created. */ export const createFolder = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/items.ts b/sdk/src/rest/commands/create/items.ts index aa2fcf3467..83627d8391 100644 --- a/sdk/src/rest/commands/create/items.ts +++ b/sdk/src/rest/commands/create/items.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, CollectionType, Query, UnpackList } from '../../ import type { RestCommand } from '../../types.js'; export type CreateItemOutput< - Schema extends object, + Schema, Collection extends keyof Schema, TQuery extends Query, > = ApplyQueryFields, TQuery['fields']>; @@ -18,7 +18,7 @@ export type CreateItemOutput< * @returns Returns the item objects of the item that were created. */ export const createItems = - >( + >( collection: Collection, items: Partial>[], query?: TQuery, @@ -48,7 +48,7 @@ export const createItems = * @returns Returns the item objects of the item that were created. */ export const createItem = - >( + >( collection: Collection, item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/create/notifications.ts b/sdk/src/rest/commands/create/notifications.ts index 0b13173286..b2a81a68fc 100644 --- a/sdk/src/rest/commands/create/notifications.ts +++ b/sdk/src/rest/commands/create/notifications.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateNotificationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusNotification, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateNotificationOutput< * @returns Returns the notification object for the created notification. */ export const createNotifications = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createNotifications = * @returns Returns the notification object for the created notification. */ export const createNotification = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/operations.ts b/sdk/src/rest/commands/create/operations.ts index 613c1f1505..c481ab98b2 100644 --- a/sdk/src/rest/commands/create/operations.ts +++ b/sdk/src/rest/commands/create/operations.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateOperationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusOperation, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateOperationOutput< * @returns Returns the operation object for the created operation. */ export const createOperations = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createOperations = * @returns Returns the operation object for the created operation. */ export const createOperation = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/panels.ts b/sdk/src/rest/commands/create/panels.ts index 8639adf60d..e9e5311ab4 100644 --- a/sdk/src/rest/commands/create/panels.ts +++ b/sdk/src/rest/commands/create/panels.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreatePanelOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPanel, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreatePanelOutput< * @returns Returns the panel object for the created panel. */ export const createPanels = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createPanels = * @returns Returns the panel object for the created panel. */ export const createPanel = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/permissions.ts b/sdk/src/rest/commands/create/permissions.ts index 7634f33f26..b7905cccc3 100644 --- a/sdk/src/rest/commands/create/permissions.ts +++ b/sdk/src/rest/commands/create/permissions.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreatePermissionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPermission, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreatePermissionOutput< * @returns Returns the permission objects for the created permissions. */ export const createPermissions = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createPermissions = * @returns Returns the permission object for the created permission. */ export const createPermission = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/presets.ts b/sdk/src/rest/commands/create/presets.ts index f5d7135337..37b34d73ad 100644 --- a/sdk/src/rest/commands/create/presets.ts +++ b/sdk/src/rest/commands/create/presets.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreatePresetOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPreset, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreatePresetOutput< * @returns Returns the preset object for the created preset. */ export const createPresets = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createPresets = * @returns Returns the preset object for the created preset. */ export const createPreset = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/relations.ts b/sdk/src/rest/commands/create/relations.ts index ceb524df1a..deae645117 100644 --- a/sdk/src/rest/commands/create/relations.ts +++ b/sdk/src/rest/commands/create/relations.ts @@ -2,10 +2,11 @@ import type { DirectusRelation } from '../../../schema/relation.js'; import type { ApplyQueryFields, NestedPartial } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; -export type CreateRelationOutput< - Schema extends object, - Item extends object = DirectusRelation, -> = ApplyQueryFields; +export type CreateRelationOutput> = ApplyQueryFields< + Schema, + Item, + '*' +>; /** * Create a new relation. @@ -16,9 +17,7 @@ export type CreateRelationOutput< * @returns Returns the relation object for the created relation. */ export const createRelation = - ( - item: NestedPartial>, - ): RestCommand, Schema> => + (item: NestedPartial>): RestCommand, Schema> => () => ({ path: `/relations`, body: JSON.stringify(item), diff --git a/sdk/src/rest/commands/create/roles.ts b/sdk/src/rest/commands/create/roles.ts index ecaf1fff5a..0e87dd4418 100644 --- a/sdk/src/rest/commands/create/roles.ts +++ b/sdk/src/rest/commands/create/roles.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateRoleOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusRole, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateRoleOutput< * @returns Returns the role objects for the created roles. */ export const createRoles = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createRoles = * @returns Returns the role object for the created role. */ export const createRole = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/shares.ts b/sdk/src/rest/commands/create/shares.ts index e675279d67..a1970b8d7e 100644 --- a/sdk/src/rest/commands/create/shares.ts +++ b/sdk/src/rest/commands/create/shares.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateShareOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusShare, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateShareOutput< * @returns Returns the share objects for the created shares. */ export const createShares = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createShares = * @returns Returns the share object for the created share. */ export const createShare = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/translations.ts b/sdk/src/rest/commands/create/translations.ts index 8ab1a9b30c..3c8ba739aa 100644 --- a/sdk/src/rest/commands/create/translations.ts +++ b/sdk/src/rest/commands/create/translations.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateTranslationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusTranslation, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateTranslationOutput< * @returns Returns the translation object for the created translation. */ export const createTranslations = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createTranslations = * @returns Returns the translation object for the created translation. */ export const createTranslation = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/users.ts b/sdk/src/rest/commands/create/users.ts index 75fbb723f4..107d8d4c52 100644 --- a/sdk/src/rest/commands/create/users.ts +++ b/sdk/src/rest/commands/create/users.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateUserOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusUser, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateUserOutput< * @returns Returns the user objects for the created users. */ export const createUsers = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createUsers = * @returns Returns the user object for the created user. */ export const createUser = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/versions.ts b/sdk/src/rest/commands/create/versions.ts index 11f8fa59d1..0a19e8926f 100644 --- a/sdk/src/rest/commands/create/versions.ts +++ b/sdk/src/rest/commands/create/versions.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateContentVersionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusVersion, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateContentVersionOutput< * @returns Returns the Content Version object for the created Content Versions. */ export const createContentVersions = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createContentVersions = * @returns Returns the Content Version object for the created Content Version. */ export const createContentVersion = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/create/webhooks.ts b/sdk/src/rest/commands/create/webhooks.ts index c4f1bf267f..d5d5e82e11 100644 --- a/sdk/src/rest/commands/create/webhooks.ts +++ b/sdk/src/rest/commands/create/webhooks.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type CreateWebhookOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusWebhook, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type CreateWebhookOutput< * @returns Returns the webhook objects for the created webhooks. */ export const createWebhooks = - >>( + >>( items: Partial>[], query?: TQuery, ): RestCommand[], Schema> => @@ -37,7 +37,7 @@ export const createWebhooks = * @returns Returns the webhook object for the created webhook. */ export const createWebhook = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/delete/activity.ts b/sdk/src/rest/commands/delete/activity.ts index 49ad829eac..c614f4c77b 100644 --- a/sdk/src/rest/commands/delete/activity.ts +++ b/sdk/src/rest/commands/delete/activity.ts @@ -7,7 +7,7 @@ import type { RestCommand } from '../../types.js'; * @returns Nothing */ export const deleteComment = - (key: DirectusActivity['id']): RestCommand => + (key: DirectusActivity['id']): RestCommand => () => ({ path: `/activity/comment/${key}`, method: 'DELETE', diff --git a/sdk/src/rest/commands/delete/collections.ts b/sdk/src/rest/commands/delete/collections.ts index d1a5956c6d..77267eb0fd 100644 --- a/sdk/src/rest/commands/delete/collections.ts +++ b/sdk/src/rest/commands/delete/collections.ts @@ -7,7 +7,7 @@ import type { RestCommand } from '../../types.js'; * @returns */ export const deleteCollection = - (collection: DirectusCollection['collection']): RestCommand => + (collection: DirectusCollection['collection']): RestCommand => () => ({ path: `/collections/${collection}`, method: 'DELETE', diff --git a/sdk/src/rest/commands/delete/dashboards.ts b/sdk/src/rest/commands/delete/dashboards.ts index 8105266947..7956ecbf03 100644 --- a/sdk/src/rest/commands/delete/dashboards.ts +++ b/sdk/src/rest/commands/delete/dashboards.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteDashboards = - (keys: DirectusDashboard['id'][]): RestCommand => + (keys: DirectusDashboard['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteDashboards = * @throws Will throw if key is empty */ export const deleteDashboard = - (key: DirectusDashboard['id']): RestCommand => + (key: DirectusDashboard['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/fields.ts b/sdk/src/rest/commands/delete/fields.ts index 25ca5ebd84..e958d2feba 100644 --- a/sdk/src/rest/commands/delete/fields.ts +++ b/sdk/src/rest/commands/delete/fields.ts @@ -11,7 +11,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if field is empty */ export const deleteField = - ( + ( collection: DirectusField['collection'], field: DirectusField['field'], ): RestCommand => diff --git a/sdk/src/rest/commands/delete/files.ts b/sdk/src/rest/commands/delete/files.ts index cb6beca400..e9279b117e 100644 --- a/sdk/src/rest/commands/delete/files.ts +++ b/sdk/src/rest/commands/delete/files.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteFiles = - (keys: DirectusFile['id'][]): RestCommand => + (keys: DirectusFile['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteFiles = * @throws Will throw if key is empty */ export const deleteFile = - (key: DirectusFile['id']): RestCommand => + (key: DirectusFile['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/flows.ts b/sdk/src/rest/commands/delete/flows.ts index 3cd0549fc6..a29752f981 100644 --- a/sdk/src/rest/commands/delete/flows.ts +++ b/sdk/src/rest/commands/delete/flows.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteFlows = - (keys: DirectusFlow['id'][]): RestCommand => + (keys: DirectusFlow['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteFlows = * @throws Will throw if key is empty */ export const deleteFlow = - (key: DirectusFlow['id']): RestCommand => + (key: DirectusFlow['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/folders.ts b/sdk/src/rest/commands/delete/folders.ts index bbf2460d0b..bcf57287f8 100644 --- a/sdk/src/rest/commands/delete/folders.ts +++ b/sdk/src/rest/commands/delete/folders.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteFolders = - (keys: DirectusFolder['id'][]): RestCommand => + (keys: DirectusFolder['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteFolders = * @throws Will throw if key is empty */ export const deleteFolder = - (key: DirectusFolder['id']): RestCommand => + (key: DirectusFolder['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/items.ts b/sdk/src/rest/commands/delete/items.ts index 9f365a9478..22abfacc75 100644 --- a/sdk/src/rest/commands/delete/items.ts +++ b/sdk/src/rest/commands/delete/items.ts @@ -14,7 +14,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keysOrQuery is empty */ export const deleteItems = - >( + >( collection: Collection, keysOrQuery: string[] | number[] | TQuery, ): RestCommand => @@ -51,10 +51,7 @@ export const deleteItems = * @throws Will throw if key is empty */ export const deleteItem = - ( - collection: Collection, - key: string | number, - ): RestCommand => + (collection: Collection, key: string | number): RestCommand => () => { throwIfEmpty(String(collection), 'Collection cannot be empty'); throwIfCoreCollection(collection, 'Cannot use deleteItem for core collections'); diff --git a/sdk/src/rest/commands/delete/notifications.ts b/sdk/src/rest/commands/delete/notifications.ts index ec2f7f8a79..3c1217538b 100644 --- a/sdk/src/rest/commands/delete/notifications.ts +++ b/sdk/src/rest/commands/delete/notifications.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteNotifications = - (keys: DirectusNotification['id'][]): RestCommand => + (keys: DirectusNotification['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteNotifications = * @throws Will throw if key is empty */ export const deleteNotification = - (key: DirectusNotification['id']): RestCommand => + (key: DirectusNotification['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/operations.ts b/sdk/src/rest/commands/delete/operations.ts index 194ce623f1..dcb303a875 100644 --- a/sdk/src/rest/commands/delete/operations.ts +++ b/sdk/src/rest/commands/delete/operations.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteOperations = - (keys: DirectusOperation['id'][]): RestCommand => + (keys: DirectusOperation['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteOperations = * @throws Will throw if key is empty */ export const deleteOperation = - (key: DirectusOperation['id']): RestCommand => + (key: DirectusOperation['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/panels.ts b/sdk/src/rest/commands/delete/panels.ts index ba71ea6850..f2125c3cc8 100644 --- a/sdk/src/rest/commands/delete/panels.ts +++ b/sdk/src/rest/commands/delete/panels.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deletePanels = - (keys: DirectusPanel['id'][]): RestCommand => + (keys: DirectusPanel['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deletePanels = * @throws Will throw if key is empty */ export const deletePanel = - (key: DirectusPanel['id']): RestCommand => + (key: DirectusPanel['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/permissions.ts b/sdk/src/rest/commands/delete/permissions.ts index e968a134e3..79163f77e6 100644 --- a/sdk/src/rest/commands/delete/permissions.ts +++ b/sdk/src/rest/commands/delete/permissions.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deletePermissions = - (keys: DirectusPermission['id'][]): RestCommand => + (keys: DirectusPermission['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deletePermissions = * @throws Will throw if key is empty */ export const deletePermission = - (key: DirectusPermission['id']): RestCommand => + (key: DirectusPermission['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/presets.ts b/sdk/src/rest/commands/delete/presets.ts index a07151601c..778c133cb3 100644 --- a/sdk/src/rest/commands/delete/presets.ts +++ b/sdk/src/rest/commands/delete/presets.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deletePresets = - (keys: DirectusPreset['id'][]): RestCommand => + (keys: DirectusPreset['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deletePresets = * @throws Will throw if key is empty */ export const deletePreset = - (key: DirectusPreset['id']): RestCommand => + (key: DirectusPreset['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/relations.ts b/sdk/src/rest/commands/delete/relations.ts index c5f6a7d410..4d80a72515 100644 --- a/sdk/src/rest/commands/delete/relations.ts +++ b/sdk/src/rest/commands/delete/relations.ts @@ -11,7 +11,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if field is empty */ export const deleteRelation = - ( + ( collection: DirectusRelation['collection'], field: DirectusRelation['field'], ): RestCommand => diff --git a/sdk/src/rest/commands/delete/roles.ts b/sdk/src/rest/commands/delete/roles.ts index 41d316b1ae..1bcea5668f 100644 --- a/sdk/src/rest/commands/delete/roles.ts +++ b/sdk/src/rest/commands/delete/roles.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteRoles = - (keys: DirectusRole['id'][]): RestCommand => + (keys: DirectusRole['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteRoles = * @throws Will throw if key is empty */ export const deleteRole = - (key: DirectusRole['id']): RestCommand => + (key: DirectusRole['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/shares.ts b/sdk/src/rest/commands/delete/shares.ts index 59a996f48c..062201bf37 100644 --- a/sdk/src/rest/commands/delete/shares.ts +++ b/sdk/src/rest/commands/delete/shares.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteShares = - (keys: DirectusShare['id'][]): RestCommand => + (keys: DirectusShare['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteShares = * @throws Will throw if key is empty */ export const deleteShare = - (key: DirectusShare['id']): RestCommand => + (key: DirectusShare['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/translations.ts b/sdk/src/rest/commands/delete/translations.ts index a1b8b762d7..412625298c 100644 --- a/sdk/src/rest/commands/delete/translations.ts +++ b/sdk/src/rest/commands/delete/translations.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteTranslations = - (keys: DirectusTranslation['id'][]): RestCommand => + (keys: DirectusTranslation['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteTranslations = * @throws Will throw if key is empty */ export const deleteTranslation = - (key: DirectusTranslation['id']): RestCommand => + (key: DirectusTranslation['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/users.ts b/sdk/src/rest/commands/delete/users.ts index 8e12d448b2..99869de300 100644 --- a/sdk/src/rest/commands/delete/users.ts +++ b/sdk/src/rest/commands/delete/users.ts @@ -10,7 +10,7 @@ import type { DirectusUser } from '../../../schema/user.js'; * @throws Will throw if keys is empty */ export const deleteUsers = - (keys: DirectusUser['id'][]): RestCommand => + (keys: DirectusUser['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -29,7 +29,7 @@ export const deleteUsers = * @throws Will throw if key is empty */ export const deleteUser = - (key: DirectusUser['id']): RestCommand => + (key: DirectusUser['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/versions.ts b/sdk/src/rest/commands/delete/versions.ts index 0429c9ae6d..8084afe333 100644 --- a/sdk/src/rest/commands/delete/versions.ts +++ b/sdk/src/rest/commands/delete/versions.ts @@ -9,7 +9,7 @@ import { throwIfEmpty } from '../../utils/index.js'; * @throws Will throw if keys is empty */ export const deleteContentVersions = - (keys: DirectusVersion['id'][]): RestCommand => + (keys: DirectusVersion['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteContentVersions = * @throws Will throw if key is empty */ export const deleteContentVersion = - (key: DirectusVersion['id']): RestCommand => + (key: DirectusVersion['id']): RestCommand => () => { throwIfEmpty(key, 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/delete/webhooks.ts b/sdk/src/rest/commands/delete/webhooks.ts index 499644e605..1724971ebe 100644 --- a/sdk/src/rest/commands/delete/webhooks.ts +++ b/sdk/src/rest/commands/delete/webhooks.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @throws Will throw if keys is empty */ export const deleteWebhooks = - (keys: DirectusWebhook['id'][]): RestCommand => + (keys: DirectusWebhook['id'][]): RestCommand => () => { throwIfEmpty(keys, 'Keys cannot be empty'); @@ -27,7 +27,7 @@ export const deleteWebhooks = * @throws Will throw if key is empty */ export const deleteWebhook = - (key: DirectusWebhook['id']): RestCommand => + (key: DirectusWebhook['id']): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/read/activity.ts b/sdk/src/rest/commands/read/activity.ts index fe3e9fbeb5..3d9228bec3 100644 --- a/sdk/src/rest/commands/read/activity.ts +++ b/sdk/src/rest/commands/read/activity.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadActivityOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusActivity, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadActivityOutput< * @returns An array of up to limit activity objects. If no items are available, data will be an empty array. */ export const readActivities = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readActivities = * @throws Will throw if key is empty */ export const readActivity = - >>( + >>( key: DirectusActivity['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/aggregate.ts b/sdk/src/rest/commands/read/aggregate.ts index 7b6da284fa..bdc3150212 100644 --- a/sdk/src/rest/commands/read/aggregate.ts +++ b/sdk/src/rest/commands/read/aggregate.ts @@ -12,11 +12,7 @@ import { isSystemCollection } from '@directus/system-data'; * @throws Will throw if collection is empty */ export const aggregate = - < - Schema extends object, - Collection extends AllCollections, - Options extends AggregationOptions, - >( + , Options extends AggregationOptions>( collection: Collection, options: Options, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/assets.ts b/sdk/src/rest/commands/read/assets.ts index 1471908f77..da85cbb3b9 100644 --- a/sdk/src/rest/commands/read/assets.ts +++ b/sdk/src/rest/commands/read/assets.ts @@ -11,10 +11,7 @@ import type { RestCommand } from '../../types.js'; * @returns {ReadableStream} */ export const readAssetRaw = - ( - key: DirectusFile['id'], - query?: AssetsQuery, - ): RestCommand, Schema> => + (key: DirectusFile['id'], query?: AssetsQuery): RestCommand, Schema> => () => { throwIfEmpty(String(key), 'Key cannot be empty'); @@ -34,7 +31,7 @@ export const readAssetRaw = * @returns {Blob} */ export const readAssetBlob = - (key: DirectusFile['id'], query?: AssetsQuery): RestCommand => + (key: DirectusFile['id'], query?: AssetsQuery): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); @@ -54,7 +51,7 @@ export const readAssetBlob = * @returns {ArrayBuffer} */ export const readAssetArrayBuffer = - (key: DirectusFile['id'], query?: AssetsQuery): RestCommand => + (key: DirectusFile['id'], query?: AssetsQuery): RestCommand => () => { throwIfEmpty(String(key), 'Key cannot be empty'); diff --git a/sdk/src/rest/commands/read/collections.ts b/sdk/src/rest/commands/read/collections.ts index 3f13e66b7b..7586e44e2d 100644 --- a/sdk/src/rest/commands/read/collections.ts +++ b/sdk/src/rest/commands/read/collections.ts @@ -3,17 +3,18 @@ import type { ApplyQueryFields } from '../../../types/index.js'; import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; -export type ReadCollectionOutput< - Schema extends object, - Item extends object = DirectusCollection, -> = ApplyQueryFields; +export type ReadCollectionOutput> = ApplyQueryFields< + Schema, + Item, + '*' +>; /** * List the available collections. * @returns An array of collection objects. */ export const readCollections = - (): RestCommand[], Schema> => + (): RestCommand[], Schema> => () => ({ path: `/collections`, method: 'GET', @@ -26,9 +27,7 @@ export const readCollections = * @throws Will throw if collection is empty */ export const readCollection = - ( - collection: DirectusCollection['collection'], - ): RestCommand, Schema> => + (collection: DirectusCollection['collection']): RestCommand, Schema> => () => { throwIfEmpty(collection, 'Collection cannot be empty'); diff --git a/sdk/src/rest/commands/read/dashboards.ts b/sdk/src/rest/commands/read/dashboards.ts index cdf96d6536..74a46e070d 100644 --- a/sdk/src/rest/commands/read/dashboards.ts +++ b/sdk/src/rest/commands/read/dashboards.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadDashboardOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusDashboard, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadDashboardOutput< * @returns An array of up to limit dashboard objects. If no items are available, data will be an empty array. */ export const readDashboards = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readDashboards = * @throws Will throw if key is empty */ export const readDashboard = - >>( + >>( key: DirectusDashboard['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/extensions.ts b/sdk/src/rest/commands/read/extensions.ts index 4abb6c750a..454fb8ece0 100644 --- a/sdk/src/rest/commands/read/extensions.ts +++ b/sdk/src/rest/commands/read/extensions.ts @@ -6,7 +6,7 @@ import type { RestCommand } from '../../types.js'; * @returns An array of extensions. */ export const readExtensions = - (): RestCommand[], Schema> => + (): RestCommand[], Schema> => () => ({ path: `/extensions/`, method: 'GET', diff --git a/sdk/src/rest/commands/read/fields.ts b/sdk/src/rest/commands/read/fields.ts index d4e05e47ab..33cfc84947 100644 --- a/sdk/src/rest/commands/read/fields.ts +++ b/sdk/src/rest/commands/read/fields.ts @@ -3,11 +3,7 @@ import type { ApplyQueryFields } from '../../../types/index.js'; import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; -export type ReadFieldOutput> = ApplyQueryFields< - Schema, - Item, - '*' ->; +export type ReadFieldOutput> = ApplyQueryFields; /** * List the available fields. @@ -15,7 +11,7 @@ export type ReadFieldOutput(): RestCommand[], Schema> => + (): RestCommand[], Schema> => () => ({ path: `/fields`, method: 'GET', @@ -28,9 +24,7 @@ export const readFields = * @throws Will throw if collection is empty */ export const readFieldsByCollection = - ( - collection: DirectusField['collection'], - ): RestCommand[], Schema> => + (collection: DirectusField['collection']): RestCommand[], Schema> => () => { throwIfEmpty(collection, 'Collection cannot be empty'); @@ -49,7 +43,7 @@ export const readFieldsByCollection = * @throws Will throw if field is empty */ export const readField = - ( + ( collection: DirectusField['collection'], field: DirectusField['field'], ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/files.ts b/sdk/src/rest/commands/read/files.ts index c63585ffdf..0398971efd 100644 --- a/sdk/src/rest/commands/read/files.ts +++ b/sdk/src/rest/commands/read/files.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadFileOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFile, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadFileOutput< * @returns An array of up to limit file objects. If no items are available, data will be an empty array. */ export const readFiles = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readFiles = * @throws Will throw if key is empty */ export const readFile = - >>( + >>( key: DirectusFile['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/flows.ts b/sdk/src/rest/commands/read/flows.ts index 41fe234f83..cd874c5bfe 100644 --- a/sdk/src/rest/commands/read/flows.ts +++ b/sdk/src/rest/commands/read/flows.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadFlowOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFlow, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadFlowOutput< * @returns An array of up to limit flow objects. If no items are available, data will be an empty array. */ export const readFlows = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readFlows = * @throws Will throw if key is empty */ export const readFlow = - >>( + >>( key: DirectusFlow['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/folders.ts b/sdk/src/rest/commands/read/folders.ts index 97e4e2b140..90f873f0d7 100644 --- a/sdk/src/rest/commands/read/folders.ts +++ b/sdk/src/rest/commands/read/folders.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadFolderOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFolder, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadFolderOutput< * @returns An array of up to limit folder objects. If no items are available, data will be an empty array. */ export const readFolders = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readFolders = * @throws Will throw if key is empty */ export const readFolder = - >>( + >>( key: DirectusFolder['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/items.ts b/sdk/src/rest/commands/read/items.ts index 3868fb3836..1f85b949a0 100644 --- a/sdk/src/rest/commands/read/items.ts +++ b/sdk/src/rest/commands/read/items.ts @@ -3,7 +3,7 @@ import { throwIfEmpty, throwIfCoreCollection } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadItemOutput< - Schema extends object, + Schema, Collection extends RegularCollections, TQuery extends Query>, > = ApplyQueryFields, TQuery['fields']>; @@ -20,7 +20,7 @@ export type ReadItemOutput< */ export const readItems = < - Schema extends object, + Schema, Collection extends RegularCollections, const TQuery extends Query>, >( @@ -52,7 +52,7 @@ export const readItems = */ export const readItem = < - Schema extends object, + Schema, Collection extends RegularCollections, const TQuery extends QueryItem>, >( diff --git a/sdk/src/rest/commands/read/notifications.ts b/sdk/src/rest/commands/read/notifications.ts index 588076af0a..2fc5500983 100644 --- a/sdk/src/rest/commands/read/notifications.ts +++ b/sdk/src/rest/commands/read/notifications.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadNotificationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusNotification, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadNotificationOutput< * @returns An array of up to limit notification objects. If no items are available, data will be an empty array. */ export const readNotifications = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readNotifications = * @throws Will throw if key is empty */ export const readNotification = - >>( + >>( key: DirectusNotification['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/operations.ts b/sdk/src/rest/commands/read/operations.ts index 79d0ee4f1c..b906064eeb 100644 --- a/sdk/src/rest/commands/read/operations.ts +++ b/sdk/src/rest/commands/read/operations.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadOperationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusOperation, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadOperationOutput< * @returns An array of up to limit operation objects. If no items are available, data will be an empty array. */ export const readOperations = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readOperations = * @throws Will throw if key is empty */ export const readOperation = - >>( + >>( key: DirectusOperation['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/panels.ts b/sdk/src/rest/commands/read/panels.ts index 88818fc566..530f6db490 100644 --- a/sdk/src/rest/commands/read/panels.ts +++ b/sdk/src/rest/commands/read/panels.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadPanelOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPanel, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadPanelOutput< * @returns An array of up to limit panel objects. If no items are available, data will be an empty array. */ export const readPanels = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readPanels = * @throws Will throw if key is empty */ export const readPanel = - >>( + >>( key: DirectusPanel['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/permissions.ts b/sdk/src/rest/commands/read/permissions.ts index 87a9571f8c..fc3179011d 100644 --- a/sdk/src/rest/commands/read/permissions.ts +++ b/sdk/src/rest/commands/read/permissions.ts @@ -4,7 +4,7 @@ import type { RestCommand } from '../../types.js'; import { throwIfEmpty } from '../../utils/index.js'; export type ReadPermissionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPermission, > = ApplyQueryFields; @@ -21,7 +21,7 @@ export type ReadItemPermissionsOutput = { * @returns An array of up to limit Permission objects. If no items are available, data will be an empty array. */ export const readPermissions = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -38,7 +38,7 @@ export const readPermissions = * @throws Will throw if key is empty */ export const readPermission = - >>( + >>( key: DirectusPermission['id'], query?: TQuery, ): RestCommand, Schema> => @@ -59,7 +59,7 @@ export const readPermission = * @returns Returns a ItemPermissions object if a valid collection / primary key was provided. */ export const readItemPermissions = - >( + >( collection: Collection, key?: string | number, ): RestCommand => diff --git a/sdk/src/rest/commands/read/presets.ts b/sdk/src/rest/commands/read/presets.ts index cbd0b1613a..ac12371114 100644 --- a/sdk/src/rest/commands/read/presets.ts +++ b/sdk/src/rest/commands/read/presets.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadPresetOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPreset, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadPresetOutput< * @returns An array of up to limit Preset objects. If no items are available, data will be an empty array. */ export const readPresets = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readPresets = * @throws Will throw if key is empty */ export const readPreset = - >>( + >>( key: DirectusPreset['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/relations.ts b/sdk/src/rest/commands/read/relations.ts index 42297aed20..10cf3200aa 100644 --- a/sdk/src/rest/commands/read/relations.ts +++ b/sdk/src/rest/commands/read/relations.ts @@ -3,10 +3,11 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; -export type ReadRelationOutput< - Schema extends object, - Item extends object = DirectusRelation, -> = ApplyQueryFields; +export type ReadRelationOutput> = ApplyQueryFields< + Schema, + Item, + '*' +>; /** * List all Relations that exist in Directus. @@ -14,7 +15,7 @@ export type ReadRelationOutput< * @returns An array of up to limit Relation objects. If no items are available, data will be an empty array. */ export const readRelations = - (): RestCommand[], Schema> => + (): RestCommand[], Schema> => () => ({ path: `/relations`, method: 'GET', @@ -27,9 +28,7 @@ export const readRelations = * @throws Will throw if collection is empty */ export const readRelationByCollection = - ( - collection: DirectusRelation['collection'], - ): RestCommand, Schema> => + (collection: DirectusRelation['collection']): RestCommand, Schema> => () => ({ path: `/relations/${collection}`, method: 'GET', @@ -44,7 +43,7 @@ export const readRelationByCollection = * @throws Will throw if field is empty */ export const readRelation = - >>( + >>( collection: DirectusRelation['collection'], field: DirectusRelation['field'], ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/revisions.ts b/sdk/src/rest/commands/read/revisions.ts index 78c1a0001d..c58afd31e7 100644 --- a/sdk/src/rest/commands/read/revisions.ts +++ b/sdk/src/rest/commands/read/revisions.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadRevisionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusRevision, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadRevisionOutput< * @returns An array of up to limit Revision objects. If no items are available, data will be an empty array. */ export const readRevisions = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readRevisions = * @throws Will throw if key is empty */ export const readRevision = - >>( + >>( key: DirectusRevision['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/roles.ts b/sdk/src/rest/commands/read/roles.ts index 7f9d774839..fa18ba68cd 100644 --- a/sdk/src/rest/commands/read/roles.ts +++ b/sdk/src/rest/commands/read/roles.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadRoleOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusRole, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadRoleOutput< * @returns An array of up to limit Role objects. If no items are available, data will be an empty array. */ export const readRoles = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readRoles = * @throws Will throw if key is empty */ export const readRole = - >>( + >>( key: DirectusRole['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/settings.ts b/sdk/src/rest/commands/read/settings.ts index 8f08cbdd9c..22709d181b 100644 --- a/sdk/src/rest/commands/read/settings.ts +++ b/sdk/src/rest/commands/read/settings.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type ReadSettingOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusSettings, > = ApplyQueryFields; @@ -16,7 +16,7 @@ export type ReadSettingOutput< * @returns Returns the settings object. */ export const readSettings = - >>( + >>( query?: TQuery, ): RestCommand, Schema> => () => ({ diff --git a/sdk/src/rest/commands/read/shares.ts b/sdk/src/rest/commands/read/shares.ts index 4385e9d106..73e71b302d 100644 --- a/sdk/src/rest/commands/read/shares.ts +++ b/sdk/src/rest/commands/read/shares.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadShareOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusShare, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadShareOutput< * @returns An array of up to limit Share objects. If no items are available, data will be an empty array. */ export const readShares = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readShares = * @throws Will throw if key is empty */ export const readShare = - >>( + >>( key: DirectusShare['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/singleton.ts b/sdk/src/rest/commands/read/singleton.ts index 5a92b87716..41a0ef4f5d 100644 --- a/sdk/src/rest/commands/read/singleton.ts +++ b/sdk/src/rest/commands/read/singleton.ts @@ -3,7 +3,7 @@ import { throwIfCoreCollection, throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadSingletonOutput< - Schema extends object, + Schema, Collection extends SingletonCollections, TQuery extends Query, > = ApplyQueryFields, TQuery['fields']>; @@ -19,11 +19,7 @@ export type ReadSingletonOutput< * @throws Will throw if collection is empty */ export const readSingleton = - < - Schema extends object, - Collection extends SingletonCollections, - const TQuery extends QueryItem, - >( + , const TQuery extends QueryItem>( collection: Collection, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/translations.ts b/sdk/src/rest/commands/read/translations.ts index 7b5fcc2060..f1ca0b6cc5 100644 --- a/sdk/src/rest/commands/read/translations.ts +++ b/sdk/src/rest/commands/read/translations.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadTranslationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusTranslation, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadTranslationOutput< * @returns An array of up to limit Translation objects. If no items are available, data will be an empty array. */ export const readTranslations = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readTranslations = * @throws Will throw if key is empty */ export const readTranslation = - >>( + >>( key: DirectusTranslation['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/users.ts b/sdk/src/rest/commands/read/users.ts index 958eb0a4d4..c46ec26f2a 100644 --- a/sdk/src/rest/commands/read/users.ts +++ b/sdk/src/rest/commands/read/users.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadUserOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusUser, > = ApplyQueryFields; @@ -17,7 +17,7 @@ export type ReadUserOutput< * @returns An array of up to limit user objects. If no items are available, data will be an empty array. */ export const readUsers = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -36,7 +36,7 @@ export const readUsers = * @throws Will throw if key is empty */ export const readUser = - >>( + >>( key: DirectusUser['id'], query?: TQuery, ): RestCommand, Schema> => @@ -58,7 +58,7 @@ export const readUser = * @returns Returns the user object for the currently authenticated user. */ export const readMe = - >>( + >>( query?: TQuery, ): RestCommand, Schema> => () => ({ diff --git a/sdk/src/rest/commands/read/versions.ts b/sdk/src/rest/commands/read/versions.ts index fbc5f55e2d..6433b91aa6 100644 --- a/sdk/src/rest/commands/read/versions.ts +++ b/sdk/src/rest/commands/read/versions.ts @@ -4,7 +4,7 @@ import type { RestCommand } from '../../types.js'; import { throwIfEmpty } from '../../utils/index.js'; export type ReadContentVersionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusVersion, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadContentVersionOutput< * @returns An array of up to limit Content Version objects. If no items are available, data will be an empty array. */ export const readContentVersions = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readContentVersions = * @throws Will throw if key is empty */ export const readContentVersion = - >>( + >>( key: DirectusVersion['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/read/webhooks.ts b/sdk/src/rest/commands/read/webhooks.ts index ec9309ce0a..f314aad939 100644 --- a/sdk/src/rest/commands/read/webhooks.ts +++ b/sdk/src/rest/commands/read/webhooks.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type ReadWebhookOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusWebhook, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type ReadWebhookOutput< * @returns An array of up to limit Webhook objects. If no items are available, data will be an empty array. */ export const readWebhooks = - >>( + >>( query?: TQuery, ): RestCommand[], Schema> => () => ({ @@ -32,7 +32,7 @@ export const readWebhooks = * @throws Will throw if key is empty */ export const readWebhook = - >>( + >>( key: DirectusWebhook['id'], query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/schema/apply.ts b/sdk/src/rest/commands/schema/apply.ts index 8f81d121e2..c4b231fd06 100644 --- a/sdk/src/rest/commands/schema/apply.ts +++ b/sdk/src/rest/commands/schema/apply.ts @@ -7,7 +7,7 @@ import type { SchemaDiffOutput } from './diff.js'; * @returns Empty body. */ export const schemaApply = - (diff: SchemaDiffOutput): RestCommand => + (diff: SchemaDiffOutput): RestCommand => () => ({ method: 'POST', path: '/schema/apply', diff --git a/sdk/src/rest/commands/schema/diff.ts b/sdk/src/rest/commands/schema/diff.ts index f9e6b4d275..a37fbfe2d3 100644 --- a/sdk/src/rest/commands/schema/diff.ts +++ b/sdk/src/rest/commands/schema/diff.ts @@ -14,7 +14,7 @@ export type SchemaDiffOutput = { * @returns Returns the differences between the current instance's schema and the schema passed in the request body. */ export const schemaDiff = - (snapshot: SchemaSnapshotOutput, force = false): RestCommand => + (snapshot: SchemaSnapshotOutput, force = false): RestCommand => () => ({ method: 'POST', path: '/schema/diff', diff --git a/sdk/src/rest/commands/schema/snapshot.ts b/sdk/src/rest/commands/schema/snapshot.ts index a89ec3e9eb..2c4bd4c0e0 100644 --- a/sdk/src/rest/commands/schema/snapshot.ts +++ b/sdk/src/rest/commands/schema/snapshot.ts @@ -15,7 +15,7 @@ export type SchemaSnapshotOutput = { * @returns Returns the JSON object containing schema details. */ export const schemaSnapshot = - (): RestCommand => + (): RestCommand => () => ({ method: 'GET', path: '/schema/snapshot', diff --git a/sdk/src/rest/commands/server/graphql.ts b/sdk/src/rest/commands/server/graphql.ts index 94901fde23..204b6c7762 100644 --- a/sdk/src/rest/commands/server/graphql.ts +++ b/sdk/src/rest/commands/server/graphql.ts @@ -5,7 +5,7 @@ import type { RestCommand } from '../../types.js'; * @returns GraphQL SDL. */ export const readGraphqlSdl = - (scope: 'item' | 'system' = 'item'): RestCommand => + (scope: 'item' | 'system' = 'item'): RestCommand => () => ({ method: 'GET', path: scope === 'item' ? '/server/specs/graphql' : '/server/specs/graphql/system', diff --git a/sdk/src/rest/commands/server/health.ts b/sdk/src/rest/commands/server/health.ts index d2fa8799d5..3035f0a900 100644 --- a/sdk/src/rest/commands/server/health.ts +++ b/sdk/src/rest/commands/server/health.ts @@ -14,7 +14,7 @@ export type ServerHealthOutput = { * @returns The current health status of the server. */ export const serverHealth = - (): RestCommand => + (): RestCommand => () => ({ method: 'GET', path: '/server/health', diff --git a/sdk/src/rest/commands/server/info.ts b/sdk/src/rest/commands/server/info.ts index e8c94df453..411d46f825 100644 --- a/sdk/src/rest/commands/server/info.ts +++ b/sdk/src/rest/commands/server/info.ts @@ -46,7 +46,7 @@ export type ServerInfoOutput = { * @returns Information about the current installation. */ export const serverInfo = - (): RestCommand => + (): RestCommand => () => ({ method: 'GET', path: '/server/info', diff --git a/sdk/src/rest/commands/server/openapi.ts b/sdk/src/rest/commands/server/openapi.ts index b9bfc99563..52c809ba31 100644 --- a/sdk/src/rest/commands/server/openapi.ts +++ b/sdk/src/rest/commands/server/openapi.ts @@ -8,7 +8,7 @@ export type OpenApiSpecOutput = Record; * @returns Object conforming to the OpenAPI Specification */ export const readOpenApiSpec = - (): RestCommand => + (): RestCommand => () => ({ method: 'GET', path: '/server/specs/oas', diff --git a/sdk/src/rest/commands/server/ping.ts b/sdk/src/rest/commands/server/ping.ts index d8440b53fe..b437c777fb 100644 --- a/sdk/src/rest/commands/server/ping.ts +++ b/sdk/src/rest/commands/server/ping.ts @@ -5,7 +5,7 @@ import type { RestCommand } from '../../types.js'; * @returns Pong */ export const serverPing = - (): RestCommand => + (): RestCommand => () => ({ method: 'GET', path: '/server/ping', diff --git a/sdk/src/rest/commands/update/activity.ts b/sdk/src/rest/commands/update/activity.ts index f90e8c1f29..b46fe74d97 100644 --- a/sdk/src/rest/commands/update/activity.ts +++ b/sdk/src/rest/commands/update/activity.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateActivityOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusActivity, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateActivityOutput< * @throws Will throw if key is empty */ export const updateComment = - >>( + >>( key: DirectusActivity['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/collections.ts b/sdk/src/rest/commands/update/collections.ts index 5ecb91e07a..389740f1ce 100644 --- a/sdk/src/rest/commands/update/collections.ts +++ b/sdk/src/rest/commands/update/collections.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateCollectionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusCollection, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateCollectionOutput< * @throws Will throw if collection is empty */ export const updateCollection = - >>( + >>( collection: DirectusCollection['collection'], item: NestedPartial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/dashboards.ts b/sdk/src/rest/commands/update/dashboards.ts index ea8d40ef32..1003b16563 100644 --- a/sdk/src/rest/commands/update/dashboards.ts +++ b/sdk/src/rest/commands/update/dashboards.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateDashboardOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusDashboard, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateDashboardOutput< * @throws Will throw if keys is empty */ export const updateDashboards = - >>( + >>( keys: DirectusDashboard['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateDashboards = * @throws Will throw if key is empty */ export const updateDashboard = - >>( + >>( key: DirectusDashboard['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/extensions.ts b/sdk/src/rest/commands/update/extensions.ts index b57a954a42..6d9c5df46a 100644 --- a/sdk/src/rest/commands/update/extensions.ts +++ b/sdk/src/rest/commands/update/extensions.ts @@ -11,7 +11,7 @@ import { throwIfEmpty } from '../../utils/index.js'; * @returns Returns the extension that was updated */ export const updateExtension = - ( + ( bundle: string | null, name: string, data: NestedPartial>, diff --git a/sdk/src/rest/commands/update/fields.ts b/sdk/src/rest/commands/update/fields.ts index 17a4091121..9442393988 100644 --- a/sdk/src/rest/commands/update/fields.ts +++ b/sdk/src/rest/commands/update/fields.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateFieldOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusField, > = ApplyQueryFields; @@ -20,7 +20,7 @@ export type UpdateFieldOutput< * @throws Will throw if field is empty */ export const updateField = - >>( + >>( collection: DirectusField['collection'], field: DirectusField['field'], item: NestedPartial>, diff --git a/sdk/src/rest/commands/update/files.ts b/sdk/src/rest/commands/update/files.ts index 61e5b395b9..329f1a5c61 100644 --- a/sdk/src/rest/commands/update/files.ts +++ b/sdk/src/rest/commands/update/files.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateFileOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFile, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateFileOutput< * @throws Will throw if keys is empty */ export const updateFiles = - >>( + >>( keys: DirectusFile['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateFiles = * @throws Will throw if key is empty */ export const updateFile = - >>( + >>( key: DirectusFile['id'], item: Partial> | FormData, query?: TQuery, diff --git a/sdk/src/rest/commands/update/flows.ts b/sdk/src/rest/commands/update/flows.ts index 4ce73b072d..807c98432d 100644 --- a/sdk/src/rest/commands/update/flows.ts +++ b/sdk/src/rest/commands/update/flows.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateFlowOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFlow, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateFlowOutput< * @throws Will throw if keys is empty */ export const updateFlows = - >>( + >>( keys: DirectusFlow['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateFlows = * @throws Will throw if key is empty */ export const updateFlow = - >>( + >>( key: DirectusFlow['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/folders.ts b/sdk/src/rest/commands/update/folders.ts index 7e2541febf..75946625c4 100644 --- a/sdk/src/rest/commands/update/folders.ts +++ b/sdk/src/rest/commands/update/folders.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateFolderOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusFolder, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateFolderOutput< * @throws Will throw if keys is empty */ export const updateFolders = - >>( + >>( keys: DirectusFolder['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateFolders = * @throws Will throw if key is empty */ export const updateFolder = - >>( + >>( key: DirectusFolder['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/items.ts b/sdk/src/rest/commands/update/items.ts index 340d89add4..df1d2cb7a3 100644 --- a/sdk/src/rest/commands/update/items.ts +++ b/sdk/src/rest/commands/update/items.ts @@ -3,7 +3,7 @@ import type { RestCommand } from '../../types.js'; import { throwIfCoreCollection, throwIfEmpty } from '../../utils/index.js'; export type UpdateItemOutput< - Schema extends object, + Schema, Collection extends keyof Schema, TQuery extends Query, > = ApplyQueryFields, TQuery['fields']>; @@ -22,7 +22,7 @@ export type UpdateItemOutput< * @throws Will throw if collection is a core collection */ export const updateItems = - >( + >( collection: Collection, keysOrQuery: string[] | number[] | Query, item: Partial>, @@ -66,7 +66,7 @@ export const updateItems = */ export const updateItem = < - Schema extends object, + Schema, Collection extends keyof Schema, const TQuery extends Query, Item = UnpackList, diff --git a/sdk/src/rest/commands/update/notifications.ts b/sdk/src/rest/commands/update/notifications.ts index 365b26a742..4eeee12362 100644 --- a/sdk/src/rest/commands/update/notifications.ts +++ b/sdk/src/rest/commands/update/notifications.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateNotificationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusNotification, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateNotificationOutput< * @throws Will throw if keys is empty */ export const updateNotifications = - >>( + >>( keys: DirectusNotification['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateNotifications = * @throws Will throw if key is empty */ export const updateNotification = - >>( + >>( key: DirectusNotification['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/operations.ts b/sdk/src/rest/commands/update/operations.ts index b464191ead..fbee5af1ea 100644 --- a/sdk/src/rest/commands/update/operations.ts +++ b/sdk/src/rest/commands/update/operations.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateOperationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusOperation, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateOperationOutput< * @throws Will throw if keys is empty */ export const updateOperations = - >>( + >>( keys: DirectusOperation['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateOperations = * @throws Will throw if key is empty */ export const updateOperation = - >>( + >>( key: DirectusOperation['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/panels.ts b/sdk/src/rest/commands/update/panels.ts index effa3f90af..503d7dc7fb 100644 --- a/sdk/src/rest/commands/update/panels.ts +++ b/sdk/src/rest/commands/update/panels.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdatePanelOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPanel, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdatePanelOutput< * @throws Will throw if keys is empty */ export const updatePanels = - >>( + >>( keys: DirectusPanel['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updatePanels = * @throws Will throw if key is empty */ export const updatePanel = - >>( + >>( key: DirectusPanel['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/permissions.ts b/sdk/src/rest/commands/update/permissions.ts index b966c968e6..640f2d1fe5 100644 --- a/sdk/src/rest/commands/update/permissions.ts +++ b/sdk/src/rest/commands/update/permissions.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdatePermissionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPermission, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdatePermissionOutput< * @throws Will throw if keys is empty */ export const updatePermissions = - >>( + >>( keys: DirectusPermission['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updatePermissions = * @throws Will throw if key is empty */ export const updatePermission = - >>( + >>( key: DirectusPermission['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/presets.ts b/sdk/src/rest/commands/update/presets.ts index b53dbaac28..6da9a4bbfb 100644 --- a/sdk/src/rest/commands/update/presets.ts +++ b/sdk/src/rest/commands/update/presets.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdatePresetOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusPreset, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdatePresetOutput< * @throws Will throw if keys is empty */ export const updatePresets = - >>( + >>( keys: DirectusPreset['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updatePresets = * @throws Will throw if key is empty */ export const updatePreset = - >>( + >>( key: DirectusPreset['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/relations.ts b/sdk/src/rest/commands/update/relations.ts index 8213cf6ec4..7855d893cf 100644 --- a/sdk/src/rest/commands/update/relations.ts +++ b/sdk/src/rest/commands/update/relations.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateRelationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusRelation, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateRelationOutput< * @returns Returns the relation object for the created relation. */ export const updateRelation = - >>( + >>( collection: DirectusRelation['collection'], field: DirectusRelation['field'], item: NestedPartial>, diff --git a/sdk/src/rest/commands/update/roles.ts b/sdk/src/rest/commands/update/roles.ts index ba931bd270..08b83dab8f 100644 --- a/sdk/src/rest/commands/update/roles.ts +++ b/sdk/src/rest/commands/update/roles.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateRoleOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusRole, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateRoleOutput< * @throws Will throw if keys is empty */ export const updateRoles = - >>( + >>( keys: DirectusRole['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateRoles = * @throws Will throw if key is empty */ export const updateRole = - >>( + >>( key: DirectusRole['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/settings.ts b/sdk/src/rest/commands/update/settings.ts index d20ae10241..2a3de42c57 100644 --- a/sdk/src/rest/commands/update/settings.ts +++ b/sdk/src/rest/commands/update/settings.ts @@ -3,7 +3,7 @@ import type { ApplyQueryFields, Query } from '../../../types/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateSettingOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusSettings, > = ApplyQueryFields; @@ -15,7 +15,7 @@ export type UpdateSettingOutput< * @returns Returns the settings object. */ export const updateSettings = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand[], Schema> => diff --git a/sdk/src/rest/commands/update/shares.ts b/sdk/src/rest/commands/update/shares.ts index acf012a5ae..3f7656f6a0 100644 --- a/sdk/src/rest/commands/update/shares.ts +++ b/sdk/src/rest/commands/update/shares.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateShareOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusShare, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateShareOutput< * @throws Will throw if keys is empty */ export const updateShares = - >>( + >>( keys: DirectusShare['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateShares = * @throws Will throw if key is empty */ export const updateShare = - >>( + >>( key: DirectusShare['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/singleton.ts b/sdk/src/rest/commands/update/singleton.ts index 3b3f382b26..e0be65d6f0 100644 --- a/sdk/src/rest/commands/update/singleton.ts +++ b/sdk/src/rest/commands/update/singleton.ts @@ -3,7 +3,7 @@ import type { RestCommand } from '../../types.js'; import { throwIfCoreCollection, throwIfEmpty } from '../../utils/index.js'; export type UpdateSingletonOutput< - Schema extends object, + Schema, Collection extends SingletonCollections, TQuery extends Query, > = ApplyQueryFields, TQuery['fields']>; @@ -20,7 +20,7 @@ export type UpdateSingletonOutput< */ export const updateSingleton = < - Schema extends object, + Schema, Collection extends SingletonCollections, const TQuery extends Query, Item = Schema[Collection], diff --git a/sdk/src/rest/commands/update/translations.ts b/sdk/src/rest/commands/update/translations.ts index 5bacfd5c01..dc8eee503c 100644 --- a/sdk/src/rest/commands/update/translations.ts +++ b/sdk/src/rest/commands/update/translations.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateTranslationOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusTranslation, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateTranslationOutput< * @throws Will throw if keys is empty */ export const updateTranslations = - >>( + >>( keys: DirectusTranslation['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateTranslations = * @throws Will throw if key is empty */ export const updateTranslation = - >>( + >>( key: DirectusTranslation['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/users.ts b/sdk/src/rest/commands/update/users.ts index 3d877bc467..f8f4185d67 100644 --- a/sdk/src/rest/commands/update/users.ts +++ b/sdk/src/rest/commands/update/users.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { DirectusUser } from '../../../schema/user.js'; export type UpdateUserOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusUser, > = ApplyQueryFields; @@ -20,7 +20,7 @@ export type UpdateUserOutput< * @throws Will throw if keys is empty */ export const updateUsers = - >>( + >>( keys: DirectusUser['id'][], item: Partial>, query?: TQuery, @@ -47,7 +47,7 @@ export const updateUsers = * @throws Will throw if key is empty */ export const updateUser = - >>( + >>( key: DirectusUser['id'], item: Partial>, query?: TQuery, @@ -72,7 +72,7 @@ export const updateUser = * @returns Returns the updated user object for the authenticated user. */ export const updateMe = - >>( + >>( item: Partial>, query?: TQuery, ): RestCommand, Schema> => diff --git a/sdk/src/rest/commands/update/versions.ts b/sdk/src/rest/commands/update/versions.ts index b3a34cc80a..88ee608a62 100644 --- a/sdk/src/rest/commands/update/versions.ts +++ b/sdk/src/rest/commands/update/versions.ts @@ -4,7 +4,7 @@ import type { RestCommand } from '../../types.js'; import { throwIfEmpty } from '../../utils/index.js'; export type UpdateContentVersionOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusVersion, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateContentVersionOutput< * @throws Will throw if keys is empty */ export const updateContentVersions = - >>( + >>( keys: DirectusVersion['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateContentVersions = * @throws Will throw if key is empty */ export const updateContentVersion = - >>( + >>( key: DirectusVersion['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/update/webhooks.ts b/sdk/src/rest/commands/update/webhooks.ts index fdde442642..2fbfe101cd 100644 --- a/sdk/src/rest/commands/update/webhooks.ts +++ b/sdk/src/rest/commands/update/webhooks.ts @@ -4,7 +4,7 @@ import { throwIfEmpty } from '../../utils/index.js'; import type { RestCommand } from '../../types.js'; export type UpdateWebhookOutput< - Schema extends object, + Schema, TQuery extends Query, Item extends object = DirectusWebhook, > = ApplyQueryFields; @@ -18,7 +18,7 @@ export type UpdateWebhookOutput< * @throws Will throw if keys is empty */ export const updateWebhooks = - >>( + >>( keys: DirectusWebhook['id'][], item: Partial>, query?: TQuery, @@ -43,7 +43,7 @@ export const updateWebhooks = * @throws Will throw if key is empty */ export const updateWebhook = - >>( + >>( key: DirectusWebhook['id'], item: Partial>, query?: TQuery, diff --git a/sdk/src/rest/commands/utils/cache.ts b/sdk/src/rest/commands/utils/cache.ts index 9b8c4839f5..ddf172beab 100644 --- a/sdk/src/rest/commands/utils/cache.ts +++ b/sdk/src/rest/commands/utils/cache.ts @@ -5,7 +5,7 @@ import type { RestCommand } from '../../types.js'; * @returns Nothing */ export const clearCache = - (): RestCommand => + (): RestCommand => () => ({ method: 'POST', path: `/utils/cache/clear`, diff --git a/sdk/src/rest/commands/utils/export.ts b/sdk/src/rest/commands/utils/export.ts index 81c8c7856c..665f7738a7 100644 --- a/sdk/src/rest/commands/utils/export.ts +++ b/sdk/src/rest/commands/utils/export.ts @@ -9,7 +9,7 @@ export type FileFormat = 'csv' | 'json' | 'xml' | 'yaml'; * @returns Nothing */ export const utilsExport = - , Collection extends keyof Schema>( + , Collection extends keyof Schema>( collection: Collection, format: FileFormat, query: TQuery, diff --git a/sdk/src/rest/commands/utils/flows.ts b/sdk/src/rest/commands/utils/flows.ts index 5191fe86f7..d63ab58364 100644 --- a/sdk/src/rest/commands/utils/flows.ts +++ b/sdk/src/rest/commands/utils/flows.ts @@ -10,11 +10,7 @@ import type { RestCommand } from '../../types.js'; * @returns Result of the flow, if any. */ export const triggerFlow = - ( - method: 'GET' | 'POST', - id: string, - data?: Record, - ): RestCommand => + (method: 'GET' | 'POST', id: string, data?: Record): RestCommand => () => { if (method === 'GET') { return { diff --git a/sdk/src/rest/commands/utils/hash.ts b/sdk/src/rest/commands/utils/hash.ts index 80e2a1e52f..1ceec5712f 100644 --- a/sdk/src/rest/commands/utils/hash.ts +++ b/sdk/src/rest/commands/utils/hash.ts @@ -6,7 +6,7 @@ import type { RestCommand } from '../../types.js'; * @returns Hashed string. */ export const generateHash = - (string: string): RestCommand => + (string: string): RestCommand => () => ({ method: 'POST', path: `/utils/hash/generate`, @@ -20,7 +20,7 @@ export const generateHash = * @returns Boolean. */ export const verifyHash = - (string: string, hash: string): RestCommand => + (string: string, hash: string): RestCommand => () => ({ method: 'POST', path: `/utils/hash/verify`, diff --git a/sdk/src/rest/commands/utils/import.ts b/sdk/src/rest/commands/utils/import.ts index 3be80a35db..7f5c75576d 100644 --- a/sdk/src/rest/commands/utils/import.ts +++ b/sdk/src/rest/commands/utils/import.ts @@ -5,7 +5,7 @@ import type { RestCommand } from '../../types.js'; * @returns Nothing */ export const utilsImport = - (collection: keyof Schema, data: FormData): RestCommand => + (collection: keyof Schema, data: FormData): RestCommand => () => ({ path: `/utils/import/${collection as string}`, method: 'POST', diff --git a/sdk/src/rest/commands/utils/operations.ts b/sdk/src/rest/commands/utils/operations.ts index efbb47a6fe..197cbac3cb 100644 --- a/sdk/src/rest/commands/utils/operations.ts +++ b/sdk/src/rest/commands/utils/operations.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../../types.js'; * @returns Result of the flow, if any. */ export const triggerOperation = - (id: string, data?: any): RestCommand => + (id: string, data?: any): RestCommand => () => ({ path: `/operations/trigger/${id}`, body: JSON.stringify(data ?? {}), diff --git a/sdk/src/rest/commands/utils/shares.ts b/sdk/src/rest/commands/utils/shares.ts index d97af26455..e6ca3ab360 100644 --- a/sdk/src/rest/commands/utils/shares.ts +++ b/sdk/src/rest/commands/utils/shares.ts @@ -11,7 +11,7 @@ import type { RestCommand } from '../../types.js'; * @returns Authentication data. */ export const authenticateShare = - ( + ( share: string, password?: string, mode: AuthenticationMode = 'cookie', @@ -30,7 +30,7 @@ export const authenticateShare = * @returns Nothing */ export const inviteShare = - (share: string, emails: string[]): RestCommand => + (share: string, emails: string[]): RestCommand => () => ({ path: `/shares/invite`, method: 'POST', @@ -45,7 +45,7 @@ export const inviteShare = * @returns The share objects for the given UUID, if it's still valid. */ export const readShareInfo = - ( + ( id: string, ): RestCommand< { diff --git a/sdk/src/rest/commands/utils/sort.ts b/sdk/src/rest/commands/utils/sort.ts index 0fe3cbbe52..e478d2941b 100644 --- a/sdk/src/rest/commands/utils/sort.ts +++ b/sdk/src/rest/commands/utils/sort.ts @@ -5,7 +5,7 @@ import type { RestCommand } from '../../types.js'; * @returns Nothing */ export const utilitySort = - (collection: keyof Schema, item: string, to: number): RestCommand => + (collection: keyof Schema, item: string, to: number): RestCommand => () => ({ method: 'POST', path: `/utils/sort/${collection as string}`, diff --git a/sdk/src/rest/commands/utils/users.ts b/sdk/src/rest/commands/utils/users.ts index a45a4325bb..9dda3bfabf 100644 --- a/sdk/src/rest/commands/utils/users.ts +++ b/sdk/src/rest/commands/utils/users.ts @@ -10,7 +10,7 @@ import type { RestCommand } from '../../types.js'; * @returns Nothing */ export const inviteUser = - (email: string, role: string, invite_url?: string): RestCommand => + (email: string, role: string, invite_url?: string): RestCommand => () => ({ path: `/users/invite`, method: 'POST', @@ -30,7 +30,7 @@ export const inviteUser = * @returns Nothing */ export const acceptUserInvite = - (token: string, password: string): RestCommand => + (token: string, password: string): RestCommand => () => ({ path: `/users/invite/accept`, method: 'POST', @@ -48,7 +48,7 @@ export const acceptUserInvite = * @returns A two-factor secret */ export const generateTwoFactorSecret = - (password: string): RestCommand<{ secret: string; otpauth_url: string }, Schema> => + (password: string): RestCommand<{ secret: string; otpauth_url: string }, Schema> => () => ({ path: `/users/me/tfa/generate`, method: 'POST', @@ -66,7 +66,7 @@ export const generateTwoFactorSecret = * @returns Nothing */ export const enableTwoFactor = - (secret: string, otp: string): RestCommand => + (secret: string, otp: string): RestCommand => () => ({ path: `/users/me/tfa/enable`, method: 'POST', @@ -84,7 +84,7 @@ export const enableTwoFactor = * @returns Nothing */ export const disableTwoFactor = - (otp: string): RestCommand => + (otp: string): RestCommand => () => ({ path: `/users/me/tfa/disable`, method: 'POST', diff --git a/sdk/src/rest/commands/utils/versions.ts b/sdk/src/rest/commands/utils/versions.ts index 02034bf19c..7ab52f6a9f 100644 --- a/sdk/src/rest/commands/utils/versions.ts +++ b/sdk/src/rest/commands/utils/versions.ts @@ -12,7 +12,7 @@ import { throwIfEmpty } from '../../utils/index.js'; * @returns State of the item after save. */ export const saveToContentVersion = - >( + >( id: DirectusVersion['id'], item: Partial, ): RestCommand => @@ -36,7 +36,7 @@ whether the Content Version is outdated (i.e. main version of the item has been Content Version) */ export const compareContentVersion = - >( + >( id: DirectusVersion['id'], ): RestCommand< { @@ -66,7 +66,7 @@ export const compareContentVersion = * @returns The primary key of the promoted item. */ export const promoteContentVersion = - >( + >( id: DirectusVersion['id'], mainHash: string, fields?: (keyof UnpackList)[], diff --git a/sdk/src/rest/composable.ts b/sdk/src/rest/composable.ts index 72195c67c0..840cf927c0 100644 --- a/sdk/src/rest/composable.ts +++ b/sdk/src/rest/composable.ts @@ -12,7 +12,7 @@ const defaultConfigValues: RestConfig = {}; * @returns A Directus REST client. */ export const rest = (config: Partial = {}) => { - return (client: DirectusClient): RestClient => { + return (client: DirectusClient): RestClient => { const restConfig = { ...defaultConfigValues, ...config }; return { async request(getOptions: RestCommand): Promise { diff --git a/sdk/src/rest/helpers/with-options.ts b/sdk/src/rest/helpers/with-options.ts index acd3bd06c0..820d9fe55b 100644 --- a/sdk/src/rest/helpers/with-options.ts +++ b/sdk/src/rest/helpers/with-options.ts @@ -9,7 +9,7 @@ import type { RestCommand } from '../types.js'; * * @returns */ -export function withOptions( +export function withOptions( getOptions: RestCommand, extraOptions: RequestTransformer | Partial, ): RestCommand { diff --git a/sdk/src/rest/helpers/with-search.ts b/sdk/src/rest/helpers/with-search.ts index 222cf17ff5..6c8e76ade3 100644 --- a/sdk/src/rest/helpers/with-search.ts +++ b/sdk/src/rest/helpers/with-search.ts @@ -1,9 +1,7 @@ import { formatFields } from '../index.js'; import type { RestCommand } from '../types.js'; -export function withSearch( - getOptions: RestCommand, -): RestCommand { +export function withSearch(getOptions: RestCommand): RestCommand { return () => { const options = getOptions(); diff --git a/sdk/src/rest/helpers/with-token.ts b/sdk/src/rest/helpers/with-token.ts index 83ac0c649b..68f379040c 100644 --- a/sdk/src/rest/helpers/with-token.ts +++ b/sdk/src/rest/helpers/with-token.ts @@ -1,6 +1,6 @@ import type { RestCommand } from '../types.js'; -export function withToken( +export function withToken( token: string, getOptions: RestCommand, ): RestCommand { diff --git a/sdk/src/rest/types.ts b/sdk/src/rest/types.ts index ef7f069eb9..e520eb4417 100644 --- a/sdk/src/rest/types.ts +++ b/sdk/src/rest/types.ts @@ -1,10 +1,10 @@ import type { RequestOptions, RequestTransformer, ResponseTransformer } from '../types/request.js'; -export interface RestCommand<_Output extends object | unknown, _Schema extends object> { +export interface RestCommand<_Output extends object | unknown, _Schema> { (): RequestOptions; } -export interface RestClient { +export interface RestClient { request(options: RestCommand): Promise; } diff --git a/sdk/src/rest/utils/query-to-params.ts b/sdk/src/rest/utils/query-to-params.ts index 12d2d27f4a..db9cf6e4ca 100644 --- a/sdk/src/rest/utils/query-to-params.ts +++ b/sdk/src/rest/utils/query-to-params.ts @@ -1,6 +1,6 @@ import type { AggregationTypes, GroupByFields, Query } from '../../types/index.js'; -type ExtendedQuery = Query & { +type ExtendedQuery = Query & { aggregate?: Record; groupBy?: (string | GroupByFields)[]; }; @@ -48,9 +48,7 @@ export const formatFields = (fields: (string | Record)[]) => { * * @returns Flat query parameters */ -export const queryToParams = ( - query: ExtendedQuery, -): Record => { +export const queryToParams = (query: ExtendedQuery): Record => { const params: Record = {}; if (Array.isArray(query.fields) && query.fields.length > 0) { diff --git a/sdk/src/schema/activity.ts b/sdk/src/schema/activity.ts index 049e4fb9bf..4ccd71343f 100644 --- a/sdk/src/schema/activity.ts +++ b/sdk/src/schema/activity.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusRevision } from './revision.js'; import type { DirectusUser } from './user.js'; -export type DirectusActivity = MergeCoreCollection< +export type DirectusActivity = MergeCoreCollection< Schema, 'directus_activity', { diff --git a/sdk/src/schema/collection.ts b/sdk/src/schema/collection.ts index f24bd7e668..82ef8fdd57 100644 --- a/sdk/src/schema/collection.ts +++ b/sdk/src/schema/collection.ts @@ -1,6 +1,6 @@ import type { DirectusField, MergeCoreCollection, NestedPartial } from '../index.js'; -export type DirectusCollection = { +export type DirectusCollection = { collection: string; // TODO keyof complete schema meta: MergeCoreCollection< Schema, diff --git a/sdk/src/schema/core.ts b/sdk/src/schema/core.ts index b87bf9abf8..1c2464cbec 100644 --- a/sdk/src/schema/core.ts +++ b/sdk/src/schema/core.ts @@ -19,7 +19,7 @@ import type { DirectusUser } from './user.js'; import type { DirectusVersion } from './version.js'; import type { DirectusWebhook } from './webhook.js'; -export interface CoreSchema { +export interface CoreSchema { directus_activity: DirectusActivity[]; directus_collections: DirectusCollection[]; directus_dashboards: DirectusDashboard[]; diff --git a/sdk/src/schema/dashboard.ts b/sdk/src/schema/dashboard.ts index 2c45f530d5..c9f3bae6e3 100644 --- a/sdk/src/schema/dashboard.ts +++ b/sdk/src/schema/dashboard.ts @@ -1,7 +1,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusUser } from './user.js'; -export type DirectusDashboard = MergeCoreCollection< +export type DirectusDashboard = MergeCoreCollection< Schema, 'directus_dashboards', { diff --git a/sdk/src/schema/extension.ts b/sdk/src/schema/extension.ts index 6970228028..900507da05 100644 --- a/sdk/src/schema/extension.ts +++ b/sdk/src/schema/extension.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusExtension = { +export type DirectusExtension = { name: string; bundle: string | null; schema: ExtensionSchema | null; diff --git a/sdk/src/schema/field.ts b/sdk/src/schema/field.ts index 8d333e54aa..0be051fced 100644 --- a/sdk/src/schema/field.ts +++ b/sdk/src/schema/field.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusField = { +export type DirectusField = { collection: string; // TODO keyof complete schema field: string; type: string; diff --git a/sdk/src/schema/file.ts b/sdk/src/schema/file.ts index b529211f9e..e4f9b421e0 100644 --- a/sdk/src/schema/file.ts +++ b/sdk/src/schema/file.ts @@ -3,7 +3,7 @@ import type { DirectusFolder } from './folder.js'; import type { DirectusUser } from './user.js'; // Base type for directus_files -export type DirectusFile = MergeCoreCollection< +export type DirectusFile = MergeCoreCollection< Schema, 'directus_files', { diff --git a/sdk/src/schema/flow.ts b/sdk/src/schema/flow.ts index 86d8233be8..eae553c6ab 100644 --- a/sdk/src/schema/flow.ts +++ b/sdk/src/schema/flow.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusUser } from './user.js'; import type { DirectusOperation } from './operation.js'; -export type DirectusFlow = MergeCoreCollection< +export type DirectusFlow = MergeCoreCollection< Schema, 'directus_flows', { diff --git a/sdk/src/schema/folder.ts b/sdk/src/schema/folder.ts index 38d15096f4..97bf4ed7b6 100644 --- a/sdk/src/schema/folder.ts +++ b/sdk/src/schema/folder.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusFolder = MergeCoreCollection< +export type DirectusFolder = MergeCoreCollection< Schema, 'directus_folders', { diff --git a/sdk/src/schema/notification.ts b/sdk/src/schema/notification.ts index a845372a0b..35ae189da4 100644 --- a/sdk/src/schema/notification.ts +++ b/sdk/src/schema/notification.ts @@ -1,7 +1,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusUser } from './user.js'; -export type DirectusNotification = MergeCoreCollection< +export type DirectusNotification = MergeCoreCollection< Schema, 'directus_notifications', { diff --git a/sdk/src/schema/operation.ts b/sdk/src/schema/operation.ts index a8ef734b5c..a4f91c8acf 100644 --- a/sdk/src/schema/operation.ts +++ b/sdk/src/schema/operation.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusFlow } from './flow.js'; import type { DirectusUser } from './user.js'; -export type DirectusOperation = MergeCoreCollection< +export type DirectusOperation = MergeCoreCollection< Schema, 'directus_operations', { diff --git a/sdk/src/schema/panel.ts b/sdk/src/schema/panel.ts index 7aea5d59c3..f6873092e2 100644 --- a/sdk/src/schema/panel.ts +++ b/sdk/src/schema/panel.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusUser } from './user.js'; import type { DirectusDashboard } from './dashboard.js'; -export type DirectusPanel = MergeCoreCollection< +export type DirectusPanel = MergeCoreCollection< Schema, 'directus_panels', { diff --git a/sdk/src/schema/permission.ts b/sdk/src/schema/permission.ts index 9c77a65dae..58891f2ac1 100644 --- a/sdk/src/schema/permission.ts +++ b/sdk/src/schema/permission.ts @@ -1,7 +1,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusRole } from './role.js'; -export type DirectusPermission = MergeCoreCollection< +export type DirectusPermission = MergeCoreCollection< Schema, 'directus_permissions', { diff --git a/sdk/src/schema/preset.ts b/sdk/src/schema/preset.ts index ce3c6ad396..7bf58528d1 100644 --- a/sdk/src/schema/preset.ts +++ b/sdk/src/schema/preset.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusRole } from './role.js'; import type { DirectusUser } from './user.js'; -export type DirectusPreset = MergeCoreCollection< +export type DirectusPreset = MergeCoreCollection< Schema, 'directus_presets', { diff --git a/sdk/src/schema/relation.ts b/sdk/src/schema/relation.ts index d5d0250c41..b6a1d1b995 100644 --- a/sdk/src/schema/relation.ts +++ b/sdk/src/schema/relation.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusRelation = { +export type DirectusRelation = { collection: string; // TODO keyof complete schema field: string; related_collection: string; // TODO keyof complete schema diff --git a/sdk/src/schema/revision.ts b/sdk/src/schema/revision.ts index df35e1b341..64c1f3f27b 100644 --- a/sdk/src/schema/revision.ts +++ b/sdk/src/schema/revision.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusActivity } from './activity.js'; import type { DirectusVersion } from './version.js'; -export type DirectusRevision = MergeCoreCollection< +export type DirectusRevision = MergeCoreCollection< Schema, 'directus_revisions', { diff --git a/sdk/src/schema/role.ts b/sdk/src/schema/role.ts index 82d5f1bdda..6d6c70436d 100644 --- a/sdk/src/schema/role.ts +++ b/sdk/src/schema/role.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusRole = MergeCoreCollection< +export type DirectusRole = MergeCoreCollection< Schema, 'directus_roles', { diff --git a/sdk/src/schema/settings.ts b/sdk/src/schema/settings.ts index 1227727895..749962df15 100644 --- a/sdk/src/schema/settings.ts +++ b/sdk/src/schema/settings.ts @@ -1,7 +1,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusFolder } from './folder.js'; -export type DirectusSettings = MergeCoreCollection< +export type DirectusSettings = MergeCoreCollection< Schema, 'directus_settings', { diff --git a/sdk/src/schema/share.ts b/sdk/src/schema/share.ts index 49d490656e..e889dac0d4 100644 --- a/sdk/src/schema/share.ts +++ b/sdk/src/schema/share.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusRole } from './role.js'; import type { DirectusUser } from './user.js'; -export type DirectusShare = MergeCoreCollection< +export type DirectusShare = MergeCoreCollection< Schema, 'directus_shares', { diff --git a/sdk/src/schema/translation.ts b/sdk/src/schema/translation.ts index 8a169c4c91..96f9c8b2ef 100644 --- a/sdk/src/schema/translation.ts +++ b/sdk/src/schema/translation.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusTranslation = MergeCoreCollection< +export type DirectusTranslation = MergeCoreCollection< Schema, 'directus_translations', { diff --git a/sdk/src/schema/user.ts b/sdk/src/schema/user.ts index ff92a83da9..6e195e9747 100644 --- a/sdk/src/schema/user.ts +++ b/sdk/src/schema/user.ts @@ -4,7 +4,7 @@ import type { DirectusFile } from './file.js'; /** * directus_users type */ -export type DirectusUser = MergeCoreCollection< +export type DirectusUser = MergeCoreCollection< Schema, 'directus_users', { diff --git a/sdk/src/schema/version.ts b/sdk/src/schema/version.ts index 5136d82350..d95ab7f9c0 100644 --- a/sdk/src/schema/version.ts +++ b/sdk/src/schema/version.ts @@ -2,7 +2,7 @@ import type { MergeCoreCollection } from '../index.js'; import type { DirectusCollection } from './collection.js'; import type { DirectusUser } from './user.js'; -export type DirectusVersion = MergeCoreCollection< +export type DirectusVersion = MergeCoreCollection< Schema, 'directus_versions', { diff --git a/sdk/src/schema/webhook.ts b/sdk/src/schema/webhook.ts index 7ef1b2831c..79324effae 100644 --- a/sdk/src/schema/webhook.ts +++ b/sdk/src/schema/webhook.ts @@ -1,6 +1,6 @@ import type { MergeCoreCollection } from '../index.js'; -export type DirectusWebhook = MergeCoreCollection< +export type DirectusWebhook = MergeCoreCollection< Schema, 'directus_webhooks', { diff --git a/sdk/src/types/aggregate.ts b/sdk/src/types/aggregate.ts index c12c55afeb..aa5b3082bb 100644 --- a/sdk/src/types/aggregate.ts +++ b/sdk/src/types/aggregate.ts @@ -55,7 +55,7 @@ export type AggregateRecord = { /** * GroupBy parameters */ -export type GroupByFields = +export type GroupByFields = | WrappedFields, DateTimeFunctions> | WrappedFields, ArrayFunctions>; @@ -63,7 +63,7 @@ export type GroupByFields = * Aggregation input options */ export type AggregationOptions< - Schema extends object, + Schema, Collection extends AllCollections, Fields = Collection extends keyof Schema ? keyof UnpackList> : string, Item = Collection extends keyof Schema ? UnpackList> : object, @@ -77,7 +77,7 @@ export type AggregationOptions< * Output typing for aggregation */ export type AggregationOutput< - Schema extends object, + Schema, Collection extends AllCollections, Options extends AggregationOptions, > = ((Options['groupBy'] extends string[] diff --git a/sdk/src/types/client.ts b/sdk/src/types/client.ts index 9514cd89ba..f6b866874d 100644 --- a/sdk/src/types/client.ts +++ b/sdk/src/types/client.ts @@ -3,7 +3,7 @@ import type { ConsoleInterface, FetchInterface, UrlInterface, WebSocketConstruct /** * empty directus client */ -export interface DirectusClient { +export interface DirectusClient { url: URL; globals: ClientGlobals; with: (createExtension: (client: DirectusClient) => Extension) => this & Extension; diff --git a/sdk/src/types/deep.ts b/sdk/src/types/deep.ts index 256144cf78..5089ccaefc 100644 --- a/sdk/src/types/deep.ts +++ b/sdk/src/types/deep.ts @@ -5,7 +5,7 @@ import type { UnpackList } from './utils.js'; /** * Deep filter object */ -export type QueryDeep = UnpackList extends infer FlatItem +export type QueryDeep = UnpackList extends infer FlatItem ? RelationalFields extends never ? never : { @@ -24,4 +24,4 @@ export type QueryDeep = UnpackList extends in } : never; -type ExtractCollection = Extract>; +type ExtractCollection = Extract>; diff --git a/sdk/src/types/fields.ts b/sdk/src/types/fields.ts index 95c6e2a8e9..0f6874ab0f 100644 --- a/sdk/src/types/fields.ts +++ b/sdk/src/types/fields.ts @@ -6,16 +6,12 @@ import type { IfNever, UnpackList } from './utils.js'; /** * Fields querying, including nested relational fields */ -export type QueryFields = WrapQueryFields< - Schema, - Item, - QueryFieldsRelational> ->; +export type QueryFields = WrapQueryFields>>; /** * Wrap array of fields */ -export type WrapQueryFields = readonly ( +export type WrapQueryFields = readonly ( | '*' | keyof UnpackList | NestedFields @@ -25,26 +21,24 @@ export type WrapQueryFields = readonl /** * Object of nested relational fields in a given Item with it's own fields available for selection */ -export type QueryFieldsRelational = RelationalFields extends infer Relations - ? IfNever< - Relations, - never, - { - [Key in RelationalFields]?: Extract> extends infer RelatedCollection - ? RelatedCollection extends any[] - ? HasManyToAnyRelation extends never - ? QueryFields // many-to-many or one-to-many - : ManyToAnyFields // many to any - : QueryFields // many-to-one - : never; - } - > - : never; +export type QueryFieldsRelational = IfNever< + RelationalFields, + never, + { + [Key in RelationalFields]?: Extract> extends infer RelatedCollection + ? RelatedCollection extends any[] + ? HasManyToAnyRelation extends never + ? QueryFields // many-to-many or one-to-many + : ManyToAnyFields // many to any + : QueryFields // many-to-one + : never; + } +>; /** * Deal with many-to-any relational fields */ -export type ManyToAnyFields = ExtractItem extends infer TItem +export type ManyToAnyFields = ExtractItem extends infer TItem ? TItem extends object ? 'collection' extends keyof TItem ? 'item' extends keyof TItem @@ -120,7 +114,7 @@ type AllKeys = T extends any ? keyof T : never; /** * Extract the required fields from an item */ -export type PickFlatFields = Extract extends never +export type PickFlatFields = Extract extends never ? never : Pick, Extract>; diff --git a/sdk/src/types/filters.ts b/sdk/src/types/filters.ts index 754657e726..9f648e0c9b 100644 --- a/sdk/src/types/filters.ts +++ b/sdk/src/types/filters.ts @@ -6,12 +6,12 @@ import type { IfNever, IsDateTime, IsNumber, IsString, MergeOptional, UnpackList /** * Filters */ -export type QueryFilter = WrapLogicalFilters>; +export type QueryFilter = WrapLogicalFilters>; /** * Query filters without logical filters */ -export type NestedQueryFilter = UnpackList extends infer FlatItem +export type NestedQueryFilter = UnpackList extends infer FlatItem ? MergeOptional< { [Field in keyof FlatItem]?: NestedRelationalFilter; @@ -31,7 +31,7 @@ export type NestedQueryFilter = UnpackList ex /** * Allow for relational filters */ -export type NestedRelationalFilter = +export type NestedRelationalFilter = | (Field extends RelationalFields ? WrapRelationalFilters> : never) diff --git a/sdk/src/types/functions.ts b/sdk/src/types/functions.ts index eb8447efa9..eaabdec6d4 100644 --- a/sdk/src/types/functions.ts +++ b/sdk/src/types/functions.ts @@ -26,7 +26,7 @@ export type PermuteFields = Fields extends string /** * Get all many relations on an item */ -type RelationalFunctions = keyof { +type RelationalFunctions = keyof { [Key in RelationalFields as Extract> extends any[] ? Key : never]: Key; }; @@ -40,7 +40,7 @@ type TranslateFunctionFields = { /** * Combine the various function types */ -export type FunctionFields = +export type FunctionFields = | { [Type in keyof QueryFunctions]: TypeFunctionFields; }[keyof QueryFunctions] @@ -57,7 +57,7 @@ export type TypeFunctionFields = keyof /** * Map all possible function fields on an item */ -export type MappedFunctionFields = Merge< +export type MappedFunctionFields = Merge< TranslateFunctionFields, ArrayFunctions>, TranslateFunctionFields, DateTimeFunctions> & TranslateFunctionFields, ArrayFunctions> @@ -73,7 +73,7 @@ type FunctionFieldNames = { /** * Map all possible function fields to name on an item */ -export type MappedFieldNames = Merge< +export type MappedFieldNames = Merge< FunctionFieldNames, ArrayFunctions>, FunctionFieldNames, DateTimeFunctions> & FunctionFieldNames, ArrayFunctions> diff --git a/sdk/src/types/output.ts b/sdk/src/types/output.ts index 640f7860ff..d8eab53b81 100644 --- a/sdk/src/types/output.ts +++ b/sdk/src/types/output.ts @@ -8,7 +8,7 @@ import type { IfAny, IsNullable, Merge, Mutable, UnpackList } from './utils.js'; */ export type ApplyQueryFields< // input types - Schema extends object, + Schema, Collection extends object, ReadonlyFields, // calculated types @@ -48,7 +48,7 @@ export type ApplyQueryFields< */ export type ApplyManyToAnyFields< // input types - Schema extends object, + Schema, JunctionCollection, FieldsList, // calculated types @@ -72,7 +72,7 @@ export type ApplyManyToAnyFields< /** * wrapper to aid in recursion */ -export type ApplyNestedQueryFields = Collection extends object +export type ApplyNestedQueryFields = Collection extends object ? ApplyQueryFields>> : never; diff --git a/sdk/src/types/query.ts b/sdk/src/types/query.ts index c5d3afa375..2ca5112df8 100644 --- a/sdk/src/types/query.ts +++ b/sdk/src/types/query.ts @@ -7,7 +7,7 @@ import type { IfAny, UnpackList } from './utils.js'; /** * All query options available */ -export interface Query { +export interface Query { readonly fields?: IfAny)[], QueryFields> | undefined; filter?: IfAny, QueryFilter> | undefined; search?: string | undefined; @@ -22,7 +22,7 @@ export interface Query { /** * All query options with an additional version query option for readItem and readSingleton */ -export interface QueryItem extends Query { +export interface QueryItem extends Query { readonly version?: string | undefined; readonly versionRaw?: boolean | undefined; } @@ -30,12 +30,12 @@ export interface QueryItem extends Query = Extract, ItemType>; +export type ExtractItem = Extract, ItemType>; /** * Returns the relation type from the current item by key */ -export type ExtractRelation = Key extends keyof Item +export type ExtractRelation = Key extends keyof Item ? ExtractItem : never; @@ -59,7 +59,7 @@ export type MergeFields = HasNestedFields extends never * Query sort * TODO expand to relational sorting (same object notation as fields i guess) */ -export type QuerySort<_Schema extends object, Item> = UnpackList extends infer FlatItem +export type QuerySort<_Schema, Item> = UnpackList extends infer FlatItem ? { [Field in keyof FlatItem]: Field | `-${Field & string}`; }[keyof FlatItem] @@ -72,4 +72,4 @@ export type MergeObjects = object extends A ? (object extends B ? A & B : * * TODO somehow include these aliases in the Field Types!! */ -export type QueryAlias<_Schema extends object, Item> = Record; +export type QueryAlias<_Schema, Item> = Record; diff --git a/sdk/src/types/schema.ts b/sdk/src/types/schema.ts index fc80fd4be5..187481b02d 100644 --- a/sdk/src/types/schema.ts +++ b/sdk/src/types/schema.ts @@ -4,7 +4,7 @@ import type { IfAny, UnpackList } from './utils.js'; /** * Get all available top level Item types from a given Schema */ -export type ItemType = +export type ItemType = | Schema[keyof Schema] | { [K in keyof Schema]: Schema[K] extends any[] ? Schema[K][number] : never; @@ -13,7 +13,7 @@ export type ItemType = /** * Return singular collection type */ -export type CollectionType = IfAny< +export type CollectionType = IfAny< Schema, any, Collection extends keyof Schema @@ -26,37 +26,33 @@ export type CollectionType = IfAny< /** * Returns a list of singleton collections in the schema */ -export type SingletonCollections = { +export type SingletonCollections = { [Key in keyof Schema]: Schema[Key] extends any[] ? never : Key; }[keyof Schema]; /** * Returns a list of regular collections in the schema */ -export type RegularCollections = IfAny< - Schema, - string, - Exclude> ->; +export type RegularCollections = IfAny>>; /** * Return string keys of all Primitive fields in the given schema Item */ -export type PrimitiveFields = { +export type PrimitiveFields = { [Key in keyof Item]: Extract> extends never ? Key : never; }[keyof Item]; /** * Return string keys of all Relational fields in the given schema Item */ -export type RelationalFields = { +export type RelationalFields = { [Key in keyof Item]: Extract> extends never ? never : Key; }[keyof Item]; /** * Remove the related Item types from relational m2o/a2o fields */ -export type RemoveRelationships = { +export type RemoveRelationships = { [Key in keyof Item]: Exclude>; }; @@ -64,7 +60,7 @@ export type RemoveRelationships = { * Merge a core collection from the schema with the builtin schema */ export type MergeCoreCollection< - Schema extends object, + Schema, Collection extends keyof Schema | string, BuiltinCollection, > = Collection extends keyof Schema @@ -78,7 +74,7 @@ export type MergeCoreCollection< /** * Merge custom and core schema objects */ -export type CompleteSchema = CoreSchema extends infer Core +export type CompleteSchema = CoreSchema extends infer Core ? { [Collection in keyof Schema | keyof Core]: Collection extends keyof Core ? Core[Collection] @@ -91,13 +87,13 @@ export type CompleteSchema = CoreSchema extends i /** * Merge custom schema with core schema */ -export type AllCollections = RegularCollections | RegularCollections>; +export type AllCollections = RegularCollections | RegularCollections>; /** * Helper to extract a collection with fallback to defaults */ export type GetCollection< - Schema extends object, + Schema, CollectionName extends AllCollections, > = CollectionName extends keyof CoreSchema ? CoreSchema[CollectionName] @@ -108,6 +104,6 @@ export type GetCollection< /** * Helper to extract a collection name */ -export type GetCollectionName> = { +export type GetCollectionName> = { [K in keyof FullSchema]: UnpackList extends Collection ? K : never; }[keyof FullSchema]; diff --git a/sdk/tests/no-schema.test.ts b/sdk/tests/no-schema.test.ts new file mode 100644 index 0000000000..00032e34ce --- /dev/null +++ b/sdk/tests/no-schema.test.ts @@ -0,0 +1,41 @@ +import { assertType, describe, test } from 'vitest'; +import type { ApplyQueryFields, Query, RegularCollections } from '../src/index.js'; + +describe('Test Schema Fallback', () => { + // RegularCollections is used to determine the collection input type of "readItems" + + test('fallback should use sensible types', () => { + // collection fallback + assertType>('string'); + + // query fallbacks + const fields: (string | Record)[] = ['*', { string: ['*'] }] as const; + const filter: Record = { string: { _eq: 'something' } }; + const sort: string | string[] = '-string'; + const deep: Record = { string: { something: 'value' } }; + const alias: Record = { string: 'alias' }; + // the rest are not based on the schema + assertType>({ fields, filter, sort, deep, alias }); + + // output fallback + const output: Record = { field: 'value' }; + assertType>(output); + }); + + test('Should fail for explicit invalid schema types', () => { + // @ts-expect-error + assertType>('test'); + // @ts-expect-error + assertType>('test'); + // @ts-expect-error + assertType>('test'); + // @ts-expect-error + assertType>('test'); + // @ts-expect-error + assertType>('test'); + // @ts-expect-error + assertType>('test'); + // @ts-expect-error + assertType>('test'); + }); +});