@dxos/effect 0.8.3 → 0.8.4-main.1068cf700f
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.
- package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +458 -87
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing.mjs +39 -0
- package/dist/lib/browser/testing.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +458 -87
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing.mjs +39 -0
- package/dist/lib/node-esm/testing.mjs.map +7 -0
- package/dist/types/src/RuntimeProvider.d.ts +21 -0
- package/dist/types/src/RuntimeProvider.d.ts.map +1 -0
- package/dist/types/src/ast.d.ts +36 -18
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/atom-kvs.d.ts +19 -0
- package/dist/types/src/atom-kvs.d.ts.map +1 -0
- package/dist/types/src/context.d.ts +5 -0
- package/dist/types/src/context.d.ts.map +1 -0
- package/dist/types/src/dynamic-runtime.d.ts +56 -0
- package/dist/types/src/dynamic-runtime.d.ts.map +1 -0
- package/dist/types/src/dynamic-runtime.test.d.ts +2 -0
- package/dist/types/src/dynamic-runtime.test.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +57 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/errors.test.d.ts +2 -0
- package/dist/types/src/errors.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +7 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interrupt.test.d.ts +2 -0
- package/dist/types/src/interrupt.test.d.ts.map +1 -0
- package/dist/types/src/{jsonPath.d.ts → json-path.d.ts} +12 -4
- package/dist/types/src/json-path.d.ts.map +1 -0
- package/dist/types/src/json-path.test.d.ts +2 -0
- package/dist/types/src/json-path.test.d.ts.map +1 -0
- package/dist/types/src/layers.test.d.ts +2 -0
- package/dist/types/src/layers.test.d.ts.map +1 -0
- package/dist/types/src/otel.d.ts +17 -0
- package/dist/types/src/otel.d.ts.map +1 -0
- package/dist/types/src/otel.test.d.ts +2 -0
- package/dist/types/src/otel.test.d.ts.map +1 -0
- package/dist/types/src/resource.d.ts +8 -0
- package/dist/types/src/resource.d.ts.map +1 -0
- package/dist/types/src/resource.test.d.ts +2 -0
- package/dist/types/src/resource.test.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +68 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/url.d.ts +3 -1
- package/dist/types/src/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -8
- package/src/RuntimeProvider.ts +35 -0
- package/src/ast.test.ts +55 -10
- package/src/ast.ts +123 -80
- package/src/atom-kvs.ts +35 -0
- package/src/context.ts +16 -0
- package/src/dynamic-runtime.test.ts +465 -0
- package/src/dynamic-runtime.ts +195 -0
- package/src/errors.test.ts +22 -0
- package/src/errors.ts +252 -0
- package/src/index.ts +7 -1
- package/src/interrupt.test.ts +35 -0
- package/src/{jsonPath.test.ts → json-path.test.ts} +47 -8
- package/src/{jsonPath.ts → json-path.ts} +29 -4
- package/src/layers.test.ts +112 -0
- package/src/otel.test.ts +126 -0
- package/src/otel.ts +45 -0
- package/src/resource.test.ts +32 -0
- package/src/resource.ts +30 -0
- package/src/sanity.test.ts +30 -15
- package/src/testing.ts +112 -0
- package/src/url.test.ts +1 -1
- package/src/url.ts +5 -2
- package/dist/lib/node/index.cjs +0 -487
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/types/src/jsonPath.d.ts.map +0 -1
- package/dist/types/src/jsonPath.test.d.ts +0 -2
- package/dist/types/src/jsonPath.test.d.ts.map +0 -1
|
@@ -1,69 +1,62 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
|
+
import {
|
|
3
|
+
__export
|
|
4
|
+
} from "./chunk-CGS2ULMK.mjs";
|
|
2
5
|
|
|
3
|
-
//
|
|
4
|
-
import
|
|
6
|
+
// src/ast.ts
|
|
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";
|
|
5
11
|
import { invariant } from "@dxos/invariant";
|
|
6
12
|
import { isNonNullable } from "@dxos/util";
|
|
7
|
-
var __dxlog_file = "/
|
|
8
|
-
var
|
|
9
|
-
if (SchemaAST.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return "number";
|
|
17
|
-
}
|
|
18
|
-
if (SchemaAST.isBooleanKeyword(node)) {
|
|
19
|
-
return "boolean";
|
|
20
|
-
}
|
|
21
|
-
if (SchemaAST.isEnums(node)) {
|
|
22
|
-
return "enum";
|
|
23
|
-
}
|
|
24
|
-
if (SchemaAST.isLiteral(node)) {
|
|
25
|
-
return "literal";
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var isSimpleType = (node) => !!getSimpleType(node);
|
|
29
|
-
(function(SimpleType2) {
|
|
30
|
-
SimpleType2.getDefaultValue = (type) => {
|
|
31
|
-
switch (type) {
|
|
32
|
-
case "string": {
|
|
33
|
-
return "";
|
|
13
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
|
|
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
|
|
34
22
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
default: {
|
|
45
|
-
throw new Error(`Unsupported type for default value: ${type}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
23
|
+
};
|
|
24
|
+
return reduceRefinements(nextType, [
|
|
25
|
+
...refinements,
|
|
26
|
+
filter
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
type,
|
|
31
|
+
refinements
|
|
48
32
|
};
|
|
49
|
-
}
|
|
50
|
-
var
|
|
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
|
+
};
|
|
48
|
+
var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
|
|
51
49
|
VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
|
|
52
50
|
VisitResult2[VisitResult2["SKIP"] = 1] = "SKIP";
|
|
53
51
|
VisitResult2[VisitResult2["EXIT"] = 2] = "EXIT";
|
|
54
52
|
return VisitResult2;
|
|
55
|
-
}({});
|
|
56
|
-
var defaultTest = isSimpleType;
|
|
53
|
+
})({});
|
|
57
54
|
var visit = (node, testOrVisitor, visitor) => {
|
|
58
|
-
|
|
59
|
-
visitNode(node, defaultTest, testOrVisitor);
|
|
60
|
-
} else {
|
|
61
|
-
visitNode(node, testOrVisitor, visitor);
|
|
62
|
-
}
|
|
55
|
+
visitNode(node, testOrVisitor, visitor);
|
|
63
56
|
};
|
|
64
57
|
var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
65
|
-
const
|
|
66
|
-
const result =
|
|
58
|
+
const $result = test?.(node, path, depth);
|
|
59
|
+
const result = $result === void 0 ? 0 : typeof $result === "boolean" ? $result ? 0 : 1 : $result;
|
|
67
60
|
if (result === 2) {
|
|
68
61
|
return result;
|
|
69
62
|
}
|
|
@@ -116,6 +109,12 @@ var findNode = (node, test) => {
|
|
|
116
109
|
return child;
|
|
117
110
|
}
|
|
118
111
|
}
|
|
112
|
+
for (const prop of getIndexSignatures(node)) {
|
|
113
|
+
const child = findNode(prop.type, test);
|
|
114
|
+
if (child) {
|
|
115
|
+
return child;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
119
118
|
} else if (SchemaAST.isTupleType(node)) {
|
|
120
119
|
for (const [_, element] of node.elements.entries()) {
|
|
121
120
|
const child = findNode(element.type, test);
|
|
@@ -124,12 +123,13 @@ var findNode = (node, test) => {
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
} else if (SchemaAST.isUnion(node)) {
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
if (isLiteralUnion(node)) {
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
for (const type of node.types) {
|
|
130
|
+
const child = findNode(type, test);
|
|
131
|
+
if (child) {
|
|
132
|
+
return child;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
} else if (SchemaAST.isRefinement(node)) {
|
|
@@ -142,7 +142,7 @@ var findProperty = (schema, path) => {
|
|
|
142
142
|
const typeNode = findNode(node, SchemaAST.isTypeLiteral);
|
|
143
143
|
invariant(typeNode, void 0, {
|
|
144
144
|
F: __dxlog_file,
|
|
145
|
-
L:
|
|
145
|
+
L: 237,
|
|
146
146
|
S: void 0,
|
|
147
147
|
A: [
|
|
148
148
|
"typeNode",
|
|
@@ -167,16 +167,16 @@ var defaultAnnotations = {
|
|
|
167
167
|
["NumberKeyword"]: SchemaAST.numberKeyword,
|
|
168
168
|
["BooleanKeyword"]: SchemaAST.booleanKeyword
|
|
169
169
|
};
|
|
170
|
-
var
|
|
171
|
-
const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);
|
|
172
|
-
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);
|
|
173
173
|
if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
|
|
174
174
|
return void 0;
|
|
175
175
|
}
|
|
176
176
|
return value;
|
|
177
177
|
};
|
|
178
178
|
var findAnnotation = (node, annotationId, noDefault = true) => {
|
|
179
|
-
const getAnnotationById =
|
|
179
|
+
const getAnnotationById = getAnnotation2(annotationId, noDefault);
|
|
180
180
|
const getBaseAnnotation = (node2) => {
|
|
181
181
|
const value = getAnnotationById(node2);
|
|
182
182
|
if (value !== void 0) {
|
|
@@ -196,13 +196,22 @@ var isOption = (node) => {
|
|
|
196
196
|
var isLiteralUnion = (node) => {
|
|
197
197
|
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
198
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
|
+
};
|
|
199
208
|
var isDiscriminatedUnion = (node) => {
|
|
200
209
|
return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
201
210
|
};
|
|
202
211
|
var getDiscriminatingProps = (node) => {
|
|
203
212
|
invariant(SchemaAST.isUnion(node), void 0, {
|
|
204
213
|
F: __dxlog_file,
|
|
205
|
-
L:
|
|
214
|
+
L: 355,
|
|
206
215
|
S: void 0,
|
|
207
216
|
A: [
|
|
208
217
|
"SchemaAST.isUnion(node)",
|
|
@@ -220,7 +229,7 @@ var getDiscriminatingProps = (node) => {
|
|
|
220
229
|
var getDiscriminatedType = (node, value = {}) => {
|
|
221
230
|
invariant(SchemaAST.isUnion(node), void 0, {
|
|
222
231
|
F: __dxlog_file,
|
|
223
|
-
L:
|
|
232
|
+
L: 379,
|
|
224
233
|
S: void 0,
|
|
225
234
|
A: [
|
|
226
235
|
"SchemaAST.isUnion(node)",
|
|
@@ -229,7 +238,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
229
238
|
});
|
|
230
239
|
invariant(value, void 0, {
|
|
231
240
|
F: __dxlog_file,
|
|
232
|
-
L:
|
|
241
|
+
L: 380,
|
|
233
242
|
S: void 0,
|
|
234
243
|
A: [
|
|
235
244
|
"value",
|
|
@@ -244,7 +253,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
244
253
|
const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
245
254
|
invariant(SchemaAST.isLiteral(prop.type), void 0, {
|
|
246
255
|
F: __dxlog_file,
|
|
247
|
-
L:
|
|
256
|
+
L: 391,
|
|
248
257
|
S: void 0,
|
|
249
258
|
A: [
|
|
250
259
|
"SchemaAST.isLiteral(prop.type)",
|
|
@@ -262,7 +271,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
262
271
|
const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
263
272
|
invariant(SchemaAST.isLiteral(literal.type), void 0, {
|
|
264
273
|
F: __dxlog_file,
|
|
265
|
-
L:
|
|
274
|
+
L: 409,
|
|
266
275
|
S: void 0,
|
|
267
276
|
A: [
|
|
268
277
|
"SchemaAST.isLiteral(literal.type)",
|
|
@@ -279,10 +288,14 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
279
288
|
const schema = Schema.Struct(fields);
|
|
280
289
|
return schema.ast;
|
|
281
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
|
+
};
|
|
282
295
|
var mapAst = (ast, f) => {
|
|
283
296
|
switch (ast._tag) {
|
|
284
297
|
case "TypeLiteral": {
|
|
285
|
-
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);
|
|
286
299
|
}
|
|
287
300
|
case "Union": {
|
|
288
301
|
return SchemaAST.Union.make(ast.types.map(f), ast.annotations);
|
|
@@ -299,13 +312,313 @@ var mapAst = (ast, f) => {
|
|
|
299
312
|
}
|
|
300
313
|
}
|
|
301
314
|
};
|
|
302
|
-
var
|
|
315
|
+
var getIndexSignatures = (ast) => {
|
|
316
|
+
const annotation = SchemaAST.getSurrogateAnnotation(ast);
|
|
317
|
+
if (Option.isSome(annotation)) {
|
|
318
|
+
return getIndexSignatures(annotation.value);
|
|
319
|
+
}
|
|
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 [];
|
|
329
|
+
};
|
|
330
|
+
|
|
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);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// src/context.ts
|
|
346
|
+
import * as Effect from "effect/Effect";
|
|
347
|
+
import { Context } from "@dxos/context";
|
|
348
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
|
|
349
|
+
var contextFromScope = () => Effect.gen(function* () {
|
|
350
|
+
const ctx = new Context(void 0, {
|
|
351
|
+
F: __dxlog_file2,
|
|
352
|
+
L: 13
|
|
353
|
+
});
|
|
354
|
+
yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
|
|
355
|
+
return ctx;
|
|
356
|
+
});
|
|
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
|
+
|
|
369
|
+
// src/errors.ts
|
|
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";
|
|
377
|
+
var spanSymbol = Symbol.for("effect/SpanAnnotation");
|
|
378
|
+
var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
|
|
379
|
+
var locationRegex = /\((.*)\)/g;
|
|
380
|
+
var prettyErrorStack = (error, appendStacks = []) => {
|
|
381
|
+
if (typeof error !== "object" || error === null) {
|
|
382
|
+
return error;
|
|
383
|
+
}
|
|
384
|
+
const span = error[spanSymbol];
|
|
385
|
+
const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
|
|
386
|
+
const out = [];
|
|
387
|
+
let atStack = false, inCore = false, passedScheduler = false;
|
|
388
|
+
for (let i = 0; i < lines.length; i++) {
|
|
389
|
+
if (!atStack && !lines[i].startsWith(" at ")) {
|
|
390
|
+
out.push(lines[i]);
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
atStack = true;
|
|
394
|
+
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
395
|
+
i++;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (lines[i].includes("Generator.next")) {
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
if (lines[i].includes("effect_internal_function")) {
|
|
402
|
+
break;
|
|
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
|
+
}
|
|
424
|
+
out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
|
|
425
|
+
}
|
|
426
|
+
if (span) {
|
|
427
|
+
let current = span;
|
|
428
|
+
let i = 0;
|
|
429
|
+
while (current && current._tag === "Span" && i < 10) {
|
|
430
|
+
const stackFn = spanToTrace.get(current);
|
|
431
|
+
if (typeof stackFn === "function") {
|
|
432
|
+
const stack = stackFn();
|
|
433
|
+
if (typeof stack === "string") {
|
|
434
|
+
const locationMatchAll = stack.matchAll(locationRegex);
|
|
435
|
+
let match = false;
|
|
436
|
+
for (const [, location] of locationMatchAll) {
|
|
437
|
+
match = true;
|
|
438
|
+
out.push(` at ${current.name} (${location})`);
|
|
439
|
+
}
|
|
440
|
+
if (!match) {
|
|
441
|
+
out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
out.push(` at ${current.name}`);
|
|
445
|
+
}
|
|
446
|
+
} else {
|
|
447
|
+
out.push(` at ${current.name}`);
|
|
448
|
+
}
|
|
449
|
+
current = Option2.getOrUndefined(current.parent);
|
|
450
|
+
i++;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
out.push(...appendStacks);
|
|
454
|
+
error = Cause.originalError(error);
|
|
455
|
+
if (error.cause) {
|
|
456
|
+
error.cause = prettyErrorStack(error.cause);
|
|
457
|
+
}
|
|
458
|
+
Object.defineProperty(error, "stack", {
|
|
459
|
+
value: out.join("\n"),
|
|
460
|
+
writable: true,
|
|
461
|
+
enumerable: false,
|
|
462
|
+
configurable: true
|
|
463
|
+
});
|
|
464
|
+
return error;
|
|
465
|
+
};
|
|
466
|
+
var causeToError = (cause) => {
|
|
467
|
+
if (Cause.isEmpty(cause)) {
|
|
468
|
+
return new Error("Fiber failed without a cause");
|
|
469
|
+
} else if (Cause.isInterruptedOnly(cause)) {
|
|
470
|
+
return new Error("Fiber was interrupted");
|
|
471
|
+
} else {
|
|
472
|
+
const errors = [
|
|
473
|
+
...Chunk.toArray(Cause.failures(cause)),
|
|
474
|
+
...Chunk.toArray(Cause.defects(cause))
|
|
475
|
+
];
|
|
476
|
+
const getStackFrames = () => {
|
|
477
|
+
const o = new Error();
|
|
478
|
+
Error.captureStackTrace(o, causeToError);
|
|
479
|
+
return o.stack.split("\n").slice(1);
|
|
480
|
+
};
|
|
481
|
+
const stackFrames = getStackFrames();
|
|
482
|
+
const newErrors = errors.map((error) => prettyErrorStack(error, stackFrames));
|
|
483
|
+
if (newErrors.length === 1) {
|
|
484
|
+
return newErrors[0];
|
|
485
|
+
} else {
|
|
486
|
+
return new AggregateError(newErrors);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
var throwCause = (cause) => {
|
|
491
|
+
throw causeToError(cause);
|
|
492
|
+
};
|
|
493
|
+
var unwrapExit = (exit) => {
|
|
494
|
+
if (Exit.isSuccess(exit)) {
|
|
495
|
+
return exit.value;
|
|
496
|
+
}
|
|
497
|
+
return throwCause(exit.cause);
|
|
498
|
+
};
|
|
499
|
+
var runAndForwardErrors = async (effect, options) => {
|
|
500
|
+
const exit = await Effect2.runPromiseExit(effect, options);
|
|
501
|
+
return unwrapExit(exit);
|
|
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
|
+
};
|
|
518
|
+
var promiseWithCauseCapture = (evaluate) => Effect2.promise(async (signal) => {
|
|
519
|
+
try {
|
|
520
|
+
const result = await evaluate(signal);
|
|
521
|
+
return Effect2.succeed(result);
|
|
522
|
+
} catch (err) {
|
|
523
|
+
return Effect2.die(err);
|
|
524
|
+
}
|
|
525
|
+
}).pipe(Effect2.flatten);
|
|
303
526
|
|
|
304
|
-
//
|
|
305
|
-
|
|
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);
|
|
534
|
+
}
|
|
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
|
+
}));
|
|
551
|
+
}
|
|
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";
|
|
306
618
|
import { JSONPath } from "jsonpath-plus";
|
|
307
619
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
308
|
-
|
|
620
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
621
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/json-path.ts";
|
|
309
622
|
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
310
623
|
var PROP_REGEX = /^\w+$/;
|
|
311
624
|
var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
|
|
@@ -316,7 +629,7 @@ var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
|
|
|
316
629
|
message: () => "Property name must contain only letters, numbers, and underscores"
|
|
317
630
|
}));
|
|
318
631
|
var isJsonPath = (value) => {
|
|
319
|
-
return
|
|
632
|
+
return Option4.isSome(Schema2.validateOption(JsonPath)(value));
|
|
320
633
|
};
|
|
321
634
|
var createJsonPath = (path) => {
|
|
322
635
|
const candidatePath = path.map((p, i) => {
|
|
@@ -327,8 +640,8 @@ var createJsonPath = (path) => {
|
|
|
327
640
|
}
|
|
328
641
|
}).join("");
|
|
329
642
|
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
|
|
330
|
-
F:
|
|
331
|
-
L:
|
|
643
|
+
F: __dxlog_file3,
|
|
644
|
+
L: 69,
|
|
332
645
|
S: void 0,
|
|
333
646
|
A: [
|
|
334
647
|
"isJsonPath(candidatePath)",
|
|
@@ -340,8 +653,8 @@ var createJsonPath = (path) => {
|
|
|
340
653
|
var fromEffectValidationPath = (effectPath) => {
|
|
341
654
|
const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
|
|
342
655
|
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
|
|
343
|
-
F:
|
|
344
|
-
L:
|
|
656
|
+
F: __dxlog_file3,
|
|
657
|
+
L: 80,
|
|
345
658
|
S: void 0,
|
|
346
659
|
A: [
|
|
347
660
|
"isJsonPath(jsonPath)",
|
|
@@ -354,7 +667,10 @@ var splitJsonPath = (path) => {
|
|
|
354
667
|
if (!isJsonPath(path)) {
|
|
355
668
|
return [];
|
|
356
669
|
}
|
|
357
|
-
return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.
|
|
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
|
+
}) ?? [];
|
|
358
674
|
};
|
|
359
675
|
var getField = (object, path) => {
|
|
360
676
|
return JSONPath({
|
|
@@ -362,9 +678,31 @@ var getField = (object, path) => {
|
|
|
362
678
|
json: object
|
|
363
679
|
})[0];
|
|
364
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
|
+
};
|
|
687
|
+
|
|
688
|
+
// src/resource.ts
|
|
689
|
+
import * as Effect4 from "effect/Effect";
|
|
690
|
+
var acquireReleaseResource = (getResource) => Effect4.acquireRelease(Effect4.gen(function* () {
|
|
691
|
+
const resource = getResource();
|
|
692
|
+
yield* Effect4.promise(async () => {
|
|
693
|
+
await resource.open?.();
|
|
694
|
+
return void 0;
|
|
695
|
+
});
|
|
696
|
+
return resource;
|
|
697
|
+
}), (resource) => Effect4.promise(async () => {
|
|
698
|
+
await resource.close?.();
|
|
699
|
+
return void 0;
|
|
700
|
+
}));
|
|
365
701
|
|
|
366
|
-
//
|
|
367
|
-
import
|
|
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";
|
|
368
706
|
import { decamelize } from "@dxos/util";
|
|
369
707
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
370
708
|
var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
|
|
@@ -372,6 +710,7 @@ var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
|
372
710
|
[ParamKeyAnnotationId]: value
|
|
373
711
|
});
|
|
374
712
|
var UrlParser = class {
|
|
713
|
+
_schema;
|
|
375
714
|
constructor(_schema) {
|
|
376
715
|
this._schema = _schema;
|
|
377
716
|
}
|
|
@@ -406,7 +745,7 @@ var UrlParser = class {
|
|
|
406
745
|
if (value !== void 0) {
|
|
407
746
|
const field = this._schema.fields[key];
|
|
408
747
|
if (field) {
|
|
409
|
-
const { key: serializedKey } =
|
|
748
|
+
const { key: serializedKey } = Function2.pipe(getParamKeyAnnotation(field.ast), Option5.getOrElse(() => ({
|
|
410
749
|
key: decamelize(key)
|
|
411
750
|
})));
|
|
412
751
|
url.searchParams.set(serializedKey, String(value));
|
|
@@ -416,31 +755,63 @@ var UrlParser = class {
|
|
|
416
755
|
return url;
|
|
417
756
|
}
|
|
418
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));
|
|
419
774
|
export {
|
|
775
|
+
dynamic_runtime_exports as DynamicRuntime,
|
|
420
776
|
JsonPath,
|
|
421
777
|
JsonProp,
|
|
422
778
|
ParamKeyAnnotation,
|
|
423
|
-
|
|
779
|
+
RuntimeProvider_exports as RuntimeProvider,
|
|
424
780
|
UrlParser,
|
|
425
781
|
VisitResult,
|
|
782
|
+
acquireReleaseResource,
|
|
783
|
+
causeToError,
|
|
784
|
+
contextFromScope,
|
|
426
785
|
createJsonPath,
|
|
786
|
+
createKvsStore,
|
|
427
787
|
findAnnotation,
|
|
428
788
|
findNode,
|
|
429
789
|
findProperty,
|
|
430
790
|
fromEffectValidationPath,
|
|
431
|
-
getAnnotation,
|
|
791
|
+
getAnnotation2 as getAnnotation,
|
|
792
|
+
getArrayElementType,
|
|
793
|
+
getBaseType,
|
|
432
794
|
getDiscriminatedType,
|
|
433
795
|
getDiscriminatingProps,
|
|
434
796
|
getField,
|
|
435
797
|
getParamKeyAnnotation,
|
|
436
|
-
|
|
798
|
+
getProperties,
|
|
799
|
+
getValue,
|
|
800
|
+
isArrayType,
|
|
437
801
|
isDiscriminatedUnion,
|
|
438
802
|
isJsonPath,
|
|
439
803
|
isLiteralUnion,
|
|
804
|
+
isNestedType,
|
|
440
805
|
isOption,
|
|
441
|
-
|
|
806
|
+
isTupleType2 as isTupleType,
|
|
442
807
|
mapAst,
|
|
808
|
+
promiseWithCauseCapture,
|
|
809
|
+
runAndForwardErrors,
|
|
810
|
+
runInRuntime,
|
|
811
|
+
setValue,
|
|
443
812
|
splitJsonPath,
|
|
813
|
+
throwCause,
|
|
814
|
+
unwrapExit,
|
|
444
815
|
visit
|
|
445
816
|
};
|
|
446
817
|
//# sourceMappingURL=index.mjs.map
|