kuzzle 2.20.3 → 2.21.1

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.
@@ -681,7 +681,7 @@ class ElasticSearch extends Service {
681
681
  index,
682
682
  collection,
683
683
  content,
684
- { id, refresh, userId = null } = {}
684
+ { id, refresh, userId = null, injectKuzzleMeta = true } = {}
685
685
  ) {
686
686
  assertIsObject(content);
687
687
 
@@ -697,12 +697,14 @@ class ElasticSearch extends Service {
697
697
  assertWellFormedRefresh(esRequest);
698
698
 
699
699
  // Add metadata
700
- esRequest.body._kuzzle_info = {
701
- author: getKuid(userId),
702
- createdAt: Date.now(),
703
- updatedAt: null,
704
- updater: null,
705
- };
700
+ if (injectKuzzleMeta) {
701
+ esRequest.body._kuzzle_info = {
702
+ author: getKuid(userId),
703
+ createdAt: Date.now(),
704
+ updatedAt: null,
705
+ updater: null,
706
+ };
707
+ }
706
708
 
707
709
  debug("Create document: %o", esRequest);
708
710
 
@@ -789,7 +791,7 @@ class ElasticSearch extends Service {
789
791
  collection,
790
792
  id,
791
793
  content,
792
- { refresh, userId = null, retryOnConflict } = {}
794
+ { refresh, userId = null, retryOnConflict, injectKuzzleMeta = true } = {}
793
795
  ) {
794
796
  const esRequest = {
795
797
  _source: true,
@@ -804,11 +806,13 @@ class ElasticSearch extends Service {
804
806
  assertNoRouting(esRequest);
805
807
  assertWellFormedRefresh(esRequest);
806
808
 
807
- // Add metadata
808
- esRequest.body.doc._kuzzle_info = {
809
- updatedAt: Date.now(),
810
- updater: getKuid(userId),
811
- };
809
+ if (injectKuzzleMeta) {
810
+ // Add metadata
811
+ esRequest.body.doc._kuzzle_info = {
812
+ updatedAt: Date.now(),
813
+ updater: getKuid(userId),
814
+ };
815
+ }
812
816
 
813
817
  debug("Update document: %o", esRequest);
814
818
 
@@ -841,7 +845,13 @@ class ElasticSearch extends Service {
841
845
  collection,
842
846
  id,
843
847
  content,
844
- { defaultValues = {}, refresh, userId = null, retryOnConflict } = {}
848
+ {
849
+ defaultValues = {},
850
+ refresh,
851
+ userId = null,
852
+ retryOnConflict,
853
+ injectKuzzleMeta = true,
854
+ } = {}
845
855
  ) {
846
856
  const esRequest = {
847
857
  _source: true,
@@ -863,14 +873,16 @@ class ElasticSearch extends Service {
863
873
  const user = getKuid(userId);
864
874
  const now = Date.now();
865
875
 
866
- esRequest.body.doc._kuzzle_info = {
867
- updatedAt: now,
868
- updater: user,
869
- };
870
- esRequest.body.upsert._kuzzle_info = {
871
- author: user,
872
- createdAt: now,
873
- };
876
+ if (injectKuzzleMeta) {
877
+ esRequest.body.doc._kuzzle_info = {
878
+ updatedAt: now,
879
+ updater: user,
880
+ };
881
+ esRequest.body.upsert._kuzzle_info = {
882
+ author: user,
883
+ createdAt: now,
884
+ };
885
+ }
874
886
 
875
887
  debug("Upsert document: %o", esRequest);
876
888
 
@@ -904,7 +916,7 @@ class ElasticSearch extends Service {
904
916
  collection,
905
917
  id,
906
918
  content,
907
- { refresh, userId = null } = {}
919
+ { refresh, userId = null, injectKuzzleMeta = true } = {}
908
920
  ) {
909
921
  const alias = this._getAlias(index, collection);
910
922
  const esRequest = {
@@ -917,13 +929,15 @@ class ElasticSearch extends Service {
917
929
  assertNoRouting(esRequest);
918
930
  assertWellFormedRefresh(esRequest);
919
931
 
920
- // Add metadata
921
- esRequest.body._kuzzle_info = {
922
- author: getKuid(userId),
923
- createdAt: Date.now(),
924
- updatedAt: Date.now(),
925
- updater: getKuid(userId),
926
- };
932
+ if (injectKuzzleMeta) {
933
+ // Add metadata
934
+ esRequest.body._kuzzle_info = {
935
+ author: getKuid(userId),
936
+ createdAt: Date.now(),
937
+ updatedAt: Date.now(),
938
+ updater: getKuid(userId),
939
+ };
940
+ }
927
941
 
928
942
  try {
929
943
  const { body: exists } = await this._client.exists({ id, index: alias });
@@ -1,4 +1,4 @@
1
- import { KuzzleRequest, KDocument, JSONObject } from "../../../";
1
+ import { KuzzleRequest, KDocument, JSONObject, PipeEventHandler } from "../../../";
2
2
  /**
3
3
  * Events with documents only having the `_id`
4
4
  */
@@ -23,4 +23,24 @@ export type EventGenericDocumentAfterWrite<KDocumentContent = JSONObject> = Even
23
23
  export type EventGenericDocumentBeforeUpdate<KDocumentContent = JSONObject> = EventGenericDocument<"beforeUpdate", KDocumentContent>;
24
24
  export type EventGenericDocumentAfterUpdate<KDocumentContent = JSONObject> = EventGenericDocument<"afterUpdate", KDocumentContent>;
25
25
  export type EventGenericDocumentAfterGet<KDocumentContent = JSONObject> = EventGenericDocument<"afterGet", KDocumentContent>;
26
+ export type EventGenericDocumentInjectMetadata = {
27
+ name: `generic:document:injectMetadata`;
28
+ args: [
29
+ {
30
+ /**
31
+ * Kuzzle Request that triggered the event
32
+ */
33
+ request: KuzzleRequest;
34
+ /**
35
+ * Metadata of the document
36
+ */
37
+ metadata: JSONObject;
38
+ /**
39
+ * Default metadata of the document.
40
+ * Only used when calling document:upsert.
41
+ */
42
+ defaultMetadata?: JSONObject;
43
+ }
44
+ ];
45
+ } & PipeEventHandler;
26
46
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.20.3",
4
+ "version": "2.21.1",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "bin": "bin/start-kuzzle-server",
7
7
  "scripts": {
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import EventEmitter from "events";
4
- import Inspector from "inspector";
5
- export type DebugModuleOptions = {
6
- methods?: string[];
7
- events?: string[];
8
- };
9
- export declare abstract class DebugModule extends EventEmitter {
10
- name: string;
11
- methods: string[];
12
- events: string[];
13
- /**
14
- * Called when the module is loaded, after the debugger has been enabled
15
- */
16
- abstract init(inspector: Inspector.Session): Promise<void>;
17
- /**
18
- * Called when the module should be cleaned up.
19
- * - After the Debug Controller has been disabled
20
- * - Before the debugger is disconnected
21
- */
22
- abstract cleanup(): Promise<void>;
23
- constructor(name: string, options?: DebugModuleOptions);
24
- }
@@ -1,39 +0,0 @@
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.DebugModule = void 0;
7
- const events_1 = __importDefault(require("events"));
8
- class DebugModule extends events_1.default {
9
- constructor(name, options = {}) {
10
- super();
11
- this.name = name;
12
- this.methods = options.methods || [];
13
- this.events = options.events || [];
14
- if (!this.name || this.name.length === 0) {
15
- throw new Error("DebugModule should have a name");
16
- }
17
- if (this.name.charAt(0) !== this.name.charAt(0).toUpperCase()) {
18
- throw new Error(`Debug Module name "${name}" should start with an uppercase letter`);
19
- }
20
- for (const event of this.events) {
21
- if (event.length === 0) {
22
- throw new Error(`Event name should not be empty for "${name}"`);
23
- }
24
- if (event.charAt(0) !== event.charAt(0).toLowerCase()) {
25
- throw new Error(`Event name "${event}" should start with a lowercase letter for module "${name}"`);
26
- }
27
- }
28
- for (const method of this.methods) {
29
- if (method.length === 0) {
30
- throw new Error(`Method name should not be empty for Debug Module "${name}"`);
31
- }
32
- if (method.charAt(0) !== method.charAt(0).toLowerCase()) {
33
- throw new Error(`Method name "${method}" should start with a lowercase letter for module "${name}"`);
34
- }
35
- }
36
- }
37
- }
38
- exports.DebugModule = DebugModule;
39
- //# sourceMappingURL=DebugModule.js.map