* Checks whether the argument looks like primary key (string, number or ObjectId).
(key: any, allowComposite = false)
| 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. |
no test coverage detected