world-process.ts
This file
Path
apps/platform/test/world-process.ts
50 lines · 1.2 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
lines 1–2why, one step back1// Imports no Worker module, so a world process may import it statically and load2// the rest after `shimWorkers` has run.Read the admission test's visibility config through the rules, share the world processes' shim, and load the forwarding routes with their test fileoscabrielbefore adoptiondb2452e
lines 3–50why, one step back3import { Config, Effect, Schema } from "effect";45import * as shim from "./workers-shim.ts";67interface BunPlugins {8 readonly plugin: (plugin: {9 readonly name: string;10 readonly setup: (build: {11 readonly module: (12 specifier: string,13 load: () => {14 readonly exports: typeof shim;15 readonly loader: "object";16 }17 ) => void;18 }) => void;19 }) => void;20}2122declare const Bun: BunPlugins;2324export const shimWorkers = Effect.sync(() => {25 Bun.plugin({26 name: "cloudflare-workers-shim",27 setup: (build) => {28 build.module("cloudflare:workers", () => ({29 exports: { ...shim },30 loader: "object",31 }));32 },33 });34});3536const decodeSessions = Schema.decodeUnknownEffect(37 Schema.fromJsonString(Schema.Record(Schema.String, Schema.String))38);3940export const worldSessions = Effect.gen(function* () {41 const raw = yield* Config.String("WORLD_SESSIONS").pipe(42 Config.withDefault("{}")43 );4445 return yield* decodeSessions(raw).pipe(46 Effect.catch(() =>47 Effect.die("WORLD_SESSIONS is not a JSON object from token to handle")48 )49 );50});