Skip to content

Commit

Permalink
DSLSchema doc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lexfm committed Feb 28, 2024
1 parent 091fb8b commit 85cd3cc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions docs/site/pages/dsl/schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ export default {
}
```

## DSL Benefit in Schema
# DSL Benefit in Schema

### Format
## Format

### Ease of Use
## Ease of Use

# DSLSchema type

A `DSLSchema` type is provided in order be able to customize a set of the acceptable data types and validator ficntions to be defined for authoring the DSL data schema in our workspace. By using it we can make sure every author only uses the included data types and validators, as well include the require parameters and types of the latter. In the following example we'll generate everything we need for our DSLSchema type instance for checking based on the data types and validators available in the Player plugin `common-types-plugin`. For this purpose you can use some types and utilities found in the `@player-tools/dsl` package.
A `DSLSchema` type is provided in order be able to customize a set of the acceptable data types and validator functions to be used for authoring the DSL data schema in our workspace. By using this schema type we can make sure every author only uses the included data types and validators, as well include the required parameters and their respective types of the latter.

We'll start out by importing the `common-types-plugin` in order to use its data types and validators for this example. Our first step would be to generate our data type object types and references:
We'll start out by importing the `DSLSchema` and relevant helper types and functions from `@player-tools/dsl`. For this example we are importing the `common-types-plugin` in order to use its data types and validators. Our first step would be to generate the data type object types and references:

```typescript
import {
Expand All @@ -247,7 +247,7 @@ import {
} from '@player-tools/dsl'
import {
dataTypes as commonDataTypes,
validators as coreValidators
validators as commonValidators
} from '@player-ui/common-types-plugin';

/** Abstracting the types from commonDataTypes to be passed as generic to the DataTypeRefs type for dynamically generating the data type reference types */
Expand All @@ -260,14 +260,17 @@ export const dataRefs = getObjectReferences<typeof commonDataTypes, myCommonData
```

We'll proceed generating the validation function types:

```typescript
/** Abstracting types from coreValidators and using as generic of ValidatorFunctionRefs for dynamically generating the data validation function reference types */
type commonValidatorRefs = ValidatorFunctionRefs<typeof coreValidators>
type commonValidatorRefs = ValidatorFunctionRefs<typeof commonValidators>
```
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:
The final step is to provide the data types set and validator function references type as generics for the `DataTypeReference` type which is the sole generic type we pass into the `DSLSchema` instance:
```typescript
type CommonDSLSchema = DSLSchema<DataTypeReference<typeof commonDataTypes, 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 85cd3cc

Please sign in to comment.