@localness/contract 0.1.1 → 0.2.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/dist/rules.d.mts +21 -0
- package/dist/rules.mjs +645 -0
- package/package.json +7 -1
package/dist/rules.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rules a client must apply the same way the server does. A draft key is named
|
|
3
|
+
* after the text it was created from, so a plugin and the server that disagree
|
|
4
|
+
* on `fpTranslation` mint two keys for one sentence. Pure functions only; a
|
|
5
|
+
* change in behaviour here is a breaking change of the package.
|
|
6
|
+
*/
|
|
7
|
+
type RowId = string | number;
|
|
8
|
+
/** Whitespace is not part of the sentence: `'Save\n As'` and `'SaveAs'` collide on purpose. */
|
|
9
|
+
export declare const fpTranslation: (text: string) => string;
|
|
10
|
+
/** Keys that only carry a text's fingerprint, awaiting a real name. */
|
|
11
|
+
export declare const DRAFT_KEY_PREFIX = "__draft_";
|
|
12
|
+
/** What a person sees for a key: a draft key's fingerprint is cut to five characters. */
|
|
13
|
+
export declare function formatI18nKeyDisplay(key: string | null | undefined): string;
|
|
14
|
+
/**
|
|
15
|
+
* Which release the workspace is looking at: `'all'`, `'unassigned'`, or one
|
|
16
|
+
* release's id. The client twin of the server's `ReleaseFilter`.
|
|
17
|
+
*/
|
|
18
|
+
export type ReleaseFilterValue = 'all' | 'unassigned' | number;
|
|
19
|
+
/** Ids are compared as strings: a row's ids come back from JSON while a picker emits numbers. */
|
|
20
|
+
export declare function entryMatchesReleaseFilter(releaseIds: RowId[] | undefined, filter: ReleaseFilterValue): boolean;
|
|
21
|
+
export {};
|
package/dist/rules.mjs
ADDED
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
// ../../shared/contract/rules.ts
|
|
24
|
+
var import_spark_md5 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
25
|
+
(function(factory) {
|
|
26
|
+
if (typeof exports === "object") module.exports = factory();
|
|
27
|
+
else if (typeof define === "function" && define.amd) define(factory);
|
|
28
|
+
else {
|
|
29
|
+
var glob;
|
|
30
|
+
try {
|
|
31
|
+
glob = window;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
glob = self;
|
|
34
|
+
}
|
|
35
|
+
glob.SparkMD5 = factory();
|
|
36
|
+
}
|
|
37
|
+
})(function(undefined) {
|
|
38
|
+
"use strict";
|
|
39
|
+
var hex_chr = [
|
|
40
|
+
"0",
|
|
41
|
+
"1",
|
|
42
|
+
"2",
|
|
43
|
+
"3",
|
|
44
|
+
"4",
|
|
45
|
+
"5",
|
|
46
|
+
"6",
|
|
47
|
+
"7",
|
|
48
|
+
"8",
|
|
49
|
+
"9",
|
|
50
|
+
"a",
|
|
51
|
+
"b",
|
|
52
|
+
"c",
|
|
53
|
+
"d",
|
|
54
|
+
"e",
|
|
55
|
+
"f"
|
|
56
|
+
];
|
|
57
|
+
function md5cycle(x, k) {
|
|
58
|
+
var a = x[0], b = x[1], c = x[2], d = x[3];
|
|
59
|
+
a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
|
60
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
|
61
|
+
d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
|
62
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
|
63
|
+
c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
|
64
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
|
65
|
+
b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
|
66
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
|
67
|
+
a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
|
68
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
|
69
|
+
d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
|
70
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
|
71
|
+
c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
|
72
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
|
73
|
+
b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
|
74
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
|
75
|
+
a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
|
76
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
|
77
|
+
d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
|
78
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
|
79
|
+
c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
|
80
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
|
81
|
+
b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
|
82
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
|
83
|
+
a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
|
84
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
|
85
|
+
d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
|
86
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
|
87
|
+
c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
|
88
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
|
89
|
+
b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
|
90
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
|
91
|
+
a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
|
92
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
|
93
|
+
d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
|
94
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
|
95
|
+
c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
|
96
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
|
97
|
+
b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
|
98
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
|
99
|
+
a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
|
100
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
|
101
|
+
d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
|
102
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
|
103
|
+
c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
|
104
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
|
105
|
+
b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
|
106
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
|
107
|
+
a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
|
108
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
|
109
|
+
d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
|
110
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
|
111
|
+
c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
|
112
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
|
113
|
+
b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
|
114
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
|
115
|
+
a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
|
116
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
|
117
|
+
d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
|
118
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
|
119
|
+
c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
|
120
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
|
121
|
+
b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
|
122
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
|
123
|
+
a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
|
124
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
|
125
|
+
d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
|
126
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
|
127
|
+
c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
|
128
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
|
129
|
+
b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
|
130
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
|
131
|
+
a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
|
132
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
|
133
|
+
d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
|
134
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
|
135
|
+
c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
|
136
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
|
137
|
+
b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
|
138
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
|
139
|
+
a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
|
140
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
|
141
|
+
d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
|
142
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
|
143
|
+
c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
|
144
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
|
145
|
+
b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
|
146
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
|
147
|
+
a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
|
148
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
|
149
|
+
d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
|
150
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
|
151
|
+
c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
|
152
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
|
153
|
+
b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
|
154
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
|
155
|
+
a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
|
156
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
|
157
|
+
d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
|
158
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
|
159
|
+
c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
|
160
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
|
161
|
+
b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
|
162
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
|
163
|
+
a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
|
164
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
|
165
|
+
d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
|
166
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
|
167
|
+
c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
|
168
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
|
169
|
+
b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
|
170
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
|
171
|
+
a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
|
172
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
|
173
|
+
d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
|
174
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
|
175
|
+
c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
|
176
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
|
177
|
+
b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
|
178
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
|
179
|
+
a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
|
180
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
|
181
|
+
d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
|
182
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
|
183
|
+
c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
|
184
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
|
185
|
+
b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
|
186
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
|
187
|
+
x[0] = a + x[0] | 0;
|
|
188
|
+
x[1] = b + x[1] | 0;
|
|
189
|
+
x[2] = c + x[2] | 0;
|
|
190
|
+
x[3] = d + x[3] | 0;
|
|
191
|
+
}
|
|
192
|
+
function md5blk(s) {
|
|
193
|
+
var md5blks = [], i = 0;
|
|
194
|
+
for (; i < 64; i += 4) md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
|
|
195
|
+
return md5blks;
|
|
196
|
+
}
|
|
197
|
+
function md5blk_array(a) {
|
|
198
|
+
var md5blks = [], i = 0;
|
|
199
|
+
for (; i < 64; i += 4) md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
|
|
200
|
+
return md5blks;
|
|
201
|
+
}
|
|
202
|
+
function md51(s) {
|
|
203
|
+
var n = s.length, state = [
|
|
204
|
+
1732584193,
|
|
205
|
+
-271733879,
|
|
206
|
+
-1732584194,
|
|
207
|
+
271733878
|
|
208
|
+
], i = 64, length, tail, tmp, lo, hi;
|
|
209
|
+
for (; i <= n; i += 64) md5cycle(state, md5blk(s.substring(i - 64, i)));
|
|
210
|
+
s = s.substring(i - 64);
|
|
211
|
+
length = s.length;
|
|
212
|
+
tail = [
|
|
213
|
+
0,
|
|
214
|
+
0,
|
|
215
|
+
0,
|
|
216
|
+
0,
|
|
217
|
+
0,
|
|
218
|
+
0,
|
|
219
|
+
0,
|
|
220
|
+
0,
|
|
221
|
+
0,
|
|
222
|
+
0,
|
|
223
|
+
0,
|
|
224
|
+
0,
|
|
225
|
+
0,
|
|
226
|
+
0,
|
|
227
|
+
0,
|
|
228
|
+
0
|
|
229
|
+
];
|
|
230
|
+
for (i = 0; i < length; i += 1) tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);
|
|
231
|
+
tail[i >> 2] |= 128 << (i % 4 << 3);
|
|
232
|
+
if (i > 55) {
|
|
233
|
+
md5cycle(state, tail);
|
|
234
|
+
for (i = 0; i < 16; i += 1) tail[i] = 0;
|
|
235
|
+
}
|
|
236
|
+
tmp = n * 8;
|
|
237
|
+
tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
|
238
|
+
lo = parseInt(tmp[2], 16);
|
|
239
|
+
hi = parseInt(tmp[1], 16) || 0;
|
|
240
|
+
tail[14] = lo;
|
|
241
|
+
tail[15] = hi;
|
|
242
|
+
md5cycle(state, tail);
|
|
243
|
+
return state;
|
|
244
|
+
}
|
|
245
|
+
function md51_array(a) {
|
|
246
|
+
var n = a.length, state = [
|
|
247
|
+
1732584193,
|
|
248
|
+
-271733879,
|
|
249
|
+
-1732584194,
|
|
250
|
+
271733878
|
|
251
|
+
], i = 64, length, tail, tmp, lo, hi;
|
|
252
|
+
for (; i <= n; i += 64) md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
|
|
253
|
+
a = i - 64 < n ? a.subarray(i - 64) : /* @__PURE__ */ new Uint8Array(0);
|
|
254
|
+
length = a.length;
|
|
255
|
+
tail = [
|
|
256
|
+
0,
|
|
257
|
+
0,
|
|
258
|
+
0,
|
|
259
|
+
0,
|
|
260
|
+
0,
|
|
261
|
+
0,
|
|
262
|
+
0,
|
|
263
|
+
0,
|
|
264
|
+
0,
|
|
265
|
+
0,
|
|
266
|
+
0,
|
|
267
|
+
0,
|
|
268
|
+
0,
|
|
269
|
+
0,
|
|
270
|
+
0,
|
|
271
|
+
0
|
|
272
|
+
];
|
|
273
|
+
for (i = 0; i < length; i += 1) tail[i >> 2] |= a[i] << (i % 4 << 3);
|
|
274
|
+
tail[i >> 2] |= 128 << (i % 4 << 3);
|
|
275
|
+
if (i > 55) {
|
|
276
|
+
md5cycle(state, tail);
|
|
277
|
+
for (i = 0; i < 16; i += 1) tail[i] = 0;
|
|
278
|
+
}
|
|
279
|
+
tmp = n * 8;
|
|
280
|
+
tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
|
281
|
+
lo = parseInt(tmp[2], 16);
|
|
282
|
+
hi = parseInt(tmp[1], 16) || 0;
|
|
283
|
+
tail[14] = lo;
|
|
284
|
+
tail[15] = hi;
|
|
285
|
+
md5cycle(state, tail);
|
|
286
|
+
return state;
|
|
287
|
+
}
|
|
288
|
+
function rhex(n) {
|
|
289
|
+
var s = "", j = 0;
|
|
290
|
+
for (; j < 4; j += 1) s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];
|
|
291
|
+
return s;
|
|
292
|
+
}
|
|
293
|
+
function hex(x) {
|
|
294
|
+
var i = 0;
|
|
295
|
+
for (; i < x.length; i += 1) x[i] = rhex(x[i]);
|
|
296
|
+
return x.join("");
|
|
297
|
+
}
|
|
298
|
+
if (hex(md51("hello")) !== "5d41402abc4b2a76b9719d911017c592");
|
|
299
|
+
/**
|
|
300
|
+
* ArrayBuffer slice polyfill.
|
|
301
|
+
*
|
|
302
|
+
* @see https://github.com/ttaubert/node-arraybuffer-slice
|
|
303
|
+
*/
|
|
304
|
+
if (typeof ArrayBuffer !== "undefined" && !ArrayBuffer.prototype.slice) (function() {
|
|
305
|
+
function clamp(val, length) {
|
|
306
|
+
val = val | 0 || 0;
|
|
307
|
+
if (val < 0) return Math.max(val + length, 0);
|
|
308
|
+
return Math.min(val, length);
|
|
309
|
+
}
|
|
310
|
+
ArrayBuffer.prototype.slice = function(from, to) {
|
|
311
|
+
var length = this.byteLength, begin = clamp(from, length), end = length, num, target, targetArray, sourceArray;
|
|
312
|
+
if (to !== undefined) end = clamp(to, length);
|
|
313
|
+
if (begin > end) return /* @__PURE__ */ new ArrayBuffer(0);
|
|
314
|
+
num = end - begin;
|
|
315
|
+
target = new ArrayBuffer(num);
|
|
316
|
+
targetArray = new Uint8Array(target);
|
|
317
|
+
sourceArray = new Uint8Array(this, begin, num);
|
|
318
|
+
targetArray.set(sourceArray);
|
|
319
|
+
return target;
|
|
320
|
+
};
|
|
321
|
+
})();
|
|
322
|
+
/**
|
|
323
|
+
* Helpers.
|
|
324
|
+
*/
|
|
325
|
+
function toUtf8(str) {
|
|
326
|
+
if (/[\u0080-\uFFFF]/.test(str)) str = unescape(encodeURIComponent(str));
|
|
327
|
+
return str;
|
|
328
|
+
}
|
|
329
|
+
function utf8Str2ArrayBuffer(str, returnUInt8Array) {
|
|
330
|
+
var length = str.length, buff = new ArrayBuffer(length), arr = new Uint8Array(buff), i = 0;
|
|
331
|
+
for (; i < length; i += 1) arr[i] = str.charCodeAt(i);
|
|
332
|
+
return returnUInt8Array ? arr : buff;
|
|
333
|
+
}
|
|
334
|
+
function arrayBuffer2Utf8Str(buff) {
|
|
335
|
+
return String.fromCharCode.apply(null, new Uint8Array(buff));
|
|
336
|
+
}
|
|
337
|
+
function concatenateArrayBuffers(first, second, returnUInt8Array) {
|
|
338
|
+
var result = new Uint8Array(first.byteLength + second.byteLength);
|
|
339
|
+
result.set(new Uint8Array(first));
|
|
340
|
+
result.set(new Uint8Array(second), first.byteLength);
|
|
341
|
+
return returnUInt8Array ? result : result.buffer;
|
|
342
|
+
}
|
|
343
|
+
function hexToBinaryString(hex) {
|
|
344
|
+
var bytes = [], length = hex.length, x = 0;
|
|
345
|
+
for (; x < length - 1; x += 2) bytes.push(parseInt(hex.substr(x, 2), 16));
|
|
346
|
+
return String.fromCharCode.apply(String, bytes);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* SparkMD5 OOP implementation.
|
|
350
|
+
*
|
|
351
|
+
* Use this class to perform an incremental md5, otherwise use the
|
|
352
|
+
* static methods instead.
|
|
353
|
+
*/
|
|
354
|
+
function SparkMD5() {
|
|
355
|
+
this.reset();
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Appends a string.
|
|
359
|
+
* A conversion will be applied if an utf8 string is detected.
|
|
360
|
+
*
|
|
361
|
+
* @param {String} str The string to be appended
|
|
362
|
+
*
|
|
363
|
+
* @return {SparkMD5} The instance itself
|
|
364
|
+
*/
|
|
365
|
+
SparkMD5.prototype.append = function(str) {
|
|
366
|
+
this.appendBinary(toUtf8(str));
|
|
367
|
+
return this;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Appends a binary string.
|
|
371
|
+
*
|
|
372
|
+
* @param {String} contents The binary string to be appended
|
|
373
|
+
*
|
|
374
|
+
* @return {SparkMD5} The instance itself
|
|
375
|
+
*/
|
|
376
|
+
SparkMD5.prototype.appendBinary = function(contents) {
|
|
377
|
+
this._buff += contents;
|
|
378
|
+
this._length += contents.length;
|
|
379
|
+
var length = this._buff.length, i = 64;
|
|
380
|
+
for (; i <= length; i += 64) md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
|
|
381
|
+
this._buff = this._buff.substring(i - 64);
|
|
382
|
+
return this;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Finishes the incremental computation, reseting the internal state and
|
|
386
|
+
* returning the result.
|
|
387
|
+
*
|
|
388
|
+
* @param {Boolean} raw True to get the raw string, false to get the hex string
|
|
389
|
+
*
|
|
390
|
+
* @return {String} The result
|
|
391
|
+
*/
|
|
392
|
+
SparkMD5.prototype.end = function(raw) {
|
|
393
|
+
var buff = this._buff, length = buff.length, i, tail = [
|
|
394
|
+
0,
|
|
395
|
+
0,
|
|
396
|
+
0,
|
|
397
|
+
0,
|
|
398
|
+
0,
|
|
399
|
+
0,
|
|
400
|
+
0,
|
|
401
|
+
0,
|
|
402
|
+
0,
|
|
403
|
+
0,
|
|
404
|
+
0,
|
|
405
|
+
0,
|
|
406
|
+
0,
|
|
407
|
+
0,
|
|
408
|
+
0,
|
|
409
|
+
0
|
|
410
|
+
], ret;
|
|
411
|
+
for (i = 0; i < length; i += 1) tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);
|
|
412
|
+
this._finish(tail, length);
|
|
413
|
+
ret = hex(this._hash);
|
|
414
|
+
if (raw) ret = hexToBinaryString(ret);
|
|
415
|
+
this.reset();
|
|
416
|
+
return ret;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Resets the internal state of the computation.
|
|
420
|
+
*
|
|
421
|
+
* @return {SparkMD5} The instance itself
|
|
422
|
+
*/
|
|
423
|
+
SparkMD5.prototype.reset = function() {
|
|
424
|
+
this._buff = "";
|
|
425
|
+
this._length = 0;
|
|
426
|
+
this._hash = [
|
|
427
|
+
1732584193,
|
|
428
|
+
-271733879,
|
|
429
|
+
-1732584194,
|
|
430
|
+
271733878
|
|
431
|
+
];
|
|
432
|
+
return this;
|
|
433
|
+
};
|
|
434
|
+
/**
|
|
435
|
+
* Gets the internal state of the computation.
|
|
436
|
+
*
|
|
437
|
+
* @return {Object} The state
|
|
438
|
+
*/
|
|
439
|
+
SparkMD5.prototype.getState = function() {
|
|
440
|
+
return {
|
|
441
|
+
buff: this._buff,
|
|
442
|
+
length: this._length,
|
|
443
|
+
hash: this._hash.slice()
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* Gets the internal state of the computation.
|
|
448
|
+
*
|
|
449
|
+
* @param {Object} state The state
|
|
450
|
+
*
|
|
451
|
+
* @return {SparkMD5} The instance itself
|
|
452
|
+
*/
|
|
453
|
+
SparkMD5.prototype.setState = function(state) {
|
|
454
|
+
this._buff = state.buff;
|
|
455
|
+
this._length = state.length;
|
|
456
|
+
this._hash = state.hash;
|
|
457
|
+
return this;
|
|
458
|
+
};
|
|
459
|
+
/**
|
|
460
|
+
* Releases memory used by the incremental buffer and other additional
|
|
461
|
+
* resources. If you plan to use the instance again, use reset instead.
|
|
462
|
+
*/
|
|
463
|
+
SparkMD5.prototype.destroy = function() {
|
|
464
|
+
delete this._hash;
|
|
465
|
+
delete this._buff;
|
|
466
|
+
delete this._length;
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Finish the final calculation based on the tail.
|
|
470
|
+
*
|
|
471
|
+
* @param {Array} tail The tail (will be modified)
|
|
472
|
+
* @param {Number} length The length of the remaining buffer
|
|
473
|
+
*/
|
|
474
|
+
SparkMD5.prototype._finish = function(tail, length) {
|
|
475
|
+
var i = length, tmp, lo, hi;
|
|
476
|
+
tail[i >> 2] |= 128 << (i % 4 << 3);
|
|
477
|
+
if (i > 55) {
|
|
478
|
+
md5cycle(this._hash, tail);
|
|
479
|
+
for (i = 0; i < 16; i += 1) tail[i] = 0;
|
|
480
|
+
}
|
|
481
|
+
tmp = this._length * 8;
|
|
482
|
+
tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
|
483
|
+
lo = parseInt(tmp[2], 16);
|
|
484
|
+
hi = parseInt(tmp[1], 16) || 0;
|
|
485
|
+
tail[14] = lo;
|
|
486
|
+
tail[15] = hi;
|
|
487
|
+
md5cycle(this._hash, tail);
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* Performs the md5 hash on a string.
|
|
491
|
+
* A conversion will be applied if utf8 string is detected.
|
|
492
|
+
*
|
|
493
|
+
* @param {String} str The string
|
|
494
|
+
* @param {Boolean} [raw] True to get the raw string, false to get the hex string
|
|
495
|
+
*
|
|
496
|
+
* @return {String} The result
|
|
497
|
+
*/
|
|
498
|
+
SparkMD5.hash = function(str, raw) {
|
|
499
|
+
return SparkMD5.hashBinary(toUtf8(str), raw);
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Performs the md5 hash on a binary string.
|
|
503
|
+
*
|
|
504
|
+
* @param {String} content The binary string
|
|
505
|
+
* @param {Boolean} [raw] True to get the raw string, false to get the hex string
|
|
506
|
+
*
|
|
507
|
+
* @return {String} The result
|
|
508
|
+
*/
|
|
509
|
+
SparkMD5.hashBinary = function(content, raw) {
|
|
510
|
+
var ret = hex(md51(content));
|
|
511
|
+
return raw ? hexToBinaryString(ret) : ret;
|
|
512
|
+
};
|
|
513
|
+
/**
|
|
514
|
+
* SparkMD5 OOP implementation for array buffers.
|
|
515
|
+
*
|
|
516
|
+
* Use this class to perform an incremental md5 ONLY for array buffers.
|
|
517
|
+
*/
|
|
518
|
+
SparkMD5.ArrayBuffer = function() {
|
|
519
|
+
this.reset();
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Appends an array buffer.
|
|
523
|
+
*
|
|
524
|
+
* @param {ArrayBuffer} arr The array to be appended
|
|
525
|
+
*
|
|
526
|
+
* @return {SparkMD5.ArrayBuffer} The instance itself
|
|
527
|
+
*/
|
|
528
|
+
SparkMD5.ArrayBuffer.prototype.append = function(arr) {
|
|
529
|
+
var buff = concatenateArrayBuffers(this._buff.buffer, arr, true), length = buff.length, i;
|
|
530
|
+
this._length += arr.byteLength;
|
|
531
|
+
for (i = 64; i <= length; i += 64) md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
|
|
532
|
+
this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : /* @__PURE__ */ new Uint8Array(0);
|
|
533
|
+
return this;
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* Finishes the incremental computation, reseting the internal state and
|
|
537
|
+
* returning the result.
|
|
538
|
+
*
|
|
539
|
+
* @param {Boolean} raw True to get the raw string, false to get the hex string
|
|
540
|
+
*
|
|
541
|
+
* @return {String} The result
|
|
542
|
+
*/
|
|
543
|
+
SparkMD5.ArrayBuffer.prototype.end = function(raw) {
|
|
544
|
+
var buff = this._buff, length = buff.length, tail = [
|
|
545
|
+
0,
|
|
546
|
+
0,
|
|
547
|
+
0,
|
|
548
|
+
0,
|
|
549
|
+
0,
|
|
550
|
+
0,
|
|
551
|
+
0,
|
|
552
|
+
0,
|
|
553
|
+
0,
|
|
554
|
+
0,
|
|
555
|
+
0,
|
|
556
|
+
0,
|
|
557
|
+
0,
|
|
558
|
+
0,
|
|
559
|
+
0,
|
|
560
|
+
0
|
|
561
|
+
], i = 0, ret;
|
|
562
|
+
for (; i < length; i += 1) tail[i >> 2] |= buff[i] << (i % 4 << 3);
|
|
563
|
+
this._finish(tail, length);
|
|
564
|
+
ret = hex(this._hash);
|
|
565
|
+
if (raw) ret = hexToBinaryString(ret);
|
|
566
|
+
this.reset();
|
|
567
|
+
return ret;
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* Resets the internal state of the computation.
|
|
571
|
+
*
|
|
572
|
+
* @return {SparkMD5.ArrayBuffer} The instance itself
|
|
573
|
+
*/
|
|
574
|
+
SparkMD5.ArrayBuffer.prototype.reset = function() {
|
|
575
|
+
this._buff = /* @__PURE__ */ new Uint8Array(0);
|
|
576
|
+
this._length = 0;
|
|
577
|
+
this._hash = [
|
|
578
|
+
1732584193,
|
|
579
|
+
-271733879,
|
|
580
|
+
-1732584194,
|
|
581
|
+
271733878
|
|
582
|
+
];
|
|
583
|
+
return this;
|
|
584
|
+
};
|
|
585
|
+
/**
|
|
586
|
+
* Gets the internal state of the computation.
|
|
587
|
+
*
|
|
588
|
+
* @return {Object} The state
|
|
589
|
+
*/
|
|
590
|
+
SparkMD5.ArrayBuffer.prototype.getState = function() {
|
|
591
|
+
var state = SparkMD5.prototype.getState.call(this);
|
|
592
|
+
state.buff = arrayBuffer2Utf8Str(state.buff);
|
|
593
|
+
return state;
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* Gets the internal state of the computation.
|
|
597
|
+
*
|
|
598
|
+
* @param {Object} state The state
|
|
599
|
+
*
|
|
600
|
+
* @return {SparkMD5.ArrayBuffer} The instance itself
|
|
601
|
+
*/
|
|
602
|
+
SparkMD5.ArrayBuffer.prototype.setState = function(state) {
|
|
603
|
+
state.buff = utf8Str2ArrayBuffer(state.buff, true);
|
|
604
|
+
return SparkMD5.prototype.setState.call(this, state);
|
|
605
|
+
};
|
|
606
|
+
SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
|
|
607
|
+
SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
|
|
608
|
+
/**
|
|
609
|
+
* Performs the md5 hash on an array buffer.
|
|
610
|
+
*
|
|
611
|
+
* @param {ArrayBuffer} arr The array buffer
|
|
612
|
+
* @param {Boolean} [raw] True to get the raw string, false to get the hex one
|
|
613
|
+
*
|
|
614
|
+
* @return {String} The result
|
|
615
|
+
*/
|
|
616
|
+
SparkMD5.ArrayBuffer.hash = function(arr, raw) {
|
|
617
|
+
var ret = hex(md51_array(new Uint8Array(arr)));
|
|
618
|
+
return raw ? hexToBinaryString(ret) : ret;
|
|
619
|
+
};
|
|
620
|
+
return SparkMD5;
|
|
621
|
+
});
|
|
622
|
+
})))(), 1);
|
|
623
|
+
/** Whitespace is not part of the sentence: `'Save\n As'` and `'SaveAs'` collide on purpose. */
|
|
624
|
+
const fpTranslation = (text) => {
|
|
625
|
+
const normalized = text.replace(/\s+/g, "").trim();
|
|
626
|
+
return import_spark_md5.default.hash(normalized);
|
|
627
|
+
};
|
|
628
|
+
/** Keys that only carry a text's fingerprint, awaiting a real name. */
|
|
629
|
+
const DRAFT_KEY_PREFIX = "__draft_";
|
|
630
|
+
/** What a person sees for a key: a draft key's fingerprint is cut to five characters. */
|
|
631
|
+
function formatI18nKeyDisplay(key) {
|
|
632
|
+
if (!key) return "";
|
|
633
|
+
if (!key.startsWith("__draft_")) return key;
|
|
634
|
+
const hash = key.slice(8);
|
|
635
|
+
if (hash.length <= 5) return key;
|
|
636
|
+
return `${DRAFT_KEY_PREFIX}${hash.slice(0, 5)}`;
|
|
637
|
+
}
|
|
638
|
+
/** Ids are compared as strings: a row's ids come back from JSON while a picker emits numbers. */
|
|
639
|
+
function entryMatchesReleaseFilter(releaseIds, filter) {
|
|
640
|
+
if (filter === "all") return true;
|
|
641
|
+
const ids = releaseIds ?? [];
|
|
642
|
+
if (filter === "unassigned") return ids.length === 0;
|
|
643
|
+
return ids.some((releaseId) => String(releaseId) === String(filter));
|
|
644
|
+
}
|
|
645
|
+
export { DRAFT_KEY_PREFIX, entryMatchesReleaseFilter, formatI18nKeyDisplay, fpTranslation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localness/contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Response contracts of the Localness public /api/v1: zod schemas and the types inferred from them.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.mts",
|
|
21
21
|
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./rules": {
|
|
24
|
+
"types": "./dist/rules.d.mts",
|
|
25
|
+
"default": "./dist/rules.mjs"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"publishConfig": {
|
|
@@ -32,6 +36,8 @@
|
|
|
32
36
|
"zod": "^4.0.0"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
39
|
+
"@types/spark-md5": "^3.0.5",
|
|
40
|
+
"spark-md5": "^3.0.2",
|
|
35
41
|
"tsdown": "^0.23.2",
|
|
36
42
|
"typescript": "^5.9.3",
|
|
37
43
|
"zod": "^4.5.4"
|