@warpfx/server 0.1.0
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 +96 -0
- package/dist/index.js +90 -0
- package/package.json +23 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @warp/server — Typed SDK for Warp server-side module development.
|
|
3
|
+
*
|
|
4
|
+
* Provides type-safe access to the Warp core API. Under the hood,
|
|
5
|
+
* all calls go through FiveM's resource exports to the 'warp' resource.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { onReady, provide, use, getEvents } from '@warp/server';
|
|
9
|
+
*
|
|
10
|
+
* onReady(() => {
|
|
11
|
+
* const events = getEvents();
|
|
12
|
+
* events.on('player:spawned', (data) => { ... });
|
|
13
|
+
* provide('economy', new EconomyService());
|
|
14
|
+
* });
|
|
15
|
+
*/
|
|
16
|
+
/** Player lifecycle event data. */
|
|
17
|
+
interface PlayerEventContext {
|
|
18
|
+
/** FiveM server-side player ID. */
|
|
19
|
+
source: number;
|
|
20
|
+
/** Citizen ID (license identifier). */
|
|
21
|
+
citizenId: string;
|
|
22
|
+
/** Display name. */
|
|
23
|
+
name: string;
|
|
24
|
+
}
|
|
25
|
+
/** Player data row from the database cache. */
|
|
26
|
+
interface PlayerRow {
|
|
27
|
+
citizenId: string;
|
|
28
|
+
name: string;
|
|
29
|
+
online: boolean;
|
|
30
|
+
lastSeen: bigint;
|
|
31
|
+
}
|
|
32
|
+
/** Typed event bus for server-side and network communication. */
|
|
33
|
+
interface ServerEventBus<TMap extends Record<string, any> = Record<string, any>> {
|
|
34
|
+
/** Subscribe to a local event. Returns an unsubscribe function. */
|
|
35
|
+
on<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): () => void;
|
|
36
|
+
/** Unsubscribe from a local event. */
|
|
37
|
+
off<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
38
|
+
/** Emit a local event to all subscribers. */
|
|
39
|
+
emit<K extends string & keyof TMap>(event: K, data: TMap[K]): void;
|
|
40
|
+
/** Send an event to a specific client. */
|
|
41
|
+
emitClient<K extends string & keyof TMap>(event: K, target: number, data: TMap[K]): void;
|
|
42
|
+
/** Broadcast an event to all connected clients. */
|
|
43
|
+
emitAllClients<K extends string & keyof TMap>(event: K, data: TMap[K]): void;
|
|
44
|
+
/** Listen for events from clients. Returns an unsubscribe function. */
|
|
45
|
+
onClient<K extends string & keyof TMap>(event: K, handler: (source: number, data: TMap[K]) => void): () => void;
|
|
46
|
+
/** Unsubscribe from a client event. */
|
|
47
|
+
offClient<K extends string & keyof TMap>(event: K, handler: (source: number, data: TMap[K]) => void): void;
|
|
48
|
+
}
|
|
49
|
+
/** ECS-inspired entity component store. */
|
|
50
|
+
interface EntityStore {
|
|
51
|
+
/** Attach a component to an entity. */
|
|
52
|
+
attach<T>(entityId: string, component: string, data: T): void;
|
|
53
|
+
/** Get a component from an entity. Returns undefined if not found. */
|
|
54
|
+
get<T>(entityId: string, component: string): T | undefined;
|
|
55
|
+
/** Remove a component from an entity. */
|
|
56
|
+
detach(entityId: string, component: string): boolean;
|
|
57
|
+
/** Remove all components for an entity. */
|
|
58
|
+
removeEntity(entityId: string): void;
|
|
59
|
+
/** Check if an entity has a specific component. */
|
|
60
|
+
has(entityId: string, component: string): boolean;
|
|
61
|
+
/** Iterate all entities that have a specific component. */
|
|
62
|
+
query<T>(component: string): IterableIterator<[string, T]>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Register a callback to run when Warp is fully booted.
|
|
66
|
+
* If Warp is already ready, the callback fires immediately.
|
|
67
|
+
* All other SDK functions should be called inside this callback.
|
|
68
|
+
*/
|
|
69
|
+
declare function onReady(cb: () => void): void;
|
|
70
|
+
/** Check if Warp has finished booting. */
|
|
71
|
+
declare function isReady(): boolean;
|
|
72
|
+
/** Register a service that other modules can resolve via use(). */
|
|
73
|
+
declare function provide<T>(token: string, service: T): void;
|
|
74
|
+
/** Resolve a service registered by another module. */
|
|
75
|
+
declare function use<T = unknown>(token: string): T;
|
|
76
|
+
/** Get the shared event bus instance. */
|
|
77
|
+
declare function getEvents<TMap extends Record<string, any> = Record<string, any>>(): ServerEventBus<TMap>;
|
|
78
|
+
/** Get the shared entity component store. */
|
|
79
|
+
declare function getEntities(): EntityStore;
|
|
80
|
+
/** Find a player by citizenId from the database cache. */
|
|
81
|
+
declare function getPlayer(citizenId: string): PlayerRow | null;
|
|
82
|
+
/** Get all cached players. */
|
|
83
|
+
declare function getPlayers(): PlayerRow[];
|
|
84
|
+
/** Register a callback for when a player connects (database confirmed). */
|
|
85
|
+
declare function onPlayerConnect(cb: (player: PlayerEventContext) => void): void;
|
|
86
|
+
/** Register a callback for when a player disconnects. */
|
|
87
|
+
declare function onPlayerDisconnect(cb: (player: PlayerEventContext) => void): void;
|
|
88
|
+
/**
|
|
89
|
+
* Get the database bridge for direct table and reducer access.
|
|
90
|
+
* Advanced — most modules should use the event bus and DI instead.
|
|
91
|
+
*/
|
|
92
|
+
declare function getBridge(): any;
|
|
93
|
+
/** Subscribe to database tables. Call inside onReady(). */
|
|
94
|
+
declare function subscribe(queries: string[]): Promise<void>;
|
|
95
|
+
|
|
96
|
+
export { type EntityStore, type PlayerEventContext, type PlayerRow, type ServerEventBus, getBridge, getEntities, getEvents, getPlayer, getPlayers, isReady, onPlayerConnect, onPlayerDisconnect, onReady, provide, subscribe, use };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
getBridge: () => getBridge,
|
|
24
|
+
getEntities: () => getEntities,
|
|
25
|
+
getEvents: () => getEvents,
|
|
26
|
+
getPlayer: () => getPlayer,
|
|
27
|
+
getPlayers: () => getPlayers,
|
|
28
|
+
isReady: () => isReady,
|
|
29
|
+
onPlayerConnect: () => onPlayerConnect,
|
|
30
|
+
onPlayerDisconnect: () => onPlayerDisconnect,
|
|
31
|
+
onReady: () => onReady,
|
|
32
|
+
provide: () => provide,
|
|
33
|
+
subscribe: () => subscribe,
|
|
34
|
+
use: () => use
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
function warp() {
|
|
38
|
+
return globalThis.exports["warp"];
|
|
39
|
+
}
|
|
40
|
+
function onReady(cb) {
|
|
41
|
+
warp().onReady(cb);
|
|
42
|
+
}
|
|
43
|
+
function isReady() {
|
|
44
|
+
return warp().isReady();
|
|
45
|
+
}
|
|
46
|
+
function provide(token, service) {
|
|
47
|
+
warp().provide(token, service);
|
|
48
|
+
}
|
|
49
|
+
function use(token) {
|
|
50
|
+
return warp().use(token);
|
|
51
|
+
}
|
|
52
|
+
function getEvents() {
|
|
53
|
+
return warp().getEvents();
|
|
54
|
+
}
|
|
55
|
+
function getEntities() {
|
|
56
|
+
return warp().getEntities();
|
|
57
|
+
}
|
|
58
|
+
function getPlayer(citizenId) {
|
|
59
|
+
return warp().getPlayer(citizenId);
|
|
60
|
+
}
|
|
61
|
+
function getPlayers() {
|
|
62
|
+
return warp().getPlayers();
|
|
63
|
+
}
|
|
64
|
+
function onPlayerConnect(cb) {
|
|
65
|
+
warp().onPlayerConnect(cb);
|
|
66
|
+
}
|
|
67
|
+
function onPlayerDisconnect(cb) {
|
|
68
|
+
warp().onPlayerDisconnect(cb);
|
|
69
|
+
}
|
|
70
|
+
function getBridge() {
|
|
71
|
+
return warp().getBridge();
|
|
72
|
+
}
|
|
73
|
+
function subscribe(queries) {
|
|
74
|
+
return warp().subscribe(queries);
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
getBridge,
|
|
79
|
+
getEntities,
|
|
80
|
+
getEvents,
|
|
81
|
+
getPlayer,
|
|
82
|
+
getPlayers,
|
|
83
|
+
isReady,
|
|
84
|
+
onPlayerConnect,
|
|
85
|
+
onPlayerDisconnect,
|
|
86
|
+
onReady,
|
|
87
|
+
provide,
|
|
88
|
+
subscribe,
|
|
89
|
+
use
|
|
90
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@warpfx/server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Warp Framework SDK for server-side FiveM module development",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/1camou/warp.git",
|
|
9
|
+
"directory": "packages/server"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["fivem", "warp", "server", "framework"],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup src/index.ts --format cjs --dts --out-dir dist --target node22"
|
|
22
|
+
}
|
|
23
|
+
}
|