fix: selectively copy mutable schema options
This commit is contained in:
parent
05d5acfb1e
commit
5ef7e15c60
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
## createInclude() function
|
## 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>
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [@apextoaster/js-yaml-schema](./js-yaml-schema.md) > [SchemaOptions](./js-yaml-schema.schemaoptions.md) > [base](./js-yaml-schema.schemaoptions.base.md)
|
||||||
|
|
||||||
|
## SchemaOptions.base property
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
base?: Schema;
|
||||||
|
```
|
|
@ -7,5 +7,5 @@
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
include: Readonly<IncludeOptions>;
|
include: Readonly<Omit<IncludeOptions, 'schema'>>;
|
||||||
```
|
```
|
||||||
|
|
|
@ -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
|
* @public
|
||||||
*/
|
*/
|
||||||
export function createInclude(options: Readonly<IncludeOptions>) {
|
export function createInclude(options: Readonly<IncludeOptions>) {
|
||||||
const optionsCopy = {...options};
|
const mutableOptions = {
|
||||||
|
schema: mustCoalesce(options.schema, DEFAULT_SCHEMA),
|
||||||
|
};
|
||||||
|
|
||||||
const includeType = new YamlType('!include', {
|
const includeType = new YamlType('!include', {
|
||||||
kind: 'scalar',
|
kind: 'scalar',
|
||||||
|
@ -45,7 +49,7 @@ export function createInclude(options: Readonly<IncludeOptions>) {
|
||||||
return load(options.read(abs, {
|
return load(options.read(abs, {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
}), {
|
}), {
|
||||||
schema: mustCoalesce(optionsCopy.schema, DEFAULT_SCHEMA),
|
schema: mutableOptions.schema,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new InvalidArgumentError('error including file', 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)
|
// callback to avoid circular dependency (type must be created before schema)
|
||||||
function setSchema(schema: Schema) {
|
function setSchema(schema: Schema) {
|
||||||
optionsCopy.schema = schema;
|
mutableOptions.schema = schema;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue