@difizen/libro-common 0.1.0 → 0.1.2

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.
Files changed (48) hide show
  1. package/es/array.d.ts +368 -0
  2. package/es/array.d.ts.map +1 -0
  3. package/es/display-wrapper.d.ts +6 -0
  4. package/es/display-wrapper.d.ts.map +1 -0
  5. package/es/dom.d.ts +3 -0
  6. package/es/dom.d.ts.map +1 -0
  7. package/es/dom.js +97 -0
  8. package/es/index.d.ts +12 -0
  9. package/es/index.d.ts.map +1 -0
  10. package/es/index.js +2 -1
  11. package/es/iter.d.ts +147 -0
  12. package/es/iter.d.ts.map +1 -0
  13. package/es/json.d.ts +126 -0
  14. package/es/json.d.ts.map +1 -0
  15. package/es/path.d.ts +97 -0
  16. package/es/path.d.ts.map +1 -0
  17. package/es/polling/index.d.ts +3 -0
  18. package/es/polling/index.d.ts.map +1 -0
  19. package/es/polling/poll.d.ts +193 -0
  20. package/es/polling/poll.d.ts.map +1 -0
  21. package/es/polling/poll.js +1 -1
  22. package/es/polling/protocol.d.ts +120 -0
  23. package/es/polling/protocol.d.ts.map +1 -0
  24. package/es/posix.d.ts +2 -0
  25. package/es/posix.d.ts.map +1 -0
  26. package/es/protocol/cell-protocol.d.ts +181 -0
  27. package/es/protocol/cell-protocol.d.ts.map +1 -0
  28. package/es/protocol/index.d.ts +4 -0
  29. package/es/protocol/index.d.ts.map +1 -0
  30. package/es/protocol/notebook-protocol.d.ts +63 -0
  31. package/es/protocol/notebook-protocol.d.ts.map +1 -0
  32. package/es/protocol/output-protocol.d.ts +125 -0
  33. package/es/protocol/output-protocol.d.ts.map +1 -0
  34. package/es/sanitizer.d.ts +45 -0
  35. package/es/sanitizer.d.ts.map +1 -0
  36. package/es/url.d.ts +98 -0
  37. package/es/url.d.ts.map +1 -0
  38. package/es/url.js +1 -1
  39. package/es/utils.d.ts +57 -0
  40. package/es/utils.d.ts.map +1 -0
  41. package/package.json +2 -2
  42. package/src/dom.ts +71 -0
  43. package/src/index.ts +1 -0
  44. package/src/iter.ts +2 -2
  45. package/src/polling/poll.ts +2 -2
  46. package/src/polling/protocol.ts +1 -1
  47. package/src/sanitizer.ts +15 -15
  48. package/src/url.ts +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iter.d.ts","sourceRoot":"","sources":["../src/iter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,IAAI,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAChD;;;;;;;;;;;OAWG;IACH,KAAK,EAAE,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC;IAE1B;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IACnD;;;;OAIG;gBACS,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAIhC;;;;OAIG;IACH,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC;IAIpB;;;;OAIG;IACH,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC;IAMrB;;;;OAIG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS;IAOrB,SAAS,CAAC,MAAM,SAAK;IACrB,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAQpE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACpB,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC9B,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,GAC9C,IAAI,CASN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAS9D"}
package/es/json.d.ts ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * A type alias for a JSON primitive.
3
+ */
4
+ export type JSONPrimitive = boolean | number | string | null;
5
+ /**
6
+ * A type alias for a JSON value.
7
+ */
8
+ export type JSONValue = JSONPrimitive | {
9
+ [key: string]: JSONValue;
10
+ } | JSONValue[];
11
+ /**
12
+ * A type definition for a JSON object.
13
+ */
14
+ export type JSONObject = Record<string, JSONValue>;
15
+ /**
16
+ * A type definition for a JSON array.
17
+ */
18
+ export type JSONArray = JSONValue[];
19
+ /**
20
+ * A type definition for a readonly JSON object.
21
+ */
22
+ export type ReadonlyJSONObject = Readonly<Record<string, ReadonlyJSONValue>>;
23
+ /**
24
+ * A type definition for a readonly JSON array.
25
+ */
26
+ export type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
27
+ /**
28
+ * A type alias for a readonly JSON value.
29
+ */
30
+ export type ReadonlyJSONValue = JSONPrimitive | Readonly<{
31
+ [key: string]: ReadonlyJSONValue;
32
+ }> | readonly ReadonlyJSONValue[];
33
+ /**
34
+ * A type alias for a partial JSON value.
35
+ *
36
+ * Note: Partial here means that JSON object attributes can be `undefined`.
37
+ */
38
+ export type PartialJSONValue = JSONPrimitive | Partial<{
39
+ [key: string]: PartialJSONValue;
40
+ }> | PartialJSONValue[];
41
+ /**
42
+ * A type definition for a partial JSON array.
43
+ *
44
+ * Note: Partial here means that JSON object attributes can be `undefined`.
45
+ */
46
+ export type PartialJSONArray = PartialJSONValue[];
47
+ /**
48
+ * A type definition for a partial JSON object.
49
+ *
50
+ * Note: Partial here means that the JSON object attributes can be `undefined`.
51
+ */
52
+ export type PartialJSONObject = Record<string, PartialJSONValue | undefined>;
53
+ /**
54
+ * A type definition for a readonly partial JSON object.
55
+ *
56
+ * Note: Partial here means that JSON object attributes can be `undefined`.
57
+ */
58
+ export type ReadonlyPartialJSONObject = Readonly<Record<string, ReadonlyPartialJSONValue | undefined>>;
59
+ /**
60
+ * A type definition for a readonly partial JSON array.
61
+ *
62
+ * Note: Partial here means that JSON object attributes can be `undefined`.
63
+ */
64
+ export type ReadonlyPartialJSONArray = readonly ReadonlyPartialJSONValue[];
65
+ /**
66
+ * A type alias for a readonly partial JSON value.
67
+ *
68
+ * Note: Partial here means that JSON object attributes can be `undefined`.
69
+ */
70
+ export type ReadonlyPartialJSONValue = JSONPrimitive | {
71
+ readonly [key: string]: ReadonlyPartialJSONValue | undefined;
72
+ } | readonly ReadonlyPartialJSONValue[];
73
+ /**
74
+ * A shared frozen empty JSONObject
75
+ */
76
+ export declare const emptyObject: Readonly<Record<string, ReadonlyJSONValue>>;
77
+ /**
78
+ * A shared frozen empty JSONArray
79
+ */
80
+ export declare const emptyArray: ReadonlyJSONArray;
81
+ /**
82
+ * Test whether a JSON value is a primitive.
83
+ *
84
+ * @param value - The JSON value of interest.
85
+ *
86
+ * @returns `true` if the value is a primitive,`false` otherwise.
87
+ */
88
+ export declare function isPrimitive(value: ReadonlyPartialJSONValue): value is JSONPrimitive;
89
+ /**
90
+ * Test whether a JSON value is an array.
91
+ *
92
+ * @param value - The JSON value of interest.
93
+ *
94
+ * @returns `true` if the value is a an array, `false` otherwise.
95
+ */
96
+ export declare function isArray(value: JSONValue): value is JSONArray;
97
+ export declare function isArray(value: PartialJSONValue): value is PartialJSONArray;
98
+ export declare function isArray(value: ReadonlyPartialJSONValue): value is ReadonlyPartialJSONArray;
99
+ /**
100
+ * Test whether a JSON value is an object.
101
+ *
102
+ * @param value - The JSON value of interest.
103
+ *
104
+ * @returns `true` if the value is a an object, `false` otherwise.
105
+ */
106
+ export declare function isObject(value: JSONValue): value is JSONObject;
107
+ export declare function isObject(value: PartialJSONValue): value is PartialJSONObject;
108
+ /**
109
+ * Compare two JSON values for deep equality.
110
+ *
111
+ * @param first - The first JSON value of interest.
112
+ *
113
+ * @param second - The second JSON value of interest.
114
+ *
115
+ * @returns `true` if the values are equivalent, `false` otherwise.
116
+ */
117
+ export declare function deepEqual(first: ReadonlyPartialJSONValue, second: ReadonlyPartialJSONValue): boolean;
118
+ /**
119
+ * Create a deep copy of a JSON value.
120
+ *
121
+ * @param value - The JSON value to copy.
122
+ *
123
+ * @returns A deep copy of the given JSON value.
124
+ */
125
+ export declare function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T;
126
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,EAAE,CAAC;AAEnF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,iBAAiB,EAAE,C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,CAAC;AAC5E,wBAAgB,OAAO,CACrB,KAAK,EAAE,wBAAwB,GAC9B,KAAK,IAAI,wBAAwB,CAAC;AAKrC;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,UAAU,CAAC;AAEhE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,KAAK,IAAI,iBAAiB,CAAC;AAM9E;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,wBAAwB,EAC/B,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAiCT;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,wBAAwB,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAaxE"}
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
@@ -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"}
@@ -0,0 +1,3 @@
1
+ export { Poll } from './poll.js';
2
+ export * from './protocol.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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-app';
3
+ import { Emitter, Deferred } from '@difizen/mana-app';
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
+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;IA+ChB;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB;;OAEG;IACH,SAAS,CAAC,QAAQ,IAAI,IAAI;CA6C3B;AAED;;GAEG;AACH,yBAAiB,IAAI,CAAC;IACpB;;;;;;;;OAQG;IACH,KAAY,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAC5C,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KACxB,OAAO,CAAC,CAAC,CAAC,CAAC;IAEhB;;OAEG;IACH,KAAY,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;IAE9C;;;;;;;;OAQG;IACH,UAAiB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM;QAC9C;;WAEG;QACH,IAAI,CAAC,EAAE,OAAO,CAAC;QAEf;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE1B;;WAEG;QACH,SAAS,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAErC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd;;;;;;;;;WASG;QACH,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC;KAC/C;IACD;;OAEG;IACI,MAAM,SAAS,IAAI,CAAC;IAE3B;;;;;OAKG;IACI,MAAM,YAAY,aAAa,CAAC;IAEvC;;OAEG;IACI,MAAM,KAAK,QAAW,CAAC;CAC/B"}
@@ -18,7 +18,7 @@ _AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator ||
18
18
  function _OverloadYield(t, e) { this.v = t, this.k = e; }
19
19
  /* eslint-disable @typescript-eslint/no-explicit-any */
20
20
 
21
- import { Emitter, Deferred } from '@difizen/mana-common';
21
+ import { Emitter, Deferred } from '@difizen/mana-app';
22
22
  import { deepEqual } from "../json.js";
23
23
  _Symbol$asyncIterator = Symbol.asyncIterator;
24
24
  /**
@@ -0,0 +1,120 @@
1
+ import type { Event } from '@difizen/mana-app';
2
+ /**
3
+ * A readonly poll that calls an asynchronous function with each tick.
4
+ *
5
+ * @typeparam T - The resolved type of the factory's promises.
6
+ *
7
+ * @typeparam U - The rejected type of the factory's promises.
8
+ *
9
+ * @typeparam V - The type to extend the phases supported by a poll.
10
+ */
11
+ export interface IPoll<T, U, V extends string> extends AsyncIterable<IPoll.State<T, U, V>> {
12
+ /**
13
+ * A signal emitted when the poll is disposed.
14
+ */
15
+ readonly onDispose: Event<void>;
16
+ /**
17
+ * The polling frequency data.
18
+ */
19
+ readonly frequency: IPoll.Frequency;
20
+ /**
21
+ * Whether the poll is disposed.
22
+ */
23
+ readonly disposed: boolean;
24
+ /**
25
+ * The name of the poll.
26
+ */
27
+ readonly name: string;
28
+ /**
29
+ * The poll state, which is the content of the currently-scheduled poll tick.
30
+ */
31
+ readonly state: IPoll.State<T, U, V>;
32
+ /**
33
+ * A promise that resolves when the currently-scheduled tick completes.
34
+ *
35
+ * #### Notes
36
+ * Usually this will resolve after `state.interval` milliseconds from
37
+ * `state.timestamp`. It can resolve earlier if the user starts or refreshes
38
+ * the poll, etc.
39
+ */
40
+ readonly tick: Promise<IPoll<T, U, V>>;
41
+ /**
42
+ * A signal emitted when the poll state changes, i.e., a new tick is scheduled.
43
+ */
44
+ readonly ticked: Event<IPoll.State<T, U, V>>;
45
+ }
46
+ /**
47
+ * A namespace for `IPoll` types.
48
+ */
49
+ export declare namespace IPoll {
50
+ /**
51
+ * The polling frequency parameters.
52
+ *
53
+ * #### Notes
54
+ * We implement the "decorrelated jitter" strategy from
55
+ * https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/.
56
+ * Essentially, if consecutive retries are needed, we choose an integer:
57
+ * `sleep = min(max, rand(interval, backoff * sleep))`
58
+ * This ensures that the poll is never less than `interval`, and nicely
59
+ * spreads out retries for consecutive tries. Over time, if (interval < max),
60
+ * the random number will be above `max` about (1 - 1/backoff) of the time
61
+ * (sleeping the `max`), and the rest of the time the sleep will be a random
62
+ * number below `max`, decorrelating our trigger time from other pollers.
63
+ */
64
+ type Frequency = {
65
+ /**
66
+ * Whether poll frequency backs off (boolean) or the backoff growth rate
67
+ * (float > 1).
68
+ *
69
+ * #### Notes
70
+ * If `true`, the default backoff growth rate is `3`.
71
+ */
72
+ readonly backoff: boolean | number;
73
+ /**
74
+ * The basic polling interval in milliseconds (integer).
75
+ */
76
+ readonly interval: number;
77
+ /**
78
+ * The maximum milliseconds (integer) between poll requests.
79
+ */
80
+ readonly max: number;
81
+ };
82
+ /**
83
+ * The phase of the poll when the current tick was scheduled.
84
+ *
85
+ * @typeparam T - A type for any additional tick phases a poll supports.
86
+ */
87
+ type Phase<T extends string> = T | 'constructed' | 'disposed' | 'reconnected' | 'refreshed' | 'rejected' | 'resolved' | 'standby' | 'started' | 'stopped';
88
+ /**
89
+ * Definition of poll state at any given time.
90
+ *
91
+ * @typeparam T - The resolved type of the factory's promises.
92
+ *
93
+ * @typeparam U - The rejected type of the factory's promises.
94
+ *
95
+ * @typeparam V - The type to extend the phases supported by a poll.
96
+ */
97
+ type State<T, U, V extends string> = {
98
+ /**
99
+ * The number of milliseconds until the current tick resolves.
100
+ */
101
+ readonly interval: number;
102
+ /**
103
+ * The payload of the last poll resolution or rejection.
104
+ *
105
+ * #### Notes
106
+ * The payload is `null` unless the `phase` is `'reconnected`, `'resolved'`,
107
+ * or `'rejected'`. Its type is `T` for resolutions and `U` for rejections.
108
+ */
109
+ readonly payload: T | U | null;
110
+ /**
111
+ * The current poll phase.
112
+ */
113
+ readonly phase: Phase<V>;
114
+ /**
115
+ * The timestamp for when this tick was scheduled.
116
+ */
117
+ readonly timestamp: number;
118
+ };
119
+ }
120
+ //# sourceMappingURL=protocol.d.ts.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C;KACtB,CAAC;IAEF;;;;OAIG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,MAAM,IAC9B,CAAC,GACD,aAAa,GACb,UAAU,GACV,aAAa,GACb,WAAW,GACX,UAAU,GACV,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,CAAC;IAEd;;;;;;;;OAQG;IACH,KAAY,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI;QAC1C;;WAEG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE1B;;;;;;WAMG;QACH,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QAE/B;;WAEG;QACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAEzB;;WAEG;QACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH"}
package/es/posix.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const join: (...args: string[]) => string;
2
+ //# sourceMappingURL=posix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posix.d.ts","sourceRoot":"","sources":["../src/posix.ts"],"names":[],"mappings":"AA0DA,eAAO,MAAM,IAAI,YAAsB,MAAM,EAAE,WAgB9C,CAAC"}