@warpfx/server 0.1.0 → 0.1.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 CHANGED
@@ -92,5 +92,63 @@ declare function onPlayerDisconnect(cb: (player: PlayerEventContext) => void): v
92
92
  declare function getBridge(): any;
93
93
  /** Subscribe to database tables. Call inside onReady(). */
94
94
  declare function subscribe(queries: string[]): Promise<void>;
95
+ /** Sync configuration for a table. */
96
+ interface SyncConfig {
97
+ /** Who receives updates for this table. */
98
+ to: "owner" | "all";
99
+ /** Column name for owner filtering (required when to: 'owner'). */
100
+ scope?: string;
101
+ /** Primary key column for row identity (defaults to 'id'). */
102
+ key?: string;
103
+ }
104
+ /** Context passed to action handlers. */
105
+ interface ActionContext {
106
+ /** FiveM server-side player ID. */
107
+ source: number;
108
+ /** Player's citizen ID (license identifier). */
109
+ citizenId: string;
110
+ /** Player's display name. */
111
+ name: string;
112
+ /** Database table accessors (read-only). */
113
+ db: any;
114
+ /** Database reducer proxy (for mutations). */
115
+ reducers: any;
116
+ }
117
+ /** Action handler function. */
118
+ type ActionHandler = (ctx: ActionContext, payload: any) => Promise<void> | void;
119
+ /**
120
+ * Register a table for automatic sync to clients.
121
+ *
122
+ * The sync engine subscribes to SpacetimeDB table changes and routes
123
+ * updates to the correct players based on the config. Call inside onReady().
124
+ *
125
+ * @example
126
+ * registerSync('inventory', { to: 'owner', scope: 'ownerId', key: 'id' });
127
+ * registerSync('itemDefinitions', { to: 'all', key: 'name' });
128
+ */
129
+ declare function registerSync(table: string, config: SyncConfig): void;
130
+ /**
131
+ * Register an action handler that clients can invoke via useAction().
132
+ *
133
+ * Actions are the only entry point for client-initiated mutations.
134
+ * The sync engine handles security, error routing, and state updates.
135
+ *
136
+ * @example
137
+ * registerAction('inventory:moveItem', async (ctx, { itemId, toSlot }) => {
138
+ * await ctx.reducers.moveItem(ctx.citizenId, itemId, toSlot);
139
+ * });
140
+ */
141
+ declare function registerAction(name: string, handler: ActionHandler): void;
142
+ /**
143
+ * Typed error for action handlers. Thrown errors with a `code` property
144
+ * are sent to the client as structured error messages.
145
+ *
146
+ * @example
147
+ * throw new WarpError('ITEM_NOT_FOUND', 'That item no longer exists');
148
+ */
149
+ declare class WarpError extends Error {
150
+ code: string;
151
+ constructor(code: string, message?: string);
152
+ }
95
153
 
96
- export { type EntityStore, type PlayerEventContext, type PlayerRow, type ServerEventBus, getBridge, getEntities, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onReady, provide, subscribe, use };
154
+ export { type ActionContext, type ActionHandler, type EntityStore, type PlayerEventContext, type PlayerRow, type ServerEventBus, type SyncConfig, WarpError, getBridge, getEntities, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onReady, provide, registerAction, registerSync, subscribe, use };
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ WarpError: () => WarpError,
23
24
  getBridge: () => getBridge,
24
25
  getEntities: () => getEntities,
25
26
  getEvents: () => getEvents,
@@ -30,6 +31,8 @@ __export(index_exports, {
30
31
  onPlayerDisconnect: () => onPlayerDisconnect,
31
32
  onReady: () => onReady,
32
33
  provide: () => provide,
34
+ registerAction: () => registerAction,
35
+ registerSync: () => registerSync,
33
36
  subscribe: () => subscribe,
34
37
  use: () => use
35
38
  });
@@ -73,8 +76,22 @@ function getBridge() {
73
76
  function subscribe(queries) {
74
77
  return warp().subscribe(queries);
75
78
  }
79
+ function registerSync(table, config) {
80
+ warp().registerSync(table, config);
81
+ }
82
+ function registerAction(name, handler) {
83
+ warp().registerAction(name, handler);
84
+ }
85
+ var WarpError = class extends Error {
86
+ constructor(code, message) {
87
+ super(message ?? code);
88
+ this.code = code;
89
+ this.name = "WarpError";
90
+ }
91
+ };
76
92
  // Annotate the CommonJS export names for ESM import in node:
77
93
  0 && (module.exports = {
94
+ WarpError,
78
95
  getBridge,
79
96
  getEntities,
80
97
  getEvents,
@@ -85,6 +102,8 @@ function subscribe(queries) {
85
102
  onPlayerDisconnect,
86
103
  onReady,
87
104
  provide,
105
+ registerAction,
106
+ registerSync,
88
107
  subscribe,
89
108
  use
90
109
  });
package/package.json CHANGED
@@ -1,22 +1,27 @@
1
1
  {
2
2
  "name": "@warpfx/server",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Warp Framework SDK for server-side FiveM module development",
5
+ "keywords": [
6
+ "fivem",
7
+ "framework",
8
+ "server",
9
+ "warp"
10
+ ],
5
11
  "license": "MIT",
6
12
  "repository": {
7
13
  "type": "git",
8
14
  "url": "https://github.com/1camou/warp.git",
9
15
  "directory": "packages/server"
10
16
  },
11
- "keywords": ["fivem", "warp", "server", "framework"],
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
17
  "files": [
16
18
  "dist"
17
19
  ],
18
20
  "main": "dist/index.js",
19
21
  "types": "dist/index.d.ts",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
20
25
  "scripts": {
21
26
  "build": "tsup src/index.ts --format cjs --dts --out-dir dist --target node22"
22
27
  }