Compare commits

..

10 Commits

Author SHA1 Message Date
Sebastian Lange
2f96bc8569 0.36.0 2020-07-16 11:37:56 +02:00
Rainer Killinger
9ce4026b1a build: lower npm audit vulnerabilities 2020-07-01 08:00:26 +00:00
Rainer Killinger
e434b2d26e test: add tests for translatedThingType function 2020-07-01 08:00:26 +00:00
Rainer Killinger
fe7f1a53ae feat: add function to get translated SCThingType 2020-07-01 08:00:26 +00:00
Frank Nagel
907d61b5d2 ci: Change 'npm audit' failure behaviour
The audit fails only if the results include a vulnerability with a level of
at least 'high' in scheduled pipelines.
2020-06-19 13:12:14 +02:00
Rainer Killinger
5fb9755841 docs: update changelog 2020-05-13 11:59:43 +02:00
Rainer Killinger
e5dd02eeca 0.35.0 2020-05-13 11:59:33 +02:00
Rainer Killinger
e7b4a426a9 test: adapt tests for translatedPropertyNames 2020-05-04 13:09:03 +02:00
Rainer Killinger
7dd74af305 refactor: simplify use of translatedPropertyNames 2020-05-04 13:08:56 +02:00
Rainer Killinger
4409101647 docs: update changelog 2020-04-21 13:40:19 +02:00
6 changed files with 963 additions and 435 deletions

View File

@@ -37,7 +37,7 @@ audit:
scheduled-audit:
stage: audit
script:
- npm audit
- npm audit --audit-level=high
only:
- schedules

View File

@@ -1,3 +1,18 @@
# [0.35.0](https://gitlab.com/openstapps/core/compare/v0.34.0...v0.35.0) (2020-05-13)
# [0.34.0](https://gitlab.com/openstapps/core/compare/v0.33.0...v0.34.0) (2020-04-21)
### Features
* add [@sortable](https://gitlab.com/sortable) tags to certain translatable properties ([f5e8856](https://gitlab.com/openstapps/core/commit/f5e88569eb75578febbcde67259c0c14563e53fe))
* annotate SCThing uid and url as filterable ([70c1a3e](https://gitlab.com/openstapps/core/commit/70c1a3eaa3d1c88f4b86f0df86d0d362ad1f930c))
* Update src/things/book.ts - made ISBN optional ([6060113](https://gitlab.com/openstapps/core/commit/6060113df56b871bb5014a8a961974895e52158f))
# [0.33.0](https://gitlab.com/openstapps/core/compare/v0.32.0...v0.33.0) (2020-02-11)

1337
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@openstapps/core",
"version": "0.34.0",
"version": "0.36.0",
"description": "StAppsCore - Generalized model of data",
"keywords": [
"Model",

View File

@@ -218,15 +218,35 @@ export class SCThingTranslator {
* All the values will be set to the known translations of the property/key name
* @example
* const translatedMetaDish = translator.translatedPropertyNames<SCCourseOfStudies>(SCThingType.CourseOfStudies);
* @param thing The thing whose property names will be translated
* @param type The type whose property names will be translated
* @param language The language all property names will be translated to
* @returns An object with the properties of the SCThingType where the values are the known property tranlations
*/
public translatedPropertyNames<T extends SCThing>(thing: T,
public translatedPropertyNames<T extends SCThing>(type: SCThingType,
language?: keyof SCTranslations<T>): T | undefined {
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
return this.getAllMetaFieldTranslations(thing.type, targetLanguage) as T;
return this.getAllMetaFieldTranslations(type, targetLanguage) as T;
}
/**
* Given a SCThingType this function will translate it
*
* @param type The type that will be translated
* @param language The language the type will be translated to
* @returns Known translation of type parameter
*/
public translatedThingType<T extends unknown>(type: SCThingType,
language?: keyof SCTranslations<T>): string {
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
const metaClass = this.getMetaClassInstance(type);
if (typeof metaClass.fieldValueTranslations[targetLanguage] !== 'undefined' &&
typeof metaClass.fieldValueTranslations[targetLanguage].type !== 'undefined') {
return metaClass.fieldValueTranslations[targetLanguage].type as string ;
}
return type;
}
/**

View File

@@ -256,20 +256,30 @@ export class MetaTranslationSpec {
@test
public consistencyWithMetaClass() {
const dishMetaTranslationsDE = translator.translatedPropertyNames(dish);
const dishMetaTranslationsEN = translator.translatedPropertyNames(dish, 'en');
const dishMetaTranslationsDE = translator.translatedPropertyNames(dish.type);
const dishMetaTranslationsEN = translator.translatedPropertyNames(dish.type, 'en');
expect(dishMetaTranslationsEN).to.not.deep.equal(dishMetaTranslationsDE);
expect(dishMetaTranslationsDE).to.deep.equal(SCDishMeta.getInstance().fieldTranslations.de);
expect(dishMetaTranslationsEN).to.deep.equal(SCDishMeta.getInstance().fieldTranslations.en);
}
@test
public retrieveTranslatedThingType() {
const dishTypeDE = translator.translatedThingType(dish.type);
const dishTypeEN = translator.translatedThingType(dish.type, 'en');
const dishTypeBASE = translatorWithFallback.translatedThingType(dish.type);
expect(dishTypeDE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.de.type);
expect(dishTypeEN).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
expect(dishTypeBASE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
}
@test
public thingWithoutMetaClass() {
const dishCopy = clone(dish);
const typeNonExistant = eval("(x) => x + 'typeNonExistant';");
// this will assign a non existant SCThingType to dishCopy
dishCopy.type = typeNonExistant();
const dishMetaTranslationsDE = translator.translatedPropertyNames(dishCopy);
const dishMetaTranslationsDE = translator.translatedPropertyNames(dishCopy.type);
expect(dishMetaTranslationsDE).to.be.undefined;
}
}