Skip to content

Commit ab2c599

Browse files
authored
Merge pull request #173 from gregolsky/v4.0
minor api fixes, enable subscription tests against 4.1
2 parents 2c7e5e3 + 9ba49ab commit ab2c599

File tree

9 files changed

+132
-75
lines changed

9 files changed

+132
-75
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ravendb",
3-
"version": "4.0.5",
3+
"version": "4.0.6",
44
"description": "RavenDB client for Node.js",
55
"files": [
66
"dist/"

src/Documents/DocumentStoreBase.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { BulkInsertOperation } from "./BulkInsertOperation";
2424
import { IDatabaseChanges } from "./Changes/IDatabaseChanges";
2525
import { DocumentSubscriptions } from "./Subscriptions/DocumentSubscriptions";
2626
import { DocumentStore } from "./DocumentStore";
27+
import { AbstractCallback } from "../Types/Callbacks";
28+
import { TypeUtil } from "../Utility/TypeUtil";
29+
import { passResultToCallback } from "../Utility/PromiseUtil";
2730

2831
export abstract class DocumentStoreBase
2932
extends EventEmitter
@@ -63,35 +66,49 @@ export abstract class DocumentStoreBase
6366
public abstract openSession(sessionOptions: SessionOptions): IDocumentSession;
6467

6568
public executeIndex(task: AbstractIndexCreationTask): Promise<void>;
66-
public executeIndex(task: AbstractIndexCreationTask, database?: string): Promise<void>;
67-
public executeIndex(task: AbstractIndexCreationTask, database?: string): Promise<void> {
69+
public executeIndex(task: AbstractIndexCreationTask, database: string): Promise<void>;
70+
public executeIndex(task: AbstractIndexCreationTask, callback: AbstractCallback<void>): Promise<void>;
71+
public executeIndex(
72+
task: AbstractIndexCreationTask,
73+
database: string,
74+
callback: AbstractCallback<void>): Promise<void>;
75+
public executeIndex(
76+
task: AbstractIndexCreationTask,
77+
databaseOrCallback?: string | AbstractCallback<void>,
78+
callback?: AbstractCallback<void>): Promise<void> {
6879
this.assertInitialized();
69-
return task.execute(this, this.conventions, database);
80+
const database = TypeUtil.isFunction(databaseOrCallback)
81+
? null
82+
: databaseOrCallback as string;
83+
const resultPromise = task.execute(this, this.conventions, database);
84+
passResultToCallback(resultPromise, callback || TypeUtil.NOOP);
85+
return resultPromise;
7086
}
7187

72-
// TODO: public void executeIndex(AbstractIndexCreationTask task) {
73-
// executeIndex(task, null);
74-
// }
75-
76-
// TODO: public void executeIndex(AbstractIndexCreationTask task, String database) {
77-
// assertInitialized();
78-
// task.execute(this, conventions, database);
79-
// }
80-
81-
// TODO: @Override
82-
// public void executeIndexes(List<AbstractIndexCreationTask> tasks) {
83-
// executeIndexes(tasks, null);
84-
// }
85-
86-
// TODO: @Override
87-
// public void executeIndexes(List<AbstractIndexCreationTask> tasks, String database) {
88-
// assertInitialized();
89-
// IndexDefinition[] indexesToAdd = IndexCreation.createIndexesToAdd(tasks, conventions);
90-
91-
// TODO: maintenance()
92-
// .forDatabase(ObjectUtils.firstNonNull(database, getDatabase()))
93-
// .send(new PutIndexesOperation(indexesToAdd));
94-
// }
88+
public async executeIndexes(tasks: AbstractIndexCreationTask[]): Promise<void>;
89+
public async executeIndexes(
90+
tasks: AbstractIndexCreationTask[], callback: AbstractCallback<void>): Promise<void>;
91+
public async executeIndexes(tasks: AbstractIndexCreationTask[], database: string): Promise<void>;
92+
public async executeIndexes(
93+
tasks: AbstractIndexCreationTask[], database: string, callback: AbstractCallback<void>): Promise<void>;
94+
public async executeIndexes(
95+
tasks: AbstractIndexCreationTask[],
96+
databaseOrCallback?: string | AbstractCallback<void>,
97+
callback?: AbstractCallback<void>): Promise<void> {
98+
this.assertInitialized();
99+
const indexesToAdd = IndexCreation.createIndexesToAdd(tasks, this.conventions);
100+
const database = TypeUtil.isFunction(databaseOrCallback)
101+
? null
102+
: databaseOrCallback as string;
103+
104+
const resultPromise = this.maintenance
105+
.forDatabase(database || this.database)
106+
.send(new PutIndexesOperation(...indexesToAdd))
107+
.then(() => {});
108+
109+
passResultToCallback(resultPromise, callback || TypeUtil.NOOP);
110+
return resultPromise;
111+
}
95112

96113
private _conventions: DocumentConventions;
97114

@@ -234,25 +251,6 @@ export abstract class DocumentStoreBase
234251

235252
public abstract operations: OperationExecutor;
236253

237-
public executeIndexes(tasks: AbstractIndexCreationTask[]): Promise<void>;
238-
public executeIndexes(tasks: AbstractIndexCreationTask[], database: string): Promise<void>;
239-
public executeIndexes(tasks: AbstractIndexCreationTask[], database?: string): Promise<void> {
240-
241-
this.assertInitialized();
242-
243-
return Promise.resolve()
244-
.then(() => {
245-
const indexesToAdd = IndexCreation.createIndexesToAdd(tasks, this.conventions);
246-
247-
return this.maintenance
248-
.forDatabase(database || this.database)
249-
.send(new PutIndexesOperation(...indexesToAdd));
250-
})
251-
// tslint:disable-next-line:no-empty
252-
.then(() => {
253-
});
254-
}
255-
256254
protected _assertValidConfiguration(): void {
257255
this.conventions.validate();
258256
}

src/Documents/IDocumentStore.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { InMemoryDocumentSessionOperations } from "./Session/InMemoryDocumentSes
1717
import { BulkInsertOperation } from "./BulkInsertOperation";
1818
import { IDatabaseChanges } from "./Changes/IDatabaseChanges";
1919
import { DocumentSubscriptions } from "./Subscriptions/DocumentSubscriptions";
20+
import { AbstractCallback } from "../Types/Callbacks";
2021

2122
export interface SessionEventsProxy {
2223
addSessionListener(eventName: "beforeStore", eventHandler: (eventArgs: SessionBeforeStoreEventArgs) => void): this;
@@ -143,6 +144,16 @@ export interface IDocumentStore extends IDisposable,
143144
*/
144145
executeIndex(task: AbstractIndexCreationTask, database: string): Promise<void>;
145146

147+
/**
148+
* Executes the index creation
149+
*/
150+
executeIndex(task: AbstractIndexCreationTask, callback: AbstractCallback<void>): Promise<void>;
151+
152+
/**
153+
* Executes the index creation
154+
*/
155+
executeIndex(task: AbstractIndexCreationTask, database: string, callback: AbstractCallback<void>): Promise<void>;
156+
146157
/**
147158
* Executes the index creation
148159
*/
@@ -153,6 +164,17 @@ export interface IDocumentStore extends IDisposable,
153164
*/
154165
executeIndexes(tasks: AbstractIndexCreationTask[], database: string): Promise<void>;
155166

167+
/**
168+
* Executes the index creation
169+
*/
170+
executeIndexes(tasks: AbstractIndexCreationTask[], callback: AbstractCallback<void>): Promise<void>;
171+
172+
/**
173+
* Executes the index creation
174+
*/
175+
executeIndexes(
176+
tasks: AbstractIndexCreationTask[], database: string, callback: AbstractCallback<void>): Promise<void>;
177+
156178
/**
157179
* Contains authentication information: client certificate data;
158180
*/

src/Documents/Indexes/index.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { IDocumentStore } from "../IDocumentStore";
77
import { CONSTANTS } from "../../Constants";
88
import { PutIndexesOperation } from "../Operations/Indexes/PutIndexesOperation";
99
import { throwError } from "../../Exceptions";
10+
import { AbstractCallback } from "../../Types/Callbacks";
11+
import { TypeUtil } from "../../Utility/TypeUtil";
12+
import { passResultToCallback } from "../../Utility/PromiseUtil";
1013

1114
export abstract class AbstractIndexCreationTask {
1215

@@ -78,16 +81,69 @@ export abstract class AbstractIndexCreationTask {
7881
return indexCtorName.replace(/_/g, "/");
7982
}
8083

81-
//TODO: introduce overloads?
8284
/**
8385
* Executes the index creation against the specified document store.
8486
*/
85-
public async execute(store: IDocumentStore, conventions?: DocumentConventions, database?: string): Promise<void> {
87+
public async execute(store: IDocumentStore): Promise<void>;
88+
/**
89+
* Executes the index creation against the specified document store.
90+
*/
91+
public async execute(store: IDocumentStore, callback: AbstractCallback<void>): Promise<void>;
92+
/**
93+
* Executes the index creation against the specified document store.
94+
*/
95+
public async execute(store: IDocumentStore, conventions: DocumentConventions): Promise<void>;
96+
/**
97+
* Executes the index creation against the specified document store.
98+
*/
99+
public async execute(
100+
store: IDocumentStore,
101+
conventions: DocumentConventions,
102+
callback: AbstractCallback<void>): Promise<void>;
103+
/**
104+
* Executes the index creation against the specified document store.
105+
*/
106+
public async execute(store: IDocumentStore, conventions: DocumentConventions, database: string): Promise<void>;
107+
/**
108+
* Executes the index creation against the specified document store.
109+
*/
110+
public async execute(
111+
store: IDocumentStore,
112+
conventions: DocumentConventions,
113+
database: string,
114+
callback: AbstractCallback<void>): Promise<void>;
115+
public async execute(
116+
store: IDocumentStore,
117+
conventionsOrCallback?: DocumentConventions | AbstractCallback<void>,
118+
databaseOrCallback?: string | AbstractCallback<void>,
119+
callback?: AbstractCallback<void>): Promise<void> {
120+
121+
let conventions: DocumentConventions;
122+
let database: string;
123+
if (arguments.length > 1) {
124+
if (TypeUtil.isFunction(conventionsOrCallback)) {
125+
callback = conventionsOrCallback;
126+
} else if (TypeUtil.isFunction(databaseOrCallback)) {
127+
callback = databaseOrCallback;
128+
conventions = conventionsOrCallback;
129+
} else {
130+
conventions = conventionsOrCallback;
131+
database = databaseOrCallback;
132+
}
133+
}
134+
135+
callback = callback || TypeUtil.NOOP;
136+
137+
let resultPromise;
86138
if (!conventions && !database) {
87-
return store.executeIndex(this);
139+
resultPromise = store.executeIndex(this);
88140
} else {
89-
return this._putIndex(store, conventions, database);
141+
resultPromise = this._putIndex(store, conventions, database);
90142
}
143+
144+
passResultToCallback(resultPromise, callback);
145+
146+
return resultPromise;
91147
}
92148

93149
private _putIndex(store: IDocumentStore, conventions: DocumentConventions, database: string): Promise<void> {

test/Documents/ReadmeSamples.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,7 @@ describe("Readme query samples", function () {
450450
}
451451
});
452452

453-
const is41 = process.env["RAVENDB_SERVER_VERSION"] === "4.1";
454-
455-
// skipped for the time being
456-
// subscriptions are not working with server version 4.1
457-
// due to RavenDB-12127
458-
(is41 ? it.skip : it)("can subscribe", async () => {
453+
it("can subscribe", async () => {
459454

460455
// create a subscription
461456
const subscriptionName = await store.subscriptions.create({

test/Ported/Subscriptions/RevisionsSubscriptionsTest.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import { RevisionsConfiguration } from "../../../src/Documents/Operations/Revisi
1010
import { ConfigureRevisionsOperation } from "../../../src/Documents/Operations/Revisions/ConfigureRevisionsOperation";
1111
import * as assert from "assert";
1212

13-
const is41 = process.env["RAVENDB_SERVER_VERSION"] === "4.1";
14-
15-
// skipped for the time being
16-
// subscriptions are not working with server version 4.1
17-
// due to RavenDB-12127
18-
(is41 ? describe.skip : describe)("RevisionsSubscriptionsTest", function () {
13+
describe("RevisionsSubscriptionsTest", function () {
1914
this.timeout(5 * 10 * 1000);
2015

2116
let store: IDocumentStore;

test/Ported/Subscriptions/SecuredSubscriptionsBasicTest.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ import {
88
} from "../../../src";
99
import { AsyncQueue } from "../../Utils/AsyncQueue";
1010

11-
const is41 = process.env["RAVENDB_SERVER_VERSION"] === "4.1";
12-
13-
// skipped for the time being
14-
// subscriptions are not working with server version 4.1
15-
// due to RavenDB-12127
16-
(is41 ? describe.skip : describe)("SecuredSubscriptionsBasicTest", function () {
11+
describe("SecuredSubscriptionsBasicTest", function () {
1712
const _reasonableWaitTime = 5 * 1000;
1813
this.timeout(5 * _reasonableWaitTime);
1914

test/Ported/Subscriptions/SubscriptionsBasicTest.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ import { getError, throwError } from "../../../src/Exceptions";
1616
import { TypeUtil } from "../../../src/Utility/TypeUtil";
1717
import { delay } from "bluebird";
1818

19-
const is41 = process.env["RAVENDB_SERVER_VERSION"] === "4.1";
20-
21-
// skipped for the time being
22-
// subscriptions are not working with server version 4.1
23-
// due to RavenDB-12127
24-
(is41 ? describe.skip : describe)("SubscriptionsBasicTest", function () {
19+
describe("SubscriptionsBasicTest", function () {
2520
const _reasonableWaitTime = 5 * 1000;
2621
this.timeout(5 * _reasonableWaitTime);
2722

tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"object-curly-spacing": [true, "always"],
3737
"comment-format": false,
3838
"no-shadowed-variable": false,
39-
"mocha-avoid-only": true
39+
"mocha-avoid-only": true,
40+
"no-debugger": true
4041
},
4142
"rulesDirectory": [
4243
"node_modules/tslint-microsoft-contrib"

0 commit comments

Comments
 (0)