@warpfx/server 0.2.0 → 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 +53 -1
- package/dist/index.js +10 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -249,6 +249,8 @@ interface ActionContext {
|
|
|
249
249
|
}
|
|
250
250
|
/** Action handler function. */
|
|
251
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;
|
|
252
254
|
/**
|
|
253
255
|
* Register a table for automatic sync to clients.
|
|
254
256
|
*
|
|
@@ -272,6 +274,20 @@ declare function registerSync(table: string, config: SyncConfig): void;
|
|
|
272
274
|
* });
|
|
273
275
|
*/
|
|
274
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;
|
|
275
291
|
/**
|
|
276
292
|
* Typed error for action handlers. Thrown errors with a `code` property
|
|
277
293
|
* are sent to the client as structured error messages.
|
|
@@ -283,5 +299,41 @@ declare class WarpError extends Error {
|
|
|
283
299
|
code: string;
|
|
284
300
|
constructor(code: string, message?: string);
|
|
285
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;
|
|
286
338
|
|
|
287
|
-
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,
|