1
0
Fork 0

feat(schema): remove include type from default schema

BREAKING CHANGE: the include type requires a significant subset of
the synchronous fs API to be provided when creating a schema, even
if the include type is never used. Since the resolution must be
synchronous, the include type is limited to local fs and memory
access, and not very useful with network loading. It has been
removed from the default schema, but can be included by calling
`createIncludeSchema` instead.
This commit is contained in:
ssube 2021-07-10 15:12:59 -05:00
parent cf41dbf134
commit 800f6bb5b2
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
8 changed files with 44 additions and 20 deletions

View File

@ -6,6 +6,8 @@
Instantiate an include type with a copy of the provided options, returning the include type and its schema setter. Instantiate an include type with a copy of the provided options, returning the include type and its schema setter.
Includes must be resolved synchronously, which greatly limits where this can be used.
<b>Signature:</b> <b>Signature:</b>
```typescript ```typescript

View File

@ -4,19 +4,18 @@
## createSchema() function ## createSchema() function
Safe schema with additional library types added.
<b>Signature:</b> <b>Signature:</b>
```typescript ```typescript
export declare function createSchema(options: Readonly<SchemaOptions>): Schema; export declare function createSchema(options: SchemaOptions): Schema;
``` ```
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| options | Readonly&lt;[SchemaOptions](./js-yaml-schema.schemaoptions.md)<!-- -->&gt; | | | options | [SchemaOptions](./js-yaml-schema.schemaoptions.md) | |
<b>Returns:</b> <b>Returns:</b>

View File

@ -4,6 +4,8 @@
## IncludeOptions interface ## IncludeOptions interface
Additional options for the include type.
<b>Signature:</b> <b>Signature:</b>
```typescript ```typescript

View File

@ -8,14 +8,14 @@
| Function | Description | | Function | Description |
| --- | --- | | --- | --- |
| [createInclude(options)](./js-yaml-schema.createinclude.md) | Instantiate an include type with a copy of the provided options, returning the include type and its schema setter. | | [createInclude(options)](./js-yaml-schema.createinclude.md) | Instantiate an include type with a copy of the provided options, returning the include type and its schema setter.<!-- -->Includes must be resolved synchronously, which greatly limits where this can be used. |
| [createSchema(options)](./js-yaml-schema.createschema.md) | Safe schema with additional library types added. | | [createSchema(options)](./js-yaml-schema.createschema.md) | |
## Interfaces ## Interfaces
| Interface | Description | | Interface | Description |
| --- | --- | | --- | --- |
| [IncludeOptions](./js-yaml-schema.includeoptions.md) | | | [IncludeOptions](./js-yaml-schema.includeoptions.md) | Additional options for the include type. |
| [SchemaOptions](./js-yaml-schema.schemaoptions.md) | | | [SchemaOptions](./js-yaml-schema.schemaoptions.md) | |
## Variables ## Variables

View File

@ -1,11 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-yaml-schema](./js-yaml-schema.md) &gt; [SchemaOptions](./js-yaml-schema.schemaoptions.md) &gt; [include](./js-yaml-schema.schemaoptions.include.md)
## SchemaOptions.include property
<b>Signature:</b>
```typescript
include: Readonly<Omit<IncludeOptions, 'schema'>>;
```

View File

@ -4,6 +4,7 @@
## SchemaOptions interface ## SchemaOptions interface
<b>Signature:</b> <b>Signature:</b>
```typescript ```typescript
@ -15,5 +16,4 @@ export interface SchemaOptions
| Property | Type | Description | | Property | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| [base?](./js-yaml-schema.schemaoptions.base.md) | Schema | <i>(Optional)</i> | | [base?](./js-yaml-schema.schemaoptions.base.md) | Schema | <i>(Optional)</i> |
| [include](./js-yaml-schema.schemaoptions.include.md) | Readonly&lt;Omit&lt;[IncludeOptions](./js-yaml-schema.includeoptions.md)<!-- -->, 'schema'&gt;&gt; | |

View File

@ -6,17 +6,43 @@ import { createInclude, IncludeOptions } from './type/Include';
import { regexpType } from './type/Regexp'; import { regexpType } from './type/Regexp';
import { streamType } from './type/Stream'; import { streamType } from './type/Stream';
/**
* @public
*/
export interface SchemaOptions { export interface SchemaOptions {
base?: Schema; base?: Schema;
}
/**
* @public
*/
export function createSchema(options: SchemaOptions) {
const base = mustCoalesce(options.base, DEFAULT_SCHEMA);
return base.extend([
envType,
regexpType,
streamType,
]);
}
/**
* @public
* @deprecated
*/
export interface IncludeSchemaOptions {
base?: Schema;
include: Readonly<Omit<IncludeOptions, 'schema'>>; include: Readonly<Omit<IncludeOptions, 'schema'>>;
} }
/** /**
* Safe schema with additional library types added. * Extended schema with the include type, and auto-configuration
* of the include schema.
* *
* @public * @public
* @deprecated use createSchema unless the include type is needed, since it requires a number of callbacks
*/ */
export function createSchema(options: Readonly<SchemaOptions>) { export function createIncludeSchema(options: Readonly<IncludeSchemaOptions>) {
const base = mustCoalesce(options.base, DEFAULT_SCHEMA); const base = mustCoalesce(options.base, DEFAULT_SCHEMA);
const {includeType, setSchema} = createInclude({ const {includeType, setSchema} = createInclude({
...options.include, ...options.include,

View File

@ -9,6 +9,10 @@ export interface ReaderOptions {
export type IncludeReader = (path: string, options: ReaderOptions) => string; export type IncludeReader = (path: string, options: ReaderOptions) => string;
/**
* Additional options for the include type.
* @public
*/
export interface IncludeOptions { export interface IncludeOptions {
exists: (path: string) => boolean; exists: (path: string) => boolean;
join: (...path: Array<string>) => string; join: (...path: Array<string>) => string;
@ -21,6 +25,8 @@ export interface IncludeOptions {
* Instantiate an include type with a copy of the provided options, * Instantiate an include type with a copy of the provided options,
* returning the include type and its schema setter. * returning the include type and its schema setter.
* *
* Includes must be resolved synchronously, which greatly limits where this can be used.
*
* @public * @public
*/ */
export function createInclude(options: Readonly<IncludeOptions>) { export function createInclude(options: Readonly<IncludeOptions>) {