@muspellheim/shared 0.6.0 → 0.7.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.txt +1 -1
- package/README.md +11 -13
- package/dist/shared.d.ts +423 -0
- package/dist/shared.js +535 -0
- package/dist/shared.umd.cjs +1 -0
- package/package.json +27 -23
- package/.prettierignore +0 -3
- package/.prettierrc +0 -5
- package/deno.json +0 -15
- package/deno.mk +0 -68
- package/eslint.config.js +0 -23
- package/lib/assert.js +0 -15
- package/lib/browser/components.js +0 -165
- package/lib/browser/index.js +0 -3
- package/lib/color.js +0 -137
- package/lib/configurable-responses.js +0 -69
- package/lib/feature-toggle.js +0 -9
- package/lib/health.js +0 -510
- package/lib/index.js +0 -23
- package/lib/lang.js +0 -100
- package/lib/logging.js +0 -599
- package/lib/long-polling-client.js +0 -186
- package/lib/message-client.js +0 -68
- package/lib/messages.js +0 -68
- package/lib/metrics.js +0 -120
- package/lib/node/actuator-controller.js +0 -102
- package/lib/node/configuration-properties.js +0 -291
- package/lib/node/handler.js +0 -25
- package/lib/node/index.js +0 -9
- package/lib/node/logging.js +0 -60
- package/lib/node/long-polling.js +0 -83
- package/lib/node/sse-emitter.js +0 -104
- package/lib/node/static-files-controller.js +0 -15
- package/lib/output-tracker.js +0 -89
- package/lib/service-locator.js +0 -44
- package/lib/sse-client.js +0 -163
- package/lib/stop-watch.js +0 -54
- package/lib/store.js +0 -129
- package/lib/time.js +0 -445
- package/lib/util.js +0 -380
- package/lib/validation.js +0 -290
- package/lib/vector.js +0 -194
- package/lib/vitest/equality-testers.js +0 -19
- package/lib/vitest/index.js +0 -1
- package/lib/web-socket-client.js +0 -262
- package/tsconfig.json +0 -13
package/eslint.config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import globals from 'globals';
|
|
3
|
-
|
|
4
|
-
/** @type { import("eslint").Linter.FlatConfig[] } */
|
|
5
|
-
export default [
|
|
6
|
-
js.configs.recommended,
|
|
7
|
-
{
|
|
8
|
-
languageOptions: {
|
|
9
|
-
ecmaVersion: 2022,
|
|
10
|
-
globals: {
|
|
11
|
-
...globals.es2021,
|
|
12
|
-
...globals.node,
|
|
13
|
-
...globals.browser,
|
|
14
|
-
//...globals.serviceworker,
|
|
15
|
-
//...globals['shared-node-browser'],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
ignores: ['coverage/**', 'docs/**'],
|
|
19
|
-
rules: {
|
|
20
|
-
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
];
|
package/lib/assert.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-2024 Falko Schumann. All rights reserved. MIT license.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Assert that an object is not `null`.
|
|
5
|
-
*
|
|
6
|
-
* @param {*} object The object to check.
|
|
7
|
-
* @param {string|Function} message The message to throw or a function that
|
|
8
|
-
* returns the message.
|
|
9
|
-
*/
|
|
10
|
-
export function assertNotNull(object, message) {
|
|
11
|
-
if (object == null) {
|
|
12
|
-
const m = typeof message === 'function' ? message() : message;
|
|
13
|
-
throw new ReferenceError(m);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-2024 Falko Schumann. All rights reserved. MIT license.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Contains a pattern to implement custom elements with
|
|
5
|
-
* [lit-html](https://lit.dev/docs/libraries/standalone-templates/).
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @import { StateType, Store } from '../store.js'
|
|
12
|
-
* @import { TemplateResult } from 'lit-html'
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { html, render } from 'lit-html';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Base class for a custom element rendered with `lit-html`.
|
|
19
|
-
*/
|
|
20
|
-
export class Component extends HTMLElement {
|
|
21
|
-
/**
|
|
22
|
-
* Updates the view after this component is inserted into the DOM.
|
|
23
|
-
*
|
|
24
|
-
* Called when this component is inserted into the DOM. Override this method
|
|
25
|
-
* to register event listeners. Don't forget to call the super method.
|
|
26
|
-
*/
|
|
27
|
-
connectedCallback() {
|
|
28
|
-
this.updateView();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Currently does nothing.
|
|
33
|
-
*
|
|
34
|
-
* Called when this component is removed from the DOM. Override this method to
|
|
35
|
-
* remove event listeners. Don't forget to call the super method.
|
|
36
|
-
*/
|
|
37
|
-
disconnectedCallback() {}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Updates this component.
|
|
41
|
-
*
|
|
42
|
-
* Renders the view into the target element.
|
|
43
|
-
*
|
|
44
|
-
* @see module:browser/components.Component#getView
|
|
45
|
-
* @see module:browser/components.Component#getRenderTarget
|
|
46
|
-
*/
|
|
47
|
-
updateView() {
|
|
48
|
-
if (!this.isConnected) {
|
|
49
|
-
// Skip rendering, e.g. when setting properties before inserting into DOM.
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
render(this.getView(), this.getRenderTarget());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Returns the view to render when this component is updated.
|
|
58
|
-
*
|
|
59
|
-
* The view is a template created with `html` from lit-html. Override this
|
|
60
|
-
* method to return the view. The default is an empty view.
|
|
61
|
-
*
|
|
62
|
-
* @return {TemplateResult} The view.
|
|
63
|
-
*/
|
|
64
|
-
getView() {
|
|
65
|
-
return html``;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Returns the target element of this component to render the view into.
|
|
70
|
-
*
|
|
71
|
-
* The default is `this`.
|
|
72
|
-
*
|
|
73
|
-
* @return {HTMLElement|DocumentFragment} The target element.
|
|
74
|
-
*/
|
|
75
|
-
getRenderTarget() {
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Base class for custom elements that use a store.
|
|
82
|
-
*
|
|
83
|
-
* @extends {Component}
|
|
84
|
-
* @see Store
|
|
85
|
-
*/
|
|
86
|
-
export class Container extends Component {
|
|
87
|
-
/** @type {Store} */ static #store;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Initializes the store for all containers.
|
|
91
|
-
*
|
|
92
|
-
* Must be call before any container is inserted into the DOM.
|
|
93
|
-
*
|
|
94
|
-
* @param {Store} store The store to use.
|
|
95
|
-
*/
|
|
96
|
-
static initStore(store) {
|
|
97
|
-
Container.#store = store;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** @type {function(): void} */ #unsubscribeStore;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Initializes this container with an empty state `{}`.
|
|
104
|
-
*/
|
|
105
|
-
constructor() {
|
|
106
|
-
super();
|
|
107
|
-
this.state = {};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Returns the store.
|
|
112
|
-
*
|
|
113
|
-
* @type {Store}
|
|
114
|
-
*/
|
|
115
|
-
get store() {
|
|
116
|
-
return Container.#store;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Subscribes to the store and update the view when the state changes.
|
|
121
|
-
*
|
|
122
|
-
* Don't forget to call the super method when overriding this method.
|
|
123
|
-
*
|
|
124
|
-
* @override
|
|
125
|
-
*/
|
|
126
|
-
connectedCallback() {
|
|
127
|
-
this.#unsubscribeStore = this.store.subscribe(() => this.updateView());
|
|
128
|
-
super.connectedCallback();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Unsubscribes from the store.
|
|
133
|
-
*
|
|
134
|
-
* Don't forget to call the super method when overriding this method.
|
|
135
|
-
*
|
|
136
|
-
* @override
|
|
137
|
-
*/
|
|
138
|
-
disconnectedCallback() {
|
|
139
|
-
this.#unsubscribeStore();
|
|
140
|
-
super.disconnectedCallback();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Updates this container with the current state from the store before
|
|
145
|
-
* updating the view.
|
|
146
|
-
*
|
|
147
|
-
* @override
|
|
148
|
-
*/
|
|
149
|
-
updateView() {
|
|
150
|
-
this.state = this.extractState(this.store.getState());
|
|
151
|
-
super.updateView();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Extracts a subset of the state for this container.
|
|
156
|
-
*
|
|
157
|
-
* Default is the entire state.
|
|
158
|
-
*
|
|
159
|
-
* @param {StateType} state The state of the store.
|
|
160
|
-
* @return {StateType} The state for the container.
|
|
161
|
-
*/
|
|
162
|
-
extractState(state) {
|
|
163
|
-
return state;
|
|
164
|
-
}
|
|
165
|
-
}
|
package/lib/browser/index.js
DELETED
package/lib/color.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-2024 Falko Schumann. All rights reserved. MIT license.
|
|
2
|
-
|
|
3
|
-
const FACTOR = 0.7;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The Color class represents a color in the RGB color space.
|
|
7
|
-
*/
|
|
8
|
-
export class Color {
|
|
9
|
-
/**
|
|
10
|
-
* The RGB value of the color.
|
|
11
|
-
*
|
|
12
|
-
* @type {number}
|
|
13
|
-
*/
|
|
14
|
-
rgb;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates a color instance from RGB values.
|
|
18
|
-
*
|
|
19
|
-
* @param {number|string} [red] The red component or the RGB value.
|
|
20
|
-
* @param {number} [green] The green component.
|
|
21
|
-
* @param {number} [blue] The blue component.
|
|
22
|
-
*/
|
|
23
|
-
constructor(red, green, blue) {
|
|
24
|
-
if (typeof red === 'string') {
|
|
25
|
-
this.rgb = parseInt(red, 16);
|
|
26
|
-
} else if (
|
|
27
|
-
typeof red === 'number' &&
|
|
28
|
-
typeof green === 'number' &&
|
|
29
|
-
typeof blue === 'number'
|
|
30
|
-
) {
|
|
31
|
-
this.rgb =
|
|
32
|
-
((red & 0xff) << 16) | ((green & 0xff) << 8) | ((blue & 0xff) << 0);
|
|
33
|
-
} else if (typeof red === 'number') {
|
|
34
|
-
this.rgb = red;
|
|
35
|
-
} else {
|
|
36
|
-
this.rgb = NaN;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The red component of the color.
|
|
42
|
-
*
|
|
43
|
-
* @type {number}
|
|
44
|
-
*/
|
|
45
|
-
get red() {
|
|
46
|
-
return (this.rgb >> 16) & 0xff;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The green component of the color.
|
|
51
|
-
*
|
|
52
|
-
* @type {number}
|
|
53
|
-
*/
|
|
54
|
-
get green() {
|
|
55
|
-
return (this.rgb >> 8) & 0xff;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* The blue component of the color.
|
|
60
|
-
*
|
|
61
|
-
* @type {number}
|
|
62
|
-
*/
|
|
63
|
-
get blue() {
|
|
64
|
-
return (this.rgb >> 0) & 0xff;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new color that is brighter than this color.
|
|
69
|
-
*
|
|
70
|
-
* @param {number} [factor] The optional factor to brighten the color.
|
|
71
|
-
* @return {Color} The brighter color.
|
|
72
|
-
*/
|
|
73
|
-
brighter(factor = FACTOR) {
|
|
74
|
-
if (Number.isNaN(this.rgb)) {
|
|
75
|
-
return new Color();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let red = this.red;
|
|
79
|
-
let green = this.green;
|
|
80
|
-
let blue = this.blue;
|
|
81
|
-
|
|
82
|
-
const inverse = Math.floor(1 / (1 - factor));
|
|
83
|
-
if (red === 0 && green === 0 && blue === 0) {
|
|
84
|
-
return new Color(inverse, inverse, inverse);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (red > 0 && red < inverse) red = inverse;
|
|
88
|
-
if (green > 0 && green < inverse) green = inverse;
|
|
89
|
-
if (blue > 0 && blue < inverse) blue = inverse;
|
|
90
|
-
|
|
91
|
-
return new Color(
|
|
92
|
-
Math.min(Math.floor(red / FACTOR), 255),
|
|
93
|
-
Math.min(Math.floor(green / FACTOR), 255),
|
|
94
|
-
Math.min(Math.floor(blue / FACTOR), 255),
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Creates a new color that is darker than this color.
|
|
100
|
-
*
|
|
101
|
-
* @param {number} [factor] The optional factor to darken the color.
|
|
102
|
-
* @return {Color} The darker color.
|
|
103
|
-
*/
|
|
104
|
-
darker(factor = FACTOR) {
|
|
105
|
-
if (Number.isNaN(this.rgb)) {
|
|
106
|
-
return new Color();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return new Color(
|
|
110
|
-
Math.max(Math.floor(this.red * factor), 0),
|
|
111
|
-
Math.max(Math.floor(this.green * factor), 0),
|
|
112
|
-
Math.max(Math.floor(this.blue * factor), 0),
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Returns the RGB value of the color.
|
|
118
|
-
*
|
|
119
|
-
* @return {number} The RGB value of the color.
|
|
120
|
-
*/
|
|
121
|
-
valueOf() {
|
|
122
|
-
return this.rgb;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Returns the hexadecimal representation of the color.
|
|
127
|
-
*
|
|
128
|
-
* @return {string} The hexadecimal representation of the color.
|
|
129
|
-
*/
|
|
130
|
-
toString() {
|
|
131
|
-
if (Number.isNaN(this.rgb)) {
|
|
132
|
-
return 'Invalid Color';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return this.rgb.toString(16).padStart(6, '0');
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2023-2024 Falko Schumann. All rights reserved. MIT license.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Handle returning a pre-configured responses.
|
|
5
|
-
*
|
|
6
|
-
* This is one of the nullability patterns from James Shore's article on
|
|
7
|
-
* [testing without mocks](https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#configurable-responses).
|
|
8
|
-
*
|
|
9
|
-
* Example usage for stubbing `fetch` function:
|
|
10
|
-
*
|
|
11
|
-
* ```javascript
|
|
12
|
-
* function createFetchStub(responses) {
|
|
13
|
-
* const configurableResponses = ConfigurableResponses.create(responses);
|
|
14
|
-
* return async function () {
|
|
15
|
-
* const response = configurableResponses.next();
|
|
16
|
-
* return {
|
|
17
|
-
* status: response.status,
|
|
18
|
-
* json: async () => response.body,
|
|
19
|
-
* };
|
|
20
|
-
* };
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export class ConfigurableResponses {
|
|
25
|
-
/**
|
|
26
|
-
* Creates a configurable responses instance from a single response or an
|
|
27
|
-
* array of responses with an optional response name.
|
|
28
|
-
*
|
|
29
|
-
* @param {*|Array} responses A single response or an array of responses.
|
|
30
|
-
* @param {string} [name] An optional name for the responses.
|
|
31
|
-
*/
|
|
32
|
-
static create(responses, name) {
|
|
33
|
-
return new ConfigurableResponses(responses, name);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
#description;
|
|
37
|
-
#responses;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates a configurable responses instance from a single response or an
|
|
41
|
-
* array of responses with an optional response name.
|
|
42
|
-
*
|
|
43
|
-
* @param {*|Array} responses A single response or an array of responses.
|
|
44
|
-
* @param {string} [name] An optional name for the responses.
|
|
45
|
-
*/
|
|
46
|
-
constructor(/** @type {*|Array} */ responses, /** @type {?string} */ name) {
|
|
47
|
-
this.#description = name == null ? '' : ` in ${name}`;
|
|
48
|
-
this.#responses = Array.isArray(responses) ? [...responses] : responses;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Returns the next response.
|
|
53
|
-
*
|
|
54
|
-
* If there are no more responses, an error is thrown. If a single response is
|
|
55
|
-
* configured, it is always returned.
|
|
56
|
-
*
|
|
57
|
-
* @return {*} The next response.
|
|
58
|
-
*/
|
|
59
|
-
next() {
|
|
60
|
-
const response = Array.isArray(this.#responses)
|
|
61
|
-
? this.#responses.shift()
|
|
62
|
-
: this.#responses;
|
|
63
|
-
if (response === undefined) {
|
|
64
|
-
throw new Error(`No more responses configured${this.#description}.`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return response;
|
|
68
|
-
}
|
|
69
|
-
}
|