Skip to content

Commit d2a93fe

Browse files
committed
Merge branch 'v5.0' into v5.2
2 parents 390602f + e775f20 commit d2a93fe

File tree

6 files changed

+211
-16
lines changed

6 files changed

+211
-16
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Documents/Queries/TimeSeries/TimeSeriesAggregationResult.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { TimeSeriesQueryResult } from "./TimeSeriesQueryResult";
22
import { TimeSeriesRangeAggregation } from "./TimeSeriesRangeAggregation";
3-
import { ClassConstructor } from "../../../Types";
3+
import { EntityConstructor } from "../../../Types";
44
import { TypedTimeSeriesAggregationResult } from "./TypedTimeSeriesAggregationResult";
55

66
export class TimeSeriesAggregationResult extends TimeSeriesQueryResult {
77
public results: TimeSeriesRangeAggregation[];
88

9-
public asTypedEntry<T extends object>(clazz: ClassConstructor<T>) {
9+
public asTypedEntry<T extends object>(clazz: EntityConstructor<T>) {
1010
const result = new TypedTimeSeriesAggregationResult<T>();
1111
result.count = this.count;
1212
result.results = this.results.map(x => x.asTypedEntry(clazz));

src/Documents/Queries/TimeSeries/TimeSeriesRangeAggregation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export class TimeSeriesRangeAggregation {
1818

1919
typedEntry.from = this.from;
2020
typedEntry.to = this.to;
21-
typedEntry.min = this.min ? TimeSeriesValuesHelper.setFields(clazz, this.min, true) : null;
22-
typedEntry.max = this.max ? TimeSeriesValuesHelper.setFields(clazz, this.max, true) : null;
23-
typedEntry.first = this.first ? TimeSeriesValuesHelper.setFields(clazz, this.first, true) : null;
24-
typedEntry.last = this.last ? TimeSeriesValuesHelper.setFields(clazz, this.last, true) : null;
25-
typedEntry.sum = this.sum ? TimeSeriesValuesHelper.setFields(clazz, this.sum, true) : null;
26-
typedEntry.count = this.count ? TimeSeriesValuesHelper.setFields(clazz, this.count, true) : null;
27-
typedEntry.average = this.average ? TimeSeriesValuesHelper.setFields(clazz, this.average, true) : null;
21+
typedEntry.min = this.min ? TimeSeriesValuesHelper.setFields(clazz, this.min, false) : null;
22+
typedEntry.max = this.max ? TimeSeriesValuesHelper.setFields(clazz, this.max, false) : null;
23+
typedEntry.first = this.first ? TimeSeriesValuesHelper.setFields(clazz, this.first, false) : null;
24+
typedEntry.last = this.last ? TimeSeriesValuesHelper.setFields(clazz, this.last, false) : null;
25+
typedEntry.sum = this.sum ? TimeSeriesValuesHelper.setFields(clazz, this.sum, false) : null;
26+
typedEntry.count = this.count ? TimeSeriesValuesHelper.setFields(clazz, this.count, false) : null;
27+
typedEntry.average = this.average ? TimeSeriesValuesHelper.setFields(clazz, this.average, false) : null;
2828

2929
return typedEntry;
3030
}

src/Documents/Session/EntityToJson.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,30 @@ export class EntityToJson {
112112
documentInfo.metadata[CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE] || typeInfo.typeName;
113113
}
114114

115+
function differentNestedTypes(): boolean {
116+
const existing = documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.NESTED_OBJECT_TYPES];
117+
if (!existing) {
118+
return true;
119+
}
120+
if (Object.keys(existing).length !== Object.keys(typeInfo.nestedTypes).length) {
121+
return true;
122+
}
123+
for (const key in typeInfo.nestedTypes) {
124+
if (typeInfo.nestedTypes[key] !== existing[key]) {
125+
return true;
126+
}
127+
}
128+
return false;
129+
}
130+
115131
if (documentInfo.metadataInstance) {
116-
documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.NESTED_OBJECT_TYPES] = typeInfo.nestedTypes;
117-
documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE] =
118-
documentInfo.metadataInstance["Raven-Node-Type"] || typeInfo.typeName;
132+
if (differentNestedTypes()) {
133+
documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.NESTED_OBJECT_TYPES] = typeInfo.nestedTypes;
134+
}
135+
const nodeType = documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE] || typeInfo.typeName;
136+
if (documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE] !== nodeType) {
137+
documentInfo.metadataInstance[CONSTANTS.Documents.Metadata.RAVEN_JS_TYPE] = nodeType;
138+
}
119139
}
120140

121141
let setMetadata: boolean = false;

test/Issues/RDBC_501.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { IDocumentStore, TimeSeriesAggregationResult, TimeSeriesValue } from "../../src";
2+
import { disposeTestDocumentStore, testContext } from "../Utils/TestUtil";
3+
4+
import moment = require("moment");
5+
import { assertThat } from "../Utils/AssertExtensions";
6+
7+
class SymbolPrice {
8+
open: number;
9+
close: number;
10+
high: number;
11+
low: number;
12+
13+
static TIME_SERIES_VALUES: TimeSeriesValue<SymbolPrice> = [
14+
{ field: "open", name: "Open" },
15+
{ field: "close", name: "Close" },
16+
{ field: "high", name: "High" },
17+
{ field: "low", name: "Low" },
18+
];
19+
}
20+
21+
class MarketSymbol {
22+
23+
}
24+
25+
describe("RDBC-501", function () {
26+
27+
let store: IDocumentStore;
28+
29+
beforeEach(async function () {
30+
store = await testContext.getDocumentStore();
31+
});
32+
33+
afterEach(async () =>
34+
await disposeTestDocumentStore(store));
35+
36+
it("should properly map typed entries", async function () {
37+
38+
const baseLine = moment().startOf("day");
39+
40+
{
41+
const session = store.openSession();
42+
const symbol = new MarketSymbol();
43+
await session.store(symbol, "markerSymbols/1-A");
44+
45+
const price1 = new SymbolPrice();
46+
price1.low = 1;
47+
price1.high = 10;
48+
price1.open = 4;
49+
price1.close = 7;
50+
51+
const price2 = new SymbolPrice();
52+
price2.low = 21;
53+
price2.high = 210;
54+
price2.open = 24;
55+
price2.close = 27;
56+
57+
const price3 = new SymbolPrice();
58+
price3.low = 321;
59+
price3.high = 310;
60+
price3.open = 34;
61+
price3.close = 37;
62+
63+
const tsf = session.timeSeriesFor<SymbolPrice>(symbol, "history", SymbolPrice);
64+
65+
tsf.append(baseLine.clone().add(1, "hours").toDate(), price1);
66+
tsf.append(baseLine.clone().add(2, "hours").toDate(), price2);
67+
tsf.append(baseLine.clone().add(2, "days").toDate(), price3);
68+
69+
await session.saveChanges();
70+
}
71+
72+
{
73+
const session = store.openSession();
74+
75+
const aggregatedHistoryQueryResult = await session
76+
.query(MarketSymbol)
77+
.selectTimeSeries(
78+
(builder) =>
79+
builder.raw(
80+
`from history
81+
group by '1 days'
82+
select first(), last(), min(), max()`
83+
),
84+
TimeSeriesAggregationResult
85+
)
86+
.firstOrNull();
87+
88+
assertThat(aggregatedHistoryQueryResult.results)
89+
.hasSize(2);
90+
91+
const typed = aggregatedHistoryQueryResult.asTypedEntry(SymbolPrice);
92+
assertThat(typed.results)
93+
.hasSize(2);
94+
95+
const firstResult = typed.results[0];
96+
assertThat(firstResult.min.open)
97+
.isEqualTo(4);
98+
assertThat(firstResult.min.close)
99+
.isEqualTo(7);
100+
assertThat(firstResult.min.low)
101+
.isEqualTo(1);
102+
assertThat(firstResult.min.high)
103+
.isEqualTo(10);
104+
105+
assertThat(firstResult.first.open)
106+
.isEqualTo(4);
107+
assertThat(firstResult.first.close)
108+
.isEqualTo(7);
109+
assertThat(firstResult.first.low)
110+
.isEqualTo(1);
111+
assertThat(firstResult.first.high)
112+
.isEqualTo(10);
113+
114+
const secondResult = typed.results[1];
115+
assertThat(secondResult.min.open)
116+
.isEqualTo(34);
117+
assertThat(secondResult.min.close)
118+
.isEqualTo(37);
119+
assertThat(secondResult.min.low)
120+
.isEqualTo(321);
121+
assertThat(secondResult.min.high)
122+
.isEqualTo(310);
123+
}
124+
});
125+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { testContext, disposeTestDocumentStore } from "../../Utils/TestUtil";
2+
3+
import {
4+
IDocumentStore,
5+
} from "../../../src";
6+
import { assertThat } from "../../Utils/AssertExtensions";
7+
8+
class Item {
9+
v: string;
10+
11+
constructor(v: string) {
12+
this.v = v;
13+
}
14+
}
15+
16+
describe("SpuriousSaveChanges", function () {
17+
18+
let store: IDocumentStore;
19+
20+
beforeEach(async function () {
21+
store = await testContext.getDocumentStore();
22+
});
23+
24+
afterEach(async () =>
25+
await disposeTestDocumentStore(store)
26+
);
27+
28+
it("willNotSaveUnmodifiedDocuments", async () => {
29+
30+
await createData(store);
31+
32+
{
33+
const session = store.openSession();
34+
const result = await session.query<Item>({ collection: "items" })
35+
.all();
36+
assertThat(session.advanced.hasChanged(result[0]))
37+
.isFalse();
38+
const old = session.advanced.numberOfRequests;
39+
await session.saveChanges();
40+
assertThat(session.advanced.numberOfRequests)
41+
.isEqualTo(old);
42+
}
43+
});
44+
45+
async function createData(store: IDocumentStore): Promise<void> {
46+
const session = store.openSession();
47+
await session.store(new Item("f"), "items/1");
48+
await session.saveChanges();
49+
}
50+
});

0 commit comments

Comments
 (0)