@api-client/core 0.19.6 → 0.19.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/modeling/DomainProperty.d.ts +7 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +10 -0
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/modeling/DomainProperty.ts +11 -0
- package/tests/unit/modeling/domain_property.spec.ts +38 -0
package/package.json
CHANGED
|
@@ -542,6 +542,17 @@ export class DomainProperty extends DomainElement {
|
|
|
542
542
|
return object.schema as PropertyWebBindings
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
+
/**
|
|
546
|
+
* Reads the web binding definition, if any.
|
|
547
|
+
* Useful for reading binding data without mutating the model when the binding
|
|
548
|
+
* is missing (unlike `getWebBinding()` which creates the binding when missing).
|
|
549
|
+
* @returns The web binding definition, if any
|
|
550
|
+
*/
|
|
551
|
+
readWebBinding(): PropertyWebBindings | undefined {
|
|
552
|
+
const object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined
|
|
553
|
+
return object?.schema as PropertyWebBindings | undefined
|
|
554
|
+
}
|
|
555
|
+
|
|
545
556
|
/**
|
|
546
557
|
* Returns the schema value of the binding, if any was created.
|
|
547
558
|
* @param type The type of the binding to read.
|
|
@@ -771,6 +771,44 @@ test.group('DomainProperty.readBinding()', () => {
|
|
|
771
771
|
})
|
|
772
772
|
})
|
|
773
773
|
|
|
774
|
+
test.group('DomainProperty.readWebBinding()', () => {
|
|
775
|
+
test('returns undefined if no web binding exists', ({ assert }) => {
|
|
776
|
+
const dataDomain = new DataDomain()
|
|
777
|
+
const property = new DomainProperty(dataDomain, 'test-parent')
|
|
778
|
+
const binding = property.readWebBinding()
|
|
779
|
+
assert.isUndefined(binding)
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
test('returns the web binding schema if it exists', ({ assert }) => {
|
|
783
|
+
const dataDomain = new DataDomain()
|
|
784
|
+
const property = new DomainProperty(dataDomain, 'test-parent', {
|
|
785
|
+
bindings: [{ type: 'web', schema: { format: 'float' } }],
|
|
786
|
+
})
|
|
787
|
+
const webBindings = property.readWebBinding()
|
|
788
|
+
assert.deepEqual(webBindings, { format: 'float' })
|
|
789
|
+
})
|
|
790
|
+
|
|
791
|
+
test('returns undefined if the web binding exists but has no schema', ({ assert }) => {
|
|
792
|
+
const dataDomain = new DataDomain()
|
|
793
|
+
const property = new DomainProperty(dataDomain, 'test-parent', {
|
|
794
|
+
// @ts-expect-error Testing undefined value
|
|
795
|
+
bindings: [{ type: 'web', schema: undefined }],
|
|
796
|
+
})
|
|
797
|
+
const webBindings = property.readWebBinding()
|
|
798
|
+
assert.isUndefined(webBindings)
|
|
799
|
+
})
|
|
800
|
+
|
|
801
|
+
test('returns undefined if the web binding exists but the schema is null', ({ assert }) => {
|
|
802
|
+
const dataDomain = new DataDomain()
|
|
803
|
+
const property = new DomainProperty(dataDomain, 'test-parent', {
|
|
804
|
+
// @ts-expect-error Testing null value
|
|
805
|
+
bindings: [{ type: 'web', schema: null }],
|
|
806
|
+
})
|
|
807
|
+
const webBindings = property.readWebBinding()
|
|
808
|
+
assert.isNull(webBindings)
|
|
809
|
+
})
|
|
810
|
+
})
|
|
811
|
+
|
|
774
812
|
test.group('DomainProperty.toApiShape()', () => {
|
|
775
813
|
test('returns an object', ({ assert }) => {
|
|
776
814
|
const dataDomain = new DataDomain()
|