From 85cd3cca174c64ba9be754a08776236b0faa1bc0 Mon Sep 17 00:00:00 2001 From: afimbres Date: Wed, 28 Feb 2024 10:04:17 -0800 Subject: [PATCH] DSLSchema doc cleanup --- docs/site/pages/dsl/schema.mdx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/site/pages/dsl/schema.mdx b/docs/site/pages/dsl/schema.mdx index 9da4b7d06..04a91323e 100644 --- a/docs/site/pages/dsl/schema.mdx +++ b/docs/site/pages/dsl/schema.mdx @@ -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 { @@ -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 */ @@ -260,14 +260,17 @@ export const dataRefs = getObjectReferences +type commonValidatorRefs = ValidatorFunctionRefs ``` -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> +type CommonDSLSchema = DSLSchema< + DataTypeReference +> ``` 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: