@aspectly/core 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 +20 -0
- package/README.md +188 -0
- package/dist/AspectlyBridge-hGuDjcI6.d.mts +242 -0
- package/dist/AspectlyBridge-hGuDjcI6.d.ts +242 -0
- package/dist/browser.d.mts +24 -0
- package/dist/browser.d.ts +24 -0
- package/dist/browser.js +398 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +396 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index.d.mts +54 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +420 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +412 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
- package/src/AspectlyBridge.test.ts +78 -0
- package/src/AspectlyBridge.ts +44 -0
- package/src/BridgeBase.test.ts +132 -0
- package/src/BridgeBase.ts +63 -0
- package/src/BridgeCore.test.ts +254 -0
- package/src/BridgeCore.ts +138 -0
- package/src/BridgeInternal.test.ts +403 -0
- package/src/BridgeInternal.ts +305 -0
- package/src/browser.ts +27 -0
- package/src/index.ts +28 -0
- package/src/types.ts +134 -0
package/src/browser.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser entry point for direct script inclusion.
|
|
3
|
+
* Creates a global `aspectlyBridge` instance on the window object.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```html
|
|
7
|
+
* <script src="https://unpkg.com/@aspectly/core/dist/browser.js"></script>
|
|
8
|
+
* <script>
|
|
9
|
+
* window.aspectlyBridge.init({
|
|
10
|
+
* greet: async (params) => ({ message: 'Hello!' })
|
|
11
|
+
* });
|
|
12
|
+
* </script>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import { AspectlyBridge } from './AspectlyBridge';
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
interface Window {
|
|
19
|
+
aspectlyBridge: AspectlyBridge;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
24
|
+
window.aspectlyBridge = new AspectlyBridge();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { AspectlyBridge };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Main exports
|
|
2
|
+
export { AspectlyBridge } from './AspectlyBridge';
|
|
3
|
+
export { BridgeBase } from './BridgeBase';
|
|
4
|
+
export { BridgeInternal } from './BridgeInternal';
|
|
5
|
+
export { BridgeCore } from './BridgeCore';
|
|
6
|
+
|
|
7
|
+
// Type exports
|
|
8
|
+
export type {
|
|
9
|
+
BridgeEvent,
|
|
10
|
+
BridgeData,
|
|
11
|
+
BridgeHandler,
|
|
12
|
+
BridgeHandlers,
|
|
13
|
+
BridgeListener,
|
|
14
|
+
BridgeOptions,
|
|
15
|
+
BridgeRequestEvent,
|
|
16
|
+
BridgeResultEvent,
|
|
17
|
+
BridgeResultError,
|
|
18
|
+
BridgeResultSuccess,
|
|
19
|
+
BridgeResultData,
|
|
20
|
+
BridgeInitEvent,
|
|
21
|
+
BridgeInitResultEvent,
|
|
22
|
+
} from './types';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
BridgeEventType,
|
|
26
|
+
BridgeResultType,
|
|
27
|
+
BridgeErrorType,
|
|
28
|
+
} from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event types used in bridge communication protocol
|
|
3
|
+
*/
|
|
4
|
+
export enum BridgeEventType {
|
|
5
|
+
/** Request to invoke a method on the other side */
|
|
6
|
+
Request = 'Request',
|
|
7
|
+
/** Response to a request */
|
|
8
|
+
Result = 'Result',
|
|
9
|
+
/** Initialization handshake */
|
|
10
|
+
Init = 'Init',
|
|
11
|
+
/** Response to initialization */
|
|
12
|
+
InitResult = 'InitResult',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Result types for bridge responses
|
|
17
|
+
*/
|
|
18
|
+
export enum BridgeResultType {
|
|
19
|
+
/** Successful response */
|
|
20
|
+
Success = 'Success',
|
|
21
|
+
/** Error response */
|
|
22
|
+
Error = 'Error',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Error types that can occur during bridge communication
|
|
27
|
+
*/
|
|
28
|
+
export enum BridgeErrorType {
|
|
29
|
+
/** Handler took longer than timeout (default: 100s) */
|
|
30
|
+
METHOD_EXECUTION_TIMEOUT = 'METHOD_EXECUTION_TIMEOUT',
|
|
31
|
+
/** Method is not registered on the receiving side */
|
|
32
|
+
UNSUPPORTED_METHOD = 'UNSUPPORTED_METHOD',
|
|
33
|
+
/** Handler threw an error */
|
|
34
|
+
REJECTED = 'REJECTED',
|
|
35
|
+
/** Bridge is not initialized or unavailable */
|
|
36
|
+
BRIDGE_NOT_AVAILABLE = 'BRIDGE_NOT_AVAILABLE',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Error data returned when a bridge call fails
|
|
41
|
+
*/
|
|
42
|
+
export interface BridgeResultError {
|
|
43
|
+
error_type: BridgeErrorType;
|
|
44
|
+
error_message?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Successful result data (any object)
|
|
49
|
+
*/
|
|
50
|
+
export type BridgeResultSuccess = object;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Union type for result data
|
|
54
|
+
*/
|
|
55
|
+
export type BridgeResultData =
|
|
56
|
+
| BridgeResultError
|
|
57
|
+
| undefined
|
|
58
|
+
| BridgeResultSuccess;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Result event sent back after processing a request
|
|
62
|
+
*/
|
|
63
|
+
export interface BridgeResultEvent {
|
|
64
|
+
type?: BridgeResultType;
|
|
65
|
+
method?: string;
|
|
66
|
+
request_id?: string;
|
|
67
|
+
data?: BridgeResultData;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Request event sent to invoke a method
|
|
72
|
+
*/
|
|
73
|
+
export interface BridgeRequestEvent {
|
|
74
|
+
method: string;
|
|
75
|
+
params: object;
|
|
76
|
+
request_id?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Initialization event with available methods
|
|
81
|
+
*/
|
|
82
|
+
export interface BridgeInitEvent {
|
|
83
|
+
methods: string[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Initialization result (success/failure)
|
|
88
|
+
*/
|
|
89
|
+
export type BridgeInitResultEvent = boolean;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Union of all possible bridge data payloads
|
|
93
|
+
*/
|
|
94
|
+
export type BridgeData =
|
|
95
|
+
| BridgeResultEvent
|
|
96
|
+
| BridgeInitEvent
|
|
97
|
+
| BridgeInitResultEvent
|
|
98
|
+
| BridgeRequestEvent;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Complete bridge event with type and data
|
|
102
|
+
*/
|
|
103
|
+
export interface BridgeEvent {
|
|
104
|
+
type: BridgeEventType;
|
|
105
|
+
data: BridgeData;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Handler function for processing incoming requests
|
|
110
|
+
*/
|
|
111
|
+
export type BridgeHandler<TParams = object, TResult = unknown> = (
|
|
112
|
+
params: TParams
|
|
113
|
+
) => Promise<TResult>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Map of method names to their handlers
|
|
117
|
+
*/
|
|
118
|
+
export interface BridgeHandlers {
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
[key: string]: BridgeHandler<any, any>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Listener function for bridge result events
|
|
125
|
+
*/
|
|
126
|
+
export type BridgeListener = (result: BridgeResultEvent) => void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Options for bridge initialization
|
|
130
|
+
*/
|
|
131
|
+
export interface BridgeOptions {
|
|
132
|
+
/** Timeout for method execution in milliseconds (default: 100000) */
|
|
133
|
+
timeout?: number;
|
|
134
|
+
}
|