Skip to content

Latest commit

 

History

History
571 lines (327 loc) · 12.7 KB

2-base-chips.md

File metadata and controls

571 lines (327 loc) · 12.7 KB

Base Chips

"Base chips" are chips that come bundled with Sealious and don't require separate installation.

Access Strategy Types

and

and access strategy type combines multiple access strategies into one. It resolves only if all of the access strategies provided in its params resolve, and it rejects otherwise.

Sensitivity

It is sensitive to the context and/or item- depending on the strategies in params.

Params synopsis
type and_params: Array<AccessStrategy>
Example instance declaration
["and", ["logged_in", "only_on_tuesdays"]]

logged_in

Resolves when the user_id in the provided context is set (not null), rejects otherwise.

  • Sensitivity

    It is only sensitive to the context argument.

  • Params synopsis

    This Access Strategy Type does not take any parameters.

  • Example instance declaration

    "logged_in"

noone

Always rejects.

  • Sensitivity

    sensitive to nothing. Always rejects.

  • Params synopsis

    This Access Strategy Type does not take any parameters.

  • Example instance declaration

    "noone"

not

Takes an Access Strategy as an argument. Resolves if the strategy in the params rejects. Rejects if the strategy in the params resolves.

  • Sensitivity

    It is sensitive to the context and/or item- depending on the strategy in params.

  • Params synopsis

     type not_params: AccessStrategy
     
  • Example instance declaration

    ["not", "logged_in"]
    ["not", ["and", ["logged_in", "owner"]]]

or

Similarly to the and access strategy type, this strategy type takes a list of AccessStrategies as the only parameter. It resolves iff one of the strategies on the list resolves.

  • Sensitivity

    It is sensitive to the context and/or item- depending on the strategies in params.

  • Params synopsis

     type or_params: Array<AccessStrategy>
     
  • Example instance declaration

    ["or", ["owner", "admin"]]

owner

Resolves only if the user_id in the provided context matches the user_id in the created_context attribute of the given item.

  • Sensitivity

    It is sensitive to the context and to the item arguments.

  • Params synopsis

    This Access Strategy Type does not take any parameters.

  • Example instance declaration

    "owner"

public

Always resolves.

  • Sensitivity

    Sensitive to nothing. Resolves for any given arguments.

  • Params synopsis

    This Access Strategy Type does not take any parameters.

  • Example instance declaration

    "public"

super

Resolves only if the provided Context is an instance of SuperContext.

  • Sensitivity

    It is sensitive to the context argument only.

  • Params synopsis

    This Access Strategy Type does not take any parameters.

  • Example instance declaration

    "super"

themselves

Resolves only if the user_id in the context argument matches the id attribute of the item argument.

Useful for creating access strategies for the User Collection.

  • Sensitivity

    It is sensitive to the context and to the item arguments.

  • Params synopsis

    This Access Strategy Type does not take any parameters.

  • Example instance declaration

    "themselves"

Field Types

boolean

Stores a true/false value.

  • acceptable values:

    This field type tries really hard to understand vast amount of ways one can want to represent a boolean value, including:

    • a boolean value: true, false;
    • a string: "1", "0", "true", "false", "True", "False";
    • a number: 1, 0.
  • sensitivity

    This field type is only sensitive to the provided value.

  • storage format

    Whatever the input value, the value stored in the database is going to be a Boolean.

color

Stores a color value

  • acceptable values:

    This field will accept any format that's acceptable in CSS, including:

    • rgb: rgb(255, 255, 255);
    • hsl: hsl(0, 0%, 100%);
    • hex: #fffff.
  • sensitivity

    This field type is only sensitive to the provided value.

  • storage format

    The colors are stored in the database as strings containing hex color representation.

context

Stores a context. Used internally to store the context of the last login of a particular user.

  • acceptable values:

    This field will only accept objects that are an instance of Context

  • sensitivity

    This field type is only sensitive to the provided context.

  • storage format:

    Values for this field type will be stored as an object.

date

Used for storing dates, without information on time of day. See also: datetime.

  • acceptable values:

    Accepts all dates in ISO standard 8601, that is: YYYY-MM-DD.

    Examples:

    • "2016-07-04"
    • "1999-12-31"
  • sensitivity

    This field type is only sensitive to the provided value.

  • storage format:

    The values are stored verbatim as strings

datetime

Stores timestamps in the form of milliseconds passed since the [Epoch](since UNIX Epoch). This time format was chosen to mitigate timezone issues.

  • acceptable values:

    Any (positive or negative) Number value is accepted.

    Examples:

    • 1467645583744 represents 2016-07-04T15:19:43.744Z
    • 0 represents 1970-01-01T00:00:00.000Z
    • -1467645583744 represents 1923-06-30T08:40:16.256Z
  • sensitivity

    This field type is only sensitive to the provided value.

  • storage format

    Values for this field type are kept verbatim as numbers in the datastore.

email

Stores a proper email address.

  • acceptable values:

    Accepts email addresses that match the following regular expression:

     /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

    Example:

  • sensitivity

    This field type is only sensitive to the provided value.

  • storage format

    Values for this field type are kept verbatim as strings.

file

Stores a binary file.

Note: the files are stored in the uploaded_files directory, located next to your app's index.js file.

  • acceptable values

    This field accepts:

    • objects that are an instance of Sealious.File and
    • strings that are HTTP URLs to an accessible file

    as it's value parameter.

    Here's an example on how to create a Sealious.File instance:

     var context = new Sealious.Context();
     var buffer = fs.readFile("photo.jpg");
     var file = new Sealious.File(context, "photo.jpg", buffer);
  • sensitivity

    This field-type's behavior depends only on the provided values.

  • storage format

    The uploaded files are stored in the uploaded_files directory, located next to your app's index.js file. The files have randomly generated names, and have no extension.

    In the datastore they are represented as entries taking the form of:

     {
     	"id": "the_random_id",
     	"filename": "the_original_filename"
     }

float

Stores any real number.

  • acceptable values:

    Accepts any number. Interprets . as the decimal separator.

    Examples:

    • 2,
    • 3.141592654,
    • -35432432132124123
  • sensitivity

    This field type's behavior depends only on the provided values.

  • storage format

    The values are stored in the datastore as verbatim real numbers (floats).

hashed-text

Extends the text field-type. Takes any text, and if it meets the criteria specified in the field's params, hashes it with the RFC 2898-recommended PBKDF2 algorithm.

  • params synopsis

     type hashed_text_params: {
     	required_digits?: Number,
     	required_capitals?: Number, 
     	hide_hash?: Boolean
    
    • required_digits: optional. If specified, the value will not be accepted if it doesn't contain at least that many digits.
    • required_capitals: optional. If specified, the value will not be accepted if it doesn't contain at least that many capitals.
    • hide_hash: optional. If set to true, the hash value will be hidden (the value for the field will be null). Useful for password fields.

    Also, all of the params from the text field-type apply.

  • acceptable values

    Any string that matches the requirements specified in the params.

  • storage format

    The values are stored as a string containing the PBKDF2 hash of the input. There's no practical way to get back the original input.

int

Accepts only integer numbers (positive or negative).

  • sensitivity

    Sensitive only to the provided value.

  • params synopsis

    This field type does not take any params.

  • acceptable values

    Any integer number, or a string representation of an integer number.

    Examples:

    • 1, 11, 123
    • -2, 0;

    Will not accept non-integer numbers.

  • storage format

    The values are stored verbatim as Numbers in the datastore.

  • filter format

      int_filter: Number | Range;
      

single_reference

Can reference any other resource.

  • params synopsis

     type single_reference_params: {
     	collection: CollectionDeclaration
     }
    • collection: required. Only references to resources of that particular type will be accepted.
  • sensitivity

    The behavior of this resource type depends on context, params and value.

  • acceptable values

    Accepts only IDs of existing resources of the type specified in the params.

    Example: qytmp7waxm

  • storage format

    The input values are stored as strings containing the referenced resource's ID.

text

Used for storing text.

  • params synopsis

     type text_params: {
     	max_length?: Number,
     	min_length?: Number,
     	include_in_search?: Boolean,
     }
    

    Explanation:

    • max_length: optional. If specified, all text with char count higher than that will be rejected with an appropriate error message.
    • min_length: optional. If specified, all text with char count lower than that will be rejected with an appropriate error message.
    • full_text_search: optional. Defaults to false. If set to true, the datastore will be instructed to create a full-text index on contents of the field.
  • sensitivity

    The behavior of this field type depends on provided value and params.

  • acceptable values

    Will accept all strings that meets the criteria contained in params.

  • storage format

    The text will be stored as an object with two properties:

    • original: the original string, as input by the user;
    • safe: a html-safe version of the user input;

username

Extends the text field-type.

  • acceptable values

    Accepts only strings that are not already used as a username, and which are neither of: "me", "myself", "current".

  • Sensitivity

    Things that can influence the behavior of fields of this type:

    • value
    • the state of the datastore (existing usernames)
    • params
  • params synopsis

    See params for the text field type.

  • storage format

    See: text field type.

html

Extends the text field-type.

  • acceptable values

    Accepts all text values that would be accepted by field-type-text with the same restrictions in params.

  • Sensitivity

    Things that can influence the behavior of fields of this type:

    • value
    • params
  • params synopsis

    See params for the text field type.

  • storage format

    Similar to text field type, but the 'safe' value is additionally deprived of any xss code.

Resource Types

User

The default field in the User resource type are:

By default, anyone can register (create a user), but only the user itself can edit or delete the account.

Misc

Range

Ranges are used to specify a range of numbers. Synnopsis:

type Range{
	'<' | 'lt'?: Number,
	'>' | 'gt'?: Number,
	'<=' | '=<' | 'lte'?: Number,
	'>=' | '=>' | 'gte'?: Number,
}

Examples:

  • {'>': 100} - a number greater than 100
  • {'>': 100, '<=': 200} - a number greater than 100, but smaller than or equal to 200