Skip to content

Commit 9272b7a

Browse files
committed
chore: update operation types
1 parent 7d50499 commit 9272b7a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/operations/client_bulk_write/command_builder.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export class ClientBulkWriteCommandBuilder {
6060
const namespaces = new Map<string, number>();
6161
for (const model of this.models) {
6262
const ns = model.namespace;
63-
if (namespaces.has(ns)) {
64-
operations.push(buildOperation(model, namespaces.get(ns) as number));
63+
const index = namespaces.get(ns);
64+
if (index != null) {
65+
operations.push(buildOperation(model, index));
6566
} else {
6667
namespaces.set(ns, currentNamespaceIndex);
6768
operations.push(buildOperation(model, currentNamespaceIndex));
@@ -92,7 +93,7 @@ export class ClientBulkWriteCommandBuilder {
9293
}
9394

9495
/** @internal */
95-
export interface InsertOperation<TSchema extends Document = Document> {
96+
interface ClientInsertOperation<TSchema extends Document = Document> {
9697
insert: number;
9798
document: OptionalId<TSchema>;
9899
}
@@ -103,16 +104,19 @@ export interface InsertOperation<TSchema extends Document = Document> {
103104
* @param index - The namespace index.
104105
* @returns the operation.
105106
*/
106-
export const buildInsertOneOperation = (model: ClientInsertOneModel, index: number): Document => {
107-
const document: InsertOperation = {
107+
export const buildInsertOneOperation = (
108+
model: ClientInsertOneModel,
109+
index: number
110+
): ClientInsertOperation => {
111+
const document: ClientInsertOperation = {
108112
insert: index,
109113
document: model.document
110114
};
111115
return document;
112116
};
113117

114118
/** @internal */
115-
export interface DeleteOperation<TSchema extends Document = Document> {
119+
export interface ClientDeleteOperation<TSchema extends Document = Document> {
116120
delete: number;
117121
multi: boolean;
118122
filter: Filter<TSchema>;
@@ -147,8 +151,8 @@ function createDeleteOperation(
147151
model: ClientDeleteOneModel | ClientDeleteManyModel,
148152
index: number,
149153
multi: boolean
150-
): DeleteOperation {
151-
const document: DeleteOperation = {
154+
): ClientDeleteOperation {
155+
const document: ClientDeleteOperation = {
152156
delete: index,
153157
multi: multi,
154158
filter: model.filter
@@ -163,7 +167,7 @@ function createDeleteOperation(
163167
}
164168

165169
/** @internal */
166-
export interface UpdateOperation<TSchema extends Document = Document> {
170+
export interface ClientUpdateOperation<TSchema extends Document = Document> {
167171
update: number;
168172
multi: boolean;
169173
filter: Filter<TSchema>;
@@ -182,7 +186,7 @@ export interface UpdateOperation<TSchema extends Document = Document> {
182186
export const buildUpdateOneOperation = (
183187
model: ClientUpdateOneModel,
184188
index: number
185-
): UpdateOperation => {
189+
): ClientUpdateOperation => {
186190
return createUpdateOperation(model, index, false);
187191
};
188192

@@ -195,7 +199,7 @@ export const buildUpdateOneOperation = (
195199
export const buildUpdateManyOperation = (
196200
model: ClientUpdateManyModel,
197201
index: number
198-
): UpdateOperation => {
202+
): ClientUpdateOperation => {
199203
return createUpdateOperation(model, index, true);
200204
};
201205

@@ -206,8 +210,8 @@ function createUpdateOperation(
206210
model: ClientUpdateOneModel | ClientUpdateManyModel,
207211
index: number,
208212
multi: boolean
209-
): UpdateOperation {
210-
const document: UpdateOperation = {
213+
): ClientUpdateOperation {
214+
const document: ClientUpdateOperation = {
211215
update: index,
212216
multi: multi,
213217
filter: model.filter,
@@ -226,7 +230,7 @@ function createUpdateOperation(
226230
}
227231

228232
/** @internal */
229-
export interface ReplaceOneOperation<TSchema extends Document = Document> {
233+
export interface ClientReplaceOneOperation<TSchema extends Document = Document> {
230234
update: number;
231235
multi: boolean;
232236
filter: Filter<TSchema>;
@@ -244,8 +248,8 @@ export interface ReplaceOneOperation<TSchema extends Document = Document> {
244248
export const buildReplaceOneOperation = (
245249
model: ClientReplaceOneModel,
246250
index: number
247-
): ReplaceOneOperation => {
248-
const document: ReplaceOneOperation = {
251+
): ClientReplaceOneOperation => {
252+
const document: ClientReplaceOneOperation = {
249253
update: index,
250254
multi: false,
251255
filter: model.filter,

0 commit comments

Comments
 (0)