@dxos/effect 0.8.4-main.84f28bd → 0.8.4-main.937b3ca

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 (77) hide show
  1. package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
  2. package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +421 -191
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing.mjs +38 -0
  7. package/dist/lib/browser/testing.mjs.map +7 -0
  8. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  9. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +421 -191
  11. package/dist/lib/node-esm/index.mjs.map +4 -4
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing.mjs +38 -0
  14. package/dist/lib/node-esm/testing.mjs.map +7 -0
  15. package/dist/types/src/RuntimeProvider.d.ts +21 -0
  16. package/dist/types/src/RuntimeProvider.d.ts.map +1 -0
  17. package/dist/types/src/ast.d.ts +36 -22
  18. package/dist/types/src/ast.d.ts.map +1 -1
  19. package/dist/types/src/atom-kvs.d.ts +19 -0
  20. package/dist/types/src/atom-kvs.d.ts.map +1 -0
  21. package/dist/types/src/context.d.ts +2 -1
  22. package/dist/types/src/context.d.ts.map +1 -1
  23. package/dist/types/src/dynamic-runtime.d.ts +56 -0
  24. package/dist/types/src/dynamic-runtime.d.ts.map +1 -0
  25. package/dist/types/src/dynamic-runtime.test.d.ts +2 -0
  26. package/dist/types/src/dynamic-runtime.test.d.ts.map +1 -0
  27. package/dist/types/src/errors.d.ts +35 -1
  28. package/dist/types/src/errors.d.ts.map +1 -1
  29. package/dist/types/src/index.d.ts +6 -2
  30. package/dist/types/src/index.d.ts.map +1 -1
  31. package/dist/types/src/interrupt.test.d.ts +2 -0
  32. package/dist/types/src/interrupt.test.d.ts.map +1 -0
  33. package/dist/types/src/{jsonPath.d.ts → json-path.d.ts} +12 -4
  34. package/dist/types/src/json-path.d.ts.map +1 -0
  35. package/dist/types/src/json-path.test.d.ts +2 -0
  36. package/dist/types/src/json-path.test.d.ts.map +1 -0
  37. package/dist/types/src/layers.test.d.ts +2 -0
  38. package/dist/types/src/layers.test.d.ts.map +1 -0
  39. package/dist/types/src/otel.d.ts +17 -0
  40. package/dist/types/src/otel.d.ts.map +1 -0
  41. package/dist/types/src/otel.test.d.ts +2 -0
  42. package/dist/types/src/otel.test.d.ts.map +1 -0
  43. package/dist/types/src/resource.d.ts +8 -0
  44. package/dist/types/src/resource.d.ts.map +1 -0
  45. package/dist/types/src/resource.test.d.ts +2 -0
  46. package/dist/types/src/resource.test.d.ts.map +1 -0
  47. package/dist/types/src/testing.d.ts +67 -0
  48. package/dist/types/src/testing.d.ts.map +1 -0
  49. package/dist/types/src/url.d.ts +3 -1
  50. package/dist/types/src/url.d.ts.map +1 -1
  51. package/dist/types/tsconfig.tsbuildinfo +1 -1
  52. package/package.json +34 -9
  53. package/src/RuntimeProvider.ts +35 -0
  54. package/src/ast.test.ts +14 -11
  55. package/src/ast.ts +119 -92
  56. package/src/atom-kvs.ts +35 -0
  57. package/src/context.ts +2 -1
  58. package/src/dynamic-runtime.test.ts +465 -0
  59. package/src/dynamic-runtime.ts +195 -0
  60. package/src/errors.test.ts +1 -1
  61. package/src/errors.ts +104 -27
  62. package/src/index.ts +6 -2
  63. package/src/interrupt.test.ts +35 -0
  64. package/src/{jsonPath.test.ts → json-path.test.ts} +47 -8
  65. package/src/{jsonPath.ts → json-path.ts} +29 -4
  66. package/src/layers.test.ts +112 -0
  67. package/src/otel.test.ts +126 -0
  68. package/src/otel.ts +45 -0
  69. package/src/resource.test.ts +32 -0
  70. package/src/resource.ts +30 -0
  71. package/src/sanity.test.ts +30 -15
  72. package/src/testing.ts +110 -0
  73. package/src/url.test.ts +1 -1
  74. package/src/url.ts +5 -2
  75. package/dist/types/src/jsonPath.d.ts.map +0 -1
  76. package/dist/types/src/jsonPath.test.d.ts +0 -2
  77. package/dist/types/src/jsonPath.test.d.ts.map +0 -1
@@ -1,70 +1,63 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ __export
4
+ } from "./chunk-HSLMI22Q.mjs";
2
5
 
3
6
  // src/ast.ts
4
- import { Option, pipe, SchemaAST, Schema } from "effect";
5
- import { isUndefinedKeyword } from "effect/SchemaAST";
7
+ import * as Function from "effect/Function";
8
+ import * as Option from "effect/Option";
9
+ import * as Schema from "effect/Schema";
10
+ import * as SchemaAST from "effect/SchemaAST";
6
11
  import { invariant } from "@dxos/invariant";
7
12
  import { isNonNullable } from "@dxos/util";
8
13
  var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
9
- var getSimpleType = (node) => {
10
- if (SchemaAST.isDeclaration(node) || SchemaAST.isObjectKeyword(node) || SchemaAST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {
11
- return "object";
12
- }
13
- if (SchemaAST.isStringKeyword(node)) {
14
- return "string";
15
- }
16
- if (SchemaAST.isNumberKeyword(node)) {
17
- return "number";
18
- }
19
- if (SchemaAST.isBooleanKeyword(node)) {
20
- return "boolean";
21
- }
22
- if (SchemaAST.isEnums(node)) {
23
- return "enum";
24
- }
25
- if (SchemaAST.isLiteral(node)) {
26
- return "literal";
27
- }
28
- };
29
- var isSimpleType = (node) => !!getSimpleType(node);
30
- (function(SimpleType2) {
31
- SimpleType2.getDefaultValue = (type) => {
32
- switch (type) {
33
- case "string": {
34
- return "";
35
- }
36
- case "number": {
37
- return 0;
14
+ var reduceRefinements = (type, refinements = []) => {
15
+ if (SchemaAST.isRefinement(type)) {
16
+ const annotations = type.annotations;
17
+ const filter = type.filter;
18
+ const nextType = {
19
+ ...type.from,
20
+ annotations: {
21
+ ...type.annotations,
22
+ ...annotations
38
23
  }
39
- case "boolean": {
40
- return false;
41
- }
42
- case "object": {
43
- return {};
44
- }
45
- default: {
46
- throw new Error(`Unsupported type for default value: ${type}`);
47
- }
48
- }
24
+ };
25
+ return reduceRefinements(nextType, [
26
+ ...refinements,
27
+ filter
28
+ ]);
29
+ }
30
+ return {
31
+ type,
32
+ refinements
49
33
  };
50
- })(SimpleType || (SimpleType = {}));
51
- var VisitResult = /* @__PURE__ */ function(VisitResult2) {
34
+ };
35
+ var getBaseType = (prop) => {
36
+ const encoded = SchemaAST.encodedBoundAST(prop.type);
37
+ const unwrapped = prop.isOptional && encoded._tag === "Union" ? encoded.types[0] : encoded;
38
+ return reduceRefinements(unwrapped);
39
+ };
40
+ var getProperties = (ast) => {
41
+ 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
+ }));
48
+ };
49
+ var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
52
50
  VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
53
51
  VisitResult2[VisitResult2["SKIP"] = 1] = "SKIP";
54
52
  VisitResult2[VisitResult2["EXIT"] = 2] = "EXIT";
55
53
  return VisitResult2;
56
- }({});
57
- var defaultTest = isSimpleType;
54
+ })({});
58
55
  var visit = (node, testOrVisitor, visitor) => {
59
- if (!visitor) {
60
- visitNode(node, defaultTest, testOrVisitor);
61
- } else {
62
- visitNode(node, testOrVisitor, visitor);
63
- }
56
+ visitNode(node, testOrVisitor, visitor);
64
57
  };
65
58
  var visitNode = (node, test, visitor, path = [], depth = 0) => {
66
- const _result = test?.(node, path, depth);
67
- const result = _result === void 0 ? 0 : typeof _result === "boolean" ? _result ? 0 : 1 : _result;
59
+ const $result = test?.(node, path, depth);
60
+ const result = $result === void 0 ? 0 : typeof $result === "boolean" ? $result ? 0 : 1 : $result;
68
61
  if (result === 2) {
69
62
  return result;
70
63
  }
@@ -117,6 +110,12 @@ var findNode = (node, test) => {
117
110
  return child;
118
111
  }
119
112
  }
113
+ for (const prop of getIndexSignatures(node)) {
114
+ const child = findNode(prop.type, test);
115
+ if (child) {
116
+ return child;
117
+ }
118
+ }
120
119
  } else if (SchemaAST.isTupleType(node)) {
121
120
  for (const [_, element] of node.elements.entries()) {
122
121
  const child = findNode(element.type, test);
@@ -125,12 +124,13 @@ var findNode = (node, test) => {
125
124
  }
126
125
  }
127
126
  } else if (SchemaAST.isUnion(node)) {
128
- if (isOption(node)) {
129
- for (const type of node.types) {
130
- const child = findNode(type, test);
131
- if (child) {
132
- return child;
133
- }
127
+ if (isLiteralUnion(node)) {
128
+ return void 0;
129
+ }
130
+ for (const type of node.types) {
131
+ const child = findNode(type, test);
132
+ if (child) {
133
+ return child;
134
134
  }
135
135
  }
136
136
  } else if (SchemaAST.isRefinement(node)) {
@@ -143,7 +143,7 @@ var findProperty = (schema, path) => {
143
143
  const typeNode = findNode(node, SchemaAST.isTypeLiteral);
144
144
  invariant(typeNode, void 0, {
145
145
  F: __dxlog_file,
146
- L: 247,
146
+ L: 235,
147
147
  S: void 0,
148
148
  A: [
149
149
  "typeNode",
@@ -168,16 +168,16 @@ var defaultAnnotations = {
168
168
  ["NumberKeyword"]: SchemaAST.numberKeyword,
169
169
  ["BooleanKeyword"]: SchemaAST.booleanKeyword
170
170
  };
171
- var getAnnotation = (annotationId, noDefault = true) => (node) => {
172
- const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
173
- const value = pipe(SchemaAST.getAnnotation(annotationId)(node), Option.getOrUndefined);
171
+ var getAnnotation2 = (annotationId, noDefault = true) => (node) => {
172
+ const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
173
+ const value = Function.pipe(SchemaAST.getAnnotation(annotationId)(node), Option.getOrUndefined);
174
174
  if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
175
175
  return void 0;
176
176
  }
177
177
  return value;
178
178
  };
179
179
  var findAnnotation = (node, annotationId, noDefault = true) => {
180
- const getAnnotationById = getAnnotation(annotationId, noDefault);
180
+ const getAnnotationById = getAnnotation2(annotationId, noDefault);
181
181
  const getBaseAnnotation = (node2) => {
182
182
  const value = getAnnotationById(node2);
183
183
  if (value !== void 0) {
@@ -197,13 +197,22 @@ var isOption = (node) => {
197
197
  var isLiteralUnion = (node) => {
198
198
  return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
199
199
  };
200
+ var isArrayType = (node) => {
201
+ return SchemaAST.isTupleType(node) && node.elements.length === 0 && node.rest.length === 1;
202
+ };
203
+ var getArrayElementType = (node) => {
204
+ return isArrayType(node) ? node.rest.at(0)?.type : void 0;
205
+ };
206
+ var isTupleType2 = (node) => {
207
+ return SchemaAST.isTupleType(node) && node.elements.length > 0;
208
+ };
200
209
  var isDiscriminatedUnion = (node) => {
201
210
  return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
202
211
  };
203
212
  var getDiscriminatingProps = (node) => {
204
213
  invariant(SchemaAST.isUnion(node), void 0, {
205
214
  F: __dxlog_file,
206
- L: 344,
215
+ L: 353,
207
216
  S: void 0,
208
217
  A: [
209
218
  "SchemaAST.isUnion(node)",
@@ -221,7 +230,7 @@ var getDiscriminatingProps = (node) => {
221
230
  var getDiscriminatedType = (node, value = {}) => {
222
231
  invariant(SchemaAST.isUnion(node), void 0, {
223
232
  F: __dxlog_file,
224
- L: 368,
233
+ L: 377,
225
234
  S: void 0,
226
235
  A: [
227
236
  "SchemaAST.isUnion(node)",
@@ -230,7 +239,7 @@ var getDiscriminatedType = (node, value = {}) => {
230
239
  });
231
240
  invariant(value, void 0, {
232
241
  F: __dxlog_file,
233
- L: 369,
242
+ L: 378,
234
243
  S: void 0,
235
244
  A: [
236
245
  "value",
@@ -245,7 +254,7 @@ var getDiscriminatedType = (node, value = {}) => {
245
254
  const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
246
255
  invariant(SchemaAST.isLiteral(prop.type), void 0, {
247
256
  F: __dxlog_file,
248
- L: 380,
257
+ L: 389,
249
258
  S: void 0,
250
259
  A: [
251
260
  "SchemaAST.isLiteral(prop.type)",
@@ -263,7 +272,7 @@ var getDiscriminatedType = (node, value = {}) => {
263
272
  const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
264
273
  invariant(SchemaAST.isLiteral(literal.type), void 0, {
265
274
  F: __dxlog_file,
266
- L: 398,
275
+ L: 407,
267
276
  S: void 0,
268
277
  A: [
269
278
  "SchemaAST.isLiteral(literal.type)",
@@ -280,10 +289,14 @@ var getDiscriminatedType = (node, value = {}) => {
280
289
  const schema = Schema.Struct(fields);
281
290
  return schema.ast;
282
291
  };
292
+ var isNestedType = (node) => {
293
+ return SchemaAST.isDeclaration(node) || SchemaAST.isObjectKeyword(node) || SchemaAST.isTypeLiteral(node) || // TODO(wittjosiah): Tuples are actually arrays.
294
+ isTupleType2(node) || isDiscriminatedUnion(node);
295
+ };
283
296
  var mapAst = (ast, f) => {
284
297
  switch (ast._tag) {
285
298
  case "TypeLiteral": {
286
- return new SchemaAST.TypeLiteral(ast.propertySignatures.map((prop) => new SchemaAST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
299
+ return new SchemaAST.TypeLiteral(ast.propertySignatures.map((prop) => new SchemaAST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures, ast.annotations);
287
300
  }
288
301
  case "Union": {
289
302
  return SchemaAST.Union.make(ast.types.map(f), ast.annotations);
@@ -300,16 +313,285 @@ var mapAst = (ast, f) => {
300
313
  }
301
314
  }
302
315
  };
303
- var isArrayType = (node) => {
304
- return SchemaAST.isTupleType(node) || SchemaAST.isUnion(node) && node.types.some(isArrayType) && node.types.some(isUndefinedKeyword) && node.types.length === 2;
316
+ var getIndexSignatures = (ast) => {
317
+ const annotation = SchemaAST.getSurrogateAnnotation(ast);
318
+ if (Option.isSome(annotation)) {
319
+ return getIndexSignatures(annotation.value);
320
+ }
321
+ switch (ast._tag) {
322
+ case "TypeLiteral":
323
+ return ast.indexSignatures.slice();
324
+ case "Suspend":
325
+ return getIndexSignatures(ast.f());
326
+ case "Refinement":
327
+ return getIndexSignatures(ast.from);
328
+ }
329
+ return [];
330
+ };
331
+
332
+ // src/atom-kvs.ts
333
+ import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
334
+ import { Atom } from "@effect-atom/atom-react";
335
+ var defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
336
+ var createKvsStore = (options) => {
337
+ const runtime2 = options.runtime ?? defaultRuntime;
338
+ return Atom.kvs({
339
+ runtime: runtime2,
340
+ key: options.key,
341
+ schema: options.schema,
342
+ defaultValue: options.defaultValue
343
+ }).pipe(Atom.keepAlive);
305
344
  };
306
- var SimpleType;
307
345
 
308
- // src/jsonPath.ts
309
- import { Schema as Schema2, Option as Option2 } from "effect";
346
+ // src/context.ts
347
+ import * as Effect from "effect/Effect";
348
+ import { Context } from "@dxos/context";
349
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
350
+ var contextFromScope = () => Effect.gen(function* () {
351
+ const ctx = new Context(void 0, {
352
+ F: __dxlog_file2,
353
+ L: 13
354
+ });
355
+ yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
356
+ return ctx;
357
+ });
358
+
359
+ // src/dynamic-runtime.ts
360
+ var dynamic_runtime_exports = {};
361
+ __export(dynamic_runtime_exports, {
362
+ make: () => make
363
+ });
364
+ import * as Context2 from "effect/Context";
365
+ import * as Effect3 from "effect/Effect";
366
+ import * as Exit2 from "effect/Exit";
367
+ import * as Option3 from "effect/Option";
368
+ import * as Runtime2 from "effect/Runtime";
369
+
370
+ // src/errors.ts
371
+ import * as Cause from "effect/Cause";
372
+ import * as Chunk from "effect/Chunk";
373
+ import * as Effect2 from "effect/Effect";
374
+ import * as Exit from "effect/Exit";
375
+ import * as GlobalValue from "effect/GlobalValue";
376
+ import * as Option2 from "effect/Option";
377
+ import * as Runtime from "effect/Runtime";
378
+ var spanSymbol = Symbol.for("effect/SpanAnnotation");
379
+ var originalSymbol = Symbol.for("effect/OriginalAnnotation");
380
+ var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
381
+ var locationRegex = /\((.*)\)/g;
382
+ var prettyErrorStack = (error, appendStacks = []) => {
383
+ if (typeof error !== "object" || error === null) {
384
+ return error;
385
+ }
386
+ const span = error[spanSymbol];
387
+ const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
388
+ const out = [];
389
+ let atStack = false;
390
+ for (let i = 0; i < lines.length; i++) {
391
+ if (!atStack && !lines[i].startsWith(" at ")) {
392
+ out.push(lines[i]);
393
+ continue;
394
+ }
395
+ atStack = true;
396
+ if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
397
+ i++;
398
+ continue;
399
+ }
400
+ if (lines[i].includes("Generator.next")) {
401
+ break;
402
+ }
403
+ if (lines[i].includes("effect_internal_function")) {
404
+ break;
405
+ }
406
+ out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
407
+ }
408
+ if (span) {
409
+ let current = span;
410
+ let i = 0;
411
+ while (current && current._tag === "Span" && i < 10) {
412
+ const stackFn = spanToTrace.get(current);
413
+ if (typeof stackFn === "function") {
414
+ const stack = stackFn();
415
+ if (typeof stack === "string") {
416
+ const locationMatchAll = stack.matchAll(locationRegex);
417
+ let match = false;
418
+ for (const [, location] of locationMatchAll) {
419
+ match = true;
420
+ out.push(` at ${current.name} (${location})`);
421
+ }
422
+ if (!match) {
423
+ out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
424
+ }
425
+ } else {
426
+ out.push(` at ${current.name}`);
427
+ }
428
+ } else {
429
+ out.push(` at ${current.name}`);
430
+ }
431
+ current = Option2.getOrUndefined(current.parent);
432
+ i++;
433
+ }
434
+ }
435
+ out.push(...appendStacks);
436
+ if (error[originalSymbol]) {
437
+ error = error[originalSymbol];
438
+ }
439
+ if (error.cause) {
440
+ error.cause = prettyErrorStack(error.cause);
441
+ }
442
+ Object.defineProperty(error, "stack", {
443
+ value: out.join("\n"),
444
+ writable: true,
445
+ enumerable: false,
446
+ configurable: true
447
+ });
448
+ return error;
449
+ };
450
+ var causeToError = (cause) => {
451
+ if (Cause.isEmpty(cause)) {
452
+ return new Error("Fiber failed without a cause");
453
+ } else if (Cause.isInterruptedOnly(cause)) {
454
+ return new Error("Fiber was interrupted");
455
+ } else {
456
+ const errors = [
457
+ ...Chunk.toArray(Cause.failures(cause)),
458
+ ...Chunk.toArray(Cause.defects(cause))
459
+ ];
460
+ const getStackFrames = () => {
461
+ const o = new Error();
462
+ Error.captureStackTrace(o, getStackFrames);
463
+ return o.stack.split("\n").slice(1);
464
+ };
465
+ const stackFrames = getStackFrames();
466
+ const newErrors = errors.map((error) => prettyErrorStack(error, stackFrames));
467
+ if (newErrors.length === 1) {
468
+ return newErrors[0];
469
+ } else {
470
+ return new AggregateError(newErrors);
471
+ }
472
+ }
473
+ };
474
+ var throwCause = (cause) => {
475
+ throw causeToError(cause);
476
+ };
477
+ var unwrapExit = (exit) => {
478
+ if (Exit.isSuccess(exit)) {
479
+ return exit.value;
480
+ }
481
+ return throwCause(exit.cause);
482
+ };
483
+ 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);
490
+ };
491
+ var promiseWithCauseCapture = (evaluate) => Effect2.promise(async (signal) => {
492
+ try {
493
+ const result = await evaluate(signal);
494
+ return Effect2.succeed(result);
495
+ } catch (err) {
496
+ return Effect2.die(err);
497
+ }
498
+ }).pipe(Effect2.flatten);
499
+
500
+ // src/dynamic-runtime.ts
501
+ var validateTags = (context, tags) => Effect3.gen(function* () {
502
+ const missingTags = [];
503
+ for (const tag of tags) {
504
+ const option = Context2.getOption(context, tag);
505
+ if (Option3.isNone(option)) {
506
+ missingTags.push(tag.key);
507
+ }
508
+ }
509
+ if (missingTags.length > 0) {
510
+ return yield* Effect3.die(new Error(`Missing required tags in runtime: ${missingTags.join(", ")}`));
511
+ }
512
+ });
513
+ function make(managedRuntime, tags) {
514
+ const managedRuntimeAny = managedRuntime;
515
+ let cachedRuntime;
516
+ let validatedRuntimePromise;
517
+ const getValidatedRuntimeAsync = async () => {
518
+ if (!validatedRuntimePromise) {
519
+ validatedRuntimePromise = managedRuntimeAny.runPromise(Effect3.gen(function* () {
520
+ const rt = yield* managedRuntimeAny.runtimeEffect;
521
+ yield* validateTags(rt.context, tags);
522
+ return rt;
523
+ }));
524
+ }
525
+ return validatedRuntimePromise;
526
+ };
527
+ const getValidatedRuntime = () => {
528
+ const validationExit = managedRuntimeAny.runSyncExit(Effect3.gen(function* () {
529
+ const rt = yield* managedRuntimeAny.runtimeEffect;
530
+ yield* validateTags(rt.context, tags);
531
+ return rt;
532
+ }));
533
+ return unwrapExit(validationExit);
534
+ };
535
+ return {
536
+ managedRuntime: managedRuntimeAny,
537
+ runPromise: async (effect) => {
538
+ const runtime2 = await getValidatedRuntimeAsync();
539
+ return Runtime2.runPromise(runtime2)(effect);
540
+ },
541
+ runSync: (effect) => {
542
+ const runtime2 = getValidatedRuntime();
543
+ return Runtime2.runSync(runtime2)(effect);
544
+ },
545
+ runSyncExit: (effect) => {
546
+ const validationExit = managedRuntimeAny.runSyncExit(Effect3.gen(function* () {
547
+ const rt = yield* managedRuntimeAny.runtimeEffect;
548
+ yield* validateTags(rt.context, tags);
549
+ return rt;
550
+ }));
551
+ if (Exit2.isSuccess(validationExit)) {
552
+ const runtime2 = validationExit.value;
553
+ return Runtime2.runSyncExit(runtime2)(effect);
554
+ }
555
+ return validationExit;
556
+ },
557
+ runPromiseExit: async (effect) => {
558
+ try {
559
+ const runtime2 = await getValidatedRuntimeAsync();
560
+ return Runtime2.runPromiseExit(runtime2)(effect);
561
+ } catch (error) {
562
+ return Exit2.die(error);
563
+ }
564
+ },
565
+ runFork: (effect) => {
566
+ const runtime2 = getValidatedRuntime();
567
+ return Runtime2.runFork(runtime2)(effect);
568
+ },
569
+ runtimeEffect: Effect3.gen(function* () {
570
+ if (cachedRuntime) {
571
+ return cachedRuntime;
572
+ }
573
+ const rt = yield* managedRuntimeAny.runtimeEffect;
574
+ yield* validateTags(rt.context, tags);
575
+ const runtime2 = rt;
576
+ cachedRuntime = runtime2;
577
+ return runtime2;
578
+ }).pipe(Effect3.catchAll(() => (
579
+ // This should never happen since validateTags uses Effect.die
580
+ Effect3.die(new Error("Unexpected error in runtimeEffect validation"))
581
+ ))),
582
+ dispose: async () => {
583
+ await managedRuntimeAny.dispose();
584
+ }
585
+ };
586
+ }
587
+
588
+ // src/json-path.ts
589
+ import * as Option4 from "effect/Option";
590
+ import * as Schema2 from "effect/Schema";
310
591
  import { JSONPath } from "jsonpath-plus";
311
592
  import { invariant as invariant2 } from "@dxos/invariant";
312
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/jsonPath.ts";
593
+ import { getDeep, setDeep } from "@dxos/util";
594
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/json-path.ts";
313
595
  var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
314
596
  var PROP_REGEX = /^\w+$/;
315
597
  var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
@@ -320,7 +602,7 @@ var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
320
602
  message: () => "Property name must contain only letters, numbers, and underscores"
321
603
  }));
322
604
  var isJsonPath = (value) => {
323
- return Option2.isSome(Schema2.validateOption(JsonPath)(value));
605
+ return Option4.isSome(Schema2.validateOption(JsonPath)(value));
324
606
  };
325
607
  var createJsonPath = (path) => {
326
608
  const candidatePath = path.map((p, i) => {
@@ -331,8 +613,8 @@ var createJsonPath = (path) => {
331
613
  }
332
614
  }).join("");
333
615
  invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
334
- F: __dxlog_file2,
335
- L: 63,
616
+ F: __dxlog_file3,
617
+ L: 69,
336
618
  S: void 0,
337
619
  A: [
338
620
  "isJsonPath(candidatePath)",
@@ -344,8 +626,8 @@ var createJsonPath = (path) => {
344
626
  var fromEffectValidationPath = (effectPath) => {
345
627
  const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
346
628
  invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
347
- F: __dxlog_file2,
348
- L: 74,
629
+ F: __dxlog_file3,
630
+ L: 80,
349
631
  S: void 0,
350
632
  A: [
351
633
  "isJsonPath(jsonPath)",
@@ -358,7 +640,10 @@ var splitJsonPath = (path) => {
358
640
  if (!isJsonPath(path)) {
359
641
  return [];
360
642
  }
361
- return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.startsWith("[") ? part.replace(/[[\]]/g, "") : part) ?? [];
643
+ return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.replace(/[[\]]/g, "")).map((part) => {
644
+ const parsed = Number.parseInt(part, 10);
645
+ return Number.isNaN(parsed) ? part : parsed;
646
+ }) ?? [];
362
647
  };
363
648
  var getField = (object, path) => {
364
649
  return JSONPath({
@@ -366,9 +651,31 @@ var getField = (object, path) => {
366
651
  json: object
367
652
  })[0];
368
653
  };
654
+ var getValue = (obj, path) => {
655
+ return getDeep(obj, splitJsonPath(path));
656
+ };
657
+ var setValue = (obj, path, value) => {
658
+ return setDeep(obj, splitJsonPath(path), value);
659
+ };
660
+
661
+ // src/resource.ts
662
+ import * as Effect4 from "effect/Effect";
663
+ var acquireReleaseResource = (getResource) => Effect4.acquireRelease(Effect4.gen(function* () {
664
+ const resource = getResource();
665
+ yield* Effect4.promise(async () => {
666
+ await resource.open?.();
667
+ return void 0;
668
+ });
669
+ return resource;
670
+ }), (resource) => Effect4.promise(async () => {
671
+ await resource.close?.();
672
+ return void 0;
673
+ }));
369
674
 
370
675
  // src/url.ts
371
- import { SchemaAST as SchemaAST2, Option as Option3, pipe as pipe2 } from "effect";
676
+ import * as Function2 from "effect/Function";
677
+ import * as Option5 from "effect/Option";
678
+ import * as SchemaAST2 from "effect/SchemaAST";
372
679
  import { decamelize } from "@dxos/util";
373
680
  var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
374
681
  var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
@@ -376,6 +683,7 @@ var ParamKeyAnnotation = (value) => (self) => self.annotations({
376
683
  [ParamKeyAnnotationId]: value
377
684
  });
378
685
  var UrlParser = class {
686
+ _schema;
379
687
  constructor(_schema) {
380
688
  this._schema = _schema;
381
689
  }
@@ -410,7 +718,7 @@ var UrlParser = class {
410
718
  if (value !== void 0) {
411
719
  const field = this._schema.fields[key];
412
720
  if (field) {
413
- const { key: serializedKey } = pipe2(getParamKeyAnnotation(field.ast), Option3.getOrElse(() => ({
721
+ const { key: serializedKey } = Function2.pipe(getParamKeyAnnotation(field.ast), Option5.getOrElse(() => ({
414
722
  key: decamelize(key)
415
723
  })));
416
724
  url.searchParams.set(serializedKey, String(value));
@@ -421,140 +729,62 @@ var UrlParser = class {
421
729
  }
422
730
  };
423
731
 
424
- // src/context.ts
425
- import { Effect } from "effect";
426
- import { Context } from "@dxos/context";
427
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
428
- var contextFromScope = () => Effect.gen(function* () {
429
- const ctx = new Context(void 0, {
430
- F: __dxlog_file3,
431
- L: 12
432
- });
433
- yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
434
- return ctx;
732
+ // src/RuntimeProvider.ts
733
+ var RuntimeProvider_exports = {};
734
+ __export(RuntimeProvider_exports, {
735
+ currentRuntime: () => currentRuntime,
736
+ provide: () => provide2,
737
+ runPromise: () => runPromise2
435
738
  });
436
-
437
- // src/errors.ts
438
- import { Cause, Chunk, Effect as Effect2, Exit, GlobalValue, Option as Option4 } from "effect";
439
- var spanSymbol = Symbol.for("effect/SpanAnnotation");
440
- var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
441
- var locationRegex = /\((.*)\)/g;
442
- var prettyErrorStack = (error, appendStacks = []) => {
443
- const span = error[spanSymbol];
444
- const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
445
- const out = [];
446
- let atStack = false;
447
- for (let i = 0; i < lines.length; i++) {
448
- if (!atStack && !lines[i].startsWith(" at ")) {
449
- out.push(lines[i]);
450
- continue;
451
- }
452
- atStack = true;
453
- if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
454
- i++;
455
- continue;
456
- }
457
- if (lines[i].includes("Generator.next")) {
458
- break;
459
- }
460
- if (lines[i].includes("effect_internal_function")) {
461
- break;
462
- }
463
- out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
464
- }
465
- if (span) {
466
- let current = span;
467
- let i = 0;
468
- while (current && current._tag === "Span" && i < 10) {
469
- const stackFn = spanToTrace.get(current);
470
- if (typeof stackFn === "function") {
471
- const stack = stackFn();
472
- if (typeof stack === "string") {
473
- const locationMatchAll = stack.matchAll(locationRegex);
474
- let match = false;
475
- for (const [, location] of locationMatchAll) {
476
- match = true;
477
- out.push(` at ${current.name} (${location})`);
478
- }
479
- if (!match) {
480
- out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
481
- }
482
- } else {
483
- out.push(` at ${current.name}`);
484
- }
485
- } else {
486
- out.push(` at ${current.name}`);
487
- }
488
- current = Option4.getOrUndefined(current.parent);
489
- i++;
490
- }
491
- }
492
- out.push(...appendStacks);
493
- Object.defineProperty(error, "stack", {
494
- value: out.join("\n"),
495
- writable: true,
496
- enumerable: false,
497
- configurable: true
498
- });
499
- };
500
- var runAndForwardErrors = async (effect, options) => {
501
- const exit = await Effect2.runPromiseExit(effect, options);
502
- if (Exit.isSuccess(exit)) {
503
- return exit.value;
504
- }
505
- if (Cause.isEmpty(exit.cause)) {
506
- throw new Error("Fiber failed without a cause");
507
- } else if (Cause.isInterrupted(exit.cause)) {
508
- throw new Error("Fiber was interrupted");
509
- } else {
510
- const errors = [
511
- ...Chunk.toArray(Cause.failures(exit.cause)),
512
- ...Chunk.toArray(Cause.defects(exit.cause))
513
- ];
514
- const getStackFrames = () => {
515
- const o = {};
516
- Error.captureStackTrace(o, getStackFrames);
517
- return o.stack.split("\n").slice(1);
518
- };
519
- const stackFrames = getStackFrames();
520
- for (const error of errors) {
521
- prettyErrorStack(error, stackFrames);
522
- }
523
- if (errors.length === 1) {
524
- throw errors[0];
525
- } else {
526
- throw new AggregateError(errors);
527
- }
528
- }
739
+ import * as Effect5 from "effect/Effect";
740
+ import * as Runtime3 from "effect/Runtime";
741
+ var currentRuntime = () => Effect5.runtime().pipe(Effect5.map(Effect5.succeed));
742
+ var runPromise2 = (provider) => async (effect) => {
743
+ const runtime2 = await runAndForwardErrors(provider);
744
+ return unwrapExit(await effect.pipe(Runtime3.runPromiseExit(runtime2)));
529
745
  };
746
+ var provide2 = (runtimeProvider) => (effect) => Effect5.flatMap(runtimeProvider, (runtime2) => Effect5.provide(effect, runtime2));
530
747
  export {
748
+ dynamic_runtime_exports as DynamicRuntime,
531
749
  JsonPath,
532
750
  JsonProp,
533
751
  ParamKeyAnnotation,
534
- SimpleType,
752
+ RuntimeProvider_exports as RuntimeProvider,
535
753
  UrlParser,
536
754
  VisitResult,
755
+ acquireReleaseResource,
756
+ causeToError,
537
757
  contextFromScope,
538
758
  createJsonPath,
759
+ createKvsStore,
539
760
  findAnnotation,
540
761
  findNode,
541
762
  findProperty,
542
763
  fromEffectValidationPath,
543
- getAnnotation,
764
+ getAnnotation2 as getAnnotation,
765
+ getArrayElementType,
766
+ getBaseType,
544
767
  getDiscriminatedType,
545
768
  getDiscriminatingProps,
546
769
  getField,
547
770
  getParamKeyAnnotation,
548
- getSimpleType,
771
+ getProperties,
772
+ getValue,
549
773
  isArrayType,
550
774
  isDiscriminatedUnion,
551
775
  isJsonPath,
552
776
  isLiteralUnion,
777
+ isNestedType,
553
778
  isOption,
554
- isSimpleType,
779
+ isTupleType2 as isTupleType,
555
780
  mapAst,
781
+ promiseWithCauseCapture,
556
782
  runAndForwardErrors,
783
+ runInRuntime,
784
+ setValue,
557
785
  splitJsonPath,
786
+ throwCause,
787
+ unwrapExit,
558
788
  visit
559
789
  };
560
790
  //# sourceMappingURL=index.mjs.map