@contello/astro 4.1.0 → 4.2.0

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/index.cjs CHANGED
@@ -4,6 +4,7 @@ let _astroscope_i18n = require("@astroscope/i18n");
4
4
  let _astroscope_node_boot = require("@astroscope/node/boot");
5
5
  let _contello_media = require("@contello/media");
6
6
  let _contello_store = require("@contello/store");
7
+ let _astroscope_node_log = require("@astroscope/node/log");
7
8
  let astro_middleware = require("astro/middleware");
8
9
  let _contello_opentelemetry = require("@contello/opentelemetry");
9
10
  let _astroscope_node_excludes = require("@astroscope/node/excludes");
@@ -28,15 +29,16 @@ function createBoundAssetsMiddleware(contello, options) {
28
29
  console.warn(`[@contello/astro] not initialized, passing through: ${pathname}`);
29
30
  return next();
30
31
  }
31
- if (isImage) return handleFile(contello.client, next, pathname.slice(imagesPrefix.length), imagesCacheControl);
32
- if (isFile) return handleFile(contello.client, next, pathname.slice(filesPrefix.length), filesCacheControl);
33
- return handleVideo(contello.client, next, pathname.slice(videoPrefix.length), ctx.request.signal);
32
+ if (isImage) return handleFile(contello.client, next, pathname.slice(imagesPrefix.length), imagesCacheControl, `${imagesPrefix}[file]`);
33
+ if (isFile) return handleFile(contello.client, next, pathname.slice(filesPrefix.length), filesCacheControl, `${filesPrefix}[file]`);
34
+ return handleVideo(contello.client, next, pathname.slice(videoPrefix.length), ctx.request.signal, `${videoPrefix}[...path]`);
34
35
  });
35
36
  }
36
- function handleFile(client, next, rest, cacheControl) {
37
+ function handleFile(client, next, rest, cacheControl, routeLabel) {
37
38
  const dot = rest.indexOf(".");
38
39
  const fileId = dot === -1 ? rest : rest.slice(0, dot);
39
40
  if (!fileId) return next();
41
+ (0, _astroscope_node_log.overrideRequestRoute)(routeLabel);
40
42
  return (async () => {
41
43
  try {
42
44
  const result = await wrap("assets:file", () => client.download(fileId));
@@ -49,8 +51,9 @@ function handleFile(client, next, rest, cacheControl) {
49
51
  }
50
52
  })();
51
53
  }
52
- function handleVideo(client, next, path, signal) {
54
+ function handleVideo(client, next, path, signal, routeLabel) {
53
55
  if (!path) return next();
56
+ (0, _astroscope_node_log.overrideRequestRoute)(routeLabel);
54
57
  return (async () => {
55
58
  try {
56
59
  const result = await wrap("assets:hls", () => client.proxyHls(path, signal));
@@ -84,21 +87,18 @@ function toRedirectStatus(status) {
84
87
  return VALID_REDIRECT_STATUSES.has(status) ? status : 302;
85
88
  }
86
89
  /**
87
- * The platform server span is named after the astro route pattern, which for
88
- * contello-served paths is the 404 fallback — rename it to the route that
89
- * actually handles the request and record what contello resolved.
90
+ * Astro's routing matches the 404 fallback for paths only contello knows how to
91
+ * serve, so report what contello resolved: `overrideRequestRoute` corrects the
92
+ * request log line, the request duration metric and the server span name
93
+ * together, then record the contello-specific attributes on top.
90
94
  */
91
- function markServerSpan(method, route) {
92
- const httpRoute = route.type === "entity" ? `/contello/entities/${route.model}/[id]` : `contello:route:${route.type}`;
93
- (0, _contello_opentelemetry.updateActiveSpan)({
94
- name: `${method} ${httpRoute}`,
95
- attributes: {
96
- "http.route": httpRoute,
97
- "contello.route.type": route.type,
98
- "contello.route.path": route.path,
99
- ...route.type === "entity" && { "contello.route.model": route.model }
100
- }
101
- });
95
+ function markRequestRoute(route) {
96
+ (0, _astroscope_node_log.overrideRequestRoute)(route.type === "entity" ? `/contello/entities/${route.model}/[id]` : `contello:route:${route.type}`);
97
+ (0, _contello_opentelemetry.updateActiveSpan)({ attributes: {
98
+ "contello.route.type": route.type,
99
+ "contello.route.path": route.path,
100
+ ...route.type === "entity" && { "contello.route.model": route.model }
101
+ } });
102
102
  }
103
103
  function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
104
104
  return (0, astro_middleware.defineMiddleware)((ctx, next) => {
@@ -120,7 +120,7 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
120
120
  route: void 0,
121
121
  rewritten: false
122
122
  }, () => next());
123
- markServerSpan(ctx.request.method, route);
123
+ markRequestRoute(route);
124
124
  switch (route.type) {
125
125
  case "redirect": return contello[runRequest]({
126
126
  url,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"mappings":";;;;;;;KAKY,2BAAA;EACV,YAAY;AAAA;AAAA,KAGF,0BAAA;EACV,YAAY;AAAA;AAAA,KAGF,0BAAA,GAA6B,MAAM;AAAA,KAEnC,+BAAA;EACV,MAAA,GAAS,2BAAA;EACT,KAAA,GAAQ,0BAAA;EACR,KAAA,GAAQ,0BAAA;AAAA;;;KCFE,SAAA,GAAY,MAAA,GAAS,UAAA,GAAa,UAAA;;;ADX9C;;;;AACc;AAGd;;KCkBY,iBAAA,IAAqB,GAAe,EAAV,UAAU;AAAA,KAEpC,gCAAA;EDnBE;AAGd;;;;AAA+C;AAE/C;ECsBE,MAAA,GAAS,SAAA;EACT,OAAA,GAAU,cAAA;EACV,gBAAA,GAAmB,iBAAA;AAAA;;;KCST,sBAAA;EACV,GAAA,EAAK,GAAA;EACL,KAAA,EAAO,YAAA,CAAa,UAAA;EACpB,SAAA;AAAA;AAAA,KAGU,mBAAA;EACV,UAAA;EACA,SAAA;EACA,KAAA,GAAQ,gBAAgB;AAAA;AAAA,KAGd,mBAAA;EACV,IAAA,GAAO,QAAQ;EACf,IAAA;IFjDoC,8FEoDhC,QAAA;IACA,IAAA;EAAA;AAAA;AAAA,KAKM,mBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA;EAAA,SACA,SAAA;AAAA;AAAA,KAGC,eAAA,iBAAgC,MAAA,4BAAkC,kBAAA,CAAmB,OAAA;EAC/F,IAAA,GAAO,mBAAA;EACP,KAAA,GAAQ,OAAA,CAAQ,mBAAA;AAAA;AAAA,KAGb,WAAA,MAAiB,CAAA;EAAY,QAAA;AAAA,MAAwB,CAAC;AAAA,cAE9C,UAAA;AAAA,KA2CR,QAAA,YAAoB,OAAA;EAAkB,MA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EAInD,gBAAA,CAAiB,OAAA,GAAU,iBAAA,eAAgC,UAAA;EAI3D,gBAAA,CAAiB,OAAA,GAAU,iBAAA,eAAgC,UAAA;EAAA,CAM1D,UAAA,KAAe,GAAA,EAAK,sBAAA,EAAwB,EAAA,QAAU,CAAA,GAAI,CAAA;AAAA;AAAA,iBAK7C,cAAA,iBAA+B,MAAA,0BAC7C,OAAA,EAAS,eAAA,CAAgB,OAAA,IACxB,QAAA,CAAS,OAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"mappings":";;;;;;;KAMY,2BAAA;EACV,YAAY;AAAA;AAAA,KAGF,0BAAA;EACV,YAAY;AAAA;AAAA,KAGF,0BAAA,GAA6B,MAAM;AAAA,KAEnC,+BAAA;EACV,MAAA,GAAS,2BAAA;EACT,KAAA,GAAQ,0BAAA;EACR,KAAA,GAAQ,0BAAA;AAAA;;;KCFE,SAAA,GAAY,MAAA,GAAS,UAAA,GAAa,UAAA;;;ADX9C;;;;AACc;AAGd;;KCkBY,iBAAA,IAAqB,GAAe,EAAV,UAAU;AAAA,KAEpC,gCAAA;EDnBE;AAGd;;;;AAA+C;AAE/C;ECsBE,MAAA,GAAS,SAAA;EACT,OAAA,GAAU,cAAA;EACV,gBAAA,GAAmB,iBAAA;AAAA;;;KCQT,sBAAA;EACV,GAAA,EAAK,GAAA;EACL,KAAA,EAAO,YAAA,CAAa,UAAA;EACpB,SAAA;AAAA;AAAA,KAGU,mBAAA;EACV,UAAA;EACA,SAAA;EACA,KAAA,GAAQ,gBAAgB;AAAA;AAAA,KAGd,mBAAA;EACV,IAAA,GAAO,QAAQ;EACf,IAAA;IFhDoC,8FEmDhC,QAAA;IACA,IAAA;EAAA;AAAA;AAAA,KAKM,mBAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA;EAAA,SACA,UAAA;EAAA,SACA,SAAA;AAAA;AAAA,KAGC,eAAA,iBAAgC,MAAA,4BA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A;EAAA,IAAe,aAAA,CAAc,OAAA,EAAS,IAAA;IAAU,EAAA;EAAA,GAElE,WAAA,EAAa,IAAA,EACb,OAAA,GAAU,qBAAA,CAAsB,aAAA,CAAc,OAAA,EAAS,IAAA,GAAO,OAAA,EAAS,QAAA,CAAS,OAAA,KAC/E,cAAA,CAAe,OAAA;EAIlB,oBAAA,cACe,aAAA,CAAc,OAAA;IACT,EAAA;EAAA,IAAe,aAAA,CAAc,OAAA,EAAS,IAAA;IAAU,EAAA;EAAA,GAElE,WAAA,EAAa,IAAA,EACb,OAAA,GAAU,qBAAA,CAAsB,aAAA,CAAc,OAAA,EAAS,IAAA,GAAO,OAAA,EAAS,QAAA,CAAS,OAAA,KAC/E,cAAA,CAAe,OAAA;EAIlB,YAAA,CAAa,OAAA,GAAU,aAAA,eAA4B,MAAA;EAInD,gBAAA,CAAiB,OAAA,GAAU,iBAAA,eAAgC,UAAA;EAI3D,gBAAA,CAAiB,OAAA,GAAU,iBAAA,eAAgC,UAAA;EAI3D,YAAA,CAAa,OAAA,GAAU,aAAA,eAA4B,MAAA;EAInD,gBAAA,CAAiB,OAAA,GAAU,iBAAA,eAAgC,UAAA;EAI3D,gBAAA,CAAiB,OAAA,GAAU,iBAAA,eAAgC,UAAA;EAAA,CAM1D,UAAA,KAAe,GAAA,EAAK,sBAAA,EAAwB,EAAA,QAAU,CAAA,GAAI,CAAA;AAAA;AAAA,iBAK7C,cAAA,iBAA+B,MAAA,0BAC7C,OAAA,EAAS,eAAA,CAAgB,OAAA,IACxB,QAAA,CAAS,OAAA"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { i18n } from "@astroscope/i18n";
3
3
  import { getBootContext } from "@astroscope/node/boot";
4
4
  import { createMediaResolver } from "@contello/media";
5
5
  import { createStore, maybeThen } from "@contello/store";
6
+ import { overrideRequestRoute } from "@astroscope/node/log";
6
7
  import { defineMiddleware } from "astro/middleware";
7
8
  import { createOperationTelemetry, updateActiveSpan } from "@contello/opentelemetry";
8
9
  import { RECOMMENDED_EXCLUDES, shouldExclude } from "@astroscope/node/excludes";
@@ -27,15 +28,16 @@ function createBoundAssetsMiddleware(contello, options) {
27
28
  console.warn(`[@contello/astro] not initialized, passing through: ${pathname}`);
28
29
  return next();
29
30
  }
30
- if (isImage) return handleFile(contello.client, next, pathname.slice(imagesPrefix.length), imagesCacheControl);
31
- if (isFile) return handleFile(contello.client, next, pathname.slice(filesPrefix.length), filesCacheControl);
32
- return handleVideo(contello.client, next, pathname.slice(videoPrefix.length), ctx.request.signal);
31
+ if (isImage) return handleFile(contello.client, next, pathname.slice(imagesPrefix.length), imagesCacheControl, `${imagesPrefix}[file]`);
32
+ if (isFile) return handleFile(contello.client, next, pathname.slice(filesPrefix.length), filesCacheControl, `${filesPrefix}[file]`);
33
+ return handleVideo(contello.client, next, pathname.slice(videoPrefix.length), ctx.request.signal, `${videoPrefix}[...path]`);
33
34
  });
34
35
  }
35
- function handleFile(client, next, rest, cacheControl) {
36
+ function handleFile(client, next, rest, cacheControl, routeLabel) {
36
37
  const dot = rest.indexOf(".");
37
38
  const fileId = dot === -1 ? rest : rest.slice(0, dot);
38
39
  if (!fileId) return next();
40
+ overrideRequestRoute(routeLabel);
39
41
  return (async () => {
40
42
  try {
41
43
  const result = await wrap("assets:file", () => client.download(fileId));
@@ -48,8 +50,9 @@ function handleFile(client, next, rest, cacheControl) {
48
50
  }
49
51
  })();
50
52
  }
51
- function handleVideo(client, next, path, signal) {
53
+ function handleVideo(client, next, path, signal, routeLabel) {
52
54
  if (!path) return next();
55
+ overrideRequestRoute(routeLabel);
53
56
  return (async () => {
54
57
  try {
55
58
  const result = await wrap("assets:hls", () => client.proxyHls(path, signal));
@@ -83,21 +86,18 @@ function toRedirectStatus(status) {
83
86
  return VALID_REDIRECT_STATUSES.has(status) ? status : 302;
84
87
  }
85
88
  /**
86
- * The platform server span is named after the astro route pattern, which for
87
- * contello-served paths is the 404 fallback — rename it to the route that
88
- * actually handles the request and record what contello resolved.
89
+ * Astro's routing matches the 404 fallback for paths only contello knows how to
90
+ * serve, so report what contello resolved: `overrideRequestRoute` corrects the
91
+ * request log line, the request duration metric and the server span name
92
+ * together, then record the contello-specific attributes on top.
89
93
  */
90
- function markServerSpan(method, route) {
91
- const httpRoute = route.type === "entity" ? `/contello/entities/${route.model}/[id]` : `contello:route:${route.type}`;
92
- updateActiveSpan({
93
- name: `${method} ${httpRoute}`,
94
- attributes: {
95
- "http.route": httpRoute,
96
- "contello.route.type": route.type,
97
- "contello.route.path": route.path,
98
- ...route.type === "entity" && { "contello.route.model": route.model }
99
- }
100
- });
94
+ function markRequestRoute(route) {
95
+ overrideRequestRoute(route.type === "entity" ? `/contello/entities/${route.model}/[id]` : `contello:route:${route.type}`);
96
+ updateActiveSpan({ attributes: {
97
+ "contello.route.type": route.type,
98
+ "contello.route.path": route.path,
99
+ ...route.type === "entity" && { "contello.route.model": route.model }
100
+ } });
101
101
  }
102
102
  function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
103
103
  return defineMiddleware((ctx, next) => {
@@ -119,7 +119,7 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
119
119
  route: void 0,
120
120
  rewritten: false
121
121
  }, () => next());
122
- markServerSpan(ctx.request.method, route);
122
+ markRequestRoute(route);
123
123
  switch (route.type) {
124
124
  case "redirect": return contello[runRequest]({
125
125
  url,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/telemetry.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"sourcesContent":["import { createOperationTelemetry } from '@contello/opentelemetry';\n\nexport const { wrap } = createOperationTelemetry('@contello/astro');\n","import type { ContelloClient } from '@contello/client';\nimport { defineMiddleware } from 'astro/middleware';\nimport type { Contello } from './contello';\nimport { wrap } from './telemetry';\n\nexport type ContelloAssetsImagesOptions = {\n cacheControl?: string | undefined;\n};\n\nexport type ContelloAssetsFilesOptions = {\n cacheControl?: string | undefined;\n};\n\nexport type ContelloAssetsVideoOptions = Record<string, never>;\n\nexport type ContelloAssetsMiddlewareOptions = {\n images?: ContelloAssetsImagesOptions | undefined;\n files?: ContelloAssetsFilesOptions | undefined;\n video?: ContelloAssetsVideoOptions | undefined;\n};\n\nconst DEFAULT_IMAGES_CACHE_CONTROL = 'public, max-age=31536000';\n\nexport function createBoundAssetsMiddleware(\n contello: Contello<any>,\n options: ContelloAssetsMiddlewareOptions | undefined,\n) {\n const imagesPrefix = contello.media.imagesPath;\n const imagesCacheControl = options?.images?.cacheControl ?? DEFAULT_IMAGES_CACHE_CONTROL;\n const filesPrefix = contello.media.filesPath;\n const filesCacheControl = options?.files?.cacheControl;\n const videoPrefix = contello.media.videosPath;\n\n return defineMiddleware((ctx, next) => {\n const { pathname } = ctx.url;\n const isImage = pathname.startsWith(imagesPrefix);\n const isFile = !isImage && pathname.startsWith(filesPrefix);\n const isVideo = !isImage && !isFile && pathname.startsWith(videoPrefix);\n\n if (!isImage && !isFile && !isVideo) {\n return next();\n }\n\n if (!contello.isReady) {\n console.warn(`[@contello/astro] not initialized, passing through: ${pathname}`);\n\n return next();\n }\n\n if (isImage) {\n return handleFile(contello.client, next, pathname.slice(imagesPrefix.length), imagesCacheControl);\n }\n\n if (isFile) {\n return handleFile(contello.client, next, pathname.slice(filesPrefix.length), filesCacheControl);\n }\n\n return handleVideo(contello.client, next, pathname.slice(videoPrefix.length), ctx.request.signal);\n });\n}\n\nfunction handleFile(\n client: ContelloClient<any>,\n next: () => Response | Promise<Response>,\n rest: string,\n cacheControl: string | undefined,\n) {\n const dot = rest.indexOf('.');\n const fileId = dot === -1 ? rest : rest.slice(0, dot);\n\n if (!fileId) {\n return next();\n }\n\n return (async () => {\n try {\n const result = await wrap('assets:file', () => client.download(fileId));\n const headers = new Headers({ 'content-type': result.mimeType });\n\n if (cacheControl) {\n headers.set('cache-control', cacheControl);\n }\n\n if (result.size > 0) {\n headers.set('content-length', String(result.size));\n }\n\n return new Response(result.stream(), { headers });\n } catch {\n return new Response(null, { status: 404 });\n }\n })();\n}\n\nfunction handleVideo(\n client: ContelloClient<any>,\n next: () => Response | Promise<Response>,\n path: string,\n signal: AbortSignal,\n) {\n if (!path) {\n return next();\n }\n\n return (async () => {\n try {\n const result = await wrap('assets:hls', () => client.proxyHls(path, signal));\n\n return new Response(result.stream(), { status: result.status, headers: result.headers });\n } catch {\n return new Response('Upstream is down', { status: 502, headers: { 'content-type': 'text/plain' } });\n }\n })();\n}\n","import { type ExcludePattern, RECOMMENDED_EXCLUDES, shouldExclude } from '@astroscope/node/excludes';\nimport { updateActiveSpan } from '@contello/opentelemetry';\nimport {\n type LazyRoutes,\n type MaybePromise,\n type Routes,\n type RoutesSync,\n type StoreRoute,\n type StoreRouteCustomHeader,\n maybeThen,\n} from '@contello/store';\nimport type { APIContext, ValidRedirectStatus } from 'astro';\nimport { defineMiddleware } from 'astro/middleware';\nimport { type Contello, runRequest } from './contello';\nimport { wrap } from './telemetry';\n\nexport type AnyRoutes = Routes | RoutesSync | LazyRoutes;\n\n/**\n * Derives the path used to look up a Contello route from the request context.\n *\n * @default `(ctx) => ctx.url.pathname`\n *\n * ```ts\n * resolveRoutePath: (ctx) => `/${ctx.url.hostname}${ctx.url.pathname}`\n * ```\n */\nexport type RoutePathResolver = (ctx: APIContext) => string;\n\nexport type ContelloRoutingMiddlewareOptions = {\n /**\n * Routes instance backing the middleware.\n *\n * Defaults to a `LazyRoutes` instance managed by contello (fetched on demand, no init-time load).\n * For eager routing, create a `RoutesSync` via `contello.defineRoutesSync()`, add it to\n * `contello.init({ load: [routes] })`, and pass that same instance here.\n */\n routes?: AnyRoutes | undefined;\n exclude?: ExcludePattern[] | undefined;\n resolveRoutePath?: RoutePathResolver | undefined;\n};\n\nfunction customHeaders(headers: readonly StoreRouteCustomHeader[]): Record<string, string> {\n const result: Record<string, string> = {};\n\n for (const h of headers) {\n result[h.name] = h.value;\n }\n\n return result;\n}\n\nconst VALID_REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\nfunction toRedirectStatus(status: number): ValidRedirectStatus {\n return (VALID_REDIRECT_STATUSES.has(status) ? status : 302) as ValidRedirectStatus;\n}\n\n/**\n * The platform server span is named after the astro route pattern, which for\n * contello-served paths is the 404 fallback — rename it to the route that\n * actually handles the request and record what contello resolved.\n */\nfunction markServerSpan(method: string, route: StoreRoute): void {\n const httpRoute = route.type === 'entity' ? `/contello/entities/${route.model}/[id]` : `contello:route:${route.type}`;\n\n updateActiveSpan({\n name: `${method} ${httpRoute}`,\n attributes: {\n 'http.route': httpRoute,\n 'contello.route.type': route.type,\n 'contello.route.path': route.path,\n ...(route.type === 'entity' && { 'contello.route.model': route.model }),\n },\n });\n}\n\nexport function createBoundRoutingMiddleware(\n contello: Contello<any>,\n routes: AnyRoutes,\n exclude: ExcludePattern[] | undefined,\n resolveRoutePath: RoutePathResolver | undefined,\n) {\n return defineMiddleware((ctx, next) => {\n if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) {\n return next();\n }\n\n if (!contello.isReady) {\n console.warn(`[@contello/astro] not initialized, passing through: ${ctx.url.pathname}`);\n\n return next();\n }\n\n const { url } = ctx;\n\n if (url.pathname.startsWith('/contello/entities/')) {\n return contello[runRequest]({ url, route: undefined, rewritten: false }, () => next());\n }\n\n const path = resolveRoutePath ? resolveRoutePath(ctx) : url.pathname;\n const lookup = routes.getByPath(path) as MaybePromise<StoreRoute | undefined>;\n\n return maybeThen(lookup, (route) => {\n if (!route) {\n return contello[runRequest]({ url, route: undefined, rewritten: false }, () => next());\n }\n\n markServerSpan(ctx.request.method, route);\n\n switch (route.type) {\n case 'redirect': {\n return contello[runRequest]({ url, route, rewritten: false }, () =>\n wrap(\n 'route:redirect',\n () =>\n new Response(null, {\n status: toRedirectStatus(route.status),\n headers: {\n Location: route.location,\n ...customHeaders(route.customHeaders),\n },\n }),\n ),\n );\n }\n\n case 'text': {\n return contello[runRequest]({ url, route, rewritten: false }, () =>\n wrap(\n 'route:text',\n () =>\n new Response(route.content, {\n status: 200,\n headers: {\n 'Content-Type': route.mimeType,\n ...customHeaders(route.customHeaders),\n },\n }),\n ),\n );\n }\n\n case 'asset': {\n return contello[runRequest]({ url, route, rewritten: false }, () =>\n wrap('route:asset', async () => {\n const result = await contello.client.download(route.fileId);\n const headers = new Headers({ 'content-type': route.mimeType || result.mimeType });\n\n headers.set('content-disposition', route.contentDisposition);\n\n if (result.size > 0) {\n headers.set('content-length', String(result.size));\n }\n\n for (const { name, value } of route.customHeaders) {\n headers.set(name, value);\n }\n\n return new Response(result.stream(), { headers });\n }),\n );\n }\n\n case 'entity': {\n return contello[runRequest]({ url, route, rewritten: true }, () =>\n wrap(`route:entity:${route.model}`, async () => {\n const response = await next(`/contello/entities/${route.model}/${route.entityId}${url.search}`);\n\n for (const { name, value } of route.customHeaders) {\n response.headers.set(name, value);\n }\n\n return response;\n }),\n );\n }\n }\n });\n });\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { type RawTranslations, i18n } from '@astroscope/i18n';\nimport { getBootContext } from '@astroscope/node/boot';\nimport type { ContelloClient, Schema, SourceDef } from '@contello/client';\nimport { type MediaResolver, type MediaResolverOptions, createMediaResolver } from '@contello/media';\nimport {\n type Assets,\n type AssetsOptions,\n type AssetsSync,\n type AssetsSyncOptions,\n type Collection,\n type CollectionOptions,\n type CollectionSync,\n type CollectionSyncOptions,\n type CreateStoreOptions,\n type ExtractSourceResult,\n type I18nMessageRegistrationDefinition,\n type I18nMessages,\n type LazyAssets,\n type LazyAssetsOptions,\n type LazyCollection,\n type LazyCollectionOptions,\n type LazyRoutes,\n type LazyRoutesOptions,\n type Loadable,\n type ReadonlyDeep,\n type ResolveSource,\n type Routes,\n type RoutesOptions,\n type RoutesSync,\n type RoutesSyncOptions,\n type Singleton,\n type SingletonOptions,\n type SingletonSync,\n type SingletonSyncOptions,\n type SourceKeysOf,\n type Store,\n type StoreRoute,\n type SyncCacheOptions,\n createStore,\n} from '@contello/store';\nimport { type ContelloAssetsMiddlewareOptions, createBoundAssetsMiddleware } from './assets-middleware';\nimport { type ContelloRoutingMiddlewareOptions, createBoundRoutingMiddleware } from './routing-middleware';\n\nconst DEFAULT_IMAGES_PREFIX = '/_contello/i/';\nconst DEFAULT_FILES_PREFIX = '/_contello/f/';\nconst DEFAULT_VIDEO_PREFIX = '/_contello/v/';\n\nexport type ContelloRequestContext = {\n url: URL;\n route: ReadonlyDeep<StoreRoute> | undefined;\n rewritten: boolean;\n};\n\nexport type ContelloI18nOptions = {\n collection: string;\n languages: string[];\n cache?: SyncCacheOptions | undefined;\n};\n\nexport type ContelloInitOptions = {\n load?: Loadable[] | undefined;\n i18n?:\n | {\n /** defaults to `true`, except in dev mode (detected via the @astroscope/node boot context) */\n register?: boolean | undefined;\n load?: boolean | undefined;\n }\n | undefined;\n};\n\nexport type ContelloMediaConfig = {\n readonly baseUrl: string;\n readonly imagesPath: string;\n readonly videosPath: string;\n readonly filesPath: string;\n};\n\nexport type ContelloOptions<TSchema extends Schema | undefined = undefined> = CreateStoreOptions<TSchema> & {\n i18n?: ContelloI18nOptions | undefined;\n media?: Partial<ContelloMediaConfig> | undefined;\n};\n\ntype HasFallback<O> = O extends { fallback: infer F } ? ([F] extends [undefined] ? false : true) : false;\n\nexport const runRequest = Symbol('@contello/astro/runRequest');\n\nfunction buildI18nRegistrations(): I18nMessageRegistrationDefinition[] {\n const manifest = i18n.getManifest();\n const defaultLanguage = i18n.getConfig().defaultLocale;\n\n return manifest.keys.map((extracted) => ({\n token: extracted.key,\n example: extracted.meta.fallback,\n description: extracted.meta.description ?? '',\n variables: Object.entries(extracted.meta.variables ?? {}).map(([name, def]) => ({\n name,\n description: def?.description ?? '',\n example: def?.fallback ?? '',\n })),\n initialTranslations: [{ language: defaultLanguage, message: extracted.meta.fallback }],\n }));\n}\n\nasync function applyTranslations(messages: I18nMessages): Promise<void> {\n const config = i18n.getConfig();\n const all = await messages.getAll();\n const byLocale = new Map<string, RawTranslations>();\n\n for (const locale of config.locales) {\n byLocale.set(locale, {});\n }\n\n for (const msg of all) {\n msg.translations.forEach((value, language) => {\n const raw = byLocale.get(language);\n\n if (raw) {\n raw[msg.token] = value;\n }\n });\n }\n\n for (const [locale, translations] of byLocale) {\n i18n.setTranslations(locale, translations);\n }\n}\n\ntype ModelsOf<TSchema> = TSchema extends { models: infer M } ? keyof M & string : string;\ntype CollectionArg<TSchema> = SourceKeysOf<TSchema, 'entity'> | SourceDef<ModelsOf<TSchema>, 'entity'>;\ntype SingletonArg<TSchema> = SourceKeysOf<TSchema, 'singleton'> | SourceDef<ModelsOf<TSchema>, 'singleton'>;\ntype CollectionRaw<TSchema, TArg> = ExtractSourceResult<\n Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>\n>;\ntype SingletonRaw<TSchema, TArg> = ExtractSourceResult<\n Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'singleton'>>\n>;\n\nexport class Contello<TSchema extends Schema | undefined = undefined> {\n private readonly _store: Store<TSchema>;\n private readonly _options: ContelloOptions<TSchema>;\n private _i18nMessages: I18nMessages | undefined;\n private _i18nUnsubscribe: (() => void) | undefined;\n private _initialized = false;\n private readonly _als = new AsyncLocalStorage<ContelloRequestContext>();\n private _autoLazyRoutes?: LazyRoutes;\n\n readonly media: ContelloMediaConfig;\n\n // --- middleware factories (arrow fields so destructuring works) ---\n\n createRoutingMiddleware = (options?: ContelloRoutingMiddlewareOptions | undefined) => {\n const routes = options?.routes ?? (this._autoLazyRoutes ??= this.defineLazyRoutes());\n\n return createBoundRoutingMiddleware(this, routes, options?.exclude, options?.resolveRoutePath);\n };\n\n createAssetsMiddleware = (options?: ContelloAssetsMiddlewareOptions | undefined) => {\n return createBoundAssetsMiddleware(this, options);\n };\n\n constructor(options: ContelloOptions<TSchema>) {\n this._options = options;\n this._store = createStore<TSchema>(options);\n\n this.media = {\n baseUrl: options.media?.baseUrl ?? '',\n imagesPath: options.media?.imagesPath ?? DEFAULT_IMAGES_PREFIX,\n videosPath: options.media?.videosPath ?? DEFAULT_VIDEO_PREFIX,\n filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX,\n };\n }\n\n // --- lifecycle ---\n\n async init(options?: ContelloInitOptions | undefined): Promise<void> {\n try {\n await this._store.init();\n\n if (this._options.i18n) {\n const { collection, languages, cache } = this._options.i18n;\n const dev = getBootContext()?.dev ?? false;\n const { register = !dev, load = true } = options?.i18n ?? {};\n\n this._i18nMessages = this._store.defineI18nMessages({ collection, cache });\n\n await i18n.configure({ locales: languages });\n\n if (register) {\n const registrations = buildI18nRegistrations();\n\n if (registrations.length > 0) {\n await this._i18nMessages.register(registrations);\n }\n }\n\n if (load) {\n await applyTranslations(this._i18nMessages);\n\n const messages = this._i18nMessages;\n const controller = new AbortController();\n\n this._i18nUnsubscribe = () => controller.abort();\n\n // background loop: re-apply translations on every refresh until destroy()\n void (async () => {\n for await (const _ of messages.refresh$) {\n if (controller.signal.aborted) {\n return;\n }\n\n await applyTranslations(messages);\n }\n })();\n }\n }\n\n await Promise.all((options?.load ?? []).map((l) => l.load()));\n\n this._initialized = true;\n } catch (error) {\n try {\n await this.destroy();\n } catch {\n // ignore teardown errors; the original init error is rethrown below\n }\n\n throw error;\n }\n }\n\n async destroy(): Promise<void> {\n this._initialized = false;\n\n this._i18nUnsubscribe?.();\n this._i18nUnsubscribe = undefined;\n\n await this._store.destroy();\n\n this._i18nMessages = undefined;\n }\n\n ping(): Promise<void> {\n return this._store.ping();\n }\n\n get isReady(): boolean {\n return this._initialized;\n }\n\n get client(): ContelloClient<TSchema> {\n return this._store.client;\n }\n\n get i18nMessages(): I18nMessages {\n if (!this._i18nMessages) {\n throw new Error('@contello/astro: .i18nMessages accessed before init() with i18n config');\n }\n\n return this._i18nMessages;\n }\n\n // --- ALS request context ---\n\n get request(): ContelloRequestContext {\n const ctx = this._als.getStore();\n\n if (!ctx) {\n throw new Error('@contello/astro: .request accessed outside of request context');\n }\n\n return ctx;\n }\n\n // --- media resolvers (on-demand) ---\n\n defineMediaResolver<O extends Partial<MediaResolverOptions>>(options?: O): MediaResolver<HasFallback<O>> {\n return createMediaResolver({\n ...this.media,\n ...options,\n }) as MediaResolver<HasFallback<O>>;\n }\n\n // --- store delegation ---\n\n defineSingleton<TArg extends SingletonArg<TSchema>, TMapped = SingletonRaw<TSchema, TArg>>(\n sourceOrKey: TArg,\n options?: SingletonOptions<SingletonRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): Singleton<TMapped> {\n return this._store.defineSingleton(sourceOrKey as any, options as any) as Singleton<TMapped>;\n }\n\n defineSingletonSync<TArg extends SingletonArg<TSchema>, TMapped = SingletonRaw<TSchema, TArg>>(\n sourceOrKey: TArg,\n options?: SingletonSyncOptions<SingletonRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): SingletonSync<TMapped> {\n return this._store.defineSingletonSync(sourceOrKey as any, options as any) as SingletonSync<TMapped>;\n }\n\n defineCollection<\n TArg extends CollectionArg<TSchema>,\n TMapped extends { id: string } = CollectionRaw<TSchema, TArg> & { id: string },\n >(\n sourceOrKey: TArg,\n options?: CollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): Collection<TMapped> {\n return this._store.defineCollection(sourceOrKey as any, options as any) as Collection<TMapped>;\n }\n\n defineCollectionSync<\n TArg extends CollectionArg<TSchema>,\n TMapped extends { id: string } = CollectionRaw<TSchema, TArg> & { id: string },\n >(\n sourceOrKey: TArg,\n options?: CollectionSyncOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): CollectionSync<TMapped> {\n return this._store.defineCollectionSync(sourceOrKey as any, options as any) as CollectionSync<TMapped>;\n }\n\n defineLazyCollection<\n TArg extends CollectionArg<TSchema>,\n TMapped extends { id: string } = CollectionRaw<TSchema, TArg> & { id: string },\n >(\n sourceOrKey: TArg,\n options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): LazyCollection<TMapped> {\n return this._store.defineLazyCollection(sourceOrKey as any, options as any) as LazyCollection<TMapped>;\n }\n\n defineRoutes(options?: RoutesOptions | undefined): Routes {\n return this._store.defineRoutes(options);\n }\n\n defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync {\n return this._store.defineRoutesSync(options);\n }\n\n defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes {\n return this._store.defineLazyRoutes(options);\n }\n\n defineAssets(options?: AssetsOptions | undefined): Assets {\n return this._store.defineAssets(options);\n }\n\n defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync {\n return this._store.defineAssetsSync(options);\n }\n\n defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets {\n return this._store.defineLazyAssets(options);\n }\n\n // --- ALS run ---\n\n [runRequest]<T>(ctx: ContelloRequestContext, fn: () => T): T {\n return this._als.run(ctx, fn);\n }\n}\n\nexport function createContello<TSchema extends Schema | undefined = undefined>(\n options: ContelloOptions<TSchema>,\n): Contello<TSchema> {\n return new Contello(options);\n}\n"],"mappings":";;;;;;;;;AAEA,MAAa,EAAE,SAAS,yBAAyB,iBAAiB;;;ACmBlE,MAAM,+BAA+B;AAErC,SAAgB,4BACd,UACA,SACA;CACA,MAAM,eAAe,SAAS,MAAM;CACpC,MAAM,qBAAqB,SAAS,QAAQ,gBAAgB;CAC5D,MAAM,cAAc,SAAS,MAAM;CACnC,MAAM,oBAAoB,SAAS,OAAO;CAC1C,MAAM,cAAc,SAAS,MAAM;CAEnC,OAAO,kBAAkB,KAAK,SAAS;EACrC,MAAM,EAAE,aAAa,IAAI;EACzB,MAAM,UAAU,SAAS,WAAW,YAAY;EAChD,MAAM,SAAS,CAAC,WAAW,SAAS,WAAW,WAAW;EAC1D,MAAM,UAAU,CAAC,WAAW,CAAC,UAAU,SAAS,WAAW,WAAW;EAEtE,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,SAC1B,OAAO,KAAK;EAGd,IAAI,CAAC,SAAS,SAAS;GACrB,QA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A,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,aAAa,SAA6C;EACxD,OAAO,KAAK,OAAO,aAAa,OAAO;CACzC;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAIA,CAAC,YAAe,KAA6B,IAAgB;EAC3D,OAAO,KAAK,KAAK,IAAI,KAAK,EAAE;CAC9B;AACF;AAEA,SAAgB,eACd,SACmB;CACnB,OAAO,IAAI,SAAS,OAAO;AAC7B"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/telemetry.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"sourcesContent":["import { createOperationTelemetry } from '@contello/opentelemetry';\n\nexport const { wrap } = createOperationTelemetry('@contello/astro');\n","import { overrideRequestRoute } from '@astroscope/node/log';\nimport type { ContelloClient } from '@contello/client';\nimport { defineMiddleware } from 'astro/middleware';\nimport type { Contello } from './contello';\nimport { wrap } from './telemetry';\n\nexport type ContelloAssetsImagesOptions = {\n cacheControl?: string | undefined;\n};\n\nexport type ContelloAssetsFilesOptions = {\n cacheControl?: string | undefined;\n};\n\nexport type ContelloAssetsVideoOptions = Record<string, never>;\n\nexport type ContelloAssetsMiddlewareOptions = {\n images?: ContelloAssetsImagesOptions | undefined;\n files?: ContelloAssetsFilesOptions | undefined;\n video?: ContelloAssetsVideoOptions | undefined;\n};\n\nconst DEFAULT_IMAGES_CACHE_CONTROL = 'public, max-age=31536000';\n\nexport function createBoundAssetsMiddleware(\n contello: Contello<any>,\n options: ContelloAssetsMiddlewareOptions | undefined,\n) {\n const imagesPrefix = contello.media.imagesPath;\n const imagesCacheControl = options?.images?.cacheControl ?? DEFAULT_IMAGES_CACHE_CONTROL;\n const filesPrefix = contello.media.filesPath;\n const filesCacheControl = options?.files?.cacheControl;\n const videoPrefix = contello.media.videosPath;\n\n return defineMiddleware((ctx, next) => {\n const { pathname } = ctx.url;\n const isImage = pathname.startsWith(imagesPrefix);\n const isFile = !isImage && pathname.startsWith(filesPrefix);\n const isVideo = !isImage && !isFile && pathname.startsWith(videoPrefix);\n\n if (!isImage && !isFile && !isVideo) {\n return next();\n }\n\n if (!contello.isReady) {\n console.warn(`[@contello/astro] not initialized, passing through: ${pathname}`);\n\n return next();\n }\n\n if (isImage) {\n return handleFile(\n contello.client,\n next,\n pathname.slice(imagesPrefix.length),\n imagesCacheControl,\n `${imagesPrefix}[file]`,\n );\n }\n\n if (isFile) {\n return handleFile(\n contello.client,\n next,\n pathname.slice(filesPrefix.length),\n filesCacheControl,\n `${filesPrefix}[file]`,\n );\n }\n\n return handleVideo(\n contello.client,\n next,\n pathname.slice(videoPrefix.length),\n ctx.request.signal,\n `${videoPrefix}[...path]`,\n );\n });\n}\n\nfunction handleFile(\n client: ContelloClient<any>,\n next: () => Response | Promise<Response>,\n rest: string,\n cacheControl: string | undefined,\n routeLabel: string,\n) {\n const dot = rest.indexOf('.');\n const fileId = dot === -1 ? rest : rest.slice(0, dot);\n\n if (!fileId) {\n return next();\n }\n\n overrideRequestRoute(routeLabel);\n\n return (async () => {\n try {\n const result = await wrap('assets:file', () => client.download(fileId));\n const headers = new Headers({ 'content-type': result.mimeType });\n\n if (cacheControl) {\n headers.set('cache-control', cacheControl);\n }\n\n if (result.size > 0) {\n headers.set('content-length', String(result.size));\n }\n\n return new Response(result.stream(), { headers });\n } catch {\n return new Response(null, { status: 404 });\n }\n })();\n}\n\nfunction handleVideo(\n client: ContelloClient<any>,\n next: () => Response | Promise<Response>,\n path: string,\n signal: AbortSignal,\n routeLabel: string,\n) {\n if (!path) {\n return next();\n }\n\n overrideRequestRoute(routeLabel);\n\n return (async () => {\n try {\n const result = await wrap('assets:hls', () => client.proxyHls(path, signal));\n\n return new Response(result.stream(), { status: result.status, headers: result.headers });\n } catch {\n return new Response('Upstream is down', { status: 502, headers: { 'content-type': 'text/plain' } });\n }\n })();\n}\n","import { type ExcludePattern, RECOMMENDED_EXCLUDES, shouldExclude } from '@astroscope/node/excludes';\nimport { overrideRequestRoute } from '@astroscope/node/log';\nimport { updateActiveSpan } from '@contello/opentelemetry';\nimport {\n type LazyRoutes,\n type MaybePromise,\n type Routes,\n type RoutesSync,\n type StoreRoute,\n type StoreRouteCustomHeader,\n maybeThen,\n} from '@contello/store';\nimport type { APIContext, ValidRedirectStatus } from 'astro';\nimport { defineMiddleware } from 'astro/middleware';\nimport { type Contello, runRequest } from './contello';\nimport { wrap } from './telemetry';\n\nexport type AnyRoutes = Routes | RoutesSync | LazyRoutes;\n\n/**\n * Derives the path used to look up a Contello route from the request context.\n *\n * @default `(ctx) => ctx.url.pathname`\n *\n * ```ts\n * resolveRoutePath: (ctx) => `/${ctx.url.hostname}${ctx.url.pathname}`\n * ```\n */\nexport type RoutePathResolver = (ctx: APIContext) => string;\n\nexport type ContelloRoutingMiddlewareOptions = {\n /**\n * Routes instance backing the middleware.\n *\n * Defaults to a `LazyRoutes` instance managed by contello (fetched on demand, no init-time load).\n * For eager routing, create a `RoutesSync` via `contello.defineRoutesSync()`, add it to\n * `contello.init({ load: [routes] })`, and pass that same instance here.\n */\n routes?: AnyRoutes | undefined;\n exclude?: ExcludePattern[] | undefined;\n resolveRoutePath?: RoutePathResolver | undefined;\n};\n\nfunction customHeaders(headers: readonly StoreRouteCustomHeader[]): Record<string, string> {\n const result: Record<string, string> = {};\n\n for (const h of headers) {\n result[h.name] = h.value;\n }\n\n return result;\n}\n\nconst VALID_REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\nfunction toRedirectStatus(status: number): ValidRedirectStatus {\n return (VALID_REDIRECT_STATUSES.has(status) ? status : 302) as ValidRedirectStatus;\n}\n\n/**\n * Astro's routing matches the 404 fallback for paths only contello knows how to\n * serve, so report what contello resolved: `overrideRequestRoute` corrects the\n * request log line, the request duration metric and the server span name\n * together, then record the contello-specific attributes on top.\n */\nfunction markRequestRoute(route: StoreRoute): void {\n overrideRequestRoute(\n route.type === 'entity' ? `/contello/entities/${route.model}/[id]` : `contello:route:${route.type}`,\n );\n\n updateActiveSpan({\n attributes: {\n 'contello.route.type': route.type,\n 'contello.route.path': route.path,\n ...(route.type === 'entity' && { 'contello.route.model': route.model }),\n },\n });\n}\n\nexport function createBoundRoutingMiddleware(\n contello: Contello<any>,\n routes: AnyRoutes,\n exclude: ExcludePattern[] | undefined,\n resolveRoutePath: RoutePathResolver | undefined,\n) {\n return defineMiddleware((ctx, next) => {\n if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) {\n return next();\n }\n\n if (!contello.isReady) {\n console.warn(`[@contello/astro] not initialized, passing through: ${ctx.url.pathname}`);\n\n return next();\n }\n\n const { url } = ctx;\n\n if (url.pathname.startsWith('/contello/entities/')) {\n return contello[runRequest]({ url, route: undefined, rewritten: false }, () => next());\n }\n\n const path = resolveRoutePath ? resolveRoutePath(ctx) : url.pathname;\n const lookup = routes.getByPath(path) as MaybePromise<StoreRoute | undefined>;\n\n return maybeThen(lookup, (route) => {\n if (!route) {\n return contello[runRequest]({ url, route: undefined, rewritten: false }, () => next());\n }\n\n markRequestRoute(route);\n\n switch (route.type) {\n case 'redirect': {\n return contello[runRequest]({ url, route, rewritten: false }, () =>\n wrap(\n 'route:redirect',\n () =>\n new Response(null, {\n status: toRedirectStatus(route.status),\n headers: {\n Location: route.location,\n ...customHeaders(route.customHeaders),\n },\n }),\n ),\n );\n }\n\n case 'text': {\n return contello[runRequest]({ url, route, rewritten: false }, () =>\n wrap(\n 'route:text',\n () =>\n new Response(route.content, {\n status: 200,\n headers: {\n 'Content-Type': route.mimeType,\n ...customHeaders(route.customHeaders),\n },\n }),\n ),\n );\n }\n\n case 'asset': {\n return contello[runRequest]({ url, route, rewritten: false }, () =>\n wrap('route:asset', async () => {\n const result = await contello.client.download(route.fileId);\n const headers = new Headers({ 'content-type': route.mimeType || result.mimeType });\n\n headers.set('content-disposition', route.contentDisposition);\n\n if (result.size > 0) {\n headers.set('content-length', String(result.size));\n }\n\n for (const { name, value } of route.customHeaders) {\n headers.set(name, value);\n }\n\n return new Response(result.stream(), { headers });\n }),\n );\n }\n\n case 'entity': {\n return contello[runRequest]({ url, route, rewritten: true }, () =>\n wrap(`route:entity:${route.model}`, async () => {\n const response = await next(`/contello/entities/${route.model}/${route.entityId}${url.search}`);\n\n for (const { name, value } of route.customHeaders) {\n response.headers.set(name, value);\n }\n\n return response;\n }),\n );\n }\n }\n });\n });\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { type RawTranslations, i18n } from '@astroscope/i18n';\nimport { getBootContext } from '@astroscope/node/boot';\nimport type { ContelloClient, Schema, SourceDef } from '@contello/client';\nimport { type MediaResolver, type MediaResolverOptions, createMediaResolver } from '@contello/media';\nimport {\n type Assets,\n type AssetsOptions,\n type AssetsSync,\n type AssetsSyncOptions,\n type Collection,\n type CollectionOptions,\n type CollectionSync,\n type CollectionSyncOptions,\n type CreateStoreOptions,\n type ExtractSourceResult,\n type I18nMessageRegistrationDefinition,\n type I18nMessages,\n type LazyAssets,\n type LazyAssetsOptions,\n type LazyCollection,\n type LazyCollectionOptions,\n type LazyRoutes,\n type LazyRoutesOptions,\n type Loadable,\n type ReadonlyDeep,\n type ResolveSource,\n type Routes,\n type RoutesOptions,\n type RoutesSync,\n type RoutesSyncOptions,\n type Singleton,\n type SingletonOptions,\n type SingletonSync,\n type SingletonSyncOptions,\n type SourceKeysOf,\n type Store,\n type StoreRoute,\n type SyncCacheOptions,\n createStore,\n} from '@contello/store';\nimport { type ContelloAssetsMiddlewareOptions, createBoundAssetsMiddleware } from './assets-middleware';\nimport { type ContelloRoutingMiddlewareOptions, createBoundRoutingMiddleware } from './routing-middleware';\n\nconst DEFAULT_IMAGES_PREFIX = '/_contello/i/';\nconst DEFAULT_FILES_PREFIX = '/_contello/f/';\nconst DEFAULT_VIDEO_PREFIX = '/_contello/v/';\n\nexport type ContelloRequestContext = {\n url: URL;\n route: ReadonlyDeep<StoreRoute> | undefined;\n rewritten: boolean;\n};\n\nexport type ContelloI18nOptions = {\n collection: string;\n languages: string[];\n cache?: SyncCacheOptions | undefined;\n};\n\nexport type ContelloInitOptions = {\n load?: Loadable[] | undefined;\n i18n?:\n | {\n /** defaults to `true`, except in dev mode (detected via the @astroscope/node boot context) */\n register?: boolean | undefined;\n load?: boolean | undefined;\n }\n | undefined;\n};\n\nexport type ContelloMediaConfig = {\n readonly baseUrl: string;\n readonly imagesPath: string;\n readonly videosPath: string;\n readonly filesPath: string;\n};\n\nexport type ContelloOptions<TSchema extends Schema | undefined = undefined> = CreateStoreOptions<TSchema> & {\n i18n?: ContelloI18nOptions | undefined;\n media?: Partial<ContelloMediaConfig> | undefined;\n};\n\ntype HasFallback<O> = O extends { fallback: infer F } ? ([F] extends [undefined] ? false : true) : false;\n\nexport const runRequest = Symbol('@contello/astro/runRequest');\n\nfunction buildI18nRegistrations(): I18nMessageRegistrationDefinition[] {\n const manifest = i18n.getManifest();\n const defaultLanguage = i18n.getConfig().defaultLocale;\n\n return manifest.keys.map((extracted) => ({\n token: extracted.key,\n example: extracted.meta.fallback,\n description: extracted.meta.description ?? '',\n variables: Object.entries(extracted.meta.variables ?? {}).map(([name, def]) => ({\n name,\n description: def?.description ?? '',\n example: def?.fallback ?? '',\n })),\n initialTranslations: [{ language: defaultLanguage, message: extracted.meta.fallback }],\n }));\n}\n\nasync function applyTranslations(messages: I18nMessages): Promise<void> {\n const config = i18n.getConfig();\n const all = await messages.getAll();\n const byLocale = new Map<string, RawTranslations>();\n\n for (const locale of config.locales) {\n byLocale.set(locale, {});\n }\n\n for (const msg of all) {\n msg.translations.forEach((value, language) => {\n const raw = byLocale.get(language);\n\n if (raw) {\n raw[msg.token] = value;\n }\n });\n }\n\n for (const [locale, translations] of byLocale) {\n i18n.setTranslations(locale, translations);\n }\n}\n\ntype ModelsOf<TSchema> = TSchema extends { models: infer M } ? keyof M & string : string;\ntype CollectionArg<TSchema> = SourceKeysOf<TSchema, 'entity'> | SourceDef<ModelsOf<TSchema>, 'entity'>;\ntype SingletonArg<TSchema> = SourceKeysOf<TSchema, 'singleton'> | SourceDef<ModelsOf<TSchema>, 'singleton'>;\ntype CollectionRaw<TSchema, TArg> = ExtractSourceResult<\n Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>\n>;\ntype SingletonRaw<TSchema, TArg> = ExtractSourceResult<\n Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'singleton'>>\n>;\n\nexport class Contello<TSchema extends Schema | undefined = undefined> {\n private readonly _store: Store<TSchema>;\n private readonly _options: ContelloOptions<TSchema>;\n private _i18nMessages: I18nMessages | undefined;\n private _i18nUnsubscribe: (() => void) | undefined;\n private _initialized = false;\n private readonly _als = new AsyncLocalStorage<ContelloRequestContext>();\n private _autoLazyRoutes?: LazyRoutes;\n\n readonly media: ContelloMediaConfig;\n\n // --- middleware factories (arrow fields so destructuring works) ---\n\n createRoutingMiddleware = (options?: ContelloRoutingMiddlewareOptions | undefined) => {\n const routes = options?.routes ?? (this._autoLazyRoutes ??= this.defineLazyRoutes());\n\n return createBoundRoutingMiddleware(this, routes, options?.exclude, options?.resolveRoutePath);\n };\n\n createAssetsMiddleware = (options?: ContelloAssetsMiddlewareOptions | undefined) => {\n return createBoundAssetsMiddleware(this, options);\n };\n\n constructor(options: ContelloOptions<TSchema>) {\n this._options = options;\n this._store = createStore<TSchema>(options);\n\n this.media = {\n baseUrl: options.media?.baseUrl ?? '',\n imagesPath: options.media?.imagesPath ?? DEFAULT_IMAGES_PREFIX,\n videosPath: options.media?.videosPath ?? DEFAULT_VIDEO_PREFIX,\n filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX,\n };\n }\n\n // --- lifecycle ---\n\n async init(options?: ContelloInitOptions | undefined): Promise<void> {\n try {\n await this._store.init();\n\n if (this._options.i18n) {\n const { collection, languages, cache } = this._options.i18n;\n const dev = getBootContext()?.dev ?? false;\n const { register = !dev, load = true } = options?.i18n ?? {};\n\n this._i18nMessages = this._store.defineI18nMessages({ collection, cache });\n\n await i18n.configure({ locales: languages });\n\n if (register) {\n const registrations = buildI18nRegistrations();\n\n if (registrations.length > 0) {\n await this._i18nMessages.register(registrations);\n }\n }\n\n if (load) {\n await applyTranslations(this._i18nMessages);\n\n const messages = this._i18nMessages;\n const controller = new AbortController();\n\n this._i18nUnsubscribe = () => controller.abort();\n\n // background loop: re-apply translations on every refresh until destroy()\n void (async () => {\n for await (const _ of messages.refresh$) {\n if (controller.signal.aborted) {\n return;\n }\n\n await applyTranslations(messages);\n }\n })();\n }\n }\n\n await Promise.all((options?.load ?? []).map((l) => l.load()));\n\n this._initialized = true;\n } catch (error) {\n try {\n await this.destroy();\n } catch {\n // ignore teardown errors; the original init error is rethrown below\n }\n\n throw error;\n }\n }\n\n async destroy(): Promise<void> {\n this._initialized = false;\n\n this._i18nUnsubscribe?.();\n this._i18nUnsubscribe = undefined;\n\n await this._store.destroy();\n\n this._i18nMessages = undefined;\n }\n\n ping(): Promise<void> {\n return this._store.ping();\n }\n\n get isReady(): boolean {\n return this._initialized;\n }\n\n get client(): ContelloClient<TSchema> {\n return this._store.client;\n }\n\n get i18nMessages(): I18nMessages {\n if (!this._i18nMessages) {\n throw new Error('@contello/astro: .i18nMessages accessed before init() with i18n config');\n }\n\n return this._i18nMessages;\n }\n\n // --- ALS request context ---\n\n get request(): ContelloRequestContext {\n const ctx = this._als.getStore();\n\n if (!ctx) {\n throw new Error('@contello/astro: .request accessed outside of request context');\n }\n\n return ctx;\n }\n\n // --- media resolvers (on-demand) ---\n\n defineMediaResolver<O extends Partial<MediaResolverOptions>>(options?: O): MediaResolver<HasFallback<O>> {\n return createMediaResolver({\n ...this.media,\n ...options,\n }) as MediaResolver<HasFallback<O>>;\n }\n\n // --- store delegation ---\n\n defineSingleton<TArg extends SingletonArg<TSchema>, TMapped = SingletonRaw<TSchema, TArg>>(\n sourceOrKey: TArg,\n options?: SingletonOptions<SingletonRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): Singleton<TMapped> {\n return this._store.defineSingleton(sourceOrKey as any, options as any) as Singleton<TMapped>;\n }\n\n defineSingletonSync<TArg extends SingletonArg<TSchema>, TMapped = SingletonRaw<TSchema, TArg>>(\n sourceOrKey: TArg,\n options?: SingletonSyncOptions<SingletonRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): SingletonSync<TMapped> {\n return this._store.defineSingletonSync(sourceOrKey as any, options as any) as SingletonSync<TMapped>;\n }\n\n defineCollection<\n TArg extends CollectionArg<TSchema>,\n TMapped extends { id: string } = CollectionRaw<TSchema, TArg> & { id: string },\n >(\n sourceOrKey: TArg,\n options?: CollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): Collection<TMapped> {\n return this._store.defineCollection(sourceOrKey as any, options as any) as Collection<TMapped>;\n }\n\n defineCollectionSync<\n TArg extends CollectionArg<TSchema>,\n TMapped extends { id: string } = CollectionRaw<TSchema, TArg> & { id: string },\n >(\n sourceOrKey: TArg,\n options?: CollectionSyncOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): CollectionSync<TMapped> {\n return this._store.defineCollectionSync(sourceOrKey as any, options as any) as CollectionSync<TMapped>;\n }\n\n defineLazyCollection<\n TArg extends CollectionArg<TSchema>,\n TMapped extends { id: string } = CollectionRaw<TSchema, TArg> & { id: string },\n >(\n sourceOrKey: TArg,\n options?: LazyCollectionOptions<CollectionRaw<TSchema, TArg>, TMapped, ModelsOf<TSchema>>,\n ): LazyCollection<TMapped> {\n return this._store.defineLazyCollection(sourceOrKey as any, options as any) as LazyCollection<TMapped>;\n }\n\n defineRoutes(options?: RoutesOptions | undefined): Routes {\n return this._store.defineRoutes(options);\n }\n\n defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync {\n return this._store.defineRoutesSync(options);\n }\n\n defineLazyRoutes(options?: LazyRoutesOptions | undefined): LazyRoutes {\n return this._store.defineLazyRoutes(options);\n }\n\n defineAssets(options?: AssetsOptions | undefined): Assets {\n return this._store.defineAssets(options);\n }\n\n defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync {\n return this._store.defineAssetsSync(options);\n }\n\n defineLazyAssets(options?: LazyAssetsOptions | undefined): LazyAssets {\n return this._store.defineLazyAssets(options);\n }\n\n // --- ALS run ---\n\n [runRequest]<T>(ctx: ContelloRequestContext, fn: () => T): T {\n return this._als.run(ctx, fn);\n }\n}\n\nexport function createContello<TSchema extends Schema | undefined = undefined>(\n options: ContelloOptions<TSchema>,\n): Contello<TSchema> {\n return new Contello(options);\n}\n"],"mappings":";;;;;;;;;;AAEA,MAAa,EAAE,SAAS,yBAAyB,iBAAiB;;;ACoBlE,MAAM,+BAA+B;AAErC,SAAgB,4BACd,UACA,SACA;CACA,MAAM,eAAe,SAAS,MAAM;CACpC,MAAM,qBAAqB,SAAS,QAAQ,gBAAgB;CAC5D,MAAM,cAAc,SAAS,MAAM;CACnC,MAAM,oBAAoB,SAAS,OAAO;CAC1C,MAAM,cAAc,SAAS,MAAM;CAEnC,OAAO,kBAAkB,KAAK,SAAS;EACrC,MAAM,EAAE,aAAa,IAAI;EACzB,MAAM,UAAU,SAAS,WAAW,YAAY;EAChD,MAAM,SAAS,CAAC,WAAW,SAAS,WAAW,WAAW;EAC1D,MAAM,UAAU,CAAC,WAAW,CAAC,UAAU,SAAS,WAAW,WAAW;EAEtE,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,SAC1B,OAAO,KAAK;EAGd,IAAI,CAAC,SAAS,SAAS;GACrB,QAAQ,KAAK,uDAAuD,UAAU;GAE9E,OAAO,KAAK;EACd;EAEA,IAAI,SACF,OAAO,WACL,SAAS,QACT,MACA,SAAS,MAAM,aAAa,MAAM,GAClC,oBACA,GAAG,aAAa,OAClB;EAGF,IAAI,QACF,OAAO,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C;EACxD,OAAO,KAAK,OAAO,aAAa,OAAO;CACzC;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAIA,CAAC,YAAe,KAA6B,IAAgB;EAC3D,OAAO,KAAK,KAAK,IAAI,KAAK,EAAE;CAC9B;AACF;AAEA,SAAgB,eACd,SACmB;CACnB,OAAO,IAAI,SAAS,OAAO;AAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contello/astro",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "Astro integration for Contello CMS — route middleware and i18n bridge",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,15 +11,15 @@
11
11
  "directory": "packages/astro"
12
12
  },
13
13
  "dependencies": {
14
- "@contello/opentelemetry": "^2.1.0"
14
+ "@contello/opentelemetry": "^2.1.1"
15
15
  },
16
16
  "peerDependencies": {
17
- "@astroscope/i18n": ">=0.3.0",
18
- "@astroscope/node": ">=1.0.0",
17
+ "@astroscope/i18n": ">=1.0.0",
18
+ "@astroscope/node": ">=1.3.0",
19
19
  "astro": "^6.0.0 || ^7.0.0",
20
- "@contello/client": "^3.0.0",
21
- "@contello/media": "^2.2.1",
22
- "@contello/store": "^4.1.0"
20
+ "@contello/client": "^3.0.1",
21
+ "@contello/store": "^4.1.1",
22
+ "@contello/media": "^2.2.2"
23
23
  },
24
24
  "peerDependenciesMeta": {
25
25
  "@astroscope/i18n": {
@@ -27,12 +27,12 @@
27
27
  }
28
28
  },
29
29
  "devDependencies": {
30
- "@astroscope/i18n": "^1.0.0",
31
- "@astroscope/node": "^1.0.0",
30
+ "@astroscope/i18n": "^1.0.2",
31
+ "@astroscope/node": "^1.3.0",
32
32
  "astro": "^7.0.3",
33
- "@contello/client": "^3.0.0",
34
- "@contello/media": "^2.2.1",
35
- "@contello/store": "^4.1.0"
33
+ "@contello/store": "^4.1.1",
34
+ "@contello/client": "^3.0.1",
35
+ "@contello/media": "^2.2.2"
36
36
  },
37
37
  "files": [
38
38
  "dist"