Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c9fc786
chore: reuse parse work
nbbeeken May 9, 2024
91418d8
chore: turn back on cursorResponse
nbbeeken May 9, 2024
414cdfa
wip
nbbeeken May 9, 2024
cd29ba1
wip
nbbeeken May 10, 2024
a342412
feat(NODE-6136): parse cursor responses on demand
nbbeeken May 15, 2024
9eff48a
wip
nbbeeken May 10, 2024
4534ada
fix: FLE
nbbeeken May 17, 2024
0075729
test: needs fail points
nbbeeken May 17, 2024
79acc71
test: undo bench changes
nbbeeken May 17, 2024
dde8250
chore: cleanup
nbbeeken May 17, 2024
0b825f1
wip
nbbeeken Jun 3, 2024
e0c2250
wip
nbbeeken Jun 4, 2024
1c10a1f
chore: fix unit tests
nbbeeken Jun 4, 2024
be871b8
chore: fix wc throw location
nbbeeken Jun 4, 2024
6989a54
fix: add get overload properly
nbbeeken Jun 5, 2024
9e07ea8
chore: use serialize to make empty_v
nbbeeken Jun 6, 2024
6d081f4
docs: add comment about type crime
nbbeeken Jun 6, 2024
241a08e
cruft
nbbeeken Jun 6, 2024
de3c271
chore: type annotation
nbbeeken Jun 6, 2024
4743695
chore: move ExecutionResult and document
nbbeeken Jun 6, 2024
cba9c49
test: add match to expected errors
nbbeeken Jun 6, 2024
acbb323
test: uncomment wc error ctor tests
nbbeeken Jun 6, 2024
1ffa752
fix: super generic
nbbeeken Jun 7, 2024
fb7de90
Merge branch 'main' into NODE-6136-cursor-response
nbbeeken Jun 7, 2024
827e3f7
chore: fix nullish documents
nbbeeken Jun 7, 2024
00b90ea
fix: pass through options
nbbeeken Jun 7, 2024
e28dbbb
Merge branch 'main' into NODE-6136-cursor-response
nbbeeken Jun 7, 2024
e517ab3
refactor: move CountDocument logic into collection API (#4138)
nbbeeken Jun 10, 2024
9d75303
Revert "refactor: move CountDocument logic into collection API" (#4139)
nbbeeken Jun 10, 2024
b9cfb7c
Merge branch 'main' into NODE-6136-cursor-response
nbbeeken Jun 10, 2024
c1c8ba4
chore: only attach encryptedResponse to cursor response
nbbeeken Jun 10, 2024
d5214c8
chore: clean up TS for "required"
nbbeeken Jun 11, 2024
eb0b618
Merge branch 'main' into NODE-6136-cursor-response
baileympearson Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: add get overload properly
  • Loading branch information
nbbeeken committed Jun 5, 2024
commit 6989a54dd5be174d4dbfae65e99fcc5722b1704f
2 changes: 1 addition & 1 deletion src/cmap/wire_protocol/on_demand/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class OnDemandDocument {
public get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required?: false | undefined
required?: false | undefined | boolean
): JSTypeOf[T] | null;

/** `required` will make `get` throw if name does not exist or is null/undefined */
Expand Down
38 changes: 24 additions & 14 deletions src/cmap/wire_protocol/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { MongoUnexpectedServerResponseError } from '../../error';
import { type ClusterTime } from '../../sdam/common';
import { decorateDecryptionResult, ns } from '../../utils';
import { OnDemandDocument } from './on_demand/document';
import { type JSTypeOf, OnDemandDocument } from './on_demand/document';

// eslint-disable-next-line no-restricted-syntax
const enum BSONElementOffset {
Expand Down Expand Up @@ -74,6 +74,29 @@ export class MongoDBResponse extends OnDemandDocument {
*/
encryptedResponse?: MongoDBResponse;

// Wrap error thrown from BSON
public override get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required?: false | undefined
): JSTypeOf[T] | null;
public override get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required: true
): JSTypeOf[T];
public override get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required?: boolean | undefined
): JSTypeOf[T] | null {
try {
return super.get(name, as, required);
} catch (cause) {
throw new MongoUnexpectedServerResponseError(cause.message, { cause });
}
}

static is(value: unknown): value is MongoDBResponse {
return value instanceof MongoDBResponse;
}
Expand Down Expand Up @@ -171,19 +194,6 @@ export class MongoDBResponse extends OnDemandDocument {
}
}

// Here's a little blast from the past.
// OLD style method definition so that I can override get without redefining ALL the fancy TS :/
// TODO there must be a better way...
Object.defineProperty(MongoDBResponse.prototype, 'get', {
value: function get(name: any, as: any, required: any) {
try {
return OnDemandDocument.prototype.get.call(this, name, as, required);
} catch (cause) {
throw new MongoUnexpectedServerResponseError(cause.message, { cause });
}
}
});

/** @internal */
export class CursorResponse extends MongoDBResponse {
/**
Expand Down