@vibecook/truffle-react 0.1.0 → 0.2.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/LICENSE +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/use-mesh.d.ts +4 -7
- package/dist/use-mesh.d.ts.map +1 -1
- package/dist/use-mesh.js +64 -35
- package/dist/use-mesh.js.map +1 -1
- package/dist/use-synced-store.d.ts +11 -7
- package/dist/use-synced-store.d.ts.map +1 -1
- package/dist/use-synced-store.js +31 -14
- package/dist/use-synced-store.js.map +1 -1
- package/package.json +28 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 James Yong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useMesh } from './use-mesh.js';
|
|
2
|
-
export { useSyncedStore } from './use-synced-store.js';
|
|
1
|
+
export { useMesh, type UseMeshResult } from './use-mesh.js';
|
|
2
|
+
export { useSyncedStore, type UseSyncedStoreResult } from './use-synced-store.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,cAAc,EAA6B,MAAM,uBAAuB,CAAC"}
|
package/dist/use-mesh.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import type { BaseDevice,
|
|
2
|
-
import type { MeshNode } from '@vibecook/truffle-mesh';
|
|
1
|
+
import type { NapiBaseDevice as BaseDevice, NapiMeshNode as MeshNode } from '@vibecook/truffle';
|
|
3
2
|
export interface UseMeshResult {
|
|
4
3
|
devices: BaseDevice[];
|
|
5
4
|
localDevice: BaseDevice | null;
|
|
6
|
-
isPrimary: boolean;
|
|
7
5
|
isConnected: boolean;
|
|
8
|
-
role: DeviceRole;
|
|
9
6
|
broadcast: (namespace: string, type: string, payload: unknown) => void;
|
|
10
|
-
sendTo: (deviceId: string, namespace: string, type: string, payload: unknown) =>
|
|
7
|
+
sendTo: (deviceId: string, namespace: string, type: string, payload: unknown) => void;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
|
-
* React hook for Truffle mesh networking.
|
|
10
|
+
* React hook for Truffle mesh networking (P2P).
|
|
14
11
|
*
|
|
15
|
-
* Subscribes to
|
|
12
|
+
* Subscribes to mesh events via the NAPI callback API and provides messaging helpers.
|
|
16
13
|
* The MeshNode must already be started before using this hook.
|
|
17
14
|
*/
|
|
18
15
|
export declare function useMesh(node: MeshNode | null): UseMeshResult;
|
package/dist/use-mesh.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mesh.d.ts","sourceRoot":"","sources":["../src/use-mesh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-mesh.d.ts","sourceRoot":"","sources":["../src/use-mesh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,IAAI,UAAU,EAC5B,YAAY,IAAI,QAAQ,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACvF;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,aAAa,CAoF5D"}
|
package/dist/use-mesh.js
CHANGED
|
@@ -1,57 +1,86 @@
|
|
|
1
1
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* React hook for Truffle mesh networking.
|
|
3
|
+
* React hook for Truffle mesh networking (P2P).
|
|
4
4
|
*
|
|
5
|
-
* Subscribes to
|
|
5
|
+
* Subscribes to mesh events via the NAPI callback API and provides messaging helpers.
|
|
6
6
|
* The MeshNode must already be started before using this hook.
|
|
7
7
|
*/
|
|
8
8
|
export function useMesh(node) {
|
|
9
9
|
const [devices, setDevices] = useState([]);
|
|
10
10
|
const [localDevice, setLocalDevice] = useState(null);
|
|
11
|
-
const [isPrimary, setIsPrimary] = useState(false);
|
|
12
11
|
const [isConnected, setIsConnected] = useState(false);
|
|
13
|
-
const
|
|
14
|
-
const busRef = useRef(null);
|
|
12
|
+
const nodeRef = useRef(null);
|
|
15
13
|
useEffect(() => {
|
|
16
14
|
if (!node)
|
|
17
15
|
return;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
nodeRef.current = node;
|
|
17
|
+
let cancelled = false;
|
|
18
|
+
// Fetch initial state
|
|
19
|
+
const init = async () => {
|
|
20
|
+
try {
|
|
21
|
+
const [running, local, devs] = await Promise.all([
|
|
22
|
+
node.isRunning(),
|
|
23
|
+
node.localDevice(),
|
|
24
|
+
node.devices(),
|
|
25
|
+
]);
|
|
26
|
+
if (cancelled)
|
|
27
|
+
return;
|
|
28
|
+
setIsConnected(running);
|
|
29
|
+
setLocalDevice(local);
|
|
30
|
+
setDevices(devs);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Node may not be started yet
|
|
34
|
+
}
|
|
28
35
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
init();
|
|
37
|
+
// Subscribe to mesh events via NAPI callback
|
|
38
|
+
node.onEvent((err, event) => {
|
|
39
|
+
if (err || cancelled)
|
|
40
|
+
return;
|
|
41
|
+
switch (event.eventType) {
|
|
42
|
+
case 'started':
|
|
43
|
+
setIsConnected(true);
|
|
44
|
+
node.localDevice().then((d) => {
|
|
45
|
+
if (!cancelled)
|
|
46
|
+
setLocalDevice(d);
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
case 'stopped':
|
|
50
|
+
setIsConnected(false);
|
|
51
|
+
setDevices([]);
|
|
52
|
+
break;
|
|
53
|
+
case 'peersChanged':
|
|
54
|
+
if (Array.isArray(event.payload)) {
|
|
55
|
+
setDevices(event.payload);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
node.devices().then((d) => {
|
|
59
|
+
if (!cancelled)
|
|
60
|
+
setDevices(d);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 'peerDiscovered':
|
|
65
|
+
case 'peerOffline':
|
|
66
|
+
node.devices().then((d) => {
|
|
67
|
+
if (!cancelled)
|
|
68
|
+
setDevices(d);
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
41
73
|
return () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
node.off('started', onStarted);
|
|
45
|
-
node.off('stopped', onStopped);
|
|
46
|
-
busRef.current = null;
|
|
74
|
+
cancelled = true;
|
|
75
|
+
nodeRef.current = null;
|
|
47
76
|
};
|
|
48
77
|
}, [node]);
|
|
49
78
|
const broadcast = useCallback((namespace, type, payload) => {
|
|
50
|
-
|
|
79
|
+
nodeRef.current?.broadcastEnvelope(namespace, type, payload);
|
|
51
80
|
}, []);
|
|
52
81
|
const sendTo = useCallback((deviceId, namespace, type, payload) => {
|
|
53
|
-
|
|
82
|
+
nodeRef.current?.sendEnvelope(deviceId, namespace, type, payload);
|
|
54
83
|
}, []);
|
|
55
|
-
return { devices, localDevice,
|
|
84
|
+
return { devices, localDevice, isConnected, broadcast, sendTo };
|
|
56
85
|
}
|
|
57
86
|
//# sourceMappingURL=use-mesh.js.map
|
package/dist/use-mesh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mesh.js","sourceRoot":"","sources":["../src/use-mesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-mesh.js","sourceRoot":"","sources":["../src/use-mesh.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import type { DeviceSlice } from '@vibecook/truffle
|
|
2
|
-
import type { ISyncableStore } from '@vibecook/truffle-store-sync';
|
|
1
|
+
import type { NapiDeviceSlice as DeviceSlice, NapiStoreSyncAdapter } from '@vibecook/truffle';
|
|
3
2
|
export interface UseSyncedStoreResult<T> {
|
|
4
|
-
localSlice: DeviceSlice
|
|
3
|
+
localSlice: DeviceSlice | null;
|
|
5
4
|
localData: T | null;
|
|
6
5
|
version: number;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
|
-
* React hook for a synced store.
|
|
8
|
+
* React hook for a synced store backed by NapiStoreSyncAdapter.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Tracks local slice state and listens for outgoing sync messages.
|
|
11
|
+
* Call `handleLocalChanged` on the adapter when your local data changes,
|
|
12
|
+
* and this hook will reflect the updated slice.
|
|
13
|
+
*
|
|
14
|
+
* @param adapter - The NapiStoreSyncAdapter instance (or null if not ready)
|
|
15
|
+
* @param storeId - The store identifier to track
|
|
16
|
+
* @param initialSlice - Optional initial slice value
|
|
13
17
|
*/
|
|
14
|
-
export declare function useSyncedStore<T>(
|
|
18
|
+
export declare function useSyncedStore<T>(adapter: NapiStoreSyncAdapter | null, storeId: string, initialSlice?: DeviceSlice | null): UseSyncedStoreResult<T>;
|
|
15
19
|
//# sourceMappingURL=use-synced-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-synced-store.d.ts","sourceRoot":"","sources":["../src/use-synced-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"use-synced-store.d.ts","sourceRoot":"","sources":["../src/use-synced-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,IAAI,WAAW,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9F,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,oBAAoB,GAAG,IAAI,EACpC,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,WAAW,GAAG,IAAI,GAChC,oBAAoB,CAAC,CAAC,CAAC,CAmCzB"}
|
package/dist/use-synced-store.js
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* React hook for a synced store.
|
|
3
|
+
* React hook for a synced store backed by NapiStoreSyncAdapter.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Tracks local slice state and listens for outgoing sync messages.
|
|
6
|
+
* Call `handleLocalChanged` on the adapter when your local data changes,
|
|
7
|
+
* and this hook will reflect the updated slice.
|
|
8
|
+
*
|
|
9
|
+
* @param adapter - The NapiStoreSyncAdapter instance (or null if not ready)
|
|
10
|
+
* @param storeId - The store identifier to track
|
|
11
|
+
* @param initialSlice - Optional initial slice value
|
|
7
12
|
*/
|
|
8
|
-
export function useSyncedStore(
|
|
9
|
-
const [localSlice, setLocalSlice] = useState(
|
|
13
|
+
export function useSyncedStore(adapter, storeId, initialSlice) {
|
|
14
|
+
const [localSlice, setLocalSlice] = useState(initialSlice ?? null);
|
|
15
|
+
const adapterRef = useRef(null);
|
|
10
16
|
useEffect(() => {
|
|
11
|
-
if (!
|
|
17
|
+
if (!adapter)
|
|
12
18
|
return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
adapterRef.current = adapter;
|
|
20
|
+
let cancelled = false;
|
|
21
|
+
// Listen for outgoing sync messages to detect local changes
|
|
22
|
+
adapter.onOutgoing((err, message) => {
|
|
23
|
+
if (err || cancelled)
|
|
24
|
+
return;
|
|
25
|
+
// When the adapter emits an outgoing message, the local data has changed.
|
|
26
|
+
// The payload contains the sync data including the slice.
|
|
27
|
+
if (message.payload && typeof message.payload === 'object') {
|
|
28
|
+
const payload = message.payload;
|
|
29
|
+
if (payload.storeId === storeId && payload.slice) {
|
|
30
|
+
setLocalSlice(payload.slice);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
18
34
|
return () => {
|
|
19
|
-
|
|
35
|
+
cancelled = true;
|
|
36
|
+
adapterRef.current = null;
|
|
20
37
|
};
|
|
21
|
-
}, [
|
|
38
|
+
}, [adapter, storeId]);
|
|
22
39
|
return {
|
|
23
40
|
localSlice,
|
|
24
41
|
localData: localSlice?.data ?? null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-synced-store.js","sourceRoot":"","sources":["../src/use-synced-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-synced-store.js","sourceRoot":"","sources":["../src/use-synced-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AASpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAoC,EACpC,OAAe,EACf,YAAiC;IAEjC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAqB,YAAY,IAAI,IAAI,CAAC,CAAC;IACvF,MAAM,UAAU,GAAG,MAAM,CAA8B,IAAI,CAAC,CAAC;IAE7D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;QAC7B,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,4DAA4D;QAC5D,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;YAClC,IAAI,GAAG,IAAI,SAAS;gBAAE,OAAO;YAE7B,0EAA0E;YAC1E,0DAA0D;YAC1D,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC3D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAkC,CAAC;gBAC3D,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;oBACjD,aAAa,CAAC,OAAO,CAAC,KAAoB,CAAC,CAAC;gBAC9C,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAEvB,OAAO;QACL,UAAU;QACV,SAAS,EAAG,UAAU,EAAE,IAAU,IAAI,IAAI;QAC1C,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibecook/truffle-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "React hooks for Truffle mesh networking",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"author": "James Yong",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "https://github.com/jamesyong-42/truffle.git",
|
|
@@ -12,29 +13,46 @@
|
|
|
12
13
|
"bugs": {
|
|
13
14
|
"url": "https://github.com/jamesyong-42/truffle/issues"
|
|
14
15
|
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mesh",
|
|
18
|
+
"networking",
|
|
19
|
+
"tailscale",
|
|
20
|
+
"local-first",
|
|
21
|
+
"p2p",
|
|
22
|
+
"react",
|
|
23
|
+
"hooks"
|
|
24
|
+
],
|
|
15
25
|
"engines": {
|
|
16
26
|
"node": ">=18"
|
|
17
27
|
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false,
|
|
18
32
|
"type": "module",
|
|
19
33
|
"main": "dist/index.js",
|
|
20
34
|
"types": "dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
21
41
|
"files": [
|
|
22
42
|
"dist"
|
|
23
43
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsc",
|
|
26
|
-
"clean": "rm -rf dist",
|
|
27
|
-
"typecheck": "tsc --noEmit"
|
|
28
|
-
},
|
|
29
44
|
"dependencies": {
|
|
30
|
-
"@vibecook/truffle
|
|
31
|
-
"@vibecook/truffle-mesh": "workspace:*",
|
|
32
|
-
"@vibecook/truffle-store-sync": "workspace:*"
|
|
45
|
+
"@vibecook/truffle": "0.2.3"
|
|
33
46
|
},
|
|
34
47
|
"peerDependencies": {
|
|
35
48
|
"react": ">=18"
|
|
36
49
|
},
|
|
37
50
|
"devDependencies": {
|
|
38
51
|
"@types/react": "^19.0.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc",
|
|
55
|
+
"clean": "rm -rf dist",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
39
57
|
}
|
|
40
|
-
}
|
|
58
|
+
}
|