@opra/elastic 1.5.2 → 1.5.4

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.
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = prepareProjection;
4
4
  exports.prepare = prepare;
5
5
  const common_1 = require("@opra/common");
6
- function prepareProjection(dataType, projection) {
6
+ function prepareProjection(dataType, projection, scope) {
7
7
  const out = {};
8
8
  const includes = [];
9
9
  const excludes = [];
10
10
  const projection_ = typeof projection === 'string' || Array.isArray(projection)
11
11
  ? (0, common_1.parseFieldsProjection)(projection)
12
12
  : projection;
13
- prepare(dataType, includes, excludes, '', projection_);
13
+ prepare(dataType, includes, excludes, '', projection_, scope);
14
14
  if (includes.length)
15
15
  out.includes = includes;
16
16
  if (excludes.length)
@@ -20,7 +20,7 @@ function prepareProjection(dataType, projection) {
20
20
  function getNeedIncludes(projection) {
21
21
  return !!(projection && Object.values(projection).find(p => !p.sign));
22
22
  }
23
- function prepare(dataType, includes, excludes, curPath, projection) {
23
+ function prepare(dataType, includes, excludes, curPath, projection, scope) {
24
24
  const needIncludes = getNeedIncludes(projection);
25
25
  const projectionKeys = projection && Object.keys(projection);
26
26
  const projectionKeysSet = new Set(projectionKeys);
@@ -29,7 +29,7 @@ function prepare(dataType, includes, excludes, curPath, projection) {
29
29
  let field;
30
30
  let k;
31
31
  /** Add fields from data type */
32
- for (field of dataType.fields.values()) {
32
+ for (field of dataType.fields(scope)) {
33
33
  fieldName = field.name;
34
34
  fieldPath = curPath + (curPath ? '.' : '') + fieldName;
35
35
  k = fieldName.toLowerCase();
@@ -215,7 +215,7 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
215
215
  sort: options?.sort
216
216
  ? elastic_adapter_js_1.ElasticAdapter.prepareSort(options?.sort)
217
217
  : undefined,
218
- _source: elastic_adapter_js_1.ElasticAdapter.prepareProjection(this.dataType, options?.projection),
218
+ _source: elastic_adapter_js_1.ElasticAdapter.prepareProjection(this.dataType, options?.projection, this.scope),
219
219
  index: this.getIndexName(),
220
220
  ...options?.request,
221
221
  query,
@@ -299,7 +299,8 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
299
299
  * @param operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
300
300
  */
301
301
  _getInputCodec(operation) {
302
- let validator = this._inputCodecs[operation];
302
+ const cacheKey = operation + (this._dataTypeScope ? ':' + this._dataTypeScope : '');
303
+ let validator = this._inputCodecs[cacheKey];
303
304
  if (validator)
304
305
  return validator;
305
306
  const options = {
@@ -310,14 +311,15 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
310
311
  options.partial = 'deep';
311
312
  const dataType = this.dataType;
312
313
  validator = dataType.generateCodec('decode', options);
313
- this._inputCodecs[operation] = validator;
314
+ this._inputCodecs[cacheKey] = validator;
314
315
  return validator;
315
316
  }
316
317
  /**
317
318
  * Retrieves the codec.
318
319
  */
319
320
  _getOutputCodec(operation) {
320
- let validator = this._outputCodecs[operation];
321
+ const cacheKey = operation + (this._dataTypeScope ? ':' + this._dataTypeScope : '');
322
+ let validator = this._outputCodecs[cacheKey];
321
323
  if (validator)
322
324
  return validator;
323
325
  const options = {
@@ -327,7 +329,7 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
327
329
  };
328
330
  const dataType = this.dataType;
329
331
  validator = dataType.generateCodec('decode', options);
330
- this._outputCodecs[operation] = validator;
332
+ this._outputCodecs[cacheKey] = validator;
331
333
  return validator;
332
334
  }
333
335
  async _executeCommand(command, commandFn) {
@@ -1,12 +1,12 @@
1
1
  import { ComplexType, parseFieldsProjection, } from '@opra/common';
2
- export default function prepareProjection(dataType, projection) {
2
+ export default function prepareProjection(dataType, projection, scope) {
3
3
  const out = {};
4
4
  const includes = [];
5
5
  const excludes = [];
6
6
  const projection_ = typeof projection === 'string' || Array.isArray(projection)
7
7
  ? parseFieldsProjection(projection)
8
8
  : projection;
9
- prepare(dataType, includes, excludes, '', projection_);
9
+ prepare(dataType, includes, excludes, '', projection_, scope);
10
10
  if (includes.length)
11
11
  out.includes = includes;
12
12
  if (excludes.length)
@@ -16,7 +16,7 @@ export default function prepareProjection(dataType, projection) {
16
16
  function getNeedIncludes(projection) {
17
17
  return !!(projection && Object.values(projection).find(p => !p.sign));
18
18
  }
19
- export function prepare(dataType, includes, excludes, curPath, projection) {
19
+ export function prepare(dataType, includes, excludes, curPath, projection, scope) {
20
20
  const needIncludes = getNeedIncludes(projection);
21
21
  const projectionKeys = projection && Object.keys(projection);
22
22
  const projectionKeysSet = new Set(projectionKeys);
@@ -25,7 +25,7 @@ export function prepare(dataType, includes, excludes, curPath, projection) {
25
25
  let field;
26
26
  let k;
27
27
  /** Add fields from data type */
28
- for (field of dataType.fields.values()) {
28
+ for (field of dataType.fields(scope)) {
29
29
  fieldName = field.name;
30
30
  fieldPath = curPath + (curPath ? '.' : '') + fieldName;
31
31
  k = fieldName.toLowerCase();
@@ -212,7 +212,7 @@ export class ElasticEntityService extends ElasticService {
212
212
  sort: options?.sort
213
213
  ? ElasticAdapter.prepareSort(options?.sort)
214
214
  : undefined,
215
- _source: ElasticAdapter.prepareProjection(this.dataType, options?.projection),
215
+ _source: ElasticAdapter.prepareProjection(this.dataType, options?.projection, this.scope),
216
216
  index: this.getIndexName(),
217
217
  ...options?.request,
218
218
  query,
@@ -296,7 +296,8 @@ export class ElasticEntityService extends ElasticService {
296
296
  * @param operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
297
297
  */
298
298
  _getInputCodec(operation) {
299
- let validator = this._inputCodecs[operation];
299
+ const cacheKey = operation + (this._dataTypeScope ? ':' + this._dataTypeScope : '');
300
+ let validator = this._inputCodecs[cacheKey];
300
301
  if (validator)
301
302
  return validator;
302
303
  const options = {
@@ -307,14 +308,15 @@ export class ElasticEntityService extends ElasticService {
307
308
  options.partial = 'deep';
308
309
  const dataType = this.dataType;
309
310
  validator = dataType.generateCodec('decode', options);
310
- this._inputCodecs[operation] = validator;
311
+ this._inputCodecs[cacheKey] = validator;
311
312
  return validator;
312
313
  }
313
314
  /**
314
315
  * Retrieves the codec.
315
316
  */
316
317
  _getOutputCodec(operation) {
317
- let validator = this._outputCodecs[operation];
318
+ const cacheKey = operation + (this._dataTypeScope ? ':' + this._dataTypeScope : '');
319
+ let validator = this._outputCodecs[cacheKey];
318
320
  if (validator)
319
321
  return validator;
320
322
  const options = {
@@ -324,7 +326,7 @@ export class ElasticEntityService extends ElasticService {
324
326
  };
325
327
  const dataType = this.dataType;
326
328
  validator = dataType.generateCodec('decode', options);
327
- this._outputCodecs[operation] = validator;
329
+ this._outputCodecs[cacheKey] = validator;
328
330
  return validator;
329
331
  }
330
332
  async _executeCommand(command, commandFn) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/elastic",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Opra Elastic Search adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@elastic/elasticsearch": ">=8.7.0",
14
- "@opra/common": "^1.5.2",
15
- "@opra/core": "^1.5.2"
14
+ "@opra/common": "^1.5.4",
15
+ "@opra/core": "^1.5.4"
16
16
  },
17
17
  "type": "module",
18
18
  "exports": {
@@ -3,5 +3,5 @@ export interface ElasticProjection {
3
3
  includes?: string[];
4
4
  excludes?: string[];
5
5
  }
6
- export default function prepareProjection(dataType: ComplexType, projection?: string | string[]): ElasticProjection | undefined;
7
- export declare function prepare(dataType: ComplexType, includes: string[], excludes: string[], curPath: string, projection?: FieldsProjection): void;
6
+ export default function prepareProjection(dataType: ComplexType, projection?: string | string[], scope?: string): ElasticProjection | undefined;
7
+ export declare function prepare(dataType: ComplexType, includes: string[], excludes: string[], curPath: string, projection?: FieldsProjection, scope?: string): void;