From fb36ded825c4f441b46e56ebcf8885a85aa04342 Mon Sep 17 00:00:00 2001 From: Rijk van Zanten Date: Fri, 8 Oct 2021 14:45:17 -0400 Subject: [PATCH] Remove deprecated code (#8670) * Remove deprecated code Just for you @aidenfoxx * Fix type signature --- api/src/services/collections.ts | 55 ---------------- api/src/services/files.ts | 33 ---------- api/src/services/items.ts | 113 -------------------------------- api/src/services/permissions.ts | 18 ----- api/src/services/roles.ts | 10 --- api/src/services/users.ts | 67 ------------------- api/src/services/webhooks.ts | 37 ----------- api/src/types/services.ts | 20 +++--- packages/cli/src/command.ts | 2 +- 9 files changed, 10 insertions(+), 345 deletions(-) diff --git a/api/src/services/collections.ts b/api/src/services/collections.ts index 2380c0e523..f1f81bf9ad 100644 --- a/api/src/services/collections.ts +++ b/api/src/services/collections.ts @@ -488,59 +488,4 @@ export class CollectionsService { return collectionKeys; } - - /** - * @deprecated Use `createOne` or `createMany` instead - */ - create(data: RawCollection[]): Promise; - create(data: RawCollection): Promise; - async create(data: RawCollection | RawCollection[]): Promise { - logger.warn( - 'CollectionsService.create is deprecated and will be removed before v9.0.0. Use createOne or createMany instead.' - ); - - if (Array.isArray(data)) { - return await this.createMany(data); - } else { - return await this.createOne(data); - } - } - - /** - * @deprecated Use `readOne` or `readMany` instead - */ - readByKey(collection: string[]): Promise; - readByKey(collection: string): Promise; - async readByKey(collection: string | string[]): Promise { - logger.warn( - 'CollectionsService.readByKey is deprecated and will be removed before v9.0.0. Use readOne or readMany instead.' - ); - - if (Array.isArray(collection)) return await this.readMany(collection); - return await this.readOne(collection); - } - - /** - * @deprecated Use `updateOne` or `updateMany` instead - */ - update(data: Partial, keys: string[]): Promise; - update(data: Partial, key: string): Promise; - async update(data: Partial, key: string | string[]): Promise { - if (Array.isArray(key)) return await this.updateMany(key, data); - return await this.updateOne(key, data); - } - - /** - * @deprecated Use `deleteOne` or `deleteMany` instead - */ - delete(collections: string[]): Promise; - delete(collection: string): Promise; - async delete(collection: string[] | string): Promise { - logger.warn( - 'CollectionsService.delete is deprecated and will be removed before v9.0.0. Use deleteOne or deleteMany instead.' - ); - - if (Array.isArray(collection)) return await this.deleteMany(collection); - return await this.deleteOne(collection); - } } diff --git a/api/src/services/files.ts b/api/src/services/files.ts index 10a8080fe1..853f64ee81 100644 --- a/api/src/services/files.ts +++ b/api/src/services/files.ts @@ -213,37 +213,4 @@ export class FilesService extends ItemsService { return keys; } - - /** - * @deprecated Use `uploadOne` instead - */ - async upload( - stream: NodeJS.ReadableStream, - data: Partial & { filename_download: string; storage: string }, - primaryKey?: PrimaryKey - ): Promise { - logger.warn('FilesService.upload is deprecated and will be removed before v9.0.0. Use uploadOne instead.'); - - return await this.uploadOne(stream, data, primaryKey); - } - - /** - * @deprecated Use `importOne` instead - */ - async import(importURL: string, body: Partial): Promise { - return await this.importOne(importURL, body); - } - - /** - * @deprecated Use `deleteOne` or `deleteMany` instead - */ - delete(key: PrimaryKey): Promise; - delete(keys: PrimaryKey[]): Promise; - async delete(key: PrimaryKey | PrimaryKey[]): Promise { - logger.warn( - 'FilesService.delete is deprecated and will be removed before v9.0.0. Use deleteOne or deleteMany instead.' - ); - if (Array.isArray(key)) return await this.deleteMany(key); - return await this.deleteOne(key); - } } diff --git a/api/src/services/items.ts b/api/src/services/items.ts index 11398819bd..97a5b1069d 100644 --- a/api/src/services/items.ts +++ b/api/src/services/items.ts @@ -719,117 +719,4 @@ export class ItemsService implements AbstractSer return await this.createOne(data, opts); } - - /** - * @deprecated Use createOne or createMany instead - */ - async create(data: Partial[], opts?: MutationOptions): Promise; - async create(data: Partial, opts?: MutationOptions): Promise; - async create(data: Partial | Partial[], opts?: MutationOptions): Promise { - logger.warn( - 'ItemsService.create is deprecated and will be removed before v9.0.0. Use createOne or createMany instead.' - ); - - if (Array.isArray(data)) return this.createMany(data, opts); - return this.createOne(data, opts); - } - - /** - * @deprecated Use `readOne` or `readMany` instead - */ - readByKey(keys: PrimaryKey[], query?: Query, action?: PermissionsAction): Promise[]>; - readByKey(key: PrimaryKey, query?: Query, action?: PermissionsAction): Promise>; - async readByKey( - key: PrimaryKey | PrimaryKey[], - query: Query = {}, - action: PermissionsAction = 'read' - ): Promise | Partial[]> { - logger.warn( - 'ItemsService.readByKey is deprecated and will be removed before v9.0.0. Use readOne or readMany instead.' - ); - - if (Array.isArray(key)) { - return this.readMany(key, query, { permissionsAction: action }); - } else { - return this.readOne(key, query, { permissionsAction: action }); - } - } - - /** - * @deprecated Use `updateOne` or `updateMany` instead - */ - update(data: Partial, keys: PrimaryKey[]): Promise; - update(data: Partial, key: PrimaryKey): Promise; - update(data: Partial[]): Promise; - async update( - data: Partial | Partial[], - key?: PrimaryKey | PrimaryKey[] - ): Promise { - logger.warn( - 'ItemsService.update is deprecated and will be removed before v9.0.0. Use updateOne or updateMany instead.' - ); - - const primaryKeyField = this.schema.collections[this.collection].primary; - - if (key) { - data = Array.isArray(data) ? data[0] : data; - if (Array.isArray(key)) return await this.updateMany(key, data); - else return await this.updateOne(key, data); - } - - const keys: PrimaryKey[] = []; - - await this.knex.transaction(async (trx) => { - const itemsService = new ItemsService(this.collection, { - accountability: this.accountability, - knex: trx, - schema: this.schema, - }); - - const payloads = toArray(data); - - for (const single of payloads as Partial[]) { - const payload = clone(single); - const key = payload[primaryKeyField]; - - if (!key) { - throw new InvalidPayloadException('Primary key is missing in update payload.'); - } - - keys.push(key); - - await itemsService.updateOne(key, payload); - } - }); - - return keys; - } - - /** - * @deprecated Use `upsertOne` or `upsertMany` instead - */ - upsert(data: Partial[]): Promise; - upsert(data: Partial): Promise; - async upsert(data: Partial | Partial[]): Promise { - logger.warn( - 'ItemsService.upsert is deprecated and will be removed before v9.0.0. Use upsertOne or upsertMany instead.' - ); - - if (Array.isArray(data)) return await this.upsertMany(data); - return await this.upsertOne(data); - } - - /** - * @deprecated Use `deleteOne` or `deleteMany` instead - */ - delete(key: PrimaryKey): Promise; - delete(keys: PrimaryKey[]): Promise; - async delete(key: PrimaryKey | PrimaryKey[]): Promise { - logger.warn( - 'ItemsService.delete is deprecated and will be removed before v9.0.0. Use deleteOne or deleteMany instead.' - ); - - if (Array.isArray(key)) return await this.deleteMany(key); - else return await this.deleteOne(key); - } } diff --git a/api/src/services/permissions.ts b/api/src/services/permissions.ts index 0dcf76c924..3cdeb9728d 100644 --- a/api/src/services/permissions.ts +++ b/api/src/services/permissions.ts @@ -69,22 +69,4 @@ export class PermissionsService extends ItemsService { return result; } - - /** - * @deprecated Use `readOne` or `readMany` instead - */ - readByKey(keys: PrimaryKey[], query?: Query, action?: PermissionsAction): Promise[]>; - readByKey(key: PrimaryKey, query?: Query, action?: PermissionsAction): Promise>; - async readByKey( - key: PrimaryKey | PrimaryKey[], - query: Query = {}, - action: PermissionsAction = 'read' - ): Promise | Partial[]> { - logger.warn( - 'PermissionsService.readByKey is deprecated and will be removed before v9.0.0. Use readOne or readMany instead.' - ); - - if (Array.isArray(key)) return await this.readMany(key, query, { permissionsAction: action }); - return await this.readOne(key, query, { permissionsAction: action }); - } } diff --git a/api/src/services/roles.ts b/api/src/services/roles.ts index c28f716c5d..b5b99d1637 100644 --- a/api/src/services/roles.ts +++ b/api/src/services/roles.ts @@ -149,14 +149,4 @@ export class RolesService extends ItemsService { deleteByQuery(query: Query, opts?: MutationOptions): Promise { return super.deleteByQuery(query, opts); } - - /** - * @deprecated Use `deleteOne` or `deleteMany` instead - */ - delete(key: PrimaryKey): Promise; - delete(keys: PrimaryKey[]): Promise; - async delete(key: PrimaryKey | PrimaryKey[]): Promise { - if (Array.isArray(key)) return await this.deleteMany(key); - return await this.deleteOne(key); - } } diff --git a/api/src/services/users.ts b/api/src/services/users.ts index 82d2c184a2..b9a2523f6c 100644 --- a/api/src/services/users.ts +++ b/api/src/services/users.ts @@ -364,71 +364,4 @@ export class UsersService extends ItemsService { await service.updateOne(user.id, { password, status: 'active' }); } - - /** - * @deprecated Use `createOne` or `createMany` instead - */ - async create(data: Partial[]): Promise; - async create(data: Partial): Promise; - async create(data: Partial | Partial[]): Promise { - logger.warn( - 'UsersService.create is deprecated and will be removed before v9.0.0. Use createOne or createMany instead.' - ); - - if (Array.isArray(data)) return this.createMany(data); - return this.createOne(data); - } - - /** - * @deprecated Use `updateOne` or `updateMany` instead - */ - update(data: Partial, keys: PrimaryKey[]): Promise; - update(data: Partial, key: PrimaryKey): Promise; - update(data: Partial[]): Promise; - async update( - data: Partial | Partial[], - key?: PrimaryKey | PrimaryKey[] - ): Promise { - if (Array.isArray(key)) return await this.updateMany(key, data); - else if (key) await this.updateOne(key, data); - - const primaryKeyField = this.schema.collections[this.collection].primary; - - const keys: PrimaryKey[] = []; - - await this.knex.transaction(async (trx) => { - const itemsService = new ItemsService(this.collection, { - accountability: this.accountability, - knex: trx, - schema: this.schema, - }); - - const payloads = toArray(data); - - for (const single of payloads as Partial[]) { - const payload = clone(single); - const key = payload[primaryKeyField]; - - if (!key) { - throw new InvalidPayloadException('Primary key is missing in update payload.'); - } - - keys.push(key); - - await itemsService.updateOne(key, payload); - } - }); - - return keys; - } - - /** - * @deprecated Use `deleteOne` or `deleteMany` instead - */ - delete(key: PrimaryKey): Promise; - delete(keys: PrimaryKey[]): Promise; - async delete(key: PrimaryKey | PrimaryKey[]): Promise { - if (Array.isArray(key)) return await this.deleteMany(key); - return await this.deleteOne(key); - } } diff --git a/api/src/services/webhooks.ts b/api/src/services/webhooks.ts index 76d779a688..efcda9dc0f 100644 --- a/api/src/services/webhooks.ts +++ b/api/src/services/webhooks.ts @@ -42,41 +42,4 @@ export class WebhooksService extends ItemsService { await register(); return result; } - - /** - * @deprecated Use `createOne` or `createMany` instead - */ - async create(data: Partial[]): Promise; - async create(data: Partial): Promise; - async create(data: Partial | Partial[]): Promise { - const result = await super.create(data); - await register(); - return result; - } - - /** - * @deprecated Use `updateOne` or `updateMany` instead - */ - update(data: Partial, keys: PrimaryKey[]): Promise; - update(data: Partial, key: PrimaryKey): Promise; - update(data: Partial[]): Promise; - async update( - data: Partial | Partial[], - key?: PrimaryKey | PrimaryKey[] - ): Promise { - const result = await super.update(data, key as any); - await register(); - return result; - } - - /** - * @deprecated Use `deleteOne` or `deleteMany` instead - */ - delete(key: PrimaryKey): Promise; - delete(keys: PrimaryKey[]): Promise; - async delete(key: PrimaryKey | PrimaryKey[]): Promise { - const result = await super.delete(key as any); - await register(); - return result; - } } diff --git a/api/src/types/services.ts b/api/src/types/services.ts index 06179f7377..b295ac92e7 100644 --- a/api/src/types/services.ts +++ b/api/src/types/services.ts @@ -14,18 +14,16 @@ export interface AbstractService { knex: Knex; accountability: Accountability | null; - create(data: Partial[]): Promise; - create(data: Partial): Promise; + createOne(data: Partial): Promise; + createMany(data: Partial[]): Promise; - readByQuery(query: Query): Promise; + readOne(key: PrimaryKey, query?: Query): Promise; + readMany(keys: PrimaryKey[], query?: Query): Promise; + readByQuery(query: Query): Promise; - readByKey(keys: PrimaryKey[], query: Query, action: PermissionsAction): Promise; - readByKey(key: PrimaryKey, query: Query, action: PermissionsAction): Promise; + updateOne(key: PrimaryKey, data: Partial): Promise; + updateMany(keys: PrimaryKey[], data: Partial): Promise; - update(data: Partial, keys: PrimaryKey[]): Promise; - update(data: Partial, key: PrimaryKey): Promise; - update(data: Partial[]): Promise; - - delete(keys: PrimaryKey[]): Promise; - delete(key: PrimaryKey): Promise; + deleteOne(key: PrimaryKey): Promise; + deleteMany(keys: PrimaryKey[]): Promise; } diff --git a/packages/cli/src/command.ts b/packages/cli/src/command.ts index 85d051c745..951a2331a1 100644 --- a/packages/cli/src/command.ts +++ b/packages/cli/src/command.ts @@ -44,7 +44,7 @@ export type Command; run: { /** - * @deprecated Please don't access this field. It's for internal use only and a workaround for Gluegun. + * @note Please don't access this field. It's for internal use only and a workaround for Gluegun. */ $directus: { settings: Settings

;