fix: selectively copy mutable schema options
This commit is contained in:
parent
05d5acfb1e
commit
5ef7e15c60
|
@ -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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
```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
|
||||
*/
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue