Skip to content

Commit 18eec5f

Browse files
committed
add callback api to index execute()
1 parent 4abe7a4 commit 18eec5f

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

src/Documents/Indexes/AbstractIndexCreationTaskBase.ts

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { IndexPriority, IndexLockMode, FieldIndexing, FieldStorage, FieldTermVec
44
import { IDocumentStore } from "../IDocumentStore";
55
import { PutIndexesOperation } from "../Operations/Indexes/PutIndexesOperation";
66
import { SpatialOptions } from "./Spatial";
7+
import { ErrorFirstCallback } from "../../Types/Callbacks";
8+
import { TypeUtil } from "../../Utility/TypeUtil";
9+
import { passResultToCallback } from "../../Utility/PromiseUtil";
710

811
export abstract class AbstractIndexCreationTaskBase {
912

@@ -39,25 +42,66 @@ export abstract class AbstractIndexCreationTaskBase {
3942
/**
4043
* Executes the index creation against the specified document store.
4144
*/
42-
public async execute(
43-
store: IDocumentStore): Promise<void>;
45+
public async execute(store: IDocumentStore): Promise<void>;
46+
/**
47+
* Executes the index creation against the specified document store.
48+
*/
49+
public async execute(store: IDocumentStore, callback: ErrorFirstCallback<void>): Promise<void>;
50+
/**
51+
* Executes the index creation against the specified document store.
52+
*/
53+
public async execute(store: IDocumentStore, conventions: DocumentConventions): Promise<void>;
4454
/**
4555
* Executes the index creation against the specified document store.
4656
*/
4757
public async execute(
48-
store: IDocumentStore, conventions: DocumentConventions): Promise<void>;
58+
store: IDocumentStore,
59+
conventions: DocumentConventions,
60+
callback: ErrorFirstCallback<void>): Promise<void>;
61+
/**
62+
* Executes the index creation against the specified document store.
63+
*/
64+
public async execute(store: IDocumentStore, conventions: DocumentConventions, database: string): Promise<void>;
4965
/**
5066
* Executes the index creation against the specified document store.
5167
*/
5268
public async execute(
53-
store: IDocumentStore, conventions: DocumentConventions, database: string): Promise<void>;
69+
store: IDocumentStore,
70+
conventions: DocumentConventions,
71+
database: string,
72+
callback: ErrorFirstCallback<void>): Promise<void>;
5473
public async execute(
55-
store: IDocumentStore, conventions?: DocumentConventions, database?: string): Promise<void> {
56-
if (arguments.length === 1) {
57-
return store.executeIndex(this);
74+
store: IDocumentStore,
75+
conventionsOrCallback?: DocumentConventions | ErrorFirstCallback<void>,
76+
databaseOrCallback?: string | ErrorFirstCallback<void>,
77+
callback?: ErrorFirstCallback<void>): Promise<void> {
78+
79+
let conventions: DocumentConventions;
80+
let database: string;
81+
if (arguments.length > 1) {
82+
if (TypeUtil.isFunction(conventionsOrCallback)) {
83+
callback = conventionsOrCallback;
84+
} else if (TypeUtil.isFunction(databaseOrCallback)) {
85+
callback = databaseOrCallback;
86+
conventions = conventionsOrCallback;
87+
} else {
88+
conventions = conventionsOrCallback;
89+
database = databaseOrCallback;
90+
}
91+
}
92+
93+
callback = callback || TypeUtil.NOOP;
94+
95+
let resultPromise;
96+
if (!conventions && !database) {
97+
resultPromise = store.executeIndex(this);
5898
} else {
59-
return this._putIndex(store, conventions, database);
99+
resultPromise = this._putIndex(store, conventions, database);
60100
}
101+
102+
passResultToCallback(resultPromise, callback);
103+
104+
return resultPromise;
61105
}
62106

63107
private async _putIndex(

src/Documents/Indexes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from "./AbstractIndexCreationTask";
2-
export * from "./AbstractMultiMapIndexCreationTask";
2+
export * from "./AbstractMultiMapIndexCreationTask";

0 commit comments

Comments
 (0)