UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 6.31 kB
{"version":3,"file":"flow.mjs","names":[],"sources":["../../../src/services/dev/flow.ts"],"sourcesContent":["import process from \"node:process\";\nimport { Context, Effect, Layer, References } from \"effect\";\nimport { MISSING_CONFIG_MESSAGE } from \"../../config\";\nimport type { DevOptions, DevResult, PhaseTiming, StartOptions, StartResult } from \"../../contract\";\nimport { ProjectEnvLive } from \"../../env/project-env\";\nimport { PortAllocatorLive } from \"../../infra/ports\";\nimport { openResolution, type ResolutionSession } from \"../resolution/session\";\nimport { startBootstrap } from \"../start/boot\";\nimport { devBootstrap } from \"./boot\";\nimport { type LogLevelEnv, resolveLogLevel, toEffectLogLevel } from \"./logs\";\n\nconst bootstrapLayers = Layer.mergeAll(ProjectEnvLive, PortAllocatorLive);\n\nexport class DevFlowService extends Context.Service<\n DevFlowService,\n {\n dev: (\n session: ResolutionSession | null,\n input: DevOptions,\n ) => Effect.Effect<DevResult, unknown>;\n start: (\n session: ResolutionSession | null,\n input: StartOptions,\n ) => Effect.Effect<StartResult, unknown>;\n }\n>()(\"bos/DevFlowService\") {\n static Live = Layer.succeed(\n DevFlowService,\n DevFlowService.of({\n dev: (session, input) =>\n Effect.gen(function* () {\n const devTimings: PhaseTiming[] = [];\n\n const outcome = yield* devBootstrap({ session }, input, devTimings).pipe(\n Effect.provideService(\n References.MinimumLogLevel,\n toEffectLogLevel(resolveLogLevel(process.env as LogLevelEnv, input.logLevel)),\n ),\n Effect.provide(bootstrapLayers),\n Effect.catchTags({\n DevConfigMissing: () => Effect.succeed({ failed: MISSING_CONFIG_MESSAGE }),\n DevProxyMissing: () =>\n Effect.succeed({\n failed: \"No valid proxy URL configured in the authored config\",\n }),\n DevPreflightFailed: (error) =>\n Effect.succeed({ failed: `Infra preflight failed: ${error.messages.join(\"; \")}` }),\n }),\n );\n\n if (\"failed\" in outcome) {\n return {\n status: \"error\" as const,\n description: outcome.failed,\n processes: [],\n timings: devTimings,\n };\n }\n\n return {\n status: \"started\" as const,\n description: outcome.description,\n processes: outcome.processes,\n timings: devTimings,\n session: outcome.session,\n };\n }),\n\n start: (session, input) =>\n Effect.gen(function* () {\n let activeSession = session;\n if (input.configPath) {\n const override = yield* Effect.promise(() =>\n openResolution({ path: input.configPath }),\n );\n if (!override) {\n return {\n status: \"error\" as const,\n url: \"\",\n error: `No config found at ${input.configPath}`,\n };\n }\n activeSession = override;\n }\n\n const outcome = yield* startBootstrap({ session: activeSession }, input).pipe(\n Effect.provide(bootstrapLayers),\n Effect.catchTags({\n StartRemoteConfigMissing: (error) => Effect.succeed({ failed: error.message }),\n StartFetchFailed: (error) => Effect.succeed({ failed: error.message }),\n StartConfigMissing: () =>\n Effect.succeed({\n failed:\n \"No configuration found. Provide --account and --gateway flags, or create a local authored config (bos.app.ts or bos.config.json).\",\n }),\n InfraError: (error) => Effect.succeed({ failed: `${error.phase}: ${error.message}` }),\n DevStepError: (error) =>\n Effect.succeed({\n failed: `${error.phase} failed: ${\n error.cause instanceof Error ? error.cause.message : String(error.cause)\n }`,\n }),\n }),\n );\n\n if (\"failed\" in outcome) {\n return {\n status: \"error\" as const,\n url: \"\",\n error: outcome.failed,\n };\n }\n\n return {\n status: \"running\" as const,\n url: outcome.url,\n session: outcome.session,\n summary: outcome.summary,\n };\n }),\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,kBAAkB,MAAM,SAAS,gBAAgB,iBAAiB;AAExE,IAAa,iBAAb,MAAa,uBAAuB,QAAQ,QAY1C,CAAC,CAAC,oBAAoB,CAAC,CAAC;CACxB,OAAO,OAAO,MAAM,QAClB,gBACA,eAAe,GAAG;EAChB,MAAM,SAAS,UACb,OAAO,IAAI,aAAa;GACtB,MAAM,aAA4B,CAAC;GAEnC,MAAM,UAAU,OAAO,aAAa,EAAE,QAAQ,GAAG,OAAO,UAAU,CAAC,CAAC,KAClE,OAAO,eACL,WAAW,iBACX,iBAAiB,gBAAgB,QAAQ,KAA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