@@ -2,7 +2,6 @@ import { BaseController } from './Base';
22import { DocumentSearchResult } from '../core/searchResult/Document' ;
33import {
44 JSONObject ,
5- Document ,
65 mCreateResponse ,
76 ArgsDefault ,
87 mCreateRequest ,
@@ -14,7 +13,9 @@ import {
1413 mReplaceResponse ,
1514 mUpdateRequest ,
1615 mUpdateResponse ,
17- DocumentHit ,
16+ KDocumentContentGeneric ,
17+ KDocument ,
18+ KHit ,
1819} from '../types' ;
1920import { SearchResult } from '../core/searchResult/SearchResultBase' ;
2021
@@ -73,13 +74,13 @@ export class DocumentController extends BaseController {
7374 *
7475 * @returns The created document
7576 */
76- create (
77+ create < TKDocumentContent extends KDocumentContentGeneric > (
7778 index : string ,
7879 collection : string ,
79- content : JSONObject ,
80+ content : Partial < TKDocumentContent > ,
8081 _id : string = null ,
8182 options : ArgsDocumentControllerCreate = { }
82- ) : Promise < Document > {
83+ ) : Promise < KDocument < TKDocumentContent > > {
8384 const request = {
8485 index,
8586 collection,
@@ -110,13 +111,13 @@ export class DocumentController extends BaseController {
110111 *
111112 * @returns The created or replaced document
112113 */
113- createOrReplace (
114+ createOrReplace < TKDocumentContent extends KDocumentContentGeneric > (
114115 index : string ,
115116 collection : string ,
116117 _id : string ,
117- content : JSONObject ,
118+ content : Partial < TKDocumentContent > ,
118119 options : ArgsDocumentControllerCreateOrReplace = { }
119- ) : Promise < Document > {
120+ ) : Promise < KDocument < TKDocumentContent > > {
120121 const request = {
121122 index,
122123 collection,
@@ -181,12 +182,12 @@ export class DocumentController extends BaseController {
181182 *
182183 * @returns The deleted documents IDs
183184 */
184- deleteByQuery (
185+ deleteByQuery (
185186 index : string ,
186187 collection : string ,
187188 query : JSONObject = { } ,
188189 options : ArgsDocumentControllerDeleteByQuery = { }
189- ) : Promise < Array < string > > {
190+ ) : Promise < string [ ] > {
190191 const request = {
191192 index,
192193 collection,
@@ -217,13 +218,13 @@ export class DocumentController extends BaseController {
217218 *
218219 * @returns The updated document
219220 */
220- deleteFields (
221+ deleteFields < TKDocumentContent extends KDocumentContentGeneric > (
221222 index : string ,
222223 collection : string ,
223224 _id : string ,
224225 fields : string [ ] ,
225226 options : ArgsDocumentControllerDeleteFields = { }
226- ) : Promise < Document > {
227+ ) : Promise < KDocument < TKDocumentContent > > {
227228 const request = {
228229 index,
229230 collection,
@@ -287,12 +288,12 @@ export class DocumentController extends BaseController {
287288 *
288289 * @returns The document
289290 */
290- get (
291+ get < TKDocumentContent extends KDocumentContentGeneric > (
291292 index : string ,
292293 collection : string ,
293294 _id : string ,
294295 options : ArgsDocumentControllerGet = { }
295- ) : Promise < Document > {
296+ ) : Promise < KDocument < TKDocumentContent > > {
296297 const request = {
297298 index,
298299 collection,
@@ -321,10 +322,10 @@ export class DocumentController extends BaseController {
321322 *
322323 * @returns An object containing 2 arrays: "successes" and "errors"
323324 */
324- mCreate (
325+ mCreate < TKDocumentContent extends KDocumentContentGeneric > (
325326 index : string ,
326327 collection : string ,
327- documents : mCreateRequest ,
328+ documents : mCreateRequest < TKDocumentContent > ,
328329 options : ArgsDocumentControllerMCreate = { }
329330 ) : Promise < mCreateResponse > {
330331 const request = {
@@ -357,10 +358,10 @@ export class DocumentController extends BaseController {
357358 *
358359 * @returns An object containing 2 arrays: "successes" and "errors"
359360 */
360- mCreateOrReplace (
361+ mCreateOrReplace < TKDocumentContent extends KDocumentContentGeneric > (
361362 index : string ,
362363 collection : string ,
363- documents : mCreateOrReplaceRequest ,
364+ documents : mCreateOrReplaceRequest < TKDocumentContent > ,
364365 options : ArgsDocumentControllerMCreateOrReplace = { }
365366 ) : Promise < mCreateOrReplaceResponse > {
366367 const request = {
@@ -427,20 +428,20 @@ export class DocumentController extends BaseController {
427428 *
428429 * @returns An object containing 2 arrays: "successes" and "errors"
429430 */
430- mGet (
431+ mGet < TKDocumentContent extends KDocumentContentGeneric > (
431432 index : string ,
432433 collection : string ,
433- ids : Array < string > ,
434+ ids : string [ ] ,
434435 options : ArgsDocumentControllerMGet = { }
435436 ) : Promise < {
436437 /**
437438 * Array of successfully retrieved documents
438439 */
439- successes : Array < Document > ;
440+ successes : KDocument < TKDocumentContent > [ ] ;
440441 /**
441442 * Array of the IDs of not found documents.
442443 */
443- errors : Array < string > ;
444+ errors : string [ ] ;
444445 } > {
445446 const request = {
446447 index,
@@ -470,10 +471,10 @@ export class DocumentController extends BaseController {
470471 *
471472 * @returns An object containing 2 arrays: "successes" and "errors"
472473 */
473- mReplace (
474+ mReplace < TKDocumentContent extends KDocumentContentGeneric > (
474475 index : string ,
475476 collection : string ,
476- documents : mReplaceRequest ,
477+ documents : mReplaceRequest < TKDocumentContent > ,
477478 options : ArgsDocumentControllerMReplace = { }
478479 ) : Promise < mReplaceResponse > {
479480 const request = {
@@ -510,10 +511,10 @@ export class DocumentController extends BaseController {
510511 *
511512 * @returns An object containing 2 arrays: "successes" and "errors"
512513 */
513- mUpdate (
514+ mUpdate < TKDocumentContent extends KDocumentContentGeneric > (
514515 index : string ,
515516 collection : string ,
516- documents : mUpdateRequest ,
517+ documents : mUpdateRequest < TKDocumentContent > ,
517518 options : ArgsDocumentControllerMUpdate = { }
518519 ) : Promise < mUpdateResponse > {
519520 const request = {
@@ -547,10 +548,10 @@ export class DocumentController extends BaseController {
547548 *
548549 * @returns An object containing 2 arrays: "successes" and "errors"
549550 */
550- mUpsert (
551+ mUpsert < TKDocumentContent extends KDocumentContentGeneric > (
551552 index : string ,
552553 collection : string ,
553- documents : mUpdateRequest ,
554+ documents : mUpdateRequest < TKDocumentContent > ,
554555 options : ArgsDocumentControllerMUpsert = { }
555556 ) : Promise < mUpdateResponse > {
556557 const request = {
@@ -582,13 +583,13 @@ export class DocumentController extends BaseController {
582583 *
583584 * @returns The replaced document
584585 */
585- replace (
586+ replace < TKDocumentContent extends KDocumentContentGeneric > (
586587 index : string ,
587588 collection : string ,
588589 _id : string ,
589- content : JSONObject ,
590+ content : Partial < TKDocumentContent > ,
590591 options : ArgsDocumentControllerReplace = { }
591- ) : Promise < Document > {
592+ ) : Promise < KDocument < TKDocumentContent > > {
592593 const request = {
593594 index,
594595 collection,
@@ -620,12 +621,12 @@ export class DocumentController extends BaseController {
620621 *
621622 * @returns A SearchResult
622623 */
623- search (
624+ search < TKDocumentContent extends KDocumentContentGeneric > (
624625 index : string ,
625626 collection : string ,
626627 searchBody : JSONObject = { } ,
627628 options : ArgsDocumentControllerSearch = { }
628- ) : Promise < SearchResult < DocumentHit > > {
629+ ) : Promise < SearchResult < KHit < TKDocumentContent > > > {
629630 return this . _search ( index , collection , searchBody , options )
630631 . then ( ( { response, request, opts } ) => (
631632 new DocumentSearchResult ( this . kuzzle , request , opts , response . result )
@@ -680,13 +681,13 @@ export class DocumentController extends BaseController {
680681 *
681682 * @returns The replaced document
682683 */
683- update (
684+ update < TKDocumentContent extends KDocumentContentGeneric > (
684685 index : string ,
685686 collection : string ,
686687 _id : string ,
687- content : JSONObject ,
688+ content : Partial < TKDocumentContent > ,
688689 options : ArgsDocumentControllerUpdate = { }
689- ) : Promise < Document > {
690+ ) : Promise < KDocument < TKDocumentContent > > {
690691 const request = {
691692 index,
692693 collection,
@@ -720,7 +721,7 @@ export class DocumentController extends BaseController {
720721 *
721722 * @returns An object containing 2 arrays: "successes" and "errors"
722723 */
723- updateByQuery (
724+ updateByQuery < TKDocumentContent extends KDocumentContentGeneric > (
724725 index : string ,
725726 collection : string ,
726727 query : JSONObject ,
@@ -730,15 +731,15 @@ export class DocumentController extends BaseController {
730731 /**
731732 * Array of successfully updated documents
732733 */
733- successes : Array < Document > ;
734+ successes : KDocument < TKDocumentContent > [ ] ;
734735 /**
735736 * Array of failed creation
736737 */
737738 errors : Array < {
738739 /**
739740 * Document that cause the error
740741 */
741- document : Document ;
742+ document : KDocument < TKDocumentContent > ;
742743 /**
743744 * HTTP error status
744745 */
@@ -781,13 +782,13 @@ export class DocumentController extends BaseController {
781782 *
782783 * @returns Information about the updated document
783784 */
784- upsert (
785+ upsert < TKDocumentContent extends KDocumentContentGeneric > (
785786 index : string ,
786787 collection : string ,
787788 _id : string ,
788- changes : JSONObject ,
789+ changes : Partial < TKDocumentContent > ,
789790 options : ArgsDocumentControllerUpsert = { }
790- ) : Promise < Document > {
791+ ) : Promise < KDocument < TKDocumentContent > > {
791792 const request = {
792793 index,
793794 collection,
@@ -816,10 +817,10 @@ export class DocumentController extends BaseController {
816817 *
817818 * @returns True if the document is valid
818819 */
819- validate (
820+ validate < TKDocumentContent extends KDocumentContentGeneric > (
820821 index : string ,
821822 collection : string ,
822- content : JSONObject ,
823+ content : TKDocumentContent ,
823824 options : ArgsDocumentControllerValidate = { }
824825 ) : Promise < boolean > {
825826 return this . query ( {
0 commit comments