@dxos/util 0.8.4-main.fdfb99ef29 → 0.8.4-staging.60fe92afc8
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 +102 -5
- package/dist/lib/browser/index.mjs +75 -26
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +75 -26
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/id.d.ts +30 -0
- package/dist/types/src/id.d.ts.map +1 -0
- package/dist/types/src/id.test.d.ts +2 -0
- package/dist/types/src/id.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/map-values.d.ts.map +1 -1
- package/dist/types/src/position.d.ts +4 -4
- package/dist/types/src/position.d.ts.map +1 -1
- package/dist/types/src/string.d.ts +12 -0
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/uint8array.d.ts +27 -0
- package/dist/types/src/uint8array.d.ts.map +1 -1
- package/dist/types/src/unit.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/id.test.ts +109 -0
- package/src/id.ts +48 -0
- package/src/index.ts +1 -0
- package/src/map-values.ts +6 -0
- package/src/position.test.ts +38 -44
- package/src/position.ts +7 -11
- package/src/string.test.ts +24 -1
- package/src/string.ts +16 -0
- package/src/uint8array.ts +44 -0
- package/src/unit.ts +3 -1
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -1060,6 +1060,19 @@ var humanize = (value) => {
|
|
|
1060
1060
|
return hasher.humanize(value);
|
|
1061
1061
|
};
|
|
1062
1062
|
|
|
1063
|
+
// src/id.ts
|
|
1064
|
+
var PART = /^[a-zA-Z][a-zA-Z0-9]{0,62}$/;
|
|
1065
|
+
var ID = /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/;
|
|
1066
|
+
function id(strings, ...values) {
|
|
1067
|
+
const raw = strings.reduce((out, str, i) => out + str + (i < values.length ? String(values[i]) : ""), "");
|
|
1068
|
+
if (!ID.test(raw)) {
|
|
1069
|
+
throw new Error(`Invalid id (expected AT Protocol NSID): ${JSON.stringify(raw)}`);
|
|
1070
|
+
}
|
|
1071
|
+
return raw;
|
|
1072
|
+
}
|
|
1073
|
+
var isWellFormedId = (value) => ID.test(value);
|
|
1074
|
+
var isWellFormedIdPart = (value) => PART.test(value);
|
|
1075
|
+
|
|
1063
1076
|
// src/map.ts
|
|
1064
1077
|
var defaultMap = (map, key, def) => {
|
|
1065
1078
|
let value = map.get(key);
|
|
@@ -1079,12 +1092,12 @@ var getPrototypeSpecificInstanceId = (instance) => {
|
|
|
1079
1092
|
nextId: 0,
|
|
1080
1093
|
instanceIds: /* @__PURE__ */ new WeakMap()
|
|
1081
1094
|
}));
|
|
1082
|
-
let
|
|
1083
|
-
if (
|
|
1084
|
-
|
|
1085
|
-
instanceCtx.instanceIds.set(instance,
|
|
1095
|
+
let id2 = instanceCtx.instanceIds.get(instance);
|
|
1096
|
+
if (id2 === void 0) {
|
|
1097
|
+
id2 = instanceCtx.nextId++;
|
|
1098
|
+
instanceCtx.instanceIds.set(instance, id2);
|
|
1086
1099
|
}
|
|
1087
|
-
return
|
|
1100
|
+
return id2;
|
|
1088
1101
|
};
|
|
1089
1102
|
var getDebugName = (instance) => {
|
|
1090
1103
|
if (instance == null) {
|
|
@@ -1151,6 +1164,26 @@ var bufferToArray = (buffer) => {
|
|
|
1151
1164
|
};
|
|
1152
1165
|
var stringToArray = (string) => bufferToArray(Buffer.from(string, "hex"));
|
|
1153
1166
|
var arrayToString = (array) => arrayToBuffer(array).toString("hex");
|
|
1167
|
+
var toUnpaddedBase64 = (bytes) => arrayToBuffer(bytes).toString("base64").replace(/=+$/, "");
|
|
1168
|
+
var encodeUint8ArrayToJson = (bytes) => ({
|
|
1169
|
+
"/": {
|
|
1170
|
+
bytes: toUnpaddedBase64(bytes)
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
var isEncodedUint8Array = (value) => {
|
|
1174
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1175
|
+
return false;
|
|
1176
|
+
}
|
|
1177
|
+
if (Object.keys(value).length !== 1) {
|
|
1178
|
+
return false;
|
|
1179
|
+
}
|
|
1180
|
+
const inner = value["/"];
|
|
1181
|
+
if (typeof inner !== "object" || inner === null || Array.isArray(inner)) {
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1184
|
+
return Object.keys(inner).length === 1 && typeof inner.bytes === "string";
|
|
1185
|
+
};
|
|
1186
|
+
var decodeUint8ArrayFromJson = (encoded) => bufferToArray(Buffer.from(encoded["/"].bytes, "base64"));
|
|
1154
1187
|
|
|
1155
1188
|
// src/json.ts
|
|
1156
1189
|
var MAX_DEPTH = 5;
|
|
@@ -1280,6 +1313,8 @@ var DeepMapper = class {
|
|
|
1280
1313
|
res[i] = this._map(value[i], i);
|
|
1281
1314
|
}
|
|
1282
1315
|
return res;
|
|
1316
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
1317
|
+
return value;
|
|
1283
1318
|
} else if (value !== null && typeof value === "object") {
|
|
1284
1319
|
const res = {};
|
|
1285
1320
|
this._cyclic.set(value, res);
|
|
@@ -1321,6 +1356,8 @@ var DeepMapperAsync = class {
|
|
|
1321
1356
|
res[i] = await this._map(value[i], i);
|
|
1322
1357
|
}
|
|
1323
1358
|
return res;
|
|
1359
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
1360
|
+
return value;
|
|
1324
1361
|
} else if (value !== null && typeof value === "object") {
|
|
1325
1362
|
const res = {};
|
|
1326
1363
|
this._cyclic.set(value, res);
|
|
@@ -1365,27 +1402,27 @@ var orderKeys = (obj, order) => {
|
|
|
1365
1402
|
|
|
1366
1403
|
// src/order.ts
|
|
1367
1404
|
var inferObjectOrder = (objectMap, order = []) => {
|
|
1368
|
-
const orderedObjects = order.reduce((acc,
|
|
1369
|
-
if (
|
|
1370
|
-
acc.objects.push(objectMap[
|
|
1371
|
-
acc.ids.add(
|
|
1405
|
+
const orderedObjects = order.reduce((acc, id2) => {
|
|
1406
|
+
if (id2 in objectMap) {
|
|
1407
|
+
acc.objects.push(objectMap[id2]);
|
|
1408
|
+
acc.ids.add(id2);
|
|
1372
1409
|
}
|
|
1373
1410
|
return acc;
|
|
1374
1411
|
}, {
|
|
1375
1412
|
objects: [],
|
|
1376
1413
|
ids: /* @__PURE__ */ new Set()
|
|
1377
1414
|
});
|
|
1378
|
-
const { objects } = Object.keys(objectMap).reduce((acc,
|
|
1379
|
-
if (!acc.ids.has(
|
|
1380
|
-
acc.objects.push(objectMap[
|
|
1415
|
+
const { objects } = Object.keys(objectMap).reduce((acc, id2) => {
|
|
1416
|
+
if (!acc.ids.has(id2)) {
|
|
1417
|
+
acc.objects.push(objectMap[id2]);
|
|
1381
1418
|
}
|
|
1382
1419
|
return acc;
|
|
1383
1420
|
}, orderedObjects);
|
|
1384
1421
|
return objects;
|
|
1385
1422
|
};
|
|
1386
1423
|
var inferRecordOrder = (objectMap, order = []) => {
|
|
1387
|
-
return Object.assign(order.filter((
|
|
1388
|
-
acc[
|
|
1424
|
+
return Object.assign(order.filter((id2) => id2 in objectMap).reduce((acc, id2) => {
|
|
1425
|
+
acc[id2] = null;
|
|
1389
1426
|
return acc;
|
|
1390
1427
|
}, {}), objectMap);
|
|
1391
1428
|
};
|
|
@@ -1471,12 +1508,12 @@ var getHostPlatform = () => {
|
|
|
1471
1508
|
};
|
|
1472
1509
|
|
|
1473
1510
|
// src/position.ts
|
|
1474
|
-
var byPosition = ({ position: a
|
|
1511
|
+
var byPosition = ({ position: a }, { position: b }) => {
|
|
1475
1512
|
if (a === b) {
|
|
1476
1513
|
return 0;
|
|
1477
|
-
} else if (a === "
|
|
1514
|
+
} else if (a === "first" || b === "last") {
|
|
1478
1515
|
return -1;
|
|
1479
|
-
} else if (b === "
|
|
1516
|
+
} else if (b === "first" || a === "last") {
|
|
1480
1517
|
return 1;
|
|
1481
1518
|
} else {
|
|
1482
1519
|
return 0;
|
|
@@ -1898,6 +1935,10 @@ var capitalize = (str) => {
|
|
|
1898
1935
|
}
|
|
1899
1936
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1900
1937
|
};
|
|
1938
|
+
function inline(strings, ...values) {
|
|
1939
|
+
const raw = strings.reduce((out, str, i) => out + str + (i < values.length ? String(values[i]) : ""), "");
|
|
1940
|
+
return raw.replace(/\s+/g, " ").trim();
|
|
1941
|
+
}
|
|
1901
1942
|
function trim(strings, ...values) {
|
|
1902
1943
|
const raw = strings.reduce((out, str, i) => {
|
|
1903
1944
|
out += str;
|
|
@@ -2118,8 +2159,8 @@ var Tracer = class {
|
|
|
2118
2159
|
keys() {
|
|
2119
2160
|
return Array.from(this._events.keys());
|
|
2120
2161
|
}
|
|
2121
|
-
get(
|
|
2122
|
-
const events = this._events.get(
|
|
2162
|
+
get(id2, filter) {
|
|
2163
|
+
const events = this._events.get(id2);
|
|
2123
2164
|
if (filter) {
|
|
2124
2165
|
return events?.filter((event) => Object.entries(filter).every(([key, value]) => event?.value[key] === value));
|
|
2125
2166
|
}
|
|
@@ -2136,11 +2177,11 @@ var Tracer = class {
|
|
|
2136
2177
|
this._recording = false;
|
|
2137
2178
|
return this;
|
|
2138
2179
|
}
|
|
2139
|
-
emit(
|
|
2140
|
-
this._post(this._createEvent(
|
|
2180
|
+
emit(id2, value) {
|
|
2181
|
+
this._post(this._createEvent(id2, value));
|
|
2141
2182
|
}
|
|
2142
|
-
mark(
|
|
2143
|
-
const event = this._createEvent(
|
|
2183
|
+
mark(id2, value) {
|
|
2184
|
+
const event = this._createEvent(id2, value);
|
|
2144
2185
|
const start = performance.now();
|
|
2145
2186
|
return {
|
|
2146
2187
|
start,
|
|
@@ -2150,9 +2191,9 @@ var Tracer = class {
|
|
|
2150
2191
|
}
|
|
2151
2192
|
};
|
|
2152
2193
|
}
|
|
2153
|
-
_createEvent(
|
|
2194
|
+
_createEvent(id2, value) {
|
|
2154
2195
|
const event = {
|
|
2155
|
-
id,
|
|
2196
|
+
id: id2,
|
|
2156
2197
|
timestamp: Date.now()
|
|
2157
2198
|
};
|
|
2158
2199
|
if (value !== void 0) {
|
|
@@ -2315,6 +2356,7 @@ var Unit = {
|
|
|
2315
2356
|
symbol: "ms",
|
|
2316
2357
|
quotient: 1
|
|
2317
2358
|
}),
|
|
2359
|
+
// TODO(burdon): Inconsistent formattedValue.
|
|
2318
2360
|
Duration: (n) => {
|
|
2319
2361
|
const hours = Math.floor(n / MS_HOURS);
|
|
2320
2362
|
const minutes = Math.floor(n % MS_HOURS / MS_MINUTES);
|
|
@@ -2332,7 +2374,7 @@ var Unit = {
|
|
|
2332
2374
|
}
|
|
2333
2375
|
if (minutes) {
|
|
2334
2376
|
const seconds2 = (n - MS_MINUTES * minutes) / MS_SECONDS;
|
|
2335
|
-
const formattedValue = seconds2 ? `${minutes}m ${seconds2}s` : `${minutes}m`;
|
|
2377
|
+
const formattedValue = seconds2 ? `${minutes}m ${Math.round(seconds2)}s` : `${minutes}m`;
|
|
2336
2378
|
return {
|
|
2337
2379
|
unit: {
|
|
2338
2380
|
symbol: "m",
|
|
@@ -2540,6 +2582,7 @@ export {
|
|
|
2540
2582
|
createSetDispatch,
|
|
2541
2583
|
createUrl,
|
|
2542
2584
|
decamelize,
|
|
2585
|
+
decodeUint8ArrayFromJson,
|
|
2543
2586
|
deepMapValues,
|
|
2544
2587
|
deepMapValuesAsync,
|
|
2545
2588
|
defaultFilter,
|
|
@@ -2550,6 +2593,7 @@ export {
|
|
|
2550
2593
|
diff,
|
|
2551
2594
|
distinctBy,
|
|
2552
2595
|
doAsync,
|
|
2596
|
+
encodeUint8ArrayToJson,
|
|
2553
2597
|
entries,
|
|
2554
2598
|
entry,
|
|
2555
2599
|
exponentialBackoffInterval,
|
|
@@ -2567,20 +2611,25 @@ export {
|
|
|
2567
2611
|
hexToHue,
|
|
2568
2612
|
humanize,
|
|
2569
2613
|
hyphenize,
|
|
2614
|
+
id,
|
|
2570
2615
|
idEmoji,
|
|
2571
2616
|
idHue,
|
|
2572
2617
|
inferObjectOrder,
|
|
2573
2618
|
inferRecordOrder,
|
|
2619
|
+
inline,
|
|
2574
2620
|
intersectBy,
|
|
2575
2621
|
intersection,
|
|
2576
2622
|
iosCheck,
|
|
2577
2623
|
isBun,
|
|
2624
|
+
isEncodedUint8Array,
|
|
2578
2625
|
isMobile,
|
|
2579
2626
|
isMobileOrTablet,
|
|
2580
2627
|
isNode,
|
|
2581
2628
|
isNonNullable,
|
|
2582
2629
|
isTauri,
|
|
2583
2630
|
isTruthy,
|
|
2631
|
+
isWellFormedId,
|
|
2632
|
+
isWellFormedIdPart,
|
|
2584
2633
|
joinTables,
|
|
2585
2634
|
jsonKeyReplacer,
|
|
2586
2635
|
jsonReplacer,
|