mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
feat: remove updateOnly parameter
This commit is contained in:
parent
85f77f963d
commit
ded2a32533
10
src/cache/adapters/default.ts
vendored
10
src/cache/adapters/default.ts
vendored
@ -64,12 +64,9 @@ export class MemoryAdapter<T> implements Adapter {
|
||||
this.storage.set(key, this.options.encode(data));
|
||||
}
|
||||
|
||||
bulkPatch(updateOnly: boolean, keys: [string, any][]) {
|
||||
bulkPatch(keys: [string, any][]) {
|
||||
for (const [key, value] of keys) {
|
||||
const oldData = this.get(key);
|
||||
if (updateOnly && !oldData) {
|
||||
continue;
|
||||
}
|
||||
this.storage.set(
|
||||
key,
|
||||
Array.isArray(value) ? this.options.encode(value) : this.options.encode({ ...(oldData ?? {}), ...value }),
|
||||
@ -77,11 +74,8 @@ export class MemoryAdapter<T> implements Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
patch(updateOnly: boolean, keys: string, data: any) {
|
||||
patch(keys: string, data: any) {
|
||||
const oldData = this.get(keys);
|
||||
if (updateOnly && !oldData) {
|
||||
return;
|
||||
}
|
||||
this.storage.set(
|
||||
keys,
|
||||
Array.isArray(data) ? this.options.encode(data) : this.options.encode({ ...(oldData ?? {}), ...data }),
|
||||
|
10
src/cache/adapters/limited.ts
vendored
10
src/cache/adapters/limited.ts
vendored
@ -156,21 +156,15 @@ export class LimitedMemoryAdapter<T> implements Adapter {
|
||||
this.__set(keys, data);
|
||||
}
|
||||
|
||||
bulkPatch(updateOnly: boolean, keys: [string, any][]) {
|
||||
bulkPatch(keys: [string, any][]) {
|
||||
for (const [key, value] of keys) {
|
||||
const oldData = this.get(key);
|
||||
if (updateOnly && !oldData) {
|
||||
continue;
|
||||
}
|
||||
this.__set(key, Array.isArray(value) ? value : { ...(oldData ?? {}), ...value });
|
||||
}
|
||||
}
|
||||
|
||||
patch(updateOnly: boolean, keys: string, data: any) {
|
||||
patch(keys: string, data: any) {
|
||||
const oldData = this.get(keys);
|
||||
if (updateOnly && !oldData) {
|
||||
return;
|
||||
}
|
||||
this.__set(keys, Array.isArray(data) ? data : { ...(oldData ?? {}), ...data });
|
||||
}
|
||||
|
||||
|
4
src/cache/adapters/types.ts
vendored
4
src/cache/adapters/types.ts
vendored
@ -15,8 +15,8 @@ export interface Adapter {
|
||||
bulkSet(keyValue: [string, any][]): Awaitable<void>;
|
||||
set(id: string, data: any): Awaitable<void>;
|
||||
|
||||
bulkPatch(updateOnly: boolean, keyValue: [string, any][]): Awaitable<void>;
|
||||
patch(updateOnly: boolean, id: string, data: any): Awaitable<void>;
|
||||
bulkPatch(keyValue: [string, any][]): Awaitable<void>;
|
||||
patch(id: string, data: any): Awaitable<void>;
|
||||
|
||||
values(to: string): Awaitable<any[]>;
|
||||
|
||||
|
2
src/cache/index.ts
vendored
2
src/cache/index.ts
vendored
@ -363,7 +363,7 @@ export class Cache {
|
||||
}
|
||||
|
||||
await this.adapter.bulkAddToRelationShip(relationshipsData);
|
||||
await this.adapter.bulkPatch(false, allData);
|
||||
await this.adapter.bulkPatch(allData);
|
||||
}
|
||||
|
||||
async bulkSet(
|
||||
|
2
src/cache/resources/default/base.ts
vendored
2
src/cache/resources/default/base.ts
vendored
@ -48,7 +48,7 @@ export class BaseResource<T = any, S = any> {
|
||||
|
||||
patch(id: string, data: S) {
|
||||
if (!this.filter(data, id)) return;
|
||||
return fakePromise(this.addToRelationship(id)).then(() => this.adapter.patch(false, this.hashId(id), data));
|
||||
return fakePromise(this.addToRelationship(id)).then(() => this.adapter.patch(this.hashId(id), data));
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
|
39
src/cache/resources/default/guild-related.ts
vendored
39
src/cache/resources/default/guild-related.ts
vendored
@ -68,38 +68,27 @@ export class GuildRelatedResource<T = any, S = any> {
|
||||
);
|
||||
}
|
||||
|
||||
patch(__keys: string, guild?: string, data?: any): ReturnCache<void>;
|
||||
patch(__keys: [string, any][], guild?: string): ReturnCache<void>;
|
||||
patch(__keys: string | [string, any][], guild?: string, data?: any): ReturnCache<void> {
|
||||
patch(__keys: string, guild: string, data?: any): ReturnCache<void>;
|
||||
patch(__keys: [string, any][], guild: string): ReturnCache<void>;
|
||||
patch(__keys: string | [string, any][], guild: string, data?: any): ReturnCache<void> {
|
||||
const keys = (Array.isArray(__keys) ? __keys : [[__keys, data]]).filter(x => this.filter(x[1], x[0], guild)) as [
|
||||
string,
|
||||
any,
|
||||
][];
|
||||
|
||||
if (guild) {
|
||||
return fakePromise(
|
||||
this.addToRelationship(
|
||||
keys.map(x => x[0]),
|
||||
guild,
|
||||
),
|
||||
).then(
|
||||
() =>
|
||||
this.adapter.bulkPatch(
|
||||
false,
|
||||
keys.map(([key, value]) => {
|
||||
return [this.hashId(key), this.parse(value, key, guild)] as const;
|
||||
}),
|
||||
) as void,
|
||||
);
|
||||
}
|
||||
return fakePromise(
|
||||
this.adapter.bulkPatch(
|
||||
true,
|
||||
keys.map(([key, value]) => {
|
||||
return [this.hashId(key), value];
|
||||
}),
|
||||
this.addToRelationship(
|
||||
keys.map(x => x[0]),
|
||||
guild,
|
||||
),
|
||||
).then(x => x);
|
||||
).then(
|
||||
() =>
|
||||
this.adapter.bulkPatch(
|
||||
keys.map(([key, value]) => {
|
||||
return [this.hashId(key), this.parse(value, key, guild)] as const;
|
||||
}),
|
||||
) as void,
|
||||
);
|
||||
}
|
||||
|
||||
remove(id: string | string[], guild: string) {
|
||||
|
@ -39,7 +39,11 @@ export class ChannelShorter extends BaseShorter {
|
||||
}
|
||||
|
||||
channel = await this.client.proxy.channels(id).get();
|
||||
await this.client.cache.channels?.patch(id, undefined, channel);
|
||||
await this.client.cache.channels?.patch(
|
||||
id,
|
||||
'guild_id' in channel && channel.guild_id ? channel.guild_id : '@me',
|
||||
channel,
|
||||
);
|
||||
return channel as APIChannel;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { ClientUserStructure } from '../client';
|
||||
import { type ClientUserStructure, Transformers } from '../client';
|
||||
import type { UsingClient } from '../commands';
|
||||
import type { GatewayReadyDispatchData, RESTPatchAPICurrentUserJSONBody } from '../types';
|
||||
import { User } from './User';
|
||||
@ -15,11 +15,11 @@ export class ClientUser extends User {
|
||||
|
||||
async fetch(): Promise<ClientUserStructure> {
|
||||
const data = await this.api.users('@me').get();
|
||||
return new ClientUser(this.client, data, this.application);
|
||||
return Transformers.ClientUser(this.client, data, this.application);
|
||||
}
|
||||
|
||||
async edit(body: RESTPatchAPICurrentUserJSONBody): Promise<ClientUserStructure> {
|
||||
const data = await this.api.users('@me').patch({ body });
|
||||
return new ClientUser(this.client, data, this.application);
|
||||
return Transformers.ClientUser(this.client, data, this.application);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user