@dxos/effect 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +76 -86
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing.mjs +0 -8
- package/dist/lib/browser/testing.mjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +76 -86
- 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 +0 -8
- package/dist/lib/node-esm/testing.mjs.map +3 -3
- package/dist/types/src/Performance.d.ts.map +1 -1
- package/dist/types/src/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/src/ast.d.ts +7 -1
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/async-task-tagging.d.ts +6 -0
- package/dist/types/src/async-task-tagging.d.ts.map +1 -0
- package/dist/types/src/atom-kvs.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/json-path.d.ts.map +1 -1
- package/dist/types/src/resource.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +3 -13
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +8 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/src/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -23
- package/src/ast.ts +30 -6
- package/src/async-task-tagging.ts +51 -0
- package/src/atom-kvs.ts +1 -1
- package/src/index.ts +2 -0
- package/src/testing.ts +3 -29
- package/src/types.ts +11 -0
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -12,4 +12,4 @@ pnpm i @dxos/effect
|
|
|
12
12
|
|
|
13
13
|
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
14
14
|
|
|
15
|
-
License: [
|
|
15
|
+
License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -10,7 +10,6 @@ import * as Schema from "effect/Schema";
|
|
|
10
10
|
import * as SchemaAST from "effect/SchemaAST";
|
|
11
11
|
import { invariant } from "@dxos/invariant";
|
|
12
12
|
import { isNonNullable } from "@dxos/util";
|
|
13
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
|
|
14
13
|
var reduceRefinements = (type, refinements = []) => {
|
|
15
14
|
if (SchemaAST.isRefinement(type)) {
|
|
16
15
|
const filter = type.filter;
|
|
@@ -38,12 +37,23 @@ var getBaseType = (prop) => {
|
|
|
38
37
|
};
|
|
39
38
|
var getProperties = (ast) => {
|
|
40
39
|
const properties = SchemaAST.getPropertySignatures(ast);
|
|
41
|
-
return properties.map((prop) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
return properties.map((prop) => {
|
|
41
|
+
const { type, refinements } = getBaseType(prop);
|
|
42
|
+
const mergedType = prop.annotations && Reflect.ownKeys(prop.annotations).length > 0 ? {
|
|
43
|
+
...type,
|
|
44
|
+
annotations: {
|
|
45
|
+
...type.annotations,
|
|
46
|
+
...prop.annotations
|
|
47
|
+
}
|
|
48
|
+
} : type;
|
|
49
|
+
return {
|
|
50
|
+
type: mergedType,
|
|
51
|
+
refinements,
|
|
52
|
+
name: prop.name,
|
|
53
|
+
isOptional: prop.isOptional,
|
|
54
|
+
isReadonly: prop.isReadonly
|
|
55
|
+
};
|
|
56
|
+
});
|
|
47
57
|
};
|
|
48
58
|
var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
|
|
49
59
|
VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
|
|
@@ -140,15 +150,7 @@ var findProperty = (schema, path) => {
|
|
|
140
150
|
const getProp = (node, path2) => {
|
|
141
151
|
const [name, ...rest] = path2;
|
|
142
152
|
const typeNode = findNode(node, SchemaAST.isTypeLiteral);
|
|
143
|
-
invariant(typeNode
|
|
144
|
-
F: __dxlog_file,
|
|
145
|
-
L: 237,
|
|
146
|
-
S: void 0,
|
|
147
|
-
A: [
|
|
148
|
-
"typeNode",
|
|
149
|
-
""
|
|
150
|
-
]
|
|
151
|
-
});
|
|
153
|
+
invariant(typeNode);
|
|
152
154
|
for (const prop of SchemaAST.getPropertySignatures(typeNode)) {
|
|
153
155
|
if (prop.name === name) {
|
|
154
156
|
if (rest.length) {
|
|
@@ -196,6 +198,12 @@ var isOption = (node) => {
|
|
|
196
198
|
var isLiteralUnion = (node) => {
|
|
197
199
|
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
198
200
|
};
|
|
201
|
+
var getLiteralValues = (schema) => {
|
|
202
|
+
if (!isLiteralUnion(schema.ast)) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
return schema.ast.types.map((node) => node.literal);
|
|
206
|
+
};
|
|
199
207
|
var isArrayType = (node) => {
|
|
200
208
|
return SchemaAST.isTupleType(node) && node.elements.length === 0 && node.rest.length === 1;
|
|
201
209
|
};
|
|
@@ -209,15 +217,7 @@ var isDiscriminatedUnion = (node) => {
|
|
|
209
217
|
return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
210
218
|
};
|
|
211
219
|
var getDiscriminatingProps = (node) => {
|
|
212
|
-
invariant(SchemaAST.isUnion(node)
|
|
213
|
-
F: __dxlog_file,
|
|
214
|
-
L: 355,
|
|
215
|
-
S: void 0,
|
|
216
|
-
A: [
|
|
217
|
-
"SchemaAST.isUnion(node)",
|
|
218
|
-
""
|
|
219
|
-
]
|
|
220
|
-
});
|
|
220
|
+
invariant(SchemaAST.isUnion(node));
|
|
221
221
|
if (isOption(node)) {
|
|
222
222
|
return;
|
|
223
223
|
}
|
|
@@ -227,39 +227,15 @@ var getDiscriminatingProps = (node) => {
|
|
|
227
227
|
}, []);
|
|
228
228
|
};
|
|
229
229
|
var getDiscriminatedType = (node, value = {}) => {
|
|
230
|
-
invariant(SchemaAST.isUnion(node)
|
|
231
|
-
|
|
232
|
-
L: 379,
|
|
233
|
-
S: void 0,
|
|
234
|
-
A: [
|
|
235
|
-
"SchemaAST.isUnion(node)",
|
|
236
|
-
""
|
|
237
|
-
]
|
|
238
|
-
});
|
|
239
|
-
invariant(value, void 0, {
|
|
240
|
-
F: __dxlog_file,
|
|
241
|
-
L: 380,
|
|
242
|
-
S: void 0,
|
|
243
|
-
A: [
|
|
244
|
-
"value",
|
|
245
|
-
""
|
|
246
|
-
]
|
|
247
|
-
});
|
|
230
|
+
invariant(SchemaAST.isUnion(node));
|
|
231
|
+
invariant(value);
|
|
248
232
|
const props = getDiscriminatingProps(node);
|
|
249
233
|
if (!props?.length) {
|
|
250
234
|
return;
|
|
251
235
|
}
|
|
252
236
|
for (const type of node.types) {
|
|
253
237
|
const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
254
|
-
invariant(SchemaAST.isLiteral(prop.type)
|
|
255
|
-
F: __dxlog_file,
|
|
256
|
-
L: 391,
|
|
257
|
-
S: void 0,
|
|
258
|
-
A: [
|
|
259
|
-
"SchemaAST.isLiteral(prop.type)",
|
|
260
|
-
""
|
|
261
|
-
]
|
|
262
|
-
});
|
|
238
|
+
invariant(SchemaAST.isLiteral(prop.type));
|
|
263
239
|
return prop.type.literal === value[prop.name.toString()];
|
|
264
240
|
});
|
|
265
241
|
if (match) {
|
|
@@ -269,15 +245,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
269
245
|
const fields = Object.fromEntries(props.map((prop) => {
|
|
270
246
|
const literals = node.types.map((type) => {
|
|
271
247
|
const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
272
|
-
invariant(SchemaAST.isLiteral(literal.type)
|
|
273
|
-
F: __dxlog_file,
|
|
274
|
-
L: 409,
|
|
275
|
-
S: void 0,
|
|
276
|
-
A: [
|
|
277
|
-
"SchemaAST.isLiteral(literal.type)",
|
|
278
|
-
""
|
|
279
|
-
]
|
|
280
|
-
});
|
|
248
|
+
invariant(SchemaAST.isLiteral(literal.type));
|
|
281
249
|
return literal.type.literal;
|
|
282
250
|
}).filter(isNonNullable);
|
|
283
251
|
return literals.length ? [
|
|
@@ -329,8 +297,8 @@ var getIndexSignatures = (ast) => {
|
|
|
329
297
|
};
|
|
330
298
|
|
|
331
299
|
// src/atom-kvs.ts
|
|
332
|
-
import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
|
|
333
300
|
import { Atom } from "@effect-atom/atom-react";
|
|
301
|
+
import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
|
|
334
302
|
var defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
|
|
335
303
|
var createKvsStore = (options) => {
|
|
336
304
|
const runtime2 = options.runtime ?? defaultRuntime;
|
|
@@ -345,12 +313,8 @@ var createKvsStore = (options) => {
|
|
|
345
313
|
// src/context.ts
|
|
346
314
|
import * as Effect from "effect/Effect";
|
|
347
315
|
import { Context } from "@dxos/context";
|
|
348
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
|
|
349
316
|
var contextFromScope = () => Effect.gen(function* () {
|
|
350
|
-
const ctx = new Context(
|
|
351
|
-
F: __dxlog_file2,
|
|
352
|
-
L: 13
|
|
353
|
-
});
|
|
317
|
+
const ctx = new Context();
|
|
354
318
|
yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
|
|
355
319
|
return ctx;
|
|
356
320
|
});
|
|
@@ -618,7 +582,6 @@ import * as Schema2 from "effect/Schema";
|
|
|
618
582
|
import { JSONPath } from "jsonpath-plus";
|
|
619
583
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
620
584
|
import { getDeep, setDeep } from "@dxos/util";
|
|
621
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/json-path.ts";
|
|
622
585
|
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
623
586
|
var PROP_REGEX = /^\w+$/;
|
|
624
587
|
var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
|
|
@@ -639,28 +602,12 @@ var createJsonPath = (path) => {
|
|
|
639
602
|
return i === 0 ? p : `.${p}`;
|
|
640
603
|
}
|
|
641
604
|
}).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
|
-
});
|
|
605
|
+
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);
|
|
651
606
|
return candidatePath;
|
|
652
607
|
};
|
|
653
608
|
var fromEffectValidationPath = (effectPath) => {
|
|
654
609
|
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
|
-
]
|
|
663
|
-
});
|
|
610
|
+
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);
|
|
664
611
|
return jsonPath;
|
|
665
612
|
};
|
|
666
613
|
var splitJsonPath = (path) => {
|
|
@@ -791,6 +738,47 @@ var addTrackEntry = (options) => (effect) => Effect6.gen(function* () {
|
|
|
791
738
|
});
|
|
792
739
|
return yield* exit2;
|
|
793
740
|
});
|
|
741
|
+
|
|
742
|
+
// src/async-task-tagging.ts
|
|
743
|
+
import * as Context3 from "effect/Context";
|
|
744
|
+
import * as Effect7 from "effect/Effect";
|
|
745
|
+
import { pipe as pipe3 } from "effect/Function";
|
|
746
|
+
import * as Layer from "effect/Layer";
|
|
747
|
+
import * as Predicate from "effect/Predicate";
|
|
748
|
+
import * as Tracer from "effect/Tracer";
|
|
749
|
+
var runInTask = /* @__PURE__ */ Symbol("runInTask");
|
|
750
|
+
var asyncTaskTaggingLayer = () => {
|
|
751
|
+
if (Predicate.hasProperty(console, "createTask") === false) {
|
|
752
|
+
return Layer.empty;
|
|
753
|
+
}
|
|
754
|
+
const makeTracer = Effect7.gen(function* () {
|
|
755
|
+
const oldTracer = yield* Effect7.tracer;
|
|
756
|
+
return Tracer.make({
|
|
757
|
+
span: (name, ...args) => {
|
|
758
|
+
const span = oldTracer.span(name, ...args);
|
|
759
|
+
const trace = console.createTask(name);
|
|
760
|
+
span[runInTask] = (f) => trace.run(f);
|
|
761
|
+
return span;
|
|
762
|
+
},
|
|
763
|
+
context: (f, fiber) => {
|
|
764
|
+
const maybeParentSpan = Context3.getOption(Tracer.ParentSpan)(fiber.currentContext);
|
|
765
|
+
if (maybeParentSpan._tag === "None") {
|
|
766
|
+
return oldTracer.context(f, fiber);
|
|
767
|
+
}
|
|
768
|
+
const parentSpan = maybeParentSpan.value;
|
|
769
|
+
if (parentSpan._tag === "ExternalSpan") {
|
|
770
|
+
return oldTracer.context(f, fiber);
|
|
771
|
+
}
|
|
772
|
+
const span = parentSpan;
|
|
773
|
+
if (runInTask in span && typeof span[runInTask] === "function") {
|
|
774
|
+
return span[runInTask](() => oldTracer.context(f, fiber));
|
|
775
|
+
}
|
|
776
|
+
return oldTracer.context(f, fiber);
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
return pipe3(makeTracer, Effect7.map(Layer.setTracer), Layer.unwrapEffect);
|
|
781
|
+
};
|
|
794
782
|
export {
|
|
795
783
|
dynamic_runtime_exports as DynamicRuntime,
|
|
796
784
|
JsonPath,
|
|
@@ -801,6 +789,7 @@ export {
|
|
|
801
789
|
UrlParser,
|
|
802
790
|
VisitResult,
|
|
803
791
|
acquireReleaseResource,
|
|
792
|
+
asyncTaskTaggingLayer,
|
|
804
793
|
causeToError,
|
|
805
794
|
contextFromScope,
|
|
806
795
|
createJsonPath,
|
|
@@ -815,6 +804,7 @@ export {
|
|
|
815
804
|
getDiscriminatedType,
|
|
816
805
|
getDiscriminatingProps,
|
|
817
806
|
getField,
|
|
807
|
+
getLiteralValues,
|
|
818
808
|
getParamKeyAnnotation,
|
|
819
809
|
getProperties,
|
|
820
810
|
getValue,
|