@contello/astro 3.1.0 → 3.2.0

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