@dxos/effect 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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/chunk-CGS2ULMK.mjs +11 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +530 -353
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing.mjs +31 -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 +530 -353
- 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 +31 -0
- package/dist/lib/node-esm/testing.mjs.map +7 -0
- 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 +25 -0
- package/dist/types/src/Performance.d.ts.map +1 -0
- package/dist/types/src/RuntimeProvider.d.ts +21 -0
- package/dist/types/src/RuntimeProvider.d.ts.map +1 -0
- 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 +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/index.d.ts +8 -7
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/{ast.d.ts → internal/ast.d.ts} +45 -21
- package/dist/types/src/internal/ast.d.ts.map +1 -0
- package/dist/types/src/internal/async-task-tagging.d.ts +6 -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} +16 -0
- package/dist/types/src/internal/errors.d.ts.map +1 -0
- package/dist/types/src/{jsonPath.d.ts → internal/json-path.d.ts} +11 -3
- 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/json-path.test.d.ts +2 -0
- package/dist/types/src/json-path.test.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +5 -14
- 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 +33 -21
- package/src/EffectEx.ts +18 -0
- package/src/Performance.ts +45 -0
- package/src/RuntimeProvider.ts +35 -0
- package/src/SchemaEx.ts +46 -0
- package/src/ast.test.ts +36 -9
- package/src/atom-kvs.ts +35 -0
- package/src/dynamic-runtime.test.ts +465 -0
- package/src/dynamic-runtime.ts +195 -0
- package/src/index.ts +12 -7
- package/src/{ast.ts → internal/ast.ts} +121 -91
- package/src/internal/async-task-tagging.ts +51 -0
- package/src/{errors.ts → internal/errors.ts} +72 -8
- package/src/{jsonPath.ts → internal/json-path.ts} +26 -3
- package/src/{resource.ts → internal/resource.ts} +2 -2
- package/src/interrupt.test.ts +3 -1
- package/src/{jsonPath.test.ts → json-path.test.ts} +55 -8
- package/src/layers.test.ts +4 -2
- package/src/resource.test.ts +1 -1
- package/src/sanity.test.ts +6 -4
- package/src/testing.ts +5 -29
- 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/context.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/jsonPath.d.ts.map +0 -1
- package/dist/types/src/jsonPath.test.d.ts +0 -2
- package/dist/types/src/jsonPath.test.d.ts.map +0 -1
- package/dist/types/src/resource.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- /package/dist/types/src/{context.d.ts → internal/context.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/{url.ts → internal/url.ts} +0 -0
|
@@ -1,72 +1,492 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
|
+
import {
|
|
3
|
+
__export
|
|
4
|
+
} from "./chunk-CGS2ULMK.mjs";
|
|
2
5
|
|
|
3
|
-
// src/
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
|
13
18
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
45
|
}
|
|
19
|
-
|
|
20
|
-
|
|
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 "));
|
|
21
87
|
}
|
|
22
|
-
if (
|
|
23
|
-
|
|
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
|
+
}
|
|
24
114
|
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
|
27
150
|
}
|
|
28
|
-
|
|
29
|
-
|
|
151
|
+
};
|
|
152
|
+
var throwCause = (cause) => {
|
|
153
|
+
throw causeToError(cause);
|
|
154
|
+
};
|
|
155
|
+
var unwrapExit = (exit2) => {
|
|
156
|
+
if (Exit.isSuccess(exit2)) {
|
|
157
|
+
return exit2.value;
|
|
30
158
|
}
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
})();
|
|
33
179
|
}
|
|
34
180
|
};
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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);
|
|
44
244
|
}
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
47
253
|
}
|
|
48
|
-
|
|
49
|
-
|
|
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;
|
|
50
262
|
}
|
|
51
|
-
|
|
52
|
-
|
|
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);
|
|
53
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
|
|
54
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
|
|
431
|
+
import * as Function from "effect/Function";
|
|
432
|
+
import * as Option3 from "effect/Option";
|
|
433
|
+
import * as Schema from "effect/Schema";
|
|
434
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
435
|
+
import { invariant } from "@dxos/invariant";
|
|
436
|
+
import { isNonNullable } from "@dxos/util";
|
|
437
|
+
var reduceRefinements = (type, refinements = []) => {
|
|
438
|
+
if (SchemaAST.isRefinement(type)) {
|
|
439
|
+
const filter = type.filter;
|
|
440
|
+
const nextType = {
|
|
441
|
+
...type.from,
|
|
442
|
+
annotations: {
|
|
443
|
+
...type.from.annotations,
|
|
444
|
+
...type.annotations
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
return reduceRefinements(nextType, [
|
|
448
|
+
...refinements,
|
|
449
|
+
filter
|
|
450
|
+
]);
|
|
451
|
+
}
|
|
452
|
+
return {
|
|
453
|
+
type,
|
|
454
|
+
refinements
|
|
55
455
|
};
|
|
56
|
-
}
|
|
456
|
+
};
|
|
457
|
+
var getBaseType = (prop) => {
|
|
458
|
+
const encoded = SchemaAST.encodedBoundAST(prop.type);
|
|
459
|
+
const unwrapped = prop.isOptional && encoded._tag === "Union" ? encoded.types[0] : encoded;
|
|
460
|
+
return reduceRefinements(unwrapped);
|
|
461
|
+
};
|
|
462
|
+
var getProperties = (ast) => {
|
|
463
|
+
const properties = SchemaAST.getPropertySignatures(ast);
|
|
464
|
+
return properties.map((prop) => {
|
|
465
|
+
const { type, refinements } = getBaseType(prop);
|
|
466
|
+
const mergedType = prop.annotations && Reflect.ownKeys(prop.annotations).length > 0 ? {
|
|
467
|
+
...type,
|
|
468
|
+
annotations: {
|
|
469
|
+
...type.annotations,
|
|
470
|
+
...prop.annotations
|
|
471
|
+
}
|
|
472
|
+
} : type;
|
|
473
|
+
return {
|
|
474
|
+
type: mergedType,
|
|
475
|
+
refinements,
|
|
476
|
+
name: prop.name,
|
|
477
|
+
isOptional: prop.isOptional,
|
|
478
|
+
isReadonly: prop.isReadonly
|
|
479
|
+
};
|
|
480
|
+
});
|
|
481
|
+
};
|
|
57
482
|
var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
|
|
58
483
|
VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
|
|
59
484
|
VisitResult2[VisitResult2["SKIP"] = 1] = "SKIP";
|
|
60
485
|
VisitResult2[VisitResult2["EXIT"] = 2] = "EXIT";
|
|
61
486
|
return VisitResult2;
|
|
62
487
|
})({});
|
|
63
|
-
var defaultTest = isSimpleType;
|
|
64
488
|
var visit = (node, testOrVisitor, visitor) => {
|
|
65
|
-
|
|
66
|
-
visitNode(node, defaultTest, testOrVisitor);
|
|
67
|
-
} else {
|
|
68
|
-
visitNode(node, testOrVisitor, visitor);
|
|
69
|
-
}
|
|
489
|
+
visitNode(node, testOrVisitor, visitor);
|
|
70
490
|
};
|
|
71
491
|
var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
72
492
|
const $result = test?.(node, path, depth);
|
|
@@ -154,15 +574,7 @@ var findProperty = (schema, path) => {
|
|
|
154
574
|
const getProp = (node, path2) => {
|
|
155
575
|
const [name, ...rest] = path2;
|
|
156
576
|
const typeNode = findNode(node, SchemaAST.isTypeLiteral);
|
|
157
|
-
invariant(typeNode
|
|
158
|
-
F: __dxlog_file,
|
|
159
|
-
L: 265,
|
|
160
|
-
S: void 0,
|
|
161
|
-
A: [
|
|
162
|
-
"typeNode",
|
|
163
|
-
""
|
|
164
|
-
]
|
|
165
|
-
});
|
|
577
|
+
invariant(typeNode);
|
|
166
578
|
for (const prop of SchemaAST.getPropertySignatures(typeNode)) {
|
|
167
579
|
if (prop.name === name) {
|
|
168
580
|
if (rest.length) {
|
|
@@ -176,14 +588,14 @@ var findProperty = (schema, path) => {
|
|
|
176
588
|
return getProp(schema.ast, path.split("."));
|
|
177
589
|
};
|
|
178
590
|
var defaultAnnotations = {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
591
|
+
ObjectKeyword: SchemaAST.objectKeyword,
|
|
592
|
+
StringKeyword: SchemaAST.stringKeyword,
|
|
593
|
+
NumberKeyword: SchemaAST.numberKeyword,
|
|
594
|
+
BooleanKeyword: SchemaAST.booleanKeyword
|
|
183
595
|
};
|
|
184
596
|
var getAnnotation2 = (annotationId, noDefault = true) => (node) => {
|
|
185
|
-
const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node),
|
|
186
|
-
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);
|
|
187
599
|
if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
|
|
188
600
|
return void 0;
|
|
189
601
|
}
|
|
@@ -210,19 +622,26 @@ var isOption = (node) => {
|
|
|
210
622
|
var isLiteralUnion = (node) => {
|
|
211
623
|
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
212
624
|
};
|
|
625
|
+
var getLiteralValues = (schema) => {
|
|
626
|
+
if (!isLiteralUnion(schema.ast)) {
|
|
627
|
+
return [];
|
|
628
|
+
}
|
|
629
|
+
return schema.ast.types.map((node) => node.literal);
|
|
630
|
+
};
|
|
631
|
+
var isArrayType = (node) => {
|
|
632
|
+
return SchemaAST.isTupleType(node) && node.elements.length === 0 && node.rest.length === 1;
|
|
633
|
+
};
|
|
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
|
+
};
|
|
213
640
|
var isDiscriminatedUnion = (node) => {
|
|
214
641
|
return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
215
642
|
};
|
|
216
643
|
var getDiscriminatingProps = (node) => {
|
|
217
|
-
invariant(SchemaAST.isUnion(node)
|
|
218
|
-
F: __dxlog_file,
|
|
219
|
-
L: 362,
|
|
220
|
-
S: void 0,
|
|
221
|
-
A: [
|
|
222
|
-
"SchemaAST.isUnion(node)",
|
|
223
|
-
""
|
|
224
|
-
]
|
|
225
|
-
});
|
|
644
|
+
invariant(SchemaAST.isUnion(node));
|
|
226
645
|
if (isOption(node)) {
|
|
227
646
|
return;
|
|
228
647
|
}
|
|
@@ -232,39 +651,15 @@ var getDiscriminatingProps = (node) => {
|
|
|
232
651
|
}, []);
|
|
233
652
|
};
|
|
234
653
|
var getDiscriminatedType = (node, value = {}) => {
|
|
235
|
-
invariant(SchemaAST.isUnion(node)
|
|
236
|
-
|
|
237
|
-
L: 386,
|
|
238
|
-
S: void 0,
|
|
239
|
-
A: [
|
|
240
|
-
"SchemaAST.isUnion(node)",
|
|
241
|
-
""
|
|
242
|
-
]
|
|
243
|
-
});
|
|
244
|
-
invariant(value, void 0, {
|
|
245
|
-
F: __dxlog_file,
|
|
246
|
-
L: 387,
|
|
247
|
-
S: void 0,
|
|
248
|
-
A: [
|
|
249
|
-
"value",
|
|
250
|
-
""
|
|
251
|
-
]
|
|
252
|
-
});
|
|
654
|
+
invariant(SchemaAST.isUnion(node));
|
|
655
|
+
invariant(value);
|
|
253
656
|
const props = getDiscriminatingProps(node);
|
|
254
657
|
if (!props?.length) {
|
|
255
658
|
return;
|
|
256
659
|
}
|
|
257
660
|
for (const type of node.types) {
|
|
258
661
|
const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
259
|
-
invariant(SchemaAST.isLiteral(prop.type)
|
|
260
|
-
F: __dxlog_file,
|
|
261
|
-
L: 398,
|
|
262
|
-
S: void 0,
|
|
263
|
-
A: [
|
|
264
|
-
"SchemaAST.isLiteral(prop.type)",
|
|
265
|
-
""
|
|
266
|
-
]
|
|
267
|
-
});
|
|
662
|
+
invariant(SchemaAST.isLiteral(prop.type));
|
|
268
663
|
return prop.type.literal === value[prop.name.toString()];
|
|
269
664
|
});
|
|
270
665
|
if (match) {
|
|
@@ -274,15 +669,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
274
669
|
const fields = Object.fromEntries(props.map((prop) => {
|
|
275
670
|
const literals = node.types.map((type) => {
|
|
276
671
|
const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
277
|
-
invariant(SchemaAST.isLiteral(literal.type)
|
|
278
|
-
F: __dxlog_file,
|
|
279
|
-
L: 416,
|
|
280
|
-
S: void 0,
|
|
281
|
-
A: [
|
|
282
|
-
"SchemaAST.isLiteral(literal.type)",
|
|
283
|
-
""
|
|
284
|
-
]
|
|
285
|
-
});
|
|
672
|
+
invariant(SchemaAST.isLiteral(literal.type));
|
|
286
673
|
return literal.type.literal;
|
|
287
674
|
}).filter(isNonNullable);
|
|
288
675
|
return literals.length ? [
|
|
@@ -293,6 +680,16 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
293
680
|
const schema = Schema.Struct(fields);
|
|
294
681
|
return schema.ast;
|
|
295
682
|
};
|
|
683
|
+
var unwrapOptional = (property) => {
|
|
684
|
+
if (!property.isOptional || !SchemaAST.isUnion(property.type) || !isOption(property.type)) {
|
|
685
|
+
return property;
|
|
686
|
+
}
|
|
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
|
+
};
|
|
296
693
|
var mapAst = (ast, f) => {
|
|
297
694
|
switch (ast._tag) {
|
|
298
695
|
case "TypeLiteral": {
|
|
@@ -313,12 +710,9 @@ var mapAst = (ast, f) => {
|
|
|
313
710
|
}
|
|
314
711
|
}
|
|
315
712
|
};
|
|
316
|
-
var isArrayType = (node) => {
|
|
317
|
-
return SchemaAST.isTupleType(node) || SchemaAST.isUnion(node) && node.types.some(isArrayType) && node.types.some(SchemaAST.isUndefinedKeyword) && node.types.length === 2;
|
|
318
|
-
};
|
|
319
713
|
var getIndexSignatures = (ast) => {
|
|
320
714
|
const annotation = SchemaAST.getSurrogateAnnotation(ast);
|
|
321
|
-
if (
|
|
715
|
+
if (Option3.isSome(annotation)) {
|
|
322
716
|
return getIndexSignatures(annotation.value);
|
|
323
717
|
}
|
|
324
718
|
switch (ast._tag) {
|
|
@@ -331,14 +725,13 @@ var getIndexSignatures = (ast) => {
|
|
|
331
725
|
}
|
|
332
726
|
return [];
|
|
333
727
|
};
|
|
334
|
-
var SimpleType;
|
|
335
728
|
|
|
336
|
-
// src/
|
|
337
|
-
import * as
|
|
729
|
+
// src/internal/json-path.ts
|
|
730
|
+
import * as Option4 from "effect/Option";
|
|
338
731
|
import * as Schema2 from "effect/Schema";
|
|
339
732
|
import { JSONPath } from "jsonpath-plus";
|
|
340
733
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
341
|
-
|
|
734
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
342
735
|
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
343
736
|
var PROP_REGEX = /^\w+$/;
|
|
344
737
|
var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
|
|
@@ -349,7 +742,7 @@ var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
|
|
|
349
742
|
message: () => "Property name must contain only letters, numbers, and underscores"
|
|
350
743
|
}));
|
|
351
744
|
var isJsonPath = (value) => {
|
|
352
|
-
return
|
|
745
|
+
return Option4.isSome(Schema2.validateOption(JsonPath)(value));
|
|
353
746
|
};
|
|
354
747
|
var createJsonPath = (path) => {
|
|
355
748
|
const candidatePath = path.map((p, i) => {
|
|
@@ -359,35 +752,22 @@ var createJsonPath = (path) => {
|
|
|
359
752
|
return i === 0 ? p : `.${p}`;
|
|
360
753
|
}
|
|
361
754
|
}).join("");
|
|
362
|
-
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}
|
|
363
|
-
F: __dxlog_file2,
|
|
364
|
-
L: 65,
|
|
365
|
-
S: void 0,
|
|
366
|
-
A: [
|
|
367
|
-
"isJsonPath(candidatePath)",
|
|
368
|
-
"`Invalid JsonPath: ${candidatePath}`"
|
|
369
|
-
]
|
|
370
|
-
});
|
|
755
|
+
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);
|
|
371
756
|
return candidatePath;
|
|
372
757
|
};
|
|
373
758
|
var fromEffectValidationPath = (effectPath) => {
|
|
374
759
|
const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
|
|
375
|
-
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}
|
|
376
|
-
F: __dxlog_file2,
|
|
377
|
-
L: 76,
|
|
378
|
-
S: void 0,
|
|
379
|
-
A: [
|
|
380
|
-
"isJsonPath(jsonPath)",
|
|
381
|
-
"`Invalid JsonPath: ${jsonPath}`"
|
|
382
|
-
]
|
|
383
|
-
});
|
|
760
|
+
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);
|
|
384
761
|
return jsonPath;
|
|
385
762
|
};
|
|
386
763
|
var splitJsonPath = (path) => {
|
|
387
764
|
if (!isJsonPath(path)) {
|
|
388
765
|
return [];
|
|
389
766
|
}
|
|
390
|
-
return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.
|
|
767
|
+
return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.replace(/[[\]]/g, "")).map((part) => {
|
|
768
|
+
const parsed = Number.parseInt(part, 10);
|
|
769
|
+
return Number.isNaN(parsed) ? part : parsed;
|
|
770
|
+
}) ?? [];
|
|
391
771
|
};
|
|
392
772
|
var getField = (object, path) => {
|
|
393
773
|
return JSONPath({
|
|
@@ -395,13 +775,19 @@ var getField = (object, path) => {
|
|
|
395
775
|
json: object
|
|
396
776
|
})[0];
|
|
397
777
|
};
|
|
778
|
+
var getValue = (obj, path) => {
|
|
779
|
+
return getDeep(obj, splitJsonPath(path));
|
|
780
|
+
};
|
|
781
|
+
var setValue = (obj, path, value) => {
|
|
782
|
+
return setDeep(obj, splitJsonPath(path), value);
|
|
783
|
+
};
|
|
398
784
|
|
|
399
|
-
// src/url.ts
|
|
785
|
+
// src/internal/url.ts
|
|
400
786
|
import * as Function2 from "effect/Function";
|
|
401
|
-
import * as
|
|
787
|
+
import * as Option5 from "effect/Option";
|
|
402
788
|
import * as SchemaAST2 from "effect/SchemaAST";
|
|
403
789
|
import { decamelize } from "@dxos/util";
|
|
404
|
-
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
790
|
+
var ParamKeyAnnotationId = /* @__PURE__ */ Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
405
791
|
var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
|
|
406
792
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
407
793
|
[ParamKeyAnnotationId]: value
|
|
@@ -442,7 +828,7 @@ var UrlParser = class {
|
|
|
442
828
|
if (value !== void 0) {
|
|
443
829
|
const field = this._schema.fields[key];
|
|
444
830
|
if (field) {
|
|
445
|
-
const { key: serializedKey } = Function2.pipe(getParamKeyAnnotation(field.ast),
|
|
831
|
+
const { key: serializedKey } = Function2.pipe(getParamKeyAnnotation(field.ast), Option5.getOrElse(() => ({
|
|
446
832
|
key: decamelize(key)
|
|
447
833
|
})));
|
|
448
834
|
url.searchParams.set(serializedKey, String(value));
|
|
@@ -452,221 +838,12 @@ var UrlParser = class {
|
|
|
452
838
|
return url;
|
|
453
839
|
}
|
|
454
840
|
};
|
|
455
|
-
|
|
456
|
-
// src/context.ts
|
|
457
|
-
import * as Effect from "effect/Effect";
|
|
458
|
-
import { Context } from "@dxos/context";
|
|
459
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
|
|
460
|
-
var contextFromScope = () => Effect.gen(function* () {
|
|
461
|
-
const ctx = new Context(void 0, {
|
|
462
|
-
F: __dxlog_file3,
|
|
463
|
-
L: 13
|
|
464
|
-
});
|
|
465
|
-
yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
|
|
466
|
-
return ctx;
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
// src/errors.ts
|
|
470
|
-
import * as Cause from "effect/Cause";
|
|
471
|
-
import * as Chunk from "effect/Chunk";
|
|
472
|
-
import * as Effect2 from "effect/Effect";
|
|
473
|
-
import * as Exit from "effect/Exit";
|
|
474
|
-
import * as GlobalValue from "effect/GlobalValue";
|
|
475
|
-
import * as Option4 from "effect/Option";
|
|
476
|
-
var spanSymbol = Symbol.for("effect/SpanAnnotation");
|
|
477
|
-
var originalSymbol = Symbol.for("effect/OriginalAnnotation");
|
|
478
|
-
var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
|
|
479
|
-
var locationRegex = /\((.*)\)/g;
|
|
480
|
-
var prettyErrorStack = (error, appendStacks = []) => {
|
|
481
|
-
const span = error[spanSymbol];
|
|
482
|
-
const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
|
|
483
|
-
const out = [];
|
|
484
|
-
let atStack = false;
|
|
485
|
-
for (let i = 0; i < lines.length; i++) {
|
|
486
|
-
if (!atStack && !lines[i].startsWith(" at ")) {
|
|
487
|
-
out.push(lines[i]);
|
|
488
|
-
continue;
|
|
489
|
-
}
|
|
490
|
-
atStack = true;
|
|
491
|
-
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
492
|
-
i++;
|
|
493
|
-
continue;
|
|
494
|
-
}
|
|
495
|
-
if (lines[i].includes("Generator.next")) {
|
|
496
|
-
break;
|
|
497
|
-
}
|
|
498
|
-
if (lines[i].includes("effect_internal_function")) {
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
|
|
502
|
-
}
|
|
503
|
-
if (span) {
|
|
504
|
-
let current = span;
|
|
505
|
-
let i = 0;
|
|
506
|
-
while (current && current._tag === "Span" && i < 10) {
|
|
507
|
-
const stackFn = spanToTrace.get(current);
|
|
508
|
-
if (typeof stackFn === "function") {
|
|
509
|
-
const stack = stackFn();
|
|
510
|
-
if (typeof stack === "string") {
|
|
511
|
-
const locationMatchAll = stack.matchAll(locationRegex);
|
|
512
|
-
let match = false;
|
|
513
|
-
for (const [, location] of locationMatchAll) {
|
|
514
|
-
match = true;
|
|
515
|
-
out.push(` at ${current.name} (${location})`);
|
|
516
|
-
}
|
|
517
|
-
if (!match) {
|
|
518
|
-
out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
|
|
519
|
-
}
|
|
520
|
-
} else {
|
|
521
|
-
out.push(` at ${current.name}`);
|
|
522
|
-
}
|
|
523
|
-
} else {
|
|
524
|
-
out.push(` at ${current.name}`);
|
|
525
|
-
}
|
|
526
|
-
current = Option4.getOrUndefined(current.parent);
|
|
527
|
-
i++;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
out.push(...appendStacks);
|
|
531
|
-
if (error[originalSymbol]) {
|
|
532
|
-
error = error[originalSymbol];
|
|
533
|
-
}
|
|
534
|
-
if (error.cause) {
|
|
535
|
-
error.cause = prettyErrorStack(error.cause);
|
|
536
|
-
}
|
|
537
|
-
Object.defineProperty(error, "stack", {
|
|
538
|
-
value: out.join("\n"),
|
|
539
|
-
writable: true,
|
|
540
|
-
enumerable: false,
|
|
541
|
-
configurable: true
|
|
542
|
-
});
|
|
543
|
-
return error;
|
|
544
|
-
};
|
|
545
|
-
var causeToError = (cause) => {
|
|
546
|
-
if (Cause.isEmpty(cause)) {
|
|
547
|
-
return new Error("Fiber failed without a cause");
|
|
548
|
-
} else if (Cause.isInterruptedOnly(cause)) {
|
|
549
|
-
return new Error("Fiber was interrupted");
|
|
550
|
-
} else {
|
|
551
|
-
const errors = [
|
|
552
|
-
...Chunk.toArray(Cause.failures(cause)),
|
|
553
|
-
...Chunk.toArray(Cause.defects(cause))
|
|
554
|
-
];
|
|
555
|
-
const getStackFrames = () => {
|
|
556
|
-
const o = {};
|
|
557
|
-
Error.captureStackTrace(o, getStackFrames);
|
|
558
|
-
return o.stack.split("\n").slice(1);
|
|
559
|
-
};
|
|
560
|
-
const stackFrames = getStackFrames();
|
|
561
|
-
const newErrors = errors.map((error) => prettyErrorStack(error, stackFrames));
|
|
562
|
-
if (newErrors.length === 1) {
|
|
563
|
-
return newErrors[0];
|
|
564
|
-
} else {
|
|
565
|
-
return new AggregateError(newErrors);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
var throwCause = (cause) => {
|
|
570
|
-
throw causeToError(cause);
|
|
571
|
-
};
|
|
572
|
-
var unwrapExit = (exit) => {
|
|
573
|
-
if (Exit.isSuccess(exit)) {
|
|
574
|
-
return exit.value;
|
|
575
|
-
}
|
|
576
|
-
return throwCause(exit.cause);
|
|
577
|
-
};
|
|
578
|
-
var runAndForwardErrors = async (effect, options) => {
|
|
579
|
-
const exit = await Effect2.runPromiseExit(effect, options);
|
|
580
|
-
return unwrapExit(exit);
|
|
581
|
-
};
|
|
582
|
-
var promiseWithCauseCapture = (evaluate) => Effect2.promise(async (signal) => {
|
|
583
|
-
try {
|
|
584
|
-
const result = await evaluate(signal);
|
|
585
|
-
return Effect2.succeed(result);
|
|
586
|
-
} catch (err) {
|
|
587
|
-
return Effect2.die(err);
|
|
588
|
-
}
|
|
589
|
-
}).pipe(Effect2.flatten);
|
|
590
|
-
|
|
591
|
-
// src/testing.ts
|
|
592
|
-
import * as Context2 from "effect/Context";
|
|
593
|
-
import * as Effect3 from "effect/Effect";
|
|
594
|
-
(function(TestHelpers2) {
|
|
595
|
-
TestHelpers2.runIf = (condition) => (effect, ctx) => Effect3.gen(function* () {
|
|
596
|
-
if (!condition) {
|
|
597
|
-
ctx.skip();
|
|
598
|
-
} else {
|
|
599
|
-
return yield* effect;
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
TestHelpers2.skipIf = (condition) => (effect, ctx) => Effect3.gen(function* () {
|
|
603
|
-
if (condition) {
|
|
604
|
-
ctx.skip();
|
|
605
|
-
} else {
|
|
606
|
-
return yield* effect;
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
TestHelpers2.taggedTest = (tag) => (effect, ctx) => Effect3.gen(function* () {
|
|
610
|
-
if (!process.env.DX_TEST_TAGS?.includes(tag)) {
|
|
611
|
-
ctx.skip();
|
|
612
|
-
} else {
|
|
613
|
-
return yield* effect;
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
TestHelpers2.provideTestContext = (effect, ctx) => Effect3.provideService(effect, TestContextService, ctx);
|
|
617
|
-
})(TestHelpers || (TestHelpers = {}));
|
|
618
|
-
var TestContextService = class extends Context2.Tag("@dxos/effect/TestContextService")() {
|
|
619
|
-
};
|
|
620
|
-
var TestHelpers;
|
|
621
|
-
|
|
622
|
-
// src/resource.ts
|
|
623
|
-
import * as Effect4 from "effect/Effect";
|
|
624
|
-
var acquireReleaseResource = (getResource) => Effect4.acquireRelease(Effect4.gen(function* () {
|
|
625
|
-
const resource = getResource();
|
|
626
|
-
yield* Effect4.promise(async () => {
|
|
627
|
-
resource.open?.();
|
|
628
|
-
return void 0;
|
|
629
|
-
});
|
|
630
|
-
return resource;
|
|
631
|
-
}), (resource) => Effect4.promise(async () => {
|
|
632
|
-
resource.close?.();
|
|
633
|
-
return void 0;
|
|
634
|
-
}));
|
|
635
841
|
export {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
UrlParser,
|
|
643
|
-
VisitResult,
|
|
644
|
-
acquireReleaseResource,
|
|
645
|
-
causeToError,
|
|
646
|
-
contextFromScope,
|
|
647
|
-
createJsonPath,
|
|
648
|
-
findAnnotation,
|
|
649
|
-
findNode,
|
|
650
|
-
findProperty,
|
|
651
|
-
fromEffectValidationPath,
|
|
652
|
-
getAnnotation2 as getAnnotation,
|
|
653
|
-
getDiscriminatedType,
|
|
654
|
-
getDiscriminatingProps,
|
|
655
|
-
getField,
|
|
656
|
-
getParamKeyAnnotation,
|
|
657
|
-
getSimpleType,
|
|
658
|
-
isArrayType,
|
|
659
|
-
isDiscriminatedUnion,
|
|
660
|
-
isJsonPath,
|
|
661
|
-
isLiteralUnion,
|
|
662
|
-
isOption,
|
|
663
|
-
isSimpleType,
|
|
664
|
-
mapAst,
|
|
665
|
-
promiseWithCauseCapture,
|
|
666
|
-
runAndForwardErrors,
|
|
667
|
-
splitJsonPath,
|
|
668
|
-
throwCause,
|
|
669
|
-
unwrapExit,
|
|
670
|
-
visit
|
|
842
|
+
dynamic_runtime_exports as DynamicRuntime,
|
|
843
|
+
EffectEx_exports as EffectEx,
|
|
844
|
+
Performance_exports as Performance,
|
|
845
|
+
RuntimeProvider_exports as RuntimeProvider,
|
|
846
|
+
SchemaEx_exports as SchemaEx,
|
|
847
|
+
createKvsStore
|
|
671
848
|
};
|
|
672
849
|
//# sourceMappingURL=index.mjs.map
|