Skip to content

Commit

Permalink
DSLSchema docs further improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
afimbres committed Feb 28, 2024
1 parent c7bb529 commit 71e2d16
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions docs/site/pages/dsl/schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,8 @@ import {
validators as coreValidators
} from '@player-ui/common-types-plugin';

/** Abstracting the types from the given data type set */
type myCommonDataTypes = typeof commonDataTypes

/** Passing myCommonDataTypes type as generic of DataTypeRefs for dynamically generating the data type reference types */
type myCommonDataTypesRefs = DataTypeRefs<myCommonDataTypes>
/** Abstracting the types from commonDataTypes to be passed as generic to the DataTypeRefs type for dynamically generating the data type reference types */
type myCommonDataTypesRefs = DataTypeRefs<typeof commonDataTypes>

/** Using getObjectReferences helper to generate the actual data type references */
export const dataRefs = getObjectReferences<commonDataTypes, myCommonDataTypesRefs>(
Expand All @@ -263,18 +260,14 @@ export const dataRefs = getObjectReferences<commonDataTypes, myCommonDataTypesRe
```

We'll proceed generating the validation function types:

```typescript
/** Abstracting the types from the given validator functions set */
type myCommonValidators = typeof coreValidators

/** Passing myCommonValidators type as generic of ValidatorFunctionRefs for dynamically generating the data type reference types */
type commonValidatorRefs = ValidatorFunctionRefs<myCommonValidators>
/** Abstracting types from coreValidators and using as generic of ValidatorFunctionRefs for dynamically generating the data validation function reference types */
type commonValidatorRefs = ValidatorFunctionRefs<typeof coreValidators>
```
The final step is to put our generated data type properties union, and our validator function references union as generics for the `DataTypeReference` type which is the sole type we pass into the `DSLSchema` type instance:
The final step is to provide the data types set and validator function references abstracted types as generics for the `DataTypeReference` type which is the sole type we pass into the `DSLSchema` type instance:
```typescript
type CommonDSLSchema = DSLSchema<DataTypeReference<myCommonDataTypes, commonValidatorRefs>>
type CommonDSLSchema = DSLSchema<DataTypeReference<typeof commonDataTypes, commonValidatorRefs>>
```
Finally, this is how to use the custom schema type to type check your schema. By adding the `satisfies` keyword followed by your `DSLSchema` generated type, your editor's LSP will show if there is anything not compliant with the data types and validation functions we defined in the schema:
Expand Down

0 comments on commit 71e2d16

Please sign in to comment.