@fliwright/plugin-riverpod 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/RiverpodStateAdapter.d.ts +17 -0
- package/dist/RiverpodStateAdapter.js +63 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +16 -0
- package/package.json +38 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fliwright contributors.
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fliwright/plugin-riverpod
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Optional TypeScript state adapter for Flutter applications instrumented with
|
|
4
|
+
`fliwright_bridge_riverpod`.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { riverpodPlugin } from '@fliwright/plugin-riverpod';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The Flutter application must attach `FliwrightRiverpodObserver` in its trusted
|
|
11
|
+
debug or test entrypoint. Provider writes require explicit app-owned writable
|
|
12
|
+
registrations.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StateAdapter } from '@fliwright/core';
|
|
2
|
+
import type { ProviderInfo } from '@fliwright/core';
|
|
3
|
+
type SendRequest = (method: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
4
|
+
export declare class RiverpodStateAdapter implements StateAdapter {
|
|
5
|
+
private sendRequest;
|
|
6
|
+
private eventListeners;
|
|
7
|
+
constructor(sendRequest: SendRequest);
|
|
8
|
+
read(key: string): Promise<unknown>;
|
|
9
|
+
write(key: string, value: unknown): Promise<void>;
|
|
10
|
+
watch(key: string, callback: (oldValue: unknown, newValue: unknown) => void): Promise<() => void>;
|
|
11
|
+
listProviders(): Promise<ProviderInfo[]>;
|
|
12
|
+
status(): Promise<unknown>;
|
|
13
|
+
override(key: string, value: unknown): Promise<void>;
|
|
14
|
+
overrideWithResult(key: string, value: unknown): Promise<unknown>;
|
|
15
|
+
handleEvent(providerKey: string, oldValue: unknown, newValue: unknown): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class RiverpodStateAdapter {
|
|
2
|
+
sendRequest;
|
|
3
|
+
eventListeners = new Map();
|
|
4
|
+
constructor(sendRequest) {
|
|
5
|
+
this.sendRequest = sendRequest;
|
|
6
|
+
}
|
|
7
|
+
async read(key) {
|
|
8
|
+
const result = normalizeResult(await this.sendRequest('ext.fliwright.riverpod.read', { provider: key }));
|
|
9
|
+
if (result.found === false) {
|
|
10
|
+
throw new Error(`Riverpod provider not found: ${key}`);
|
|
11
|
+
}
|
|
12
|
+
if (typeof result.error === 'string' && result.error.length > 0) {
|
|
13
|
+
throw new Error(result.error);
|
|
14
|
+
}
|
|
15
|
+
return result.value;
|
|
16
|
+
}
|
|
17
|
+
async write(key, value) {
|
|
18
|
+
await this.overrideWithResult(key, value);
|
|
19
|
+
}
|
|
20
|
+
async watch(key, callback) {
|
|
21
|
+
const listeners = this.eventListeners.get(key) ?? new Set();
|
|
22
|
+
listeners.add(callback);
|
|
23
|
+
this.eventListeners.set(key, listeners);
|
|
24
|
+
normalizeResult(await this.sendRequest('ext.fliwright.riverpod.watch', { provider: key }));
|
|
25
|
+
return () => {
|
|
26
|
+
listeners.delete(callback);
|
|
27
|
+
if (listeners.size === 0) {
|
|
28
|
+
this.eventListeners.delete(key);
|
|
29
|
+
this.sendRequest('ext.fliwright.riverpod.unwatch', { provider: key }).catch(() => { });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async listProviders() {
|
|
34
|
+
const result = normalizeResult(await this.sendRequest('ext.fliwright.riverpod.list'));
|
|
35
|
+
return result.providers ?? [];
|
|
36
|
+
}
|
|
37
|
+
async status() {
|
|
38
|
+
return normalizeResult(await this.sendRequest('ext.fliwright.riverpod.status'));
|
|
39
|
+
}
|
|
40
|
+
async override(key, value) {
|
|
41
|
+
await this.overrideWithResult(key, value);
|
|
42
|
+
}
|
|
43
|
+
async overrideWithResult(key, value) {
|
|
44
|
+
return normalizeResult(await this.sendRequest('ext.fliwright.riverpod.override', { provider: key, value: JSON.stringify(value) }));
|
|
45
|
+
}
|
|
46
|
+
handleEvent(providerKey, oldValue, newValue) {
|
|
47
|
+
const listeners = this.eventListeners.get(providerKey);
|
|
48
|
+
if (listeners) {
|
|
49
|
+
for (const cb of listeners) {
|
|
50
|
+
cb(oldValue, newValue);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function normalizeResult(result) {
|
|
56
|
+
if (typeof result === 'object' && result !== null && 'error' in result) {
|
|
57
|
+
const error = result.error;
|
|
58
|
+
if (typeof error === 'string' && error.length > 0) {
|
|
59
|
+
throw new Error(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RiverpodStateAdapter } from './RiverpodStateAdapter.js';
|
|
2
|
+
export function riverpodPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'riverpod',
|
|
5
|
+
async onInit(context) {
|
|
6
|
+
const adapter = new RiverpodStateAdapter((method, params) => context.sendRequest(method, params));
|
|
7
|
+
context.registerStateAdapter('riverpod', adapter);
|
|
8
|
+
// Wire up event pipeline: VM Service events -> adapter.handleEvent
|
|
9
|
+
context.onEvent((event) => {
|
|
10
|
+
if (event.kind === 'riverpod.stateChanged' && event.data) {
|
|
11
|
+
adapter.handleEvent(event.data.providerKey, event.data.oldValue, event.data.newValue);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fliwright/plugin-riverpod",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Optional Riverpod state adapter for Fliwright Flutter automation.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/0x01lab/fliwright.git",
|
|
9
|
+
"directory": "packages/fliwright-plugin-riverpod"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/0x01lab/fliwright/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/0x01lab/fliwright#readme",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@fliwright/core": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^5.5.0",
|
|
34
|
+
"vitest": "5.0.5"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"lint": "tsc --noEmit"
|
|
40
|
+
}
|
|
6
41
|
}
|