if (!Sealious.ChipManager.chip_exists("field_type", this.type_name)) {
- throw new Sealious.Errors.DeveloperError("In declaration of resource type '" + resource_type.name +"': unknown field type '"+this.type_name+"' in field '"+this.name+"'.");
+ throw new Sealious.Errors.DeveloperError("In declaration of resource type '" + resource_type.name + "': unknown field type '" + this.type_name + "' in field '" + this.name + "'.");
//with_validator:boolean - whether to include validator function in field description. Warning! If set to true, the output is not serializable in JSON.
var ResourceTypeField = require("./resource-type-field.js");
/**
ResourceType constructor
@constructor
@params {object} declaration
Resource-type declaration syntax:
{
name: String,
fields: Array<FieldDescription>,
access_strategy?: AccessStrategyDescription
}
* name, required - the name of the resource-type. It becomes the name of the chip representing the resource type, as well. It has to be unique amongst all other resource-types.
* fields, required - an array of field descriptions. You can read about field description syntax below.
* access_strategy, optional. A hashmap or string compatible with access strategy description syntax, described below. Defaults to public.
*/
var ResourceType = function(declaration){
if (typeof declaration !== "object"){
throw new Sealious.Errors.DeveloperError("Tried to create a resource-type without a declaration");
@param {object} field_declaration - consistnent with field declaration syntax
{
name: String,
type: FieldTypeName,
human_readable_name?: String,
params?: Object
}
* name, required - a string representing the machine-readable name for the field. Should be short. No spaces allowed. All lower-case letters, the _ and - symbols are allowed.
* human_readable_name, optional - a string representing a human-readable version of the field’s name. No restrictions on what is and what is not allowed here. When not specified, the value of ‘name’ attribute is used instead.
* type, required - a string representing a resource-type name that is already registred in your Sealious application.
* params, optional - a hashmap of parameters that will be passed to the field-type. These parameters are also a part of the field’s signature. Defaults to {}.
@returns void
*/
this.add_field = function(field_declaration){
var field_object = new ResourceTypeField(field_declaration, this);
var field_name = field_object.name;
if (!this.fields[field_name]) {
this.fields[field_name] = field_object;
}
else {
- throw new Sealious.Errors.DeveloperError("Duplicate field names: '" + field_name + "' in resource: '" + this.name +"'" );
+ throw new Sealious.Errors.DeveloperError("Duplicate field names: '" + field_name + "' in resource: '" + this.name + "'" );
}
}
/*
Adds multiple fields to resource type
@param {array} field_declarations_array - array of declarations consistnent with field declaration syntax
if (this.fields[field_name].has_previous_value_sensitive_methods()){
return true;
}
}
return false;
}
/*
Checks if all values from given array are represented as fields resource type
@params {array} values - array of names of fields, which resource type should have
@returns {hashmap} validation_errors - hashmap of errors, if there was an unknown field there would be entry under key "missing_field_name" with value "unknown_field"
//with_validators:boolean - whether to include validator functions in field descriptions. Warning! If set to true, the output is not serializable in JSON.
var resource_type_specification = {};
for (var field_name in this.fields){
var field_specification = this.fields[field_name].get_specification(with_validators);