@limetech/lime-web-components 5.39.0 → 5.40.0
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/CHANGELOG.md +8 -0
- package/dist/es5/limetype/find-limetype-by-label.js +8 -0
- package/dist/es5/limetype/find-limetype-by-label.spec.js +47 -0
- package/dist/es5/limetype/get-properties-by-type.js +7 -0
- package/dist/es5/limetype/get-properties-by-type.spec.js +36 -0
- package/dist/es5/limetype/get-property-by-label.js +8 -0
- package/dist/es5/limetype/get-property-by-label.spec.js +33 -0
- package/dist/es5/limetype/get-property-by-name.js +7 -0
- package/dist/es5/limetype/get-property-by-name.spec.js +31 -0
- package/dist/es5/limetype/has-label.js +7 -0
- package/dist/es5/limetype/has-label.spec.js +30 -0
- package/dist/es5/limetype/index.js +5 -0
- package/dist/limetype/find-limetype-by-label.d.ts +42 -0
- package/dist/limetype/find-limetype-by-label.d.ts.map +1 -0
- package/dist/limetype/find-limetype-by-label.js +43 -0
- package/dist/limetype/find-limetype-by-label.spec.d.ts +2 -0
- package/dist/limetype/find-limetype-by-label.spec.d.ts.map +1 -0
- package/dist/limetype/find-limetype-by-label.spec.js +44 -0
- package/dist/limetype/get-properties-by-type.d.ts +16 -0
- package/dist/limetype/get-properties-by-type.d.ts.map +1 -0
- package/dist/limetype/get-properties-by-type.js +16 -0
- package/dist/limetype/get-properties-by-type.spec.d.ts +2 -0
- package/dist/limetype/get-properties-by-type.spec.d.ts.map +1 -0
- package/dist/limetype/get-properties-by-type.spec.js +31 -0
- package/dist/limetype/get-property-by-label.d.ts +16 -0
- package/dist/limetype/get-property-by-label.d.ts.map +1 -0
- package/dist/limetype/get-property-by-label.js +17 -0
- package/dist/limetype/get-property-by-label.spec.d.ts +2 -0
- package/dist/limetype/get-property-by-label.spec.d.ts.map +1 -0
- package/dist/limetype/get-property-by-label.spec.js +26 -0
- package/dist/limetype/get-property-by-name.d.ts +17 -0
- package/dist/limetype/get-property-by-name.d.ts.map +1 -0
- package/dist/limetype/get-property-by-name.js +17 -0
- package/dist/limetype/get-property-by-name.spec.d.ts +2 -0
- package/dist/limetype/get-property-by-name.spec.d.ts.map +1 -0
- package/dist/limetype/get-property-by-name.spec.js +26 -0
- package/dist/limetype/has-label.d.ts +29 -0
- package/dist/limetype/has-label.d.ts.map +1 -0
- package/dist/limetype/has-label.js +29 -0
- package/dist/limetype/has-label.spec.d.ts +2 -0
- package/dist/limetype/has-label.spec.d.ts.map +1 -0
- package/dist/limetype/has-label.spec.js +31 -0
- package/dist/limetype/index.d.ts +5 -0
- package/dist/limetype/index.d.ts.map +1 -1
- package/dist/limetype/index.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [5.40.0](https://github.com/Lundalogik/lime-web-components/compare/v5.39.0...v5.40.0) (2024-11-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
* **limetype:** add helper functions for working with limetypes ([70c0cba](https://github.com/Lundalogik/lime-web-components/commit/70c0cbadc3e23794b8236d973ebf789803e71d02))
|
|
8
|
+
|
|
1
9
|
## [5.39.0](https://github.com/Lundalogik/lime-web-components/compare/v5.38.1...v5.39.0) (2024-11-21)
|
|
2
10
|
|
|
3
11
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findLimetypeByLabel = void 0;
|
|
4
|
+
var _1 = require(".");
|
|
5
|
+
var findLimetypeByLabel = function (label) { return function (limetypes) {
|
|
6
|
+
return Object.values(limetypes).find((0, _1.hasLabel)(label));
|
|
7
|
+
}; };
|
|
8
|
+
exports.findLimetypeByLabel = findLimetypeByLabel;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var company_1 = require("../testing/limetypes/company");
|
|
5
|
+
var person_1 = require("../testing/limetypes/person");
|
|
6
|
+
var find_limetype_by_label_1 = require("./find-limetype-by-label");
|
|
7
|
+
describe('findLimetypeByLabel', function () {
|
|
8
|
+
var limetypes = {
|
|
9
|
+
company: tslib_1.__assign({}, company_1.company),
|
|
10
|
+
person: tslib_1.__assign({}, person_1.person),
|
|
11
|
+
};
|
|
12
|
+
it('returns a function', function () {
|
|
13
|
+
var result = (0, find_limetype_by_label_1.findLimetypeByLabel)('person');
|
|
14
|
+
expect(typeof result).toBe('function');
|
|
15
|
+
});
|
|
16
|
+
describe('when the label exists', function () {
|
|
17
|
+
it('returns the correct limetype', function () {
|
|
18
|
+
var findUser = (0, find_limetype_by_label_1.findLimetypeByLabel)('person');
|
|
19
|
+
var result = findUser(limetypes);
|
|
20
|
+
expect(result).toStrictEqual(person_1.person);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('when the label does not exist', function () {
|
|
24
|
+
it('returns undefined', function () {
|
|
25
|
+
var findNonexistent = (0, find_limetype_by_label_1.findLimetypeByLabel)('nonexistent');
|
|
26
|
+
var result = findNonexistent(limetypes);
|
|
27
|
+
expect(result).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('when the limetypes object is empty', function () {
|
|
31
|
+
it('returns undefined', function () {
|
|
32
|
+
var findUser = (0, find_limetype_by_label_1.findLimetypeByLabel)('person');
|
|
33
|
+
var result = findUser({});
|
|
34
|
+
expect(result).toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('when the input is invalid', function () {
|
|
38
|
+
it('throws an error if limetypes is null', function () {
|
|
39
|
+
var findUser = (0, find_limetype_by_label_1.findLimetypeByLabel)('person');
|
|
40
|
+
expect(function () { return findUser(null); }).toThrow();
|
|
41
|
+
});
|
|
42
|
+
it('throws an error if limetypes is undefined', function () {
|
|
43
|
+
var findUser = (0, find_limetype_by_label_1.findLimetypeByLabel)('person');
|
|
44
|
+
expect(function () { return findUser(undefined); }).toThrow();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPropertiesByType = void 0;
|
|
4
|
+
function getPropertiesByType(limetype, type) {
|
|
5
|
+
return Object.values(limetype.properties).filter(function (property) { return property.type === type; });
|
|
6
|
+
}
|
|
7
|
+
exports.getPropertiesByType = getPropertiesByType;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var person_1 = require("../testing/limetypes/person");
|
|
5
|
+
var get_properties_by_type_1 = require("./get-properties-by-type");
|
|
6
|
+
describe('getPropertiesByType', function () {
|
|
7
|
+
it('retrieves all properties of a specified type', function () {
|
|
8
|
+
var result = (0, get_properties_by_type_1.getPropertiesByType)(tslib_1.__assign({}, person_1.person), 'string');
|
|
9
|
+
expect(result).toStrictEqual([
|
|
10
|
+
person_1.person.properties.firstname,
|
|
11
|
+
person_1.person.properties.lastname,
|
|
12
|
+
person_1.person.properties.name,
|
|
13
|
+
person_1.person.properties.position,
|
|
14
|
+
]);
|
|
15
|
+
});
|
|
16
|
+
it('returns an empty array if no properties match the type', function () {
|
|
17
|
+
var result = (0, get_properties_by_type_1.getPropertiesByType)(tslib_1.__assign({}, person_1.person), 'integer');
|
|
18
|
+
expect(result).toStrictEqual([]);
|
|
19
|
+
});
|
|
20
|
+
describe('edge cases', function () {
|
|
21
|
+
it('returns an empty array if limetype has no properties', function () {
|
|
22
|
+
var emptyLimetype = {
|
|
23
|
+
label: 'empty',
|
|
24
|
+
properties: {},
|
|
25
|
+
};
|
|
26
|
+
var result = (0, get_properties_by_type_1.getPropertiesByType)(emptyLimetype, 'string');
|
|
27
|
+
expect(result).toStrictEqual([]);
|
|
28
|
+
});
|
|
29
|
+
it('throws an error if limetype is null or undefined', function () {
|
|
30
|
+
expect(function () { return (0, get_properties_by_type_1.getPropertiesByType)(null, 'string'); }).toThrow();
|
|
31
|
+
expect(function () {
|
|
32
|
+
return (0, get_properties_by_type_1.getPropertiesByType)(undefined, 'string');
|
|
33
|
+
}).toThrow();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPropertyByLabel = void 0;
|
|
4
|
+
var _1 = require(".");
|
|
5
|
+
function getPropertyByLabel(limetype, label) {
|
|
6
|
+
return Object.values(limetype.properties).find((0, _1.hasLabel)(label));
|
|
7
|
+
}
|
|
8
|
+
exports.getPropertyByLabel = getPropertyByLabel;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var person_1 = require("../testing/limetypes/person");
|
|
5
|
+
var get_property_by_label_1 = require("./get-property-by-label");
|
|
6
|
+
describe('getPropertyByLabel', function () {
|
|
7
|
+
it('retrieves a property by its label', function () {
|
|
8
|
+
var result = (0, get_property_by_label_1.getPropertyByLabel)(tslib_1.__assign({}, person_1.person), 'primaryemailaddress');
|
|
9
|
+
expect(result).toStrictEqual(person_1.person.properties.email);
|
|
10
|
+
});
|
|
11
|
+
it('returns undefined if no property matches the label', function () {
|
|
12
|
+
var result = (0, get_property_by_label_1.getPropertyByLabel)(tslib_1.__assign({}, person_1.person), 'nonexistent');
|
|
13
|
+
expect(result).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
describe('edge cases', function () {
|
|
16
|
+
it('returns undefined if limetype has no properties', function () {
|
|
17
|
+
var emptyLimetype = {
|
|
18
|
+
label: 'empty',
|
|
19
|
+
properties: {},
|
|
20
|
+
};
|
|
21
|
+
var result = (0, get_property_by_label_1.getPropertyByLabel)(emptyLimetype, 'primaryemailaddress');
|
|
22
|
+
expect(result).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
it('throws an error if limetype is null or undefined', function () {
|
|
25
|
+
expect(function () {
|
|
26
|
+
return (0, get_property_by_label_1.getPropertyByLabel)(null, 'primaryemailaddress');
|
|
27
|
+
}).toThrow();
|
|
28
|
+
expect(function () {
|
|
29
|
+
return (0, get_property_by_label_1.getPropertyByLabel)(undefined, 'primaryemailaddress');
|
|
30
|
+
}).toThrow();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPropertyByName = void 0;
|
|
4
|
+
function getPropertyByName(limetype, propertyName) {
|
|
5
|
+
return limetype.properties[propertyName];
|
|
6
|
+
}
|
|
7
|
+
exports.getPropertyByName = getPropertyByName;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var person_1 = require("../testing/limetypes/person");
|
|
5
|
+
var get_property_by_name_1 = require("./get-property-by-name");
|
|
6
|
+
describe('getPropertyByName', function () {
|
|
7
|
+
it('retrieves a property by its name', function () {
|
|
8
|
+
var result = (0, get_property_by_name_1.getPropertyByName)(tslib_1.__assign({}, person_1.person), 'email');
|
|
9
|
+
expect(result).toStrictEqual(person_1.person.properties.email);
|
|
10
|
+
});
|
|
11
|
+
it('returns `undefined` if the property does not exist', function () {
|
|
12
|
+
var result = (0, get_property_by_name_1.getPropertyByName)(tslib_1.__assign({}, person_1.person), 'age');
|
|
13
|
+
expect(result).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
describe('edge cases', function () {
|
|
16
|
+
it('returns undefined if limetype has no properties', function () {
|
|
17
|
+
var emptyLimetype = {
|
|
18
|
+
label: 'Empty',
|
|
19
|
+
properties: {},
|
|
20
|
+
};
|
|
21
|
+
var result = (0, get_property_by_name_1.getPropertyByName)(emptyLimetype, 'email');
|
|
22
|
+
expect(result).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
it('throws an error if limetype is null or undefined', function () {
|
|
25
|
+
expect(function () { return (0, get_property_by_name_1.getPropertyByName)(null, 'email'); }).toThrow();
|
|
26
|
+
expect(function () {
|
|
27
|
+
return (0, get_property_by_name_1.getPropertyByName)(undefined, 'email');
|
|
28
|
+
}).toThrow();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasLabel = void 0;
|
|
4
|
+
var hasLabel = function (label) { return function (object) {
|
|
5
|
+
return (object === null || object === void 0 ? void 0 : object.label) === label;
|
|
6
|
+
}; };
|
|
7
|
+
exports.hasLabel = hasLabel;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var person_1 = require("../testing/limetypes/person");
|
|
4
|
+
var has_label_1 = require("./has-label");
|
|
5
|
+
describe('hasLabel', function () {
|
|
6
|
+
it('returns true if the object has the specified label', function () {
|
|
7
|
+
var checkLabel = (0, has_label_1.hasLabel)('primaryemailaddress');
|
|
8
|
+
expect(checkLabel(person_1.person.properties.email)).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
it('returns false if the object does not have the specified label', function () {
|
|
11
|
+
var checkLabel = (0, has_label_1.hasLabel)('firstname');
|
|
12
|
+
expect(checkLabel(person_1.person.properties.email)).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
it('returns false if the object is undefined', function () {
|
|
15
|
+
var checkLabel = (0, has_label_1.hasLabel)('firstname');
|
|
16
|
+
expect(checkLabel(undefined)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
describe('edge cases', function () {
|
|
19
|
+
it('returns false if the object has no label property', function () {
|
|
20
|
+
var obj = { type: 'string' };
|
|
21
|
+
var checkLabel = (0, has_label_1.hasLabel)('firstname');
|
|
22
|
+
expect(checkLabel(obj)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it.skip('returns false if the label is an empty string', function () {
|
|
25
|
+
var obj = { label: '', type: 'string' };
|
|
26
|
+
var checkLabel = (0, has_label_1.hasLabel)('');
|
|
27
|
+
expect(checkLabel(obj)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -7,3 +7,8 @@ tslib_1.__exportStar(require("./property"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./repository"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./types"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./decorator"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./find-limetype-by-label"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./get-properties-by-type"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./get-property-by-label"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./get-property-by-name"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./has-label"), exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LimeType } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function to find a limetype by its label in a collection of limetypes.
|
|
4
|
+
*
|
|
5
|
+
* The returned function searches through a collection of limetypes and returns
|
|
6
|
+
* the first one that matches the given label. This function is typically used
|
|
7
|
+
* to generate a callback for decorators or other higher-order logic.
|
|
8
|
+
*
|
|
9
|
+
* @param label - The label of the limetype to find.
|
|
10
|
+
* @returns A function that takes a collection of limetypes and returns the first
|
|
11
|
+
* limetype that matches the label, or `undefined` if no match is found.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { findLimetypeByLabel } from '@limetech/lime-web-components';
|
|
16
|
+
*
|
|
17
|
+
* const limetypes = {
|
|
18
|
+
* company: { label: 'company', properties: {} },
|
|
19
|
+
* person: { label: 'person', properties: {} },
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* const findPersonLimetype = findLimetypeByLabel('person');
|
|
23
|
+
* const personLimetype = findPersonLimetype(limetypes);
|
|
24
|
+
* console.log(personLimetype); // { label: 'person', properties: {} }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Using `findLimetypeByLabel` as a callback for a decorator
|
|
30
|
+
* import { findLimetypeByLabel, SelectLimeTypes } from '@limetech/lime-web-components';
|
|
31
|
+
*
|
|
32
|
+
* @SelectLimeTypes({
|
|
33
|
+
* map: [findLimetypeByLabel('person')],
|
|
34
|
+
* })
|
|
35
|
+
* private personLimetype: LimeType;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @group Lime types
|
|
40
|
+
*/
|
|
41
|
+
export declare const findLimetypeByLabel: (label: string) => (limetypes: Record<string, LimeType>) => LimeType;
|
|
42
|
+
//# sourceMappingURL=find-limetype-by-label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-limetype-by-label.d.ts","sourceRoot":"","sources":["../../src/limetype/find-limetype-by-label.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,GAAG,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,mBAAmB,UACpB,MAAM,iBAAiB,OAAO,MAAM,EAAE,QAAQ,CAAC,aAEtD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { hasLabel } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function to find a limetype by its label in a collection of limetypes.
|
|
4
|
+
*
|
|
5
|
+
* The returned function searches through a collection of limetypes and returns
|
|
6
|
+
* the first one that matches the given label. This function is typically used
|
|
7
|
+
* to generate a callback for decorators or other higher-order logic.
|
|
8
|
+
*
|
|
9
|
+
* @param label - The label of the limetype to find.
|
|
10
|
+
* @returns A function that takes a collection of limetypes and returns the first
|
|
11
|
+
* limetype that matches the label, or `undefined` if no match is found.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { findLimetypeByLabel } from '@limetech/lime-web-components';
|
|
16
|
+
*
|
|
17
|
+
* const limetypes = {
|
|
18
|
+
* company: { label: 'company', properties: {} },
|
|
19
|
+
* person: { label: 'person', properties: {} },
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* const findPersonLimetype = findLimetypeByLabel('person');
|
|
23
|
+
* const personLimetype = findPersonLimetype(limetypes);
|
|
24
|
+
* console.log(personLimetype); // { label: 'person', properties: {} }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Using `findLimetypeByLabel` as a callback for a decorator
|
|
30
|
+
* import { findLimetypeByLabel, SelectLimeTypes } from '@limetech/lime-web-components';
|
|
31
|
+
*
|
|
32
|
+
* @SelectLimeTypes({
|
|
33
|
+
* map: [findLimetypeByLabel('person')],
|
|
34
|
+
* })
|
|
35
|
+
* private personLimetype: LimeType;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @group Lime types
|
|
40
|
+
*/
|
|
41
|
+
export const findLimetypeByLabel = (label) => (limetypes) => {
|
|
42
|
+
return Object.values(limetypes).find(hasLabel(label));
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-limetype-by-label.spec.d.ts","sourceRoot":"","sources":["../../src/limetype/find-limetype-by-label.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { company } from '../testing/limetypes/company';
|
|
2
|
+
import { person } from '../testing/limetypes/person';
|
|
3
|
+
import { findLimetypeByLabel } from './find-limetype-by-label';
|
|
4
|
+
describe('findLimetypeByLabel', () => {
|
|
5
|
+
const limetypes = {
|
|
6
|
+
company: Object.assign({}, company),
|
|
7
|
+
person: Object.assign({}, person),
|
|
8
|
+
};
|
|
9
|
+
it('returns a function', () => {
|
|
10
|
+
const result = findLimetypeByLabel('person');
|
|
11
|
+
expect(typeof result).toBe('function');
|
|
12
|
+
});
|
|
13
|
+
describe('when the label exists', () => {
|
|
14
|
+
it('returns the correct limetype', () => {
|
|
15
|
+
const findUser = findLimetypeByLabel('person');
|
|
16
|
+
const result = findUser(limetypes);
|
|
17
|
+
expect(result).toStrictEqual(person);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('when the label does not exist', () => {
|
|
21
|
+
it('returns undefined', () => {
|
|
22
|
+
const findNonexistent = findLimetypeByLabel('nonexistent');
|
|
23
|
+
const result = findNonexistent(limetypes);
|
|
24
|
+
expect(result).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('when the limetypes object is empty', () => {
|
|
28
|
+
it('returns undefined', () => {
|
|
29
|
+
const findUser = findLimetypeByLabel('person');
|
|
30
|
+
const result = findUser({});
|
|
31
|
+
expect(result).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('when the input is invalid', () => {
|
|
35
|
+
it('throws an error if limetypes is null', () => {
|
|
36
|
+
const findUser = findLimetypeByLabel('person');
|
|
37
|
+
expect(() => findUser(null)).toThrow();
|
|
38
|
+
});
|
|
39
|
+
it('throws an error if limetypes is undefined', () => {
|
|
40
|
+
const findUser = findLimetypeByLabel('person');
|
|
41
|
+
expect(() => findUser(undefined)).toThrow();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LimeProperty, LimeType, PropertyType } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves all properties of a specific type from a limetype.
|
|
4
|
+
*
|
|
5
|
+
* This function filters the properties of a limetype and returns
|
|
6
|
+
* those that match the specified property type.
|
|
7
|
+
*
|
|
8
|
+
* @param limetype - The limetype containing the properties.
|
|
9
|
+
* @param type - The type of properties to retrieve.
|
|
10
|
+
* @returns An array of properties that match the specified type.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
* @group Lime types
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPropertiesByType(limetype: LimeType, type: PropertyType): LimeProperty[];
|
|
16
|
+
//# sourceMappingURL=get-properties-by-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-properties-by-type.d.ts","sourceRoot":"","sources":["../../src/limetype/get-properties-by-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAC/B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,YAAY,GACnB,YAAY,EAAE,CAIhB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves all properties of a specific type from a limetype.
|
|
3
|
+
*
|
|
4
|
+
* This function filters the properties of a limetype and returns
|
|
5
|
+
* those that match the specified property type.
|
|
6
|
+
*
|
|
7
|
+
* @param limetype - The limetype containing the properties.
|
|
8
|
+
* @param type - The type of properties to retrieve.
|
|
9
|
+
* @returns An array of properties that match the specified type.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
* @group Lime types
|
|
13
|
+
*/
|
|
14
|
+
export function getPropertiesByType(limetype, type) {
|
|
15
|
+
return Object.values(limetype.properties).filter((property) => property.type === type);
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-properties-by-type.spec.d.ts","sourceRoot":"","sources":["../../src/limetype/get-properties-by-type.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { person } from '../testing/limetypes/person';
|
|
2
|
+
import { getPropertiesByType } from './get-properties-by-type';
|
|
3
|
+
describe('getPropertiesByType', () => {
|
|
4
|
+
it('retrieves all properties of a specified type', () => {
|
|
5
|
+
const result = getPropertiesByType(Object.assign({}, person), 'string');
|
|
6
|
+
expect(result).toStrictEqual([
|
|
7
|
+
person.properties.firstname,
|
|
8
|
+
person.properties.lastname,
|
|
9
|
+
person.properties.name,
|
|
10
|
+
person.properties.position,
|
|
11
|
+
]);
|
|
12
|
+
});
|
|
13
|
+
it('returns an empty array if no properties match the type', () => {
|
|
14
|
+
const result = getPropertiesByType(Object.assign({}, person), 'integer');
|
|
15
|
+
expect(result).toStrictEqual([]);
|
|
16
|
+
});
|
|
17
|
+
describe('edge cases', () => {
|
|
18
|
+
it('returns an empty array if limetype has no properties', () => {
|
|
19
|
+
const emptyLimetype = {
|
|
20
|
+
label: 'empty',
|
|
21
|
+
properties: {},
|
|
22
|
+
};
|
|
23
|
+
const result = getPropertiesByType(emptyLimetype, 'string');
|
|
24
|
+
expect(result).toStrictEqual([]);
|
|
25
|
+
});
|
|
26
|
+
it('throws an error if limetype is null or undefined', () => {
|
|
27
|
+
expect(() => getPropertiesByType(null, 'string')).toThrow();
|
|
28
|
+
expect(() => getPropertiesByType(undefined, 'string')).toThrow();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LimeProperty, LimeType } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a property from a limetype by its label.
|
|
4
|
+
*
|
|
5
|
+
* This function searches through the properties of a given limetype
|
|
6
|
+
* and returns the first property that matches the specified label.
|
|
7
|
+
*
|
|
8
|
+
* @param limetype - The limetype containing the properties.
|
|
9
|
+
* @param label - The label of the property to retrieve.
|
|
10
|
+
* @returns The property with the specified label, or `undefined` if no match is found.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
* @group Lime types
|
|
14
|
+
*/
|
|
15
|
+
export declare function getPropertyByLabel(limetype: LimeType, label: string): LimeProperty | undefined;
|
|
16
|
+
//# sourceMappingURL=get-property-by-label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-property-by-label.d.ts","sourceRoot":"","sources":["../../src/limetype/get-property-by-label.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAC9B,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,GACd,YAAY,GAAG,SAAS,CAE1B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { hasLabel } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a property from a limetype by its label.
|
|
4
|
+
*
|
|
5
|
+
* This function searches through the properties of a given limetype
|
|
6
|
+
* and returns the first property that matches the specified label.
|
|
7
|
+
*
|
|
8
|
+
* @param limetype - The limetype containing the properties.
|
|
9
|
+
* @param label - The label of the property to retrieve.
|
|
10
|
+
* @returns The property with the specified label, or `undefined` if no match is found.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
* @group Lime types
|
|
14
|
+
*/
|
|
15
|
+
export function getPropertyByLabel(limetype, label) {
|
|
16
|
+
return Object.values(limetype.properties).find(hasLabel(label));
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-property-by-label.spec.d.ts","sourceRoot":"","sources":["../../src/limetype/get-property-by-label.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { person } from '../testing/limetypes/person';
|
|
2
|
+
import { getPropertyByLabel } from './get-property-by-label';
|
|
3
|
+
describe('getPropertyByLabel', () => {
|
|
4
|
+
it('retrieves a property by its label', () => {
|
|
5
|
+
const result = getPropertyByLabel(Object.assign({}, person), 'primaryemailaddress');
|
|
6
|
+
expect(result).toStrictEqual(person.properties.email);
|
|
7
|
+
});
|
|
8
|
+
it('returns undefined if no property matches the label', () => {
|
|
9
|
+
const result = getPropertyByLabel(Object.assign({}, person), 'nonexistent');
|
|
10
|
+
expect(result).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
describe('edge cases', () => {
|
|
13
|
+
it('returns undefined if limetype has no properties', () => {
|
|
14
|
+
const emptyLimetype = {
|
|
15
|
+
label: 'empty',
|
|
16
|
+
properties: {},
|
|
17
|
+
};
|
|
18
|
+
const result = getPropertyByLabel(emptyLimetype, 'primaryemailaddress');
|
|
19
|
+
expect(result).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it('throws an error if limetype is null or undefined', () => {
|
|
22
|
+
expect(() => getPropertyByLabel(null, 'primaryemailaddress')).toThrow();
|
|
23
|
+
expect(() => getPropertyByLabel(undefined, 'primaryemailaddress')).toThrow();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LimeProperty, LimeType } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a property from a limetype by its name.
|
|
4
|
+
*
|
|
5
|
+
* This function extracts a specific property from a given limetype
|
|
6
|
+
* based on the property's name.
|
|
7
|
+
*
|
|
8
|
+
* @param limetype - The limetype containing the properties.
|
|
9
|
+
* @param propertyName - The name of the property to retrieve.
|
|
10
|
+
* @returns The property with the specified name.
|
|
11
|
+
* @throws Will throw an error if the property name does not exist in the limetype.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
* @group Lime types
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPropertyByName(limetype: LimeType, propertyName: string): LimeProperty;
|
|
17
|
+
//# sourceMappingURL=get-property-by-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-property-by-name.d.ts","sourceRoot":"","sources":["../../src/limetype/get-property-by-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAE3C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC7B,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,GACrB,YAAY,CAEd"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves a property from a limetype by its name.
|
|
3
|
+
*
|
|
4
|
+
* This function extracts a specific property from a given limetype
|
|
5
|
+
* based on the property's name.
|
|
6
|
+
*
|
|
7
|
+
* @param limetype - The limetype containing the properties.
|
|
8
|
+
* @param propertyName - The name of the property to retrieve.
|
|
9
|
+
* @returns The property with the specified name.
|
|
10
|
+
* @throws Will throw an error if the property name does not exist in the limetype.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
* @group Lime types
|
|
14
|
+
*/
|
|
15
|
+
export function getPropertyByName(limetype, propertyName) {
|
|
16
|
+
return limetype.properties[propertyName];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-property-by-name.spec.d.ts","sourceRoot":"","sources":["../../src/limetype/get-property-by-name.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { person } from '../testing/limetypes/person';
|
|
2
|
+
import { getPropertyByName } from './get-property-by-name';
|
|
3
|
+
describe('getPropertyByName', () => {
|
|
4
|
+
it('retrieves a property by its name', () => {
|
|
5
|
+
const result = getPropertyByName(Object.assign({}, person), 'email');
|
|
6
|
+
expect(result).toStrictEqual(person.properties.email);
|
|
7
|
+
});
|
|
8
|
+
it('returns `undefined` if the property does not exist', () => {
|
|
9
|
+
const result = getPropertyByName(Object.assign({}, person), 'age');
|
|
10
|
+
expect(result).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
describe('edge cases', () => {
|
|
13
|
+
it('returns undefined if limetype has no properties', () => {
|
|
14
|
+
const emptyLimetype = {
|
|
15
|
+
label: 'Empty',
|
|
16
|
+
properties: {},
|
|
17
|
+
};
|
|
18
|
+
const result = getPropertyByName(emptyLimetype, 'email');
|
|
19
|
+
expect(result).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it('throws an error if limetype is null or undefined', () => {
|
|
22
|
+
expect(() => getPropertyByName(null, 'email')).toThrow();
|
|
23
|
+
expect(() => getPropertyByName(undefined, 'email')).toThrow();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LimeProperty, LimeType } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function to check if a given object has a specific label.
|
|
4
|
+
*
|
|
5
|
+
* The returned function takes an object (a `LimeType` or `LimeProperty`) and
|
|
6
|
+
* checks whether it contains the specified label. This function is typically
|
|
7
|
+
* used as a callback for array methods like `.find` or `.filter`.
|
|
8
|
+
*
|
|
9
|
+
* @param label - The label to check for.
|
|
10
|
+
* @returns A function that takes an optional object and returns `true` if the label matches, or `false` otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { hasLabel } from '@limetech/lime-web-components';
|
|
15
|
+
*
|
|
16
|
+
* const properties = [
|
|
17
|
+
* { label: 'name', type: 'string' },
|
|
18
|
+
* { label: 'email', type: 'string' },
|
|
19
|
+
* ];
|
|
20
|
+
*
|
|
21
|
+
* const emailProperty = properties.find(hasLabel('email'));
|
|
22
|
+
* console.log(emailProperty); // { label: 'email', type: 'string' }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @group Lime types
|
|
27
|
+
*/
|
|
28
|
+
export declare const hasLabel: (label: string) => (object?: LimeType | LimeProperty) => boolean;
|
|
29
|
+
//# sourceMappingURL=has-label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-label.d.ts","sourceRoot":"","sources":["../../src/limetype/has-label.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,QAAQ,UACT,MAAM,eAAe,QAAQ,GAAG,YAAY,YAEnD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function to check if a given object has a specific label.
|
|
3
|
+
*
|
|
4
|
+
* The returned function takes an object (a `LimeType` or `LimeProperty`) and
|
|
5
|
+
* checks whether it contains the specified label. This function is typically
|
|
6
|
+
* used as a callback for array methods like `.find` or `.filter`.
|
|
7
|
+
*
|
|
8
|
+
* @param label - The label to check for.
|
|
9
|
+
* @returns A function that takes an optional object and returns `true` if the label matches, or `false` otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { hasLabel } from '@limetech/lime-web-components';
|
|
14
|
+
*
|
|
15
|
+
* const properties = [
|
|
16
|
+
* { label: 'name', type: 'string' },
|
|
17
|
+
* { label: 'email', type: 'string' },
|
|
18
|
+
* ];
|
|
19
|
+
*
|
|
20
|
+
* const emailProperty = properties.find(hasLabel('email'));
|
|
21
|
+
* console.log(emailProperty); // { label: 'email', type: 'string' }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
* @group Lime types
|
|
26
|
+
*/
|
|
27
|
+
export const hasLabel = (label) => (object) => {
|
|
28
|
+
return (object === null || object === void 0 ? void 0 : object.label) === label;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-label.spec.d.ts","sourceRoot":"","sources":["../../src/limetype/has-label.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { person } from '../testing/limetypes/person';
|
|
2
|
+
import { hasLabel } from './has-label';
|
|
3
|
+
describe('hasLabel', () => {
|
|
4
|
+
it('returns true if the object has the specified label', () => {
|
|
5
|
+
const checkLabel = hasLabel('primaryemailaddress');
|
|
6
|
+
expect(checkLabel(person.properties.email)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
it('returns false if the object does not have the specified label', () => {
|
|
9
|
+
const checkLabel = hasLabel('firstname');
|
|
10
|
+
expect(checkLabel(person.properties.email)).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
it('returns false if the object is undefined', () => {
|
|
13
|
+
const checkLabel = hasLabel('firstname');
|
|
14
|
+
expect(checkLabel(undefined)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
describe('edge cases', () => {
|
|
17
|
+
it('returns false if the object has no label property', () => {
|
|
18
|
+
const obj = { type: 'string' };
|
|
19
|
+
const checkLabel = hasLabel('firstname');
|
|
20
|
+
expect(checkLabel(obj)).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
// At the moment, if both the label and the search string are empty
|
|
23
|
+
// strings, the function will return true.
|
|
24
|
+
// That's probably a mistake? /Ads
|
|
25
|
+
it.skip('returns false if the label is an empty string', () => {
|
|
26
|
+
const obj = { label: '', type: 'string' };
|
|
27
|
+
const checkLabel = hasLabel('');
|
|
28
|
+
expect(checkLabel(obj)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
package/dist/limetype/index.d.ts
CHANGED
|
@@ -4,4 +4,9 @@ export * from './property';
|
|
|
4
4
|
export * from './repository';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './decorator';
|
|
7
|
+
export * from './find-limetype-by-label';
|
|
8
|
+
export * from './get-properties-by-type';
|
|
9
|
+
export * from './get-property-by-label';
|
|
10
|
+
export * from './get-property-by-name';
|
|
11
|
+
export * from './has-label';
|
|
7
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/limetype/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/limetype/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC"}
|
package/dist/limetype/index.js
CHANGED
|
@@ -4,3 +4,8 @@ export * from './property';
|
|
|
4
4
|
export * from './repository';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './decorator';
|
|
7
|
+
export * from './find-limetype-by-label';
|
|
8
|
+
export * from './get-properties-by-type';
|
|
9
|
+
export * from './get-property-by-label';
|
|
10
|
+
export * from './get-property-by-name';
|
|
11
|
+
export * from './has-label';
|