@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.
@@ -35,6 +35,8 @@ __export(node_exports, {
35
35
  ComplexSet: () => ComplexSet,
36
36
  HumanHasher: () => HumanHasher,
37
37
  MapEntry: () => MapEntry,
38
+ ParamKeyAnnotation: () => ParamKeyAnnotation,
39
+ Params: () => Params,
38
40
  Tracer: () => Tracer,
39
41
  WeakDictionary: () => WeakDictionary,
40
42
  accessBy: () => accessBy,
@@ -54,6 +56,7 @@ __export(node_exports, {
54
56
  createGroupReducer: () => createGroupReducer,
55
57
  createSetDispatch: () => createSetDispatch,
56
58
  deepMapValues: () => deepMapValues,
59
+ deepMapValuesAsync: () => deepMapValuesAsync,
57
60
  defaultMap: () => defaultMap,
58
61
  defer: () => defer,
59
62
  deferAsync: () => deferAsync,
@@ -122,12 +125,14 @@ var import_invariant = require("@dxos/invariant");
122
125
  var import_node_util = __toESM(require("node:util"));
123
126
  var import_invariant2 = require("@dxos/invariant");
124
127
  var import_invariant3 = require("@dxos/invariant");
128
+ var import_invariant4 = require("@dxos/invariant");
125
129
  var import_node_util2 = require("node:util");
126
130
  var import_debug = require("@dxos/debug");
127
131
  var import_keys = require("@dxos/keys");
128
132
  var import_node_util3 = require("node:util");
129
133
  var import_keys2 = require("@dxos/keys");
130
- var import_invariant4 = require("@dxos/invariant");
134
+ var import_schema = require("@effect/schema");
135
+ var import_xcase = require("xcase");
131
136
  var diff = (previous, next, comparator) => {
132
137
  const remaining = [
133
138
  ...previous
@@ -306,6 +311,57 @@ var createSetDispatch = ({ handlers }) => {
306
311
  }
307
312
  });
308
313
  };
314
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
315
+ var CircularBuffer = class {
316
+ constructor(size) {
317
+ this._nextIndex = 0;
318
+ this._elementCount = 0;
319
+ (0, import_invariant4.invariant)(size >= 1, void 0, {
320
+ F: __dxlog_file4,
321
+ L: 13,
322
+ S: this,
323
+ A: [
324
+ "size >= 1",
325
+ ""
326
+ ]
327
+ });
328
+ this._buffer = new Array(size);
329
+ }
330
+ push(element) {
331
+ this._buffer[this._nextIndex] = element;
332
+ this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
333
+ this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
334
+ }
335
+ getLast() {
336
+ if (this._elementCount === 0) {
337
+ return void 0;
338
+ }
339
+ if (this._nextIndex === 0) {
340
+ return this._buffer[this._buffer.length - 1];
341
+ }
342
+ return this._buffer[this._nextIndex - 1];
343
+ }
344
+ [Symbol.iterator]() {
345
+ return this.values();
346
+ }
347
+ *values() {
348
+ if (this._elementCount === 0) {
349
+ return;
350
+ }
351
+ if (this._elementCount < this._buffer.length) {
352
+ for (let i = 0; i < this._elementCount; i++) {
353
+ yield this._buffer[i];
354
+ }
355
+ return;
356
+ }
357
+ for (let i = this._nextIndex; i < this._buffer.length; i++) {
358
+ yield this._buffer[i];
359
+ }
360
+ for (let i = 0; i < this._nextIndex; i++) {
361
+ yield this._buffer[i];
362
+ }
363
+ }
364
+ };
309
365
  var MAX_SERIALIZATION_LENGTH = 10;
310
366
  var ComplexSet = class {
311
367
  // prettier-ignore
@@ -467,203 +523,55 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
467
523
  super(keyProjection, entries);
468
524
  }
469
525
  };
470
- var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
471
- var idEmoji = [
472
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
473
- // 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.
474
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
475
- // – not people or isolated anthropomorphic faces
476
- // – not flags
477
- // – more concrete than abstract
478
- // – less culturally specific
479
- // – less easily confused with another emoji in the set
480
- // – requires less special knowledge to identify
481
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
482
- // – less common as a signifier in UX
483
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
484
- "\u{1F479}",
485
- "\u{1F47B}",
486
- "\u{1F47D}",
487
- "\u{1F916}",
488
- "\u{1F383}",
489
- "\u{1F9BE}",
490
- "\u{1F9BF}",
491
- "\u{1F9B7}",
492
- "\u{1F463}",
493
- "\u{1F441}\uFE0F",
494
- "\u{1F9F6}",
495
- "\u{1F451}",
496
- "\u{1F412}",
497
- "\u{1F986}",
498
- "\u{1F989}",
499
- "\u{1F434}",
500
- "\u{1F984}",
501
- "\u{1F41D}",
502
- "\u{1F98B}",
503
- "\u{1F41E}",
504
- "\u{1FAB2}",
505
- "\u{1F422}",
506
- "\u{1F98E}",
507
- "\u{1F995}",
508
- "\u{1F991}",
509
- "\u{1F980}",
510
- "\u{1F420}",
511
- "\u{1F42C}",
512
- "\u{1F40B}",
513
- "\u{1F9AD}",
514
- "\u{1F405}",
515
- "\u{1F406}",
516
- "\u{1F993}",
517
- "\u{1F98D}",
518
- "\u{1F9A7}",
519
- "\u{1F418}",
520
- "\u{1F42B}",
521
- "\u{1F992}",
522
- "\u{1F998}",
523
- "\u{1F9AC}",
524
- "\u{1F416}",
525
- "\u{1F40F}",
526
- "\u{1F98C}",
527
- "\u{1F415}",
528
- "\u{1F408}",
529
- "\u{1F413}",
530
- "\u{1F99A}",
531
- "\u{1F99C}",
532
- "\u{1F9A2}",
533
- "\u{1F9A9}",
534
- "\u{1F9A6}",
535
- "\u{1F401}",
536
- "\u{1F43F}\uFE0F",
537
- "\u{1F335}",
538
- "\u{1F332}",
539
- "\u{1F333}",
540
- "\u{1FAB5}",
541
- "\u{1F331}",
542
- "\u{1F341}",
543
- "\u{1FABA}",
544
- "\u{1F344}",
545
- "\u{1F41A}",
546
- "\u{1FAB8}",
547
- "\u{1FAA8}",
548
- "\u{1F33E}",
549
- "\u{1F337}",
550
- "\u{1F33B}",
551
- "\u2600\uFE0F",
552
- "\u{1F319}",
553
- "\u{1FA90}",
554
- "\u2B50\uFE0F",
555
- "\u26A1\uFE0F",
556
- "\u2604\uFE0F",
557
- "\u{1F525}",
558
- "\u{1F308}",
559
- "\u2601\uFE0F",
560
- "\u{1F4A7}",
561
- "\u26F1\uFE0F",
562
- "\u{1F30A}",
563
- "\u{1F34E}",
564
- "\u{1F34B}",
565
- "\u{1F349}",
566
- "\u{1F347}",
567
- "\u{1FAD0}",
568
- "\u{1F348}",
569
- "\u{1F352}",
570
- "\u{1F351}",
571
- "\u{1F96D}",
572
- "\u{1F34D}",
573
- "\u{1F965}",
574
- "\u{1F95D}",
575
- "\u{1F951}",
576
- "\u{1F336}\uFE0F",
577
- "\u{1F33D}",
578
- "\u{1F955}",
579
- "\u{1F36C}",
580
- "\u{1F95C}",
581
- "\u{1FAD6}",
582
- "\u2615\uFE0F",
583
- "\u{1F375}",
584
- "\u{1F9CA}",
585
- "\u{1F9C2}",
586
- "\u{1F3D4}\uFE0F",
587
- "\u2693\uFE0F",
588
- "\u{1F6DF}",
589
- "\u{1F3DD}\uFE0F",
590
- "\u{1F6F6}",
591
- "\u{1F680}",
592
- "\u{1F6F0}\uFE0F",
593
- "\u26F2\uFE0F",
594
- "\u{1F3F0}",
595
- "\u{1F6B2}",
596
- "\u26FA\uFE0F",
597
- "\u{1F399}\uFE0F",
598
- "\u{1F9F2}",
599
- "\u2699\uFE0F",
600
- "\u{1F529}",
601
- "\u{1F52E}",
602
- "\u{1F52D}",
603
- "\u{1F52C}",
604
- "\u{1F9EC}",
605
- "\u{1F321}\uFE0F",
606
- "\u{1F9FA}",
607
- "\u{1F6CE}\uFE0F",
608
- "\u{1F511}",
609
- "\u{1FA91}",
610
- "\u{1F9F8}",
611
- "\u{1F388}",
612
- "\u{1F380}",
613
- "\u{1F38A}",
614
- "\u267B\uFE0F",
615
- "\u{1F3B5}"
616
- ];
617
- var idHue = [
618
- "red",
619
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
620
- "amber",
621
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
622
- "lime",
623
- "green",
624
- "emerald",
625
- "teal",
626
- "cyan",
627
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
628
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
629
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
630
- "violet",
631
- "purple",
632
- "fuchsia",
633
- "pink",
634
- "rose"
635
- ];
636
- var keyToEmoji = (key) => hexToEmoji(key.toHex());
637
- var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
638
- var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
639
- var keyToHue = (key) => hexToHue(key.toHex());
640
- var hexToHue = (hex) => toHue(parseInt(hex, 16));
641
- var toHue = (hash) => idHue[hash % idHue.length];
642
- var keyToFallback = (key) => hexToFallback(key.toHex());
643
- var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
644
- var toFallback = (hash) => ({
645
- emoji: toEmoji(hash),
646
- hue: toHue(hash)
647
- });
648
- var entry = (map, key) => new MapEntry(map, key);
649
- var MapEntry = class {
526
+ Symbol.dispose ??= Symbol("Symbol.dispose");
527
+ Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
528
+ var defer = (fn) => new DeferGuard(fn);
529
+ var DeferGuard = class {
650
530
  /**
651
531
  * @internal
652
532
  */
653
- // prettier-ignore
654
- constructor(_map, _key) {
655
- this._map = _map;
656
- this._key = _key;
657
- }
658
- get key() {
659
- return this._key;
660
- }
661
- get value() {
662
- return this._map.get(this._key);
533
+ constructor(_fn) {
534
+ this._fn = _fn;
663
535
  }
664
- orInsert(value) {
665
- if (!this._map.has(this._key)) {
666
- this._map.set(this._key, value);
536
+ [Symbol.dispose]() {
537
+ const result = this._fn();
538
+ if (result instanceof Promise) {
539
+ throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
540
+ }
541
+ }
542
+ };
543
+ var deferAsync = (fn) => new DeferAsyncGuard(fn);
544
+ var DeferAsyncGuard = class {
545
+ /**
546
+ * @internal
547
+ */
548
+ constructor(_fn) {
549
+ this._fn = _fn;
550
+ }
551
+ async [Symbol.asyncDispose]() {
552
+ await this._fn();
553
+ }
554
+ };
555
+ var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
556
+ var entry = (map, key) => new MapEntry(map, key);
557
+ var MapEntry = class {
558
+ /**
559
+ * @internal
560
+ */
561
+ // prettier-ignore
562
+ constructor(_map, _key) {
563
+ this._map = _map;
564
+ this._key = _key;
565
+ }
566
+ get key() {
567
+ return this._key;
568
+ }
569
+ get value() {
570
+ return this._map.get(this._key);
571
+ }
572
+ orInsert(value) {
573
+ if (!this._map.has(this._key)) {
574
+ this._map.set(this._key, value);
667
575
  }
668
576
  return this;
669
577
  }
@@ -671,6 +579,7 @@ var MapEntry = class {
671
579
  return entry(this.value, key);
672
580
  }
673
581
  };
582
+ var forEachAsync = (items, fn) => Promise.all(items.map(fn));
674
583
  var DEFAULT_WORDLIST = [
675
584
  "ack",
676
585
  "alabama",
@@ -1009,6 +918,55 @@ var exponentialBackoffInterval = (cb, initialInterval) => {
1009
918
  let timeoutId = setTimeout(repeat, interval);
1010
919
  return () => clearTimeout(timeoutId);
1011
920
  };
921
+ var defaultMap = (map, key, def) => {
922
+ let value = map.get(key);
923
+ if (value === void 0) {
924
+ value = typeof def === "function" ? def() : def;
925
+ map.set(key, value);
926
+ }
927
+ return value;
928
+ };
929
+ var symbol = Symbol.for("dxos.instance-contexts");
930
+ var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
931
+ var getPrototypeSpecificInstanceId = (instance) => {
932
+ const prototype = Object.getPrototypeOf(instance);
933
+ const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
934
+ nextId: 0,
935
+ instanceIds: /* @__PURE__ */ new WeakMap()
936
+ }));
937
+ let id = instanceCtx.instanceIds.get(instance);
938
+ if (id === void 0) {
939
+ id = instanceCtx.nextId++;
940
+ instanceCtx.instanceIds.set(instance, id);
941
+ }
942
+ return id;
943
+ };
944
+ var getDebugName = (instance) => {
945
+ if (instance == null) {
946
+ return "null";
947
+ }
948
+ const prototype = Object.getPrototypeOf(instance);
949
+ return `${prototype.constructor.name}#${getPrototypeSpecificInstanceId(instance)}`;
950
+ };
951
+ var joinTables = (leftColumn, rightColumn, left, right) => {
952
+ const map = /* @__PURE__ */ new Map();
953
+ const used = /* @__PURE__ */ new Set();
954
+ for (const row of right) {
955
+ map.set(row[rightColumn], row);
956
+ }
957
+ const result = [];
958
+ for (const row of left) {
959
+ const right2 = map.get(row[leftColumn]);
960
+ used.add(right2);
961
+ result.push(Object.assign(right2 ?? {}, row));
962
+ }
963
+ for (const row of right) {
964
+ if (!used.has(row)) {
965
+ result.push(row);
966
+ }
967
+ }
968
+ return result;
969
+ };
1012
970
  var arraysEqual = (a, b) => {
1013
971
  if (a.length !== b.length) {
1014
972
  return false;
@@ -1117,13 +1075,86 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1117
1075
  }
1118
1076
  return value;
1119
1077
  };
1120
- var defaultMap = (map, key, def) => {
1121
- let value = map.get(key);
1122
- if (value === void 0) {
1123
- value = typeof def === "function" ? def() : def;
1124
- map.set(key, value);
1078
+ var mapValues = (obj, fn) => {
1079
+ const result = {};
1080
+ Object.keys(obj).forEach((key) => {
1081
+ result[key] = fn(obj[key], key);
1082
+ });
1083
+ return result;
1084
+ };
1085
+ var deepMapValues = (value, fn) => {
1086
+ return new DeepMapper(fn).map(value);
1087
+ };
1088
+ var DeepMapper = class {
1089
+ constructor(_fn) {
1090
+ this._fn = _fn;
1091
+ this._cyclic = /* @__PURE__ */ new Map();
1092
+ this._recurse = (value) => {
1093
+ if (this._cyclic.has(value)) {
1094
+ return this._cyclic.get(value);
1095
+ }
1096
+ if (Array.isArray(value)) {
1097
+ const res = new Array(value.length);
1098
+ this._cyclic.set(value, res);
1099
+ for (let i = 0; i < value.length; i++) {
1100
+ res[i] = this.map(value[i]);
1101
+ }
1102
+ return res;
1103
+ } else if (value !== null && typeof value === "object") {
1104
+ const res = {};
1105
+ this._cyclic.set(value, res);
1106
+ for (const key in value) {
1107
+ res[key] = this.map(value[key]);
1108
+ }
1109
+ return res;
1110
+ } else {
1111
+ return value;
1112
+ }
1113
+ };
1114
+ }
1115
+ map(value) {
1116
+ if (this._cyclic.has(value)) {
1117
+ return this._cyclic.get(value);
1118
+ }
1119
+ return this._fn(value, this._recurse);
1120
+ }
1121
+ };
1122
+ var deepMapValuesAsync = (value, fn) => {
1123
+ return new DeepMapperAsync(fn).map(value);
1124
+ };
1125
+ var DeepMapperAsync = class {
1126
+ constructor(_fn) {
1127
+ this._fn = _fn;
1128
+ this._cyclic = /* @__PURE__ */ new Map();
1129
+ this._recurse = async (value) => {
1130
+ if (this._cyclic.has(value)) {
1131
+ return this._cyclic.get(value);
1132
+ }
1133
+ if (Array.isArray(value)) {
1134
+ const res = new Array(value.length);
1135
+ this._cyclic.set(value, res);
1136
+ for (let i = 0; i < value.length; i++) {
1137
+ res[i] = await this.map(value[i]);
1138
+ }
1139
+ return res;
1140
+ } else if (value !== null && typeof value === "object") {
1141
+ const res = {};
1142
+ this._cyclic.set(value, res);
1143
+ for (const key in value) {
1144
+ res[key] = await this.map(value[key]);
1145
+ }
1146
+ return res;
1147
+ } else {
1148
+ return value;
1149
+ }
1150
+ };
1151
+ }
1152
+ map(value) {
1153
+ if (this._cyclic.has(value)) {
1154
+ return this._cyclic.get(value);
1155
+ }
1156
+ return this._fn(value, this._recurse);
1125
1157
  }
1126
- return value;
1127
1158
  };
1128
1159
  var inferObjectOrder = (objectMap, order = []) => {
1129
1160
  const orderedObjects = order.reduce((acc, id) => {
@@ -1150,6 +1181,51 @@ var inferRecordOrder = (objectMap, order = []) => {
1150
1181
  return acc;
1151
1182
  }, {}), objectMap);
1152
1183
  };
1184
+ var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKeyAnnotation");
1185
+ var ParamKeyAnnotation = (value) => (self) => self.annotations({
1186
+ [ParamKeyAnnotationId]: value
1187
+ });
1188
+ var Params = class {
1189
+ constructor(_schema) {
1190
+ this._schema = _schema;
1191
+ }
1192
+ /**
1193
+ * Parse URL params.
1194
+ * @param url
1195
+ */
1196
+ parse(url) {
1197
+ return Object.entries(this._schema.fields).reduce((acc, [key, type]) => {
1198
+ let v = url.searchParams.get((0, import_xcase.decamelize)(key));
1199
+ if (v == null) {
1200
+ v = url.searchParams.get(key);
1201
+ }
1202
+ if (v != null) {
1203
+ if (import_schema.AST.isNumberKeyword(type.ast)) {
1204
+ acc[key] = parseInt(v);
1205
+ } else if (import_schema.AST.isBooleanKeyword(type.ast)) {
1206
+ acc[key] = v === "true" || v === "1";
1207
+ } else {
1208
+ acc[key] = v;
1209
+ }
1210
+ }
1211
+ return acc;
1212
+ }, {});
1213
+ }
1214
+ /**
1215
+ * Update URL with params.
1216
+ */
1217
+ params(url, values) {
1218
+ Object.entries(values).forEach(([key, value]) => {
1219
+ const type = this._schema.fields[key];
1220
+ if (type && value != null) {
1221
+ const { value: alt } = import_schema.AST.getAnnotation(ParamKeyAnnotationId)(type.ast);
1222
+ const k = alt ?? (0, import_xcase.decamelize)(key);
1223
+ url.searchParams.set(k, String(value));
1224
+ }
1225
+ });
1226
+ return url;
1227
+ }
1228
+ };
1153
1229
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1154
1230
  var mobileAndTabletCheck = () => {
1155
1231
  let check = false;
@@ -1285,6 +1361,22 @@ var createBucketReducer = (period) => ({
1285
1361
  return series;
1286
1362
  }
1287
1363
  });
1364
+ var safeAwaitAll = async (source, taskFactory, onError) => {
1365
+ const failedItems = [];
1366
+ await Promise.all([
1367
+ ...source
1368
+ ].map(async (item, idx) => {
1369
+ try {
1370
+ await taskFactory(item);
1371
+ } catch (err) {
1372
+ if (onError) {
1373
+ onError(err, item, idx);
1374
+ }
1375
+ failedItems.push(item);
1376
+ }
1377
+ }));
1378
+ return failedItems;
1379
+ };
1288
1380
  var instanceTag = Symbol("instanceTag");
1289
1381
  var safeInstanceof = (tag) => (target) => {
1290
1382
  target.prototype[instanceTag] = tag;
@@ -1324,68 +1416,250 @@ var compareMulti = (sorters) => (a, b) => {
1324
1416
  };
1325
1417
  return sort();
1326
1418
  };
1327
- var Tracer = class {
1328
- constructor() {
1329
- this._events = /* @__PURE__ */ new Map();
1330
- this._recording = false;
1331
- }
1332
- // TODO(burdon): Start/stop methods for recording data? By id?
1333
- // Alternatively, enable subscriptions to track/compute series.
1334
- // TODO(burdon): Hierarchical traces?
1335
- get recording() {
1336
- return this._recording;
1337
- }
1338
- keys() {
1339
- return Array.from(this._events.keys());
1340
- }
1341
- get(id, filter) {
1342
- const events = this._events.get(id);
1343
- if (filter) {
1344
- return events?.filter((event) => Object.entries(filter).every(([key, value]) => event?.value[key] === value));
1345
- }
1346
- return events;
1347
- }
1348
- clear() {
1349
- this._events.clear();
1350
- }
1351
- start() {
1352
- this._recording = true;
1353
- return this;
1354
- }
1355
- stop() {
1356
- this._recording = false;
1357
- return this;
1358
- }
1359
- emit(id, value) {
1360
- this._post(this._createEvent(id, value));
1361
- }
1362
- mark(id, value) {
1363
- const event = this._createEvent(id, value);
1364
- const start = performance.now();
1365
- return {
1366
- start,
1367
- end: () => {
1368
- event.duration = performance.now() - start;
1369
- this._post(event);
1370
- }
1371
- };
1372
- }
1373
- _createEvent(id, value) {
1374
- const event = {
1375
- id,
1376
- timestamp: Date.now()
1377
- };
1378
- if (value !== void 0) {
1379
- event.value = value;
1380
- }
1381
- return event;
1382
- }
1383
- _post(event) {
1384
- if (this._recording) {
1385
- defaultMap(this._events, event.id, []).push(event);
1386
- }
1387
- }
1388
- };
1419
+ var throwUnhandledError = (error) => {
1420
+ queueMicrotask(() => {
1421
+ throw error;
1422
+ });
1423
+ };
1424
+ var idEmoji = [
1425
+ // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
1426
+ // 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.
1427
+ // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
1428
+ // – not people or isolated anthropomorphic faces
1429
+ // – not flags
1430
+ // – more concrete than abstract
1431
+ // – less culturally specific
1432
+ // – less easily confused with another emoji in the set
1433
+ // requires less special knowledge to identify
1434
+ // less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1435
+ // less common as a signifier in UX
1436
+ // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1437
+ "\u{1F479}",
1438
+ "\u{1F47B}",
1439
+ "\u{1F47D}",
1440
+ "\u{1F916}",
1441
+ "\u{1F383}",
1442
+ "\u{1F9BE}",
1443
+ "\u{1F9BF}",
1444
+ "\u{1F9B7}",
1445
+ "\u{1F463}",
1446
+ "\u{1F441}\uFE0F",
1447
+ "\u{1F9F6}",
1448
+ "\u{1F451}",
1449
+ "\u{1F412}",
1450
+ "\u{1F986}",
1451
+ "\u{1F989}",
1452
+ "\u{1F434}",
1453
+ "\u{1F984}",
1454
+ "\u{1F41D}",
1455
+ "\u{1F98B}",
1456
+ "\u{1F41E}",
1457
+ "\u{1FAB2}",
1458
+ "\u{1F422}",
1459
+ "\u{1F98E}",
1460
+ "\u{1F995}",
1461
+ "\u{1F991}",
1462
+ "\u{1F980}",
1463
+ "\u{1F420}",
1464
+ "\u{1F42C}",
1465
+ "\u{1F40B}",
1466
+ "\u{1F9AD}",
1467
+ "\u{1F405}",
1468
+ "\u{1F406}",
1469
+ "\u{1F993}",
1470
+ "\u{1F98D}",
1471
+ "\u{1F9A7}",
1472
+ "\u{1F418}",
1473
+ "\u{1F42B}",
1474
+ "\u{1F992}",
1475
+ "\u{1F998}",
1476
+ "\u{1F9AC}",
1477
+ "\u{1F416}",
1478
+ "\u{1F40F}",
1479
+ "\u{1F98C}",
1480
+ "\u{1F415}",
1481
+ "\u{1F408}",
1482
+ "\u{1F413}",
1483
+ "\u{1F99A}",
1484
+ "\u{1F99C}",
1485
+ "\u{1F9A2}",
1486
+ "\u{1F9A9}",
1487
+ "\u{1F9A6}",
1488
+ "\u{1F401}",
1489
+ "\u{1F43F}\uFE0F",
1490
+ "\u{1F335}",
1491
+ "\u{1F332}",
1492
+ "\u{1F333}",
1493
+ "\u{1FAB5}",
1494
+ "\u{1F331}",
1495
+ "\u{1F341}",
1496
+ "\u{1FABA}",
1497
+ "\u{1F344}",
1498
+ "\u{1F41A}",
1499
+ "\u{1FAB8}",
1500
+ "\u{1FAA8}",
1501
+ "\u{1F33E}",
1502
+ "\u{1F337}",
1503
+ "\u{1F33B}",
1504
+ "\u2600\uFE0F",
1505
+ "\u{1F319}",
1506
+ "\u{1FA90}",
1507
+ "\u2B50\uFE0F",
1508
+ "\u26A1\uFE0F",
1509
+ "\u2604\uFE0F",
1510
+ "\u{1F525}",
1511
+ "\u{1F308}",
1512
+ "\u2601\uFE0F",
1513
+ "\u{1F4A7}",
1514
+ "\u26F1\uFE0F",
1515
+ "\u{1F30A}",
1516
+ "\u{1F34E}",
1517
+ "\u{1F34B}",
1518
+ "\u{1F349}",
1519
+ "\u{1F347}",
1520
+ "\u{1FAD0}",
1521
+ "\u{1F348}",
1522
+ "\u{1F352}",
1523
+ "\u{1F351}",
1524
+ "\u{1F96D}",
1525
+ "\u{1F34D}",
1526
+ "\u{1F965}",
1527
+ "\u{1F95D}",
1528
+ "\u{1F951}",
1529
+ "\u{1F336}\uFE0F",
1530
+ "\u{1F33D}",
1531
+ "\u{1F955}",
1532
+ "\u{1F36C}",
1533
+ "\u{1F95C}",
1534
+ "\u{1FAD6}",
1535
+ "\u2615\uFE0F",
1536
+ "\u{1F375}",
1537
+ "\u{1F9CA}",
1538
+ "\u{1F9C2}",
1539
+ "\u{1F3D4}\uFE0F",
1540
+ "\u2693\uFE0F",
1541
+ "\u{1F6DF}",
1542
+ "\u{1F3DD}\uFE0F",
1543
+ "\u{1F6F6}",
1544
+ "\u{1F680}",
1545
+ "\u{1F6F0}\uFE0F",
1546
+ "\u26F2\uFE0F",
1547
+ "\u{1F3F0}",
1548
+ "\u{1F6B2}",
1549
+ "\u26FA\uFE0F",
1550
+ "\u{1F399}\uFE0F",
1551
+ "\u{1F9F2}",
1552
+ "\u2699\uFE0F",
1553
+ "\u{1F529}",
1554
+ "\u{1F52E}",
1555
+ "\u{1F52D}",
1556
+ "\u{1F52C}",
1557
+ "\u{1F9EC}",
1558
+ "\u{1F321}\uFE0F",
1559
+ "\u{1F9FA}",
1560
+ "\u{1F6CE}\uFE0F",
1561
+ "\u{1F511}",
1562
+ "\u{1FA91}",
1563
+ "\u{1F9F8}",
1564
+ "\u{1F388}",
1565
+ "\u{1F380}",
1566
+ "\u{1F38A}",
1567
+ "\u267B\uFE0F",
1568
+ "\u{1F3B5}"
1569
+ ];
1570
+ var idHue = [
1571
+ "red",
1572
+ // 'orange' as const, /* More shades in these palettes are considered “ugly” */
1573
+ "amber",
1574
+ // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
1575
+ "lime",
1576
+ "green",
1577
+ "emerald",
1578
+ "teal",
1579
+ "cyan",
1580
+ // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
1581
+ // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
1582
+ // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
1583
+ "violet",
1584
+ "purple",
1585
+ "fuchsia",
1586
+ "pink",
1587
+ "rose"
1588
+ ];
1589
+ var keyToEmoji = (key) => hexToEmoji(key.toHex());
1590
+ var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
1591
+ var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
1592
+ var keyToHue = (key) => hexToHue(key.toHex());
1593
+ var hexToHue = (hex) => toHue(parseInt(hex, 16));
1594
+ var toHue = (hash) => idHue[hash % idHue.length];
1595
+ var keyToFallback = (key) => hexToFallback(key.toHex());
1596
+ var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
1597
+ var toFallback = (hash) => ({
1598
+ emoji: toEmoji(hash),
1599
+ hue: toHue(hash)
1600
+ });
1601
+ var Tracer = class {
1602
+ constructor() {
1603
+ this._events = /* @__PURE__ */ new Map();
1604
+ this._recording = false;
1605
+ }
1606
+ // TODO(burdon): Start/stop methods for recording data? By id?
1607
+ // Alternatively, enable subscriptions to track/compute series.
1608
+ // TODO(burdon): Hierarchical traces?
1609
+ get recording() {
1610
+ return this._recording;
1611
+ }
1612
+ keys() {
1613
+ return Array.from(this._events.keys());
1614
+ }
1615
+ get(id, filter) {
1616
+ const events = this._events.get(id);
1617
+ if (filter) {
1618
+ return events?.filter((event) => Object.entries(filter).every(([key, value]) => event?.value[key] === value));
1619
+ }
1620
+ return events;
1621
+ }
1622
+ clear() {
1623
+ this._events.clear();
1624
+ }
1625
+ start() {
1626
+ this._recording = true;
1627
+ return this;
1628
+ }
1629
+ stop() {
1630
+ this._recording = false;
1631
+ return this;
1632
+ }
1633
+ emit(id, value) {
1634
+ this._post(this._createEvent(id, value));
1635
+ }
1636
+ mark(id, value) {
1637
+ const event = this._createEvent(id, value);
1638
+ const start = performance.now();
1639
+ return {
1640
+ start,
1641
+ end: () => {
1642
+ event.duration = performance.now() - start;
1643
+ this._post(event);
1644
+ }
1645
+ };
1646
+ }
1647
+ _createEvent(id, value) {
1648
+ const event = {
1649
+ id,
1650
+ timestamp: Date.now()
1651
+ };
1652
+ if (value !== void 0) {
1653
+ event.value = value;
1654
+ }
1655
+ return event;
1656
+ }
1657
+ _post(event) {
1658
+ if (this._recording) {
1659
+ defaultMap(this._events, event.id, []).push(event);
1660
+ }
1661
+ }
1662
+ };
1389
1663
  var tracer = new Tracer();
1390
1664
  var isNotFalsy = (value) => !!value;
1391
1665
  var nonNullable = (value) => value !== null && value !== void 0;
@@ -1423,30 +1697,7 @@ var safeParseInt = (value, defaultValue) => {
1423
1697
  return defaultValue;
1424
1698
  }
1425
1699
  };
1426
- var symbol = Symbol.for("dxos.instance-contexts");
1427
- var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1428
- var getPrototypeSpecificInstanceId = (instance) => {
1429
- const prototype = Object.getPrototypeOf(instance);
1430
- const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
1431
- nextId: 0,
1432
- instanceIds: /* @__PURE__ */ new WeakMap()
1433
- }));
1434
- let id = instanceCtx.instanceIds.get(instance);
1435
- if (id === void 0) {
1436
- id = instanceCtx.nextId++;
1437
- instanceCtx.instanceIds.set(instance, id);
1438
- }
1439
- return id;
1440
- };
1441
- var getDebugName = (instance) => {
1442
- if (instance == null) {
1443
- return "null";
1444
- }
1445
- const prototype = Object.getPrototypeOf(instance);
1446
- return `${prototype.constructor.name}#${getPrototypeSpecificInstanceId(instance)}`;
1447
- };
1448
1700
  var sum = (values) => values.reduce((a, b) => a + b, 0);
1449
- var forEachAsync = (items, fn) => Promise.all(items.map(fn));
1450
1701
  var WeakDictionary = class {
1451
1702
  constructor(entries) {
1452
1703
  this._internal = /* @__PURE__ */ new Map();
@@ -1540,170 +1791,6 @@ var WeakDictionary = class {
1540
1791
  this._finalization.unregister(value);
1541
1792
  }
1542
1793
  };
1543
- var mapValues = (obj, fn) => {
1544
- const result = {};
1545
- Object.keys(obj).forEach((key) => {
1546
- result[key] = fn(obj[key], key);
1547
- });
1548
- return result;
1549
- };
1550
- var deepMapValues = (value, fn) => {
1551
- return new DeepMapper(fn).map(value);
1552
- };
1553
- var DeepMapper = class {
1554
- constructor(_fn) {
1555
- this._fn = _fn;
1556
- this._cyclic = /* @__PURE__ */ new Map();
1557
- this._recurse = (value) => {
1558
- if (this._cyclic.has(value)) {
1559
- return this._cyclic.get(value);
1560
- }
1561
- if (Array.isArray(value)) {
1562
- const res = new Array(value.length);
1563
- this._cyclic.set(value, res);
1564
- for (let i = 0; i < value.length; i++) {
1565
- res[i] = this.map(value[i]);
1566
- }
1567
- return res;
1568
- } else if (value !== null && typeof value === "object") {
1569
- const res = {};
1570
- this._cyclic.set(value, res);
1571
- for (const key in value) {
1572
- res[key] = this.map(value[key]);
1573
- }
1574
- return res;
1575
- } else {
1576
- return value;
1577
- }
1578
- };
1579
- }
1580
- map(value) {
1581
- if (this._cyclic.has(value)) {
1582
- return this._cyclic.get(value);
1583
- }
1584
- return this._fn(value, this._recurse);
1585
- }
1586
- };
1587
- Symbol.dispose ??= Symbol("Symbol.dispose");
1588
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
1589
- var defer = (fn) => new DeferGuard(fn);
1590
- var DeferGuard = class {
1591
- /**
1592
- * @internal
1593
- */
1594
- constructor(_fn) {
1595
- this._fn = _fn;
1596
- }
1597
- [Symbol.dispose]() {
1598
- const result = this._fn();
1599
- if (result instanceof Promise) {
1600
- throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
1601
- }
1602
- }
1603
- };
1604
- var deferAsync = (fn) => new DeferAsyncGuard(fn);
1605
- var DeferAsyncGuard = class {
1606
- /**
1607
- * @internal
1608
- */
1609
- constructor(_fn) {
1610
- this._fn = _fn;
1611
- }
1612
- async [Symbol.asyncDispose]() {
1613
- await this._fn();
1614
- }
1615
- };
1616
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
1617
- var CircularBuffer = class {
1618
- constructor(size) {
1619
- this._nextIndex = 0;
1620
- this._elementCount = 0;
1621
- (0, import_invariant4.invariant)(size >= 1, void 0, {
1622
- F: __dxlog_file4,
1623
- L: 13,
1624
- S: this,
1625
- A: [
1626
- "size >= 1",
1627
- ""
1628
- ]
1629
- });
1630
- this._buffer = new Array(size);
1631
- }
1632
- push(element) {
1633
- this._buffer[this._nextIndex] = element;
1634
- this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
1635
- this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
1636
- }
1637
- getLast() {
1638
- if (this._elementCount === 0) {
1639
- return void 0;
1640
- }
1641
- if (this._nextIndex === 0) {
1642
- return this._buffer[this._buffer.length - 1];
1643
- }
1644
- return this._buffer[this._nextIndex - 1];
1645
- }
1646
- [Symbol.iterator]() {
1647
- return this.values();
1648
- }
1649
- *values() {
1650
- if (this._elementCount === 0) {
1651
- return;
1652
- }
1653
- if (this._elementCount < this._buffer.length) {
1654
- for (let i = 0; i < this._elementCount; i++) {
1655
- yield this._buffer[i];
1656
- }
1657
- return;
1658
- }
1659
- for (let i = this._nextIndex; i < this._buffer.length; i++) {
1660
- yield this._buffer[i];
1661
- }
1662
- for (let i = 0; i < this._nextIndex; i++) {
1663
- yield this._buffer[i];
1664
- }
1665
- }
1666
- };
1667
- var joinTables = (leftColumn, rightColumn, left, right) => {
1668
- const map = /* @__PURE__ */ new Map();
1669
- const used = /* @__PURE__ */ new Set();
1670
- for (const row of right) {
1671
- map.set(row[rightColumn], row);
1672
- }
1673
- const result = [];
1674
- for (const row of left) {
1675
- const right2 = map.get(row[leftColumn]);
1676
- used.add(right2);
1677
- result.push(Object.assign(right2 ?? {}, row));
1678
- }
1679
- for (const row of right) {
1680
- if (!used.has(row)) {
1681
- result.push(row);
1682
- }
1683
- }
1684
- return result;
1685
- };
1686
- var throwUnhandledError = (error) => {
1687
- queueMicrotask(() => {
1688
- throw error;
1689
- });
1690
- };
1691
- var safeAwaitAll = async (source, taskFactory, onError) => {
1692
- const failedItems = [];
1693
- await Promise.all([
1694
- ...source
1695
- ].map(async (item, idx) => {
1696
- try {
1697
- await taskFactory(item);
1698
- } catch (err) {
1699
- if (onError) {
1700
- onError(err, item, idx);
1701
- }
1702
- failedItems.push(item);
1703
- }
1704
- }));
1705
- return failedItems;
1706
- };
1707
1794
  // Annotate the CommonJS export names for ESM import in node:
1708
1795
  0 && (module.exports = {
1709
1796
  BitField,
@@ -1713,6 +1800,8 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
1713
1800
  ComplexSet,
1714
1801
  HumanHasher,
1715
1802
  MapEntry,
1803
+ ParamKeyAnnotation,
1804
+ Params,
1716
1805
  Tracer,
1717
1806
  WeakDictionary,
1718
1807
  accessBy,
@@ -1732,6 +1821,7 @@ var safeAwaitAll = async (source, taskFactory, onError) => {
1732
1821
  createGroupReducer,
1733
1822
  createSetDispatch,
1734
1823
  deepMapValues,
1824
+ deepMapValuesAsync,
1735
1825
  defaultMap,
1736
1826
  defer,
1737
1827
  deferAsync,