@warpfx/server 0.1.3 → 0.2.1
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.
- package/dist/index.d.ts +68 -2
- package/dist/index.js +10 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -106,13 +106,19 @@ interface PlayerEventContext {
|
|
|
106
106
|
citizenId: string;
|
|
107
107
|
/** Display name. */
|
|
108
108
|
name: string;
|
|
109
|
+
/** Discord identifier (e.g. "discord:123456789"), if linked. */
|
|
110
|
+
discordId?: string;
|
|
111
|
+
/** Steam identifier (e.g. "steam:110000..."), if linked. */
|
|
112
|
+
steamId?: string;
|
|
109
113
|
}
|
|
110
114
|
/** Player data row from the database cache. */
|
|
111
115
|
interface PlayerRow {
|
|
112
116
|
citizenId: string;
|
|
113
117
|
name: string;
|
|
118
|
+
discordId?: string;
|
|
119
|
+
steamId?: string;
|
|
114
120
|
online: boolean;
|
|
115
|
-
lastSeen:
|
|
121
|
+
lastSeen: number;
|
|
116
122
|
}
|
|
117
123
|
/** Player lifecycle state. */
|
|
118
124
|
type PlayerState = "connecting" | "connected" | "spawned";
|
|
@@ -124,6 +130,10 @@ interface PlayerEntity {
|
|
|
124
130
|
readonly citizenId: string;
|
|
125
131
|
/** Display name. */
|
|
126
132
|
readonly name: string;
|
|
133
|
+
/** Discord identifier (e.g. "discord:123456789"), if linked. */
|
|
134
|
+
readonly discordId: string | undefined;
|
|
135
|
+
/** Steam identifier (e.g. "steam:110000..."), if linked. */
|
|
136
|
+
readonly steamId: string | undefined;
|
|
127
137
|
/** Current lifecycle state. */
|
|
128
138
|
readonly state: PlayerState;
|
|
129
139
|
/** Get a component attached to this player. */
|
|
@@ -228,6 +238,10 @@ interface ActionContext {
|
|
|
228
238
|
citizenId: string;
|
|
229
239
|
/** Player's display name. */
|
|
230
240
|
name: string;
|
|
241
|
+
/** Discord identifier (e.g. "discord:123456789"), if linked. */
|
|
242
|
+
discordId?: string;
|
|
243
|
+
/** Steam identifier (e.g. "steam:110000..."), if linked. */
|
|
244
|
+
steamId?: string;
|
|
231
245
|
/** Database table accessors (read-only). */
|
|
232
246
|
db: any;
|
|
233
247
|
/** Database reducer proxy (for mutations). */
|
|
@@ -235,6 +249,8 @@ interface ActionContext {
|
|
|
235
249
|
}
|
|
236
250
|
/** Action handler function. */
|
|
237
251
|
type ActionHandler = (ctx: ActionContext, payload: any) => Promise<void> | void;
|
|
252
|
+
/** Server function handler — returns a value back to the caller. */
|
|
253
|
+
type FunctionHandler<T = any> = (ctx: ActionContext, payload: any) => Promise<T> | T;
|
|
238
254
|
/**
|
|
239
255
|
* Register a table for automatic sync to clients.
|
|
240
256
|
*
|
|
@@ -258,6 +274,20 @@ declare function registerSync(table: string, config: SyncConfig): void;
|
|
|
258
274
|
* });
|
|
259
275
|
*/
|
|
260
276
|
declare function registerAction(name: string, handler: ActionHandler): void;
|
|
277
|
+
/**
|
|
278
|
+
* Register a server function that clients can call and await a result.
|
|
279
|
+
*
|
|
280
|
+
* Unlike actions (fire-and-forget mutations), functions return a value
|
|
281
|
+
* to the caller. Use for request/response patterns like data fetches,
|
|
282
|
+
* calculations, or validations that need a result.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* registerFunction('economy:getBalance', async (ctx) => {
|
|
286
|
+
* const account = ctx.db.economy_accounts.citizenId.find(ctx.citizenId);
|
|
287
|
+
* return { balance: account?.balance ?? 0 };
|
|
288
|
+
* });
|
|
289
|
+
*/
|
|
290
|
+
declare function registerFunction<T = any>(name: string, handler: FunctionHandler<T>): void;
|
|
261
291
|
/**
|
|
262
292
|
* Typed error for action handlers. Thrown errors with a `code` property
|
|
263
293
|
* are sent to the client as structured error messages.
|
|
@@ -269,5 +299,41 @@ declare class WarpError extends Error {
|
|
|
269
299
|
code: string;
|
|
270
300
|
constructor(code: string, message?: string);
|
|
271
301
|
}
|
|
302
|
+
/** Parameter hint shown in command autocomplete. */
|
|
303
|
+
interface CommandParam {
|
|
304
|
+
/** Parameter name displayed in the suggestion (e.g. "id", "reason"). */
|
|
305
|
+
name: string;
|
|
306
|
+
/** Optional help text for the parameter. */
|
|
307
|
+
help?: string;
|
|
308
|
+
}
|
|
309
|
+
/** Options for registerCommand(). */
|
|
310
|
+
interface CommandOptions {
|
|
311
|
+
/** Short description shown in autocomplete. */
|
|
312
|
+
description?: string;
|
|
313
|
+
/** ACE permission required — players without it won't see the command. */
|
|
314
|
+
ace?: string;
|
|
315
|
+
/** Custom permission predicate (overrides ace check when provided). */
|
|
316
|
+
canUse?: (source: number) => boolean;
|
|
317
|
+
/** Parameter hints shown in autocomplete. */
|
|
318
|
+
params?: CommandParam[];
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Register a command with autocomplete support.
|
|
322
|
+
*
|
|
323
|
+
* Players see matching commands as they type in the chat input,
|
|
324
|
+
* filtered by permission. The handler receives the standard FiveM
|
|
325
|
+
* command arguments.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* registerCommand('arrest', {
|
|
329
|
+
* description: 'Arrest a nearby player',
|
|
330
|
+
* ace: 'police.arrest',
|
|
331
|
+
* params: [{ name: 'id', help: 'Player server ID' }],
|
|
332
|
+
* }, (source, args) => {
|
|
333
|
+
* const targetId = parseInt(args[0], 10);
|
|
334
|
+
* // ...
|
|
335
|
+
* });
|
|
336
|
+
*/
|
|
337
|
+
declare function registerCommand(name: string, options: CommandOptions, handler: (source: number, args: string[], rawCommand: string) => void): void;
|
|
272
338
|
|
|
273
|
-
export { type ActionContext, type ActionHandler, type ColumnDef, type ColumnType, type EntityStore, type PlayerEntity, type PlayerEventContext, type PlayerRow, type PlayerState, type ServerEventBus, type SyncConfig, type TableDef, WarpError, type WarpSchema, getBridge, getEntities, getEntity, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onPlayerSpawned, onReady, provide, registerAction, registerSync, spawnPlayer, subscribe, use };
|
|
339
|
+
export { type ActionContext, type ActionHandler, type ColumnDef, type ColumnType, type CommandOptions, type CommandParam, type EntityStore, type FunctionHandler, type PlayerEntity, type PlayerEventContext, type PlayerRow, type PlayerState, type ServerEventBus, type SyncConfig, type TableDef, WarpError, type WarpSchema, getBridge, getEntities, getEntity, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onPlayerSpawned, onReady, provide, registerAction, registerCommand, registerFunction, registerSync, spawnPlayer, subscribe, use };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,8 @@ __export(index_exports, {
|
|
|
34
34
|
onReady: () => onReady,
|
|
35
35
|
provide: () => provide,
|
|
36
36
|
registerAction: () => registerAction,
|
|
37
|
+
registerCommand: () => registerCommand,
|
|
38
|
+
registerFunction: () => registerFunction,
|
|
37
39
|
registerSync: () => registerSync,
|
|
38
40
|
spawnPlayer: () => spawnPlayer,
|
|
39
41
|
subscribe: () => subscribe,
|
|
@@ -94,6 +96,9 @@ function registerSync(table, config) {
|
|
|
94
96
|
function registerAction(name, handler) {
|
|
95
97
|
warp().registerAction(name, handler);
|
|
96
98
|
}
|
|
99
|
+
function registerFunction(name, handler) {
|
|
100
|
+
warp().registerFunction(name, handler);
|
|
101
|
+
}
|
|
97
102
|
var WarpError = class extends Error {
|
|
98
103
|
constructor(code, message) {
|
|
99
104
|
super(message ?? code);
|
|
@@ -101,6 +106,9 @@ var WarpError = class extends Error {
|
|
|
101
106
|
this.name = "WarpError";
|
|
102
107
|
}
|
|
103
108
|
};
|
|
109
|
+
function registerCommand(name, options, handler) {
|
|
110
|
+
warp().registerCommand(name, options, handler);
|
|
111
|
+
}
|
|
104
112
|
// Annotate the CommonJS export names for ESM import in node:
|
|
105
113
|
0 && (module.exports = {
|
|
106
114
|
WarpError,
|
|
@@ -117,6 +125,8 @@ var WarpError = class extends Error {
|
|
|
117
125
|
onReady,
|
|
118
126
|
provide,
|
|
119
127
|
registerAction,
|
|
128
|
+
registerCommand,
|
|
129
|
+
registerFunction,
|
|
120
130
|
registerSync,
|
|
121
131
|
spawnPlayer,
|
|
122
132
|
subscribe,
|