@difizen/libro-common 0.0.2-alpha.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 +0 -0
- package/es/array.d.ts +368 -0
- package/es/array.d.ts.map +1 -0
- package/es/array.js +577 -0
- package/es/display-wrapper.d.ts +6 -0
- package/es/display-wrapper.d.ts.map +1 -0
- package/es/display-wrapper.js +12 -0
- package/es/index.d.ts +11 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +10 -0
- package/es/iter.d.ts +147 -0
- package/es/iter.d.ts.map +1 -0
- package/es/iter.js +162 -0
- package/es/json.d.ts +126 -0
- package/es/json.d.ts.map +1 -0
- package/es/json.js +274 -0
- package/es/path.d.ts +97 -0
- package/es/path.d.ts.map +1 -0
- package/es/path.js +60 -0
- package/es/polling/index.d.ts +3 -0
- package/es/polling/index.d.ts.map +1 -0
- package/es/polling/index.js +2 -0
- package/es/polling/poll.d.ts +193 -0
- package/es/polling/poll.d.ts.map +1 -0
- package/es/polling/poll.js +501 -0
- package/es/polling/protocol.d.ts +120 -0
- package/es/polling/protocol.d.ts.map +1 -0
- package/es/polling/protocol.js +13 -0
- package/es/posix.d.ts +2 -0
- package/es/posix.d.ts.map +1 -0
- package/es/posix.js +71 -0
- package/es/protocol/cell-protocol.d.ts +181 -0
- package/es/protocol/cell-protocol.d.ts.map +1 -0
- package/es/protocol/cell-protocol.js +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -0
- package/es/protocol/index.js +3 -0
- package/es/protocol/notebook-protocol.d.ts +63 -0
- package/es/protocol/notebook-protocol.d.ts.map +1 -0
- package/es/protocol/notebook-protocol.js +41 -0
- package/es/protocol/output-protocol.d.ts +125 -0
- package/es/protocol/output-protocol.d.ts.map +1 -0
- package/es/protocol/output-protocol.js +1 -0
- package/es/sanitizer.d.ts +44 -0
- package/es/sanitizer.d.ts.map +1 -0
- package/es/sanitizer.js +659 -0
- package/es/url.d.ts +98 -0
- package/es/url.d.ts.map +1 -0
- package/es/url.js +134 -0
- package/es/utils.d.ts +57 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +124 -0
- package/package.json +62 -0
- package/src/array.ts +608 -0
- package/src/display-wrapper.tsx +11 -0
- package/src/index.ts +10 -0
- package/src/iter.ts +199 -0
- package/src/json.ts +321 -0
- package/src/path.ts +138 -0
- package/src/polling/index.ts +2 -0
- package/src/polling/poll.ts +508 -0
- package/src/polling/protocol.ts +145 -0
- package/src/posix.ts +75 -0
- package/src/protocol/cell-protocol.ts +215 -0
- package/src/protocol/index.ts +3 -0
- package/src/protocol/notebook-protocol.ts +73 -0
- package/src/protocol/output-protocol.ts +162 -0
- package/src/sanitizer.ts +944 -0
- package/src/url.ts +157 -0
- package/src/utils.ts +145 -0
package/es/json.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type alias for a JSON primitive.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A type alias for a JSON value.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A type definition for a JSON object.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A type definition for a JSON array.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A type definition for a readonly JSON object.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A type definition for a readonly JSON array.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A type alias for a readonly JSON value.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A type alias for a partial JSON value.
|
|
31
|
+
*
|
|
32
|
+
* Note: Partial here means that JSON object attributes can be `undefined`.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A type definition for a partial JSON array.
|
|
37
|
+
*
|
|
38
|
+
* Note: Partial here means that JSON object attributes can be `undefined`.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A type definition for a partial JSON object.
|
|
43
|
+
*
|
|
44
|
+
* Note: Partial here means that the JSON object attributes can be `undefined`.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A type definition for a readonly partial JSON object.
|
|
49
|
+
*
|
|
50
|
+
* Note: Partial here means that JSON object attributes can be `undefined`.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A type definition for a readonly partial JSON array.
|
|
55
|
+
*
|
|
56
|
+
* Note: Partial here means that JSON object attributes can be `undefined`.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A type alias for a readonly partial JSON value.
|
|
61
|
+
*
|
|
62
|
+
* Note: Partial here means that JSON object attributes can be `undefined`.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A shared frozen empty JSONObject
|
|
67
|
+
*/
|
|
68
|
+
export var emptyObject = Object.freeze({});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A shared frozen empty JSONArray
|
|
72
|
+
*/
|
|
73
|
+
export var emptyArray = Object.freeze([]);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Test whether a JSON value is a primitive.
|
|
77
|
+
*
|
|
78
|
+
* @param value - The JSON value of interest.
|
|
79
|
+
*
|
|
80
|
+
* @returns `true` if the value is a primitive,`false` otherwise.
|
|
81
|
+
*/
|
|
82
|
+
export function isPrimitive(value) {
|
|
83
|
+
return value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Test whether a JSON value is an array.
|
|
88
|
+
*
|
|
89
|
+
* @param value - The JSON value of interest.
|
|
90
|
+
*
|
|
91
|
+
* @returns `true` if the value is a an array, `false` otherwise.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
// export function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray;
|
|
95
|
+
|
|
96
|
+
export function isArray(value) {
|
|
97
|
+
return Array.isArray(value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Test whether a JSON value is an object.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The JSON value of interest.
|
|
104
|
+
*
|
|
105
|
+
* @returns `true` if the value is a an object, `false` otherwise.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
// export function isObject(value: ReadonlyJSONValue): value is ReadonlyJSONObject;
|
|
109
|
+
|
|
110
|
+
// export function isObject(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONObject;
|
|
111
|
+
export function isObject(value) {
|
|
112
|
+
return !isPrimitive(value) && !isArray(value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Compare two JSON values for deep equality.
|
|
117
|
+
*
|
|
118
|
+
* @param first - The first JSON value of interest.
|
|
119
|
+
*
|
|
120
|
+
* @param second - The second JSON value of interest.
|
|
121
|
+
*
|
|
122
|
+
* @returns `true` if the values are equivalent, `false` otherwise.
|
|
123
|
+
*/
|
|
124
|
+
export function deepEqual(first, second) {
|
|
125
|
+
// Check referential and primitive equality first.
|
|
126
|
+
if (first === second) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// If one is a primitive, the `===` check ruled out the other.
|
|
131
|
+
if (isPrimitive(first) || isPrimitive(second)) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Test whether they are arrays.
|
|
136
|
+
var a1 = isArray(first);
|
|
137
|
+
var a2 = isArray(second);
|
|
138
|
+
|
|
139
|
+
// Bail if the types are different.
|
|
140
|
+
if (a1 !== a2) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// If they are both arrays, compare them.
|
|
145
|
+
if (a1 && a2) {
|
|
146
|
+
return deepArrayEqual(first, second);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// At this point, they must both be objects.
|
|
150
|
+
return deepObjectEqual(first, second);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Create a deep copy of a JSON value.
|
|
155
|
+
*
|
|
156
|
+
* @param value - The JSON value to copy.
|
|
157
|
+
*
|
|
158
|
+
* @returns A deep copy of the given JSON value.
|
|
159
|
+
*/
|
|
160
|
+
export function deepCopy(value) {
|
|
161
|
+
// Do nothing for primitive values.
|
|
162
|
+
if (isPrimitive(value)) {
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Deep copy an array.
|
|
167
|
+
if (isArray(value)) {
|
|
168
|
+
return deepArrayCopy(value);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Deep copy an object.
|
|
172
|
+
return deepObjectCopy(value);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Compare two JSON arrays for deep equality.
|
|
177
|
+
*/
|
|
178
|
+
function deepArrayEqual(first, second) {
|
|
179
|
+
// Check referential equality first.
|
|
180
|
+
if (first === second) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Test the arrays for equal length.
|
|
185
|
+
if (first.length !== second.length) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Compare the values for equality.
|
|
190
|
+
for (var i = 0, n = first.length; i < n; ++i) {
|
|
191
|
+
if (!deepEqual(first[i], second[i])) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// At this point, the arrays are equal.
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Compare two JSON objects for deep equality.
|
|
202
|
+
*/
|
|
203
|
+
function deepObjectEqual(first, second) {
|
|
204
|
+
// Check referential equality first.
|
|
205
|
+
if (first === second) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Check for the first object's keys in the second object.
|
|
210
|
+
for (var _key in first) {
|
|
211
|
+
if (first[_key] !== undefined && !(_key in second)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Check for the second object's keys in the first object.
|
|
217
|
+
for (var _key2 in second) {
|
|
218
|
+
if (second[_key2] !== undefined && !(_key2 in first)) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Compare the values for equality.
|
|
224
|
+
for (var _key3 in first) {
|
|
225
|
+
// Get the values.
|
|
226
|
+
var firstValue = first[_key3];
|
|
227
|
+
var secondValue = second[_key3];
|
|
228
|
+
|
|
229
|
+
// If both are undefined, ignore the key.
|
|
230
|
+
if (firstValue === undefined && secondValue === undefined) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// If only one value is undefined, the objects are not equal.
|
|
235
|
+
if (firstValue === undefined || secondValue === undefined) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Compare the values.
|
|
240
|
+
if (!deepEqual(firstValue, secondValue)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// At this point, the objects are equal.
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Create a deep copy of a JSON array.
|
|
251
|
+
*/
|
|
252
|
+
function deepArrayCopy(value) {
|
|
253
|
+
var result = new Array(value.length);
|
|
254
|
+
for (var i = 0, n = value.length; i < n; ++i) {
|
|
255
|
+
result[i] = deepCopy(value[i]);
|
|
256
|
+
}
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Create a deep copy of a JSON object.
|
|
262
|
+
*/
|
|
263
|
+
function deepObjectCopy(value) {
|
|
264
|
+
var result = {};
|
|
265
|
+
for (var _key4 in value) {
|
|
266
|
+
// Ignore undefined values.
|
|
267
|
+
var subvalue = value[_key4];
|
|
268
|
+
if (subvalue === undefined) {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
result[_key4] = deepCopy(subvalue);
|
|
272
|
+
}
|
|
273
|
+
return result;
|
|
274
|
+
}
|
package/es/path.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The namespace for path-related functions.
|
|
3
|
+
*
|
|
4
|
+
* Note that Jupyter server paths do not start with a leading slash.
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace PathExt {
|
|
7
|
+
/**
|
|
8
|
+
* Join all arguments together and normalize the resulting path.
|
|
9
|
+
* Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
|
|
10
|
+
*
|
|
11
|
+
* @param paths - The string paths to join.
|
|
12
|
+
*/
|
|
13
|
+
function join(...paths: string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Return the last portion of a path. Similar to the Unix basename command.
|
|
16
|
+
* Often used to extract the file name from a fully qualified path.
|
|
17
|
+
*
|
|
18
|
+
* @param path - The path to evaluate.
|
|
19
|
+
*
|
|
20
|
+
* @param ext - An extension to remove from the result.
|
|
21
|
+
*/
|
|
22
|
+
function basename(path: string, ext?: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the directory name of a path, similar to the Unix dirname command.
|
|
25
|
+
* When an empty path is given, returns the root path.
|
|
26
|
+
*
|
|
27
|
+
* @param path - The file path.
|
|
28
|
+
*/
|
|
29
|
+
function dirname(path: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get the extension of the path.
|
|
32
|
+
*
|
|
33
|
+
* @param path - The file path.
|
|
34
|
+
*
|
|
35
|
+
* @returns the extension of the file.
|
|
36
|
+
*
|
|
37
|
+
* #### Notes
|
|
38
|
+
* The extension is the string from the last occurrence of the `.`
|
|
39
|
+
* character to end of string in the last portion of the path, inclusive.
|
|
40
|
+
* If there is no `.` in the last portion of the path, or if the first
|
|
41
|
+
* character of the basename of path [[basename]] is `.`, then an
|
|
42
|
+
* empty string is returned.
|
|
43
|
+
*/
|
|
44
|
+
function extname(path: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Normalize a string path, reducing '..' and '.' parts.
|
|
47
|
+
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
|
|
48
|
+
* When an empty path is given, returns the root path.
|
|
49
|
+
*
|
|
50
|
+
* @param path - The string path to normalize.
|
|
51
|
+
*/
|
|
52
|
+
function normalize(path: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Resolve a sequence of paths or path segments into an absolute path.
|
|
55
|
+
* The root path in the application has no leading slash, so it is removed.
|
|
56
|
+
*
|
|
57
|
+
* @param parts - The paths to join.
|
|
58
|
+
*
|
|
59
|
+
* #### Notes
|
|
60
|
+
* The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
|
|
61
|
+
*
|
|
62
|
+
* Starting from leftmost {from} parameter, resolves {to} to an absolute path.
|
|
63
|
+
*
|
|
64
|
+
* If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.
|
|
65
|
+
*/
|
|
66
|
+
function resolve(...parts: string[]): string;
|
|
67
|
+
/**
|
|
68
|
+
* Solve the relative path from {from} to {to}.
|
|
69
|
+
*
|
|
70
|
+
* @param from - The source path.
|
|
71
|
+
*
|
|
72
|
+
* @param to - The target path.
|
|
73
|
+
*
|
|
74
|
+
* #### Notes
|
|
75
|
+
* If from and to each resolve to the same path (after calling
|
|
76
|
+
* path.resolve() on each), a zero-length string is returned.
|
|
77
|
+
* If a zero-length string is passed as from or to, `/`
|
|
78
|
+
* will be used instead of the zero-length strings.
|
|
79
|
+
*/
|
|
80
|
+
function relative(from: string, to: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Normalize a file extension to be of the type `'.foo'`.
|
|
83
|
+
*
|
|
84
|
+
* @param extension - the file extension.
|
|
85
|
+
*
|
|
86
|
+
* #### Notes
|
|
87
|
+
* Adds a leading dot if not present and converts to lower case.
|
|
88
|
+
*/
|
|
89
|
+
function normalizeExtension(extension: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* Remove the leading slash from a path.
|
|
92
|
+
*
|
|
93
|
+
* @param path: the path from which to remove a leading slash.
|
|
94
|
+
*/
|
|
95
|
+
function removeSlash(path: string): string;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=path.d.ts.map
|
package/es/path.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,yBAAiB,OAAO,CAAC;IACvB;;;;;OAKG;IACH,SAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAG/C;IAED;;;;;;;OAOG;IACH,SAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;IAED;;;;;OAKG;IACH,SAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5C;IAED;;;;;;;;;;;;;OAaG;IACH,SAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;IAED;;;;;;OAMG;IACH,SAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK9C;IAED;;;;;;;;;;;;OAYG;IACH,SAAgB,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAElD;IAED;;;;;;;;;;;;OAYG;IACH,SAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEzD;IAED;;;;;;;OAOG;IACH,SAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK5D;IAED;;;;OAIG;IACH,SAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKhD;CACF"}
|
package/es/path.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { posix } from 'path-browserify';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The namespace for path-related functions.
|
|
8
|
+
*
|
|
9
|
+
* Note that Jupyter server paths do not start with a leading slash.
|
|
10
|
+
*/
|
|
11
|
+
export var PathExt;
|
|
12
|
+
(function (_PathExt) {
|
|
13
|
+
function join() {
|
|
14
|
+
var path = posix.join.apply(posix, arguments);
|
|
15
|
+
return path === '.' ? '' : removeSlash(path);
|
|
16
|
+
}
|
|
17
|
+
_PathExt.join = join;
|
|
18
|
+
function basename(path, ext) {
|
|
19
|
+
return posix.basename(path, ext);
|
|
20
|
+
}
|
|
21
|
+
_PathExt.basename = basename;
|
|
22
|
+
function dirname(path) {
|
|
23
|
+
var dir = removeSlash(posix.dirname(path));
|
|
24
|
+
return dir === '.' ? '' : dir;
|
|
25
|
+
}
|
|
26
|
+
_PathExt.dirname = dirname;
|
|
27
|
+
function extname(path) {
|
|
28
|
+
return posix.extname(path);
|
|
29
|
+
}
|
|
30
|
+
_PathExt.extname = extname;
|
|
31
|
+
function normalize(path) {
|
|
32
|
+
if (path === '') {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
return removeSlash(posix.normalize(path));
|
|
36
|
+
}
|
|
37
|
+
_PathExt.normalize = normalize;
|
|
38
|
+
function resolve() {
|
|
39
|
+
return removeSlash(posix.resolve.apply(posix, arguments));
|
|
40
|
+
}
|
|
41
|
+
_PathExt.resolve = resolve;
|
|
42
|
+
function relative(from, to) {
|
|
43
|
+
return removeSlash(posix.relative(from, to));
|
|
44
|
+
}
|
|
45
|
+
_PathExt.relative = relative;
|
|
46
|
+
function normalizeExtension(extension) {
|
|
47
|
+
if (extension.length > 0 && extension.indexOf('.') !== 0) {
|
|
48
|
+
extension = ".".concat(extension);
|
|
49
|
+
}
|
|
50
|
+
return extension;
|
|
51
|
+
}
|
|
52
|
+
_PathExt.normalizeExtension = normalizeExtension;
|
|
53
|
+
function removeSlash(path) {
|
|
54
|
+
if (path.indexOf('/') === 0) {
|
|
55
|
+
path = path.slice(1);
|
|
56
|
+
}
|
|
57
|
+
return path;
|
|
58
|
+
}
|
|
59
|
+
_PathExt.removeSlash = removeSlash;
|
|
60
|
+
})(PathExt || (PathExt = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/polling/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { Event } from '@difizen/mana-common';
|
|
3
|
+
import { Emitter, Deferred } from '@difizen/mana-common';
|
|
4
|
+
import type { IPoll } from './protocol.js';
|
|
5
|
+
/**
|
|
6
|
+
* A class that wraps an asynchronous function to poll at a regular interval
|
|
7
|
+
* with exponential increases to the interval length if the poll fails.
|
|
8
|
+
*
|
|
9
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
10
|
+
* Defaults to `any`.
|
|
11
|
+
*
|
|
12
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
13
|
+
* Defaults to `any`.
|
|
14
|
+
*
|
|
15
|
+
* @typeparam V - An optional type to extend the phases supported by a poll.
|
|
16
|
+
* Defaults to `standby`, which already exists in the `Phase` type.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Poll<T = any, U = any, V extends string = 'standby'> implements IPoll<T, U, V> {
|
|
19
|
+
protected disposeEmitter: Emitter<void>;
|
|
20
|
+
protected _factory: Poll.Factory<T, U, V>;
|
|
21
|
+
protected _frequency: IPoll.Frequency;
|
|
22
|
+
protected _standby: Poll.Standby | (() => boolean | Poll.Standby);
|
|
23
|
+
protected _state: IPoll.State<T, U, V>;
|
|
24
|
+
protected _tick: Deferred<this>;
|
|
25
|
+
protected tickedEmitter: Emitter<IPoll.State<T, U, V>>;
|
|
26
|
+
protected _timeout?: NodeJS.Timeout | undefined;
|
|
27
|
+
disposed: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Instantiate a new poll with exponential backoff in case of failure.
|
|
30
|
+
*
|
|
31
|
+
* @param options - The poll instantiation options.
|
|
32
|
+
*/
|
|
33
|
+
constructor(options: Poll.IOptions<T, U, V>);
|
|
34
|
+
/**
|
|
35
|
+
* The name of the poll.
|
|
36
|
+
*/
|
|
37
|
+
readonly name: string;
|
|
38
|
+
/**
|
|
39
|
+
* A signal emitted when the poll is disposed.
|
|
40
|
+
*/
|
|
41
|
+
get onDispose(): Event<void>;
|
|
42
|
+
/**
|
|
43
|
+
* The polling frequency parameters.
|
|
44
|
+
*/
|
|
45
|
+
get frequency(): IPoll.Frequency;
|
|
46
|
+
set frequency(frequency: IPoll.Frequency);
|
|
47
|
+
/**
|
|
48
|
+
* Whether the poll is disposed.
|
|
49
|
+
*/
|
|
50
|
+
get isDisposed(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Indicates when the poll switches to standby.
|
|
53
|
+
*/
|
|
54
|
+
get standby(): Poll.Standby | (() => boolean | Poll.Standby);
|
|
55
|
+
set standby(standby: Poll.Standby | (() => boolean | Poll.Standby));
|
|
56
|
+
/**
|
|
57
|
+
* The poll state, which is the content of the current poll tick.
|
|
58
|
+
*/
|
|
59
|
+
get state(): IPoll.State<T, U, V>;
|
|
60
|
+
/**
|
|
61
|
+
* A promise that resolves when the poll next ticks.
|
|
62
|
+
*/
|
|
63
|
+
get tick(): Promise<this>;
|
|
64
|
+
/**
|
|
65
|
+
* A signal emitted when the poll ticks and fires off a new request.
|
|
66
|
+
*/
|
|
67
|
+
get ticked(): Event<IPoll.State<T, U, V>>;
|
|
68
|
+
/**
|
|
69
|
+
* Return an async iterator that yields every tick.
|
|
70
|
+
*/
|
|
71
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<IPoll.State<T, U, V>>;
|
|
72
|
+
/**
|
|
73
|
+
* Dispose the poll.
|
|
74
|
+
*/
|
|
75
|
+
dispose(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Refreshes the poll. Schedules `refreshed` tick if necessary.
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise that resolves after tick is scheduled and never rejects.
|
|
80
|
+
*
|
|
81
|
+
* #### Notes
|
|
82
|
+
* The returned promise resolves after the tick is scheduled, but before
|
|
83
|
+
* the polling action is run. To wait until after the poll action executes,
|
|
84
|
+
* await the `poll.tick` promise: `await poll.refresh(); await poll.tick;`
|
|
85
|
+
*/
|
|
86
|
+
refresh(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Schedule the next poll tick.
|
|
89
|
+
*
|
|
90
|
+
* @param next - The next poll state data to schedule. Defaults to standby.
|
|
91
|
+
*
|
|
92
|
+
* @param next.cancel - Cancels state transition if function returns `true`.
|
|
93
|
+
*
|
|
94
|
+
* @returns A promise that resolves when the next poll state is active.
|
|
95
|
+
*
|
|
96
|
+
* #### Notes
|
|
97
|
+
* This method is not meant to be invoked by user code typically. It is public
|
|
98
|
+
* to allow poll instances to be composed into classes that schedule ticks.
|
|
99
|
+
*/
|
|
100
|
+
schedule(next?: Partial<IPoll.State<T, U, V> & {
|
|
101
|
+
cancel: (last: IPoll.State<T, U, V>) => boolean;
|
|
102
|
+
}>): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Starts the poll. Schedules `started` tick if necessary.
|
|
105
|
+
*
|
|
106
|
+
* @returns A promise that resolves after tick is scheduled and never rejects.
|
|
107
|
+
*/
|
|
108
|
+
start(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Stops the poll. Schedules `stopped` tick if necessary.
|
|
111
|
+
*
|
|
112
|
+
* @returns A promise that resolves after tick is scheduled and never rejects.
|
|
113
|
+
*/
|
|
114
|
+
stop(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Execute a new poll factory promise or stand by if necessary.
|
|
117
|
+
*/
|
|
118
|
+
protected _execute(): void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A namespace for `Poll` types, interfaces, and statics.
|
|
122
|
+
*/
|
|
123
|
+
export declare namespace Poll {
|
|
124
|
+
/**
|
|
125
|
+
* A promise factory that returns an individual poll request.
|
|
126
|
+
*
|
|
127
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
128
|
+
*
|
|
129
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
130
|
+
*
|
|
131
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
132
|
+
*/
|
|
133
|
+
type Factory<T, U, V extends string> = (state: IPoll.State<T, U, V>) => Promise<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Indicates when the poll switches to standby.
|
|
136
|
+
*/
|
|
137
|
+
type Standby = 'never' | 'when-hidden';
|
|
138
|
+
/**
|
|
139
|
+
* Instantiation options for polls.
|
|
140
|
+
*
|
|
141
|
+
* @typeparam T - The resolved type of the factory's promises.
|
|
142
|
+
*
|
|
143
|
+
* @typeparam U - The rejected type of the factory's promises.
|
|
144
|
+
*
|
|
145
|
+
* @typeparam V - The type to extend the phases supported by a poll.
|
|
146
|
+
*/
|
|
147
|
+
interface IOptions<T, U, V extends string> {
|
|
148
|
+
/**
|
|
149
|
+
* Whether to begin polling automatically; defaults to `true`.
|
|
150
|
+
*/
|
|
151
|
+
auto?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* A factory function that is passed a poll tick and returns a poll promise.
|
|
154
|
+
*/
|
|
155
|
+
factory: Factory<T, U, V>;
|
|
156
|
+
/**
|
|
157
|
+
* The polling frequency parameters.
|
|
158
|
+
*/
|
|
159
|
+
frequency?: Partial<IPoll.Frequency>;
|
|
160
|
+
/**
|
|
161
|
+
* The name of the poll.
|
|
162
|
+
* Defaults to `'unknown'`.
|
|
163
|
+
*/
|
|
164
|
+
name?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Indicates when the poll switches to standby or a function that returns
|
|
167
|
+
* a boolean or a `Poll.Standby` value to indicate whether to stand by.
|
|
168
|
+
* Defaults to `'when-hidden'`.
|
|
169
|
+
*
|
|
170
|
+
* #### Notes
|
|
171
|
+
* If a function is passed in, for any given context, it should be
|
|
172
|
+
* idempotent and safe to call multiple times. It will be called before each
|
|
173
|
+
* tick execution, but may be called by clients as well.
|
|
174
|
+
*/
|
|
175
|
+
standby?: Standby | (() => boolean | Standby);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* An interval value (0ms) that indicates the poll should tick immediately.
|
|
179
|
+
*/
|
|
180
|
+
const IMMEDIATE = 0;
|
|
181
|
+
/**
|
|
182
|
+
* Delays are 32-bit integers in many browsers so intervals need to be capped.
|
|
183
|
+
*
|
|
184
|
+
* #### Notes
|
|
185
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Maximum_delay_value
|
|
186
|
+
*/
|
|
187
|
+
const MAX_INTERVAL = 2147483647;
|
|
188
|
+
/**
|
|
189
|
+
* An interval value that indicates the poll should never tick.
|
|
190
|
+
*/
|
|
191
|
+
const NEVER: number;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=poll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../src/polling/poll.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD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