@dxos/effect 0.8.4-staging.ac66bdf99f → 0.9.0
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 +535 -573
- 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 +535 -573
- 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/EffectEx.d.ts +5 -0
- package/dist/types/src/EffectEx.d.ts.map +1 -0
- package/dist/types/src/Performance.d.ts.map +1 -1
- package/dist/types/src/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/src/SchemaEx.d.ts +4 -0
- package/dist/types/src/SchemaEx.d.ts.map +1 -0
- package/dist/types/src/atom-kvs.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -8
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/{ast.d.ts → internal/ast.d.ts} +12 -1
- package/dist/types/src/internal/ast.d.ts.map +1 -0
- package/dist/types/src/internal/async-task-tagging.d.ts.map +1 -0
- package/dist/types/src/internal/context.d.ts.map +1 -0
- package/dist/types/src/{errors.d.ts → internal/errors.d.ts} +4 -0
- package/dist/types/src/internal/errors.d.ts.map +1 -0
- package/dist/types/src/internal/json-path.d.ts.map +1 -0
- package/dist/types/src/internal/resource.d.ts.map +1 -0
- package/dist/types/src/internal/url.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +2 -12
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -28
- package/src/EffectEx.ts +18 -0
- package/src/RuntimeProvider.ts +1 -1
- package/src/SchemaEx.ts +46 -0
- package/src/ast.test.ts +2 -2
- package/src/dynamic-runtime.test.ts +1 -1
- package/src/dynamic-runtime.ts +1 -1
- package/src/index.ts +9 -8
- package/src/{ast.ts → internal/ast.ts} +26 -0
- package/src/{async-task-tagging.ts → internal/async-task-tagging.ts} +6 -2
- package/src/{errors.ts → internal/errors.ts} +6 -3
- package/src/interrupt.test.ts +1 -1
- package/src/json-path.test.ts +9 -1
- package/src/layers.test.ts +1 -1
- package/src/resource.test.ts +1 -1
- package/src/sanity.test.ts +1 -1
- package/src/testing.ts +2 -28
- package/src/types.ts +11 -0
- package/src/url.test.ts +1 -1
- package/dist/types/src/ast.d.ts.map +0 -1
- package/dist/types/src/async-task-tagging.d.ts.map +0 -1
- package/dist/types/src/context.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/json-path.d.ts.map +0 -1
- package/dist/types/src/resource.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- /package/dist/types/src/{async-task-tagging.d.ts → internal/async-task-tagging.d.ts} +0 -0
- /package/dist/types/src/{context.d.ts → internal/context.d.ts} +0 -0
- /package/dist/types/src/{json-path.d.ts → internal/json-path.d.ts} +0 -0
- /package/dist/types/src/{resource.d.ts → internal/resource.d.ts} +0 -0
- /package/dist/types/src/{url.d.ts → internal/url.d.ts} +0 -0
- /package/src/{context.ts → internal/context.ts} +0 -0
- /package/src/{json-path.ts → internal/json-path.ts} +0 -0
- /package/src/{resource.ts → internal/resource.ts} +0 -0
- /package/src/{url.ts → internal/url.ts} +0 -0
|
@@ -3,14 +3,437 @@ import {
|
|
|
3
3
|
__export
|
|
4
4
|
} from "./chunk-CGS2ULMK.mjs";
|
|
5
5
|
|
|
6
|
-
// src/
|
|
6
|
+
// src/atom-kvs.ts
|
|
7
|
+
import { Atom } from "@effect-atom/atom-react";
|
|
8
|
+
import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
|
|
9
|
+
var defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
|
|
10
|
+
var createKvsStore = (options) => {
|
|
11
|
+
const runtime2 = options.runtime ?? defaultRuntime;
|
|
12
|
+
return Atom.kvs({
|
|
13
|
+
runtime: runtime2,
|
|
14
|
+
key: options.key,
|
|
15
|
+
schema: options.schema,
|
|
16
|
+
defaultValue: options.defaultValue
|
|
17
|
+
}).pipe(Atom.keepAlive);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/dynamic-runtime.ts
|
|
21
|
+
var dynamic_runtime_exports = {};
|
|
22
|
+
__export(dynamic_runtime_exports, {
|
|
23
|
+
make: () => make
|
|
24
|
+
});
|
|
25
|
+
import * as Context from "effect/Context";
|
|
26
|
+
import * as Effect2 from "effect/Effect";
|
|
27
|
+
import * as Exit2 from "effect/Exit";
|
|
28
|
+
import * as Option2 from "effect/Option";
|
|
29
|
+
import * as Runtime2 from "effect/Runtime";
|
|
30
|
+
|
|
31
|
+
// src/internal/errors.ts
|
|
32
|
+
import * as Cause from "effect/Cause";
|
|
33
|
+
import * as Chunk from "effect/Chunk";
|
|
34
|
+
import * as Effect from "effect/Effect";
|
|
35
|
+
import * as Exit from "effect/Exit";
|
|
36
|
+
import * as GlobalValue from "effect/GlobalValue";
|
|
37
|
+
import * as Option from "effect/Option";
|
|
38
|
+
import * as Runtime from "effect/Runtime";
|
|
39
|
+
var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
|
|
40
|
+
var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
|
|
41
|
+
var locationRegex = /\((.*)\)/g;
|
|
42
|
+
var prettyErrorStack = (error, appendStacks = []) => {
|
|
43
|
+
if (typeof error !== "object" || error === null) {
|
|
44
|
+
return error;
|
|
45
|
+
}
|
|
46
|
+
const span = error[spanSymbol];
|
|
47
|
+
const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
|
|
48
|
+
const out = [];
|
|
49
|
+
let atStack = false, inCore = false, passedScheduler = false;
|
|
50
|
+
for (let i = 0; i < lines.length; i++) {
|
|
51
|
+
if (!atStack && !lines[i].startsWith(" at ")) {
|
|
52
|
+
out.push(lines[i]);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
atStack = true;
|
|
56
|
+
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
57
|
+
i++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (lines[i].includes("Generator.next")) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
if (lines[i].includes("effect_internal_function")) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const filename = lines[i].match(/\/([a-zA-Z0-9_\-.]+):\d+:\d+\)$/)?.[1];
|
|
67
|
+
if (!inCore && [
|
|
68
|
+
"core-effect.ts"
|
|
69
|
+
].includes(filename)) {
|
|
70
|
+
inCore = true;
|
|
71
|
+
}
|
|
72
|
+
if (inCore && !passedScheduler && [
|
|
73
|
+
"Scheduler.ts"
|
|
74
|
+
].includes(filename)) {
|
|
75
|
+
passedScheduler = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (passedScheduler && ![
|
|
79
|
+
"Scheduler.ts"
|
|
80
|
+
].includes(filename)) {
|
|
81
|
+
inCore = false;
|
|
82
|
+
}
|
|
83
|
+
if (inCore) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
|
|
87
|
+
}
|
|
88
|
+
if (span) {
|
|
89
|
+
let current = span;
|
|
90
|
+
let i = 0;
|
|
91
|
+
while (current && current._tag === "Span" && i < 10) {
|
|
92
|
+
const stackFn = spanToTrace.get(current);
|
|
93
|
+
if (typeof stackFn === "function") {
|
|
94
|
+
const stack = stackFn();
|
|
95
|
+
if (typeof stack === "string") {
|
|
96
|
+
const locationMatchAll = stack.matchAll(locationRegex);
|
|
97
|
+
let match = false;
|
|
98
|
+
for (const [, location] of locationMatchAll) {
|
|
99
|
+
match = true;
|
|
100
|
+
out.push(` at ${current.name} (${location})`);
|
|
101
|
+
}
|
|
102
|
+
if (!match) {
|
|
103
|
+
out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
out.push(` at ${current.name}`);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
out.push(` at ${current.name}`);
|
|
110
|
+
}
|
|
111
|
+
current = Option.getOrUndefined(current.parent);
|
|
112
|
+
i++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
out.push(...appendStacks);
|
|
116
|
+
error = Cause.originalError(error);
|
|
117
|
+
if (error.cause) {
|
|
118
|
+
error.cause = prettyErrorStack(error.cause);
|
|
119
|
+
}
|
|
120
|
+
Object.defineProperty(error, "stack", {
|
|
121
|
+
value: out.join("\n"),
|
|
122
|
+
writable: true,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
configurable: true
|
|
125
|
+
});
|
|
126
|
+
return error;
|
|
127
|
+
};
|
|
128
|
+
var causeToError = (cause) => {
|
|
129
|
+
if (Cause.isEmpty(cause)) {
|
|
130
|
+
return new Error("Fiber failed without a cause");
|
|
131
|
+
} else if (Cause.isInterruptedOnly(cause)) {
|
|
132
|
+
return new Error("Fiber was interrupted");
|
|
133
|
+
} else {
|
|
134
|
+
const errors = [
|
|
135
|
+
...Chunk.toArray(Cause.failures(cause)),
|
|
136
|
+
...Chunk.toArray(Cause.defects(cause))
|
|
137
|
+
];
|
|
138
|
+
const getStackFrames = () => {
|
|
139
|
+
const err = new Error();
|
|
140
|
+
Error.captureStackTrace(err, causeToError);
|
|
141
|
+
return err.stack.split("\n").slice(1);
|
|
142
|
+
};
|
|
143
|
+
const stackFrames = getStackFrames();
|
|
144
|
+
const newErrors = errors.map((error) => prettyErrorStack(error, stackFrames));
|
|
145
|
+
if (newErrors.length === 1) {
|
|
146
|
+
return newErrors[0];
|
|
147
|
+
} else {
|
|
148
|
+
return new AggregateError(newErrors);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var throwCause = (cause) => {
|
|
153
|
+
throw causeToError(cause);
|
|
154
|
+
};
|
|
155
|
+
var unwrapExit = (exit2) => {
|
|
156
|
+
if (Exit.isSuccess(exit2)) {
|
|
157
|
+
return exit2.value;
|
|
158
|
+
}
|
|
159
|
+
return throwCause(exit2.cause);
|
|
160
|
+
};
|
|
161
|
+
var runAndForwardErrors = async (effect, options) => {
|
|
162
|
+
const exit2 = await Effect.runPromiseExit(effect, options);
|
|
163
|
+
return unwrapExit(exit2);
|
|
164
|
+
};
|
|
165
|
+
var runPromise = runAndForwardErrors;
|
|
166
|
+
var runInRuntime = (...args) => {
|
|
167
|
+
if (args.length === 1) {
|
|
168
|
+
const [runtime2] = args;
|
|
169
|
+
return async (effect, options) => {
|
|
170
|
+
const exit2 = await Runtime.runPromiseExit(runtime2, effect, options);
|
|
171
|
+
return unwrapExit(exit2);
|
|
172
|
+
};
|
|
173
|
+
} else {
|
|
174
|
+
const [runtime2, effect, options] = args;
|
|
175
|
+
return (async () => {
|
|
176
|
+
const exit2 = await Runtime.runPromiseExit(runtime2, effect, options);
|
|
177
|
+
return unwrapExit(exit2);
|
|
178
|
+
})();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var promiseWithCauseCapture = (evaluate) => Effect.promise(async (signal) => {
|
|
182
|
+
try {
|
|
183
|
+
const result = await evaluate(signal);
|
|
184
|
+
return Effect.succeed(result);
|
|
185
|
+
} catch (err) {
|
|
186
|
+
return Effect.die(err);
|
|
187
|
+
}
|
|
188
|
+
}).pipe(Effect.flatten);
|
|
189
|
+
|
|
190
|
+
// src/dynamic-runtime.ts
|
|
191
|
+
var validateTags = (context, tags) => Effect2.gen(function* () {
|
|
192
|
+
const missingTags = [];
|
|
193
|
+
for (const tag of tags) {
|
|
194
|
+
const option = Context.getOption(context, tag);
|
|
195
|
+
if (Option2.isNone(option)) {
|
|
196
|
+
missingTags.push(tag.key);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (missingTags.length > 0) {
|
|
200
|
+
return yield* Effect2.die(new Error(`Missing required tags in runtime: ${missingTags.join(", ")}`));
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
function make(managedRuntime, tags) {
|
|
204
|
+
const managedRuntimeAny = managedRuntime;
|
|
205
|
+
let cachedRuntime;
|
|
206
|
+
let validatedRuntimePromise;
|
|
207
|
+
const getValidatedRuntimeAsync = async () => {
|
|
208
|
+
if (!validatedRuntimePromise) {
|
|
209
|
+
validatedRuntimePromise = managedRuntimeAny.runPromise(Effect2.gen(function* () {
|
|
210
|
+
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
211
|
+
yield* validateTags(rt.context, tags);
|
|
212
|
+
return rt;
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
return validatedRuntimePromise;
|
|
216
|
+
};
|
|
217
|
+
const getValidatedRuntime = () => {
|
|
218
|
+
const validationExit = managedRuntimeAny.runSyncExit(Effect2.gen(function* () {
|
|
219
|
+
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
220
|
+
yield* validateTags(rt.context, tags);
|
|
221
|
+
return rt;
|
|
222
|
+
}));
|
|
223
|
+
return unwrapExit(validationExit);
|
|
224
|
+
};
|
|
225
|
+
return {
|
|
226
|
+
managedRuntime: managedRuntimeAny,
|
|
227
|
+
runPromise: async (effect) => {
|
|
228
|
+
const runtime2 = await getValidatedRuntimeAsync();
|
|
229
|
+
return Runtime2.runPromise(runtime2)(effect);
|
|
230
|
+
},
|
|
231
|
+
runSync: (effect) => {
|
|
232
|
+
const runtime2 = getValidatedRuntime();
|
|
233
|
+
return Runtime2.runSync(runtime2)(effect);
|
|
234
|
+
},
|
|
235
|
+
runSyncExit: (effect) => {
|
|
236
|
+
const validationExit = managedRuntimeAny.runSyncExit(Effect2.gen(function* () {
|
|
237
|
+
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
238
|
+
yield* validateTags(rt.context, tags);
|
|
239
|
+
return rt;
|
|
240
|
+
}));
|
|
241
|
+
if (Exit2.isSuccess(validationExit)) {
|
|
242
|
+
const runtime2 = validationExit.value;
|
|
243
|
+
return Runtime2.runSyncExit(runtime2)(effect);
|
|
244
|
+
}
|
|
245
|
+
return validationExit;
|
|
246
|
+
},
|
|
247
|
+
runPromiseExit: async (effect) => {
|
|
248
|
+
try {
|
|
249
|
+
const runtime2 = await getValidatedRuntimeAsync();
|
|
250
|
+
return Runtime2.runPromiseExit(runtime2)(effect);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
return Exit2.die(error);
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
runFork: (effect) => {
|
|
256
|
+
const runtime2 = getValidatedRuntime();
|
|
257
|
+
return Runtime2.runFork(runtime2)(effect);
|
|
258
|
+
},
|
|
259
|
+
runtimeEffect: Effect2.gen(function* () {
|
|
260
|
+
if (cachedRuntime) {
|
|
261
|
+
return cachedRuntime;
|
|
262
|
+
}
|
|
263
|
+
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
264
|
+
yield* validateTags(rt.context, tags);
|
|
265
|
+
const runtime2 = rt;
|
|
266
|
+
cachedRuntime = runtime2;
|
|
267
|
+
return runtime2;
|
|
268
|
+
}).pipe(Effect2.catchAll(() => (
|
|
269
|
+
// This should never happen since validateTags uses Effect.die
|
|
270
|
+
Effect2.die(new Error("Unexpected error in runtimeEffect validation"))
|
|
271
|
+
))),
|
|
272
|
+
dispose: async () => {
|
|
273
|
+
await managedRuntimeAny.dispose();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/EffectEx.ts
|
|
279
|
+
var EffectEx_exports = {};
|
|
280
|
+
__export(EffectEx_exports, {
|
|
281
|
+
acquireReleaseResource: () => acquireReleaseResource,
|
|
282
|
+
asyncTaskTaggingLayer: () => asyncTaskTaggingLayer,
|
|
283
|
+
causeToError: () => causeToError,
|
|
284
|
+
contextFromScope: () => contextFromScope,
|
|
285
|
+
promiseWithCauseCapture: () => promiseWithCauseCapture,
|
|
286
|
+
runAndForwardErrors: () => runAndForwardErrors,
|
|
287
|
+
runInRuntime: () => runInRuntime,
|
|
288
|
+
runPromise: () => runPromise,
|
|
289
|
+
throwCause: () => throwCause,
|
|
290
|
+
unwrapExit: () => unwrapExit
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// src/internal/async-task-tagging.ts
|
|
294
|
+
import * as Context2 from "effect/Context";
|
|
295
|
+
import * as Effect3 from "effect/Effect";
|
|
296
|
+
import { pipe } from "effect/Function";
|
|
297
|
+
import * as Layer from "effect/Layer";
|
|
298
|
+
import * as Predicate from "effect/Predicate";
|
|
299
|
+
import * as Tracer from "effect/Tracer";
|
|
300
|
+
var runInTask = /* @__PURE__ */ Symbol("runInTask");
|
|
301
|
+
var asyncTaskTaggingLayer = () => {
|
|
302
|
+
if (Predicate.hasProperty(console, "createTask") === false) {
|
|
303
|
+
return Layer.empty;
|
|
304
|
+
}
|
|
305
|
+
const makeTracer = Effect3.gen(function* () {
|
|
306
|
+
const oldTracer = yield* Effect3.tracer;
|
|
307
|
+
return Tracer.make({
|
|
308
|
+
span: (name, ...args) => {
|
|
309
|
+
const span = oldTracer.span(name, ...args);
|
|
310
|
+
const trace = console.createTask(name);
|
|
311
|
+
span[runInTask] = (f) => trace.run(f);
|
|
312
|
+
return span;
|
|
313
|
+
},
|
|
314
|
+
context: (f, fiber) => {
|
|
315
|
+
const maybeParentSpan = Context2.getOption(Tracer.ParentSpan)(fiber.currentContext);
|
|
316
|
+
if (maybeParentSpan._tag === "None") {
|
|
317
|
+
return oldTracer.context(f, fiber);
|
|
318
|
+
}
|
|
319
|
+
const parentSpan = maybeParentSpan.value;
|
|
320
|
+
if (parentSpan._tag === "ExternalSpan") {
|
|
321
|
+
return oldTracer.context(f, fiber);
|
|
322
|
+
}
|
|
323
|
+
const span = parentSpan;
|
|
324
|
+
if (runInTask in span && typeof span[runInTask] === "function") {
|
|
325
|
+
return span[runInTask](() => oldTracer.context(f, fiber));
|
|
326
|
+
}
|
|
327
|
+
return oldTracer.context(f, fiber);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
return pipe(makeTracer, Effect3.map(Layer.setTracer), Layer.unwrapEffect);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// src/internal/context.ts
|
|
335
|
+
import * as Effect4 from "effect/Effect";
|
|
336
|
+
import { Context as Context3 } from "@dxos/context";
|
|
337
|
+
var contextFromScope = () => Effect4.gen(function* () {
|
|
338
|
+
const ctx = new Context3();
|
|
339
|
+
yield* Effect4.addFinalizer(() => Effect4.promise(() => ctx.dispose()));
|
|
340
|
+
return ctx;
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// src/internal/resource.ts
|
|
344
|
+
import * as Effect5 from "effect/Effect";
|
|
345
|
+
var acquireReleaseResource = (getResource) => Effect5.acquireRelease(Effect5.gen(function* () {
|
|
346
|
+
const resource = getResource();
|
|
347
|
+
yield* Effect5.promise(async () => {
|
|
348
|
+
await resource.open?.();
|
|
349
|
+
return void 0;
|
|
350
|
+
});
|
|
351
|
+
return resource;
|
|
352
|
+
}), (resource) => Effect5.promise(async () => {
|
|
353
|
+
await resource.close?.();
|
|
354
|
+
return void 0;
|
|
355
|
+
}));
|
|
356
|
+
|
|
357
|
+
// src/Performance.ts
|
|
358
|
+
var Performance_exports = {};
|
|
359
|
+
__export(Performance_exports, {
|
|
360
|
+
addTrackEntry: () => addTrackEntry
|
|
361
|
+
});
|
|
362
|
+
import * as Effect6 from "effect/Effect";
|
|
363
|
+
var addTrackEntry = (options) => (effect) => Effect6.gen(function* () {
|
|
364
|
+
const start = performance.now();
|
|
365
|
+
const exit2 = yield* Effect6.exit(effect);
|
|
366
|
+
const resolvedOptions = typeof options === "function" ? options(exit2) : options;
|
|
367
|
+
performance.measure(resolvedOptions.name, {
|
|
368
|
+
start,
|
|
369
|
+
detail: {
|
|
370
|
+
...resolvedOptions.detail,
|
|
371
|
+
devtools: resolvedOptions.devtools
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
return yield* exit2;
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// src/RuntimeProvider.ts
|
|
378
|
+
var RuntimeProvider_exports = {};
|
|
379
|
+
__export(RuntimeProvider_exports, {
|
|
380
|
+
currentRuntime: () => currentRuntime,
|
|
381
|
+
provide: () => provide2,
|
|
382
|
+
runPromise: () => runPromise3
|
|
383
|
+
});
|
|
384
|
+
import * as Effect7 from "effect/Effect";
|
|
385
|
+
import * as Runtime3 from "effect/Runtime";
|
|
386
|
+
var currentRuntime = () => Effect7.runtime().pipe(Effect7.map(Effect7.succeed));
|
|
387
|
+
var runPromise3 = (provider) => async (effect) => {
|
|
388
|
+
const runtime2 = await runAndForwardErrors(provider);
|
|
389
|
+
return unwrapExit(await effect.pipe(Runtime3.runPromiseExit(runtime2)));
|
|
390
|
+
};
|
|
391
|
+
var provide2 = (runtimeProvider) => (effect) => Effect7.flatMap(runtimeProvider, (runtime2) => Effect7.provide(effect, runtime2));
|
|
392
|
+
|
|
393
|
+
// src/SchemaEx.ts
|
|
394
|
+
var SchemaEx_exports = {};
|
|
395
|
+
__export(SchemaEx_exports, {
|
|
396
|
+
JsonPath: () => JsonPath,
|
|
397
|
+
JsonProp: () => JsonProp,
|
|
398
|
+
ParamKeyAnnotation: () => ParamKeyAnnotation,
|
|
399
|
+
UrlParser: () => UrlParser,
|
|
400
|
+
VisitResult: () => VisitResult,
|
|
401
|
+
createJsonPath: () => createJsonPath,
|
|
402
|
+
findAnnotation: () => findAnnotation,
|
|
403
|
+
findNode: () => findNode,
|
|
404
|
+
findProperty: () => findProperty,
|
|
405
|
+
fromEffectValidationPath: () => fromEffectValidationPath,
|
|
406
|
+
getAnnotation: () => getAnnotation2,
|
|
407
|
+
getArrayElementType: () => getArrayElementType,
|
|
408
|
+
getBaseType: () => getBaseType,
|
|
409
|
+
getDiscriminatedType: () => getDiscriminatedType,
|
|
410
|
+
getDiscriminatingProps: () => getDiscriminatingProps,
|
|
411
|
+
getField: () => getField,
|
|
412
|
+
getLiteralValues: () => getLiteralValues,
|
|
413
|
+
getParamKeyAnnotation: () => getParamKeyAnnotation,
|
|
414
|
+
getProperties: () => getProperties,
|
|
415
|
+
getValue: () => getValue,
|
|
416
|
+
isArrayType: () => isArrayType,
|
|
417
|
+
isDiscriminatedUnion: () => isDiscriminatedUnion,
|
|
418
|
+
isJsonPath: () => isJsonPath,
|
|
419
|
+
isLiteralUnion: () => isLiteralUnion,
|
|
420
|
+
isNestedType: () => isNestedType,
|
|
421
|
+
isOption: () => isOption,
|
|
422
|
+
isTupleType: () => isTupleType2,
|
|
423
|
+
mapAst: () => mapAst,
|
|
424
|
+
setValue: () => setValue,
|
|
425
|
+
splitJsonPath: () => splitJsonPath,
|
|
426
|
+
unwrapOptional: () => unwrapOptional,
|
|
427
|
+
visit: () => visit
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// src/internal/ast.ts
|
|
7
431
|
import * as Function from "effect/Function";
|
|
8
|
-
import * as
|
|
432
|
+
import * as Option3 from "effect/Option";
|
|
9
433
|
import * as Schema from "effect/Schema";
|
|
10
434
|
import * as SchemaAST from "effect/SchemaAST";
|
|
11
435
|
import { invariant } from "@dxos/invariant";
|
|
12
436
|
import { isNonNullable } from "@dxos/util";
|
|
13
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/common/effect/src/ast.ts";
|
|
14
437
|
var reduceRefinements = (type, refinements = []) => {
|
|
15
438
|
if (SchemaAST.isRefinement(type)) {
|
|
16
439
|
const filter = type.filter;
|
|
@@ -151,15 +574,7 @@ var findProperty = (schema, path) => {
|
|
|
151
574
|
const getProp = (node, path2) => {
|
|
152
575
|
const [name, ...rest] = path2;
|
|
153
576
|
const typeNode = findNode(node, SchemaAST.isTypeLiteral);
|
|
154
|
-
invariant(typeNode
|
|
155
|
-
F: __dxlog_file,
|
|
156
|
-
L: 247,
|
|
157
|
-
S: void 0,
|
|
158
|
-
A: [
|
|
159
|
-
"typeNode",
|
|
160
|
-
""
|
|
161
|
-
]
|
|
162
|
-
});
|
|
577
|
+
invariant(typeNode);
|
|
163
578
|
for (const prop of SchemaAST.getPropertySignatures(typeNode)) {
|
|
164
579
|
if (prop.name === name) {
|
|
165
580
|
if (rest.length) {
|
|
@@ -179,8 +594,8 @@ var defaultAnnotations = {
|
|
|
179
594
|
BooleanKeyword: SchemaAST.booleanKeyword
|
|
180
595
|
};
|
|
181
596
|
var getAnnotation2 = (annotationId, noDefault = true) => (node) => {
|
|
182
|
-
const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node),
|
|
183
|
-
const value = Function.pipe(SchemaAST.getAnnotation(annotationId)(node),
|
|
597
|
+
const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node), Option3.getOrUndefined);
|
|
598
|
+
const value = Function.pipe(SchemaAST.getAnnotation(annotationId)(node), Option3.getOrUndefined);
|
|
184
599
|
if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
|
|
185
600
|
return void 0;
|
|
186
601
|
}
|
|
@@ -198,438 +613,125 @@ var findAnnotation = (node, annotationId, noDefault = true) => {
|
|
|
198
613
|
return getAnnotationById(node2.types[0]);
|
|
199
614
|
}
|
|
200
615
|
}
|
|
201
|
-
};
|
|
202
|
-
return getBaseAnnotation(node);
|
|
203
|
-
};
|
|
204
|
-
var isOption = (node) => {
|
|
205
|
-
return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);
|
|
206
|
-
};
|
|
207
|
-
var isLiteralUnion = (node) => {
|
|
208
|
-
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
209
|
-
};
|
|
210
|
-
var isArrayType = (node) => {
|
|
211
|
-
return SchemaAST.isTupleType(node) && node.elements.length === 0 && node.rest.length === 1;
|
|
212
|
-
};
|
|
213
|
-
var getArrayElementType = (node) => {
|
|
214
|
-
return isArrayType(node) ? node.rest.at(0)?.type : void 0;
|
|
215
|
-
};
|
|
216
|
-
var isTupleType2 = (node) => {
|
|
217
|
-
return SchemaAST.isTupleType(node) && node.elements.length > 0;
|
|
218
|
-
};
|
|
219
|
-
var isDiscriminatedUnion = (node) => {
|
|
220
|
-
return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
221
|
-
};
|
|
222
|
-
var getDiscriminatingProps = (node) => {
|
|
223
|
-
invariant(SchemaAST.isUnion(node), void 0, {
|
|
224
|
-
F: __dxlog_file,
|
|
225
|
-
L: 365,
|
|
226
|
-
S: void 0,
|
|
227
|
-
A: [
|
|
228
|
-
"SchemaAST.isUnion(node)",
|
|
229
|
-
""
|
|
230
|
-
]
|
|
231
|
-
});
|
|
232
|
-
if (isOption(node)) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
return node.types.reduce((shared, type) => {
|
|
236
|
-
const props = SchemaAST.getPropertySignatures(type).filter((p) => SchemaAST.isLiteral(p.type)).map((p) => p.name.toString());
|
|
237
|
-
return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));
|
|
238
|
-
}, []);
|
|
239
|
-
};
|
|
240
|
-
var getDiscriminatedType = (node, value = {}) => {
|
|
241
|
-
invariant(SchemaAST.isUnion(node), void 0, {
|
|
242
|
-
F: __dxlog_file,
|
|
243
|
-
L: 389,
|
|
244
|
-
S: void 0,
|
|
245
|
-
A: [
|
|
246
|
-
"SchemaAST.isUnion(node)",
|
|
247
|
-
""
|
|
248
|
-
]
|
|
249
|
-
});
|
|
250
|
-
invariant(value, void 0, {
|
|
251
|
-
F: __dxlog_file,
|
|
252
|
-
L: 390,
|
|
253
|
-
S: void 0,
|
|
254
|
-
A: [
|
|
255
|
-
"value",
|
|
256
|
-
""
|
|
257
|
-
]
|
|
258
|
-
});
|
|
259
|
-
const props = getDiscriminatingProps(node);
|
|
260
|
-
if (!props?.length) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
for (const type of node.types) {
|
|
264
|
-
const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
265
|
-
invariant(SchemaAST.isLiteral(prop.type), void 0, {
|
|
266
|
-
F: __dxlog_file,
|
|
267
|
-
L: 401,
|
|
268
|
-
S: void 0,
|
|
269
|
-
A: [
|
|
270
|
-
"SchemaAST.isLiteral(prop.type)",
|
|
271
|
-
""
|
|
272
|
-
]
|
|
273
|
-
});
|
|
274
|
-
return prop.type.literal === value[prop.name.toString()];
|
|
275
|
-
});
|
|
276
|
-
if (match) {
|
|
277
|
-
return type;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const fields = Object.fromEntries(props.map((prop) => {
|
|
281
|
-
const literals = node.types.map((type) => {
|
|
282
|
-
const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
283
|
-
invariant(SchemaAST.isLiteral(literal.type), void 0, {
|
|
284
|
-
F: __dxlog_file,
|
|
285
|
-
L: 419,
|
|
286
|
-
S: void 0,
|
|
287
|
-
A: [
|
|
288
|
-
"SchemaAST.isLiteral(literal.type)",
|
|
289
|
-
""
|
|
290
|
-
]
|
|
291
|
-
});
|
|
292
|
-
return literal.type.literal;
|
|
293
|
-
}).filter(isNonNullable);
|
|
294
|
-
return literals.length ? [
|
|
295
|
-
prop,
|
|
296
|
-
Schema.Literal(...literals)
|
|
297
|
-
] : void 0;
|
|
298
|
-
}).filter(isNonNullable));
|
|
299
|
-
const schema = Schema.Struct(fields);
|
|
300
|
-
return schema.ast;
|
|
301
|
-
};
|
|
302
|
-
var isNestedType = (node) => {
|
|
303
|
-
return SchemaAST.isDeclaration(node) || SchemaAST.isObjectKeyword(node) || SchemaAST.isTypeLiteral(node) || // TODO(wittjosiah): Tuples are actually arrays.
|
|
304
|
-
isTupleType2(node) || isDiscriminatedUnion(node);
|
|
305
|
-
};
|
|
306
|
-
var mapAst = (ast, f) => {
|
|
307
|
-
switch (ast._tag) {
|
|
308
|
-
case "TypeLiteral": {
|
|
309
|
-
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);
|
|
310
|
-
}
|
|
311
|
-
case "Union": {
|
|
312
|
-
return SchemaAST.Union.make(ast.types.map(f), ast.annotations);
|
|
313
|
-
}
|
|
314
|
-
case "TupleType": {
|
|
315
|
-
return new SchemaAST.TupleType(ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new SchemaAST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
|
|
316
|
-
}
|
|
317
|
-
case "Suspend": {
|
|
318
|
-
const newAst = f(ast.f(), void 0);
|
|
319
|
-
return new SchemaAST.Suspend(() => newAst, ast.annotations);
|
|
320
|
-
}
|
|
321
|
-
default: {
|
|
322
|
-
return ast;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
var getIndexSignatures = (ast) => {
|
|
327
|
-
const annotation = SchemaAST.getSurrogateAnnotation(ast);
|
|
328
|
-
if (Option.isSome(annotation)) {
|
|
329
|
-
return getIndexSignatures(annotation.value);
|
|
330
|
-
}
|
|
331
|
-
switch (ast._tag) {
|
|
332
|
-
case "TypeLiteral":
|
|
333
|
-
return ast.indexSignatures.slice();
|
|
334
|
-
case "Suspend":
|
|
335
|
-
return getIndexSignatures(ast.f());
|
|
336
|
-
case "Refinement":
|
|
337
|
-
return getIndexSignatures(ast.from);
|
|
338
|
-
}
|
|
339
|
-
return [];
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
// src/atom-kvs.ts
|
|
343
|
-
import { Atom } from "@effect-atom/atom-react";
|
|
344
|
-
import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
|
|
345
|
-
var defaultRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
|
|
346
|
-
var createKvsStore = (options) => {
|
|
347
|
-
const runtime2 = options.runtime ?? defaultRuntime;
|
|
348
|
-
return Atom.kvs({
|
|
349
|
-
runtime: runtime2,
|
|
350
|
-
key: options.key,
|
|
351
|
-
schema: options.schema,
|
|
352
|
-
defaultValue: options.defaultValue
|
|
353
|
-
}).pipe(Atom.keepAlive);
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
// src/context.ts
|
|
357
|
-
import * as Effect from "effect/Effect";
|
|
358
|
-
import { Context } from "@dxos/context";
|
|
359
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
|
|
360
|
-
var contextFromScope = () => Effect.gen(function* () {
|
|
361
|
-
const ctx = new Context(void 0, {
|
|
362
|
-
F: __dxlog_file2,
|
|
363
|
-
L: 13
|
|
364
|
-
});
|
|
365
|
-
yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
|
|
366
|
-
return ctx;
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
// src/dynamic-runtime.ts
|
|
370
|
-
var dynamic_runtime_exports = {};
|
|
371
|
-
__export(dynamic_runtime_exports, {
|
|
372
|
-
make: () => make
|
|
373
|
-
});
|
|
374
|
-
import * as Context2 from "effect/Context";
|
|
375
|
-
import * as Effect3 from "effect/Effect";
|
|
376
|
-
import * as Exit2 from "effect/Exit";
|
|
377
|
-
import * as Option3 from "effect/Option";
|
|
378
|
-
import * as Runtime2 from "effect/Runtime";
|
|
379
|
-
|
|
380
|
-
// src/errors.ts
|
|
381
|
-
import * as Cause from "effect/Cause";
|
|
382
|
-
import * as Chunk from "effect/Chunk";
|
|
383
|
-
import * as Effect2 from "effect/Effect";
|
|
384
|
-
import * as Exit from "effect/Exit";
|
|
385
|
-
import * as GlobalValue from "effect/GlobalValue";
|
|
386
|
-
import * as Option2 from "effect/Option";
|
|
387
|
-
import * as Runtime from "effect/Runtime";
|
|
388
|
-
var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation");
|
|
389
|
-
var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
|
|
390
|
-
var locationRegex = /\((.*)\)/g;
|
|
391
|
-
var prettyErrorStack = (error, appendStacks = []) => {
|
|
392
|
-
if (typeof error !== "object" || error === null) {
|
|
393
|
-
return error;
|
|
394
|
-
}
|
|
395
|
-
const span = error[spanSymbol];
|
|
396
|
-
const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
|
|
397
|
-
const out = [];
|
|
398
|
-
let atStack = false, inCore = false, passedScheduler = false;
|
|
399
|
-
for (let i = 0; i < lines.length; i++) {
|
|
400
|
-
if (!atStack && !lines[i].startsWith(" at ")) {
|
|
401
|
-
out.push(lines[i]);
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
atStack = true;
|
|
405
|
-
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
406
|
-
i++;
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
if (lines[i].includes("Generator.next")) {
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
if (lines[i].includes("effect_internal_function")) {
|
|
413
|
-
break;
|
|
414
|
-
}
|
|
415
|
-
const filename = lines[i].match(/\/([a-zA-Z0-9_\-.]+):\d+:\d+\)$/)?.[1];
|
|
416
|
-
if (!inCore && [
|
|
417
|
-
"core-effect.ts"
|
|
418
|
-
].includes(filename)) {
|
|
419
|
-
inCore = true;
|
|
420
|
-
}
|
|
421
|
-
if (inCore && !passedScheduler && [
|
|
422
|
-
"Scheduler.ts"
|
|
423
|
-
].includes(filename)) {
|
|
424
|
-
passedScheduler = true;
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
if (passedScheduler && ![
|
|
428
|
-
"Scheduler.ts"
|
|
429
|
-
].includes(filename)) {
|
|
430
|
-
inCore = false;
|
|
431
|
-
}
|
|
432
|
-
if (inCore) {
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
|
|
436
|
-
}
|
|
437
|
-
if (span) {
|
|
438
|
-
let current = span;
|
|
439
|
-
let i = 0;
|
|
440
|
-
while (current && current._tag === "Span" && i < 10) {
|
|
441
|
-
const stackFn = spanToTrace.get(current);
|
|
442
|
-
if (typeof stackFn === "function") {
|
|
443
|
-
const stack = stackFn();
|
|
444
|
-
if (typeof stack === "string") {
|
|
445
|
-
const locationMatchAll = stack.matchAll(locationRegex);
|
|
446
|
-
let match = false;
|
|
447
|
-
for (const [, location] of locationMatchAll) {
|
|
448
|
-
match = true;
|
|
449
|
-
out.push(` at ${current.name} (${location})`);
|
|
450
|
-
}
|
|
451
|
-
if (!match) {
|
|
452
|
-
out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
|
|
453
|
-
}
|
|
454
|
-
} else {
|
|
455
|
-
out.push(` at ${current.name}`);
|
|
456
|
-
}
|
|
457
|
-
} else {
|
|
458
|
-
out.push(` at ${current.name}`);
|
|
459
|
-
}
|
|
460
|
-
current = Option2.getOrUndefined(current.parent);
|
|
461
|
-
i++;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
out.push(...appendStacks);
|
|
465
|
-
error = Cause.originalError(error);
|
|
466
|
-
if (error.cause) {
|
|
467
|
-
error.cause = prettyErrorStack(error.cause);
|
|
468
|
-
}
|
|
469
|
-
Object.defineProperty(error, "stack", {
|
|
470
|
-
value: out.join("\n"),
|
|
471
|
-
writable: true,
|
|
472
|
-
enumerable: false,
|
|
473
|
-
configurable: true
|
|
474
|
-
});
|
|
475
|
-
return error;
|
|
476
|
-
};
|
|
477
|
-
var causeToError = (cause) => {
|
|
478
|
-
if (Cause.isEmpty(cause)) {
|
|
479
|
-
return new Error("Fiber failed without a cause");
|
|
480
|
-
} else if (Cause.isInterruptedOnly(cause)) {
|
|
481
|
-
return new Error("Fiber was interrupted");
|
|
482
|
-
} else {
|
|
483
|
-
const errors = [
|
|
484
|
-
...Chunk.toArray(Cause.failures(cause)),
|
|
485
|
-
...Chunk.toArray(Cause.defects(cause))
|
|
486
|
-
];
|
|
487
|
-
const getStackFrames = () => {
|
|
488
|
-
const o = new Error();
|
|
489
|
-
Error.captureStackTrace(o, causeToError);
|
|
490
|
-
return o.stack.split("\n").slice(1);
|
|
491
|
-
};
|
|
492
|
-
const stackFrames = getStackFrames();
|
|
493
|
-
const newErrors = errors.map((error) => prettyErrorStack(error, stackFrames));
|
|
494
|
-
if (newErrors.length === 1) {
|
|
495
|
-
return newErrors[0];
|
|
496
|
-
} else {
|
|
497
|
-
return new AggregateError(newErrors);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
616
|
+
};
|
|
617
|
+
return getBaseAnnotation(node);
|
|
500
618
|
};
|
|
501
|
-
var
|
|
502
|
-
|
|
619
|
+
var isOption = (node) => {
|
|
620
|
+
return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);
|
|
503
621
|
};
|
|
504
|
-
var
|
|
505
|
-
|
|
506
|
-
|
|
622
|
+
var isLiteralUnion = (node) => {
|
|
623
|
+
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
624
|
+
};
|
|
625
|
+
var getLiteralValues = (schema) => {
|
|
626
|
+
if (!isLiteralUnion(schema.ast)) {
|
|
627
|
+
return [];
|
|
507
628
|
}
|
|
508
|
-
return
|
|
629
|
+
return schema.ast.types.map((node) => node.literal);
|
|
509
630
|
};
|
|
510
|
-
var
|
|
511
|
-
|
|
512
|
-
return unwrapExit(exit2);
|
|
631
|
+
var isArrayType = (node) => {
|
|
632
|
+
return SchemaAST.isTupleType(node) && node.elements.length === 0 && node.rest.length === 1;
|
|
513
633
|
};
|
|
514
|
-
var
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
634
|
+
var getArrayElementType = (node) => {
|
|
635
|
+
return isArrayType(node) ? node.rest.at(0)?.type : void 0;
|
|
636
|
+
};
|
|
637
|
+
var isTupleType2 = (node) => {
|
|
638
|
+
return SchemaAST.isTupleType(node) && node.elements.length > 0;
|
|
639
|
+
};
|
|
640
|
+
var isDiscriminatedUnion = (node) => {
|
|
641
|
+
return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
642
|
+
};
|
|
643
|
+
var getDiscriminatingProps = (node) => {
|
|
644
|
+
invariant(SchemaAST.isUnion(node));
|
|
645
|
+
if (isOption(node)) {
|
|
646
|
+
return;
|
|
527
647
|
}
|
|
648
|
+
return node.types.reduce((shared, type) => {
|
|
649
|
+
const props = SchemaAST.getPropertySignatures(type).filter((p) => SchemaAST.isLiteral(p.type)).map((p) => p.name.toString());
|
|
650
|
+
return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));
|
|
651
|
+
}, []);
|
|
528
652
|
};
|
|
529
|
-
var
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
return
|
|
653
|
+
var getDiscriminatedType = (node, value = {}) => {
|
|
654
|
+
invariant(SchemaAST.isUnion(node));
|
|
655
|
+
invariant(value);
|
|
656
|
+
const props = getDiscriminatingProps(node);
|
|
657
|
+
if (!props?.length) {
|
|
658
|
+
return;
|
|
535
659
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (Option3.isNone(option)) {
|
|
544
|
-
missingTags.push(tag.key);
|
|
660
|
+
for (const type of node.types) {
|
|
661
|
+
const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
662
|
+
invariant(SchemaAST.isLiteral(prop.type));
|
|
663
|
+
return prop.type.literal === value[prop.name.toString()];
|
|
664
|
+
});
|
|
665
|
+
if (match) {
|
|
666
|
+
return type;
|
|
545
667
|
}
|
|
546
668
|
}
|
|
547
|
-
|
|
548
|
-
|
|
669
|
+
const fields = Object.fromEntries(props.map((prop) => {
|
|
670
|
+
const literals = node.types.map((type) => {
|
|
671
|
+
const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
672
|
+
invariant(SchemaAST.isLiteral(literal.type));
|
|
673
|
+
return literal.type.literal;
|
|
674
|
+
}).filter(isNonNullable);
|
|
675
|
+
return literals.length ? [
|
|
676
|
+
prop,
|
|
677
|
+
Schema.Literal(...literals)
|
|
678
|
+
] : void 0;
|
|
679
|
+
}).filter(isNonNullable));
|
|
680
|
+
const schema = Schema.Struct(fields);
|
|
681
|
+
return schema.ast;
|
|
682
|
+
};
|
|
683
|
+
var unwrapOptional = (property) => {
|
|
684
|
+
if (!property.isOptional || !SchemaAST.isUnion(property.type) || !isOption(property.type)) {
|
|
685
|
+
return property;
|
|
549
686
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
return rt;
|
|
561
|
-
}));
|
|
687
|
+
return property.type.types[0];
|
|
688
|
+
};
|
|
689
|
+
var isNestedType = (node) => {
|
|
690
|
+
return SchemaAST.isDeclaration(node) || SchemaAST.isObjectKeyword(node) || SchemaAST.isTypeLiteral(node) || // TODO(wittjosiah): Tuples are actually arrays.
|
|
691
|
+
isTupleType2(node) || isDiscriminatedUnion(node);
|
|
692
|
+
};
|
|
693
|
+
var mapAst = (ast, f) => {
|
|
694
|
+
switch (ast._tag) {
|
|
695
|
+
case "TypeLiteral": {
|
|
696
|
+
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);
|
|
562
697
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const getValidatedRuntime = () => {
|
|
566
|
-
const validationExit = managedRuntimeAny.runSyncExit(Effect3.gen(function* () {
|
|
567
|
-
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
568
|
-
yield* validateTags(rt.context, tags);
|
|
569
|
-
return rt;
|
|
570
|
-
}));
|
|
571
|
-
return unwrapExit(validationExit);
|
|
572
|
-
};
|
|
573
|
-
return {
|
|
574
|
-
managedRuntime: managedRuntimeAny,
|
|
575
|
-
runPromise: async (effect) => {
|
|
576
|
-
const runtime2 = await getValidatedRuntimeAsync();
|
|
577
|
-
return Runtime2.runPromise(runtime2)(effect);
|
|
578
|
-
},
|
|
579
|
-
runSync: (effect) => {
|
|
580
|
-
const runtime2 = getValidatedRuntime();
|
|
581
|
-
return Runtime2.runSync(runtime2)(effect);
|
|
582
|
-
},
|
|
583
|
-
runSyncExit: (effect) => {
|
|
584
|
-
const validationExit = managedRuntimeAny.runSyncExit(Effect3.gen(function* () {
|
|
585
|
-
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
586
|
-
yield* validateTags(rt.context, tags);
|
|
587
|
-
return rt;
|
|
588
|
-
}));
|
|
589
|
-
if (Exit2.isSuccess(validationExit)) {
|
|
590
|
-
const runtime2 = validationExit.value;
|
|
591
|
-
return Runtime2.runSyncExit(runtime2)(effect);
|
|
592
|
-
}
|
|
593
|
-
return validationExit;
|
|
594
|
-
},
|
|
595
|
-
runPromiseExit: async (effect) => {
|
|
596
|
-
try {
|
|
597
|
-
const runtime2 = await getValidatedRuntimeAsync();
|
|
598
|
-
return Runtime2.runPromiseExit(runtime2)(effect);
|
|
599
|
-
} catch (error) {
|
|
600
|
-
return Exit2.die(error);
|
|
601
|
-
}
|
|
602
|
-
},
|
|
603
|
-
runFork: (effect) => {
|
|
604
|
-
const runtime2 = getValidatedRuntime();
|
|
605
|
-
return Runtime2.runFork(runtime2)(effect);
|
|
606
|
-
},
|
|
607
|
-
runtimeEffect: Effect3.gen(function* () {
|
|
608
|
-
if (cachedRuntime) {
|
|
609
|
-
return cachedRuntime;
|
|
610
|
-
}
|
|
611
|
-
const rt = yield* managedRuntimeAny.runtimeEffect;
|
|
612
|
-
yield* validateTags(rt.context, tags);
|
|
613
|
-
const runtime2 = rt;
|
|
614
|
-
cachedRuntime = runtime2;
|
|
615
|
-
return runtime2;
|
|
616
|
-
}).pipe(Effect3.catchAll(() => (
|
|
617
|
-
// This should never happen since validateTags uses Effect.die
|
|
618
|
-
Effect3.die(new Error("Unexpected error in runtimeEffect validation"))
|
|
619
|
-
))),
|
|
620
|
-
dispose: async () => {
|
|
621
|
-
await managedRuntimeAny.dispose();
|
|
698
|
+
case "Union": {
|
|
699
|
+
return SchemaAST.Union.make(ast.types.map(f), ast.annotations);
|
|
622
700
|
}
|
|
623
|
-
|
|
624
|
-
|
|
701
|
+
case "TupleType": {
|
|
702
|
+
return new SchemaAST.TupleType(ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new SchemaAST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
|
|
703
|
+
}
|
|
704
|
+
case "Suspend": {
|
|
705
|
+
const newAst = f(ast.f(), void 0);
|
|
706
|
+
return new SchemaAST.Suspend(() => newAst, ast.annotations);
|
|
707
|
+
}
|
|
708
|
+
default: {
|
|
709
|
+
return ast;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
var getIndexSignatures = (ast) => {
|
|
714
|
+
const annotation = SchemaAST.getSurrogateAnnotation(ast);
|
|
715
|
+
if (Option3.isSome(annotation)) {
|
|
716
|
+
return getIndexSignatures(annotation.value);
|
|
717
|
+
}
|
|
718
|
+
switch (ast._tag) {
|
|
719
|
+
case "TypeLiteral":
|
|
720
|
+
return ast.indexSignatures.slice();
|
|
721
|
+
case "Suspend":
|
|
722
|
+
return getIndexSignatures(ast.f());
|
|
723
|
+
case "Refinement":
|
|
724
|
+
return getIndexSignatures(ast.from);
|
|
725
|
+
}
|
|
726
|
+
return [];
|
|
727
|
+
};
|
|
625
728
|
|
|
626
|
-
// src/json-path.ts
|
|
729
|
+
// src/internal/json-path.ts
|
|
627
730
|
import * as Option4 from "effect/Option";
|
|
628
731
|
import * as Schema2 from "effect/Schema";
|
|
629
732
|
import { JSONPath } from "jsonpath-plus";
|
|
630
733
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
631
734
|
import { getDeep, setDeep } from "@dxos/util";
|
|
632
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/json-path.ts";
|
|
633
735
|
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
634
736
|
var PROP_REGEX = /^\w+$/;
|
|
635
737
|
var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
|
|
@@ -650,28 +752,12 @@ var createJsonPath = (path) => {
|
|
|
650
752
|
return i === 0 ? p : `.${p}`;
|
|
651
753
|
}
|
|
652
754
|
}).join("");
|
|
653
|
-
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}
|
|
654
|
-
F: __dxlog_file3,
|
|
655
|
-
L: 69,
|
|
656
|
-
S: void 0,
|
|
657
|
-
A: [
|
|
658
|
-
"isJsonPath(candidatePath)",
|
|
659
|
-
"`Invalid JsonPath: ${candidatePath}`"
|
|
660
|
-
]
|
|
661
|
-
});
|
|
755
|
+
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);
|
|
662
756
|
return candidatePath;
|
|
663
757
|
};
|
|
664
758
|
var fromEffectValidationPath = (effectPath) => {
|
|
665
759
|
const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
|
|
666
|
-
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}
|
|
667
|
-
F: __dxlog_file3,
|
|
668
|
-
L: 80,
|
|
669
|
-
S: void 0,
|
|
670
|
-
A: [
|
|
671
|
-
"isJsonPath(jsonPath)",
|
|
672
|
-
"`Invalid JsonPath: ${jsonPath}`"
|
|
673
|
-
]
|
|
674
|
-
});
|
|
760
|
+
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);
|
|
675
761
|
return jsonPath;
|
|
676
762
|
};
|
|
677
763
|
var splitJsonPath = (path) => {
|
|
@@ -696,21 +782,7 @@ var setValue = (obj, path, value) => {
|
|
|
696
782
|
return setDeep(obj, splitJsonPath(path), value);
|
|
697
783
|
};
|
|
698
784
|
|
|
699
|
-
// src/
|
|
700
|
-
import * as Effect4 from "effect/Effect";
|
|
701
|
-
var acquireReleaseResource = (getResource) => Effect4.acquireRelease(Effect4.gen(function* () {
|
|
702
|
-
const resource = getResource();
|
|
703
|
-
yield* Effect4.promise(async () => {
|
|
704
|
-
await resource.open?.();
|
|
705
|
-
return void 0;
|
|
706
|
-
});
|
|
707
|
-
return resource;
|
|
708
|
-
}), (resource) => Effect4.promise(async () => {
|
|
709
|
-
await resource.close?.();
|
|
710
|
-
return void 0;
|
|
711
|
-
}));
|
|
712
|
-
|
|
713
|
-
// src/url.ts
|
|
785
|
+
// src/internal/url.ts
|
|
714
786
|
import * as Function2 from "effect/Function";
|
|
715
787
|
import * as Option5 from "effect/Option";
|
|
716
788
|
import * as SchemaAST2 from "effect/SchemaAST";
|
|
@@ -766,122 +838,12 @@ var UrlParser = class {
|
|
|
766
838
|
return url;
|
|
767
839
|
}
|
|
768
840
|
};
|
|
769
|
-
|
|
770
|
-
// src/RuntimeProvider.ts
|
|
771
|
-
var RuntimeProvider_exports = {};
|
|
772
|
-
__export(RuntimeProvider_exports, {
|
|
773
|
-
currentRuntime: () => currentRuntime,
|
|
774
|
-
provide: () => provide2,
|
|
775
|
-
runPromise: () => runPromise2
|
|
776
|
-
});
|
|
777
|
-
import * as Effect5 from "effect/Effect";
|
|
778
|
-
import * as Runtime3 from "effect/Runtime";
|
|
779
|
-
var currentRuntime = () => Effect5.runtime().pipe(Effect5.map(Effect5.succeed));
|
|
780
|
-
var runPromise2 = (provider) => async (effect) => {
|
|
781
|
-
const runtime2 = await runAndForwardErrors(provider);
|
|
782
|
-
return unwrapExit(await effect.pipe(Runtime3.runPromiseExit(runtime2)));
|
|
783
|
-
};
|
|
784
|
-
var provide2 = (runtimeProvider) => (effect) => Effect5.flatMap(runtimeProvider, (runtime2) => Effect5.provide(effect, runtime2));
|
|
785
|
-
|
|
786
|
-
// src/Performance.ts
|
|
787
|
-
var Performance_exports = {};
|
|
788
|
-
__export(Performance_exports, {
|
|
789
|
-
addTrackEntry: () => addTrackEntry
|
|
790
|
-
});
|
|
791
|
-
import * as Effect6 from "effect/Effect";
|
|
792
|
-
var addTrackEntry = (options) => (effect) => Effect6.gen(function* () {
|
|
793
|
-
const start = performance.now();
|
|
794
|
-
const exit2 = yield* Effect6.exit(effect);
|
|
795
|
-
const resolvedOptions = typeof options === "function" ? options(exit2) : options;
|
|
796
|
-
performance.measure(resolvedOptions.name, {
|
|
797
|
-
start,
|
|
798
|
-
detail: {
|
|
799
|
-
...resolvedOptions.detail,
|
|
800
|
-
devtools: resolvedOptions.devtools
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
return yield* exit2;
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
// src/async-task-tagging.ts
|
|
807
|
-
import * as Context3 from "effect/Context";
|
|
808
|
-
import * as Effect7 from "effect/Effect";
|
|
809
|
-
import { pipe as pipe3 } from "effect/Function";
|
|
810
|
-
import * as Layer from "effect/Layer";
|
|
811
|
-
import * as Predicate from "effect/Predicate";
|
|
812
|
-
import * as Tracer from "effect/Tracer";
|
|
813
|
-
var runInTask = /* @__PURE__ */ Symbol("runInTask");
|
|
814
|
-
var asyncTaskTaggingLayer = () => {
|
|
815
|
-
if (Predicate.hasProperty(console, "createTask") === false) {
|
|
816
|
-
return Layer.empty;
|
|
817
|
-
}
|
|
818
|
-
const makeTracer = Effect7.gen(function* () {
|
|
819
|
-
const oldTracer = yield* Effect7.tracer;
|
|
820
|
-
return Tracer.make({
|
|
821
|
-
span: (name, ...args) => {
|
|
822
|
-
const span = oldTracer.span(name, ...args);
|
|
823
|
-
const trace = console.createTask(name);
|
|
824
|
-
span[runInTask] = (f) => trace.run(f);
|
|
825
|
-
return span;
|
|
826
|
-
},
|
|
827
|
-
context: (f, fiber) => {
|
|
828
|
-
const maybeParentSpan = Context3.getOption(Tracer.ParentSpan)(fiber.currentContext);
|
|
829
|
-
if (maybeParentSpan._tag === "None") return oldTracer.context(f, fiber);
|
|
830
|
-
const parentSpan = maybeParentSpan.value;
|
|
831
|
-
if (parentSpan._tag === "ExternalSpan") return oldTracer.context(f, fiber);
|
|
832
|
-
const span = parentSpan;
|
|
833
|
-
if (runInTask in span && typeof span[runInTask] === "function") {
|
|
834
|
-
return span[runInTask](() => oldTracer.context(f, fiber));
|
|
835
|
-
}
|
|
836
|
-
return oldTracer.context(f, fiber);
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
});
|
|
840
|
-
return pipe3(makeTracer, Effect7.map(Layer.setTracer), Layer.unwrapEffect);
|
|
841
|
-
};
|
|
842
841
|
export {
|
|
843
842
|
dynamic_runtime_exports as DynamicRuntime,
|
|
844
|
-
|
|
845
|
-
JsonProp,
|
|
846
|
-
ParamKeyAnnotation,
|
|
843
|
+
EffectEx_exports as EffectEx,
|
|
847
844
|
Performance_exports as Performance,
|
|
848
845
|
RuntimeProvider_exports as RuntimeProvider,
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
acquireReleaseResource,
|
|
852
|
-
asyncTaskTaggingLayer,
|
|
853
|
-
causeToError,
|
|
854
|
-
contextFromScope,
|
|
855
|
-
createJsonPath,
|
|
856
|
-
createKvsStore,
|
|
857
|
-
findAnnotation,
|
|
858
|
-
findNode,
|
|
859
|
-
findProperty,
|
|
860
|
-
fromEffectValidationPath,
|
|
861
|
-
getAnnotation2 as getAnnotation,
|
|
862
|
-
getArrayElementType,
|
|
863
|
-
getBaseType,
|
|
864
|
-
getDiscriminatedType,
|
|
865
|
-
getDiscriminatingProps,
|
|
866
|
-
getField,
|
|
867
|
-
getParamKeyAnnotation,
|
|
868
|
-
getProperties,
|
|
869
|
-
getValue,
|
|
870
|
-
isArrayType,
|
|
871
|
-
isDiscriminatedUnion,
|
|
872
|
-
isJsonPath,
|
|
873
|
-
isLiteralUnion,
|
|
874
|
-
isNestedType,
|
|
875
|
-
isOption,
|
|
876
|
-
isTupleType2 as isTupleType,
|
|
877
|
-
mapAst,
|
|
878
|
-
promiseWithCauseCapture,
|
|
879
|
-
runAndForwardErrors,
|
|
880
|
-
runInRuntime,
|
|
881
|
-
setValue,
|
|
882
|
-
splitJsonPath,
|
|
883
|
-
throwCause,
|
|
884
|
-
unwrapExit,
|
|
885
|
-
visit
|
|
846
|
+
SchemaEx_exports as SchemaEx,
|
|
847
|
+
createKvsStore
|
|
886
848
|
};
|
|
887
849
|
//# sourceMappingURL=index.mjs.map
|