@dxos/effect 0.8.4-main.e99c46d → 0.8.4-main.ef1bc66f44

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