diff --git a/docs/schemata/Struct.md b/docs/schemata/Struct.md index 6c6c84f9..9b843f1d 100644 --- a/docs/schemata/Struct.md +++ b/docs/schemata/Struct.md @@ -14,6 +14,17 @@ Added in v1.4.0 - [Combinators](#combinators) - [Struct](#struct) +- [Transformations](#transformations) + - [StructSchema (class)](#structschema-class) + - [pick (property)](#pick-property) + - [omit (property)](#omit-property) + - [partial (property)](#partial-property) + - [partialOption (property)](#partialoption-property) + - [readonly (property)](#readonly-property) + - [strict (property)](#strict-property) + - [addIndexSignature (property)](#addindexsignature-property) + - [extend (property)](#extend-property) + - [intersect (property)](#intersect-property) --- @@ -40,3 +51,150 @@ export declare const Struct: >, Ix ext ``` Added in v1.0.0 + +# Transformations + +## StructSchema (class) + +Use `Struct({})` schema combinator instead + +**Signature** + +```ts +export declare class StructSchema { + constructor(private readonly props: T, private readonly indexSignature?: ExtraProps) +} +``` + +Added in v2.1.0 + +### pick (property) + +Re-declares a StructSchema by only including specified properties. + +Returns a new `StructSchema` + +**Signature** + +```ts +readonly pick: (...keys: readonly K[]) => StructSchema<{ [KeyType in keyof Pick]: Pick[KeyType]; }, Ix> +``` + +Added in v2.1.0 + +### omit (property) + +Re-declares a StructSchema by excluding specified properties. + +Returns a new `StructSchema` + +**Signature** + +```ts +readonly omit: (...keys: readonly K[]) => StructSchema<{ [KeyType in keyof Pick>]: Pick>[KeyType]; }, Ix> +``` + +Added in v2.1.0 + +### partial (property) + +Marks all properties as optional; applies `Partial` to both input and output types. + +Returns a new schema. + +**Signature** + +```ts +readonly partial: () => Schema>>, Simplify>>> +``` + +Added in v2.1.0 + +### partialOption (property) + +A variant of `partial` that applies `Partial` to input properties and maps each +output property to the fp-ts `Option` type. + +Returns a new schema. + +**Signature** + +```ts +readonly partialOption: () => Schema>>, Simplify>> +``` + +Added in v2.1.0 + +### readonly (property) + +Marks all properties as readonly; applies `Readonly` to both input and output types. + +Returns a new schema. + +**Signature** + +```ts +readonly readonly: () => Schema>>, Simplify>>> +``` + +Added in v2.1.0 + +### strict (property) + +Sets a Struct Schema's index signature to be strict + +Returns a new `StructSchema`. + +**Signature** + +```ts +readonly strict: () => StructSchema +``` + +Added in v2.1.0 + +### addIndexSignature (property) + +Adds an index signature to a Struct Schema. + +Returns a new `StructSchema`. + +**Signature** + +```ts +readonly addIndexSignature: >(indexSignature: Ix2) => StructSchema +``` + +Added in v2.1.0 + +### extend (property) + +Extends a Struct Schema with additional properties. Keys specified in `props` will +overwrite keys in `this`. + +Returns a new `StructSchema`. + +**Signature** + +```ts +readonly extend: >>(props: T2) => StructSchema, Ix> +``` + +Added in v2.1.0 + +### intersect (property) + +Intersects the present Struct Schema with another effectively concatenating their +keys. Keys in `this` will be overwritten with identical keys in `that`. + +**Note:** The index signature of `that` will be discarded. + +Returns a new `StructSchema`. + +**Signature** + +```ts +readonly intersect: >>(that: StructSchema) => StructSchema, Ix> +``` + +Added in v2.1.0 diff --git a/docs/schemata/index.md b/docs/schemata/index.md index b8338f1d..7c1c0a4f 100644 --- a/docs/schemata/index.md +++ b/docs/schemata/index.md @@ -82,23 +82,23 @@ has_children: true ### String (17) -* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `]VadFaS<`, `h2{`, `6~3n)`) -* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `3/G/+aUW+F+5S80xef/Vuj2W+k3+5Rd/`, `3+8+//h+`, `/o79pZ//++63yV+mV/+1Iu2t/JYy/Oc/+EI6+0==`) -* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `b__-bA`, `_CX67Cm`, `-mN-hBs-1b`) -* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `bc16wfmybhcf3jozffw2dn30tuhgf39a7s8k7`, `3iyPKiQRyMTqvXUDV3DBFnoAb4`, `2QkQcd7Lkj6JLgAFhLkobsB153Co1GYamADJYQFD`) +* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `.2~pj`, `Xzicp`, `(<{nIBab`) +* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `C6/h//++`, `8Z/AD/6p++==`, `phn/++/+/m++8+8W4//vQ2++/EDH`) +* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `1w__-e0-_`, `l_-_VZ5_-_`, `pHz7_b5`) +* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `3CXSUGbZ85hnkAcLaLL2wRc3FpK8R`, `2J5rM1HcLAKA2CLyhRmsKHJA3wwUWLQn`, `bc1os8pxxfe76tsa6l91nsp518bqh549y`) * CamelCaseString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CamelCaseString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CamelCaseString.ts)) (e.g: `Camel_case-string` → `camelCaseString`) -* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `6283588107863572`, `65971290953001950`, `62820139863139410`) -* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `x}?+/%.+/*%}~#~&&.=%^_}-.^~|+%{5=.#}.#.}+_&+$./=_?&7_{.}G#!+|'.'@[2.8.7.547]`, `"䛐ﭰ챝賅䤄䔚숍�৙"@-F2-W.hS-----.-5-g-l2T.----R--Om.QGGkwcHbWi`, `"銴顳"@[16.68.96.2]`) -* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0x1Eb5aFB9D0F0cee2bB950C7Aa1cBc7EDAaD3B5AD`, `0xB09AFeE9DdECBBE3fA2d2EE51caE0f7EEED2bf65`, `0xAaB1cC2F1a6C0eD11E5Dd6C0d9eEbecAc8ce43cB`) -* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `aDC1Ac`, `E7f0Fc`, `a8EC6bDd`) -* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `0xeAec99f0`, `0HCC2E`, `0HFDfBD`) -* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsla(-.60turn,0000.87765e622%,+.0933e57743766624%,186e-22729)`, `hsla(409822e8520+65.015193067e-99652845382%.4444206e98%/99515%)`, `hsla(61058,+003%,0000022e45%)`) -* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `--f.-_c3-Q.bZ`, `._Ba__-aG`, `.4K_N_D_L`) -* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(89,180.0000)`, `(-90.0000000000,177)`, `(90,127)`) -* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `valueOf=`, `{;%oUQ`, `qC73keycalltoStr`) -* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgba(100%,100%,100%,0)`, `rgba(99%,2%,100%,.2)`, `rgba(100%,93%,93%,1.0)`) +* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `62411770467721586`, `3528751036300588292`, `50864381596660195`) +* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `{#/_/!__.$?C.?~{5_-%=.$?'=^?*.7/_'}=~$}%.-.=.^|_+&&^#-!.{}#|%}=!+@[6.39.1.537]`, `!^-A&zs#|}.#%$?+W^{/+~%.+-.}{+''!8{P._#*'~.$?$~_.|8~&@I5w.6-fQ44O-q..u7-fE..195-M-Ei03.0XC-76-c5.-x-C.gMYwxOeuJIHhaF`, `"뾰㷯鏎￳￰"@[30.49.838.25]`) +* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xAB05bEd1ADA0ADa39ddeFBABEAa0af8300CFbAC9`, `0xC39f07eEc1f5B0d17C3d2FbcddbDBDC0bEAaccCd`, `0xC8AC7ECbC47DFD82e5cF8Beb3eF0fDDDdBB1EAAf`) +* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `12d1f625`, `0713CDBA`, `#F1CaCFe9`) +* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `2c21AdFd815`, `0Hb21A`, `0H38EBAAd`) +* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsla(.4384991e+058689613121,0.7438854870%,95e-37766%,8727511084e0)`, `hsl(242.2323248grad00000000.7039915138e+3889361%0100e+97581358157%/187.9e808)`, `hsl(.51e+10turn,00000100%,000.6879%)`) +* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `8-._X._3f`, `._aA_s7-`, `_-5-9-_nD.30-PZ`) +* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `-90.000000,98.6358`, `90.000,180`, `90.00000,178`) +* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `,hP5brRD2W`, `"\_M{#@~!`, `CW`) +* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgb(206,112,200)`, `rgba(82%,100%,96%,.80)`, `rgba(206,71,200,0.6815)`) * String ([docs](https://jacob-alford.github.io/schemata-ts/schemata/String.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/String.ts)) -* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `BaE39c9C-b9DC-c6Ca-3CB8-BEBc2bb2Ac6a`, `6A96fE3D-f88e-ebAD-C8Cf-90C976aA22BF`, `dC2eEAAc-1fd0-bfd0-2bbB-c9DdaF232abC`) +* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `eCcAfcbB-b8e5-2CeC-f20c-Bda9DAca8Af9`, `f5ccB60e-9AAC-C68a-Bf1b-F8CEE23Bf9aA`, `8fC88f3F-462b-ecc1-aaA5-bDCacEfbAA2f`) ### Unit (1) diff --git a/scripts/gen-docs-schemas.ts b/scripts/gen-docs-schemas.ts index 92cca900..13a986ee 100644 --- a/scripts/gen-docs-schemas.ts +++ b/scripts/gen-docs-schemas.ts @@ -108,6 +108,7 @@ export const genSchemas: Build = _ => RA.findLastMap(line => pipe( O.fromNullable(line.match(/@category\b(.*)\b/)), + O.map(RA.filter(category => !category.includes('Transformations'))), O.chain(RA.head), O.map(categoryString => tuple( diff --git a/src/schemata/Struct.ts b/src/schemata/Struct.ts index 9df1456f..e9fd34d9 100644 --- a/src/schemata/Struct.ts +++ b/src/schemata/Struct.ts @@ -64,8 +64,13 @@ type OptionOutput = Simplify< RestOutput & OptionOutputProps > -/** @since 2.1.0 */ -class StructSchema +/** + * Use `Struct({})` schema combinator instead + * + * @since 2.1.0 + * @category Transformations + */ +export class StructSchema extends SchemaImplementation, Output> implements Schema, Output> {