@dxos/effect 0.8.4-main.1068cf700f → 0.8.4-main.16b68245aa

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.
Files changed (37) hide show
  1. package/dist/lib/browser/index.mjs +113 -102
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/testing.mjs +0 -8
  5. package/dist/lib/browser/testing.mjs.map +3 -3
  6. package/dist/lib/node-esm/index.mjs +113 -102
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/lib/node-esm/testing.mjs +0 -8
  10. package/dist/lib/node-esm/testing.mjs.map +3 -3
  11. package/dist/types/src/Performance.d.ts +25 -0
  12. package/dist/types/src/Performance.d.ts.map +1 -0
  13. package/dist/types/src/RuntimeProvider.d.ts.map +1 -1
  14. package/dist/types/src/ast.d.ts +7 -1
  15. package/dist/types/src/ast.d.ts.map +1 -1
  16. package/dist/types/src/async-task-tagging.d.ts +6 -0
  17. package/dist/types/src/async-task-tagging.d.ts.map +1 -0
  18. package/dist/types/src/atom-kvs.d.ts.map +1 -1
  19. package/dist/types/src/errors.d.ts.map +1 -1
  20. package/dist/types/src/index.d.ts +3 -0
  21. package/dist/types/src/index.d.ts.map +1 -1
  22. package/dist/types/src/json-path.d.ts.map +1 -1
  23. package/dist/types/src/resource.d.ts.map +1 -1
  24. package/dist/types/src/testing.d.ts +3 -13
  25. package/dist/types/src/testing.d.ts.map +1 -1
  26. package/dist/types/src/types.d.ts +8 -0
  27. package/dist/types/src/types.d.ts.map +1 -0
  28. package/dist/types/src/url.d.ts.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +9 -16
  31. package/src/Performance.ts +45 -0
  32. package/src/ast.ts +34 -10
  33. package/src/async-task-tagging.ts +51 -0
  34. package/src/atom-kvs.ts +1 -1
  35. package/src/index.ts +3 -0
  36. package/src/testing.ts +3 -29
  37. package/src/types.ts +11 -0
@@ -10,7 +10,6 @@ import * as Schema from "effect/Schema";
10
10
  import * as SchemaAST from "effect/SchemaAST";
11
11
  import { invariant } from "@dxos/invariant";
12
12
  import { isNonNullable } from "@dxos/util";
13
- var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
14
13
  var reduceRefinements = (type, refinements = []) => {
15
14
  if (SchemaAST.isRefinement(type)) {
16
15
  const filter = type.filter;
@@ -38,12 +37,23 @@ var getBaseType = (prop) => {
38
37
  };
39
38
  var getProperties = (ast) => {
40
39
  const properties = SchemaAST.getPropertySignatures(ast);
41
- return properties.map((prop) => ({
42
- ...getBaseType(prop),
43
- name: prop.name,
44
- isOptional: prop.isOptional,
45
- isReadonly: prop.isReadonly
46
- }));
40
+ return properties.map((prop) => {
41
+ const { type, refinements } = getBaseType(prop);
42
+ const mergedType = prop.annotations && Reflect.ownKeys(prop.annotations).length > 0 ? {
43
+ ...type,
44
+ annotations: {
45
+ ...type.annotations,
46
+ ...prop.annotations
47
+ }
48
+ } : type;
49
+ return {
50
+ type: mergedType,
51
+ refinements,
52
+ name: prop.name,
53
+ isOptional: prop.isOptional,
54
+ isReadonly: prop.isReadonly
55
+ };
56
+ });
47
57
  };
48
58
  var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
49
59
  VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
@@ -140,15 +150,7 @@ var findProperty = (schema, path) => {
140
150
  const getProp = (node, path2) => {
141
151
  const [name, ...rest] = path2;
142
152
  const typeNode = findNode(node, SchemaAST.isTypeLiteral);
143
- invariant(typeNode, void 0, {
144
- F: __dxlog_file,
145
- L: 237,
146
- S: void 0,
147
- A: [
148
- "typeNode",
149
- ""
150
- ]
151
- });
153
+ invariant(typeNode);
152
154
  for (const prop of SchemaAST.getPropertySignatures(typeNode)) {
153
155
  if (prop.name === name) {
154
156
  if (rest.length) {
@@ -162,10 +164,10 @@ var findProperty = (schema, path) => {
162
164
  return getProp(schema.ast, path.split("."));
163
165
  };
164
166
  var defaultAnnotations = {
165
- ["ObjectKeyword"]: SchemaAST.objectKeyword,
166
- ["StringKeyword"]: SchemaAST.stringKeyword,
167
- ["NumberKeyword"]: SchemaAST.numberKeyword,
168
- ["BooleanKeyword"]: SchemaAST.booleanKeyword
167
+ ObjectKeyword: SchemaAST.objectKeyword,
168
+ StringKeyword: SchemaAST.stringKeyword,
169
+ NumberKeyword: SchemaAST.numberKeyword,
170
+ BooleanKeyword: SchemaAST.booleanKeyword
169
171
  };
170
172
  var getAnnotation2 = (annotationId, noDefault = true) => (node) => {
171
173
  const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
@@ -196,6 +198,12 @@ var isOption = (node) => {
196
198
  var isLiteralUnion = (node) => {
197
199
  return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
198
200
  };
201
+ var getLiteralValues = (schema) => {
202
+ if (!isLiteralUnion(schema.ast)) {
203
+ return [];
204
+ }
205
+ return schema.ast.types.map((node) => node.literal);
206
+ };
199
207
  var isArrayType = (node) => {
200
208
  return SchemaAST.isTupleType(node) && node.elements.length === 0 && node.rest.length === 1;
201
209
  };
@@ -209,15 +217,7 @@ var isDiscriminatedUnion = (node) => {
209
217
  return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
210
218
  };
211
219
  var getDiscriminatingProps = (node) => {
212
- invariant(SchemaAST.isUnion(node), void 0, {
213
- F: __dxlog_file,
214
- L: 355,
215
- S: void 0,
216
- A: [
217
- "SchemaAST.isUnion(node)",
218
- ""
219
- ]
220
- });
220
+ invariant(SchemaAST.isUnion(node));
221
221
  if (isOption(node)) {
222
222
  return;
223
223
  }
@@ -227,39 +227,15 @@ var getDiscriminatingProps = (node) => {
227
227
  }, []);
228
228
  };
229
229
  var getDiscriminatedType = (node, value = {}) => {
230
- invariant(SchemaAST.isUnion(node), void 0, {
231
- F: __dxlog_file,
232
- L: 379,
233
- S: void 0,
234
- A: [
235
- "SchemaAST.isUnion(node)",
236
- ""
237
- ]
238
- });
239
- invariant(value, void 0, {
240
- F: __dxlog_file,
241
- L: 380,
242
- S: void 0,
243
- A: [
244
- "value",
245
- ""
246
- ]
247
- });
230
+ invariant(SchemaAST.isUnion(node));
231
+ invariant(value);
248
232
  const props = getDiscriminatingProps(node);
249
233
  if (!props?.length) {
250
234
  return;
251
235
  }
252
236
  for (const type of node.types) {
253
237
  const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
254
- invariant(SchemaAST.isLiteral(prop.type), void 0, {
255
- F: __dxlog_file,
256
- L: 391,
257
- S: void 0,
258
- A: [
259
- "SchemaAST.isLiteral(prop.type)",
260
- ""
261
- ]
262
- });
238
+ invariant(SchemaAST.isLiteral(prop.type));
263
239
  return prop.type.literal === value[prop.name.toString()];
264
240
  });
265
241
  if (match) {
@@ -269,15 +245,7 @@ var getDiscriminatedType = (node, value = {}) => {
269
245
  const fields = Object.fromEntries(props.map((prop) => {
270
246
  const literals = node.types.map((type) => {
271
247
  const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
272
- invariant(SchemaAST.isLiteral(literal.type), void 0, {
273
- F: __dxlog_file,
274
- L: 409,
275
- S: void 0,
276
- A: [
277
- "SchemaAST.isLiteral(literal.type)",
278
- ""
279
- ]
280
- });
248
+ invariant(SchemaAST.isLiteral(literal.type));
281
249
  return literal.type.literal;
282
250
  }).filter(isNonNullable);
283
251
  return literals.length ? [
@@ -329,8 +297,8 @@ var getIndexSignatures = (ast) => {
329
297
  };
330
298
 
331
299
  // src/atom-kvs.ts
332
- import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
333
300
  import { Atom } from "@effect-atom/atom-react";
301
+ import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
334
302
  var defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
335
303
  var createKvsStore = (options) => {
336
304
  const runtime2 = options.runtime ?? defaultRuntime;
@@ -345,12 +313,8 @@ var createKvsStore = (options) => {
345
313
  // src/context.ts
346
314
  import * as Effect from "effect/Effect";
347
315
  import { Context } from "@dxos/context";
348
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
349
316
  var contextFromScope = () => Effect.gen(function* () {
350
- const ctx = new Context(void 0, {
351
- F: __dxlog_file2,
352
- L: 13
353
- });
317
+ const ctx = new Context();
354
318
  yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
355
319
  return ctx;
356
320
  });
@@ -374,7 +338,7 @@ import * as Exit from "effect/Exit";
374
338
  import * as GlobalValue from "effect/GlobalValue";
375
339
  import * as Option2 from "effect/Option";
376
340
  import * as Runtime from "effect/Runtime";
377
- var spanSymbol = Symbol.for("effect/SpanAnnotation");
341
+ var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
378
342
  var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
379
343
  var locationRegex = /\((.*)\)/g;
380
344
  var prettyErrorStack = (error, appendStacks = []) => {
@@ -490,28 +454,28 @@ var causeToError = (cause) => {
490
454
  var throwCause = (cause) => {
491
455
  throw causeToError(cause);
492
456
  };
493
- var unwrapExit = (exit) => {
494
- if (Exit.isSuccess(exit)) {
495
- return exit.value;
457
+ var unwrapExit = (exit2) => {
458
+ if (Exit.isSuccess(exit2)) {
459
+ return exit2.value;
496
460
  }
497
- return throwCause(exit.cause);
461
+ return throwCause(exit2.cause);
498
462
  };
499
463
  var runAndForwardErrors = async (effect, options) => {
500
- const exit = await Effect2.runPromiseExit(effect, options);
501
- return unwrapExit(exit);
464
+ const exit2 = await Effect2.runPromiseExit(effect, options);
465
+ return unwrapExit(exit2);
502
466
  };
503
467
  var runInRuntime = (...args) => {
504
468
  if (args.length === 1) {
505
469
  const [runtime2] = args;
506
470
  return async (effect, options) => {
507
- const exit = await Runtime.runPromiseExit(runtime2, effect, options);
508
- return unwrapExit(exit);
471
+ const exit2 = await Runtime.runPromiseExit(runtime2, effect, options);
472
+ return unwrapExit(exit2);
509
473
  };
510
474
  } else {
511
475
  const [runtime2, effect, options] = args;
512
476
  return (async () => {
513
- const exit = await Runtime.runPromiseExit(runtime2, effect, options);
514
- return unwrapExit(exit);
477
+ const exit2 = await Runtime.runPromiseExit(runtime2, effect, options);
478
+ return unwrapExit(exit2);
515
479
  })();
516
480
  }
517
481
  };
@@ -618,7 +582,6 @@ import * as Schema2 from "effect/Schema";
618
582
  import { JSONPath } from "jsonpath-plus";
619
583
  import { invariant as invariant2 } from "@dxos/invariant";
620
584
  import { getDeep, setDeep } from "@dxos/util";
621
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/json-path.ts";
622
585
  var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
623
586
  var PROP_REGEX = /^\w+$/;
624
587
  var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
@@ -639,28 +602,12 @@ var createJsonPath = (path) => {
639
602
  return i === 0 ? p : `.${p}`;
640
603
  }
641
604
  }).join("");
642
- invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
643
- F: __dxlog_file3,
644
- L: 69,
645
- S: void 0,
646
- A: [
647
- "isJsonPath(candidatePath)",
648
- "`Invalid JsonPath: ${candidatePath}`"
649
- ]
650
- });
605
+ invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);
651
606
  return candidatePath;
652
607
  };
653
608
  var fromEffectValidationPath = (effectPath) => {
654
609
  const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
655
- invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
656
- F: __dxlog_file3,
657
- L: 80,
658
- S: void 0,
659
- A: [
660
- "isJsonPath(jsonPath)",
661
- "`Invalid JsonPath: ${jsonPath}`"
662
- ]
663
- });
610
+ invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);
664
611
  return jsonPath;
665
612
  };
666
613
  var splitJsonPath = (path) => {
@@ -704,7 +651,7 @@ import * as Function2 from "effect/Function";
704
651
  import * as Option5 from "effect/Option";
705
652
  import * as SchemaAST2 from "effect/SchemaAST";
706
653
  import { decamelize } from "@dxos/util";
707
- var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
654
+ var ParamKeyAnnotationId = /* @__PURE__ */ Symbol.for("@dxos/schema/annotation/ParamKey");
708
655
  var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
709
656
  var ParamKeyAnnotation = (value) => (self) => self.annotations({
710
657
  [ParamKeyAnnotationId]: value
@@ -771,15 +718,78 @@ var runPromise2 = (provider) => async (effect) => {
771
718
  return unwrapExit(await effect.pipe(Runtime3.runPromiseExit(runtime2)));
772
719
  };
773
720
  var provide2 = (runtimeProvider) => (effect) => Effect5.flatMap(runtimeProvider, (runtime2) => Effect5.provide(effect, runtime2));
721
+
722
+ // src/Performance.ts
723
+ var Performance_exports = {};
724
+ __export(Performance_exports, {
725
+ addTrackEntry: () => addTrackEntry
726
+ });
727
+ import * as Effect6 from "effect/Effect";
728
+ var addTrackEntry = (options) => (effect) => Effect6.gen(function* () {
729
+ const start = performance.now();
730
+ const exit2 = yield* Effect6.exit(effect);
731
+ const resolvedOptions = typeof options === "function" ? options(exit2) : options;
732
+ performance.measure(resolvedOptions.name, {
733
+ start,
734
+ detail: {
735
+ ...resolvedOptions.detail,
736
+ devtools: resolvedOptions.devtools
737
+ }
738
+ });
739
+ return yield* exit2;
740
+ });
741
+
742
+ // src/async-task-tagging.ts
743
+ import * as Context3 from "effect/Context";
744
+ import * as Effect7 from "effect/Effect";
745
+ import { pipe as pipe3 } from "effect/Function";
746
+ import * as Layer from "effect/Layer";
747
+ import * as Predicate from "effect/Predicate";
748
+ import * as Tracer from "effect/Tracer";
749
+ var runInTask = /* @__PURE__ */ Symbol("runInTask");
750
+ var asyncTaskTaggingLayer = () => {
751
+ if (Predicate.hasProperty(console, "createTask") === false) {
752
+ return Layer.empty;
753
+ }
754
+ const makeTracer = Effect7.gen(function* () {
755
+ const oldTracer = yield* Effect7.tracer;
756
+ return Tracer.make({
757
+ span: (name, ...args) => {
758
+ const span = oldTracer.span(name, ...args);
759
+ const trace = console.createTask(name);
760
+ span[runInTask] = (f) => trace.run(f);
761
+ return span;
762
+ },
763
+ context: (f, fiber) => {
764
+ const maybeParentSpan = Context3.getOption(Tracer.ParentSpan)(fiber.currentContext);
765
+ if (maybeParentSpan._tag === "None") {
766
+ return oldTracer.context(f, fiber);
767
+ }
768
+ const parentSpan = maybeParentSpan.value;
769
+ if (parentSpan._tag === "ExternalSpan") {
770
+ return oldTracer.context(f, fiber);
771
+ }
772
+ const span = parentSpan;
773
+ if (runInTask in span && typeof span[runInTask] === "function") {
774
+ return span[runInTask](() => oldTracer.context(f, fiber));
775
+ }
776
+ return oldTracer.context(f, fiber);
777
+ }
778
+ });
779
+ });
780
+ return pipe3(makeTracer, Effect7.map(Layer.setTracer), Layer.unwrapEffect);
781
+ };
774
782
  export {
775
783
  dynamic_runtime_exports as DynamicRuntime,
776
784
  JsonPath,
777
785
  JsonProp,
778
786
  ParamKeyAnnotation,
787
+ Performance_exports as Performance,
779
788
  RuntimeProvider_exports as RuntimeProvider,
780
789
  UrlParser,
781
790
  VisitResult,
782
791
  acquireReleaseResource,
792
+ asyncTaskTaggingLayer,
783
793
  causeToError,
784
794
  contextFromScope,
785
795
  createJsonPath,
@@ -794,6 +804,7 @@ export {
794
804
  getDiscriminatedType,
795
805
  getDiscriminatingProps,
796
806
  getField,
807
+ getLiteralValues,
797
808
  getParamKeyAnnotation,
798
809
  getProperties,
799
810
  getValue,