@warpfx/server 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Schema types for Warp module developers.
2
+ * Schema types for Warp resource developers.
3
3
  *
4
- * Modules define their database tables in a `warp.schema.json` file
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 module name (used as table prefix in the database). */
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 module development.
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.
@@ -195,6 +218,15 @@ interface ActionError {
195
218
  code: string;
196
219
  message: string;
197
220
  }
221
+ /** Describes a single table row change. */
222
+ interface TableChange<T = any> {
223
+ /** The type of change. */
224
+ type: "insert" | "update" | "delete";
225
+ /** The current row (new on insert/update, deleted row on delete). */
226
+ row: T;
227
+ /** The previous row (on update only, undefined otherwise). */
228
+ oldRow?: T;
229
+ }
198
230
  /**
199
231
  * Register an action handler that clients can invoke.
200
232
  *
@@ -256,6 +288,21 @@ declare function error(code: string, message?: string): Error;
256
288
  * await accounts.update(citizenId, { balance: 500 });
257
289
  */
258
290
  declare function table<T = any>(name: string): Table<T>;
291
+ /**
292
+ * React to any change in a database table.
293
+ *
294
+ * Fires on insert, update, or delete — regardless of what caused the change
295
+ * (action, another resource, migration, Studio edit). Works on all tables
296
+ * including server-only tables without an `access` field.
297
+ *
298
+ * @example
299
+ * onTableChange<Account>('economy_accounts', (change) => {
300
+ * if (change.type === 'update' && change.row.balance < 0) {
301
+ * accounts.update(change.row.citizenId, { frozen: true });
302
+ * }
303
+ * });
304
+ */
305
+ declare function onTableChange<T = any>(table: string, handler: (change: TableChange<T>) => void): void;
259
306
  /**
260
307
  * Register a callback to run when Warp is fully booted.
261
308
  * If Warp is already ready, the callback fires immediately.
@@ -263,9 +310,9 @@ declare function table<T = any>(name: string): Table<T>;
263
310
  declare function onReady(cb: () => void): void;
264
311
  /** Check if Warp has finished booting. */
265
312
  declare function isReady(): boolean;
266
- /** Register a service that other modules can resolve via use(). */
313
+ /** Register a service that other resources can resolve via use(). */
267
314
  declare function provide<T>(token: string, service: T): void;
268
- /** Resolve a service registered by another module. */
315
+ /** Resolve a service registered by another resource. */
269
316
  declare function use<T = unknown>(token: string): T;
270
317
  /** Get the shared event bus instance. */
271
318
  declare function getEvents<TMap extends Record<string, any> = Record<string, any>>(): ServerEventBus<TMap>;
@@ -290,4 +337,4 @@ declare function getBridge(): any;
290
337
  /** Subscribe to database tables. */
291
338
  declare function subscribe(queries: string[]): Promise<void>;
292
339
 
293
- 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 TableDef, type WarpSchema, action, command, error, fn, getBridge, getEntities, getEntity, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onPlayerSpawned, onReady, provide, spawnPlayer, subscribe, table, use };
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 };
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  onPlayerDisconnect: () => onPlayerDisconnect,
36
36
  onPlayerSpawned: () => onPlayerSpawned,
37
37
  onReady: () => onReady,
38
+ onTableChange: () => onTableChange,
38
39
  provide: () => provide,
39
40
  spawnPlayer: () => spawnPlayer,
40
41
  subscribe: () => subscribe,
@@ -64,6 +65,9 @@ function error(code, message) {
64
65
  function table(name) {
65
66
  return warp().table(name);
66
67
  }
68
+ function onTableChange(table2, handler) {
69
+ warp().onTableChange(table2, handler);
70
+ }
67
71
  function onReady(cb) {
68
72
  warp().onReady(cb);
69
73
  }
@@ -126,6 +130,7 @@ function subscribe(queries) {
126
130
  onPlayerDisconnect,
127
131
  onPlayerSpawned,
128
132
  onReady,
133
+ onTableChange,
129
134
  provide,
130
135
  spawnPlayer,
131
136
  subscribe,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warpfx/server",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Warp Framework SDK for server-side FiveM module development",
5
5
  "keywords": [
6
6
  "fivem",