@contello/astro 1.3.1 → 1.4.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 +12 -9
- package/dist/index.d.cts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +12 -9
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
40
40
|
// src/contello.ts
|
|
41
41
|
var import_node_async_hooks = require("async_hooks");
|
|
42
42
|
var import_i18n = require("@astroscope/i18n");
|
|
43
|
+
var import_media = require("@contello/media");
|
|
43
44
|
var import_store = require("@contello/store");
|
|
44
45
|
var DEFAULT_IMAGES_PREFIX = "/_contello/i/";
|
|
45
46
|
var DEFAULT_FILES_PREFIX = "/_contello/f/";
|
|
@@ -87,18 +88,16 @@ var Contello = class {
|
|
|
87
88
|
_i18nMessages;
|
|
88
89
|
_i18nSubscription;
|
|
89
90
|
_als = new import_node_async_hooks.AsyncLocalStorage();
|
|
91
|
+
media;
|
|
90
92
|
constructor(options) {
|
|
91
93
|
this._options = options;
|
|
92
|
-
|
|
94
|
+
this._store = (0, import_store.createStore)(options);
|
|
95
|
+
this.media = {
|
|
93
96
|
baseUrl: options.media?.baseUrl ?? "",
|
|
94
97
|
imagesPath: options.media?.imagesPath ?? DEFAULT_IMAGES_PREFIX,
|
|
95
98
|
videosPath: options.media?.videosPath ?? DEFAULT_VIDEO_PREFIX,
|
|
96
|
-
filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX
|
|
97
|
-
...options.media?.fallback !== void 0 ? { fallback: options.media.fallback } : {},
|
|
98
|
-
...options.media?.breakpoints !== void 0 ? { breakpoints: options.media.breakpoints } : {},
|
|
99
|
-
...options.media?.pictureFormats !== void 0 ? { pictureFormats: options.media.pictureFormats } : {}
|
|
99
|
+
filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX
|
|
100
100
|
};
|
|
101
|
-
this._store = (0, import_store.createStore)({ ...options, media: mediaOptions });
|
|
102
101
|
}
|
|
103
102
|
// --- lifecycle ---
|
|
104
103
|
async init(options) {
|
|
@@ -159,9 +158,6 @@ var Contello = class {
|
|
|
159
158
|
}
|
|
160
159
|
return this._i18nMessages;
|
|
161
160
|
}
|
|
162
|
-
get media() {
|
|
163
|
-
return this._store.media;
|
|
164
|
-
}
|
|
165
161
|
// --- ALS request context ---
|
|
166
162
|
get request() {
|
|
167
163
|
const ctx = this._als.getStore();
|
|
@@ -170,6 +166,13 @@ var Contello = class {
|
|
|
170
166
|
}
|
|
171
167
|
return ctx;
|
|
172
168
|
}
|
|
169
|
+
// --- media resolvers (on-demand) ---
|
|
170
|
+
defineMediaResolver(options) {
|
|
171
|
+
return (0, import_media.createMediaResolver)({
|
|
172
|
+
...this.media,
|
|
173
|
+
...options
|
|
174
|
+
});
|
|
175
|
+
}
|
|
173
176
|
// --- store delegation ---
|
|
174
177
|
defineSingleton(def) {
|
|
175
178
|
return this._store.defineSingleton(def);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationMap } from '@contello/client';
|
|
2
|
-
import { MediaResolverOptions, MediaResolver } from '@contello/media';
|
|
2
|
+
import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
|
|
3
3
|
import { CreateStoreOptions, AssetCollectionOptions, RouteCollectionOptions, Loadable, Assets, Routes, I18nMessages, StoreRoute, SingletonDef, Singleton, SingletonSyncDef, SingletonSync, CollectionDef, Collection, CollectionSyncDef, CollectionSync, LazyCollectionDef, LazyCollection } from '@contello/store';
|
|
4
4
|
import * as astro from 'astro';
|
|
5
5
|
import { ExcludePattern } from '@astroscope/excludes';
|
|
@@ -20,13 +20,21 @@ type ContelloInitOptions = {
|
|
|
20
20
|
load?: boolean | undefined;
|
|
21
21
|
} | undefined;
|
|
22
22
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
23
|
+
type ContelloMediaConfig = {
|
|
24
|
+
readonly baseUrl: string;
|
|
25
|
+
readonly imagesPath: string;
|
|
26
|
+
readonly videosPath: string;
|
|
27
|
+
readonly filesPath: string;
|
|
28
|
+
};
|
|
29
|
+
type ContelloOptions<TOps extends OperationMap | undefined = undefined, TModels extends string = string> = CreateStoreOptions<TOps, TModels> & {
|
|
25
30
|
assets?: AssetCollectionOptions | undefined;
|
|
26
31
|
i18n?: ContelloI18nOptions | undefined;
|
|
27
32
|
routes?: RouteCollectionOptions | undefined;
|
|
28
|
-
media?:
|
|
33
|
+
media?: Partial<ContelloMediaConfig> | undefined;
|
|
29
34
|
};
|
|
35
|
+
type HasFallback<O> = O extends {
|
|
36
|
+
fallback: ImageDef;
|
|
37
|
+
} ? true : false;
|
|
30
38
|
declare const runRequest: unique symbol;
|
|
31
39
|
declare class Contello<TOps extends OperationMap | undefined = undefined, TModels extends string = string> {
|
|
32
40
|
private readonly _store;
|
|
@@ -36,6 +44,7 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
|
|
|
36
44
|
private _i18nMessages;
|
|
37
45
|
private _i18nSubscription;
|
|
38
46
|
private readonly _als;
|
|
47
|
+
readonly media: ContelloMediaConfig;
|
|
39
48
|
constructor(options: ContelloOptions<TOps, TModels>);
|
|
40
49
|
init(options?: ContelloInitOptions | undefined): Promise<void>;
|
|
41
50
|
destroy(): Promise<void>;
|
|
@@ -44,8 +53,8 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
|
|
|
44
53
|
get assets(): Assets;
|
|
45
54
|
get routes(): Routes;
|
|
46
55
|
get i18nMessages(): I18nMessages;
|
|
47
|
-
get media(): MediaResolver;
|
|
48
56
|
get request(): ContelloRequestContext;
|
|
57
|
+
defineMediaResolver<O extends Partial<MediaResolverOptions>>(options?: O): MediaResolver<HasFallback<O>>;
|
|
49
58
|
defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
|
|
50
59
|
defineSingletonSync<TModel extends TModels, TRaw, TMapped>(def: SingletonSyncDef<TOps, TModel, TRaw, TMapped, TModels>): SingletonSync<TMapped>;
|
|
51
60
|
defineCollection<TModel extends TModels, TRaw, TMapped extends {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationMap } from '@contello/client';
|
|
2
|
-
import { MediaResolverOptions, MediaResolver } from '@contello/media';
|
|
2
|
+
import { MediaResolverOptions, MediaResolver, ImageDef } from '@contello/media';
|
|
3
3
|
import { CreateStoreOptions, AssetCollectionOptions, RouteCollectionOptions, Loadable, Assets, Routes, I18nMessages, StoreRoute, SingletonDef, Singleton, SingletonSyncDef, SingletonSync, CollectionDef, Collection, CollectionSyncDef, CollectionSync, LazyCollectionDef, LazyCollection } from '@contello/store';
|
|
4
4
|
import * as astro from 'astro';
|
|
5
5
|
import { ExcludePattern } from '@astroscope/excludes';
|
|
@@ -20,13 +20,21 @@ type ContelloInitOptions = {
|
|
|
20
20
|
load?: boolean | undefined;
|
|
21
21
|
} | undefined;
|
|
22
22
|
};
|
|
23
|
-
type
|
|
24
|
-
|
|
23
|
+
type ContelloMediaConfig = {
|
|
24
|
+
readonly baseUrl: string;
|
|
25
|
+
readonly imagesPath: string;
|
|
26
|
+
readonly videosPath: string;
|
|
27
|
+
readonly filesPath: string;
|
|
28
|
+
};
|
|
29
|
+
type ContelloOptions<TOps extends OperationMap | undefined = undefined, TModels extends string = string> = CreateStoreOptions<TOps, TModels> & {
|
|
25
30
|
assets?: AssetCollectionOptions | undefined;
|
|
26
31
|
i18n?: ContelloI18nOptions | undefined;
|
|
27
32
|
routes?: RouteCollectionOptions | undefined;
|
|
28
|
-
media?:
|
|
33
|
+
media?: Partial<ContelloMediaConfig> | undefined;
|
|
29
34
|
};
|
|
35
|
+
type HasFallback<O> = O extends {
|
|
36
|
+
fallback: ImageDef;
|
|
37
|
+
} ? true : false;
|
|
30
38
|
declare const runRequest: unique symbol;
|
|
31
39
|
declare class Contello<TOps extends OperationMap | undefined = undefined, TModels extends string = string> {
|
|
32
40
|
private readonly _store;
|
|
@@ -36,6 +44,7 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
|
|
|
36
44
|
private _i18nMessages;
|
|
37
45
|
private _i18nSubscription;
|
|
38
46
|
private readonly _als;
|
|
47
|
+
readonly media: ContelloMediaConfig;
|
|
39
48
|
constructor(options: ContelloOptions<TOps, TModels>);
|
|
40
49
|
init(options?: ContelloInitOptions | undefined): Promise<void>;
|
|
41
50
|
destroy(): Promise<void>;
|
|
@@ -44,8 +53,8 @@ declare class Contello<TOps extends OperationMap | undefined = undefined, TModel
|
|
|
44
53
|
get assets(): Assets;
|
|
45
54
|
get routes(): Routes;
|
|
46
55
|
get i18nMessages(): I18nMessages;
|
|
47
|
-
get media(): MediaResolver;
|
|
48
56
|
get request(): ContelloRequestContext;
|
|
57
|
+
defineMediaResolver<O extends Partial<MediaResolverOptions>>(options?: O): MediaResolver<HasFallback<O>>;
|
|
49
58
|
defineSingleton<TModel extends TModels, TRaw, TMapped>(def: SingletonDef<TOps, TModel, TRaw, TMapped, TModels>): Singleton<TMapped>;
|
|
50
59
|
defineSingletonSync<TModel extends TModels, TRaw, TMapped>(def: SingletonSyncDef<TOps, TModel, TRaw, TMapped, TModels>): SingletonSync<TMapped>;
|
|
51
60
|
defineCollection<TModel extends TModels, TRaw, TMapped extends {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/contello.ts
|
|
2
2
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
import { i18n } from "@astroscope/i18n";
|
|
4
|
+
import { createMediaResolver } from "@contello/media";
|
|
4
5
|
import {
|
|
5
6
|
createStore
|
|
6
7
|
} from "@contello/store";
|
|
@@ -50,18 +51,16 @@ var Contello = class {
|
|
|
50
51
|
_i18nMessages;
|
|
51
52
|
_i18nSubscription;
|
|
52
53
|
_als = new AsyncLocalStorage();
|
|
54
|
+
media;
|
|
53
55
|
constructor(options) {
|
|
54
56
|
this._options = options;
|
|
55
|
-
|
|
57
|
+
this._store = createStore(options);
|
|
58
|
+
this.media = {
|
|
56
59
|
baseUrl: options.media?.baseUrl ?? "",
|
|
57
60
|
imagesPath: options.media?.imagesPath ?? DEFAULT_IMAGES_PREFIX,
|
|
58
61
|
videosPath: options.media?.videosPath ?? DEFAULT_VIDEO_PREFIX,
|
|
59
|
-
filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX
|
|
60
|
-
...options.media?.fallback !== void 0 ? { fallback: options.media.fallback } : {},
|
|
61
|
-
...options.media?.breakpoints !== void 0 ? { breakpoints: options.media.breakpoints } : {},
|
|
62
|
-
...options.media?.pictureFormats !== void 0 ? { pictureFormats: options.media.pictureFormats } : {}
|
|
62
|
+
filesPath: options.media?.filesPath ?? DEFAULT_FILES_PREFIX
|
|
63
63
|
};
|
|
64
|
-
this._store = createStore({ ...options, media: mediaOptions });
|
|
65
64
|
}
|
|
66
65
|
// --- lifecycle ---
|
|
67
66
|
async init(options) {
|
|
@@ -122,9 +121,6 @@ var Contello = class {
|
|
|
122
121
|
}
|
|
123
122
|
return this._i18nMessages;
|
|
124
123
|
}
|
|
125
|
-
get media() {
|
|
126
|
-
return this._store.media;
|
|
127
|
-
}
|
|
128
124
|
// --- ALS request context ---
|
|
129
125
|
get request() {
|
|
130
126
|
const ctx = this._als.getStore();
|
|
@@ -133,6 +129,13 @@ var Contello = class {
|
|
|
133
129
|
}
|
|
134
130
|
return ctx;
|
|
135
131
|
}
|
|
132
|
+
// --- media resolvers (on-demand) ---
|
|
133
|
+
defineMediaResolver(options) {
|
|
134
|
+
return createMediaResolver({
|
|
135
|
+
...this.media,
|
|
136
|
+
...options
|
|
137
|
+
});
|
|
138
|
+
}
|
|
136
139
|
// --- store delegation ---
|
|
137
140
|
defineSingleton(def) {
|
|
138
141
|
return this._store.defineSingleton(def);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contello/astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Astro integration for Contello CMS — route middleware and i18n bridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"astro": "^6.0.0",
|
|
17
17
|
"@contello/client": "^1.1.0",
|
|
18
18
|
"@contello/media": "^1.0.0",
|
|
19
|
-
"@contello/store": "^1.
|
|
19
|
+
"@contello/store": "^1.5.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependenciesMeta": {
|
|
22
22
|
"@astroscope/i18n": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"astro": "^6.1.8",
|
|
30
30
|
"@contello/client": "^1.1.0",
|
|
31
31
|
"@contello/media": "^1.0.0",
|
|
32
|
-
"@contello/store": "^1.
|
|
32
|
+
"@contello/store": "^1.5.0"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|