Skip to content

Commit 3a0eeb0

Browse files
committed
add test RavenDB-11552 + code cleanup
1 parent b0acebe commit 3a0eeb0

31 files changed

+227
-219
lines changed

src/Constants.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { MetadataObject } from "./Documents/Session/MetadataObject";
2+
13
export const CONSTANTS = {
24
Documents: {
35
Indexing: {
@@ -15,23 +17,23 @@ export const CONSTANTS = {
1517
SIDE_BY_SIDE_INDEX_NAME_PREFIX: "ReplacementOf/",
1618
},
1719
Metadata: {
18-
COLLECTION: "@collection",
19-
PROJECTION: "@projection",
20-
KEY: "@metadata",
21-
ID: "@id",
20+
COLLECTION: "@collection" as keyof MetadataObject,
21+
PROJECTION: "@projection" as keyof MetadataObject,
22+
KEY: "@metadata" as keyof MetadataObject,
23+
ID: "@id" as keyof MetadataObject,
2224
CONFLICT: "@conflict",
2325
ID_PROPERTY: "id",
24-
FLAGS: "@flags",
25-
ATTACHMENTS: "@attachments",
26-
INDEX_SCORE: "@index-score",
27-
LAST_MODIFIED: "@last-modified",
28-
RAVEN_JS_TYPE: "Raven-Node-Type",
29-
CHANGE_VECTOR: "@change-vector",
30-
EXPIRES: "@expires",
26+
FLAGS: "@flags" as keyof MetadataObject,
27+
ATTACHMENTS: "@attachments" as keyof MetadataObject,
28+
INDEX_SCORE: "@index-score" as keyof MetadataObject,
29+
LAST_MODIFIED: "@last-modified" as keyof MetadataObject,
30+
RAVEN_JS_TYPE: "Raven-Node-Type" as keyof MetadataObject,
31+
CHANGE_VECTOR: "@change-vector" as keyof MetadataObject,
32+
EXPIRES: "@expires" as keyof MetadataObject,
3133
ALL_DOCUMENTS_COLLECTION: "@all_docs",
3234
EMPTY_COLLECTION: "@empty",
33-
NESTED_OBJECT_TYPES: "@nested-object-types",
34-
COUNTERS: "@counters",
35+
NESTED_OBJECT_TYPES: "@nested-object-types" as keyof MetadataObject,
36+
COUNTERS: "@counters" as keyof MetadataObject,
3537
REVISION_COUNTERS: "@counters-snapshot",
3638
IGNORE_CASE_TRANSFORM_REGEX:
3739
// tslint:disable-next-line:max-line-length

src/Documents/Attachments/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface AttachmentName {
1313

1414
export interface AttachmentDetails extends AttachmentName {
1515
changeVector: string;
16-
documentId: string;
16+
documentId?: string;
1717
}
1818

1919
export class AttachmentResult {

src/Documents/BulkInsertOperation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ServerNode } from "../Http/ServerNode";
2121
import { AbstractCallback } from "../Types/Callbacks";
2222
import { passResultToCallback } from "../Utility/PromiseUtil";
2323
import { BatchOperation } from "./Session/Operations/BatchOperation";
24+
import { MetadataObject } from "./Session/MetadataObject";
2425

2526
export class BulkInsertOperation {
2627
private readonly _generateEntityIdOnTheClient: GenerateEntityIdOnTheClient;
@@ -162,18 +163,18 @@ export class BulkInsertOperation {
162163
});
163164
}
164165

165-
if (!(CONSTANTS.Documents.Metadata.COLLECTION in metadata)) {
166+
if (!(("@collection" as keyof MetadataObject) in metadata)) {
166167
const collection = this._requestExecutor.conventions.getCollectionNameForEntity(entity);
167168
if (collection) {
168-
metadata[CONSTANTS.Documents.Metadata.COLLECTION] = collection;
169+
metadata["@collection"] = collection;
169170
}
170171
}
171172

172-
if (!(CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE in metadata)) {
173+
if (!("Raven-Node-Type" as keyof MetadataObject in metadata)) {
173174
const descriptor = this._conventions.getEntityTypeDescriptor(entity);
174175
const jsType = this._requestExecutor.conventions.getJsTypeName(descriptor);
175176
if (jsType) {
176-
metadata[CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE] = jsType;
177+
metadata["Raven-Node-Type"] = jsType;
177178
}
178179
}
179180

src/Documents/Commands/Batches/BatchPatchCommandData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ export class BatchPatchCommandData implements ICommandData {
108108
: undefined
109109
};
110110
}
111-
}
111+
}

src/Documents/Commands/Batches/DeleteAttachmentCommandData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export class DeleteAttachmentCommandData implements ICommandData {
1111
public type: CommandType = "AttachmentDELETE";
1212

1313
public constructor(documentId: string, name: string, changeVector: string) {
14-
if (StringUtil.isWhitespace(documentId)) {
14+
if (StringUtil.isNullOrWhitespace(documentId)) {
1515
throwError("InvalidArgumentException", "DocumentId cannot be null");
1616
}
1717

18-
if (StringUtil.isWhitespace(name)) {
18+
if (StringUtil.isNullOrWhitespace(name)) {
1919
throwError("InvalidArgumentException", "Name cannot be null");
2020
}
2121

src/Documents/Commands/Batches/PutAttachmentCommandData.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export class PutAttachmentCommandData implements ICommandData {
1919
contentType: string,
2020
changeVector: string) {
2121

22-
if (StringUtil.isWhitespace(documentId)) {
23-
throwError("InvalidArgumentException", "DocumentId cannot be null");
22+
if (StringUtil.isNullOrWhitespace(documentId)) {
23+
throwError("InvalidArgumentException", "DocumentId cannot be null.");
2424
}
2525

26-
if (StringUtil.isWhitespace(name)) {
27-
throwError("InvalidArgumentException", "Name cannot be null");
26+
if (StringUtil.isNullOrWhitespace(name)) {
27+
throwError("InvalidArgumentException", "Name cannot be null.");
2828
}
2929

3030
this.id = documentId;

src/Documents/Commands/HeadAttachmentCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export class HeadAttachmentCommand extends RavenCommand<string> {
2121
public constructor(documentId: string, name: string, changeVector: string) {
2222
super();
2323

24-
if (StringUtil.isWhitespace(documentId)) {
24+
if (StringUtil.isNullOrWhitespace(documentId)) {
2525
throwError("InvalidArgumentException", "DocumentId cannot be null or empty");
2626
}
2727

28-
if (StringUtil.isWhitespace(name)) {
28+
if (StringUtil.isNullOrWhitespace(name)) {
2929
throwError("InvalidArgumentException", "Name cannot be null or empty");
3030
}
3131

src/Documents/Operations/Attachments/DeleteAttachmentOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export class DeleteAttachmentCommand extends RavenCommand<void> {
3333

3434
public constructor(documentId: string, name: string, changeVector: string) {
3535
super();
36-
if (StringUtil.isWhitespace(documentId)) {
36+
if (StringUtil.isNullOrWhitespace(documentId)) {
3737
throwError("InvalidArgumentException", "DocumentId cannot be null or empty");
3838
}
39-
if (StringUtil.isWhitespace(name)) {
39+
if (StringUtil.isNullOrWhitespace(name)) {
4040
throwError("InvalidArgumentException", "Name cannot be null or empty");
4141
}
4242

src/Documents/Operations/Attachments/GetAttachmentOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export class GetAttachmentCommand extends RavenCommand<AttachmentResult> {
4646
public constructor(documentId: string, name: string, type: AttachmentType, changeVector: string) {
4747
super();
4848

49-
if (StringUtil.isWhitespace(documentId)) {
49+
if (StringUtil.isNullOrWhitespace(documentId)) {
5050
throwError("InvalidArgumentException", "DocumentId cannot be null or empty");
5151
}
52-
if (StringUtil.isWhitespace(name)) {
52+
if (StringUtil.isNullOrWhitespace(name)) {
5353
throwError("InvalidArgumentException", "Name cannot be null or empty");
5454
}
5555
if (type !== "Document" && !changeVector) {

src/Documents/Operations/Attachments/PutAttachmentOperation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export class PutAttachmentCommand extends RavenCommand<AttachmentDetails> {
5050
stream: AttachmentData, contentType: string, changeVector: string) {
5151
super();
5252

53-
if (StringUtil.isWhitespace(documentId)) {
53+
if (StringUtil.isNullOrWhitespace(documentId)) {
5454
throwError("InvalidArgumentException", "DocumentId cannot be null or empty");
5555
}
56-
if (StringUtil.isWhitespace(name)) {
56+
if (StringUtil.isNullOrWhitespace(name)) {
5757
throwError("InvalidArgumentException", "Name cannot be null or empty");
5858
}
5959

0 commit comments

Comments
 (0)