@contello/astro 3.1.0 → 4.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/index.js CHANGED
@@ -1,400 +1,326 @@
1
- // src/contello.ts
2
- import { AsyncLocalStorage } from "async_hooks";
1
+ import { AsyncLocalStorage } from "node:async_hooks";
3
2
  import { i18n } from "@astroscope/i18n";
3
+ import { getBootContext } from "@astroscope/node/boot";
4
4
  import { createMediaResolver } from "@contello/media";
5
- import {
6
- createStore
7
- } from "@contello/store";
8
-
9
- // src/assets-middleware.ts
5
+ import { createStore, maybeThen } from "@contello/store";
10
6
  import { defineMiddleware } from "astro/middleware";
11
-
12
- // src/diagnostics.ts
13
- import dc from "diagnostics_channel";
14
- var channels = {
15
- start: "@contello/astro:start",
16
- end: "@contello/astro:end",
17
- error: "@contello/astro:error"
18
- };
19
- var onStart = dc.channel(channels.start);
20
- var onEnd = dc.channel(channels.end);
21
- var onError = dc.channel(channels.error);
22
- function hasSubscribers() {
23
- return onStart.hasSubscribers || onEnd.hasSubscribers || onError.hasSubscribers;
24
- }
25
- function wrap(name, fn) {
26
- if (!hasSubscribers()) {
27
- return fn();
28
- }
29
- const start = performance.now();
30
- onStart.publish({ name });
31
- let result;
32
- try {
33
- result = fn();
34
- } catch (error) {
35
- onError.publish({ name, error, durationMs: performance.now() - start });
36
- throw error;
37
- }
38
- if (result instanceof Promise) {
39
- return result.then(
40
- (r) => {
41
- onEnd.publish({ name, durationMs: performance.now() - start });
42
- return r;
43
- },
44
- (error) => {
45
- onError.publish({ name, error, durationMs: performance.now() - start });
46
- throw error;
47
- }
48
- );
49
- }
50
- onEnd.publish({ name, durationMs: performance.now() - start });
51
- return result;
52
- }
53
-
54
- // src/assets-middleware.ts
55
- var DEFAULT_IMAGES_CACHE_CONTROL = "public, max-age=31536000";
7
+ import { createOperationTelemetry } from "@contello/opentelemetry";
8
+ import { RECOMMENDED_EXCLUDES, shouldExclude } from "@astroscope/node/excludes";
9
+ //#region src/telemetry.ts
10
+ const { wrap } = createOperationTelemetry("@contello/astro");
11
+ //#endregion
12
+ //#region src/assets-middleware.ts
13
+ const DEFAULT_IMAGES_CACHE_CONTROL = "public, max-age=31536000";
56
14
  function createBoundAssetsMiddleware(contello, options) {
57
- const imagesPrefix = contello.media.imagesPath;
58
- const imagesCacheControl = options?.images?.cacheControl ?? DEFAULT_IMAGES_CACHE_CONTROL;
59
- const filesPrefix = contello.media.filesPath;
60
- const filesCacheControl = options?.files?.cacheControl;
61
- const videoPrefix = contello.media.videosPath;
62
- return defineMiddleware((ctx, next) => {
63
- const { pathname } = ctx.url;
64
- const isImage = pathname.startsWith(imagesPrefix);
65
- const isFile = !isImage && pathname.startsWith(filesPrefix);
66
- const isVideo = !isImage && !isFile && pathname.startsWith(videoPrefix);
67
- if (!isImage && !isFile && !isVideo) {
68
- return next();
69
- }
70
- if (!contello.isReady) {
71
- console.warn(`[@contello/astro] not initialized, passing through: ${pathname}`);
72
- return next();
73
- }
74
- if (isImage) {
75
- return handleFile(contello.client, next, pathname.slice(imagesPrefix.length), imagesCacheControl);
76
- }
77
- if (isFile) {
78
- return handleFile(contello.client, next, pathname.slice(filesPrefix.length), filesCacheControl);
79
- }
80
- return handleVideo(contello.client, next, pathname.slice(videoPrefix.length), ctx.request.signal);
81
- });
15
+ const imagesPrefix = contello.media.imagesPath;
16
+ const imagesCacheControl = options?.images?.cacheControl ?? DEFAULT_IMAGES_CACHE_CONTROL;
17
+ const filesPrefix = contello.media.filesPath;
18
+ const filesCacheControl = options?.files?.cacheControl;
19
+ const videoPrefix = contello.media.videosPath;
20
+ return defineMiddleware((ctx, next) => {
21
+ const { pathname } = ctx.url;
22
+ const isImage = pathname.startsWith(imagesPrefix);
23
+ const isFile = !isImage && pathname.startsWith(filesPrefix);
24
+ const isVideo = !isImage && !isFile && pathname.startsWith(videoPrefix);
25
+ if (!isImage && !isFile && !isVideo) return next();
26
+ if (!contello.isReady) {
27
+ console.warn(`[@contello/astro] not initialized, passing through: ${pathname}`);
28
+ return next();
29
+ }
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);
33
+ });
82
34
  }
83
35
  function handleFile(client, next, rest, cacheControl) {
84
- const dot = rest.indexOf(".");
85
- const fileId = dot === -1 ? rest : rest.slice(0, dot);
86
- if (!fileId) {
87
- return next();
88
- }
89
- return wrap("assets:file", () => client.download(fileId)).then(
90
- (result) => {
91
- const headers = new Headers({ "content-type": result.mimeType });
92
- if (cacheControl) {
93
- headers.set("cache-control", cacheControl);
94
- }
95
- if (result.size > 0) {
96
- headers.set("content-length", String(result.size));
97
- }
98
- return new Response(result.stream(), { headers });
99
- },
100
- () => new Response(null, { status: 404 })
101
- );
36
+ const dot = rest.indexOf(".");
37
+ const fileId = dot === -1 ? rest : rest.slice(0, dot);
38
+ if (!fileId) return next();
39
+ return (async () => {
40
+ try {
41
+ const result = await wrap("assets:file", () => client.download(fileId));
42
+ const headers = new Headers({ "content-type": result.mimeType });
43
+ if (cacheControl) headers.set("cache-control", cacheControl);
44
+ if (result.size > 0) headers.set("content-length", String(result.size));
45
+ return new Response(result.stream(), { headers });
46
+ } catch {
47
+ return new Response(null, { status: 404 });
48
+ }
49
+ })();
102
50
  }
103
51
  function handleVideo(client, next, path, signal) {
104
- if (!path) {
105
- return next();
106
- }
107
- return wrap("assets:hls", () => client.proxyHls(path, signal)).then(
108
- (result) => new Response(result.stream(), { status: result.status, headers: result.headers }),
109
- () => new Response("Upstream is down", { status: 502, headers: { "content-type": "text/plain" } })
110
- );
52
+ if (!path) return next();
53
+ return (async () => {
54
+ try {
55
+ const result = await wrap("assets:hls", () => client.proxyHls(path, signal));
56
+ return new Response(result.stream(), {
57
+ status: result.status,
58
+ headers: result.headers
59
+ });
60
+ } catch {
61
+ return new Response("Upstream is down", {
62
+ status: 502,
63
+ headers: { "content-type": "text/plain" }
64
+ });
65
+ }
66
+ })();
111
67
  }
112
-
113
- // src/routing-middleware.ts
114
- import { RECOMMENDED_EXCLUDES, shouldExclude } from "@astroscope/excludes";
115
- import {
116
- maybeThen
117
- } from "@contello/store";
118
- import { defineMiddleware as defineMiddleware2 } from "astro/middleware";
68
+ //#endregion
69
+ //#region src/routing-middleware.ts
119
70
  function customHeaders(headers) {
120
- const result = {};
121
- for (const h of headers) {
122
- result[h.name] = h.value;
123
- }
124
- return result;
71
+ const result = {};
72
+ for (const h of headers) result[h.name] = h.value;
73
+ return result;
125
74
  }
126
- var VALID_REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
75
+ const VALID_REDIRECT_STATUSES = /* @__PURE__ */ new Set([
76
+ 301,
77
+ 302,
78
+ 303,
79
+ 307,
80
+ 308
81
+ ]);
127
82
  function toRedirectStatus(status) {
128
- return VALID_REDIRECT_STATUSES.has(status) ? status : 302;
83
+ return VALID_REDIRECT_STATUSES.has(status) ? status : 302;
129
84
  }
130
85
  function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
131
- return defineMiddleware2((ctx, next) => {
132
- if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) {
133
- return next();
134
- }
135
- if (!contello.isReady) {
136
- console.warn(`[@contello/astro] not initialized, passing through: ${ctx.url.pathname}`);
137
- return next();
138
- }
139
- const { url } = ctx;
140
- if (url.pathname.startsWith("/contello/entities/")) {
141
- return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
142
- }
143
- const path = resolveRoutePath ? resolveRoutePath(ctx) : url.pathname;
144
- const lookup = routes.getByPath(path);
145
- return maybeThen(lookup, (route) => {
146
- if (!route) {
147
- return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
148
- }
149
- switch (route.type) {
150
- case "redirect": {
151
- return contello[runRequest](
152
- { url, route, rewritten: false },
153
- () => wrap(
154
- "route:redirect",
155
- () => new Response(null, {
156
- status: toRedirectStatus(route.status),
157
- headers: {
158
- Location: route.location,
159
- ...customHeaders(route.customHeaders)
160
- }
161
- })
162
- )
163
- );
164
- }
165
- case "text": {
166
- return contello[runRequest](
167
- { url, route, rewritten: false },
168
- () => wrap(
169
- "route:text",
170
- () => new Response(route.content, {
171
- status: 200,
172
- headers: {
173
- "Content-Type": route.mimeType,
174
- ...customHeaders(route.customHeaders)
175
- }
176
- })
177
- )
178
- );
179
- }
180
- case "asset": {
181
- return contello[runRequest](
182
- { url, route, rewritten: false },
183
- () => wrap("route:asset", async () => {
184
- const result = await contello.client.download(route.fileId);
185
- const headers = new Headers({ "content-type": route.mimeType || result.mimeType });
186
- headers.set("content-disposition", route.contentDisposition);
187
- if (result.size > 0) {
188
- headers.set("content-length", String(result.size));
189
- }
190
- for (const { name, value } of route.customHeaders) {
191
- headers.set(name, value);
192
- }
193
- return new Response(result.stream(), { headers });
194
- })
195
- );
196
- }
197
- case "entity": {
198
- return contello[runRequest](
199
- { url, route, rewritten: true },
200
- () => wrap(`route:entity:${route.model}`, async () => {
201
- const response = await next(`/contello/entities/${route.model}/${route.entityId}${url.search}`);
202
- for (const { name, value } of route.customHeaders) {
203
- response.headers.set(name, value);
204
- }
205
- return response;
206
- })
207
- );
208
- }
209
- }
210
- });
211
- });
86
+ return defineMiddleware((ctx, next) => {
87
+ if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) return next();
88
+ if (!contello.isReady) {
89
+ console.warn(`[@contello/astro] not initialized, passing through: ${ctx.url.pathname}`);
90
+ return next();
91
+ }
92
+ const { url } = ctx;
93
+ if (url.pathname.startsWith("/contello/entities/")) return contello[runRequest]({
94
+ url,
95
+ route: void 0,
96
+ rewritten: false
97
+ }, () => next());
98
+ const path = resolveRoutePath ? resolveRoutePath(ctx) : url.pathname;
99
+ return maybeThen(routes.getByPath(path), (route) => {
100
+ if (!route) return contello[runRequest]({
101
+ url,
102
+ route: void 0,
103
+ rewritten: false
104
+ }, () => next());
105
+ switch (route.type) {
106
+ case "redirect": return contello[runRequest]({
107
+ url,
108
+ route,
109
+ rewritten: false
110
+ }, () => wrap("route:redirect", () => new Response(null, {
111
+ status: toRedirectStatus(route.status),
112
+ headers: {
113
+ Location: route.location,
114
+ ...customHeaders(route.customHeaders)
115
+ }
116
+ })));
117
+ case "text": return contello[runRequest]({
118
+ url,
119
+ route,
120
+ rewritten: false
121
+ }, () => wrap("route:text", () => new Response(route.content, {
122
+ status: 200,
123
+ headers: {
124
+ "Content-Type": route.mimeType,
125
+ ...customHeaders(route.customHeaders)
126
+ }
127
+ })));
128
+ case "asset": return contello[runRequest]({
129
+ url,
130
+ route,
131
+ rewritten: false
132
+ }, () => wrap("route:asset", async () => {
133
+ const result = await contello.client.download(route.fileId);
134
+ const headers = new Headers({ "content-type": route.mimeType || result.mimeType });
135
+ headers.set("content-disposition", route.contentDisposition);
136
+ if (result.size > 0) headers.set("content-length", String(result.size));
137
+ for (const { name, value } of route.customHeaders) headers.set(name, value);
138
+ return new Response(result.stream(), { headers });
139
+ }));
140
+ case "entity": return contello[runRequest]({
141
+ url,
142
+ route,
143
+ rewritten: true
144
+ }, () => wrap(`route:entity:${route.model}`, async () => {
145
+ const response = await next(`/contello/entities/${route.model}/${route.entityId}${url.search}`);
146
+ for (const { name, value } of route.customHeaders) response.headers.set(name, value);
147
+ return response;
148
+ }));
149
+ }
150
+ });
151
+ });
212
152
  }
213
-
214
- // src/contello.ts
215
- var DEFAULT_IMAGES_PREFIX = "/_contello/i/";
216
- var DEFAULT_FILES_PREFIX = "/_contello/f/";
217
- var DEFAULT_VIDEO_PREFIX = "/_contello/v/";
218
- var runRequest = /* @__PURE__ */ Symbol("@contello/astro/runRequest");
153
+ //#endregion
154
+ //#region src/contello.ts
155
+ const DEFAULT_IMAGES_PREFIX = "/_contello/i/";
156
+ const DEFAULT_FILES_PREFIX = "/_contello/f/";
157
+ const DEFAULT_VIDEO_PREFIX = "/_contello/v/";
158
+ const runRequest = Symbol("@contello/astro/runRequest");
219
159
  function buildI18nRegistrations() {
220
- const manifest = i18n.getManifest();
221
- const defaultLanguage = i18n.getConfig().defaultLocale;
222
- return manifest.keys.map((extracted) => ({
223
- token: extracted.key,
224
- example: extracted.meta.fallback,
225
- description: extracted.meta.description ?? "",
226
- variables: Object.entries(extracted.meta.variables ?? {}).map(([name, def]) => ({
227
- name,
228
- description: def?.description ?? "",
229
- example: def?.fallback ?? ""
230
- })),
231
- initialTranslations: [{ language: defaultLanguage, message: extracted.meta.fallback }]
232
- }));
160
+ const manifest = i18n.getManifest();
161
+ const defaultLanguage = i18n.getConfig().defaultLocale;
162
+ return manifest.keys.map((extracted) => ({
163
+ token: extracted.key,
164
+ example: extracted.meta.fallback,
165
+ description: extracted.meta.description ?? "",
166
+ variables: Object.entries(extracted.meta.variables ?? {}).map(([name, def]) => ({
167
+ name,
168
+ description: def?.description ?? "",
169
+ example: def?.fallback ?? ""
170
+ })),
171
+ initialTranslations: [{
172
+ language: defaultLanguage,
173
+ message: extracted.meta.fallback
174
+ }]
175
+ }));
233
176
  }
234
177
  async function applyTranslations(messages) {
235
- const config = i18n.getConfig();
236
- const all = await messages.getAll();
237
- const byLocale = /* @__PURE__ */ new Map();
238
- for (const locale of config.locales) {
239
- byLocale.set(locale, {});
240
- }
241
- for (const msg of all) {
242
- msg.translations.forEach((value, language) => {
243
- const raw = byLocale.get(language);
244
- if (raw) {
245
- raw[msg.token] = value;
246
- }
247
- });
248
- }
249
- for (const [locale, translations] of byLocale.entries()) {
250
- i18n.setTranslations(locale, translations);
251
- }
178
+ const config = i18n.getConfig();
179
+ const all = await messages.getAll();
180
+ const byLocale = /* @__PURE__ */ new Map();
181
+ for (const locale of config.locales) byLocale.set(locale, {});
182
+ for (const msg of all) msg.translations.forEach((value, language) => {
183
+ const raw = byLocale.get(language);
184
+ if (raw) raw[msg.token] = value;
185
+ });
186
+ for (const [locale, translations] of byLocale) i18n.setTranslations(locale, translations);
252
187
  }
253
188
  var Contello = class {
254
- _store;
255
- _options;
256
- _i18nMessages;
257
- _i18nUnsubscribe;
258
- _initialized = false;
259
- _als = new AsyncLocalStorage();
260
- _autoLazyRoutes;
261
- media;
262
- constructor(options) {
263
- this._options = options;
264
- this._store = createStore(options);
265
- this.media = {
266
- baseUrl: options.media?.baseUrl ?? "",
267
- imagesPath: options.media?.imagesPath ?? DEFAULT_IMAGES_PREFIX,
268
- videosPath: options.media?.videosPath ?? DEFAULT_VIDEO_PREFIX,
269
- filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX
270
- };
271
- }
272
- // --- lifecycle ---
273
- async init(options) {
274
- try {
275
- await this._store.init();
276
- if (this._options.i18n) {
277
- const { collection, languages, cache } = this._options.i18n;
278
- const { register = true, load = true } = options?.i18n ?? {};
279
- this._i18nMessages = this._store.defineI18nMessages({ collection, cache });
280
- await i18n.configure({ locales: languages });
281
- if (register) {
282
- const registrations = buildI18nRegistrations();
283
- if (registrations.length > 0) {
284
- await this._i18nMessages.register(registrations);
285
- }
286
- }
287
- if (load) {
288
- await applyTranslations(this._i18nMessages);
289
- const messages = this._i18nMessages;
290
- const controller = new AbortController();
291
- this._i18nUnsubscribe = () => controller.abort();
292
- void (async () => {
293
- for await (const _ of messages.refresh$) {
294
- if (controller.signal.aborted) {
295
- return;
296
- }
297
- await applyTranslations(messages);
298
- }
299
- })();
300
- }
301
- }
302
- await Promise.all((options?.load ?? []).map((l) => l.load()));
303
- this._initialized = true;
304
- } catch (error) {
305
- await this.destroy().catch(() => {
306
- });
307
- throw error;
308
- }
309
- }
310
- async destroy() {
311
- this._initialized = false;
312
- this._i18nUnsubscribe?.();
313
- this._i18nUnsubscribe = void 0;
314
- await this._store.destroy();
315
- this._i18nMessages = void 0;
316
- }
317
- ping() {
318
- return this._store.ping();
319
- }
320
- get isReady() {
321
- return this._initialized;
322
- }
323
- get client() {
324
- return this._store.client;
325
- }
326
- get i18nMessages() {
327
- if (!this._i18nMessages) {
328
- throw new Error("@contello/astro: .i18nMessages accessed before init() with i18n config");
329
- }
330
- return this._i18nMessages;
331
- }
332
- // --- ALS request context ---
333
- get request() {
334
- const ctx = this._als.getStore();
335
- if (!ctx) {
336
- throw new Error("@contello/astro: .request accessed outside of request context");
337
- }
338
- return ctx;
339
- }
340
- // --- media resolvers (on-demand) ---
341
- defineMediaResolver(options) {
342
- return createMediaResolver({
343
- ...this.media,
344
- ...options
345
- });
346
- }
347
- // --- store delegation ---
348
- defineSingleton(sourceOrKey, options) {
349
- return this._store.defineSingleton(sourceOrKey, options);
350
- }
351
- defineSingletonSync(sourceOrKey, options) {
352
- return this._store.defineSingletonSync(sourceOrKey, options);
353
- }
354
- defineCollection(sourceOrKey, options) {
355
- return this._store.defineCollection(sourceOrKey, options);
356
- }
357
- defineCollectionSync(sourceOrKey, options) {
358
- return this._store.defineCollectionSync(sourceOrKey, options);
359
- }
360
- defineLazyCollection(sourceOrKey, options) {
361
- return this._store.defineLazyCollection(sourceOrKey, options);
362
- }
363
- defineRoutes(options) {
364
- return this._store.defineRoutes(options);
365
- }
366
- defineRoutesSync(options) {
367
- return this._store.defineRoutesSync(options);
368
- }
369
- defineLazyRoutes(options) {
370
- return this._store.defineLazyRoutes(options);
371
- }
372
- defineAssets(options) {
373
- return this._store.defineAssets(options);
374
- }
375
- defineAssetsSync(options) {
376
- return this._store.defineAssetsSync(options);
377
- }
378
- defineLazyAssets(options) {
379
- return this._store.defineLazyAssets(options);
380
- }
381
- // --- middleware factories (arrow fields so destructuring works) ---
382
- createRoutingMiddleware = (options) => {
383
- const routes = options?.routes ?? (this._autoLazyRoutes ??= this.defineLazyRoutes());
384
- return createBoundRoutingMiddleware(this, routes, options?.exclude, options?.resolveRoutePath);
385
- };
386
- createAssetsMiddleware = (options) => {
387
- return createBoundAssetsMiddleware(this, options);
388
- };
389
- // --- ALS run ---
390
- [runRequest](ctx, fn) {
391
- return this._als.run(ctx, fn);
392
- }
189
+ _store;
190
+ _options;
191
+ _i18nMessages;
192
+ _i18nUnsubscribe;
193
+ _initialized = false;
194
+ _als = new AsyncLocalStorage();
195
+ _autoLazyRoutes;
196
+ media;
197
+ createRoutingMiddleware = (options) => {
198
+ const routes = options?.routes ?? (this._autoLazyRoutes ??= this.defineLazyRoutes());
199
+ return createBoundRoutingMiddleware(this, routes, options?.exclude, options?.resolveRoutePath);
200
+ };
201
+ createAssetsMiddleware = (options) => {
202
+ return createBoundAssetsMiddleware(this, options);
203
+ };
204
+ constructor(options) {
205
+ this._options = options;
206
+ this._store = createStore(options);
207
+ this.media = {
208
+ baseUrl: options.media?.baseUrl ?? "",
209
+ imagesPath: options.media?.imagesPath ?? DEFAULT_IMAGES_PREFIX,
210
+ videosPath: options.media?.videosPath ?? DEFAULT_VIDEO_PREFIX,
211
+ filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX
212
+ };
213
+ }
214
+ async init(options) {
215
+ try {
216
+ await this._store.init();
217
+ if (this._options.i18n) {
218
+ const { collection, languages, cache } = this._options.i18n;
219
+ const dev = getBootContext()?.dev ?? false;
220
+ const { register = !dev, load = true } = options?.i18n ?? {};
221
+ this._i18nMessages = this._store.defineI18nMessages({
222
+ collection,
223
+ cache
224
+ });
225
+ await i18n.configure({ locales: languages });
226
+ if (register) {
227
+ const registrations = buildI18nRegistrations();
228
+ if (registrations.length > 0) await this._i18nMessages.register(registrations);
229
+ }
230
+ if (load) {
231
+ await applyTranslations(this._i18nMessages);
232
+ const messages = this._i18nMessages;
233
+ const controller = new AbortController();
234
+ this._i18nUnsubscribe = () => controller.abort();
235
+ (async () => {
236
+ for await (const _ of messages.refresh$) {
237
+ if (controller.signal.aborted) return;
238
+ await applyTranslations(messages);
239
+ }
240
+ })();
241
+ }
242
+ }
243
+ await Promise.all((options?.load ?? []).map((l) => l.load()));
244
+ this._initialized = true;
245
+ } catch (error) {
246
+ try {
247
+ await this.destroy();
248
+ } catch {}
249
+ throw error;
250
+ }
251
+ }
252
+ async destroy() {
253
+ this._initialized = false;
254
+ this._i18nUnsubscribe?.();
255
+ this._i18nUnsubscribe = void 0;
256
+ await this._store.destroy();
257
+ this._i18nMessages = void 0;
258
+ }
259
+ ping() {
260
+ return this._store.ping();
261
+ }
262
+ get isReady() {
263
+ return this._initialized;
264
+ }
265
+ get client() {
266
+ return this._store.client;
267
+ }
268
+ get i18nMessages() {
269
+ if (!this._i18nMessages) throw new Error("@contello/astro: .i18nMessages accessed before init() with i18n config");
270
+ return this._i18nMessages;
271
+ }
272
+ get request() {
273
+ const ctx = this._als.getStore();
274
+ if (!ctx) throw new Error("@contello/astro: .request accessed outside of request context");
275
+ return ctx;
276
+ }
277
+ defineMediaResolver(options) {
278
+ return createMediaResolver({
279
+ ...this.media,
280
+ ...options
281
+ });
282
+ }
283
+ defineSingleton(sourceOrKey, options) {
284
+ return this._store.defineSingleton(sourceOrKey, options);
285
+ }
286
+ defineSingletonSync(sourceOrKey, options) {
287
+ return this._store.defineSingletonSync(sourceOrKey, options);
288
+ }
289
+ defineCollection(sourceOrKey, options) {
290
+ return this._store.defineCollection(sourceOrKey, options);
291
+ }
292
+ defineCollectionSync(sourceOrKey, options) {
293
+ return this._store.defineCollectionSync(sourceOrKey, options);
294
+ }
295
+ defineLazyCollection(sourceOrKey, options) {
296
+ return this._store.defineLazyCollection(sourceOrKey, options);
297
+ }
298
+ defineRoutes(options) {
299
+ return this._store.defineRoutes(options);
300
+ }
301
+ defineRoutesSync(options) {
302
+ return this._store.defineRoutesSync(options);
303
+ }
304
+ defineLazyRoutes(options) {
305
+ return this._store.defineLazyRoutes(options);
306
+ }
307
+ defineAssets(options) {
308
+ return this._store.defineAssets(options);
309
+ }
310
+ defineAssetsSync(options) {
311
+ return this._store.defineAssetsSync(options);
312
+ }
313
+ defineLazyAssets(options) {
314
+ return this._store.defineLazyAssets(options);
315
+ }
316
+ [runRequest](ctx, fn) {
317
+ return this._als.run(ctx, fn);
318
+ }
393
319
  };
394
320
  function createContello(options) {
395
- return new Contello(options);
321
+ return new Contello(options);
396
322
  }
397
- export {
398
- Contello,
399
- createContello
400
- };
323
+ //#endregion
324
+ export { Contello, createContello };
325
+
326
+ //# sourceMappingURL=index.js.map