@warpfx/client 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 +41 -0
- package/dist/index.js +45 -0
- package/package.json +23 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @warp/client — Typed SDK for Warp client-side module development.
|
|
3
|
+
*
|
|
4
|
+
* Provides type-safe access to the Warp client API. Under the hood,
|
|
5
|
+
* all calls go through FiveM's resource exports to the 'warp' resource.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { onReady, getEvents } from '@warp/client';
|
|
9
|
+
*
|
|
10
|
+
* onReady(() => {
|
|
11
|
+
* const events = getEvents();
|
|
12
|
+
* events.onServer('economy:balance', (data) => { ... });
|
|
13
|
+
* events.emitServer('economy:request-balance', {});
|
|
14
|
+
* });
|
|
15
|
+
*/
|
|
16
|
+
/** Typed event bus for client-side and network communication. */
|
|
17
|
+
interface ClientEventBus<TMap extends Record<string, any> = Record<string, any>> {
|
|
18
|
+
/** Subscribe to a local event. Returns an unsubscribe function. */
|
|
19
|
+
on<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): () => void;
|
|
20
|
+
/** Unsubscribe from a local event. */
|
|
21
|
+
off<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
22
|
+
/** Emit a local event to all subscribers. */
|
|
23
|
+
emit<K extends string & keyof TMap>(event: K, data: TMap[K]): void;
|
|
24
|
+
/** Send an event to the server. */
|
|
25
|
+
emitServer<K extends string & keyof TMap>(event: K, data: TMap[K]): void;
|
|
26
|
+
/** Listen for events from the server. Returns an unsubscribe function. */
|
|
27
|
+
onServer<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): () => void;
|
|
28
|
+
/** Unsubscribe from a server event. */
|
|
29
|
+
offServer<K extends string & keyof TMap>(event: K, handler: (data: TMap[K]) => void): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Register a callback to run when Warp client is ready.
|
|
33
|
+
* If already ready, the callback fires immediately.
|
|
34
|
+
*/
|
|
35
|
+
declare function onReady(cb: () => void): void;
|
|
36
|
+
/** Check if Warp client has finished initializing. */
|
|
37
|
+
declare function isReady(): boolean;
|
|
38
|
+
/** Get the shared client event bus instance. */
|
|
39
|
+
declare function getEvents<TMap extends Record<string, any> = Record<string, any>>(): ClientEventBus<TMap>;
|
|
40
|
+
|
|
41
|
+
export { type ClientEventBus, getEvents, isReady, onReady };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
getEvents: () => getEvents,
|
|
24
|
+
isReady: () => isReady,
|
|
25
|
+
onReady: () => onReady
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
function warp() {
|
|
29
|
+
return globalThis.exports["warp"];
|
|
30
|
+
}
|
|
31
|
+
function onReady(cb) {
|
|
32
|
+
warp().onReady(cb);
|
|
33
|
+
}
|
|
34
|
+
function isReady() {
|
|
35
|
+
return warp().isReady();
|
|
36
|
+
}
|
|
37
|
+
function getEvents() {
|
|
38
|
+
return warp().getEvents();
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
getEvents,
|
|
43
|
+
isReady,
|
|
44
|
+
onReady
|
|
45
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@warpfx/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Warp Framework SDK for client-side FiveM module development",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/1camou/warp.git",
|
|
9
|
+
"directory": "packages/client"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["fivem", "warp", "client", "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 es2017"
|
|
22
|
+
}
|
|
23
|
+
}
|