Rename extention types
This commit is contained in:
@ -4,20 +4,20 @@ import { assert } from "tsafe/assert";
|
|||||||
import type { Equals } from "tsafe";
|
import type { Equals } from "tsafe";
|
||||||
|
|
||||||
export type ExtendKcContext<
|
export type ExtendKcContext<
|
||||||
KcContextExtraProperties extends { properties?: Record<string, string | undefined> },
|
KcContextExtension extends { properties?: Record<string, string | undefined> },
|
||||||
KcContextExtraPropertiesPerPage extends Record<string, Record<string, unknown>>
|
KcContextExtensionPerPage extends Record<string, Record<string, unknown>>
|
||||||
> = ValueOf<{
|
> = ValueOf<{
|
||||||
[PageId in keyof KcContextExtraPropertiesPerPage | KcContext["pageId"]]: Extract<
|
[PageId in keyof KcContextExtensionPerPage | KcContext["pageId"]]: Extract<
|
||||||
KcContext,
|
KcContext,
|
||||||
{ pageId: PageId }
|
{ pageId: PageId }
|
||||||
> extends never
|
> extends never
|
||||||
? KcContext.Common &
|
? KcContext.Common &
|
||||||
KcContextExtraProperties & {
|
KcContextExtension & {
|
||||||
pageId: PageId;
|
pageId: PageId;
|
||||||
} & KcContextExtraPropertiesPerPage[PageId]
|
} & KcContextExtensionPerPage[PageId]
|
||||||
: Extract<KcContext, { pageId: PageId }> &
|
: Extract<KcContext, { pageId: PageId }> &
|
||||||
KcContextExtraProperties &
|
KcContextExtension &
|
||||||
KcContextExtraPropertiesPerPage[PageId];
|
KcContextExtensionPerPage[PageId];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type KcContext =
|
export type KcContext =
|
||||||
|
@ -7,43 +7,32 @@ import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
|||||||
import { exclude } from "tsafe/exclude";
|
import { exclude } from "tsafe/exclude";
|
||||||
|
|
||||||
export function createGetKcContextMock<
|
export function createGetKcContextMock<
|
||||||
KcContextExtraProperties extends { properties?: Record<string, string | undefined> },
|
KcContextExtension extends { properties?: Record<string, string | undefined> },
|
||||||
KcContextExtraPropertiesPerPage extends Record<
|
KcContextExtensionPerPage extends Record<`${string}.ftl`, Record<string, unknown>>
|
||||||
`${string}.ftl`,
|
|
||||||
Record<string, unknown>
|
|
||||||
>
|
|
||||||
>(params: {
|
>(params: {
|
||||||
kcContextExtraProperties: KcContextExtraProperties;
|
kcContextExtension: KcContextExtension;
|
||||||
kcContextExtraPropertiesPerPage: KcContextExtraPropertiesPerPage;
|
kcContextExtensionPerPage: KcContextExtensionPerPage;
|
||||||
overrides?: DeepPartial<KcContextExtraProperties & KcContextBase.Common>;
|
overrides?: DeepPartial<KcContextExtension & KcContextBase.Common>;
|
||||||
overridesPerPage?: {
|
overridesPerPage?: {
|
||||||
[PageId in
|
[PageId in AccountThemePageId | keyof KcContextExtensionPerPage]?: DeepPartial<
|
||||||
| AccountThemePageId
|
|
||||||
| keyof KcContextExtraPropertiesPerPage]?: DeepPartial<
|
|
||||||
Extract<
|
Extract<
|
||||||
ExtendKcContext<
|
ExtendKcContext<KcContextExtension, KcContextExtensionPerPage>,
|
||||||
KcContextExtraProperties,
|
|
||||||
KcContextExtraPropertiesPerPage
|
|
||||||
>,
|
|
||||||
{ pageId: PageId }
|
{ pageId: PageId }
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
kcContextExtraProperties,
|
kcContextExtension,
|
||||||
kcContextExtraPropertiesPerPage,
|
kcContextExtensionPerPage,
|
||||||
overrides: overrides_global,
|
overrides: overrides_global,
|
||||||
overridesPerPage: overridesPerPage_global
|
overridesPerPage: overridesPerPage_global
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
type KcContext = ExtendKcContext<
|
type KcContext = ExtendKcContext<KcContextExtension, KcContextExtensionPerPage>;
|
||||||
KcContextExtraProperties,
|
|
||||||
KcContextExtraPropertiesPerPage
|
|
||||||
>;
|
|
||||||
|
|
||||||
function getKcContextMock<
|
function getKcContextMock<
|
||||||
PageId extends AccountThemePageId | keyof KcContextExtraPropertiesPerPage
|
PageId extends AccountThemePageId | keyof KcContextExtensionPerPage
|
||||||
>(params: {
|
>(params: {
|
||||||
pageId: PageId;
|
pageId: PageId;
|
||||||
overrides?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
|
overrides?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
|
||||||
@ -58,8 +47,8 @@ export function createGetKcContextMock<
|
|||||||
);
|
);
|
||||||
|
|
||||||
[
|
[
|
||||||
kcContextExtraProperties,
|
kcContextExtension,
|
||||||
kcContextExtraPropertiesPerPage[pageId],
|
kcContextExtensionPerPage[pageId],
|
||||||
overrides_global,
|
overrides_global,
|
||||||
overridesPerPage_global?.[pageId],
|
overridesPerPage_global?.[pageId],
|
||||||
overrides
|
overrides
|
||||||
|
@ -51,7 +51,7 @@ export async function generateKcGenTs(params: {
|
|||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
2
|
2
|
||||||
)}`,
|
)};`,
|
||||||
``,
|
``,
|
||||||
`/* prettier-ignore-end */`
|
`/* prettier-ignore-end */`
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
|
@ -10,20 +10,20 @@ import type { Equals } from "tsafe";
|
|||||||
import type { MessageKey } from "../i18n/i18n";
|
import type { MessageKey } from "../i18n/i18n";
|
||||||
|
|
||||||
export type ExtendKcContext<
|
export type ExtendKcContext<
|
||||||
KcContextExtraProperties extends { properties?: Record<string, string | undefined> },
|
KcContextExtension extends { properties?: Record<string, string | undefined> },
|
||||||
KcContextExtraPropertiesPerPage extends Record<string, Record<string, unknown>>
|
KcContextExtensionPerPage extends Record<string, Record<string, unknown>>
|
||||||
> = ValueOf<{
|
> = ValueOf<{
|
||||||
[PageId in keyof KcContextExtraPropertiesPerPage | KcContext["pageId"]]: Extract<
|
[PageId in keyof KcContextExtensionPerPage | KcContext["pageId"]]: Extract<
|
||||||
KcContext,
|
KcContext,
|
||||||
{ pageId: PageId }
|
{ pageId: PageId }
|
||||||
> extends never
|
> extends never
|
||||||
? KcContext.Common &
|
? KcContext.Common &
|
||||||
KcContextExtraProperties & {
|
KcContextExtension & {
|
||||||
pageId: PageId;
|
pageId: PageId;
|
||||||
} & KcContextExtraPropertiesPerPage[PageId]
|
} & KcContextExtensionPerPage[PageId]
|
||||||
: Extract<KcContext, { pageId: PageId }> &
|
: Extract<KcContext, { pageId: PageId }> &
|
||||||
KcContextExtraProperties &
|
KcContextExtension &
|
||||||
KcContextExtraPropertiesPerPage[PageId];
|
KcContextExtensionPerPage[PageId];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
/** Take theses type definition with a grain of salt.
|
/** Take theses type definition with a grain of salt.
|
||||||
|
@ -7,43 +7,32 @@ import { kcContextMocks, kcContextCommonMock } from "./kcContextMocks";
|
|||||||
import { exclude } from "tsafe/exclude";
|
import { exclude } from "tsafe/exclude";
|
||||||
|
|
||||||
export function createGetKcContextMock<
|
export function createGetKcContextMock<
|
||||||
KcContextExtraProperties extends { properties?: Record<string, string | undefined> },
|
KcContextExtension extends { properties?: Record<string, string | undefined> },
|
||||||
KcContextExtraPropertiesPerPage extends Record<
|
KcContextExtensionPerPage extends Record<`${string}.ftl`, Record<string, unknown>>
|
||||||
`${string}.ftl`,
|
|
||||||
Record<string, unknown>
|
|
||||||
>
|
|
||||||
>(params: {
|
>(params: {
|
||||||
kcContextExtraProperties: KcContextExtraProperties;
|
kcContextExtension: KcContextExtension;
|
||||||
kcContextExtraPropertiesPerPage: KcContextExtraPropertiesPerPage;
|
kcContextExtensionPerPage: KcContextExtensionPerPage;
|
||||||
overrides?: DeepPartial<KcContextExtraProperties & KcContextBase.Common>;
|
overrides?: DeepPartial<KcContextExtension & KcContextBase.Common>;
|
||||||
overridesPerPage?: {
|
overridesPerPage?: {
|
||||||
[PageId in
|
[PageId in LoginThemePageId | keyof KcContextExtensionPerPage]?: DeepPartial<
|
||||||
| LoginThemePageId
|
|
||||||
| keyof KcContextExtraPropertiesPerPage]?: DeepPartial<
|
|
||||||
Extract<
|
Extract<
|
||||||
ExtendKcContext<
|
ExtendKcContext<KcContextExtension, KcContextExtensionPerPage>,
|
||||||
KcContextExtraProperties,
|
|
||||||
KcContextExtraPropertiesPerPage
|
|
||||||
>,
|
|
||||||
{ pageId: PageId }
|
{ pageId: PageId }
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
kcContextExtraProperties,
|
kcContextExtension,
|
||||||
kcContextExtraPropertiesPerPage,
|
kcContextExtensionPerPage,
|
||||||
overrides: overrides_global,
|
overrides: overrides_global,
|
||||||
overridesPerPage: overridesPerPage_global
|
overridesPerPage: overridesPerPage_global
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
type KcContext = ExtendKcContext<
|
type KcContext = ExtendKcContext<KcContextExtension, KcContextExtensionPerPage>;
|
||||||
KcContextExtraProperties,
|
|
||||||
KcContextExtraPropertiesPerPage
|
|
||||||
>;
|
|
||||||
|
|
||||||
function getKcContextMock<
|
function getKcContextMock<
|
||||||
PageId extends LoginThemePageId | keyof KcContextExtraPropertiesPerPage
|
PageId extends LoginThemePageId | keyof KcContextExtensionPerPage
|
||||||
>(params: {
|
>(params: {
|
||||||
pageId: PageId;
|
pageId: PageId;
|
||||||
overrides?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
|
overrides?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
|
||||||
@ -58,8 +47,8 @@ export function createGetKcContextMock<
|
|||||||
);
|
);
|
||||||
|
|
||||||
[
|
[
|
||||||
kcContextExtraProperties,
|
kcContextExtension,
|
||||||
kcContextExtraPropertiesPerPage[pageId],
|
kcContextExtensionPerPage[pageId],
|
||||||
overrides_global,
|
overrides_global,
|
||||||
overridesPerPage_global?.[pageId],
|
overridesPerPage_global?.[pageId],
|
||||||
overrides
|
overrides
|
||||||
|
Reference in New Issue
Block a user