@zimi/remote 0.1.0 → 0.1.1-alpha.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/README.md +35 -7
- package/dist/adaptors/http.d.ts +13 -13
- package/dist/adaptors/http.js +26 -25
- package/dist/adaptors/http.js.map +1 -1
- package/dist/adaptors/iframe.d.ts +4 -4
- package/dist/adaptors/iframe.js +38 -37
- package/dist/adaptors/iframe.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/remote.d.ts +79 -79
- package/dist/remote.js +191 -191
- package/dist/remote.js.map +1 -1
- package/dist/remoteValue/index.d.ts +39 -0
- package/dist/remoteValue/index.js +110 -0
- package/dist/remoteValue/index.js.map +1 -0
- package/dist/response.d.ts +104 -104
- package/dist/response.js +154 -154
- package/dist/response.js.map +1 -1
- package/package.json +5 -5
- package/src/adaptor.d.ts +1 -0
- package/src/adaptors/http.ts +1 -0
- package/src/adaptors/iframe.ts +1 -0
- package/src/index.ts +1 -0
- package/src/remoteValue/index.ts +143 -0
- package/src/remoteValue/type.d.ts +113 -0
package/dist/response.d.ts
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
interface RawRemoteError {
|
|
2
|
-
/**
|
|
3
|
-
* code > 0 才是合法的 Error;
|
|
4
|
-
* name 和 message 都是 human readable 的字符串,
|
|
5
|
-
* 仅用于调试和展示,
|
|
6
|
-
* 程序逻辑判断请使用 code
|
|
7
|
-
*/
|
|
8
|
-
code: number;
|
|
9
|
-
/**
|
|
10
|
-
* name 和 message 都是 human readable 的字符串,
|
|
11
|
-
* 仅用于调试和展示,
|
|
12
|
-
* 程序逻辑判断请使用 code
|
|
13
|
-
*/
|
|
14
|
-
name: string;
|
|
15
|
-
/**
|
|
16
|
-
* name 和 message 都是 human readable 的字符串,
|
|
17
|
-
* 仅用于调试和展示,
|
|
18
|
-
* 程序逻辑判断请使用 code
|
|
19
|
-
*/
|
|
20
|
-
message: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* name 和 message 都是 human readable 的字符串,
|
|
24
|
-
* 仅用于调试和展示,
|
|
25
|
-
* 程序逻辑判断请使用 code
|
|
26
|
-
*/
|
|
27
|
-
export declare class RemoteError extends Error {
|
|
28
|
-
/**
|
|
29
|
-
* code > 0 才是合法的 Error;
|
|
30
|
-
* name 和 message 都是 human readable 的字符串,
|
|
31
|
-
* 仅用于调试和展示,
|
|
32
|
-
* 程序逻辑判断请使用 code
|
|
33
|
-
*/
|
|
34
|
-
code: number;
|
|
35
|
-
/**
|
|
36
|
-
* name 和 message 都是 human readable 的字符串,
|
|
37
|
-
* 仅用于调试和展示,
|
|
38
|
-
* 程序逻辑判断请使用 code
|
|
39
|
-
*/
|
|
40
|
-
constructor(message: string);
|
|
41
|
-
toJson(): RawRemoteError;
|
|
42
|
-
toString(): string;
|
|
43
|
-
valueOf(): string;
|
|
44
|
-
static fromError(err: unknown): RemoteError;
|
|
45
|
-
static isRemoteError(data: unknown): data is RawRemoteError;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* name 和 message 都是 human readable 的字符串,
|
|
49
|
-
* 仅用于调试和展示,
|
|
50
|
-
* 程序逻辑判断请使用 code
|
|
51
|
-
*/
|
|
52
|
-
export declare class RemoteTimeoutError extends RemoteError {
|
|
53
|
-
/**
|
|
54
|
-
* name 和 message 都是 human readable 的字符串,
|
|
55
|
-
* 仅用于调试和展示,
|
|
56
|
-
* 程序逻辑判断请使用 code
|
|
57
|
-
*/
|
|
58
|
-
static code: number;
|
|
59
|
-
/**
|
|
60
|
-
* name 和 message 都是 human readable 的字符串,
|
|
61
|
-
* 仅用于调试和展示,
|
|
62
|
-
* 程序逻辑判断请使用 code
|
|
63
|
-
*/
|
|
64
|
-
code: number;
|
|
65
|
-
/**
|
|
66
|
-
* name 和 message 都是 human readable 的字符串,
|
|
67
|
-
* 仅用于调试和展示,
|
|
68
|
-
* 程序逻辑判断请使用 code
|
|
69
|
-
*/
|
|
70
|
-
constructor(message: string);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* name 和 message 都是 human readable 的字符串,
|
|
74
|
-
* 仅用于调试和展示,
|
|
75
|
-
* 程序逻辑判断请使用 code
|
|
76
|
-
*/
|
|
77
|
-
export declare class RemoteNotFoundError extends RemoteError {
|
|
78
|
-
/**
|
|
79
|
-
* name 和 message 都是 human readable 的字符串,
|
|
80
|
-
* 仅用于调试和展示,
|
|
81
|
-
* 程序逻辑判断请使用 code
|
|
82
|
-
*/
|
|
83
|
-
static code: number;
|
|
84
|
-
/**
|
|
85
|
-
* name 和 message 都是 human readable 的字符串,
|
|
86
|
-
* 仅用于调试和展示,
|
|
87
|
-
* 程序逻辑判断请使用 code
|
|
88
|
-
*/
|
|
89
|
-
code: number;
|
|
90
|
-
/**
|
|
91
|
-
* name 和 message 都是 human readable 的字符串,
|
|
92
|
-
* 仅用于调试和展示,
|
|
93
|
-
* 程序逻辑判断请使用 code
|
|
94
|
-
*/
|
|
95
|
-
constructor(message: string);
|
|
96
|
-
}
|
|
97
|
-
export declare const response: {
|
|
98
|
-
success<T>(data: T): {
|
|
99
|
-
readonly code: 0;
|
|
100
|
-
readonly data: T;
|
|
101
|
-
};
|
|
102
|
-
error(error: RemoteError): RawRemoteError;
|
|
103
|
-
};
|
|
104
|
-
export {};
|
|
1
|
+
interface RawRemoteError {
|
|
2
|
+
/**
|
|
3
|
+
* code > 0 才是合法的 Error;
|
|
4
|
+
* name 和 message 都是 human readable 的字符串,
|
|
5
|
+
* 仅用于调试和展示,
|
|
6
|
+
* 程序逻辑判断请使用 code
|
|
7
|
+
*/
|
|
8
|
+
code: number;
|
|
9
|
+
/**
|
|
10
|
+
* name 和 message 都是 human readable 的字符串,
|
|
11
|
+
* 仅用于调试和展示,
|
|
12
|
+
* 程序逻辑判断请使用 code
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* name 和 message 都是 human readable 的字符串,
|
|
17
|
+
* 仅用于调试和展示,
|
|
18
|
+
* 程序逻辑判断请使用 code
|
|
19
|
+
*/
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* name 和 message 都是 human readable 的字符串,
|
|
24
|
+
* 仅用于调试和展示,
|
|
25
|
+
* 程序逻辑判断请使用 code
|
|
26
|
+
*/
|
|
27
|
+
export declare class RemoteError extends Error {
|
|
28
|
+
/**
|
|
29
|
+
* code > 0 才是合法的 Error;
|
|
30
|
+
* name 和 message 都是 human readable 的字符串,
|
|
31
|
+
* 仅用于调试和展示,
|
|
32
|
+
* 程序逻辑判断请使用 code
|
|
33
|
+
*/
|
|
34
|
+
code: number;
|
|
35
|
+
/**
|
|
36
|
+
* name 和 message 都是 human readable 的字符串,
|
|
37
|
+
* 仅用于调试和展示,
|
|
38
|
+
* 程序逻辑判断请使用 code
|
|
39
|
+
*/
|
|
40
|
+
constructor(message: string);
|
|
41
|
+
toJson(): RawRemoteError;
|
|
42
|
+
toString(): string;
|
|
43
|
+
valueOf(): string;
|
|
44
|
+
static fromError(err: unknown): RemoteError;
|
|
45
|
+
static isRemoteError(data: unknown): data is RawRemoteError;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* name 和 message 都是 human readable 的字符串,
|
|
49
|
+
* 仅用于调试和展示,
|
|
50
|
+
* 程序逻辑判断请使用 code
|
|
51
|
+
*/
|
|
52
|
+
export declare class RemoteTimeoutError extends RemoteError {
|
|
53
|
+
/**
|
|
54
|
+
* name 和 message 都是 human readable 的字符串,
|
|
55
|
+
* 仅用于调试和展示,
|
|
56
|
+
* 程序逻辑判断请使用 code
|
|
57
|
+
*/
|
|
58
|
+
static code: number;
|
|
59
|
+
/**
|
|
60
|
+
* name 和 message 都是 human readable 的字符串,
|
|
61
|
+
* 仅用于调试和展示,
|
|
62
|
+
* 程序逻辑判断请使用 code
|
|
63
|
+
*/
|
|
64
|
+
code: number;
|
|
65
|
+
/**
|
|
66
|
+
* name 和 message 都是 human readable 的字符串,
|
|
67
|
+
* 仅用于调试和展示,
|
|
68
|
+
* 程序逻辑判断请使用 code
|
|
69
|
+
*/
|
|
70
|
+
constructor(message: string);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* name 和 message 都是 human readable 的字符串,
|
|
74
|
+
* 仅用于调试和展示,
|
|
75
|
+
* 程序逻辑判断请使用 code
|
|
76
|
+
*/
|
|
77
|
+
export declare class RemoteNotFoundError extends RemoteError {
|
|
78
|
+
/**
|
|
79
|
+
* name 和 message 都是 human readable 的字符串,
|
|
80
|
+
* 仅用于调试和展示,
|
|
81
|
+
* 程序逻辑判断请使用 code
|
|
82
|
+
*/
|
|
83
|
+
static code: number;
|
|
84
|
+
/**
|
|
85
|
+
* name 和 message 都是 human readable 的字符串,
|
|
86
|
+
* 仅用于调试和展示,
|
|
87
|
+
* 程序逻辑判断请使用 code
|
|
88
|
+
*/
|
|
89
|
+
code: number;
|
|
90
|
+
/**
|
|
91
|
+
* name 和 message 都是 human readable 的字符串,
|
|
92
|
+
* 仅用于调试和展示,
|
|
93
|
+
* 程序逻辑判断请使用 code
|
|
94
|
+
*/
|
|
95
|
+
constructor(message: string);
|
|
96
|
+
}
|
|
97
|
+
export declare const response: {
|
|
98
|
+
success<T>(data: T): {
|
|
99
|
+
readonly code: 0;
|
|
100
|
+
readonly data: T;
|
|
101
|
+
};
|
|
102
|
+
error(error: RemoteError): RawRemoteError;
|
|
103
|
+
};
|
|
104
|
+
export {};
|
package/dist/response.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* name 和 message 都是 human readable 的字符串,
|
|
3
|
-
* 仅用于调试和展示,
|
|
4
|
-
* 程序逻辑判断请使用 code
|
|
5
|
-
*/
|
|
6
|
-
export class RemoteError extends Error {
|
|
7
|
-
/**
|
|
8
|
-
* name 和 message 都是 human readable 的字符串,
|
|
9
|
-
* 仅用于调试和展示,
|
|
10
|
-
* 程序逻辑判断请使用 code
|
|
11
|
-
*/
|
|
12
|
-
constructor(message) {
|
|
13
|
-
super(message);
|
|
14
|
-
/**
|
|
15
|
-
* code > 0 才是合法的 Error;
|
|
16
|
-
* name 和 message 都是 human readable 的字符串,
|
|
17
|
-
* 仅用于调试和展示,
|
|
18
|
-
* 程序逻辑判断请使用 code
|
|
19
|
-
*/
|
|
20
|
-
Object.defineProperty(this, "code", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: 1
|
|
25
|
-
});
|
|
26
|
-
this.name = 'RemoteError';
|
|
27
|
-
}
|
|
28
|
-
toJson() {
|
|
29
|
-
return {
|
|
30
|
-
code: this.code,
|
|
31
|
-
name: this.name,
|
|
32
|
-
message: this.message,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
toString() {
|
|
36
|
-
return JSON.stringify(this.toJson());
|
|
37
|
-
}
|
|
38
|
-
valueOf() {
|
|
39
|
-
return `${this.name} [${this.code}]: ${this.message}`;
|
|
40
|
-
}
|
|
41
|
-
static fromError(err) {
|
|
42
|
-
if (typeof err === 'string') {
|
|
43
|
-
return new RemoteError(err);
|
|
44
|
-
}
|
|
45
|
-
if (!err) {
|
|
46
|
-
return new RemoteError('Unknown error');
|
|
47
|
-
}
|
|
48
|
-
const json = err;
|
|
49
|
-
const error = new RemoteError(typeof json.message === 'string' ? json.message : 'Unknown error');
|
|
50
|
-
if (typeof json.code === 'number' && json.code > 0) {
|
|
51
|
-
error.code = json.code;
|
|
52
|
-
}
|
|
53
|
-
if (json.name && typeof json.name === 'string') {
|
|
54
|
-
error.name = json.name;
|
|
55
|
-
}
|
|
56
|
-
return error;
|
|
57
|
-
}
|
|
58
|
-
static isRemoteError(data) {
|
|
59
|
-
const json = data;
|
|
60
|
-
return (!!json &&
|
|
61
|
-
typeof json === 'object' &&
|
|
62
|
-
typeof json.code === 'number' &&
|
|
63
|
-
json.code > 0 &&
|
|
64
|
-
typeof json.name === 'string' &&
|
|
65
|
-
typeof json.message === 'string');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* name 和 message 都是 human readable 的字符串,
|
|
70
|
-
* 仅用于调试和展示,
|
|
71
|
-
* 程序逻辑判断请使用 code
|
|
72
|
-
*/
|
|
73
|
-
export class RemoteTimeoutError extends RemoteError {
|
|
74
|
-
/**
|
|
75
|
-
* name 和 message 都是 human readable 的字符串,
|
|
76
|
-
* 仅用于调试和展示,
|
|
77
|
-
* 程序逻辑判断请使用 code
|
|
78
|
-
*/
|
|
79
|
-
constructor(message) {
|
|
80
|
-
super(message);
|
|
81
|
-
/**
|
|
82
|
-
* name 和 message 都是 human readable 的字符串,
|
|
83
|
-
* 仅用于调试和展示,
|
|
84
|
-
* 程序逻辑判断请使用 code
|
|
85
|
-
*/
|
|
86
|
-
Object.defineProperty(this, "code", {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true,
|
|
90
|
-
value: 2
|
|
91
|
-
});
|
|
92
|
-
this.name = 'RemoteTimeoutError';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* name 和 message 都是 human readable 的字符串,
|
|
97
|
-
* 仅用于调试和展示,
|
|
98
|
-
* 程序逻辑判断请使用 code
|
|
99
|
-
*/
|
|
100
|
-
Object.defineProperty(RemoteTimeoutError, "code", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true,
|
|
104
|
-
value: 2
|
|
105
|
-
});
|
|
106
|
-
/**
|
|
107
|
-
* name 和 message 都是 human readable 的字符串,
|
|
108
|
-
* 仅用于调试和展示,
|
|
109
|
-
* 程序逻辑判断请使用 code
|
|
110
|
-
*/
|
|
111
|
-
export class RemoteNotFoundError extends RemoteError {
|
|
112
|
-
/**
|
|
113
|
-
* name 和 message 都是 human readable 的字符串,
|
|
114
|
-
* 仅用于调试和展示,
|
|
115
|
-
* 程序逻辑判断请使用 code
|
|
116
|
-
*/
|
|
117
|
-
constructor(message) {
|
|
118
|
-
super(message);
|
|
119
|
-
/**
|
|
120
|
-
* name 和 message 都是 human readable 的字符串,
|
|
121
|
-
* 仅用于调试和展示,
|
|
122
|
-
* 程序逻辑判断请使用 code
|
|
123
|
-
*/
|
|
124
|
-
Object.defineProperty(this, "code", {
|
|
125
|
-
enumerable: true,
|
|
126
|
-
configurable: true,
|
|
127
|
-
writable: true,
|
|
128
|
-
value: 3
|
|
129
|
-
});
|
|
130
|
-
this.name = 'RemoteNotFoundError';
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* name 和 message 都是 human readable 的字符串,
|
|
135
|
-
* 仅用于调试和展示,
|
|
136
|
-
* 程序逻辑判断请使用 code
|
|
137
|
-
*/
|
|
138
|
-
Object.defineProperty(RemoteNotFoundError, "code", {
|
|
139
|
-
enumerable: true,
|
|
140
|
-
configurable: true,
|
|
141
|
-
writable: true,
|
|
142
|
-
value: 3
|
|
143
|
-
});
|
|
144
|
-
export const response = {
|
|
145
|
-
success(data) {
|
|
146
|
-
return {
|
|
147
|
-
code: 0,
|
|
148
|
-
data,
|
|
149
|
-
};
|
|
150
|
-
},
|
|
151
|
-
error(error) {
|
|
152
|
-
return error.toJson();
|
|
153
|
-
},
|
|
154
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* name 和 message 都是 human readable 的字符串,
|
|
3
|
+
* 仅用于调试和展示,
|
|
4
|
+
* 程序逻辑判断请使用 code
|
|
5
|
+
*/
|
|
6
|
+
export class RemoteError extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* name 和 message 都是 human readable 的字符串,
|
|
9
|
+
* 仅用于调试和展示,
|
|
10
|
+
* 程序逻辑判断请使用 code
|
|
11
|
+
*/
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
/**
|
|
15
|
+
* code > 0 才是合法的 Error;
|
|
16
|
+
* name 和 message 都是 human readable 的字符串,
|
|
17
|
+
* 仅用于调试和展示,
|
|
18
|
+
* 程序逻辑判断请使用 code
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(this, "code", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: 1
|
|
25
|
+
});
|
|
26
|
+
this.name = 'RemoteError';
|
|
27
|
+
}
|
|
28
|
+
toJson() {
|
|
29
|
+
return {
|
|
30
|
+
code: this.code,
|
|
31
|
+
name: this.name,
|
|
32
|
+
message: this.message,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
toString() {
|
|
36
|
+
return JSON.stringify(this.toJson());
|
|
37
|
+
}
|
|
38
|
+
valueOf() {
|
|
39
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
40
|
+
}
|
|
41
|
+
static fromError(err) {
|
|
42
|
+
if (typeof err === 'string') {
|
|
43
|
+
return new RemoteError(err);
|
|
44
|
+
}
|
|
45
|
+
if (!err) {
|
|
46
|
+
return new RemoteError('Unknown error');
|
|
47
|
+
}
|
|
48
|
+
const json = err;
|
|
49
|
+
const error = new RemoteError(typeof json.message === 'string' ? json.message : 'Unknown error');
|
|
50
|
+
if (typeof json.code === 'number' && json.code > 0) {
|
|
51
|
+
error.code = json.code;
|
|
52
|
+
}
|
|
53
|
+
if (json.name && typeof json.name === 'string') {
|
|
54
|
+
error.name = json.name;
|
|
55
|
+
}
|
|
56
|
+
return error;
|
|
57
|
+
}
|
|
58
|
+
static isRemoteError(data) {
|
|
59
|
+
const json = data;
|
|
60
|
+
return (!!json &&
|
|
61
|
+
typeof json === 'object' &&
|
|
62
|
+
typeof json.code === 'number' &&
|
|
63
|
+
json.code > 0 &&
|
|
64
|
+
typeof json.name === 'string' &&
|
|
65
|
+
typeof json.message === 'string');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* name 和 message 都是 human readable 的字符串,
|
|
70
|
+
* 仅用于调试和展示,
|
|
71
|
+
* 程序逻辑判断请使用 code
|
|
72
|
+
*/
|
|
73
|
+
export class RemoteTimeoutError extends RemoteError {
|
|
74
|
+
/**
|
|
75
|
+
* name 和 message 都是 human readable 的字符串,
|
|
76
|
+
* 仅用于调试和展示,
|
|
77
|
+
* 程序逻辑判断请使用 code
|
|
78
|
+
*/
|
|
79
|
+
constructor(message) {
|
|
80
|
+
super(message);
|
|
81
|
+
/**
|
|
82
|
+
* name 和 message 都是 human readable 的字符串,
|
|
83
|
+
* 仅用于调试和展示,
|
|
84
|
+
* 程序逻辑判断请使用 code
|
|
85
|
+
*/
|
|
86
|
+
Object.defineProperty(this, "code", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: 2
|
|
91
|
+
});
|
|
92
|
+
this.name = 'RemoteTimeoutError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* name 和 message 都是 human readable 的字符串,
|
|
97
|
+
* 仅用于调试和展示,
|
|
98
|
+
* 程序逻辑判断请使用 code
|
|
99
|
+
*/
|
|
100
|
+
Object.defineProperty(RemoteTimeoutError, "code", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: 2
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* name 和 message 都是 human readable 的字符串,
|
|
108
|
+
* 仅用于调试和展示,
|
|
109
|
+
* 程序逻辑判断请使用 code
|
|
110
|
+
*/
|
|
111
|
+
export class RemoteNotFoundError extends RemoteError {
|
|
112
|
+
/**
|
|
113
|
+
* name 和 message 都是 human readable 的字符串,
|
|
114
|
+
* 仅用于调试和展示,
|
|
115
|
+
* 程序逻辑判断请使用 code
|
|
116
|
+
*/
|
|
117
|
+
constructor(message) {
|
|
118
|
+
super(message);
|
|
119
|
+
/**
|
|
120
|
+
* name 和 message 都是 human readable 的字符串,
|
|
121
|
+
* 仅用于调试和展示,
|
|
122
|
+
* 程序逻辑判断请使用 code
|
|
123
|
+
*/
|
|
124
|
+
Object.defineProperty(this, "code", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: 3
|
|
129
|
+
});
|
|
130
|
+
this.name = 'RemoteNotFoundError';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* name 和 message 都是 human readable 的字符串,
|
|
135
|
+
* 仅用于调试和展示,
|
|
136
|
+
* 程序逻辑判断请使用 code
|
|
137
|
+
*/
|
|
138
|
+
Object.defineProperty(RemoteNotFoundError, "code", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
configurable: true,
|
|
141
|
+
writable: true,
|
|
142
|
+
value: 3
|
|
143
|
+
});
|
|
144
|
+
export const response = {
|
|
145
|
+
success(data) {
|
|
146
|
+
return {
|
|
147
|
+
code: 0,
|
|
148
|
+
data,
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
error(error) {
|
|
152
|
+
return error.toJson();
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
155
|
//# sourceMappingURL=response.js.map
|
package/dist/response.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IASpC;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAdhB;;;;;WAKG;QACH;;;;mBAAO,CAAC;WAAA;QASN,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAA;IACH,CAAC;IAED,QA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IG;QACH;;;;mBAAO,CAAC;WAAA;QASN,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;;AAtBD;;;;GAIG;AACI;;;;WAAO,CAAC;EAAJ,CAAI;AAoBjB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,CAAI,IAAO;QAChB,OAAO;YACL,IAAI,EAAE,CAAC;YACP,IAAI;SACI,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,KAAkB;QACtB,OAAO,KAAK,CAAC,MAAM,EAAE,CAAA;IACvB,CAAC;CACF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zimi/remote",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1-alpha.1",
|
|
5
5
|
"author": "xiaomingTang",
|
|
6
6
|
"description": "call remote functions as local",
|
|
7
7
|
"private": false,
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"src",
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"eventemitter3": "^5.0.1"
|
|
19
|
+
},
|
|
17
20
|
"scripts": {
|
|
18
21
|
"build": "tsc",
|
|
19
22
|
"build:watch": "tsc --watch"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"eventemitter3": "^5.0.1"
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|
package/src/adaptor.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface Adaptor {
|
|
|
28
28
|
* off 用于移除 once 注册的事件,当事件超时后,需要主动 off
|
|
29
29
|
*/
|
|
30
30
|
off: (name: string, callback: AdaptorCallback) => void
|
|
31
|
+
on: (name: string, callback: AdaptorCallback) => void
|
|
31
32
|
once: (name: string, callback: AdaptorCallback) => void
|
|
32
33
|
emit: (data: AdaptorPackageData) => void
|
|
33
34
|
}
|
package/src/adaptors/http.ts
CHANGED
|
@@ -21,6 +21,7 @@ export function createHttpAdaptor({
|
|
|
21
21
|
}) {
|
|
22
22
|
const adaptor: Adaptor = {
|
|
23
23
|
every: remoteEventManager.onEvery.bind(remoteEventManager),
|
|
24
|
+
on: remoteEventManager.on.bind(remoteEventManager),
|
|
24
25
|
once: remoteEventManager.once.bind(remoteEventManager),
|
|
25
26
|
off: remoteEventManager.off.bind(remoteEventManager),
|
|
26
27
|
emit: onEmit,
|
package/src/adaptors/iframe.ts
CHANGED
|
@@ -37,6 +37,7 @@ export function createIframeAdaptor({
|
|
|
37
37
|
|
|
38
38
|
const adaptor: Adaptor = {
|
|
39
39
|
every: remoteEventManager.onEvery.bind(remoteEventManager),
|
|
40
|
+
on: remoteEventManager.on.bind(remoteEventManager),
|
|
40
41
|
once: remoteEventManager.once.bind(remoteEventManager),
|
|
41
42
|
off: remoteEventManager.off.bind(remoteEventManager),
|
|
42
43
|
emit: onEmit,
|
package/src/index.ts
CHANGED