Skip to content

Commit

Permalink
Merge branch 'development' into dependabot/npm_and_yarn/sass-1.79.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Zasa-san authored Sep 26, 2024
2 parents 2903d08 + ecd15fc commit 0aaf436
Show file tree
Hide file tree
Showing 17 changed files with 751 additions and 91 deletions.
88 changes: 88 additions & 0 deletions app/api/entities.v2/EntityInputDataSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { availableLanguagesISO6391 } from 'shared/languagesList';

const linkSchema = {
type: 'object',
additionalProperties: false,
required: ['label', 'url'],
properties: {
label: { oneOf: [{ type: 'string' }, { type: 'null' }] },
url: { oneOf: [{ type: 'string' }, { type: 'null' }] },
},
};

const dateRangeSchema = {
type: 'object',
additionalProperties: false,
required: ['from', 'to'],
properties: {
from: { oneOf: [{ type: 'number' }, { type: 'null' }] },
to: { oneOf: [{ type: 'number' }, { type: 'null' }] },
},
};

const latLonSchema = {
type: 'object',
required: ['lon', 'lat'],
additionalProperties: false,
properties: {
label: { type: 'string' },
lat: { type: 'number', minimum: -90, maximum: 90 },
lon: { type: 'number', minimum: -180, maximum: 180 },
},
};

const geolocationSchema = {
type: 'array',
items: latLonSchema,
};

const propertyValueSchema = {
definitions: { linkSchema, dateRangeSchema, latLonSchema },
oneOf: [
{ type: 'null' },
{ type: 'string' },
{ type: 'number' },
{ type: 'boolean' },
linkSchema,
dateRangeSchema,
latLonSchema,
geolocationSchema,
],
};

const metadataObjectSchema = {
type: 'object',
definitions: { propertyValueSchema },
required: ['value'],
properties: {
value: propertyValueSchema,
},
};

const metadataSchema = {
type: 'object',
definitions: { metadataObjectSchema },
additionalProperties: {
anyOf: [{ type: 'array', items: metadataObjectSchema }],
},
patternProperties: {
'^.*_nested$': { type: 'array', items: { type: 'object' } },
},
};

export const entityInputDataSchema = {
title: 'EntityInputData',
$schema: 'http://json-schema.org/schema#',
type: 'object',
required: ['_id', 'sharedId', 'language', 'title', 'template', 'metadata'],
properties: {
_id: { type: 'string' },
sharedId: { type: 'string', minLength: 1 },
language: { enum: availableLanguagesISO6391 },
title: { type: 'string', minLength: 1 },
template: { type: 'string' },
metadata: metadataSchema,
},
};

export const emitSchemaTypes = true;
227 changes: 227 additions & 0 deletions app/api/entities.v2/EntityInputDataType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/* eslint-disable */
/**AUTO-GENERATED. RUN yarn emit-types to update.*/

export interface EntityInputData {
_id: string;
sharedId: string;
language:
| 'ab'
| 'aa'
| 'af'
| 'ak'
| 'sq'
| 'am'
| 'ar'
| 'an'
| 'hy'
| 'as'
| 'av'
| 'ae'
| 'ay'
| 'az'
| 'bm'
| 'ba'
| 'eu'
| 'be'
| 'bn'
| 'bh'
| 'bi'
| 'bs'
| 'br'
| 'bg'
| 'my'
| 'ca'
| 'ch'
| 'ce'
| 'ny'
| 'zh'
| 'zh-Hans'
| 'zh-Hant'
| 'cv'
| 'kw'
| 'co'
| 'cr'
| 'hr'
| 'cs'
| 'da'
| 'dv'
| 'nl'
| 'dz'
| 'en'
| 'eo'
| 'et'
| 'ee'
| 'fo'
| 'fj'
| 'fi'
| 'fr'
| 'ff'
| 'gl'
| 'gd'
| 'gv'
| 'ka'
| 'de'
| 'el'
| 'gn'
| 'gu'
| 'ht'
| 'ha'
| 'he'
| 'hz'
| 'hi'
| 'ho'
| 'hu'
| 'is'
| 'io'
| 'ig'
| 'in'
| 'ia'
| 'ie'
| 'iu'
| 'ik'
| 'ga'
| 'it'
| 'ja'
| 'jv'
| 'kl'
| 'kn'
| 'kr'
| 'ks'
| 'kk'
| 'km'
| 'ki'
| 'rw'
| 'rn'
| 'ky'
| 'kv'
| 'kg'
| 'ko'
| 'ku'
| 'kj'
| 'lo'
| 'la'
| 'lv'
| 'li'
| 'ln'
| 'lt'
| 'lu'
| 'lg'
| 'lb'
| 'mk'
| 'mg'
| 'ms'
| 'ml'
| 'mt'
| 'mi'
| 'mr'
| 'mh'
| 'mn'
| 'na'
| 'nv'
| 'ng'
| 'nd'
| 'ne'
| 'no'
| 'nb'
| 'nn'
| 'oc'
| 'oj'
| 'cu'
| 'or'
| 'om'
| 'os'
| 'pi'
| 'ps'
| 'fa'
| 'pl'
| 'pt'
| 'pa'
| 'qu'
| 'rm'
| 'ro'
| 'ru'
| 'se'
| 'sm'
| 'sg'
| 'sa'
| 'sr'
| 'sh'
| 'st'
| 'tn'
| 'sn'
| 'ii'
| 'sd'
| 'si'
| 'ss'
| 'sk'
| 'sl'
| 'so'
| 'nr'
| 'es'
| 'su'
| 'sw'
| 'sv'
| 'tl'
| 'ty'
| 'tg'
| 'ta'
| 'tt'
| 'te'
| 'th'
| 'bo'
| 'ti'
| 'to'
| 'ts'
| 'tr'
| 'tk'
| 'tw'
| 'ug'
| 'uk'
| 'ur'
| 'uz'
| 've'
| 'vi'
| 'vo'
| 'wa'
| 'cy'
| 'wo'
| 'fy'
| 'xh'
| 'yi'
| 'yo'
| 'za'
| 'zu';
title: string;
template: string;
metadata: {
[k: string]:
| {
value:
| null
| string
| number
| boolean
| {
label: string | null;
url: string | null;
}
| {
from: number | null;
to: number | null;
}
| {
label?: string;
lat: number;
lon: number;
}
| {
label?: string;
lat: number;
lon: number;
}[];
[k: string]: unknown | undefined;
}[]
| undefined;
};
[k: string]: unknown | undefined;
}
20 changes: 17 additions & 3 deletions app/api/entities/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ID from 'shared/uniqueID';

import { denormalizeMetadata, denormalizeRelated } from './denormalize';
import model from './entitiesModel';
import { EntityCreatedEvent } from './events/EntityCreatedEvent';
import { EntityUpdatedEvent } from './events/EntityUpdatedEvent';
import { EntityDeletedEvent } from './events/EntityDeletedEvent';
import { saveSelections } from './metadataExtraction/saveSelections';
Expand Down Expand Up @@ -149,15 +150,15 @@ async function updateEntity(entity, _template, unrestricted = false) {
await applicationEventsBus.emit(
new EntityUpdatedEvent({
before: docLanguages,
after: result,
after: await model.get({ sharedId: entity.sharedId }),
targetLanguageKey: entity.language,
})
);

return result;
}

async function createEntity(doc, languages, sharedId, docTemplate) {
async function createEntity(doc, [currentLanguage, languages], sharedId, docTemplate) {
if (!docTemplate) docTemplate = await templates.getById(doc.template);
const thesauriByKey = await templates.getRelatedThesauri(docTemplate);

Expand Down Expand Up @@ -203,6 +204,14 @@ async function createEntity(doc, languages, sharedId, docTemplate) {
await updateNewRelationships(v2RelationshipsUpdates);

await Promise.all(result.map(r => denormalizeAfterEntityCreation(r)));

await applicationEventsBus.emit(
new EntityCreatedEvent({
entities: await model.get({ sharedId }),
targetLanguageKey: currentLanguage,
})
);

return result;
}

Expand Down Expand Up @@ -410,7 +419,12 @@ export default {
docTemplate = defaultTemplate;
}
doc.metadata = doc.metadata || {};
await this.createEntity(this.sanitize(doc, docTemplate), languages, sharedId, docTemplate);
await this.createEntity(
this.sanitize(doc, docTemplate),
[language, languages],
sharedId,
docTemplate
);
}

const [entity] = includeDocuments
Expand Down
11 changes: 11 additions & 0 deletions app/api/entities/events/EntityCreatedEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AbstractEvent } from 'api/eventsbus';
import { EntitySchema } from 'shared/types/entityType';

interface EntityCreatedData {
entities: EntitySchema[];
targetLanguageKey: string;
}

class EntityCreatedEvent extends AbstractEvent<EntityCreatedData> {}

export { EntityCreatedEvent };
Loading

0 comments on commit 0aaf436

Please sign in to comment.