@contello/astro 2.2.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +19 -10
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +19 -10
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -127,7 +127,7 @@ function handleFile(client, next, rest, cacheControl) {
|
|
|
127
127
|
if (cacheControl) {
|
|
128
128
|
headers.set("cache-control", cacheControl);
|
|
129
129
|
}
|
|
130
|
-
if (result.size) {
|
|
130
|
+
if (result.size > 0) {
|
|
131
131
|
headers.set("content-length", String(result.size));
|
|
132
132
|
}
|
|
133
133
|
return new Response(result.stream(), { headers });
|
|
@@ -156,6 +156,10 @@ function customHeaders(headers) {
|
|
|
156
156
|
}
|
|
157
157
|
return result;
|
|
158
158
|
}
|
|
159
|
+
var VALID_REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
160
|
+
function toRedirectStatus(status) {
|
|
161
|
+
return VALID_REDIRECT_STATUSES.has(status) ? status : 302;
|
|
162
|
+
}
|
|
159
163
|
function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
|
|
160
164
|
return (0, import_middleware2.defineMiddleware)((ctx, next) => {
|
|
161
165
|
if ((0, import_excludes.shouldExclude)(ctx, exclude ?? import_excludes.RECOMMENDED_EXCLUDES)) {
|
|
@@ -176,13 +180,13 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
176
180
|
return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
|
|
177
181
|
}
|
|
178
182
|
switch (route.type) {
|
|
179
|
-
case "redirect":
|
|
183
|
+
case "redirect": {
|
|
180
184
|
return contello[runRequest](
|
|
181
185
|
{ url, route, rewritten: false },
|
|
182
186
|
() => wrap(
|
|
183
187
|
"route:redirect",
|
|
184
188
|
() => new Response(null, {
|
|
185
|
-
status: route.status,
|
|
189
|
+
status: toRedirectStatus(route.status),
|
|
186
190
|
headers: {
|
|
187
191
|
Location: route.location,
|
|
188
192
|
...customHeaders(route.customHeaders)
|
|
@@ -190,7 +194,8 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
190
194
|
})
|
|
191
195
|
)
|
|
192
196
|
);
|
|
193
|
-
|
|
197
|
+
}
|
|
198
|
+
case "text": {
|
|
194
199
|
return contello[runRequest](
|
|
195
200
|
{ url, route, rewritten: false },
|
|
196
201
|
() => wrap(
|
|
@@ -204,13 +209,15 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
204
209
|
})
|
|
205
210
|
)
|
|
206
211
|
);
|
|
207
|
-
|
|
212
|
+
}
|
|
213
|
+
case "asset": {
|
|
208
214
|
return contello[runRequest](
|
|
209
215
|
{ url, route, rewritten: false },
|
|
210
216
|
() => wrap("route:asset", async () => {
|
|
211
217
|
const result = await contello.client.download(route.fileId);
|
|
212
|
-
const headers = new Headers({ "content-type": result.mimeType });
|
|
213
|
-
|
|
218
|
+
const headers = new Headers({ "content-type": route.mimeType || result.mimeType });
|
|
219
|
+
headers.set("content-disposition", route.contentDisposition);
|
|
220
|
+
if (result.size > 0) {
|
|
214
221
|
headers.set("content-length", String(result.size));
|
|
215
222
|
}
|
|
216
223
|
for (const { name, value } of route.customHeaders) {
|
|
@@ -219,7 +226,8 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
219
226
|
return new Response(result.stream(), { headers });
|
|
220
227
|
})
|
|
221
228
|
);
|
|
222
|
-
|
|
229
|
+
}
|
|
230
|
+
case "entity": {
|
|
223
231
|
return contello[runRequest](
|
|
224
232
|
{ url, route, rewritten: true },
|
|
225
233
|
() => wrap(`route:entity:${route.model}`, async () => {
|
|
@@ -230,6 +238,7 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
230
238
|
return response;
|
|
231
239
|
})
|
|
232
240
|
);
|
|
241
|
+
}
|
|
233
242
|
}
|
|
234
243
|
});
|
|
235
244
|
});
|
|
@@ -325,10 +334,10 @@ var Contello = class {
|
|
|
325
334
|
}
|
|
326
335
|
await Promise.all((options?.load ?? []).map((l) => l.load()));
|
|
327
336
|
this._initialized = true;
|
|
328
|
-
} catch (
|
|
337
|
+
} catch (error) {
|
|
329
338
|
await this.destroy().catch(() => {
|
|
330
339
|
});
|
|
331
|
-
throw
|
|
340
|
+
throw error;
|
|
332
341
|
}
|
|
333
342
|
}
|
|
334
343
|
async destroy() {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as astro from 'astro';
|
|
2
2
|
import { APIContext } from 'astro';
|
|
3
3
|
import { Schema, ContelloClient, SourceDef } from '@contello/client';
|
|
4
|
-
import { MediaResolverOptions, MediaResolver
|
|
4
|
+
import { MediaResolverOptions, MediaResolver } from '@contello/media';
|
|
5
5
|
import { Routes, RoutesSync, LazyRoutes, CreateStoreOptions, SyncCacheOptions, Loadable, I18nMessages, ReadonlyDeep, StoreRoute, SourceKeysOf, ExtractSourceResult, ResolveSource, SingletonOptions, Singleton, SingletonSyncOptions, SingletonSync, CollectionOptions, Collection, CollectionSyncOptions, CollectionSync, LazyCollectionOptions, LazyCollection, RoutesOptions, RoutesSyncOptions, LazyRoutesOptions, AssetsOptions, Assets, AssetsSyncOptions, AssetsSync, LazyAssetsOptions, LazyAssets } from '@contello/store';
|
|
6
6
|
import { ExcludePattern } from '@astroscope/excludes';
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ type ContelloAssetsImagesOptions = {
|
|
|
11
11
|
type ContelloAssetsFilesOptions = {
|
|
12
12
|
cacheControl?: string | undefined;
|
|
13
13
|
};
|
|
14
|
-
type ContelloAssetsVideoOptions =
|
|
14
|
+
type ContelloAssetsVideoOptions = Record<string, never>;
|
|
15
15
|
type ContelloAssetsMiddlewareOptions = {
|
|
16
16
|
images?: ContelloAssetsImagesOptions | undefined;
|
|
17
17
|
files?: ContelloAssetsFilesOptions | undefined;
|
|
@@ -70,8 +70,8 @@ type ContelloOptions<TSchema extends Schema | undefined = undefined> = CreateSto
|
|
|
70
70
|
media?: Partial<ContelloMediaConfig> | undefined;
|
|
71
71
|
};
|
|
72
72
|
type HasFallback<O> = O extends {
|
|
73
|
-
fallback:
|
|
74
|
-
} ? true : false;
|
|
73
|
+
fallback: infer F;
|
|
74
|
+
} ? ([F] extends [undefined] ? false : true) : false;
|
|
75
75
|
declare const runRequest: unique symbol;
|
|
76
76
|
type ModelsOf<TSchema> = TSchema extends {
|
|
77
77
|
models: infer M;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as astro from 'astro';
|
|
2
2
|
import { APIContext } from 'astro';
|
|
3
3
|
import { Schema, ContelloClient, SourceDef } from '@contello/client';
|
|
4
|
-
import { MediaResolverOptions, MediaResolver
|
|
4
|
+
import { MediaResolverOptions, MediaResolver } from '@contello/media';
|
|
5
5
|
import { Routes, RoutesSync, LazyRoutes, CreateStoreOptions, SyncCacheOptions, Loadable, I18nMessages, ReadonlyDeep, StoreRoute, SourceKeysOf, ExtractSourceResult, ResolveSource, SingletonOptions, Singleton, SingletonSyncOptions, SingletonSync, CollectionOptions, Collection, CollectionSyncOptions, CollectionSync, LazyCollectionOptions, LazyCollection, RoutesOptions, RoutesSyncOptions, LazyRoutesOptions, AssetsOptions, Assets, AssetsSyncOptions, AssetsSync, LazyAssetsOptions, LazyAssets } from '@contello/store';
|
|
6
6
|
import { ExcludePattern } from '@astroscope/excludes';
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ type ContelloAssetsImagesOptions = {
|
|
|
11
11
|
type ContelloAssetsFilesOptions = {
|
|
12
12
|
cacheControl?: string | undefined;
|
|
13
13
|
};
|
|
14
|
-
type ContelloAssetsVideoOptions =
|
|
14
|
+
type ContelloAssetsVideoOptions = Record<string, never>;
|
|
15
15
|
type ContelloAssetsMiddlewareOptions = {
|
|
16
16
|
images?: ContelloAssetsImagesOptions | undefined;
|
|
17
17
|
files?: ContelloAssetsFilesOptions | undefined;
|
|
@@ -70,8 +70,8 @@ type ContelloOptions<TSchema extends Schema | undefined = undefined> = CreateSto
|
|
|
70
70
|
media?: Partial<ContelloMediaConfig> | undefined;
|
|
71
71
|
};
|
|
72
72
|
type HasFallback<O> = O extends {
|
|
73
|
-
fallback:
|
|
74
|
-
} ? true : false;
|
|
73
|
+
fallback: infer F;
|
|
74
|
+
} ? ([F] extends [undefined] ? false : true) : false;
|
|
75
75
|
declare const runRequest: unique symbol;
|
|
76
76
|
type ModelsOf<TSchema> = TSchema extends {
|
|
77
77
|
models: infer M;
|
package/dist/index.js
CHANGED
|
@@ -92,7 +92,7 @@ function handleFile(client, next, rest, cacheControl) {
|
|
|
92
92
|
if (cacheControl) {
|
|
93
93
|
headers.set("cache-control", cacheControl);
|
|
94
94
|
}
|
|
95
|
-
if (result.size) {
|
|
95
|
+
if (result.size > 0) {
|
|
96
96
|
headers.set("content-length", String(result.size));
|
|
97
97
|
}
|
|
98
98
|
return new Response(result.stream(), { headers });
|
|
@@ -123,6 +123,10 @@ function customHeaders(headers) {
|
|
|
123
123
|
}
|
|
124
124
|
return result;
|
|
125
125
|
}
|
|
126
|
+
var VALID_REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
127
|
+
function toRedirectStatus(status) {
|
|
128
|
+
return VALID_REDIRECT_STATUSES.has(status) ? status : 302;
|
|
129
|
+
}
|
|
126
130
|
function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePath) {
|
|
127
131
|
return defineMiddleware2((ctx, next) => {
|
|
128
132
|
if (shouldExclude(ctx, exclude ?? RECOMMENDED_EXCLUDES)) {
|
|
@@ -143,13 +147,13 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
143
147
|
return contello[runRequest]({ url, route: void 0, rewritten: false }, () => next());
|
|
144
148
|
}
|
|
145
149
|
switch (route.type) {
|
|
146
|
-
case "redirect":
|
|
150
|
+
case "redirect": {
|
|
147
151
|
return contello[runRequest](
|
|
148
152
|
{ url, route, rewritten: false },
|
|
149
153
|
() => wrap(
|
|
150
154
|
"route:redirect",
|
|
151
155
|
() => new Response(null, {
|
|
152
|
-
status: route.status,
|
|
156
|
+
status: toRedirectStatus(route.status),
|
|
153
157
|
headers: {
|
|
154
158
|
Location: route.location,
|
|
155
159
|
...customHeaders(route.customHeaders)
|
|
@@ -157,7 +161,8 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
157
161
|
})
|
|
158
162
|
)
|
|
159
163
|
);
|
|
160
|
-
|
|
164
|
+
}
|
|
165
|
+
case "text": {
|
|
161
166
|
return contello[runRequest](
|
|
162
167
|
{ url, route, rewritten: false },
|
|
163
168
|
() => wrap(
|
|
@@ -171,13 +176,15 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
171
176
|
})
|
|
172
177
|
)
|
|
173
178
|
);
|
|
174
|
-
|
|
179
|
+
}
|
|
180
|
+
case "asset": {
|
|
175
181
|
return contello[runRequest](
|
|
176
182
|
{ url, route, rewritten: false },
|
|
177
183
|
() => wrap("route:asset", async () => {
|
|
178
184
|
const result = await contello.client.download(route.fileId);
|
|
179
|
-
const headers = new Headers({ "content-type": result.mimeType });
|
|
180
|
-
|
|
185
|
+
const headers = new Headers({ "content-type": route.mimeType || result.mimeType });
|
|
186
|
+
headers.set("content-disposition", route.contentDisposition);
|
|
187
|
+
if (result.size > 0) {
|
|
181
188
|
headers.set("content-length", String(result.size));
|
|
182
189
|
}
|
|
183
190
|
for (const { name, value } of route.customHeaders) {
|
|
@@ -186,7 +193,8 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
186
193
|
return new Response(result.stream(), { headers });
|
|
187
194
|
})
|
|
188
195
|
);
|
|
189
|
-
|
|
196
|
+
}
|
|
197
|
+
case "entity": {
|
|
190
198
|
return contello[runRequest](
|
|
191
199
|
{ url, route, rewritten: true },
|
|
192
200
|
() => wrap(`route:entity:${route.model}`, async () => {
|
|
@@ -197,6 +205,7 @@ function createBoundRoutingMiddleware(contello, routes, exclude, resolveRoutePat
|
|
|
197
205
|
return response;
|
|
198
206
|
})
|
|
199
207
|
);
|
|
208
|
+
}
|
|
200
209
|
}
|
|
201
210
|
});
|
|
202
211
|
});
|
|
@@ -292,10 +301,10 @@ var Contello = class {
|
|
|
292
301
|
}
|
|
293
302
|
await Promise.all((options?.load ?? []).map((l) => l.load()));
|
|
294
303
|
this._initialized = true;
|
|
295
|
-
} catch (
|
|
304
|
+
} catch (error) {
|
|
296
305
|
await this.destroy().catch(() => {
|
|
297
306
|
});
|
|
298
|
-
throw
|
|
307
|
+
throw error;
|
|
299
308
|
}
|
|
300
309
|
}
|
|
301
310
|
async destroy() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/astro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Astro integration for Contello CMS — route middleware and i18n bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@astroscope/excludes": ">=0.1.0",
|
|
15
15
|
"@astroscope/i18n": ">=0.3.0",
|
|
16
|
-
"astro": "^6.0.0",
|
|
17
|
-
"@contello/client": "^2.2.
|
|
18
|
-
"@contello/media": "^
|
|
19
|
-
"@contello/store": "^
|
|
16
|
+
"astro": "^6.0.0 || ^7.0.0",
|
|
17
|
+
"@contello/client": "^2.2.2",
|
|
18
|
+
"@contello/media": "^2.0.1",
|
|
19
|
+
"@contello/store": "^3.0.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependenciesMeta": {
|
|
22
22
|
"@astroscope/i18n": {
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@astroscope/excludes": "^0.
|
|
28
|
-
"@astroscope/i18n": "^0.
|
|
29
|
-
"astro": "^
|
|
30
|
-
"@contello/client": "^2.2.
|
|
31
|
-
"@contello/
|
|
32
|
-
"@contello/
|
|
27
|
+
"@astroscope/excludes": "^0.4.0",
|
|
28
|
+
"@astroscope/i18n": "^0.6.0",
|
|
29
|
+
"astro": "^7.0.3",
|
|
30
|
+
"@contello/client": "^2.2.2",
|
|
31
|
+
"@contello/store": "^3.0.0",
|
|
32
|
+
"@contello/media": "^2.0.1"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup",
|
|
50
|
-
"lint": "eslint .",
|
|
50
|
+
"lint": "eslint . --cache",
|
|
51
51
|
"lint:fix": "eslint . --fix",
|
|
52
52
|
"typecheck": "tsc --noEmit"
|
|
53
53
|
}
|