routier-collection / core/src / SchemaDefinition
Class: SchemaDefinition<T>
Defined in: core/src/schema/SchemaDefinition.ts:154
Extends
SchemaBase<T,any>
Type Parameters
T
T extends object
Constructors
Constructor
new SchemaDefinition<
T>(collectionName,schema):SchemaDefinition<T>
Defined in: core/src/schema/SchemaDefinition.ts:160
Parameters
collectionName
schema
T
Returns
SchemaDefinition<T>
Overrides
Properties
instance
instance:
T
Defined in: core/src/schema/SchemaDefinition.ts:156
Overrides
type
type:
SchemaTypes=SchemaTypes.Definition
Defined in: core/src/schema/SchemaDefinition.ts:157
Overrides
collectionName
collectionName:
CollectionName
Defined in: core/src/schema/SchemaDefinition.ts:158
modifiers
modifiers:
any
Defined in: core/src/schema/property/base/SchemaBase.ts:6
Inherited from
isNullable
isNullable:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:8
Inherited from
isUnmapped
isUnmapped:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:9
Inherited from
isOptional
isOptional:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:10
Inherited from
isKey
isKey:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:11
Inherited from
isIdentity
isIdentity:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:12
Inherited from
isReadonly
isReadonly:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:13
Inherited from
isDistinct
isDistinct:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:14
Inherited from
transform
transform:
PropertyTransform<unknown> =null
Defined in: core/src/schema/property/base/SchemaBase.ts:19
Set by .modify(x => x.transform(...)). A live reference, never stringified. null when the property is stored as it is.
Inherited from
indexes
indexes:
string[] =[]
Defined in: core/src/schema/property/base/SchemaBase.ts:20
Inherited from
fromPropertyName
fromPropertyName:
string=null
Defined in: core/src/schema/property/base/SchemaBase.ts:21
Inherited from
dimensions
dimensions:
number=null
Defined in: core/src/schema/property/base/SchemaBase.ts:35
How many numbers a vector holds. null for every other type.
Declared here rather than on SchemaVector because a modifier WRAPS rather than extends: s.vector(1536).optional() is a SchemaOptional, and anything reachable only through the original class is lost the moment a modifier is added. type survives for exactly this reason — the copy constructor below carries it — and a dimension count has to travel with it, or an optional vector reaches a backend as a vector of unknown width and cannot be given a column.
innerSchema is the cautionary example: it lives on SchemaArray alone, so a modified array arrives with no element type and clones through the slow path.
Inherited from
maxLength
maxLength:
number=null
Defined in: core/src/schema/property/base/SchemaBase.ts:50
The longest string the property is declared to hold. null for every other type, and for a string that declares nothing.
Declared here rather than on SchemaString for the same reason as dimensions above: s.string({ maxLength: 4000 }).optional() is a SchemaOptional, so anything reachable only through SchemaString is lost the moment a modifier is added.
A declaration, never a validation. Core does not check a value against it and does not truncate. The backend that can use the number does: MySQL gives the column VARCHAR(maxLength) instead of the blanket VARCHAR(255). Every other backend ignores it, because a string column that is already unbounded cannot be made more correct by knowing a bound.
Inherited from
isSearchable
isSearchable:
boolean=false
Defined in: core/src/schema/property/base/SchemaBase.ts:62
Whether this string may be tokenised into a full-text search index.
Set by .searchable(), and only ever true on a string. Eligibility, not membership: a collection that never declares .searchIndex() indexes nothing regardless.
Copied by the constructor below, so s.string().searchable().optional() stays searchable. Every flag on this class is copied for the same reason: a modifier WRAPS rather than extends, so anything the constructor forgets is silently dropped the moment a property gains one more modifier.
Inherited from
foreignKeyDefinition
foreignKeyDefinition:
ForeignKey<unknown> =null
Defined in: core/src/schema/property/base/SchemaBase.ts:64
Inherited from
SchemaBase.foreignKeyDefinition
tags
tags:
string[] =[]
Defined in: core/src/schema/property/base/SchemaBase.ts:65
Inherited from
injected
injected:
any=null
Defined in: core/src/schema/property/base/SchemaBase.ts:66
Inherited from
defaultValue
defaultValue:
DefaultValue<T> =null
Defined in: core/src/schema/property/base/SchemaBase.ts:67
Inherited from
valueSerializer
valueSerializer:
PropertySerializer<T> =null
Defined in: core/src/schema/property/base/SchemaBase.ts:68
Inherited from
valueDeserializer
valueDeserializer:
PropertyDeserializer<T> =null
Defined in: core/src/schema/property/base/SchemaBase.ts:69
Inherited from
functionBody
functionBody:
FunctionBody<any,T>
Defined in: core/src/schema/property/base/SchemaBase.ts:71
Inherited from
literals
readonlyliterals:T[] =[]
Defined in: core/src/schema/property/base/SchemaBase.ts:73
Inherited from
Accessors
~standard
Get Signature
get ~standard():
Props<InferCreateType<T>,InferType<T>>
Defined in: core/src/schema/SchemaDefinition.ts:197
Standard JSON Schema V1 implementation. Provides JSON Schema conversion for Routier schemas.
Returns
Props<InferCreateType<T>, InferType<T>>
Methods
fromJson()
staticfromJson(jsonString,collectionName?):CompiledSchema<any>
Defined in: core/src/schema/SchemaDefinition.ts:188
Creates a SchemaDefinition from a JSON string containing a JSON Schema. Parses the JSON string, rehydrates the schema structure, and compiles it.
Parameters
jsonString
string
The JSON string containing the JSON Schema (typically from schema['~standard'].jsonSchema.input() or output())
collectionName?
string
Optional collection name override (if not present in JSON Schema metadata)
Returns
CompiledSchema<any>
A compiled schema ready to use
Throws
Error if the JSON string is invalid or doesn't contain a valid JSON Schema
Example
// Serialize a schema to JSON
const jsonSchema = mySchema['~standard'].jsonSchema.input({ target: 'draft-2020-12' });
const jsonString = JSON.stringify(jsonSchema);
// Rehydrate from JSON string
const rehydratedSchema = SchemaDefinition.fromJson(jsonString);
// Schema is already compiled and ready to usemodify()
modify<
R>(builder):SchemaDefinition<R&T>
Defined in: core/src/schema/SchemaDefinition.ts:224
Type Parameters
R
R
Parameters
builder
(d) => R
Returns
SchemaDefinition<R & T>
compile()
Call Signature
compile<
TMetadata>(metadata):CompiledSchemaWithMetadata<T,TMetadata>
Defined in: core/src/schema/SchemaDefinition.ts:376
Type Parameters
TMetadata
TMetadata
Parameters
metadata
TMetadata
Returns
CompiledSchemaWithMetadata<T, TMetadata>
Call Signature
compile():
CompiledSchema<T>
Defined in: core/src/schema/SchemaDefinition.ts:377