Skip to content

Commit ca5cb66

Browse files
committed
Revert "Use raw schema compiler previews"
This reverts commit 1b69bc7.
1 parent 1b69bc7 commit ca5cb66

4 files changed

Lines changed: 717 additions & 279 deletions

File tree

packages/core/sdk/src/executor.test.ts

Lines changed: 67 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ const txPlugin = definePlugin(() => ({
3737
schema: txSchema,
3838
storage: ({ fuma }) => ({
3939
create: (row: TxItemRow) =>
40-
fuma
41-
.use("tx.item.create", (db) => db.create("executor_tx_item", row))
42-
.pipe(Effect.asVoid),
40+
fuma.use("tx.item.create", (db) => db.create("executor_tx_item", row)).pipe(Effect.asVoid),
4341
list: () =>
4442
fuma.use("tx.item.list", (db) =>
4543
db.findMany("executor_tx_item", {
@@ -74,30 +72,18 @@ const txPlugin = definePlugin(() => ({
7472
catchDuplicateCreate: () =>
7573
Effect.gen(function* () {
7674
const scope = String(ctx.scopes[0]!.id);
77-
yield* ctx.storage.create({
78-
id: "dup",
79-
scope_id: scope,
80-
value: "first",
81-
});
82-
return yield* ctx.storage
83-
.create({ id: "dup", scope_id: scope, value: "second" })
84-
.pipe(
85-
Effect.as({ caught: false as const, model: null as string | null }),
86-
Effect.catchTag("UniqueViolationError", (error) =>
87-
Effect.succeed({
88-
caught: true as const,
89-
model: error.model ?? null,
90-
}),
91-
),
92-
);
75+
yield* ctx.storage.create({ id: "dup", scope_id: scope, value: "first" });
76+
return yield* ctx.storage.create({ id: "dup", scope_id: scope, value: "second" }).pipe(
77+
Effect.as({ caught: false as const, model: null as string | null }),
78+
Effect.catchTag("UniqueViolationError", (error) =>
79+
Effect.succeed({ caught: true as const, model: error.model ?? null }),
80+
),
81+
);
9382
}),
9483
}),
9584
}))();
9685

97-
const detector = (
98-
id: string,
99-
confidence: SourceDetectionResult["confidence"],
100-
) =>
86+
const detector = (id: string, confidence: SourceDetectionResult["confidence"]) =>
10187
definePlugin(() => ({
10288
id,
10389
storage: () => ({}),
@@ -186,33 +172,22 @@ const schemaProbePlugin = definePlugin(() => ({
186172
}))();
187173

188174
describe("createExecutor", () => {
189-
it.effect(
190-
"rolls back plugin and core writes from ctx.transaction failures",
191-
() =>
192-
Effect.gen(function* () {
193-
const executor = yield* makeTestExecutor({
194-
plugins: [txPlugin] as const,
195-
});
175+
it.effect("rolls back plugin and core writes from ctx.transaction failures", () =>
176+
Effect.gen(function* () {
177+
const executor = yield* makeTestExecutor({ plugins: [txPlugin] as const });
196178

197-
const error = yield* executor.tx
198-
.failAfterPluginAndCoreWrites()
199-
.pipe(Effect.flip);
179+
const error = yield* executor.tx.failAfterPluginAndCoreWrites().pipe(Effect.flip);
200180

201-
expect(error).toMatchObject({
202-
_tag: "TestPluginError",
203-
message: "rollback",
204-
});
205-
expect(yield* executor.tx.list()).toEqual([]);
206-
expect(yield* executor.sources.list()).toEqual([]);
207-
expect(yield* executor.tools.list()).toEqual([]);
208-
}),
181+
expect(error).toMatchObject({ _tag: "TestPluginError", message: "rollback" });
182+
expect(yield* executor.tx.list()).toEqual([]);
183+
expect(yield* executor.sources.list()).toEqual([]);
184+
expect(yield* executor.tools.list()).toEqual([]);
185+
}),
209186
);
210187

211188
it.effect("keeps FumaDB unique violations catchable inside plugin code", () =>
212189
Effect.gen(function* () {
213-
const executor = yield* makeTestExecutor({
214-
plugins: [txPlugin] as const,
215-
});
190+
const executor = yield* makeTestExecutor({ plugins: [txPlugin] as const });
216191

217192
const result = yield* executor.tx.catchDuplicateCreate();
218193

@@ -254,71 +229,57 @@ describe("createExecutor", () => {
254229
}),
255230
);
256231

257-
it.effect(
258-
"orders source detection results by confidence and applies configured bounds",
259-
() =>
260-
Effect.gen(function* () {
261-
const executor = yield* createExecutor({
262-
...makeTestConfig({
263-
plugins: [
264-
detector("low", "low"),
265-
detector("high", "high"),
266-
detector("medium", "medium"),
267-
],
268-
}),
269-
sourceDetection: { maxDetectors: 2, maxResults: 1 },
270-
onElicitation: "accept-all",
271-
});
232+
it.effect("orders source detection results by confidence and applies configured bounds", () =>
233+
Effect.gen(function* () {
234+
const executor = yield* createExecutor({
235+
...makeTestConfig({
236+
plugins: [detector("low", "low"), detector("high", "high"), detector("medium", "medium")],
237+
}),
238+
sourceDetection: { maxDetectors: 2, maxResults: 1 },
239+
onElicitation: "accept-all",
240+
});
272241

273-
const results = yield* executor.sources.detect(
274-
"https://example.com/source",
275-
);
242+
const results = yield* executor.sources.detect("https://example.com/source");
276243

277-
expect(results.map((result) => result.kind)).toEqual(["high"]);
278-
}),
244+
expect(results.map((result) => result.kind)).toEqual(["high"]);
245+
}),
279246
);
280247

281-
it.effect(
282-
"applies hosted outbound policy before source detection plugins run",
283-
() =>
284-
Effect.gen(function* () {
285-
let called = false;
286-
const hostedDetector = definePlugin(() => ({
287-
id: "hosted-detector" as const,
288-
storage: () => ({}),
289-
detect: () =>
290-
Effect.sync(() => {
291-
called = true;
292-
return SourceDetectionResult.make({
293-
kind: "hosted-detector",
294-
confidence: "high",
295-
endpoint: "http://127.0.0.1/source",
296-
name: "hosted detector",
297-
namespace: "hosted_detector",
298-
});
299-
}),
300-
}));
301-
const executor = yield* createExecutor({
302-
scopes: [testScope],
303-
plugins: [hostedDetector()] as const,
304-
httpClientLayer: FetchHttpClient.layer,
305-
onElicitation: "accept-all",
306-
});
248+
it.effect("applies hosted outbound policy before source detection plugins run", () =>
249+
Effect.gen(function* () {
250+
let called = false;
251+
const hostedDetector = definePlugin(() => ({
252+
id: "hosted-detector" as const,
253+
storage: () => ({}),
254+
detect: () =>
255+
Effect.sync(() => {
256+
called = true;
257+
return SourceDetectionResult.make({
258+
kind: "hosted-detector",
259+
confidence: "high",
260+
endpoint: "http://127.0.0.1/source",
261+
name: "hosted detector",
262+
namespace: "hosted_detector",
263+
});
264+
}),
265+
}));
266+
const executor = yield* createExecutor({
267+
scopes: [testScope],
268+
plugins: [hostedDetector()] as const,
269+
httpClientLayer: FetchHttpClient.layer,
270+
onElicitation: "accept-all",
271+
});
307272

308-
const results = yield* executor.sources.detect(
309-
"http://127.0.0.1/source",
310-
);
273+
const results = yield* executor.sources.detect("http://127.0.0.1/source");
311274

312-
expect(results).toEqual([]);
313-
expect(called).toBe(false);
314-
}),
275+
expect(results).toEqual([]);
276+
expect(called).toBe(false);
277+
}),
315278
);
316279

317280
it.effect("returns schema roots with shared reachable definitions", () =>
318281
Effect.gen(function* () {
319-
const executor = yield* makeTestExecutor({
320-
plugins: [schemaProbePlugin] as const,
321-
});
282+
const executor = yield* makeTestExecutor({ plugins: [schemaProbePlugin] as const });
322283

323284
yield* executor.schemaProbe.registerSource();
324285

@@ -341,9 +302,13 @@ describe("createExecutor", () => {
341302
});
342303
expect(schema?.schemaDefinitions).not.toHaveProperty("Unused");
343304
expect(schema?.inputTypeScript).toContain("pet: Pet");
344-
expect(schema?.outputTypeScript).toContain("__root: Owner");
345-
expect(schema?.outputTypeScript).toContain("export interface Owner");
346-
expect(schema?.typeScriptDefinitions).toBeUndefined();
305+
expect(schema?.outputTypeScript).toBe("Owner");
306+
expect(schema?.typeScriptDefinitions).toEqual(
307+
expect.objectContaining({
308+
Pet: expect.any(String),
309+
Owner: expect.any(String),
310+
}),
311+
);
347312
}),
348313
);
349314
});

0 commit comments

Comments
 (0)