MCPcopy
hub / github.com/drizzle-team/drizzle-orm / is

Function is

drizzle-orm/src/entity.ts:12–42  ·  view source on GitHub ↗
(value: any, type: T)

Source from the content-addressed store, hash-verified

10 & DrizzleEntity;
11
12export function is<T extends DrizzleEntityClass<any>>(value: any, type: T): value is InstanceType<T> {
13 if (!value || typeof value !== 'object') {
14 return false;
15 }
16
17 if (value instanceof type) { // eslint-disable-line no-instanceof/no-instanceof
18 return true;
19 }
20
21 if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
22 throw new Error(
23 `Class "${
24 type.name ?? '<unknown>'
25 }" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`,
26 );
27 }
28
29 let cls = Object.getPrototypeOf(value).constructor;
30 if (cls) {
31 // Traverse the prototype chain to find the entityKind
32 while (cls) {
33 if (entityKind in cls && cls[entityKind] === type[entityKind]) {
34 return true;
35 }
36
37 cls = Object.getPrototypeOf(cls);
38 }
39 }
40
41 return false;
42}

Callers 15

onMutateMethod · 0.90
onMutateMethod · 0.90
testsFunction · 0.90
onMutateMethod · 0.90
onMutateMethod · 0.90
gel.test.tsFile · 0.90
bun-sql.test.tsFile · 0.90
onMutateMethod · 0.90
handleColumnsFunction · 0.90
handleColumnsFunction · 0.90
seedFuncFunction · 0.90
resetFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected