kuzzle-device-manager 3.0.0-3-dev.20 → 3.0.0-3-dev.21

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.
Files changed (65) hide show
  1. package/dist/lib/modules/asset/AssetService.d.ts +6 -0
  2. package/dist/lib/modules/asset/AssetService.js +46 -46
  3. package/dist/lib/modules/asset/AssetService.js.map +1 -1
  4. package/dist/lib/modules/asset/roles/RoleAssetsAdmin.d.ts +1 -0
  5. package/dist/lib/modules/asset/roles/RoleAssetsAdmin.js +2 -0
  6. package/dist/lib/modules/asset/roles/RoleAssetsAdmin.js.map +1 -1
  7. package/dist/lib/modules/asset/roles/RoleAssetsReader.d.ts +1 -0
  8. package/dist/lib/modules/asset/roles/RoleAssetsReader.js +2 -0
  9. package/dist/lib/modules/asset/roles/RoleAssetsReader.js.map +1 -1
  10. package/dist/lib/modules/device/DeviceService.js +23 -23
  11. package/dist/lib/modules/device/DeviceService.js.map +1 -1
  12. package/dist/lib/modules/device/roles/RoleDevicesAdmin.d.ts +1 -0
  13. package/dist/lib/modules/device/roles/RoleDevicesAdmin.js +2 -0
  14. package/dist/lib/modules/device/roles/RoleDevicesAdmin.js.map +1 -1
  15. package/dist/lib/modules/device/roles/RoleDevicesReader.d.ts +1 -0
  16. package/dist/lib/modules/device/roles/RoleDevicesReader.js +2 -0
  17. package/dist/lib/modules/device/roles/RoleDevicesReader.js.map +1 -1
  18. package/dist/lib/modules/group/GroupsService.d.ts +5 -0
  19. package/dist/lib/modules/group/GroupsService.js +39 -0
  20. package/dist/lib/modules/group/GroupsService.js.map +1 -1
  21. package/dist/lib/modules/group/index.d.ts +1 -0
  22. package/dist/lib/modules/group/index.js +1 -0
  23. package/dist/lib/modules/group/index.js.map +1 -1
  24. package/dist/lib/modules/group/roles/RoleGroupsAdmin.d.ts +1 -0
  25. package/dist/lib/modules/group/roles/RoleGroupsAdmin.js +2 -0
  26. package/dist/lib/modules/group/roles/RoleGroupsAdmin.js.map +1 -1
  27. package/dist/lib/modules/group/roles/RoleGroupsReader.d.ts +1 -0
  28. package/dist/lib/modules/group/roles/RoleGroupsReader.js +2 -0
  29. package/dist/lib/modules/group/roles/RoleGroupsReader.js.map +1 -1
  30. package/dist/lib/modules/group/types/GroupEvents.d.ts +8 -0
  31. package/dist/lib/modules/group/types/GroupEvents.js +3 -0
  32. package/dist/lib/modules/group/types/GroupEvents.js.map +1 -0
  33. package/dist/lib/modules/model/MetadataReferential.d.ts +119 -0
  34. package/dist/lib/modules/model/MetadataReferential.js +342 -0
  35. package/dist/lib/modules/model/MetadataReferential.js.map +1 -0
  36. package/dist/lib/modules/model/ModelService.d.ts +103 -1
  37. package/dist/lib/modules/model/ModelService.js +486 -185
  38. package/dist/lib/modules/model/ModelService.js.map +1 -1
  39. package/dist/lib/modules/model/ModelsConflicts.d.ts +23 -0
  40. package/dist/lib/modules/model/ModelsConflicts.js +54 -4
  41. package/dist/lib/modules/model/ModelsConflicts.js.map +1 -1
  42. package/dist/lib/modules/model/ModelsController.d.ts +11 -2
  43. package/dist/lib/modules/model/ModelsController.js +109 -11
  44. package/dist/lib/modules/model/ModelsController.js.map +1 -1
  45. package/dist/lib/modules/model/ModelsRegister.d.ts +33 -1
  46. package/dist/lib/modules/model/ModelsRegister.js +101 -3
  47. package/dist/lib/modules/model/ModelsRegister.js.map +1 -1
  48. package/dist/lib/modules/model/collections/modelsMappings.js +7 -0
  49. package/dist/lib/modules/model/collections/modelsMappings.js.map +1 -1
  50. package/dist/lib/modules/model/types/ModelApi.d.ts +93 -2
  51. package/dist/lib/modules/model/types/ModelContent.d.ts +67 -1
  52. package/dist/lib/modules/model/types/ModelContent.js.map +1 -1
  53. package/dist/lib/modules/model/types/ModelDefinition.d.ts +6 -3
  54. package/dist/lib/modules/model/types/ModelEvents.d.ts +6 -1
  55. package/dist/lib/modules/plugin/DeviceManagerEngine.d.ts +33 -0
  56. package/dist/lib/modules/plugin/DeviceManagerEngine.js +106 -10
  57. package/dist/lib/modules/plugin/DeviceManagerEngine.js.map +1 -1
  58. package/dist/lib/modules/plugin/DeviceManagerPlugin.d.ts +36 -1
  59. package/dist/lib/modules/plugin/DeviceManagerPlugin.js +42 -0
  60. package/dist/lib/modules/plugin/DeviceManagerPlugin.js.map +1 -1
  61. package/dist/lib/modules/plugin/types/DeviceManagerConfiguration.d.ts +11 -0
  62. package/dist/lib/modules/shared/utils/lock.d.ts +7 -1
  63. package/dist/lib/modules/shared/utils/lock.js +2 -2
  64. package/dist/lib/modules/shared/utils/lock.js.map +1 -1
  65. package/package.json +1 -1
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchReferencingModels = exports.fetchMetadataModels = exports.saveMetadataReferential = exports.fetchMetadataReferential = exports.getAddedInlineMetadata = exports.getEntryModelsConflicts = exports.enrichModelMetadata = exports.checkMetadataReferentialEntry = exports.resolveModelMetadata = exports.resolveModelMappings = exports.resolveMetadataMappings = exports.getReferentialNames = exports.isReferentialMapping = exports.withMetadataReferentialLock = exports.METADATA_REFERENTIAL_ID = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const InternalCollection_1 = require("../plugin/types/InternalCollection");
9
+ const lock_1 = require("../shared/utils/lock");
10
+ const MappingsConflictsError_1 = require("./MappingsConflictsError");
11
+ const ModelsConflicts_1 = require("./ModelsConflicts");
12
+ exports.METADATA_REFERENTIAL_ID = "model-metadata-referential";
13
+ /**
14
+ * TTL of the metadata referential lock. Kuzzle locks expire after 5s by default,
15
+ * less than a model write updating the engines collections.
16
+ */
17
+ const METADATA_REFERENTIAL_LOCK_TTL = 120000;
18
+ /**
19
+ * Runs cb holding the metadata referential lock, taken by every write of the referential
20
+ * and of asset, device and group models, so their conflicts checks see each other writes
21
+ */
22
+ async function withMetadataReferentialLock(cb) {
23
+ return (0, lock_1.lock)("device-manager/metadataReferential", cb, {
24
+ ttl: METADATA_REFERENTIAL_LOCK_TTL,
25
+ });
26
+ }
27
+ exports.withMetadataReferentialLock = withMetadataReferentialLock;
28
+ /**
29
+ * @returns true if the metadata mappings mark a metadata of the referential
30
+ */
31
+ function isReferentialMapping(mapping) {
32
+ return (lodash_1.default.isPlainObject(mapping) && mapping.referential === true);
33
+ }
34
+ exports.isReferentialMapping = isReferentialMapping;
35
+ /**
36
+ * Lists the metadata of a model coming from the metadata referential
37
+ */
38
+ function getReferentialNames(metadataMappings = {}) {
39
+ return Object.keys(metadataMappings).filter((name) => isReferentialMapping(metadataMappings[name]));
40
+ }
41
+ exports.getReferentialNames = getReferentialNames;
42
+ /**
43
+ * Replaces the referential markers of metadata mappings by the referential mappings.
44
+ * A marker of a metadata missing from the referential is dropped.
45
+ */
46
+ function resolveMetadataMappings(referential, metadataMappings = {}) {
47
+ const resolved = {};
48
+ for (const [name, mapping] of Object.entries(metadataMappings)) {
49
+ if (!isReferentialMapping(mapping)) {
50
+ resolved[name] = mapping;
51
+ }
52
+ else if (referential[name]) {
53
+ resolved[name] = lodash_1.default.cloneDeep(referential[name].mappings);
54
+ }
55
+ }
56
+ return resolved;
57
+ }
58
+ exports.resolveMetadataMappings = resolveMetadataMappings;
59
+ /**
60
+ * @returns The model with the referential markers of its metadata mappings resolved
61
+ */
62
+ function resolveModelMappings(referential, content) {
63
+ const twin = content[content.type];
64
+ return {
65
+ ...content,
66
+ [content.type]: {
67
+ ...twin,
68
+ metadataMappings: resolveMetadataMappings(referential, twin.metadataMappings),
69
+ },
70
+ };
71
+ }
72
+ exports.resolveModelMappings = resolveModelMappings;
73
+ function isDefaultOf(key, name) {
74
+ return key === name || key.startsWith(`${name}.`);
75
+ }
76
+ /**
77
+ * Merges, per locale, the model translations over the referential ones.
78
+ * A locale missing from the referential falls back to the metadata name and an empty description.
79
+ */
80
+ function mergeLocales(name, entryLocales = {}, modelLocales = {}) {
81
+ const locales = {};
82
+ for (const locale of lodash_1.default.union(Object.keys(entryLocales), Object.keys(modelLocales))) {
83
+ locales[locale] = {
84
+ description: "",
85
+ friendlyName: name,
86
+ ...entryLocales[locale],
87
+ ...modelLocales[locale],
88
+ };
89
+ }
90
+ return locales;
91
+ }
92
+ /**
93
+ * Builds the details of a metadata of the referential, the model values taking precedence
94
+ */
95
+ function enrichDetails(name, entry, details = {}) {
96
+ return {
97
+ ...(entry.editorHint ? { editorHint: lodash_1.default.cloneDeep(entry.editorHint) } : {}),
98
+ ...(entry.icon !== undefined ? { icon: entry.icon } : {}),
99
+ ...details,
100
+ locales: mergeLocales(name, entry.locales, details.locales),
101
+ };
102
+ }
103
+ /**
104
+ * Fills the details and default value of a referential metadata with the referential values,
105
+ * the model values taking precedence
106
+ */
107
+ function applyReferentialValues(name, entry, metadataDetails, defaultMetadata) {
108
+ metadataDetails[name] = enrichDetails(name, entry, metadataDetails[name]);
109
+ const hasDefault = Object.keys(defaultMetadata).some((key) => isDefaultOf(key, name));
110
+ if (!hasDefault && entry.defaultValue !== undefined) {
111
+ defaultMetadata[name] = lodash_1.default.cloneDeep(entry.defaultValue);
112
+ }
113
+ }
114
+ /**
115
+ * Resolves the referential metadata of a stored model, to be read:
116
+ * the markers are replaced by the referential mappings, the details and default values
117
+ * are merged over the current referential values.
118
+ * A marker of a metadata missing from the referential is dropped.
119
+ *
120
+ * @returns The model with its referential metadata resolved
121
+ */
122
+ function resolveModelMetadata(referential, content) {
123
+ const twin = content[content.type];
124
+ const metadataDetails = { ...twin.metadataDetails };
125
+ const defaultMetadata = { ...twin.defaultMetadata };
126
+ for (const name of getReferentialNames(twin.metadataMappings)) {
127
+ if (referential[name]) {
128
+ applyReferentialValues(name, referential[name], metadataDetails, defaultMetadata);
129
+ }
130
+ }
131
+ return {
132
+ ...content,
133
+ [content.type]: {
134
+ ...twin,
135
+ defaultMetadata,
136
+ metadataDetails,
137
+ metadataMappings: resolveMetadataMappings(referential, twin.metadataMappings),
138
+ },
139
+ };
140
+ }
141
+ exports.resolveModelMetadata = resolveModelMetadata;
142
+ /**
143
+ * Validates the shape of a metadata referential entry
144
+ *
145
+ * @throws The error built by createError if the entry is invalid
146
+ */
147
+ function checkMetadataReferentialEntry(name, entry, createError) {
148
+ if (typeof name !== "string" || name.length === 0 || name.includes(".")) {
149
+ throw createError(`Metadata name "${name}" is invalid: it must be a non empty string without "."`);
150
+ }
151
+ if (!lodash_1.default.isPlainObject(entry)) {
152
+ throw createError(`Metadata "${name}" definition must be an object`);
153
+ }
154
+ const mappings = entry.mappings;
155
+ if (!lodash_1.default.isPlainObject(mappings) ||
156
+ (typeof mappings.type !== "string" && !lodash_1.default.isPlainObject(mappings.properties))) {
157
+ throw createError(`Metadata "${name}" mappings must define either a "type" or "properties"`);
158
+ }
159
+ if (entry.locales !== undefined && !lodash_1.default.isPlainObject(entry.locales)) {
160
+ throw createError(`Metadata "${name}" locales must be an object`);
161
+ }
162
+ if (entry.editorHint !== undefined &&
163
+ (!lodash_1.default.isPlainObject(entry.editorHint) ||
164
+ typeof entry.editorHint.type !== "string")) {
165
+ throw createError(`Metadata "${name}" editorHint must be an object with a "type"`);
166
+ }
167
+ if (entry.icon !== undefined && typeof entry.icon !== "string") {
168
+ throw createError(`Metadata "${name}" icon must be a string`);
169
+ }
170
+ }
171
+ exports.checkMetadataReferentialEntry = checkMetadataReferentialEntry;
172
+ /**
173
+ * Lists the conflicts between an inline metadata and a referential entry of the same name.
174
+ * Any difference is a conflict: an inline metadata must be identical to the referential one.
175
+ */
176
+ function getInlineConflicts(name, inlineMappings, entry, basePath) {
177
+ if (lodash_1.default.isEqual(inlineMappings, entry.mappings)) {
178
+ return [];
179
+ }
180
+ const conflicts = (0, ModelsConflicts_1.findMappingsConflicts)({ [name]: entry.mappings }, { [name]: inlineMappings }, basePath);
181
+ // ? Same leaves but different structure (e.g. additional properties)
182
+ if (conflicts.length === 0) {
183
+ return [
184
+ {
185
+ currentType: JSON.stringify(entry.mappings),
186
+ newType: JSON.stringify(inlineMappings),
187
+ path: `${basePath}.${name}`,
188
+ },
189
+ ];
190
+ }
191
+ return conflicts;
192
+ }
193
+ function describeModel(context) {
194
+ return `${context.modelType} model "${context.model}"`;
195
+ }
196
+ /**
197
+ * Validates the metadata mappings of a model against the metadata referential and enriches
198
+ * the details and default values of the metadata coming from the referential.
199
+ *
200
+ * A metadata of the referential is marked `{ referential: true }` in metadataMappings, the marker is kept.
201
+ * Its details are the referential locales (merged per locale), editorHint and icon, overridden by the
202
+ * model ones. Its default value is the referential one, unless the model defines one.
203
+ *
204
+ * An inline metadata with the name of a referential entry must have the same mappings (legacy).
205
+ *
206
+ * @throws The error built by createError on an invalid marker or an unknown metadata
207
+ * @throws MappingsConflictsError if an inline metadata conflicts with the referential
208
+ */
209
+ function enrichModelMetadata(referential, fields, context) {
210
+ const model = describeModel(context);
211
+ const metadataMappings = fields.metadataMappings ?? {};
212
+ const metadataDetails = { ...fields.metadataDetails };
213
+ const defaultMetadata = { ...fields.defaultMetadata };
214
+ const warnings = [];
215
+ const conflicts = [];
216
+ if (!lodash_1.default.isPlainObject(metadataMappings)) {
217
+ throw context.createError(`Metadata mappings of ${model} must be an object`);
218
+ }
219
+ for (const [name, mapping] of Object.entries(metadataMappings)) {
220
+ const entry = referential[name];
221
+ if (lodash_1.default.isPlainObject(mapping) && "referential" in mapping) {
222
+ if (!isReferentialMapping(mapping) || Object.keys(mapping).length !== 1) {
223
+ throw context.createError(`The metadata "${name}" of ${model} must be { referential: true } to use the metadata referential`);
224
+ }
225
+ if (!entry) {
226
+ throw context.createError(`The ${model} uses the unknown referential metadata "${name}"`);
227
+ }
228
+ applyReferentialValues(name, entry, metadataDetails, defaultMetadata);
229
+ continue;
230
+ }
231
+ if (!entry) {
232
+ continue;
233
+ }
234
+ conflicts.push(...getInlineConflicts(name, mapping, entry, `${context.modelType}.metadataMappings`));
235
+ warnings.push(`The ${model} defines the metadata "${name}" inline, it should use the metadata referential instead with { referential: true }`);
236
+ }
237
+ if (conflicts.length > 0) {
238
+ throw new MappingsConflictsError_1.MappingsConflictsError(`Metadata of ${model} conflict with the metadata referential`, [
239
+ {
240
+ conflicts,
241
+ modelType: context.modelType,
242
+ newModel: context.model,
243
+ sourceModel: "metadata-referential",
244
+ },
245
+ ]);
246
+ }
247
+ return {
248
+ fields: { defaultMetadata, metadataDetails, metadataMappings },
249
+ resolvedMappings: resolveMetadataMappings(referential, metadataMappings),
250
+ warnings,
251
+ };
252
+ }
253
+ exports.enrichModelMetadata = enrichModelMetadata;
254
+ /**
255
+ * Lists the conflicts between a referential entry and the inline metadata of the same name of models
256
+ */
257
+ function getEntryModelsConflicts(name, entry, models) {
258
+ const chunks = [];
259
+ for (const content of models) {
260
+ const twin = content[content.type];
261
+ const mapping = twin.metadataMappings?.[name];
262
+ if (mapping === undefined || isReferentialMapping(mapping)) {
263
+ continue;
264
+ }
265
+ const conflicts = getInlineConflicts(name, mapping, entry, `${content.type}.metadataMappings`);
266
+ if (conflicts.length > 0) {
267
+ chunks.push({
268
+ conflicts,
269
+ modelType: content.type,
270
+ newModel: "metadata-referential",
271
+ sourceModel: twin.model,
272
+ });
273
+ }
274
+ }
275
+ return chunks;
276
+ }
277
+ exports.getEntryModelsConflicts = getEntryModelsConflicts;
278
+ /**
279
+ * Lists the inline metadata a model write adds: metadataMappings keys that neither
280
+ * use the referential nor are already defined inline by the stored model.
281
+ */
282
+ function getAddedInlineMetadata(metadataMappings, stored) {
283
+ const storedMappings = stored?.[stored.type]?.metadataMappings ?? {};
284
+ return Object.keys(metadataMappings).filter((name) => !isReferentialMapping(metadataMappings[name]) &&
285
+ !(name in storedMappings && !isReferentialMapping(storedMappings[name])));
286
+ }
287
+ exports.getAddedInlineMetadata = getAddedInlineMetadata;
288
+ /**
289
+ * Reads the metadata referential document
290
+ *
291
+ * @returns The referential metadata, empty if the document does not exist yet
292
+ */
293
+ async function fetchMetadataReferential(sdk, platformIndex) {
294
+ try {
295
+ const document = await sdk.document.get(platformIndex, InternalCollection_1.InternalCollection.MODELS, exports.METADATA_REFERENTIAL_ID);
296
+ return document._source.metadata ?? {};
297
+ }
298
+ catch (error) {
299
+ if (error.status === 404) {
300
+ return {};
301
+ }
302
+ throw error;
303
+ }
304
+ }
305
+ exports.fetchMetadataReferential = fetchMetadataReferential;
306
+ /**
307
+ * Writes the whole metadata referential document
308
+ */
309
+ async function saveMetadataReferential(sdk, platformIndex, referential) {
310
+ const content = {
311
+ metadata: referential,
312
+ type: "metadata-referential",
313
+ };
314
+ return sdk.document.createOrReplace(platformIndex, InternalCollection_1.InternalCollection.MODELS, exports.METADATA_REFERENTIAL_ID, content, { refresh: "wait_for" });
315
+ }
316
+ exports.saveMetadataReferential = saveMetadataReferential;
317
+ /**
318
+ * Lists every stored asset, device and group model
319
+ */
320
+ async function fetchMetadataModels(sdk, platformIndex) {
321
+ const models = [];
322
+ let result = await sdk.document.search(platformIndex, InternalCollection_1.InternalCollection.MODELS, { query: { terms: { type: ["asset", "device", "group"] } } }, { lang: "elasticsearch", scroll: "10s", size: 500 });
323
+ while (result) {
324
+ for (const hit of result.hits) {
325
+ models.push({ _id: hit._id, _source: hit._source });
326
+ }
327
+ result = await result.next();
328
+ }
329
+ return models;
330
+ }
331
+ exports.fetchMetadataModels = fetchMetadataModels;
332
+ /**
333
+ * Lists every stored asset, device and group model using the given metadata of the referential.
334
+ *
335
+ * metadataMappings is not indexed, the filtering is done after fetching the models.
336
+ */
337
+ async function fetchReferencingModels(sdk, platformIndex, name) {
338
+ const models = await fetchMetadataModels(sdk, platformIndex);
339
+ return models.filter(({ _source }) => isReferentialMapping(_source[_source.type]?.metadataMappings?.[name]));
340
+ }
341
+ exports.fetchReferencingModels = fetchReferencingModels;
342
+ //# sourceMappingURL=MetadataReferential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetadataReferential.js","sourceRoot":"","sources":["../../../../lib/modules/model/MetadataReferential.ts"],"names":[],"mappings":";;;;;;AAEA,oDAAuB;AAEvB,2EAAwE;AACxE,+CAA4C;AAE5C,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AAY;IAEZ,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IAE7D,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACnC,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC,IAAI,CAAC,CAAC,CACtE,CAAC;AACJ,CAAC;AAVD,wDAUC"}
@@ -2,11 +2,36 @@ import { KuzzleRequest } from "kuzzle";
2
2
  import { JSONObject, KDocument, KHit, SearchResult } from "kuzzle-sdk";
3
3
  import { DeviceManagerPlugin } from "../plugin";
4
4
  import { BaseService, SearchParams } from "../shared";
5
- import { AssetModelContent, DeviceModelContent, GroupModelContent, LocaleDetails, MeasureModelContent, MetadataDetails, MetadataGroups, MetadataMappings, TooltipModels } from "./types/ModelContent";
5
+ import { AssetModelContent, DeviceModelContent, GroupModelContent, LocaleDetails, MeasureModelContent, MetadataDetails, MetadataGroups, MetadataMappings, MetadataReferential, MetadataReferentialEntry, TooltipModels } from "./types/ModelContent";
6
6
  import { SchemaObject } from "ajv";
7
7
  import { MeasureValuesDetails } from "../measure";
8
8
  import { NamedMeasures } from "../decoder";
9
9
  import { KuzzleLogger } from "kuzzle-logger";
10
+ import { MetadataModelContent } from "./MetadataReferential";
11
+ /**
12
+ * Fields of a group model update.
13
+ * Affinity and icon are kept when omitted.
14
+ */
15
+ export type GroupModelUpdate = {
16
+ affinity?: JSONObject;
17
+ defaultMetadata: JSONObject;
18
+ icon?: string;
19
+ locales: {
20
+ [valueName: string]: LocaleDetails;
21
+ };
22
+ metadataDetails: MetadataDetails;
23
+ metadataGroups: MetadataGroups;
24
+ metadataMappings: MetadataMappings;
25
+ };
26
+ /**
27
+ * Fields of a device model update.
28
+ * Metadata details and default values are kept when omitted.
29
+ */
30
+ export type DeviceModelUpdate = {
31
+ defaultMetadata?: JSONObject;
32
+ metadataDetails?: MetadataDetails;
33
+ metadataMappings: MetadataMappings;
34
+ };
10
35
  export declare class ModelService extends BaseService {
11
36
  readonly logger: KuzzleLogger;
12
37
  constructor(plugin: DeviceManagerPlugin, logger: KuzzleLogger);
@@ -66,4 +91,81 @@ export declare class ModelService extends BaseService {
66
91
  updateAsset(tenantClasses: string[], index: string | undefined, model: string, metadataMappings: MetadataMappings, defaultMetadata: JSONObject, metadataDetails: MetadataDetails, metadataGroups: MetadataGroups, measures: AssetModelContent["asset"]["measures"], tooltipModels: TooltipModels, locales: {
67
92
  [valueName: string]: LocaleDetails;
68
93
  }, icon: string | undefined, request: KuzzleRequest): Promise<KDocument<AssetModelContent>>;
94
+ /**
95
+ * Adds metadata of the metadata referential to a device model.
96
+ *
97
+ * Device models are additive only from the API: every existing metadata must be kept unchanged,
98
+ * new metadata must come from the referential. Metadata details and default values can change.
99
+ * The engines mappings are updated and the devices get the new metadata with their default value.
100
+ *
101
+ * @throws BadRequestError if an existing metadata is missing or changed, or a new one is inline
102
+ * @throws MappingsConflictsError if the new metadata conflict with the existing mappings
103
+ */
104
+ updateDevice(model: string, { defaultMetadata, metadataDetails, metadataMappings }: DeviceModelUpdate): Promise<KDocument<DeviceModelContent>>;
105
+ /**
106
+ * Returns the group model available for the given tenant classes:
107
+ * a model of these classes first, then a commons model.
108
+ *
109
+ * @throws NotFoundError if no group model with this name is available
110
+ */
111
+ private getScopedGroup;
112
+ /**
113
+ * Updates a group model, keeping its scope.
114
+ * Affinity and icon are kept when omitted.
115
+ *
116
+ * The engines mappings are updated and the groups of the model are refreshed.
117
+ *
118
+ * @throws MappingsConflictsError if the new mappings conflict with the existing ones
119
+ */
120
+ updateGroup(tenantClasses: string[], model: string, { affinity, defaultMetadata, icon, locales, metadataDetails, metadataGroups, metadataMappings, }: GroupModelUpdate): Promise<KDocument<GroupModelContent>>;
121
+ /**
122
+ * Validates the metadata of a model written through the API against the metadata referential
123
+ * and enriches the details and default values of the metadata coming from it
124
+ */
125
+ private resolveMetadata;
126
+ /**
127
+ * Resolves the referential metadata of stored models, to be returned by the API
128
+ */
129
+ resolveModels<D extends {
130
+ _source: MetadataModelContent;
131
+ }>(documents: D[]): Promise<D[]>;
132
+ getMetadataReferential(): Promise<MetadataReferential>;
133
+ /**
134
+ * Creates a metadata of the metadata referential, or updates its details.
135
+ *
136
+ * The mappings of a new metadata are merged into the assets, devices and groups collections
137
+ * of every engine. They cannot be modified afterwards: only the locales, editor hint,
138
+ * default value and icon of an existing metadata can change. These are copied into the models
139
+ * using the metadata when they are written, the existing models are not modified.
140
+ *
141
+ * @throws BadRequestError if the mappings of an existing metadata are modified
142
+ * @throws MappingsConflictsError if the new metadata conflicts with an inline metadata of a model
143
+ * or with the actual mappings of an engine collection
144
+ */
145
+ writeMetadata(name: string, definition: MetadataReferentialEntry): Promise<MetadataReferential>;
146
+ /**
147
+ * Deletes a metadata of the metadata referential.
148
+ * Its mappings stay in the engines collections, Elasticsearch cannot remove them.
149
+ *
150
+ * @throws BadRequestError if a model still uses the metadata
151
+ */
152
+ deleteMetadata(name: string): Promise<MetadataReferential>;
153
+ /**
154
+ * With the referentialOnly option, rejects the inline metadata a model write adds.
155
+ * The inline metadata already defined by the stored model are kept (legacy).
156
+ *
157
+ * @throws BadRequestError if new inline metadata are added
158
+ */
159
+ private checkReferentialOnly;
160
+ /**
161
+ * Updates the engines collections. If Elasticsearch rejects the new mappings, the model is
162
+ * restored to its previous version (or deleted if it is new), otherwise every next engines
163
+ * update would fail on it.
164
+ */
165
+ private updateEnginesOrRestore;
166
+ private getStoredModel;
167
+ /**
168
+ * @throws BadRequestError if the metadata is registered from code
169
+ */
170
+ private checkUnmanagedMetadata;
69
171
  }