@contello/astro 1.0.0 → 1.0.1
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 +12 -8
- package/dist/index.d.cts +13 -12
- package/dist/index.d.ts +13 -12
- package/dist/index.js +12 -8
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -179,9 +179,9 @@ var import_middleware = require("astro/middleware");
|
|
|
179
179
|
// src/diagnostics.ts
|
|
180
180
|
var import_node_diagnostics_channel = __toESM(require("diagnostics_channel"), 1);
|
|
181
181
|
var channels = {
|
|
182
|
-
start: "contello:
|
|
183
|
-
end: "contello:
|
|
184
|
-
error: "contello:
|
|
182
|
+
start: "@contello/astro:start",
|
|
183
|
+
end: "@contello/astro:end",
|
|
184
|
+
error: "@contello/astro:error"
|
|
185
185
|
};
|
|
186
186
|
var onStart = import_node_diagnostics_channel.default.channel(channels.start);
|
|
187
187
|
var onEnd = import_node_diagnostics_channel.default.channel(channels.end);
|
|
@@ -273,18 +273,22 @@ function createRoutingMiddleware(instance, options) {
|
|
|
273
273
|
return instance[runRequest](
|
|
274
274
|
{ url, route, rewritten: false },
|
|
275
275
|
() => wrap("route:asset", async () => {
|
|
276
|
-
const
|
|
276
|
+
const result = await instance.assets.download(route.fileId);
|
|
277
|
+
const headers = new Headers({ "content-type": result.mimeType });
|
|
278
|
+
if (result.size) {
|
|
279
|
+
headers.set("content-length", String(result.size));
|
|
280
|
+
}
|
|
277
281
|
for (const { name, value } of route.customHeaders) {
|
|
278
|
-
|
|
282
|
+
headers.set(name, value);
|
|
279
283
|
}
|
|
280
|
-
return
|
|
284
|
+
return new Response(result.stream(), { headers });
|
|
281
285
|
})
|
|
282
286
|
);
|
|
283
287
|
case "entity":
|
|
284
288
|
return instance[runRequest](
|
|
285
289
|
{ url, route, rewritten: true },
|
|
286
|
-
() => wrap(`route:entity:${route.
|
|
287
|
-
const response = await next(`/contello/entities/${route.
|
|
290
|
+
() => wrap(`route:entity:${route.model}`, async () => {
|
|
291
|
+
const response = await next(`/contello/entities/${route.model}/${route.entityId}${url.search}`);
|
|
288
292
|
for (const { name, value } of route.customHeaders) {
|
|
289
293
|
response.headers.set(name, value);
|
|
290
294
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OperationMap } from '@contello/client';
|
|
1
2
|
import { CreateStoreOptions, AssetCollectionOptions, RouteCollectionOptions, Assets, Routes, I18nMessages, StoreRoute, SingletonDef, Singleton, SingletonSyncDef, SingletonSync, CollectionDef, Collection, CollectionSyncDef, CollectionSync, LazyCollectionDef, LazyCollection } from '@contello/store';
|
|
2
3
|
import * as astro from 'astro';
|
|
3
4
|
import { ExcludePattern } from '@astroscope/excludes';
|
|
@@ -13,13 +14,13 @@ type ContelloI18nOptions = {
|
|
|
13
14
|
register?: boolean | undefined;
|
|
14
15
|
load?: boolean | undefined;
|
|
15
16
|
};
|
|
16
|
-
type ContelloOptions<
|
|
17
|
+
type ContelloOptions<TOps extends OperationMap | undefined = undefined, TModels extends string = string> = CreateStoreOptions<TOps, TModels> & {
|
|
17
18
|
assets?: AssetCollectionOptions | undefined;
|
|
18
19
|
i18n?: ContelloI18nOptions | undefined;
|
|
19
20
|
routes?: RouteCollectionOptions | undefined;
|
|
20
21
|
};
|
|
21
22
|
declare const runRequest: unique symbol;
|
|
22
|
-
declare class Contello<
|
|
23
|
+
declare class Contello<TOps extends OperationMap | undefined = undefined, TModels extends string = string> {
|
|
23
24
|
private readonly _store;
|
|
24
25
|
private readonly _options;
|
|
25
26
|
private _assets;
|
|
@@ -27,7 +28,7 @@ declare class Contello<TSdk, TEntityTypes extends string = string> {
|
|
|
27
28
|
private _i18nMessages;
|
|
28
29
|
private _i18nSubscription;
|
|
29
30
|
private readonly _als;
|
|
30
|
-
constructor(options: ContelloOptions<
|
|
31
|
+
constructor(options: ContelloOptions<TOps, TModels>);
|
|
31
32
|
init(): Promise<void>;
|
|
32
33
|
destroy(): Promise<void>;
|
|
33
34
|
ping(): Promise<void>;
|
|
@@ -35,20 +36,20 @@ declare class Contello<TSdk, TEntityTypes extends string = string> {
|
|
|
35
36
|
get routes(): Routes;
|
|
36
37
|
get i18nMessages(): I18nMessages;
|
|
37
38
|
get request(): ContelloRequestContext;
|
|
38
|
-
defineSingleton<TModel extends
|
|
39
|
-
defineSingletonSync<TModel extends
|
|
40
|
-
defineCollection<TModel extends
|
|
39
|
+
defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
|
|
40
|
+
defineSingletonSync<TModel extends TModels, TRaw, TMapped>(def: SingletonSyncDef<TOps, TModel, TRaw, TMapped, TModels>): SingletonSync<TMapped>;
|
|
41
|
+
defineCollection<TModel extends TModels, TRaw, TMapped extends {
|
|
41
42
|
id: string;
|
|
42
|
-
}>(def: CollectionDef<
|
|
43
|
-
defineCollectionSync<TModel extends
|
|
43
|
+
}>(def: CollectionDef<TOps, TModel, TRaw, TMapped, TModels>): Collection<TMapped>;
|
|
44
|
+
defineCollectionSync<TModel extends TModels, TRaw, TMapped extends {
|
|
44
45
|
id: string;
|
|
45
|
-
}>(def: CollectionSyncDef<
|
|
46
|
-
defineLazyCollection<TModel extends
|
|
46
|
+
}>(def: CollectionSyncDef<TOps, TModel, TRaw, TMapped, TModels>): CollectionSync<TMapped>;
|
|
47
|
+
defineLazyCollection<TModel extends TModels, TRaw, TMapped extends {
|
|
47
48
|
id: string;
|
|
48
|
-
}>(def: LazyCollectionDef<
|
|
49
|
+
}>(def: LazyCollectionDef<TOps, TModel, TRaw, TMapped, TModels>): LazyCollection<TMapped>;
|
|
49
50
|
[runRequest]<T>(ctx: ContelloRequestContext, fn: () => T): T;
|
|
50
51
|
}
|
|
51
|
-
declare function createContello<
|
|
52
|
+
declare function createContello<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: ContelloOptions<TOps, TModels>): Contello<TOps, TModels>;
|
|
52
53
|
|
|
53
54
|
type ContelloMiddlewareOptions = {
|
|
54
55
|
exclude?: ExcludePattern[] | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OperationMap } from '@contello/client';
|
|
1
2
|
import { CreateStoreOptions, AssetCollectionOptions, RouteCollectionOptions, Assets, Routes, I18nMessages, StoreRoute, SingletonDef, Singleton, SingletonSyncDef, SingletonSync, CollectionDef, Collection, CollectionSyncDef, CollectionSync, LazyCollectionDef, LazyCollection } from '@contello/store';
|
|
2
3
|
import * as astro from 'astro';
|
|
3
4
|
import { ExcludePattern } from '@astroscope/excludes';
|
|
@@ -13,13 +14,13 @@ type ContelloI18nOptions = {
|
|
|
13
14
|
register?: boolean | undefined;
|
|
14
15
|
load?: boolean | undefined;
|
|
15
16
|
};
|
|
16
|
-
type ContelloOptions<
|
|
17
|
+
type ContelloOptions<TOps extends OperationMap | undefined = undefined, TModels extends string = string> = CreateStoreOptions<TOps, TModels> & {
|
|
17
18
|
assets?: AssetCollectionOptions | undefined;
|
|
18
19
|
i18n?: ContelloI18nOptions | undefined;
|
|
19
20
|
routes?: RouteCollectionOptions | undefined;
|
|
20
21
|
};
|
|
21
22
|
declare const runRequest: unique symbol;
|
|
22
|
-
declare class Contello<
|
|
23
|
+
declare class Contello<TOps extends OperationMap | undefined = undefined, TModels extends string = string> {
|
|
23
24
|
private readonly _store;
|
|
24
25
|
private readonly _options;
|
|
25
26
|
private _assets;
|
|
@@ -27,7 +28,7 @@ declare class Contello<TSdk, TEntityTypes extends string = string> {
|
|
|
27
28
|
private _i18nMessages;
|
|
28
29
|
private _i18nSubscription;
|
|
29
30
|
private readonly _als;
|
|
30
|
-
constructor(options: ContelloOptions<
|
|
31
|
+
constructor(options: ContelloOptions<TOps, TModels>);
|
|
31
32
|
init(): Promise<void>;
|
|
32
33
|
destroy(): Promise<void>;
|
|
33
34
|
ping(): Promise<void>;
|
|
@@ -35,20 +36,20 @@ declare class Contello<TSdk, TEntityTypes extends string = string> {
|
|
|
35
36
|
get routes(): Routes;
|
|
36
37
|
get i18nMessages(): I18nMessages;
|
|
37
38
|
get request(): ContelloRequestContext;
|
|
38
|
-
defineSingleton<TModel extends
|
|
39
|
-
defineSingletonSync<TModel extends
|
|
40
|
-
defineCollection<TModel extends
|
|
39
|
+
defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
|
|
40
|
+
defineSingletonSync<TModel extends TModels, TRaw, TMapped>(def: SingletonSyncDef<TOps, TModel, TRaw, TMapped, TModels>): SingletonSync<TMapped>;
|
|
41
|
+
defineCollection<TModel extends TModels, TRaw, TMapped extends {
|
|
41
42
|
id: string;
|
|
42
|
-
}>(def: CollectionDef<
|
|
43
|
-
defineCollectionSync<TModel extends
|
|
43
|
+
}>(def: CollectionDef<TOps, TModel, TRaw, TMapped, TModels>): Collection<TMapped>;
|
|
44
|
+
defineCollectionSync<TModel extends TModels, TRaw, TMapped extends {
|
|
44
45
|
id: string;
|
|
45
|
-
}>(def: CollectionSyncDef<
|
|
46
|
-
defineLazyCollection<TModel extends
|
|
46
|
+
}>(def: CollectionSyncDef<TOps, TModel, TRaw, TMapped, TModels>): CollectionSync<TMapped>;
|
|
47
|
+
defineLazyCollection<TModel extends TModels, TRaw, TMapped extends {
|
|
47
48
|
id: string;
|
|
48
|
-
}>(def: LazyCollectionDef<
|
|
49
|
+
}>(def: LazyCollectionDef<TOps, TModel, TRaw, TMapped, TModels>): LazyCollection<TMapped>;
|
|
49
50
|
[runRequest]<T>(ctx: ContelloRequestContext, fn: () => T): T;
|
|
50
51
|
}
|
|
51
|
-
declare function createContello<
|
|
52
|
+
declare function createContello<TOps extends OperationMap | undefined = undefined, TModels extends string = string>(options: ContelloOptions<TOps, TModels>): Contello<TOps, TModels>;
|
|
52
53
|
|
|
53
54
|
type ContelloMiddlewareOptions = {
|
|
54
55
|
exclude?: ExcludePattern[] | undefined;
|
package/dist/index.js
CHANGED
|
@@ -143,9 +143,9 @@ import { defineMiddleware } from "astro/middleware";
|
|
|
143
143
|
// src/diagnostics.ts
|
|
144
144
|
import dc from "diagnostics_channel";
|
|
145
145
|
var channels = {
|
|
146
|
-
start: "contello:
|
|
147
|
-
end: "contello:
|
|
148
|
-
error: "contello:
|
|
146
|
+
start: "@contello/astro:start",
|
|
147
|
+
end: "@contello/astro:end",
|
|
148
|
+
error: "@contello/astro:error"
|
|
149
149
|
};
|
|
150
150
|
var onStart = dc.channel(channels.start);
|
|
151
151
|
var onEnd = dc.channel(channels.end);
|
|
@@ -237,18 +237,22 @@ function createRoutingMiddleware(instance, options) {
|
|
|
237
237
|
return instance[runRequest](
|
|
238
238
|
{ url, route, rewritten: false },
|
|
239
239
|
() => wrap("route:asset", async () => {
|
|
240
|
-
const
|
|
240
|
+
const result = await instance.assets.download(route.fileId);
|
|
241
|
+
const headers = new Headers({ "content-type": result.mimeType });
|
|
242
|
+
if (result.size) {
|
|
243
|
+
headers.set("content-length", String(result.size));
|
|
244
|
+
}
|
|
241
245
|
for (const { name, value } of route.customHeaders) {
|
|
242
|
-
|
|
246
|
+
headers.set(name, value);
|
|
243
247
|
}
|
|
244
|
-
return
|
|
248
|
+
return new Response(result.stream(), { headers });
|
|
245
249
|
})
|
|
246
250
|
);
|
|
247
251
|
case "entity":
|
|
248
252
|
return instance[runRequest](
|
|
249
253
|
{ url, route, rewritten: true },
|
|
250
|
-
() => wrap(`route:entity:${route.
|
|
251
|
-
const response = await next(`/contello/entities/${route.
|
|
254
|
+
() => wrap(`route:entity:${route.model}`, async () => {
|
|
255
|
+
const response = await next(`/contello/entities/${route.model}/${route.entityId}${url.search}`);
|
|
252
256
|
for (const { name, value } of route.customHeaders) {
|
|
253
257
|
response.headers.set(name, value);
|
|
254
258
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/astro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Astro integration for Contello CMS — route middleware and i18n bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@astroscope/excludes": ">=0.1.0",
|
|
21
21
|
"@astroscope/i18n": ">=0.3.0",
|
|
22
|
-
"@contello/store": ">=0.0.0",
|
|
23
22
|
"astro": "^6.0.0"
|
|
24
23
|
},
|
|
25
24
|
"peerDependenciesMeta": {
|
|
@@ -27,10 +26,13 @@
|
|
|
27
26
|
"optional": true
|
|
28
27
|
}
|
|
29
28
|
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@contello/client": "workspace:*",
|
|
31
|
+
"@contello/store": "workspace:*"
|
|
32
|
+
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@astroscope/excludes": "^0.3.0",
|
|
32
35
|
"@astroscope/i18n": "^0.4.0",
|
|
33
|
-
"@contello/store": "workspace:*",
|
|
34
36
|
"astro": "^6.0.4"
|
|
35
37
|
},
|
|
36
38
|
"files": [
|