Skip to content

Commit 4f87f3c

Browse files
committed
RDBC-622 removed transform json keys
1 parent 864ca38 commit 4f87f3c

File tree

9 files changed

+76
-228
lines changed

9 files changed

+76
-228
lines changed

src/Documents/Commands/FacetQueryCommand.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,12 @@ export class FacetQueryCommand extends QueryCommand {
4848
defaultTransform: "camel"
4949
}) as any;
5050

51-
const mappedIncludes: Record<string, any> = {};
52-
if (json.Includes) {
53-
for (const [key, value] of Object.entries(json.Includes)) {
54-
mappedIncludes[key] = ObjectUtil.transformDocumentKeys(value, conventions);
55-
}
56-
}
57-
5851
return {
5952
...restMapped,
6053
indexTimestamp: conventions.dateUtil.parse(IndexTimestamp),
6154
lastQueryTime: conventions.dateUtil.parse(LastQueryTime),
6255
results: Results.map(x => ObjectUtil.transformObjectKeys(x, { defaultTransform: "camel" })),
63-
includes: mappedIncludes
56+
includes: ObjectUtil.mapIncludesToLocalObject(json.Includes, conventions)
6457
};
6558
}
6659
}

src/Documents/Commands/GetDocumentsCommand.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,9 @@ export class GetDocumentsCommand extends RavenCommand<GetDocumentsResult> {
346346
}
347347

348348
private static _mapToLocalObject(json: any, conventions: DocumentConventions): GetDocumentsResult {
349-
const mappedIncludes: Record<string, any> = {};
350-
if (json.Includes) {
351-
for (const [key, value] of Object.entries(json.Includes)) {
352-
mappedIncludes[key] = ObjectUtil.transformDocumentKeys(value, conventions);
353-
}
354-
}
355-
356349
return {
357350
results: json.Results.map(x => ObjectUtil.transformDocumentKeys(x, conventions)),
358-
includes: mappedIncludes,
351+
includes: ObjectUtil.mapIncludesToLocalObject(json.Includes, conventions),
359352
compareExchangeValueIncludes: ObjectUtil.mapCompareExchangeToLocalObject(json.CompareExchangeValueIncludes),
360353
timeSeriesIncludes: ObjectUtil.mapTimeSeriesIncludesToLocalObject(json.TimeSeriesIncludes),
361354
counterIncludes: ObjectUtil.mapCounterIncludesToLocalObject(json.CounterIncludes),

src/Documents/Commands/QueryCommand.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,9 @@ export class QueryCommand extends RavenCommand<QueryResult> {
154154

155155

156156
private static _mapToLocalObject(json: any, conventions: DocumentConventions): QueryResult {
157-
const mappedIncludes: Record<string, any> = {};
158-
if (json.Includes) {
159-
for (const [key, value] of Object.entries(json.Includes)) {
160-
mappedIncludes[key] = ObjectUtil.transformDocumentKeys(value, conventions);
161-
}
162-
}
163-
164157
const props: Omit<QueryResult, "scoreExplanations" | "cappedMaxResults" | "createSnapshot" | "resultSize"> = {
165158
results: json.Results.map(x => ObjectUtil.transformDocumentKeys(x, conventions)),
166-
includes: mappedIncludes,
159+
includes: ObjectUtil.mapIncludesToLocalObject(json.Includes, conventions),
167160
indexName: json.IndexName,
168161
indexTimestamp: conventions.dateUtil.parse(json.IndexTimestamp),
169162
includedPaths: json.IncludedPaths,

src/Documents/Subscriptions/SubscriptionConnectionServerMessage.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
export interface SubscriptionConnectionServerMessage {
33
type: MessageType;
4-
status: ConnectionStatus;
5-
data: any;
6-
includes: any;
7-
counterIncludes: any;
8-
includedCounterNames: Record<string, string[]>;
9-
timeSeriesIncludes: any;
10-
exception: string;
11-
message: string;
4+
status?: ConnectionStatus;
5+
data?: any;
6+
includes?: any;
7+
counterIncludes?: any;
8+
includedCounterNames?: Record<string, string[]>;
9+
timeSeriesIncludes?: any;
10+
exception?: string;
11+
message?: string;
1212
}
1313

1414
export interface SubscriptionRedirectData {

src/Documents/Subscriptions/SubscriptionWorker.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ import { EmptyCallback } from "../../Types/Callbacks";
2525
import { delay } from "../../Utility/PromiseUtil";
2626
import * as Parser from "stream-json/Parser";
2727
import * as StreamValues from "stream-json/streamers/StreamValues";
28-
import { TransformKeysJsonStream } from "../../Mapping/Json/Streams/TransformKeysJsonStream";
29-
import { getTransformJsonKeysProfile } from "../../Mapping/Json/Streams/TransformJsonKeysProfiles";
3028
import { BatchFromServer, CounterIncludeItem } from "./BatchFromServer";
3129
import { ServerNode } from "../../Http/ServerNode";
3230
import { RequestExecutor } from "../../Http/RequestExecutor";
3331
import { GetTcpInfoCommand, TcpConnectionInfo } from "../../ServerWide/Commands/GetTcpInfoCommand";
3432
import { GetTcpInfoForRemoteTaskCommand } from "../Commands/GetTcpInfoForRemoteTaskCommand";
3533
import * as os from "os";
34+
import { DocumentConventions } from "../Conventions/DocumentConventions";
35+
import { ServerCasing, ServerResponse } from "../../Types";
36+
import { CONSTANTS } from "../../Constants";
3637

3738
type EventTypes = "afterAcknowledgment" | "connectionRetry" | "batch" | "error" | "end" | "unexpectedSubscriptionError";
3839

@@ -239,16 +240,29 @@ export class SubscriptionWorker<T extends object> implements IDisposable {
239240
}
240241

241242
private _ensureParser(socket: Socket) {
242-
const keysTransformProfile = getTransformJsonKeysProfile(
243-
this._revisions
244-
? "SubscriptionRevisionsResponsePayload"
245-
: "SubscriptionResponsePayload", this._store.conventions);
243+
const conventions = this._store.conventions;
244+
const revisions = this._revisions;
245+
246+
const keysTransform = new stream.Transform({
247+
objectMode: true,
248+
transform(chunk, encoding, callback) {
249+
let value = chunk["value"];
250+
if (!value) {
251+
return callback();
252+
}
253+
254+
value = SubscriptionWorker._mapToLocalObject(value, revisions, conventions);
255+
256+
callback(null, {...chunk, value});
257+
}
258+
});
259+
246260

247261
this._parser = stream.pipeline([
248262
socket,
249263
new Parser({ jsonStreaming: true, streamValues: false }),
250-
new TransformKeysJsonStream(keysTransformProfile),
251-
new StreamValues()
264+
new StreamValues(),
265+
keysTransform
252266
], err => {
253267
if (err && !socket.destroyed) {
254268
this._emitter.emit("error", err);
@@ -804,4 +818,30 @@ export class SubscriptionWorker<T extends object> implements IDisposable {
804818
return this;
805819
}
806820

821+
private static _mapToLocalObject(json: ServerCasing<ServerResponse<SubscriptionConnectionServerMessage>>, revisions: boolean, conventions: DocumentConventions): SubscriptionConnectionServerMessage {
822+
const { Data, Includes, CounterIncludes, ...rest } = json;
823+
824+
let data: any;
825+
if (Data) {
826+
if (revisions) {
827+
data = {
828+
current: ObjectUtil.transformDocumentKeys(Data.Current, conventions),
829+
previous: ObjectUtil.transformDocumentKeys(Data.Previous, conventions),
830+
[CONSTANTS.Documents.Metadata.KEY]: ObjectUtil.transformMetadataKeys(Data[CONSTANTS.Documents.Metadata.KEY], conventions)
831+
}
832+
} else {
833+
data = ObjectUtil.transformDocumentKeys(Data, conventions);
834+
}
835+
}
836+
837+
return {
838+
...ObjectUtil.transformObjectKeys(rest, {
839+
defaultTransform: "camel"
840+
}),
841+
data,
842+
includes: ObjectUtil.mapIncludesToLocalObject(Includes, conventions),
843+
counterIncludes: ObjectUtil.mapCounterIncludesToLocalObject(CounterIncludes),
844+
} as SubscriptionConnectionServerMessage;
845+
}
846+
807847
}

src/Http/RavenCommandResponsePipeline.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import { throwError, getError } from "../Exceptions";
2020
import { TypeUtil } from "../Utility/TypeUtil";
2121
import * as Asm from "stream-json/Assembler";
22-
import { DocumentConventions } from "../Documents/Conventions/DocumentConventions";
2322
import { ErrorFirstCallback } from "../Types/Callbacks";
2423
import { StringBuilder } from "../Utility/StringBuilder";
2524
import { parser as jsonlParser } from "stream-json/jsonl/Parser";

src/Mapping/Json/Streams/TransformJsonKeysProfiles.ts

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/Mapping/Json/Streams/TransformKeysJsonStream.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/Utility/ObjectUtil.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ export class ObjectUtil {
155155
};
156156
}
157157

158+
public static mapIncludesToLocalObject(json: any, conventions: DocumentConventions) {
159+
const mappedIncludes: Record<string, any> = {};
160+
if (json) {
161+
for (const [key, value] of Object.entries(json)) {
162+
mappedIncludes[key] = ObjectUtil.transformDocumentKeys(value, conventions);
163+
}
164+
}
165+
return mappedIncludes;
166+
}
167+
158168
public static mapCompareExchangeToLocalObject(json: Record<string, any>) {
159169
if (!json) {
160170
return undefined;
@@ -345,16 +355,19 @@ function makeKeyPath(keyStack) {
345355
}
346356

347357
function shouldTransformKey(currentKey, currentPath, opts) {
348-
const currentPathPlusKey = currentPath ? currentPath + "." + currentKey : currentKey;
349358
for (const x of opts.ignoreKeys) {
350359
if ("test" in x ? x.test(currentKey) : x === currentKey) {
351360
return false;
352361
}
353362
}
354363

355-
for (const x of opts.ignorePaths) {
356-
if ("test" in x ? x.test(currentPathPlusKey) : x === currentPathPlusKey) {
357-
return false;
364+
if (opts.ignorePaths) {
365+
const currentPathPlusKey = currentPath ? currentPath + "." + currentKey : currentKey;
366+
367+
for (const x of opts.ignorePaths) {
368+
if ("test" in x ? x.test(currentPathPlusKey) : x === currentPathPlusKey) {
369+
return false;
370+
}
358371
}
359372
}
360373

0 commit comments

Comments
 (0)