@dxos/util 0.5.9-next.a50ff17 → 0.6.0

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