@siteimprove/alfa-hash 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-hash
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
package/dist/hash.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import type { Equatable } from "@siteimprove/alfa-equatable";
2
+ import type { JSON } from "@siteimprove/alfa-json";
3
+ import { Hashable } from "./hashable.js";
4
+ /**
5
+ * @public
6
+ */
7
+ export declare abstract class Hash implements Equatable, Hashable {
8
+ /**
9
+ * A map from objects to their hash values. Objects are weakly referenced as
10
+ * to not prevent them from being garbage collected.
11
+ */
12
+ private static _objectHashes;
13
+ /**
14
+ * A map from symbols to their hash values. As there's not currently a way to
15
+ * weakly reference symbols, we have to instead use strong references.
16
+ *
17
+ * {@link https://github.com/tc39/proposal-symbols-as-weakmap-keys}
18
+ */
19
+ private static _symbolHashes;
20
+ /**
21
+ * The next available hash value. This is used for symbols and objects that
22
+ * don't implement the {@link (Hashable:interface)} interface.
23
+ */
24
+ private static _nextHash;
25
+ protected constructor();
26
+ /**
27
+ * Get the current hash value as a 32-bit integer.
28
+ *
29
+ * @remarks
30
+ * The method is limited to 32-bit integers as this is the limit of bitwise
31
+ * operations in JavaScript.
32
+ */
33
+ abstract finish(): number;
34
+ abstract write(data: Uint8Array): this;
35
+ writeString(data: string): this;
36
+ /**
37
+ * @remarks
38
+ * As JavaScript represents numbers in double-precision floating-point format,
39
+ * numbers in general will be written as such.
40
+ *
41
+ * {@link https://en.wikipedia.org/wiki/Double-precision_floating-point_format}
42
+ */
43
+ writeNumber(data: number): this;
44
+ writeInt(data: number, size?: 8 | 16 | 32, signed?: boolean): this;
45
+ writeInt8(data: number): this;
46
+ writeUint8(data: number): this;
47
+ writeInt16(data: number): this;
48
+ writeUint16(data: number): this;
49
+ writeInt32(data: number): this;
50
+ writeUint32(data: number): this;
51
+ writeBigInt(data: bigint, size?: 64, signed?: boolean): this;
52
+ writeBigInt64(data: bigint): this;
53
+ writeBigUint64(data: bigint): this;
54
+ writeFloat(data: number, size?: 32 | 64): this;
55
+ writeFloat32(data: number): this;
56
+ writeFloat64(data: number): this;
57
+ writeBoolean(data: boolean): this;
58
+ writeUndefined(): this;
59
+ writeNull(): this;
60
+ writeObject(data: object): this;
61
+ writeSymbol(data: symbol): this;
62
+ writeHashable(data: Hashable): this;
63
+ writeUnknown(data: unknown): this;
64
+ writeJSON(data: JSON): this;
65
+ equals(value: Hash): boolean;
66
+ equals(value: unknown): value is this;
67
+ hash(hash: Hash): void;
68
+ private static _getNextHash;
69
+ }
70
+ //# sourceMappingURL=hash.d.ts.map
package/dist/hash.js ADDED
@@ -0,0 +1,209 @@
1
+ import { Encoder } from "@siteimprove/alfa-encoding";
2
+ import { Hashable } from "./hashable.js";
3
+ const { keys } = Object;
4
+ /**
5
+ * A special offset used for the builtin types `true`, `false`, `undefined`, and
6
+ * `null`. The offset is designed to minimize the chance of collisions for data
7
+ * structures that rely on 5-bit partitioning. We use the first 30 bits for 6 of
8
+ * these partitions, leaving us 2 bits to encode the 4 builtin types.
9
+ */
10
+ const builtinOffset = 0b10000_10000_10000_10000_10000_10000_00;
11
+ /**
12
+ * @public
13
+ */
14
+ export class Hash {
15
+ /**
16
+ * A map from objects to their hash values. Objects are weakly referenced as
17
+ * to not prevent them from being garbage collected.
18
+ */
19
+ static _objectHashes = new WeakMap();
20
+ /**
21
+ * A map from symbols to their hash values. As there's not currently a way to
22
+ * weakly reference symbols, we have to instead use strong references.
23
+ *
24
+ * {@link https://github.com/tc39/proposal-symbols-as-weakmap-keys}
25
+ */
26
+ static _symbolHashes = new Map();
27
+ /**
28
+ * The next available hash value. This is used for symbols and objects that
29
+ * don't implement the {@link (Hashable:interface)} interface.
30
+ */
31
+ static _nextHash = 0;
32
+ constructor() { }
33
+ writeString(data) {
34
+ return this.write(Encoder.encode(data));
35
+ }
36
+ /**
37
+ * @remarks
38
+ * As JavaScript represents numbers in double-precision floating-point format,
39
+ * numbers in general will be written as such.
40
+ *
41
+ * {@link https://en.wikipedia.org/wiki/Double-precision_floating-point_format}
42
+ */
43
+ writeNumber(data) {
44
+ return this.writeFloat64(data);
45
+ }
46
+ writeInt(data, size = 32, signed = true) {
47
+ const buffer = new ArrayBuffer(size / 8);
48
+ const view = new DataView(buffer);
49
+ switch (size) {
50
+ case 8:
51
+ signed ? view.setInt8(0, data) : view.setUint8(0, data);
52
+ break;
53
+ case 16:
54
+ signed ? view.setInt16(0, data) : view.setUint16(0, data);
55
+ break;
56
+ case 32:
57
+ signed ? view.setInt32(0, data) : view.setUint32(0, data);
58
+ }
59
+ return this.write(new Uint8Array(buffer));
60
+ }
61
+ writeInt8(data) {
62
+ return this.writeInt(data, 8, true);
63
+ }
64
+ writeUint8(data) {
65
+ return this.writeInt(data, 8, false);
66
+ }
67
+ writeInt16(data) {
68
+ return this.writeInt(data, 16, true);
69
+ }
70
+ writeUint16(data) {
71
+ return this.writeInt(data, 16, false);
72
+ }
73
+ writeInt32(data) {
74
+ return this.writeInt(data, 32, true);
75
+ }
76
+ writeUint32(data) {
77
+ return this.writeInt(data, 32, false);
78
+ }
79
+ writeBigInt(data, size = 64, signed = true) {
80
+ const buffer = new ArrayBuffer(size / 8);
81
+ const view = new DataView(buffer);
82
+ switch (size) {
83
+ case 64:
84
+ signed ? view.setBigInt64(0, data) : view.setBigUint64(0, data);
85
+ }
86
+ return this.write(new Uint8Array(buffer));
87
+ }
88
+ writeBigInt64(data) {
89
+ return this.writeBigInt(data, 64, true);
90
+ }
91
+ writeBigUint64(data) {
92
+ return this.writeBigInt(data, 64, false);
93
+ }
94
+ writeFloat(data, size = 32) {
95
+ const buffer = new ArrayBuffer(size / 8);
96
+ const view = new DataView(buffer);
97
+ switch (size) {
98
+ case 32:
99
+ view.setFloat32(0, data);
100
+ break;
101
+ case 64:
102
+ view.setFloat64(0, data);
103
+ }
104
+ return this.write(new Uint8Array(buffer));
105
+ }
106
+ writeFloat32(data) {
107
+ return this.writeFloat(data, 32);
108
+ }
109
+ writeFloat64(data) {
110
+ return this.writeFloat(data, 64);
111
+ }
112
+ writeBoolean(data) {
113
+ return this.writeUint8(builtinOffset + (data ? 1 : 0));
114
+ }
115
+ writeUndefined() {
116
+ return this.writeUint32(builtinOffset + 2);
117
+ }
118
+ writeNull() {
119
+ return this.writeUint32(builtinOffset + 3);
120
+ }
121
+ writeObject(data) {
122
+ let hash = Hash._objectHashes.get(data);
123
+ if (hash === undefined) {
124
+ hash = Hash._getNextHash();
125
+ Hash._objectHashes.set(data, hash);
126
+ }
127
+ return this.writeUint32(hash);
128
+ }
129
+ writeSymbol(data) {
130
+ let hash = Hash._symbolHashes.get(data);
131
+ if (hash === undefined) {
132
+ hash = Hash._getNextHash();
133
+ Hash._symbolHashes.set(data, hash);
134
+ }
135
+ return this.writeUint32(hash);
136
+ }
137
+ writeHashable(data) {
138
+ data.hash(this);
139
+ return this;
140
+ }
141
+ writeUnknown(data) {
142
+ switch (typeof data) {
143
+ case "string":
144
+ return this.writeString(data);
145
+ case "number":
146
+ return this.writeNumber(data);
147
+ case "bigint":
148
+ return this.writeBigInt(data);
149
+ case "boolean":
150
+ return this.writeBoolean(data);
151
+ case "symbol":
152
+ return this.writeSymbol(data);
153
+ case "undefined":
154
+ return this.writeUndefined();
155
+ case "object":
156
+ if (data === null) {
157
+ return this.writeNull();
158
+ }
159
+ if (Hashable.isHashable(data)) {
160
+ return this.writeHashable(data);
161
+ }
162
+ return this.writeObject(data);
163
+ case "function":
164
+ return this.writeObject(data);
165
+ }
166
+ }
167
+ writeJSON(data) {
168
+ switch (typeof data) {
169
+ case "string":
170
+ return this.writeString(data);
171
+ case "number":
172
+ return this.writeNumber(data);
173
+ case "boolean":
174
+ return this.writeBoolean(data);
175
+ case "object":
176
+ if (Array.isArray(data)) {
177
+ for (let i = 0, n = data.length; i < n; i++) {
178
+ this.writeJSON(data[i]);
179
+ }
180
+ this.writeUint32(data.length);
181
+ }
182
+ else if (data !== null) {
183
+ for (const key of keys(data).sort()) {
184
+ const value = data[key];
185
+ this.writeString(key);
186
+ if (value !== undefined) {
187
+ this.writeJSON(value);
188
+ }
189
+ // Write a null byte as a separator between key/value pairs.
190
+ this.writeUint8(0);
191
+ }
192
+ }
193
+ return this;
194
+ }
195
+ }
196
+ equals(value) {
197
+ return value instanceof Hash && value.finish() === this.finish();
198
+ }
199
+ hash(hash) {
200
+ hash.writeUint32(this.finish());
201
+ }
202
+ static _getNextHash() {
203
+ const nextHash = Hash._nextHash;
204
+ // Increase the hash, wrapping around when it reaches the limit of 32 bits.
205
+ Hash._nextHash = (Hash._nextHash + 1) >>> 0;
206
+ return nextHash;
207
+ }
208
+ }
209
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1,14 @@
1
+ import type { Hash } from "./hash.js";
2
+ /**
3
+ * @public
4
+ */
5
+ export interface Hashable {
6
+ hash(hash: Hash): void;
7
+ }
8
+ /**
9
+ * @public
10
+ */
11
+ export declare namespace Hashable {
12
+ function isHashable(value: unknown): value is Hashable;
13
+ }
14
+ //# sourceMappingURL=hashable.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { Refinement } from "@siteimprove/alfa-refinement";
2
+ const { isFunction, isObject } = Refinement;
3
+ /**
4
+ * @public
5
+ */
6
+ export var Hashable;
7
+ (function (Hashable) {
8
+ function isHashable(value) {
9
+ return isObject(value) && isFunction(value.hash);
10
+ }
11
+ Hashable.isHashable = isHashable;
12
+ })(Hashable || (Hashable = {}));
13
+ //# sourceMappingURL=hashable.js.map
@@ -0,0 +1,3 @@
1
+ export * from "./hash.js";
2
+ export * from "./hashable.js";
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./hash.js";
2
+ export * from "./hashable.js";
3
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "http://json.schemastore.org/package",
3
+ "name": "@siteimprove/alfa-hash",
4
+ "homepage": "https://alfa.siteimprove.com",
5
+ "version": "0.89.5",
6
+ "license": "MIT",
7
+ "description": "Types for modelling structures that support hashing",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "github:Siteimprove/alfa",
11
+ "directory": "packages/alfa-hash"
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-encoding": "^0.89.5",
26
+ "@siteimprove/alfa-equatable": "^0.89.5",
27
+ "@siteimprove/alfa-json": "^0.89.5",
28
+ "@siteimprove/alfa-refinement": "^0.89.5"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://npm.pkg.github.com/"
33
+ }
34
+ }