update decorators

This commit is contained in:
tresabhi committed 2026-06-23 14:41:44 -05:00
1 parent 81cc43bd08
commit c292ddcd6a
4 files changed
+41 -38

No files matched your search

+1 -5
View File
@@ -11,11 +11,7 @@ export default defineConfig({
vite: {
server: { allowedHosts: [] },
esbuild: {
minifyIdentifiers: true,
minifySyntax: false,
minifyWhitespace: true,
},
esbuild: { target: "es2022" },
build: {
rollupOptions: {
+16 -14
View File
@@ -82,35 +82,37 @@ export abstract class AbstractAPI {
}
}
export function Cache<Arguments extends unknown[]>(disableInDev = false) {
export function Cache(disableInDev = false) {
const cache = new WeakMap<object, Map<string, Promise<unknown>>>();
return function (
_target: unknown,
_propertyKey: string,
descriptor: PropertyDescriptor,
return function <This, Arguments extends any[], Return>(
target: (this: This, ...args: Arguments) => Promise<Return>,
// TODO: evaluate if we need context to make the error trace easier
// context: ClassMethodDecoratorContext<
// This,
// (this: This, ...args: Arguments) => Promise<Return>
// >,
) {
const original = descriptor.value;
descriptor.value = function (...args: Arguments) {
return async function replacementMethod(this: This, ...args: Arguments) {
const key = args.join("-");
let thisCache: Map<string, Promise<Return>>;
let thisCache = cache.get(this);
if (!thisCache) {
if (cache.has(this as object)) {
thisCache = cache.get(this as object) as Map<string, Promise<Return>>;
} else {
thisCache = new Map();
cache.set(this, thisCache);
cache.set(this as object, thisCache);
}
const disabled = disableInDev && import.meta.env.DEV;
if (thisCache.has(key) && !disabled) {
return thisCache.get(key);
return thisCache.get(key)!;
}
const promise = (async () => {
try {
return await original.apply(this, args);
return await target.apply(this, args);
} catch (error) {
thisCache!.delete(key);
throw error;
+22 -16
View File
@@ -21,7 +21,7 @@ export class ClientAPI extends AbstractAPI {
throw new Error("MetadataAccessor is inaccessible on the client");
}
@UnimplementedOnClient
@UnimplementedOnClient()
mediaPrefix(): never {
throw rejected();
}
@@ -85,7 +85,7 @@ export class ClientAPI extends AbstractAPI {
return json;
}
@UnimplementedOnClient
@UnimplementedOnClient()
gameStrings() {
return rejected();
}
@@ -98,12 +98,12 @@ export class ClientAPI extends AbstractAPI {
return json;
}
@UnimplementedOnClient
@UnimplementedOnClient()
gameStringGroups() {
return rejected();
}
@UnimplementedOnClient
@UnimplementedOnClient()
avatar() {
return rejected();
}
@@ -112,38 +112,44 @@ export class ClientAPI extends AbstractAPI {
return fetchPB("/api/avatars/all.pb", Avatars);
}
@UnimplementedOnClient
@UnimplementedOnClient()
avatarList() {
return rejected();
}
@UnimplementedOnClient
@UnimplementedOnClient()
background() {
return rejected();
}
@UnimplementedOnClient
@UnimplementedOnClient()
backgrounds() {
return rejected();
}
@UnimplementedOnClient
@UnimplementedOnClient()
currencyIcon() {
return rejected();
}
@UnimplementedOnClient
@UnimplementedOnClient()
stuffIcon() {
return rejected();
}
}
function UnimplementedOnClient(
_target: unknown,
propertyKey: string,
descriptor: PropertyDescriptor,
) {
descriptor.value = function () {
throw new Error(`${propertyKey} is not implemented on the client`);
export function UnimplementedOnClient() {
return function <This, Arguments extends any[], Return>(
_target: (this: This, ...args: Arguments) => Promise<Return>,
context: ClassMethodDecoratorContext<
This,
(this: This, ...args: Arguments) => Promise<Return>
>,
) {
return function () {
throw new Error(
`${String(context.name)} is not implemented on the client`,
);
};
};
}
+2 -3
View File
@@ -15,10 +15,9 @@
"incremental": true,
"isolatedModules": true,
"paths": {
"@protos/*": ["./packages/closed/protos/*"]
"@protos/*": ["./packages/closed/protos/*"],
},
"strictNullChecks": true,
"experimentalDecorators": true
},
"exclude": ["node_modules/**/*", "dist"]
"exclude": ["node_modules/**/*", "dist"],
}