@websimai/socket-types 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.d.mts +29 -42
  2. package/package.json +3 -3
package/dist/index.d.mts CHANGED
@@ -3,47 +3,34 @@ type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
3
3
  type KeyValue = Record<string, any>;
4
4
  //#endregion
5
5
  //#region src/types/collection-api.d.ts
6
- interface CollectionAPI<T extends string> {
7
- getList: <TData extends KeyValue>() => Expand<TData & {
8
- readonly id: string;
9
- readonly $type: T;
10
- readonly created_at: string;
6
+ type BaseData<$Type extends string, Id extends string = string> = {
7
+ readonly id: Id;
8
+ readonly $type: $Type;
9
+ readonly created_at: string;
10
+ readonly username: string;
11
+ };
12
+ interface CollectionAPI<$Type extends string> {
13
+ getList<Data extends KeyValue>(): Expand<Data & BaseData<$Type> & {
11
14
  readonly updated_at: string;
12
15
  readonly user_id: string;
13
- readonly username: string;
14
16
  }>[];
15
- create: <TData extends KeyValue>(data: TData) => Promise<Expand<TData & {
16
- readonly id: string;
17
- readonly $type: T;
18
- readonly created_at: string;
19
- readonly username: string;
20
- }>>;
21
- update: <T_Id extends string, TData extends KeyValue>(id: T_Id, data: TData) => Promise<Expand<TData & {
22
- readonly id: T_Id;
23
- readonly $type: T;
24
- readonly created_at: string;
25
- readonly username: string;
26
- }>>;
27
- upsert: <TData extends KeyValue & {
28
- id?: T_Id;
29
- }, T_Id extends string = string>(data: TData) => Promise<Expand<(TData extends {
30
- id: T_Id;
31
- } ? TData & KeyValue : TData) & {
32
- readonly id: T_Id;
33
- readonly $type: T;
34
- readonly created_at: string;
35
- readonly username: string;
36
- }>>;
37
- delete: (id: string) => Promise<void>;
38
- subscribe: (callback: (records: Expand<KeyValue & {
17
+ create<Data extends KeyValue>(data: Data): Promise<Expand<Data & BaseData<$Type>>>;
18
+ update<Id extends string, Data extends KeyValue>(id: Id, data: Data): Promise<Expand<Data & BaseData<$Type, Id>>>;
19
+ upsert<Data extends KeyValue & {
20
+ id?: Id;
21
+ }, Id extends string = string>(data: Data): Promise<Expand<(Data extends {
22
+ id: Id;
23
+ } ? Data & KeyValue : Data) & BaseData<$Type, Id>>>;
24
+ delete(id: string): Promise<void>;
25
+ subscribe(callback: (records: Expand<KeyValue & {
39
26
  id: string;
40
- $type: T;
27
+ $type: $Type;
41
28
  created_at: string;
42
29
  updated_at: string;
43
30
  user_id: string;
44
31
  username: string;
45
- }>[]) => void) => () => void;
46
- filter: (filters: KeyValue) => CollectionAPI<T>;
32
+ }>[]) => void): () => void;
33
+ filter(filters: KeyValue): CollectionAPI<$Type>;
47
34
  }
48
35
  //#endregion
49
36
  //#region src/types/peers.d.ts
@@ -75,14 +62,14 @@ interface WebsimSocketParty {
75
62
  * This is always up-to-date.
76
63
  */
77
64
  readonly peers: {
78
- [id: string]: {
65
+ readonly [id: string]: {
79
66
  readonly avatarUrl: `https://${string}/${string}`;
80
67
  readonly username: string;
81
68
  readonly id: string;
82
69
  readonly is_anonymous: boolean;
83
70
  };
84
71
  };
85
- subscribe: (callback: (peers: Peers) => void) => () => void;
72
+ subscribe(callback: (peers: Peers) => void): () => void;
86
73
  /**
87
74
  * Object containing the current presence state of all connected peers, including this client.
88
75
  * This is always up-to-date after initialization.
@@ -132,7 +119,7 @@ declare class WebsimSocketClass {
132
119
  close(_code?: number, _reason?: string): void;
133
120
  send<TData extends string | object>(data: TData): void;
134
121
  query<TParams extends unknown = unknown>(queryString: string, params?: TParams[]): QueryAPI;
135
- collection<T extends string>($type: T): CollectionAPI<T>;
122
+ collection<$Type extends string>($type: $Type): CollectionAPI<$Type>;
136
123
  readonly clientId: string;
137
124
  /**
138
125
  * Object containing information about the connected client and their peers.
@@ -159,18 +146,18 @@ declare class WebsimSocketClass {
159
146
  * @param callback Function to call when a presence update is requested.
160
147
  * @returns Function to unsubscribe.
161
148
  */
162
- subscribePresenceUpdateRequests<TUpdateRequest extends KeyValue>(callback: (updateRequest: TUpdateRequest, fromClientId: string) => void): () => void;
149
+ subscribePresenceUpdateRequests<UpdateRequest extends KeyValue>(callback: (updateRequest: UpdateRequest, fromClientId: string) => void): () => void;
163
150
  /**
164
151
  * Updates the room-wide state. This merges with existing state.
165
152
  * @param delta The new state to merge with current room state.
166
153
  */
167
- updateRoomState<TDelta extends KeyValue>(delta: TDelta): void;
154
+ updateRoomState<Delta extends KeyValue>(delta: Delta): void;
168
155
  /**
169
156
  * Subscribe to room state updates.
170
157
  * @param callback Function to call when room state changes.
171
158
  * @returns Function to unsubscribe.
172
159
  */
173
- subscribeRoomState<TRoomState extends KeyValue>(callback: (state: TRoomState) => void): () => void;
160
+ subscribeRoomState<RoomState extends KeyValue>(callback: (state: RoomState) => void): () => void;
174
161
  /**
175
162
  * Object containing the current presence state of all connected peers, including this client.
176
163
  * This is always up-to-date after initialization.
@@ -192,14 +179,14 @@ declare class WebsimSocketClass {
192
179
  * Updates the current client's presence state.
193
180
  * @param presence The new presence state to set.
194
181
  */
195
- updatePresence<TPresence extends KeyValue>(presence: TPresence): void;
182
+ updatePresence<Presence extends KeyValue>(presence: Presence): void;
196
183
  /**
197
184
  * Subscribe to presence updates from all peers.
198
185
  * @param callback Function to call when presence changes.
199
186
  * @returns Function to unsubscribe.
200
187
  */
201
- subscribePresence<TPresence extends KeyValue>(callback: (presence: {
202
- [clientId: string]: TPresence;
188
+ subscribePresence<Presence extends KeyValue>(callback: (presence: {
189
+ [clientId: string]: Presence;
203
190
  }) => void): () => void;
204
191
  }
205
192
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websimai/socket-types",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Type declarations for the `WebsimSocket` class",
5
5
  "type": "module",
6
6
  "author": "GameRoMan",
@@ -11,7 +11,7 @@
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "https://github.com/websimnpm/websim.git",
14
- "directory": "packages/socket-api-types"
14
+ "directory": "packages/socket-types"
15
15
  },
16
16
  "keywords": [
17
17
  "websim",
@@ -35,6 +35,6 @@
35
35
  "./package.json": "./package.json"
36
36
  },
37
37
  "devDependencies": {
38
- "tsdown": "^0.17.3"
38
+ "tsdown": "^0.18.2"
39
39
  }
40
40
  }