@jfdevelops/react-layout 0.3.0 → 0.4.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/dist/create-config/define-layout.cjs +23 -18
- package/dist/create-config/define-layout.cjs.map +1 -1
- package/dist/create-config/define-layout.d.cts +25 -24
- package/dist/create-config/define-layout.d.cts.map +1 -1
- package/dist/create-config/define-layout.d.mts +25 -24
- package/dist/create-config/define-layout.d.mts.map +1 -1
- package/dist/create-config/define-layout.mjs +17 -12
- package/dist/create-config/define-layout.mjs.map +1 -1
- package/dist/index.cjs +81 -9
- package/dist/index.d.cts +4 -6
- package/dist/index.d.mts +4 -6
- package/dist/index.mjs +4 -5
- package/dist/props.d.cts +6 -6
- package/dist/props.d.cts.map +1 -1
- package/dist/props.d.mts +6 -6
- package/dist/props.d.mts.map +1 -1
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +1 -1
- package/dist/resource.d.cts.map +1 -1
- package/dist/resource.d.mts +1 -1
- package/dist/resource.d.mts.map +1 -1
- package/dist/resource.mjs.map +1 -1
- package/dist/utils.cjs +0 -12
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +1 -12
- package/dist/utils.mjs.map +1 -1
- package/package.json +5 -1
- package/dist/composable.cjs +0 -72
- package/dist/composable.cjs.map +0 -1
- package/dist/composable.d.cts +0 -44
- package/dist/composable.d.cts.map +0 -1
- package/dist/composable.d.mts +0 -44
- package/dist/composable.d.mts.map +0 -1
- package/dist/composable.mjs +0 -70
- package/dist/composable.mjs.map +0 -1
- package/dist/utils/capitalize.d.cts +0 -7
- package/dist/utils/capitalize.d.cts.map +0 -1
- package/dist/utils/capitalize.d.mts +0 -7
- package/dist/utils/capitalize.d.mts.map +0 -1
- package/dist/validators/base.cjs +0 -41
- package/dist/validators/base.cjs.map +0 -1
- package/dist/validators/base.d.cts +0 -18
- package/dist/validators/base.d.cts.map +0 -1
- package/dist/validators/base.d.mts +0 -18
- package/dist/validators/base.d.mts.map +0 -1
- package/dist/validators/base.mjs +0 -39
- package/dist/validators/base.mjs.map +0 -1
- package/dist/validators/builders.cjs +0 -137
- package/dist/validators/builders.cjs.map +0 -1
- package/dist/validators/builders.d.cts +0 -156
- package/dist/validators/builders.d.cts.map +0 -1
- package/dist/validators/builders.d.mts +0 -156
- package/dist/validators/builders.d.mts.map +0 -1
- package/dist/validators/builders.mjs +0 -136
- package/dist/validators/builders.mjs.map +0 -1
- package/dist/validators/component.cjs +0 -73
- package/dist/validators/component.cjs.map +0 -1
- package/dist/validators/component.d.cts +0 -28
- package/dist/validators/component.d.cts.map +0 -1
- package/dist/validators/component.d.mts +0 -28
- package/dist/validators/component.d.mts.map +0 -1
- package/dist/validators/component.mjs +0 -71
- package/dist/validators/component.mjs.map +0 -1
- package/dist/validators/enum.cjs +0 -27
- package/dist/validators/enum.cjs.map +0 -1
- package/dist/validators/enum.d.cts +0 -14
- package/dist/validators/enum.d.cts.map +0 -1
- package/dist/validators/enum.d.mts +0 -14
- package/dist/validators/enum.d.mts.map +0 -1
- package/dist/validators/enum.mjs +0 -27
- package/dist/validators/enum.mjs.map +0 -1
- package/dist/validators/index.d.cts +0 -10
- package/dist/validators/index.d.mts +0 -10
- package/dist/validators/literal.cjs +0 -25
- package/dist/validators/literal.cjs.map +0 -1
- package/dist/validators/literal.d.cts +0 -14
- package/dist/validators/literal.d.cts.map +0 -1
- package/dist/validators/literal.d.mts +0 -14
- package/dist/validators/literal.d.mts.map +0 -1
- package/dist/validators/literal.mjs +0 -25
- package/dist/validators/literal.mjs.map +0 -1
- package/dist/validators/object.cjs +0 -53
- package/dist/validators/object.cjs.map +0 -1
- package/dist/validators/object.d.cts +0 -14
- package/dist/validators/object.d.cts.map +0 -1
- package/dist/validators/object.d.mts +0 -14
- package/dist/validators/object.d.mts.map +0 -1
- package/dist/validators/object.mjs +0 -53
- package/dist/validators/object.mjs.map +0 -1
- package/dist/validators/primitive.cjs +0 -80
- package/dist/validators/primitive.cjs.map +0 -1
- package/dist/validators/primitive.d.cts +0 -33
- package/dist/validators/primitive.d.cts.map +0 -1
- package/dist/validators/primitive.d.mts +0 -33
- package/dist/validators/primitive.d.mts.map +0 -1
- package/dist/validators/primitive.mjs +0 -78
- package/dist/validators/primitive.mjs.map +0 -1
- package/dist/validators/types.d.cts +0 -71
- package/dist/validators/types.d.cts.map +0 -1
- package/dist/validators/types.d.mts +0 -71
- package/dist/validators/types.d.mts.map +0 -1
- package/dist/validators/union.cjs +0 -27
- package/dist/validators/union.cjs.map +0 -1
- package/dist/validators/union.d.cts +0 -14
- package/dist/validators/union.d.cts.map +0 -1
- package/dist/validators/union.d.mts +0 -14
- package/dist/validators/union.d.mts.map +0 -1
- package/dist/validators/union.mjs +0 -27
- package/dist/validators/union.mjs.map +0 -1
- package/dist/validators/validate-props.cjs +0 -22
- package/dist/validators/validate-props.cjs.map +0 -1
- package/dist/validators/validate-props.d.cts +0 -7
- package/dist/validators/validate-props.d.cts.map +0 -1
- package/dist/validators/validate-props.d.mts +0 -7
- package/dist/validators/validate-props.d.mts.map +0 -1
- package/dist/validators/validate-props.mjs +0 -21
- package/dist/validators/validate-props.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builders.mjs","names":[],"sources":["../../src/validators/builders.ts"],"sourcesContent":["import { JSX } from 'react';\nimport { BaseProp } from './base';\nimport { ComponentProp, ComponentPropWithPropertiesProp, RenderChildrenProp } from './component';\nimport { EnumProp } from './enum';\nimport { LiteralProp } from './literal';\nimport { ObjectProp } from './object';\nimport { BooleanProp, NumberProp, StringProp } from './primitive';\nimport type {\n AnyBaseProp,\n AnyBuiltPropDefinition,\n BuiltPropShape,\n ComponentPropType,\n ExtractPropValue,\n NonEmptyReadonlyArray,\n PrimitivePropType,\n PrimitiveTypesMap,\n PropConfig,\n PropVisibility,\n ResolveLayoutProps,\n} from './types';\nimport { UnionProp } from './union';\n\ntype ExtractVisibility<Prop extends AnyBaseProp> =\n Prop extends BaseProp<any, infer V extends PropVisibility, any>\n ? V\n : PropVisibility;\n\ntype OptionalChain<\n Visibility extends PropVisibility,\n OptionalProp extends AnyBaseProp,\n> = Visibility extends 'required'\n ? { optional(): WrappedProp<OptionalProp> }\n : {};\n\ntype ConfigChain<Prop extends AnyBaseProp> = {\n config<const Config extends PropConfig>(\n config: Config,\n ): ConfiguredWrappedProp<Prop, Config>;\n};\n\ntype PrimitiveWrappedPropState<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n Value,\n> = {\n type: Type;\n visibility: Visibility;\n} & ([Value] extends [never] ? {} : { value: Value });\n\ntype ObjectWrappedPropState<\n Shape extends BuiltPropShape,\n Visibility extends PropVisibility,\n> = {\n type: 'object';\n visibility: Visibility;\n properties: Shape;\n};\n\ntype ComponentWithPropsWrappedPropState<\n Type extends ComponentPropType,\n Shape extends BuiltPropShape,\n Visibility extends PropVisibility,\n> = {\n type: Type;\n visibility: Visibility;\n properties: Shape;\n};\n\ntype UnionWrappedPropState<\n Members extends readonly AnyBaseProp[],\n Visibility extends PropVisibility,\n> = {\n type: 'union';\n visibility: Visibility;\n members: Members;\n};\n\ntype RenderChildrenWrappedPropState<\n Shape extends BuiltPropShape,\n ChildrenType extends ComponentPropType,\n Visibility extends PropVisibility,\n> = {\n type: 'function';\n visibility: Visibility;\n renderProps: Shape;\n childrenType: ChildrenType;\n};\n\ntype StringWrappedPropState<Visibility extends PropVisibility> =\n PrimitiveWrappedPropState<'string', Visibility, string | undefined>;\ntype NumberWrappedPropState<Visibility extends PropVisibility> =\n PrimitiveWrappedPropState<'number', Visibility, number | undefined>;\ntype BooleanWrappedPropState<Visibility extends PropVisibility> =\n PrimitiveWrappedPropState<'boolean', Visibility, boolean | undefined>;\ntype LiteralWrappedPropState<\n Value,\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> = PrimitiveWrappedPropState<Type, Visibility, Value>;\ntype EnumWrappedPropState<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> = PrimitiveWrappedPropState<Type, Visibility, never>;\n\ntype WrappedPropState<Prop extends AnyBaseProp> =\n Prop extends StringProp<infer Visibility>\n ? StringWrappedPropState<Visibility>\n : Prop extends NumberProp<infer Visibility>\n ? NumberWrappedPropState<Visibility>\n : Prop extends BooleanProp<infer Visibility>\n ? BooleanWrappedPropState<Visibility>\n : Prop extends LiteralProp<infer Value, infer Type, infer Visibility>\n ? LiteralWrappedPropState<Value, Type, Visibility>\n : Prop extends EnumProp<infer _Values, infer Type, infer Visibility>\n ? EnumWrappedPropState<Type, Visibility>\n : Prop extends ObjectProp<infer Shape, infer Visibility>\n ? ObjectWrappedPropState<Shape, Visibility>\n : Prop extends ComponentPropWithPropertiesProp<\n infer Type,\n infer Shape,\n infer Visibility\n >\n ? ComponentWithPropsWrappedPropState<Type, Shape, Visibility>\n : Prop extends ComponentProp<infer Type, infer Visibility>\n ? { type: Type; visibility: Visibility }\n : Prop extends UnionProp<infer Members, infer Visibility>\n ? UnionWrappedPropState<Members, Visibility>\n : Prop extends RenderChildrenProp<\n infer Shape,\n infer ChildrenType,\n infer Visibility\n >\n ? RenderChildrenWrappedPropState<\n Shape,\n ChildrenType,\n Visibility\n >\n : never;\n\ntype ConfiguredWrappedProp<\n Prop extends AnyBaseProp,\n Config extends PropConfig,\n> = ((value: unknown) => ReturnType<Prop['validate']>) &\n WrappedPropState<Prop> & {\n _baseProp: Prop;\n config: Config;\n };\n\nexport type WrappedProp<Prop extends AnyBaseProp> = ((\n value: unknown,\n) => ReturnType<Prop['validate']>) &\n WrappedPropState<Prop> &\n WrappedPropChainMembers<Prop> & {\n _baseProp: Prop;\n or<Other extends AnyBaseProp>(other: {\n _baseProp: Other;\n }): WrappedProp<UnionProp<readonly [Prop, Other], ExtractVisibility<Prop>>>;\n };\n\nexport type LiteralWrappedProp<\n Value extends PrimitiveTypesMap[Type],\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> = WrappedProp<LiteralProp<Value, Type, Visibility>>;\n\nexport type EnumWrappedProp<\n Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> = WrappedProp<EnumProp<Values, Type, Visibility>>;\n\ntype WrapperFor = 'literal' | 'enum';\n\ntype GetValueForWrapper<\n Type extends PrimitivePropType,\n For extends WrapperFor,\n Value extends PrimitiveTypesMap[Type],\n> = For extends 'literal'\n ? Value\n : For extends 'enum'\n ? NonEmptyReadonlyArray<Value>\n : never;\n\ntype WrappedPropFor<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n For extends WrapperFor,\n Value extends PrimitiveTypesMap[Type],\n> = For extends 'literal'\n ? LiteralWrappedProp<Value, Type, Visibility>\n : For extends 'enum'\n ? EnumWrappedProp<NonEmptyReadonlyArray<Value>, Type, Visibility>\n : never;\n\ntype CreateWrappedProp<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n For extends WrapperFor,\n> = <Value extends PrimitiveTypesMap[Type]>(\n value: GetValueForWrapper<Type, For, Value>,\n) => WrappedPropFor<Type, Visibility, For, Value>;\n\ntype WrappedPropBuilder<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n Prop extends AnyBaseProp,\n OptionalProp extends AnyBaseProp,\n> = ConfigChain<Prop> &\n OptionalChain<Visibility, OptionalProp> & {\n literal: CreateWrappedProp<Type, Visibility, 'literal'>;\n enum: CreateWrappedProp<Type, Visibility, 'enum'>;\n };\n\ntype PrimitivePropTypeMap<Visibility extends PropVisibility> = {\n string: WrappedPropBuilder<\n 'string',\n Visibility,\n StringProp<Visibility>,\n StringProp<'optional'>\n >;\n number: WrappedPropBuilder<\n 'number',\n Visibility,\n NumberProp<Visibility>,\n NumberProp<'optional'>\n >;\n boolean: WrappedPropBuilder<\n 'boolean',\n Visibility,\n BooleanProp<Visibility>,\n BooleanProp<'optional'>\n >;\n};\n\ntype WrappedPrimitiveProp<Prop> =\n Prop extends BaseProp<\n infer Type extends PrimitivePropType,\n infer Visibility extends PropVisibility\n >\n ? PrimitivePropTypeMap<Visibility>[Type]\n : never;\n\ntype ConfigChainBuilder<\n Prop extends AnyBaseProp,\n Visibility extends PropVisibility,\n OptionalProp extends AnyBaseProp,\n> = ConfigChain<Prop> & OptionalChain<Visibility, OptionalProp>;\n\ntype WrappedSpecialProp<Prop> =\n Prop extends LiteralProp<infer Value, infer Type, infer Visibility>\n ? ConfigChainBuilder<\n LiteralProp<Value, Type, Visibility>,\n Visibility,\n LiteralProp<Value, Type, 'optional'>\n >\n : Prop extends EnumProp<infer Values, infer Type, infer Visibility>\n ? ConfigChainBuilder<\n EnumProp<Values, Type, Visibility>,\n Visibility,\n EnumProp<Values, Type, 'optional'>\n >\n : never;\n\ntype WrappedObjectProp<Prop> =\n Prop extends ObjectProp<infer Shape, infer Visibility>\n ? OptionalChain<Visibility, ObjectProp<Shape, 'optional'>>\n : never;\n\ntype WrappedComponentWithPropsProp<Prop> =\n Prop extends ComponentPropWithPropertiesProp<\n infer Type,\n infer Shape,\n infer Visibility\n >\n ? OptionalChain<\n Visibility,\n ComponentPropWithPropertiesProp<Type, Shape, 'optional'>\n >\n : never;\n\ntype WrappedUnionProp<Prop> =\n Prop extends UnionProp<infer Members, infer Visibility>\n ? OptionalChain<Visibility, UnionProp<Members, 'optional'>>\n : never;\n\ntype WrappedPropChainMembers<Prop extends AnyBaseProp> = [\n WrappedSpecialProp<Prop>,\n] extends [never]\n ? [WrappedObjectProp<Prop>] extends [never]\n ? [WrappedComponentWithPropsProp<Prop>] extends [never]\n ? [WrappedUnionProp<Prop>] extends [never]\n ? [WrappedPrimitiveProp<Prop>] extends [never]\n ? {}\n : WrappedPrimitiveProp<Prop>\n : WrappedUnionProp<Prop>\n : WrappedComponentWithPropsProp<Prop>\n : WrappedObjectProp<Prop>\n : WrappedSpecialProp<Prop>;\n\nexport type EnumValueDefinition<\n Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\n Type extends PrimitivePropType,\n Visibility extends PropVisibility = 'required',\n> = WrappedProp<EnumProp<Values, Type, Visibility>>;\n\nexport type ObjectValueDefinition<\n Shape extends BuiltPropShape,\n Visibility extends PropVisibility = 'required',\n> = WrappedProp<ObjectProp<Shape, Visibility>>;\n\ntype PrimitivePropInstanceMap<Visibility extends PropVisibility> = {\n string: WrappedProp<StringProp<Visibility>>;\n number: WrappedProp<NumberProp<Visibility>>;\n boolean: WrappedProp<BooleanProp<Visibility>>;\n};\n\ntype PrimitiveBasePropInstanceMap<Visibility extends PropVisibility> = {\n string: StringProp<Visibility>;\n number: NumberProp<Visibility>;\n boolean: BooleanProp<Visibility>;\n};\n\ntype LiteralPropBuilder<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility = 'required',\n> = <const Value extends PrimitiveTypesMap[Type]>(\n value: Value,\n) => LiteralWrappedProp<Value, Type, Visibility>;\n\ntype EnumPropBuilder<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility = 'required',\n> = <const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>>(\n values: Values,\n) => EnumWrappedProp<Values, Type, Visibility>;\n\ntype PrimitivePropBuilder<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility = 'required',\n> = (() => PrimitivePropInstanceMap<Visibility>[Type]) & {\n literal: LiteralPropBuilder<Type, Visibility>;\n enum: EnumPropBuilder<Type, Visibility>;\n config<const Config extends PropConfig>(\n config: Config,\n ): ConfiguredWrappedProp<\n PrimitiveBasePropInstanceMap<Visibility>[Type],\n Config\n >;\n} & (Visibility extends 'required'\n ? { optional(): PrimitivePropBuilder<Type, 'optional'> }\n : {});\n\nfunction createConfiguredWrappedProp<\n Prop extends AnyBaseProp,\n const Config extends PropConfig,\n>(prop: Prop, config: Config): ConfiguredWrappedProp<Prop, Config> {\n const validate = ((value: unknown) =>\n prop.validate(value)) as ConfiguredWrappedProp<Prop, Config>;\n\n return Object.assign(validate, getPropState(prop), {\n _baseProp: prop,\n config,\n });\n}\n\nfunction getPropState<Prop extends AnyBaseProp>(\n prop: Prop,\n): WrappedPropState<Prop> {\n const state = {\n type: prop.type,\n visibility: prop.visibility,\n } as Record<string, unknown>;\n\n if ('value' in prop && prop.value !== undefined) {\n state.value = prop.value;\n }\n\n if (\n prop instanceof ObjectProp ||\n prop instanceof ComponentPropWithPropertiesProp\n ) {\n state.properties = prop.properties;\n }\n\n if (prop instanceof UnionProp) {\n state.members = prop.members;\n }\n\n if (prop instanceof RenderChildrenProp) {\n state.renderProps = prop.renderProps;\n state.childrenType = prop.childrenType;\n }\n\n return state as WrappedPropState<Prop>;\n}\n\nfunction flattenUnionMembers(prop: AnyBaseProp): AnyBaseProp[] {\n return prop instanceof UnionProp\n ? [...(prop.members as AnyBaseProp[])]\n : [prop];\n}\n\nfunction wrapProp<Prop extends AnyBaseProp>(prop: Prop): WrappedProp<Prop> {\n const validate = ((value: unknown) =>\n prop.validate(value)) as WrappedProp<Prop>;\n const chainedProps = getPropState(prop) as Record<string, unknown>;\n const methodNames = ['optional', 'literal', 'enum', 'config'] as const;\n\n for (const methodName of methodNames) {\n const method = (prop as Record<string, unknown>)[methodName];\n\n if (typeof method === 'function') {\n if (methodName === 'config') {\n chainedProps.config = <const Config extends PropConfig>(\n config: Config,\n ) => createConfiguredWrappedProp(prop, config);\n continue;\n }\n\n chainedProps[methodName] = (...args: unknown[]) => {\n const nextProp = (\n method as (...methodArgs: unknown[]) => AnyBaseProp\n ).apply(prop, args);\n\n return wrapProp(nextProp);\n };\n }\n }\n\n chainedProps._baseProp = prop;\n chainedProps.or = (other: WrappedProp<AnyBaseProp>) => {\n const otherBase = (other as unknown as Record<string, unknown>)\n ._baseProp as AnyBaseProp;\n const members = [\n ...flattenUnionMembers(prop),\n ...flattenUnionMembers(otherBase),\n ] as never;\n return wrapProp(new UnionProp(members, prop.visibility));\n };\n\n return Object.assign(validate, chainedProps);\n}\n\nfunction createPrimitiveProp<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n>(\n type: Type,\n visibility: Visibility,\n): PrimitiveBasePropInstanceMap<Visibility>[Type] {\n switch (type) {\n case 'string':\n return new StringProp(\n visibility,\n ) as unknown as PrimitiveBasePropInstanceMap<Visibility>[Type];\n case 'number':\n return new NumberProp(\n visibility,\n ) as unknown as PrimitiveBasePropInstanceMap<Visibility>[Type];\n case 'boolean':\n return new BooleanProp(\n visibility,\n ) as unknown as PrimitiveBasePropInstanceMap<Visibility>[Type];\n }\n}\n\nfunction createWrappedProp<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n>(type: Type, visibility: Visibility) {\n return <For extends WrapperFor>(wrapperFor: For) =>\n <Value extends PrimitiveTypesMap[Type]>(\n value: GetValueForWrapper<Type, For, Value>,\n ) => {\n if (wrapperFor === 'literal') {\n return wrapProp(\n new LiteralProp(value as never, type, visibility),\n ) as unknown as WrappedPropFor<Type, Visibility, For, Value>;\n }\n\n if (wrapperFor === 'enum') {\n return wrapProp(\n new EnumProp(value as never, type, visibility),\n ) as unknown as WrappedPropFor<Type, Visibility, For, Value>;\n }\n\n throw new Error(`Invalid wrapper for: ${wrapperFor}`);\n };\n}\n\nexport function createPrimitivePropBuilder<\n Type extends PrimitivePropType,\n Visibility extends PropVisibility = 'required',\n>(\n type: Type,\n visibility = 'required' as Visibility,\n): PrimitivePropBuilder<Type, Visibility> {\n const propWrapper = createWrappedProp(type, visibility);\n const builder = (() =>\n wrapProp(\n createPrimitiveProp(type, visibility),\n )) as unknown as PrimitivePropBuilder<Type, Visibility>;\n\n return Object.assign(builder, {\n literal: propWrapper('literal'),\n enum: propWrapper('enum'),\n config: <const Config extends PropConfig>(config: Config) =>\n createConfiguredWrappedProp(\n createPrimitiveProp(type, visibility),\n config,\n ),\n ...(visibility === 'required'\n ? { optional: () => createPrimitivePropBuilder(type, 'optional') }\n : {}),\n }) as unknown as PrimitivePropBuilder<Type, Visibility>;\n}\n\nfunction createObjectProp<const Shape extends BuiltPropShape>(\n properties: Shape,\n): ObjectValueDefinition<Shape, 'required'> {\n return wrapProp(new ObjectProp(properties, 'required'));\n}\n\ntype ChildrenPropFor<\n ChildrenType extends ComponentPropType,\n ChildrenVisibility extends PropVisibility,\n RenderProps extends BuiltPropShape | undefined,\n> = (RenderProps extends BuiltPropShape\n ? WrappedProp<\n RenderChildrenProp<RenderProps, ChildrenType, ChildrenVisibility>\n >\n : WrappedProp<ComponentProp<ChildrenType, ChildrenVisibility>>) &\n AnyBuiltPropDefinition;\n\ntype WithChildrenShape<\n Shape extends BuiltPropShape,\n ChildrenProp extends AnyBuiltPropDefinition,\n> = Shape & { children: ChildrenProp };\n\ntype WithChildrenOptions<\n ChildrenType extends ComponentPropType,\n ChildrenVisibility extends PropVisibility,\n RenderProps extends BuiltPropShape | undefined,\n> = {\n type?: ChildrenType;\n visibility?: ChildrenVisibility;\n props?: RenderProps;\n};\n\nexport type ComponentPropWithChildrenBuilder<\n Type extends ComponentPropType,\n Visibility extends PropVisibility,\n ChildrenProp extends AnyBuiltPropDefinition,\n> = ((value: unknown) => void) & {\n _baseProp: ComponentPropWithPropertiesProp<\n Type,\n { children: ChildrenProp },\n Visibility\n >;\n type: Type;\n visibility: Visibility;\n props<const Shape extends BuiltPropShape>(\n shape: Shape,\n ): WrappedProp<\n ComponentPropWithPropertiesProp<\n Type,\n WithChildrenShape<Shape, ChildrenProp>,\n Visibility\n >\n >;\n or<Other extends AnyBaseProp>(other: {\n _baseProp: Other;\n }): WrappedProp<\n UnionProp<\n readonly [\n ComponentPropWithPropertiesProp<\n Type,\n { children: ChildrenProp },\n Visibility\n >,\n Other,\n ],\n Visibility\n >\n >;\n} & (Visibility extends 'required'\n ? {\n optional(): ComponentPropWithChildrenBuilder<\n Type,\n 'optional',\n ChildrenProp\n >;\n }\n : {});\n\nexport type ComponentPropBuilder<\n Type extends ComponentPropType,\n Visibility extends PropVisibility = 'required',\n> = ((value: unknown) => void) & {\n _baseProp: ComponentProp<Type, Visibility>;\n type: Type;\n visibility: Visibility;\n props<const Shape extends BuiltPropShape>(\n shape: Shape,\n ): WrappedProp<ComponentPropWithPropertiesProp<Type, Shape, Visibility>>;\n config<const Config extends PropConfig>(\n config: Config,\n ): ConfiguredWrappedProp<ComponentProp<Type, Visibility>, Config>;\n withChildren<\n ChildrenType extends ComponentPropType = 'ReactNode',\n ChildrenVisibility extends PropVisibility = 'optional',\n const RenderProps extends BuiltPropShape | undefined = undefined,\n >(\n options?: WithChildrenOptions<\n ChildrenType,\n ChildrenVisibility,\n RenderProps\n >,\n ): ComponentPropWithChildrenBuilder<\n Type,\n Visibility,\n ChildrenPropFor<ChildrenType, ChildrenVisibility, RenderProps>\n >;\n or<Other extends AnyBaseProp>(other: {\n _baseProp: Other;\n }): WrappedProp<\n UnionProp<readonly [ComponentProp<Type, Visibility>, Other], Visibility>\n >;\n} & (Visibility extends 'required'\n ? { optional(): ComponentPropBuilder<Type, 'optional'> }\n : {});\n\nfunction createComponentPropWithChildrenBuilder<\n Type extends ComponentPropType,\n Visibility extends PropVisibility,\n ChildrenProp extends AnyBuiltPropDefinition,\n>(\n type: Type,\n visibility: Visibility,\n childrenProp: ChildrenProp,\n): ComponentPropWithChildrenBuilder<Type, Visibility, ChildrenProp> {\n const baseProp = new ComponentPropWithPropertiesProp(\n type,\n { children: childrenProp },\n visibility,\n );\n const validate = ((value: unknown) =>\n baseProp.validate(value)) as unknown as ComponentPropWithChildrenBuilder<\n Type,\n Visibility,\n ChildrenProp\n >;\n\n return Object.assign(validate, {\n _baseProp: baseProp,\n type,\n visibility,\n props: <const Shape extends BuiltPropShape>(shape: Shape) =>\n wrapProp(\n new ComponentPropWithPropertiesProp(\n type,\n { ...shape, children: childrenProp },\n visibility,\n ),\n ),\n or: (other: { _baseProp: AnyBaseProp }) => {\n const members = [\n baseProp,\n ...flattenUnionMembers(other._baseProp),\n ] as never;\n return wrapProp(new UnionProp(members, baseProp.visibility));\n },\n ...(visibility === 'required'\n ? {\n optional: () =>\n createComponentPropWithChildrenBuilder(\n type,\n 'optional' as const,\n childrenProp,\n ),\n }\n : {}),\n }) as unknown as ComponentPropWithChildrenBuilder<\n Type,\n Visibility,\n ChildrenProp\n >;\n}\n\nfunction buildChildrenProp<\n ChildrenType extends ComponentPropType,\n ChildrenVisibility extends PropVisibility,\n RenderProps extends BuiltPropShape | undefined,\n>(\n childrenType: ChildrenType,\n childrenVisibility: ChildrenVisibility,\n renderProps: RenderProps,\n): ChildrenPropFor<ChildrenType, ChildrenVisibility, RenderProps> {\n if (renderProps !== undefined) {\n return wrapProp(\n new RenderChildrenProp(renderProps, childrenType, childrenVisibility),\n ) as unknown as ChildrenPropFor<\n ChildrenType,\n ChildrenVisibility,\n RenderProps\n >;\n }\n\n return wrapProp(\n new ComponentProp(childrenType, childrenVisibility),\n ) as unknown as ChildrenPropFor<\n ChildrenType,\n ChildrenVisibility,\n RenderProps\n >;\n}\n\nfunction createComponentPropBuilder<\n Type extends ComponentPropType,\n Visibility extends PropVisibility = 'required',\n>(\n type: Type,\n visibility = 'required' as Visibility,\n): ComponentPropBuilder<Type, Visibility> {\n const prop = new ComponentProp(type, visibility);\n const validate = ((value: unknown) =>\n prop.validate(value)) as ComponentPropBuilder<Type, Visibility>;\n\n return Object.assign(validate, {\n type,\n visibility,\n _baseProp: prop,\n props: <const Shape extends BuiltPropShape>(shape: Shape) =>\n wrapProp(new ComponentPropWithPropertiesProp(type, shape, visibility)),\n config: <const Config extends PropConfig>(config: Config) =>\n createConfiguredWrappedProp(prop, config),\n withChildren: <\n ChildrenType extends ComponentPropType = 'ReactNode',\n ChildrenVisibility extends PropVisibility = 'optional',\n const RenderProps extends BuiltPropShape | undefined = undefined,\n >(\n options?: WithChildrenOptions<\n ChildrenType,\n ChildrenVisibility,\n RenderProps\n >,\n ) => {\n const childrenType = (options?.type ?? 'ReactNode') as ChildrenType;\n const childrenVisibility = (options?.visibility ??\n 'optional') as ChildrenVisibility;\n const renderProps = (options?.props ?? undefined) as RenderProps;\n return createComponentPropWithChildrenBuilder(\n type,\n visibility,\n buildChildrenProp(childrenType, childrenVisibility, renderProps),\n );\n },\n or: (other: { _baseProp: AnyBaseProp }) => {\n const members = [prop, ...flattenUnionMembers(other._baseProp)] as never;\n return wrapProp(new UnionProp(members, prop.visibility));\n },\n ...(visibility === 'required'\n ? { optional: () => createComponentPropBuilder(type, 'optional') }\n : {}),\n }) as unknown as ComponentPropBuilder<Type, Visibility>;\n}\n\nexport const createProp = {\n string: createPrimitivePropBuilder('string'),\n number: createPrimitivePropBuilder('number'),\n boolean: createPrimitivePropBuilder('boolean'),\n object: createObjectProp,\n component: <Type extends ComponentPropType>(options: { type: Type }) =>\n createComponentPropBuilder(options.type),\n};\n"],"mappings":"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"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const require_base = require('./base.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/validators/component.ts
|
|
4
|
-
var ComponentProp = class ComponentProp extends require_base.BaseProp {
|
|
5
|
-
constructor(type, visibility) {
|
|
6
|
-
super({
|
|
7
|
-
type,
|
|
8
|
-
visibility
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
optional() {
|
|
12
|
-
return new ComponentProp(this.type, "optional");
|
|
13
|
-
}
|
|
14
|
-
validate(value) {
|
|
15
|
-
if (this.type === "JSX.Element") {
|
|
16
|
-
if (value === null || typeof value !== "object" || !("$$typeof" in value)) throw this.error;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
allows(value) {
|
|
20
|
-
if (this.type === "JSX.Element") return value !== null && typeof value === "object" && "$$typeof" in value;
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var ComponentPropWithPropertiesProp = class ComponentPropWithPropertiesProp extends require_base.BaseProp {
|
|
25
|
-
properties;
|
|
26
|
-
constructor(type, properties, visibility) {
|
|
27
|
-
super({
|
|
28
|
-
type,
|
|
29
|
-
visibility
|
|
30
|
-
});
|
|
31
|
-
this.properties = properties;
|
|
32
|
-
}
|
|
33
|
-
optional() {
|
|
34
|
-
return new ComponentPropWithPropertiesProp(this.type, this.properties, "optional");
|
|
35
|
-
}
|
|
36
|
-
validate(value) {
|
|
37
|
-
if (this.type === "JSX.Element") {
|
|
38
|
-
if (value === null || typeof value !== "object" || !("$$typeof" in value)) throw this.error;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
allows(value) {
|
|
42
|
-
if (this.type === "JSX.Element") return value !== null && typeof value === "object" && "$$typeof" in value;
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var RenderChildrenProp = class RenderChildrenProp extends require_base.BaseProp {
|
|
47
|
-
renderProps;
|
|
48
|
-
childrenType;
|
|
49
|
-
constructor(renderProps, childrenType, visibility) {
|
|
50
|
-
super({
|
|
51
|
-
type: "function",
|
|
52
|
-
visibility
|
|
53
|
-
});
|
|
54
|
-
this.renderProps = renderProps;
|
|
55
|
-
this.childrenType = childrenType;
|
|
56
|
-
}
|
|
57
|
-
optional() {
|
|
58
|
-
return new RenderChildrenProp(this.renderProps, this.childrenType, "optional");
|
|
59
|
-
}
|
|
60
|
-
validate(value) {
|
|
61
|
-
if (typeof value !== "function") throw this.error;
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
allows(value) {
|
|
65
|
-
return typeof value === "function";
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
exports.ComponentProp = ComponentProp;
|
|
71
|
-
exports.ComponentPropWithPropertiesProp = ComponentPropWithPropertiesProp;
|
|
72
|
-
exports.RenderChildrenProp = RenderChildrenProp;
|
|
73
|
-
//# sourceMappingURL=component.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.cjs","names":["BaseProp"],"sources":["../../src/validators/component.ts"],"sourcesContent":["import type {\n BuiltPropShape,\n ComponentPropType,\n ComponentPropTypeMap,\n PropVisibility,\n ResolvedBuiltPropShape,\n} from './types';\nimport { BaseProp } from './base';\n\nexport class ComponentProp<\n Type extends ComponentPropType,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {\n constructor(type: Type, visibility: Visibility) {\n super({ type, visibility });\n }\n\n optional(this: ComponentProp<Type, 'required'>) {\n return new ComponentProp(this.type, 'optional');\n }\n\n validate(value: unknown) {\n if (this.type === 'JSX.Element') {\n if (\n value === null ||\n typeof value !== 'object' ||\n !('$$typeof' in value)\n ) {\n throw this.error;\n }\n }\n }\n\n allows(value: unknown): value is ComponentPropTypeMap[Type] {\n if (this.type === 'JSX.Element') {\n return value !== null && typeof value === 'object' && '$$typeof' in value;\n }\n\n return true;\n }\n}\n\nexport class ComponentPropWithPropertiesProp<\n Type extends ComponentPropType,\n const Shape extends BuiltPropShape,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {\n readonly properties: Shape;\n\n constructor(type: Type, properties: Shape, visibility: Visibility) {\n super({ type, visibility });\n this.properties = properties;\n }\n\n optional(this: ComponentPropWithPropertiesProp<Type, Shape, 'required'>) {\n return new ComponentPropWithPropertiesProp(\n this.type,\n this.properties,\n 'optional',\n );\n }\n\n validate(value: unknown) {\n if (this.type === 'JSX.Element') {\n if (\n value === null ||\n typeof value !== 'object' ||\n !('$$typeof' in value)\n ) {\n throw this.error;\n }\n }\n }\n\n allows(value: unknown): value is ComponentPropTypeMap[Type] {\n if (this.type === 'JSX.Element') {\n return value !== null && typeof value === 'object' && '$$typeof' in value;\n }\n\n return true;\n }\n}\n\nexport class RenderChildrenProp<\n const Shape extends BuiltPropShape,\n ChildrenType extends ComponentPropType,\n Visibility extends PropVisibility,\n> extends BaseProp<\n 'function',\n Visibility,\n (\n renderProps: ResolvedBuiltPropShape<Shape>,\n ) => ComponentPropTypeMap[ChildrenType]\n> {\n readonly renderProps: Shape;\n readonly childrenType: ChildrenType;\n\n constructor(\n renderProps: Shape,\n childrenType: ChildrenType,\n visibility: Visibility,\n ) {\n super({ type: 'function', visibility });\n this.renderProps = renderProps;\n this.childrenType = childrenType;\n }\n\n optional(this: RenderChildrenProp<Shape, ChildrenType, 'required'>) {\n return new RenderChildrenProp(\n this.renderProps,\n this.childrenType,\n 'optional',\n );\n }\n\n validate(value: unknown) {\n if (typeof value !== 'function') {\n throw this.error;\n }\n\n return value as (\n renderProps: ResolvedBuiltPropShape<Shape>,\n ) => ComponentPropTypeMap[ChildrenType];\n }\n\n allows(\n value: unknown,\n ): value is (\n renderProps: ResolvedBuiltPropShape<Shape>,\n ) => ComponentPropTypeMap[ChildrenType] {\n return typeof value === 'function';\n }\n}\n"],"mappings":";;;AASA,IAAa,gBAAb,MAAa,sBAGHA,sBAAuD;CAC/D,YAAY,MAAY,YAAwB;EAC9C,MAAM;GAAE;GAAM;EAAW,CAAC;CAC5B;CAEA,WAAgD;EAC9C,OAAO,IAAI,cAAc,KAAK,MAAM,UAAU;CAChD;CAEA,SAAS,OAAgB;EACvB,IAAI,KAAK,SAAS,eAChB;OACE,UAAU,QACV,OAAO,UAAU,YACjB,EAAE,cAAc,QAEhB,MAAM,KAAK;EACb;CAEJ;CAEA,OAAO,OAAqD;EAC1D,IAAI,KAAK,SAAS,eAChB,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,cAAc;EAGtE,OAAO;CACT;AACF;AAEA,IAAa,kCAAb,MAAa,wCAIHA,sBAAuD;CAC/D,AAAS;CAET,YAAY,MAAY,YAAmB,YAAwB;EACjE,MAAM;GAAE;GAAM;EAAW,CAAC;EAC1B,KAAK,aAAa;CACpB;CAEA,WAAyE;EACvE,OAAO,IAAI,gCACT,KAAK,MACL,KAAK,YACL,UACF;CACF;CAEA,SAAS,OAAgB;EACvB,IAAI,KAAK,SAAS,eAChB;OACE,UAAU,QACV,OAAO,UAAU,YACjB,EAAE,cAAc,QAEhB,MAAM,KAAK;EACb;CAEJ;CAEA,OAAO,OAAqD;EAC1D,IAAI,KAAK,SAAS,eAChB,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,cAAc;EAGtE,OAAO;CACT;AACF;AAEA,IAAa,qBAAb,MAAa,2BAIHA,sBAMR;CACA,AAAS;CACT,AAAS;CAET,YACE,aACA,cACA,YACA;EACA,MAAM;GAAE,MAAM;GAAY;EAAW,CAAC;EACtC,KAAK,cAAc;EACnB,KAAK,eAAe;CACtB;CAEA,WAAoE;EAClE,OAAO,IAAI,mBACT,KAAK,aACL,KAAK,cACL,UACF;CACF;CAEA,SAAS,OAAgB;EACvB,IAAI,OAAO,UAAU,YACnB,MAAM,KAAK;EAGb,OAAO;CAGT;CAEA,OACE,OAGsC;EACtC,OAAO,OAAO,UAAU;CAC1B;AACF"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { BuiltPropShape, ComponentPropType, ComponentPropTypeMap, PropVisibility, ResolvedBuiltPropShape } from "./types.cjs";
|
|
2
|
-
import { BaseProp } from "./base.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/component.d.ts
|
|
5
|
-
declare class ComponentProp<Type extends ComponentPropType, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {
|
|
6
|
-
constructor(type: Type, visibility: Visibility);
|
|
7
|
-
optional(this: ComponentProp<Type, 'required'>): ComponentProp<Type, "optional">;
|
|
8
|
-
validate(value: unknown): void;
|
|
9
|
-
allows(value: unknown): value is ComponentPropTypeMap[Type];
|
|
10
|
-
}
|
|
11
|
-
declare class ComponentPropWithPropertiesProp<Type extends ComponentPropType, const Shape extends BuiltPropShape, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {
|
|
12
|
-
readonly properties: Shape;
|
|
13
|
-
constructor(type: Type, properties: Shape, visibility: Visibility);
|
|
14
|
-
optional(this: ComponentPropWithPropertiesProp<Type, Shape, 'required'>): ComponentPropWithPropertiesProp<Type, Shape, "optional">;
|
|
15
|
-
validate(value: unknown): void;
|
|
16
|
-
allows(value: unknown): value is ComponentPropTypeMap[Type];
|
|
17
|
-
}
|
|
18
|
-
declare class RenderChildrenProp<const Shape extends BuiltPropShape, ChildrenType extends ComponentPropType, Visibility extends PropVisibility> extends BaseProp<'function', Visibility, (renderProps: ResolvedBuiltPropShape<Shape>) => ComponentPropTypeMap[ChildrenType]> {
|
|
19
|
-
readonly renderProps: Shape;
|
|
20
|
-
readonly childrenType: ChildrenType;
|
|
21
|
-
constructor(renderProps: Shape, childrenType: ChildrenType, visibility: Visibility);
|
|
22
|
-
optional(this: RenderChildrenProp<Shape, ChildrenType, 'required'>): RenderChildrenProp<Shape, ChildrenType, "optional">;
|
|
23
|
-
validate(value: unknown): (renderProps: ResolvedBuiltPropShape<Shape>) => ComponentPropTypeMap[ChildrenType];
|
|
24
|
-
allows(value: unknown): value is (renderProps: ResolvedBuiltPropShape<Shape>) => ComponentPropTypeMap[ChildrenType];
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { ComponentProp, ComponentPropWithPropertiesProp, RenderChildrenProp };
|
|
28
|
-
//# sourceMappingURL=component.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.cts","names":[],"sources":["../../src/validators/component.ts"],"mappings":";;;;cASa,aAAA,cACE,iBAAA,qBACM,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,oBAAA,CAAqB,IAAA;cAC5C,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,UAAA;EAIpC,QAAA,CAAS,IAAA,EAAM,aAAA,CAAc,IAAA,gBAAiB,aAAA,CAAA,IAAA;EAI9C,QAAA,CAAS,KAAA;EAYT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,oBAAA,CAAqB,IAAA;AAAA;AAAA,cAS3C,+BAAA,cACE,iBAAA,sBACO,cAAA,qBACD,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,oBAAA,CAAqB,IAAA;EAAA,SAC/C,UAAA,EAAY,KAAA;cAET,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,KAAA,EAAO,UAAA,EAAY,UAAA;EAKvD,QAAA,CAAS,IAAA,EAAM,+BAAA,CAAgC,IAAA,EAAM,KAAA,gBAAkB,+BAAA,CAAA,IAAA,EAAA,KAAA;EAQvE,QAAA,CAAS,KAAA;EAYT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,oBAAA,CAAqB,IAAA;AAAA;AAAA,cAS3C,kBAAA,qBACS,cAAA,uBACC,iBAAA,qBACF,cAAA,UACX,QAAA,aAER,UAAA,GAEE,WAAA,EAAa,sBAAA,CAAuB,KAAA,MACjC,oBAAA,CAAqB,YAAA;EAAA,SAEjB,WAAA,EAAa,KAAA;EAAA,SACb,YAAA,EAAc,YAAA;cAGrB,WAAA,EAAa,KAAA,EACb,YAAA,EAAc,YAAA,EACd,UAAA,EAAY,UAAA;EAOd,QAAA,CAAS,IAAA,EAAM,kBAAA,CAAmB,KAAA,EAAO,YAAA,gBAAyB,kBAAA,CAAA,KAAA,EAAA,YAAA;EAQlE,QAAA,CAAS,KAAA,aAML,WAAA,EAAa,sBAAA,CAAuB,KAAA,MACjC,oBAAA,CAAqB,YAAA;EAG5B,MAAA,CACE,KAAA,YACC,KAAA,KACD,WAAA,EAAa,sBAAA,CAAuB,KAAA,MACjC,oBAAA,CAAqB,YAAA;AAAA"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { BuiltPropShape, ComponentPropType, ComponentPropTypeMap, PropVisibility, ResolvedBuiltPropShape } from "./types.mjs";
|
|
2
|
-
import { BaseProp } from "./base.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/component.d.ts
|
|
5
|
-
declare class ComponentProp<Type extends ComponentPropType, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {
|
|
6
|
-
constructor(type: Type, visibility: Visibility);
|
|
7
|
-
optional(this: ComponentProp<Type, 'required'>): ComponentProp<Type, "optional">;
|
|
8
|
-
validate(value: unknown): void;
|
|
9
|
-
allows(value: unknown): value is ComponentPropTypeMap[Type];
|
|
10
|
-
}
|
|
11
|
-
declare class ComponentPropWithPropertiesProp<Type extends ComponentPropType, const Shape extends BuiltPropShape, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {
|
|
12
|
-
readonly properties: Shape;
|
|
13
|
-
constructor(type: Type, properties: Shape, visibility: Visibility);
|
|
14
|
-
optional(this: ComponentPropWithPropertiesProp<Type, Shape, 'required'>): ComponentPropWithPropertiesProp<Type, Shape, "optional">;
|
|
15
|
-
validate(value: unknown): void;
|
|
16
|
-
allows(value: unknown): value is ComponentPropTypeMap[Type];
|
|
17
|
-
}
|
|
18
|
-
declare class RenderChildrenProp<const Shape extends BuiltPropShape, ChildrenType extends ComponentPropType, Visibility extends PropVisibility> extends BaseProp<'function', Visibility, (renderProps: ResolvedBuiltPropShape<Shape>) => ComponentPropTypeMap[ChildrenType]> {
|
|
19
|
-
readonly renderProps: Shape;
|
|
20
|
-
readonly childrenType: ChildrenType;
|
|
21
|
-
constructor(renderProps: Shape, childrenType: ChildrenType, visibility: Visibility);
|
|
22
|
-
optional(this: RenderChildrenProp<Shape, ChildrenType, 'required'>): RenderChildrenProp<Shape, ChildrenType, "optional">;
|
|
23
|
-
validate(value: unknown): (renderProps: ResolvedBuiltPropShape<Shape>) => ComponentPropTypeMap[ChildrenType];
|
|
24
|
-
allows(value: unknown): value is (renderProps: ResolvedBuiltPropShape<Shape>) => ComponentPropTypeMap[ChildrenType];
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { ComponentProp, ComponentPropWithPropertiesProp, RenderChildrenProp };
|
|
28
|
-
//# sourceMappingURL=component.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.mts","names":[],"sources":["../../src/validators/component.ts"],"mappings":";;;;cASa,aAAA,cACE,iBAAA,qBACM,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,oBAAA,CAAqB,IAAA;cAC5C,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,UAAA;EAIpC,QAAA,CAAS,IAAA,EAAM,aAAA,CAAc,IAAA,gBAAiB,aAAA,CAAA,IAAA;EAI9C,QAAA,CAAS,KAAA;EAYT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,oBAAA,CAAqB,IAAA;AAAA;AAAA,cAS3C,+BAAA,cACE,iBAAA,sBACO,cAAA,qBACD,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,oBAAA,CAAqB,IAAA;EAAA,SAC/C,UAAA,EAAY,KAAA;cAET,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,KAAA,EAAO,UAAA,EAAY,UAAA;EAKvD,QAAA,CAAS,IAAA,EAAM,+BAAA,CAAgC,IAAA,EAAM,KAAA,gBAAkB,+BAAA,CAAA,IAAA,EAAA,KAAA;EAQvE,QAAA,CAAS,KAAA;EAYT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,oBAAA,CAAqB,IAAA;AAAA;AAAA,cAS3C,kBAAA,qBACS,cAAA,uBACC,iBAAA,qBACF,cAAA,UACX,QAAA,aAER,UAAA,GAEE,WAAA,EAAa,sBAAA,CAAuB,KAAA,MACjC,oBAAA,CAAqB,YAAA;EAAA,SAEjB,WAAA,EAAa,KAAA;EAAA,SACb,YAAA,EAAc,YAAA;cAGrB,WAAA,EAAa,KAAA,EACb,YAAA,EAAc,YAAA,EACd,UAAA,EAAY,UAAA;EAOd,QAAA,CAAS,IAAA,EAAM,kBAAA,CAAmB,KAAA,EAAO,YAAA,gBAAyB,kBAAA,CAAA,KAAA,EAAA,YAAA;EAQlE,QAAA,CAAS,KAAA,aAML,WAAA,EAAa,sBAAA,CAAuB,KAAA,MACjC,oBAAA,CAAqB,YAAA;EAG5B,MAAA,CACE,KAAA,YACC,KAAA,KACD,WAAA,EAAa,sBAAA,CAAuB,KAAA,MACjC,oBAAA,CAAqB,YAAA;AAAA"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { BaseProp } from "./base.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/validators/component.ts
|
|
4
|
-
var ComponentProp = class ComponentProp extends BaseProp {
|
|
5
|
-
constructor(type, visibility) {
|
|
6
|
-
super({
|
|
7
|
-
type,
|
|
8
|
-
visibility
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
optional() {
|
|
12
|
-
return new ComponentProp(this.type, "optional");
|
|
13
|
-
}
|
|
14
|
-
validate(value) {
|
|
15
|
-
if (this.type === "JSX.Element") {
|
|
16
|
-
if (value === null || typeof value !== "object" || !("$$typeof" in value)) throw this.error;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
allows(value) {
|
|
20
|
-
if (this.type === "JSX.Element") return value !== null && typeof value === "object" && "$$typeof" in value;
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var ComponentPropWithPropertiesProp = class ComponentPropWithPropertiesProp extends BaseProp {
|
|
25
|
-
properties;
|
|
26
|
-
constructor(type, properties, visibility) {
|
|
27
|
-
super({
|
|
28
|
-
type,
|
|
29
|
-
visibility
|
|
30
|
-
});
|
|
31
|
-
this.properties = properties;
|
|
32
|
-
}
|
|
33
|
-
optional() {
|
|
34
|
-
return new ComponentPropWithPropertiesProp(this.type, this.properties, "optional");
|
|
35
|
-
}
|
|
36
|
-
validate(value) {
|
|
37
|
-
if (this.type === "JSX.Element") {
|
|
38
|
-
if (value === null || typeof value !== "object" || !("$$typeof" in value)) throw this.error;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
allows(value) {
|
|
42
|
-
if (this.type === "JSX.Element") return value !== null && typeof value === "object" && "$$typeof" in value;
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var RenderChildrenProp = class RenderChildrenProp extends BaseProp {
|
|
47
|
-
renderProps;
|
|
48
|
-
childrenType;
|
|
49
|
-
constructor(renderProps, childrenType, visibility) {
|
|
50
|
-
super({
|
|
51
|
-
type: "function",
|
|
52
|
-
visibility
|
|
53
|
-
});
|
|
54
|
-
this.renderProps = renderProps;
|
|
55
|
-
this.childrenType = childrenType;
|
|
56
|
-
}
|
|
57
|
-
optional() {
|
|
58
|
-
return new RenderChildrenProp(this.renderProps, this.childrenType, "optional");
|
|
59
|
-
}
|
|
60
|
-
validate(value) {
|
|
61
|
-
if (typeof value !== "function") throw this.error;
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
allows(value) {
|
|
65
|
-
return typeof value === "function";
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
export { ComponentProp, ComponentPropWithPropertiesProp, RenderChildrenProp };
|
|
71
|
-
//# sourceMappingURL=component.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.mjs","names":[],"sources":["../../src/validators/component.ts"],"sourcesContent":["import type {\n BuiltPropShape,\n ComponentPropType,\n ComponentPropTypeMap,\n PropVisibility,\n ResolvedBuiltPropShape,\n} from './types';\nimport { BaseProp } from './base';\n\nexport class ComponentProp<\n Type extends ComponentPropType,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {\n constructor(type: Type, visibility: Visibility) {\n super({ type, visibility });\n }\n\n optional(this: ComponentProp<Type, 'required'>) {\n return new ComponentProp(this.type, 'optional');\n }\n\n validate(value: unknown) {\n if (this.type === 'JSX.Element') {\n if (\n value === null ||\n typeof value !== 'object' ||\n !('$$typeof' in value)\n ) {\n throw this.error;\n }\n }\n }\n\n allows(value: unknown): value is ComponentPropTypeMap[Type] {\n if (this.type === 'JSX.Element') {\n return value !== null && typeof value === 'object' && '$$typeof' in value;\n }\n\n return true;\n }\n}\n\nexport class ComponentPropWithPropertiesProp<\n Type extends ComponentPropType,\n const Shape extends BuiltPropShape,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, ComponentPropTypeMap[Type]> {\n readonly properties: Shape;\n\n constructor(type: Type, properties: Shape, visibility: Visibility) {\n super({ type, visibility });\n this.properties = properties;\n }\n\n optional(this: ComponentPropWithPropertiesProp<Type, Shape, 'required'>) {\n return new ComponentPropWithPropertiesProp(\n this.type,\n this.properties,\n 'optional',\n );\n }\n\n validate(value: unknown) {\n if (this.type === 'JSX.Element') {\n if (\n value === null ||\n typeof value !== 'object' ||\n !('$$typeof' in value)\n ) {\n throw this.error;\n }\n }\n }\n\n allows(value: unknown): value is ComponentPropTypeMap[Type] {\n if (this.type === 'JSX.Element') {\n return value !== null && typeof value === 'object' && '$$typeof' in value;\n }\n\n return true;\n }\n}\n\nexport class RenderChildrenProp<\n const Shape extends BuiltPropShape,\n ChildrenType extends ComponentPropType,\n Visibility extends PropVisibility,\n> extends BaseProp<\n 'function',\n Visibility,\n (\n renderProps: ResolvedBuiltPropShape<Shape>,\n ) => ComponentPropTypeMap[ChildrenType]\n> {\n readonly renderProps: Shape;\n readonly childrenType: ChildrenType;\n\n constructor(\n renderProps: Shape,\n childrenType: ChildrenType,\n visibility: Visibility,\n ) {\n super({ type: 'function', visibility });\n this.renderProps = renderProps;\n this.childrenType = childrenType;\n }\n\n optional(this: RenderChildrenProp<Shape, ChildrenType, 'required'>) {\n return new RenderChildrenProp(\n this.renderProps,\n this.childrenType,\n 'optional',\n );\n }\n\n validate(value: unknown) {\n if (typeof value !== 'function') {\n throw this.error;\n }\n\n return value as (\n renderProps: ResolvedBuiltPropShape<Shape>,\n ) => ComponentPropTypeMap[ChildrenType];\n }\n\n allows(\n value: unknown,\n ): value is (\n renderProps: ResolvedBuiltPropShape<Shape>,\n ) => ComponentPropTypeMap[ChildrenType] {\n return typeof value === 'function';\n }\n}\n"],"mappings":";;;AASA,IAAa,gBAAb,MAAa,sBAGH,SAAuD;CAC/D,YAAY,MAAY,YAAwB;EAC9C,MAAM;GAAE;GAAM;EAAW,CAAC;CAC5B;CAEA,WAAgD;EAC9C,OAAO,IAAI,cAAc,KAAK,MAAM,UAAU;CAChD;CAEA,SAAS,OAAgB;EACvB,IAAI,KAAK,SAAS,eAChB;OACE,UAAU,QACV,OAAO,UAAU,YACjB,EAAE,cAAc,QAEhB,MAAM,KAAK;EACb;CAEJ;CAEA,OAAO,OAAqD;EAC1D,IAAI,KAAK,SAAS,eAChB,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,cAAc;EAGtE,OAAO;CACT;AACF;AAEA,IAAa,kCAAb,MAAa,wCAIH,SAAuD;CAC/D,AAAS;CAET,YAAY,MAAY,YAAmB,YAAwB;EACjE,MAAM;GAAE;GAAM;EAAW,CAAC;EAC1B,KAAK,aAAa;CACpB;CAEA,WAAyE;EACvE,OAAO,IAAI,gCACT,KAAK,MACL,KAAK,YACL,UACF;CACF;CAEA,SAAS,OAAgB;EACvB,IAAI,KAAK,SAAS,eAChB;OACE,UAAU,QACV,OAAO,UAAU,YACjB,EAAE,cAAc,QAEhB,MAAM,KAAK;EACb;CAEJ;CAEA,OAAO,OAAqD;EAC1D,IAAI,KAAK,SAAS,eAChB,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,cAAc;EAGtE,OAAO;CACT;AACF;AAEA,IAAa,qBAAb,MAAa,2BAIH,SAMR;CACA,AAAS;CACT,AAAS;CAET,YACE,aACA,cACA,YACA;EACA,MAAM;GAAE,MAAM;GAAY;EAAW,CAAC;EACtC,KAAK,cAAc;EACnB,KAAK,eAAe;CACtB;CAEA,WAAoE;EAClE,OAAO,IAAI,mBACT,KAAK,aACL,KAAK,cACL,UACF;CACF;CAEA,SAAS,OAAgB;EACvB,IAAI,OAAO,UAAU,YACnB,MAAM,KAAK;EAGb,OAAO;CAGT;CAEA,OACE,OAGsC;EACtC,OAAO,OAAO,UAAU;CAC1B;AACF"}
|
package/dist/validators/enum.cjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const require_base = require('./base.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/validators/enum.ts
|
|
4
|
-
var EnumProp = class EnumProp extends require_base.BaseProp {
|
|
5
|
-
allowedValues;
|
|
6
|
-
constructor(values, type, visibility) {
|
|
7
|
-
super({
|
|
8
|
-
type,
|
|
9
|
-
visibility
|
|
10
|
-
});
|
|
11
|
-
this.allowedValues = values;
|
|
12
|
-
}
|
|
13
|
-
optional() {
|
|
14
|
-
return new EnumProp(this.allowedValues, this.type, "optional");
|
|
15
|
-
}
|
|
16
|
-
validate(value) {
|
|
17
|
-
if (typeof value !== require_base.primitiveTypes[this.type]) throw this.error;
|
|
18
|
-
if (!this.allowedValues.includes(value)) throw this.error;
|
|
19
|
-
}
|
|
20
|
-
allows(value) {
|
|
21
|
-
return this.allowedValues.includes(value);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
exports.EnumProp = EnumProp;
|
|
27
|
-
//# sourceMappingURL=enum.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.cjs","names":["BaseProp","primitiveTypes"],"sources":["../../src/validators/enum.ts"],"sourcesContent":["import type {\n NonEmptyReadonlyArray,\n PrimitivePropType,\n PrimitiveTypesMap,\n PropVisibility,\n} from './types';\nimport { BaseProp, primitiveTypes } from './base';\n\nexport class EnumProp<\n const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, Values[number]> {\n private readonly allowedValues: Values;\n\n constructor(values: Values, type: Type, visibility: Visibility) {\n super({ type, visibility });\n this.allowedValues = values;\n }\n\n optional(this: EnumProp<Values, Type, 'required'>) {\n return new EnumProp(this.allowedValues, this.type, 'optional');\n }\n\n validate(value: unknown) {\n if (typeof value !== primitiveTypes[this.type]) {\n throw this.error;\n }\n\n if (\n !(this.allowedValues as readonly PrimitiveTypesMap[Type][]).includes(\n value as PrimitiveTypesMap[Type],\n )\n ) {\n throw this.error;\n }\n }\n\n allows(value: unknown): value is Values[number] {\n return this.allowedValues.includes(value as never);\n }\n}\n"],"mappings":";;;AAQA,IAAa,WAAb,MAAa,iBAIHA,sBAA2C;CACnD,AAAiB;CAEjB,YAAY,QAAgB,MAAY,YAAwB;EAC9D,MAAM;GAAE;GAAM;EAAW,CAAC;EAC1B,KAAK,gBAAgB;CACvB;CAEA,WAAmD;EACjD,OAAO,IAAI,SAAS,KAAK,eAAe,KAAK,MAAM,UAAU;CAC/D;CAEA,SAAS,OAAgB;EACvB,IAAI,OAAO,UAAUC,4BAAe,KAAK,OACvC,MAAM,KAAK;EAGb,IACE,CAAE,KAAK,cAAqD,SAC1D,KACF,GAEA,MAAM,KAAK;CAEf;CAEA,OAAO,OAAyC;EAC9C,OAAO,KAAK,cAAc,SAAS,KAAc;CACnD;AACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NonEmptyReadonlyArray, PrimitivePropType, PrimitiveTypesMap, PropVisibility } from "./types.cjs";
|
|
2
|
-
import { BaseProp } from "./base.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/enum.d.ts
|
|
5
|
-
declare class EnumProp<const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>, Type extends PrimitivePropType, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, Values[number]> {
|
|
6
|
-
private readonly allowedValues;
|
|
7
|
-
constructor(values: Values, type: Type, visibility: Visibility);
|
|
8
|
-
optional(this: EnumProp<Values, Type, 'required'>): EnumProp<Values, Type, "optional">;
|
|
9
|
-
validate(value: unknown): void;
|
|
10
|
-
allows(value: unknown): value is Values[number];
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { EnumProp };
|
|
14
|
-
//# sourceMappingURL=enum.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.cts","names":[],"sources":["../../src/validators/enum.ts"],"mappings":";;;;cAQa,QAAA,sBACU,qBAAA,CAAsB,iBAAA,CAAkB,IAAA,iBAChD,iBAAA,qBACM,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,MAAA;EAAA,iBAClB,aAAA;cAEL,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,UAAA;EAKpD,QAAA,CAAS,IAAA,EAAM,QAAA,CAAS,MAAA,EAAQ,IAAA,gBAAiB,QAAA,CAAA,MAAA,EAAA,IAAA;EAIjD,QAAA,CAAS,KAAA;EAcT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,MAAA;AAAA"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { NonEmptyReadonlyArray, PrimitivePropType, PrimitiveTypesMap, PropVisibility } from "./types.mjs";
|
|
2
|
-
import { BaseProp } from "./base.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/enum.d.ts
|
|
5
|
-
declare class EnumProp<const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>, Type extends PrimitivePropType, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, Values[number]> {
|
|
6
|
-
private readonly allowedValues;
|
|
7
|
-
constructor(values: Values, type: Type, visibility: Visibility);
|
|
8
|
-
optional(this: EnumProp<Values, Type, 'required'>): EnumProp<Values, Type, "optional">;
|
|
9
|
-
validate(value: unknown): void;
|
|
10
|
-
allows(value: unknown): value is Values[number];
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { EnumProp };
|
|
14
|
-
//# sourceMappingURL=enum.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.mts","names":[],"sources":["../../src/validators/enum.ts"],"mappings":";;;;cAQa,QAAA,sBACU,qBAAA,CAAsB,iBAAA,CAAkB,IAAA,iBAChD,iBAAA,qBACM,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,MAAA;EAAA,iBAClB,aAAA;cAEL,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,UAAA;EAKpD,QAAA,CAAS,IAAA,EAAM,QAAA,CAAS,MAAA,EAAQ,IAAA,gBAAiB,QAAA,CAAA,MAAA,EAAA,IAAA;EAIjD,QAAA,CAAS,KAAA;EAcT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,MAAA;AAAA"}
|
package/dist/validators/enum.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BaseProp, primitiveTypes } from "./base.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/validators/enum.ts
|
|
4
|
-
var EnumProp = class EnumProp extends BaseProp {
|
|
5
|
-
allowedValues;
|
|
6
|
-
constructor(values, type, visibility) {
|
|
7
|
-
super({
|
|
8
|
-
type,
|
|
9
|
-
visibility
|
|
10
|
-
});
|
|
11
|
-
this.allowedValues = values;
|
|
12
|
-
}
|
|
13
|
-
optional() {
|
|
14
|
-
return new EnumProp(this.allowedValues, this.type, "optional");
|
|
15
|
-
}
|
|
16
|
-
validate(value) {
|
|
17
|
-
if (typeof value !== primitiveTypes[this.type]) throw this.error;
|
|
18
|
-
if (!this.allowedValues.includes(value)) throw this.error;
|
|
19
|
-
}
|
|
20
|
-
allows(value) {
|
|
21
|
-
return this.allowedValues.includes(value);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
export { EnumProp };
|
|
27
|
-
//# sourceMappingURL=enum.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum.mjs","names":[],"sources":["../../src/validators/enum.ts"],"sourcesContent":["import type {\n NonEmptyReadonlyArray,\n PrimitivePropType,\n PrimitiveTypesMap,\n PropVisibility,\n} from './types';\nimport { BaseProp, primitiveTypes } from './base';\n\nexport class EnumProp<\n const Values extends NonEmptyReadonlyArray<PrimitiveTypesMap[Type]>,\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, Values[number]> {\n private readonly allowedValues: Values;\n\n constructor(values: Values, type: Type, visibility: Visibility) {\n super({ type, visibility });\n this.allowedValues = values;\n }\n\n optional(this: EnumProp<Values, Type, 'required'>) {\n return new EnumProp(this.allowedValues, this.type, 'optional');\n }\n\n validate(value: unknown) {\n if (typeof value !== primitiveTypes[this.type]) {\n throw this.error;\n }\n\n if (\n !(this.allowedValues as readonly PrimitiveTypesMap[Type][]).includes(\n value as PrimitiveTypesMap[Type],\n )\n ) {\n throw this.error;\n }\n }\n\n allows(value: unknown): value is Values[number] {\n return this.allowedValues.includes(value as never);\n }\n}\n"],"mappings":";;;AAQA,IAAa,WAAb,MAAa,iBAIH,SAA2C;CACnD,AAAiB;CAEjB,YAAY,QAAgB,MAAY,YAAwB;EAC9D,MAAM;GAAE;GAAM;EAAW,CAAC;EAC1B,KAAK,gBAAgB;CACvB;CAEA,WAAmD;EACjD,OAAO,IAAI,SAAS,KAAK,eAAe,KAAK,MAAM,UAAU;CAC/D;CAEA,SAAS,OAAgB;EACvB,IAAI,OAAO,UAAU,eAAe,KAAK,OACvC,MAAM,KAAK;EAGb,IACE,CAAE,KAAK,cAAqD,SAC1D,KACF,GAEA,MAAM,KAAK;CAEf;CAEA,OAAO,OAAyC;EAC9C,OAAO,KAAK,cAAc,SAAS,KAAc;CACnD;AACF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AnyBaseProp, AnyBuiltPropDefinition, BasePropOptions, BuiltPropShape, ComponentPropType, ComponentPropTypeMap, ExtractPropValue, NonEmptyReadonlyArray, PrimitivePropType, PrimitiveTypesMap, PrimitiveValueTypes, PropConfig, PropType, PropVisibility, ResolveBuiltPropValue, ResolveLayoutProps, ResolveProps, ResolvedBuiltPropShape } from "./types.cjs";
|
|
2
|
-
import { BaseProp, InvalidPropValueError } from "./base.cjs";
|
|
3
|
-
import { ComponentProp, ComponentPropWithPropertiesProp, RenderChildrenProp } from "./component.cjs";
|
|
4
|
-
import { EnumProp } from "./enum.cjs";
|
|
5
|
-
import { LiteralProp } from "./literal.cjs";
|
|
6
|
-
import { ObjectProp } from "./object.cjs";
|
|
7
|
-
import { BooleanProp, NumberProp, StringProp } from "./primitive.cjs";
|
|
8
|
-
import { UnionProp } from "./union.cjs";
|
|
9
|
-
import { ComponentPropBuilder, ComponentPropWithChildrenBuilder, EnumWrappedProp, LiteralWrappedProp, ObjectValueDefinition, WrappedProp, createPrimitivePropBuilder, createProp } from "./builders.cjs";
|
|
10
|
-
import { validateProps } from "./validate-props.cjs";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AnyBaseProp, AnyBuiltPropDefinition, BasePropOptions, BuiltPropShape, ComponentPropType, ComponentPropTypeMap, ExtractPropValue, NonEmptyReadonlyArray, PrimitivePropType, PrimitiveTypesMap, PrimitiveValueTypes, PropConfig, PropType, PropVisibility, ResolveBuiltPropValue, ResolveLayoutProps, ResolveProps, ResolvedBuiltPropShape } from "./types.mjs";
|
|
2
|
-
import { BaseProp, InvalidPropValueError } from "./base.mjs";
|
|
3
|
-
import { ComponentProp, ComponentPropWithPropertiesProp, RenderChildrenProp } from "./component.mjs";
|
|
4
|
-
import { EnumProp } from "./enum.mjs";
|
|
5
|
-
import { LiteralProp } from "./literal.mjs";
|
|
6
|
-
import { ObjectProp } from "./object.mjs";
|
|
7
|
-
import { BooleanProp, NumberProp, StringProp } from "./primitive.mjs";
|
|
8
|
-
import { UnionProp } from "./union.mjs";
|
|
9
|
-
import { ComponentPropBuilder, ComponentPropWithChildrenBuilder, EnumWrappedProp, LiteralWrappedProp, ObjectValueDefinition, WrappedProp, createPrimitivePropBuilder, createProp } from "./builders.mjs";
|
|
10
|
-
import { validateProps } from "./validate-props.mjs";
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const require_base = require('./base.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/validators/literal.ts
|
|
4
|
-
var LiteralProp = class LiteralProp extends require_base.BaseProp {
|
|
5
|
-
constructor(value, type, visibility) {
|
|
6
|
-
super({
|
|
7
|
-
type,
|
|
8
|
-
visibility,
|
|
9
|
-
value
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
optional() {
|
|
13
|
-
return new LiteralProp(this.value, this.type, "optional");
|
|
14
|
-
}
|
|
15
|
-
validate(value) {
|
|
16
|
-
if (value !== this.value) throw this.error;
|
|
17
|
-
}
|
|
18
|
-
allows(value) {
|
|
19
|
-
return value === this.value;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.LiteralProp = LiteralProp;
|
|
25
|
-
//# sourceMappingURL=literal.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"literal.cjs","names":["BaseProp"],"sources":["../../src/validators/literal.ts"],"sourcesContent":["import type {\n PrimitivePropType,\n PrimitiveTypesMap,\n PropVisibility,\n} from './types';\nimport { BaseProp } from './base';\n\nexport class LiteralProp<\n const Value extends PrimitiveTypesMap[Type],\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, Value> {\n declare readonly value: Value;\n\n constructor(value: Value, type: Type, visibility: Visibility) {\n super({ type, visibility, value });\n }\n\n optional(this: LiteralProp<Value, Type, 'required'>) {\n return new LiteralProp(this.value, this.type, 'optional');\n }\n\n validate(value: unknown) {\n if (value !== this.value) {\n throw this.error;\n }\n }\n\n allows(value: unknown): value is Value {\n return value === this.value;\n }\n}\n"],"mappings":";;;AAOA,IAAa,cAAb,MAAa,oBAIHA,sBAAkC;CAG1C,YAAY,OAAc,MAAY,YAAwB;EAC5D,MAAM;GAAE;GAAM;GAAY;EAAM,CAAC;CACnC;CAEA,WAAqD;EACnD,OAAO,IAAI,YAAY,KAAK,OAAO,KAAK,MAAM,UAAU;CAC1D;CAEA,SAAS,OAAgB;EACvB,IAAI,UAAU,KAAK,OACjB,MAAM,KAAK;CAEf;CAEA,OAAO,OAAgC;EACrC,OAAO,UAAU,KAAK;CACxB;AACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PrimitivePropType, PrimitiveTypesMap, PropVisibility } from "./types.cjs";
|
|
2
|
-
import { BaseProp } from "./base.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/literal.d.ts
|
|
5
|
-
declare class LiteralProp<const Value extends PrimitiveTypesMap[Type], Type extends PrimitivePropType, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, Value> {
|
|
6
|
-
readonly value: Value;
|
|
7
|
-
constructor(value: Value, type: Type, visibility: Visibility);
|
|
8
|
-
optional(this: LiteralProp<Value, Type, 'required'>): LiteralProp<Value, Type, "optional">;
|
|
9
|
-
validate(value: unknown): void;
|
|
10
|
-
allows(value: unknown): value is Value;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { LiteralProp };
|
|
14
|
-
//# sourceMappingURL=literal.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"literal.d.cts","names":[],"sources":["../../src/validators/literal.ts"],"mappings":";;;;cAOa,WAAA,qBACS,iBAAA,CAAkB,IAAA,gBACzB,iBAAA,qBACM,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,KAAA;EAAA,SAClB,KAAA,EAAO,KAAA;cAEZ,KAAA,EAAO,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,UAAA;EAIlD,QAAA,CAAS,IAAA,EAAM,WAAA,CAAY,KAAA,EAAO,IAAA,gBAAiB,WAAA,CAAA,KAAA,EAAA,IAAA;EAInD,QAAA,CAAS,KAAA;EAMT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,KAAA;AAAA"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PrimitivePropType, PrimitiveTypesMap, PropVisibility } from "./types.mjs";
|
|
2
|
-
import { BaseProp } from "./base.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/literal.d.ts
|
|
5
|
-
declare class LiteralProp<const Value extends PrimitiveTypesMap[Type], Type extends PrimitivePropType, Visibility extends PropVisibility> extends BaseProp<Type, Visibility, Value> {
|
|
6
|
-
readonly value: Value;
|
|
7
|
-
constructor(value: Value, type: Type, visibility: Visibility);
|
|
8
|
-
optional(this: LiteralProp<Value, Type, 'required'>): LiteralProp<Value, Type, "optional">;
|
|
9
|
-
validate(value: unknown): void;
|
|
10
|
-
allows(value: unknown): value is Value;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { LiteralProp };
|
|
14
|
-
//# sourceMappingURL=literal.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"literal.d.mts","names":[],"sources":["../../src/validators/literal.ts"],"mappings":";;;;cAOa,WAAA,qBACS,iBAAA,CAAkB,IAAA,gBACzB,iBAAA,qBACM,cAAA,UACX,QAAA,CAAS,IAAA,EAAM,UAAA,EAAY,KAAA;EAAA,SAClB,KAAA,EAAO,KAAA;cAEZ,KAAA,EAAO,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,UAAA,EAAY,UAAA;EAIlD,QAAA,CAAS,IAAA,EAAM,WAAA,CAAY,KAAA,EAAO,IAAA,gBAAiB,WAAA,CAAA,KAAA,EAAA,IAAA;EAInD,QAAA,CAAS,KAAA;EAMT,MAAA,CAAO,KAAA,YAAiB,KAAA,IAAS,KAAA;AAAA"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { BaseProp } from "./base.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/validators/literal.ts
|
|
4
|
-
var LiteralProp = class LiteralProp extends BaseProp {
|
|
5
|
-
constructor(value, type, visibility) {
|
|
6
|
-
super({
|
|
7
|
-
type,
|
|
8
|
-
visibility,
|
|
9
|
-
value
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
optional() {
|
|
13
|
-
return new LiteralProp(this.value, this.type, "optional");
|
|
14
|
-
}
|
|
15
|
-
validate(value) {
|
|
16
|
-
if (value !== this.value) throw this.error;
|
|
17
|
-
}
|
|
18
|
-
allows(value) {
|
|
19
|
-
return value === this.value;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { LiteralProp };
|
|
25
|
-
//# sourceMappingURL=literal.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"literal.mjs","names":[],"sources":["../../src/validators/literal.ts"],"sourcesContent":["import type {\n PrimitivePropType,\n PrimitiveTypesMap,\n PropVisibility,\n} from './types';\nimport { BaseProp } from './base';\n\nexport class LiteralProp<\n const Value extends PrimitiveTypesMap[Type],\n Type extends PrimitivePropType,\n Visibility extends PropVisibility,\n> extends BaseProp<Type, Visibility, Value> {\n declare readonly value: Value;\n\n constructor(value: Value, type: Type, visibility: Visibility) {\n super({ type, visibility, value });\n }\n\n optional(this: LiteralProp<Value, Type, 'required'>) {\n return new LiteralProp(this.value, this.type, 'optional');\n }\n\n validate(value: unknown) {\n if (value !== this.value) {\n throw this.error;\n }\n }\n\n allows(value: unknown): value is Value {\n return value === this.value;\n }\n}\n"],"mappings":";;;AAOA,IAAa,cAAb,MAAa,oBAIH,SAAkC;CAG1C,YAAY,OAAc,MAAY,YAAwB;EAC5D,MAAM;GAAE;GAAM;GAAY;EAAM,CAAC;CACnC;CAEA,WAAqD;EACnD,OAAO,IAAI,YAAY,KAAK,OAAO,KAAK,MAAM,UAAU;CAC1D;CAEA,SAAS,OAAgB;EACvB,IAAI,UAAU,KAAK,OACjB,MAAM,KAAK;CAEf;CAEA,OAAO,OAAgC;EACrC,OAAO,UAAU,KAAK;CACxB;AACF"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const require_base = require('./base.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/validators/object.ts
|
|
4
|
-
var ObjectProp = class ObjectProp extends require_base.BaseProp {
|
|
5
|
-
properties;
|
|
6
|
-
constructor(properties, visibility) {
|
|
7
|
-
super({
|
|
8
|
-
type: "object",
|
|
9
|
-
visibility
|
|
10
|
-
});
|
|
11
|
-
this.properties = properties;
|
|
12
|
-
}
|
|
13
|
-
optional() {
|
|
14
|
-
return new ObjectProp(this.properties, "optional");
|
|
15
|
-
}
|
|
16
|
-
validate(value) {
|
|
17
|
-
const validatedObject = {};
|
|
18
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw this.error;
|
|
19
|
-
const objectValue = value;
|
|
20
|
-
for (const key in this.properties) {
|
|
21
|
-
const prop = this.properties[key];
|
|
22
|
-
const propertyValue = objectValue[key];
|
|
23
|
-
if (propertyValue === void 0) {
|
|
24
|
-
if (prop.visibility !== "optional") throw new TypeError(`"${key}" is required.`);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
validatedObject[key] = prop(propertyValue);
|
|
28
|
-
}
|
|
29
|
-
return validatedObject;
|
|
30
|
-
}
|
|
31
|
-
allows(value) {
|
|
32
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
33
|
-
const objectValue = value;
|
|
34
|
-
for (const key in this.properties) {
|
|
35
|
-
const prop = this.properties[key];
|
|
36
|
-
const propertyValue = objectValue[key];
|
|
37
|
-
if (propertyValue === void 0) {
|
|
38
|
-
if (prop.visibility !== "optional") return false;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
prop(propertyValue);
|
|
43
|
-
} catch {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
exports.ObjectProp = ObjectProp;
|
|
53
|
-
//# sourceMappingURL=object.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.cjs","names":["BaseProp"],"sources":["../../src/validators/object.ts"],"sourcesContent":["import type {\n BuiltPropShape,\n PropVisibility,\n ResolveBuiltPropValue,\n} from './types';\nimport { BaseProp } from './base';\n\nexport class ObjectProp<\n const Shape extends BuiltPropShape,\n Visibility extends PropVisibility,\n> extends BaseProp<\n 'object',\n Visibility,\n {\n [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]>;\n }\n> {\n readonly properties: Shape;\n\n constructor(properties: Shape, visibility: Visibility) {\n super({ type: 'object', visibility });\n this.properties = properties;\n }\n\n optional(this: ObjectProp<Shape, 'required'>) {\n return new ObjectProp(this.properties, 'optional');\n }\n\n validate(value: unknown) {\n const validatedObject = {} as {\n [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]>;\n };\n\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw this.error;\n }\n\n const objectValue = value as Record<string, unknown>;\n\n for (const key in this.properties) {\n const prop = this.properties[key];\n const propertyValue = objectValue[key];\n\n if (propertyValue === undefined) {\n if (prop.visibility !== 'optional') {\n throw new TypeError(`\"${key}\" is required.`);\n }\n\n continue;\n }\n\n validatedObject[key] = prop(propertyValue) as ResolveBuiltPropValue<\n Shape[typeof key]\n >;\n }\n\n return validatedObject;\n }\n\n allows(value: unknown): value is {\n [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]>;\n } {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n const objectValue = value as Record<string, unknown>;\n\n for (const key in this.properties) {\n const prop = this.properties[key];\n const propertyValue = objectValue[key];\n\n if (propertyValue === undefined) {\n if (prop.visibility !== 'optional') {\n return false;\n }\n\n continue;\n }\n\n try {\n prop(propertyValue);\n } catch {\n return false;\n }\n }\n\n return true;\n }\n}\n"],"mappings":";;;AAOA,IAAa,aAAb,MAAa,mBAGHA,sBAMR;CACA,AAAS;CAET,YAAY,YAAmB,YAAwB;EACrD,MAAM;GAAE,MAAM;GAAU;EAAW,CAAC;EACpC,KAAK,aAAa;CACpB;CAEA,WAA8C;EAC5C,OAAO,IAAI,WAAW,KAAK,YAAY,UAAU;CACnD;CAEA,SAAS,OAAgB;EACvB,MAAM,kBAAkB,CAAC;EAIzB,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,MAAM,KAAK;EAGb,MAAM,cAAc;EAEpB,KAAK,MAAM,OAAO,KAAK,YAAY;GACjC,MAAM,OAAO,KAAK,WAAW;GAC7B,MAAM,gBAAgB,YAAY;GAElC,IAAI,kBAAkB,QAAW;IAC/B,IAAI,KAAK,eAAe,YACtB,MAAM,IAAI,UAAU,IAAI,IAAI,eAAe;IAG7C;GACF;GAEA,gBAAgB,OAAO,KAAK,aAAa;EAG3C;EAEA,OAAO;CACT;CAEA,OAAO,OAEL;EACA,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,OAAO;EAGT,MAAM,cAAc;EAEpB,KAAK,MAAM,OAAO,KAAK,YAAY;GACjC,MAAM,OAAO,KAAK,WAAW;GAC7B,MAAM,gBAAgB,YAAY;GAElC,IAAI,kBAAkB,QAAW;IAC/B,IAAI,KAAK,eAAe,YACtB,OAAO;IAGT;GACF;GAEA,IAAI;IACF,KAAK,aAAa;GACpB,QAAQ;IACN,OAAO;GACT;EACF;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BuiltPropShape, PropVisibility, ResolveBuiltPropValue } from "./types.cjs";
|
|
2
|
-
import { BaseProp } from "./base.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/validators/object.d.ts
|
|
5
|
-
declare class ObjectProp<const Shape extends BuiltPropShape, Visibility extends PropVisibility> extends BaseProp<'object', Visibility, { [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]> }> {
|
|
6
|
-
readonly properties: Shape;
|
|
7
|
-
constructor(properties: Shape, visibility: Visibility);
|
|
8
|
-
optional(this: ObjectProp<Shape, 'required'>): ObjectProp<Shape, "optional">;
|
|
9
|
-
validate(value: unknown): { [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]> };
|
|
10
|
-
allows(value: unknown): value is { [Key in keyof Shape]: ResolveBuiltPropValue<Shape[Key]> };
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { ObjectProp };
|
|
14
|
-
//# sourceMappingURL=object.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.cts","names":[],"sources":["../../src/validators/object.ts"],"mappings":";;;;cAOa,UAAA,qBACS,cAAA,qBACD,cAAA,UACX,QAAA,WAER,UAAA,kBAEgB,KAAA,GAAQ,qBAAA,CAAsB,KAAA,CAAM,GAAA;EAAA,SAG3C,UAAA,EAAY,KAAA;cAET,UAAA,EAAY,KAAA,EAAO,UAAA,EAAY,UAAA;EAK3C,QAAA,CAAS,IAAA,EAAM,UAAA,CAAW,KAAA,gBAAkB,UAAA,CAAA,KAAA;EAI5C,QAAA,CAAS,KAAA,4BAED,KAAA,GAAA,qBAAA,CAAA,KAAA,CAAA,GAAA;EA6BR,MAAA,CAAO,KAAA,YAAiB,KAAA,oBACR,KAAA,GAAQ,qBAAA,CAAsB,KAAA,CAAM,GAAA;AAAA"}
|