@jfdevelops/react-layout 0.1.1 → 0.3.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/composable.cjs.map +1 -1
- package/dist/composable.d.cts +3 -1
- package/dist/composable.d.cts.map +1 -1
- package/dist/composable.d.mts +3 -1
- package/dist/composable.d.mts.map +1 -1
- package/dist/composable.mjs.map +1 -1
- package/dist/create-config/define-layout.cjs +144 -0
- package/dist/create-config/define-layout.cjs.map +1 -0
- package/dist/create-config/define-layout.d.cts +106 -0
- package/dist/create-config/define-layout.d.cts.map +1 -0
- package/dist/create-config/define-layout.d.mts +106 -0
- package/dist/create-config/define-layout.d.mts.map +1 -0
- package/dist/create-config/define-layout.mjs +144 -0
- package/dist/create-config/define-layout.mjs.map +1 -0
- package/dist/create-config/get-component.cjs +52 -0
- package/dist/create-config/get-component.cjs.map +1 -0
- package/dist/create-config/get-component.d.cts +62 -0
- package/dist/create-config/get-component.d.cts.map +1 -0
- package/dist/create-config/get-component.d.mts +62 -0
- package/dist/create-config/get-component.d.mts.map +1 -0
- package/dist/create-config/get-component.mjs +51 -0
- package/dist/create-config/get-component.mjs.map +1 -0
- package/dist/create-config/index.d.cts +3 -0
- package/dist/create-config/index.d.mts +3 -0
- package/dist/create-config/types.d.cts +42 -0
- package/dist/create-config/types.d.cts.map +1 -0
- package/dist/create-config/types.d.mts +42 -0
- package/dist/create-config/types.d.mts.map +1 -0
- package/dist/index.cjs +7 -6
- package/dist/index.d.cts +4 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +3 -2
- package/dist/props.d.cts +3 -2
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +3 -2
- package/dist/props.d.mts.map +1 -1
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +23 -3
- package/dist/resource.d.cts.map +1 -1
- package/dist/resource.d.mts +23 -3
- package/dist/resource.d.mts.map +1 -1
- package/dist/resource.mjs.map +1 -1
- package/dist/utils/capitalize.cjs +9 -0
- package/dist/utils/capitalize.cjs.map +1 -0
- package/dist/utils/capitalize.d.cts +7 -0
- package/dist/utils/capitalize.d.cts.map +1 -0
- package/dist/utils/capitalize.d.mts +7 -0
- package/dist/utils/capitalize.d.mts.map +1 -0
- package/dist/utils/capitalize.mjs +8 -0
- package/dist/utils/capitalize.mjs.map +1 -0
- package/dist/utils.cjs +5 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -1
- package/dist/utils.mjs.map +1 -1
- package/dist/validators/base.cjs +41 -0
- package/dist/validators/base.cjs.map +1 -0
- package/dist/validators/base.d.cts +18 -0
- package/dist/validators/base.d.cts.map +1 -0
- package/dist/validators/base.d.mts +18 -0
- package/dist/validators/base.d.mts.map +1 -0
- package/dist/validators/base.mjs +39 -0
- package/dist/validators/base.mjs.map +1 -0
- package/dist/validators/builders.cjs +137 -0
- package/dist/validators/builders.cjs.map +1 -0
- package/dist/validators/builders.d.cts +156 -0
- package/dist/validators/builders.d.cts.map +1 -0
- package/dist/validators/builders.d.mts +156 -0
- package/dist/validators/builders.d.mts.map +1 -0
- package/dist/validators/builders.mjs +136 -0
- package/dist/validators/builders.mjs.map +1 -0
- package/dist/validators/component.cjs +73 -0
- package/dist/validators/component.cjs.map +1 -0
- package/dist/validators/component.d.cts +28 -0
- package/dist/validators/component.d.cts.map +1 -0
- package/dist/validators/component.d.mts +28 -0
- package/dist/validators/component.d.mts.map +1 -0
- package/dist/validators/component.mjs +71 -0
- package/dist/validators/component.mjs.map +1 -0
- package/dist/validators/enum.cjs +27 -0
- package/dist/validators/enum.cjs.map +1 -0
- package/dist/validators/enum.d.cts +14 -0
- package/dist/validators/enum.d.cts.map +1 -0
- package/dist/validators/enum.d.mts +14 -0
- package/dist/validators/enum.d.mts.map +1 -0
- package/dist/validators/enum.mjs +27 -0
- package/dist/validators/enum.mjs.map +1 -0
- package/dist/validators/index.d.cts +10 -0
- package/dist/validators/index.d.mts +10 -0
- package/dist/validators/literal.cjs +25 -0
- package/dist/validators/literal.cjs.map +1 -0
- package/dist/validators/literal.d.cts +14 -0
- package/dist/validators/literal.d.cts.map +1 -0
- package/dist/validators/literal.d.mts +14 -0
- package/dist/validators/literal.d.mts.map +1 -0
- package/dist/validators/literal.mjs +25 -0
- package/dist/validators/literal.mjs.map +1 -0
- package/dist/validators/object.cjs +53 -0
- package/dist/validators/object.cjs.map +1 -0
- package/dist/validators/object.d.cts +14 -0
- package/dist/validators/object.d.cts.map +1 -0
- package/dist/validators/object.d.mts +14 -0
- package/dist/validators/object.d.mts.map +1 -0
- package/dist/validators/object.mjs +53 -0
- package/dist/validators/object.mjs.map +1 -0
- package/dist/validators/primitive.cjs +80 -0
- package/dist/validators/primitive.cjs.map +1 -0
- package/dist/validators/primitive.d.cts +33 -0
- package/dist/validators/primitive.d.cts.map +1 -0
- package/dist/validators/primitive.d.mts +33 -0
- package/dist/validators/primitive.d.mts.map +1 -0
- package/dist/validators/primitive.mjs +78 -0
- package/dist/validators/primitive.mjs.map +1 -0
- package/dist/validators/types.d.cts +71 -0
- package/dist/validators/types.d.cts.map +1 -0
- package/dist/validators/types.d.mts +71 -0
- package/dist/validators/types.d.mts.map +1 -0
- package/dist/validators/union.cjs +27 -0
- package/dist/validators/union.cjs.map +1 -0
- package/dist/validators/union.d.cts +14 -0
- package/dist/validators/union.d.cts.map +1 -0
- package/dist/validators/union.d.mts +14 -0
- package/dist/validators/union.d.mts.map +1 -0
- package/dist/validators/union.mjs +27 -0
- package/dist/validators/union.mjs.map +1 -0
- package/dist/validators/validate-props.cjs +22 -0
- package/dist/validators/validate-props.cjs.map +1 -0
- package/dist/validators/validate-props.d.cts +7 -0
- package/dist/validators/validate-props.d.cts.map +1 -0
- package/dist/validators/validate-props.d.mts +7 -0
- package/dist/validators/validate-props.d.mts.map +1 -0
- package/dist/validators/validate-props.mjs +21 -0
- package/dist/validators/validate-props.mjs.map +1 -0
- package/package.json +63 -59
- package/dist/create-config.cjs +0 -98
- package/dist/create-config.cjs.map +0 -1
- package/dist/create-config.d.cts +0 -67
- package/dist/create-config.d.cts.map +0 -1
- package/dist/create-config.d.mts +0 -67
- package/dist/create-config.d.mts.map +0 -1
- package/dist/create-config.mjs +0 -98
- package/dist/create-config.mjs.map +0 -1
- package/dist/create-value.cjs +0 -417
- package/dist/create-value.cjs.map +0 -1
- package/dist/create-value.d.cts +0 -348
- package/dist/create-value.d.cts.map +0 -1
- package/dist/create-value.d.mts +0 -348
- package/dist/create-value.d.mts.map +0 -1
- package/dist/create-value.mjs +0 -414
- package/dist/create-value.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_utils = require('./utils.cjs');
|
|
3
3
|
const require_composable = require('./composable.cjs');
|
|
4
|
-
const
|
|
4
|
+
const require_builders = require('./validators/builders.cjs');
|
|
5
|
+
const require_validate_props = require('./validators/validate-props.cjs');
|
|
5
6
|
const require_resource = require('./resource.cjs');
|
|
6
|
-
const
|
|
7
|
+
const require_define_layout = require('./create-config/define-layout.cjs');
|
|
7
8
|
|
|
8
9
|
exports.createComposableComponent = require_composable.createComposableComponent;
|
|
9
|
-
exports.createPrimitivePropBuilder =
|
|
10
|
-
exports.createProp =
|
|
11
|
-
exports.defineResourceLayout =
|
|
10
|
+
exports.createPrimitivePropBuilder = require_builders.createPrimitivePropBuilder;
|
|
11
|
+
exports.createProp = require_builders.createProp;
|
|
12
|
+
exports.defineResourceLayout = require_define_layout.defineResourceLayout;
|
|
12
13
|
exports.makeComposable = require_composable.makeComposable;
|
|
13
14
|
exports.normalizeResource = require_resource.normalizeResource;
|
|
14
15
|
exports.normalizeResources = require_resource.normalizeResources;
|
|
15
16
|
exports.pick = require_utils.pick;
|
|
16
17
|
exports.toResourceEnum = require_resource.toResourceEnum;
|
|
17
|
-
exports.validateProps =
|
|
18
|
+
exports.validateProps = require_validate_props.validateProps;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AnyBuiltPropDefinition, ResolveLayoutProps, ResolveProps
|
|
1
|
+
import { AnyBuiltPropDefinition, ResolveLayoutProps, ResolveProps } from "./validators/types.cjs";
|
|
2
|
+
import { createPrimitivePropBuilder, createProp } from "./validators/builders.cjs";
|
|
3
|
+
import { validateProps } from "./validators/validate-props.cjs";
|
|
2
4
|
import { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick } from "./utils.cjs";
|
|
3
5
|
import { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, normalizeResource, normalizeResources, toResourceEnum } from "./resource.cjs";
|
|
4
6
|
import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps } from "./props.cjs";
|
|
5
7
|
import { ComposableComponent, ComposableComponents, ComposableNameContext, ComposableResourceLayout, CreateLayoutComposable, LayoutComposablesFactory, MakeComposable, MakeComposableOptions, createComposableComponent, makeComposable } from "./composable.cjs";
|
|
6
|
-
import { defineResourceLayout } from "./create-config.cjs";
|
|
8
|
+
import { defineResourceLayout } from "./create-config/define-layout.cjs";
|
|
7
9
|
export { type AnyBuiltPropDefinition, type BaseComponent, type ComposableComponent, type ComposableComponents, type ComposableNameContext, type ComposableResourceLayout, type CreateLayoutComposable, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedProps, type InferredInProps, type LayoutComposablesFactory, type LayoutRenderProps, type LayoutResourceKey, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type NormalizeResource, type NormalizeResources, type ResolveLayoutProps, type ResolveProps, type ResourceDefinition, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceTree, type Show, type UnionToIntersection, createComposableComponent, createPrimitivePropBuilder, createProp, defineResourceLayout, makeComposable, normalizeResource, normalizeResources, pick, toResourceEnum, validateProps };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AnyBuiltPropDefinition, ResolveLayoutProps, ResolveProps
|
|
1
|
+
import { AnyBuiltPropDefinition, ResolveLayoutProps, ResolveProps } from "./validators/types.mjs";
|
|
2
|
+
import { createPrimitivePropBuilder, createProp } from "./validators/builders.mjs";
|
|
3
|
+
import { validateProps } from "./validators/validate-props.mjs";
|
|
2
4
|
import { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick } from "./utils.mjs";
|
|
3
5
|
import { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, normalizeResource, normalizeResources, toResourceEnum } from "./resource.mjs";
|
|
4
6
|
import { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps } from "./props.mjs";
|
|
5
7
|
import { ComposableComponent, ComposableComponents, ComposableNameContext, ComposableResourceLayout, CreateLayoutComposable, LayoutComposablesFactory, MakeComposable, MakeComposableOptions, createComposableComponent, makeComposable } from "./composable.mjs";
|
|
6
|
-
import { defineResourceLayout } from "./create-config.mjs";
|
|
8
|
+
import { defineResourceLayout } from "./create-config/define-layout.mjs";
|
|
7
9
|
export { type AnyBuiltPropDefinition, type BaseComponent, type ComposableComponent, type ComposableComponents, type ComposableNameContext, type ComposableResourceLayout, type CreateLayoutComposable, type InPropsDefinition, type InPropsFunction, type InPropsObject, type InPropsOptions, type IncludedProps, type InferredInProps, type LayoutComposablesFactory, type LayoutRenderProps, type LayoutResourceKey, type MakeComposable, type MakeComposableOptions, type MergeIntersection, type NormalizeResource, type NormalizeResources, type ResolveLayoutProps, type ResolveProps, type ResourceDefinition, type ResourceEnum, type ResourceLayoutComponentProps, type ResourceTree, type Show, type UnionToIntersection, createComposableComponent, createPrimitivePropBuilder, createProp, defineResourceLayout, makeComposable, normalizeResource, normalizeResources, pick, toResourceEnum, validateProps };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { pick } from "./utils.mjs";
|
|
2
2
|
import { createComposableComponent, makeComposable } from "./composable.mjs";
|
|
3
|
-
import { createPrimitivePropBuilder, createProp
|
|
3
|
+
import { createPrimitivePropBuilder, createProp } from "./validators/builders.mjs";
|
|
4
|
+
import { validateProps } from "./validators/validate-props.mjs";
|
|
4
5
|
import { normalizeResource, normalizeResources, toResourceEnum } from "./resource.mjs";
|
|
5
|
-
import { defineResourceLayout } from "./create-config.mjs";
|
|
6
|
+
import { defineResourceLayout } from "./create-config/define-layout.mjs";
|
|
6
7
|
|
|
7
8
|
export { createComposableComponent, createPrimitivePropBuilder, createProp, defineResourceLayout, makeComposable, normalizeResource, normalizeResources, pick, toResourceEnum, validateProps };
|
package/dist/props.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnyBuiltPropDefinition,
|
|
1
|
+
import { AnyBuiltPropDefinition, ResolveLayoutProps, ResolveProps } from "./validators/types.cjs";
|
|
2
|
+
import { EnumWrappedProp, LiteralWrappedProp } from "./validators/builders.cjs";
|
|
2
3
|
import { Show } from "./utils.cjs";
|
|
3
4
|
import { ResourceDefinition, ResourceEnum } from "./resource.cjs";
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ type InferredInProps<Resources extends ReadonlyArray<ResourceDefinition>, Option
|
|
|
15
16
|
* A map of props to include in the layout.
|
|
16
17
|
*/
|
|
17
18
|
type IncludedProps<T> = { [_ in keyof T]?: true };
|
|
18
|
-
type LayoutRenderProps<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, IncludeProps extends IncludedProps<InferredInProps<Resources, Options>> = {}, CustomProps extends InPropsObject = {}> = Show<ResolveProps<CustomProps & Pick<InferredInProps<Resources, Options>, keyof IncludeProps & string>>>;
|
|
19
|
+
type LayoutRenderProps<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, IncludeProps extends IncludedProps<InferredInProps<Resources, Options>> = {}, CustomProps extends InPropsObject = {}> = Show<ResolveProps<CustomProps> & ResolveLayoutProps<Pick<InferredInProps<Resources, Options>, keyof IncludeProps & string>>>;
|
|
19
20
|
//#endregion
|
|
20
21
|
export { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps };
|
|
21
22
|
//# sourceMappingURL=props.d.cts.map
|
package/dist/props.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.d.cts","names":[],"sources":["../src/props.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"props.d.cts","names":[],"sources":["../src/props.ts"],"mappings":";;;;;;KAUY,aAAA,GAAgB,MAAM,SAAS,sBAAA;AAAA,KAC/B,cAAA,mBACQ,aAAA,CAAc,kBAAA;EAGhC,IAAA,EAAM,kBAAA,CAAmB,IAAA;EACzB,QAAA,EAAU,eAAA,CAAgB,YAAA,CAAa,SAAA;AAAA;AAAA,KAE7B,eAAA,mBACQ,aAAA,CAAc,kBAAA,2BAEhC,KAAA,EAAO,IAAA,CAAK,cAAA,CAAe,SAAA,EAAW,IAAA,OACnC,aAAA;AAAA,KACO,iBAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,aAAA,GAAgB,eAAA,CAAgB,SAAA;AAAA,KACxB,eAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,KAChC,OAAA,SAAgB,eAAA,CAAgB,SAAA,IAAa,UAAA,CAAW,OAAA,IAAW,OAAA;AAnBN;AACjE;;AADiE,KAuBrD,aAAA,oBACE,CAAC;AAAA,KAEH,iBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,wBACb,aAAA,CAAc,eAAA,CAAgB,SAAA,EAAW,OAAA,6BAC1C,aAAA,SAClB,IAAA,CACF,YAAA,CAAa,WAAA,IACX,kBAAA,CACE,IAAA,CAAK,eAAA,CAAgB,SAAA,EAAW,OAAA,SAAgB,YAAA"}
|
package/dist/props.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnyBuiltPropDefinition,
|
|
1
|
+
import { AnyBuiltPropDefinition, ResolveLayoutProps, ResolveProps } from "./validators/types.mjs";
|
|
2
|
+
import { EnumWrappedProp, LiteralWrappedProp } from "./validators/builders.mjs";
|
|
2
3
|
import { Show } from "./utils.mjs";
|
|
3
4
|
import { ResourceDefinition, ResourceEnum } from "./resource.mjs";
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ type InferredInProps<Resources extends ReadonlyArray<ResourceDefinition>, Option
|
|
|
15
16
|
* A map of props to include in the layout.
|
|
16
17
|
*/
|
|
17
18
|
type IncludedProps<T> = { [_ in keyof T]?: true };
|
|
18
|
-
type LayoutRenderProps<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, IncludeProps extends IncludedProps<InferredInProps<Resources, Options>> = {}, CustomProps extends InPropsObject = {}> = Show<ResolveProps<CustomProps & Pick<InferredInProps<Resources, Options>, keyof IncludeProps & string>>>;
|
|
19
|
+
type LayoutRenderProps<Resources extends ReadonlyArray<ResourceDefinition>, Options extends InPropsDefinition<Resources>, IncludeProps extends IncludedProps<InferredInProps<Resources, Options>> = {}, CustomProps extends InPropsObject = {}> = Show<ResolveProps<CustomProps> & ResolveLayoutProps<Pick<InferredInProps<Resources, Options>, keyof IncludeProps & string>>>;
|
|
19
20
|
//#endregion
|
|
20
21
|
export { InPropsDefinition, InPropsFunction, InPropsObject, InPropsOptions, IncludedProps, InferredInProps, LayoutRenderProps };
|
|
21
22
|
//# sourceMappingURL=props.d.mts.map
|
package/dist/props.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.d.mts","names":[],"sources":["../src/props.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"props.d.mts","names":[],"sources":["../src/props.ts"],"mappings":";;;;;;KAUY,aAAA,GAAgB,MAAM,SAAS,sBAAA;AAAA,KAC/B,cAAA,mBACQ,aAAA,CAAc,kBAAA;EAGhC,IAAA,EAAM,kBAAA,CAAmB,IAAA;EACzB,QAAA,EAAU,eAAA,CAAgB,YAAA,CAAa,SAAA;AAAA;AAAA,KAE7B,eAAA,mBACQ,aAAA,CAAc,kBAAA,2BAEhC,KAAA,EAAO,IAAA,CAAK,cAAA,CAAe,SAAA,EAAW,IAAA,OACnC,aAAA;AAAA,KACO,iBAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,aAAA,GAAgB,eAAA,CAAgB,SAAA;AAAA,KACxB,eAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,KAChC,OAAA,SAAgB,eAAA,CAAgB,SAAA,IAAa,UAAA,CAAW,OAAA,IAAW,OAAA;AAnBN;AACjE;;AADiE,KAuBrD,aAAA,oBACE,CAAC;AAAA,KAEH,iBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,iBAAA,CAAkB,SAAA,wBACb,aAAA,CAAc,eAAA,CAAgB,SAAA,EAAW,OAAA,6BAC1C,aAAA,SAClB,IAAA,CACF,YAAA,CAAa,WAAA,IACX,kBAAA,CACE,IAAA,CAAK,eAAA,CAAgB,SAAA,EAAW,OAAA,SAAgB,YAAA"}
|
package/dist/resource.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.cjs","names":[],"sources":["../src/resource.ts"],"sourcesContent":["import { ReactNode } from 'react';\
|
|
1
|
+
{"version":3,"file":"resource.cjs","names":[],"sources":["../src/resource.ts"],"sourcesContent":["import { ReactNode } from 'react';\nimport { NonEmptyReadonlyArray } from './validators';\nimport { MergeIntersection, UnionToIntersection } from './utils';\n\nexport type ResourceDefinition =\n | string\n | {\n value: string;\n subResources: ReadonlyArray<\n ResourceDefinition & {\n /**\n * Whether to allow any string as a sub resource.\n *\n * @default false\n */\n allowAnyString?: boolean;\n }\n >;\n };\n\nexport type ResourceTree = Record<\n string,\n {\n subResources: ResourceTree;\n }\n>;\n\nexport type NormalizeResource<Resource extends ResourceDefinition> =\n Resource extends string\n ? {\n [Key in Resource]: {\n subResources: {};\n };\n }\n : Resource extends {\n value: infer Value extends string;\n subResources: infer SubResources extends\n ReadonlyArray<ResourceDefinition>;\n }\n ? {\n [Key in Value]: {\n subResources: NormalizeResources<SubResources>;\n };\n }\n : never;\n\nexport type NormalizeResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = MergeIntersection<\n UnionToIntersection<NormalizeResource<Resources[number]>>\n>;\nexport type ResourceLayoutComponentProps = {\n children: ReactNode;\n};\n\nfunction normalizeResourceTree(resource: ResourceDefinition): ResourceTree {\n if (typeof resource === 'string') {\n return {\n [resource]: {\n subResources: {},\n },\n };\n }\n\n const { value, subResources } = resource;\n\n return {\n [value]: {\n subResources: normalizeResourcesTree(subResources),\n },\n };\n}\n\nfunction normalizeResourcesTree(\n resources: ReadonlyArray<ResourceDefinition>,\n): ResourceTree {\n const normalizedResources: ResourceTree = {};\n\n for (const resource of resources) {\n Object.assign(normalizedResources, normalizeResourceTree(resource));\n }\n\n return normalizedResources;\n}\n\nexport function normalizeResource(resource: ResourceDefinition): ResourceTree {\n return normalizeResourceTree(resource);\n}\n\nexport function normalizeResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources): NormalizeResources<Resources> {\n return normalizeResourcesTree(resources) as NormalizeResources<Resources>;\n}\n\ntype ResourceDefinitionValue<Resource extends ResourceDefinition> =\n Resource extends string\n ? Resource\n : Resource extends { value: infer Value extends string }\n ? Value\n : never;\n\n /**\n * Top-level resource names declared in a `resources` array. Preserves string\n * literal unions for const resource definitions (unlike `keyof` on the\n * normalized resource tree, which tends to widen to `string` in hovers).\n */\nexport type LayoutResourceKey<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = ResourceDefinitionValue<Resources[number]>;\n\nexport type ResourceDefinitionForKey<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Key extends string,\n> = Extract<Resources[number], Key | { value: Key }>;\n\n/** `subResources` array declared on a layout resource. */\nexport type SubResourceDefinitionsFor<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = ResourceDefinitionForKey<Resources, Resource> extends {\n subResources: infer SubResources extends ReadonlyArray<ResourceDefinition>;\n}\n ? SubResources\n : readonly [];\n\ntype CanNestSubResourceParam<\n MaxDepth extends number,\n DepthAcc extends readonly unknown[],\n> = [...DepthAcc, unknown]['length'] extends MaxDepth ? false : true;\n\n/**\n * `subResource` route param: a slug at the current depth, or `{ resource, subResource }`\n * when that slug has nested `subResources` in the layout tree and `MaxDepth` allows it.\n */\nexport type RecursiveSubResourceParam<\n Resources extends ReadonlyArray<ResourceDefinition>,\n SubDefs extends ReadonlyArray<ResourceDefinition>,\n MaxDepth extends number = 6,\n DepthAcc extends readonly unknown[] = readonly [],\n> = LayoutResourceKey<SubDefs> extends infer Key\n ? Key extends LayoutResourceKey<SubDefs>\n ? CanNestSubResourceParam<MaxDepth, DepthAcc> extends true\n ? ResourceDefinitionForKey<SubDefs, Key> extends {\n subResources: infer Nested extends ReadonlyArray<ResourceDefinition>;\n }\n ? [LayoutResourceKey<Nested>] extends [never]\n ? Key\n :\n | Key\n | {\n resource: Key;\n subResource: RecursiveSubResourceParam<\n Resources,\n Nested,\n MaxDepth,\n readonly [...DepthAcc, unknown]\n >;\n }\n : Key\n : Key\n : never\n : never;\n\n/** Recursive `subResource` values for a layout resource (full tree depth). */\nexport type SubResourceParamForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = [SubResourceDefinitionsFor<Resources, Resource>] extends [readonly []]\n ? never\n : RecursiveSubResourceParam<\n Resources,\n SubResourceDefinitionsFor<Resources, Resource>\n >;\n\nexport type GetSubResourceKeys<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = ResourceDefinitionForKey<Resources, Resource> extends {\n subResources: infer SubResources extends ReadonlyArray<ResourceDefinition>;\n}\n ? LayoutResourceKey<SubResources>\n : never;\nexport type ResourceEnum<Resources extends ReadonlyArray<ResourceDefinition>> =\n NonEmptyReadonlyArray<LayoutResourceKey<Resources>>;\nexport function toResourceEnum<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: NormalizeResources<Resources>) {\n const keys = Object.keys(resources);\n\n if (keys.length === 0) {\n throw new Error('No resources provided');\n }\n\n return keys as unknown as ResourceEnum<Resources>;\n}\n"],"mappings":";;AAuDA,SAAS,sBAAsB,UAA4C;CACzE,IAAI,OAAO,aAAa,UACtB,OAAO,GACJ,WAAW,EACV,cAAc,CAAC,EACjB,EACF;CAGF,MAAM,EAAE,OAAO,iBAAiB;CAEhC,OAAO,GACJ,QAAQ,EACP,cAAc,uBAAuB,YAAY,EACnD,EACF;AACF;AAEA,SAAS,uBACP,WACc;CACd,MAAM,sBAAoC,CAAC;CAE3C,KAAK,MAAM,YAAY,WACrB,OAAO,OAAO,qBAAqB,sBAAsB,QAAQ,CAAC;CAGpE,OAAO;AACT;AAEA,SAAgB,kBAAkB,UAA4C;CAC5E,OAAO,sBAAsB,QAAQ;AACvC;AAEA,SAAgB,mBAEd,WAAqD;CACrD,OAAO,uBAAuB,SAAS;AACzC;AA4FA,SAAgB,eAEd,WAA0C;CAC1C,MAAM,OAAO,OAAO,KAAK,SAAS;CAElC,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MAAM,uBAAuB;CAGzC,OAAO;AACT"}
|
package/dist/resource.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NonEmptyReadonlyArray } from "./
|
|
1
|
+
import { NonEmptyReadonlyArray } from "./validators/types.cjs";
|
|
2
2
|
import { MergeIntersection, UnionToIntersection } from "./utils.cjs";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
|
|
@@ -38,10 +38,30 @@ type ResourceDefinitionValue<Resource extends ResourceDefinition> = Resource ext
|
|
|
38
38
|
* Top-level resource names declared in a `resources` array. Preserves string
|
|
39
39
|
* literal unions for const resource definitions (unlike `keyof` on the
|
|
40
40
|
* normalized resource tree, which tends to widen to `string` in hovers).
|
|
41
|
-
|
|
41
|
+
*/
|
|
42
42
|
type LayoutResourceKey<Resources extends ReadonlyArray<ResourceDefinition>> = ResourceDefinitionValue<Resources[number]>;
|
|
43
|
+
type ResourceDefinitionForKey<Resources extends ReadonlyArray<ResourceDefinition>, Key extends string> = Extract<Resources[number], Key | {
|
|
44
|
+
value: Key;
|
|
45
|
+
}>;
|
|
46
|
+
/** `subResources` array declared on a layout resource. */
|
|
47
|
+
type SubResourceDefinitionsFor<Resources extends ReadonlyArray<ResourceDefinition>, Resource extends LayoutResourceKey<Resources>> = ResourceDefinitionForKey<Resources, Resource> extends {
|
|
48
|
+
subResources: infer SubResources extends ReadonlyArray<ResourceDefinition>;
|
|
49
|
+
} ? SubResources : readonly [];
|
|
50
|
+
type CanNestSubResourceParam<MaxDepth extends number, DepthAcc extends readonly unknown[]> = [...DepthAcc, unknown]['length'] extends MaxDepth ? false : true;
|
|
51
|
+
/**
|
|
52
|
+
* `subResource` route param: a slug at the current depth, or `{ resource, subResource }`
|
|
53
|
+
* when that slug has nested `subResources` in the layout tree and `MaxDepth` allows it.
|
|
54
|
+
*/
|
|
55
|
+
type RecursiveSubResourceParam<Resources extends ReadonlyArray<ResourceDefinition>, SubDefs extends ReadonlyArray<ResourceDefinition>, MaxDepth extends number = 6, DepthAcc extends readonly unknown[] = readonly []> = LayoutResourceKey<SubDefs> extends infer Key ? Key extends LayoutResourceKey<SubDefs> ? CanNestSubResourceParam<MaxDepth, DepthAcc> extends true ? ResourceDefinitionForKey<SubDefs, Key> extends {
|
|
56
|
+
subResources: infer Nested extends ReadonlyArray<ResourceDefinition>;
|
|
57
|
+
} ? [LayoutResourceKey<Nested>] extends [never] ? Key : Key | {
|
|
58
|
+
resource: Key;
|
|
59
|
+
subResource: RecursiveSubResourceParam<Resources, Nested, MaxDepth, readonly [...DepthAcc, unknown]>;
|
|
60
|
+
} : Key : Key : never : never;
|
|
61
|
+
/** Recursive `subResource` values for a layout resource (full tree depth). */
|
|
62
|
+
type SubResourceParamForResource<Resources extends ReadonlyArray<ResourceDefinition>, Resource extends LayoutResourceKey<Resources>> = [SubResourceDefinitionsFor<Resources, Resource>] extends [readonly []] ? never : RecursiveSubResourceParam<Resources, SubResourceDefinitionsFor<Resources, Resource>>;
|
|
43
63
|
type ResourceEnum<Resources extends ReadonlyArray<ResourceDefinition>> = NonEmptyReadonlyArray<LayoutResourceKey<Resources>>;
|
|
44
64
|
declare function toResourceEnum<Resources extends ReadonlyArray<ResourceDefinition>>(resources: NormalizeResources<Resources>): ResourceEnum<Resources>;
|
|
45
65
|
//#endregion
|
|
46
|
-
export { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, normalizeResource, normalizeResources, toResourceEnum };
|
|
66
|
+
export { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceDefinitionForKey, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, SubResourceDefinitionsFor, SubResourceParamForResource, normalizeResource, normalizeResources, toResourceEnum };
|
|
47
67
|
//# sourceMappingURL=resource.d.cts.map
|
package/dist/resource.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.cts","names":[],"sources":["../src/resource.ts"],"mappings":";;;;;KAIY,kBAAA;EAGN,KAAA;EACA,YAAA,EAAc,aAAa,CACzB,kBAAA;
|
|
1
|
+
{"version":3,"file":"resource.d.cts","names":[],"sources":["../src/resource.ts"],"mappings":";;;;;KAIY,kBAAA;EAGN,KAAA;EACA,YAAA,EAAc,aAAa,CACzB,kBAAA;IALI;;;;;IAWF,cAAA;EAAA;AAAA;AAAA,KAKE,YAAA,GAAe,MAAM;EAG7B,YAAA,EAAc,YAAA;AAAA;AAAA,KAIN,iBAAA,kBAAmC,kBAAA,IAC7C,QAAA,4BAEc,QAAA;EACN,YAAA;AAAA,MAGJ,QAAA;EACI,KAAA;EACA,YAAA,6BACE,aAAA,CAAc,kBAAA;AAAA,cAGR,KAAA;EACN,YAAA,EAAc,kBAAA,CAAmB,YAAA;AAAA;AAAA,KAKjC,kBAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,iBAAA,CACF,mBAAA,CAAoB,iBAAA,CAAkB,SAAA;AAAA,KAE5B,4BAAA;EACV,QAAA,EAAU,SAAS;AAAA;AAAA,iBAiCL,iBAAA,CAAkB,QAAA,EAAU,kBAAA,GAAqB,YAAY;AAAA,iBAI7D,kBAAA,mBACI,aAAA,CAAc,kBAAA,GAChC,SAAA,EAAW,SAAA,GAAY,kBAAA,CAAmB,SAAA;AAAA,KAIvC,uBAAA,kBAAyC,kBAAA,IAC5C,QAAA,kBACI,QAAA,GACA,QAAA;EAAmB,KAAA;AAAA,IACjB,KAAA;;;;;;KAQI,iBAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,uBAAA,CAAwB,SAAA;AAAA,KAEhB,wBAAA,mBACQ,aAAA,CAAc,kBAAA,yBAE9B,OAAA,CAAQ,SAAA,UAAmB,GAAA;EAAQ,KAAA,EAAO,GAAA;AAAA;;KAGlC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,KACjC,wBAAA,CAAyB,SAAA,EAAW,QAAA;EACtC,YAAA,6BAAyC,aAAA,CAAc,kBAAA;AAAA,IAErD,YAAA;AAAA,KAGC,uBAAA,qEAGG,QAAA,6BAAqC,QAAQ;;;;;KAMzC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,aAAA,CAAc,kBAAA,qFAG5B,iBAAA,CAAkB,OAAA,sBAClB,GAAA,SAAY,iBAAA,CAAkB,OAAA,IAC5B,uBAAA,CAAwB,QAAA,EAAU,QAAA,iBAChC,wBAAA,CAAyB,OAAA,EAAS,GAAA;EAChC,YAAA,uBAAmC,aAAA,CAAc,kBAAA;AAAA,KAEhD,iBAAA,CAAkB,MAAA,qBACjB,GAAA,GAEI,GAAA;EAEE,QAAA,EAAU,GAAA;EACV,WAAA,EAAa,yBAAA,CACX,SAAA,EACA,MAAA,EACA,QAAA,eACa,QAAA;AAAA,IAGvB,GAAA,GACF,GAAA;;KAKI,2BAAA,mBACQ,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,MAChC,yBAAA,CAA0B,SAAA,EAAW,QAAA,mCAEtC,yBAAA,CACE,SAAA,EACA,yBAAA,CAA0B,SAAA,EAAW,QAAA;AAAA,KAW/B,YAAA,mBAA+B,aAAA,CAAc,kBAAA,KACvD,qBAAA,CAAsB,iBAAA,CAAkB,SAAA;AAAA,iBAC1B,cAAA,mBACI,aAAA,CAAc,kBAAA,GAChC,SAAA,EAAW,kBAAA,CAAmB,SAAA,IAOJ,YAAA,CAAa,SAAA"}
|
package/dist/resource.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NonEmptyReadonlyArray } from "./
|
|
1
|
+
import { NonEmptyReadonlyArray } from "./validators/types.mjs";
|
|
2
2
|
import { MergeIntersection, UnionToIntersection } from "./utils.mjs";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
|
|
@@ -38,10 +38,30 @@ type ResourceDefinitionValue<Resource extends ResourceDefinition> = Resource ext
|
|
|
38
38
|
* Top-level resource names declared in a `resources` array. Preserves string
|
|
39
39
|
* literal unions for const resource definitions (unlike `keyof` on the
|
|
40
40
|
* normalized resource tree, which tends to widen to `string` in hovers).
|
|
41
|
-
|
|
41
|
+
*/
|
|
42
42
|
type LayoutResourceKey<Resources extends ReadonlyArray<ResourceDefinition>> = ResourceDefinitionValue<Resources[number]>;
|
|
43
|
+
type ResourceDefinitionForKey<Resources extends ReadonlyArray<ResourceDefinition>, Key extends string> = Extract<Resources[number], Key | {
|
|
44
|
+
value: Key;
|
|
45
|
+
}>;
|
|
46
|
+
/** `subResources` array declared on a layout resource. */
|
|
47
|
+
type SubResourceDefinitionsFor<Resources extends ReadonlyArray<ResourceDefinition>, Resource extends LayoutResourceKey<Resources>> = ResourceDefinitionForKey<Resources, Resource> extends {
|
|
48
|
+
subResources: infer SubResources extends ReadonlyArray<ResourceDefinition>;
|
|
49
|
+
} ? SubResources : readonly [];
|
|
50
|
+
type CanNestSubResourceParam<MaxDepth extends number, DepthAcc extends readonly unknown[]> = [...DepthAcc, unknown]['length'] extends MaxDepth ? false : true;
|
|
51
|
+
/**
|
|
52
|
+
* `subResource` route param: a slug at the current depth, or `{ resource, subResource }`
|
|
53
|
+
* when that slug has nested `subResources` in the layout tree and `MaxDepth` allows it.
|
|
54
|
+
*/
|
|
55
|
+
type RecursiveSubResourceParam<Resources extends ReadonlyArray<ResourceDefinition>, SubDefs extends ReadonlyArray<ResourceDefinition>, MaxDepth extends number = 6, DepthAcc extends readonly unknown[] = readonly []> = LayoutResourceKey<SubDefs> extends infer Key ? Key extends LayoutResourceKey<SubDefs> ? CanNestSubResourceParam<MaxDepth, DepthAcc> extends true ? ResourceDefinitionForKey<SubDefs, Key> extends {
|
|
56
|
+
subResources: infer Nested extends ReadonlyArray<ResourceDefinition>;
|
|
57
|
+
} ? [LayoutResourceKey<Nested>] extends [never] ? Key : Key | {
|
|
58
|
+
resource: Key;
|
|
59
|
+
subResource: RecursiveSubResourceParam<Resources, Nested, MaxDepth, readonly [...DepthAcc, unknown]>;
|
|
60
|
+
} : Key : Key : never : never;
|
|
61
|
+
/** Recursive `subResource` values for a layout resource (full tree depth). */
|
|
62
|
+
type SubResourceParamForResource<Resources extends ReadonlyArray<ResourceDefinition>, Resource extends LayoutResourceKey<Resources>> = [SubResourceDefinitionsFor<Resources, Resource>] extends [readonly []] ? never : RecursiveSubResourceParam<Resources, SubResourceDefinitionsFor<Resources, Resource>>;
|
|
43
63
|
type ResourceEnum<Resources extends ReadonlyArray<ResourceDefinition>> = NonEmptyReadonlyArray<LayoutResourceKey<Resources>>;
|
|
44
64
|
declare function toResourceEnum<Resources extends ReadonlyArray<ResourceDefinition>>(resources: NormalizeResources<Resources>): ResourceEnum<Resources>;
|
|
45
65
|
//#endregion
|
|
46
|
-
export { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, normalizeResource, normalizeResources, toResourceEnum };
|
|
66
|
+
export { LayoutResourceKey, NormalizeResource, NormalizeResources, ResourceDefinition, ResourceDefinitionForKey, ResourceEnum, ResourceLayoutComponentProps, ResourceTree, SubResourceDefinitionsFor, SubResourceParamForResource, normalizeResource, normalizeResources, toResourceEnum };
|
|
47
67
|
//# sourceMappingURL=resource.d.mts.map
|
package/dist/resource.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.mts","names":[],"sources":["../src/resource.ts"],"mappings":";;;;;KAIY,kBAAA;EAGN,KAAA;EACA,YAAA,EAAc,aAAa,CACzB,kBAAA;
|
|
1
|
+
{"version":3,"file":"resource.d.mts","names":[],"sources":["../src/resource.ts"],"mappings":";;;;;KAIY,kBAAA;EAGN,KAAA;EACA,YAAA,EAAc,aAAa,CACzB,kBAAA;IALI;;;;;IAWF,cAAA;EAAA;AAAA;AAAA,KAKE,YAAA,GAAe,MAAM;EAG7B,YAAA,EAAc,YAAA;AAAA;AAAA,KAIN,iBAAA,kBAAmC,kBAAA,IAC7C,QAAA,4BAEc,QAAA;EACN,YAAA;AAAA,MAGJ,QAAA;EACI,KAAA;EACA,YAAA,6BACE,aAAA,CAAc,kBAAA;AAAA,cAGR,KAAA;EACN,YAAA,EAAc,kBAAA,CAAmB,YAAA;AAAA;AAAA,KAKjC,kBAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,iBAAA,CACF,mBAAA,CAAoB,iBAAA,CAAkB,SAAA;AAAA,KAE5B,4BAAA;EACV,QAAA,EAAU,SAAS;AAAA;AAAA,iBAiCL,iBAAA,CAAkB,QAAA,EAAU,kBAAA,GAAqB,YAAY;AAAA,iBAI7D,kBAAA,mBACI,aAAA,CAAc,kBAAA,GAChC,SAAA,EAAW,SAAA,GAAY,kBAAA,CAAmB,SAAA;AAAA,KAIvC,uBAAA,kBAAyC,kBAAA,IAC5C,QAAA,kBACI,QAAA,GACA,QAAA;EAAmB,KAAA;AAAA,IACjB,KAAA;;;;;;KAQI,iBAAA,mBACQ,aAAA,CAAc,kBAAA,KAC9B,uBAAA,CAAwB,SAAA;AAAA,KAEhB,wBAAA,mBACQ,aAAA,CAAc,kBAAA,yBAE9B,OAAA,CAAQ,SAAA,UAAmB,GAAA;EAAQ,KAAA,EAAO,GAAA;AAAA;;KAGlC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,KACjC,wBAAA,CAAyB,SAAA,EAAW,QAAA;EACtC,YAAA,6BAAyC,aAAA,CAAc,kBAAA;AAAA,IAErD,YAAA;AAAA,KAGC,uBAAA,qEAGG,QAAA,6BAAqC,QAAQ;;;;;KAMzC,yBAAA,mBACQ,aAAA,CAAc,kBAAA,mBAChB,aAAA,CAAc,kBAAA,qFAG5B,iBAAA,CAAkB,OAAA,sBAClB,GAAA,SAAY,iBAAA,CAAkB,OAAA,IAC5B,uBAAA,CAAwB,QAAA,EAAU,QAAA,iBAChC,wBAAA,CAAyB,OAAA,EAAS,GAAA;EAChC,YAAA,uBAAmC,aAAA,CAAc,kBAAA;AAAA,KAEhD,iBAAA,CAAkB,MAAA,qBACjB,GAAA,GAEI,GAAA;EAEE,QAAA,EAAU,GAAA;EACV,WAAA,EAAa,yBAAA,CACX,SAAA,EACA,MAAA,EACA,QAAA,eACa,QAAA;AAAA,IAGvB,GAAA,GACF,GAAA;;KAKI,2BAAA,mBACQ,aAAA,CAAc,kBAAA,oBACf,iBAAA,CAAkB,SAAA,MAChC,yBAAA,CAA0B,SAAA,EAAW,QAAA,mCAEtC,yBAAA,CACE,SAAA,EACA,yBAAA,CAA0B,SAAA,EAAW,QAAA;AAAA,KAW/B,YAAA,mBAA+B,aAAA,CAAc,kBAAA,KACvD,qBAAA,CAAsB,iBAAA,CAAkB,SAAA;AAAA,iBAC1B,cAAA,mBACI,aAAA,CAAc,kBAAA,GAChC,SAAA,EAAW,kBAAA,CAAmB,SAAA,IAOJ,YAAA,CAAa,SAAA"}
|
package/dist/resource.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.mjs","names":[],"sources":["../src/resource.ts"],"sourcesContent":["import { ReactNode } from 'react';\
|
|
1
|
+
{"version":3,"file":"resource.mjs","names":[],"sources":["../src/resource.ts"],"sourcesContent":["import { ReactNode } from 'react';\nimport { NonEmptyReadonlyArray } from './validators';\nimport { MergeIntersection, UnionToIntersection } from './utils';\n\nexport type ResourceDefinition =\n | string\n | {\n value: string;\n subResources: ReadonlyArray<\n ResourceDefinition & {\n /**\n * Whether to allow any string as a sub resource.\n *\n * @default false\n */\n allowAnyString?: boolean;\n }\n >;\n };\n\nexport type ResourceTree = Record<\n string,\n {\n subResources: ResourceTree;\n }\n>;\n\nexport type NormalizeResource<Resource extends ResourceDefinition> =\n Resource extends string\n ? {\n [Key in Resource]: {\n subResources: {};\n };\n }\n : Resource extends {\n value: infer Value extends string;\n subResources: infer SubResources extends\n ReadonlyArray<ResourceDefinition>;\n }\n ? {\n [Key in Value]: {\n subResources: NormalizeResources<SubResources>;\n };\n }\n : never;\n\nexport type NormalizeResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = MergeIntersection<\n UnionToIntersection<NormalizeResource<Resources[number]>>\n>;\nexport type ResourceLayoutComponentProps = {\n children: ReactNode;\n};\n\nfunction normalizeResourceTree(resource: ResourceDefinition): ResourceTree {\n if (typeof resource === 'string') {\n return {\n [resource]: {\n subResources: {},\n },\n };\n }\n\n const { value, subResources } = resource;\n\n return {\n [value]: {\n subResources: normalizeResourcesTree(subResources),\n },\n };\n}\n\nfunction normalizeResourcesTree(\n resources: ReadonlyArray<ResourceDefinition>,\n): ResourceTree {\n const normalizedResources: ResourceTree = {};\n\n for (const resource of resources) {\n Object.assign(normalizedResources, normalizeResourceTree(resource));\n }\n\n return normalizedResources;\n}\n\nexport function normalizeResource(resource: ResourceDefinition): ResourceTree {\n return normalizeResourceTree(resource);\n}\n\nexport function normalizeResources<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: Resources): NormalizeResources<Resources> {\n return normalizeResourcesTree(resources) as NormalizeResources<Resources>;\n}\n\ntype ResourceDefinitionValue<Resource extends ResourceDefinition> =\n Resource extends string\n ? Resource\n : Resource extends { value: infer Value extends string }\n ? Value\n : never;\n\n /**\n * Top-level resource names declared in a `resources` array. Preserves string\n * literal unions for const resource definitions (unlike `keyof` on the\n * normalized resource tree, which tends to widen to `string` in hovers).\n */\nexport type LayoutResourceKey<\n Resources extends ReadonlyArray<ResourceDefinition>,\n> = ResourceDefinitionValue<Resources[number]>;\n\nexport type ResourceDefinitionForKey<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Key extends string,\n> = Extract<Resources[number], Key | { value: Key }>;\n\n/** `subResources` array declared on a layout resource. */\nexport type SubResourceDefinitionsFor<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = ResourceDefinitionForKey<Resources, Resource> extends {\n subResources: infer SubResources extends ReadonlyArray<ResourceDefinition>;\n}\n ? SubResources\n : readonly [];\n\ntype CanNestSubResourceParam<\n MaxDepth extends number,\n DepthAcc extends readonly unknown[],\n> = [...DepthAcc, unknown]['length'] extends MaxDepth ? false : true;\n\n/**\n * `subResource` route param: a slug at the current depth, or `{ resource, subResource }`\n * when that slug has nested `subResources` in the layout tree and `MaxDepth` allows it.\n */\nexport type RecursiveSubResourceParam<\n Resources extends ReadonlyArray<ResourceDefinition>,\n SubDefs extends ReadonlyArray<ResourceDefinition>,\n MaxDepth extends number = 6,\n DepthAcc extends readonly unknown[] = readonly [],\n> = LayoutResourceKey<SubDefs> extends infer Key\n ? Key extends LayoutResourceKey<SubDefs>\n ? CanNestSubResourceParam<MaxDepth, DepthAcc> extends true\n ? ResourceDefinitionForKey<SubDefs, Key> extends {\n subResources: infer Nested extends ReadonlyArray<ResourceDefinition>;\n }\n ? [LayoutResourceKey<Nested>] extends [never]\n ? Key\n :\n | Key\n | {\n resource: Key;\n subResource: RecursiveSubResourceParam<\n Resources,\n Nested,\n MaxDepth,\n readonly [...DepthAcc, unknown]\n >;\n }\n : Key\n : Key\n : never\n : never;\n\n/** Recursive `subResource` values for a layout resource (full tree depth). */\nexport type SubResourceParamForResource<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = [SubResourceDefinitionsFor<Resources, Resource>] extends [readonly []]\n ? never\n : RecursiveSubResourceParam<\n Resources,\n SubResourceDefinitionsFor<Resources, Resource>\n >;\n\nexport type GetSubResourceKeys<\n Resources extends ReadonlyArray<ResourceDefinition>,\n Resource extends LayoutResourceKey<Resources>,\n> = ResourceDefinitionForKey<Resources, Resource> extends {\n subResources: infer SubResources extends ReadonlyArray<ResourceDefinition>;\n}\n ? LayoutResourceKey<SubResources>\n : never;\nexport type ResourceEnum<Resources extends ReadonlyArray<ResourceDefinition>> =\n NonEmptyReadonlyArray<LayoutResourceKey<Resources>>;\nexport function toResourceEnum<\n Resources extends ReadonlyArray<ResourceDefinition>,\n>(resources: NormalizeResources<Resources>) {\n const keys = Object.keys(resources);\n\n if (keys.length === 0) {\n throw new Error('No resources provided');\n }\n\n return keys as unknown as ResourceEnum<Resources>;\n}\n"],"mappings":";AAuDA,SAAS,sBAAsB,UAA4C;CACzE,IAAI,OAAO,aAAa,UACtB,OAAO,GACJ,WAAW,EACV,cAAc,CAAC,EACjB,EACF;CAGF,MAAM,EAAE,OAAO,iBAAiB;CAEhC,OAAO,GACJ,QAAQ,EACP,cAAc,uBAAuB,YAAY,EACnD,EACF;AACF;AAEA,SAAS,uBACP,WACc;CACd,MAAM,sBAAoC,CAAC;CAE3C,KAAK,MAAM,YAAY,WACrB,OAAO,OAAO,qBAAqB,sBAAsB,QAAQ,CAAC;CAGpE,OAAO;AACT;AAEA,SAAgB,kBAAkB,UAA4C;CAC5E,OAAO,sBAAsB,QAAQ;AACvC;AAEA,SAAgB,mBAEd,WAAqD;CACrD,OAAO,uBAAuB,SAAS;AACzC;AA4FA,SAAgB,eAEd,WAA0C;CAC1C,MAAM,OAAO,OAAO,KAAK,SAAS;CAElC,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MAAM,uBAAuB;CAGzC,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capitalize.cjs","names":[],"sources":["../../src/utils/capitalize.ts"],"sourcesContent":["export type CapitalizeFn = typeof capitalize;\n\nexport function capitalize<T extends string>(str: T): Capitalize<T>;\nexport function capitalize(str: string): string;\nexport function capitalize(...words: string[]) {\n return words\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ');\n}"],"mappings":";;AAIA,SAAgB,WAAW,GAAG,OAAiB;CAC7C,OAAO,MACJ,KAAK,SAAS,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,GAAG;AACb"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/capitalize.d.ts
|
|
2
|
+
type CapitalizeFn = typeof capitalize;
|
|
3
|
+
declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
4
|
+
declare function capitalize(str: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { CapitalizeFn };
|
|
7
|
+
//# sourceMappingURL=capitalize.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capitalize.d.cts","names":[],"sources":["../../src/utils/capitalize.ts"],"mappings":";KAAY,YAAA,UAAsB,UAAU;AAAA,iBAE5B,UAAA,mBAA6B,GAAA,EAAK,CAAA,GAAI,UAAA,CAAW,CAAA;AAAA,iBACjD,UAAA,CAAW,GAAW"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/capitalize.d.ts
|
|
2
|
+
type CapitalizeFn = typeof capitalize;
|
|
3
|
+
declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
4
|
+
declare function capitalize(str: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { CapitalizeFn };
|
|
7
|
+
//# sourceMappingURL=capitalize.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capitalize.d.mts","names":[],"sources":["../../src/utils/capitalize.ts"],"mappings":";KAAY,YAAA,UAAsB,UAAU;AAAA,iBAE5B,UAAA,mBAA6B,GAAA,EAAK,CAAA,GAAI,UAAA,CAAW,CAAA;AAAA,iBACjD,UAAA,CAAW,GAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capitalize.mjs","names":[],"sources":["../../src/utils/capitalize.ts"],"sourcesContent":["export type CapitalizeFn = typeof capitalize;\n\nexport function capitalize<T extends string>(str: T): Capitalize<T>;\nexport function capitalize(str: string): string;\nexport function capitalize(...words: string[]) {\n return words\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(' ');\n}"],"mappings":";AAIA,SAAgB,WAAW,GAAG,OAAiB;CAC7C,OAAO,MACJ,KAAK,SAAS,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,GAAG;AACb"}
|
package/dist/utils.cjs
CHANGED
|
@@ -18,8 +18,13 @@ function pick(obj, keys) {
|
|
|
18
18
|
return acc;
|
|
19
19
|
}, {});
|
|
20
20
|
}
|
|
21
|
+
function functionalUpdate(value, updater) {
|
|
22
|
+
if (typeof updater === "function") return updater(value);
|
|
23
|
+
return updater;
|
|
24
|
+
}
|
|
21
25
|
|
|
22
26
|
//#endregion
|
|
27
|
+
exports.functionalUpdate = functionalUpdate;
|
|
23
28
|
exports.pick = pick;
|
|
24
29
|
exports.resolvePropDefinitionValues = resolvePropDefinitionValues;
|
|
25
30
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\n [Key in keyof T]: T[Key];\n};\nexport type IsUnion<T, U = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\nexport type UnionToIntersection<Union> = (\n Union extends unknown ? (value: Union) => void : never\n) extends (value: infer Intersection) => void\n ? Intersection\n : never;\nexport type Updater<T> = T | ((prev: T) => T);\n\nexport interface BaseComponent<Name extends string, Props = {}> {\n /**\n * The name of the component. Useful for debugging and error messages.\n */\n displayName: Name;\n /**\n * A type only property to get the type of the props. At runtime,\n * this is `undefined`.\n */\n props: Props;\n}\n\ntype ValueBackedDefinition = {\n _baseProp?: {\n value?: unknown;\n };\n};\n\nexport function isPropDefinitionShape(value: unknown): value is {\n visibility: unknown;\n} {\n return typeof value === 'function' && value !== null && 'visibility' in value;\n}\n\nexport function resolvePropDefinitionValues(input: Record<string, unknown>) {\n const out: Record<string, unknown> = {};\n\n for (const key of Object.keys(input)) {\n const value = input[key];\n out[key] = isPropDefinitionShape(value)\n ? (value as ValueBackedDefinition)._baseProp?.value\n : value;\n }\n\n return out;\n}\n\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]) {\n if (keys.length === 0) {\n return {} as Pick<T, K>;\n }\n\n return keys.reduce(\n (acc, key) => {\n if (key in obj) acc[key] = obj[key];\n\n return acc;\n },\n {} as Pick<T, K>,\n );\n}\n\nexport function functionalUpdate<T>(value: T, updater: Updater<T>){\n if (typeof updater === 'function') {\n return (updater as (prev: T) => T)(value);\n }\n\n return updater;\n}\n"],"mappings":";;AAoCA,SAAgB,sBAAsB,OAEpC;CACA,OAAO,OAAO,UAAU,cAAc,UAAU,QAAQ,gBAAgB;AAC1E;AAEA,SAAgB,4BAA4B,OAAgC;CAC1E,MAAM,MAA+B,CAAC;CAEtC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACpC,MAAM,QAAQ,MAAM;EACpB,IAAI,OAAO,sBAAsB,KAAK,IACjC,MAAgC,WAAW,QAC5C;CACN;CAEA,OAAO;AACT;AAEA,SAAgB,KAA0C,KAAQ,MAAW;CAC3E,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAGV,OAAO,KAAK,QACT,KAAK,QAAQ;EACZ,IAAI,OAAO,KAAK,IAAI,OAAO,IAAI;EAE/B,OAAO;CACT,GACA,CAAC,CACH;AACF;AAEA,SAAgB,iBAAoB,OAAU,SAAoB;CAChE,IAAI,OAAO,YAAY,YACrB,OAAQ,QAA2B,KAAK;CAG1C,OAAO;AACT"}
|
package/dist/utils.d.cts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
type Show<T> = T extends ((...args: infer A) => infer R) ? (...args: A) => R : { [K in keyof T]: T[K] } & {};
|
|
3
3
|
type MergeIntersection<T> = { [Key in keyof T]: T[Key] };
|
|
4
4
|
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends ((value: infer Intersection) => void) ? Intersection : never;
|
|
5
|
+
type Updater<T> = T | ((prev: T) => T);
|
|
5
6
|
interface BaseComponent<Name extends string, Props = {}> {
|
|
6
7
|
/**
|
|
7
8
|
* The name of the component. Useful for debugging and error messages.
|
|
@@ -15,5 +16,5 @@ interface BaseComponent<Name extends string, Props = {}> {
|
|
|
15
16
|
}
|
|
16
17
|
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
17
18
|
//#endregion
|
|
18
|
-
export { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick };
|
|
19
|
+
export { BaseComponent, MergeIntersection, Show, UnionToIntersection, Updater, pick };
|
|
19
20
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.cts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,KAOV,mBAAA,WACV,KAAA,oBAAyB,KAAA,EAAO,KAAK,6BAC5B,KAAA,iCACP,YAAA;AAAA,KAEQ,OAAA,MAAa,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA,UAE1B,aAAA;EAhBQ;;;EAoBvB,WAAA,EAAa,IAAA;EAtBqB;;;;EA2BlC,KAAA,EAAO,KAAK;AAAA;AAAA,iBA4BE,IAAA,mCAAuC,CAAA,EAAG,GAAA,EAAK,CAAA,EAAG,IAAA,EAAM,CAAA,KAAG,IAAA,CAAA,CAAA,EAAA,CAAA"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
type Show<T> = T extends ((...args: infer A) => infer R) ? (...args: A) => R : { [K in keyof T]: T[K] } & {};
|
|
3
3
|
type MergeIntersection<T> = { [Key in keyof T]: T[Key] };
|
|
4
4
|
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends ((value: infer Intersection) => void) ? Intersection : never;
|
|
5
|
+
type Updater<T> = T | ((prev: T) => T);
|
|
5
6
|
interface BaseComponent<Name extends string, Props = {}> {
|
|
6
7
|
/**
|
|
7
8
|
* The name of the component. Useful for debugging and error messages.
|
|
@@ -15,5 +16,5 @@ interface BaseComponent<Name extends string, Props = {}> {
|
|
|
15
16
|
}
|
|
16
17
|
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
17
18
|
//#endregion
|
|
18
|
-
export { BaseComponent, MergeIntersection, Show, UnionToIntersection, pick };
|
|
19
|
+
export { BaseComponent, MergeIntersection, Show, UnionToIntersection, Updater, pick };
|
|
19
20
|
//# sourceMappingURL=utils.d.mts.map
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";KAAY,IAAA,MAAU,CAAA,cAAc,IAAA,6BAC5B,IAAA,EAAM,CAAA,KAAM,CAAA,iBACF,CAAA,GAAI,CAAA,CAAE,CAAA;AAAA,KACZ,iBAAA,sBACI,CAAA,GAAI,CAAA,CAAE,GAAA;AAAA,KAOV,mBAAA,WACV,KAAA,oBAAyB,KAAA,EAAO,KAAK,6BAC5B,KAAA,iCACP,YAAA;AAAA,KAEQ,OAAA,MAAa,CAAA,KAAM,IAAA,EAAM,CAAA,KAAM,CAAA;AAAA,UAE1B,aAAA;EAhBQ;;;EAoBvB,WAAA,EAAa,IAAA;EAtBqB;;;;EA2BlC,KAAA,EAAO,KAAK;AAAA;AAAA,iBA4BE,IAAA,mCAAuC,CAAA,EAAG,GAAA,EAAK,CAAA,EAAG,IAAA,EAAM,CAAA,KAAG,IAAA,CAAA,CAAA,EAAA,CAAA"}
|
package/dist/utils.mjs
CHANGED
|
@@ -17,7 +17,11 @@ function pick(obj, keys) {
|
|
|
17
17
|
return acc;
|
|
18
18
|
}, {});
|
|
19
19
|
}
|
|
20
|
+
function functionalUpdate(value, updater) {
|
|
21
|
+
if (typeof updater === "function") return updater(value);
|
|
22
|
+
return updater;
|
|
23
|
+
}
|
|
20
24
|
|
|
21
25
|
//#endregion
|
|
22
|
-
export { pick, resolvePropDefinitionValues };
|
|
26
|
+
export { functionalUpdate, pick, resolvePropDefinitionValues };
|
|
23
27
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["export type Show<T> = T extends (...args: infer A) => infer R\n ? (...args: A) => R\n : { [K in keyof T]: T[K] } & {};\nexport type MergeIntersection<T> = {\n [Key in keyof T]: T[Key];\n};\nexport type IsUnion<T, U = T> = T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never;\nexport type UnionToIntersection<Union> = (\n Union extends unknown ? (value: Union) => void : never\n) extends (value: infer Intersection) => void\n ? Intersection\n : never;\nexport type Updater<T> = T | ((prev: T) => T);\n\nexport interface BaseComponent<Name extends string, Props = {}> {\n /**\n * The name of the component. Useful for debugging and error messages.\n */\n displayName: Name;\n /**\n * A type only property to get the type of the props. At runtime,\n * this is `undefined`.\n */\n props: Props;\n}\n\ntype ValueBackedDefinition = {\n _baseProp?: {\n value?: unknown;\n };\n};\n\nexport function isPropDefinitionShape(value: unknown): value is {\n visibility: unknown;\n} {\n return typeof value === 'function' && value !== null && 'visibility' in value;\n}\n\nexport function resolvePropDefinitionValues(input: Record<string, unknown>) {\n const out: Record<string, unknown> = {};\n\n for (const key of Object.keys(input)) {\n const value = input[key];\n out[key] = isPropDefinitionShape(value)\n ? (value as ValueBackedDefinition)._baseProp?.value\n : value;\n }\n\n return out;\n}\n\nexport function pick<T extends object, K extends keyof T>(obj: T, keys: K[]) {\n if (keys.length === 0) {\n return {} as Pick<T, K>;\n }\n\n return keys.reduce(\n (acc, key) => {\n if (key in obj) acc[key] = obj[key];\n\n return acc;\n },\n {} as Pick<T, K>,\n );\n}\n\nexport function functionalUpdate<T>(value: T, updater: Updater<T>){\n if (typeof updater === 'function') {\n return (updater as (prev: T) => T)(value);\n }\n\n return updater;\n}\n"],"mappings":";AAoCA,SAAgB,sBAAsB,OAEpC;CACA,OAAO,OAAO,UAAU,cAAc,UAAU,QAAQ,gBAAgB;AAC1E;AAEA,SAAgB,4BAA4B,OAAgC;CAC1E,MAAM,MAA+B,CAAC;CAEtC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACpC,MAAM,QAAQ,MAAM;EACpB,IAAI,OAAO,sBAAsB,KAAK,IACjC,MAAgC,WAAW,QAC5C;CACN;CAEA,OAAO;AACT;AAEA,SAAgB,KAA0C,KAAQ,MAAW;CAC3E,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAGV,OAAO,KAAK,QACT,KAAK,QAAQ;EACZ,IAAI,OAAO,KAAK,IAAI,OAAO,IAAI;EAE/B,OAAO;CACT,GACA,CAAC,CACH;AACF;AAEA,SAAgB,iBAAoB,OAAU,SAAoB;CAChE,IAAI,OAAO,YAAY,YACrB,OAAQ,QAA2B,KAAK;CAG1C,OAAO;AACT"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/validators/base.ts
|
|
3
|
+
const primitiveTypes = {
|
|
4
|
+
string: "string",
|
|
5
|
+
number: "number",
|
|
6
|
+
boolean: "boolean",
|
|
7
|
+
object: "object",
|
|
8
|
+
array: "array",
|
|
9
|
+
date: "date",
|
|
10
|
+
regex: "regex",
|
|
11
|
+
error: "error",
|
|
12
|
+
symbol: "symbol",
|
|
13
|
+
bigint: "bigint"
|
|
14
|
+
};
|
|
15
|
+
function createInvalidPropValueMessage(type) {
|
|
16
|
+
return `"value" is not of type "${type}".`;
|
|
17
|
+
}
|
|
18
|
+
var InvalidPropValueError = class extends Error {
|
|
19
|
+
constructor(type) {
|
|
20
|
+
super(createInvalidPropValueMessage(type));
|
|
21
|
+
this.name = "InvalidPropValueError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var BaseProp = class {
|
|
25
|
+
type;
|
|
26
|
+
visibility;
|
|
27
|
+
value;
|
|
28
|
+
error;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
const { type, visibility, value } = options;
|
|
31
|
+
this.type = type;
|
|
32
|
+
this.visibility = visibility;
|
|
33
|
+
this.value = value;
|
|
34
|
+
this.error = new InvalidPropValueError(type);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.BaseProp = BaseProp;
|
|
40
|
+
exports.primitiveTypes = primitiveTypes;
|
|
41
|
+
//# sourceMappingURL=base.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.cjs","names":[],"sources":["../../src/validators/base.ts"],"sourcesContent":["import type { BasePropOptions, PropType, PropVisibility } from './types';\n\nexport const primitiveTypes = {\n string: 'string',\n number: 'number',\n boolean: 'boolean',\n object: 'object',\n array: 'array',\n date: 'date',\n regex: 'regex',\n error: 'error',\n symbol: 'symbol',\n bigint: 'bigint',\n};\n\nfunction createInvalidPropValueMessage(type: string) {\n return `\"value\" is not of type \"${type}\".`;\n}\n\nexport class InvalidPropValueError<Type extends string> extends Error {\n constructor(type: Type) {\n super(createInvalidPropValueMessage(type));\n\n this.name = 'InvalidPropValueError';\n }\n}\n\nexport abstract class BaseProp<\n Type extends PropType,\n Visibility extends PropVisibility,\n Value = unknown,\n> {\n readonly type: Type;\n readonly visibility: Visibility;\n readonly value?: Value;\n\n protected error: InvalidPropValueError<Type>;\n\n constructor(options: BasePropOptions<Type, Visibility, Value>) {\n const { type, visibility, value } = options;\n\n this.type = type;\n this.visibility = visibility;\n this.value = value;\n this.error = new InvalidPropValueError(type);\n }\n\n abstract validate(value: unknown): void;\n abstract allows(value: unknown): value is Value;\n}\n"],"mappings":";;AAEA,MAAa,iBAAiB;CAC5B,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,8BAA8B,MAAc;CACnD,OAAO,2BAA2B,KAAK;AACzC;AAEA,IAAa,wBAAb,cAAgE,MAAM;CACpE,YAAY,MAAY;EACtB,MAAM,8BAA8B,IAAI,CAAC;EAEzC,KAAK,OAAO;CACd;AACF;AAEA,IAAsB,WAAtB,MAIE;CACA,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAU;CAEV,YAAY,SAAmD;EAC7D,MAAM,EAAE,MAAM,YAAY,UAAU;EAEpC,KAAK,OAAO;EACZ,KAAK,aAAa;EAClB,KAAK,QAAQ;EACb,KAAK,QAAQ,IAAI,sBAAsB,IAAI;CAC7C;AAIF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BasePropOptions, PropType, PropVisibility } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/validators/base.d.ts
|
|
4
|
+
declare class InvalidPropValueError<Type extends string> extends Error {
|
|
5
|
+
constructor(type: Type);
|
|
6
|
+
}
|
|
7
|
+
declare abstract class BaseProp<Type extends PropType, Visibility extends PropVisibility, Value = unknown> {
|
|
8
|
+
readonly type: Type;
|
|
9
|
+
readonly visibility: Visibility;
|
|
10
|
+
readonly value?: Value;
|
|
11
|
+
protected error: InvalidPropValueError<Type>;
|
|
12
|
+
constructor(options: BasePropOptions<Type, Visibility, Value>);
|
|
13
|
+
abstract validate(value: unknown): void;
|
|
14
|
+
abstract allows(value: unknown): value is Value;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { BaseProp, InvalidPropValueError };
|
|
18
|
+
//# sourceMappingURL=base.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.cts","names":[],"sources":["../../src/validators/base.ts"],"mappings":";;;cAmBa,qBAAA,8BAAmD,KAAK;cACvD,IAAA,EAAM,IAAA;AAAA;AAAA,uBAOE,QAAA,cACP,QAAA,qBACM,cAAA;EAAA,SAGV,IAAA,EAAM,IAAA;EAAA,SACN,UAAA,EAAY,UAAA;EAAA,SACZ,KAAA,GAAQ,KAAA;EAAA,UAEP,KAAA,EAAO,qBAAA,CAAsB,IAAA;cAE3B,OAAA,EAAS,eAAA,CAAgB,IAAA,EAAM,UAAA,EAAY,KAAA;EAAA,SAS9C,QAAA,CAAS,KAAA;EAAA,SACT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,KAAA;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BasePropOptions, PropType, PropVisibility } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/validators/base.d.ts
|
|
4
|
+
declare class InvalidPropValueError<Type extends string> extends Error {
|
|
5
|
+
constructor(type: Type);
|
|
6
|
+
}
|
|
7
|
+
declare abstract class BaseProp<Type extends PropType, Visibility extends PropVisibility, Value = unknown> {
|
|
8
|
+
readonly type: Type;
|
|
9
|
+
readonly visibility: Visibility;
|
|
10
|
+
readonly value?: Value;
|
|
11
|
+
protected error: InvalidPropValueError<Type>;
|
|
12
|
+
constructor(options: BasePropOptions<Type, Visibility, Value>);
|
|
13
|
+
abstract validate(value: unknown): void;
|
|
14
|
+
abstract allows(value: unknown): value is Value;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { BaseProp, InvalidPropValueError };
|
|
18
|
+
//# sourceMappingURL=base.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.mts","names":[],"sources":["../../src/validators/base.ts"],"mappings":";;;cAmBa,qBAAA,8BAAmD,KAAK;cACvD,IAAA,EAAM,IAAA;AAAA;AAAA,uBAOE,QAAA,cACP,QAAA,qBACM,cAAA;EAAA,SAGV,IAAA,EAAM,IAAA;EAAA,SACN,UAAA,EAAY,UAAA;EAAA,SACZ,KAAA,GAAQ,KAAA;EAAA,UAEP,KAAA,EAAO,qBAAA,CAAsB,IAAA;cAE3B,OAAA,EAAS,eAAA,CAAgB,IAAA,EAAM,UAAA,EAAY,KAAA;EAAA,SAS9C,QAAA,CAAS,KAAA;EAAA,SACT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,KAAA;AAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/validators/base.ts
|
|
2
|
+
const primitiveTypes = {
|
|
3
|
+
string: "string",
|
|
4
|
+
number: "number",
|
|
5
|
+
boolean: "boolean",
|
|
6
|
+
object: "object",
|
|
7
|
+
array: "array",
|
|
8
|
+
date: "date",
|
|
9
|
+
regex: "regex",
|
|
10
|
+
error: "error",
|
|
11
|
+
symbol: "symbol",
|
|
12
|
+
bigint: "bigint"
|
|
13
|
+
};
|
|
14
|
+
function createInvalidPropValueMessage(type) {
|
|
15
|
+
return `"value" is not of type "${type}".`;
|
|
16
|
+
}
|
|
17
|
+
var InvalidPropValueError = class extends Error {
|
|
18
|
+
constructor(type) {
|
|
19
|
+
super(createInvalidPropValueMessage(type));
|
|
20
|
+
this.name = "InvalidPropValueError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var BaseProp = class {
|
|
24
|
+
type;
|
|
25
|
+
visibility;
|
|
26
|
+
value;
|
|
27
|
+
error;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
const { type, visibility, value } = options;
|
|
30
|
+
this.type = type;
|
|
31
|
+
this.visibility = visibility;
|
|
32
|
+
this.value = value;
|
|
33
|
+
this.error = new InvalidPropValueError(type);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { BaseProp, primitiveTypes };
|
|
39
|
+
//# sourceMappingURL=base.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.mjs","names":[],"sources":["../../src/validators/base.ts"],"sourcesContent":["import type { BasePropOptions, PropType, PropVisibility } from './types';\n\nexport const primitiveTypes = {\n string: 'string',\n number: 'number',\n boolean: 'boolean',\n object: 'object',\n array: 'array',\n date: 'date',\n regex: 'regex',\n error: 'error',\n symbol: 'symbol',\n bigint: 'bigint',\n};\n\nfunction createInvalidPropValueMessage(type: string) {\n return `\"value\" is not of type \"${type}\".`;\n}\n\nexport class InvalidPropValueError<Type extends string> extends Error {\n constructor(type: Type) {\n super(createInvalidPropValueMessage(type));\n\n this.name = 'InvalidPropValueError';\n }\n}\n\nexport abstract class BaseProp<\n Type extends PropType,\n Visibility extends PropVisibility,\n Value = unknown,\n> {\n readonly type: Type;\n readonly visibility: Visibility;\n readonly value?: Value;\n\n protected error: InvalidPropValueError<Type>;\n\n constructor(options: BasePropOptions<Type, Visibility, Value>) {\n const { type, visibility, value } = options;\n\n this.type = type;\n this.visibility = visibility;\n this.value = value;\n this.error = new InvalidPropValueError(type);\n }\n\n abstract validate(value: unknown): void;\n abstract allows(value: unknown): value is Value;\n}\n"],"mappings":";AAEA,MAAa,iBAAiB;CAC5B,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,OAAO;CACP,MAAM;CACN,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,8BAA8B,MAAc;CACnD,OAAO,2BAA2B,KAAK;AACzC;AAEA,IAAa,wBAAb,cAAgE,MAAM;CACpE,YAAY,MAAY;EACtB,MAAM,8BAA8B,IAAI,CAAC;EAEzC,KAAK,OAAO;CACd;AACF;AAEA,IAAsB,WAAtB,MAIE;CACA,AAAS;CACT,AAAS;CACT,AAAS;CAET,AAAU;CAEV,YAAY,SAAmD;EAC7D,MAAM,EAAE,MAAM,YAAY,UAAU;EAEpC,KAAK,OAAO;EACZ,KAAK,aAAa;EAClB,KAAK,QAAQ;EACb,KAAK,QAAQ,IAAI,sBAAsB,IAAI;CAC7C;AAIF"}
|