@dxos/effect 0.8.4-main.72ec0f3 → 0.8.4-main.8342792842

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 (54) 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 +365 -220
  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 +365 -220
  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 +34 -21
  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/dynamic-runtime.d.ts +56 -0
  22. package/dist/types/src/dynamic-runtime.d.ts.map +1 -0
  23. package/dist/types/src/dynamic-runtime.test.d.ts +2 -0
  24. package/dist/types/src/dynamic-runtime.test.d.ts.map +1 -0
  25. package/dist/types/src/errors.d.ts +12 -0
  26. package/dist/types/src/errors.d.ts.map +1 -1
  27. package/dist/types/src/index.d.ts +5 -3
  28. package/dist/types/src/index.d.ts.map +1 -1
  29. package/dist/types/src/{jsonPath.d.ts → json-path.d.ts} +11 -3
  30. package/dist/types/src/json-path.d.ts.map +1 -0
  31. package/dist/types/src/json-path.test.d.ts +2 -0
  32. package/dist/types/src/json-path.test.d.ts.map +1 -0
  33. package/dist/types/src/testing.d.ts +1 -0
  34. package/dist/types/src/testing.d.ts.map +1 -1
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +29 -10
  37. package/src/RuntimeProvider.ts +35 -0
  38. package/src/ast.test.ts +35 -8
  39. package/src/ast.ts +81 -87
  40. package/src/atom-kvs.ts +35 -0
  41. package/src/dynamic-runtime.test.ts +465 -0
  42. package/src/dynamic-runtime.ts +195 -0
  43. package/src/errors.ts +69 -8
  44. package/src/index.ts +5 -3
  45. package/src/interrupt.test.ts +3 -1
  46. package/src/{jsonPath.test.ts → json-path.test.ts} +47 -8
  47. package/src/{jsonPath.ts → json-path.ts} +26 -3
  48. package/src/layers.test.ts +4 -2
  49. package/src/resource.ts +2 -2
  50. package/src/sanity.test.ts +6 -4
  51. package/src/testing.ts +3 -1
  52. package/dist/types/src/jsonPath.d.ts.map +0 -1
  53. package/dist/types/src/jsonPath.test.d.ts +0 -2
  54. package/dist/types/src/jsonPath.test.d.ts.map +0 -1
@@ -1,4 +1,7 @@
1
1
  import "@dxos/node-std/globals";
2
+ import {
3
+ __export
4
+ } from "./chunk-CGS2ULMK.mjs";
2
5
 
3
6
  // src/ast.ts
4
7
  import * as Function from "effect/Function";
@@ -8,65 +11,48 @@ import * as SchemaAST from "effect/SchemaAST";
8
11
  import { invariant } from "@dxos/invariant";
9
12
  import { isNonNullable } from "@dxos/util";
10
13
  var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
11
- var isTupleType2 = (node) => {
12
- return SchemaAST.isTupleType(node) && node.elements.length > 0;
13
- };
14
- var getSimpleType = (node) => {
15
- if (SchemaAST.isDeclaration(node) || SchemaAST.isObjectKeyword(node) || SchemaAST.isTypeLiteral(node) || // TODO(wittjosiah): Tuples are actually arrays.
16
- isTupleType2(node) || isDiscriminatedUnion(node)) {
17
- return "object";
18
- }
19
- if (SchemaAST.isStringKeyword(node)) {
20
- return "string";
21
- }
22
- if (SchemaAST.isNumberKeyword(node)) {
23
- return "number";
24
- }
25
- if (SchemaAST.isBooleanKeyword(node)) {
26
- return "boolean";
27
- }
28
- if (SchemaAST.isEnums(node)) {
29
- return "enum";
30
- }
31
- if (SchemaAST.isLiteral(node)) {
32
- return "literal";
33
- }
34
- };
35
- var isSimpleType = (node) => !!getSimpleType(node);
36
- (function(SimpleType2) {
37
- SimpleType2.getDefaultValue = (type) => {
38
- switch (type) {
39
- case "string": {
40
- 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
41
22
  }
42
- case "number": {
43
- return 0;
44
- }
45
- case "boolean": {
46
- return false;
47
- }
48
- case "object": {
49
- return {};
50
- }
51
- default: {
52
- throw new Error(`Unsupported type for default value: ${type}`);
53
- }
54
- }
23
+ };
24
+ return reduceRefinements(nextType, [
25
+ ...refinements,
26
+ filter
27
+ ]);
28
+ }
29
+ return {
30
+ type,
31
+ refinements
55
32
  };
56
- })(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
+ };
57
48
  var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
58
49
  VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
59
50
  VisitResult2[VisitResult2["SKIP"] = 1] = "SKIP";
60
51
  VisitResult2[VisitResult2["EXIT"] = 2] = "EXIT";
61
52
  return VisitResult2;
62
53
  })({});
63
- var defaultTest = isSimpleType;
64
54
  var visit = (node, testOrVisitor, visitor) => {
65
- if (!visitor) {
66
- visitNode(node, defaultTest, testOrVisitor);
67
- } else {
68
- visitNode(node, testOrVisitor, visitor);
69
- }
55
+ visitNode(node, testOrVisitor, visitor);
70
56
  };
71
57
  var visitNode = (node, test, visitor, path = [], depth = 0) => {
72
58
  const $result = test?.(node, path, depth);
@@ -156,7 +142,7 @@ var findProperty = (schema, path) => {
156
142
  const typeNode = findNode(node, SchemaAST.isTypeLiteral);
157
143
  invariant(typeNode, void 0, {
158
144
  F: __dxlog_file,
159
- L: 265,
145
+ L: 237,
160
146
  S: void 0,
161
147
  A: [
162
148
  "typeNode",
@@ -210,13 +196,22 @@ var isOption = (node) => {
210
196
  var isLiteralUnion = (node) => {
211
197
  return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
212
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
+ };
213
208
  var isDiscriminatedUnion = (node) => {
214
209
  return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
215
210
  };
216
211
  var getDiscriminatingProps = (node) => {
217
212
  invariant(SchemaAST.isUnion(node), void 0, {
218
213
  F: __dxlog_file,
219
- L: 362,
214
+ L: 355,
220
215
  S: void 0,
221
216
  A: [
222
217
  "SchemaAST.isUnion(node)",
@@ -234,7 +229,7 @@ var getDiscriminatingProps = (node) => {
234
229
  var getDiscriminatedType = (node, value = {}) => {
235
230
  invariant(SchemaAST.isUnion(node), void 0, {
236
231
  F: __dxlog_file,
237
- L: 386,
232
+ L: 379,
238
233
  S: void 0,
239
234
  A: [
240
235
  "SchemaAST.isUnion(node)",
@@ -243,7 +238,7 @@ var getDiscriminatedType = (node, value = {}) => {
243
238
  });
244
239
  invariant(value, void 0, {
245
240
  F: __dxlog_file,
246
- L: 387,
241
+ L: 380,
247
242
  S: void 0,
248
243
  A: [
249
244
  "value",
@@ -258,7 +253,7 @@ var getDiscriminatedType = (node, value = {}) => {
258
253
  const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
259
254
  invariant(SchemaAST.isLiteral(prop.type), void 0, {
260
255
  F: __dxlog_file,
261
- L: 398,
256
+ L: 391,
262
257
  S: void 0,
263
258
  A: [
264
259
  "SchemaAST.isLiteral(prop.type)",
@@ -276,7 +271,7 @@ var getDiscriminatedType = (node, value = {}) => {
276
271
  const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
277
272
  invariant(SchemaAST.isLiteral(literal.type), void 0, {
278
273
  F: __dxlog_file,
279
- L: 416,
274
+ L: 409,
280
275
  S: void 0,
281
276
  A: [
282
277
  "SchemaAST.isLiteral(literal.type)",
@@ -293,6 +288,10 @@ var getDiscriminatedType = (node, value = {}) => {
293
288
  const schema = Schema.Struct(fields);
294
289
  return schema.ast;
295
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
+ };
296
295
  var mapAst = (ast, f) => {
297
296
  switch (ast._tag) {
298
297
  case "TypeLiteral": {
@@ -313,9 +312,6 @@ var mapAst = (ast, f) => {
313
312
  }
314
313
  }
315
314
  };
316
- var isArrayType = (node) => {
317
- return SchemaAST.isTupleType(node) || SchemaAST.isUnion(node) && node.types.some(isArrayType) && node.types.some(SchemaAST.isUndefinedKeyword) && node.types.length === 2;
318
- };
319
315
  var getIndexSignatures = (ast) => {
320
316
  const annotation = SchemaAST.getSurrogateAnnotation(ast);
321
317
  if (Option.isSome(annotation)) {
@@ -331,157 +327,64 @@ var getIndexSignatures = (ast) => {
331
327
  }
332
328
  return [];
333
329
  };
334
- var SimpleType;
335
-
336
- // src/jsonPath.ts
337
- import * as Option2 from "effect/Option";
338
- import * as Schema2 from "effect/Schema";
339
- import { JSONPath } from "jsonpath-plus";
340
- import { invariant as invariant2 } from "@dxos/invariant";
341
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/jsonPath.ts";
342
- var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
343
- var PROP_REGEX = /^\w+$/;
344
- var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
345
- title: "JSON path",
346
- description: "JSON path to a property"
347
- });
348
- var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
349
- message: () => "Property name must contain only letters, numbers, and underscores"
350
- }));
351
- var isJsonPath = (value) => {
352
- return Option2.isSome(Schema2.validateOption(JsonPath)(value));
353
- };
354
- var createJsonPath = (path) => {
355
- const candidatePath = path.map((p, i) => {
356
- if (typeof p === "number") {
357
- return `[${p}]`;
358
- } else {
359
- return i === 0 ? p : `.${p}`;
360
- }
361
- }).join("");
362
- invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
363
- F: __dxlog_file2,
364
- L: 65,
365
- S: void 0,
366
- A: [
367
- "isJsonPath(candidatePath)",
368
- "`Invalid JsonPath: ${candidatePath}`"
369
- ]
370
- });
371
- return candidatePath;
372
- };
373
- var fromEffectValidationPath = (effectPath) => {
374
- const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
375
- invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
376
- F: __dxlog_file2,
377
- L: 76,
378
- S: void 0,
379
- A: [
380
- "isJsonPath(jsonPath)",
381
- "`Invalid JsonPath: ${jsonPath}`"
382
- ]
383
- });
384
- return jsonPath;
385
- };
386
- var splitJsonPath = (path) => {
387
- if (!isJsonPath(path)) {
388
- return [];
389
- }
390
- return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.startsWith("[") ? part.replace(/[[\]]/g, "") : part) ?? [];
391
- };
392
- var getField = (object, path) => {
393
- return JSONPath({
394
- path,
395
- json: object
396
- })[0];
397
- };
398
330
 
399
- // src/url.ts
400
- import * as Function2 from "effect/Function";
401
- import * as Option3 from "effect/Option";
402
- import * as SchemaAST2 from "effect/SchemaAST";
403
- import { decamelize } from "@dxos/util";
404
- var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
405
- var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
406
- var ParamKeyAnnotation = (value) => (self) => self.annotations({
407
- [ParamKeyAnnotationId]: value
408
- });
409
- var UrlParser = class {
410
- _schema;
411
- constructor(_schema) {
412
- this._schema = _schema;
413
- }
414
- /**
415
- * Parse URL params.
416
- */
417
- parse(_url) {
418
- const url = new URL(_url);
419
- return Object.entries(this._schema.fields).reduce((params, [key, type]) => {
420
- let value = url.searchParams.get(decamelize(key));
421
- if (value == null) {
422
- value = url.searchParams.get(key);
423
- }
424
- if (value != null) {
425
- if (SchemaAST2.isNumberKeyword(type.ast)) {
426
- params[key] = parseInt(value);
427
- } else if (SchemaAST2.isBooleanKeyword(type.ast)) {
428
- params[key] = value === "true" || value === "1";
429
- } else {
430
- params[key] = value;
431
- }
432
- }
433
- return params;
434
- }, {});
435
- }
436
- /**
437
- * Return URL with encoded params.
438
- */
439
- create(_url, params) {
440
- const url = new URL(_url);
441
- Object.entries(params).forEach(([key, value]) => {
442
- if (value !== void 0) {
443
- const field = this._schema.fields[key];
444
- if (field) {
445
- const { key: serializedKey } = Function2.pipe(getParamKeyAnnotation(field.ast), Option3.getOrElse(() => ({
446
- key: decamelize(key)
447
- })));
448
- url.searchParams.set(serializedKey, String(value));
449
- }
450
- }
451
- });
452
- return url;
453
- }
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);
454
343
  };
455
344
 
456
345
  // src/context.ts
457
346
  import * as Effect from "effect/Effect";
458
347
  import { Context } from "@dxos/context";
459
- 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";
460
349
  var contextFromScope = () => Effect.gen(function* () {
461
350
  const ctx = new Context(void 0, {
462
- F: __dxlog_file3,
351
+ F: __dxlog_file2,
463
352
  L: 13
464
353
  });
465
354
  yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
466
355
  return ctx;
467
356
  });
468
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
+
469
369
  // src/errors.ts
470
370
  import * as Cause from "effect/Cause";
471
371
  import * as Chunk from "effect/Chunk";
472
372
  import * as Effect2 from "effect/Effect";
473
373
  import * as Exit from "effect/Exit";
474
374
  import * as GlobalValue from "effect/GlobalValue";
475
- import * as Option4 from "effect/Option";
375
+ import * as Option2 from "effect/Option";
376
+ import * as Runtime from "effect/Runtime";
476
377
  var spanSymbol = Symbol.for("effect/SpanAnnotation");
477
- var originalSymbol = Symbol.for("effect/OriginalAnnotation");
478
378
  var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
479
379
  var locationRegex = /\((.*)\)/g;
480
380
  var prettyErrorStack = (error, appendStacks = []) => {
381
+ if (typeof error !== "object" || error === null) {
382
+ return error;
383
+ }
481
384
  const span = error[spanSymbol];
482
385
  const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
483
386
  const out = [];
484
- let atStack = false;
387
+ let atStack = false, inCore = false, passedScheduler = false;
485
388
  for (let i = 0; i < lines.length; i++) {
486
389
  if (!atStack && !lines[i].startsWith(" at ")) {
487
390
  out.push(lines[i]);
@@ -498,6 +401,26 @@ var prettyErrorStack = (error, appendStacks = []) => {
498
401
  if (lines[i].includes("effect_internal_function")) {
499
402
  break;
500
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
+ }
501
424
  out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
502
425
  }
503
426
  if (span) {
@@ -523,14 +446,12 @@ var prettyErrorStack = (error, appendStacks = []) => {
523
446
  } else {
524
447
  out.push(` at ${current.name}`);
525
448
  }
526
- current = Option4.getOrUndefined(current.parent);
449
+ current = Option2.getOrUndefined(current.parent);
527
450
  i++;
528
451
  }
529
452
  }
530
453
  out.push(...appendStacks);
531
- if (error[originalSymbol]) {
532
- error = error[originalSymbol];
533
- }
454
+ error = Cause.originalError(error);
534
455
  if (error.cause) {
535
456
  error.cause = prettyErrorStack(error.cause);
536
457
  }
@@ -553,8 +474,8 @@ var causeToError = (cause) => {
553
474
  ...Chunk.toArray(Cause.defects(cause))
554
475
  ];
555
476
  const getStackFrames = () => {
556
- const o = {};
557
- Error.captureStackTrace(o, getStackFrames);
477
+ const o = new Error();
478
+ Error.captureStackTrace(o, causeToError);
558
479
  return o.stack.split("\n").slice(1);
559
480
  };
560
481
  const stackFrames = getStackFrames();
@@ -579,6 +500,21 @@ var runAndForwardErrors = async (effect, options) => {
579
500
  const exit = await Effect2.runPromiseExit(effect, options);
580
501
  return unwrapExit(exit);
581
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
+ };
582
518
  var promiseWithCauseCapture = (evaluate) => Effect2.promise(async (signal) => {
583
519
  try {
584
520
  const result = await evaluate(signal);
@@ -588,82 +524,291 @@ var promiseWithCauseCapture = (evaluate) => Effect2.promise(async (signal) => {
588
524
  }
589
525
  }).pipe(Effect2.flatten);
590
526
 
591
- // src/testing.ts
592
- import * as Context2 from "effect/Context";
593
- import * as Effect3 from "effect/Effect";
594
- (function(TestHelpers2) {
595
- TestHelpers2.runIf = (condition) => (effect, ctx) => Effect3.gen(function* () {
596
- if (!condition) {
597
- ctx.skip();
598
- } else {
599
- 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);
600
534
  }
601
- });
602
- TestHelpers2.skipIf = (condition) => (effect, ctx) => Effect3.gen(function* () {
603
- if (condition) {
604
- ctx.skip();
605
- } else {
606
- 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
+ }));
607
551
  }
608
- });
609
- TestHelpers2.taggedTest = (tag) => (effect, ctx) => Effect3.gen(function* () {
610
- if (!process.env.DX_TEST_TAGS?.includes(tag)) {
611
- 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}]`;
612
638
  } else {
613
- return yield* effect;
639
+ return i === 0 ? p : `.${p}`;
614
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
+ ]
615
663
  });
616
- TestHelpers2.provideTestContext = (effect, ctx) => Effect3.provideService(effect, TestContextService, ctx);
617
- })(TestHelpers || (TestHelpers = {}));
618
- var TestContextService = class extends Context2.Tag("@dxos/effect/TestContextService")() {
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);
619
686
  };
620
- var TestHelpers;
621
687
 
622
688
  // src/resource.ts
623
689
  import * as Effect4 from "effect/Effect";
624
690
  var acquireReleaseResource = (getResource) => Effect4.acquireRelease(Effect4.gen(function* () {
625
691
  const resource = getResource();
626
692
  yield* Effect4.promise(async () => {
627
- resource.open?.();
693
+ await resource.open?.();
628
694
  return void 0;
629
695
  });
630
696
  return resource;
631
697
  }), (resource) => Effect4.promise(async () => {
632
- resource.close?.();
698
+ await resource.close?.();
633
699
  return void 0;
634
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));
635
774
  export {
775
+ dynamic_runtime_exports as DynamicRuntime,
636
776
  JsonPath,
637
777
  JsonProp,
638
778
  ParamKeyAnnotation,
639
- SimpleType,
640
- TestContextService,
641
- TestHelpers,
779
+ RuntimeProvider_exports as RuntimeProvider,
642
780
  UrlParser,
643
781
  VisitResult,
644
782
  acquireReleaseResource,
645
783
  causeToError,
646
784
  contextFromScope,
647
785
  createJsonPath,
786
+ createKvsStore,
648
787
  findAnnotation,
649
788
  findNode,
650
789
  findProperty,
651
790
  fromEffectValidationPath,
652
791
  getAnnotation2 as getAnnotation,
792
+ getArrayElementType,
793
+ getBaseType,
653
794
  getDiscriminatedType,
654
795
  getDiscriminatingProps,
655
796
  getField,
656
797
  getParamKeyAnnotation,
657
- getSimpleType,
798
+ getProperties,
799
+ getValue,
658
800
  isArrayType,
659
801
  isDiscriminatedUnion,
660
802
  isJsonPath,
661
803
  isLiteralUnion,
804
+ isNestedType,
662
805
  isOption,
663
- isSimpleType,
806
+ isTupleType2 as isTupleType,
664
807
  mapAst,
665
808
  promiseWithCauseCapture,
666
809
  runAndForwardErrors,
810
+ runInRuntime,
811
+ setValue,
667
812
  splitJsonPath,
668
813
  throwCause,
669
814
  unwrapExit,