mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 01:22:54 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d7a0e10c6 | ||
|
|
4865f911d1 | ||
|
|
15ae5e0873 | ||
|
|
a246bdea84 | ||
|
|
8641bfc877 | ||
|
|
d34e66fbbc |
@@ -1,8 +1,10 @@
|
|||||||
|
## [0.38.1](https://gitlab.com/openstapps/core/compare/v0.38.0...v0.38.1) (2020-11-02)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [0.38.0](https://gitlab.com/openstapps/core/compare/v0.37.0...v0.38.0) (2020-10-30)
|
# [0.38.0](https://gitlab.com/openstapps/core/compare/v0.37.0...v0.38.0) (2020-10-30)
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* Replaced `jsonschema` package for `json-schema`
|
|
||||||
|
|
||||||
# [0.37.0](https://gitlab.com/openstapps/core/compare/v0.36.0...v0.37.0) (2020-09-23)
|
# [0.37.0](https://gitlab.com/openstapps/core/compare/v0.36.0...v0.37.0) (2020-09-23)
|
||||||
|
|
||||||
|
|||||||
@@ -36,15 +36,16 @@ Annotations are used to add additional informations to fields, which are used to
|
|||||||
External dependencies can not be covered by the annotations. Documentation about some of the annotations can be found in: [typedoc](https://typedoc.org/guides/doccomments/)
|
External dependencies can not be covered by the annotations. Documentation about some of the annotations can be found in: [typedoc](https://typedoc.org/guides/doccomments/)
|
||||||
|
|
||||||
| annotation | description | parameters |
|
| annotation | description | parameters |
|
||||||
|-------------------|-------------------------------------------|---------------|
|
|-------------------|-------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
|
||||||
| `@aggregatable` | used for generating of aggregations of the field if the core schema is used to put data into a database/key-value store | whether the property is being used on the top type or across all types: `global` |
|
| `@aggregatable` | used for generating of aggregations of the field if the core schema is used to put data into a database/key-value store | whether the property is being used on the top type or across all types: `global` |
|
||||||
| `@float` | number field is interpreted as float | |
|
| `@float` | number field is interpreted as float | |
|
||||||
| `@indexable` | marks the type as indexable if the core schema is used to put data into a database/key-value store| |
|
| `@indexable` | marks the type as indexable if the core schema is used to put data into a database/key-value store | |
|
||||||
| `@integer` | number field is interpreted as integer | |
|
| `@integer` | number field is interpreted as integer | |
|
||||||
| `@keyword` | string field is interpreted as keyword | |
|
| `@keyword` | string field is interpreted as keyword | |
|
||||||
| `@sortable` | field is sortable if the core schema is used to put data into a database/key-value store | sort method to be used: `ducet`, `price`, `distance` |
|
| `@sortable` | field is sortable if the core schema is used to put data into a database/key-value store | sort method to be used: `ducet`, `price`, `distance` |
|
||||||
| `@text` | string field is interpreted as text | |
|
| `@text` | string field is interpreted as text | |
|
||||||
| `@validatable` | marks the type as validatable if the core schema is used to put data into a database/key-value store | |
|
| `@validatable` | marks the type as validatable if the core schema is used to put data into a database/key-value store | |
|
||||||
| `@filterable` | non-object/nested field is filterable if the core schema is used to put data into a database/key-value store | |
|
| `@filterable` | non-object/nested field is filterable if the core schema is used to put data into a database/key-value store | |
|
||||||
|
| `@inheritTags` | inherit all tags from another field | `[SCThingType]::[field]` |
|
||||||
|
|
||||||
|
*Note: tags ignore casing, but for consistency they should use the variants proposed here.*
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@openstapps/core",
|
"name": "@openstapps/core",
|
||||||
"version": "0.38.1",
|
"version": "0.39.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@openstapps/core",
|
"name": "@openstapps/core",
|
||||||
"version": "0.38.1",
|
"version": "0.39.0",
|
||||||
"description": "StAppsCore - Generalized model of data",
|
"description": "StAppsCore - Generalized model of data",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Model",
|
"Model",
|
||||||
|
|||||||
@@ -224,29 +224,27 @@ export class SCThingTranslator {
|
|||||||
*/
|
*/
|
||||||
public translatedPropertyNames<T extends SCThing>(type: SCThingType,
|
public translatedPropertyNames<T extends SCThing>(type: SCThingType,
|
||||||
language?: keyof SCTranslations<T>): T | undefined {
|
language?: keyof SCTranslations<T>): T | undefined {
|
||||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
return this.getAllMetaFieldTranslations(type, language ?? this.language) as T;
|
||||||
|
|
||||||
return this.getAllMetaFieldTranslations(type, targetLanguage) as T;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a SCThingType this function will translate it
|
* Given a SCThingType and a corresponding property name it returns the known property value translation
|
||||||
*
|
* Access pattern to the meta object containing the translation can be thought of as type.field[key] with key being optional
|
||||||
* @param type The type that will be translated
|
* @example
|
||||||
* @param language The language the type will be translated to
|
* const translatedMetaDish = translator.translatedPropertyNames(SCThingType.Dish, 'categories', 'main dish');
|
||||||
* @returns Known translation of type parameter
|
* @param type The type for whose property values a translation is required
|
||||||
|
* @param field The property for which a translation is required
|
||||||
|
* @param key If specified tries to access the field with this key
|
||||||
|
* @param language The language all property names will be translated to
|
||||||
|
* @returns Known translation for the property
|
||||||
*/
|
*/
|
||||||
public translatedThingType<T extends unknown>(type: SCThingType,
|
public translatedPropertyValue<T extends unknown>(type: SCThingType,
|
||||||
language?: keyof SCTranslations<T>): string {
|
field: string,
|
||||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
key?: string,
|
||||||
const metaClass = this.getMetaClassInstance(type);
|
language?: keyof SCTranslations<T>): string | undefined {
|
||||||
|
const fieldTranslation = this.getMetaClassInstance(type).fieldValueTranslations[language ?? this.language]?.[field];
|
||||||
|
|
||||||
if (typeof metaClass.fieldValueTranslations[targetLanguage] !== 'undefined' &&
|
return fieldTranslation?.[key ?? ''] ?? key ?? fieldTranslation;
|
||||||
typeof metaClass.fieldValueTranslations[targetLanguage].type !== 'undefined') {
|
|
||||||
return metaClass.fieldValueTranslations[targetLanguage].type as string ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -269,13 +269,23 @@ export class MetaTranslationSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
public retrieveTranslatedThingType() {
|
public retrieveTranslatedPropertyValueType() {
|
||||||
const dishTypeDE = translator.translatedThingType(dish.type);
|
const dishTypeDE = translator.translatedPropertyValue(dish.type, 'type');
|
||||||
const dishTypeEN = translator.translatedThingType(dish.type, 'en');
|
const dishTypeEN = translator.translatedPropertyValue(dish.type, 'type', undefined, 'en');
|
||||||
const dishTypeBASE = translatorWithFallback.translatedThingType(dish.type);
|
const dishTypeBASE = translatorWithFallback.translatedPropertyValue(dish.type, 'type');
|
||||||
expect(dishTypeDE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.de.type);
|
expect(dishTypeDE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.de.type);
|
||||||
expect(dishTypeEN).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
|
expect(dishTypeEN).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
|
||||||
expect(dishTypeBASE).to.deep.equal(SCDishMeta.getInstance().fieldValueTranslations.en.type);
|
expect(dishTypeBASE).to.be.undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
public retrieveTranslatedPropertyValueNested() {
|
||||||
|
const dishTypeDE = translator.translatedPropertyValue<SCDish>(dish.type, 'categories', 'main dish');
|
||||||
|
const dishTypeEN = translator.translatedPropertyValue<SCDish>(dish.type, 'categories', 'main dish', 'en');
|
||||||
|
const dishTypeBASE = translatorWithFallback.translatedPropertyValue(dish.type, 'categories', 'main dish');
|
||||||
|
expect(dishTypeDE).to.deep.equal(SCDishMeta.getInstance<SCDishMeta>().fieldValueTranslations.de.categories['main dish']);
|
||||||
|
expect(dishTypeEN).to.deep.equal(dish.categories[0]);
|
||||||
|
expect(dishTypeBASE).to.deep.equal(dish.categories[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
|
|||||||
Reference in New Issue
Block a user