storyloco 2.3.0 → 2.3.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/README.md
CHANGED
|
@@ -186,8 +186,8 @@ const links = await storyblok.links({ starts_with: 'blog/' })
|
|
|
186
186
|
Reads with a `content_type` are typed from your generated schema: the plugin registers
|
|
187
187
|
the space's content types with storyloco, so `stories({ content_type: 'product' })` yields
|
|
188
188
|
product stories and `content_type: 'product,category'` a union of both — no type argument
|
|
189
|
-
needed. Until a schema has been generated,
|
|
190
|
-
|
|
189
|
+
needed, and unknown names are rejected. Until a schema has been generated, any name is
|
|
190
|
+
accepted and the content is the SDK's permissive type. An explicit type argument always wins.
|
|
191
191
|
|
|
192
192
|
Your params are spread last, so any default can be overridden:
|
|
193
193
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ISbStoriesParams, ISbStoryParams } from "@storyblok/svelte";
|
|
2
2
|
import type { ISbLink, ISbLinksParams } from "storyblok-js-client";
|
|
3
|
-
import { type ContentFor, type Story, type StoryblokClient, type Version } from "./storyblok.svelte.js";
|
|
3
|
+
import { type ContentFor, type ContentTypeParam, type Story, type StoryblokClient, type Version } from "./storyblok.svelte.js";
|
|
4
4
|
/** The content version for the current request, as set by the `version` hook. */
|
|
5
5
|
export declare function version(): Version;
|
|
6
6
|
/**
|
|
@@ -39,7 +39,7 @@ export declare function setup(client: StoryblokClient): (() => {
|
|
|
39
39
|
[index: string]: any;
|
|
40
40
|
}>(slug: string, params?: ISbStoryParams) => Promise<Story<T> | null>;
|
|
41
41
|
stories: {
|
|
42
|
-
<K extends
|
|
42
|
+
<K extends ContentTypeParam>(params: ISbStoriesParams & {
|
|
43
43
|
content_type: K;
|
|
44
44
|
}): Promise<{
|
|
45
45
|
stories: Story<ContentFor<K>>[];
|
|
@@ -47,18 +47,22 @@ export declare function setup(client: StoryblokClient): (() => {
|
|
|
47
47
|
}>;
|
|
48
48
|
<T = import("storyblok-js-client").ISbComponentType<string> & {
|
|
49
49
|
[index: string]: any;
|
|
50
|
-
}>(params?: ISbStoriesParams
|
|
50
|
+
}>(params?: Omit<ISbStoriesParams, "content_type"> & {
|
|
51
|
+
content_type?: ContentTypeParam;
|
|
52
|
+
}): Promise<{
|
|
51
53
|
stories: Story<T>[];
|
|
52
54
|
total: number;
|
|
53
55
|
}>;
|
|
54
56
|
};
|
|
55
57
|
all: {
|
|
56
|
-
<K extends
|
|
58
|
+
<K extends ContentTypeParam>(params: ISbStoriesParams & {
|
|
57
59
|
content_type: K;
|
|
58
60
|
}): Promise<Array<Story<ContentFor<K>>>>;
|
|
59
61
|
<T = import("storyblok-js-client").ISbComponentType<string> & {
|
|
60
62
|
[index: string]: any;
|
|
61
|
-
}>(params?: ISbStoriesParams
|
|
63
|
+
}>(params?: Omit<ISbStoriesParams, "content_type"> & {
|
|
64
|
+
content_type?: ContentTypeParam;
|
|
65
|
+
}): Promise<Array<Story<T>>>;
|
|
62
66
|
};
|
|
63
67
|
/**
|
|
64
68
|
* The link tree as a flat array — Storyblok returns it keyed by uuid, which is
|
|
@@ -152,11 +152,18 @@ export interface Registry {
|
|
|
152
152
|
export type Content = ISbStoryData["content"];
|
|
153
153
|
/** Each name in a comma-separated `content_type`. */
|
|
154
154
|
type Names<S extends string> = S extends `${infer A},${infer B}` ? A | Names<B> : S;
|
|
155
|
+
/** Registered content type names; `never` until a schema has been generated. */
|
|
156
|
+
export type Known = keyof Registry & string;
|
|
157
|
+
/**
|
|
158
|
+
* What a `content_type` param accepts: any string until a schema registers names, then a
|
|
159
|
+
* registered name (autocompleted) or a comma-separated list starting with one.
|
|
160
|
+
*/
|
|
161
|
+
export type ContentTypeParam = [Known] extends [never] ? string : Known | `${Known},${string}`;
|
|
155
162
|
/**
|
|
156
163
|
* The content behind a `content_type` param. Registered names map to their generated
|
|
157
164
|
* types (a list to their union); anything else is the permissive `Content`.
|
|
158
165
|
*/
|
|
159
|
-
export type ContentFor<K extends string> = [Names<K>] extends [
|
|
166
|
+
export type ContentFor<K extends string> = [Names<K>] extends [Known] ? Registry[Names<K>] : Content;
|
|
160
167
|
/**
|
|
161
168
|
* A story per member of `T`, so a union of content types is a union of stories —
|
|
162
169
|
* `Story<Product | Category>` is `ISbStoryData<Product> | ISbStoryData<Category>`, which
|