Search
K
Links

Is Object, a MemberDef or a Schema?

An object can be represented as a MemberDef or a Schema. Object as a MemberDef can be easily differentiated from Object as a schema using some rules expressed in the flowchart below.

When the first value is a datatype

If the first value in the object is a string and valid datatype such as number, string, object, bool, etc. then the object is a MemberDef. In the following example, the name is a MemberDef, because it defines the string value.
Example
name: { string, maxLen:100 } # MemberDef

When the first value is an object

If the first value in the object is an object then it is a MemberDef. In the following example, testValue is a MemberDef, as it defines the object as its first value.
Example
testValues: { {a?, b?,}, default:{ } } # MemberDef

If the first value is an array

If the first value in the object is an array then it is a MemberDef. In the following example, rollNumber is a MemberDef, as it defines an array of an integer as its first value.
Example
rollNumber: { [int], default:[ ] } # MemberDef

If the first value is a type

If the first value in the object is a type then it is MemberDef. In the following example, testScore is a MemberDef, as it defines the type of object.
Example
testScore: { type: int, min: 0 } # MemberDef

If the object contains schema

If the object contains schema then it is a MemberDef. In the following example, testData is a MemberDef, because it contains schema.
Example
testData: { default: { }, schema: {a, b, c} } # MemberDef

If the schema is set to an array in the object

If the schema inside the object is set to an array then it is a MemberDef. In the following example, subjectMarks is a MemberDef, because it contains the schema of an array.
Example
subjectMarks: { default: { }, schema: [int] } # MemberDef

If the object does not fall under any conditions given above

If the object does not fall under any of the above conditions then it is not a MemberDef. It is a schema of an object. The following example represents the object schema.
Example
name, age, address, isActive, remark # schema of an object