@warpfx/server 0.3.1 → 0.3.3
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 +62 -8
- package/dist/index.js +5 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Schema types for Warp
|
|
2
|
+
* Schema types for Warp resource developers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Resources define their database tables in a `warp.schema.json` file
|
|
5
5
|
* placed at the root of their FiveM resource. These types document
|
|
6
6
|
* the expected format.
|
|
7
7
|
*
|
|
@@ -81,12 +81,35 @@ interface TableDef {
|
|
|
81
81
|
*/
|
|
82
82
|
access?: AccessMode;
|
|
83
83
|
}
|
|
84
|
+
/** Parameter/field definition for actions and functions. */
|
|
85
|
+
interface ParamDef {
|
|
86
|
+
/** The data type of this parameter. */
|
|
87
|
+
type: ColumnType;
|
|
88
|
+
/** If true, this parameter is optional in the payload. */
|
|
89
|
+
optional?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** Action definition — declares the payload shape for a client-to-server action. */
|
|
92
|
+
interface ActionDef {
|
|
93
|
+
/** Parameters the action accepts from the client. */
|
|
94
|
+
params: Record<string, ParamDef>;
|
|
95
|
+
}
|
|
96
|
+
/** Function definition — declares request params and return shape for a client-to-server function. */
|
|
97
|
+
interface FunctionDef {
|
|
98
|
+
/** Parameters the function accepts from the client. */
|
|
99
|
+
params: Record<string, ParamDef>;
|
|
100
|
+
/** Fields the function returns to the client. */
|
|
101
|
+
returns: Record<string, ParamDef>;
|
|
102
|
+
}
|
|
84
103
|
/** The full warp.schema.json format. */
|
|
85
104
|
interface WarpSchema {
|
|
86
|
-
/** Unique
|
|
105
|
+
/** Unique resource name (used as table prefix in the database). */
|
|
87
106
|
module: string;
|
|
88
107
|
/** Table definitions keyed by table name. */
|
|
89
108
|
tables: Record<string, TableDef>;
|
|
109
|
+
/** Action definitions keyed by action name. */
|
|
110
|
+
actions?: Record<string, ActionDef>;
|
|
111
|
+
/** Function definitions keyed by function name. */
|
|
112
|
+
functions?: Record<string, FunctionDef>;
|
|
90
113
|
/** Schema version number (increment when making breaking changes). */
|
|
91
114
|
version?: number;
|
|
92
115
|
/** Acknowledged breaking changes (required in production for destructive schema changes). */
|
|
@@ -94,7 +117,7 @@ interface WarpSchema {
|
|
|
94
117
|
}
|
|
95
118
|
|
|
96
119
|
/**
|
|
97
|
-
* @warpfx/server — Server-side SDK for Warp
|
|
120
|
+
* @warpfx/server — Server-side SDK for Warp resource development.
|
|
98
121
|
*
|
|
99
122
|
* Clean, minimal API for building FiveM server features with Warp.
|
|
100
123
|
* All calls delegate to the Warp core via FiveM resource exports.
|
|
@@ -245,6 +268,37 @@ declare function fn<T = any>(name: string, handler: (player: Player, payload: an
|
|
|
245
268
|
* }, (player, args) => { ... });
|
|
246
269
|
*/
|
|
247
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;
|
|
248
302
|
/**
|
|
249
303
|
* Create an error to throw from action/function handlers.
|
|
250
304
|
* The error is sent back to the client with a structured code and message.
|
|
@@ -269,7 +323,7 @@ declare function table<T = any>(name: string): Table<T>;
|
|
|
269
323
|
* React to any change in a database table.
|
|
270
324
|
*
|
|
271
325
|
* Fires on insert, update, or delete — regardless of what caused the change
|
|
272
|
-
* (action, another
|
|
326
|
+
* (action, another resource, migration, Studio edit). Works on all tables
|
|
273
327
|
* including server-only tables without an `access` field.
|
|
274
328
|
*
|
|
275
329
|
* @example
|
|
@@ -287,9 +341,9 @@ declare function onTableChange<T = any>(table: string, handler: (change: TableCh
|
|
|
287
341
|
declare function onReady(cb: () => void): void;
|
|
288
342
|
/** Check if Warp has finished booting. */
|
|
289
343
|
declare function isReady(): boolean;
|
|
290
|
-
/** Register a service that other
|
|
344
|
+
/** Register a service that other resources can resolve via use(). */
|
|
291
345
|
declare function provide<T>(token: string, service: T): void;
|
|
292
|
-
/** Resolve a service registered by another
|
|
346
|
+
/** Resolve a service registered by another resource. */
|
|
293
347
|
declare function use<T = unknown>(token: string): T;
|
|
294
348
|
/** Get the shared event bus instance. */
|
|
295
349
|
declare function getEvents<TMap extends Record<string, any> = Record<string, any>>(): ServerEventBus<TMap>;
|
|
@@ -314,4 +368,4 @@ declare function getBridge(): any;
|
|
|
314
368
|
/** Subscribe to database tables. */
|
|
315
369
|
declare function subscribe(queries: string[]): Promise<void>;
|
|
316
370
|
|
|
317
|
-
export { type AccessMode, type ActionError, type ColumnDef, type ColumnType, type CommandOptions, type CommandParam, type EntityStore, 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,
|