Skip to content

Commit

Permalink
feat: add multiple metadata setters (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxshady authored and xLuxy committed Sep 16, 2024
1 parent bbb1037 commit d49b84b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
11 changes: 11 additions & 0 deletions client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomBaseObjectMeta>>(key: K, value: ICustomBaseObjectMeta[K]): void;
/** @deprecated See {@link ICustomBaseObjectMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomBaseObjectMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomBaseObjectMeta>): void;
}

/** [Documentation](https://docs.altv.mp/articles/virtualentity.html) */
Expand Down Expand Up @@ -739,6 +740,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomAudioMeta>>(key: K, value: ICustomAudioMeta[K]): void;
/** @deprecated See {@link ICustomAudioMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomAudioMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomAudioMeta>): void;
}

export class AudioOutput extends BaseObject {
Expand Down Expand Up @@ -847,6 +849,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomCheckpointMeta>>(key: K, value: ICustomCheckpointMeta[K]): void;
/** @deprecated See {@link ICustomCheckpointMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomCheckpointMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomCheckpointMeta>): void;
}

export class Entity extends WorldObject {
Expand Down Expand Up @@ -916,6 +919,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomEntityMeta>>(key: K, value: ICustomEntityMeta[K]): void;
/** @deprecated See {@link ICustomEntityMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomEntityMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomEntityMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomEntityMeta>>(key: K): void;
Expand Down Expand Up @@ -1202,6 +1206,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomPlayerMeta>>(key: K, value: ICustomPlayerMeta[K]): void;
/** @deprecated See {@link ICustomPlayerMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomPlayerMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomPlayerMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomPlayerMeta>>(key: K): void;
Expand Down Expand Up @@ -1282,6 +1287,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomLocalPlayerMeta>>(key: K, value: ICustomLocalPlayerMeta[K]): void;
/** @deprecated See {@link ICustomLocalPlayerMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomLocalPlayerMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomLocalPlayerMeta>): void;
}

export class Vehicle extends Entity {
Expand Down Expand Up @@ -1734,6 +1740,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomVehicleMeta>>(key: K, value: ICustomVehicleMeta[K]): void;
/** @deprecated See {@link ICustomVehicleMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomVehicleMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomVehicleMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomVehicleMeta>>(key: K): void;
Expand Down Expand Up @@ -1998,6 +2005,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomWebViewMeta>>(key: K, value: ICustomWebViewMeta[K]): void;
/** @deprecated See {@link ICustomWebViewMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomWebViewMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomWebViewMeta>): void;
}

/** @deprecated */
Expand Down Expand Up @@ -2249,6 +2257,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomBlipMeta>>(key: K, value: ICustomBlipMeta[K]): void;
/** @deprecated See {@link ICustomBlipMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomBlipMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomBlipMeta>): void;
}

export class AreaBlip extends Blip {
Expand Down Expand Up @@ -3987,6 +3996,7 @@ declare module "alt-client" {

public setMeta<K extends string>(key: K, value: shared.InterfaceValueByKey<ICustomPedMeta, K>): void;
public setMeta<K extends shared.ExtractStringKeys<ICustomPedMeta>>(key: K, value: ICustomPedMeta[K]): void;
public setMeta(values: shared.MetaValues<ICustomPedMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomPedMeta>>(key: K): void;
Expand Down Expand Up @@ -4168,6 +4178,7 @@ declare module "alt-client" {
public setMeta<K extends shared.ExtractStringKeys<ICustomColshapeMeta>>(key: K, value: ICustomColshapeMeta[K]): void;
/** @deprecated See {@link ICustomColshapeMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomColshapeMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomColshapeMeta>): void;
}

export class ColshapeCylinder extends Colshape {
Expand Down
30 changes: 24 additions & 6 deletions server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomBaseObjectMeta>>(key: K, value: ICustomBaseObjectMeta[K]): void;
/** @deprecated See {@link ICustomBaseObjectMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomBaseObjectMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomBaseObjectMeta>): void;

/**
* Removes the specified key and the data connected to that specific key.
Expand All @@ -707,6 +708,7 @@ declare module "alt-server" {
public setSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomBaseObjectSyncedMeta>>(key: K, value: shared.ICustomBaseObjectSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomBaseObjectSyncedMeta} */
public setSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomBaseObjectSyncedMeta, K, V>): void;
public setSyncedMeta(values: shared.MetaValues<shared.ICustomBaseObjectSyncedMeta>): void;
}

export class WorldObject extends BaseObject {
Expand Down Expand Up @@ -792,6 +794,7 @@ declare module "alt-server" {
public setStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomVirtualEntityStreamSyncedMeta>>(key: K, value: shared.ICustomVirtualEntityStreamSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomVirtualEntityStreamSyncedMeta} */
public setStreamSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomVirtualEntityStreamSyncedMeta, K, V>): void;
public setStreamSyncedMeta(values: shared.MetaValues<shared.ICustomVirtualEntityStreamSyncedMeta>): void;

/**
* Removes the specified key and the data connected to that specific key.
Expand Down Expand Up @@ -857,6 +860,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomEntityMeta>>(key: K, value: ICustomEntityMeta[K]): void;
/** @deprecated See {@link ICustomEntityMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomEntityMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomEntityMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomEntityMeta>>(key: K): void;
Expand Down Expand Up @@ -911,6 +915,7 @@ declare module "alt-server" {
public setSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomEntitySyncedMeta>>(key: K, value: shared.ICustomEntitySyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomEntitySyncedMeta} */
public setSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomEntitySyncedMeta, K, V>): void;
public setSyncedMeta(values: shared.MetaValues<shared.ICustomEntitySyncedMeta>): void;

/**
* Removes the specified key and the data connected to that specific key.
Expand Down Expand Up @@ -954,6 +959,7 @@ declare module "alt-server" {
public setStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomEntityStreamSyncedMeta>>(key: K, value: shared.ICustomEntityStreamSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomEntityStreamSyncedMeta} */
public setStreamSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomEntityStreamSyncedMeta, K, V>): void;
public setStreamSyncedMeta(values: shared.MetaValues<shared.ICustomEntityStreamSyncedMeta>): void;

/**
* Changes network owner to the specified player.
Expand Down Expand Up @@ -1485,6 +1491,7 @@ declare module "alt-server" {
public setLocalMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerLocalMeta>>(key: K, value: shared.ICustomPlayerLocalMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomPlayerLocalMeta} */
public setLocalMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomPlayerLocalMeta, K, V>): void;
public setLocalMeta(values: shared.MetaValues<shared.ICustomPlayerLocalMeta>): void;

public deleteLocalMeta(key: string): void;
public deleteLocalMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerLocalMeta>>(key: K): void;
Expand All @@ -1511,6 +1518,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomPlayerMeta>>(key: K, value: ICustomPlayerMeta[K]): void;
/** @deprecated See {@link ICustomPlayerMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomPlayerMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomPlayerMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomPlayerMeta>>(key: K): void;
Expand All @@ -1529,6 +1537,7 @@ declare module "alt-server" {
public setSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerSyncedMeta>>(key: K, value: shared.ICustomPlayerSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomPlayerSyncedMeta} */
public setSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomPlayerSyncedMeta, K, V>): void;
public setSyncedMeta(values: shared.MetaValues<shared.ICustomPlayerSyncedMeta>): void;

public deleteSyncedMeta(key: string): void;
public deleteSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerSyncedMeta>>(key: K): void;
Expand All @@ -1547,6 +1556,7 @@ declare module "alt-server" {
public setStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerStreamSyncedMeta>>(key: K, value: shared.ICustomPlayerStreamSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomPlayerStreamSyncedMeta} */
public setStreamSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomPlayerStreamSyncedMeta, K, V>): void;
public setStreamSyncedMeta(values: shared.MetaValues<shared.ICustomPlayerStreamSyncedMeta>): void;

public deleteStreamSyncedMeta(key: string): void;
public deleteStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerStreamSyncedMeta>>(key: K): void;
Expand Down Expand Up @@ -2491,6 +2501,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomVehicleMeta>>(key: K, value: ICustomVehicleMeta[K]): void;
/** @deprecated See {@link ICustomVehicleMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomVehicleMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomVehicleMeta>): void;

public deleteMeta(key: string): void;
public deleteMeta<K extends shared.ExtractStringKeys<ICustomVehicleMeta>>(key: K): void;
Expand All @@ -2509,6 +2520,7 @@ declare module "alt-server" {
public setSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomVehicleSyncedMeta>>(key: K, value: shared.ICustomVehicleSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomVehicleSyncedMeta} */
public setSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomVehicleSyncedMeta, K, V>): void;
public setSyncedMeta(values: shared.MetaValues<shared.ICustomVehicleSyncedMeta>): void;

public deleteSyncedMeta(key: string): void;
public deleteSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomVehicleSyncedMeta>>(key: K): void;
Expand All @@ -2527,6 +2539,7 @@ declare module "alt-server" {
public setStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomVehicleStreamSyncedMeta>>(key: K, value: shared.ICustomVehicleStreamSyncedMeta[K]): void;
/** @deprecated See {@link "alt-shared".ICustomVehicleStreamSyncedMeta} */
public setStreamSyncedMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomVehicleStreamSyncedMeta, K, V>): void;
public setStreamSyncedMeta(values: shared.MetaValues<shared.ICustomVehicleStreamSyncedMeta>): void;

public deleteStreamSyncedMeta(key: string): void;
public deleteStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomVehicleStreamSyncedMeta>>(key: K): void;
Expand Down Expand Up @@ -2667,6 +2680,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomBlipMeta>>(key: K, value: ICustomBlipMeta[K]): void;
/** @deprecated See {@link ICustomBlipMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomBlipMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomBlipMeta>): void;
}

export class AreaBlip extends Blip {
Expand Down Expand Up @@ -2732,6 +2746,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomColshapeMeta>>(key: K, value: ICustomColshapeMeta[K]): void;
/** @deprecated See {@link ICustomColshapeMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomColshapeMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomColshapeMeta>): void;
}

export class ColshapeCylinder extends Colshape {
Expand Down Expand Up @@ -2792,18 +2807,20 @@ declare module "alt-server" {

public setMeta<K extends string>(key: K, value: shared.InterfaceValueByKey<ICustomCheckpointMeta, K>): void;
public setMeta<K extends shared.ExtractStringKeys<ICustomCheckpointMeta>>(key: K, value: ICustomCheckpointMeta[K]): void;
public setMeta(values: shared.MetaValues<ICustomCheckpointMeta>): void;

public setStreamSyncedMeta<K extends string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomPlayerStreamSyncedMeta, K>): void;
public setStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerStreamSyncedMeta>>(key: K, value: shared.ICustomPlayerStreamSyncedMeta[K]): void;
public setStreamSyncedMeta<K extends string>(key: K, value: shared.InterfaceValueByKey<shared.ICustomCheckpointStreamSyncedMeta, K>): void;
public setStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomCheckpointStreamSyncedMeta>>(key: K, value: shared.ICustomCheckpointStreamSyncedMeta[K]): void;
public setStreamSyncedMeta(values: shared.MetaValues<shared.ICustomCheckpointStreamSyncedMeta>): void;

public deleteStreamSyncedMeta(key: string): void;
public deleteStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerStreamSyncedMeta>>(key: K): void;
public deleteStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomCheckpointStreamSyncedMeta>>(key: K): void;

public getStreamSyncedMeta<K extends string>(key: Exclude<K, keyof shared.ICustomPlayerStreamSyncedMeta>): unknown;
public getStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerStreamSyncedMeta>>(key: K): shared.ICustomPlayerStreamSyncedMeta[K] | undefined;
public getStreamSyncedMeta<K extends string>(key: Exclude<K, keyof shared.ICustomCheckpointStreamSyncedMeta>): unknown;
public getStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomCheckpointStreamSyncedMeta>>(key: K): shared.ICustomCheckpointStreamSyncedMeta[K] | undefined;

public hasStreamSyncedMeta(key: string): boolean;
public hasStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomPlayerStreamSyncedMeta>>(key: K): boolean;
public hasStreamSyncedMeta<K extends shared.ExtractStringKeys<shared.ICustomCheckpointStreamSyncedMeta>>(key: K): boolean;

public getStreamSyncedMetaKeys(): readonly string[];
}
Expand Down Expand Up @@ -2862,6 +2879,7 @@ declare module "alt-server" {
public setMeta<K extends shared.ExtractStringKeys<ICustomVoiceChannelMeta>>(key: K, value: ICustomVoiceChannelMeta[K]): void;
/** @deprecated See {@link ICustomVoiceChannelMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: shared.InterfaceValueByKey<ICustomVoiceChannelMeta, K, V>): void;
public setMeta(values: shared.MetaValues<ICustomVoiceChannelMeta>): void;

public readonly players: readonly Player[];

Expand Down
35 changes: 35 additions & 0 deletions shared/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,33 @@ declare module "alt-shared" {
>
);

/**
* This is an internal utility type and you probably don't need it
*
* Converts metadata interface for multi values setter.
* For example, `setStreamSyncedMeta(values: MetaValues<ICustomVehicleStreamSyncedMeta>): void` in `alt.Vehicle`:
* ```
* declare module "alt-shared" {
* export interface ICustomVehicleStreamSyncedMeta {
* typed: boolean,
* }
* }
*
* // vehicle is alt.Vehicle
* vehicle.setStreamSyncedMeta({
* // must be boolean
* typed: true,
*
* // unknown type
* a: 1,
* b: 2
* });
* ```
*
* @hidden
*/
export type MetaValues<TInterface> = Partial<TInterface> & Record<string, unknown>;

export interface IVector2 {
readonly x: number;
readonly y: number;
Expand Down Expand Up @@ -1895,6 +1922,13 @@ declare module "alt-shared" {
*/
export interface ICustomPedStreamSyncedMeta extends ICustomEntityStreamSyncedMeta {}

/**
* Extend it by interface merging for use in checkpoint stream synced meta (class `Checkpoint` on client & server, e.g. `checkpoint.getStreamSyncedMeta`)
*
* @remarks See {@link ICustomGlobalMeta} for an example of use
*/
export interface ICustomCheckpointStreamSyncedMeta {}

/**
* Extend `alt.emitServer` and `alt.onServer` auto-completion by merging interfaces.
*
Expand Down Expand Up @@ -2604,6 +2638,7 @@ declare module "alt-shared" {
public setMeta<K extends ExtractStringKeys<ICustomBaseObjectMeta>>(key: K, value: ICustomBaseObjectMeta[K]): void;
/** @deprecated See {@link ICustomBaseObjectMeta} */
public setMeta<V extends any, K extends string = string>(key: K, value: InterfaceValueByKey<ICustomBaseObjectMeta, K, V>): void;
public setMeta(values: MetaValues<ICustomBaseObjectMeta>): void;

/**
* Gets a value using the specified key.
Expand Down

0 comments on commit d49b84b

Please sign in to comment.