@fedify/adonisjs 2.5.0-dev.2619 → 2.5.0-dev.2664
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.
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -244,7 +244,11 @@ var FedifyProvider = class {
|
|
|
244
244
|
const stopped = this.#queue ?? Promise.resolve();
|
|
245
245
|
if (!this.#loggingConfigured) return stopped;
|
|
246
246
|
this.#loggingConfigured = false;
|
|
247
|
-
return stopped.then(
|
|
247
|
+
return stopped.then(async () => {
|
|
248
|
+
try {
|
|
249
|
+
await (0, _logtape_logtape.reset)();
|
|
250
|
+
} catch {}
|
|
251
|
+
});
|
|
248
252
|
}
|
|
249
253
|
/**
|
|
250
254
|
* Called when the HTTP server starts listening and requests can arrive.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fedify_provider.cjs","names":["#ready","builder","configProvider","E_INVALID_FEDIFY_CONFIG","#buildable","E_FEDERATION_NOT_READY","#middleware","#listening","FedifyMiddleware","#loggingConfigured","configureFedifyLogging","#serverStarted","#settle","#queueController","#queue","#readyTimer"],"sources":["../../providers/fedify_provider.ts"],"sourcesContent":["/**\n * The `@fedify/adonisjs` service provider; see {@link FedifyProvider}.\n *\n * @module\n */\nimport { configProvider } from \"@adonisjs/core\";\nimport type { Logger } from \"@adonisjs/core/logger\";\nimport type { ApplicationService, ConfigProvider } from \"@adonisjs/core/types\";\nimport type { Federation } from \"@fedify/fedify\";\nimport { reset as resetLogging } from \"@logtape/logtape\";\n\nimport { builder } from \"../src/builder.ts\";\nimport {\n E_FEDERATION_NOT_READY,\n E_INVALID_FEDIFY_CONFIG,\n} from \"../src/errors.ts\";\nimport FedifyMiddleware from \"../src/fedify_middleware.ts\";\nimport { installFederationGetter } from \"../src/http_context.ts\";\nimport { configureFedifyLogging } from \"../src/logging.ts\";\nimport type { ContextData, ResolvedFedifyConfig } from \"../src/types.ts\";\n\n/**\n * How long a request that arrives before `ready()` waits for the federation.\n *\n * Generous, since it only needs to outlast earlier providers' `ready()` hooks.\n * It turns a `ready()` that never comes (an earlier provider waiting on this\n * server) into an error instead of a request that never completes.\n */\nconst READY_TIMEOUT_MS = 30_000;\n\n/**\n * A memoised factory: the value, plus a way to drop what was cached.\n */\ntype Memoized<T> = (() => Promise<T>) & { forget(): void };\n\n/**\n * Memoises an asynchronous factory, caching successes only.\n *\n * Used for the container bindings instead of `container.singleton()`, which\n * also caches *rejections*: one early, swallowed `make('fedify')` would pin\n * `E_FEDERATION_NOT_READY` for the life of the process. A failed attempt is\n * forgotten instead, so the next caller runs the factory again. `forget()`\n * drops a cached success once the caller knows it is stale.\n */\nfunction memoizeSuccess<T>(factory: () => Promise<T>): Memoized<T> {\n let cached: Promise<T> | undefined;\n\n const memo = (): Promise<T> => {\n cached ??= factory().catch((error: unknown) => {\n cached = undefined;\n throw error;\n });\n\n return cached;\n };\n\n return Object.assign(memo, {\n forget: (): void => {\n cached = undefined;\n },\n });\n}\n\n/**\n * The service provider registered from `adonisrc.ts` as\n * `@fedify/adonisjs/fedify_provider`.\n *\n * Binds `fedify.builder`, `fedify.config`, `fedify` and\n * {@link FedifyMiddleware}, installs `ctx.federation`, bridges Fedify's logs\n * into the AdonisJS logger, builds the federation after the preload files\n * have run, and drains the task queue in the web process.\n */\nexport default class FedifyProvider {\n /**\n * Aborts the queue worker on shutdown.\n */\n #queueController = new AbortController();\n\n /**\n * The `startQueue()` promise, settled once every listener has stopped.\n * `shutdown()` returns it so AdonisJS waits for the workers. Undefined when\n * this process does not drain the queue.\n */\n #queue?: Promise<void>;\n\n /**\n * Whether this provider configured LogTape and must undo it on shutdown.\n *\n * LogTape's configuration is process-global and its sink closes over *this*\n * application's `Logger`. Left in place, a second application in the same\n * process (the test runner, a dev-server restart) would find LogTape already\n * configured and keep logging into the terminated application's logger.\n */\n #loggingConfigured = false;\n\n /**\n * Whether the builder may be sealed into a `Federation` object.\n *\n * Dispatchers are registered in preload files, which AdonisJS imports *after*\n * every provider's `boot()` and `start()`. Building earlier would yield a\n * federation with no routes and 404s as the only symptom, so an early build\n * fails with an explanatory error instead.\n */\n #buildable = false;\n\n /**\n * Whether the HTTP server has started accepting connections.\n *\n * AdonisJS listens inside `start()` and runs `ready()` hooks afterwards, so a\n * request (a health probe, `fedify tunnel`) can arrive before this provider\n * is ready. Such a request is the one caller allowed to *wait* for the\n * federation, since `ready()` is on its way; any other caller (a `start()`\n * hook, a preload file, an Ace command) fails fast because nothing would\n * make it ready while they wait.\n */\n #listening = false;\n\n /**\n * Settles once `ready()` has built the federation: resolved on success,\n * rejected with the configuration error, or with `E_FEDERATION_NOT_READY`\n * when the application shuts down first or {@link READY_TIMEOUT_MS} passes.\n */\n #ready = Promise.withResolvers<void>();\n #readyTimer?: ReturnType<typeof setTimeout>;\n\n /**\n * The memoised middleware binding, kept here so that a failed `ready()` can\n * forget it.\n *\n * A request that arrives while `ready()` is running builds its middleware\n * from a federation that is buildable at that moment. Should `ready()` fail\n * afterwards, that middleware would otherwise stay cached and keep serving\n * federation traffic in an application whose `make('fedify')` fails fast and\n * whose queue never started.\n */\n #middleware?: Memoized<FedifyMiddleware<ContextData>>;\n\n protected app: ApplicationService;\n\n /**\n * Longhand rather than a parameter property, which Node's type stripping\n * does not support; the tests run these sources through it.\n */\n constructor(app: ApplicationService) {\n this.app = app;\n\n // Only requests waiting on `ready()` observe the rejection; without this\n // handler Node would report it as unhandled when nobody was.\n this.#ready.promise.catch(() => {});\n }\n\n /**\n * Registers the container bindings.\n */\n register(): void {\n /**\n * Bound as a value: the builder is a module-level singleton that\n * application code also imports directly, and both routes must reach the\n * same object.\n */\n this.app.container.bindValue(\"fedify.builder\", builder);\n\n this.app.container.bind(\n \"fedify.config\",\n memoizeSuccess(async () => {\n const provider = this.app.config.get<\n ConfigProvider<ResolvedFedifyConfig>\n >(\"fedify\");\n const config = await configProvider.resolve<ResolvedFedifyConfig>(\n this.app,\n provider,\n );\n\n if (!config) {\n throw new E_INVALID_FEDIFY_CONFIG();\n }\n\n return config;\n }),\n );\n\n const buildFederation = memoizeSuccess(async () => {\n const config = await this.app.container.make(\"fedify.config\");\n const federationBuilder = await this.app.container.make(\"fedify.builder\");\n\n return federationBuilder.build(config);\n });\n\n this.app.container.bind(\"fedify\", () => {\n if (!this.#buildable) {\n throw new E_FEDERATION_NOT_READY();\n }\n\n return buildFederation();\n });\n\n /**\n * The middleware, built with the federation and configuration in scope, as\n * `@adonisjs/cors` and `@adonisjs/session` do. `server.use()` resolves\n * the class through the container on every request, which lands here.\n *\n * A plain `bind()` plus {@link memoizeSuccess} rather than `singleton()`\n * (see the helper), so every request shares one instance.\n *\n * A request that arrives after the server listens but before `ready()` has\n * built the federation waits for it (see {@link #listening}); any other\n * caller gets `E_FEDERATION_NOT_READY` at once.\n */\n this.#middleware = memoizeSuccess(async () => {\n if (!this.#buildable) {\n if (!this.#listening) throw new E_FEDERATION_NOT_READY();\n await this.#ready.promise;\n }\n\n const federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n return new FedifyMiddleware<ContextData>(\n federation,\n config.contextDataFactory,\n { ignoreRoutePrefixes: config.ignoreRoutePrefixes },\n );\n });\n\n this.app.container.bind(FedifyMiddleware, this.#middleware);\n }\n\n /**\n * Installs `ctx.federation`, bridges Fedify's logs into the AdonisJS logger,\n * and subscribes to the HTTP server's ready event.\n */\n async boot(): Promise<void> {\n // `ctx.federation` as a Macroable getter on the `HttpContext` prototype.\n // The middleware also installs it on each context's class (covering\n // another `@adonisjs/core` copy); this covers requests the middleware\n // never saw, which then get `E_FEDIFY_CONTEXT_UNAVAILABLE` rather than\n // `undefined`.\n installFederationGetter();\n\n const config = await this.app.container.make(\"fedify.config\");\n\n if (config.logging !== false) {\n const logger = await this.app.container.make(\"logger\");\n this.#loggingConfigured = await configureFedifyLogging({\n logger,\n categories: config.logging === true\n ? undefined\n : config.logging.categories,\n });\n }\n\n // The core `app_provider` binds the emitter; a bare application in a test\n // may lack it, and then has no HTTP server to hear from either.\n if (this.app.container.hasBinding(\"emitter\")) {\n const emitter = await this.app.container.make(\"emitter\");\n emitter.on(\"http:server_ready\", () => this.#serverStarted());\n }\n }\n\n /**\n * Runs after the preload files have registered every dispatcher.\n */\n async ready(): Promise<void> {\n this.#buildable = true;\n\n // Build eagerly so a broken federation surfaces at startup rather than on\n // the first federation request. Requests waiting in the middleware\n // binding get the same outcome.\n let federation: Federation<ContextData>;\n let worker: { contextData: ContextData; logger: Logger } | undefined;\n try {\n federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n // Only the web process drains the queue: Ace commands, the REPL and the\n // test runner also reach `ready()`, where a worker would outlive the\n // command and compete for the queue. The context data is built before\n // the waiting requests are released, so a throwing callback fails\n // startup like a broken federation instead of rejecting `ready()` with\n // requests already being served.\n if (\n typeof config.queueContextData === \"function\" &&\n this.app.getEnvironment() === \"web\"\n ) {\n worker = {\n contextData: await config.queueContextData(),\n logger: await this.app.container.make(\"logger\"),\n };\n }\n } catch (error: unknown) {\n // Back to failing fast: a surviving process (an Ace command, the REPL)\n // must not have later `make('fedify')` calls re-run the configuration,\n // nor keep the middleware a request built while this hook was still\n // running (see {@link #middleware}).\n this.#buildable = false;\n this.#middleware?.forget();\n this.#settle(error);\n throw error;\n }\n this.#settle();\n\n if (worker === undefined) return;\n\n // `shutdown()` can have run while this hook was awaiting above: it settles\n // and aborts, but finds no queue promise to wait for. Starting a worker on\n // the aborted signal now would leave one running that nothing awaits.\n if (this.#queueController.signal.aborted) return;\n\n // `startQueue` settles only when the queue stops, so it must not be\n // awaited here. The promise is kept for `shutdown()`, `catch` included,\n // so awaiting it there never rejects.\n const { contextData, logger } = worker;\n this.#queue = federation\n .startQueue(contextData, { signal: this.#queueController.signal })\n .catch((error: unknown) => {\n if (this.#queueController.signal.aborted) return;\n logger.error(\n { err: error },\n \"The Fedify task queue stopped unexpectedly\",\n );\n });\n }\n\n /**\n * Stops the queue worker and waits for it, releases any request still\n * waiting on `ready()`, and takes the LogTape configuration down.\n *\n * Aborting only *asks* the listeners to stop; `startQueue()` settles once\n * they have, possibly one in-flight delivery later. Returning that promise\n * keeps the rest of the shutdown sequence (closing the database, most\n * importantly) behind it.\n *\n * LogTape is reset after the queue stops, so an outgoing delivery can still\n * log, and only if this provider configured it (see\n * {@link #loggingConfigured}); resetting the application's own\n * configuration would silence its logs.\n *\n * The return type stays a promise even with no queue to wait for: AdonisJS\n * warns when a provider hook returns a non-thenable.\n */\n shutdown(): Promise<void> {\n this.#settle(new E_FEDERATION_NOT_READY());\n this.#queueController.abort();\n\n const stopped = this.#queue ?? Promise.resolve();\n if (!this.#loggingConfigured) return stopped;\n\n this.#loggingConfigured = false;\n // A failing reset must not fail the shutdown queued behind it. The queue\n // promise never rejects, so only the reset is guarded.\n return stopped.then(() => resetLogging().catch(() => {}));\n }\n\n /**\n * Called when the HTTP server starts listening and requests can arrive.\n */\n #serverStarted(): void {\n this.#listening = true;\n if (this.#buildable) return;\n\n this.#readyTimer = setTimeout(\n () => this.#settle(new E_FEDERATION_NOT_READY()),\n READY_TIMEOUT_MS,\n );\n // A pending timer must not keep the process alive.\n this.#readyTimer.unref();\n }\n\n /**\n * Settles the `ready()` promise once; later calls are no-ops.\n */\n #settle(error?: unknown): void {\n clearTimeout(this.#readyTimer);\n if (error === undefined) this.#ready.resolve();\n else this.#ready.reject(error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,mBAAmB;;;;;;;;;;AAgBzB,SAAS,eAAkB,SAAwC;CACjE,IAAI;CAEJ,MAAM,aAAyB;EAC7B,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAmB;GAC7C,SAAS;GACT,MAAM;EACR,CAAC;EAED,OAAO;CACT;CAEA,OAAO,OAAO,OAAO,MAAM,EACzB,cAAoB;EAClB,SAAS;CACX,EACF,CAAC;AACH;;;;;;;;;;AAWA,IAAqB,iBAArB,MAAoC;;;;CAIlC,mBAAmB,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AAKA,iBAAiB,OAAO,SAAS;GAC1C,OAAO,MACL,EAAE,KAAK,MAAM,GACb,4CACF;EACF,CAAC;CACL;;;;;;;;;;;;;;;;;;CAmBA,WAA0B;EACxB,KAAKD,QAAQ,IAAIP,0CAAuB,CAAC;EACzC,KAAKQ,iBAAiB,MAAM;EAE5B,MAAM,UAAU,KAAKC,UAAU,QAAQ,QAAQ;EAC/C,IAAI,CAAC,KAAKL,oBAAoB,OAAO;EAErC,KAAKA,qBAAqB;EAG1B,OAAO,QAAQ,uCAAwB,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;CAC1D;;;;CAKA,iBAAuB;EACrB,KAAKF,aAAa;EAClB,IAAI,KAAKH,YAAY;EAErB,KAAKW,cAAc,iBACX,KAAKH,QAAQ,IAAIP,0CAAuB,CAAC,GAC/C,gBACF;EAEA,KAAKU,YAAY,MAAM;CACzB;;;;CAKA,QAAQ,OAAuB;EAC7B,aAAa,KAAKA,WAAW;EAC7B,IAAI,UAAU,WAAW,KAAKf,OAAO,QAAQ;OACxC,KAAKA,OAAO,OAAO,KAAK;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"fedify_provider.cjs","names":["#ready","builder","configProvider","E_INVALID_FEDIFY_CONFIG","#buildable","E_FEDERATION_NOT_READY","#middleware","#listening","FedifyMiddleware","#loggingConfigured","configureFedifyLogging","#serverStarted","#settle","#queueController","#queue","#readyTimer"],"sources":["../../providers/fedify_provider.ts"],"sourcesContent":["/**\n * The `@fedify/adonisjs` service provider; see {@link FedifyProvider}.\n *\n * @module\n */\nimport { configProvider } from \"@adonisjs/core\";\nimport type { Logger } from \"@adonisjs/core/logger\";\nimport type { ApplicationService, ConfigProvider } from \"@adonisjs/core/types\";\nimport type { Federation } from \"@fedify/fedify\";\nimport { reset as resetLogging } from \"@logtape/logtape\";\n\nimport { builder } from \"../src/builder.ts\";\nimport {\n E_FEDERATION_NOT_READY,\n E_INVALID_FEDIFY_CONFIG,\n} from \"../src/errors.ts\";\nimport FedifyMiddleware from \"../src/fedify_middleware.ts\";\nimport { installFederationGetter } from \"../src/http_context.ts\";\nimport { configureFedifyLogging } from \"../src/logging.ts\";\nimport type { ContextData, ResolvedFedifyConfig } from \"../src/types.ts\";\n\n/**\n * How long a request that arrives before `ready()` waits for the federation.\n *\n * Generous, since it only needs to outlast earlier providers' `ready()` hooks.\n * It turns a `ready()` that never comes (an earlier provider waiting on this\n * server) into an error instead of a request that never completes.\n */\nconst READY_TIMEOUT_MS = 30_000;\n\n/**\n * A memoised factory: the value, plus a way to drop what was cached.\n */\ntype Memoized<T> = (() => Promise<T>) & { forget(): void };\n\n/**\n * Memoises an asynchronous factory, caching successes only.\n *\n * Used for the container bindings instead of `container.singleton()`, which\n * also caches *rejections*: one early, swallowed `make('fedify')` would pin\n * `E_FEDERATION_NOT_READY` for the life of the process. A failed attempt is\n * forgotten instead, so the next caller runs the factory again. `forget()`\n * drops a cached success once the caller knows it is stale.\n */\nfunction memoizeSuccess<T>(factory: () => Promise<T>): Memoized<T> {\n let cached: Promise<T> | undefined;\n\n const memo = (): Promise<T> => {\n cached ??= factory().catch((error: unknown) => {\n cached = undefined;\n throw error;\n });\n\n return cached;\n };\n\n return Object.assign(memo, {\n forget: (): void => {\n cached = undefined;\n },\n });\n}\n\n/**\n * The service provider registered from `adonisrc.ts` as\n * `@fedify/adonisjs/fedify_provider`.\n *\n * Binds `fedify.builder`, `fedify.config`, `fedify` and\n * {@link FedifyMiddleware}, installs `ctx.federation`, bridges Fedify's logs\n * into the AdonisJS logger, builds the federation after the preload files\n * have run, and drains the task queue in the web process.\n */\nexport default class FedifyProvider {\n /**\n * Aborts the queue worker on shutdown.\n */\n #queueController = new AbortController();\n\n /**\n * The `startQueue()` promise, settled once every listener has stopped.\n * `shutdown()` returns it so AdonisJS waits for the workers. Undefined when\n * this process does not drain the queue.\n */\n #queue?: Promise<void>;\n\n /**\n * Whether this provider configured LogTape and must undo it on shutdown.\n *\n * LogTape's configuration is process-global and its sink closes over *this*\n * application's `Logger`. Left in place, a second application in the same\n * process (the test runner, a dev-server restart) would find LogTape already\n * configured and keep logging into the terminated application's logger.\n */\n #loggingConfigured = false;\n\n /**\n * Whether the builder may be sealed into a `Federation` object.\n *\n * Dispatchers are registered in preload files, which AdonisJS imports *after*\n * every provider's `boot()` and `start()`. Building earlier would yield a\n * federation with no routes and 404s as the only symptom, so an early build\n * fails with an explanatory error instead.\n */\n #buildable = false;\n\n /**\n * Whether the HTTP server has started accepting connections.\n *\n * AdonisJS listens inside `start()` and runs `ready()` hooks afterwards, so a\n * request (a health probe, `fedify tunnel`) can arrive before this provider\n * is ready. Such a request is the one caller allowed to *wait* for the\n * federation, since `ready()` is on its way; any other caller (a `start()`\n * hook, a preload file, an Ace command) fails fast because nothing would\n * make it ready while they wait.\n */\n #listening = false;\n\n /**\n * Settles once `ready()` has built the federation: resolved on success,\n * rejected with the configuration error, or with `E_FEDERATION_NOT_READY`\n * when the application shuts down first or {@link READY_TIMEOUT_MS} passes.\n */\n #ready = Promise.withResolvers<void>();\n #readyTimer?: ReturnType<typeof setTimeout>;\n\n /**\n * The memoised middleware binding, kept here so that a failed `ready()` can\n * forget it.\n *\n * A request that arrives while `ready()` is running builds its middleware\n * from a federation that is buildable at that moment. Should `ready()` fail\n * afterwards, that middleware would otherwise stay cached and keep serving\n * federation traffic in an application whose `make('fedify')` fails fast and\n * whose queue never started.\n */\n #middleware?: Memoized<FedifyMiddleware<ContextData>>;\n\n protected app: ApplicationService;\n\n /**\n * Longhand rather than a parameter property, which Node's type stripping\n * does not support; the tests run these sources through it.\n */\n constructor(app: ApplicationService) {\n this.app = app;\n\n // Only requests waiting on `ready()` observe the rejection; without this\n // handler Node would report it as unhandled when nobody was.\n this.#ready.promise.catch(() => {});\n }\n\n /**\n * Registers the container bindings.\n */\n register(): void {\n /**\n * Bound as a value: the builder is a module-level singleton that\n * application code also imports directly, and both routes must reach the\n * same object.\n */\n this.app.container.bindValue(\"fedify.builder\", builder);\n\n this.app.container.bind(\n \"fedify.config\",\n memoizeSuccess(async () => {\n const provider = this.app.config.get<\n ConfigProvider<ResolvedFedifyConfig>\n >(\"fedify\");\n const config = await configProvider.resolve<ResolvedFedifyConfig>(\n this.app,\n provider,\n );\n\n if (!config) {\n throw new E_INVALID_FEDIFY_CONFIG();\n }\n\n return config;\n }),\n );\n\n const buildFederation = memoizeSuccess(async () => {\n const config = await this.app.container.make(\"fedify.config\");\n const federationBuilder = await this.app.container.make(\"fedify.builder\");\n\n return federationBuilder.build(config);\n });\n\n this.app.container.bind(\"fedify\", () => {\n if (!this.#buildable) {\n throw new E_FEDERATION_NOT_READY();\n }\n\n return buildFederation();\n });\n\n /**\n * The middleware, built with the federation and configuration in scope, as\n * `@adonisjs/cors` and `@adonisjs/session` do. `server.use()` resolves\n * the class through the container on every request, which lands here.\n *\n * A plain `bind()` plus {@link memoizeSuccess} rather than `singleton()`\n * (see the helper), so every request shares one instance.\n *\n * A request that arrives after the server listens but before `ready()` has\n * built the federation waits for it (see {@link #listening}); any other\n * caller gets `E_FEDERATION_NOT_READY` at once.\n */\n this.#middleware = memoizeSuccess(async () => {\n if (!this.#buildable) {\n if (!this.#listening) throw new E_FEDERATION_NOT_READY();\n await this.#ready.promise;\n }\n\n const federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n return new FedifyMiddleware<ContextData>(\n federation,\n config.contextDataFactory,\n { ignoreRoutePrefixes: config.ignoreRoutePrefixes },\n );\n });\n\n this.app.container.bind(FedifyMiddleware, this.#middleware);\n }\n\n /**\n * Installs `ctx.federation`, bridges Fedify's logs into the AdonisJS logger,\n * and subscribes to the HTTP server's ready event.\n */\n async boot(): Promise<void> {\n // `ctx.federation` as a Macroable getter on the `HttpContext` prototype.\n // The middleware also installs it on each context's class (covering\n // another `@adonisjs/core` copy); this covers requests the middleware\n // never saw, which then get `E_FEDIFY_CONTEXT_UNAVAILABLE` rather than\n // `undefined`.\n installFederationGetter();\n\n const config = await this.app.container.make(\"fedify.config\");\n\n if (config.logging !== false) {\n const logger = await this.app.container.make(\"logger\");\n this.#loggingConfigured = await configureFedifyLogging({\n logger,\n categories: config.logging === true\n ? undefined\n : config.logging.categories,\n });\n }\n\n // The core `app_provider` binds the emitter; a bare application in a test\n // may lack it, and then has no HTTP server to hear from either.\n if (this.app.container.hasBinding(\"emitter\")) {\n const emitter = await this.app.container.make(\"emitter\");\n emitter.on(\"http:server_ready\", () => this.#serverStarted());\n }\n }\n\n /**\n * Runs after the preload files have registered every dispatcher.\n */\n async ready(): Promise<void> {\n this.#buildable = true;\n\n // Build eagerly so a broken federation surfaces at startup rather than on\n // the first federation request. Requests waiting in the middleware\n // binding get the same outcome.\n let federation: Federation<ContextData>;\n let worker: { contextData: ContextData; logger: Logger } | undefined;\n try {\n federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n // Only the web process drains the queue: Ace commands, the REPL and the\n // test runner also reach `ready()`, where a worker would outlive the\n // command and compete for the queue. The context data is built before\n // the waiting requests are released, so a throwing callback fails\n // startup like a broken federation instead of rejecting `ready()` with\n // requests already being served.\n if (\n typeof config.queueContextData === \"function\" &&\n this.app.getEnvironment() === \"web\"\n ) {\n worker = {\n contextData: await config.queueContextData(),\n logger: await this.app.container.make(\"logger\"),\n };\n }\n } catch (error: unknown) {\n // Back to failing fast: a surviving process (an Ace command, the REPL)\n // must not have later `make('fedify')` calls re-run the configuration,\n // nor keep the middleware a request built while this hook was still\n // running (see {@link #middleware}).\n this.#buildable = false;\n this.#middleware?.forget();\n this.#settle(error);\n throw error;\n }\n this.#settle();\n\n if (worker === undefined) return;\n\n // `shutdown()` can have run while this hook was awaiting above: it settles\n // and aborts, but finds no queue promise to wait for. Starting a worker on\n // the aborted signal now would leave one running that nothing awaits.\n if (this.#queueController.signal.aborted) return;\n\n // `startQueue` settles only when the queue stops, so it must not be\n // awaited here. The promise is kept for `shutdown()`, `catch` included,\n // so awaiting it there never rejects.\n const { contextData, logger } = worker;\n this.#queue = federation\n .startQueue(contextData, { signal: this.#queueController.signal })\n .catch((error: unknown) => {\n if (this.#queueController.signal.aborted) return;\n logger.error(\n { err: error },\n \"The Fedify task queue stopped unexpectedly\",\n );\n });\n }\n\n /**\n * Stops the queue worker and waits for it, releases any request still\n * waiting on `ready()`, and takes the LogTape configuration down.\n *\n * Aborting only *asks* the listeners to stop; `startQueue()` settles once\n * they have, possibly one in-flight delivery later. Returning that promise\n * keeps the rest of the shutdown sequence (closing the database, most\n * importantly) behind it.\n *\n * LogTape is reset after the queue stops, so an outgoing delivery can still\n * log, and only if this provider configured it (see\n * {@link #loggingConfigured}); resetting the application's own\n * configuration would silence its logs.\n *\n * The return type stays a promise even with no queue to wait for: AdonisJS\n * warns when a provider hook returns a non-thenable.\n */\n shutdown(): Promise<void> {\n this.#settle(new E_FEDERATION_NOT_READY());\n this.#queueController.abort();\n\n const stopped = this.#queue ?? Promise.resolve();\n if (!this.#loggingConfigured) return stopped;\n\n this.#loggingConfigured = false;\n // A failing reset must not fail the shutdown queued behind it. The queue\n // promise never rejects, so only the reset is guarded.\n return stopped.then(async () => {\n try {\n await resetLogging();\n } catch {\n // Reset failures must not fail the shutdown queued behind them.\n }\n });\n }\n\n /**\n * Called when the HTTP server starts listening and requests can arrive.\n */\n #serverStarted(): void {\n this.#listening = true;\n if (this.#buildable) return;\n\n this.#readyTimer = setTimeout(\n () => this.#settle(new E_FEDERATION_NOT_READY()),\n READY_TIMEOUT_MS,\n );\n // A pending timer must not keep the process alive.\n this.#readyTimer.unref();\n }\n\n /**\n * Settles the `ready()` promise once; later calls are no-ops.\n */\n #settle(error?: unknown): void {\n clearTimeout(this.#readyTimer);\n if (error === undefined) this.#ready.resolve();\n else this.#ready.reject(error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,mBAAmB;;;;;;;;;;AAgBzB,SAAS,eAAkB,SAAwC;CACjE,IAAI;CAEJ,MAAM,aAAyB;EAC7B,WAAW,QAAQ,CAAC,CAA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WAAW,WAAW;EAK1B,IAAI,KAAKC,iBAAiB,OAAO,SAAS;EAK1C,MAAM,EAAE,aAAa,WAAW;EAChC,KAAKC,SAAS,WACX,WAAW,aAAa,EAAE,QAAQ,KAAKD,iBAAiB,OAAO,CAAC,CAAC,CACjE,OAAO,UAAmB;GACzB,IAAI,KAAKA,iBAAiB,OAAO,SAAS;GAC1C,OAAO,MACL,EAAE,KAAK,MAAM,GACb,4CACF;EACF,CAAC;CACL;;;;;;;;;;;;;;;;;;CAmBA,WAA0B;EACxB,KAAKD,QAAQ,IAAIP,0CAAuB,CAAC;EACzC,KAAKQ,iBAAiB,MAAM;EAE5B,MAAM,UAAU,KAAKC,UAAU,QAAQ,QAAQ;EAC/C,IAAI,CAAC,KAAKL,oBAAoB,OAAO;EAErC,KAAKA,qBAAqB;EAG1B,OAAO,QAAQ,KAAK,YAAY;GAC9B,IAAI;IACF,kCAAmB;GACrB,QAAQ,CAER;EACF,CAAC;CACH;;;;CAKA,iBAAuB;EACrB,KAAKF,aAAa;EAClB,IAAI,KAAKH,YAAY;EAErB,KAAKW,cAAc,iBACX,KAAKH,QAAQ,IAAIP,0CAAuB,CAAC,GAC/C,gBACF;EAEA,KAAKU,YAAY,MAAM;CACzB;;;;CAKA,QAAQ,OAAuB;EAC7B,aAAa,KAAKA,WAAW;EAC7B,IAAI,UAAU,WAAW,KAAKf,OAAO,QAAQ;OACxC,KAAKA,OAAO,OAAO,KAAK;CAC/B;AACF"}
|
|
@@ -243,7 +243,11 @@ var FedifyProvider = class {
|
|
|
243
243
|
const stopped = this.#queue ?? Promise.resolve();
|
|
244
244
|
if (!this.#loggingConfigured) return stopped;
|
|
245
245
|
this.#loggingConfigured = false;
|
|
246
|
-
return stopped.then(
|
|
246
|
+
return stopped.then(async () => {
|
|
247
|
+
try {
|
|
248
|
+
await reset();
|
|
249
|
+
} catch {}
|
|
250
|
+
});
|
|
247
251
|
}
|
|
248
252
|
/**
|
|
249
253
|
* Called when the HTTP server starts listening and requests can arrive.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fedify_provider.js","names":["#ready","#buildable","#middleware","#listening","#loggingConfigured","#serverStarted","#settle","#queueController","#queue","resetLogging","#readyTimer"],"sources":["../../providers/fedify_provider.ts"],"sourcesContent":["/**\n * The `@fedify/adonisjs` service provider; see {@link FedifyProvider}.\n *\n * @module\n */\nimport { configProvider } from \"@adonisjs/core\";\nimport type { Logger } from \"@adonisjs/core/logger\";\nimport type { ApplicationService, ConfigProvider } from \"@adonisjs/core/types\";\nimport type { Federation } from \"@fedify/fedify\";\nimport { reset as resetLogging } from \"@logtape/logtape\";\n\nimport { builder } from \"../src/builder.ts\";\nimport {\n E_FEDERATION_NOT_READY,\n E_INVALID_FEDIFY_CONFIG,\n} from \"../src/errors.ts\";\nimport FedifyMiddleware from \"../src/fedify_middleware.ts\";\nimport { installFederationGetter } from \"../src/http_context.ts\";\nimport { configureFedifyLogging } from \"../src/logging.ts\";\nimport type { ContextData, ResolvedFedifyConfig } from \"../src/types.ts\";\n\n/**\n * How long a request that arrives before `ready()` waits for the federation.\n *\n * Generous, since it only needs to outlast earlier providers' `ready()` hooks.\n * It turns a `ready()` that never comes (an earlier provider waiting on this\n * server) into an error instead of a request that never completes.\n */\nconst READY_TIMEOUT_MS = 30_000;\n\n/**\n * A memoised factory: the value, plus a way to drop what was cached.\n */\ntype Memoized<T> = (() => Promise<T>) & { forget(): void };\n\n/**\n * Memoises an asynchronous factory, caching successes only.\n *\n * Used for the container bindings instead of `container.singleton()`, which\n * also caches *rejections*: one early, swallowed `make('fedify')` would pin\n * `E_FEDERATION_NOT_READY` for the life of the process. A failed attempt is\n * forgotten instead, so the next caller runs the factory again. `forget()`\n * drops a cached success once the caller knows it is stale.\n */\nfunction memoizeSuccess<T>(factory: () => Promise<T>): Memoized<T> {\n let cached: Promise<T> | undefined;\n\n const memo = (): Promise<T> => {\n cached ??= factory().catch((error: unknown) => {\n cached = undefined;\n throw error;\n });\n\n return cached;\n };\n\n return Object.assign(memo, {\n forget: (): void => {\n cached = undefined;\n },\n });\n}\n\n/**\n * The service provider registered from `adonisrc.ts` as\n * `@fedify/adonisjs/fedify_provider`.\n *\n * Binds `fedify.builder`, `fedify.config`, `fedify` and\n * {@link FedifyMiddleware}, installs `ctx.federation`, bridges Fedify's logs\n * into the AdonisJS logger, builds the federation after the preload files\n * have run, and drains the task queue in the web process.\n */\nexport default class FedifyProvider {\n /**\n * Aborts the queue worker on shutdown.\n */\n #queueController = new AbortController();\n\n /**\n * The `startQueue()` promise, settled once every listener has stopped.\n * `shutdown()` returns it so AdonisJS waits for the workers. Undefined when\n * this process does not drain the queue.\n */\n #queue?: Promise<void>;\n\n /**\n * Whether this provider configured LogTape and must undo it on shutdown.\n *\n * LogTape's configuration is process-global and its sink closes over *this*\n * application's `Logger`. Left in place, a second application in the same\n * process (the test runner, a dev-server restart) would find LogTape already\n * configured and keep logging into the terminated application's logger.\n */\n #loggingConfigured = false;\n\n /**\n * Whether the builder may be sealed into a `Federation` object.\n *\n * Dispatchers are registered in preload files, which AdonisJS imports *after*\n * every provider's `boot()` and `start()`. Building earlier would yield a\n * federation with no routes and 404s as the only symptom, so an early build\n * fails with an explanatory error instead.\n */\n #buildable = false;\n\n /**\n * Whether the HTTP server has started accepting connections.\n *\n * AdonisJS listens inside `start()` and runs `ready()` hooks afterwards, so a\n * request (a health probe, `fedify tunnel`) can arrive before this provider\n * is ready. Such a request is the one caller allowed to *wait* for the\n * federation, since `ready()` is on its way; any other caller (a `start()`\n * hook, a preload file, an Ace command) fails fast because nothing would\n * make it ready while they wait.\n */\n #listening = false;\n\n /**\n * Settles once `ready()` has built the federation: resolved on success,\n * rejected with the configuration error, or with `E_FEDERATION_NOT_READY`\n * when the application shuts down first or {@link READY_TIMEOUT_MS} passes.\n */\n #ready = Promise.withResolvers<void>();\n #readyTimer?: ReturnType<typeof setTimeout>;\n\n /**\n * The memoised middleware binding, kept here so that a failed `ready()` can\n * forget it.\n *\n * A request that arrives while `ready()` is running builds its middleware\n * from a federation that is buildable at that moment. Should `ready()` fail\n * afterwards, that middleware would otherwise stay cached and keep serving\n * federation traffic in an application whose `make('fedify')` fails fast and\n * whose queue never started.\n */\n #middleware?: Memoized<FedifyMiddleware<ContextData>>;\n\n protected app: ApplicationService;\n\n /**\n * Longhand rather than a parameter property, which Node's type stripping\n * does not support; the tests run these sources through it.\n */\n constructor(app: ApplicationService) {\n this.app = app;\n\n // Only requests waiting on `ready()` observe the rejection; without this\n // handler Node would report it as unhandled when nobody was.\n this.#ready.promise.catch(() => {});\n }\n\n /**\n * Registers the container bindings.\n */\n register(): void {\n /**\n * Bound as a value: the builder is a module-level singleton that\n * application code also imports directly, and both routes must reach the\n * same object.\n */\n this.app.container.bindValue(\"fedify.builder\", builder);\n\n this.app.container.bind(\n \"fedify.config\",\n memoizeSuccess(async () => {\n const provider = this.app.config.get<\n ConfigProvider<ResolvedFedifyConfig>\n >(\"fedify\");\n const config = await configProvider.resolve<ResolvedFedifyConfig>(\n this.app,\n provider,\n );\n\n if (!config) {\n throw new E_INVALID_FEDIFY_CONFIG();\n }\n\n return config;\n }),\n );\n\n const buildFederation = memoizeSuccess(async () => {\n const config = await this.app.container.make(\"fedify.config\");\n const federationBuilder = await this.app.container.make(\"fedify.builder\");\n\n return federationBuilder.build(config);\n });\n\n this.app.container.bind(\"fedify\", () => {\n if (!this.#buildable) {\n throw new E_FEDERATION_NOT_READY();\n }\n\n return buildFederation();\n });\n\n /**\n * The middleware, built with the federation and configuration in scope, as\n * `@adonisjs/cors` and `@adonisjs/session` do. `server.use()` resolves\n * the class through the container on every request, which lands here.\n *\n * A plain `bind()` plus {@link memoizeSuccess} rather than `singleton()`\n * (see the helper), so every request shares one instance.\n *\n * A request that arrives after the server listens but before `ready()` has\n * built the federation waits for it (see {@link #listening}); any other\n * caller gets `E_FEDERATION_NOT_READY` at once.\n */\n this.#middleware = memoizeSuccess(async () => {\n if (!this.#buildable) {\n if (!this.#listening) throw new E_FEDERATION_NOT_READY();\n await this.#ready.promise;\n }\n\n const federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n return new FedifyMiddleware<ContextData>(\n federation,\n config.contextDataFactory,\n { ignoreRoutePrefixes: config.ignoreRoutePrefixes },\n );\n });\n\n this.app.container.bind(FedifyMiddleware, this.#middleware);\n }\n\n /**\n * Installs `ctx.federation`, bridges Fedify's logs into the AdonisJS logger,\n * and subscribes to the HTTP server's ready event.\n */\n async boot(): Promise<void> {\n // `ctx.federation` as a Macroable getter on the `HttpContext` prototype.\n // The middleware also installs it on each context's class (covering\n // another `@adonisjs/core` copy); this covers requests the middleware\n // never saw, which then get `E_FEDIFY_CONTEXT_UNAVAILABLE` rather than\n // `undefined`.\n installFederationGetter();\n\n const config = await this.app.container.make(\"fedify.config\");\n\n if (config.logging !== false) {\n const logger = await this.app.container.make(\"logger\");\n this.#loggingConfigured = await configureFedifyLogging({\n logger,\n categories: config.logging === true\n ? undefined\n : config.logging.categories,\n });\n }\n\n // The core `app_provider` binds the emitter; a bare application in a test\n // may lack it, and then has no HTTP server to hear from either.\n if (this.app.container.hasBinding(\"emitter\")) {\n const emitter = await this.app.container.make(\"emitter\");\n emitter.on(\"http:server_ready\", () => this.#serverStarted());\n }\n }\n\n /**\n * Runs after the preload files have registered every dispatcher.\n */\n async ready(): Promise<void> {\n this.#buildable = true;\n\n // Build eagerly so a broken federation surfaces at startup rather than on\n // the first federation request. Requests waiting in the middleware\n // binding get the same outcome.\n let federation: Federation<ContextData>;\n let worker: { contextData: ContextData; logger: Logger } | undefined;\n try {\n federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n // Only the web process drains the queue: Ace commands, the REPL and the\n // test runner also reach `ready()`, where a worker would outlive the\n // command and compete for the queue. The context data is built before\n // the waiting requests are released, so a throwing callback fails\n // startup like a broken federation instead of rejecting `ready()` with\n // requests already being served.\n if (\n typeof config.queueContextData === \"function\" &&\n this.app.getEnvironment() === \"web\"\n ) {\n worker = {\n contextData: await config.queueContextData(),\n logger: await this.app.container.make(\"logger\"),\n };\n }\n } catch (error: unknown) {\n // Back to failing fast: a surviving process (an Ace command, the REPL)\n // must not have later `make('fedify')` calls re-run the configuration,\n // nor keep the middleware a request built while this hook was still\n // running (see {@link #middleware}).\n this.#buildable = false;\n this.#middleware?.forget();\n this.#settle(error);\n throw error;\n }\n this.#settle();\n\n if (worker === undefined) return;\n\n // `shutdown()` can have run while this hook was awaiting above: it settles\n // and aborts, but finds no queue promise to wait for. Starting a worker on\n // the aborted signal now would leave one running that nothing awaits.\n if (this.#queueController.signal.aborted) return;\n\n // `startQueue` settles only when the queue stops, so it must not be\n // awaited here. The promise is kept for `shutdown()`, `catch` included,\n // so awaiting it there never rejects.\n const { contextData, logger } = worker;\n this.#queue = federation\n .startQueue(contextData, { signal: this.#queueController.signal })\n .catch((error: unknown) => {\n if (this.#queueController.signal.aborted) return;\n logger.error(\n { err: error },\n \"The Fedify task queue stopped unexpectedly\",\n );\n });\n }\n\n /**\n * Stops the queue worker and waits for it, releases any request still\n * waiting on `ready()`, and takes the LogTape configuration down.\n *\n * Aborting only *asks* the listeners to stop; `startQueue()` settles once\n * they have, possibly one in-flight delivery later. Returning that promise\n * keeps the rest of the shutdown sequence (closing the database, most\n * importantly) behind it.\n *\n * LogTape is reset after the queue stops, so an outgoing delivery can still\n * log, and only if this provider configured it (see\n * {@link #loggingConfigured}); resetting the application's own\n * configuration would silence its logs.\n *\n * The return type stays a promise even with no queue to wait for: AdonisJS\n * warns when a provider hook returns a non-thenable.\n */\n shutdown(): Promise<void> {\n this.#settle(new E_FEDERATION_NOT_READY());\n this.#queueController.abort();\n\n const stopped = this.#queue ?? Promise.resolve();\n if (!this.#loggingConfigured) return stopped;\n\n this.#loggingConfigured = false;\n // A failing reset must not fail the shutdown queued behind it. The queue\n // promise never rejects, so only the reset is guarded.\n return stopped.then(() => resetLogging().catch(() => {}));\n }\n\n /**\n * Called when the HTTP server starts listening and requests can arrive.\n */\n #serverStarted(): void {\n this.#listening = true;\n if (this.#buildable) return;\n\n this.#readyTimer = setTimeout(\n () => this.#settle(new E_FEDERATION_NOT_READY()),\n READY_TIMEOUT_MS,\n );\n // A pending timer must not keep the process alive.\n this.#readyTimer.unref();\n }\n\n /**\n * Settles the `ready()` promise once; later calls are no-ops.\n */\n #settle(error?: unknown): void {\n clearTimeout(this.#readyTimer);\n if (error === undefined) this.#ready.resolve();\n else this.#ready.reject(error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,mBAAmB;;;;;;;;;;AAgBzB,SAAS,eAAkB,SAAwC;CACjE,IAAI;CAEJ,MAAM,aAAyB;EAC7B,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAmB;GAC7C,SAAS;GACT,MAAM;EACR,CAAC;EAED,OAAO;CACT;CAEA,OAAO,OAAO,OAAO,MAAM,EACzB,cAAoB;EAClB,SAAS;CACX,EACF,CAAC;AACH;;;;;;;;;;AAWA,IAAqB,iBAArB,MAAoC;;;;CAIlC,mBAAmB,IAAI,gBAAgB;;;;;;CAOvC;;;;;;;;;CAUA,qBAAqB;;;;;;;;;CAUrB,aAAa;;;;;;;;;;;CAYb,aAAa;;;;;;CAOb,SAAS,QAAQ,cAAoB;CACrC;;;;;;;;;;;CAYA;CAEA,AAAU;;;;;CAMV,YAAY,KAAyB;EACnC,KAAK,MAAM;EAIX,KAAKA,OAAO,QAAQ,YAAY,CAAC,CAAC;CACpC;;;;CAKA,WAAiB;;;;;;EAMf,KAAK,IAAI,UAAU,UAAU,kBAAkB,OAAO;EAEtD,KAAK,IAAI,UAAU,KACjB,iBACA,eAAe,YAAY;GACzB,MAAM,WAAW,KAAK,IAAI,OAAO,IAE/B,QAAQ;GACV,MAAM,SAAS,MAAM,eAAe,QAClC,KAAK,KACL,QACF;GAEA,IAAI,CAAC,QAAQ;IACX,MAAM,IAAI,wBAAwB;GACpC;GAEA,OAAO;EACT,CAAC,CACH;EAEA,MAAM,kBA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KA,WAAW;EAC7B,IAAI,UAAU,WAAW,KAAKV,OAAO,QAAQ;OACxC,KAAKA,OAAO,OAAO,KAAK;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"fedify_provider.js","names":["#ready","#buildable","#middleware","#listening","#loggingConfigured","#serverStarted","#settle","#queueController","#queue","resetLogging","#readyTimer"],"sources":["../../providers/fedify_provider.ts"],"sourcesContent":["/**\n * The `@fedify/adonisjs` service provider; see {@link FedifyProvider}.\n *\n * @module\n */\nimport { configProvider } from \"@adonisjs/core\";\nimport type { Logger } from \"@adonisjs/core/logger\";\nimport type { ApplicationService, ConfigProvider } from \"@adonisjs/core/types\";\nimport type { Federation } from \"@fedify/fedify\";\nimport { reset as resetLogging } from \"@logtape/logtape\";\n\nimport { builder } from \"../src/builder.ts\";\nimport {\n E_FEDERATION_NOT_READY,\n E_INVALID_FEDIFY_CONFIG,\n} from \"../src/errors.ts\";\nimport FedifyMiddleware from \"../src/fedify_middleware.ts\";\nimport { installFederationGetter } from \"../src/http_context.ts\";\nimport { configureFedifyLogging } from \"../src/logging.ts\";\nimport type { ContextData, ResolvedFedifyConfig } from \"../src/types.ts\";\n\n/**\n * How long a request that arrives before `ready()` waits for the federation.\n *\n * Generous, since it only needs to outlast earlier providers' `ready()` hooks.\n * It turns a `ready()` that never comes (an earlier provider waiting on this\n * server) into an error instead of a request that never completes.\n */\nconst READY_TIMEOUT_MS = 30_000;\n\n/**\n * A memoised factory: the value, plus a way to drop what was cached.\n */\ntype Memoized<T> = (() => Promise<T>) & { forget(): void };\n\n/**\n * Memoises an asynchronous factory, caching successes only.\n *\n * Used for the container bindings instead of `container.singleton()`, which\n * also caches *rejections*: one early, swallowed `make('fedify')` would pin\n * `E_FEDERATION_NOT_READY` for the life of the process. A failed attempt is\n * forgotten instead, so the next caller runs the factory again. `forget()`\n * drops a cached success once the caller knows it is stale.\n */\nfunction memoizeSuccess<T>(factory: () => Promise<T>): Memoized<T> {\n let cached: Promise<T> | undefined;\n\n const memo = (): Promise<T> => {\n cached ??= factory().catch((error: unknown) => {\n cached = undefined;\n throw error;\n });\n\n return cached;\n };\n\n return Object.assign(memo, {\n forget: (): void => {\n cached = undefined;\n },\n });\n}\n\n/**\n * The service provider registered from `adonisrc.ts` as\n * `@fedify/adonisjs/fedify_provider`.\n *\n * Binds `fedify.builder`, `fedify.config`, `fedify` and\n * {@link FedifyMiddleware}, installs `ctx.federation`, bridges Fedify's logs\n * into the AdonisJS logger, builds the federation after the preload files\n * have run, and drains the task queue in the web process.\n */\nexport default class FedifyProvider {\n /**\n * Aborts the queue worker on shutdown.\n */\n #queueController = new AbortController();\n\n /**\n * The `startQueue()` promise, settled once every listener has stopped.\n * `shutdown()` returns it so AdonisJS waits for the workers. Undefined when\n * this process does not drain the queue.\n */\n #queue?: Promise<void>;\n\n /**\n * Whether this provider configured LogTape and must undo it on shutdown.\n *\n * LogTape's configuration is process-global and its sink closes over *this*\n * application's `Logger`. Left in place, a second application in the same\n * process (the test runner, a dev-server restart) would find LogTape already\n * configured and keep logging into the terminated application's logger.\n */\n #loggingConfigured = false;\n\n /**\n * Whether the builder may be sealed into a `Federation` object.\n *\n * Dispatchers are registered in preload files, which AdonisJS imports *after*\n * every provider's `boot()` and `start()`. Building earlier would yield a\n * federation with no routes and 404s as the only symptom, so an early build\n * fails with an explanatory error instead.\n */\n #buildable = false;\n\n /**\n * Whether the HTTP server has started accepting connections.\n *\n * AdonisJS listens inside `start()` and runs `ready()` hooks afterwards, so a\n * request (a health probe, `fedify tunnel`) can arrive before this provider\n * is ready. Such a request is the one caller allowed to *wait* for the\n * federation, since `ready()` is on its way; any other caller (a `start()`\n * hook, a preload file, an Ace command) fails fast because nothing would\n * make it ready while they wait.\n */\n #listening = false;\n\n /**\n * Settles once `ready()` has built the federation: resolved on success,\n * rejected with the configuration error, or with `E_FEDERATION_NOT_READY`\n * when the application shuts down first or {@link READY_TIMEOUT_MS} passes.\n */\n #ready = Promise.withResolvers<void>();\n #readyTimer?: ReturnType<typeof setTimeout>;\n\n /**\n * The memoised middleware binding, kept here so that a failed `ready()` can\n * forget it.\n *\n * A request that arrives while `ready()` is running builds its middleware\n * from a federation that is buildable at that moment. Should `ready()` fail\n * afterwards, that middleware would otherwise stay cached and keep serving\n * federation traffic in an application whose `make('fedify')` fails fast and\n * whose queue never started.\n */\n #middleware?: Memoized<FedifyMiddleware<ContextData>>;\n\n protected app: ApplicationService;\n\n /**\n * Longhand rather than a parameter property, which Node's type stripping\n * does not support; the tests run these sources through it.\n */\n constructor(app: ApplicationService) {\n this.app = app;\n\n // Only requests waiting on `ready()` observe the rejection; without this\n // handler Node would report it as unhandled when nobody was.\n this.#ready.promise.catch(() => {});\n }\n\n /**\n * Registers the container bindings.\n */\n register(): void {\n /**\n * Bound as a value: the builder is a module-level singleton that\n * application code also imports directly, and both routes must reach the\n * same object.\n */\n this.app.container.bindValue(\"fedify.builder\", builder);\n\n this.app.container.bind(\n \"fedify.config\",\n memoizeSuccess(async () => {\n const provider = this.app.config.get<\n ConfigProvider<ResolvedFedifyConfig>\n >(\"fedify\");\n const config = await configProvider.resolve<ResolvedFedifyConfig>(\n this.app,\n provider,\n );\n\n if (!config) {\n throw new E_INVALID_FEDIFY_CONFIG();\n }\n\n return config;\n }),\n );\n\n const buildFederation = memoizeSuccess(async () => {\n const config = await this.app.container.make(\"fedify.config\");\n const federationBuilder = await this.app.container.make(\"fedify.builder\");\n\n return federationBuilder.build(config);\n });\n\n this.app.container.bind(\"fedify\", () => {\n if (!this.#buildable) {\n throw new E_FEDERATION_NOT_READY();\n }\n\n return buildFederation();\n });\n\n /**\n * The middleware, built with the federation and configuration in scope, as\n * `@adonisjs/cors` and `@adonisjs/session` do. `server.use()` resolves\n * the class through the container on every request, which lands here.\n *\n * A plain `bind()` plus {@link memoizeSuccess} rather than `singleton()`\n * (see the helper), so every request shares one instance.\n *\n * A request that arrives after the server listens but before `ready()` has\n * built the federation waits for it (see {@link #listening}); any other\n * caller gets `E_FEDERATION_NOT_READY` at once.\n */\n this.#middleware = memoizeSuccess(async () => {\n if (!this.#buildable) {\n if (!this.#listening) throw new E_FEDERATION_NOT_READY();\n await this.#ready.promise;\n }\n\n const federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n return new FedifyMiddleware<ContextData>(\n federation,\n config.contextDataFactory,\n { ignoreRoutePrefixes: config.ignoreRoutePrefixes },\n );\n });\n\n this.app.container.bind(FedifyMiddleware, this.#middleware);\n }\n\n /**\n * Installs `ctx.federation`, bridges Fedify's logs into the AdonisJS logger,\n * and subscribes to the HTTP server's ready event.\n */\n async boot(): Promise<void> {\n // `ctx.federation` as a Macroable getter on the `HttpContext` prototype.\n // The middleware also installs it on each context's class (covering\n // another `@adonisjs/core` copy); this covers requests the middleware\n // never saw, which then get `E_FEDIFY_CONTEXT_UNAVAILABLE` rather than\n // `undefined`.\n installFederationGetter();\n\n const config = await this.app.container.make(\"fedify.config\");\n\n if (config.logging !== false) {\n const logger = await this.app.container.make(\"logger\");\n this.#loggingConfigured = await configureFedifyLogging({\n logger,\n categories: config.logging === true\n ? undefined\n : config.logging.categories,\n });\n }\n\n // The core `app_provider` binds the emitter; a bare application in a test\n // may lack it, and then has no HTTP server to hear from either.\n if (this.app.container.hasBinding(\"emitter\")) {\n const emitter = await this.app.container.make(\"emitter\");\n emitter.on(\"http:server_ready\", () => this.#serverStarted());\n }\n }\n\n /**\n * Runs after the preload files have registered every dispatcher.\n */\n async ready(): Promise<void> {\n this.#buildable = true;\n\n // Build eagerly so a broken federation surfaces at startup rather than on\n // the first federation request. Requests waiting in the middleware\n // binding get the same outcome.\n let federation: Federation<ContextData>;\n let worker: { contextData: ContextData; logger: Logger } | undefined;\n try {\n federation = await this.app.container.make(\"fedify\");\n const config = await this.app.container.make(\"fedify.config\");\n\n // Only the web process drains the queue: Ace commands, the REPL and the\n // test runner also reach `ready()`, where a worker would outlive the\n // command and compete for the queue. The context data is built before\n // the waiting requests are released, so a throwing callback fails\n // startup like a broken federation instead of rejecting `ready()` with\n // requests already being served.\n if (\n typeof config.queueContextData === \"function\" &&\n this.app.getEnvironment() === \"web\"\n ) {\n worker = {\n contextData: await config.queueContextData(),\n logger: await this.app.container.make(\"logger\"),\n };\n }\n } catch (error: unknown) {\n // Back to failing fast: a surviving process (an Ace command, the REPL)\n // must not have later `make('fedify')` calls re-run the configuration,\n // nor keep the middleware a request built while this hook was still\n // running (see {@link #middleware}).\n this.#buildable = false;\n this.#middleware?.forget();\n this.#settle(error);\n throw error;\n }\n this.#settle();\n\n if (worker === undefined) return;\n\n // `shutdown()` can have run while this hook was awaiting above: it settles\n // and aborts, but finds no queue promise to wait for. Starting a worker on\n // the aborted signal now would leave one running that nothing awaits.\n if (this.#queueController.signal.aborted) return;\n\n // `startQueue` settles only when the queue stops, so it must not be\n // awaited here. The promise is kept for `shutdown()`, `catch` included,\n // so awaiting it there never rejects.\n const { contextData, logger } = worker;\n this.#queue = federation\n .startQueue(contextData, { signal: this.#queueController.signal })\n .catch((error: unknown) => {\n if (this.#queueController.signal.aborted) return;\n logger.error(\n { err: error },\n \"The Fedify task queue stopped unexpectedly\",\n );\n });\n }\n\n /**\n * Stops the queue worker and waits for it, releases any request still\n * waiting on `ready()`, and takes the LogTape configuration down.\n *\n * Aborting only *asks* the listeners to stop; `startQueue()` settles once\n * they have, possibly one in-flight delivery later. Returning that promise\n * keeps the rest of the shutdown sequence (closing the database, most\n * importantly) behind it.\n *\n * LogTape is reset after the queue stops, so an outgoing delivery can still\n * log, and only if this provider configured it (see\n * {@link #loggingConfigured}); resetting the application's own\n * configuration would silence its logs.\n *\n * The return type stays a promise even with no queue to wait for: AdonisJS\n * warns when a provider hook returns a non-thenable.\n */\n shutdown(): Promise<void> {\n this.#settle(new E_FEDERATION_NOT_READY());\n this.#queueController.abort();\n\n const stopped = this.#queue ?? Promise.resolve();\n if (!this.#loggingConfigured) return stopped;\n\n this.#loggingConfigured = false;\n // A failing reset must not fail the shutdown queued behind it. The queue\n // promise never rejects, so only the reset is guarded.\n return stopped.then(async () => {\n try {\n await resetLogging();\n } catch {\n // Reset failures must not fail the shutdown queued behind them.\n }\n });\n }\n\n /**\n * Called when the HTTP server starts listening and requests can arrive.\n */\n #serverStarted(): void {\n this.#listening = true;\n if (this.#buildable) return;\n\n this.#readyTimer = setTimeout(\n () => this.#settle(new E_FEDERATION_NOT_READY()),\n READY_TIMEOUT_MS,\n );\n // A pending timer must not keep the process alive.\n this.#readyTimer.unref();\n }\n\n /**\n * Settles the `ready()` promise once; later calls are no-ops.\n */\n #settle(error?: unknown): void {\n clearTimeout(this.#readyTimer);\n if (error === undefined) this.#ready.resolve();\n else this.#ready.reject(error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,mBAAmB;;;;;;;;;;AAgBzB,SAAS,eAAkB,SAAwC;CACjE,IAAI;CAEJ,MAAM,aAAyB;EAC7B,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAmB;GAC7C,SAAS;GACT,MAAM;EACR,CAAC;EAED,OAAO;CACT;CAEA,OAAO,OAAO,OAAO,MAAM,EACzB,cAAoB;EAClB,SAAS;CACX,EACF,CAAC;AACH;;;;;;;;;;AAWA,IAAqB,iBAArB,MAAoC;;;;CAIlC,mBAAmB,IAAI,gBAAgB;;;;;;CAOvC;;;;;;;;;CAUA,qBAAqB;;;;;;;;;CAUrB,aAAa;;;;;;;;;;;CAYb,aAAa;;;;;;CAOb,SAAS,QAAQ,cAAoB;CACrC;;;;;;;;;;;CAYA;CAEA,AAAU;;;;;CAMV,YAAY,KAAyB;EACnC,KAAK,MAAM;EAIX,KAAKA,OAAO,QAAQ,YAAY,CAAC,CAAC;CACpC;;;;CAKA,WAAiB;;;;;;EAMf,KAAK,IAAI,UAAU,UAAU,kBAAkB,OAAO;EAEtD,KAAK,IAAI,UAAU,KACjB,iBACA,eAAe,YAAY;GACzB,MAAM,WAAW,KAAK,IAAI,OAAO,IAE/B,QAAQ;GACV,MAAM,SAAS,MAAM,eAAe,QACl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AKS,cAAc,iBACX,KAAKJ,QAAQ,IAAI,uBAAuB,CAAC,GAC/C,gBACF;EAEA,KAAKI,YAAY,MAAM;CACzB;;;;CAKA,QAAQ,OAAuB;EAC7B,aAAa,KAAKA,WAAW;EAC7B,IAAI,UAAU,WAAW,KAAKV,OAAO,QAAQ;OACxC,KAAKA,OAAO,OAAO,KAAK;CAC/B;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/adonisjs",
|
|
3
|
-
"version": "2.5.0-dev.
|
|
3
|
+
"version": "2.5.0-dev.2664+4790a72e",
|
|
4
4
|
"description": "Integration package for Fedify with AdonisJS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@adonisjs/assembler": "^8.0.0",
|
|
96
96
|
"@adonisjs/core": "^7.4.0",
|
|
97
|
-
"@fedify/fedify": "^2.5.0-dev.
|
|
97
|
+
"@fedify/fedify": "^2.5.0-dev.2664+4790a72e"
|
|
98
98
|
},
|
|
99
99
|
"peerDependenciesMeta": {
|
|
100
100
|
"@adonisjs/assembler": {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@logtape/logtape": "
|
|
105
|
+
"@logtape/logtape": "2.4.2"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"@adonisjs/assembler": "^8.0.0",
|
|
@@ -110,8 +110,8 @@
|
|
|
110
110
|
"@types/node": "^24.12.2",
|
|
111
111
|
"tsdown": "^0.22.0",
|
|
112
112
|
"typescript": "^6.0.3",
|
|
113
|
-
"@fedify/fedify": "^2.5.0-dev.
|
|
114
|
-
"@fedify/vocab": "^2.5.0-dev.
|
|
113
|
+
"@fedify/fedify": "^2.5.0-dev.2664+4790a72e",
|
|
114
|
+
"@fedify/vocab": "^2.5.0-dev.2664+4790a72e"
|
|
115
115
|
},
|
|
116
116
|
"scripts": {
|
|
117
117
|
"build:self": "tsdown",
|