@warpfx/server 0.1.1 → 0.1.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 CHANGED
@@ -1,3 +1,88 @@
1
+ /**
2
+ * Schema types for Warp module developers.
3
+ *
4
+ * Modules define their database tables in a `warp.schema.json` file
5
+ * placed at the root of their FiveM resource. These types document
6
+ * the expected format.
7
+ *
8
+ * @example
9
+ * ```json
10
+ * {
11
+ * "module": "superrobbery",
12
+ * "tables": {
13
+ * "robberies": {
14
+ * "columns": {
15
+ * "id": { "type": "string", "primaryKey": true },
16
+ * "name": { "type": "string" },
17
+ * "reward": { "type": "number", "default": 0 },
18
+ * "lastRobbedBy": { "type": "string", "optional": true }
19
+ * }
20
+ * }
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * ## Column Types
26
+ *
27
+ * | Type | Description | SpacetimeDB |
28
+ * |------------|------------------------------|-------------|
29
+ * | `string` | UTF-8 text | String |
30
+ * | `number` | 64-bit float (JS number) | F64 |
31
+ * | `boolean` | true/false | Bool |
32
+ *
33
+ * ## Column Options
34
+ *
35
+ * | Option | Type | Description |
36
+ * |--------------|-----------|------------------------------------------|
37
+ * | `primaryKey` | boolean | Marks this column as the table's PK |
38
+ * | `optional` | boolean | Column can be null/undefined |
39
+ * | `default` | any | Default value for new rows |
40
+ *
41
+ * ## Breaking Changes
42
+ *
43
+ * When you modify a schema in a way that could lose data (remove column,
44
+ * change type, etc.), Warp will block startup in production mode.
45
+ * To acknowledge breaking changes, add an `allowBreaking` array:
46
+ *
47
+ * ```json
48
+ * {
49
+ * "module": "superrobbery",
50
+ * "tables": { ... },
51
+ * "allowBreaking": ["robberies.cooldown:removed"],
52
+ * "version": 2
53
+ * }
54
+ * ```
55
+ */
56
+ /** Supported column types. */
57
+ type ColumnType = "string" | "number" | "boolean";
58
+ /** Column definition in a warp.schema.json table. */
59
+ interface ColumnDef {
60
+ /** The data type of this column. */
61
+ type: ColumnType;
62
+ /** If true, this column is the table's primary key. Exactly one required per table. */
63
+ primaryKey?: boolean;
64
+ /** If true, this column can be null/undefined. Cannot be combined with primaryKey. */
65
+ optional?: boolean;
66
+ /** Default value for this column when inserting a row without it. */
67
+ default?: unknown;
68
+ }
69
+ /** Table definition in a warp.schema.json. */
70
+ interface TableDef {
71
+ /** Column definitions keyed by column name. */
72
+ columns: Record<string, ColumnDef>;
73
+ }
74
+ /** The full warp.schema.json format. */
75
+ interface WarpSchema {
76
+ /** Unique module name (used as table prefix in the database). */
77
+ module: string;
78
+ /** Table definitions keyed by table name. */
79
+ tables: Record<string, TableDef>;
80
+ /** Schema version number (increment when making breaking changes). */
81
+ version?: number;
82
+ /** Acknowledged breaking changes (required in production for destructive schema changes). */
83
+ allowBreaking?: string[];
84
+ }
85
+
1
86
  /**
2
87
  * @warp/server — Typed SDK for Warp server-side module development.
3
88
  *
@@ -29,6 +114,27 @@ interface PlayerRow {
29
114
  online: boolean;
30
115
  lastSeen: bigint;
31
116
  }
117
+ /** Player lifecycle state. */
118
+ type PlayerState = "connecting" | "connected" | "spawned";
119
+ /** Player entity with ECS component access. */
120
+ interface PlayerEntity {
121
+ /** FiveM server-side player ID. */
122
+ readonly source: number;
123
+ /** Citizen ID (license identifier). */
124
+ readonly citizenId: string;
125
+ /** Display name. */
126
+ readonly name: string;
127
+ /** Current lifecycle state. */
128
+ readonly state: PlayerState;
129
+ /** Get a component attached to this player. */
130
+ getComponent<T>(component: string): T | undefined;
131
+ /** Attach or replace a component on this player. */
132
+ setComponent<T>(component: string, data: T): void;
133
+ /** Check if this player has a specific component. */
134
+ hasComponent(component: string): boolean;
135
+ /** Remove a component from this player. */
136
+ removeComponent(component: string): boolean;
137
+ }
32
138
  /** Typed event bus for server-side and network communication. */
33
139
  interface ServerEventBus<TMap extends Record<string, any> = Record<string, any>> {
34
140
  /** Subscribe to a local event. Returns an unsubscribe function. */
@@ -81,8 +187,21 @@ declare function getEntities(): EntityStore;
81
187
  declare function getPlayer(citizenId: string): PlayerRow | null;
82
188
  /** Get all cached players. */
83
189
  declare function getPlayers(): PlayerRow[];
190
+ /**
191
+ * Get the player entity for a citizenId.
192
+ * Returns the entity with lifecycle state and component access.
193
+ */
194
+ declare function getEntity(citizenId: string): PlayerEntity | null;
195
+ /**
196
+ * Transition a player to the "spawned" state.
197
+ * Call after character selection (e.g. from a multichar module).
198
+ * Fires all onPlayerSpawned hooks.
199
+ */
200
+ declare function spawnPlayer(citizenId: string): void;
84
201
  /** Register a callback for when a player connects (database confirmed). */
85
202
  declare function onPlayerConnect(cb: (player: PlayerEventContext) => void): void;
203
+ /** Register a callback for when a player spawns (character selected). */
204
+ declare function onPlayerSpawned(cb: (player: PlayerEventContext) => void): void;
86
205
  /** Register a callback for when a player disconnects. */
87
206
  declare function onPlayerDisconnect(cb: (player: PlayerEventContext) => void): void;
88
207
  /**
@@ -151,4 +270,4 @@ declare class WarpError extends Error {
151
270
  constructor(code: string, message?: string);
152
271
  }
153
272
 
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 };
273
+ 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 };
package/dist/index.js CHANGED
@@ -23,16 +23,19 @@ __export(index_exports, {
23
23
  WarpError: () => WarpError,
24
24
  getBridge: () => getBridge,
25
25
  getEntities: () => getEntities,
26
+ getEntity: () => getEntity,
26
27
  getEvents: () => getEvents,
27
28
  getPlayer: () => getPlayer,
28
29
  getPlayers: () => getPlayers,
29
30
  isReady: () => isReady,
30
31
  onPlayerConnect: () => onPlayerConnect,
31
32
  onPlayerDisconnect: () => onPlayerDisconnect,
33
+ onPlayerSpawned: () => onPlayerSpawned,
32
34
  onReady: () => onReady,
33
35
  provide: () => provide,
34
36
  registerAction: () => registerAction,
35
37
  registerSync: () => registerSync,
38
+ spawnPlayer: () => spawnPlayer,
36
39
  subscribe: () => subscribe,
37
40
  use: () => use
38
41
  });
@@ -64,9 +67,18 @@ function getPlayer(citizenId) {
64
67
  function getPlayers() {
65
68
  return warp().getPlayers();
66
69
  }
70
+ function getEntity(citizenId) {
71
+ return warp().getEntity(citizenId);
72
+ }
73
+ function spawnPlayer(citizenId) {
74
+ warp().spawnPlayer(citizenId);
75
+ }
67
76
  function onPlayerConnect(cb) {
68
77
  warp().onPlayerConnect(cb);
69
78
  }
79
+ function onPlayerSpawned(cb) {
80
+ warp().onPlayerSpawned(cb);
81
+ }
70
82
  function onPlayerDisconnect(cb) {
71
83
  warp().onPlayerDisconnect(cb);
72
84
  }
@@ -94,16 +106,19 @@ var WarpError = class extends Error {
94
106
  WarpError,
95
107
  getBridge,
96
108
  getEntities,
109
+ getEntity,
97
110
  getEvents,
98
111
  getPlayer,
99
112
  getPlayers,
100
113
  isReady,
101
114
  onPlayerConnect,
102
115
  onPlayerDisconnect,
116
+ onPlayerSpawned,
103
117
  onReady,
104
118
  provide,
105
119
  registerAction,
106
120
  registerSync,
121
+ spawnPlayer,
107
122
  subscribe,
108
123
  use
109
124
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warpfx/server",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Warp Framework SDK for server-side FiveM module development",
5
5
  "keywords": [
6
6
  "fivem",