@contello/astro 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -1
- package/dist/index.d.cts +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.js +9 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -93,7 +93,8 @@ var Contello = class {
|
|
|
93
93
|
this._assets = this._store.defineAssets(this._options.assets);
|
|
94
94
|
this._routes = this._store.defineRoutes(this._options.routes);
|
|
95
95
|
if (this._options.i18n) {
|
|
96
|
-
const { collection, languages
|
|
96
|
+
const { collection, languages } = this._options.i18n;
|
|
97
|
+
const { register = true, load = true } = options?.i18n ?? {};
|
|
97
98
|
this._i18nMessages = this._store.defineI18nMessages({ collection });
|
|
98
99
|
await import_i18n.i18n.configure({ locales: languages });
|
|
99
100
|
if (register) {
|
|
@@ -123,6 +124,9 @@ var Contello = class {
|
|
|
123
124
|
ping() {
|
|
124
125
|
return this._store.ping();
|
|
125
126
|
}
|
|
127
|
+
get isReady() {
|
|
128
|
+
return !!this._routes;
|
|
129
|
+
}
|
|
126
130
|
// --- pre-wired collections ---
|
|
127
131
|
get assets() {
|
|
128
132
|
if (!this._assets) {
|
|
@@ -235,6 +239,10 @@ function createRoutingMiddleware(instance, options) {
|
|
|
235
239
|
if ((0, import_excludes.shouldExclude)(ctx, exclude ?? import_excludes.RECOMMENDED_EXCLUDES)) {
|
|
236
240
|
return next();
|
|
237
241
|
}
|
|
242
|
+
if (!instance.isReady) {
|
|
243
|
+
console.warn(`[@contello/astro] not initialized, passing through: ${ctx.url.pathname}`);
|
|
244
|
+
return next();
|
|
245
|
+
}
|
|
238
246
|
const { url } = ctx;
|
|
239
247
|
if (url.pathname.startsWith("/contello/entities/")) {
|
|
240
248
|
return instance[runRequest]({ url, route: void 0, rewritten: false }, () => next());
|
package/dist/index.d.cts
CHANGED
|
@@ -11,8 +11,13 @@ type ContelloRequestContext = {
|
|
|
11
11
|
type ContelloI18nOptions = {
|
|
12
12
|
collection: string;
|
|
13
13
|
languages: string[];
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
};
|
|
15
|
+
type ContelloInitOptions = {
|
|
16
|
+
load?: Loadable[] | undefined;
|
|
17
|
+
i18n?: {
|
|
18
|
+
register?: boolean | undefined;
|
|
19
|
+
load?: boolean | undefined;
|
|
20
|
+
} | undefined;
|
|
16
21
|
};
|
|
17
22
|
type ContelloOptions<TOps extends OperationMap | undefined = undefined, TModels extends string = string> = CreateStoreOptions<TOps, TModels> & {
|
|
18
23
|
assets?: AssetCollectionOptions | undefined;
|
|
@@ -29,11 +34,10 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
|
|
|
29
34
|
private _i18nSubscription;
|
|
30
35
|
private readonly _als;
|
|
31
36
|
constructor(options: ContelloOptions<TOps, TModels>);
|
|
32
|
-
init(options?:
|
|
33
|
-
load?: Loadable[] | undefined;
|
|
34
|
-
} | undefined): Promise<void>;
|
|
37
|
+
init(options?: ContelloInitOptions | undefined): Promise<void>;
|
|
35
38
|
destroy(): Promise<void>;
|
|
36
39
|
ping(): Promise<void>;
|
|
40
|
+
get isReady(): boolean;
|
|
37
41
|
get assets(): Assets;
|
|
38
42
|
get routes(): Routes;
|
|
39
43
|
get i18nMessages(): I18nMessages;
|
|
@@ -58,4 +62,4 @@ type ContelloMiddlewareOptions = {
|
|
|
58
62
|
};
|
|
59
63
|
declare function createRoutingMiddleware(instance: Contello<any, any>, options?: ContelloMiddlewareOptions | undefined): astro.MiddlewareHandler;
|
|
60
64
|
|
|
61
|
-
export { Contello, type ContelloI18nOptions, type ContelloMiddlewareOptions, type ContelloOptions, type ContelloRequestContext, createContello, createRoutingMiddleware };
|
|
65
|
+
export { Contello, type ContelloI18nOptions, type ContelloInitOptions, type ContelloMiddlewareOptions, type ContelloOptions, type ContelloRequestContext, createContello, createRoutingMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,13 @@ type ContelloRequestContext = {
|
|
|
11
11
|
type ContelloI18nOptions = {
|
|
12
12
|
collection: string;
|
|
13
13
|
languages: string[];
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
};
|
|
15
|
+
type ContelloInitOptions = {
|
|
16
|
+
load?: Loadable[] | undefined;
|
|
17
|
+
i18n?: {
|
|
18
|
+
register?: boolean | undefined;
|
|
19
|
+
load?: boolean | undefined;
|
|
20
|
+
} | undefined;
|
|
16
21
|
};
|
|
17
22
|
type ContelloOptions<TOps extends OperationMap | undefined = undefined, TModels extends string = string> = CreateStoreOptions<TOps, TModels> & {
|
|
18
23
|
assets?: AssetCollectionOptions | undefined;
|
|
@@ -29,11 +34,10 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
|
|
|
29
34
|
private _i18nSubscription;
|
|
30
35
|
private readonly _als;
|
|
31
36
|
constructor(options: ContelloOptions<TOps, TModels>);
|
|
32
|
-
init(options?:
|
|
33
|
-
load?: Loadable[] | undefined;
|
|
34
|
-
} | undefined): Promise<void>;
|
|
37
|
+
init(options?: ContelloInitOptions | undefined): Promise<void>;
|
|
35
38
|
destroy(): Promise<void>;
|
|
36
39
|
ping(): Promise<void>;
|
|
40
|
+
get isReady(): boolean;
|
|
37
41
|
get assets(): Assets;
|
|
38
42
|
get routes(): Routes;
|
|
39
43
|
get i18nMessages(): I18nMessages;
|
|
@@ -58,4 +62,4 @@ type ContelloMiddlewareOptions = {
|
|
|
58
62
|
};
|
|
59
63
|
declare function createRoutingMiddleware(instance: Contello<any, any>, options?: ContelloMiddlewareOptions | undefined): astro.MiddlewareHandler;
|
|
60
64
|
|
|
61
|
-
export { Contello, type ContelloI18nOptions, type ContelloMiddlewareOptions, type ContelloOptions, type ContelloRequestContext, createContello, createRoutingMiddleware };
|
|
65
|
+
export { Contello, type ContelloI18nOptions, type ContelloInitOptions, type ContelloMiddlewareOptions, type ContelloOptions, type ContelloRequestContext, createContello, createRoutingMiddleware };
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,8 @@ var Contello = class {
|
|
|
57
57
|
this._assets = this._store.defineAssets(this._options.assets);
|
|
58
58
|
this._routes = this._store.defineRoutes(this._options.routes);
|
|
59
59
|
if (this._options.i18n) {
|
|
60
|
-
const { collection, languages
|
|
60
|
+
const { collection, languages } = this._options.i18n;
|
|
61
|
+
const { register = true, load = true } = options?.i18n ?? {};
|
|
61
62
|
this._i18nMessages = this._store.defineI18nMessages({ collection });
|
|
62
63
|
await i18n.configure({ locales: languages });
|
|
63
64
|
if (register) {
|
|
@@ -87,6 +88,9 @@ var Contello = class {
|
|
|
87
88
|
ping() {
|
|
88
89
|
return this._store.ping();
|
|
89
90
|
}
|
|
91
|
+
get isReady() {
|
|
92
|
+
return !!this._routes;
|
|
93
|
+
}
|
|
90
94
|
// --- pre-wired collections ---
|
|
91
95
|
get assets() {
|
|
92
96
|
if (!this._assets) {
|
|
@@ -199,6 +203,10 @@ function createRoutingMiddleware(instance, options) {
|
|
|
199
203
|
if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) {
|
|
200
204
|
return next();
|
|
201
205
|
}
|
|
206
|
+
if (!instance.isReady) {
|
|
207
|
+
console.warn(`[@contello/astro] not initialized, passing through: ${ctx.url.pathname}`);
|
|
208
|
+
return next();
|
|
209
|
+
}
|
|
202
210
|
const { url } = ctx;
|
|
203
211
|
if (url.pathname.startsWith("/contello/entities/")) {
|
|
204
212
|
return instance[runRequest]({ url, route: void 0, rewritten: false }, () => next());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/astro",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Astro integration for Contello CMS — route middleware and i18n bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@contello/client": "^1.0.3",
|
|
25
|
-
"@contello/store": "^1.1.
|
|
25
|
+
"@contello/store": "^1.1.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@astroscope/excludes": "^0.3.
|
|
29
|
-
"@astroscope/i18n": "^0.4.
|
|
30
|
-
"astro": "^6.
|
|
28
|
+
"@astroscope/excludes": "^0.3.1",
|
|
29
|
+
"@astroscope/i18n": "^0.4.4",
|
|
30
|
+
"astro": "^6.1.8"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist"
|