1
0
Fork 0

fix: selectively copy mutable schema options

This commit is contained in:
ssube 2021-04-17 18:57:18 -05:00
parent 05d5acfb1e
commit 5ef7e15c60
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
4 changed files with 21 additions and 6 deletions

View File

@ -4,7 +4,7 @@
## createInclude() function
Instantiate an includer with closure over the provided options.
Instantiate an include type with a copy of the provided options, returning the include type and its schema setter.
<b>Signature:</b>

View File

@ -0,0 +1,11 @@
<!-- 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; [base](./js-yaml-schema.schemaoptions.base.md)
## SchemaOptions.base property
<b>Signature:</b>
```typescript
base?: Schema;
```

View File

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
include: Readonly<IncludeOptions>;
include: Readonly<Omit<IncludeOptions, 'schema'>>;
```

View File

@ -18,11 +18,15 @@ export interface IncludeOptions {
}
/**
* Instantiate an includer with closure over the provided options.
* Instantiate an include type with a copy of the provided options,
* returning the include type and its schema setter.
*
* @public
*/
export function createInclude(options: Readonly<IncludeOptions>) {
const optionsCopy = {...options};
const mutableOptions = {
schema: mustCoalesce(options.schema, DEFAULT_SCHEMA),
};
const includeType = new YamlType('!include', {
kind: 'scalar',
@ -45,7 +49,7 @@ export function createInclude(options: Readonly<IncludeOptions>) {
return load(options.read(abs, {
encoding: 'utf-8',
}), {
schema: mustCoalesce(optionsCopy.schema, DEFAULT_SCHEMA),
schema: mutableOptions.schema,
});
} catch (err) {
throw new InvalidArgumentError('error including file', err);
@ -55,7 +59,7 @@ export function createInclude(options: Readonly<IncludeOptions>) {
// callback to avoid circular dependency (type must be created before schema)
function setSchema(schema: Schema) {
optionsCopy.schema = schema;
mutableOptions.schema = schema;
};
return {