@opra/elastic 1.5.1 → 1.5.3

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();
@@ -72,8 +72,11 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
72
72
  * @throws {NotAcceptableError} If the data type is not a ComplexType.
73
73
  */
74
74
  get dataType() {
75
+ if (this._dataType && this._dataTypeScope !== this.scope)
76
+ this._dataType = undefined;
75
77
  if (!this._dataType)
76
78
  this._dataType = this.context.documentNode.getComplexType(this._dataType_);
79
+ this._dataTypeScope = this.scope;
77
80
  return this._dataType;
78
81
  }
79
82
  /**
@@ -212,7 +215,7 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
212
215
  sort: options?.sort
213
216
  ? elastic_adapter_js_1.ElasticAdapter.prepareSort(options?.sort)
214
217
  : undefined,
215
- _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),
216
219
  index: this.getIndexName(),
217
220
  ...options?.request,
218
221
  query,
@@ -299,7 +302,10 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
299
302
  let validator = this._inputCodecs[operation];
300
303
  if (validator)
301
304
  return validator;
302
- const options = { projection: '*' };
305
+ const options = {
306
+ projection: '*',
307
+ scope: this._dataTypeScope,
308
+ };
303
309
  if (operation === 'update')
304
310
  options.partial = 'deep';
305
311
  const dataType = this.dataType;
@@ -317,6 +323,7 @@ class ElasticEntityService extends elastic_service_js_1.ElasticService {
317
323
  const options = {
318
324
  projection: '*',
319
325
  partial: 'deep',
326
+ scope: this._dataTypeScope,
320
327
  };
321
328
  const dataType = this.dataType;
322
329
  validator = dataType.generateCodec('decode', options);
@@ -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();
@@ -69,8 +69,11 @@ export class ElasticEntityService extends ElasticService {
69
69
  * @throws {NotAcceptableError} If the data type is not a ComplexType.
70
70
  */
71
71
  get dataType() {
72
+ if (this._dataType && this._dataTypeScope !== this.scope)
73
+ this._dataType = undefined;
72
74
  if (!this._dataType)
73
75
  this._dataType = this.context.documentNode.getComplexType(this._dataType_);
76
+ this._dataTypeScope = this.scope;
74
77
  return this._dataType;
75
78
  }
76
79
  /**
@@ -209,7 +212,7 @@ export class ElasticEntityService extends ElasticService {
209
212
  sort: options?.sort
210
213
  ? ElasticAdapter.prepareSort(options?.sort)
211
214
  : undefined,
212
- _source: ElasticAdapter.prepareProjection(this.dataType, options?.projection),
215
+ _source: ElasticAdapter.prepareProjection(this.dataType, options?.projection, this.scope),
213
216
  index: this.getIndexName(),
214
217
  ...options?.request,
215
218
  query,
@@ -296,7 +299,10 @@ export class ElasticEntityService extends ElasticService {
296
299
  let validator = this._inputCodecs[operation];
297
300
  if (validator)
298
301
  return validator;
299
- const options = { projection: '*' };
302
+ const options = {
303
+ projection: '*',
304
+ scope: this._dataTypeScope,
305
+ };
300
306
  if (operation === 'update')
301
307
  options.partial = 'deep';
302
308
  const dataType = this.dataType;
@@ -314,6 +320,7 @@ export class ElasticEntityService extends ElasticService {
314
320
  const options = {
315
321
  projection: '*',
316
322
  partial: 'deep',
323
+ scope: this._dataTypeScope,
317
324
  };
318
325
  const dataType = this.dataType;
319
326
  validator = dataType.generateCodec('decode', options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/elastic",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
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.1",
15
- "@opra/core": "^1.5.1"
14
+ "@opra/common": "^1.5.3",
15
+ "@opra/core": "^1.5.3"
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;
@@ -20,6 +20,7 @@ export declare namespace ElasticEntityService {
20
20
  indexName?: ElasticEntityService['indexName'];
21
21
  resourceName?: ElasticEntityService['resourceName'];
22
22
  idGenerator?: ElasticEntityService['idGenerator'];
23
+ scope?: ElasticEntityService['scope'];
23
24
  }
24
25
  interface CommandInfo extends ElasticService.CommandInfo {
25
26
  }
@@ -141,10 +142,15 @@ export declare namespace ElasticEntityService {
141
142
  * @template T - The type of the documents in the collection.
142
143
  */
143
144
  export declare class ElasticEntityService<T extends object = any> extends ElasticService {
145
+ protected _dataTypeScope?: string;
144
146
  protected _dataType_: Type | string;
145
147
  protected _dataType?: ComplexType;
146
148
  protected _inputCodecs: Record<string, IsObject.Validator<T>>;
147
149
  protected _outputCodecs: Record<string, IsObject.Validator<T>>;
150
+ /**
151
+ * Defines comma delimited scopes for api document
152
+ */
153
+ scope?: string;
148
154
  /**
149
155
  * Represents the name of a index in ElasticDB
150
156
  */