@rustra/react 0.1.3 → 0.2.1

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@rustra/react",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "React and React Native bindings and hooks for rustra-bridge",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "sideEffects": false,
9
10
  "exports": {
10
11
  ".": {
11
12
  "types": "./dist/index.d.ts",
@@ -16,18 +17,38 @@
16
17
  "access": "public"
17
18
  },
18
19
  "files": [
19
- "dist"
20
+ "dist/context.d.ts",
21
+ "dist/context.d.ts.map",
22
+ "dist/context.js",
23
+ "dist/context.js.map",
24
+ "dist/index.d.ts",
25
+ "dist/index.d.ts.map",
26
+ "dist/index.js",
27
+ "dist/index.js.map",
28
+ "dist/useCommand.d.ts",
29
+ "dist/useCommand.d.ts.map",
30
+ "dist/useCommand.js",
31
+ "dist/useCommand.js.map",
32
+ "dist/useEvent.d.ts",
33
+ "dist/useEvent.d.ts.map",
34
+ "dist/useEvent.js",
35
+ "dist/useEvent.js.map",
36
+ "dist/useMutation.d.ts",
37
+ "dist/useMutation.d.ts.map",
38
+ "dist/useMutation.js",
39
+ "dist/useMutation.js.map"
20
40
  ],
21
41
  "scripts": {
22
42
  "build": "tsc",
23
43
  "clean": "rm -rf dist",
24
- "test": "npm run build && node --test dist/index.test.js"
44
+ "test": "tsc -p tsconfig.test.json && node --test dist-test/index.test.js",
45
+ "test:compile": "tsc -p tsconfig.test.json"
25
46
  },
26
47
  "peerDependencies": {
27
48
  "react": ">=18.0.0"
28
49
  },
29
50
  "dependencies": {
30
- "@rustra/types": "^0.1.3"
51
+ "@rustra/types": "^0.3.0"
31
52
  },
32
53
  "devDependencies": {
33
54
  "@types/react": "^19.0.0",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -1,92 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
- import { createElement } from 'react';
4
- import { renderToString } from 'react-dom/server';
5
- import { RustraProvider, useRustraEngine, useCommand, useMutation, useEvent } from './index.js';
6
- function createTestEngine(dataMap) {
7
- return {
8
- async invoke(command, _args) {
9
- if (command in dataMap) {
10
- return dataMap[command];
11
- }
12
- throw new Error(`Command not found: ${command}`);
13
- },
14
- };
15
- }
16
- test('RustraProvider supplies engine to useRustraEngine', () => {
17
- const engine = createTestEngine({ testCmd: 'hello' });
18
- let capturedEngine = null;
19
- function TestComponent() {
20
- capturedEngine = useRustraEngine();
21
- return createElement('div', null, 'test');
22
- }
23
- renderToString(createElement(RustraProvider, { engine, children: createElement(TestComponent) }));
24
- assert.equal(capturedEngine, engine);
25
- });
26
- test('useCommand hook contract and properties', () => {
27
- async function dummyCmd(input) {
28
- return { res: input.val * 2 };
29
- }
30
- const hookResult = { current: null };
31
- function TestComponent() {
32
- const result = useCommand(dummyCmd, { val: 5 }, { enabled: false });
33
- hookResult.current = result;
34
- return createElement('div', null, String(result.loading));
35
- }
36
- const engine = createTestEngine({ dummyCmd: { res: 10 } });
37
- renderToString(createElement(RustraProvider, { engine, children: createElement(TestComponent) }));
38
- const result = hookResult.current;
39
- assert.ok(result);
40
- assert.equal(result.loading, false);
41
- assert.equal(typeof result.refetch, 'function');
42
- });
43
- test('useMutation hook contract and execution', async () => {
44
- async function updateItem(_input) {
45
- return { updated: true };
46
- }
47
- const engine = createTestEngine({ updateItem: { updated: true } });
48
- const mutationResult = { current: null };
49
- function TestComponent() {
50
- mutationResult.current = useMutation(updateItem);
51
- return createElement('div', null, 'mutation');
52
- }
53
- renderToString(createElement(RustraProvider, { engine, children: createElement(TestComponent) }));
54
- const result = mutationResult.current;
55
- assert.ok(result);
56
- assert.equal(typeof result.mutate, 'function');
57
- assert.equal(typeof result.mutateAsync, 'function');
58
- assert.equal(typeof result.reset, 'function');
59
- // Execute mutation
60
- const res = await result.mutateAsync({ id: 'item-1' });
61
- assert.deepEqual(res, { updated: true });
62
- });
63
- test('useEvent handles subscription and contract', () => {
64
- let subscribedName = '';
65
- let unsubscribed = false;
66
- let handlerCalledWith = null;
67
- const mockSubscriber = (name, cb) => {
68
- subscribedName = name;
69
- cb({ count: 1 });
70
- return () => {
71
- unsubscribed = true;
72
- };
73
- };
74
- function TestComponent() {
75
- useEvent('tick', (payload) => {
76
- handlerCalledWith = payload;
77
- }, mockSubscriber);
78
- return createElement('div', null, 'events');
79
- }
80
- const el = createElement(TestComponent);
81
- assert.ok(el);
82
- assert.equal(typeof useEvent, 'function');
83
- // Verify subscriber invocation contract
84
- const unsub = mockSubscriber('tick', (payload) => {
85
- handlerCalledWith = payload;
86
- });
87
- assert.equal(subscribedName, 'tick');
88
- assert.deepEqual(handlerCalledWith, { count: 1 });
89
- unsub();
90
- assert.equal(unsubscribed, true);
91
- });
92
- //# sourceMappingURL=index.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKhG,SAAS,gBAAgB,CAAC,OAAgC;IACxD,OAAO;QACL,KAAK,CAAC,MAAM,CAAI,OAAe,EAAE,KAAe;YAC9C,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;gBACvB,OAAO,OAAO,CAAC,OA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