MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / isPrimaryKey

Method isPrimaryKey

packages/core/src/utils/Utils.ts:424–444  ·  view source on GitHub ↗

* Checks whether the argument looks like primary key (string, number or ObjectId).

(key: any, allowComposite = false)

Source from the content-addressed store, hash-verified

422 * Checks whether the argument looks like primary key (string, number or ObjectId).
423 */
424 static isPrimaryKey<T>(key: any, allowComposite = false): key is Primary<T> {
425 if (['string', 'number', 'bigint'].includes(typeof key)) {
426 return true;
427 }
428
429 if (allowComposite && Array.isArray(key) && key.every(v => Utils.isPrimaryKey(v, true))) {
430 return true;
431 }
432
433 if (Utils.isObject(key)) {
434 if (key.constructor?.name === 'ObjectId') {
435 return true;
436 }
437
438 if (!Utils.isPlainObject(key) && !Utils.isEntity(key, true)) {
439 return true;
440 }
441 }
442
443 return false;
444 }
445
446 /**
447 * Extracts primary key from `data`. Accepts objects or primary keys directly.

Callers 15

findOneMethod · 0.80
nativeCloneMethod · 0.80
nativeUpdateMethod · 0.80
nativeDeleteMethod · 0.80
nativeUpdateFunction · 0.80
nativeDeleteFunction · 0.80
shouldInlineMethod · 0.80
autoJoinMethod · 0.80
shouldRenameMethod · 0.80
isPivotJoinMethod · 0.80
createNodeMethod · 0.80

Calls 3

isObjectMethod · 0.80
isPlainObjectMethod · 0.80
isEntityMethod · 0.45

Tested by

no test coverage detected