@warpfx/client 0.1.0 → 0.1.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 +61 -1
- package/dist/index.js +32 -2
- package/package.json +10 -5
package/dist/index.d.ts
CHANGED
|
@@ -37,5 +37,65 @@ declare function onReady(cb: () => void): void;
|
|
|
37
37
|
declare function isReady(): boolean;
|
|
38
38
|
/** Get the shared client event bus instance. */
|
|
39
39
|
declare function getEvents<TMap extends Record<string, any> = Record<string, any>>(): ClientEventBus<TMap>;
|
|
40
|
+
/** Reactive handle to synced state. */
|
|
41
|
+
interface SyncHandle<T = any> {
|
|
42
|
+
/** Current value of the synced state. */
|
|
43
|
+
readonly value: T;
|
|
44
|
+
/** Register a callback for when state changes. Returns unsubscribe function. */
|
|
45
|
+
onChange(handler: (newState: T, oldState: T) => void): () => void;
|
|
46
|
+
}
|
|
47
|
+
/** Action error received from the server. */
|
|
48
|
+
interface ActionError {
|
|
49
|
+
action: string;
|
|
50
|
+
code: string;
|
|
51
|
+
message: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Subscribe to synced state from the server.
|
|
55
|
+
*
|
|
56
|
+
* Returns a handle with a `.value` getter and `.onChange()` method.
|
|
57
|
+
* State updates automatically when the server pushes changes.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const inventory = useSync<InventoryItem[]>('inventory', []);
|
|
61
|
+
* console.log(inventory.value); // current items
|
|
62
|
+
* inventory.onChange((items) => console.log('Updated:', items.length));
|
|
63
|
+
*/
|
|
64
|
+
declare function useSync<T = any>(key: string, defaultValue?: T): SyncHandle<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Create an action dispatcher to call server-side action handlers.
|
|
67
|
+
*
|
|
68
|
+
* Returns a function that sends the action to the server.
|
|
69
|
+
* State updates flow back automatically via the sync engine.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const moveItem = useAction<{ itemId: string; toSlot: number }>('inventory:moveItem');
|
|
73
|
+
* moveItem({ itemId: 'abc', toSlot: 5 });
|
|
74
|
+
*/
|
|
75
|
+
declare function useAction<P = any>(name: string, opts?: {
|
|
76
|
+
onError?: (error: ActionError) => void;
|
|
77
|
+
}): (payload: P) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Register a global error handler for all action errors.
|
|
80
|
+
* Returns an unsubscribe function.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* useErrorHandler((error) => {
|
|
84
|
+
* console.log(`Action ${error.action} failed: ${error.message}`);
|
|
85
|
+
* });
|
|
86
|
+
*/
|
|
87
|
+
declare function useErrorHandler(handler: (error: ActionError) => void): () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Get the current synced state for a key.
|
|
90
|
+
* Unlike useSync(), this is a one-shot read with no change tracking.
|
|
91
|
+
*/
|
|
92
|
+
declare function getSyncState<T = any>(key: string): T | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Show the NUI overlay with mouse/keyboard focus.
|
|
95
|
+
* Optionally specify a panel name to show a specific module UI.
|
|
96
|
+
*/
|
|
97
|
+
declare function showNUI(panel?: string): void;
|
|
98
|
+
/** Hide the NUI overlay and release mouse/keyboard focus. */
|
|
99
|
+
declare function hideNUI(): void;
|
|
40
100
|
|
|
41
|
-
export { type ClientEventBus, getEvents, isReady, onReady };
|
|
101
|
+
export { type ActionError, type ClientEventBus, type SyncHandle, getEvents, getSyncState, hideNUI, isReady, onReady, showNUI, useAction, useErrorHandler, useSync };
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
getEvents: () => getEvents,
|
|
24
|
+
getSyncState: () => getSyncState,
|
|
25
|
+
hideNUI: () => hideNUI,
|
|
24
26
|
isReady: () => isReady,
|
|
25
|
-
onReady: () => onReady
|
|
27
|
+
onReady: () => onReady,
|
|
28
|
+
showNUI: () => showNUI,
|
|
29
|
+
useAction: () => useAction,
|
|
30
|
+
useErrorHandler: () => useErrorHandler,
|
|
31
|
+
useSync: () => useSync
|
|
26
32
|
});
|
|
27
33
|
module.exports = __toCommonJS(index_exports);
|
|
28
34
|
function warp() {
|
|
@@ -37,9 +43,33 @@ function isReady() {
|
|
|
37
43
|
function getEvents() {
|
|
38
44
|
return warp().getEvents();
|
|
39
45
|
}
|
|
46
|
+
function useSync(key, defaultValue) {
|
|
47
|
+
return warp().useSync(key, defaultValue);
|
|
48
|
+
}
|
|
49
|
+
function useAction(name, opts) {
|
|
50
|
+
return warp().useAction(name, opts);
|
|
51
|
+
}
|
|
52
|
+
function useErrorHandler(handler) {
|
|
53
|
+
return warp().useErrorHandler(handler);
|
|
54
|
+
}
|
|
55
|
+
function getSyncState(key) {
|
|
56
|
+
return warp().getSyncState(key);
|
|
57
|
+
}
|
|
58
|
+
function showNUI(panel) {
|
|
59
|
+
warp().showNUI(panel);
|
|
60
|
+
}
|
|
61
|
+
function hideNUI() {
|
|
62
|
+
warp().hideNUI();
|
|
63
|
+
}
|
|
40
64
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
65
|
0 && (module.exports = {
|
|
42
66
|
getEvents,
|
|
67
|
+
getSyncState,
|
|
68
|
+
hideNUI,
|
|
43
69
|
isReady,
|
|
44
|
-
onReady
|
|
70
|
+
onReady,
|
|
71
|
+
showNUI,
|
|
72
|
+
useAction,
|
|
73
|
+
useErrorHandler,
|
|
74
|
+
useSync
|
|
45
75
|
});
|
package/package.json
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warpfx/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Warp Framework SDK for client-side FiveM module development",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"client",
|
|
7
|
+
"fivem",
|
|
8
|
+
"framework",
|
|
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/client"
|
|
10
16
|
},
|
|
11
|
-
"keywords": ["fivem", "warp", "client", "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 es2017"
|
|
22
27
|
}
|