ff-serv 0.1.3 → 0.1.4

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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/exports/orpc.ts
@@ -25,11 +35,229 @@ __export(orpc_exports, {
25
35
  module.exports = __toCommonJS(orpc_exports);
26
36
 
27
37
  // src/http/orpc.ts
28
- function oRPCHandler(handler, ...rest) {
29
- return {
30
- _tag: "oRPCHandler",
31
- handle: async ({ request }) => handler.handle(request, ...rest)
32
- };
38
+ var import_effect3 = require("effect");
39
+
40
+ // src/http/fetch-handler.ts
41
+ var import_effect2 = require("effect");
42
+ var import_nanoid = require("nanoid");
43
+
44
+ // src/logger.ts
45
+ var import_effect = require("effect");
46
+ var import_pino = __toESM(require("pino"), 1);
47
+ var LoggerType;
48
+ ((LoggerType2) => {
49
+ function fromPino(x) {
50
+ return {
51
+ info: x.info.bind(x),
52
+ error: x.error.bind(x),
53
+ warn: x.warn.bind(x),
54
+ debug: x.debug.bind(x),
55
+ child: (...params) => {
56
+ return fromPino(
57
+ x.child(...params)
58
+ );
59
+ },
60
+ flush: x.flush.bind(x),
61
+ _pino: x
62
+ };
63
+ }
64
+ LoggerType2.fromPino = fromPino;
65
+ function create(params) {
66
+ const logger = (0, import_pino.default)(
67
+ {
68
+ level: "trace",
69
+ // Level is managed by Effect, so we set the lowest here
70
+ serializers: {
71
+ error: import_pino.default.stdSerializers.errWithCause,
72
+ err: import_pino.default.stdSerializers.errWithCause
73
+ },
74
+ formatters: {
75
+ level: (label) => {
76
+ return { level: label };
77
+ }
78
+ }
79
+ },
80
+ params?.stream
81
+ );
82
+ return fromPino(logger);
83
+ }
84
+ LoggerType2.create = create;
85
+ function is(x) {
86
+ return "_pino" in x;
87
+ }
88
+ LoggerType2.is = is;
89
+ })(LoggerType || (LoggerType = {}));
90
+ var createInstance = (params) => import_effect.Effect.gen(function* () {
91
+ const isDev = import_effect.Option.getOrNull(
92
+ yield* import_effect.Config.boolean("DEV").pipe(import_effect.Config.option)
93
+ );
94
+ const logFile = import_effect.Option.getOrNull(
95
+ yield* import_effect.Config.boolean("LOGGER_LOGFILE").pipe(import_effect.Config.option)
96
+ );
97
+ return LoggerType.create({
98
+ ...params,
99
+ ...isDev && {
100
+ stream: logFile ? import_pino.default.transport({
101
+ target: "pino/file",
102
+ options: {
103
+ destination: "./logs/server.log",
104
+ mkdir: true
105
+ }
106
+ }) : import_pino.default.transport({
107
+ target: "pino-pretty",
108
+ options: {
109
+ ignore: "pid,hostname"
110
+ }
111
+ })
112
+ }
113
+ });
114
+ });
115
+ function extractParams(...[obj, msg]) {
116
+ if (typeof obj === "string") {
117
+ return { message: obj };
118
+ }
119
+ return { message: msg, attributes: obj };
120
+ }
121
+ function callPino({
122
+ annotations,
123
+ message
124
+ }, call) {
125
+ const entries = import_effect.HashMap.toEntries(annotations);
126
+ if (entries.length > 0) {
127
+ return call(Object.fromEntries(entries), String(message));
128
+ }
129
+ return call(String(message));
130
+ }
131
+ var PinoCtx;
132
+ ((PinoCtx2) => {
133
+ const tag = "ff-serv/Pino";
134
+ function is(obj) {
135
+ return typeof obj === "object" && obj != null && "_tag" in obj && obj._tag === tag;
136
+ }
137
+ PinoCtx2.is = is;
138
+ function create(pino2) {
139
+ return {
140
+ _tag: tag,
141
+ pino: pino2,
142
+ effectLogger: import_effect.Logger.make(({ logLevel, ...input }) => {
143
+ switch (logLevel) {
144
+ case import_effect.LogLevel.Info:
145
+ return callPino(input, pino2.info);
146
+ case import_effect.LogLevel.Debug:
147
+ return callPino(input, pino2.debug);
148
+ case import_effect.LogLevel.Warning:
149
+ return callPino(input, pino2.warn);
150
+ case import_effect.LogLevel.Error:
151
+ case import_effect.LogLevel.Fatal:
152
+ return callPino(input, pino2.error);
153
+ default:
154
+ return callPino(input, pino2.info);
155
+ }
156
+ })
157
+ };
158
+ }
159
+ PinoCtx2.create = create;
160
+ })(PinoCtx || (PinoCtx = {}));
161
+ var Pino = class extends import_effect.Context.Tag("ff-serv/Pino")() {
162
+ };
163
+ var Logger;
164
+ ((Logger2) => {
165
+ Logger2.layer = (opts) => import_effect.Logger.replaceEffect(
166
+ import_effect.Logger.defaultLogger,
167
+ import_effect.Effect.gen(function* () {
168
+ return (yield* Pino).effectLogger;
169
+ })
170
+ ).pipe(
171
+ import_effect.Layer.provideMerge(
172
+ import_effect.Layer.effect(
173
+ Pino,
174
+ import_effect.Effect.gen(function* () {
175
+ return PinoCtx.create(yield* createInstance(opts));
176
+ })
177
+ )
178
+ )
179
+ );
180
+ Logger2.sync = () => import_effect.Effect.gen(function* () {
181
+ const pino2 = yield* Pino;
182
+ const runtime = import_effect.ManagedRuntime.make(
183
+ import_effect.Logger.replace(import_effect.Logger.defaultLogger, pino2.effectLogger)
184
+ );
185
+ return {
186
+ info: (...params) => Logger2.info(...params).pipe((e) => runtime.runSync(e)),
187
+ debug: (...params) => Logger2.debug(...params).pipe((e) => runtime.runSync(e)),
188
+ warn: (...params) => Logger2.warn(...params).pipe((e) => runtime.runSync(e)),
189
+ error: (...params) => Logger2.error(...params).pipe((e) => runtime.runSync(e))
190
+ };
191
+ });
192
+ Logger2.get = () => Logger2.sync();
193
+ Logger2.replace = (logger) => (e) => import_effect.Effect.gen(function* () {
194
+ const oldPinoCtx = yield* Pino;
195
+ const pino2 = LoggerType.is(logger) ? logger : LoggerType.fromPino(logger);
196
+ const pinoCtx = PinoCtx.create(pino2);
197
+ return yield* import_effect.Effect.provide(
198
+ e,
199
+ import_effect.Layer.mergeAll(
200
+ import_effect.Logger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger),
201
+ import_effect.Layer.succeed(Pino, pinoCtx)
202
+ )
203
+ );
204
+ });
205
+ Logger2.replaceChild = (...params) => (e) => import_effect.Effect.gen(function* () {
206
+ const oldPinoCtx = yield* Pino;
207
+ const pino2 = oldPinoCtx.pino.child(...params);
208
+ const pinoCtx = PinoCtx.create(pino2);
209
+ return yield* import_effect.Effect.provide(
210
+ import_effect.Effect.provide(
211
+ e,
212
+ import_effect.Logger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger)
213
+ ),
214
+ import_effect.Layer.succeed(Pino, pinoCtx)
215
+ );
216
+ });
217
+ Logger2.info = (...params) => import_effect.Effect.gen(function* () {
218
+ const { message, attributes } = extractParams(...params);
219
+ yield* import_effect.Effect.logInfo(message).pipe(
220
+ attributes ? import_effect.Effect.annotateLogs(attributes) : (e) => e
221
+ );
222
+ });
223
+ Logger2.debug = (...params) => import_effect.Effect.gen(function* () {
224
+ const { message, attributes } = extractParams(...params);
225
+ yield* import_effect.Effect.logDebug(message).pipe(
226
+ attributes ? import_effect.Effect.annotateLogs(attributes) : (e) => e
227
+ );
228
+ });
229
+ Logger2.warn = (...params) => import_effect.Effect.gen(function* () {
230
+ const { message, attributes } = extractParams(...params);
231
+ yield* import_effect.Effect.logWarning(message).pipe(
232
+ attributes ? import_effect.Effect.annotateLogs(attributes) : (e) => e
233
+ );
234
+ });
235
+ Logger2.error = (...params) => import_effect.Effect.gen(function* () {
236
+ const { message, attributes } = extractParams(...params);
237
+ yield* import_effect.Effect.logError(message).pipe(
238
+ attributes ? import_effect.Effect.annotateLogs(attributes) : (e) => e
239
+ );
240
+ });
241
+ Logger2.flush = (..._params) => import_effect.Effect.void;
242
+ })(Logger || (Logger = {}));
243
+
244
+ // src/http/fetch-handler.ts
245
+ var Handler = class {
246
+ constructor(_tag, handle) {
247
+ this._tag = _tag;
248
+ this.handle = handle;
249
+ }
250
+ };
251
+
252
+ // src/http/orpc.ts
253
+ function oRPCHandler(handler, opt) {
254
+ return new Handler(
255
+ "oRPCHandler",
256
+ ({ request }) => import_effect3.Effect.gen(function* () {
257
+ const _opt = opt ? [import_effect3.Effect.isEffect(opt) ? yield* opt : opt] : [];
258
+ return yield* import_effect3.Effect.tryPromise(() => handler.handle(request, ..._opt));
259
+ })
260
+ );
33
261
  }
34
262
  // Annotate the CommonJS export names for ESM import in node:
35
263
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/orpc.ts","../../src/http/orpc.ts"],"sourcesContent":["export { oRPCHandler } from '../http/orpc.js';","import type { Context } from '@orpc/server';\nimport type { FetchHandler } from '@orpc/server/fetch';\nimport type { FriendlyStandardHandleOptions } from '@orpc/server/standard';\nimport type { Handler } from './fetch-handler.js';\n\ntype MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions\n\t? [options?: TOptions]\n\t: [options: TOptions];\n\nexport function oRPCHandler<T extends Context>(\n\thandler: FetchHandler<T>,\n\t...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>\n): Handler<'oRPCHandler'> {\n\treturn {\n\t\t_tag: 'oRPCHandler',\n\t\thandle: async ({ request }) => handler.handle(request, ...rest),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,YACf,YACG,MACsB;AACzB,SAAO;AAAA,IACN,MAAM;AAAA,IACN,QAAQ,OAAO,EAAE,QAAQ,MAAM,QAAQ,OAAO,SAAS,GAAG,IAAI;AAAA,EAC/D;AACD;","names":[]}
1
+ {"version":3,"sources":["../../src/exports/orpc.ts","../../src/http/orpc.ts","../../src/http/fetch-handler.ts","../../src/logger.ts"],"sourcesContent":["export { oRPCHandler } from '../http/orpc.js';","import type { Context } from '@orpc/server';\nimport type { FetchHandler } from '@orpc/server/fetch';\nimport type { FriendlyStandardHandleOptions } from '@orpc/server/standard';\nimport { Effect } from 'effect';\nimport { Handler } from './fetch-handler.js';\n\ntype MaybeOptionalOptions<TOptions> =\n\tRecord<never, never> extends TOptions\n\t\t? [options?: TOptions]\n\t\t: [options: TOptions];\n\nexport function oRPCHandler<T extends Context, E, R>(\n\thandler: FetchHandler<T>,\n\topt?:\n\t\t| FriendlyStandardHandleOptions<T>\n\t\t| Effect.Effect<FriendlyStandardHandleOptions<T>, E, R>,\n) {\n\treturn new Handler('oRPCHandler', ({ request }) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst _opt = (\n\t\t\t\topt ? [Effect.isEffect(opt) ? yield* opt : opt] : []\n\t\t\t) as MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>;\n\t\t\treturn yield* Effect.tryPromise(() => handler.handle(request, ..._opt));\n\t\t}),\n\t);\n}\n","import { Effect, FiberSet } from 'effect';\nimport type { Cause } from 'effect/Cause';\nimport { nanoid } from 'nanoid';\nimport { Logger } from '../logger.js';\n\n// #region Handler\n\nexport type AnyResponse = Response | Promise<Response>;\n\nexport type HandlerResult =\n\t| {\n\t\t\tmatched: true;\n\t\t\tresponse: AnyResponse;\n\t }\n\t| {\n\t\t\tmatched: false;\n\t\t\tresponse: undefined;\n\t };\n\nexport class Handler<NAME extends string, R> {\n\tconstructor(\n\t\treadonly _tag: NAME,\n\t\treadonly handle: (opt: {\n\t\t\turl: URL;\n\t\t\trequest: Request;\n\t\t}) => Effect.Effect<HandlerResult, unknown, R>,\n\t) {}\n}\n\n// #endregion\n\ntype ExtractRequirements<T> = T extends Handler<string, infer R> ? R : never;\n\nexport const createFetchHandler = <\n\tconst HANDLERS extends [\n\t\tHandler<string, unknown>,\n\t\t...Array<Handler<string, unknown>>,\n\t],\n\tR = ExtractRequirements<HANDLERS[number]>,\n>(\n\thandlers: HANDLERS,\n\topts?: {\n\t\tdebug?: boolean;\n\t\tonError?: (ctx: {\n\t\t\terror: Cause<unknown>;\n\t\t}) => Effect.Effect<unknown, unknown>;\n\t},\n) =>\n\tEffect.gen(function* () {\n\t\tconst runFork = yield* FiberSet.makeRuntimePromise<R>();\n\t\treturn async (request: Request) => {\n\t\t\tconst urlObj = new URL(request.url);\n\t\t\tconst requestId = nanoid(6);\n\n\t\t\tconst effect = Effect.gen(function* () {\n\t\t\t\tyield* Logger.info(\n\t\t\t\t\t{ request: { pathname: urlObj.pathname } },\n\t\t\t\t\t'Request started',\n\t\t\t\t);\n\n\t\t\t\tfor (const handler of handlers) {\n\t\t\t\t\tif (!handler) continue;\n\n\t\t\t\t\tconst result = yield* handler.handle({ url: urlObj, request }).pipe(\n\t\t\t\t\t\tEffect.flatMap(({ matched, response }) =>\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tif (matched) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\tmatched: true,\n\t\t\t\t\t\t\t\t\t\tresponse:\n\t\t\t\t\t\t\t\t\t\t\tresponse instanceof Promise\n\t\t\t\t\t\t\t\t\t\t\t\t? yield* Effect.tryPromise(() => response)\n\t\t\t\t\t\t\t\t\t\t\t\t: response,\n\t\t\t\t\t\t\t\t\t} as const;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn { matched: false, response: undefined } as const;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.catchAllCause((error) =>\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tyield* Logger.error(\n\t\t\t\t\t\t\t\t\t{ error },\n\t\t\t\t\t\t\t\t\t`Unhandled exception in HTTP handler '${handler._tag}'`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif (opts?.onError) yield* opts.onError({ error });\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tmatched: true,\n\t\t\t\t\t\t\t\t\tresponse: new Response('Internal Server Error', {\n\t\t\t\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t} as const;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (opts?.debug)\n\t\t\t\t\t\tyield* Logger.debug(\n\t\t\t\t\t\t\t{ handler: handler._tag, request, result },\n\t\t\t\t\t\t\t'Processed handler',\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif (!result.matched) continue;\n\t\t\t\t\treturn result.response;\n\t\t\t\t}\n\n\t\t\t\treturn new Response('Not Found', { status: 404 });\n\t\t\t}).pipe(\n\t\t\t\tEffect.tap((response) =>\n\t\t\t\t\tresponse.ok\n\t\t\t\t\t\t? Logger.info(`Request completed with status ${response.status}`)\n\t\t\t\t\t\t: Logger.warn(`Request completed with status ${response.status}`),\n\t\t\t\t),\n\t\t\t\tEffect.withSpan('http'),\n\t\t\t\tEffect.annotateLogs({ requestId }),\n\t\t\t\tEffect.scoped,\n\t\t\t) as Effect.Effect<Response, never, R>;\n\n\t\t\treturn runFork(effect);\n\t\t};\n\t});\n","import {\n\tConfig,\n\tContext,\n\tEffect,\n\tLogger as EffectLogger,\n\tHashMap,\n\tLayer,\n\tLogLevel,\n\tManagedRuntime,\n\tOption,\n} from 'effect';\nimport pino from 'pino';\n\n// Pino Instance\n\nnamespace LoggerType {\n\texport function fromPino(x: pino.Logger<never, boolean>) {\n\t\treturn {\n\t\t\tinfo: x.info.bind(x),\n\t\t\terror: x.error.bind(x),\n\t\t\twarn: x.warn.bind(x),\n\t\t\tdebug: x.debug.bind(x),\n\t\t\tchild: (...params: Parameters<typeof x.child>) => {\n\t\t\t\treturn fromPino(\n\t\t\t\t\tx.child(...params) as unknown as pino.Logger<never, boolean>,\n\t\t\t\t);\n\t\t\t},\n\t\t\tflush: x.flush.bind(x),\n\t\t\t_pino: x,\n\t\t};\n\t}\n\n\texport type CreateParams = {\n\t\tstream?: pino.DestinationStream;\n\t};\n\n\texport function create(params?: CreateParams) {\n\t\tconst logger = pino(\n\t\t\t{\n\t\t\t\tlevel: 'trace', // Level is managed by Effect, so we set the lowest here\n\t\t\t\tserializers: {\n\t\t\t\t\terror: pino.stdSerializers.errWithCause,\n\t\t\t\t\terr: pino.stdSerializers.errWithCause,\n\t\t\t\t},\n\t\t\t\tformatters: {\n\t\t\t\t\tlevel: (label) => {\n\t\t\t\t\t\treturn { level: label };\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tparams?.stream,\n\t\t);\n\t\treturn fromPino(logger);\n\t}\n\n\texport type Type = ReturnType<typeof LoggerType.create>;\n\n\texport function is(x: object): x is Type {\n\t\treturn '_pino' in x;\n\t}\n}\ntype LoggerType = LoggerType.Type;\n\n// The Gist\n\nconst createInstance = (params?: LoggerType.CreateParams) =>\n\tEffect.gen(function* () {\n\t\tconst isDev = Option.getOrNull(\n\t\t\tyield* Config.boolean('DEV').pipe(Config.option),\n\t\t);\n\t\tconst logFile = Option.getOrNull(\n\t\t\tyield* Config.boolean('LOGGER_LOGFILE').pipe(Config.option),\n\t\t);\n\n\t\treturn LoggerType.create({\n\t\t\t...params,\n\t\t\t...(isDev && {\n\t\t\t\tstream: logFile\n\t\t\t\t\t? pino.transport({\n\t\t\t\t\t\t\ttarget: 'pino/file',\n\t\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\t\tdestination: './logs/server.log',\n\t\t\t\t\t\t\t\tmkdir: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t: pino.transport({\n\t\t\t\t\t\t\ttarget: 'pino-pretty',\n\t\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\t\tignore: 'pid,hostname',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t}),\n\t\t});\n\t});\n\n// Pino Context and Effect Logger integration\n\ntype LogParams = [obj: unknown, msg?: string];\nfunction extractParams(...[obj, msg]: LogParams) {\n\tif (typeof obj === 'string') {\n\t\treturn { message: obj };\n\t}\n\treturn { message: msg, attributes: obj as Record<string, any> };\n}\n\n/** A simple helper for calling pino log functions */\nfunction callPino(\n\t{\n\t\tannotations,\n\t\tmessage,\n\t}: Pick<EffectLogger.Logger.Options<unknown>, 'annotations' | 'message'>,\n\tcall: (...params: [obj: unknown, msg?: string]) => void,\n) {\n\tconst entries = HashMap.toEntries(annotations);\n\tif (entries.length > 0) {\n\t\treturn call(Object.fromEntries(entries), String(message));\n\t}\n\n\treturn call(String(message));\n}\n\nnamespace PinoCtx {\n\tconst tag = 'ff-serv/Pino';\n\texport type Type = ReturnType<typeof create>;\n\n\texport function is(obj: unknown): obj is Type {\n\t\treturn (\n\t\t\ttypeof obj === 'object' &&\n\t\t\tobj != null &&\n\t\t\t'_tag' in obj &&\n\t\t\tobj._tag === tag\n\t\t);\n\t}\n\n\texport function create(pino: LoggerType) {\n\t\treturn {\n\t\t\t_tag: tag,\n\t\t\tpino,\n\t\t\teffectLogger: EffectLogger.make(({ logLevel, ...input }) => {\n\t\t\t\tswitch (logLevel) {\n\t\t\t\t\tcase LogLevel.Info:\n\t\t\t\t\t\treturn callPino(input, pino.info);\n\t\t\t\t\tcase LogLevel.Debug:\n\t\t\t\t\t\treturn callPino(input, pino.debug);\n\t\t\t\t\tcase LogLevel.Warning:\n\t\t\t\t\t\treturn callPino(input, pino.warn);\n\t\t\t\t\tcase LogLevel.Error:\n\t\t\t\t\tcase LogLevel.Fatal:\n\t\t\t\t\t\treturn callPino(input, pino.error);\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn callPino(input, pino.info);\n\t\t\t\t}\n\t\t\t}),\n\t\t};\n\t}\n}\ntype PinoCtx = PinoCtx.Type;\n\nclass Pino extends Context.Tag('ff-serv/Pino')<Pino, PinoCtx>() {}\n\n// Facade\n\nexport namespace Logger {\n\texport const layer = (opts?: Parameters<typeof createInstance>[0]) =>\n\t\tEffectLogger.replaceEffect(\n\t\t\tEffectLogger.defaultLogger,\n\t\t\tEffect.gen(function* () {\n\t\t\t\treturn (yield* Pino).effectLogger;\n\t\t\t}),\n\t\t).pipe(\n\t\t\tLayer.provideMerge(\n\t\t\t\tLayer.effect(\n\t\t\t\t\tPino,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\treturn PinoCtx.create(yield* createInstance(opts));\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t//\n\n\texport const sync = () =>\n\t\tEffect.gen(function* () {\n\t\t\tconst pino = yield* Pino;\n\t\t\tconst runtime = ManagedRuntime.make(\n\t\t\t\tEffectLogger.replace(EffectLogger.defaultLogger, pino.effectLogger),\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tinfo: (...params: Parameters<typeof Logger.info>) =>\n\t\t\t\t\tLogger.info(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t\tdebug: (...params: Parameters<typeof Logger.debug>) =>\n\t\t\t\t\tLogger.debug(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t\twarn: (...params: Parameters<typeof Logger.warn>) =>\n\t\t\t\t\tLogger.warn(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t\terror: (...params: Parameters<typeof Logger.error>) =>\n\t\t\t\t\tLogger.error(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t};\n\t\t});\n\n\t/** @deprecated — will be renamed to `sync` */\n\texport const get = () => Logger.sync();\n\n\texport const replace =\n\t\t(logger: LoggerType | pino.Logger) =>\n\t\t<A, E, R>(e: Effect.Effect<A, E, R>) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst oldPinoCtx = yield* Pino;\n\t\t\t\tconst pino = LoggerType.is(logger)\n\t\t\t\t\t? logger\n\t\t\t\t\t: LoggerType.fromPino(logger);\n\t\t\t\tconst pinoCtx = PinoCtx.create(pino);\n\n\t\t\t\treturn yield* Effect.provide(\n\t\t\t\t\te,\n\t\t\t\t\tLayer.mergeAll(\n\t\t\t\t\t\tEffectLogger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger),\n\t\t\t\t\t\tLayer.succeed(Pino, pinoCtx),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t});\n\n\texport const replaceChild =\n\t\t(...params: Parameters<LoggerType['child']>) =>\n\t\t<A, E, R>(e: Effect.Effect<A, E, R>) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst oldPinoCtx = yield* Pino;\n\t\t\t\tconst pino = oldPinoCtx.pino.child(...params);\n\t\t\t\tconst pinoCtx = PinoCtx.create(pino);\n\n\t\t\t\treturn yield* Effect.provide(\n\t\t\t\t\tEffect.provide(\n\t\t\t\t\t\te,\n\t\t\t\t\t\tEffectLogger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger),\n\t\t\t\t\t),\n\t\t\t\t\tLayer.succeed(Pino, pinoCtx),\n\t\t\t\t);\n\t\t\t});\n\n\t// --\n\n\texport const info = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logInfo(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\texport const debug = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logDebug(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\texport const warn = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logWarning(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\texport const error = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logError(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\t/** @deprecated */\n\texport const flush = (..._params: Parameters<LoggerType['flush']>) =>\n\t\tEffect.void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAAA,iBAAuB;;;ACHvB,IAAAC,iBAAiC;AAEjC,oBAAuB;;;ACFvB,oBAUO;AACP,kBAAiB;AAIjB,IAAU;AAAA,CAAV,CAAUC,gBAAV;AACQ,WAAS,SAAS,GAAgC;AACxD,WAAO;AAAA,MACN,MAAM,EAAE,KAAK,KAAK,CAAC;AAAA,MACnB,OAAO,EAAE,MAAM,KAAK,CAAC;AAAA,MACrB,MAAM,EAAE,KAAK,KAAK,CAAC;AAAA,MACnB,OAAO,EAAE,MAAM,KAAK,CAAC;AAAA,MACrB,OAAO,IAAI,WAAuC;AACjD,eAAO;AAAA,UACN,EAAE,MAAM,GAAG,MAAM;AAAA,QAClB;AAAA,MACD;AAAA,MACA,OAAO,EAAE,MAAM,KAAK,CAAC;AAAA,MACrB,OAAO;AAAA,IACR;AAAA,EACD;AAdO,EAAAA,YAAS;AAoBT,WAAS,OAAO,QAAuB;AAC7C,UAAM,aAAS,YAAAC;AAAA,MACd;AAAA,QACC,OAAO;AAAA;AAAA,QACP,aAAa;AAAA,UACZ,OAAO,YAAAA,QAAK,eAAe;AAAA,UAC3B,KAAK,YAAAA,QAAK,eAAe;AAAA,QAC1B;AAAA,QACA,YAAY;AAAA,UACX,OAAO,CAAC,UAAU;AACjB,mBAAO,EAAE,OAAO,MAAM;AAAA,UACvB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AACJ;;;ADhBO,SAAS,YACf,SACA,KAGC;AACD,SAAO,IAAI;AAAA,IAAQ;AAAA,IAAe,CAAC,EAAE,QAAQ,MAC5C,sBAAO,IAAI,aAAa;AACvB,YAAM,OACL,MAAM,CAAC,sBAAO,SAAS,GAAG,IAAI,OAAO,MAAM,GAAG,IAAI,CAAC;AAEpD,aAAO,OAAO,sBAAO,WAAW,MAAM,QAAQ,OAAO,SAAS,GAAG,IAAI,CAAC;AAAA,IACvE,CAAC;AAAA,EACF;AACD;","names":["import_effect","import_effect","LoggerType","pino","PinoCtx","EffectLogger","Logger"]}
@@ -1,11 +1,11 @@
1
1
  import { Context } from '@orpc/server';
2
2
  import { FetchHandler } from '@orpc/server/fetch';
3
3
  import { FriendlyStandardHandleOptions } from '@orpc/server/standard';
4
- import { H as Handler } from '../fetch-handler-BgTGMsrV.cjs';
4
+ import { Effect } from 'effect';
5
+ import { H as Handler } from '../fetch-handler-Dwj0ax2Z.cjs';
5
6
  import 'effect/Scope';
6
- import 'effect';
7
+ import 'effect/Cause';
7
8
 
8
- type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
9
- declare function oRPCHandler<T extends Context>(handler: FetchHandler<T>, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Handler<'oRPCHandler'>;
9
+ declare function oRPCHandler<T extends Context, E, R>(handler: FetchHandler<T>, opt?: FriendlyStandardHandleOptions<T> | Effect.Effect<FriendlyStandardHandleOptions<T>, E, R>): Handler<"oRPCHandler", R>;
10
10
 
11
11
  export { oRPCHandler };
@@ -1,11 +1,11 @@
1
1
  import { Context } from '@orpc/server';
2
2
  import { FetchHandler } from '@orpc/server/fetch';
3
3
  import { FriendlyStandardHandleOptions } from '@orpc/server/standard';
4
- import { H as Handler } from '../fetch-handler-BgTGMsrV.js';
4
+ import { Effect } from 'effect';
5
+ import { H as Handler } from '../fetch-handler-Dwj0ax2Z.js';
5
6
  import 'effect/Scope';
6
- import 'effect';
7
+ import 'effect/Cause';
7
8
 
8
- type MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions ? [options?: TOptions] : [options: TOptions];
9
- declare function oRPCHandler<T extends Context>(handler: FetchHandler<T>, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Handler<'oRPCHandler'>;
9
+ declare function oRPCHandler<T extends Context, E, R>(handler: FetchHandler<T>, opt?: FriendlyStandardHandleOptions<T> | Effect.Effect<FriendlyStandardHandleOptions<T>, E, R>): Handler<"oRPCHandler", R>;
10
10
 
11
11
  export { oRPCHandler };
@@ -1,9 +1,237 @@
1
1
  // src/http/orpc.ts
2
- function oRPCHandler(handler, ...rest) {
3
- return {
4
- _tag: "oRPCHandler",
5
- handle: async ({ request }) => handler.handle(request, ...rest)
6
- };
2
+ import { Effect as Effect3 } from "effect";
3
+
4
+ // src/http/fetch-handler.ts
5
+ import { Effect as Effect2, FiberSet } from "effect";
6
+ import { nanoid } from "nanoid";
7
+
8
+ // src/logger.ts
9
+ import {
10
+ Config,
11
+ Context,
12
+ Effect,
13
+ Logger as EffectLogger,
14
+ HashMap,
15
+ Layer,
16
+ LogLevel,
17
+ ManagedRuntime,
18
+ Option
19
+ } from "effect";
20
+ import pino from "pino";
21
+ var LoggerType;
22
+ ((LoggerType2) => {
23
+ function fromPino(x) {
24
+ return {
25
+ info: x.info.bind(x),
26
+ error: x.error.bind(x),
27
+ warn: x.warn.bind(x),
28
+ debug: x.debug.bind(x),
29
+ child: (...params) => {
30
+ return fromPino(
31
+ x.child(...params)
32
+ );
33
+ },
34
+ flush: x.flush.bind(x),
35
+ _pino: x
36
+ };
37
+ }
38
+ LoggerType2.fromPino = fromPino;
39
+ function create(params) {
40
+ const logger = pino(
41
+ {
42
+ level: "trace",
43
+ // Level is managed by Effect, so we set the lowest here
44
+ serializers: {
45
+ error: pino.stdSerializers.errWithCause,
46
+ err: pino.stdSerializers.errWithCause
47
+ },
48
+ formatters: {
49
+ level: (label) => {
50
+ return { level: label };
51
+ }
52
+ }
53
+ },
54
+ params?.stream
55
+ );
56
+ return fromPino(logger);
57
+ }
58
+ LoggerType2.create = create;
59
+ function is(x) {
60
+ return "_pino" in x;
61
+ }
62
+ LoggerType2.is = is;
63
+ })(LoggerType || (LoggerType = {}));
64
+ var createInstance = (params) => Effect.gen(function* () {
65
+ const isDev = Option.getOrNull(
66
+ yield* Config.boolean("DEV").pipe(Config.option)
67
+ );
68
+ const logFile = Option.getOrNull(
69
+ yield* Config.boolean("LOGGER_LOGFILE").pipe(Config.option)
70
+ );
71
+ return LoggerType.create({
72
+ ...params,
73
+ ...isDev && {
74
+ stream: logFile ? pino.transport({
75
+ target: "pino/file",
76
+ options: {
77
+ destination: "./logs/server.log",
78
+ mkdir: true
79
+ }
80
+ }) : pino.transport({
81
+ target: "pino-pretty",
82
+ options: {
83
+ ignore: "pid,hostname"
84
+ }
85
+ })
86
+ }
87
+ });
88
+ });
89
+ function extractParams(...[obj, msg]) {
90
+ if (typeof obj === "string") {
91
+ return { message: obj };
92
+ }
93
+ return { message: msg, attributes: obj };
94
+ }
95
+ function callPino({
96
+ annotations,
97
+ message
98
+ }, call) {
99
+ const entries = HashMap.toEntries(annotations);
100
+ if (entries.length > 0) {
101
+ return call(Object.fromEntries(entries), String(message));
102
+ }
103
+ return call(String(message));
104
+ }
105
+ var PinoCtx;
106
+ ((PinoCtx2) => {
107
+ const tag = "ff-serv/Pino";
108
+ function is(obj) {
109
+ return typeof obj === "object" && obj != null && "_tag" in obj && obj._tag === tag;
110
+ }
111
+ PinoCtx2.is = is;
112
+ function create(pino2) {
113
+ return {
114
+ _tag: tag,
115
+ pino: pino2,
116
+ effectLogger: EffectLogger.make(({ logLevel, ...input }) => {
117
+ switch (logLevel) {
118
+ case LogLevel.Info:
119
+ return callPino(input, pino2.info);
120
+ case LogLevel.Debug:
121
+ return callPino(input, pino2.debug);
122
+ case LogLevel.Warning:
123
+ return callPino(input, pino2.warn);
124
+ case LogLevel.Error:
125
+ case LogLevel.Fatal:
126
+ return callPino(input, pino2.error);
127
+ default:
128
+ return callPino(input, pino2.info);
129
+ }
130
+ })
131
+ };
132
+ }
133
+ PinoCtx2.create = create;
134
+ })(PinoCtx || (PinoCtx = {}));
135
+ var Pino = class extends Context.Tag("ff-serv/Pino")() {
136
+ };
137
+ var Logger;
138
+ ((Logger2) => {
139
+ Logger2.layer = (opts) => EffectLogger.replaceEffect(
140
+ EffectLogger.defaultLogger,
141
+ Effect.gen(function* () {
142
+ return (yield* Pino).effectLogger;
143
+ })
144
+ ).pipe(
145
+ Layer.provideMerge(
146
+ Layer.effect(
147
+ Pino,
148
+ Effect.gen(function* () {
149
+ return PinoCtx.create(yield* createInstance(opts));
150
+ })
151
+ )
152
+ )
153
+ );
154
+ Logger2.sync = () => Effect.gen(function* () {
155
+ const pino2 = yield* Pino;
156
+ const runtime = ManagedRuntime.make(
157
+ EffectLogger.replace(EffectLogger.defaultLogger, pino2.effectLogger)
158
+ );
159
+ return {
160
+ info: (...params) => Logger2.info(...params).pipe((e) => runtime.runSync(e)),
161
+ debug: (...params) => Logger2.debug(...params).pipe((e) => runtime.runSync(e)),
162
+ warn: (...params) => Logger2.warn(...params).pipe((e) => runtime.runSync(e)),
163
+ error: (...params) => Logger2.error(...params).pipe((e) => runtime.runSync(e))
164
+ };
165
+ });
166
+ Logger2.get = () => Logger2.sync();
167
+ Logger2.replace = (logger) => (e) => Effect.gen(function* () {
168
+ const oldPinoCtx = yield* Pino;
169
+ const pino2 = LoggerType.is(logger) ? logger : LoggerType.fromPino(logger);
170
+ const pinoCtx = PinoCtx.create(pino2);
171
+ return yield* Effect.provide(
172
+ e,
173
+ Layer.mergeAll(
174
+ EffectLogger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger),
175
+ Layer.succeed(Pino, pinoCtx)
176
+ )
177
+ );
178
+ });
179
+ Logger2.replaceChild = (...params) => (e) => Effect.gen(function* () {
180
+ const oldPinoCtx = yield* Pino;
181
+ const pino2 = oldPinoCtx.pino.child(...params);
182
+ const pinoCtx = PinoCtx.create(pino2);
183
+ return yield* Effect.provide(
184
+ Effect.provide(
185
+ e,
186
+ EffectLogger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger)
187
+ ),
188
+ Layer.succeed(Pino, pinoCtx)
189
+ );
190
+ });
191
+ Logger2.info = (...params) => Effect.gen(function* () {
192
+ const { message, attributes } = extractParams(...params);
193
+ yield* Effect.logInfo(message).pipe(
194
+ attributes ? Effect.annotateLogs(attributes) : (e) => e
195
+ );
196
+ });
197
+ Logger2.debug = (...params) => Effect.gen(function* () {
198
+ const { message, attributes } = extractParams(...params);
199
+ yield* Effect.logDebug(message).pipe(
200
+ attributes ? Effect.annotateLogs(attributes) : (e) => e
201
+ );
202
+ });
203
+ Logger2.warn = (...params) => Effect.gen(function* () {
204
+ const { message, attributes } = extractParams(...params);
205
+ yield* Effect.logWarning(message).pipe(
206
+ attributes ? Effect.annotateLogs(attributes) : (e) => e
207
+ );
208
+ });
209
+ Logger2.error = (...params) => Effect.gen(function* () {
210
+ const { message, attributes } = extractParams(...params);
211
+ yield* Effect.logError(message).pipe(
212
+ attributes ? Effect.annotateLogs(attributes) : (e) => e
213
+ );
214
+ });
215
+ Logger2.flush = (..._params) => Effect.void;
216
+ })(Logger || (Logger = {}));
217
+
218
+ // src/http/fetch-handler.ts
219
+ var Handler = class {
220
+ constructor(_tag, handle) {
221
+ this._tag = _tag;
222
+ this.handle = handle;
223
+ }
224
+ };
225
+
226
+ // src/http/orpc.ts
227
+ function oRPCHandler(handler, opt) {
228
+ return new Handler(
229
+ "oRPCHandler",
230
+ ({ request }) => Effect3.gen(function* () {
231
+ const _opt = opt ? [Effect3.isEffect(opt) ? yield* opt : opt] : [];
232
+ return yield* Effect3.tryPromise(() => handler.handle(request, ..._opt));
233
+ })
234
+ );
7
235
  }
8
236
  export {
9
237
  oRPCHandler
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/http/orpc.ts"],"sourcesContent":["import type { Context } from '@orpc/server';\nimport type { FetchHandler } from '@orpc/server/fetch';\nimport type { FriendlyStandardHandleOptions } from '@orpc/server/standard';\nimport type { Handler } from './fetch-handler.js';\n\ntype MaybeOptionalOptions<TOptions> = Record<never, never> extends TOptions\n\t? [options?: TOptions]\n\t: [options: TOptions];\n\nexport function oRPCHandler<T extends Context>(\n\thandler: FetchHandler<T>,\n\t...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>\n): Handler<'oRPCHandler'> {\n\treturn {\n\t\t_tag: 'oRPCHandler',\n\t\thandle: async ({ request }) => handler.handle(request, ...rest),\n\t};\n}\n"],"mappings":";AASO,SAAS,YACf,YACG,MACsB;AACzB,SAAO;AAAA,IACN,MAAM;AAAA,IACN,QAAQ,OAAO,EAAE,QAAQ,MAAM,QAAQ,OAAO,SAAS,GAAG,IAAI;AAAA,EAC/D;AACD;","names":[]}
1
+ {"version":3,"sources":["../../src/http/orpc.ts","../../src/http/fetch-handler.ts","../../src/logger.ts"],"sourcesContent":["import type { Context } from '@orpc/server';\nimport type { FetchHandler } from '@orpc/server/fetch';\nimport type { FriendlyStandardHandleOptions } from '@orpc/server/standard';\nimport { Effect } from 'effect';\nimport { Handler } from './fetch-handler.js';\n\ntype MaybeOptionalOptions<TOptions> =\n\tRecord<never, never> extends TOptions\n\t\t? [options?: TOptions]\n\t\t: [options: TOptions];\n\nexport function oRPCHandler<T extends Context, E, R>(\n\thandler: FetchHandler<T>,\n\topt?:\n\t\t| FriendlyStandardHandleOptions<T>\n\t\t| Effect.Effect<FriendlyStandardHandleOptions<T>, E, R>,\n) {\n\treturn new Handler('oRPCHandler', ({ request }) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst _opt = (\n\t\t\t\topt ? [Effect.isEffect(opt) ? yield* opt : opt] : []\n\t\t\t) as MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>;\n\t\t\treturn yield* Effect.tryPromise(() => handler.handle(request, ..._opt));\n\t\t}),\n\t);\n}\n","import { Effect, FiberSet } from 'effect';\nimport type { Cause } from 'effect/Cause';\nimport { nanoid } from 'nanoid';\nimport { Logger } from '../logger.js';\n\n// #region Handler\n\nexport type AnyResponse = Response | Promise<Response>;\n\nexport type HandlerResult =\n\t| {\n\t\t\tmatched: true;\n\t\t\tresponse: AnyResponse;\n\t }\n\t| {\n\t\t\tmatched: false;\n\t\t\tresponse: undefined;\n\t };\n\nexport class Handler<NAME extends string, R> {\n\tconstructor(\n\t\treadonly _tag: NAME,\n\t\treadonly handle: (opt: {\n\t\t\turl: URL;\n\t\t\trequest: Request;\n\t\t}) => Effect.Effect<HandlerResult, unknown, R>,\n\t) {}\n}\n\n// #endregion\n\ntype ExtractRequirements<T> = T extends Handler<string, infer R> ? R : never;\n\nexport const createFetchHandler = <\n\tconst HANDLERS extends [\n\t\tHandler<string, unknown>,\n\t\t...Array<Handler<string, unknown>>,\n\t],\n\tR = ExtractRequirements<HANDLERS[number]>,\n>(\n\thandlers: HANDLERS,\n\topts?: {\n\t\tdebug?: boolean;\n\t\tonError?: (ctx: {\n\t\t\terror: Cause<unknown>;\n\t\t}) => Effect.Effect<unknown, unknown>;\n\t},\n) =>\n\tEffect.gen(function* () {\n\t\tconst runFork = yield* FiberSet.makeRuntimePromise<R>();\n\t\treturn async (request: Request) => {\n\t\t\tconst urlObj = new URL(request.url);\n\t\t\tconst requestId = nanoid(6);\n\n\t\t\tconst effect = Effect.gen(function* () {\n\t\t\t\tyield* Logger.info(\n\t\t\t\t\t{ request: { pathname: urlObj.pathname } },\n\t\t\t\t\t'Request started',\n\t\t\t\t);\n\n\t\t\t\tfor (const handler of handlers) {\n\t\t\t\t\tif (!handler) continue;\n\n\t\t\t\t\tconst result = yield* handler.handle({ url: urlObj, request }).pipe(\n\t\t\t\t\t\tEffect.flatMap(({ matched, response }) =>\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tif (matched) {\n\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\tmatched: true,\n\t\t\t\t\t\t\t\t\t\tresponse:\n\t\t\t\t\t\t\t\t\t\t\tresponse instanceof Promise\n\t\t\t\t\t\t\t\t\t\t\t\t? yield* Effect.tryPromise(() => response)\n\t\t\t\t\t\t\t\t\t\t\t\t: response,\n\t\t\t\t\t\t\t\t\t} as const;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn { matched: false, response: undefined } as const;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.catchAllCause((error) =>\n\t\t\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\t\t\tyield* Logger.error(\n\t\t\t\t\t\t\t\t\t{ error },\n\t\t\t\t\t\t\t\t\t`Unhandled exception in HTTP handler '${handler._tag}'`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif (opts?.onError) yield* opts.onError({ error });\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tmatched: true,\n\t\t\t\t\t\t\t\t\tresponse: new Response('Internal Server Error', {\n\t\t\t\t\t\t\t\t\t\tstatus: 500,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t} as const;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tif (opts?.debug)\n\t\t\t\t\t\tyield* Logger.debug(\n\t\t\t\t\t\t\t{ handler: handler._tag, request, result },\n\t\t\t\t\t\t\t'Processed handler',\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif (!result.matched) continue;\n\t\t\t\t\treturn result.response;\n\t\t\t\t}\n\n\t\t\t\treturn new Response('Not Found', { status: 404 });\n\t\t\t}).pipe(\n\t\t\t\tEffect.tap((response) =>\n\t\t\t\t\tresponse.ok\n\t\t\t\t\t\t? Logger.info(`Request completed with status ${response.status}`)\n\t\t\t\t\t\t: Logger.warn(`Request completed with status ${response.status}`),\n\t\t\t\t),\n\t\t\t\tEffect.withSpan('http'),\n\t\t\t\tEffect.annotateLogs({ requestId }),\n\t\t\t\tEffect.scoped,\n\t\t\t) as Effect.Effect<Response, never, R>;\n\n\t\t\treturn runFork(effect);\n\t\t};\n\t});\n","import {\n\tConfig,\n\tContext,\n\tEffect,\n\tLogger as EffectLogger,\n\tHashMap,\n\tLayer,\n\tLogLevel,\n\tManagedRuntime,\n\tOption,\n} from 'effect';\nimport pino from 'pino';\n\n// Pino Instance\n\nnamespace LoggerType {\n\texport function fromPino(x: pino.Logger<never, boolean>) {\n\t\treturn {\n\t\t\tinfo: x.info.bind(x),\n\t\t\terror: x.error.bind(x),\n\t\t\twarn: x.warn.bind(x),\n\t\t\tdebug: x.debug.bind(x),\n\t\t\tchild: (...params: Parameters<typeof x.child>) => {\n\t\t\t\treturn fromPino(\n\t\t\t\t\tx.child(...params) as unknown as pino.Logger<never, boolean>,\n\t\t\t\t);\n\t\t\t},\n\t\t\tflush: x.flush.bind(x),\n\t\t\t_pino: x,\n\t\t};\n\t}\n\n\texport type CreateParams = {\n\t\tstream?: pino.DestinationStream;\n\t};\n\n\texport function create(params?: CreateParams) {\n\t\tconst logger = pino(\n\t\t\t{\n\t\t\t\tlevel: 'trace', // Level is managed by Effect, so we set the lowest here\n\t\t\t\tserializers: {\n\t\t\t\t\terror: pino.stdSerializers.errWithCause,\n\t\t\t\t\terr: pino.stdSerializers.errWithCause,\n\t\t\t\t},\n\t\t\t\tformatters: {\n\t\t\t\t\tlevel: (label) => {\n\t\t\t\t\t\treturn { level: label };\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tparams?.stream,\n\t\t);\n\t\treturn fromPino(logger);\n\t}\n\n\texport type Type = ReturnType<typeof LoggerType.create>;\n\n\texport function is(x: object): x is Type {\n\t\treturn '_pino' in x;\n\t}\n}\ntype LoggerType = LoggerType.Type;\n\n// The Gist\n\nconst createInstance = (params?: LoggerType.CreateParams) =>\n\tEffect.gen(function* () {\n\t\tconst isDev = Option.getOrNull(\n\t\t\tyield* Config.boolean('DEV').pipe(Config.option),\n\t\t);\n\t\tconst logFile = Option.getOrNull(\n\t\t\tyield* Config.boolean('LOGGER_LOGFILE').pipe(Config.option),\n\t\t);\n\n\t\treturn LoggerType.create({\n\t\t\t...params,\n\t\t\t...(isDev && {\n\t\t\t\tstream: logFile\n\t\t\t\t\t? pino.transport({\n\t\t\t\t\t\t\ttarget: 'pino/file',\n\t\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\t\tdestination: './logs/server.log',\n\t\t\t\t\t\t\t\tmkdir: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t})\n\t\t\t\t\t: pino.transport({\n\t\t\t\t\t\t\ttarget: 'pino-pretty',\n\t\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\t\tignore: 'pid,hostname',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t}),\n\t\t});\n\t});\n\n// Pino Context and Effect Logger integration\n\ntype LogParams = [obj: unknown, msg?: string];\nfunction extractParams(...[obj, msg]: LogParams) {\n\tif (typeof obj === 'string') {\n\t\treturn { message: obj };\n\t}\n\treturn { message: msg, attributes: obj as Record<string, any> };\n}\n\n/** A simple helper for calling pino log functions */\nfunction callPino(\n\t{\n\t\tannotations,\n\t\tmessage,\n\t}: Pick<EffectLogger.Logger.Options<unknown>, 'annotations' | 'message'>,\n\tcall: (...params: [obj: unknown, msg?: string]) => void,\n) {\n\tconst entries = HashMap.toEntries(annotations);\n\tif (entries.length > 0) {\n\t\treturn call(Object.fromEntries(entries), String(message));\n\t}\n\n\treturn call(String(message));\n}\n\nnamespace PinoCtx {\n\tconst tag = 'ff-serv/Pino';\n\texport type Type = ReturnType<typeof create>;\n\n\texport function is(obj: unknown): obj is Type {\n\t\treturn (\n\t\t\ttypeof obj === 'object' &&\n\t\t\tobj != null &&\n\t\t\t'_tag' in obj &&\n\t\t\tobj._tag === tag\n\t\t);\n\t}\n\n\texport function create(pino: LoggerType) {\n\t\treturn {\n\t\t\t_tag: tag,\n\t\t\tpino,\n\t\t\teffectLogger: EffectLogger.make(({ logLevel, ...input }) => {\n\t\t\t\tswitch (logLevel) {\n\t\t\t\t\tcase LogLevel.Info:\n\t\t\t\t\t\treturn callPino(input, pino.info);\n\t\t\t\t\tcase LogLevel.Debug:\n\t\t\t\t\t\treturn callPino(input, pino.debug);\n\t\t\t\t\tcase LogLevel.Warning:\n\t\t\t\t\t\treturn callPino(input, pino.warn);\n\t\t\t\t\tcase LogLevel.Error:\n\t\t\t\t\tcase LogLevel.Fatal:\n\t\t\t\t\t\treturn callPino(input, pino.error);\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn callPino(input, pino.info);\n\t\t\t\t}\n\t\t\t}),\n\t\t};\n\t}\n}\ntype PinoCtx = PinoCtx.Type;\n\nclass Pino extends Context.Tag('ff-serv/Pino')<Pino, PinoCtx>() {}\n\n// Facade\n\nexport namespace Logger {\n\texport const layer = (opts?: Parameters<typeof createInstance>[0]) =>\n\t\tEffectLogger.replaceEffect(\n\t\t\tEffectLogger.defaultLogger,\n\t\t\tEffect.gen(function* () {\n\t\t\t\treturn (yield* Pino).effectLogger;\n\t\t\t}),\n\t\t).pipe(\n\t\t\tLayer.provideMerge(\n\t\t\t\tLayer.effect(\n\t\t\t\t\tPino,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\treturn PinoCtx.create(yield* createInstance(opts));\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t//\n\n\texport const sync = () =>\n\t\tEffect.gen(function* () {\n\t\t\tconst pino = yield* Pino;\n\t\t\tconst runtime = ManagedRuntime.make(\n\t\t\t\tEffectLogger.replace(EffectLogger.defaultLogger, pino.effectLogger),\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tinfo: (...params: Parameters<typeof Logger.info>) =>\n\t\t\t\t\tLogger.info(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t\tdebug: (...params: Parameters<typeof Logger.debug>) =>\n\t\t\t\t\tLogger.debug(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t\twarn: (...params: Parameters<typeof Logger.warn>) =>\n\t\t\t\t\tLogger.warn(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t\terror: (...params: Parameters<typeof Logger.error>) =>\n\t\t\t\t\tLogger.error(...params).pipe((e) => runtime.runSync(e)),\n\t\t\t};\n\t\t});\n\n\t/** @deprecated — will be renamed to `sync` */\n\texport const get = () => Logger.sync();\n\n\texport const replace =\n\t\t(logger: LoggerType | pino.Logger) =>\n\t\t<A, E, R>(e: Effect.Effect<A, E, R>) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst oldPinoCtx = yield* Pino;\n\t\t\t\tconst pino = LoggerType.is(logger)\n\t\t\t\t\t? logger\n\t\t\t\t\t: LoggerType.fromPino(logger);\n\t\t\t\tconst pinoCtx = PinoCtx.create(pino);\n\n\t\t\t\treturn yield* Effect.provide(\n\t\t\t\t\te,\n\t\t\t\t\tLayer.mergeAll(\n\t\t\t\t\t\tEffectLogger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger),\n\t\t\t\t\t\tLayer.succeed(Pino, pinoCtx),\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t});\n\n\texport const replaceChild =\n\t\t(...params: Parameters<LoggerType['child']>) =>\n\t\t<A, E, R>(e: Effect.Effect<A, E, R>) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst oldPinoCtx = yield* Pino;\n\t\t\t\tconst pino = oldPinoCtx.pino.child(...params);\n\t\t\t\tconst pinoCtx = PinoCtx.create(pino);\n\n\t\t\t\treturn yield* Effect.provide(\n\t\t\t\t\tEffect.provide(\n\t\t\t\t\t\te,\n\t\t\t\t\t\tEffectLogger.replace(oldPinoCtx.effectLogger, pinoCtx.effectLogger),\n\t\t\t\t\t),\n\t\t\t\t\tLayer.succeed(Pino, pinoCtx),\n\t\t\t\t);\n\t\t\t});\n\n\t// --\n\n\texport const info = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logInfo(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\texport const debug = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logDebug(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\texport const warn = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logWarning(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\texport const error = (...params: LogParams) =>\n\t\tEffect.gen(function* () {\n\t\t\tconst { message, attributes } = extractParams(...params);\n\t\t\tyield* Effect.logError(message).pipe(\n\t\t\t\tattributes ? Effect.annotateLogs(attributes) : (e) => e,\n\t\t\t);\n\t\t});\n\n\t/** @deprecated */\n\texport const flush = (..._params: Parameters<LoggerType['flush']>) =>\n\t\tEffect.void;\n}\n"],"mappings":";AAGA,SAAS,UAAAA,eAAc;;;ACHvB,SAAS,UAAAC,SAAQ,gBAAgB;AAEjC,SAAS,cAAc;;;ACFvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,UAAU;AAIjB,IAAU;AAAA,CAAV,CAAUC,gBAAV;AACQ,WAAS,SAAS,GAAgC;AACxD,WAAO;AAAA,MACN,MAAM,EAAE,KAAK,KAAK,CAAC;AAAA,MACnB,OAAO,EAAE,MAAM,KAAK,CAAC;AAAA,MACrB,MAAM,EAAE,KAAK,KAAK,CAAC;AAAA,MACnB,OAAO,EAAE,MAAM,KAAK,CAAC;AAAA,MACrB,OAAO,IAAI,WAAuC;AACjD,eAAO;AAAA,UACN,E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WAAW,IAAI,cAAc,GAAG,MAAM;AACvD,WAAO,OAAO,SAAS,OAAO,EAAE;AAAA,MAC/B,aAAa,OAAO,aAAa,UAAU,IAAI,CAAC,MAAM;AAAA,IACvD;AAAA,EACD,CAAC;AAGK,EAAMA,QAAA,QAAQ,IAAI,YACxB,OAAO;AAAA,GAjHQ;;;AD/IV,IAAM,UAAN,MAAsC;AAAA,EAC5C,YACU,MACA,QAIR;AALQ;AACA;AAAA,EAIP;AACJ;;;ADhBO,SAAS,YACf,SACA,KAGC;AACD,SAAO,IAAI;AAAA,IAAQ;AAAA,IAAe,CAAC,EAAE,QAAQ,MAC5CC,QAAO,IAAI,aAAa;AACvB,YAAM,OACL,MAAM,CAACA,QAAO,SAAS,GAAG,IAAI,OAAO,MAAM,GAAG,IAAI,CAAC;AAEpD,aAAO,OAAOA,QAAO,WAAW,MAAM,QAAQ,OAAO,SAAS,GAAG,IAAI,CAAC;AAAA,IACvE,CAAC;AAAA,EACF;AACD;","names":["Effect","Effect","LoggerType","PinoCtx","pino","Logger","Effect"]}
@@ -0,0 +1,32 @@
1
+ import * as effect_Scope from 'effect/Scope';
2
+ import { Effect } from 'effect';
3
+ import { Cause } from 'effect/Cause';
4
+
5
+ type AnyResponse = Response | Promise<Response>;
6
+ type HandlerResult = {
7
+ matched: true;
8
+ response: AnyResponse;
9
+ } | {
10
+ matched: false;
11
+ response: undefined;
12
+ };
13
+ declare class Handler<NAME extends string, R> {
14
+ readonly _tag: NAME;
15
+ readonly handle: (opt: {
16
+ url: URL;
17
+ request: Request;
18
+ }) => Effect.Effect<HandlerResult, unknown, R>;
19
+ constructor(_tag: NAME, handle: (opt: {
20
+ url: URL;
21
+ request: Request;
22
+ }) => Effect.Effect<HandlerResult, unknown, R>);
23
+ }
24
+ type ExtractRequirements<T> = T extends Handler<string, infer R> ? R : never;
25
+ declare const createFetchHandler: <const HANDLERS extends [Handler<string, unknown>, ...Array<Handler<string, unknown>>], R = ExtractRequirements<HANDLERS[number]>>(handlers: HANDLERS, opts?: {
26
+ debug?: boolean;
27
+ onError?: (ctx: {
28
+ error: Cause<unknown>;
29
+ }) => Effect.Effect<unknown, unknown>;
30
+ }) => Effect.Effect<(request: Request) => Promise<Response>, never, R | effect_Scope.Scope>;
31
+
32
+ export { type AnyResponse as A, Handler as H, createFetchHandler as c };