@dxos/effect 0.8.4-main.fd6878d → 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 +568 -329
- 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 +568 -329
- 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} +47 -22
- 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/{context.d.ts → internal/context.d.ts} +2 -1
- package/dist/types/src/internal/context.d.ts.map +1 -0
- package/dist/types/src/internal/errors.d.ts +61 -0
- package/dist/types/src/internal/errors.d.ts.map +1 -0
- package/dist/types/src/{jsonPath.d.ts → internal/json-path.d.ts} +12 -4
- package/dist/types/src/internal/json-path.d.ts.map +1 -0
- package/dist/types/src/internal/resource.d.ts +8 -0
- package/dist/types/src/internal/resource.d.ts.map +1 -0
- package/dist/types/src/{url.d.ts → internal/url.d.ts} +3 -1
- package/dist/types/src/internal/url.d.ts.map +1 -0
- package/dist/types/src/interrupt.test.d.ts +2 -0
- package/dist/types/src/interrupt.test.d.ts.map +1 -0
- package/dist/types/src/json-path.test.d.ts +2 -0
- package/dist/types/src/json-path.test.d.ts.map +1 -0
- package/dist/types/src/otel.d.ts +17 -0
- package/dist/types/src/otel.d.ts.map +1 -0
- package/dist/types/src/otel.test.d.ts +2 -0
- package/dist/types/src/otel.test.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +25 -11
- 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 -13
- 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 +38 -10
- package/src/atom-kvs.ts +35 -0
- package/src/dynamic-runtime.test.ts +465 -0
- package/src/dynamic-runtime.ts +195 -0
- package/src/errors.test.ts +1 -1
- package/src/index.ts +12 -7
- package/src/{ast.ts → internal/ast.ts} +161 -96
- package/src/internal/async-task-tagging.ts +51 -0
- package/src/{context.ts → internal/context.ts} +2 -1
- package/src/internal/errors.ts +255 -0
- package/src/{jsonPath.ts → internal/json-path.ts} +29 -4
- package/src/{resource.ts → internal/resource.ts} +10 -5
- package/src/{url.ts → internal/url.ts} +5 -2
- package/src/interrupt.test.ts +35 -0
- package/src/{jsonPath.test.ts → json-path.test.ts} +55 -8
- package/src/layers.test.ts +10 -4
- package/src/otel.test.ts +126 -0
- package/src/otel.ts +45 -0
- package/src/resource.test.ts +3 -3
- package/src/sanity.test.ts +30 -15
- package/src/testing.ts +29 -22
- package/src/types.ts +11 -0
- package/src/url.test.ts +2 -2
- 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 +0 -15
- 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 +0 -4
- package/dist/types/src/resource.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/errors.ts +0 -138
|
@@ -1,70 +1,496 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
__export
|
|
4
|
+
} from "./chunk-HSLMI22Q.mjs";
|
|
2
5
|
|
|
3
|
-
// src/
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
45
|
}
|
|
13
|
-
|
|
14
|
-
|
|
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 "));
|
|
15
87
|
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
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
|
+
}
|
|
18
114
|
}
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
}
|
|
21
150
|
}
|
|
22
|
-
|
|
23
|
-
|
|
151
|
+
};
|
|
152
|
+
var throwCause = (cause) => {
|
|
153
|
+
throw causeToError(cause);
|
|
154
|
+
};
|
|
155
|
+
var unwrapExit = (exit2) => {
|
|
156
|
+
if (Exit.isSuccess(exit2)) {
|
|
157
|
+
return exit2.value;
|
|
24
158
|
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
})();
|
|
27
179
|
}
|
|
28
180
|
};
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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);
|
|
38
244
|
}
|
|
39
|
-
|
|
40
|
-
|
|
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);
|
|
41
253
|
}
|
|
42
|
-
|
|
43
|
-
|
|
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;
|
|
44
262
|
}
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
47
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
|
|
48
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
|
|
49
455
|
};
|
|
50
|
-
}
|
|
51
|
-
var
|
|
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
|
+
};
|
|
482
|
+
var VisitResult = /* @__PURE__ */ (function(VisitResult2) {
|
|
52
483
|
VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
|
|
53
484
|
VisitResult2[VisitResult2["SKIP"] = 1] = "SKIP";
|
|
54
485
|
VisitResult2[VisitResult2["EXIT"] = 2] = "EXIT";
|
|
55
486
|
return VisitResult2;
|
|
56
|
-
}({});
|
|
57
|
-
var defaultTest = isSimpleType;
|
|
487
|
+
})({});
|
|
58
488
|
var visit = (node, testOrVisitor, visitor) => {
|
|
59
|
-
|
|
60
|
-
visitNode(node, defaultTest, testOrVisitor);
|
|
61
|
-
} else {
|
|
62
|
-
visitNode(node, testOrVisitor, visitor);
|
|
63
|
-
}
|
|
489
|
+
visitNode(node, testOrVisitor, visitor);
|
|
64
490
|
};
|
|
65
491
|
var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
66
|
-
const
|
|
67
|
-
const result =
|
|
492
|
+
const $result = test?.(node, path, depth);
|
|
493
|
+
const result = $result === void 0 ? 0 : typeof $result === "boolean" ? $result ? 0 : 1 : $result;
|
|
68
494
|
if (result === 2) {
|
|
69
495
|
return result;
|
|
70
496
|
}
|
|
@@ -117,6 +543,12 @@ var findNode = (node, test) => {
|
|
|
117
543
|
return child;
|
|
118
544
|
}
|
|
119
545
|
}
|
|
546
|
+
for (const prop of getIndexSignatures(node)) {
|
|
547
|
+
const child = findNode(prop.type, test);
|
|
548
|
+
if (child) {
|
|
549
|
+
return child;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
120
552
|
} else if (SchemaAST.isTupleType(node)) {
|
|
121
553
|
for (const [_, element] of node.elements.entries()) {
|
|
122
554
|
const child = findNode(element.type, test);
|
|
@@ -125,12 +557,13 @@ var findNode = (node, test) => {
|
|
|
125
557
|
}
|
|
126
558
|
}
|
|
127
559
|
} else if (SchemaAST.isUnion(node)) {
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
560
|
+
if (isLiteralUnion(node)) {
|
|
561
|
+
return void 0;
|
|
562
|
+
}
|
|
563
|
+
for (const type of node.types) {
|
|
564
|
+
const child = findNode(type, test);
|
|
565
|
+
if (child) {
|
|
566
|
+
return child;
|
|
134
567
|
}
|
|
135
568
|
}
|
|
136
569
|
} else if (SchemaAST.isRefinement(node)) {
|
|
@@ -141,15 +574,7 @@ var findProperty = (schema, path) => {
|
|
|
141
574
|
const getProp = (node, path2) => {
|
|
142
575
|
const [name, ...rest] = path2;
|
|
143
576
|
const typeNode = findNode(node, SchemaAST.isTypeLiteral);
|
|
144
|
-
invariant(typeNode
|
|
145
|
-
F: __dxlog_file,
|
|
146
|
-
L: 247,
|
|
147
|
-
S: void 0,
|
|
148
|
-
A: [
|
|
149
|
-
"typeNode",
|
|
150
|
-
""
|
|
151
|
-
]
|
|
152
|
-
});
|
|
577
|
+
invariant(typeNode);
|
|
153
578
|
for (const prop of SchemaAST.getPropertySignatures(typeNode)) {
|
|
154
579
|
if (prop.name === name) {
|
|
155
580
|
if (rest.length) {
|
|
@@ -163,21 +588,21 @@ var findProperty = (schema, path) => {
|
|
|
163
588
|
return getProp(schema.ast, path.split("."));
|
|
164
589
|
};
|
|
165
590
|
var defaultAnnotations = {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
var
|
|
172
|
-
const id = pipe(SchemaAST.getIdentifierAnnotation(node),
|
|
173
|
-
const value = pipe(SchemaAST.getAnnotation(annotationId)(node),
|
|
591
|
+
ObjectKeyword: SchemaAST.objectKeyword,
|
|
592
|
+
StringKeyword: SchemaAST.stringKeyword,
|
|
593
|
+
NumberKeyword: SchemaAST.numberKeyword,
|
|
594
|
+
BooleanKeyword: SchemaAST.booleanKeyword
|
|
595
|
+
};
|
|
596
|
+
var getAnnotation2 = (annotationId, noDefault = true) => (node) => {
|
|
597
|
+
const id = Function.pipe(SchemaAST.getIdentifierAnnotation(node), Option3.getOrUndefined);
|
|
598
|
+
const value = Function.pipe(SchemaAST.getAnnotation(annotationId)(node), Option3.getOrUndefined);
|
|
174
599
|
if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
|
|
175
600
|
return void 0;
|
|
176
601
|
}
|
|
177
602
|
return value;
|
|
178
603
|
};
|
|
179
604
|
var findAnnotation = (node, annotationId, noDefault = true) => {
|
|
180
|
-
const getAnnotationById =
|
|
605
|
+
const getAnnotationById = getAnnotation2(annotationId, noDefault);
|
|
181
606
|
const getBaseAnnotation = (node2) => {
|
|
182
607
|
const value = getAnnotationById(node2);
|
|
183
608
|
if (value !== void 0) {
|
|
@@ -197,19 +622,26 @@ var isOption = (node) => {
|
|
|
197
622
|
var isLiteralUnion = (node) => {
|
|
198
623
|
return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);
|
|
199
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
|
+
};
|
|
200
640
|
var isDiscriminatedUnion = (node) => {
|
|
201
641
|
return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
202
642
|
};
|
|
203
643
|
var getDiscriminatingProps = (node) => {
|
|
204
|
-
invariant(SchemaAST.isUnion(node)
|
|
205
|
-
F: __dxlog_file,
|
|
206
|
-
L: 344,
|
|
207
|
-
S: void 0,
|
|
208
|
-
A: [
|
|
209
|
-
"SchemaAST.isUnion(node)",
|
|
210
|
-
""
|
|
211
|
-
]
|
|
212
|
-
});
|
|
644
|
+
invariant(SchemaAST.isUnion(node));
|
|
213
645
|
if (isOption(node)) {
|
|
214
646
|
return;
|
|
215
647
|
}
|
|
@@ -219,39 +651,15 @@ var getDiscriminatingProps = (node) => {
|
|
|
219
651
|
}, []);
|
|
220
652
|
};
|
|
221
653
|
var getDiscriminatedType = (node, value = {}) => {
|
|
222
|
-
invariant(SchemaAST.isUnion(node)
|
|
223
|
-
|
|
224
|
-
L: 368,
|
|
225
|
-
S: void 0,
|
|
226
|
-
A: [
|
|
227
|
-
"SchemaAST.isUnion(node)",
|
|
228
|
-
""
|
|
229
|
-
]
|
|
230
|
-
});
|
|
231
|
-
invariant(value, void 0, {
|
|
232
|
-
F: __dxlog_file,
|
|
233
|
-
L: 369,
|
|
234
|
-
S: void 0,
|
|
235
|
-
A: [
|
|
236
|
-
"value",
|
|
237
|
-
""
|
|
238
|
-
]
|
|
239
|
-
});
|
|
654
|
+
invariant(SchemaAST.isUnion(node));
|
|
655
|
+
invariant(value);
|
|
240
656
|
const props = getDiscriminatingProps(node);
|
|
241
657
|
if (!props?.length) {
|
|
242
658
|
return;
|
|
243
659
|
}
|
|
244
660
|
for (const type of node.types) {
|
|
245
661
|
const match = SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
246
|
-
invariant(SchemaAST.isLiteral(prop.type)
|
|
247
|
-
F: __dxlog_file,
|
|
248
|
-
L: 380,
|
|
249
|
-
S: void 0,
|
|
250
|
-
A: [
|
|
251
|
-
"SchemaAST.isLiteral(prop.type)",
|
|
252
|
-
""
|
|
253
|
-
]
|
|
254
|
-
});
|
|
662
|
+
invariant(SchemaAST.isLiteral(prop.type));
|
|
255
663
|
return prop.type.literal === value[prop.name.toString()];
|
|
256
664
|
});
|
|
257
665
|
if (match) {
|
|
@@ -261,15 +669,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
261
669
|
const fields = Object.fromEntries(props.map((prop) => {
|
|
262
670
|
const literals = node.types.map((type) => {
|
|
263
671
|
const literal = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
264
|
-
invariant(SchemaAST.isLiteral(literal.type)
|
|
265
|
-
F: __dxlog_file,
|
|
266
|
-
L: 398,
|
|
267
|
-
S: void 0,
|
|
268
|
-
A: [
|
|
269
|
-
"SchemaAST.isLiteral(literal.type)",
|
|
270
|
-
""
|
|
271
|
-
]
|
|
272
|
-
});
|
|
672
|
+
invariant(SchemaAST.isLiteral(literal.type));
|
|
273
673
|
return literal.type.literal;
|
|
274
674
|
}).filter(isNonNullable);
|
|
275
675
|
return literals.length ? [
|
|
@@ -280,10 +680,20 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
280
680
|
const schema = Schema.Struct(fields);
|
|
281
681
|
return schema.ast;
|
|
282
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
|
+
};
|
|
283
693
|
var mapAst = (ast, f) => {
|
|
284
694
|
switch (ast._tag) {
|
|
285
695
|
case "TypeLiteral": {
|
|
286
|
-
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);
|
|
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);
|
|
287
697
|
}
|
|
288
698
|
case "Union": {
|
|
289
699
|
return SchemaAST.Union.make(ast.types.map(f), ast.annotations);
|
|
@@ -300,16 +710,28 @@ var mapAst = (ast, f) => {
|
|
|
300
710
|
}
|
|
301
711
|
}
|
|
302
712
|
};
|
|
303
|
-
var
|
|
304
|
-
|
|
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 [];
|
|
305
727
|
};
|
|
306
|
-
var SimpleType;
|
|
307
728
|
|
|
308
|
-
// src/
|
|
309
|
-
import
|
|
729
|
+
// src/internal/json-path.ts
|
|
730
|
+
import * as Option4 from "effect/Option";
|
|
731
|
+
import * as Schema2 from "effect/Schema";
|
|
310
732
|
import { JSONPath } from "jsonpath-plus";
|
|
311
733
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
312
|
-
|
|
734
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
313
735
|
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
314
736
|
var PROP_REGEX = /^\w+$/;
|
|
315
737
|
var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
|
|
@@ -320,7 +742,7 @@ var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
|
|
|
320
742
|
message: () => "Property name must contain only letters, numbers, and underscores"
|
|
321
743
|
}));
|
|
322
744
|
var isJsonPath = (value) => {
|
|
323
|
-
return
|
|
745
|
+
return Option4.isSome(Schema2.validateOption(JsonPath)(value));
|
|
324
746
|
};
|
|
325
747
|
var createJsonPath = (path) => {
|
|
326
748
|
const candidatePath = path.map((p, i) => {
|
|
@@ -330,35 +752,22 @@ var createJsonPath = (path) => {
|
|
|
330
752
|
return i === 0 ? p : `.${p}`;
|
|
331
753
|
}
|
|
332
754
|
}).join("");
|
|
333
|
-
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}
|
|
334
|
-
F: __dxlog_file2,
|
|
335
|
-
L: 63,
|
|
336
|
-
S: void 0,
|
|
337
|
-
A: [
|
|
338
|
-
"isJsonPath(candidatePath)",
|
|
339
|
-
"`Invalid JsonPath: ${candidatePath}`"
|
|
340
|
-
]
|
|
341
|
-
});
|
|
755
|
+
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);
|
|
342
756
|
return candidatePath;
|
|
343
757
|
};
|
|
344
758
|
var fromEffectValidationPath = (effectPath) => {
|
|
345
759
|
const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
|
|
346
|
-
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}
|
|
347
|
-
F: __dxlog_file2,
|
|
348
|
-
L: 74,
|
|
349
|
-
S: void 0,
|
|
350
|
-
A: [
|
|
351
|
-
"isJsonPath(jsonPath)",
|
|
352
|
-
"`Invalid JsonPath: ${jsonPath}`"
|
|
353
|
-
]
|
|
354
|
-
});
|
|
760
|
+
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);
|
|
355
761
|
return jsonPath;
|
|
356
762
|
};
|
|
357
763
|
var splitJsonPath = (path) => {
|
|
358
764
|
if (!isJsonPath(path)) {
|
|
359
765
|
return [];
|
|
360
766
|
}
|
|
361
|
-
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
|
+
}) ?? [];
|
|
362
771
|
};
|
|
363
772
|
var getField = (object, path) => {
|
|
364
773
|
return JSONPath({
|
|
@@ -366,11 +775,19 @@ var getField = (object, path) => {
|
|
|
366
775
|
json: object
|
|
367
776
|
})[0];
|
|
368
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
|
+
};
|
|
369
784
|
|
|
370
|
-
// src/url.ts
|
|
371
|
-
import
|
|
785
|
+
// src/internal/url.ts
|
|
786
|
+
import * as Function2 from "effect/Function";
|
|
787
|
+
import * as Option5 from "effect/Option";
|
|
788
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
372
789
|
import { decamelize } from "@dxos/util";
|
|
373
|
-
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
790
|
+
var ParamKeyAnnotationId = /* @__PURE__ */ Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
374
791
|
var getParamKeyAnnotation = SchemaAST2.getAnnotation(ParamKeyAnnotationId);
|
|
375
792
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
376
793
|
[ParamKeyAnnotationId]: value
|
|
@@ -411,7 +828,7 @@ var UrlParser = class {
|
|
|
411
828
|
if (value !== void 0) {
|
|
412
829
|
const field = this._schema.fields[key];
|
|
413
830
|
if (field) {
|
|
414
|
-
const { key: serializedKey } =
|
|
831
|
+
const { key: serializedKey } = Function2.pipe(getParamKeyAnnotation(field.ast), Option5.getOrElse(() => ({
|
|
415
832
|
key: decamelize(key)
|
|
416
833
|
})));
|
|
417
834
|
url.searchParams.set(serializedKey, String(value));
|
|
@@ -421,190 +838,12 @@ var UrlParser = class {
|
|
|
421
838
|
return url;
|
|
422
839
|
}
|
|
423
840
|
};
|
|
424
|
-
|
|
425
|
-
// src/context.ts
|
|
426
|
-
import { Effect } from "effect";
|
|
427
|
-
import { Context } from "@dxos/context";
|
|
428
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/effect/src/context.ts";
|
|
429
|
-
var contextFromScope = () => Effect.gen(function* () {
|
|
430
|
-
const ctx = new Context(void 0, {
|
|
431
|
-
F: __dxlog_file3,
|
|
432
|
-
L: 12
|
|
433
|
-
});
|
|
434
|
-
yield* Effect.addFinalizer(() => Effect.promise(() => ctx.dispose()));
|
|
435
|
-
return ctx;
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
// src/errors.ts
|
|
439
|
-
import { Cause, Chunk, Effect as Effect2, Exit, GlobalValue, Option as Option4 } from "effect";
|
|
440
|
-
var spanSymbol = Symbol.for("effect/SpanAnnotation");
|
|
441
|
-
var originalSymbol = Symbol.for("effect/OriginalAnnotation");
|
|
442
|
-
var spanToTrace = GlobalValue.globalValue("effect/Tracer/spanToTrace", () => /* @__PURE__ */ new WeakMap());
|
|
443
|
-
var locationRegex = /\((.*)\)/g;
|
|
444
|
-
var prettyErrorStack = (error, appendStacks = []) => {
|
|
445
|
-
const span = error[spanSymbol];
|
|
446
|
-
const lines = typeof error.stack === "string" ? error.stack.split("\n") : [];
|
|
447
|
-
const out = [];
|
|
448
|
-
let atStack = false;
|
|
449
|
-
for (let i = 0; i < lines.length; i++) {
|
|
450
|
-
if (!atStack && !lines[i].startsWith(" at ")) {
|
|
451
|
-
out.push(lines[i]);
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
atStack = true;
|
|
455
|
-
if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
|
|
456
|
-
i++;
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
if (lines[i].includes("Generator.next")) {
|
|
460
|
-
break;
|
|
461
|
-
}
|
|
462
|
-
if (lines[i].includes("effect_internal_function")) {
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "<anonymous>").replace(/at Arguments\./, "at "));
|
|
466
|
-
}
|
|
467
|
-
if (span) {
|
|
468
|
-
let current = span;
|
|
469
|
-
let i = 0;
|
|
470
|
-
while (current && current._tag === "Span" && i < 10) {
|
|
471
|
-
const stackFn = spanToTrace.get(current);
|
|
472
|
-
if (typeof stackFn === "function") {
|
|
473
|
-
const stack = stackFn();
|
|
474
|
-
if (typeof stack === "string") {
|
|
475
|
-
const locationMatchAll = stack.matchAll(locationRegex);
|
|
476
|
-
let match = false;
|
|
477
|
-
for (const [, location] of locationMatchAll) {
|
|
478
|
-
match = true;
|
|
479
|
-
out.push(` at ${current.name} (${location})`);
|
|
480
|
-
}
|
|
481
|
-
if (!match) {
|
|
482
|
-
out.push(` at ${current.name} (${stack.replace(/^at /, "")})`);
|
|
483
|
-
}
|
|
484
|
-
} else {
|
|
485
|
-
out.push(` at ${current.name}`);
|
|
486
|
-
}
|
|
487
|
-
} else {
|
|
488
|
-
out.push(` at ${current.name}`);
|
|
489
|
-
}
|
|
490
|
-
current = Option4.getOrUndefined(current.parent);
|
|
491
|
-
i++;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
out.push(...appendStacks);
|
|
495
|
-
if (error[originalSymbol]) {
|
|
496
|
-
error = error[originalSymbol];
|
|
497
|
-
}
|
|
498
|
-
if (error.cause) {
|
|
499
|
-
error.cause = prettyErrorStack(error.cause);
|
|
500
|
-
}
|
|
501
|
-
Object.defineProperty(error, "stack", {
|
|
502
|
-
value: out.join("\n"),
|
|
503
|
-
writable: true,
|
|
504
|
-
enumerable: false,
|
|
505
|
-
configurable: true
|
|
506
|
-
});
|
|
507
|
-
return error;
|
|
508
|
-
};
|
|
509
|
-
var runAndForwardErrors = async (effect, options) => {
|
|
510
|
-
const exit = await Effect2.runPromiseExit(effect, options);
|
|
511
|
-
if (Exit.isSuccess(exit)) {
|
|
512
|
-
return exit.value;
|
|
513
|
-
}
|
|
514
|
-
if (Cause.isEmpty(exit.cause)) {
|
|
515
|
-
throw new Error("Fiber failed without a cause");
|
|
516
|
-
} else if (Cause.isInterrupted(exit.cause)) {
|
|
517
|
-
throw new Error("Fiber was interrupted");
|
|
518
|
-
} else {
|
|
519
|
-
const errors = [
|
|
520
|
-
...Chunk.toArray(Cause.failures(exit.cause)),
|
|
521
|
-
...Chunk.toArray(Cause.defects(exit.cause))
|
|
522
|
-
];
|
|
523
|
-
const getStackFrames = () => {
|
|
524
|
-
const o = {};
|
|
525
|
-
Error.captureStackTrace(o, getStackFrames);
|
|
526
|
-
return o.stack.split("\n").slice(1);
|
|
527
|
-
};
|
|
528
|
-
const stackFrames = getStackFrames();
|
|
529
|
-
const newErrors = errors.map((error) => prettyErrorStack(error, stackFrames));
|
|
530
|
-
if (newErrors.length === 1) {
|
|
531
|
-
throw newErrors[0];
|
|
532
|
-
} else {
|
|
533
|
-
throw new AggregateError(newErrors);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
// src/testing.ts
|
|
539
|
-
import { Effect as Effect3 } from "effect";
|
|
540
|
-
(function(TestHelpers2) {
|
|
541
|
-
TestHelpers2.runIf = (condition) => (effect, ctx) => Effect3.gen(function* () {
|
|
542
|
-
if (!condition) {
|
|
543
|
-
ctx.skip();
|
|
544
|
-
} else {
|
|
545
|
-
return yield* effect;
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
TestHelpers2.skipIf = (condition) => (effect, ctx) => Effect3.gen(function* () {
|
|
549
|
-
if (condition) {
|
|
550
|
-
ctx.skip();
|
|
551
|
-
} else {
|
|
552
|
-
return yield* effect;
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
TestHelpers2.taggedTest = (tag) => (effect, ctx) => Effect3.gen(function* () {
|
|
556
|
-
if (!process.env.DX_TEST_TAGS?.includes(tag)) {
|
|
557
|
-
ctx.skip();
|
|
558
|
-
} else {
|
|
559
|
-
return yield* effect;
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
})(TestHelpers || (TestHelpers = {}));
|
|
563
|
-
var TestHelpers;
|
|
564
|
-
|
|
565
|
-
// src/resource.ts
|
|
566
|
-
import { Effect as Effect4 } from "effect";
|
|
567
|
-
var accuireReleaseResource = (getResource) => Effect4.acquireRelease(Effect4.gen(function* () {
|
|
568
|
-
const resource = getResource();
|
|
569
|
-
yield* Effect4.promise(async () => {
|
|
570
|
-
resource.open?.();
|
|
571
|
-
return void 0;
|
|
572
|
-
});
|
|
573
|
-
return resource;
|
|
574
|
-
}), (resource) => Effect4.promise(async () => {
|
|
575
|
-
resource.close?.();
|
|
576
|
-
return void 0;
|
|
577
|
-
}));
|
|
578
841
|
export {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
VisitResult,
|
|
586
|
-
accuireReleaseResource,
|
|
587
|
-
contextFromScope,
|
|
588
|
-
createJsonPath,
|
|
589
|
-
findAnnotation,
|
|
590
|
-
findNode,
|
|
591
|
-
findProperty,
|
|
592
|
-
fromEffectValidationPath,
|
|
593
|
-
getAnnotation,
|
|
594
|
-
getDiscriminatedType,
|
|
595
|
-
getDiscriminatingProps,
|
|
596
|
-
getField,
|
|
597
|
-
getParamKeyAnnotation,
|
|
598
|
-
getSimpleType,
|
|
599
|
-
isArrayType,
|
|
600
|
-
isDiscriminatedUnion,
|
|
601
|
-
isJsonPath,
|
|
602
|
-
isLiteralUnion,
|
|
603
|
-
isOption,
|
|
604
|
-
isSimpleType,
|
|
605
|
-
mapAst,
|
|
606
|
-
runAndForwardErrors,
|
|
607
|
-
splitJsonPath,
|
|
608
|
-
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
|
|
609
848
|
};
|
|
610
849
|
//# sourceMappingURL=index.mjs.map
|