@dxos/util 0.5.9-main.bf0ae3e → 0.5.9-main.bf3bb8f

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.
@@ -199,6 +199,60 @@ var createSetDispatch = ({ handlers }) => {
199
199
  });
200
200
  };
201
201
 
202
+ // packages/common/util/src/circular-buffer.ts
203
+ import { invariant as invariant4 } from "@dxos/invariant";
204
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
205
+ var CircularBuffer = class {
206
+ constructor(size) {
207
+ this._nextIndex = 0;
208
+ this._elementCount = 0;
209
+ invariant4(size >= 1, void 0, {
210
+ F: __dxlog_file4,
211
+ L: 13,
212
+ S: this,
213
+ A: [
214
+ "size >= 1",
215
+ ""
216
+ ]
217
+ });
218
+ this._buffer = new Array(size);
219
+ }
220
+ push(element) {
221
+ this._buffer[this._nextIndex] = element;
222
+ this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
223
+ this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
224
+ }
225
+ getLast() {
226
+ if (this._elementCount === 0) {
227
+ return void 0;
228
+ }
229
+ if (this._nextIndex === 0) {
230
+ return this._buffer[this._buffer.length - 1];
231
+ }
232
+ return this._buffer[this._nextIndex - 1];
233
+ }
234
+ [Symbol.iterator]() {
235
+ return this.values();
236
+ }
237
+ *values() {
238
+ if (this._elementCount === 0) {
239
+ return;
240
+ }
241
+ if (this._elementCount < this._buffer.length) {
242
+ for (let i = 0; i < this._elementCount; i++) {
243
+ yield this._buffer[i];
244
+ }
245
+ return;
246
+ }
247
+ for (let i = this._nextIndex; i < this._buffer.length; i++) {
248
+ yield this._buffer[i];
249
+ }
250
+ for (let i = 0; i < this._nextIndex; i++) {
251
+ yield this._buffer[i];
252
+ }
253
+ }
254
+ };
255
+
202
256
  // packages/common/util/src/complex.ts
203
257
  import { inspect } from "@dxos/node-std/util";
204
258
  import { inspectObject, raise } from "@dxos/debug";
@@ -364,204 +418,58 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
364
418
  }
365
419
  };
366
420
 
367
- // packages/common/util/src/defer-function.ts
368
- var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
369
-
370
- // packages/common/util/src/to-fallback.ts
371
- var idEmoji = [
372
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
373
- // Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
374
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
375
- // – not people or isolated anthropomorphic faces
376
- // – not flags
377
- // – more concrete than abstract
378
- // – less culturally specific
379
- // – less easily confused with another emoji in the set
380
- // – requires less special knowledge to identify
381
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
382
- // – less common as a signifier in UX
383
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
384
- "\u{1F479}",
385
- "\u{1F47B}",
386
- "\u{1F47D}",
387
- "\u{1F916}",
388
- "\u{1F383}",
389
- "\u{1F9BE}",
390
- "\u{1F9BF}",
391
- "\u{1F9B7}",
392
- "\u{1F463}",
393
- "\u{1F441}\uFE0F",
394
- "\u{1F9F6}",
395
- "\u{1F451}",
396
- "\u{1F412}",
397
- "\u{1F986}",
398
- "\u{1F989}",
399
- "\u{1F434}",
400
- "\u{1F984}",
401
- "\u{1F41D}",
402
- "\u{1F98B}",
403
- "\u{1F41E}",
404
- "\u{1FAB2}",
405
- "\u{1F422}",
406
- "\u{1F98E}",
407
- "\u{1F995}",
408
- "\u{1F991}",
409
- "\u{1F980}",
410
- "\u{1F420}",
411
- "\u{1F42C}",
412
- "\u{1F40B}",
413
- "\u{1F9AD}",
414
- "\u{1F405}",
415
- "\u{1F406}",
416
- "\u{1F993}",
417
- "\u{1F98D}",
418
- "\u{1F9A7}",
419
- "\u{1F418}",
420
- "\u{1F42B}",
421
- "\u{1F992}",
422
- "\u{1F998}",
423
- "\u{1F9AC}",
424
- "\u{1F416}",
425
- "\u{1F40F}",
426
- "\u{1F98C}",
427
- "\u{1F415}",
428
- "\u{1F408}",
429
- "\u{1F413}",
430
- "\u{1F99A}",
431
- "\u{1F99C}",
432
- "\u{1F9A2}",
433
- "\u{1F9A9}",
434
- "\u{1F9A6}",
435
- "\u{1F401}",
436
- "\u{1F43F}\uFE0F",
437
- "\u{1F335}",
438
- "\u{1F332}",
439
- "\u{1F333}",
440
- "\u{1FAB5}",
441
- "\u{1F331}",
442
- "\u{1F341}",
443
- "\u{1FABA}",
444
- "\u{1F344}",
445
- "\u{1F41A}",
446
- "\u{1FAB8}",
447
- "\u{1FAA8}",
448
- "\u{1F33E}",
449
- "\u{1F337}",
450
- "\u{1F33B}",
451
- "\u2600\uFE0F",
452
- "\u{1F319}",
453
- "\u{1FA90}",
454
- "\u2B50\uFE0F",
455
- "\u26A1\uFE0F",
456
- "\u2604\uFE0F",
457
- "\u{1F525}",
458
- "\u{1F308}",
459
- "\u2601\uFE0F",
460
- "\u{1F4A7}",
461
- "\u26F1\uFE0F",
462
- "\u{1F30A}",
463
- "\u{1F34E}",
464
- "\u{1F34B}",
465
- "\u{1F349}",
466
- "\u{1F347}",
467
- "\u{1FAD0}",
468
- "\u{1F348}",
469
- "\u{1F352}",
470
- "\u{1F351}",
471
- "\u{1F96D}",
472
- "\u{1F34D}",
473
- "\u{1F965}",
474
- "\u{1F95D}",
475
- "\u{1F951}",
476
- "\u{1F336}\uFE0F",
477
- "\u{1F33D}",
478
- "\u{1F955}",
479
- "\u{1F36C}",
480
- "\u{1F95C}",
481
- "\u{1FAD6}",
482
- "\u2615\uFE0F",
483
- "\u{1F375}",
484
- "\u{1F9CA}",
485
- "\u{1F9C2}",
486
- "\u{1F3D4}\uFE0F",
487
- "\u2693\uFE0F",
488
- "\u{1F6DF}",
489
- "\u{1F3DD}\uFE0F",
490
- "\u{1F6F6}",
491
- "\u{1F680}",
492
- "\u{1F6F0}\uFE0F",
493
- "\u26F2\uFE0F",
494
- "\u{1F3F0}",
495
- "\u{1F6B2}",
496
- "\u26FA\uFE0F",
497
- "\u{1F399}\uFE0F",
498
- "\u{1F9F2}",
499
- "\u2699\uFE0F",
500
- "\u{1F529}",
501
- "\u{1F52E}",
502
- "\u{1F52D}",
503
- "\u{1F52C}",
504
- "\u{1F9EC}",
505
- "\u{1F321}\uFE0F",
506
- "\u{1F9FA}",
507
- "\u{1F6CE}\uFE0F",
508
- "\u{1F511}",
509
- "\u{1FA91}",
510
- "\u{1F9F8}",
511
- "\u{1F388}",
512
- "\u{1F380}",
513
- "\u{1F38A}",
514
- "\u267B\uFE0F",
515
- "\u{1F3B5}"
516
- ];
517
- var idHue = [
518
- "red",
519
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
520
- "amber",
521
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
522
- "lime",
523
- "green",
524
- "emerald",
525
- "teal",
526
- "cyan",
527
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
528
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
529
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
530
- "violet",
531
- "purple",
532
- "fuchsia",
533
- "pink",
534
- "rose"
535
- ];
536
- var keyToEmoji = (key) => hexToEmoji(key.toHex());
537
- var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
538
- var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
539
- var keyToHue = (key) => hexToHue(key.toHex());
540
- var hexToHue = (hex) => toHue(parseInt(hex, 16));
541
- var toHue = (hash) => idHue[hash % idHue.length];
542
- var keyToFallback = (key) => hexToFallback(key.toHex());
543
- var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
544
- var toFallback = (hash) => ({
545
- emoji: toEmoji(hash),
546
- hue: toHue(hash)
547
- });
421
+ // packages/common/util/src/explicit-resource-management-polyfill.ts
422
+ Symbol.dispose ??= Symbol("Symbol.dispose");
423
+ Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
548
424
 
549
- // packages/common/util/src/entry.ts
550
- var entry = (map, key) => new MapEntry(map, key);
551
- var MapEntry = class {
425
+ // packages/common/util/src/defer.ts
426
+ var defer = (fn) => new DeferGuard(fn);
427
+ var DeferGuard = class {
552
428
  /**
553
429
  * @internal
554
430
  */
555
- // prettier-ignore
556
- constructor(_map, _key) {
557
- this._map = _map;
558
- this._key = _key;
559
- }
560
- get key() {
561
- return this._key;
562
- }
563
- get value() {
564
- return this._map.get(this._key);
431
+ constructor(_fn) {
432
+ this._fn = _fn;
433
+ }
434
+ [Symbol.dispose]() {
435
+ const result = this._fn();
436
+ if (result instanceof Promise) {
437
+ throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
438
+ }
439
+ }
440
+ };
441
+ var deferAsync = (fn) => new DeferAsyncGuard(fn);
442
+ var DeferAsyncGuard = class {
443
+ /**
444
+ * @internal
445
+ */
446
+ constructor(_fn) {
447
+ this._fn = _fn;
448
+ }
449
+ async [Symbol.asyncDispose]() {
450
+ await this._fn();
451
+ }
452
+ };
453
+
454
+ // packages/common/util/src/defer-function.ts
455
+ var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
456
+
457
+ // packages/common/util/src/entry.ts
458
+ var entry = (map, key) => new MapEntry(map, key);
459
+ var MapEntry = class {
460
+ /**
461
+ * @internal
462
+ */
463
+ // prettier-ignore
464
+ constructor(_map, _key) {
465
+ this._map = _map;
466
+ this._key = _key;
467
+ }
468
+ get key() {
469
+ return this._key;
470
+ }
471
+ get value() {
472
+ return this._map.get(this._key);
565
473
  }
566
474
  orInsert(value) {
567
475
  if (!this._map.has(this._key)) {
@@ -574,6 +482,9 @@ var MapEntry = class {
574
482
  }
575
483
  };
576
484
 
485
+ // packages/common/util/src/for-each-async.ts
486
+ var forEachAsync = (items, fn) => Promise.all(items.map(fn));
487
+
577
488
  // packages/common/util/src/human-hash.ts
578
489
  import { PublicKey } from "@dxos/keys";
579
490
  var DEFAULT_WORDLIST = [
@@ -917,6 +828,61 @@ var exponentialBackoffInterval = (cb, initialInterval) => {
917
828
  return () => clearTimeout(timeoutId);
918
829
  };
919
830
 
831
+ // packages/common/util/src/map.ts
832
+ var defaultMap = (map, key, def) => {
833
+ let value = map.get(key);
834
+ if (value === void 0) {
835
+ value = typeof def === "function" ? def() : def;
836
+ map.set(key, value);
837
+ }
838
+ return value;
839
+ };
840
+
841
+ // packages/common/util/src/instance-id.ts
842
+ var symbol = Symbol.for("dxos.instance-contexts");
843
+ var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
844
+ var getPrototypeSpecificInstanceId = (instance) => {
845
+ const prototype = Object.getPrototypeOf(instance);
846
+ const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
847
+ nextId: 0,
848
+ instanceIds: /* @__PURE__ */ new WeakMap()
849
+ }));
850
+ let id = instanceCtx.instanceIds.get(instance);
851
+ if (id === void 0) {
852
+ id = instanceCtx.nextId++;
853
+ instanceCtx.instanceIds.set(instance, id);
854
+ }
855
+ return id;
856
+ };
857
+ var getDebugName = (instance) => {
858
+ if (instance == null) {
859
+ return "null";
860
+ }
861
+ const prototype = Object.getPrototypeOf(instance);
862
+ return `${prototype.constructor.name}#${getPrototypeSpecificInstanceId(instance)}`;
863
+ };
864
+
865
+ // packages/common/util/src/join-tables.ts
866
+ var joinTables = (leftColumn, rightColumn, left, right) => {
867
+ const map = /* @__PURE__ */ new Map();
868
+ const used = /* @__PURE__ */ new Set();
869
+ for (const row of right) {
870
+ map.set(row[rightColumn], row);
871
+ }
872
+ const result = [];
873
+ for (const row of left) {
874
+ const right2 = map.get(row[leftColumn]);
875
+ used.add(right2);
876
+ result.push(Object.assign(right2 ?? {}, row));
877
+ }
878
+ for (const row of right) {
879
+ if (!used.has(row)) {
880
+ result.push(row);
881
+ }
882
+ }
883
+ return result;
884
+ };
885
+
920
886
  // packages/common/util/src/json.ts
921
887
  import { inspect as inspect2 } from "@dxos/node-std/util";
922
888
  import { PublicKey as PublicKey2 } from "@dxos/keys";
@@ -1033,14 +999,87 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1033
999
  return value;
1034
1000
  };
1035
1001
 
1036
- // packages/common/util/src/map.ts
1037
- var defaultMap = (map, key, def) => {
1038
- let value = map.get(key);
1039
- if (value === void 0) {
1040
- value = typeof def === "function" ? def() : def;
1041
- map.set(key, value);
1002
+ // packages/common/util/src/map-values.ts
1003
+ var mapValues = (obj, fn) => {
1004
+ const result = {};
1005
+ Object.keys(obj).forEach((key) => {
1006
+ result[key] = fn(obj[key], key);
1007
+ });
1008
+ return result;
1009
+ };
1010
+ var deepMapValues = (value, fn) => {
1011
+ return new DeepMapper(fn).map(value);
1012
+ };
1013
+ var DeepMapper = class {
1014
+ constructor(_fn) {
1015
+ this._fn = _fn;
1016
+ this._cyclic = /* @__PURE__ */ new Map();
1017
+ this._recurse = (value) => {
1018
+ if (this._cyclic.has(value)) {
1019
+ return this._cyclic.get(value);
1020
+ }
1021
+ if (Array.isArray(value)) {
1022
+ const res = new Array(value.length);
1023
+ this._cyclic.set(value, res);
1024
+ for (let i = 0; i < value.length; i++) {
1025
+ res[i] = this.map(value[i]);
1026
+ }
1027
+ return res;
1028
+ } else if (value !== null && typeof value === "object") {
1029
+ const res = {};
1030
+ this._cyclic.set(value, res);
1031
+ for (const key in value) {
1032
+ res[key] = this.map(value[key]);
1033
+ }
1034
+ return res;
1035
+ } else {
1036
+ return value;
1037
+ }
1038
+ };
1039
+ }
1040
+ map(value) {
1041
+ if (this._cyclic.has(value)) {
1042
+ return this._cyclic.get(value);
1043
+ }
1044
+ return this._fn(value, this._recurse);
1045
+ }
1046
+ };
1047
+ var deepMapValuesAsync = (value, fn) => {
1048
+ return new DeepMapperAsync(fn).map(value);
1049
+ };
1050
+ var DeepMapperAsync = class {
1051
+ constructor(_fn) {
1052
+ this._fn = _fn;
1053
+ this._cyclic = /* @__PURE__ */ new Map();
1054
+ this._recurse = async (value) => {
1055
+ if (this._cyclic.has(value)) {
1056
+ return this._cyclic.get(value);
1057
+ }
1058
+ if (Array.isArray(value)) {
1059
+ const res = new Array(value.length);
1060
+ this._cyclic.set(value, res);
1061
+ for (let i = 0; i < value.length; i++) {
1062
+ res[i] = await this.map(value[i]);
1063
+ }
1064
+ return res;
1065
+ } else if (value !== null && typeof value === "object") {
1066
+ const res = {};
1067
+ this._cyclic.set(value, res);
1068
+ for (const key in value) {
1069
+ res[key] = await this.map(value[key]);
1070
+ }
1071
+ return res;
1072
+ } else {
1073
+ return value;
1074
+ }
1075
+ };
1076
+ }
1077
+ map(value) {
1078
+ if (this._cyclic.has(value)) {
1079
+ return this._cyclic.get(value);
1080
+ }
1081
+ return this._fn(value, this._recurse);
1042
1082
  }
1043
- return value;
1044
1083
  };
1045
1084
 
1046
1085
  // packages/common/util/src/order.ts
@@ -1070,6 +1109,55 @@ var inferRecordOrder = (objectMap, order = []) => {
1070
1109
  }, {}), objectMap);
1071
1110
  };
1072
1111
 
1112
+ // packages/common/util/src/params.ts
1113
+ import { AST } from "@effect/schema";
1114
+ import { decamelize } from "xcase";
1115
+ var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKeyAnnotation");
1116
+ var ParamKeyAnnotation = (value) => (self) => self.annotations({
1117
+ [ParamKeyAnnotationId]: value
1118
+ });
1119
+ var Params = class {
1120
+ constructor(_schema) {
1121
+ this._schema = _schema;
1122
+ }
1123
+ /**
1124
+ * Parse URL params.
1125
+ * @param url
1126
+ */
1127
+ parse(url) {
1128
+ return Object.entries(this._schema.fields).reduce((acc, [key, type]) => {
1129
+ let v = url.searchParams.get(decamelize(key));
1130
+ if (v == null) {
1131
+ v = url.searchParams.get(key);
1132
+ }
1133
+ if (v != null) {
1134
+ if (AST.isNumberKeyword(type.ast)) {
1135
+ acc[key] = parseInt(v);
1136
+ } else if (AST.isBooleanKeyword(type.ast)) {
1137
+ acc[key] = v === "true" || v === "1";
1138
+ } else {
1139
+ acc[key] = v;
1140
+ }
1141
+ }
1142
+ return acc;
1143
+ }, {});
1144
+ }
1145
+ /**
1146
+ * Update URL with params.
1147
+ */
1148
+ params(url, values) {
1149
+ Object.entries(values).forEach(([key, value]) => {
1150
+ const type = this._schema.fields[key];
1151
+ if (type && value != null) {
1152
+ const { value: alt } = AST.getAnnotation(ParamKeyAnnotationId)(type.ast);
1153
+ const k = alt ?? decamelize(key);
1154
+ url.searchParams.set(k, String(value));
1155
+ }
1156
+ });
1157
+ return url;
1158
+ }
1159
+ };
1160
+
1073
1161
  // packages/common/util/src/platform.ts
1074
1162
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1075
1163
  var mobileAndTabletCheck = () => {
@@ -1213,51 +1301,255 @@ var createBucketReducer = (period) => ({
1213
1301
  }
1214
1302
  });
1215
1303
 
1216
- // packages/common/util/src/safe-instanceof.ts
1217
- var instanceTag = Symbol("instanceTag");
1218
- var safeInstanceof = (tag) => (target) => {
1219
- target.prototype[instanceTag] = tag;
1220
- Object.defineProperty(target.prototype, Symbol.hasInstance, {
1221
- value: (instance) => instance?.[instanceTag] === tag
1222
- });
1223
- Object.defineProperty(target, Symbol.hasInstance, {
1224
- value: (instance) => instance?.[instanceTag] === tag
1225
- });
1226
- };
1227
-
1228
- // packages/common/util/src/safe-parse-json.ts
1229
- var safeParseJson = (data, defaultValue) => {
1230
- if (data) {
1231
- try {
1232
- return JSON.parse(data);
1233
- } catch (err) {
1234
- }
1235
- }
1236
- return defaultValue;
1237
- };
1238
-
1239
- // packages/common/util/src/sort.ts
1240
- var compareScalar = (inc = true) => (a, b) => (inc ? 1 : -1) * (a < b ? -1 : a > b ? 1 : 0);
1241
- var compareString = (inc = true, caseInsensitive = true) => (a, b) => {
1242
- if (caseInsensitive) {
1243
- a = a?.toLowerCase();
1244
- b = b?.toLowerCase();
1245
- }
1246
- return (inc ? 1 : -1) * (a < b ? -1 : a > b ? 1 : 0);
1247
- };
1248
- var compareObject = (prop, sorter, inc = true) => (a, b) => (inc ? 1 : -1) * sorter(a[prop], b[prop]);
1249
- var compareMulti = (sorters) => (a, b) => {
1250
- const sort = (i = 0) => {
1251
- const s = sorters[i](a, b);
1252
- if (s === 0 && i < sorters.length - 1) {
1253
- return sort(i + 1);
1254
- } else {
1255
- return s;
1256
- }
1257
- };
1258
- return sort();
1259
- };
1260
-
1304
+ // packages/common/util/src/safe-await.ts
1305
+ var safeAwaitAll = async (source, taskFactory, onError) => {
1306
+ const failedItems = [];
1307
+ await Promise.all([
1308
+ ...source
1309
+ ].map(async (item, idx) => {
1310
+ try {
1311
+ await taskFactory(item);
1312
+ } catch (err) {
1313
+ if (onError) {
1314
+ onError(err, item, idx);
1315
+ }
1316
+ failedItems.push(item);
1317
+ }
1318
+ }));
1319
+ return failedItems;
1320
+ };
1321
+
1322
+ // packages/common/util/src/safe-instanceof.ts
1323
+ var instanceTag = Symbol("instanceTag");
1324
+ var safeInstanceof = (tag) => (target) => {
1325
+ target.prototype[instanceTag] = tag;
1326
+ Object.defineProperty(target.prototype, Symbol.hasInstance, {
1327
+ value: (instance) => instance?.[instanceTag] === tag
1328
+ });
1329
+ Object.defineProperty(target, Symbol.hasInstance, {
1330
+ value: (instance) => instance?.[instanceTag] === tag
1331
+ });
1332
+ };
1333
+
1334
+ // packages/common/util/src/safe-parse-json.ts
1335
+ var safeParseJson = (data, defaultValue) => {
1336
+ if (data) {
1337
+ try {
1338
+ return JSON.parse(data);
1339
+ } catch (err) {
1340
+ }
1341
+ }
1342
+ return defaultValue;
1343
+ };
1344
+
1345
+ // packages/common/util/src/sort.ts
1346
+ var compareScalar = (inc = true) => (a, b) => (inc ? 1 : -1) * (a < b ? -1 : a > b ? 1 : 0);
1347
+ var compareString = (inc = true, caseInsensitive = true) => (a, b) => {
1348
+ if (caseInsensitive) {
1349
+ a = a?.toLowerCase();
1350
+ b = b?.toLowerCase();
1351
+ }
1352
+ return (inc ? 1 : -1) * (a < b ? -1 : a > b ? 1 : 0);
1353
+ };
1354
+ var compareObject = (prop, sorter, inc = true) => (a, b) => (inc ? 1 : -1) * sorter(a[prop], b[prop]);
1355
+ var compareMulti = (sorters) => (a, b) => {
1356
+ const sort = (i = 0) => {
1357
+ const s = sorters[i](a, b);
1358
+ if (s === 0 && i < sorters.length - 1) {
1359
+ return sort(i + 1);
1360
+ } else {
1361
+ return s;
1362
+ }
1363
+ };
1364
+ return sort();
1365
+ };
1366
+
1367
+ // packages/common/util/src/throw-unhandled-error.ts
1368
+ var throwUnhandledError = (error) => {
1369
+ queueMicrotask(() => {
1370
+ throw error;
1371
+ });
1372
+ };
1373
+
1374
+ // packages/common/util/src/to-fallback.ts
1375
+ var idEmoji = [
1376
+ // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
1377
+ // Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
1378
+ // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
1379
+ // – not people or isolated anthropomorphic faces
1380
+ // – not flags
1381
+ // – more concrete than abstract
1382
+ // – less culturally specific
1383
+ // – less easily confused with another emoji in the set
1384
+ // – requires less special knowledge to identify
1385
+ // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1386
+ // – less common as a signifier in UX
1387
+ // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1388
+ "\u{1F479}",
1389
+ "\u{1F47B}",
1390
+ "\u{1F47D}",
1391
+ "\u{1F916}",
1392
+ "\u{1F383}",
1393
+ "\u{1F9BE}",
1394
+ "\u{1F9BF}",
1395
+ "\u{1F9B7}",
1396
+ "\u{1F463}",
1397
+ "\u{1F441}\uFE0F",
1398
+ "\u{1F9F6}",
1399
+ "\u{1F451}",
1400
+ "\u{1F412}",
1401
+ "\u{1F986}",
1402
+ "\u{1F989}",
1403
+ "\u{1F434}",
1404
+ "\u{1F984}",
1405
+ "\u{1F41D}",
1406
+ "\u{1F98B}",
1407
+ "\u{1F41E}",
1408
+ "\u{1FAB2}",
1409
+ "\u{1F422}",
1410
+ "\u{1F98E}",
1411
+ "\u{1F995}",
1412
+ "\u{1F991}",
1413
+ "\u{1F980}",
1414
+ "\u{1F420}",
1415
+ "\u{1F42C}",
1416
+ "\u{1F40B}",
1417
+ "\u{1F9AD}",
1418
+ "\u{1F405}",
1419
+ "\u{1F406}",
1420
+ "\u{1F993}",
1421
+ "\u{1F98D}",
1422
+ "\u{1F9A7}",
1423
+ "\u{1F418}",
1424
+ "\u{1F42B}",
1425
+ "\u{1F992}",
1426
+ "\u{1F998}",
1427
+ "\u{1F9AC}",
1428
+ "\u{1F416}",
1429
+ "\u{1F40F}",
1430
+ "\u{1F98C}",
1431
+ "\u{1F415}",
1432
+ "\u{1F408}",
1433
+ "\u{1F413}",
1434
+ "\u{1F99A}",
1435
+ "\u{1F99C}",
1436
+ "\u{1F9A2}",
1437
+ "\u{1F9A9}",
1438
+ "\u{1F9A6}",
1439
+ "\u{1F401}",
1440
+ "\u{1F43F}\uFE0F",
1441
+ "\u{1F335}",
1442
+ "\u{1F332}",
1443
+ "\u{1F333}",
1444
+ "\u{1FAB5}",
1445
+ "\u{1F331}",
1446
+ "\u{1F341}",
1447
+ "\u{1FABA}",
1448
+ "\u{1F344}",
1449
+ "\u{1F41A}",
1450
+ "\u{1FAB8}",
1451
+ "\u{1FAA8}",
1452
+ "\u{1F33E}",
1453
+ "\u{1F337}",
1454
+ "\u{1F33B}",
1455
+ "\u2600\uFE0F",
1456
+ "\u{1F319}",
1457
+ "\u{1FA90}",
1458
+ "\u2B50\uFE0F",
1459
+ "\u26A1\uFE0F",
1460
+ "\u2604\uFE0F",
1461
+ "\u{1F525}",
1462
+ "\u{1F308}",
1463
+ "\u2601\uFE0F",
1464
+ "\u{1F4A7}",
1465
+ "\u26F1\uFE0F",
1466
+ "\u{1F30A}",
1467
+ "\u{1F34E}",
1468
+ "\u{1F34B}",
1469
+ "\u{1F349}",
1470
+ "\u{1F347}",
1471
+ "\u{1FAD0}",
1472
+ "\u{1F348}",
1473
+ "\u{1F352}",
1474
+ "\u{1F351}",
1475
+ "\u{1F96D}",
1476
+ "\u{1F34D}",
1477
+ "\u{1F965}",
1478
+ "\u{1F95D}",
1479
+ "\u{1F951}",
1480
+ "\u{1F336}\uFE0F",
1481
+ "\u{1F33D}",
1482
+ "\u{1F955}",
1483
+ "\u{1F36C}",
1484
+ "\u{1F95C}",
1485
+ "\u{1FAD6}",
1486
+ "\u2615\uFE0F",
1487
+ "\u{1F375}",
1488
+ "\u{1F9CA}",
1489
+ "\u{1F9C2}",
1490
+ "\u{1F3D4}\uFE0F",
1491
+ "\u2693\uFE0F",
1492
+ "\u{1F6DF}",
1493
+ "\u{1F3DD}\uFE0F",
1494
+ "\u{1F6F6}",
1495
+ "\u{1F680}",
1496
+ "\u{1F6F0}\uFE0F",
1497
+ "\u26F2\uFE0F",
1498
+ "\u{1F3F0}",
1499
+ "\u{1F6B2}",
1500
+ "\u26FA\uFE0F",
1501
+ "\u{1F399}\uFE0F",
1502
+ "\u{1F9F2}",
1503
+ "\u2699\uFE0F",
1504
+ "\u{1F529}",
1505
+ "\u{1F52E}",
1506
+ "\u{1F52D}",
1507
+ "\u{1F52C}",
1508
+ "\u{1F9EC}",
1509
+ "\u{1F321}\uFE0F",
1510
+ "\u{1F9FA}",
1511
+ "\u{1F6CE}\uFE0F",
1512
+ "\u{1F511}",
1513
+ "\u{1FA91}",
1514
+ "\u{1F9F8}",
1515
+ "\u{1F388}",
1516
+ "\u{1F380}",
1517
+ "\u{1F38A}",
1518
+ "\u267B\uFE0F",
1519
+ "\u{1F3B5}"
1520
+ ];
1521
+ var idHue = [
1522
+ "red",
1523
+ // 'orange' as const, /* More shades in these palettes are considered “ugly” */
1524
+ "amber",
1525
+ // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
1526
+ "lime",
1527
+ "green",
1528
+ "emerald",
1529
+ "teal",
1530
+ "cyan",
1531
+ // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
1532
+ // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
1533
+ // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
1534
+ "violet",
1535
+ "purple",
1536
+ "fuchsia",
1537
+ "pink",
1538
+ "rose"
1539
+ ];
1540
+ var keyToEmoji = (key) => hexToEmoji(key.toHex());
1541
+ var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
1542
+ var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
1543
+ var keyToHue = (key) => hexToHue(key.toHex());
1544
+ var hexToHue = (hex) => toHue(parseInt(hex, 16));
1545
+ var toHue = (hash) => idHue[hash % idHue.length];
1546
+ var keyToFallback = (key) => hexToFallback(key.toHex());
1547
+ var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
1548
+ var toFallback = (hash) => ({
1549
+ emoji: toEmoji(hash),
1550
+ hue: toHue(hash)
1551
+ });
1552
+
1261
1553
  // packages/common/util/src/tracer.ts
1262
1554
  var Tracer = class {
1263
1555
  constructor() {
@@ -1361,36 +1653,9 @@ var safeParseInt = (value, defaultValue) => {
1361
1653
  }
1362
1654
  };
1363
1655
 
1364
- // packages/common/util/src/instance-id.ts
1365
- var symbol = Symbol.for("dxos.instance-contexts");
1366
- var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1367
- var getPrototypeSpecificInstanceId = (instance) => {
1368
- const prototype = Object.getPrototypeOf(instance);
1369
- const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
1370
- nextId: 0,
1371
- instanceIds: /* @__PURE__ */ new WeakMap()
1372
- }));
1373
- let id = instanceCtx.instanceIds.get(instance);
1374
- if (id === void 0) {
1375
- id = instanceCtx.nextId++;
1376
- instanceCtx.instanceIds.set(instance, id);
1377
- }
1378
- return id;
1379
- };
1380
- var getDebugName = (instance) => {
1381
- if (instance == null) {
1382
- return "null";
1383
- }
1384
- const prototype = Object.getPrototypeOf(instance);
1385
- return `${prototype.constructor.name}#${getPrototypeSpecificInstanceId(instance)}`;
1386
- };
1387
-
1388
1656
  // packages/common/util/src/sum.ts
1389
1657
  var sum = (values) => values.reduce((a, b) => a + b, 0);
1390
1658
 
1391
- // packages/common/util/src/for-each-async.ts
1392
- var forEachAsync = (items, fn) => Promise.all(items.map(fn));
1393
-
1394
1659
  // packages/common/util/src/weak.ts
1395
1660
  var WeakDictionary = class {
1396
1661
  constructor(entries) {
@@ -1485,185 +1750,6 @@ var WeakDictionary = class {
1485
1750
  this._finalization.unregister(value);
1486
1751
  }
1487
1752
  };
1488
-
1489
- // packages/common/util/src/map-values.ts
1490
- var mapValues = (obj, fn) => {
1491
- const result = {};
1492
- Object.keys(obj).forEach((key) => {
1493
- result[key] = fn(obj[key], key);
1494
- });
1495
- return result;
1496
- };
1497
- var deepMapValues = (value, fn) => {
1498
- return new DeepMapper(fn).map(value);
1499
- };
1500
- var DeepMapper = class {
1501
- constructor(_fn) {
1502
- this._fn = _fn;
1503
- this._cyclic = /* @__PURE__ */ new Map();
1504
- this._recurse = (value) => {
1505
- if (this._cyclic.has(value)) {
1506
- return this._cyclic.get(value);
1507
- }
1508
- if (Array.isArray(value)) {
1509
- const res = new Array(value.length);
1510
- this._cyclic.set(value, res);
1511
- for (let i = 0; i < value.length; i++) {
1512
- res[i] = this.map(value[i]);
1513
- }
1514
- return res;
1515
- } else if (value !== null && typeof value === "object") {
1516
- const res = {};
1517
- this._cyclic.set(value, res);
1518
- for (const key in value) {
1519
- res[key] = this.map(value[key]);
1520
- }
1521
- return res;
1522
- } else {
1523
- return value;
1524
- }
1525
- };
1526
- }
1527
- map(value) {
1528
- if (this._cyclic.has(value)) {
1529
- return this._cyclic.get(value);
1530
- }
1531
- return this._fn(value, this._recurse);
1532
- }
1533
- };
1534
-
1535
- // packages/common/util/src/explicit-resource-management-polyfill.ts
1536
- Symbol.dispose ??= Symbol("Symbol.dispose");
1537
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
1538
-
1539
- // packages/common/util/src/defer.ts
1540
- var defer = (fn) => new DeferGuard(fn);
1541
- var DeferGuard = class {
1542
- /**
1543
- * @internal
1544
- */
1545
- constructor(_fn) {
1546
- this._fn = _fn;
1547
- }
1548
- [Symbol.dispose]() {
1549
- const result = this._fn();
1550
- if (result instanceof Promise) {
1551
- throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
1552
- }
1553
- }
1554
- };
1555
- var deferAsync = (fn) => new DeferAsyncGuard(fn);
1556
- var DeferAsyncGuard = class {
1557
- /**
1558
- * @internal
1559
- */
1560
- constructor(_fn) {
1561
- this._fn = _fn;
1562
- }
1563
- async [Symbol.asyncDispose]() {
1564
- await this._fn();
1565
- }
1566
- };
1567
-
1568
- // packages/common/util/src/circular-buffer.ts
1569
- import { invariant as invariant4 } from "@dxos/invariant";
1570
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
1571
- var CircularBuffer = class {
1572
- constructor(size) {
1573
- this._nextIndex = 0;
1574
- this._elementCount = 0;
1575
- invariant4(size >= 1, void 0, {
1576
- F: __dxlog_file4,
1577
- L: 13,
1578
- S: this,
1579
- A: [
1580
- "size >= 1",
1581
- ""
1582
- ]
1583
- });
1584
- this._buffer = new Array(size);
1585
- }
1586
- push(element) {
1587
- this._buffer[this._nextIndex] = element;
1588
- this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
1589
- this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
1590
- }
1591
- getLast() {
1592
- if (this._elementCount === 0) {
1593
- return void 0;
1594
- }
1595
- if (this._nextIndex === 0) {
1596
- return this._buffer[this._buffer.length - 1];
1597
- }
1598
- return this._buffer[this._nextIndex - 1];
1599
- }
1600
- [Symbol.iterator]() {
1601
- return this.values();
1602
- }
1603
- *values() {
1604
- if (this._elementCount === 0) {
1605
- return;
1606
- }
1607
- if (this._elementCount < this._buffer.length) {
1608
- for (let i = 0; i < this._elementCount; i++) {
1609
- yield this._buffer[i];
1610
- }
1611
- return;
1612
- }
1613
- for (let i = this._nextIndex; i < this._buffer.length; i++) {
1614
- yield this._buffer[i];
1615
- }
1616
- for (let i = 0; i < this._nextIndex; i++) {
1617
- yield this._buffer[i];
1618
- }
1619
- }
1620
- };
1621
-
1622
- // packages/common/util/src/join-tables.ts
1623
- var joinTables = (leftColumn, rightColumn, left, right) => {
1624
- const map = /* @__PURE__ */ new Map();
1625
- const used = /* @__PURE__ */ new Set();
1626
- for (const row of right) {
1627
- map.set(row[rightColumn], row);
1628
- }
1629
- const result = [];
1630
- for (const row of left) {
1631
- const right2 = map.get(row[leftColumn]);
1632
- used.add(right2);
1633
- result.push(Object.assign(right2 ?? {}, row));
1634
- }
1635
- for (const row of right) {
1636
- if (!used.has(row)) {
1637
- result.push(row);
1638
- }
1639
- }
1640
- return result;
1641
- };
1642
-
1643
- // packages/common/util/src/throw-unhandled-error.ts
1644
- var throwUnhandledError = (error) => {
1645
- queueMicrotask(() => {
1646
- throw error;
1647
- });
1648
- };
1649
-
1650
- // packages/common/util/src/safe-await.ts
1651
- var safeAwaitAll = async (source, taskFactory, onError) => {
1652
- const failedItems = [];
1653
- await Promise.all([
1654
- ...source
1655
- ].map(async (item, idx) => {
1656
- try {
1657
- await taskFactory(item);
1658
- } catch (err) {
1659
- if (onError) {
1660
- onError(err, item, idx);
1661
- }
1662
- failedItems.push(item);
1663
- }
1664
- }));
1665
- return failedItems;
1666
- };
1667
1753
  export {
1668
1754
  BitField,
1669
1755
  Callback,
@@ -1672,6 +1758,8 @@ export {
1672
1758
  ComplexSet,
1673
1759
  HumanHasher,
1674
1760
  MapEntry,
1761
+ ParamKeyAnnotation,
1762
+ Params,
1675
1763
  Tracer,
1676
1764
  WeakDictionary,
1677
1765
  accessBy,
@@ -1691,6 +1779,7 @@ export {
1691
1779
  createGroupReducer,
1692
1780
  createSetDispatch,
1693
1781
  deepMapValues,
1782
+ deepMapValuesAsync,
1694
1783
  defaultMap,
1695
1784
  defer,
1696
1785
  deferAsync,