@warpfx/server 0.3.2 → 0.3.4
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 +32 -1
- package/dist/index.js +5 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -268,6 +268,37 @@ declare function fn<T = any>(name: string, handler: (player: Player, payload: an
|
|
|
268
268
|
* }, (player, args) => { ... });
|
|
269
269
|
*/
|
|
270
270
|
declare function command(name: string, handlerOrOptions: CommandOptions | ((player: Player, args: string[], raw: string) => void), handler?: (player: Player, args: string[], raw: string) => void): void;
|
|
271
|
+
/** Context passed to middleware handlers. */
|
|
272
|
+
interface MiddlewareContext extends Player {
|
|
273
|
+
/** The action or function name being dispatched. */
|
|
274
|
+
actionName: string;
|
|
275
|
+
/** The payload sent by the client. */
|
|
276
|
+
payload: any;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Register middleware that intercepts actions and functions.
|
|
280
|
+
*
|
|
281
|
+
* Middleware runs in registration order, wrapping the handler (Koa-style).
|
|
282
|
+
* Use glob patterns to match action/function names.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* // Module-scoped — applies to all economy actions
|
|
286
|
+
* middleware('economy:*', async (ctx, next) => {
|
|
287
|
+
* const entity = getEntity(ctx.citizenId);
|
|
288
|
+
* if (entity?.getComponent('frozen')) {
|
|
289
|
+
* throw error('FROZEN', 'Account is frozen');
|
|
290
|
+
* }
|
|
291
|
+
* await next();
|
|
292
|
+
* });
|
|
293
|
+
*
|
|
294
|
+
* // Global — applies to everything
|
|
295
|
+
* middleware('*', async (ctx, next) => {
|
|
296
|
+
* const start = Date.now();
|
|
297
|
+
* await next();
|
|
298
|
+
* console.log(`[${ctx.actionName}] ${Date.now() - start}ms`);
|
|
299
|
+
* });
|
|
300
|
+
*/
|
|
301
|
+
declare function middleware(pattern: string, handler: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void> | void): void;
|
|
271
302
|
/**
|
|
272
303
|
* Create an error to throw from action/function handlers.
|
|
273
304
|
* The error is sent back to the client with a structured code and message.
|
|
@@ -337,4 +368,4 @@ declare function getBridge(): any;
|
|
|
337
368
|
/** Subscribe to database tables. */
|
|
338
369
|
declare function subscribe(queries: string[]): Promise<void>;
|
|
339
370
|
|
|
340
|
-
export { type AccessMode, type ActionDef, type ActionError, type ColumnDef, type ColumnType, type CommandOptions, type CommandParam, type EntityStore, type FunctionDef, type ParamDef, type Player, type PlayerEntity, type PlayerRow, type PlayerState, type ServerEventBus, type Table, type TableChange, type TableDef, type WarpSchema, action, command, error, fn, getBridge, getEntities, getEntity, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onPlayerSpawned, onReady, onTableChange, provide, spawnPlayer, subscribe, table, use };
|
|
371
|
+
export { type AccessMode, type ActionDef, type ActionError, type ColumnDef, type ColumnType, type CommandOptions, type CommandParam, type EntityStore, type FunctionDef, type MiddlewareContext, type ParamDef, type Player, type PlayerEntity, type PlayerRow, type PlayerState, type ServerEventBus, type Table, type TableChange, type TableDef, type WarpSchema, action, command, error, fn, getBridge, getEntities, getEntity, getEvents, getPlayer, getPlayers, isReady, middleware, onPlayerConnect, onPlayerDisconnect, onPlayerSpawned, onReady, onTableChange, provide, spawnPlayer, subscribe, table, use };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
getPlayer: () => getPlayer,
|
|
32
32
|
getPlayers: () => getPlayers,
|
|
33
33
|
isReady: () => isReady,
|
|
34
|
+
middleware: () => middleware,
|
|
34
35
|
onPlayerConnect: () => onPlayerConnect,
|
|
35
36
|
onPlayerDisconnect: () => onPlayerDisconnect,
|
|
36
37
|
onPlayerSpawned: () => onPlayerSpawned,
|
|
@@ -59,6 +60,9 @@ function command(name, handlerOrOptions, handler) {
|
|
|
59
60
|
warp().command(name, handlerOrOptions, handler);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
63
|
+
function middleware(pattern, handler) {
|
|
64
|
+
warp().middleware(pattern, handler);
|
|
65
|
+
}
|
|
62
66
|
function error(code, message) {
|
|
63
67
|
return warp().error(code, message);
|
|
64
68
|
}
|
|
@@ -126,6 +130,7 @@ function subscribe(queries) {
|
|
|
126
130
|
getPlayer,
|
|
127
131
|
getPlayers,
|
|
128
132
|
isReady,
|
|
133
|
+
middleware,
|
|
129
134
|
onPlayerConnect,
|
|
130
135
|
onPlayerDisconnect,
|
|
131
136
|
onPlayerSpawned,
|