feat: add optional base schema to schema options
This commit is contained in:
parent
6f097d8e7e
commit
05d5acfb1e
|
@ -9,7 +9,7 @@ Safe schema with additional library types added.
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
export declare function createSchema(options: Readonly<SchemaOptions>): import("js-yaml").Schema;
|
export declare function createSchema(options: Readonly<SchemaOptions>): Schema;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
@ -20,5 +20,5 @@ export declare function createSchema(options: Readonly<SchemaOptions>): import("
|
||||||
|
|
||||||
<b>Returns:</b>
|
<b>Returns:</b>
|
||||||
|
|
||||||
import("js-yaml").Schema
|
Schema
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
| Function | Description |
|
| Function | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| [createInclude(options)](./js-yaml-schema.createinclude.md) | Instantiate an includer with closure over the provided options. |
|
| [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. |
|
||||||
| [createSchema(options)](./js-yaml-schema.createschema.md) | Safe schema with additional library types added. |
|
| [createSchema(options)](./js-yaml-schema.createschema.md) | Safe schema with additional library types added. |
|
||||||
|
|
||||||
## Interfaces
|
## Interfaces
|
||||||
|
|
|
@ -14,5 +14,6 @@ export interface SchemaOptions
|
||||||
|
|
||||||
| Property | Type | Description |
|
| Property | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| [include](./js-yaml-schema.schemaoptions.include.md) | Readonly<[IncludeOptions](./js-yaml-schema.includeoptions.md)<!-- -->> | |
|
| [base?](./js-yaml-schema.schemaoptions.base.md) | Schema | <i>(Optional)</i> |
|
||||||
|
| [include](./js-yaml-schema.schemaoptions.include.md) | Readonly<Omit<[IncludeOptions](./js-yaml-schema.includeoptions.md)<!-- -->, 'schema'>> | |
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { DEFAULT_SCHEMA } from 'js-yaml';
|
import { mustCoalesce } from '@apextoaster/js-utils';
|
||||||
|
import { DEFAULT_SCHEMA, Schema } from 'js-yaml';
|
||||||
|
|
||||||
import { envType } from './type/Env';
|
import { envType } from './type/Env';
|
||||||
import { createInclude, IncludeOptions } from './type/Include';
|
import { createInclude, IncludeOptions } from './type/Include';
|
||||||
|
@ -6,7 +7,8 @@ import { regexpType } from './type/Regexp';
|
||||||
import { streamType } from './type/Stream';
|
import { streamType } from './type/Stream';
|
||||||
|
|
||||||
export interface SchemaOptions {
|
export interface SchemaOptions {
|
||||||
include: Readonly<IncludeOptions>;
|
base?: Schema;
|
||||||
|
include: Readonly<Omit<IncludeOptions, 'schema'>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,8 +17,12 @@ export interface SchemaOptions {
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function createSchema(options: Readonly<SchemaOptions>) {
|
export function createSchema(options: Readonly<SchemaOptions>) {
|
||||||
const {includeType, setSchema} = createInclude(options.include);
|
const base = mustCoalesce(options.base, DEFAULT_SCHEMA);
|
||||||
const schema = DEFAULT_SCHEMA.extend([
|
const {includeType, setSchema} = createInclude({
|
||||||
|
...options.include,
|
||||||
|
schema: base,
|
||||||
|
});
|
||||||
|
const schema = base.extend([
|
||||||
envType,
|
envType,
|
||||||
includeType,
|
includeType,
|
||||||
regexpType,
|
regexpType,
|
||||||
|
|
Loading…
Reference in New Issue