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