Namespace: $k

$k

The i-views namespace

Classes

AbstractEditorConfiguration
AbstractTextDocument
Action
ActionResponse
AlternativeGroupCondition
ApplicationConfiguration
Attribute
AttributeType
AttributeValueCondition
AutoFlushingTextDocument
Blob
Cause
Choice
ChoiceRange
Color
Cookie
Copier
Date
DateTime
Domain
ElementsCondition
FlexDateTime
Folder
FolderElement
GeoPosition
GeoRange
GraphConfiguration
HasAttributeCondition
HasPropertyCondition
HasRelationCondition
HistoryChangeLogEntry
Hit
HttpConnection
HttpRequest
HttpResponse
Instance
InstanceType
Interaction
Interval
IntervalRange
JSONRenderContext
JWT
KScriptDocument
LinkedQueryCondition
MailMessage
Mapping
Mustache
Mustache
NetEntity
NewCookie
NullDocument
OAuth
Operator
PersistentCollection
Property
PropertyFilter
PropertySourceCondition
PropertyType
Query
QueryParameter
QueryReference
RDFExporter
RDFImporter
Relation
RelationTargetCondition
RelationType
ScriptJob
SemanticCollection
SemanticElement
Session
StructuredQuery
TableConfiguration
Tag
TaggingConfiguration
TaggingContext
TagTypeConfiguration
TextDocument
Time
Type
UI
User
ValueRange
ValueString
View
ViewConfiguration
XMLWriter
Zip
ZipContainer
ZipDirectory

Namespaces

exception
History
Registry

Members

static$k.LOG_DEBUG

Log level [DEBUG]

static$k.LOG_ERROR

Log level [ERROR]

static$k.LOG_NORMAL

Normal log level

static$k.LOG_WARNING

Log level [WARNING]

Returns the document that represents the output stream of some script environments.
The kind of object depends on the environment, but is usually an instance of $k.TextDocument.

See:
Example

$k.out.print("Name: ", this.name());

Methods

static$k.abortTransaction()

Aborts the current transaction. All changes will be rolled back. Has no effect if not transaction is active.
No error is thrown.


If the transaction function was called with a reject function,
then this function is called before rolling back the transaction.

Since:
  • 5.1.1

static$k.checkAccessRight(context) : boolean

Check access right

Name Type Description
context object

List of possible operation types: createAttribute { attributeType, element }, createCompleteRelation { relationType, sourceElement, targetElement }, createConcept { superType }, createInstance { type }, createRelation { relationType, sourceElement, targetElement }, delete { element }, deleteAttribute { attribute, element }, deleteConcept { element }, deleteExtension { element, object }, deleteInstance { element }, deleteRelation { relation, element }, modify { element }, modifyAttributeValue { attribute, element }, modifySchema { element }, read { element }, readAttribute { attribute, element }, readConcept { type }, readExtension { element }, readInstance { object }, readObjectsOfType { type }, optional can additionally set the user, e.g. $k.checkAccessRight("read", { "user" : , "element" : })

Throws:
Type Description
$k.exception.TypeError

Unknown operation type

$k.exception.TypeError

Context is missing

Returns:
Type Description
boolean The decision

static$k.define(id, dependencies, factory)

Defines a module

Name Type Description
id string optional

Optional module ID

dependencies Array.<string>

IDs of required modules

factory

Factory that returns the value of the module

static$k.elevatedDo(f)

Evaluates the function in an evelated context that does not check any access right. This function is only allowed in scripts that are controlled by administrators, otherwise an error is thrown

Name Type Description
f function

Function that should be evaluated in a system context

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.AccessDenied

If an elevated context cannot be activated, e.g. in a script created by a user without administration rights

Returns:
The return value of the function

static$k.filterWithAccessRights(operationType, elements, context, decision) : Array.<$k.SemanticElement>

Filter semantic elements in array with access rights

Name Type Description
operationType string

List of possible operation types: delete, deleteConcept, deleteInstance, modify, modifySchema, read, readExtension, readInstance

elements Array.<$k.SemanticElement>
context object optional
decision object optional

Default is true

Throws:
Type Description
$k.exception.TypeError

Unknown operation type

$k.exception.TypeError

Only semantic elements in array can be processed

Returns:
Type Description
Array.<$k.SemanticElement> Returns the filtered semantic elements

static$k.getClientContext(key)

Returns an object from the application client context. The application client context can be used to cache / transfer values across scripts.
Use getTransactionContext(key) if possible.
WARNING: do not use this function in REST scripts, "application client" refers to the entire bridge, thus the client context is shared by all users.
The client context is resetted if

  • the client reconnects
  • client caches are flushed
Name Type Description
key string

Key of the object

Since:
  • 4.1.1
Returns:
The object with the given key

static$k.getTransactionContext(key)

Returns an object from the transaction context. The client context can be used to cache / transfer values across scripts within the transaction.

Name Type Description
key string

Key of the object

Since:
  • 4.1.1
Throws:
Type Description
$k.exception.TransactionError

If no transaction is active

Returns:
The object with the given key

static$k.isDebugEnabled() : boolean

Returns true if running in a debugger

Version:
  • Experimental feature, might be removed at any time
Since:
  • 5.1.1
Returns:
Type Description
boolean

static$k.language() : string

Returns the current language (ISO 639 2b)

Since:
  • 4.1.1
Returns:
Type Description
string Current language, eg. "eng"

static$k.languageDo(language, f)

Evaluates the function with the given language as current language

Name Type Description
language string

Language to activate. Either ISO 639-1 (2-letter code, e.g. "en") or ISO 639-2B (3-letter code, e.g. "eng")

f function

Function that should be evaluated

Since:
  • 4.1.1
Throws:
Type Description
$k.exception.InvalidLanguage

If an invalid language was specified

Returns:
The return value of the function

static$k.locale() : string

Returns the current locale

Since:
  • 4.1.1
Returns:
Type Description
string Current locale, eg. "en_US"

static$k.localeDo(locale, f)

Evaluates the function with the given locale as current locale

Name Type Description
locale string

Locale, e.g. "en_GB"

f function

Function that should be evaluated

Since:
  • 4.1.1
Throws:
Type Description
$k.exception.InvalidLanguage

If an invalid locale was specified

Returns:
The return value of the function

static$k.log(object, level, channel)

Log an object on the current log stream (if available)

Name Type Description
object

Object to log. Will be converted with toString().

level optional

Log level. Either a number or a string ("debug", "normal", "warning", "error").

channel string optional

Optional log channel.

Examples

$k.log("New instance created");

$k.log("The cake is a lie", $k.LOG_WARNING, "Portal");

static$k.logData(data, object, level, channel)

Log an object and additional structured data on the current log stream (if available)

Name Type Description
data

Additional structured data.

object

Object to log. Will be converted with toString().

level optional

Log level. Either a number or a string ("debug", "normal", "warning", "error").

channel string optional

Optional log channel.

Examples

$k.logData({"size":42}, "New instance created");

$k.logData({"companionCube":"dead"}, "The cake is a lie", $k.LOG_WARNING, "Portal");

static$k.mapInstances(internalName, proto)

Map the prototype of instances of the type with the internal name to the prototype object

Name Type Description
internalName string

Internal name of the type of instances to map

proto

Prototype object

Example

function Person() { }
Person.prototype.fullName = function() {
return this.attributeValue("familyName").toUpperCase()

    + ", " + this.attributeValue("firstName");

};
$k.mapInstances("person", Person);
var persons = $k.Registry.type("person").instances();
for (var p in persons)
$k.out.print(persons[p].fullName() + "\n");

static$k.mapModule(moduleName, registryID)

Maps a module ID to the ID of a registered script.
Allows to register scripts containing modules under a different ID

Name Type Description
moduleName string

The ID of the module

registryID string

The ID of the registered script

static$k.mapTypes(internalName, proto)

Map the prototype of types with the internal name to the prototype object

Name Type Description
internalName string

Internal name of the type to map

proto

Prototype object

static$k.module(moduleName, isLocal)

Loads a module

Name Type Description
moduleName string

The ID of the module

isLocal boolean optional

(Since 4.0.2) True if the module script should be evaluated in a local environment, false if it should be evaluated in the environment of the caller. Default is false"

Throws:
Type Description
$k.exception.ModuleError

If the module was not found or defined more than once

Returns:
The model value

static$k.noTriggersDo(f)

Evaluates the function without performing any triggers

Name Type Description
f function

Function that should be evaluated

Since:
  • 4.1.0
Returns:
The return value of the function

static$k.optimisticTransaction(f)

Evaluates the function in a transaction and returns its return value.
Does not check if the transaction has been accepted or rejected.
Allows to start a transaction within another transaction, the nested transaction will be a part of the outer transaction

Name Type Description
f function

Function that should be evaluated in a transaction

See:
Throws:
Type Description
$k.exception.TransactionError

If a read-only transaction is already active

Returns:
The return value of the function

static$k.require(dependencies, callback)

Calls a function with required modules. Passes the value of each required module

Name Type Description
dependencies Array.<string>

IDs of required modules

callback function

Callback function

Throws:
Type Description
$k.exception.ModuleError

If a required module was not found or defined more than once

Returns:
The return value of the callback function

static$k.rootType() : $k.Type

Returns the root type of the semantic network

Returns:
Type Description
$k.Type

static$k.setClientContext(key, value)

Sets an object of the application client context. The application client context can be used to cache / transfer values across scripts.
Use setTransactionContext(key, value) if possible.
WARNING: do not use this function in REST scripts, "application client" refers to the entire bridge, thus the client context is shared by all users.
The client context is resetted if

  • the client reconnects
  • client caches are flushed
Name Type Description
key string

Key of the object

value object

The object to store

Since:
  • 4.1.1

static$k.setTransactionContext(key, value)

Sets an object of the transaction context. The client context can be used to cache / transfer values across scripts within the transaction.

Name Type Description
key string

Key of the object

value object

The object to store

Since:
  • 4.1.1

static$k.shortcutRelationType() : $k.Type

Returns the parent type of all shortcut relation types

Returns:
Type Description
$k.Type

static$k.sleep(delayMillis)

Suspends the current thread for a given number of milliseconds. Note: This blocks the whole execution of the current client.

Name Type Description
delayMillis number

The number of milliseconds to wait for. The function does not sleep if +-Infinity or NaN is set.

Since:
  • 4.3.0

static$k.softwareVersion() : object

Returns the core software version

Since:
  • 4.4.0
Returns:
Type Description
object An object containing information about the core software version{major: 4, minor: 4, patch: 0, state: "Release"}

static$k.symmetricRelationProperties() : boolean

Returns true if symmetric relation properties are enabled

Returns:
Type Description
boolean

static$k.systemRelationType() : $k.Type

Returns the parent type of all system relation types

Returns:
Type Description
$k.Type

static$k.timeLimitedDo(timeout, f, timeoutFunction)

Evaluates the function, but stops execution after the specified time and evaluates the (optional) timeout function.

If the evaluated function has started a transaction, then this transaction will be rolled back. Outer transaction will not be rolled back. To avoid incomplete write operations, an exception is raised if a write transaction is active when calling this function.

Name Type Description
timeout number

Timeout in milliseconds

f function

Function that should be evaluated

timeoutFunction function optional

Function that is evaluated when a timeout occurs.

Since:
  • 4.2.0
Throws:
Type Description
$k.exception.TransactionError

If a write transaction is active

Returns:
The return value of the function, or the value of the timeout function when a timeout occurs, or undefined if no timout function is supplied
Example

$k.timeLimitedDo(1000,
function() { return $k.Registry.query("longRunningQuery").findElements() },
function() { throw "Query did not finish" }
)

static$k.topAttributeType() : $k.Type

Returns the parent type of all attribute types

Returns:
Type Description
$k.Type

static$k.topRelationType() : $k.Type

Returns the parent type of all relation types

Returns:
Type Description
$k.Type

static$k.topTypes() : Array.<$k.Type>

Returns all top types except the top attribute and relation types

Returns:
Type Description
Array.<$k.Type>

static$k.transaction(f, rejectFunction)

Evaluates the function in a transaction and returns its return value if the transaction has been accepted.
If the transaction is rejected due to concurrency conflicts, the optional reject function is performed.
This function does not allow to start a transaction within an outer transaction, use optimisticTransaction() instead.

Name Type Description
f function

Function that should be evaluated in a transaction

rejectFunction function optional

Optional function that is evaluated if the transaction is rejected.

See:
Throws:
Type Description
$k.exception.TransactionError

If another transaction is already active

Returns:
The return value of the function. If the transaction is rejected, the return value of the reject function (if defined) or undefined is returned.

static$k.transactionContext()

Returns an object that is bound to the active transaction. It can be used to cache / transfer values across scripts within the transaction.
Creates a new object if none has been set yet

Deprecated
  • Use getTransactionContext(key) and setTransactionContext(key, value)
    Throws:
    Type Description
    $k.exception.TransactionError

    If no transaction is active

    Returns:
    The context object

    static$k.user() : $k.User

    Returns the current user

    Returns:
    Type Description
    $k.User

    static$k.userDo(user, f)

    Runs the function in an context bound to the user.
    This function is only allowed in scripts that are controlled by administrators, otherwise an error is thrown.


    Access rights checking is enabled in the function, call $k.elevatedDo() to disable checks

    Name Type Description
    user $k.User

    User or user instance

    f function

    Function that should be evaluated in the user context

    Version:
    • Experimental feature, might be removed at any time
    Since:
    • 5.1.0
    Throws:
    Type Description
    $k.exception.AccessDenied

    If a user context cannot be activated, e.g. in a script created by a user without administration rights

    Returns:
    The return value of the function

    static$k.userRelationType() : $k.Type

    Returns the parent type of user-defined relation type

    Returns:
    Type Description
    $k.Type

    static$k.uuid() : string

    Generates a UUID

    Returns:
    Type Description
    string

    static$k.volume() : string

    Returns the name of the semantic network

    Returns:
    Type Description
    string