@siteimprove/alfa-network 0.89.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,151 @@
1
+ # @siteimprove/alfa-network
2
+
3
+ ## 0.89.3
4
+
5
+ ## 0.89.2
6
+
7
+ ### Patch Changes
8
+
9
+ - **Changed:** Trying to fix a problem in generating provenance statements ([#1674](https://github.com/Siteimprove/alfa/pull/1674))
10
+
11
+ ## 0.89.1
12
+
13
+ ### Patch Changes
14
+
15
+ - **Added:** Trying to publish Alfa packages on the npm registry ([#1673](https://github.com/Siteimprove/alfa/pull/1673))
16
+
17
+ ## 0.89.0
18
+
19
+ ## 0.88.0
20
+
21
+ ### Minor Changes
22
+
23
+ - **Fixed:** The publish flow was updated to a new version. ([`a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2`](https://github.com/Siteimprove/alfa/commit/a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2))
24
+
25
+ Some 0.87.\* versions were generating uninstallable package. This should be fixed now.
26
+
27
+ ## 0.87.12
28
+
29
+ ## 0.87.11
30
+
31
+ ## 0.87.10
32
+
33
+ ## 0.87.7
34
+
35
+ ## 0.87.6
36
+
37
+ ## 0.87.5
38
+
39
+ ## 0.87.4
40
+
41
+ ## 0.87.3
42
+
43
+ ## 0.87.2
44
+
45
+ ## 0.87.1
46
+
47
+ ## 0.87.0
48
+
49
+ ## 0.86.2
50
+
51
+ ## 0.86.1
52
+
53
+ ## 0.86.0
54
+
55
+ ### Minor Changes
56
+
57
+ - **Breaking:** TS resolution has been changed to `Node16`, target to `es2022`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
58
+
59
+ - **Breaking:** Alfa is now distributed as ESM rather than CJS modules; projects using it must be ESM or use dynamic `import()`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
60
+
61
+ ⚠️ This is the last of a series of changes on the internal structure and build process of distributed packages that was started with v0.85.0.
62
+
63
+ ## 0.85.1
64
+
65
+ ## 0.85.0
66
+
67
+ ### Minor Changes
68
+
69
+ - **Breaking:** The .js files are now built in the `dist` folder rather than in `src`. ([#1628](https://github.com/Siteimprove/alfa/pull/1628))
70
+
71
+ ⚠️ This is the first of a series of changes on the internal structure and build process of distributed packages. It is probably better to not use this version and wait until more of these internal changes have been done to jump directly to the final result. We are internally releasing these changes for validation purpose only.
72
+
73
+ This should not impact consumers, the `package.json` files should be set correctly to consume these files.
74
+
75
+ ## 0.84.0
76
+
77
+ ## 0.83.1
78
+
79
+ ## 0.83.0
80
+
81
+ ## 0.82.0
82
+
83
+ ### Minor Changes
84
+
85
+ - **Breaking:** Node 18 is no longer supported. ([#1618](https://github.com/Siteimprove/alfa/pull/1618))
86
+
87
+ ## 0.81.0
88
+
89
+ ### Patch Changes
90
+
91
+ - **Added:** Each package now contains its internal dependency graph in its `docs` directory. ([#1610](https://github.com/Siteimprove/alfa/pull/1610))
92
+
93
+ ## 0.80.0
94
+
95
+ ## 0.79.1
96
+
97
+ ## 0.79.0
98
+
99
+ ## 0.78.2
100
+
101
+ ## 0.78.1
102
+
103
+ ## 0.78.0
104
+
105
+ ## 0.77.0
106
+
107
+ ## 0.76.0
108
+
109
+ ## 0.75.2
110
+
111
+ ## 0.75.1
112
+
113
+ ## 0.75.0
114
+
115
+ ## 0.74.0
116
+
117
+ ## 0.73.0
118
+
119
+ ## 0.72.0
120
+
121
+ ## 0.71.1
122
+
123
+ ## 0.71.0
124
+
125
+ ## 0.70.0
126
+
127
+ ## 0.69.0
128
+
129
+ ## 0.68.0
130
+
131
+ ## 0.67.0
132
+
133
+ ## 0.66.0
134
+
135
+ ## 0.65.1
136
+
137
+ ## 0.65.0
138
+
139
+ ## 0.64.0
140
+
141
+ ## 0.63.3
142
+
143
+ ## 0.63.2
144
+
145
+ ## 0.63.1
146
+
147
+ ## 0.63.0
148
+
149
+ ## 0.62.2
150
+
151
+ ## 0.62.1
@@ -0,0 +1,2 @@
1
+ export * from "./network.js";
2
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./network.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,66 @@
1
+ import type { Equatable } from "@siteimprove/alfa-equatable";
2
+ import { Graph } from "@siteimprove/alfa-graph";
3
+ import type { Hashable, Hash } from "@siteimprove/alfa-hash";
4
+ import { Iterable } from "@siteimprove/alfa-iterable";
5
+ import { Serializable } from "@siteimprove/alfa-json";
6
+ import { Map } from "@siteimprove/alfa-map";
7
+ import { Sequence } from "@siteimprove/alfa-sequence";
8
+ import { Set } from "@siteimprove/alfa-set";
9
+ /**
10
+ * @public
11
+ */
12
+ export declare class Network<N, E> implements Iterable<[N, Iterable<[N, Iterable<E>]>]>, Equatable, Hashable, Serializable<Network.JSON<N, E>> {
13
+ static of<N, E>(nodes: Map<N, Map<N, Set<E>>>): Network<N, E>;
14
+ private static _empty;
15
+ static empty<N, E>(): Network<N, E>;
16
+ private readonly _nodes;
17
+ private constructor();
18
+ get size(): number;
19
+ isEmpty(): this is Network<N, never>;
20
+ nodes(): Iterable<N>;
21
+ neighbors(node: N): Iterable<[N, Iterable<E>]>;
22
+ edges(from: N, to: N): Iterable<E>;
23
+ has(node: N): boolean;
24
+ add(node: N): Network<N, E>;
25
+ delete(node: N): Network<N, E>;
26
+ connect(from: N, to: N, ...edges: Array<E>): Network<N, E>;
27
+ disconnect(from: N, to: N, ...edges: Array<E>): Network<N, E>;
28
+ traverse(root: N, traversal?: Network.Traversal): Sequence<[node: N, edges: Iterable<E>, parent: N]>;
29
+ path(from: N, to: N, traversal?: Network.Traversal): Sequence<[node: N, edges: Iterable<E>]>;
30
+ hasPath(from: N, to: N): boolean;
31
+ reverse(): Network<N, E>;
32
+ sort(): Iterable<N>;
33
+ equals<N, E>(value: Network<N, E>): boolean;
34
+ equals(value: unknown): value is this;
35
+ hash(hash: Hash): void;
36
+ iterator(): Iterator<[N, Iterable<[N, Iterable<E>]>]>;
37
+ [Symbol.iterator](): Iterator<[N, Iterable<[N, Iterable<E>]>]>;
38
+ toArray(): Array<[N, Array<[N, Array<E>]>]>;
39
+ toGraph(): Graph<N>;
40
+ toJSON(): Network.JSON<N, E>;
41
+ toString(): string;
42
+ }
43
+ /**
44
+ * @public
45
+ */
46
+ export declare namespace Network {
47
+ type JSON<N, E> = Array<[
48
+ Serializable.ToJSON<N>,
49
+ Array<[Serializable.ToJSON<N>, Array<Serializable.ToJSON<E>>]>
50
+ ]>;
51
+ function isNetwork<N, E>(value: Iterable<readonly [N, Iterable<readonly [N, Iterable<E>]>]>): value is Network<N, E>;
52
+ function isNetwork<N, E>(value: unknown): value is Network<N, E>;
53
+ function from<N, E>(iterable: Iterable<readonly [N, Iterable<readonly [N, Iterable<E>]>]>): Network<N, E>;
54
+ interface Traversal {
55
+ <N, E>(network: Network<N, E>, root: N): Iterable<[node: N, edges: Iterable<E>, parent: N]>;
56
+ }
57
+ /**
58
+ * {@link https://en.wikipedia.org/wiki/Depth-first_search}
59
+ */
60
+ const DepthFirst: Traversal;
61
+ /**
62
+ * {@link https://en.wikipedia.org/wiki/Breadth-first_search}
63
+ */
64
+ const BreadthFirst: Traversal;
65
+ }
66
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1,263 @@
1
+ import { Graph } from "@siteimprove/alfa-graph";
2
+ import { Iterable } from "@siteimprove/alfa-iterable";
3
+ import { Serializable } from "@siteimprove/alfa-json";
4
+ import { Map } from "@siteimprove/alfa-map";
5
+ import { Sequence } from "@siteimprove/alfa-sequence";
6
+ import { Set } from "@siteimprove/alfa-set";
7
+ /**
8
+ * @public
9
+ */
10
+ export class Network {
11
+ static of(nodes) {
12
+ return new Network(nodes);
13
+ }
14
+ static _empty = new Network(Map.empty());
15
+ static empty() {
16
+ return this._empty;
17
+ }
18
+ _nodes;
19
+ constructor(nodes) {
20
+ this._nodes = nodes;
21
+ }
22
+ get size() {
23
+ return this._nodes.size;
24
+ }
25
+ isEmpty() {
26
+ return this._nodes.isEmpty();
27
+ }
28
+ nodes() {
29
+ return this._nodes.keys();
30
+ }
31
+ neighbors(node) {
32
+ return this._nodes.get(node).getOr([]);
33
+ }
34
+ edges(from, to) {
35
+ return this._nodes
36
+ .get(from)
37
+ .flatMap((neighbors) => neighbors.get(to))
38
+ .getOr([]);
39
+ }
40
+ has(node) {
41
+ return this._nodes.has(node);
42
+ }
43
+ add(node) {
44
+ if (this.has(node)) {
45
+ return this;
46
+ }
47
+ return new Network(this._nodes.set(node, Map.empty()));
48
+ }
49
+ delete(node) {
50
+ const nodes = this._nodes;
51
+ if (!nodes.has(node)) {
52
+ return this;
53
+ }
54
+ return new Network(nodes.delete(node).map((neighbors) => neighbors.delete(node)));
55
+ }
56
+ connect(from, to, ...edges) {
57
+ if (edges.length === 0) {
58
+ return this;
59
+ }
60
+ let nodes = this._nodes;
61
+ if (!nodes.has(from)) {
62
+ nodes = nodes.set(from, Map.empty());
63
+ }
64
+ if (!nodes.has(to)) {
65
+ nodes = nodes.set(to, Map.empty());
66
+ }
67
+ return new Network(nodes.set(from, nodes
68
+ .get(from)
69
+ .map((from) => from.set(to, from
70
+ .get(to)
71
+ .map((existing) => edges.reduce((edges, edge) => edges.add(edge), existing))
72
+ .getOrElse(() => Set.from(edges))))
73
+ // The presence of from is guaranteed by the second test.
74
+ .getUnsafe()));
75
+ }
76
+ disconnect(from, to, ...edges) {
77
+ if (!this.has(from) || !this.has(to)) {
78
+ return this;
79
+ }
80
+ const nodes = this._nodes;
81
+ return new Network(nodes.set(from, nodes
82
+ .get(from)
83
+ .map((from) => {
84
+ if (edges.length === 0) {
85
+ return from.delete(to);
86
+ }
87
+ for (let existing of from.get(to)) {
88
+ existing = edges.reduce((edges, edge) => edges.delete(edge), existing);
89
+ if (existing.size === 0) {
90
+ return from.delete(to);
91
+ }
92
+ return from.set(to, existing);
93
+ }
94
+ return from;
95
+ })
96
+ // The presence of from is guaranteed by the initial test.
97
+ .getUnsafe()));
98
+ }
99
+ traverse(root, traversal = Network.DepthFirst) {
100
+ return Sequence.from(traversal(this, root));
101
+ }
102
+ path(from, to, traversal = Network.BreadthFirst) {
103
+ const parents = Map.from(Iterable.map(traversal(this, from), ([node, edges, parent]) => [
104
+ node,
105
+ [edges, parent],
106
+ ]));
107
+ const path = [];
108
+ while (parents.has(to)) {
109
+ // The presence of to is guaranteed by the loop condition.
110
+ const [edges, parent] = parents.get(to).getUnsafe();
111
+ path.unshift([to, edges]);
112
+ to = parent;
113
+ }
114
+ return Sequence.from(path);
115
+ }
116
+ hasPath(from, to) {
117
+ if (!this.has(from) || !this.has(to)) {
118
+ return false;
119
+ }
120
+ return this.traverse(from)
121
+ .map(([node]) => node)
122
+ .includes(to);
123
+ }
124
+ reverse() {
125
+ let reversed = Network.empty();
126
+ for (const [node, neighbors] of this._nodes) {
127
+ reversed = reversed.add(node);
128
+ for (const [neighbor, edges] of neighbors) {
129
+ reversed = reversed.connect(neighbor, node, ...edges);
130
+ }
131
+ }
132
+ return reversed;
133
+ }
134
+ *sort() {
135
+ let incoming = this.reverse();
136
+ const queue = incoming
137
+ .toArray()
138
+ .filter(([, edges]) => edges.length === 0)
139
+ .map(([node]) => node);
140
+ while (queue.length > 0) {
141
+ const next = queue.shift();
142
+ yield next;
143
+ for (const [neighbor] of this.neighbors(next)) {
144
+ incoming = incoming.disconnect(neighbor, next);
145
+ if (Iterable.isEmpty(incoming.neighbors(neighbor))) {
146
+ queue.push(neighbor);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ equals(value) {
152
+ return value instanceof Network && value._nodes.equals(this._nodes);
153
+ }
154
+ hash(hash) {
155
+ hash.writeHashable(this._nodes);
156
+ }
157
+ *iterator() {
158
+ yield* this._nodes;
159
+ }
160
+ [Symbol.iterator]() {
161
+ return this.iterator();
162
+ }
163
+ toArray() {
164
+ return [...this].map(([node, neighbors]) => [
165
+ node,
166
+ [...neighbors].map(([node, edges]) => [node, [...edges]]),
167
+ ]);
168
+ }
169
+ toGraph() {
170
+ return Graph.from(Iterable.map(this, ([node, neighbors]) => [
171
+ node,
172
+ Iterable.map(neighbors, ([node]) => node),
173
+ ]));
174
+ }
175
+ toJSON() {
176
+ return this.toArray().map(([node, neighbors]) => [
177
+ Serializable.toJSON(node),
178
+ neighbors.map(([node, edges]) => [
179
+ Serializable.toJSON(node),
180
+ edges.map((edge) => Serializable.toJSON(edge)),
181
+ ]),
182
+ ]);
183
+ }
184
+ toString() {
185
+ const entries = this.toArray()
186
+ .map(([node, neighbors]) => {
187
+ const entries = neighbors
188
+ .map(([node, edges]) => {
189
+ const entries = edges.join(", ");
190
+ return `${node}${entries === "" ? "" : ` (${entries})`}`;
191
+ })
192
+ .join(", ");
193
+ return `${node}${entries === "" ? "" : ` => [ ${entries} ]`}`;
194
+ })
195
+ .join(", ");
196
+ return `Network {${entries === "" ? "" : ` ${entries} `}}`;
197
+ }
198
+ }
199
+ /**
200
+ * @public
201
+ */
202
+ (function (Network) {
203
+ function isNetwork(value) {
204
+ return value instanceof Network;
205
+ }
206
+ Network.isNetwork = isNetwork;
207
+ function from(iterable) {
208
+ if (isNetwork(iterable)) {
209
+ return iterable;
210
+ }
211
+ return Network.of(Map.from(Iterable.map(iterable, ([node, neighbors]) => [
212
+ node,
213
+ Map.from(Iterable.flatMap(neighbors, function* ([node, edges]) {
214
+ const set = Set.from(edges);
215
+ if (set.size > 0) {
216
+ yield [node, set];
217
+ }
218
+ })),
219
+ ])));
220
+ }
221
+ Network.from = from;
222
+ /**
223
+ * {@link https://en.wikipedia.org/wiki/Depth-first_search}
224
+ */
225
+ Network.DepthFirst = function* (graph, root) {
226
+ const stack = [
227
+ ...graph.neighbors(root),
228
+ ].map((node) => [...node, root]);
229
+ let seen = Set.of(root);
230
+ while (stack.length > 0) {
231
+ const next = stack.pop();
232
+ if (seen.has(next[0])) {
233
+ continue;
234
+ }
235
+ yield next;
236
+ seen = seen.add(next[0]);
237
+ for (const neighbor of graph.neighbors(next[0])) {
238
+ stack.push([...neighbor, next[0]]);
239
+ }
240
+ }
241
+ };
242
+ /**
243
+ * {@link https://en.wikipedia.org/wiki/Breadth-first_search}
244
+ */
245
+ Network.BreadthFirst = function* (graph, root) {
246
+ const queue = [
247
+ ...graph.neighbors(root),
248
+ ].map((node) => [...node, root]);
249
+ let seen = Set.of(root, ...[...graph.neighbors(root)].map(([node]) => node));
250
+ while (queue.length > 0) {
251
+ const next = queue.shift();
252
+ yield next;
253
+ for (const neighbor of graph.neighbors(next[0])) {
254
+ if (seen.has(neighbor[0])) {
255
+ continue;
256
+ }
257
+ seen = seen.add(neighbor[0]);
258
+ queue.push([...neighbor, next[0]]);
259
+ }
260
+ }
261
+ };
262
+ })(Network || (Network = {}));
263
+ //# sourceMappingURL=network.js.map
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "$schema": "http://json.schemastore.org/package",
3
+ "name": "@siteimprove/alfa-network",
4
+ "homepage": "https://alfa.siteimprove.com",
5
+ "version": "0.89.5",
6
+ "license": "MIT",
7
+ "description": "An implementation of an immutable, directed graph that allows for multiple, unique edges",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "github:Siteimprove/alfa",
11
+ "directory": "packages/alfa-network"
12
+ },
13
+ "bugs": "https://github.com/siteimprove/alfa/issues",
14
+ "engines": {
15
+ "node": ">=20.0.0"
16
+ },
17
+ "type": "module",
18
+ "main": "dist/index.js",
19
+ "types": "dist/index.d.ts",
20
+ "files": [
21
+ "dist/**/*.js",
22
+ "dist/**/*.d.ts"
23
+ ],
24
+ "dependencies": {
25
+ "@siteimprove/alfa-equatable": "^0.89.5",
26
+ "@siteimprove/alfa-graph": "^0.89.5",
27
+ "@siteimprove/alfa-hash": "^0.89.5",
28
+ "@siteimprove/alfa-iterable": "^0.89.5",
29
+ "@siteimprove/alfa-json": "^0.89.5",
30
+ "@siteimprove/alfa-map": "^0.89.5",
31
+ "@siteimprove/alfa-sequence": "^0.89.5",
32
+ "@siteimprove/alfa-set": "^0.89.5"
33
+ },
34
+ "devDependencies": {
35
+ "@siteimprove/alfa-test": "^0.89.5"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://npm.pkg.github.com/"
40
+ }
41
+ }