Skip to content

Commit f613ca7

Browse files
remove array overloads of maybeAddObjectId
1 parent 18d6c8f commit f613ca7

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

src/operations/insert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export interface InsertOneResult<TSchema = Document> {
7171

7272
export class InsertOneOperation extends InsertOperation {
7373
constructor(collection: Collection, doc: Document, options: InsertOneOptions) {
74-
super(collection.s.namespace, maybeAddIdToDocuments(collection, [doc], options), options);
74+
super(collection.s.namespace, [maybeAddIdToDocuments(collection, doc, options)], options);
7575
}
7676

7777
override async execute(

src/utils.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,38 +1357,23 @@ export async function once<T>(ee: EventEmitter, name: string, options?: Abortabl
13571357
}
13581358

13591359
export function maybeAddIdToDocuments(
1360-
coll: Collection,
1361-
docs: Document[],
1360+
collection: Collection,
1361+
document: Document,
13621362
options: { forceServerObjectId?: boolean }
1363-
): Document[];
1364-
export function maybeAddIdToDocuments(
1365-
coll: Collection,
1366-
docs: Document,
1367-
options: { forceServerObjectId?: boolean }
1368-
): Document;
1369-
export function maybeAddIdToDocuments(
1370-
coll: Collection,
1371-
docOrDocs: Document[] | Document,
1372-
options: { forceServerObjectId?: boolean }
1373-
): Document[] | Document {
1363+
): Document {
13741364
const forceServerObjectId =
1375-
typeof options.forceServerObjectId === 'boolean'
1376-
? options.forceServerObjectId
1377-
: coll.s.db.options?.forceServerObjectId;
1365+
options.forceServerObjectId ?? collection.s.db.options?.forceServerObjectId ?? false;
13781366

13791367
// no need to modify the docs if server sets the ObjectId
1380-
if (forceServerObjectId === true) {
1381-
return docOrDocs;
1368+
if (forceServerObjectId) {
1369+
return document;
13821370
}
13831371

1384-
const transform = (doc: Document): Document => {
1385-
if (doc._id == null) {
1386-
doc._id = coll.s.pkFactory.createPk();
1387-
}
1372+
if (document._id == null) {
1373+
document._id = collection.s.pkFactory.createPk();
1374+
}
13881375

1389-
return doc;
1390-
};
1391-
return Array.isArray(docOrDocs) ? docOrDocs.map(transform) : transform(docOrDocs);
1376+
return document;
13921377
}
13931378

13941379
export async function fileIsAccessible(fileName: string, mode?: number) {

0 commit comments

Comments
 (0)