@swagger-api/apidom-core
Advanced tools
Comparing version 0.95.0 to 0.96.0
@@ -6,2 +6,16 @@ # Change Log | ||
# [0.96.0](https://github.com/swagger-api/apidom/compare/v0.95.0...v0.96.0) (2024-02-28) | ||
### Bug Fixes | ||
- **core:** assign unique ID to elements only when missing ([#3841](https://github.com/swagger-api/apidom/issues/3841)) ([89af0a9](https://github.com/swagger-api/apidom/commit/89af0a95c1675706c1b8aec6f67a656f5d85f96b)), closes [#3840](https://github.com/swagger-api/apidom/issues/3840) | ||
- **core:** retain meta & attributes during refracting ([#3843](https://github.com/swagger-api/apidom/issues/3843)) ([a7aac32](https://github.com/swagger-api/apidom/commit/a7aac3217730cb058370f906c2d8cc333c8111ee)), closes [#3842](https://github.com/swagger-api/apidom/issues/3842) | ||
- **playground:** fix bug related to instantiating parser ([#3851](https://github.com/swagger-api/apidom/issues/3851)) ([9b23628](https://github.com/swagger-api/apidom/commit/9b23628d20dda075cb844d5eca0f1d63018de70b)) | ||
### Features | ||
- **core:** add mechanism for left shallow merge ([#3849](https://github.com/swagger-api/apidom/issues/3849)) ([3334c6b](https://github.com/swagger-api/apidom/commit/3334c6bd200adedf84c8215bb263ab9009b1d1de)), closes [#3845](https://github.com/swagger-api/apidom/issues/3845) | ||
- **core:** add mechanism for right shallow merge ([#3846](https://github.com/swagger-api/apidom/issues/3846)) ([2059f28](https://github.com/swagger-api/apidom/commit/2059f28b810c70159d6fa4ddec1115cb38fa330b)), closes [#3845](https://github.com/swagger-api/apidom/issues/3845) | ||
- **core:** customize meta & attributes merges for deepmerge function ([#3855](https://github.com/swagger-api/apidom/issues/3855)) ([1e94924](https://github.com/swagger-api/apidom/commit/1e94924ab474f4ce4773239f9a9b175d129602f0)), closes [#3853](https://github.com/swagger-api/apidom/issues/3853) | ||
# [0.95.0](https://github.com/swagger-api/apidom/compare/v0.94.0...v0.95.0) (2024-02-09) | ||
@@ -8,0 +22,0 @@ |
{ | ||
"name": "@swagger-api/apidom-core", | ||
"version": "0.95.0", | ||
"version": "0.96.0", | ||
"description": "Tools for manipulating ApiDOM structures.", | ||
@@ -33,3 +33,3 @@ "publishConfig": { | ||
"test": "cross-env NODE_ENV=test BABEL_ENV=cjs mocha", | ||
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 BABEL_ENV=cjs mocha", | ||
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 NODE_ENV=test BABEL_ENV=cjs mocha", | ||
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .", | ||
@@ -46,4 +46,4 @@ "postpack": "rimraf NOTICE LICENSES" | ||
"@babel/runtime-corejs3": "^7.20.7", | ||
"@swagger-api/apidom-ast": "^0.95.0", | ||
"@swagger-api/apidom-error": "^0.95.0", | ||
"@swagger-api/apidom-ast": "^0.96.0", | ||
"@swagger-api/apidom-error": "^0.96.0", | ||
"@types/ramda": "~0.29.6", | ||
@@ -67,3 +67,3 @@ "minim": "~0.23.8", | ||
], | ||
"gitHead": "c56f672154649ce4b6236e4f5e12e05e34867fd7" | ||
"gitHead": "851320569f5a9bd24aff9deec3f5ba1e7f002917" | ||
} |
141
README.md
@@ -107,2 +107,101 @@ # @swagger-api/apidom-core | ||
## Shallow merging | ||
`mergeRight` and `mergeLeft` functions merge members of two or more ObjectElements shallowly | ||
and handles shallow merging of ArrayElements as well. | ||
### API | ||
#### mergeRight(target, source, [options]) | ||
Merges two ApiDOM elements target and source shallowly, returning a new merged ApiDOM element with the elements | ||
from both target and source. If an element at the same key is present for both target and source, | ||
the value from source will appear in the result. Merging creates a new ApiDOM element, | ||
so that neither target nor source is modified (operation is immutable). | ||
```js | ||
import { mergeRight, ObjectElement } from '@swagger-api/apidom-core'; | ||
const x = new ObjectElement({ | ||
foo: { bar: 3 }, | ||
}); | ||
const y = new ObjectElement({ | ||
foo: { baz: 4 }, | ||
quux: 5, | ||
}); | ||
const output = mergeRight(x, y); | ||
// => | ||
// ObjectElement({ | ||
// foo: ObjectElement({ | ||
// baz: 4, | ||
// }), | ||
// quux: 5, | ||
// }) | ||
``` | ||
#### mergeRight.all([element1, element2, ...], [options]) | ||
Merges shallowly any number of ApiDOM elements into a single ApiDOM element. | ||
```js | ||
import { mergeRight, ObjectElement } from '@swagger-api/apidom-core'; | ||
const foobar = new ObjectElement({ foo: { bar: 3 } }); | ||
const foobaz = new ObjectElement({ foo: { baz: 4 } }); | ||
const bar = new ObjectElement({ bar: 'yay!' }); | ||
const output = mergeRight.all([ foobar, foobaz, bar ]); | ||
// => ObjectElement({ foo: { baz: 4 }, bar: 'yay!' }) | ||
``` | ||
#### mergeLeft(source, target, [options]) | ||
Merges two ApiDOM elements source and target shallowly, returning a new merged ApiDOM element with the elements | ||
from both target and source. If an element at the same key is present for both target and source, | ||
the value from source will appear in the result. Merging creates a new ApiDOM element, | ||
so that neither target nor source is modified (operation is immutable). | ||
```js | ||
import { mergeLeft, ObjectElement } from '@swagger-api/apidom-core'; | ||
const x = new ObjectElement({ | ||
foo: { bar: 3 }, | ||
}); | ||
const y = new ObjectElement({ | ||
foo: { baz: 4 }, | ||
quux: 5, | ||
}); | ||
const output = mergeLeft(x, y); | ||
// => | ||
// ObjectElement({ | ||
// foo: ObjectElement({ | ||
// bar: 3, | ||
// }), | ||
// quux: 5, | ||
// }) | ||
``` | ||
#### mergeLeft.all([element1, element2, ...], [options]) | ||
Merges shallowly any number of ApiDOM elements into a single ApiDOM element. | ||
```js | ||
import { mergeLeft, ObjectElement } from '@swagger-api/apidom-core'; | ||
const foobar = new ObjectElement({ foo: { bar: 3 } }); | ||
const foobaz = new ObjectElement({ foo: { baz: 4 } }); | ||
const bar = new ObjectElement({ bar: 'yay!' }); | ||
const output = mergeLeft.all([ foobar, foobaz, bar ]); | ||
// => ObjectElement({ foo: { baz: 3 }, bar: 'yay!' }) | ||
``` | ||
### Shallow merge Options | ||
`mergeRight` and `mergeLeft` take the same options as [deepmerge](#deepmerge-options), except for `customMerge` and `clone`. | ||
## Deep merging | ||
@@ -119,3 +218,3 @@ | ||
Merge two ApiDOM elements target and source deeply, returning a new merged ApiDOM element with the elements | ||
Merges two ApiDOM elements target and source deeply, returning a new merged ApiDOM element with the elements | ||
from both target and source. If an element at the same key is present for both target and source, | ||
@@ -178,3 +277,3 @@ the value from source will appear in the result. Merging creates a new ApiDOM element, | ||
Merges any number of ApiDOM elements into a single ApiDOM element. | ||
Merges deeply any number of ApiDOM elements into a single ApiDOM element. | ||
@@ -192,3 +291,3 @@ ```js | ||
### Options | ||
### Deepmerge Options | ||
@@ -299,2 +398,38 @@ #### arrayElementMerge | ||
#### customMetaMerge | ||
Specifies a function which can be used to override the default metadata merge behavior. | ||
The `customMetaMerge` function will be passed target and source metadata. If not specified, | ||
the default behavior is to deep copy metadata from target to new merged element. | ||
```js | ||
import { deepmerge, ObjectElement } from '@swagger-api/apidom-core'; | ||
const alex = new ObjectElement({ name: { first: 'Alex' } }, { metaKey: true }); | ||
const tony = new ObjectElement({ name: { first: 'Tony' } }, { metaKey: false }); | ||
const customMetaMerge = (targetMeta, sourceMeta) => deepmerge(targetMeta, sourceMeta); | ||
const output = deepmerge(alex, tony, { customMetaMerge }); | ||
// output.meta.get('metaKey') // => BooleanElement(false) | ||
``` | ||
#### customAttributesMerge | ||
Specifies a function which can be used to override the default attributes merge behavior. | ||
The `customAttributesMerge` function will be passed target and source attributes. If not specified, | ||
the default behavior is to deep copy attributes from target to new merged element. | ||
```js | ||
import { deepmerge, ObjectElement } from '@swagger-api/apidom-core'; | ||
const alex = new ObjectElement({ name: { first: 'Alex' } }, undefined, { attributeKey: true }); | ||
const tony = new ObjectElement({ name: { first: 'Tony' } }, undefined, { attributeKey: false }); | ||
const customAttributesMerge = (targetMeta, sourceMeta) => deepmerge(targetMeta, sourceMeta); | ||
const output = deepmerge(alex, tony, { customAttributesMerge }); | ||
// output.attributs.get('attributeKey') // => BooleanElement(false) | ||
``` | ||
#### clone | ||
@@ -301,0 +436,0 @@ |
/// <reference path="./minim.d.ts" /> | ||
import * as minim from 'minim'; | ||
import { Element, StringElement, Meta, Attributes, ArrayElement, ArraySlice, NumberElement, NullElement, BooleanElement, ObjectElement, MemberElement, LinkElement, RefElement, Namespace as Namespace$1, NamespacePlugin, KeyValuePair, ObjectSlice } from 'minim'; | ||
@@ -306,2 +307,4 @@ export { ArrayElement, ArraySlice, Attributes, BooleanElement, Element, KeyValuePair, LinkElement, MemberElement, Meta, NamespacePluginOptions, NullElement, NumberElement, ObjectElement, ObjectSlice, RefElement, StringElement, refract } from 'minim'; | ||
type CustomMerge = (keyElement: Element, options: DeepMergeOptions) => DeepMerge; | ||
type CustomMetaMerge = (targetElementMeta: ObjectElement, sourceElementMeta: ObjectElement) => ObjectElement; | ||
type CustomAttributesMerge = (targetElementAttributes: ObjectElement, sourceElementAttributes: ObjectElement) => ObjectElement; | ||
type ArrayElementMerge = (targetElement: ArrayElement, sourceElement: ArrayElement, options: DeepMergeOptions) => ArrayElement; | ||
@@ -315,2 +318,4 @@ type ObjectElementMerge = (targetElement: ObjectElement, source: ObjectElement, options: DeepMergeOptions) => ObjectElement; | ||
customMerge?: CustomMerge; | ||
customMetaMerge?: CustomMetaMerge; | ||
customAttributesMerge?: CustomAttributesMerge; | ||
}; | ||
@@ -323,8 +328,21 @@ type DeepMergeOptions = DeepMergeUserOptions & { | ||
customMerge: CustomMerge | undefined; | ||
customMetaMerge: CustomMetaMerge | undefined; | ||
customAttributesMerge: CustomAttributesMerge | undefined; | ||
}; | ||
declare function deepmerge(targetElement: ObjectOrArrayElement, sourceElement: ObjectOrArrayElement, options?: DeepMergeUserOptions): AnyElement; | ||
declare namespace deepmerge { | ||
var all: (list: ObjectOrArrayElement[], options?: DeepMergeOptions | undefined) => any; | ||
var all: (list: ObjectOrArrayElement[], options?: DeepMergeUserOptions | undefined) => any; | ||
} | ||
export { Annotation as AnnotationElement, CloneError, Comment as CommentElement, DeepCloneError, ElementIdentityError, type ElementPredicate, IdentityManager, MediaTypes, Namespace, ParseResult as ParseResultElement, type Position, type PositionRange, ShallowCloneError, SourceMap as SourceMapElement, Transcluder, cloneDeep, cloneNode, cloneShallow, createNamespace, createPredicate, deepmerge, defaultIdentityManager, dehydrate, dereference, dispatchPlugins as dispatchRefractorPlugins, filter, find, findAtOffset, fromFn as from, getNodeType, hasElementSourceMap, includesClasses, includesSymbols, isAnnotationElement, isArrayElement, isBooleanElement, isElement, isLinkElement, isMemberElement, isNullElement, isNumberElement, isObjectElement, isParseResultElement, isPrimitiveElement, isRefElement, isSourceMapElement, isStringElement, keyMapDefault as keyMap, namespace, parents, plugin$1 as refractorPluginElementIdentity, plugin as refractorPluginSemanticElementIdentity, reject, sexprs, some, serializer$1 as toJSON, toString, serializer$2 as toValue, serializer as toYAML, transclude, traverse, visit }; | ||
type MergeRightOptions = Omit<DeepMergeUserOptions, 'customMerge' | 'clone'>; | ||
declare const mergeRight: { | ||
(targetElement: ObjectOrArrayElement, sourceElement: ObjectOrArrayElement, options?: MergeRightOptions): minim.Element | ObjectElement | minim.ArrayElement; | ||
all(list: ObjectOrArrayElement[], options?: MergeRightOptions): any; | ||
}; | ||
declare const mergeLeft: { | ||
(targetElement: ObjectOrArrayElement, sourceElement: ObjectOrArrayElement, options?: MergeRightOptions | undefined): minim.Element | minim.ObjectElement | minim.ArrayElement; | ||
all(list: ObjectOrArrayElement[], options?: MergeRightOptions | undefined): any; | ||
}; | ||
export { Annotation as AnnotationElement, CloneError, Comment as CommentElement, DeepCloneError, type DeepMergeUserOptions, ElementIdentityError, type ElementPredicate, IdentityManager, MediaTypes, type MergeRightOptions as MergeLeftOptions, type MergeRightOptions, Namespace, type ObjectOrArrayElement, ParseResult as ParseResultElement, type Position, type PositionRange, ShallowCloneError, SourceMap as SourceMapElement, Transcluder, cloneDeep, cloneNode, cloneShallow, createNamespace, createPredicate, deepmerge, defaultIdentityManager, dehydrate, dereference, dispatchPlugins as dispatchRefractorPlugins, filter, find, findAtOffset, fromFn as from, getNodeType, hasElementSourceMap, includesClasses, includesSymbols, isAnnotationElement, isArrayElement, isBooleanElement, isElement, isLinkElement, isMemberElement, isNullElement, isNumberElement, isObjectElement, isParseResultElement, isPrimitiveElement, isRefElement, isSourceMapElement, isStringElement, keyMapDefault as keyMap, mergeLeft, mergeRight, namespace, parents, plugin$1 as refractorPluginElementIdentity, plugin as refractorPluginSemanticElementIdentity, reject, sexprs, some, serializer$1 as toJSON, toString, serializer$2 as toValue, serializer as toYAML, transclude, traverse, visit }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
878113
103
18190
882
+ Added@swagger-api/apidom-ast@0.96.0(transitive)
+ Added@swagger-api/apidom-error@0.96.0(transitive)
- Removed@swagger-api/apidom-ast@0.95.0(transitive)
- Removed@swagger-api/apidom-error@0.95.0(transitive)