Remove deprecated code (#8670)

* Remove deprecated code

Just for you @aidenfoxx

* Fix type signature
This commit is contained in:
Rijk van Zanten
2021-10-08 14:45:17 -04:00
committed by GitHub
parent 1c70d2af90
commit fb36ded825
9 changed files with 10 additions and 345 deletions

View File

@@ -488,59 +488,4 @@ export class CollectionsService {
return collectionKeys;
}
/**
* @deprecated Use `createOne` or `createMany` instead
*/
create(data: RawCollection[]): Promise<string[]>;
create(data: RawCollection): Promise<string>;
async create(data: RawCollection | RawCollection[]): Promise<string | string[]> {
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<Collection[]>;
readByKey(collection: string): Promise<Collection>;
async readByKey(collection: string | string[]): Promise<Collection | Collection[]> {
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<Collection>, keys: string[]): Promise<string[]>;
update(data: Partial<Collection>, key: string): Promise<string>;
async update(data: Partial<Collection>, key: string | string[]): Promise<string | string[]> {
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<string[]>;
delete(collection: string): Promise<string>;
async delete(collection: string[] | string): Promise<string[] | string> {
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);
}
}

View File

@@ -213,37 +213,4 @@ export class FilesService extends ItemsService {
return keys;
}
/**
* @deprecated Use `uploadOne` instead
*/
async upload(
stream: NodeJS.ReadableStream,
data: Partial<File> & { filename_download: string; storage: string },
primaryKey?: PrimaryKey
): Promise<PrimaryKey> {
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<File>): Promise<PrimaryKey> {
return await this.importOne(importURL, body);
}
/**
* @deprecated Use `deleteOne` or `deleteMany` instead
*/
delete(key: PrimaryKey): Promise<PrimaryKey>;
delete(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
async delete(key: PrimaryKey | PrimaryKey[]): Promise<PrimaryKey | PrimaryKey[]> {
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);
}
}

View File

@@ -719,117 +719,4 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
return await this.createOne(data, opts);
}
/**
* @deprecated Use createOne or createMany instead
*/
async create(data: Partial<Item>[], opts?: MutationOptions): Promise<PrimaryKey[]>;
async create(data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey>;
async create(data: Partial<Item> | Partial<Item>[], opts?: MutationOptions): Promise<PrimaryKey | PrimaryKey[]> {
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<null | Partial<Item>[]>;
readByKey(key: PrimaryKey, query?: Query, action?: PermissionsAction): Promise<null | Partial<Item>>;
async readByKey(
key: PrimaryKey | PrimaryKey[],
query: Query = {},
action: PermissionsAction = 'read'
): Promise<null | Partial<Item> | Partial<Item>[]> {
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<Item>, keys: PrimaryKey[]): Promise<PrimaryKey[]>;
update(data: Partial<Item>, key: PrimaryKey): Promise<PrimaryKey>;
update(data: Partial<Item>[]): Promise<PrimaryKey[]>;
async update(
data: Partial<Item> | Partial<Item>[],
key?: PrimaryKey | PrimaryKey[]
): Promise<PrimaryKey | PrimaryKey[]> {
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<Item>[]) {
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<Item>[]): Promise<PrimaryKey[]>;
upsert(data: Partial<Item>): Promise<PrimaryKey>;
async upsert(data: Partial<Item> | Partial<Item>[]): Promise<PrimaryKey | PrimaryKey[]> {
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<PrimaryKey>;
delete(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
async delete(key: PrimaryKey | PrimaryKey[]): Promise<PrimaryKey | PrimaryKey[]> {
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);
}
}

View File

@@ -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<null | Partial<Item>[]>;
readByKey(key: PrimaryKey, query?: Query, action?: PermissionsAction): Promise<null | Partial<Item>>;
async readByKey(
key: PrimaryKey | PrimaryKey[],
query: Query = {},
action: PermissionsAction = 'read'
): Promise<null | Partial<Item> | Partial<Item>[]> {
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 });
}
}

View File

@@ -149,14 +149,4 @@ export class RolesService extends ItemsService {
deleteByQuery(query: Query, opts?: MutationOptions): Promise<PrimaryKey[]> {
return super.deleteByQuery(query, opts);
}
/**
* @deprecated Use `deleteOne` or `deleteMany` instead
*/
delete(key: PrimaryKey): Promise<PrimaryKey>;
delete(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
async delete(key: PrimaryKey | PrimaryKey[]): Promise<PrimaryKey | PrimaryKey[]> {
if (Array.isArray(key)) return await this.deleteMany(key);
return await this.deleteOne(key);
}
}

View File

@@ -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<Item>[]): Promise<PrimaryKey[]>;
async create(data: Partial<Item>): Promise<PrimaryKey>;
async create(data: Partial<Item> | Partial<Item>[]): Promise<PrimaryKey | PrimaryKey[]> {
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<Item>, keys: PrimaryKey[]): Promise<PrimaryKey[]>;
update(data: Partial<Item>, key: PrimaryKey): Promise<PrimaryKey>;
update(data: Partial<Item>[]): Promise<PrimaryKey[]>;
async update(
data: Partial<Item> | Partial<Item>[],
key?: PrimaryKey | PrimaryKey[]
): Promise<PrimaryKey | PrimaryKey[]> {
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<Item>[]) {
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<PrimaryKey>;
delete(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
async delete(key: PrimaryKey | PrimaryKey[]): Promise<PrimaryKey | PrimaryKey[]> {
if (Array.isArray(key)) return await this.deleteMany(key);
return await this.deleteOne(key);
}
}

View File

@@ -42,41 +42,4 @@ export class WebhooksService extends ItemsService {
await register();
return result;
}
/**
* @deprecated Use `createOne` or `createMany` instead
*/
async create(data: Partial<Item>[]): Promise<PrimaryKey[]>;
async create(data: Partial<Item>): Promise<PrimaryKey>;
async create(data: Partial<Item> | Partial<Item>[]): Promise<PrimaryKey | PrimaryKey[]> {
const result = await super.create(data);
await register();
return result;
}
/**
* @deprecated Use `updateOne` or `updateMany` instead
*/
update(data: Partial<Item>, keys: PrimaryKey[]): Promise<PrimaryKey[]>;
update(data: Partial<Item>, key: PrimaryKey): Promise<PrimaryKey>;
update(data: Partial<Item>[]): Promise<PrimaryKey[]>;
async update(
data: Partial<Item> | Partial<Item>[],
key?: PrimaryKey | PrimaryKey[]
): Promise<PrimaryKey | PrimaryKey[]> {
const result = await super.update(data, key as any);
await register();
return result;
}
/**
* @deprecated Use `deleteOne` or `deleteMany` instead
*/
delete(key: PrimaryKey): Promise<PrimaryKey>;
delete(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
async delete(key: PrimaryKey | PrimaryKey[]): Promise<PrimaryKey | PrimaryKey[]> {
const result = await super.delete(key as any);
await register();
return result;
}
}

View File

@@ -14,18 +14,16 @@ export interface AbstractService {
knex: Knex;
accountability: Accountability | null;
create(data: Partial<Item>[]): Promise<PrimaryKey[]>;
create(data: Partial<Item>): Promise<PrimaryKey>;
createOne(data: Partial<Item>): Promise<PrimaryKey>;
createMany(data: Partial<Item>[]): Promise<PrimaryKey[]>;
readByQuery(query: Query): Promise<null | Item | Item[]>;
readOne(key: PrimaryKey, query?: Query): Promise<Item>;
readMany(keys: PrimaryKey[], query?: Query): Promise<Item[]>;
readByQuery(query: Query): Promise<Item[]>;
readByKey(keys: PrimaryKey[], query: Query, action: PermissionsAction): Promise<null | Item[]>;
readByKey(key: PrimaryKey, query: Query, action: PermissionsAction): Promise<null | Item>;
updateOne(key: PrimaryKey, data: Partial<Item>): Promise<PrimaryKey>;
updateMany(keys: PrimaryKey[], data: Partial<Item>): Promise<PrimaryKey[]>;
update(data: Partial<Item>, keys: PrimaryKey[]): Promise<PrimaryKey[]>;
update(data: Partial<Item>, key: PrimaryKey): Promise<PrimaryKey>;
update(data: Partial<Item>[]): Promise<PrimaryKey[]>;
delete(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
delete(key: PrimaryKey): Promise<PrimaryKey>;
deleteOne(key: PrimaryKey): Promise<PrimaryKey>;
deleteMany(keys: PrimaryKey[]): Promise<PrimaryKey[]>;
}

View File

@@ -44,7 +44,7 @@ export type Command<T extends Toolbox = Toolbox, P = unknown, R extends any = vo
settings?: Settings<P>;
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<P>;