@dxos/util 0.5.9-main.bdf733d → 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,
@@ -104,6 +107,7 @@ __export(node_exports, {
104
107
  reduceSeries: () => reduceSeries,
105
108
  reduceSet: () => reduceSet,
106
109
  safariCheck: () => safariCheck,
110
+ safeAwaitAll: () => safeAwaitAll,
107
111
  safeInstanceof: () => safeInstanceof,
108
112
  safeParseInt: () => safeParseInt,
109
113
  safeParseJson: () => safeParseJson,
@@ -121,12 +125,14 @@ var import_invariant = require("@dxos/invariant");
121
125
  var import_node_util = __toESM(require("node:util"));
122
126
  var import_invariant2 = require("@dxos/invariant");
123
127
  var import_invariant3 = require("@dxos/invariant");
128
+ var import_invariant4 = require("@dxos/invariant");
124
129
  var import_node_util2 = require("node:util");
125
130
  var import_debug = require("@dxos/debug");
126
131
  var import_keys = require("@dxos/keys");
127
132
  var import_node_util3 = require("node:util");
128
133
  var import_keys2 = require("@dxos/keys");
129
- var import_invariant4 = require("@dxos/invariant");
134
+ var import_schema = require("@effect/schema");
135
+ var import_xcase = require("xcase");
130
136
  var diff = (previous, next, comparator) => {
131
137
  const remaining = [
132
138
  ...previous
@@ -305,6 +311,57 @@ var createSetDispatch = ({ handlers }) => {
305
311
  }
306
312
  });
307
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
+ };
308
365
  var MAX_SERIALIZATION_LENGTH = 10;
309
366
  var ComplexSet = class {
310
367
  // prettier-ignore
@@ -466,203 +523,55 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
466
523
  super(keyProjection, entries);
467
524
  }
468
525
  };
469
- var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
470
- var idEmoji = [
471
- // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
472
- // 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.
473
- // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
474
- // – not people or isolated anthropomorphic faces
475
- // – not flags
476
- // – more concrete than abstract
477
- // – less culturally specific
478
- // – less easily confused with another emoji in the set
479
- // – requires less special knowledge to identify
480
- // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
481
- // – less common as a signifier in UX
482
- // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
483
- "\u{1F479}",
484
- "\u{1F47B}",
485
- "\u{1F47D}",
486
- "\u{1F916}",
487
- "\u{1F383}",
488
- "\u{1F9BE}",
489
- "\u{1F9BF}",
490
- "\u{1F9B7}",
491
- "\u{1F463}",
492
- "\u{1F441}\uFE0F",
493
- "\u{1F9F6}",
494
- "\u{1F451}",
495
- "\u{1F412}",
496
- "\u{1F986}",
497
- "\u{1F989}",
498
- "\u{1F434}",
499
- "\u{1F984}",
500
- "\u{1F41D}",
501
- "\u{1F98B}",
502
- "\u{1F41E}",
503
- "\u{1FAB2}",
504
- "\u{1F422}",
505
- "\u{1F98E}",
506
- "\u{1F995}",
507
- "\u{1F991}",
508
- "\u{1F980}",
509
- "\u{1F420}",
510
- "\u{1F42C}",
511
- "\u{1F40B}",
512
- "\u{1F9AD}",
513
- "\u{1F405}",
514
- "\u{1F406}",
515
- "\u{1F993}",
516
- "\u{1F98D}",
517
- "\u{1F9A7}",
518
- "\u{1F418}",
519
- "\u{1F42B}",
520
- "\u{1F992}",
521
- "\u{1F998}",
522
- "\u{1F9AC}",
523
- "\u{1F416}",
524
- "\u{1F40F}",
525
- "\u{1F98C}",
526
- "\u{1F415}",
527
- "\u{1F408}",
528
- "\u{1F413}",
529
- "\u{1F99A}",
530
- "\u{1F99C}",
531
- "\u{1F9A2}",
532
- "\u{1F9A9}",
533
- "\u{1F9A6}",
534
- "\u{1F401}",
535
- "\u{1F43F}\uFE0F",
536
- "\u{1F335}",
537
- "\u{1F332}",
538
- "\u{1F333}",
539
- "\u{1FAB5}",
540
- "\u{1F331}",
541
- "\u{1F341}",
542
- "\u{1FABA}",
543
- "\u{1F344}",
544
- "\u{1F41A}",
545
- "\u{1FAB8}",
546
- "\u{1FAA8}",
547
- "\u{1F33E}",
548
- "\u{1F337}",
549
- "\u{1F33B}",
550
- "\u2600\uFE0F",
551
- "\u{1F319}",
552
- "\u{1FA90}",
553
- "\u2B50\uFE0F",
554
- "\u26A1\uFE0F",
555
- "\u2604\uFE0F",
556
- "\u{1F525}",
557
- "\u{1F308}",
558
- "\u2601\uFE0F",
559
- "\u{1F4A7}",
560
- "\u26F1\uFE0F",
561
- "\u{1F30A}",
562
- "\u{1F34E}",
563
- "\u{1F34B}",
564
- "\u{1F349}",
565
- "\u{1F347}",
566
- "\u{1FAD0}",
567
- "\u{1F348}",
568
- "\u{1F352}",
569
- "\u{1F351}",
570
- "\u{1F96D}",
571
- "\u{1F34D}",
572
- "\u{1F965}",
573
- "\u{1F95D}",
574
- "\u{1F951}",
575
- "\u{1F336}\uFE0F",
576
- "\u{1F33D}",
577
- "\u{1F955}",
578
- "\u{1F36C}",
579
- "\u{1F95C}",
580
- "\u{1FAD6}",
581
- "\u2615\uFE0F",
582
- "\u{1F375}",
583
- "\u{1F9CA}",
584
- "\u{1F9C2}",
585
- "\u{1F3D4}\uFE0F",
586
- "\u2693\uFE0F",
587
- "\u{1F6DF}",
588
- "\u{1F3DD}\uFE0F",
589
- "\u{1F6F6}",
590
- "\u{1F680}",
591
- "\u{1F6F0}\uFE0F",
592
- "\u26F2\uFE0F",
593
- "\u{1F3F0}",
594
- "\u{1F6B2}",
595
- "\u26FA\uFE0F",
596
- "\u{1F399}\uFE0F",
597
- "\u{1F9F2}",
598
- "\u2699\uFE0F",
599
- "\u{1F529}",
600
- "\u{1F52E}",
601
- "\u{1F52D}",
602
- "\u{1F52C}",
603
- "\u{1F9EC}",
604
- "\u{1F321}\uFE0F",
605
- "\u{1F9FA}",
606
- "\u{1F6CE}\uFE0F",
607
- "\u{1F511}",
608
- "\u{1FA91}",
609
- "\u{1F9F8}",
610
- "\u{1F388}",
611
- "\u{1F380}",
612
- "\u{1F38A}",
613
- "\u267B\uFE0F",
614
- "\u{1F3B5}"
615
- ];
616
- var idHue = [
617
- "red",
618
- // 'orange' as const, /* More shades in these palettes are considered “ugly” */
619
- "amber",
620
- // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
621
- "lime",
622
- "green",
623
- "emerald",
624
- "teal",
625
- "cyan",
626
- // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
627
- // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
628
- // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
629
- "violet",
630
- "purple",
631
- "fuchsia",
632
- "pink",
633
- "rose"
634
- ];
635
- var keyToEmoji = (key) => hexToEmoji(key.toHex());
636
- var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
637
- var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
638
- var keyToHue = (key) => hexToHue(key.toHex());
639
- var hexToHue = (hex) => toHue(parseInt(hex, 16));
640
- var toHue = (hash) => idHue[hash % idHue.length];
641
- var keyToFallback = (key) => hexToFallback(key.toHex());
642
- var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
643
- var toFallback = (hash) => ({
644
- emoji: toEmoji(hash),
645
- hue: toHue(hash)
646
- });
647
- var entry = (map, key) => new MapEntry(map, key);
648
- 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 {
649
530
  /**
650
531
  * @internal
651
532
  */
652
- // prettier-ignore
653
- constructor(_map, _key) {
654
- this._map = _map;
655
- this._key = _key;
656
- }
657
- get key() {
658
- return this._key;
659
- }
660
- get value() {
661
- return this._map.get(this._key);
533
+ constructor(_fn) {
534
+ this._fn = _fn;
662
535
  }
663
- orInsert(value) {
664
- if (!this._map.has(this._key)) {
665
- 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);
666
575
  }
667
576
  return this;
668
577
  }
@@ -670,6 +579,7 @@ var MapEntry = class {
670
579
  return entry(this.value, key);
671
580
  }
672
581
  };
582
+ var forEachAsync = (items, fn) => Promise.all(items.map(fn));
673
583
  var DEFAULT_WORDLIST = [
674
584
  "ack",
675
585
  "alabama",
@@ -1008,6 +918,55 @@ var exponentialBackoffInterval = (cb, initialInterval) => {
1008
918
  let timeoutId = setTimeout(repeat, interval);
1009
919
  return () => clearTimeout(timeoutId);
1010
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
+ };
1011
970
  var arraysEqual = (a, b) => {
1012
971
  if (a.length !== b.length) {
1013
972
  return false;
@@ -1116,13 +1075,86 @@ var jsonKeyReplacer = (options = {}) => (key, value) => {
1116
1075
  }
1117
1076
  return value;
1118
1077
  };
1119
- var defaultMap = (map, key, def) => {
1120
- let value = map.get(key);
1121
- if (value === void 0) {
1122
- value = typeof def === "function" ? def() : def;
1123
- 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);
1124
1157
  }
1125
- return value;
1126
1158
  };
1127
1159
  var inferObjectOrder = (objectMap, order = []) => {
1128
1160
  const orderedObjects = order.reduce((acc, id) => {
@@ -1149,6 +1181,51 @@ var inferRecordOrder = (objectMap, order = []) => {
1149
1181
  return acc;
1150
1182
  }, {}), objectMap);
1151
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
+ };
1152
1229
  var isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1153
1230
  var mobileAndTabletCheck = () => {
1154
1231
  let check = false;
@@ -1284,6 +1361,22 @@ var createBucketReducer = (period) => ({
1284
1361
  return series;
1285
1362
  }
1286
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
+ };
1287
1380
  var instanceTag = Symbol("instanceTag");
1288
1381
  var safeInstanceof = (tag) => (target) => {
1289
1382
  target.prototype[instanceTag] = tag;
@@ -1323,75 +1416,257 @@ var compareMulti = (sorters) => (a, b) => {
1323
1416
  };
1324
1417
  return sort();
1325
1418
  };
1326
- var Tracer = class {
1327
- constructor() {
1328
- this._events = /* @__PURE__ */ new Map();
1329
- this._recording = false;
1330
- }
1331
- // TODO(burdon): Start/stop methods for recording data? By id?
1332
- // Alternatively, enable subscriptions to track/compute series.
1333
- // TODO(burdon): Hierarchical traces?
1334
- get recording() {
1335
- return this._recording;
1336
- }
1337
- keys() {
1338
- return Array.from(this._events.keys());
1339
- }
1340
- get(id, filter) {
1341
- const events = this._events.get(id);
1342
- if (filter) {
1343
- return events?.filter((event) => Object.entries(filter).every(([key, value]) => event?.value[key] === value));
1344
- }
1345
- return events;
1346
- }
1347
- clear() {
1348
- this._events.clear();
1349
- }
1350
- start() {
1351
- this._recording = true;
1352
- return this;
1353
- }
1354
- stop() {
1355
- this._recording = false;
1356
- return this;
1357
- }
1358
- emit(id, value) {
1359
- this._post(this._createEvent(id, value));
1360
- }
1361
- mark(id, value) {
1362
- const event = this._createEvent(id, value);
1363
- const start = performance.now();
1364
- return {
1365
- start,
1366
- end: () => {
1367
- event.duration = performance.now() - start;
1368
- this._post(event);
1369
- }
1370
- };
1371
- }
1372
- _createEvent(id, value) {
1373
- const event = {
1374
- id,
1375
- timestamp: Date.now()
1376
- };
1377
- if (value !== void 0) {
1378
- event.value = value;
1379
- }
1380
- return event;
1381
- }
1382
- _post(event) {
1383
- if (this._recording) {
1384
- defaultMap(this._events, event.id, []).push(event);
1385
- }
1386
- }
1419
+ var throwUnhandledError = (error) => {
1420
+ queueMicrotask(() => {
1421
+ throw error;
1422
+ });
1387
1423
  };
1388
- var tracer = new Tracer();
1389
- var isNotFalsy = (value) => !!value;
1390
- var nonNullable = (value) => value !== null && value !== void 0;
1391
- var isNotNullOrUndefined = (value) => value != null;
1392
- var boolGuard = (value) => Boolean(value);
1393
- var getAsyncValue = async (value) => {
1394
- if (typeof value === "function") {
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
+ };
1663
+ var tracer = new Tracer();
1664
+ var isNotFalsy = (value) => !!value;
1665
+ var nonNullable = (value) => value !== null && value !== void 0;
1666
+ var isNotNullOrUndefined = (value) => value != null;
1667
+ var boolGuard = (value) => Boolean(value);
1668
+ var getAsyncValue = async (value) => {
1669
+ if (typeof value === "function") {
1395
1670
  return value();
1396
1671
  } else {
1397
1672
  return value;
@@ -1422,30 +1697,7 @@ var safeParseInt = (value, defaultValue) => {
1422
1697
  return defaultValue;
1423
1698
  }
1424
1699
  };
1425
- var symbol = Symbol.for("dxos.instance-contexts");
1426
- var instanceContexts = globalThis[symbol] ??= /* @__PURE__ */ new WeakMap();
1427
- var getPrototypeSpecificInstanceId = (instance) => {
1428
- const prototype = Object.getPrototypeOf(instance);
1429
- const instanceCtx = defaultMap(instanceContexts, prototype, () => ({
1430
- nextId: 0,
1431
- instanceIds: /* @__PURE__ */ new WeakMap()
1432
- }));
1433
- let id = instanceCtx.instanceIds.get(instance);
1434
- if (id === void 0) {
1435
- id = instanceCtx.nextId++;
1436
- instanceCtx.instanceIds.set(instance, id);
1437
- }
1438
- return id;
1439
- };
1440
- var getDebugName = (instance) => {
1441
- if (instance == null) {
1442
- return "null";
1443
- }
1444
- const prototype = Object.getPrototypeOf(instance);
1445
- return `${prototype.constructor.name}#${getPrototypeSpecificInstanceId(instance)}`;
1446
- };
1447
1700
  var sum = (values) => values.reduce((a, b) => a + b, 0);
1448
- var forEachAsync = (items, fn) => Promise.all(items.map(fn));
1449
1701
  var WeakDictionary = class {
1450
1702
  constructor(entries) {
1451
1703
  this._internal = /* @__PURE__ */ new Map();
@@ -1539,154 +1791,6 @@ var WeakDictionary = class {
1539
1791
  this._finalization.unregister(value);
1540
1792
  }
1541
1793
  };
1542
- var mapValues = (obj, fn) => {
1543
- const result = {};
1544
- Object.keys(obj).forEach((key) => {
1545
- result[key] = fn(obj[key], key);
1546
- });
1547
- return result;
1548
- };
1549
- var deepMapValues = (value, fn) => {
1550
- return new DeepMapper(fn).map(value);
1551
- };
1552
- var DeepMapper = class {
1553
- constructor(_fn) {
1554
- this._fn = _fn;
1555
- this._cyclic = /* @__PURE__ */ new Map();
1556
- this._recurse = (value) => {
1557
- if (this._cyclic.has(value)) {
1558
- return this._cyclic.get(value);
1559
- }
1560
- if (Array.isArray(value)) {
1561
- const res = new Array(value.length);
1562
- this._cyclic.set(value, res);
1563
- for (let i = 0; i < value.length; i++) {
1564
- res[i] = this.map(value[i]);
1565
- }
1566
- return res;
1567
- } else if (value !== null && typeof value === "object") {
1568
- const res = {};
1569
- this._cyclic.set(value, res);
1570
- for (const key in value) {
1571
- res[key] = this.map(value[key]);
1572
- }
1573
- return res;
1574
- } else {
1575
- return value;
1576
- }
1577
- };
1578
- }
1579
- map(value) {
1580
- if (this._cyclic.has(value)) {
1581
- return this._cyclic.get(value);
1582
- }
1583
- return this._fn(value, this._recurse);
1584
- }
1585
- };
1586
- Symbol.dispose ??= Symbol("Symbol.dispose");
1587
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
1588
- var defer = (fn) => new DeferGuard(fn);
1589
- var DeferGuard = class {
1590
- /**
1591
- * @internal
1592
- */
1593
- constructor(_fn) {
1594
- this._fn = _fn;
1595
- }
1596
- [Symbol.dispose]() {
1597
- const result = this._fn();
1598
- if (result instanceof Promise) {
1599
- throw new Error("Async functions in defer are not supported. Use deferAsync instead.");
1600
- }
1601
- }
1602
- };
1603
- var deferAsync = (fn) => new DeferAsyncGuard(fn);
1604
- var DeferAsyncGuard = class {
1605
- /**
1606
- * @internal
1607
- */
1608
- constructor(_fn) {
1609
- this._fn = _fn;
1610
- }
1611
- async [Symbol.asyncDispose]() {
1612
- await this._fn();
1613
- }
1614
- };
1615
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
1616
- var CircularBuffer = class {
1617
- constructor(size) {
1618
- this._nextIndex = 0;
1619
- this._elementCount = 0;
1620
- (0, import_invariant4.invariant)(size >= 1, void 0, {
1621
- F: __dxlog_file4,
1622
- L: 13,
1623
- S: this,
1624
- A: [
1625
- "size >= 1",
1626
- ""
1627
- ]
1628
- });
1629
- this._buffer = new Array(size);
1630
- }
1631
- push(element) {
1632
- this._buffer[this._nextIndex] = element;
1633
- this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
1634
- this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
1635
- }
1636
- getLast() {
1637
- if (this._elementCount === 0) {
1638
- return void 0;
1639
- }
1640
- if (this._nextIndex === 0) {
1641
- return this._buffer[this._buffer.length - 1];
1642
- }
1643
- return this._buffer[this._nextIndex - 1];
1644
- }
1645
- [Symbol.iterator]() {
1646
- return this.values();
1647
- }
1648
- *values() {
1649
- if (this._elementCount === 0) {
1650
- return;
1651
- }
1652
- if (this._elementCount < this._buffer.length) {
1653
- for (let i = 0; i < this._elementCount; i++) {
1654
- yield this._buffer[i];
1655
- }
1656
- return;
1657
- }
1658
- for (let i = this._nextIndex; i < this._buffer.length; i++) {
1659
- yield this._buffer[i];
1660
- }
1661
- for (let i = 0; i < this._nextIndex; i++) {
1662
- yield this._buffer[i];
1663
- }
1664
- }
1665
- };
1666
- var joinTables = (leftColumn, rightColumn, left, right) => {
1667
- const map = /* @__PURE__ */ new Map();
1668
- const used = /* @__PURE__ */ new Set();
1669
- for (const row of right) {
1670
- map.set(row[rightColumn], row);
1671
- }
1672
- const result = [];
1673
- for (const row of left) {
1674
- const right2 = map.get(row[leftColumn]);
1675
- used.add(right2);
1676
- result.push(Object.assign(right2 ?? {}, row));
1677
- }
1678
- for (const row of right) {
1679
- if (!used.has(row)) {
1680
- result.push(row);
1681
- }
1682
- }
1683
- return result;
1684
- };
1685
- var throwUnhandledError = (error) => {
1686
- queueMicrotask(() => {
1687
- throw error;
1688
- });
1689
- };
1690
1794
  // Annotate the CommonJS export names for ESM import in node:
1691
1795
  0 && (module.exports = {
1692
1796
  BitField,
@@ -1696,6 +1800,8 @@ var throwUnhandledError = (error) => {
1696
1800
  ComplexSet,
1697
1801
  HumanHasher,
1698
1802
  MapEntry,
1803
+ ParamKeyAnnotation,
1804
+ Params,
1699
1805
  Tracer,
1700
1806
  WeakDictionary,
1701
1807
  accessBy,
@@ -1715,6 +1821,7 @@ var throwUnhandledError = (error) => {
1715
1821
  createGroupReducer,
1716
1822
  createSetDispatch,
1717
1823
  deepMapValues,
1824
+ deepMapValuesAsync,
1718
1825
  defaultMap,
1719
1826
  defer,
1720
1827
  deferAsync,
@@ -1765,6 +1872,7 @@ var throwUnhandledError = (error) => {
1765
1872
  reduceSeries,
1766
1873
  reduceSet,
1767
1874
  safariCheck,
1875
+ safeAwaitAll,
1768
1876
  safeInstanceof,
1769
1877
  safeParseInt,
1770
1878
  safeParseJson,