Repository navigation
Expand file tree
/
Copy pathstorage.ts
More file actions
48 lines (47 loc) · 1.8 KB
/
Copy pathstorage.ts
File metadata and controls
48 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/** Caller-owned Effect SQL driver and one reactive storage handle shared by SDK clients. */
import { makeExecutorStorage, AppRequirements, StoredApp, StoredVersion } from "@executor-js/sdk";
import { pgliteLayer } from "fumadb-effect/pglite";
import { Effect, Schema } from "effect";
/** Initialize SQLite, commit an app, and close the driver with the enclosing scope. */
export const storageWalkthrough = () =>
Effect.runPromise(
Effect.scoped(
Effect.gen(function* () {
const storage = yield* makeExecutorStorage({ provider: "postgresql" });
yield* storage.migrate;
const orm = storage.orm("4.0.16");
const createdAt = new Date("2026-01-01T00:00:00.000Z");
const version = yield* Schema.decodeUnknownEffect(StoredVersion)({
id: "dpl_example",
code: "code_example",
owner: "example-publisher",
sourceCommit: "a".repeat(40),
fileCount: 1,
build: "bld_example",
requirements: { accounts: {} },
createdAt,
});
const app = yield* Schema.decodeUnknownEffect(StoredApp)({
id: "app_example",
code: version.code,
owner: "example-user",
name: "Example",
activeVersion: version.id,
accounts: {},
createdAt,
});
yield* orm.transaction(
Effect.gen(function* () {
yield* orm.create("deployments", {
...version,
requirements: yield* Schema.encodeEffect(Schema.toCodecJson(AppRequirements))(
version.requirements,
),
});
yield* orm.create("apps", app);
}),
);
return yield* orm.findFirst("apps", { where: (b) => b("id", "=", app.id) });
}).pipe(Effect.provide(pgliteLayer())),
),
);