@okam/directus-next 1.2.10 → 1.2.12
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/CHANGELOG.md +50 -0
- package/ErrorIcon-DM65zoku.mjs +14 -0
- package/ErrorIcon-Vnk7YKtL.js +14 -0
- package/draft/route.d.ts +21 -16
- package/index.d.ts +0 -1
- package/index.js +113 -88
- package/index.mjs +96 -88
- package/package.json +6 -5
- package/pageSettings/context.d.ts +3 -2
- package/pageSettings/{usePageSettings.d.ts → getPageSettings.d.ts} +7 -2
- package/pageSettings/index.d.ts +2 -2
- package/pageSettings/interface.d.ts +9 -52
- package/redirect/utils/getRedirectsRoute.d.ts +3 -3
- package/redirect/utils/handleRedirect.d.ts +2 -2
- package/router/router.d.ts +4 -4
- package/router/utils/fetchPageSettingsTranslation.d.ts +2 -2
- package/router/utils/locale.d.ts +3 -3
- package/server.d.ts +1 -1
- package/server.js +2562 -12
- package/server.mjs +2567 -17
- package/types/Fragments.d.ts +5 -0
- package/types/directusRouteConfig.d.ts +3 -3
- package/types/index.d.ts +2 -2
- package/types/pageSettings.d.ts +39 -11
|
@@ -1,60 +1,17 @@
|
|
|
1
1
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { Nullable } from '../../../../stack/stack-ui/src/index.ts';
|
|
2
3
|
import { Variables } from 'graphql-request';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { TDirectusRouteConfig } from '../types/directusRouteConfig';
|
|
5
|
+
import { Fragmentize } from '../types/Fragments';
|
|
6
|
+
import { TPageSettings, TPageSettingsItemQuery, TPageSettingsQueryItem } from '../types/pageSettings';
|
|
5
7
|
|
|
6
|
-
export type Fragmentize<FragmentData, FragmentName extends string = string> = {
|
|
7
|
-
' $fragmentRefs'?: {
|
|
8
|
-
[FragmentKey in FragmentName]?: FragmentData | null | undefined;
|
|
9
|
-
} | null | undefined;
|
|
10
|
-
} | null | undefined;
|
|
11
|
-
export type MaybeArray<T> = T | (T | null | undefined)[] | null | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* Directus page settings translations collection.
|
|
14
|
-
*/
|
|
15
|
-
export type TPageSettingsTranslation = {
|
|
16
|
-
slug?: string | null;
|
|
17
|
-
title?: string | null;
|
|
18
|
-
path?: string | null;
|
|
19
|
-
languages_code?: {
|
|
20
|
-
code: string;
|
|
21
|
-
} | null;
|
|
22
|
-
page_settings_id?: TPageSettings | null;
|
|
23
|
-
canonical_url?: string | null;
|
|
24
|
-
meta_description?: string | null;
|
|
25
|
-
no_follow?: boolean | null;
|
|
26
|
-
no_index?: boolean | null;
|
|
27
|
-
og_image?: TFiles | null;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Directus page settings collection.
|
|
31
|
-
*/
|
|
32
|
-
export type TPageSettings = {
|
|
33
|
-
id: string;
|
|
34
|
-
belongs_to_collection?: string | null;
|
|
35
|
-
belongs_to_key?: string | null;
|
|
36
|
-
translations?: Array<TPageSettingsTranslation | null> | null;
|
|
37
|
-
route?: {
|
|
38
|
-
translations?: Array<{
|
|
39
|
-
route?: string | null;
|
|
40
|
-
} | null> | null;
|
|
41
|
-
} | null;
|
|
42
|
-
};
|
|
43
|
-
export type TPageSettingsQueryItem = {
|
|
44
|
-
page_settings?: TPageSettings | Fragmentize<TPageSettings, 'PageSettingsFragment'> | null | undefined;
|
|
45
|
-
} | null | undefined;
|
|
46
|
-
export type TPageSettingsItemQuery<Item extends TPageSettingsQueryItem, ItemKey extends string> = {
|
|
47
|
-
__typename?: 'Query';
|
|
48
|
-
} & {
|
|
49
|
-
[Key in ItemKey]?: MaybeArray<Item> | MaybeArray<Fragmentize<Item>>;
|
|
50
|
-
};
|
|
51
8
|
export type TPageSettingsItemDocument<Item extends TPageSettingsQueryItem, ItemKey extends string, QueryVariables extends Variables> = TypedDocumentNode<TPageSettingsItemQuery<Item, ItemKey>, QueryVariables>;
|
|
52
|
-
export type
|
|
9
|
+
export type TGetPageSettingsConfig = TDirectusRouteConfig | Record<string, string>;
|
|
53
10
|
/**
|
|
54
11
|
* If not using a fragment in the item key, all type parameters must be passed. Otherwise, only the `page_settings` field will be in the type definition.
|
|
55
12
|
* If using a fragment in the item key, the return type will contain the fragment.
|
|
56
13
|
*/
|
|
57
|
-
export interface
|
|
14
|
+
export interface TGetPageSettingsProps<Item extends TPageSettingsQueryItem, ItemKey extends string, QueryVariables extends Variables> {
|
|
58
15
|
document: TPageSettingsItemDocument<Item, ItemKey, QueryVariables>;
|
|
59
16
|
/**
|
|
60
17
|
* `variables.locale` is a special value that will get mapped according to the config.
|
|
@@ -63,8 +20,8 @@ export interface TUsePageSettingsProps<Item extends TPageSettingsQueryItem, Item
|
|
|
63
20
|
/**
|
|
64
21
|
* Either a directus route config or directly a locale map. Not passing a config while passing a document will result in direct usage of the `locale` variable.
|
|
65
22
|
*/
|
|
66
|
-
config?:
|
|
23
|
+
config?: TGetPageSettingsConfig;
|
|
67
24
|
}
|
|
68
|
-
export type
|
|
69
|
-
page_settings?: Exclude<NonNullable<Item>['page_settings'], Fragmentize<TPageSettings, 'PageSettingsFragment'
|
|
25
|
+
export type TGetPageSettingsReturn<Item extends TPageSettingsQueryItem> = Omit<Item, 'page_settings'> & {
|
|
26
|
+
page_settings?: Nullable<Exclude<NonNullable<Item>['page_settings'], Fragmentize<TPageSettings, 'PageSettingsFragment'>>>;
|
|
70
27
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TFetchRedirectsResponse } from '../../../../directus-node/src/edge.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { TDirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Gets a response from `options.apiRoute`
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {TDirectusRouteRedirectsModule} options
|
|
7
7
|
* @returns {Promise<TFetchRedirectsResponse>}
|
|
8
8
|
*/
|
|
9
|
-
export declare function getRedirectsRoute({ apiRoute, getApiRouteUrl, getRedirectSecret, }?:
|
|
9
|
+
export declare function getRedirectsRoute({ apiRoute, getApiRouteUrl, getRedirectSecret, }?: TDirectusRouteRedirectsModule): Promise<TFetchRedirectsResponse>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { TDirectusRouteRedirectsModule } from '../../types/directusRouteConfig';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Handles next redirection using directus redirects
|
|
6
6
|
*/
|
|
7
|
-
export declare function handleRedirect(request: NextRequest, options?:
|
|
7
|
+
export declare function handleRedirect(request: NextRequest, options?: TDirectusRouteRedirectsModule): Promise<NextResponse<unknown> | null>;
|
package/router/router.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { NextRequest, NextResponse as NextResponseType } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { TDirectusRouteConfig } from '../types/directusRouteConfig';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Handles incoming middleware requests and rewrites the path to the new format according to fetched page settings.
|
|
6
6
|
* @param request - The NextRequest object
|
|
7
|
-
* @param config - The
|
|
7
|
+
* @param config - The TDirectusRouteConfig object
|
|
8
8
|
* @deprecated Use `directusRouteRouter(request, config)` instead. NextResponse is now directly imported in this file.
|
|
9
9
|
* @param NextResponse - The NextResponse object
|
|
10
10
|
* @returns NextResponse
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
14
|
-
* export const directusConfig:
|
|
14
|
+
* export const directusConfig: TDirectusRouteConfig = {
|
|
15
15
|
* localeMap: {
|
|
16
16
|
* 'fr-CA': 'fr',
|
|
17
17
|
* 'en-CA': 'en',
|
|
@@ -28,7 +28,7 @@ import { DirectusRouteConfig } from '../types/directusRouteConfig';
|
|
|
28
28
|
* }
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export declare function directusRouteRouter(request: NextRequest, config:
|
|
31
|
+
export declare function directusRouteRouter(request: NextRequest, config: TDirectusRouteConfig,
|
|
32
32
|
/**
|
|
33
33
|
* @deprecated Use `directusRouteRouter(request, config)` instead. NextResponse is now directly imported in this file.
|
|
34
34
|
*/
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TPageSettingsTranslation } from '../../types';
|
|
2
2
|
|
|
3
|
-
export declare function fetchPageSettingsTranslation(path: string): Promise<
|
|
3
|
+
export declare function fetchPageSettingsTranslation(path: string): Promise<TPageSettingsTranslation[] | null>;
|
package/router/utils/locale.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TDirectusRouteConfig } from '../../types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Validates if a given string is a valid locale from the directus route configuration.
|
|
@@ -6,14 +6,14 @@ import { DirectusRouteConfig } from '../../types';
|
|
|
6
6
|
* @param config The Directus route configuration containing the locale map
|
|
7
7
|
* @returns The validated locale string, or undefined if invalid
|
|
8
8
|
*/
|
|
9
|
-
export declare function getValidLocale(maybeLocale: string | null | undefined, config:
|
|
9
|
+
export declare function getValidLocale(maybeLocale: string | null | undefined, config: TDirectusRouteConfig): string | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Splits the locale from the pathname and returns the locale and the pathname without the locale.
|
|
12
12
|
* @param pathname The pathname to split the locale from
|
|
13
13
|
* @param config The Directus route configuration containing the locale map
|
|
14
14
|
* @returns The locale and the pathname without the locale
|
|
15
15
|
*/
|
|
16
|
-
export declare function splitLocaleFromPathname(pathname: string, config:
|
|
16
|
+
export declare function splitLocaleFromPathname(pathname: string, config: TDirectusRouteConfig): {
|
|
17
17
|
locale: string;
|
|
18
18
|
pathname: string;
|
|
19
19
|
} | {
|
package/server.d.ts
CHANGED