Vesta Core Libraries
List of libraries [Alphabetically]
Condition
Low level condition for Vql
[It is much easier to use Hlc
-more on that later].
Culture
Providing support for i18n, i10n.
You may build your own culture by providing 3 arguments:
locale
: An object that provides the cultural information and is of type ILocale
vocabs
: An object that the keys are the words to be translated and the values are the translation of keys
dateTime
: A class that provides support for locale dateTime and extends the DateTime
class
After proving these arguments you may register your locale like this:
import { Culture } from "@vesta/core";
Culture.register(myLocal, myVocabs, MyDateTime);
In case of multiple culture the first culture is considered to be the default culture. You may change the default culture using Culture.setDefault(cultureCode);
In any part of your application you may access these parameters by the following static methods:
const locale = Culture.getLocale(localeCode);
const dateTime = Culture.getDateTimeInstance(localeCode);
const vocabs = Culture.getDictionary(localeCode);
Database
DateTime
abstract DateTime
class that any localized DateTime must extend
Dictionary
dictionary is the storage of key: translation
and some methods for finding vocabs and extending the translations. keys are NOT case-sensitive.
import { Dictionary } from "@vesta/core";
const dictionary = new Dictionary();
dictionary.inject(myVocabs);
var translation = dictionary.lookup(myKey);
Culture
uses this class for handling vocabs. You may access the Dictionary
object by Dictionary.getDictionary
method;
Err
Provides a class for customr Error
s since the default class has some limitations.
To create new Err
you may use Err.Code.*
to clarify error types.
The following errors are two most used errors so we encapsulate them into new Err
classes [extends Err
]:
DatabaseError
ValidationError
Field
Hlc (High Level Condition)
Using this class you may create any kind of -even very complex- conditions which is used by Vql
to build a query.
import { Condition, Hlc as C, Vql } from "@vesta/core";
import { MyModel } from "./path/to/model";
const condition: Condition = C.or(
C.and(
C.eq("firstName", "lastName", true),
C.elt("age", 30)
),
C.and(
C.not(C.eq("firstName", "lastName", true)),
C.gt("age", 30)
),
);
var query = new Vql(MyModel.schema.name);
query.where(condition);
var result = await MyModel.find(query);
Mime
Querying mime/type
based on extensions.
import { Mime } from "@vesta/core";
Mime.addMime("MyExt", "MyExtMimeType");
const mimeType = Mime.find("jpg");
Model
abstract Model
class that any other models must extend. Do not create new models manually, instead use vesta
cli. Go to the root of the project directory and on command line execute vesta gen model ModelName
. The tool will ask you several questions for each fields and generates the model automatically.
This model is shared between client and server.
In model file you may provide extra meta for more customization.
Platform
Provides information about the platform at which the application is executing, e.g. Platform.isServer()
, Platform.isAndroid()
, ...
Sanitizer
Schema
Validation
Vql (Vesta Query Language)
Provides the query builder for Model
s to execute queries and retrieve records.
import { Vql } from "@vesta/core";
import { SomeModel } from "./pth/to/model";
const query = new Vql(SomeModel.schema.name);
query.select("firstField", "secondField");
query.limitTo(10);
query.fromOffset(15);
query.sortBy("firstField", true);
query.filter({firstName: "first", age: 20});
const result = SomeModel.find(query);
You may view source files for more information