@travetto/model-elasticsearch 3.1.7 → 3.1.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-elasticsearch",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "Elasticsearch backing for the travetto model module, with real-time modeling support for Elasticsearch mappings.",
5
5
  "keywords": [
6
6
  "elasticsearch",
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@elastic/elasticsearch": "^8.6.0",
31
- "@travetto/config": "^3.1.2",
32
- "@travetto/model": "^3.1.8",
33
- "@travetto/model-query": "^3.1.7"
31
+ "@travetto/config": "^3.1.3",
32
+ "@travetto/model": "^3.1.9",
33
+ "@travetto/model-query": "^3.1.9"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@travetto/command": "^3.1.2"
@@ -1,4 +1,4 @@
1
- import { InlineScript, QueryDslQueryContainer, SearchRequest, SearchResponse, Sort, SortOptions } from '@elastic/elasticsearch/lib/api/types';
1
+ import { QueryDslQueryContainer, SearchRequest, SearchResponse, Sort, SortOptions } from '@elastic/elasticsearch/lib/api/types';
2
2
 
3
3
  import { Class, DataUtil, ObjectUtil } from '@travetto/base';
4
4
  import { WhereClause, SelectClause, SortClause, Query } from '@travetto/model-query';
@@ -24,18 +24,6 @@ const has$Not = (o: unknown): o is ({ $not: WhereClause<unknown> }) => !!o && '$
24
24
  */
25
25
  export class ElasticsearchQueryUtil {
26
26
 
27
- /**
28
- * Build the update script for a given object
29
- */
30
- static generateEmptyScript(path: string): InlineScript {
31
- const out: InlineScript = {
32
- lang: 'painless',
33
- source: 'return doc[params.key] == null || doc[params.key].size() == 0;',
34
- params: { key: path },
35
- };
36
- return out;
37
- }
38
-
39
27
  /**
40
28
  * Convert `a.b.c` to `a : { b : { c : ... }}`
41
29
  */
@@ -170,11 +158,9 @@ export class ElasticsearchQueryUtil {
170
158
  }
171
159
  case '$empty': {
172
160
  const q = {
173
- script: {
174
- script: this.generateEmptyScript(sPath)
175
- }
161
+ exists: { field: sPath }
176
162
  };
177
- items.push(v ? q : { bool: { ['must_not']: q } });
163
+ items.push(!v ? q : { bool: { ['must_not']: q } });
178
164
  break;
179
165
  }
180
166
  case '$regex': {
package/src/service.ts CHANGED
@@ -69,7 +69,9 @@ export class ElasticsearchModelService implements
69
69
  });
70
70
  return res;
71
71
  } catch (err) {
72
- console.error((err as any).meta.body.error);
72
+ if (err instanceof es.errors.ResponseError && err.meta.body && typeof err.meta.body === 'object' && 'error' in err.meta.body) {
73
+ console.error(err.meta.body.error);
74
+ }
73
75
  throw err;
74
76
  }
75
77
  }
@@ -77,24 +79,23 @@ export class ElasticsearchModelService implements
77
79
  /**
78
80
  * Convert _id to id
79
81
  */
80
- async postLoad<T extends ModelType>(cls: Class<T>, o: T): Promise<T> {
81
- if (isWithId(o)) {
82
- o.id = o._id!;
83
- delete o._id;
82
+ async postLoad<T extends ModelType>(cls: Class<T>, item: T): Promise<T> {
83
+ if (isWithId(item)) {
84
+ delete item._id;
84
85
  }
85
86
 
86
- o = await ModelCrudUtil.load(cls, o);
87
+ item = await ModelCrudUtil.load(cls, item);
87
88
 
88
89
  const { expiresAt } = ModelRegistry.get(cls);
89
90
 
90
91
  if (expiresAt) {
91
- const expiry = ModelExpiryUtil.getExpiryState(cls, o);
92
+ const expiry = ModelExpiryUtil.getExpiryState(cls, item);
92
93
  if (!expiry.expired) {
93
- return o;
94
+ return item;
94
95
  }
95
- throw new NotFoundError(cls, o.id);
96
+ throw new NotFoundError(cls, item.id);
96
97
  } else {
97
- return o;
98
+ return item;
98
99
  }
99
100
  }
100
101
 
@@ -269,15 +270,11 @@ export class ElasticsearchModelService implements
269
270
  } else if (op.insert) {
270
271
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
271
272
  acc.push({ create: { ...ident, _id: op.insert.id } }, op.insert as T);
272
- delete op.insert.id;
273
273
  } else if (op.upsert) {
274
274
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
275
275
  acc.push({ index: { ...ident, _id: op.upsert.id } }, op.upsert as T);
276
- delete op.upsert.id;
277
276
  } else if (op.update) {
278
277
  acc.push({ update: { ...ident, _id: op.update.id } }, { doc: op.update });
279
- // @ts-expect-error
280
- delete op.update.id;
281
278
  }
282
279
  return acc;
283
280
  }, []);