@standardbeagle/data-router 1.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/README.md +134 -0
- package/dist/FormHandler.d.ts +19 -0
- package/dist/hooks/useAsyncBatch.d.ts +46 -0
- package/dist/hooks/useAsyncData.d.ts +23 -0
- package/dist/hooks/useAsyncMutation.d.ts +22 -0
- package/dist/hooks/useAsyncState.d.ts +44 -0
- package/dist/hooks/useData.d.ts +3 -0
- package/dist/hooks/useDataManipulation.d.ts +2 -0
- package/dist/hooks/useInvalidation.d.ts +28 -0
- package/dist/hooks/useNavigate.d.ts +4 -0
- package/dist/hooks/useOptimisticUpdates.d.ts +27 -0
- package/dist/hooks/useXPath.d.ts +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.es.d.ts +1 -0
- package/dist/index.es.js +2904 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.cjs +11 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/provider.d.ts +12 -0
- package/dist/state/actions.d.ts +23 -0
- package/dist/state/command-queue.d.ts +18 -0
- package/dist/state/reducer.d.ts +3 -0
- package/dist/state/xpath-utils.d.ts +10 -0
- package/dist/types.d.ts +135 -0
- package/package.json +67 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export interface AsyncState {
|
|
2
|
+
readonly status: 'idle' | 'loading' | 'success' | 'error';
|
|
3
|
+
readonly error?: Error;
|
|
4
|
+
readonly timestamp?: number;
|
|
5
|
+
readonly requestId?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AsyncCommand {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly xpath: string;
|
|
10
|
+
readonly operation: 'fetch' | 'mutate';
|
|
11
|
+
readonly abortController: AbortController;
|
|
12
|
+
readonly promise: Promise<any>;
|
|
13
|
+
readonly timestamp: number;
|
|
14
|
+
readonly priority: 'low' | 'normal' | 'high';
|
|
15
|
+
}
|
|
16
|
+
export interface CommandQueue {
|
|
17
|
+
readonly pending: readonly AsyncCommand[];
|
|
18
|
+
readonly executing: ReadonlyMap<string, AsyncCommand>;
|
|
19
|
+
readonly maxConcurrent: number;
|
|
20
|
+
}
|
|
21
|
+
export interface OptimisticUpdate {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly xpath: string;
|
|
24
|
+
readonly originalData: any;
|
|
25
|
+
readonly optimisticData: any;
|
|
26
|
+
readonly rollbackOnError: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface DataContext {
|
|
29
|
+
readonly data: Record<string, any>;
|
|
30
|
+
readonly xpath: string;
|
|
31
|
+
readonly history: readonly string[];
|
|
32
|
+
readonly location: number;
|
|
33
|
+
readonly asyncStates: Record<string, AsyncState>;
|
|
34
|
+
readonly pendingOperations: ReadonlySet<string>;
|
|
35
|
+
readonly commandQueue: CommandQueue;
|
|
36
|
+
readonly optimisticUpdates: Record<string, OptimisticUpdate>;
|
|
37
|
+
}
|
|
38
|
+
export interface XPathParams {
|
|
39
|
+
[key: string]: string | number | undefined;
|
|
40
|
+
}
|
|
41
|
+
export interface DataRouteContext {
|
|
42
|
+
readonly xpath: string;
|
|
43
|
+
readonly data: Record<string, any>;
|
|
44
|
+
readonly targetData: any;
|
|
45
|
+
readonly params: XPathParams;
|
|
46
|
+
}
|
|
47
|
+
export type DataOperationType = 'merge' | 'replace' | 'append' | 'delete';
|
|
48
|
+
export type NavigateAction = {
|
|
49
|
+
readonly type: 'NAVIGATE';
|
|
50
|
+
readonly payload: string;
|
|
51
|
+
};
|
|
52
|
+
export type BackAction = {
|
|
53
|
+
readonly type: 'BACK';
|
|
54
|
+
readonly payload: number;
|
|
55
|
+
};
|
|
56
|
+
export type ForwardAction = {
|
|
57
|
+
readonly type: 'FORWARD';
|
|
58
|
+
readonly payload: number;
|
|
59
|
+
};
|
|
60
|
+
export type DataAction = {
|
|
61
|
+
readonly type: 'DATA_OPERATION';
|
|
62
|
+
readonly payload: {
|
|
63
|
+
xpath: string;
|
|
64
|
+
operation: DataOperationType;
|
|
65
|
+
data: any;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type AsyncStartAction = {
|
|
69
|
+
readonly type: 'ASYNC_START';
|
|
70
|
+
readonly payload: {
|
|
71
|
+
xpath: string;
|
|
72
|
+
requestId: string;
|
|
73
|
+
operation: 'fetch' | 'mutate';
|
|
74
|
+
priority?: 'low' | 'normal' | 'high';
|
|
75
|
+
optimisticData?: any;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export type AsyncSuccessAction = {
|
|
79
|
+
readonly type: 'ASYNC_SUCCESS';
|
|
80
|
+
readonly payload: {
|
|
81
|
+
xpath: string;
|
|
82
|
+
requestId: string;
|
|
83
|
+
data: any;
|
|
84
|
+
timestamp: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export type AsyncErrorAction = {
|
|
88
|
+
readonly type: 'ASYNC_ERROR';
|
|
89
|
+
readonly payload: {
|
|
90
|
+
xpath: string;
|
|
91
|
+
requestId: string;
|
|
92
|
+
error: Error;
|
|
93
|
+
shouldRollback: boolean;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export type AsyncCancelAction = {
|
|
97
|
+
readonly type: 'ASYNC_CANCEL';
|
|
98
|
+
readonly payload: {
|
|
99
|
+
xpath: string;
|
|
100
|
+
requestId: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export type CommandQueueAction = {
|
|
104
|
+
readonly type: 'COMMAND_QUEUE_UPDATE';
|
|
105
|
+
readonly payload: {
|
|
106
|
+
operation: 'add' | 'remove' | 'execute';
|
|
107
|
+
command?: AsyncCommand;
|
|
108
|
+
commandId?: string;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export type DataRouterAction = NavigateAction | BackAction | ForwardAction | DataAction | AsyncStartAction | AsyncSuccessAction | AsyncErrorAction | AsyncCancelAction | CommandQueueAction;
|
|
112
|
+
export interface Action<T> {
|
|
113
|
+
readonly type: string;
|
|
114
|
+
readonly payload: T;
|
|
115
|
+
}
|
|
116
|
+
export interface NavigationObject {
|
|
117
|
+
readonly navigate: (xpath: string) => void;
|
|
118
|
+
readonly back: (count?: number) => void;
|
|
119
|
+
readonly forward: (count?: number) => void;
|
|
120
|
+
readonly hasBack: boolean;
|
|
121
|
+
readonly hasForward: boolean;
|
|
122
|
+
readonly xpath: string;
|
|
123
|
+
readonly history: readonly string[];
|
|
124
|
+
readonly location: number;
|
|
125
|
+
}
|
|
126
|
+
export interface FormData {
|
|
127
|
+
[key: string]: FormDataEntryValue | FormDataEntryValue[];
|
|
128
|
+
}
|
|
129
|
+
export interface DataManipulationHook {
|
|
130
|
+
readonly setData: (xpath: string, data: any, operation?: DataOperationType) => void;
|
|
131
|
+
readonly mergeData: (xpath: string, data: any) => void;
|
|
132
|
+
readonly replaceData: (xpath: string, data: any) => void;
|
|
133
|
+
readonly appendData: (xpath: string, data: any) => void;
|
|
134
|
+
readonly deleteData: (xpath: string) => void;
|
|
135
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@standardbeagle/data-router",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"/dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "dist/index.umd.cjs",
|
|
10
|
+
"module": "dist/index.es.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.es.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.umd.cjs"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/standardbeagle/beagle-core",
|
|
26
|
+
"directory": "data-router"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"dev": "vite",
|
|
30
|
+
"build": "tsc && vite build",
|
|
31
|
+
"ts": "tsc",
|
|
32
|
+
"test": "vitest",
|
|
33
|
+
"prepublish": "npm run build",
|
|
34
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
35
|
+
"preview": "vite preview"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"redux-actions": "^3.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
42
|
+
"@testing-library/react": "^14.2.0",
|
|
43
|
+
"@testing-library/user-event": "^14.5.2",
|
|
44
|
+
"@types/jsdom": "^21.1.6",
|
|
45
|
+
"@types/react": "^18.2.43",
|
|
46
|
+
"@types/react-dom": "^18.2.17",
|
|
47
|
+
"@types/redux-actions": "^2.6.5",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
49
|
+
"@typescript-eslint/parser": "^6.14.0",
|
|
50
|
+
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
51
|
+
"eslint": "^8.55.0",
|
|
52
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
53
|
+
"eslint-plugin-react-refresh": "^0.4.5",
|
|
54
|
+
"jsdom": "^24.0.0",
|
|
55
|
+
"react": "^18.2.0",
|
|
56
|
+
"react-dom": "^18.2.0",
|
|
57
|
+
"terser": "^5.43.1",
|
|
58
|
+
"typescript": "^5.2.2",
|
|
59
|
+
"vite": "^5.0.8",
|
|
60
|
+
"vite-plugin-dts": "^3.7.2",
|
|
61
|
+
"vitest": "^1.2.2"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"react": "^18.2.0",
|
|
65
|
+
"react-dom": "^18.2.0"
|
|
66
|
+
}
|
|
67
|
+
}
|