@contello/astro 5.0.0 → 6.0.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/assets-middleware-entrypoint.d.ts +0 -2
- package/dist/assets-middleware-entrypoint.d.ts.map +1 -1
- package/dist/assets-middleware-entrypoint.js +1 -2
- package/dist/index.cjs +7 -15
- package/dist/index.d.cts +0 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -13
- package/dist/index.js.map +1 -1
- package/dist/routing-middleware-entrypoint.d.ts +0 -2
- package/dist/routing-middleware-entrypoint.d.ts.map +1 -1
- package/dist/routing-middleware-entrypoint.js +1 -2
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets-middleware-entrypoint.d.ts","names":[],"sources":["../src/assets-middleware-entrypoint.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"assets-middleware-entrypoint.d.ts","names":[],"sources":["../src/assets-middleware-entrypoint.ts"],"mappings":"A,qBAEa"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { contello } from "virtual:@contello/astro/instance";
|
|
2
|
-
|
|
2
|
+
// src/assets-middleware-entrypoint.ts
|
|
3
3
|
const onRequest = contello.createAssetsMiddleware();
|
|
4
|
-
//#endregion
|
|
5
4
|
export { onRequest };
|
|
6
5
|
|
|
7
6
|
//# sourceMappingURL=assets-middleware-entrypoint.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
|
|
5
|
+
// \0rolldown/runtime.js
|
|
6
6
|
var __create = Object.create;
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
26
|
let node_fs = require("node:fs");
|
|
28
27
|
node_fs = __toESM(node_fs, 1);
|
|
29
28
|
let node_path = require("node:path");
|
|
@@ -57,8 +56,7 @@ function contelloVitePlugin(options) {
|
|
|
57
56
|
}
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
//#region src/integration.ts
|
|
59
|
+
// src/integration.ts
|
|
62
60
|
const DEFAULT_ENTRY = "src/server/contello.ts";
|
|
63
61
|
/**
|
|
64
62
|
* Astro integration for Contello.
|
|
@@ -91,16 +89,13 @@ function contelloIntegration(options = {}) {
|
|
|
91
89
|
} }
|
|
92
90
|
};
|
|
93
91
|
}
|
|
94
|
-
|
|
95
|
-
//#region src/middleware.ts
|
|
92
|
+
// src/middleware.ts
|
|
96
93
|
function defineMiddleware(handler) {
|
|
97
94
|
return handler;
|
|
98
95
|
}
|
|
99
|
-
|
|
100
|
-
//#region src/telemetry.ts
|
|
96
|
+
// src/telemetry.ts
|
|
101
97
|
const { wrap } = (0, _contello_opentelemetry.createOperationTelemetry)("@contello/astro");
|
|
102
|
-
|
|
103
|
-
//#region src/assets-middleware.ts
|
|
98
|
+
// src/assets-middleware.ts
|
|
104
99
|
const DEFAULT_IMAGES_CACHE_CONTROL = "public, max-age=31536000";
|
|
105
100
|
/**
|
|
106
101
|
* `options` is read per request: the integration creates the middleware before `init()`
|
|
@@ -162,8 +157,7 @@ function handleVideo(client, next, path, signal, routeLabel) {
|
|
|
162
157
|
}
|
|
163
158
|
})();
|
|
164
159
|
}
|
|
165
|
-
|
|
166
|
-
//#region src/routing-middleware.ts
|
|
160
|
+
// src/routing-middleware.ts
|
|
167
161
|
function customHeaders(headers) {
|
|
168
162
|
const result = {};
|
|
169
163
|
for (const h of headers) result[h.name] = h.value;
|
|
@@ -290,8 +284,7 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
290
284
|
});
|
|
291
285
|
});
|
|
292
286
|
}
|
|
293
|
-
|
|
294
|
-
//#region src/contello.ts
|
|
287
|
+
// src/contello.ts
|
|
295
288
|
const DEFAULT_IMAGES_PREFIX = "/_contello/i/";
|
|
296
289
|
const DEFAULT_FILES_PREFIX = "/_contello/f/";
|
|
297
290
|
const DEFAULT_VIDEO_PREFIX = "/_contello/v/";
|
|
@@ -502,7 +495,6 @@ var Contello = class {
|
|
|
502
495
|
function createContello(options) {
|
|
503
496
|
return new Contello(options);
|
|
504
497
|
}
|
|
505
|
-
//#endregion
|
|
506
498
|
exports.Contello = Contello;
|
|
507
499
|
exports.createContello = createContello;
|
|
508
500
|
exports.default = contelloIntegration;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,6 @@ import { ContelloClient, Schema, SourceDef } from "@contello/client";
|
|
|
5
5
|
import { MediaResolver, MediaResolverOptions } from "@contello/media";
|
|
6
6
|
import { Assets, AssetsOptions, AssetsSync, AssetsSyncOptions, BuiltInWrites, Collection, CollectionOptions, CollectionSync, CollectionSyncOptions, CreateStoreOptions, ExtractSourceResult, ExtractSourceWrites, I18nMessages, LazyAssets, LazyAssetsOptions, LazyCollection, LazyCollectionOptions, LazyRoutes, LazyRoutesOptions, Loadable, ResolveSource, Routes, RoutesOptions, RoutesSync, RoutesSyncOptions, Singleton, SingletonOptions, SingletonSync, SingletonSyncOptions, SourceKeysOf, StoreRoute, SyncCacheOptions } from "@contello/store";
|
|
7
7
|
import { ReadonlyDeep } from "@entwico/dash";
|
|
8
|
-
//#region src/integration.d.ts
|
|
9
8
|
type ContelloIntegrationOptions = {
|
|
10
9
|
/**
|
|
11
10
|
* Module exporting the `contello` instance (`export const contello = createContello(...)`),
|
|
@@ -42,8 +41,6 @@ type ContelloIntegrationOptions = {
|
|
|
42
41
|
* only serializable ones belong here.
|
|
43
42
|
*/
|
|
44
43
|
export default function contelloIntegration(options?: ContelloIntegrationOptions): AstroIntegration;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/assets-middleware.d.ts
|
|
47
44
|
type ContelloAssetsImagesOptions = {
|
|
48
45
|
cacheControl?: string | undefined;
|
|
49
46
|
};
|
|
@@ -56,8 +53,6 @@ type ContelloAssetsMiddlewareOptions = {
|
|
|
56
53
|
files?: ContelloAssetsFilesOptions | undefined;
|
|
57
54
|
video?: ContelloAssetsVideoOptions | undefined;
|
|
58
55
|
};
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/routing-middleware.d.ts
|
|
61
56
|
type AnyRoutes = Routes | RoutesSync | LazyRoutes;
|
|
62
57
|
/**
|
|
63
58
|
* Derives the path used to look up a Contello route from the request context.
|
|
@@ -81,8 +76,6 @@ type ContelloRoutingMiddlewareOptions = {
|
|
|
81
76
|
exclude?: ExcludePattern[] | undefined;
|
|
82
77
|
resolveRoutePath?: RoutePathResolver | undefined;
|
|
83
78
|
};
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/contello.d.ts
|
|
86
79
|
type ContelloRequestContext = {
|
|
87
80
|
url: URL;
|
|
88
81
|
route: ReadonlyDeep<StoreRoute> | undefined;
|
|
@@ -210,6 +203,5 @@ export declare class Contello<TSchema extends Schema | undefined = undefined> {
|
|
|
210
203
|
[runRequest]<T>(ctx: ContelloRequestContext, fn: () => T): T;
|
|
211
204
|
}
|
|
212
205
|
export declare function createContello<TSchema extends Schema | undefined = undefined>(options: ContelloOptions<TSchema>): Contello<TSchema>;
|
|
213
|
-
//#endregion
|
|
214
206
|
export type { AnyRoutes, ContelloAssetsFilesOptions, ContelloAssetsImagesOptions, ContelloAssetsMiddlewareOptions, ContelloAssetsVideoOptions, ContelloHealthOptions, ContelloI18nOptions, ContelloInitI18nOptions, ContelloInitOptions, ContelloIntegrationOptions, ContelloOptions, ContelloRequestContext, ContelloRoutingMiddlewareOptions, ContelloRoutingOptions, RoutePathResolver };
|
|
215
207
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/integration.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/integration.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"mappings":";;;;;;;KASY;;;;;;EAMV;;;;;;EAMA;;;;;;;EAOA;;;;;EAKA,UAAU;;;;;;;;;;;wBAYY,oBAAoB,UAAS,6BAAkC;KCvC3E;EACV;;KAGU;EACV;;KAGU,6BAA6B;KAE7B;EACV,SAAS;EACT,QAAQ;EACR,QAAQ;;KCTE,YAAY,SAAS,aAAa;;;;;;;;;;KAWlC,qBAAqB,KAAK;KAE1B;;;;;;;;EAQV,SAAS;EACT,UAAU;EACV,mBAAmB;;KCuBT;EACV,KAAK;EACL,OAAO,aAAa;EACpB;;;KAIU;EACV;EACA,QAAQ;;;;;;KAOE,0BAA0B;;;;;EAKpC;;EAEA;;KAGU;EACV,mBAAmB;;;KAIT;;EAEV;EACA;EACA;;KAGU;EACV,OAAO;;;;;;;EAOP,0BAA0B;;EAE1B,OAAO;;EAEP,UAAU;;EAEV,SAAS;EACT,SAAS;;KAGC;WACD;WACA;WACA;WACA;;KAGC,gBAAgB,gBAAgB,kCAAkC,mBAAmB;EAC/F,OAAO;EACP,QAAQ,QAAQ;;KAOb,YAAY,KAAK;EAAY,gBAAgB;MAAQ;cAE7C;KA2CR,SAAS,WAAW;EAAkB,cAAc;UAAY;KAChE,cAAc,WAAW,aAAa,qBAAqB,UAAU,SAAS;KAC9E,aAAa,WAAW,aAAa,wBAAwB,UAAU,SAAS;KAChF,cAAc,SAAS,QAAQ,oBAClC,QAAQ,cAAc,SAAS,OAAO;;KAGnC,mBAAmB,SAAS,QAAQ,oBACvC,QAAQ,cAAc,SAAS,OAAO;KAE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U,gCAAgC,WAAW,YAAY;EAIlF,iBAAiB,UAAU,gCAAgC;EAI3D,aAAa,UAAU,4BAA4B,OAAO,YAAY;EAItE,iBAAiB,UAAU,gCAAgC,WAAW,YAAY;EAIlF,iBAAiB,UAAU,gCAAgC;GAM1D,YAAY,GAAG,KAAK,wBAAwB,UAAU,IAAI;;wBAK7C,eAAe,gBAAgB,gCAC7C,SAAS,gBAAgB,WACxB,SAAS"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { Assets, AssetsOptions, AssetsSync, AssetsSyncOptions, BuiltInWrites, Co
|
|
|
5
5
|
import { ReadonlyDeep } from "@entwico/dash";
|
|
6
6
|
import { APIContext, AstroIntegration } from "astro";
|
|
7
7
|
import { ContelloClient, Schema, SourceDef } from "@contello/client";
|
|
8
|
-
//#region src/integration.d.ts
|
|
9
8
|
type ContelloIntegrationOptions = {
|
|
10
9
|
/**
|
|
11
10
|
* Module exporting the `contello` instance (`export const contello = createContello(...)`),
|
|
@@ -42,8 +41,6 @@ type ContelloIntegrationOptions = {
|
|
|
42
41
|
* only serializable ones belong here.
|
|
43
42
|
*/
|
|
44
43
|
export default function contelloIntegration(options?: ContelloIntegrationOptions): AstroIntegration;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/assets-middleware.d.ts
|
|
47
44
|
type ContelloAssetsImagesOptions = {
|
|
48
45
|
cacheControl?: string | undefined;
|
|
49
46
|
};
|
|
@@ -56,8 +53,6 @@ type ContelloAssetsMiddlewareOptions = {
|
|
|
56
53
|
files?: ContelloAssetsFilesOptions | undefined;
|
|
57
54
|
video?: ContelloAssetsVideoOptions | undefined;
|
|
58
55
|
};
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/routing-middleware.d.ts
|
|
61
56
|
type AnyRoutes = Routes | RoutesSync | LazyRoutes;
|
|
62
57
|
/**
|
|
63
58
|
* Derives the path used to look up a Contello route from the request context.
|
|
@@ -81,8 +76,6 @@ type ContelloRoutingMiddlewareOptions = {
|
|
|
81
76
|
exclude?: ExcludePattern[] | undefined;
|
|
82
77
|
resolveRoutePath?: RoutePathResolver | undefined;
|
|
83
78
|
};
|
|
84
|
-
//#endregion
|
|
85
|
-
//#region src/contello.d.ts
|
|
86
79
|
type ContelloRequestContext = {
|
|
87
80
|
url: URL;
|
|
88
81
|
route: ReadonlyDeep<StoreRoute> | undefined;
|
|
@@ -210,6 +203,5 @@ export declare class Contello<TSchema extends Schema | undefined = undefined> {
|
|
|
210
203
|
[runRequest]<T>(ctx: ContelloRequestContext, fn: () => T): T;
|
|
211
204
|
}
|
|
212
205
|
export declare function createContello<TSchema extends Schema | undefined = undefined>(options: ContelloOptions<TSchema>): Contello<TSchema>;
|
|
213
|
-
//#endregion
|
|
214
206
|
export type { AnyRoutes, ContelloAssetsFilesOptions, ContelloAssetsImagesOptions, ContelloAssetsMiddlewareOptions, ContelloAssetsVideoOptions, ContelloHealthOptions, ContelloI18nOptions, ContelloInitI18nOptions, ContelloInitOptions, ContelloIntegrationOptions, ContelloOptions, ContelloRequestContext, ContelloRoutingMiddlewareOptions, ContelloRoutingOptions, RoutePathResolver };
|
|
215
207
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/integration.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/integration.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"mappings":";;;;;;;KASY;;;;;;EAMV;;;;;;EAMA;;;;;;;EAOA;;;;;EAKA,UAAU;;;;;;;;;;;wBAYY,oBAAoB,UAAS,6BAAkC;KCvC3E;EACV;;KAGU;EACV;;KAGU,6BAA6B;KAE7B;EACV,SAAS;EACT,QAAQ;EACR,QAAQ;;KCTE,YAAY,SAAS,aAAa;;;;;;;;;;KAWlC,qBAAqB,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a,MACb,UAAU,iBAAiB,aAAa,SAAS,OAAO,SAAS,SAAS,YACzE,UAAU;EAIb,oBAAoB,aAAa,aAAa,UAAU,UAAU,aAAa,SAAS,OACtF,aAAa,MACb,UAAU,qBAAqB,aAAa,SAAS,OAAO,SAAS,SAAS,YAC7E,cAAc;EAIjB,iBACE,aAAa,cAAc,UAC3B;IAAkB;MAAe,cAAc,SAAS;IAAU;KAElE,aAAa,MACb,UAAU,kBAAkB,cAAc,SAAS,OAAO,SAAS,SAAS,YAC3E,WAAW,SAAS,mBAAmB,SAAS;EAOnD,qBACE,aAAa,cAAc,UAC3B;IAAkB;MAAe,cAAc,SAAS;IAAU;KAElE,aAAa,MACb,UAAU,sBAAsB,cAAc,SAAS,OAAO,SAAS,SAAS,YAC/E,eAAe,SAAS,mBAAmB,SAAS;EAOvD,qBACE,aAAa,cAAc,UAC3B;IAAkB;MAAe,cAAc,SAAS;IAAU;KAElE,aAAa,MACb,UAAU,sBAAsB,cAAc,SAAS,OAAO,SAAS,SAAS,YAC/E,eAAe;EAIlB,aAAa,UAAU,4BAA4B,OAAO,YAAY;EAItE,iBAAiB,UAAU,gCAAgC,WAAW,YAAY;EAIlF,iBAAiB,UAAU,gCAAgC;EAI3D,aAAa,UAAU,4BAA4B,OAAO,YAAY;EAItE,iBAAiB,UAAU,gCAAgC,WAAW,YAAY;EAIlF,iBAAiB,UAAU,gCAAgC;GAM1D,YAAY,GAAG,KAAK,wBAAwB,UAAU,IAAI;;wBAK7C,eAAe,gBAAgB,gCAC7C,SAAS,gBAAgB,WACxB,SAAS"}
|
package/dist/index.js
CHANGED
|
@@ -29,8 +29,7 @@ function contelloVitePlugin(options) {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
//#region src/integration.ts
|
|
32
|
+
// src/integration.ts
|
|
34
33
|
const DEFAULT_ENTRY = "src/server/contello.ts";
|
|
35
34
|
/**
|
|
36
35
|
* Astro integration for Contello.
|
|
@@ -63,16 +62,13 @@ function contelloIntegration(options = {}) {
|
|
|
63
62
|
} }
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
|
-
|
|
67
|
-
//#region src/middleware.ts
|
|
65
|
+
// src/middleware.ts
|
|
68
66
|
function defineMiddleware(handler) {
|
|
69
67
|
return handler;
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
//#region src/telemetry.ts
|
|
69
|
+
// src/telemetry.ts
|
|
73
70
|
const { wrap } = createOperationTelemetry("@contello/astro");
|
|
74
|
-
|
|
75
|
-
//#region src/assets-middleware.ts
|
|
71
|
+
// src/assets-middleware.ts
|
|
76
72
|
const DEFAULT_IMAGES_CACHE_CONTROL = "public, max-age=31536000";
|
|
77
73
|
/**
|
|
78
74
|
* `options` is read per request: the integration creates the middleware before `init()`
|
|
@@ -134,8 +130,7 @@ function handleVideo(client, next, path, signal, routeLabel) {
|
|
|
134
130
|
}
|
|
135
131
|
})();
|
|
136
132
|
}
|
|
137
|
-
|
|
138
|
-
//#region src/routing-middleware.ts
|
|
133
|
+
// src/routing-middleware.ts
|
|
139
134
|
function customHeaders(headers) {
|
|
140
135
|
const result = {};
|
|
141
136
|
for (const h of headers) result[h.name] = h.value;
|
|
@@ -262,8 +257,7 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
262
257
|
});
|
|
263
258
|
});
|
|
264
259
|
}
|
|
265
|
-
|
|
266
|
-
//#region src/contello.ts
|
|
260
|
+
// src/contello.ts
|
|
267
261
|
const DEFAULT_IMAGES_PREFIX = "/_contello/i/";
|
|
268
262
|
const DEFAULT_FILES_PREFIX = "/_contello/f/";
|
|
269
263
|
const DEFAULT_VIDEO_PREFIX = "/_contello/v/";
|
|
@@ -474,7 +468,6 @@ var Contello = class {
|
|
|
474
468
|
function createContello(options) {
|
|
475
469
|
return new Contello(options);
|
|
476
470
|
}
|
|
477
|
-
//#endregion
|
|
478
471
|
export { Contello, createContello, contelloIntegration as default };
|
|
479
472
|
|
|
480
473
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/vite-plugin.ts","../src/integration.ts","../src/middleware.ts","../src/telemetry.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"sourcesContent":["import { type ExcludePattern, serializeExcludePatterns } from '@astroscope/node/excludes';\nimport type { Plugin } from 'vite';\n\nexport const INSTANCE_VIRTUAL_MODULE_ID = 'virtual:@contello/astro/instance';\nexport const CONFIG_VIRTUAL_MODULE_ID = 'virtual:@contello/astro/config';\n\nconst RESOLVED_CONFIG_VIRTUAL_MODULE_ID = `\\0${CONFIG_VIRTUAL_MODULE_ID}`;\n\nexport type ContelloVitePluginOptions = {\n /** absolute path of the module exporting the `contello` instance */\n entry: string;\n /** routing exclude patterns, null for the middleware default */\n exclude: ExcludePattern[] | null;\n};\n\n/**\n * Resolves the instance id straight to the project's module, so the injected\n * middlewares and the project's own imports share one `Contello` instance, and\n * serves the serializable integration options as a config module.\n */\nexport function contelloVitePlugin(options: ContelloVitePluginOptions): Plugin {\n return {\n name: '@contello/astro',\n\n resolveId(id) {\n if (id === INSTANCE_VIRTUAL_MODULE_ID) {\n return options.entry;\n }\n\n if (id === CONFIG_VIRTUAL_MODULE_ID) {\n return RESOLVED_CONFIG_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_CONFIG_VIRTUAL_MODULE_ID) {\n // exclude patterns may contain RegExp — serialized as code, not JSON\n return `export const exclude = ${options.exclude ? serializeExcludePatterns(options.exclude) : 'null'};`;\n }\n },\n };\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ExcludePattern } from '@astroscope/node/excludes';\nimport type { AstroIntegration } from 'astro';\nimport { contelloVitePlugin } from './vite-plugin';\n\nconst DEFAULT_ENTRY = 'src/server/contello.ts';\n\nexport type ContelloIntegrationOptions = {\n /**\n * Module exporting the `contello` instance (`export const contello = createContello(...)`),\n * relative to the project root.\n * @default 'src/server/contello.ts'\n */\n entry?: string | undefined;\n /**\n * Where the assets middleware (`/_contello/i/`, `/_contello/f/`, `/_contello/v/`) is injected;\n * `false` leaves it to the project (`contello.createAssetsMiddleware()`).\n * @default 'pre'\n */\n assets?: 'pre' | false | undefined;\n /**\n * Where the routing middleware is injected; `false` leaves it to the project\n * (`contello.createRoutingMiddleware()`). Post middlewares run in `integrations` order, so list\n * `contello()` before integrations whose middleware depends on the resolved route, e.g. `@astroscope/wormhole`.\n * @default 'post'\n */\n routing?: 'post' | false | undefined;\n /**\n * Paths the routing middleware skips.\n * @default RECOMMENDED_EXCLUDES from `@astroscope/node/excludes`\n */\n exclude?: ExcludePattern[] | undefined;\n};\n\n/**\n * Astro integration for Contello.\n *\n * Injects the assets middleware ahead of the project's own middleware and the routing\n * middleware after it, both bound to the project's `contello` instance, which the\n * integration resolves from `src/server/contello.ts` (or `entry`). Runtime options\n * (`resolveRoutePath`, assets cache control, the routes instance) live on the instance,\n * only serializable ones belong here.\n */\nexport default function contelloIntegration(options: ContelloIntegrationOptions = {}): AstroIntegration {\n const { entry = DEFAULT_ENTRY, assets = 'pre', routing = 'post', exclude = null } = options;\n\n return {\n name: '@contello/astro',\n hooks: {\n 'astro:config:setup': ({ config, updateConfig, addMiddleware }) => {\n const entryPath = path.resolve(fileURLToPath(config.root), entry);\n\n if (!fs.existsSync(entryPath)) {\n throw new Error(\n `@contello/astro: instance module ${entry} not found — ` +\n 'export `contello = createContello(...)` from it or point the integration\\'s `entry` option at it',\n );\n }\n\n if (assets) {\n addMiddleware({ order: assets, entrypoint: '@contello/astro/assets-middleware' });\n }\n\n if (routing) {\n addMiddleware({ order: routing, entrypoint: '@contello/astro/routing-middleware' });\n }\n\n updateConfig({\n vite: {\n plugins: [contelloVitePlugin({ entry: entryPath, exclude })],\n },\n });\n },\n },\n };\n}\n","import type { MiddlewareHandler } from 'astro';\n\n// a local identity instead of `astro/middleware`: a runtime import of astro's middleware entry pulls every module that\n// imports this package into astro's runtime module graph — in dev, astro invalidates that graph on any file change,\n// which re-evaluates boot-loaded singletons and makes @astroscope/node restart the server on every component edit\nexport function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler {\n return handler;\n}\n","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 type { Contello } from './contello';\nimport { defineMiddleware } from './middleware';\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\n/**\n * `options` is read per request: the integration creates the middleware before `init()`\n * brings the project's assets options; `false` disables the middleware (`init({ assets: false })`).\n */\nexport function createBoundAssetsMiddleware(\n contello: Contello<any>,\n options: () => ContelloAssetsMiddlewareOptions | false | undefined,\n) {\n const imagesPrefix = contello.media.imagesPath;\n const filesPrefix = contello.media.filesPath;\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 const current = options();\n\n if (current === false) {\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 current?.images?.cacheControl ?? DEFAULT_IMAGES_CACHE_CONTROL,\n `${imagesPrefix}[file]`,\n );\n }\n\n if (isFile) {\n return handleFile(\n contello.client,\n next,\n pathname.slice(filesPrefix.length),\n current?.files?.cacheControl,\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 type { LazyRoutes, Routes, RoutesSync, StoreRoute, StoreRouteCustomHeader } from '@contello/store';\nimport { type MaybePromise, maybeThen } from '@entwico/dash';\nimport type { APIContext, ValidRedirectStatus } from 'astro';\nimport { type Contello, runRequest } from './contello';\nimport { defineMiddleware } from './middleware';\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 | undefined,\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 // undefined: the project disabled routing (`init({ routes: false })`)\n const current = routes();\n\n if (!current) {\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 = current.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](\n { url, route, rewritten: false },\n () => wrap(\n 'route:redirect',\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](\n { url, route, rewritten: false },\n () => wrap(\n 'route:text',\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](\n { 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 'sitemap': {\n return contello[runRequest](\n { url, route, rewritten: false },\n () => wrap('route:sitemap', async () => {\n const result = await contello.client.proxySitemap(\n route.sitemapId,\n {\n source: url.searchParams.get('source') ?? undefined,\n page: url.searchParams.get('page') ?? undefined,\n acceptEncoding: ctx.request.headers.get('accept-encoding') ?? undefined,\n ifNoneMatch: ctx.request.headers.get('if-none-match') ?? undefined,\n },\n ctx.request.signal,\n );\n\n const passthrough = result.status === 304 || (result.status >= 200 && result.status < 300);\n\n if (!passthrough) {\n // core's error format stays internal: same status, no body, none of the upstream headers\n await result.stream().cancel();\n\n return new Response(null, { status: result.status, headers: customHeaders(route.customHeaders) });\n }\n\n const headers = new Headers(result.headers);\n\n for (const { name, value } of route.customHeaders) {\n headers.set(name, value);\n }\n\n return new Response(result.status === 304 ? null : result.stream(), { status: result.status, headers });\n }),\n );\n }\n\n case 'entity': {\n return contello[runRequest](\n { 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 I18nConfig, type RawTranslations, i18n } from '@astroscope/i18n';\nimport { getBootContext } from '@astroscope/node/boot';\nimport { registerHealthCheck } from '@astroscope/node/health';\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 BuiltInWrites,\n type Collection,\n type CollectionOptions,\n type CollectionSync,\n type CollectionSyncOptions,\n type CreateStoreOptions,\n type ExtractSourceResult,\n type ExtractSourceWrites,\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 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 { ReadonlyDeep } from '@entwico/dash';\nimport { type ContelloAssetsMiddlewareOptions, createBoundAssetsMiddleware } from './assets-middleware';\nimport {\n type AnyRoutes,\n type ContelloRoutingMiddlewareOptions,\n type RoutePathResolver,\n createBoundRoutingMiddleware,\n} 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\n/** The Contello i18n message collection bridged to `@astroscope/i18n`; `init()` takes the runtime side. */\nexport type ContelloI18nOptions = {\n collection: string;\n cache?: SyncCacheOptions | undefined;\n};\n\n/**\n * The `@astroscope/i18n` config `init()` passes to `i18n.configure()` before it pushes the\n * collection's translations, plus what to do with the extracted keys.\n */\nexport type ContelloInitI18nOptions = I18nConfig & {\n /**\n * Register the extracted keys in the collection; defaults to `true`, except in dev mode (detected via the\n * @astroscope/node boot context).\n */\n register?: boolean | undefined;\n /** push the collection's translations and follow its refreshes; defaults to `true` */\n load?: boolean | undefined;\n};\n\nexport type ContelloRoutingOptions = {\n resolveRoutePath?: RoutePathResolver | undefined;\n};\n\n/** The readiness check `init()` registers with `@astroscope/node/health`; `false` registers none. */\nexport type ContelloHealthOptions = {\n /** @default 'contello' */\n name?: string | undefined;\n optional?: boolean | undefined;\n timeout?: number | undefined;\n};\n\nexport type ContelloInitOptions = {\n load?: Loadable[] | undefined;\n /**\n * Routes backing the routing middleware: `'sync'` creates and loads a `RoutesSync` (eager, synchronous\n * lookups), `'lazy'` creates a `LazyRoutes` (fetched on demand), or an instance the project defined\n * itself, loaded by `init()` when it is loadable. Reachable as `contello.routes` after `init()`.\n * `false` for a project without Contello routes: the routing middleware passes through.\n */\n routes: 'sync' | 'lazy' | AnyRoutes | false;\n /** required when `createContello` got an `i18n` collection */\n i18n?: ContelloInitI18nOptions | undefined;\n /** defaults for the routing middleware, used by the integration-injected one */\n routing?: ContelloRoutingOptions | undefined;\n /** defaults for the assets middleware, used by the integration-injected one; `false` makes it pass through */\n assets?: ContelloAssetsMiddlewareOptions | false | undefined;\n health?: ContelloHealthOptions | false | 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\nfunction isLoadable(value: object): value is Loadable {\n return typeof (value as Partial<Loadable>).load === 'function';\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 createI18nRegistrations(): 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>;\n/** The write-input shape the source carries — keeps the collection's write half through the proxy. */\ntype CollectionWritesOf<TSchema, TArg> = ExtractSourceWrites<\n Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>\n>;\ntype RouteWrites<TSchema> = BuiltInWrites<TSchema, 'route'>;\ntype AssetWrites<TSchema> = BuiltInWrites<TSchema, 'asset'>;\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 _routes: AnyRoutes | undefined;\n private _initOptions: ContelloInitOptions | undefined;\n private _unregisterHealthCheck: (() => void) | undefined;\n\n readonly media: ContelloMediaConfig;\n\n // --- middleware factories (arrow fields so destructuring works) ---\n\n createRoutingMiddleware = (options?: ContelloRoutingMiddlewareOptions | undefined) => {\n // resolved per request: the integration creates the middleware before init() brings the routes and options\n const routes = () => options?.routes ?? (this._initOptions?.routes === false ? undefined : this.routes);\n const resolveRoutePath: RoutePathResolver = (ctx) => {\n const resolver = options?.resolveRoutePath ?? this._initOptions?.routing?.resolveRoutePath;\n\n return resolver ? resolver(ctx) : ctx.url.pathname;\n };\n\n return createBoundRoutingMiddleware(this, routes, options?.exclude, resolveRoutePath);\n };\n\n createAssetsMiddleware = (options?: ContelloAssetsMiddlewareOptions | undefined) => {\n return createBoundAssetsMiddleware(this, () => options ?? this._initOptions?.assets);\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 private createRoutes(routes: ContelloInitOptions['routes']): AnyRoutes | undefined {\n switch (routes) {\n case false: {\n return undefined;\n }\n\n case 'sync': {\n return this.defineRoutesSync();\n }\n\n case 'lazy': {\n return this.defineLazyRoutes();\n }\n\n default: {\n return routes;\n }\n }\n }\n\n private registerHealthCheck(health: ContelloHealthOptions | false | undefined): void {\n if (health === false) {\n return;\n }\n\n this._unregisterHealthCheck?.();\n this._unregisterHealthCheck = registerHealthCheck({\n name: health?.name ?? 'contello',\n check: () => this.ping(),\n optional: health?.optional,\n timeout: health?.timeout,\n });\n }\n\n async init(options: ContelloInitOptions): Promise<void> {\n try {\n this._initOptions = options;\n\n this.registerHealthCheck(options.health);\n\n await this._store.init();\n\n this._routes = this.createRoutes(options.routes);\n\n if (this._options.i18n) {\n if (!options.i18n) {\n throw new Error('@contello/astro: init() needs the i18n option (locales, locale resolver) for the configured i18n collection');\n }\n\n const { collection, cache } = this._options.i18n;\n const dev = getBootContext()?.dev ?? false;\n const { register = !dev, load = true, ...i18nConfig } = options.i18n;\n\n this._i18nMessages = this._store.defineI18nMessages({ collection, cache });\n\n await i18n.configure(i18nConfig);\n\n if (register) {\n const registrations = createI18nRegistrations();\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 const routes = this._routes;\n const loadables = [...(options.load ?? []), ...(routes && isLoadable(routes) ? [routes] : [])];\n\n await Promise.all(loadables.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 this._unregisterHealthCheck?.();\n this._unregisterHealthCheck = undefined;\n\n await this._store.destroy();\n\n this._i18nMessages = undefined;\n this._routes = undefined;\n this._initOptions = 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 /** the routes backing the routing middleware, created by `init()` from its `routes` option */\n get routes(): AnyRoutes {\n if (!this._routes) {\n throw new Error('@contello/astro: .routes accessed before init() or with routes disabled');\n }\n\n return this._routes;\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, CollectionWritesOf<TSchema, TArg>> {\n return this._store.defineCollection(sourceOrKey as any, options as any) as Collection<\n TMapped,\n CollectionWritesOf<TSchema, TArg>\n >;\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, CollectionWritesOf<TSchema, TArg>> {\n return this._store.defineCollectionSync(sourceOrKey as any, options as any) as CollectionSync<\n TMapped,\n CollectionWritesOf<TSchema, TArg>\n >;\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<RouteWrites<TSchema>> {\n return this._store.defineRoutes(options);\n }\n\n defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync<RouteWrites<TSchema>> {\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<AssetWrites<TSchema>> {\n return this._store.defineAssets(options);\n }\n\n defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync<AssetWrites<TSchema>> {\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":";;;;;;;;;;;;;AAMA,MAAM,oCAAoC;;;;;;AAc1C,SAAgB,mBAAmB,SAA4C;CAC7E,OAAO;EACL,MAAM;EAEN,UAAU,IAAI;GACZ,IAAI,OAAA,oCACF,OAAO,QAAQ;GAGjB,IAAI,OAAA,kCACF,OAAO;EAEX;EAEA,KAAK,IAAI;GACP,IAAI,OAAO,mCAET,OAAO,0BAA0B,QAAQ,UAAU,yBAAyB,QAAQ,OAAO,IAAI,OAAO;EAE1G;CACF;AACF;;;AClCA,MAAM,gBAAgB;;;;;;;;;;AAsCtB,SAAwB,oBAAoB,UAAsC,CAAC,GAAqB;CACtG,MAAM,EAAE,QAAQ,eAAe,SAAS,OAAO,UAAU,QAAQ,UAAU,SAAS;CAEpF,OAAO;EACL,MAAM;EACN,OAAO,EACL,uBAAuB,EAAE,QAAQ,cAAc,oBAAoB;GACjE,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,IAAI,GAAG,KAAK;G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4C;EACvG,OAAO,oBAAoB;GACzB,GAAG,KAAK;GACR,GAAG;EACL,CAAC;CACH;CAIA,gBACE,aACA,SACoB;EACpB,OAAO,KAAK,OAAO,gBAAgB,aAAoB,OAAc;CACvE;CAEA,oBACE,aACA,SACwB;EACxB,OAAO,KAAK,OAAO,oBAAoB,aAAoB,OAAc;CAC3E;CAEA,iBAIE,aACA,SACwD;EACxD,OAAO,KAAK,OAAO,iBAAiB,aAAoB,OAAc;CAIxE;CAEA,qBAIE,aACA,SAC4D;EAC5D,OAAO,KAAK,OAAO,qBAAqB,aAAoB,OAAc;CAI5E;CAEA,qBAIE,aACA,SACyB;EACzB,OAAO,KAAK,OAAO,qBAAqB,aAAoB,OAAc;CAC5E;CAEA,aAAa,SAAmE;EAC9E,OAAO,KAAK,OAAO,aAAa,OAAO;CACzC;CAEA,iBAAiB,SAA2E;EAC1F,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,aAAa,SAAmE;EAC9E,OAAO,KAAK,OAAO,aAAa,OAAO;CACzC;CAEA,iBAAiB,SAA2E;EAC1F,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/vite-plugin.ts","../src/integration.ts","../src/middleware.ts","../src/telemetry.ts","../src/assets-middleware.ts","../src/routing-middleware.ts","../src/contello.ts"],"sourcesContent":["import { type ExcludePattern, serializeExcludePatterns } from '@astroscope/node/excludes';\nimport type { Plugin } from 'vite';\n\nexport const INSTANCE_VIRTUAL_MODULE_ID = 'virtual:@contello/astro/instance';\nexport const CONFIG_VIRTUAL_MODULE_ID = 'virtual:@contello/astro/config';\n\nconst RESOLVED_CONFIG_VIRTUAL_MODULE_ID = `\\0${CONFIG_VIRTUAL_MODULE_ID}`;\n\nexport type ContelloVitePluginOptions = {\n /** absolute path of the module exporting the `contello` instance */\n entry: string;\n /** routing exclude patterns, null for the middleware default */\n exclude: ExcludePattern[] | null;\n};\n\n/**\n * Resolves the instance id straight to the project's module, so the injected\n * middlewares and the project's own imports share one `Contello` instance, and\n * serves the serializable integration options as a config module.\n */\nexport function contelloVitePlugin(options: ContelloVitePluginOptions): Plugin {\n return {\n name: '@contello/astro',\n\n resolveId(id) {\n if (id === INSTANCE_VIRTUAL_MODULE_ID) {\n return options.entry;\n }\n\n if (id === CONFIG_VIRTUAL_MODULE_ID) {\n return RESOLVED_CONFIG_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_CONFIG_VIRTUAL_MODULE_ID) {\n // exclude patterns may contain RegExp — serialized as code, not JSON\n return `export const exclude = ${options.exclude ? serializeExcludePatterns(options.exclude) : 'null'};`;\n }\n },\n };\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { ExcludePattern } from '@astroscope/node/excludes';\nimport type { AstroIntegration } from 'astro';\nimport { contelloVitePlugin } from './vite-plugin';\n\nconst DEFAULT_ENTRY = 'src/server/contello.ts';\n\nexport type ContelloIntegrationOptions = {\n /**\n * Module exporting the `contello` instance (`export const contello = createContello(...)`),\n * relative to the project root.\n * @default 'src/server/contello.ts'\n */\n entry?: string | undefined;\n /**\n * Where the assets middleware (`/_contello/i/`, `/_contello/f/`, `/_contello/v/`) is injected;\n * `false` leaves it to the project (`contello.createAssetsMiddleware()`).\n * @default 'pre'\n */\n assets?: 'pre' | false | undefined;\n /**\n * Where the routing middleware is injected; `false` leaves it to the project\n * (`contello.createRoutingMiddleware()`). Post middlewares run in `integrations` order, so list\n * `contello()` before integrations whose middleware depends on the resolved route, e.g. `@astroscope/wormhole`.\n * @default 'post'\n */\n routing?: 'post' | false | undefined;\n /**\n * Paths the routing middleware skips.\n * @default RECOMMENDED_EXCLUDES from `@astroscope/node/excludes`\n */\n exclude?: ExcludePattern[] | undefined;\n};\n\n/**\n * Astro integration for Contello.\n *\n * Injects the assets middleware ahead of the project's own middleware and the routing\n * middleware after it, both bound to the project's `contello` instance, which the\n * integration resolves from `src/server/contello.ts` (or `entry`). Runtime options\n * (`resolveRoutePath`, assets cache control, the routes instance) live on the instance,\n * only serializable ones belong here.\n */\nexport default function contelloIntegration(options: ContelloIntegrationOptions = {}): AstroIntegration {\n const { entry = DEFAULT_ENTRY, assets = 'pre', routing = 'post', exclude = null } = options;\n\n return {\n name: '@contello/astro',\n hooks: {\n 'astro:config:setup': ({ config, updateConfig, addMiddleware }) => {\n const entryPath = path.resolve(fileURLToPath(config.root), entry);\n\n if (!fs.existsSync(entryPath)) {\n throw new Error(\n `@contello/astro: instance module ${entry} not found — ` +\n 'export `contello = createContello(...)` from it or point the integration\\'s `entry` option at it',\n );\n }\n\n if (assets) {\n addMiddleware({ order: assets, entrypoint: '@contello/astro/assets-middleware' });\n }\n\n if (routing) {\n addMiddleware({ order: routing, entrypoint: '@contello/astro/routing-middleware' });\n }\n\n updateConfig({\n vite: {\n plugins: [contelloVitePlugin({ entry: entryPath, exclude })],\n },\n });\n },\n },\n };\n}\n","import type { MiddlewareHandler } from 'astro';\n\n// a local identity instead of `astro/middleware`: a runtime import of astro's middleware entry pulls every module that\n// imports this package into astro's runtime module graph — in dev, astro invalidates that graph on any file change,\n// which re-evaluates boot-loaded singletons and makes @astroscope/node restart the server on every component edit\nexport function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler {\n return handler;\n}\n","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 type { Contello } from './contello';\nimport { defineMiddleware } from './middleware';\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\n/**\n * `options` is read per request: the integration creates the middleware before `init()`\n * brings the project's assets options; `false` disables the middleware (`init({ assets: false })`).\n */\nexport function createBoundAssetsMiddleware(\n contello: Contello<any>,\n options: () => ContelloAssetsMiddlewareOptions | false | undefined,\n) {\n const imagesPrefix = contello.media.imagesPath;\n const filesPrefix = contello.media.filesPath;\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 const current = options();\n\n if (current === false) {\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 current?.images?.cacheControl ?? DEFAULT_IMAGES_CACHE_CONTROL,\n `${imagesPrefix}[file]`,\n );\n }\n\n if (isFile) {\n return handleFile(\n contello.client,\n next,\n pathname.slice(filesPrefix.length),\n current?.files?.cacheControl,\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 type { LazyRoutes, Routes, RoutesSync, StoreRoute, StoreRouteCustomHeader } from '@contello/store';\nimport { type MaybePromise, maybeThen } from '@entwico/dash';\nimport type { APIContext, ValidRedirectStatus } from 'astro';\nimport { type Contello, runRequest } from './contello';\nimport { defineMiddleware } from './middleware';\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 | undefined,\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 // undefined: the project disabled routing (`init({ routes: false })`)\n const current = routes();\n\n if (!current) {\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 = current.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](\n { url, route, rewritten: false },\n () => wrap(\n 'route:redirect',\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](\n { url, route, rewritten: false },\n () => wrap(\n 'route:text',\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](\n { 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 'sitemap': {\n return contello[runRequest](\n { url, route, rewritten: false },\n () => wrap('route:sitemap', async () => {\n const result = await contello.client.proxySitemap(\n route.sitemapId,\n {\n source: url.searchParams.get('source') ?? undefined,\n page: url.searchParams.get('page') ?? undefined,\n acceptEncoding: ctx.request.headers.get('accept-encoding') ?? undefined,\n ifNoneMatch: ctx.request.headers.get('if-none-match') ?? undefined,\n },\n ctx.request.signal,\n );\n\n const passthrough = result.status === 304 || (result.status >= 200 && result.status < 300);\n\n if (!passthrough) {\n // core's error format stays internal: same status, no body, none of the upstream headers\n await result.stream().cancel();\n\n return new Response(null, { status: result.status, headers: customHeaders(route.customHeaders) });\n }\n\n const headers = new Headers(result.headers);\n\n for (const { name, value } of route.customHeaders) {\n headers.set(name, value);\n }\n\n return new Response(result.status === 304 ? null : result.stream(), { status: result.status, headers });\n }),\n );\n }\n\n case 'entity': {\n return contello[runRequest](\n { 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 I18nConfig, type RawTranslations, i18n } from '@astroscope/i18n';\nimport { getBootContext } from '@astroscope/node/boot';\nimport { registerHealthCheck } from '@astroscope/node/health';\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 BuiltInWrites,\n type Collection,\n type CollectionOptions,\n type CollectionSync,\n type CollectionSyncOptions,\n type CreateStoreOptions,\n type ExtractSourceResult,\n type ExtractSourceWrites,\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 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 { ReadonlyDeep } from '@entwico/dash';\nimport { type ContelloAssetsMiddlewareOptions, createBoundAssetsMiddleware } from './assets-middleware';\nimport {\n type AnyRoutes,\n type ContelloRoutingMiddlewareOptions,\n type RoutePathResolver,\n createBoundRoutingMiddleware,\n} 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\n/** The Contello i18n message collection bridged to `@astroscope/i18n`; `init()` takes the runtime side. */\nexport type ContelloI18nOptions = {\n collection: string;\n cache?: SyncCacheOptions | undefined;\n};\n\n/**\n * The `@astroscope/i18n` config `init()` passes to `i18n.configure()` before it pushes the\n * collection's translations, plus what to do with the extracted keys.\n */\nexport type ContelloInitI18nOptions = I18nConfig & {\n /**\n * Register the extracted keys in the collection; defaults to `true`, except in dev mode (detected via the\n * @astroscope/node boot context).\n */\n register?: boolean | undefined;\n /** push the collection's translations and follow its refreshes; defaults to `true` */\n load?: boolean | undefined;\n};\n\nexport type ContelloRoutingOptions = {\n resolveRoutePath?: RoutePathResolver | undefined;\n};\n\n/** The readiness check `init()` registers with `@astroscope/node/health`; `false` registers none. */\nexport type ContelloHealthOptions = {\n /** @default 'contello' */\n name?: string | undefined;\n optional?: boolean | undefined;\n timeout?: number | undefined;\n};\n\nexport type ContelloInitOptions = {\n load?: Loadable[] | undefined;\n /**\n * Routes backing the routing middleware: `'sync'` creates and loads a `RoutesSync` (eager, synchronous\n * lookups), `'lazy'` creates a `LazyRoutes` (fetched on demand), or an instance the project defined\n * itself, loaded by `init()` when it is loadable. Reachable as `contello.routes` after `init()`.\n * `false` for a project without Contello routes: the routing middleware passes through.\n */\n routes: 'sync' | 'lazy' | AnyRoutes | false;\n /** required when `createContello` got an `i18n` collection */\n i18n?: ContelloInitI18nOptions | undefined;\n /** defaults for the routing middleware, used by the integration-injected one */\n routing?: ContelloRoutingOptions | undefined;\n /** defaults for the assets middleware, used by the integration-injected one; `false` makes it pass through */\n assets?: ContelloAssetsMiddlewareOptions | false | undefined;\n health?: ContelloHealthOptions | false | 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\nfunction isLoadable(value: object): value is Loadable {\n return typeof (value as Partial<Loadable>).load === 'function';\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 createI18nRegistrations(): 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>;\n/** The write-input shape the source carries — keeps the collection's write half through the proxy. */\ntype CollectionWritesOf<TSchema, TArg> = ExtractSourceWrites<\n Extract<ResolveSource<TSchema, TArg>, SourceDef<string, 'entity'>>\n>;\ntype RouteWrites<TSchema> = BuiltInWrites<TSchema, 'route'>;\ntype AssetWrites<TSchema> = BuiltInWrites<TSchema, 'asset'>;\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 _routes: AnyRoutes | undefined;\n private _initOptions: ContelloInitOptions | undefined;\n private _unregisterHealthCheck: (() => void) | undefined;\n\n readonly media: ContelloMediaConfig;\n\n // --- middleware factories (arrow fields so destructuring works) ---\n\n createRoutingMiddleware = (options?: ContelloRoutingMiddlewareOptions | undefined) => {\n // resolved per request: the integration creates the middleware before init() brings the routes and options\n const routes = () => options?.routes ?? (this._initOptions?.routes === false ? undefined : this.routes);\n const resolveRoutePath: RoutePathResolver = (ctx) => {\n const resolver = options?.resolveRoutePath ?? this._initOptions?.routing?.resolveRoutePath;\n\n return resolver ? resolver(ctx) : ctx.url.pathname;\n };\n\n return createBoundRoutingMiddleware(this, routes, options?.exclude, resolveRoutePath);\n };\n\n createAssetsMiddleware = (options?: ContelloAssetsMiddlewareOptions | undefined) => {\n return createBoundAssetsMiddleware(this, () => options ?? this._initOptions?.assets);\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 private createRoutes(routes: ContelloInitOptions['routes']): AnyRoutes | undefined {\n switch (routes) {\n case false: {\n return undefined;\n }\n\n case 'sync': {\n return this.defineRoutesSync();\n }\n\n case 'lazy': {\n return this.defineLazyRoutes();\n }\n\n default: {\n return routes;\n }\n }\n }\n\n private registerHealthCheck(health: ContelloHealthOptions | false | undefined): void {\n if (health === false) {\n return;\n }\n\n this._unregisterHealthCheck?.();\n this._unregisterHealthCheck = registerHealthCheck({\n name: health?.name ?? 'contello',\n check: () => this.ping(),\n optional: health?.optional,\n timeout: health?.timeout,\n });\n }\n\n async init(options: ContelloInitOptions): Promise<void> {\n try {\n this._initOptions = options;\n\n this.registerHealthCheck(options.health);\n\n await this._store.init();\n\n this._routes = this.createRoutes(options.routes);\n\n if (this._options.i18n) {\n if (!options.i18n) {\n throw new Error('@contello/astro: init() needs the i18n option (locales, locale resolver) for the configured i18n collection');\n }\n\n const { collection, cache } = this._options.i18n;\n const dev = getBootContext()?.dev ?? false;\n const { register = !dev, load = true, ...i18nConfig } = options.i18n;\n\n this._i18nMessages = this._store.defineI18nMessages({ collection, cache });\n\n await i18n.configure(i18nConfig);\n\n if (register) {\n const registrations = createI18nRegistrations();\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 const routes = this._routes;\n const loadables = [...(options.load ?? []), ...(routes && isLoadable(routes) ? [routes] : [])];\n\n await Promise.all(loadables.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 this._unregisterHealthCheck?.();\n this._unregisterHealthCheck = undefined;\n\n await this._store.destroy();\n\n this._i18nMessages = undefined;\n this._routes = undefined;\n this._initOptions = 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 /** the routes backing the routing middleware, created by `init()` from its `routes` option */\n get routes(): AnyRoutes {\n if (!this._routes) {\n throw new Error('@contello/astro: .routes accessed before init() or with routes disabled');\n }\n\n return this._routes;\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, CollectionWritesOf<TSchema, TArg>> {\n return this._store.defineCollection(sourceOrKey as any, options as any) as Collection<\n TMapped,\n CollectionWritesOf<TSchema, TArg>\n >;\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, CollectionWritesOf<TSchema, TArg>> {\n return this._store.defineCollectionSync(sourceOrKey as any, options as any) as CollectionSync<\n TMapped,\n CollectionWritesOf<TSchema, TArg>\n >;\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<RouteWrites<TSchema>> {\n return this._store.defineRoutes(options);\n }\n\n defineRoutesSync(options?: RoutesSyncOptions | undefined): RoutesSync<RouteWrites<TSchema>> {\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<AssetWrites<TSchema>> {\n return this._store.defineAssets(options);\n }\n\n defineAssetsSync(options?: AssetsSyncOptions | undefined): AssetsSync<AssetWrites<TSchema>> {\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":";;;;;;;;;;;;;AAMA,MAAM,oCAAoC;;;;;;AAc1C,SAAgB,mBAAmB,SAA4C;CAC7E,OAAO;EACL,MAAM;EAEN,UAAU,IAAI;GACZ,IAAI,OAAA,oCACF,OAAO,QAAQ;GAGjB,IAAI,OAAA,kCACF,OAAO;EAEX;EAEA,KAAK,IAAI;GACP,IAAI,OAAO,mCAET,OAAO,0BAA0B,QAAQ,UAAU,yBAAyB,QAAQ,OAAO,IAAI,OAAO;EAE1G;CACF;AACF;;AClCA,MAAM,gBAAgB;;;;;;;;;;AAsCtB,SAAwB,oBAAoB,UAAsC,CAAC,GAAqB;CACtG,MAAM,EAAE,QAAQ,eAAe,SAAS,OAAO,UAAU,QAAQ,UAAU,SAAS;CAEpF,OAAO;EACL,MAAM;EACN,OAAO,EACL,uBAAuB,EAAE,QAAQ,cAAc,oBAAoB;GACjE,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,IAAI,GAAG,KAAK;GAEhE,IAAI,CAAC,GAAG,WAAW,SAAS,GAC1B,MAAM,IAAI,MACR,oCAAoC,MAAM,iHAE5C;GAGF,IAAI,QACF,cAAc;IAAE,OAAO;IAAQ,YAAY;GAAoC,CAAC;GAGlF,IAAI,SACF,cAAc;IAAE,OAAO;IAAS,YAAY;GAAqC,CAAC;GAGpF,aAAa,EACX,MAAM,EACJ,SAAS,CAAC,mBAAmB;IAAE,OAAO;IAAW;GAAQ,CAAC,CAAC,EAC7D,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E,aACA,SAC4D;EAC5D,OAAO,KAAK,OAAO,qBAAqB,aAAoB,OAAc;CAI5E;CAEA,qBAIE,aACA,SACyB;EACzB,OAAO,KAAK,OAAO,qBAAqB,aAAoB,OAAc;CAC5E;CAEA,aAAa,SAAmE;EAC9E,OAAO,KAAK,OAAO,aAAa,OAAO;CACzC;CAEA,iBAAiB,SAA2E;EAC1F,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,iBAAiB,SAAqD;EACpE,OAAO,KAAK,OAAO,iBAAiB,OAAO;CAC7C;CAEA,aAAa,SAAmE;EAC9E,OAAO,KAAK,OAAO,aAAa,OAAO;CACzC;CAEA,iBAAiB,SAA2E;EAC1F,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing-middleware-entrypoint.d.ts","names":[],"sources":["../src/routing-middleware-entrypoint.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"routing-middleware-entrypoint.d.ts","names":[],"sources":["../src/routing-middleware-entrypoint.ts"],"mappings":"A,qBAGa"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { contello } from "virtual:@contello/astro/instance";
|
|
2
2
|
import { exclude } from "virtual:@contello/astro/config";
|
|
3
|
-
|
|
3
|
+
// src/routing-middleware-entrypoint.ts
|
|
4
4
|
const onRequest = contello.createRoutingMiddleware({ exclude: exclude ?? void 0 });
|
|
5
|
-
//#endregion
|
|
6
5
|
export { onRequest };
|
|
7
6
|
|
|
8
7
|
//# sourceMappingURL=routing-middleware-entrypoint.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/astro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Astro integration for Contello CMS — assets and routing middlewares, i18n bridge",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"@entwico/dash": "^1.3.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@astroscope/i18n": "^
|
|
25
|
-
"@astroscope/node": "^
|
|
26
|
-
"@contello/client": "^3.
|
|
24
|
+
"@astroscope/i18n": "^4.0.0",
|
|
25
|
+
"@astroscope/node": "^5.0.0",
|
|
26
|
+
"@contello/client": "^3.4.1",
|
|
27
27
|
"@contello/media": "^2.2.3",
|
|
28
|
-
"@contello/store": "^4.
|
|
28
|
+
"@contello/store": "^4.5.0",
|
|
29
29
|
"astro": "^6.0.0 || ^7.0.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependenciesMeta": {
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@astroscope/i18n": "^
|
|
38
|
-
"@astroscope/node": "^
|
|
39
|
-
"@contello/client": "^3.
|
|
37
|
+
"@astroscope/i18n": "^4.0.0",
|
|
38
|
+
"@astroscope/node": "^5.0.0",
|
|
39
|
+
"@contello/client": "^3.4.1",
|
|
40
40
|
"@contello/media": "^2.2.3",
|
|
41
|
-
"@contello/store": "^4.
|
|
42
|
-
"astro": "^7.
|
|
43
|
-
"vite": "^8.
|
|
41
|
+
"@contello/store": "^4.5.0",
|
|
42
|
+
"astro": "^7.4.5",
|
|
43
|
+
"vite": "^8.3.5"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist"
|