@dxos/effect 0.8.4-main.fbb7a13 → 0.8.4-main.fcfe5033a5

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.
@@ -13,13 +13,12 @@ import { isNonNullable } from "@dxos/util";
13
13
  var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
14
14
  var reduceRefinements = (type, refinements = []) => {
15
15
  if (SchemaAST.isRefinement(type)) {
16
- const annotations = type.annotations;
17
16
  const filter = type.filter;
18
17
  const nextType = {
19
18
  ...type.from,
20
19
  annotations: {
21
- ...type.annotations,
22
- ...annotations
20
+ ...type.from.annotations,
21
+ ...type.annotations
23
22
  }
24
23
  };
25
24
  return reduceRefinements(nextType, [
@@ -39,12 +38,23 @@ var getBaseType = (prop) => {
39
38
  };
40
39
  var getProperties = (ast) => {
41
40
  const properties = SchemaAST.getPropertySignatures(ast);
42
- return properties.map((prop) => ({
43
- ...getBaseType(prop),
44
- name: prop.name,
45
- isOptional: prop.isOptional,
46
- isReadonly: prop.isReadonly
47
- }));
41
+ return properties.map((prop) => {
42
+ const { type, refinements } = getBaseType(prop);
43
+ const mergedType = prop.annotations && Reflect.ownKeys(prop.annotations).length > 0 ? {
44
+ ...type,
45
+ annotations: {
46
+ ...type.annotations,
47
+ ...prop.annotations
48
+ }
49
+ } : type;
50
+ return {
51
+ type: mergedType,
52
+ refinements,
53
+ name: prop.name,
54
+ isOptional: prop.isOptional,
55
+ isReadonly: prop.isReadonly
56
+ };
57
+ });
48
58
  };
49
59
  var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
50
60
  VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
@@ -143,7 +153,7 @@ var findProperty = (schema, path) => {
143
153
  const typeNode = findNode(node, SchemaAST.isTypeLiteral);
144
154
  invariant(typeNode, void 0, {
145
155
  F: __dxlog_file,
146
- L: 235,
156
+ L: 247,
147
157
  S: void 0,
148
158
  A: [
149
159
  "typeNode",
@@ -163,10 +173,10 @@ var findProperty = (schema, path) => {
163
173
  return getProp(schema.ast, path.split("."));
164
174
  };
165
175
  var defaultAnnotations = {
166
- ["ObjectKeyword"]: SchemaAST.objectKeyword,
167
- ["StringKeyword"]: SchemaAST.stringKeyword,
168
- ["NumberKeyword"]: SchemaAST.numberKeyword,
169
- ["BooleanKeyword"]: SchemaAST.booleanKeyword
176
+ ObjectKeyword: SchemaAST.objectKeyword,
177
+ StringKeyword: SchemaAST.stringKeyword,
178
+ NumberKeyword: SchemaAST.numberKeyword,
179
+ BooleanKeyword: SchemaAST.booleanKeyword
170
180
  };
171
181
  var getAnnotation2 = (annotationId, noDefault = true) => (node) => {
172
182
  const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
@@ -212,7 +222,7 @@ var isDiscriminatedUnion = (node) => {
212
222
  var getDiscriminatingProps = (node) => {
213
223
  invariant(SchemaAST.isUnion(node), void 0, {
214
224
  F: __dxlog_file,
215
- L: 353,
225
+ L: 365,
216
226
  S: void 0,
217
227
  A: [
218
228
  "SchemaAST.isUnion(node)",
@@ -230,7 +240,7 @@ var getDiscriminatingProps = (node) => {
230
240
  var getDiscriminatedType = (node, value = {}) => {
231
241
  invariant(SchemaAST.isUnion(node), void 0, {
232
242
  F: __dxlog_file,
233
- L: 377,
243
+ L: 389,
234
244
  S: void 0,
235
245
  A: [
236
246
  "SchemaAST.isUnion(node)",
@@ -239,7 +249,7 @@ var getDiscriminatedType = (node, value = {}) => {
239
249
  });
240
250
  invariant(value, void 0, {
241
251
  F: __dxlog_file,
242
- L: 378,
252
+ L: 390,
243
253
  S: void 0,
244
254
  A: [
245
255
  "value",
@@ -254,7 +264,7 @@ var getDiscriminatedType = (node, value = {}) => {
254
264
  const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
255
265
  invariant(SchemaAST.isLiteral(prop.type), void 0, {
256
266
  F: __dxlog_file,
257
- L: 389,
267
+ L: 401,
258
268
  S: void 0,
259
269
  A: [
260
270
  "SchemaAST.isLiteral(prop.type)",
@@ -272,7 +282,7 @@ var getDiscriminatedType = (node, value = {}) => {
272
282
  const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
273
283
  invariant(SchemaAST.isLiteral(literal.type), void 0, {
274
284
  F: __dxlog_file,
275
- L: 407,
285
+ L: 419,
276
286
  S: void 0,
277
287
  A: [
278
288
  "SchemaAST.isLiteral(literal.type)",
@@ -330,8 +340,8 @@ var getIndexSignatures = (ast) => {
330
340
  };
331
341
 
332
342
  // src/atom-kvs.ts
333
- import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
334
343
  import { Atom } from "@effect-atom/atom-react";
344
+ import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
335
345
  var defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
336
346
  var createKvsStore = (options) => {
337
347
  const runtime2 = options.runtime ?? defaultRuntime;
@@ -375,8 +385,7 @@ import * as Exit from "effect/Exit";
375
385
  import * as GlobalValue from "effect/GlobalValue";
376
386
  import * as Option2 from "effect/Option";
377
387
  import * as Runtime from "effect/Runtime";
378
- var spanSymbol = Symbol.for("effect/SpanAnnotation");
379
- var originalSymbol = Symbol.for("effect/OriginalAnnotation");
388
+ var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
380
389
  var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
381
390
  var locationRegex = /\((.*)\)/g;
382
391
  var prettyErrorStack = (error, appendStacks = []) => {
@@ -386,7 +395,7 @@ var prettyErrorStack = (error, appendStacks = []) => {
386
395
  const span = error[spanSymbol];
387
396
  const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
388
397
  const out = [];
389
- let atStack = false;
398
+ let atStack = false, inCore = false, passedScheduler = false;
390
399
  for (let i = 0; i < lines.length; i++) {
391
400
  if (!atStack && !lines[i].startsWith(" at ")) {
392
401
  out.push(lines[i]);
@@ -403,6 +412,26 @@ var prettyErrorStack = (error, appendStacks = []) => {
403
412
  if (lines[i].includes("effect_internal_function")) {
404
413
  break;
405
414
  }
415
+ const filename = lines[i].match(/\/([a-zA-Z0-9_\-.]+):\d+:\d+\)$/)?.[1];
416
+ if (!inCore && [
417
+ "core-effect.ts"
418
+ ].includes(filename)) {
419
+ inCore = true;
420
+ }
421
+ if (inCore && !passedScheduler && [
422
+ "Scheduler.ts"
423
+ ].includes(filename)) {
424
+ passedScheduler = true;
425
+ continue;
426
+ }
427
+ if (passedScheduler && ![
428
+ "Scheduler.ts"
429
+ ].includes(filename)) {
430
+ inCore = false;
431
+ }
432
+ if (inCore) {
433
+ continue;
434
+ }
406
435
  out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
407
436
  }
408
437
  if (span) {
@@ -433,9 +462,7 @@ var prettyErrorStack = (error, appendStacks = []) => {
433
462
  }
434
463
  }
435
464
  out.push(...appendStacks);
436
- if (error[originalSymbol]) {
437
- error = error[originalSymbol];
438
- }
465
+ error = Cause.originalError(error);
439
466
  if (error.cause) {
440
467
  error.cause = prettyErrorStack(error.cause);
441
468
  }
@@ -459,7 +486,7 @@ var causeToError = (cause) => {
459
486
  ];
460
487
  const getStackFrames = () => {
461
488
  const o = new Error();
462
- Error.captureStackTrace(o, getStackFrames);
489
+ Error.captureStackTrace(o, causeToError);
463
490
  return o.stack.split("\n").slice(1);
464
491
  };
465
492
  const stackFrames = getStackFrames();
@@ -474,19 +501,30 @@ var causeToError = (cause) => {
474
501
  var throwCause = (cause) => {
475
502
  throw causeToError(cause);
476
503
  };
477
- var unwrapExit = (exit) => {
478
- if (Exit.isSuccess(exit)) {
479
- return exit.value;
504
+ var unwrapExit = (exit2) => {
505
+ if (Exit.isSuccess(exit2)) {
506
+ return exit2.value;
480
507
  }
481
- return throwCause(exit.cause);
508
+ return throwCause(exit2.cause);
482
509
  };
483
510
  var runAndForwardErrors = async (effect, options) => {
484
- const exit = await Effect2.runPromiseExit(effect, options);
485
- return unwrapExit(exit);
486
- };
487
- var runInRuntime = async (runtime2, effect, options) => {
488
- const exit = await Runtime.runPromiseExit(runtime2, effect, options);
489
- return unwrapExit(exit);
511
+ const exit2 = await Effect2.runPromiseExit(effect, options);
512
+ return unwrapExit(exit2);
513
+ };
514
+ var runInRuntime = (...args) => {
515
+ if (args.length === 1) {
516
+ const [runtime2] = args;
517
+ return async (effect, options) => {
518
+ const exit2 = await Runtime.runPromiseExit(runtime2, effect, options);
519
+ return unwrapExit(exit2);
520
+ };
521
+ } else {
522
+ const [runtime2, effect, options] = args;
523
+ return (async () => {
524
+ const exit2 = await Runtime.runPromiseExit(runtime2, effect, options);
525
+ return unwrapExit(exit2);
526
+ })();
527
+ }
490
528
  };
491
529
  var promiseWithCauseCapture = (evaluate) => Effect2.promise(async (signal) => {
492
530
  try {
@@ -677,7 +715,7 @@ import * as Function2 from "effect/Function";
677
715
  import * as Option5 from "effect/Option";
678
716
  import * as SchemaAST2 from "effect/SchemaAST";
679
717
  import { decamelize } from "@dxos/util";
680
- var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
718
+ var ParamKeyAnnotationId = /* @__PURE__ */ Symbol.for("@dxos/schema/annotation/ParamKey");
681
719
  var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
682
720
  var ParamKeyAnnotation = (value) => (self) => self.annotations({
683
721
  [ParamKeyAnnotationId]: value
@@ -744,15 +782,74 @@ var runPromise2 = (provider) => async (effect) => {
744
782
  return unwrapExit(await effect.pipe(Runtime3.runPromiseExit(runtime2)));
745
783
  };
746
784
  var provide2 = (runtimeProvider) => (effect) => Effect5.flatMap(runtimeProvider, (runtime2) => Effect5.provide(effect, runtime2));
785
+
786
+ // src/Performance.ts
787
+ var Performance_exports = {};
788
+ __export(Performance_exports, {
789
+ addTrackEntry: () => addTrackEntry
790
+ });
791
+ import * as Effect6 from "effect/Effect";
792
+ var addTrackEntry = (options) => (effect) => Effect6.gen(function* () {
793
+ const start = performance.now();
794
+ const exit2 = yield* Effect6.exit(effect);
795
+ const resolvedOptions = typeof options === "function" ? options(exit2) : options;
796
+ performance.measure(resolvedOptions.name, {
797
+ start,
798
+ detail: {
799
+ ...resolvedOptions.detail,
800
+ devtools: resolvedOptions.devtools
801
+ }
802
+ });
803
+ return yield* exit2;
804
+ });
805
+
806
+ // src/async-task-tagging.ts
807
+ import * as Context3 from "effect/Context";
808
+ import * as Effect7 from "effect/Effect";
809
+ import { pipe as pipe3 } from "effect/Function";
810
+ import * as Layer from "effect/Layer";
811
+ import * as Predicate from "effect/Predicate";
812
+ import * as Tracer from "effect/Tracer";
813
+ var runInTask = /* @__PURE__ */ Symbol("runInTask");
814
+ var asyncTaskTaggingLayer = () => {
815
+ if (Predicate.hasProperty(console, "createTask") === false) {
816
+ return Layer.empty;
817
+ }
818
+ const makeTracer = Effect7.gen(function* () {
819
+ const oldTracer = yield* Effect7.tracer;
820
+ return Tracer.make({
821
+ span: (name, ...args) => {
822
+ const span = oldTracer.span(name, ...args);
823
+ const trace = console.createTask(name);
824
+ span[runInTask] = (f) => trace.run(f);
825
+ return span;
826
+ },
827
+ context: (f, fiber) => {
828
+ const maybeParentSpan = Context3.getOption(Tracer.ParentSpan)(fiber.currentContext);
829
+ if (maybeParentSpan._tag === "None") return oldTracer.context(f, fiber);
830
+ const parentSpan = maybeParentSpan.value;
831
+ if (parentSpan._tag === "ExternalSpan") return oldTracer.context(f, fiber);
832
+ const span = parentSpan;
833
+ if (runInTask in span && typeof span[runInTask] === "function") {
834
+ return span[runInTask](() => oldTracer.context(f, fiber));
835
+ }
836
+ return oldTracer.context(f, fiber);
837
+ }
838
+ });
839
+ });
840
+ return pipe3(makeTracer, Effect7.map(Layer.setTracer), Layer.unwrapEffect);
841
+ };
747
842
  export {
748
843
  dynamic_runtime_exports as DynamicRuntime,
749
844
  JsonPath,
750
845
  JsonProp,
751
846
  ParamKeyAnnotation,
847
+ Performance_exports as Performance,
752
848
  RuntimeProvider_exports as RuntimeProvider,
753
849
  UrlParser,
754
850
  VisitResult,
755
851
  acquireReleaseResource,
852
+ asyncTaskTaggingLayer,
756
853
  causeToError,
757
854
  contextFromScope,
758
855
  createJsonPath,