Documentation / @warp-drive/schema-record / SchemaService
Class: SchemaService
Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:226
A SchemaService designed to work with dynamically registered schemas.
Implements
Constructors
Constructor
new SchemaService(): SchemaService;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:241
Returns
SchemaService
Methods
attributesDefinitionFor()
attributesDefinitionFor(identifier): Record<string, LegacyAttributeField>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:228
DEPRECATED - use fields instead
Returns definitions for all properties of the specified resource that are considered "attributes". Generally these are properties that are not related to book-keeping state on the client and do not represent a linkage to another resource.
The return value should be a dictionary of key:value pairs where the key is the attribute or property's name and value is an object with at least the property name which should also match key.
Optionally, this object may also specify type, which should be a string reference to a transform, and options which should be dictionary in which any key:value pairs are permissable.
For instance, when using @warp-drive/legacy/model, the following attribute definition:
class extends Model {
@attr('string', { defaultValue: 'hello' }) greeting;
@attr('date') birthday;
@attr firstName;
}Would be returned as:
{
greeting: { name: 'greeting', type: 'string', options: { defaultValue: 'hello' } },
birthday: { name: 'birthday', type: 'date' },
firstName: { name: 'firstName' }
}Parameters
identifier
type
string
Returns
Record<string, LegacyAttributeField>
Deprecated
- use fields
cacheFields()
cacheFields(__namedParameters): Map<string,
| LegacyAttributeField
| LegacyBelongsToField
| LegacyHasManyField
| LinksModeBelongsToField
| LinksModeHasManyField
| GenericField
| ObjectField
| ArrayField
| SchemaObjectField
| SchemaArrayField
| ResourceField
| CollectionField>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:319
Queries for the fields of a given resource type or resource identity.
Should error if the resource type is not recognized.
Parameters
__namedParameters
type
string
Returns
Map<string, | LegacyAttributeField | LegacyBelongsToField | LegacyHasManyField | LinksModeBelongsToField | LinksModeHasManyField | GenericField | ObjectField | ArrayField | SchemaObjectField | SchemaArrayField | ResourceField | CollectionField>
CAUTION_MEGA_DANGER_ZONE_arrayExtensions()
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field):
| null
| Map<string | symbol, ExtensionDef>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:304
Retrieve the extension map for an array field
Parameters
field
ExtensibleField
Returns
| null | Map<string | symbol, ExtensionDef>
CAUTION_MEGA_DANGER_ZONE_hasExtension()
CAUTION_MEGA_DANGER_ZONE_hasExtension(ext): boolean;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:305
Check if a specific extension has been registered previously
Parameters
ext
kind
"object" | "array"
name
string
Returns
boolean
CAUTION_MEGA_DANGER_ZONE_objectExtensions()
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field, resolvedType):
| null
| Map<string | symbol, ExtensionDef>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:303
Retrieve the extension map for an object field
Parameters
field
ExtensibleField
resolvedType
null | string
Returns
| null | Map<string | symbol, ExtensionDef>
CAUTION_MEGA_DANGER_ZONE_registerExtension()
CAUTION_MEGA_DANGER_ZONE_registerExtension(extension): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:299
Register an extension for either objects or arrays
See also CAUTION_MEGA_DANGER_ZONE_Extension
Parameters
extension
CAUTION_MEGA_DANGER_ZONE_Extension
Returns
void
CAUTION_MEGA_DANGER_ZONE_resourceExtensions()
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource):
| null
| Map<string | symbol, ExtensionDef>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:300
Retrieve the extension map for a resource
Parameters
resource
ResourceKey | { type: string; }
Returns
| null | Map<string | symbol, ExtensionDef>
derivation()
derivation(field): Derivation;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:250
Returns the derivation registered with the name provided by field.type. Validates that the field is a valid DerivedField.
Parameters
field
DerivedField | { type: string; }
Returns
doesTypeExist()
doesTypeExist(type): boolean;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:227
DEPRECATED - use hasResource instead
Queries whether the SchemaService recognizes type as a resource type
Parameters
type
string
Returns
boolean
Deprecated
- use hasResource
fields()
fields(__namedParameters): Map<string, FieldSchema>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:316
Queries for the fields of a given resource type or resource identity.
Should error if the resource type is not recognized.
Parameters
__namedParameters
type
string
Returns
Map<string, FieldSchema>
hashFn()
hashFn(field): HashFn;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:253
Returns the hash function registered with the name provided by field.type. Validates that the field is a valid HashField.
Parameters
field
HashField | { type: string; }
Returns
hasResource()
hasResource(resource): boolean;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:322
Queries whether the SchemaService recognizes type as a resource type
Parameters
resource
type
string
Returns
boolean
hasTrait()
hasTrait(type): boolean;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:243
Queries whether the SchemaService recognizes type as a resource trait
Parameters
type
string
Returns
boolean
registerDerivation()
registerDerivation<R, T, FM>(derivation): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:294
Enables registration of a derivation.
The derivation can later be retrieved by the name attached to it's [Type] property.
Type Parameters
R
R
T
T
FM
FM extends | null | ObjectValue
Parameters
derivation
Derivation<R, T, FM>
Returns
void
registerHashFn()
registerHashFn<T>(hashFn): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:315
Registers a HashFn for use with a HashField for either ObjectSchema identity or polymorphic type calculation.
Type Parameters
T
T extends object
Parameters
hashFn
HashFn<T>
Returns
void
registerResource()
registerResource(schema): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:260
Enables registration of a single Schema representing either a resource in PolarisMode or LegacyMode or an ObjectSchema representing an embedded structure in other schemas.
This can be useful for either pre-loading schema information or for registering schema information delivered by API calls or other sources just-in-time.
Parameters
schema
Returns
void
registerResources()
registerResources(schemas): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:259
Enables registration of multiple Schemas at once.
This can be useful for either pre-loading schema information or for registering schema information delivered by API calls or other sources just-in-time.
Parameters
schemas
( | ResourceSchema | ObjectSchema)[]
Returns
void
registerTrait()
registerTrait(trait): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:289
Registers a Trait for use by resource schemas.
Traits are re-usable collections of fields that can be composed to build up a resource schema. Often they represent polymorphic behaviors a resource should exhibit.
When we finalize a resource, we walk its traits and apply their fields to the resource's fields. All specified traits must be registered by this time or an error will be thrown.
Traits are applied left-to-right, with traits of traits being applied in the same way. Thus for the most part, application of traits is a post-order graph traversal problem.
A trait is only ever processed once. If multiple traits (A, B, C) have the same trait (D) as a dependency, D will be included only once when first encountered by A.
If a cycle exists such that trait A has trait B which has Trait A, trait A will be applied after trait B in production. In development a cycle error will be thrown.
Fields are finalized on a "last wins principle". Thus traits appearing higher in the tree and further to the right of a traits array take precedence, with the resource's fields always being applied last and winning out.
Parameters
trait
Returns
void
registerTransformation()
registerTransformation<T, PT>(transformation): void;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:290
Enables registration of a transformation.
The transformation can later be retrieved by the name attached to it's [Type] property.
Type Parameters
T
T extends Value = string
PT
PT = unknown
Parameters
transformation
Transformation<T, PT>
Returns
void
relationshipsDefinitionFor()
relationshipsDefinitionFor(identifier): Record<string, LegacyRelationshipField>;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:231
DEPRECATED - use fields instead
Returns definitions for all properties of the specified resource that are considered "relationships". Generally these are properties that represent a linkage to another resource.
The return value should be a dictionary of key:value pairs where the key is the relationship or property's name and value is an object with at least the following properties:
namewhich should also match thekeyused in the dictionary.kindwhich should be eitherbelongsToorhasManytypewhich should be the related resource's string "type"optionswhich should be a dictionary allowing any key but with at least the below keys present.options.asynca boolean representing whether data for this relationship is typically loaded on-demand.options.inversea string or null representing the field name / key of the corresponding relationship on the inverse resource.
Additionally the following options properties are optional. See Polymorphic Relationships
options.polymorphica boolean representing whether multiple resource types can be used to satisfy this relationship.options.asa string representing the abstract type that the concrete side of a relationship must specify when fulfilling a polymorphic inverse.
For example, the following Model using @warp-drive/legacy/model would generate this relationships definition by default:
class User extends Model {
@belongsTo('user', { async: false, inverse: null }) bestFriend;
@hasMany('user', { async: true, inverse: 'friends' }) friends;
@hasMany('pet', { async: false, polymorphic: true, inverse: 'owner' }) pets;
}Which would be returned as
{
bestFriend: {
name: 'bestFriend',
kind: 'belongsTo',
type: 'user',
options: {
async: false,
inverse: null
}
},
friends: {
name: 'friends',
kind: 'hasMany',
type: 'user',
options: {
async: true,
inverse: 'friends'
}
},
pets: {
name: 'pets',
kind: 'hasMany',
type: 'pet',
options: {
async: false,
polymorphic: true,
inverse: 'owner'
}
},
}Parameters
identifier
type
string
Returns
Record<string, LegacyRelationshipField>
Deprecated
- use fields
resource()
resource(resource):
| ResourceSchema
| ObjectSchema;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:256
Returns the schema for the provided resource type.
Parameters
resource
ResourceKey | { type: string; }
Returns
| ResourceSchema | ObjectSchema
resourceHasTrait()
resourceHasTrait(resource, trait): boolean;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:244
Queries whether the given resource has the given trait
Parameters
resource
ResourceKey | { type: string; }
trait
string
Returns
boolean
resourceTypes()
resourceTypes(): readonly string[];Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:242
Returns all known resource types
Returns
readonly string[]
transformation()
transformation(field): Transformation;Defined in: warp-drive-packages/core/declarations/reactive/-private/schema.d.ts:247
Returns the transformation registered with the name provided by field.type. Validates that the field is a valid transformable.
Parameters
field
GenericField | ObjectField | ArrayField | { type: string; }