mendixmodelsdk
Advanced tools
Comparing version 2.3.0 to 2.4.0-dev.223f367
[ | ||
{ | ||
"deltaType": "CREATE_UNIT", | ||
"unitId": "308383d0-408c-4231-8ed7-35c35c162031", | ||
"unitId": "2eb7fca3-6346-4b2d-9e14-a0f853a6e32a", | ||
"containerId": "eec3241d-13a9-4ba9-940c-5d5223624304", | ||
@@ -10,4 +10,4 @@ "containmentName": "modules", | ||
{ | ||
"unitId": "308383d0-408c-4231-8ed7-35c35c162031", | ||
"elementId": "308383d0-408c-4231-8ed7-35c35c162031", | ||
"unitId": "2eb7fca3-6346-4b2d-9e14-a0f853a6e32a", | ||
"elementId": "2eb7fca3-6346-4b2d-9e14-a0f853a6e32a", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -22,4 +22,4 @@ "propertyName": "name", | ||
"deltaType": "CREATE_UNIT", | ||
"unitId": "8aa9cb6d-36e6-4ae7-948e-9a853b0f1185", | ||
"containerId": "308383d0-408c-4231-8ed7-35c35c162031", | ||
"unitId": "517ebb5d-d18a-40b0-8f17-b8184d5ca584", | ||
"containerId": "2eb7fca3-6346-4b2d-9e14-a0f853a6e32a", | ||
"containmentName": "domainModel", | ||
@@ -30,4 +30,4 @@ "contentType": "DomainModels$DomainModel" | ||
"deltaType": "CREATE_UNIT", | ||
"unitId": "cffed51b-b38b-46b4-9fe7-74a9c332907f", | ||
"containerId": "308383d0-408c-4231-8ed7-35c35c162031", | ||
"unitId": "1323e492-d6bf-4e56-bdec-81b232eaa336", | ||
"containerId": "2eb7fca3-6346-4b2d-9e14-a0f853a6e32a", | ||
"containmentName": "folders", | ||
@@ -37,4 +37,4 @@ "contentType": "Projects$Folder" | ||
{ | ||
"unitId": "cffed51b-b38b-46b4-9fe7-74a9c332907f", | ||
"elementId": "cffed51b-b38b-46b4-9fe7-74a9c332907f", | ||
"unitId": "1323e492-d6bf-4e56-bdec-81b232eaa336", | ||
"elementId": "1323e492-d6bf-4e56-bdec-81b232eaa336", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -49,4 +49,4 @@ "propertyName": "name", | ||
"deltaType": "CREATE_UNIT", | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"containerId": "cffed51b-b38b-46b4-9fe7-74a9c332907f", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"containerId": "1323e492-d6bf-4e56-bdec-81b232eaa336", | ||
"containmentName": "documents", | ||
@@ -56,4 +56,4 @@ "contentType": "Pages$Page" | ||
{ | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -67,4 +67,4 @@ "propertyName": "canvasWidth", | ||
{ | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -78,28 +78,28 @@ "propertyName": "canvasHeight", | ||
{ | ||
"parentId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"parentId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementType": "Pages$LayoutCall", | ||
"parentPropertyName": "layoutCall", | ||
"deltaType": "CREATE_ELEMENT", | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "4a2bbec9-f25a-4053-abb4-cfd753bd56eb" | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "d22a5e15-dfdb-4ac5-88bc-8fdf008f6743" | ||
}, | ||
{ | ||
"parentId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"parentId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementType": "Texts$Text", | ||
"parentPropertyName": "title", | ||
"deltaType": "CREATE_ELEMENT", | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "7458bc5f-c13a-450f-8181-67cc1a8f7a03" | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "a0bf9f53-2d49-4359-8653-1da3081a8666" | ||
}, | ||
{ | ||
"parentId": "7458bc5f-c13a-450f-8181-67cc1a8f7a03", | ||
"parentId": "a0bf9f53-2d49-4359-8653-1da3081a8666", | ||
"elementType": "Texts$Translation", | ||
"parentPropertyName": "translations", | ||
"deltaType": "CREATE_ELEMENT", | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "7b074826-f7b0-491e-a806-9dce30532eb0" | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "d29ea4fa-1b79-4a59-a6ca-3a310a2aefb9" | ||
}, | ||
{ | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "7b074826-f7b0-491e-a806-9dce30532eb0", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "d29ea4fa-1b79-4a59-a6ca-3a310a2aefb9", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -113,4 +113,4 @@ "propertyName": "languageCode", | ||
{ | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "7b074826-f7b0-491e-a806-9dce30532eb0", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "d29ea4fa-1b79-4a59-a6ca-3a310a2aefb9", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -124,4 +124,4 @@ "propertyName": "text", | ||
{ | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -135,4 +135,4 @@ "propertyName": "popupResizable", | ||
{ | ||
"unitId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"elementId": "bdeeb434-c70f-4b61-94c2-7d7f9cd6b23f", | ||
"unitId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"elementId": "ea908362-58b7-458c-a1f5-f1339137d91a", | ||
"deltaType": "UPDATE_PROPERTY_VALUE", | ||
@@ -139,0 +139,0 @@ "propertyName": "name", |
@@ -1,115 +0,116 @@ | ||
import { IEObject } from '../sdk/checks/base-types'; | ||
export interface MxBinaryExpression extends MxExpression { | ||
left: MxExpression; | ||
operator: MxOperator; | ||
right: MxExpression; | ||
import { ITyped } from '../sdk/checks/base-types'; | ||
export declare namespace expressions { | ||
interface MxApplicableExpression extends MxExpression { | ||
appliedFeature: MxFeatureCallWrapper; | ||
} | ||
interface MxBinaryExpression extends MxExpression { | ||
left: MxExpression; | ||
operator: MxOperator; | ||
right: MxExpression; | ||
} | ||
interface MxBooleanLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: boolean; | ||
} | ||
interface MxBuiltInCall extends MxFeatureCall { | ||
variable: MxBuiltInVariableDeclaration; | ||
} | ||
interface MxBuiltInVariableDeclaration extends MxNamed { | ||
} | ||
interface MxColorLiteralExpression extends MxPrimitiveLiteralExpression { | ||
blue: number; | ||
green: number; | ||
red: number; | ||
} | ||
interface MxDoubleLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: number; | ||
} | ||
interface MxExpression extends ITyped { | ||
} | ||
interface MxFeatureCall extends ITyped { | ||
} | ||
interface MxFeatureCallWrapper extends MxApplicableExpression { | ||
featureCall: MxFeatureCall; | ||
} | ||
interface MxFollow extends MxBuiltInCall { | ||
path: MxExpression; | ||
} | ||
interface MxIntegerLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: number; | ||
} | ||
interface MxIteratorCall extends MxFeatureCall { | ||
body: MxExpression; | ||
type: MxIteratorType; | ||
variable: MxIteratorVariableDeclaration; | ||
} | ||
interface MxIteratorVariableDeclaration extends MxNamed { | ||
} | ||
interface MxListLiteralExpression extends MxLiteralExpression, MxApplicableExpression { | ||
items: MxExpression[]; | ||
} | ||
interface MxLiteralExpression extends MxExpression { | ||
} | ||
interface MxMethodCall extends MxFeatureCall { | ||
arguments: MxExpression[]; | ||
referredMethod: string; | ||
} | ||
interface MxNamed extends ITyped { | ||
name: string; | ||
} | ||
interface MxPrefixExpression extends MxExpression { | ||
expression: MxExpression; | ||
} | ||
interface MxPreviousExpression extends MxApplicableExpression { | ||
variable: MxVariableRefExpression; | ||
} | ||
interface MxPrimitiveLiteralExpression extends MxSingleLiteralExpression { | ||
} | ||
interface MxPropertyAssignment extends ITyped { | ||
property: string; | ||
value: MxExpression; | ||
} | ||
interface MxPropertyCall extends MxFeatureCall { | ||
referredProperty: string; | ||
} | ||
interface MxQualifiedEnumLiteralExpression extends MxSingleLiteralExpression { | ||
enumeration: string; | ||
literal: string; | ||
} | ||
interface MxSingleLiteralExpression extends MxLiteralExpression { | ||
} | ||
interface MxSizeLiteralExpression extends MxPrimitiveLiteralExpression { | ||
height: number; | ||
width: number; | ||
} | ||
interface MxStringLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: string; | ||
} | ||
interface MxStructureLiteralExpression extends MxSingleLiteralExpression, MxApplicableExpression { | ||
assignments: MxPropertyAssignment[]; | ||
structure: string; | ||
} | ||
interface MxSwitch extends MxBuiltInCall { | ||
cases: MxSwitchCase[]; | ||
} | ||
interface MxSwitchCase extends ITyped { | ||
condition: MxExpression; | ||
expectedType: MxTypeStructureLiteralExpression; | ||
value: MxExpression; | ||
} | ||
interface MxThisExpression extends MxApplicableExpression { | ||
} | ||
interface MxTypeLiteralExpression extends MxSingleLiteralExpression { | ||
} | ||
interface MxTypeStructureLiteralExpression extends MxTypeLiteralExpression { | ||
referredStructure: string; | ||
} | ||
interface MxUndefinedExpression extends ITyped { | ||
} | ||
interface MxVariableRefExpression extends MxApplicableExpression { | ||
referredVariable: string; | ||
} | ||
type MxCheckSeverity = "NONE" | "WARNING" | "ERROR" | "DEPRECATION" | "TODO"; | ||
type MxIteratorType = "NONE" | "MAP" | "FILTER" | "EVERY" | "SOME" | "FIND_FIRST"; | ||
type MxOperator = "NONE" | "EQUALS" | "UNEQUALS" | "GREATER" | "LESS" | "GREATER_OR_EQUALS" | "LESS_OR_EQUALS" | "AND" | "OR"; | ||
type MxPrimitiveTypeEnum = "Integer" | "String" | "Boolean" | "Double" | "DateTime" | "Guid" | "Point" | "Size" | "Color" | "Blob"; | ||
const concreteApplicableExpressionTypes: string[]; | ||
} | ||
export interface MxBooleanLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: boolean; | ||
} | ||
export interface MxBuiltInCall extends MxFeatureCall { | ||
variable: MxBuiltInVariableDeclaration; | ||
} | ||
export interface MxBuiltInVariableDeclaration extends MxNamed { | ||
} | ||
export interface MxColorLiteralExpression extends MxPrimitiveLiteralExpression { | ||
blue: number; | ||
green: number; | ||
red: number; | ||
} | ||
export interface MxDoubleLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: number; | ||
} | ||
export interface MxExpression extends IEObject { | ||
} | ||
export interface MxFeatureCall extends IEObject { | ||
} | ||
export interface MxFeatureCallWrapper extends IEObject { | ||
featureCall: MxFeatureCall; | ||
tail: MxFeatureCallWrapper; | ||
} | ||
export interface MxFollow extends MxBuiltInCall { | ||
path: MxExpression; | ||
} | ||
export interface MxIntegerLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: number; | ||
} | ||
export interface MxIteratorCall extends MxFeatureCall { | ||
body: MxExpression; | ||
type: MxIteratorType; | ||
variable: MxIteratorVariableDeclaration; | ||
} | ||
export interface MxIteratorVariableDeclaration extends MxNamed { | ||
} | ||
export interface MxListLiteralExpression extends MxLiteralExpression { | ||
items: MxExpression[]; | ||
} | ||
export interface MxLiteralExpression extends MxExpression { | ||
} | ||
export interface MxMethodCall extends MxFeatureCall { | ||
arguments: MxExpression[]; | ||
referredMethod: string; | ||
} | ||
export interface MxNamed extends IEObject { | ||
name: string; | ||
} | ||
export interface MxNavigationExpression extends MxExpression { | ||
base: MxExpression; | ||
tail: MxFeatureCallWrapper; | ||
} | ||
export interface MxPrefixExpression extends MxExpression { | ||
expression: MxExpression; | ||
} | ||
export interface MxPreviousExpression extends MxExpression { | ||
variable: MxVariableRefExpression; | ||
} | ||
export interface MxPrimitiveLiteralExpression extends MxSingleLiteralExpression { | ||
} | ||
export interface MxPropertyAssignment extends IEObject { | ||
property: string; | ||
value: MxExpression; | ||
} | ||
export interface MxPropertyCall extends MxFeatureCall { | ||
referredProperty: string; | ||
} | ||
export interface MxQualifiedEnumLiteralExpression extends MxSingleLiteralExpression { | ||
enumeration: string; | ||
literal: string; | ||
} | ||
export interface MxSingleLiteralExpression extends MxLiteralExpression { | ||
} | ||
export interface MxSizeLiteralExpression extends MxPrimitiveLiteralExpression { | ||
height: number; | ||
width: number; | ||
} | ||
export interface MxStringLiteralExpression extends MxPrimitiveLiteralExpression { | ||
value: string; | ||
} | ||
export interface MxStructureLiteralExpression extends MxSingleLiteralExpression { | ||
assignments: MxPropertyAssignment[]; | ||
structure: string; | ||
} | ||
export interface MxSwitch extends MxBuiltInCall { | ||
cases: MxSwitchCase[]; | ||
} | ||
export interface MxSwitchCase extends IEObject { | ||
condition: MxExpression; | ||
expectedType: MxTypeStructureLiteralExpression; | ||
value: MxExpression; | ||
} | ||
export interface MxThisExpression extends MxExpression { | ||
} | ||
export interface MxTypeLiteralExpression extends MxSingleLiteralExpression { | ||
} | ||
export interface MxTypeStructureLiteralExpression extends MxTypeLiteralExpression { | ||
referredStructure: string; | ||
} | ||
export interface MxUndefinedExpression extends IEObject { | ||
} | ||
export interface MxVariableRefExpression extends MxExpression { | ||
referredVariable: string; | ||
} | ||
export declare type MxCheckSeverity = "NONE" | "WARNING" | "ERROR" | "DEPRECATION" | "TODO"; | ||
export declare type MxIteratorType = "NONE" | "MAP" | "FILTER" | "EVERY" | "SOME" | "FIND_FIRST"; | ||
export declare type MxOperator = "NONE" | "EQUALS" | "UNEQUALS" | "GREATER" | "LESS" | "GREATER_OR_EQUALS" | "LESS_OR_EQUALS" | "AND" | "OR"; | ||
export declare type MxPrimitiveTypeEnum = "Integer" | "String" | "Boolean" | "Double" | "DateTime" | "Guid" | "Point" | "Size" | "Color" | "Blob"; |
"use strict"; | ||
var expressions; | ||
(function (expressions) { | ||
expressions.concreteApplicableExpressionTypes = ["MxFeatureCallWrapper", "MxListLiteralExpression", "MxPreviousExpression", "MxStructureLiteralExpression", "MxThisExpression", "MxVariableRefExpression"]; | ||
})(expressions = exports.expressions || (exports.expressions = {})); |
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2015 Arjan Blok, Erik van de Pol, Meinte Boersma, Michel Weststrate | ||
Copyright (c) 2015-2016 Arjan Blok, Meinte Boersma, Onur Gündüz, Erik van de Pol, Michel Weststrate | ||
@@ -26,10 +26,11 @@ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// [ts-npm-lint] disabled triple slash reference to '../src/typings.d.ts' | ||
import './sdk/internal'; | ||
export * from './version'; | ||
export * from './common'; | ||
export { IModel, Model, ModelSdkClient } from './mendix-model'; | ||
export * from './gen/all-model-classes'; | ||
export * from './sdk/utils'; | ||
export * from './sdk/config'; | ||
export * from './sdk/internal/properties'; | ||
export { IStructure, Structure, IList, IAbstractUnit, AbstractUnit, IAbstractElement, AbstractElement, IEnum, IElement, Element, IModelUnit, ModelUnit, ITransportation, aliases, IWorkingCopyMetaData, IWorkingCopy, IModelApiClient, IDeploymentResult, IAbstractUnitJson, IDelta, IProblem, IProblemLocation, IEditorData } from './sdk/internal'; | ||
import "./sdk/internal"; | ||
export * from "./version"; | ||
export * from "./common"; | ||
export { IModel, Model, ModelSdkClient } from "./mendix-model"; | ||
export * from "./gen/all-model-classes"; | ||
export * from "./sdk/utils"; | ||
export * from "./sdk/config"; | ||
export * from "./sdk/internal/properties"; | ||
export { IStructure, Structure, IList, IAbstractUnit, AbstractUnit, IAbstractElement, AbstractElement, IEnum, IElement, Element, IModelUnit, ModelUnit, ITransportation, aliases, IWorkingCopyMetaData, IWorkingCopy, IModelApiClient, IDeploymentResult, IAbstractUnitJson, IDelta, IProblem, IProblemLocation, IEditorData } from "./sdk/internal"; | ||
export * from "./sdk/checks/checks-index"; |
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2015 Arjan Blok, Erik van de Pol, Meinte Boersma, Michel Weststrate | ||
Copyright (c) 2015-2016 Arjan Blok, Meinte Boersma, Onur Gündüz, Erik van de Pol, Michel Weststrate | ||
@@ -30,11 +30,11 @@ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
} | ||
require('./sdk/internal'); // early import to fix circular deps and guarantee correct import order | ||
__export(require('./version')); | ||
var mendix_model_1 = require('./mendix-model'); | ||
require("./sdk/internal"); // early import to fix circular deps and guarantee correct import order | ||
__export(require("./version")); | ||
var mendix_model_1 = require("./mendix-model"); | ||
exports.Model = mendix_model_1.Model; | ||
__export(require('./gen/all-model-classes')); | ||
__export(require('./sdk/utils')); | ||
__export(require('./sdk/config')); | ||
__export(require('./sdk/internal/properties')); | ||
var internal_1 = require('./sdk/internal'); | ||
__export(require("./gen/all-model-classes")); | ||
__export(require("./sdk/utils")); | ||
__export(require("./sdk/config")); | ||
__export(require("./sdk/internal/properties")); | ||
var internal_1 = require("./sdk/internal"); | ||
exports.Structure = internal_1.Structure; | ||
@@ -46,1 +46,2 @@ exports.AbstractUnit = internal_1.AbstractUnit; | ||
exports.ModelUnit = internal_1.ModelUnit; | ||
__export(require("./sdk/checks/checks-index")); |
@@ -48,3 +48,3 @@ import * as internal from './sdk/internal'; | ||
*/ | ||
deploy(workingCopyId: string, callback: common.ICallback<IDeploymentResult>, errorCallback: common.IErrorCallback): void; | ||
deploy(workingCopyId: string, forceFullDeployment: boolean, callback: common.ICallback<IDeploymentResult>, errorCallback: common.IErrorCallback): void; | ||
/** | ||
@@ -51,0 +51,0 @@ * Retrieves status information about the working copy deployment. |
@@ -84,5 +84,5 @@ "use strict"; | ||
*/ | ||
ModelSdkClientImpl.prototype.deploy = function (workingCopyId, callback, errorCallback) { | ||
ModelSdkClientImpl.prototype.deploy = function (workingCopyId, forceFullDeployment, callback, errorCallback) { | ||
config_1.configuration.checkCallbacks(callback, errorCallback); | ||
this.client.deploy(workingCopyId, callback, errorCallback); | ||
this.client.deploy(workingCopyId, forceFullDeployment, callback, errorCallback); | ||
}; | ||
@@ -89,0 +89,0 @@ /** |
/** | ||
* Base serialization of an EObject. | ||
*/ | ||
export interface IEObject { | ||
export interface ITyped { | ||
$type: string; | ||
} |
@@ -1,3 +0,4 @@ | ||
import * as expressions from '../../gen/expressions-meta-types'; | ||
import { Structure } from '../internal/structures'; | ||
import { expressions } from "../../gen/expressions-meta-types"; | ||
import { IStructure } from "../internal/structures"; | ||
import { IQueryResolver } from "./queries"; | ||
export declare class StructureTypeLiteral { | ||
@@ -7,3 +8,3 @@ clazz: any; | ||
} | ||
export declare function evaluateExpr(expr: expressions.MxExpression, structure: Structure, queryResolver: IQueryResolver): any; | ||
export declare function evaluateExpression(expr: expressions.MxExpression, structure: IStructure, queryResolver: IQueryResolver): any; | ||
/** | ||
@@ -13,2 +14,1 @@ * Checks whether the argument is "nothing", i.e. either undefined or null. | ||
export declare function isNothing(arg: any): boolean; | ||
export declare type IQueryResolver = (queryName: string, qualifiedStructureName: string) => expressions.MxExpression; |
"use strict"; | ||
var instances_1 = require('../../sdk/internal/instances'); | ||
var structures_1 = require('../internal/structures'); | ||
var standard_library_iterators_1 = require('./standard-library-iterators'); | ||
var standard_library_methods_1 = require('./standard-library-methods'); | ||
var Closure = (function () { | ||
function Closure(parent, vars, iterationStates) { | ||
var expressions_meta_types_1 = require("../../gen/expressions-meta-types"); | ||
var instances_1 = require("../../sdk/internal/instances"); | ||
var structures_1 = require("../internal/structures"); | ||
var standard_library_iterators_1 = require("./standard-library-iterators"); | ||
var standard_library_methods_1 = require("./standard-library-methods"); | ||
var Context = (function () { | ||
function Context(parent, thisStructure, vars, iterationStates) { | ||
if (parent === void 0) { parent = null; } | ||
if (thisStructure === void 0) { thisStructure = null; } | ||
if (vars === void 0) { vars = {}; } | ||
if (iterationStates === void 0) { iterationStates = {}; } | ||
this.parent = parent; | ||
this.thisStructure = thisStructure; | ||
this.vars = vars; | ||
this.iterationStates = iterationStates; | ||
} | ||
Closure.prototype.get = function (_varName) { | ||
if (_varName in this.vars) | ||
Context.prototype.getThis = function () { | ||
if (this.thisStructure) { | ||
return this.thisStructure; | ||
} | ||
if (this.parent) { | ||
return this.parent.getThis(); | ||
} | ||
console.warn("'this' not defined"); // (happens in principle only in tests...) | ||
return undefined; | ||
}; | ||
Context.prototype.withThis = function (newThis) { | ||
var newContext = new Context(this); | ||
newContext.thisStructure = newThis; | ||
return newContext; | ||
}; | ||
Context.prototype.getValue = function (_varName) { | ||
if (_varName in this.vars) { | ||
return this.vars[_varName]; | ||
if (this.parent) | ||
return this.parent.get(_varName); | ||
} | ||
if (this.parent) { | ||
return this.parent.getValue(_varName); | ||
} | ||
throw new Error("Undefined variable: '" + _varName + "'"); | ||
}; | ||
Closure.prototype.getIterationState = function (_varName) { | ||
if (_varName in this.vars) | ||
Context.prototype.withValue = function (varName, value) { | ||
var newContext = new Context(this); | ||
newContext.vars[varName] = value; | ||
return newContext; | ||
}; | ||
Context.prototype.getIterationState = function (_varName) { | ||
if (_varName in this.vars) { | ||
return this.iterationStates[_varName]; | ||
if (this.parent) | ||
} | ||
if (this.parent) { | ||
return this.parent.getIterationState(_varName); | ||
} | ||
throw new Error("Undefined iterator argument for variable: '" + _varName + "'"); | ||
}; | ||
Closure.prototype.withValue = function (varName, value) { | ||
var newClosure = new Closure(this); | ||
newClosure.vars[varName] = value; | ||
return newClosure; | ||
Context.prototype.withIterationState = function (varName, iterationState) { | ||
var newContext = new Context(this); | ||
newContext.vars[varName] = iterationState.value(); | ||
newContext.iterationStates[varName] = iterationState; | ||
return newContext; | ||
}; | ||
Closure.prototype.withIterationState = function (varName, iterationState) { | ||
var newClosure = new Closure(this); | ||
newClosure.vars[varName] = iterationState.value(); | ||
newClosure.iterationStates[varName] = iterationState; | ||
return newClosure; | ||
}; | ||
return Closure; | ||
return Context; | ||
}()); | ||
@@ -49,35 +71,40 @@ var StructureTypeLiteral = (function () { | ||
exports.StructureTypeLiteral = StructureTypeLiteral; | ||
function evaluateExpr(expr, structure, queryResolver) { | ||
function evaluateExpression(expr, structure, queryResolver) { | ||
// share model across all helper functions (fall-backs are purely for testing...): | ||
var model = structure ? structure.model : undefined; | ||
var modelClasses = structure ? model._allModelClasses() : {}; | ||
return evalInt(expr, structure, new Closure(null, {})); | ||
function evalInt(expr_, source, variables) { | ||
return evalInt(expr, structure, new Context(null, structure, {})); | ||
// FIXME 2nd argument should be nothing but then switch doesn't work anymore... | ||
function evalInt(evaluatable, source, context) { | ||
var polyMap = { | ||
// for every non-abstract sub type of Evaluatable, provide an interpretation -- please sort by type name: | ||
"MxBinaryExpression": function (expr) { return evalBinary(expr, source, variables); }, | ||
"MxBinaryExpression": function (expr) { return evalBinary(expr, source, context); }, | ||
"MxBooleanLiteralExpression": function (expr) { return expr.value; }, | ||
"MxColorLiteralExpression": function (expr) { return { red: expr.red, green: expr.green, blue: expr.blue }; }, | ||
"MxColorLiteralExpression": function (expr) { | ||
return { red: expr.red, green: expr.green, blue: expr.blue }; | ||
}, | ||
"MxDoubleLiteralExpression": function (expr) { return expr.value; }, | ||
"MxFeatureCallWrapper": function (expr) { return evalTailable(expr.featureCall, expr.tail, source, variables); }, | ||
"MxFollow": function (expr) { return evalFollow(expr, source, variables); }, | ||
"MxFeatureCallWrapper": function (expr) { return evalInt(expr.featureCall, source, context); }, | ||
"MxFollow": function (expr) { return evalFollow(expr, source, context); }, | ||
"MxIntegerLiteralExpression": function (expr) { return expr.value; }, | ||
"MxIteratorCall": function (expr) { | ||
var iterator = standard_library_iterators_1.StandardIterators[expr.type]; | ||
if (!iterator) | ||
var iterator = standard_library_iterators_1.standardIterators[expr.type]; | ||
if (!iterator) { | ||
throw new Error("Iterator not implemented: '" + expr.type + "'"); | ||
return iterator(source, function (value, index, array) { return evalInt(expr.body, null /* could be 'source' but null seems to be more correct */, variables.withIterationState(expr.variable.name, new standard_library_iterators_1.IterationState(index, array))); }); | ||
} | ||
return iterator(source, function (value, index, array) { return evalInt(expr.body, undefined /* could be "source" but nothing seems to be more correct */, context.withIterationState(expr.variable.name, new standard_library_iterators_1.IterationState(index, array))); }); | ||
}, | ||
"MxListLiteralExpression": function (expr) { | ||
var evalItems = expr.items.map(function (item) { return evalInt(item, source, variables); }); | ||
return evalItems.some(function (evalItem) { return isNothing(evalItem); }) ? undefined : evalItems; // simple failure semantics: propagate undefined | ||
var evalItems = expr.items.map(function (item) { return evalInt(item, source, context); }); | ||
return evalItems.some(function (evalItem) { return isNothing(evalItem); }) ? undefined : evalItems; | ||
// simple failure semantics: propagate undefined | ||
}, | ||
"MxMethodCall": function (expr) { return evalMethodCall(expr, source, variables); }, | ||
// MxNavigationExpression is the "top-level" construct which has (wrapped) MxFeatureCall's nested (recursively) in its tail. | ||
"MxNavigationExpression": function (expr) { return evalTailable(expr.base, expr.tail, source, variables); }, | ||
"MxMethodCall": function (expr) { return evalMethodCall(expr, source, context); }, | ||
"MxPrefixExpression": function (expr) { | ||
var exprEval = evalInt(expr.expression, source, variables); | ||
var exprEval = evalInt(expr.expression, source, context); | ||
return isNothing(exprEval) ? exprEval : (!exprEval); // simple failure semantics: propagate undefined | ||
}, | ||
"MxPreviousExpression": function (expr) { return variables.getIterationState(expr.variable.referredVariable).previous().value(); }, | ||
"MxPreviousExpression": function (expr) { | ||
return context.getIterationState(expr.variable.referredVariable).previous().value(); | ||
}, | ||
"MxPropertyCall": function (expr) { return isNothing(source) ? undefined : source[expr.referredProperty]; }, | ||
@@ -87,5 +114,5 @@ "MxQualifiedEnumLiteralExpression": function (expr) { return evalQualifiedEnumLiteral(expr); }, | ||
"MxStringLiteralExpression": function (expr) { return expr.value; }, | ||
"MxStructureLiteralExpression": function (expr) { return evalStructureLiteral(expr, source, variables); }, | ||
"MxSwitch": function (expr) { return evalSwitch(expr, source, variables); }, | ||
"MxThisExpression": function (expr) { return structure; }, | ||
"MxStructureLiteralExpression": function (expr) { return evalStructureLiteral(expr, source, context); }, | ||
"MxSwitch": function (expr) { return evalSwitch(expr, source, context); }, | ||
"MxThisExpression": function (expr) { return context.getThis(); }, | ||
"MxTypeStructureLiteralExpression": function (expr) { | ||
@@ -95,14 +122,25 @@ return new StructureTypeLiteral(instances_1.instancehelpers.lookupClass(expr.referredStructure, modelClasses)); | ||
"MxUndefinedExpression": function (expr) { return undefined; }, | ||
"MxVariableRefExpression": function (expr) { return variables.get(expr.referredVariable); } | ||
"MxVariableRefExpression": function (expr) { return context.getValue(expr.referredVariable); } | ||
}; | ||
var evalFn = polyMap[expr_.$type]; | ||
if (!evalFn) | ||
throw new Error("unhandled expression type: " + expr_.$type); | ||
return evalFn(expr_); | ||
var evalFn = polyMap[evaluatable.$type]; | ||
if (!evalFn) { | ||
throw new Error("unhandled expression type: " + evaluatable.$type); | ||
} | ||
var baseEval = evalFn(evaluatable); | ||
var totalEval = expressions_meta_types_1.expressions.concreteApplicableExpressionTypes.indexOf(evaluatable.$type) > -1 | ||
? evalApplicable(evaluatable, baseEval, context) | ||
: baseEval; | ||
return totalEval; | ||
} | ||
function evalBinary(expr, source, variables) { | ||
if (expr.operator === "NONE") | ||
throw new Error('sentinel value of MxOperator not allowed in runtime'); | ||
var evalLeft = evalInt(expr.left, source, variables); | ||
var evalRight = evalInt(expr.right, source, variables); // (no shortcutting) | ||
function evalApplicable(expr, baseEval, context) { | ||
return !expr.appliedFeature // no check for nothingness: e.g. '.isUndefined()' can turn nothing into something | ||
? baseEval // simple failure semantics: propagate undefined | ||
: evalInt(expr.appliedFeature, baseEval, context); | ||
} | ||
function evalBinary(expr, source, context) { | ||
if (expr.operator === "NONE") { | ||
throw new Error("sentinel value of MxOperator not allowed in runtime"); | ||
} | ||
var evalLeft = evalInt(expr.left, source, context); | ||
var evalRight = evalInt(expr.right, source, context); // (no shortcutting) | ||
if (isNothing(evalLeft) || isNothing(evalRight)) { | ||
@@ -134,32 +172,36 @@ switch (expr.operator) { | ||
} | ||
function evalTailable(baseExpr, tailExpr, source, variables) { | ||
var baseEval = evalInt(baseExpr, source, variables); | ||
return (tailExpr === null || isNothing(baseEval)) | ||
? baseEval // simple failure semantics: propagate undefined | ||
: evalInt(tailExpr, baseEval, variables); | ||
} | ||
function evalFollow(expr, source, variables) { | ||
if (isNothing(source)) | ||
function evalFollow(expr, source, context) { | ||
if (isNothing(source)) { | ||
return undefined; | ||
} | ||
var visited = []; | ||
var currentElement = source; | ||
while (!isNothing(currentElement)) { | ||
if (visited.indexOf(currentElement) > -1) | ||
if (visited.indexOf(currentElement) > -1) { | ||
return undefined; // cycle! | ||
} | ||
visited.push(currentElement); | ||
currentElement = evalInt(expr.path, currentElement, variables.withValue(expr.variable.name, currentElement)); | ||
currentElement = evalInt(expr.path, currentElement, context.withValue(expr.variable.name, currentElement)); | ||
} | ||
return visited.slice(1); | ||
return visited; | ||
} | ||
function evalMethodCall(expr, source, variables) { | ||
if (isNothing(source)) | ||
function evalMethodCall(expr, source, context) { | ||
var method = standard_library_methods_1.standardMethods[expr.referredMethod]; | ||
if (method) { | ||
return method(source, (expr.arguments || []).map(function (argExpr) { return evalInt(argExpr, source, context); })); | ||
} | ||
if (isNothing(source)) { | ||
return undefined; | ||
var method = standard_library_methods_1.StandardMethods[expr.referredMethod]; | ||
if (method) | ||
return method(source, (expr.arguments || []).map(function (argExpr) { return evalInt(argExpr, source, variables); })); | ||
if (!(source instanceof structures_1.Structure)) | ||
throw new Error("Cannot call query on non-Structure"); | ||
var queryExpr = queryResolver(expr.referredMethod, source.typeName); | ||
if (queryExpr) | ||
return evaluateExpr(queryExpr, source, queryResolver); | ||
} | ||
if (!(source instanceof structures_1.Structure)) { | ||
throw new Error("Cannot call query '" + expr.referredMethod + "' on non-Structure"); | ||
} | ||
var query = queryResolver(expr.referredMethod, source.typeName); | ||
if (query) { | ||
var queryContext = context.withThis(source); | ||
for (var variableName in query.variables) { | ||
queryContext = queryContext.withValue(variableName, evalInt(query.variables[variableName], source, queryContext)); | ||
} | ||
return evalInt(query.valueExpr, source, queryContext); | ||
} | ||
throw new Error("Method not implemented by either standard lib or as query on instance of " + source.typeName + ": " + expr.referredMethod); | ||
@@ -169,49 +211,56 @@ } | ||
var enumClazz = instances_1.instancehelpers.lookupClass(expr.enumeration, modelClasses); | ||
if (!enumClazz) | ||
if (!enumClazz) { | ||
return undefined; | ||
} | ||
var literal = enumClazz[expr.literal]; | ||
if (!literal) | ||
if (!literal) { | ||
return undefined; | ||
} | ||
return literal; | ||
} | ||
function evalStructureLiteral(expr, source, variables) { | ||
function evalStructureLiteral(expr, source, context) { | ||
var assignments = {}; | ||
for (var _i = 0, _a = expr.assignments; _i < _a.length; _i++) { | ||
var assignment = _a[_i]; | ||
var evalAssignment = evalInt(assignment.value, source, variables); | ||
if (isNothing(evalAssignment)) | ||
var evalAssignment = evalInt(assignment.value, source, context); | ||
if (isNothing(evalAssignment)) { | ||
return undefined; | ||
} | ||
assignments[assignment.property] = evalAssignment; | ||
} | ||
var clazz = instances_1.instancehelpers.lookupClass(expr.structure, modelClasses); | ||
if (!clazz) | ||
if (!clazz) { | ||
return undefined; | ||
var structure = clazz.create(model); | ||
if (!structure) | ||
} | ||
var newStructure = clazz.create(model); | ||
if (!newStructure) { | ||
return undefined; | ||
} | ||
for (var propertyName in assignments) { | ||
structure['__' + propertyName].set(assignments[propertyName]); | ||
newStructure["__" + propertyName].set(assignments[propertyName]); | ||
} | ||
return structure; | ||
return newStructure; | ||
} | ||
function evalSwitch(expr, source, variables) { | ||
var context = variables.withValue(expr.variable.name, source); // (put source in variables under expr.variable.name) | ||
function evalSwitch(expr, source, context) { | ||
var switchContext = context.withValue(expr.variable.name, source); | ||
for (var _i = 0, _a = expr.cases; _i < _a.length; _i++) { | ||
var switchCase = _a[_i]; | ||
if (evalSwitchCase(switchCase, source, context)) | ||
return evalInt(switchCase.value, null, context); | ||
if (evalSwitchCase(switchCase, source, switchContext)) { | ||
return evalInt(switchCase.value, undefined, switchContext); | ||
} | ||
} | ||
return undefined; | ||
} | ||
function evalSwitchCase(switchCase, source, variables) { | ||
function evalSwitchCase(switchCase, source, context) { | ||
var typeMatches = (function () { | ||
if (!switchCase.expectedType) | ||
if (!switchCase.expectedType) { | ||
return true; | ||
var typeLiteral = evalInt(switchCase.expectedType, null, variables); | ||
} | ||
var typeLiteral = evalInt(switchCase.expectedType, undefined, context); | ||
return isNothing(typeLiteral) ? false : source instanceof typeLiteral.clazz; | ||
})(); | ||
return typeMatches && (!switchCase.condition || !!evalInt(switchCase.condition, null, variables)); | ||
return typeMatches && (!switchCase.condition || !!evalInt(switchCase.condition, undefined, context)); | ||
} | ||
} | ||
exports.evaluateExpr = evaluateExpr; | ||
exports.evaluateExpression = evaluateExpression; | ||
/** | ||
@@ -218,0 +267,0 @@ * Checks whether the argument is "nothing", i.e. either undefined or null. |
@@ -1,2 +0,2 @@ | ||
export declare const StandardIterators: { | ||
export declare const standardIterators: { | ||
[name: string]: (operand: any[] | void, boundExpr: IteratorLambda<any, any>) => any; | ||
@@ -14,3 +14,3 @@ }; | ||
* It helps in implementing the previous operator (and even more generic offset operators) | ||
* by updating the iteration state in the current closure to it.previous(). | ||
* by updating the iteration state in the current context to it.previous(). | ||
* This is a cleaner way than to keep track of the previous value and passing that to expressions | ||
@@ -17,0 +17,0 @@ * bound in the iterator. |
"use strict"; | ||
var lodash = require('lodash'); | ||
var expressions_evaluator_1 = require('./expressions-evaluator'); | ||
exports.StandardIterators = { | ||
var lodash_1 = require("lodash"); | ||
var expressions_evaluator_1 = require("./expressions-evaluator"); | ||
exports.standardIterators = { | ||
// (in alphabetic order, for easy lookup:) | ||
@@ -16,3 +16,3 @@ EVERY: every, | ||
function normalize(lambda) { | ||
return lodash.compose(function (b) { return !!b; }, lambda); | ||
return lodash_1.compose(function (b) { return !!b; }, lambda); | ||
} | ||
@@ -23,3 +23,3 @@ /** | ||
* It helps in implementing the previous operator (and even more generic offset operators) | ||
* by updating the iteration state in the current closure to it.previous(). | ||
* by updating the iteration state in the current context to it.previous(). | ||
* This is a cleaner way than to keep track of the previous value and passing that to expressions | ||
@@ -48,35 +48,44 @@ * bound in the iterator. | ||
function every(items, boundExpr) { | ||
if (expressions_evaluator_1.isNothing(items)) | ||
if (expressions_evaluator_1.isNothing(items)) { | ||
return false; | ||
} | ||
var fItems = items.map(boundExpr); | ||
if (fItems.some(function (fItem) { return expressions_evaluator_1.isNothing(fItem); })) | ||
if (fItems.some(function (fItem) { return expressions_evaluator_1.isNothing(fItem); })) { | ||
return false; | ||
} | ||
return fItems.every(function (fItem) { return !!fItem; }); | ||
} | ||
function findFirst(items, boundExpr) { | ||
if (expressions_evaluator_1.isNothing(items)) | ||
if (expressions_evaluator_1.isNothing(items)) { | ||
return undefined; | ||
return lodash.find(items, normalize(boundExpr)); | ||
} | ||
return lodash_1.find(items, normalize(boundExpr)); | ||
} | ||
function filter(items, boundExpr) { | ||
if (expressions_evaluator_1.isNothing(items)) | ||
if (expressions_evaluator_1.isNothing(items)) { | ||
return undefined; | ||
} | ||
return items.filter(normalize(boundExpr)); | ||
} | ||
function map(items, boundExpr) { | ||
if (expressions_evaluator_1.isNothing(items)) | ||
if (expressions_evaluator_1.isNothing(items)) { | ||
return undefined; | ||
} | ||
return items.map(boundExpr).filter(function (item) { return item !== undefined; }); | ||
} | ||
function some(items, boundExpr) { | ||
if (expressions_evaluator_1.isNothing(items)) | ||
if (expressions_evaluator_1.isNothing(items)) { | ||
return false; | ||
if (items.length == 0) | ||
} | ||
if (items.length === 0) { | ||
return false; | ||
} | ||
var fItems = items.map(boundExpr); | ||
if (fItems.some(function (fItem) { return !!fItem; })) | ||
if (fItems.some(function (fItem) { return !!fItem; })) { | ||
return true; | ||
if (fItems.every(function (fItem) { return expressions_evaluator_1.isNothing(fItem); })) | ||
} | ||
if (fItems.every(function (fItem) { return expressions_evaluator_1.isNothing(fItem); })) { | ||
return undefined; | ||
} | ||
return false; | ||
} |
@@ -1,3 +0,3 @@ | ||
export declare const StandardMethods: { | ||
export declare const standardMethods: { | ||
[name: string]: (source: any | void, args: any[] | void) => any; | ||
}; |
"use strict"; | ||
var utils_1 = require('../utils'); | ||
var expressions_evaluator_1 = require('./expressions-evaluator'); | ||
var lodash_1 = require('lodash'); | ||
var structures_1 = require('../internal/structures'); | ||
exports.StandardMethods = { | ||
var utils_1 = require("../utils"); | ||
var expressions_evaluator_1 = require("./expressions-evaluator"); | ||
var lodash_1 = require("lodash"); | ||
var structures_1 = require("../internal/structures"); | ||
var elements_1 = require("../internal/elements"); | ||
var units_1 = require("../internal/units"); | ||
exports.standardMethods = { | ||
// (in alphabetic order, for easy lookup:) | ||
asType: asType, | ||
concat: concat, | ||
container: container, | ||
@@ -17,8 +20,13 @@ containerAs: containerAs, | ||
hasDuplicates: hasDuplicates, | ||
hasPrefix: hasPrefix, | ||
isDefined: isDefined, | ||
isEmpty: isEmpty, | ||
isEmptyOrUndefined: isEmptyOrUndefined, | ||
isOfType: isOfType, | ||
isUndefined: isUndefined, | ||
last: last, | ||
length: length, | ||
modelUnit: modelUnit, | ||
notEmpty: notEmpty, | ||
qualifiedName: qualifiedName, | ||
typeFilter: typeFilter | ||
@@ -34,5 +42,20 @@ }; | ||
var typeLiteral = firstArg(args); | ||
return (expressions_evaluator_1.isNothing(source) || !(source instanceof structures_1.Structure) || expressions_evaluator_1.isNothing(typeLiteral) || !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral) || !(source instanceof typeLiteral.clazz)) | ||
? undefined : source; | ||
return (expressions_evaluator_1.isNothing(source) | ||
|| !(source instanceof structures_1.Structure) | ||
|| expressions_evaluator_1.isNothing(typeLiteral) | ||
|| !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral) | ||
|| !(source instanceof typeLiteral.clazz)) | ||
? undefined | ||
: source; | ||
} | ||
function concat(items, args) { | ||
var toConcat = firstArg(args); | ||
if (expressions_evaluator_1.isNothing(toConcat) || isNotList(toConcat)) { | ||
return undefined; | ||
} | ||
if (expressions_evaluator_1.isNothing(items) || isNotList(items)) { | ||
return undefined; | ||
} | ||
return items.concat(toConcat); | ||
} | ||
function container(source) { | ||
@@ -45,7 +68,9 @@ return expressions_evaluator_1.isNothing(source) | ||
var typeLiteral = firstArg(args); | ||
if (expressions_evaluator_1.isNothing(source) || !(source instanceof structures_1.Structure) || expressions_evaluator_1.isNothing(typeLiteral)) | ||
if (expressions_evaluator_1.isNothing(source) || !(source instanceof structures_1.Structure) || expressions_evaluator_1.isNothing(typeLiteral)) { | ||
return undefined; | ||
} | ||
var _container = container(source); | ||
if (expressions_evaluator_1.isNothing(_container)) | ||
if (expressions_evaluator_1.isNothing(_container)) { | ||
return undefined; | ||
} | ||
return asType(_container, [typeLiteral]); | ||
@@ -55,4 +80,5 @@ } | ||
var element = firstArg(args); | ||
if (isNotList(items) || expressions_evaluator_1.isNothing(element)) | ||
if (isNotList(items) || expressions_evaluator_1.isNothing(element)) { | ||
return undefined; | ||
} | ||
return items.indexOf(element) > -1; | ||
@@ -62,4 +88,5 @@ } | ||
var typeLiteral = firstArg(args); | ||
if (expressions_evaluator_1.isNothing(typeLiteral) || !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral)) | ||
if (expressions_evaluator_1.isNothing(typeLiteral) || !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral)) { | ||
return undefined; | ||
} | ||
return firstContainerOfTypes(source, [typeLiteral]); | ||
@@ -69,4 +96,5 @@ } | ||
var typeLiterals = isNotList(args) ? [] : args.filter(function (typeLiteral) { return typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral; }); | ||
if (expressions_evaluator_1.isNothing(source) || !(source instanceof structures_1.Structure) || typeLiterals.length == 0) | ||
if (expressions_evaluator_1.isNothing(source) || !(source instanceof structures_1.Structure) || typeLiterals.length === 0) { | ||
return undefined; | ||
} | ||
var currentStructure = source.container; | ||
@@ -79,9 +107,11 @@ while (!expressions_evaluator_1.isNothing(currentStructure) && !(typeLiterals.some(function (typeLiteral) { return currentStructure instanceof typeLiteral.clazz; }))) { | ||
function flatten(items) { | ||
if (isNotList(items)) | ||
if (isNotList(items)) { | ||
return undefined; | ||
} | ||
return utils_1.utils.flatten(items); | ||
} | ||
function get(items, args) { | ||
if (isNotList(items) || isNotList(args) || !lodash_1.isNumber(args[0])) | ||
if (isNotList(items) || isNotList(args) || !lodash_1.isNumber(args[0])) { | ||
return undefined; | ||
} | ||
var index = args[0]; | ||
@@ -91,7 +121,14 @@ return (index < 1 || items.length < index) ? undefined : items[index - 1]; | ||
function hasDuplicates(items) { | ||
if (isNotList(items)) | ||
if (isNotList(items)) { | ||
return undefined; | ||
} | ||
var list = items; | ||
return lodash_1.uniq(list).length < list.length; | ||
} | ||
function hasPrefix(source, args) { | ||
if (expressions_evaluator_1.isNothing(source) || isNotList(args) || !lodash_1.isString(args[0])) { | ||
return undefined; | ||
} | ||
return source.indexOf(args[0]) === 0; | ||
} | ||
function isDefined(source) { | ||
@@ -103,3 +140,3 @@ return !expressions_evaluator_1.isNothing(source); | ||
? undefined | ||
: (items.length == 0); | ||
: (items.length === 0); | ||
} | ||
@@ -109,2 +146,11 @@ function isEmptyOrUndefined(items) { | ||
} | ||
function isOfType(source, args) { | ||
var typeLiteral = firstArg(args); | ||
return (expressions_evaluator_1.isNothing(source) | ||
|| !(source instanceof structures_1.Structure) | ||
|| expressions_evaluator_1.isNothing(typeLiteral) | ||
|| !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral)) | ||
? undefined | ||
: (source instanceof typeLiteral.clazz); | ||
} | ||
function isUndefined(source) { | ||
@@ -123,2 +169,10 @@ return expressions_evaluator_1.isNothing(source); | ||
} | ||
function modelUnit(source) { | ||
if (expressions_evaluator_1.isNothing(source) || !(source instanceof structures_1.Structure)) { | ||
return undefined; | ||
} | ||
return (source instanceof units_1.AbstractUnit) | ||
? source | ||
: source.unit; | ||
} | ||
function notEmpty(items) { | ||
@@ -129,7 +183,13 @@ return (isNotList(items)) | ||
} | ||
function qualifiedName(source) { | ||
return expressions_evaluator_1.isNothing(source) || !(source instanceof elements_1.AbstractElement) | ||
? undefined | ||
: source.qualifiedName; | ||
} | ||
function typeFilter(items, args) { | ||
var typeLiteral = firstArg(args); | ||
if (expressions_evaluator_1.isNothing(items) || expressions_evaluator_1.isNothing(typeLiteral) || !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral)) | ||
if (expressions_evaluator_1.isNothing(items) || expressions_evaluator_1.isNothing(typeLiteral) || !(typeLiteral instanceof expressions_evaluator_1.StructureTypeLiteral)) { | ||
return undefined; | ||
} | ||
return items.filter(function (item) { return item instanceof typeLiteral.clazz; }); | ||
} |
@@ -1,3 +0,3 @@ | ||
import * as units from '../internal/units'; | ||
import * as structures from '../internal/structures'; | ||
import * as units from "../internal/units"; | ||
import * as structures from "../internal/structures"; | ||
/** | ||
@@ -10,3 +10,2 @@ * Class which allows to serialize a given model part as TypeScript code that constructs that model piece. | ||
static serializeToJs(unit: units.IAbstractUnit): string; | ||
@@ -16,2 +15,3 @@ | ||
static serializeToJs(unit: units.IAbstractUnit): string; | ||
constructor(_unit: units.IAbstractUnit); | ||
@@ -18,0 +18,0 @@ schedule(structure: structures.IStructure): void; |
"use strict"; | ||
var properties = require('../internal/properties'); | ||
var units = require('../internal/units'); | ||
var properties = require("../internal/properties"); | ||
var units = require("../internal/units"); | ||
var PropertyKind; | ||
@@ -29,4 +29,5 @@ (function (PropertyKind) { | ||
JavaScriptSerializer.serializeToJs = function (unit) { | ||
if (!unit.isLoaded) | ||
if (!unit.isLoaded) { | ||
throw new Error("serializeToJs can be used on loaded units only!"); | ||
} | ||
var serializer = new JavaScriptSerializer(unit); | ||
@@ -37,4 +38,5 @@ serializer.schedule(unit); | ||
JavaScriptSerializer.prototype.schedule = function (structure) { | ||
if (!structure || this._creationsById[structure.id]) | ||
if (!structure || this._creationsById[structure.id]) { | ||
return; | ||
} | ||
this._creationsById[structure.id] = true; | ||
@@ -51,24 +53,24 @@ this._creations.push(this._asCreation(structure)); | ||
// 2. build source for everything but assignments of by-id references: | ||
var phase1 = this._creations.map(function (creation) { return _this._creationAsSource(creation); }).join('\n'); | ||
var phase1 = this._creations.map(function (creation) { return _this._creationAsSource(creation); }).join("\n"); | ||
// 3. add source for assignments of by-id references: | ||
var creationsWithByIdRefencesAssigments = this._creations.filter(function (creation) { return creation.settings.some(function (setting) { return setting.kind === PropertyKind.byIdReference; }); }); | ||
var phase2 = creationsWithByIdRefencesAssigments.map(function (creation) { return '\n' + | ||
var phase2 = creationsWithByIdRefencesAssigments.map(function (creation) { return "\n" + | ||
creation.settings | ||
.filter(function (setting) { return setting.kind === PropertyKind.byIdReference; }) | ||
.map(function (setting) { return '\t' + _this._settingAsSource(_this._varNamesById[creation.id], setting) + '\n'; }) | ||
.join(''); }).join(''); | ||
.map(function (setting) { return "\t" + _this._settingAsSource(_this._varNamesById[creation.id], setting) + "\n"; }) | ||
.join(""); }).join(""); | ||
var today = new Date(); | ||
var header = "(function (unit, model) {\n\n\t/*\n\t * JavaScript code generated by mendixmodelsdk.sdk.extras.JavaScriptSerializer\n\t * from unit with id '" + this._unit.id + "' of type " + this._unit.typeName + "\n\t * in working copy '" + this._unit._model.metadata.metaData.name + "'\n\t * on " + today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear() + ".\n\t */\n\n"; | ||
return header + phase1 + phase2 + '\n})'; | ||
var header = "(function (unit, model) {\n\n\t/*\n\t * JavaScript code generated by mendixmodelsdk.sdk.extras.JavaScriptSerializer\n\t * from unit with id \"" + this._unit.id + "\" of type " + this._unit.typeName + "\n\t * in working copy \"" + this._unit._model.metadata.metaData.name + "\"\n\t * on " + today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear() + ".\n\t */\n\n"; | ||
return header + phase1 + phase2 + "\n})"; | ||
}; | ||
JavaScriptSerializer.prototype._computeVarName = function (creation) { | ||
var preName, name, uniqueIndex = 0, add_ = false; | ||
var preName, name, uniqueIndex = 0, addUnderscore = false; | ||
if (creation.name) { | ||
preName = this._sanitizeName(creation.name); | ||
name = preName; | ||
add_ = !!preName.match(/\d$/); | ||
addUnderscore = !!preName.match(/\d$/); | ||
} | ||
else { | ||
preName = toFirstLowerCase(creation.unqualifiedTypeName); | ||
name = preName + '1'; | ||
name = preName + "1"; | ||
uniqueIndex = 1; | ||
@@ -78,3 +80,3 @@ } | ||
uniqueIndex++; | ||
name = preName + (add_ ? '_' : '') + uniqueIndex; | ||
name = preName + (addUnderscore ? "_" : "") + uniqueIndex; | ||
} | ||
@@ -85,4 +87,4 @@ this._varNamesById[creation.id] = name; | ||
JavaScriptSerializer.prototype._sanitizeName = function (name) { | ||
name = name.replace(/[!\"#$%&'\(\)\*\+,\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, ''); | ||
name = name.replace(/^\d+/, ''); | ||
name = name.replace(/[!\"#$%&'\(\)\*\+,\.\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g, ""); | ||
name = name.replace(/^\d+/, ""); | ||
name = name.charAt(0).toLowerCase() + name.substring(1); // == toFirstLowerCase | ||
@@ -95,5 +97,5 @@ return name; | ||
var varName = this._varNamesById[creation.id]; | ||
lines.push("var " + varName + " = " + creation.subMetaModel.toLowerCase() + "." + creation.unqualifiedTypeName + ".create" + (creation.unit ? 'In(unit' : '(model') + ");"); | ||
lines.push("var " + varName + " = " + creation.subMetaModel.toLowerCase() + "." + creation.unqualifiedTypeName + ".create" + (creation.unit ? "In(unit" : "(model") + ");"); | ||
creation.settings.filter(function (setting) { return setting.kind !== PropertyKind.byIdReference; }).forEach(function (setting) { return lines.push.apply(lines, _this._settingAsSource(varName, setting)); }); | ||
return lines.map(function (line) { return '\t' + line + '\n'; }).join(''); | ||
return lines.map(function (line) { return "\t" + line + "\n"; }).join(""); | ||
}; | ||
@@ -113,3 +115,3 @@ JavaScriptSerializer.prototype._settingAsSource = function (varName, setting) { | ||
case PropertyKind.byNameReference: { | ||
var $index = setting.targetType.indexOf('$'); | ||
var $index = setting.targetType.indexOf("$"); | ||
return "model.find" + setting.targetType.substring($index + 1) + "ByQualifiedName(\"" + singleValue + "\")"; | ||
@@ -124,3 +126,3 @@ } | ||
var _this = this; | ||
var typeParts = structure.typeName.split('$'); | ||
var typeParts = structure.typeName.split("$"); | ||
var creation = { | ||
@@ -132,4 +134,4 @@ id: structure.id, | ||
}; | ||
if (structure['name']) { | ||
creation.name = structure['name']; | ||
if (structure["name"]) { | ||
creation.name = structure["name"]; | ||
} | ||
@@ -143,4 +145,4 @@ if (structure instanceof units.ModelUnit || structure instanceof units.StructuralUnit) { | ||
var value = property.get(); | ||
if (value !== property['defaultValue']) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.enumeration, value: value }); | ||
if (value !== property["defaultValue"]) { | ||
creation.settings.push({ propertyName: property["name"], kind: PropertyKind.enumeration, value: value }); | ||
} | ||
@@ -152,13 +154,14 @@ return; | ||
if (value.length > 0) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.enumeration, value: value, listy: true }); | ||
creation.settings.push({ propertyName: property["name"], kind: PropertyKind.enumeration, value: value, listy: true }); | ||
} | ||
return; | ||
} | ||
// Primitive(List)Property must be handled _after_ Enum(List)Property since the latter inherit from the first! | ||
// Primitive(List)Property must be handled _after_ Enum(List)Property since the latter inherit from the first! | ||
if (property instanceof properties.PrimitiveProperty) { | ||
if (property['primitiveType'] === properties.PrimitiveTypeEnum.Guid) | ||
if (property["primitiveType"] === properties.PrimitiveTypeEnum.Guid) { | ||
return; | ||
} | ||
var value = property.get(); | ||
if (value !== property['defaultValue']) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.primitive, value: value }); | ||
if (value !== property["defaultValue"]) { | ||
creation.settings.push({ propertyName: property["name"], kind: PropertyKind.primitive, value: value }); | ||
} | ||
@@ -170,3 +173,3 @@ return; | ||
if (value.length > 0) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.primitive, value: value, listy: true }); | ||
creation.settings.push({ propertyName: property["name"], kind: PropertyKind.primitive, value: value, listy: true }); | ||
} | ||
@@ -180,4 +183,9 @@ return; | ||
} | ||
if (property['hasDefaultValue'] || value) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.part, value: value, couldBeDefaultValue: property['hasDefaultValue'] }); | ||
if (property["hasDefaultValue"] || value) { | ||
creation.settings.push({ | ||
propertyName: property["name"], | ||
kind: PropertyKind.part, | ||
value: value, | ||
couldBeDefaultValue: property["hasDefaultValue"] | ||
}); | ||
} | ||
@@ -190,3 +198,3 @@ return; | ||
value.forEach(function (item) { return _this.schedule(item); }); | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.part, value: value, listy: true }); | ||
creation.settings.push({ propertyName: property["name"], kind: PropertyKind.part, value: value, listy: true }); | ||
} | ||
@@ -198,3 +206,8 @@ return; | ||
if (value) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.byNameReference, value: property.qualifiedName(), targetType: property.targetType }); | ||
creation.settings.push({ | ||
propertyName: property["name"], | ||
kind: PropertyKind.byNameReference, | ||
value: property.qualifiedName(), | ||
targetType: property.targetType | ||
}); | ||
} | ||
@@ -206,3 +219,9 @@ return; | ||
if (value.length > 0) { | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.byNameReference, value: property.qualifiedNames(), targetType: property.targetType, listy: true }); | ||
creation.settings.push({ | ||
propertyName: property["name"], | ||
kind: PropertyKind.byNameReference, | ||
value: property.qualifiedNames(), | ||
targetType: property.targetType, | ||
listy: true | ||
}); | ||
} | ||
@@ -215,3 +234,3 @@ return; | ||
_this.schedule(value); | ||
creation.settings.push({ propertyName: property['name'], kind: PropertyKind.byIdReference, value: value.id }); | ||
creation.settings.push({ propertyName: property["name"], kind: PropertyKind.byIdReference, value: value.id }); | ||
} | ||
@@ -218,0 +237,0 @@ return; |
@@ -46,3 +46,3 @@ import { common } from '../../common'; | ||
*/ | ||
deploy(callback: common.ICallback<IDeploymentResult>, errorCallback?: common.IErrorCallback): any; | ||
deploy(forceFullDeployment: boolean, callback: common.ICallback<IDeploymentResult>, errorCallback?: common.IErrorCallback): any; | ||
/** | ||
@@ -203,3 +203,3 @@ * Get the deployment status of the working copy. Can be STARTED, STARTING, UPDATING, STOPPED and APP_NOT_FOUND. Contains other deploy info as well. | ||
deleteFile(filePath: string, callback: common.IVoidCallback, errorCallback: common.IErrorCallback): void; | ||
deploy(callback: common.ICallback<IDeploymentResult>, errorCallback?: common.IErrorCallback): void; | ||
deploy(forceFullDeployment: boolean, callback: common.ICallback<IDeploymentResult>, errorCallback?: common.IErrorCallback): void; | ||
getDeploymentStatus(callback: common.ICallback<IDeploymentResult>, errorCallback?: common.IErrorCallback): void; | ||
@@ -206,0 +206,0 @@ getEditorData(callback: common.ICallback<IEditorData>, errorCallback: common.IErrorCallback): void; |
@@ -351,4 +351,4 @@ "use strict"; | ||
}; | ||
AbstractModel.prototype.deploy = function (callback, errorCallback) { | ||
this._client.deploy(this.id, callback, errorCallback || this._errorHandler); | ||
AbstractModel.prototype.deploy = function (forceFullDeployment, callback, errorCallback) { | ||
this._client.deploy(this.id, forceFullDeployment, callback, errorCallback || this._errorHandler); | ||
}; | ||
@@ -355,0 +355,0 @@ AbstractModel.prototype.getDeploymentStatus = function (callback, errorCallback) { |
@@ -36,3 +36,3 @@ import { configuration } from '../config'; | ||
checkAccess(workingCopyId: string, memberOpenId: string, callback: common.ICallback<boolean>, errorCallback: common.IErrorCallback): any; | ||
deploy(workingCopyId: string, callback: common.ICallback<transport.IDeploymentResult>, errorCallback: common.IErrorCallback): any; | ||
deploy(workingCopyId: string, forceFullDeployment: boolean, callback: common.ICallback<transport.IDeploymentResult>, errorCallback: common.IErrorCallback): any; | ||
getDeploymentStatus(workingCopyId: string, callback: common.ICallback<transport.IDeploymentResult>, errorCallback: common.IErrorCallback): any; | ||
@@ -84,3 +84,3 @@ getMyWorkingCopies(callback: common.ICallback<transport.IWorkingCopy[]>, errorCallback: common.IErrorCallback): any; | ||
exportMpk(workingCopyId: string, outFilePath: string, callback: common.IVoidCallback, errorCallback: common.IErrorCallback): void; | ||
deploy(workingCopyId: string, callback: common.ICallback<transport.IDeploymentResult>, errorCallback: common.IErrorCallback): void; | ||
deploy(workingCopyId: string, forceFullDeployment: boolean, callback: common.ICallback<transport.IDeploymentResult>, errorCallback: common.IErrorCallback): void; | ||
loadUnitById<T extends units.AbstractUnit>(workingCopyId: string, unitId: string, callback: common.ICallback<transport.IAbstractUnitJson>, errorCallback: common.IErrorCallback): void; | ||
@@ -106,5 +106,5 @@ sendDeltas(workingCopyId: string, deltas: transport.IDelta[], callback: common.ICallback<Object>, errorCallback: common.IErrorCallback): void; | ||
export declare type IEditorData = { | ||
[version: string]: { | ||
templates: string; | ||
[mmVersion: string]: { | ||
pageTemplates: string; | ||
}; | ||
}; |
@@ -54,4 +54,6 @@ "use strict"; | ||
}; | ||
ModelApiClientImpl.prototype.deploy = function (workingCopyId, callback, errorCallback) { | ||
this.transportation.request("post", apiEndPoint + "wc/" + workingCopyId + "/deploy", null, this.handleRawDeploymentResult.bind(this, callback, errorCallback), errorCallback, true); | ||
ModelApiClientImpl.prototype.deploy = function (workingCopyId, forceFullDeployment, callback, errorCallback) { | ||
this.transportation.request("post", apiEndPoint + "wc/" + workingCopyId + "/deploy", { | ||
fulldeploy: forceFullDeployment === false ? false : true // always true unless explicitly false | ||
}, this.handleRawDeploymentResult.bind(this, callback, errorCallback), errorCallback, true); | ||
}; | ||
@@ -58,0 +60,0 @@ ModelApiClientImpl.prototype.loadUnitById = function (workingCopyId, unitId, callback, errorCallback) { |
@@ -270,13 +270,14 @@ /** | ||
url: string; | ||
profile: string; | ||
profile?: string; | ||
state: string; | ||
endpoint: string; | ||
instances: number; | ||
memory: number; | ||
endpoint?: string; | ||
instances?: number; | ||
memory?: number; | ||
errordetails?: string; | ||
} | ||
export interface IRawDeploymentResult extends IBaseDeploymentResult { | ||
buildstatus: string; | ||
buildstatus?: string; | ||
} | ||
export interface IDeploymentResult extends IBaseDeploymentResult { | ||
buildstatus: IProblem[]; | ||
buildstatus?: IProblem[]; | ||
} | ||
@@ -283,0 +284,0 @@ export interface IProblem { |
@@ -1,2 +0,2 @@ | ||
/** Current SDK version: 2.3.0 */ | ||
/** Current SDK version: 2.4.0-dev.223f367 */ | ||
export declare const SDK_VERSION: string; |
"use strict"; | ||
/** Current SDK version: 2.3.0 */ | ||
exports.SDK_VERSION = "2.3.0"; | ||
/** Current SDK version: 2.4.0-dev.223f367 */ | ||
exports.SDK_VERSION = "2.4.0"; |
{ | ||
"name": "mendixmodelsdk", | ||
"version": "2.3.0", | ||
"version": "2.4.0-dev.223f367", | ||
"description": "Mendix Model SDK", | ||
@@ -31,2 +31,3 @@ "main": "dist/index.js", | ||
"grunt-exec": "0.4.6", | ||
"json-loader": "^0.5.4", | ||
"mkdirp": "0.5.1", | ||
@@ -47,2 +48,2 @@ "mocha": "2.2.1", | ||
"license": "MIT" | ||
} | ||
} |
# Release notes Mendix Model SDK | ||
## 2.5.0 | ||
| story# | impact | description | | ||
|---|---|---| | ||
| 716682 | None | Support for forcing full deployment. Deploying a working copy is functionality that's not accessible to regular Model SDK users (i.e. non-trusted backends), so no impact. | | ||
## 2.4.0 | ||
| story# | impact | description | | ||
|---|---|---| | ||
| 790285 | None | Support for Mendix 6.5.1. | | ||
| 692298 | None | Exposed facilities for running consistency checks on models. | | ||
## 2.3.0 | ||
@@ -9,2 +24,3 @@ | ||
## 2.2.2 | ||
@@ -20,2 +36,3 @@ | ||
## 2.1.0 | ||
@@ -31,2 +48,3 @@ | ||
## 2.0.0 | ||
@@ -33,0 +51,0 @@ |
@@ -113,3 +113,3 @@ /// <reference path="../test-typings.d.ts"/> | ||
deploy(workingCopyId: string, callback: common.ICallback<IDeploymentResult>, errorCallback: common.IErrorCallback) { | ||
deploy(workingCopyId: string, forceFullDeployment: boolean, callback: common.ICallback<IDeploymentResult>, errorCallback: common.IErrorCallback) { | ||
return void callback({ | ||
@@ -141,6 +141,6 @@ url: "example.com/app", | ||
"6.3.0": { | ||
templates: "53839423-715e-490d-8eb8-5e1c6bc9525h" | ||
pageTemplates: "53839423-715e-490d-8eb8-5e1c6bc9525h" | ||
}, | ||
"6.4.0": { | ||
templates: "f95f2763-4fdc-4758-8a02-69a8e126742b" | ||
pageTemplates: "f95f2763-4fdc-4758-8a02-69a8e126742b" | ||
} | ||
@@ -147,0 +147,0 @@ }); |
/// <reference path="../../test-typings.d.ts"/> | ||
import * as expressions from '../../../src/gen/expressions-meta-types'; | ||
import {evaluateExpr, StructureTypeLiteral} from '../../../src/sdk/checks/expressions-evaluator'; | ||
import {expressions} from "../../../src/gen/expressions-meta-types"; | ||
import {evaluateExpression, StructureTypeLiteral} from "../../../src/sdk/checks/expressions-evaluator"; | ||
import {assert} from 'chai'; | ||
import * as lodash from 'lodash'; | ||
import {assert} from "chai"; | ||
import {range} from "lodash"; | ||
import {withEntityLoaded} from '../../helpers/test-model-helper'; | ||
import {domainmodels_simple} from '../../gen/domainmodels_simple'; | ||
import {withEntityLoaded} from "../../helpers/test-model-helper"; | ||
import {domainmodels_simple} from "../../gen/domainmodels_simple"; | ||
import {mkBinaryExpr, trueExpr, falseExpr, | ||
wrap, mkFollow, mkIteratorCall, mkMethodCall, mkNavigationExpr, mkPreviousExpr, mkPropertyCall, | ||
wrap, mkFollow, mkIteratorCall, mkMethodCall, mkPrefixExpression, mkPreviousExpr, mkPropertyCall, | ||
mkStringLiteral, stringTypeLiteral, thisExpr, undefinedExpr, mkVariableRef, | ||
chain} from './expressions-factories'; | ||
import {augmentWithSimpleEntities} from './simple-entities-helper'; | ||
import {Structure} from '../../../src/sdk/internal/structures'; | ||
import {loadTestQueries, makeLoadingQueryResolver} from './json-loaders'; | ||
chain} from "./expressions-factories"; | ||
import {augmentWithSimpleEntities} from "./simple-entities-helper"; | ||
import {Structure} from "../../../src/sdk/internal/structures"; | ||
import {testQueryResolver, testQueries} from "./test-metadata-loaders"; | ||
describe('expressions evaluator should be able to: ', () => { | ||
describe("expressions evaluator should be able to: ", () => { | ||
const testQueryResolver = makeLoadingQueryResolver(); | ||
const evaluateWithTestQueries = (expr: expressions.MxExpression, structure: Structure) => | ||
evaluateExpression(expr, structure, testQueryResolver); | ||
const evaluateWithTestQueries = (expr: expressions.MxExpression, structure: Structure) => evaluateExpr(expr, structure, testQueryResolver); | ||
const evaluateWithNullThis = (expr: expressions.MxExpression) => evaluateWithTestQueries(expr, null); | ||
@@ -32,9 +31,15 @@ | ||
it('a binary expression with faulty data', () => { | ||
assert.throws(() => { | ||
evaluateWithNullThis(mkBinaryExpr(null, "NONE", null)); | ||
}, "sentinel value of MxOperator not allowed in runtime"); | ||
// TODO test handling of applicable expressions | ||
it("a binary expression with faulty data", () => { | ||
assert.throws( | ||
() => { | ||
evaluateWithNullThis(mkBinaryExpr(null, "NONE", null)); | ||
}, | ||
"sentinel value of MxOperator not allowed in runtime" | ||
); | ||
}); | ||
it('a binary expression with undefined data', () => { | ||
it("a binary expression with undefined data", () => { | ||
function testBinaryExprWithUndefineds(operator: expressions.MxOperator, expected: boolean | void) { | ||
@@ -61,3 +66,3 @@ assertEvalWithNullThis(mkBinaryExpr(undefinedExpr, operator, trueExpr), expected); | ||
it('a binary expression with valid data', () => { | ||
it("a binary expression with valid data", () => { | ||
const foo = mkStringLiteral("foo"); | ||
@@ -98,3 +103,3 @@ const bar = mkStringLiteral("bar"); | ||
it('a boolean literal expression', () => { | ||
it("a boolean literal expression", () => { | ||
assertEvalWithNullThis(trueExpr, true); | ||
@@ -104,15 +109,21 @@ assertEvalWithNullThis(falseExpr, false); | ||
it('a color literal expression', () => { | ||
assertEvalWithNullThis(<expressions.MxColorLiteralExpression>{ $type: "MxColorLiteralExpression", red: 100, green: 150, blue: 200 }, { red: 100, green: 150, blue: 200 }); | ||
it("a color literal expression", () => { | ||
assertEvalWithNullThis( | ||
{ $type: "MxColorLiteralExpression", red: 100, green: 150, blue: 200 } as expressions.MxColorLiteralExpression, | ||
{ red: 100, green: 150, blue: 200 } | ||
); | ||
}); | ||
it('a double literal expression', () => { | ||
assertEvalWithNullThis(<expressions.MxDoubleLiteralExpression>{ $type: "MxDoubleLiteralExpression", value: Math.PI }, Math.PI); | ||
it("a double literal expression", () => { | ||
assertEvalWithNullThis( | ||
{ $type: "MxDoubleLiteralExpression", value: Math.PI } as expressions.MxDoubleLiteralExpression, | ||
Math.PI | ||
); | ||
}); | ||
// TODO MxFeatureCallWrapper? (already implicitly tested in all feature call expressions unit tests) | ||
// MxFeatureCallWrapper is already implicitly tested in all feature call expressions unit tests | ||
it('a follow expression', done => { | ||
const expr = mkNavigationExpr(thisExpr, wrap( // "this."... | ||
mkFollow("e", wrap(mkNavigationExpr(mkVariableRef("e"), wrap(mkPropertyCall("generalization"))))) // ...".follow[ e | e.generalization ]" | ||
it("a follow expression", done => { | ||
const expr = thisExpr(wrap( // "this."... | ||
mkFollow("e", wrap(mkVariableRef("e", wrap(mkPropertyCall("generalization"))))) // ...".follow[ e | e.generalization ]" | ||
)); | ||
@@ -125,5 +136,8 @@ | ||
const simpleEntities = augmentWithSimpleEntities(domainModel); | ||
assert.deepEqual(evaluateWithTestQueries(expr, simpleEntities['NonInheriting']), []); | ||
assert.deepEqual(evaluateWithTestQueries(expr, simpleEntities['AInCycle']), undefined); | ||
assert.deepEqual(evaluateWithTestQueries(expr, simpleEntities['ANotInCycle']), ['BNotInCycle', 'CNotInCycle', 'DNotInCycle'].map(entName => simpleEntities[entName])); | ||
assert.deepEqual(evaluateWithTestQueries(expr, simpleEntities["NonInheriting"]), [simpleEntities["NonInheriting"]]); | ||
assert.deepEqual(evaluateWithTestQueries(expr, simpleEntities["AInCycle"]), undefined); | ||
assert.deepEqual( | ||
evaluateWithTestQueries(expr, simpleEntities["ANotInCycle"]), | ||
["ANotInCycle", "BNotInCycle", "CNotInCycle", "DNotInCycle"].map(entName => simpleEntities[entName]) | ||
); | ||
@@ -134,10 +148,10 @@ done(); | ||
it('a integer literal expression', () => { | ||
assertEvalWithNullThis(<expressions.MxIntegerLiteralExpression>{ $type: "MxIntegerLiteralExpression", value: 42 }, 42); | ||
it("a integer literal expression", () => { | ||
assertEvalWithNullThis({ $type: "MxIntegerLiteralExpression", value: 42 } as expressions.MxIntegerLiteralExpression, 42); | ||
}); | ||
it('a [map] iterator call expression (and implicitly a variable reference expression)', done => { | ||
const iteratorBody = mkNavigationExpr(mkVariableRef("ent"), wrap(mkPropertyCall("name"))); // "ent.name" | ||
const iteratorCall = mkIteratorCall("MAP", "ent", iteratorBody); // *".map[ ent | ent.name ]" | ||
const expr = mkNavigationExpr(thisExpr, chain(mkPropertyCall("entities"), iteratorCall)); // "this.entities.map[ ent | ent.name ]"" | ||
it("a [map] iterator call expression (and implicitly a variable reference expression)", done => { | ||
const iteratorBody = mkVariableRef("ent", wrap(mkPropertyCall("name"))); // "ent.name" | ||
const iteratorCall = mkIteratorCall("MAP", "ent", iteratorBody); // *".map[ ent | ent.name ]" | ||
const expr = thisExpr(chain(mkPropertyCall("entities"), iteratorCall)); // "this.entities.map[ ent | ent.name ]"" | ||
@@ -155,10 +169,10 @@ withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
it('[map and flatten] iterator and method call expressions (and implicitly a variable reference expression)', done => { | ||
it("[map and flatten] iterator and method call expressions (and implicitly a variable reference expression)", done => { | ||
// "this.entities.map[ ent | ent.attributes.map[ attr | attr.name ]].flatten()" | ||
const innerMapBody = mkNavigationExpr(mkVariableRef("attr"), wrap(mkPropertyCall("name"))); // "attr.name" | ||
const innerMapCall = mkIteratorCall("MAP", "attr", wrap(innerMapBody)); // *".map[ attr | ++<innerMapBody>++ ]" | ||
const outerMapBody = mkNavigationExpr(mkVariableRef("ent"), chain(mkPropertyCall("attributes"), innerMapCall)); // "ent.attributes++<innerMapCall>++" | ||
const outerMapCall = mkIteratorCall("MAP", "ent", outerMapBody); // *".map[ ent | ++<outerMapBody>++]" | ||
const flattenCall = mkMethodCall("flatten"); // *".flatten()" | ||
const expr = mkNavigationExpr(thisExpr, chain(mkPropertyCall("entities"), outerMapCall, flattenCall)); // "this.entities++<outerMapCall>++.flatten()" | ||
const innerMapBody = mkVariableRef("attr", wrap(mkPropertyCall("name"))); // "attr.name" | ||
const innerMapCall = mkIteratorCall("MAP", "attr", wrap(innerMapBody)); // *".map[ attr | ++<innerMapBody>++ ]" | ||
const outerMapBody = mkVariableRef("ent", chain(mkPropertyCall("attributes"), innerMapCall)); // "ent.attributes++<innerMapCall>++" | ||
const outerMapCall = mkIteratorCall("MAP", "ent", outerMapBody); // *".map[ ent | ++<outerMapBody>++]" | ||
const flattenCall = mkMethodCall("flatten"); // *".flatten()" | ||
const expr = thisExpr(chain(mkPropertyCall("entities"), outerMapCall, flattenCall)); // "this.entities++<outerMapCall>++.flatten()" | ||
@@ -179,26 +193,34 @@ withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
it('a list literal expression', () => { | ||
assertEvalWithNullThis(<expressions.MxListLiteralExpression>{ | ||
$type: "MxListLiteralExpression", items: [ | ||
trueExpr, | ||
falseExpr, | ||
<expressions.MxColorLiteralExpression>{ $type: "MxColorLiteralExpression", red: 100, green: 150, blue: 200 } | ||
it("a list literal expression", () => { | ||
assertEvalWithNullThis( | ||
{ | ||
$type: "MxListLiteralExpression", | ||
items: [ | ||
trueExpr, | ||
falseExpr, | ||
{ $type: "MxColorLiteralExpression", red: 100, green: 150, blue: 200 } as expressions.MxColorLiteralExpression | ||
], | ||
appliedFeature: null | ||
} as expressions.MxListLiteralExpression, | ||
[ | ||
true, false, { red: 100, green: 150, blue: 200 } | ||
] | ||
}, [ | ||
true, false, { red: 100, green: 150, blue: 200 } | ||
]); | ||
); | ||
}); | ||
// TODO MxNavigationExpression? (already tested implicitly almost everywhere) | ||
it("a method call that operates on undefined", () => { | ||
assertEvalWithNullThis(wrap(mkMethodCall("isUndefined")), true); | ||
assertEvalWithNullThis(wrap(mkMethodCall("someQuery")), undefined); | ||
}); | ||
it('a prefix (==boolean negation) expression', () => { | ||
assertEvalWithNullThis(<expressions.MxPrefixExpression>{ $type: "MxPrefixExpression", expression: trueExpr }, false); | ||
assertEvalWithNullThis(<expressions.MxPrefixExpression>{ $type: "MxPrefixExpression", expression: falseExpr }, true); | ||
assertEvalWithNullThis(<expressions.MxPrefixExpression>{ $type: "MxPrefixExpression", expression: undefinedExpr }, undefined); | ||
it("a prefix (==boolean negation) expression", () => { | ||
assertEvalWithNullThis(mkPrefixExpression(trueExpr), false); | ||
assertEvalWithNullThis(mkPrefixExpression(falseExpr), true); | ||
assertEvalWithNullThis(mkPrefixExpression(undefinedExpr), undefined); | ||
}); | ||
it('a previous expression', done => { | ||
it("a previous expression", done => { | ||
// "this.intsList.map[ i | previous(i) ]" | ||
const iteratorBody = mkNavigationExpr(mkPreviousExpr(mkVariableRef("i"))); | ||
const expr = mkNavigationExpr(thisExpr, | ||
const iteratorBody = mkPreviousExpr(mkVariableRef("i")); | ||
const expr = thisExpr( | ||
chain(mkPropertyCall("intsList"), mkIteratorCall("MAP", "i", iteratorBody)) // *".intsList.map[ i | ++<iteratorBody>++ ]" | ||
@@ -209,5 +231,5 @@ ); | ||
const n = 4; | ||
entity.intsList.replace(lodash.range(n)); // [ 0, 1, 2, 3 ] --[previous]--> [ undefined, 0, 1, 2 ] --[flatMap]--> [0, 1, 2] | ||
entity.intsList.replace(range(n)); // [ 0, 1, 2, 3 ] --[previous]--> [ undefined, 0, 1, 2 ] --[flatMap]--> [0, 1, 2] | ||
const value = evaluateWithTestQueries(expr, entity); | ||
assert.deepEqual(value, lodash.range(n-1)); // map is flatMappy, so undefined @ position 0 is skipped | ||
assert.deepEqual(value, range(n - 1)); // map is flatMappy, so undefined @ position 0 is skipped | ||
done(); | ||
@@ -217,4 +239,4 @@ }); | ||
it('a property call expression', done => { | ||
const expr = mkNavigationExpr(thisExpr, wrap(mkPropertyCall("name"))); // "this.name" | ||
it("a property call expression", done => { | ||
const expr = thisExpr(wrap(mkPropertyCall("name"))); // "this.name" | ||
@@ -230,9 +252,12 @@ withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
it('a qualified enum literal expression', done => { | ||
it("a qualified enum literal expression", done => { | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
const value = evaluateWithTestQueries(<expressions.MxQualifiedEnumLiteralExpression>{ | ||
$type: "MxQualifiedEnumLiteralExpression", | ||
enumeration: "DomainModels_simple$MyEnum", | ||
literal: "AnotherValue" | ||
}, domainModel); | ||
const value = evaluateWithTestQueries( | ||
{ | ||
$type: "MxQualifiedEnumLiteralExpression", | ||
enumeration: "DomainModels_simple$MyEnum", | ||
literal: "AnotherValue" | ||
} as expressions.MxQualifiedEnumLiteralExpression, | ||
domainModel | ||
); | ||
assert.equal(domainmodels_simple.MyEnum.AnotherValue, value); | ||
@@ -243,11 +268,18 @@ done(); | ||
it('a size literal expression', () => { | ||
assertEvalWithNullThis(<expressions.MxSizeLiteralExpression>{ $type: "MxSizeLiteralExpression", height: 1000, width: 800 }, { height: 1000, width: 800 }); | ||
it("a size literal expression", () => { | ||
assertEvalWithNullThis( | ||
{ | ||
$type: "MxSizeLiteralExpression", | ||
height: 1000, | ||
width: 800 | ||
} as expressions.MxSizeLiteralExpression, | ||
{ height: 1000, width: 800 } | ||
); | ||
}); | ||
it('a string literal expression', () => { | ||
it("a string literal expression", () => { | ||
assertEvalWithNullThis(mkStringLiteral("foo"), "foo"); | ||
}); | ||
it('a structure literal expression', done => { | ||
it("a structure literal expression", done => { | ||
function mkPropertyAssignment(propertyName: string, valueExpr: expressions.MxLiteralExpression): expressions.MxPropertyAssignment { | ||
@@ -262,9 +294,12 @@ return { | ||
const entityName = "fooBar!"; | ||
const structure = evaluateWithTestQueries(<expressions.MxStructureLiteralExpression>{ | ||
$type: "MxStructureLiteralExpression", | ||
structure: "domainmodels_simple$Entity", | ||
assignments: [ | ||
mkPropertyAssignment("name", mkStringLiteral(entityName)) | ||
] | ||
}, domainModel); | ||
const structure = evaluateWithTestQueries( | ||
{ | ||
$type: "MxStructureLiteralExpression", | ||
structure: "domainmodels_simple$Entity", | ||
assignments: [ | ||
mkPropertyAssignment("name", mkStringLiteral(entityName)) | ||
] | ||
} as expressions.MxStructureLiteralExpression, | ||
domainModel | ||
); | ||
assert.ok(structure); | ||
@@ -277,10 +312,21 @@ assert.isTrue(structure instanceof domainmodels_simple.Entity); | ||
it('a switch expression', done => { | ||
const encompassingExpr = loadTestQueries()[domainmodels_simple.Attribute.typeName]["fooable"].valueExpr as expressions.MxNavigationExpression; | ||
const switchExpr = encompassingExpr.tail.tail.featureCall as expressions.MxSwitch; | ||
it("a switch expression", done => { | ||
const encompassingExpr = | ||
testQueries[domainmodels_simple.Attribute.typeName]["fooable"].valueExpr as expressions.MxThisExpression; | ||
const switchExpr = encompassingExpr.appliedFeature.appliedFeature.featureCall as expressions.MxSwitch; | ||
assert.equal(switchExpr.$type, "MxSwitch", "drill-down to MxSwitch not correct"); | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
assert.equal(evaluateExpr(switchExpr, domainmodels_simple.StringAttributeType.create(model), testQueryResolver), domainmodels_simple.FooableType.Both); | ||
assert.equal(evaluateExpr(switchExpr, domainmodels_simple.IntegerAttributeType.create(model), testQueryResolver), domainmodels_simple.FooableType.TypeOfOnly); | ||
assert.equal(evaluateExpr(switchExpr, domainmodels_simple.BinaryAttributeType.create(model), testQueryResolver), domainmodels_simple.FooableType.WhenOnly); | ||
const fooableType = domainmodels_simple.FooableType; | ||
assert.equal( | ||
evaluateExpression(switchExpr, domainmodels_simple.StringAttributeType.create(model), testQueryResolver), | ||
fooableType.Both | ||
); | ||
assert.equal( | ||
evaluateExpression(switchExpr, domainmodels_simple.IntegerAttributeType.create(model), testQueryResolver), | ||
fooableType.TypeOfOnly | ||
); | ||
assert.equal( | ||
evaluateExpression(switchExpr, domainmodels_simple.BinaryAttributeType.create(model), testQueryResolver), | ||
fooableType.WhenOnly | ||
); | ||
done(); | ||
@@ -290,9 +336,7 @@ }); | ||
it('a this expression', (done) => { | ||
it("a this expression", (done) => { | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
const entityName = "fooBar!"; | ||
entity.name = entityName; | ||
const value = evaluateWithTestQueries(<expressions.MxThisExpression>{ | ||
$type: "MxThisExpression" | ||
}, entity); | ||
const value = evaluateWithTestQueries(thisExpr(), entity); | ||
assert.equal(value, entity); | ||
@@ -303,8 +347,11 @@ done(); | ||
it('a type primitive [type] literal expression', () => { | ||
it("a type primitive [type] literal expression", () => { | ||
assert.throws(() => { evaluateWithNullThis(stringTypeLiteral); }); | ||
}); | ||
it('a type structure literal expression', done => { | ||
const structureTypeLiteralExpr = <expressions.MxTypeStructureLiteralExpression>{ $type: "MxTypeStructureLiteralExpression", referredStructure: domainmodels_simple.Entity.typeName }; | ||
it("a type structure literal expression", done => { | ||
const structureTypeLiteralExpr = { | ||
$type: "MxTypeStructureLiteralExpression", | ||
referredStructure: domainmodels_simple.Entity.typeName | ||
} as expressions.MxTypeStructureLiteralExpression; | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
@@ -322,3 +369,3 @@ const typeLiteral = evaluateWithTestQueries(structureTypeLiteralExpr, domainModel); | ||
it('an undefined expression', () => { | ||
it("an undefined expression", () => { | ||
assertEvalWithNullThis(undefinedExpr, undefined); | ||
@@ -329,2 +376,6 @@ }); | ||
// TODO test all concrete sub types of MxApplicableExpression whether they're actually "applied" | ||
}); |
@@ -1,5 +0,6 @@ | ||
import * as expressions from '../../../src/gen/expressions-meta-types'; | ||
import {expressions} from "../../../src/gen/expressions-meta-types"; | ||
export function mkBinaryExpr(left: expressions.MxExpression, operator: expressions.MxOperator, right: expressions.MxExpression): expressions.MxBinaryExpression { | ||
export function mkBinaryExpr(left: expressions.MxExpression, operator: expressions.MxOperator, right: expressions.MxExpression) | ||
: expressions.MxBinaryExpression { | ||
return { | ||
@@ -10,3 +11,3 @@ $type: "MxBinaryExpression", | ||
right: right | ||
} | ||
}; | ||
}; | ||
@@ -20,7 +21,8 @@ | ||
export function mkFeatureCallWrapper(featureCall: expressions.MxFeatureCall, tail: expressions.MxFeatureCallWrapper = null): expressions.MxFeatureCallWrapper { | ||
export function mkFeatureCallWrapper(featureCall: expressions.MxFeatureCall, appliedFeature: expressions.MxFeatureCallWrapper = null) | ||
: expressions.MxFeatureCallWrapper { | ||
return { | ||
$type: "MxFeatureCallWrapper", | ||
featureCall: featureCall, | ||
tail: tail | ||
appliedFeature: appliedFeature | ||
}; | ||
@@ -34,6 +36,6 @@ } | ||
$type: "MxFollow", | ||
variable: <expressions.MxBuiltInVariableDeclaration>{ | ||
variable: { | ||
$type: "MxBuiltInVariableDeclaration", | ||
name: variableName | ||
}, | ||
} as expressions.MxBuiltInVariableDeclaration, | ||
path: path | ||
@@ -43,3 +45,4 @@ }; | ||
export function mkIteratorCall(type: expressions.MxIteratorType, iteratorVariableName: string, body: expressions.MxExpression): expressions.MxIteratorCall { | ||
export function mkIteratorCall(type: expressions.MxIteratorType, iteratorVariableName: string, body: expressions.MxExpression) | ||
: expressions.MxIteratorCall { | ||
return { | ||
@@ -68,8 +71,4 @@ $type: "MxIteratorCall", | ||
export function mkNavigationExpr(base: expressions.MxExpression, tail: expressions.MxFeatureCallWrapper = null): expressions.MxNavigationExpression { | ||
return { | ||
$type: "MxNavigationExpression", | ||
base: base, | ||
tail: tail | ||
}; | ||
export function mkPrefixExpression(expr: expressions.MxExpression): expressions.MxPrefixExpression { | ||
return { $type: "MxPrefixExpression", expression: expr }; | ||
} | ||
@@ -85,7 +84,11 @@ | ||
export function mkPreviousExpr(variable: expressions.MxVariableRefExpression): expressions.MxPreviousExpression { | ||
return { | ||
$type: "MxPreviousExpression", | ||
variable: variable | ||
}; | ||
export function mkPreviousExpr(variable: expressions.MxVariableRefExpression, appliedFeature: expressions.MxFeatureCallWrapper = null): | ||
expressions.MxPreviousExpression { | ||
return apply<expressions.MxPreviousExpression>( | ||
{ | ||
$type: "MxPreviousExpression", | ||
variable: variable | ||
}, | ||
appliedFeature | ||
); | ||
} | ||
@@ -104,11 +107,14 @@ | ||
export const thisExpr: expressions.MxThisExpression = { $type: "MxThisExpression" }; | ||
export function thisExpr(appliedFeature: expressions.MxFeatureCallWrapper = null): expressions.MxThisExpression { | ||
return apply<expressions.MxThisExpression>({ $type: "MxThisExpression" }, appliedFeature); | ||
} | ||
export const undefinedExpr: expressions.MxUndefinedExpression = { $type: "MxUndefinedExpression" }; | ||
export function mkVariableRef(referredVariable: string): expressions.MxVariableRefExpression { | ||
return { | ||
$type: "MxVariableRefExpression", | ||
referredVariable: referredVariable | ||
}; | ||
export function mkVariableRef(referredVariable: string, appliedFeature: expressions.MxFeatureCallWrapper = null): | ||
expressions.MxVariableRefExpression { | ||
return apply<expressions.MxVariableRefExpression>( | ||
{ $type: "MxVariableRefExpression", referredVariable: referredVariable }, | ||
appliedFeature | ||
); | ||
} | ||
@@ -127,1 +133,7 @@ | ||
function apply<T extends expressions.MxApplicableExpression>(expr: Object, appliedFeature: expressions.MxFeatureCallWrapper): T { | ||
expr["appliedFeature"] = appliedFeature; | ||
return expr as T; | ||
} | ||
@@ -1,2 +0,2 @@ | ||
import {domainmodels_simple} from '../../gen/domainmodels_simple'; | ||
import {domainmodels_simple} from "../../gen/domainmodels_simple"; | ||
@@ -10,4 +10,5 @@ export function augmentWithSimpleEntities(domainModel: domainmodels_simple.DomainModel) { | ||
newSimpleEntity.name = name; | ||
if (generalization) | ||
if (generalization) { | ||
newSimpleEntity.generalization = generalization; | ||
} | ||
simpleEntities[name] = newSimpleEntity; | ||
@@ -17,3 +18,3 @@ return newSimpleEntity; | ||
const nonInheriting = mkSimpleEntity("NonInheriting"); | ||
mkSimpleEntity("NonInheriting"); | ||
@@ -28,5 +29,5 @@ const cInCycle = mkSimpleEntity("CInCycle"); | ||
const bNotInCycle = mkSimpleEntity("BNotInCycle", cNotInCycle); | ||
const aNotInCycle = mkSimpleEntity("ANotInCycle", bNotInCycle); | ||
mkSimpleEntity("ANotInCycle", bNotInCycle); | ||
return simpleEntities; | ||
} |
/// <reference path="../../test-typings.d.ts"/> | ||
import {StandardIterators} from '../../../src/sdk/checks/standard-library-iterators'; | ||
import {standardIterators} from "../../../src/sdk/checks/standard-library-iterators"; | ||
import {assert} from 'chai'; | ||
import {assert} from "chai"; | ||
describe('iterators in the standard library', () => { | ||
describe("iterators in the standard library", () => { | ||
const map = StandardIterators['MAP']; | ||
const some = StandardIterators['SOME']; | ||
const every = StandardIterators['EVERY']; | ||
const filter = StandardIterators['FILTER']; | ||
const findFirst = StandardIterators['FIND_FIRST']; | ||
const map = standardIterators["MAP"]; | ||
const some = standardIterators["SOME"]; | ||
const every = standardIterators["EVERY"]; | ||
const filter = standardIterators["FILTER"]; | ||
const findFirst = standardIterators["FIND_FIRST"]; | ||
it('should all do the right thing on undefined', () => { | ||
it("should all do the right thing on undefined", () => { | ||
const trueFunc = item => true; | ||
@@ -25,6 +25,6 @@ assert.equal(map(undefined, trueFunc), undefined); | ||
const oddFunc = (n: number) => n % 2 == 1; | ||
const oddFunc = (n: number) => n % 2 === 1; | ||
const undefinedFunc = (x: any) => undefined; | ||
it('map', () => { | ||
it("map", () => { | ||
const asymDoubler = (n: number) => n < 0 ? undefined : 2 * n; | ||
@@ -36,3 +36,3 @@ assert.deepEqual(map([1, 2, 3, -1, 4], asymDoubler), [2, 4, 6, 8]); | ||
it('some', () => { | ||
it("some", () => { | ||
const boolId = (b: boolean) => b; | ||
@@ -42,3 +42,3 @@ assert.deepEqual(some([true, undefined], boolId), true); | ||
assert.deepEqual(some([undefined, false], boolId), false); | ||
assert.deepEqual(some([], boolId), false, 'exists on empty'); | ||
assert.deepEqual(some([], boolId), false, "exists on empty"); | ||
assert.deepEqual(some([1, 2], undefinedFunc), undefined); | ||
@@ -49,6 +49,6 @@ }); | ||
it('every', () => { | ||
it("every", () => { | ||
assert.deepEqual(every([1, 2, 3, -1, 4], asymOddFunc), false); | ||
assert.deepEqual(every([1, 3], oddFunc), true); | ||
assert.deepEqual(every([], oddFunc), true, 'forAll on empty'); | ||
assert.deepEqual(every([], oddFunc), true, "forAll on empty"); | ||
assert.deepEqual(every([42], oddFunc), false); | ||
@@ -58,3 +58,3 @@ assert.deepEqual(every([42], undefinedFunc), false); | ||
it('filter', () => { | ||
it("filter", () => { | ||
assert.deepEqual(filter([1, 2, 3, -1, 4], asymOddFunc), [1, 3]); | ||
@@ -65,3 +65,3 @@ assert.deepEqual(filter([1, 2, 3, -1, 4], undefinedFunc), []); | ||
it('findFirst', () => { | ||
it("findFirst", () => { | ||
assert.deepEqual(findFirst([1, 2, 3, -1, 4], asymOddFunc), 1); | ||
@@ -68,0 +68,0 @@ assert.deepEqual(findFirst([1, 2, 3, -1, 4], undefinedFunc), undefined); |
/// <reference path="../../test-typings.d.ts"/> | ||
import {StandardMethods} from '../../../src/sdk/checks/standard-library-methods'; | ||
import {standardMethods} from "../../../src/sdk/checks/standard-library-methods"; | ||
import {assert} from 'chai'; | ||
import {range} from 'lodash'; | ||
import {assert} from "chai"; | ||
import {range} from "lodash"; | ||
import {StructureTypeLiteral} from '../../../src/sdk/checks/expressions-evaluator'; | ||
import {withEntityLoaded} from '../../helpers/test-model-helper'; | ||
import {domainmodels_simple} from '../../gen/domainmodels_simple'; | ||
import {stringTypeLiteral as mxStringTypeLiteral} from './expressions-factories'; | ||
import {StructureTypeLiteral} from "../../../src/sdk/checks/expressions-evaluator"; | ||
import {withEntityLoaded} from "../../helpers/test-model-helper"; | ||
import {domainmodels_simple} from "../../gen/domainmodels_simple"; | ||
import {stringTypeLiteral as mxStringTypeLiteral} from "./expressions-factories"; | ||
describe('methods in the standard library', () => { | ||
describe("methods in the standard library", () => { | ||
@@ -21,4 +21,4 @@ const entityType = new StructureTypeLiteral(domainmodels_simple.Entity); | ||
it('asType', done => { | ||
const asType = StandardMethods['asType']; | ||
it("asType", done => { | ||
const asType = standardMethods["asType"]; | ||
assert.equal(asType(undefined, []), undefined); | ||
@@ -35,4 +35,14 @@ assert.equal(asType(undefined, [undefined]), undefined); | ||
it('container', done => { | ||
const container = StandardMethods['container']; | ||
it("concat", () => { | ||
const concat = standardMethods["concat"]; | ||
assert.equal(concat(undefined, []), undefined); | ||
assert.equal(concat("foo", [[]]), undefined); | ||
assert.deepEqual(concat(range(3), [[3, 4]]), range(5)); | ||
assert.deepEqual(concat(range(10), [[]]), range(10)); | ||
assert.equal(concat(range(4), [undefined]), undefined); | ||
assert.equal(concat(range(4), ["foo"]), undefined); | ||
}); | ||
it("container", done => { | ||
const container = standardMethods["container"]; | ||
assert.equal(container(undefined, []), undefined); | ||
@@ -49,4 +59,4 @@ assert.equal(container("foo", []), undefined); | ||
it('containerAs', done => { | ||
const containerAs = StandardMethods['containerAs']; | ||
it("containerAs", done => { | ||
const containerAs = standardMethods["containerAs"]; | ||
assert.equal(containerAs(undefined, []), undefined); | ||
@@ -62,4 +72,4 @@ assert.equal(containerAs("foo", [new StructureTypeLiteral(domainmodels_simple.Entity)]), undefined); | ||
it('contains', () => { | ||
const contains = StandardMethods['contains']; | ||
it("contains", () => { | ||
const contains = standardMethods["contains"]; | ||
assert.equal(contains(undefined, undefined), undefined); | ||
@@ -72,4 +82,4 @@ assert.equal(contains("foo", undefined), undefined); | ||
it('firstContainerOfType', done => { | ||
const firstContainerOfType = StandardMethods['firstContainerOfType']; | ||
it("firstContainerOfType", done => { | ||
const firstContainerOfType = standardMethods["firstContainerOfType"]; | ||
assert.equal(firstContainerOfType(undefined, []), undefined); | ||
@@ -86,4 +96,4 @@ assert.equal(firstContainerOfType("foo", []), undefined); | ||
it('firstContainerOfTypes', done => { | ||
const firstContainerOfTypes = StandardMethods['firstContainerOfTypes']; | ||
it("firstContainerOfTypes", done => { | ||
const firstContainerOfTypes = standardMethods["firstContainerOfTypes"]; | ||
assert.equal(firstContainerOfTypes(undefined, []), undefined); | ||
@@ -101,4 +111,4 @@ assert.equal(firstContainerOfTypes("foo", []), undefined); | ||
it('flatten', () => { | ||
const flatten = StandardMethods['flatten']; | ||
it("flatten", () => { | ||
const flatten = standardMethods["flatten"]; | ||
assert.equal(flatten(undefined, []), undefined); | ||
@@ -109,4 +119,4 @@ assert.deepEqual(flatten([[[]]], []), [[]]); | ||
it('get', () => { | ||
const get = StandardMethods['get']; | ||
it("get", () => { | ||
const get = standardMethods["get"]; | ||
const n = 4; | ||
@@ -118,3 +128,3 @@ const list = range(n).map(i => i + 1); | ||
assert.equal(get(list, [-42]), undefined); | ||
assert.equal(get(list, [n+1]), undefined); | ||
assert.equal(get(list, [n + 1]), undefined); | ||
assert.deepEqual(list.map(i => get(list, [i])), list); | ||
@@ -124,4 +134,4 @@ assert.equal(get(list, [Math.PI]), undefined); | ||
it('hasDuplicates', () => { | ||
const hasDuplicates = StandardMethods['hasDuplicates']; | ||
it("hasDuplicates", () => { | ||
const hasDuplicates = standardMethods["hasDuplicates"]; | ||
assert.equal(hasDuplicates(undefined, []), undefined); | ||
@@ -134,4 +144,14 @@ assert.equal(hasDuplicates("foo", []), undefined); | ||
it('isEmpty', () => { | ||
const isEmpty = StandardMethods['isEmpty']; | ||
it("hasPrefix", () => { | ||
const hasPrefix = standardMethods["hasPrefix"]; | ||
assert.equal(hasPrefix(undefined, []), undefined); | ||
assert.equal(hasPrefix("foo", []), undefined); | ||
assert.equal(hasPrefix("abcda", ["a"]), true); | ||
assert.equal(hasPrefix("abcda", ["bcd"]), false); | ||
assert.equal(hasPrefix("abcda", ["e"]), false); | ||
assert.equal(hasPrefix("abcda", ["abcde"]), false); | ||
}); | ||
it("isEmpty", () => { | ||
const isEmpty = standardMethods["isEmpty"]; | ||
assert.equal(isEmpty(undefined, []), undefined); | ||
@@ -144,4 +164,4 @@ assert.equal(isEmpty(null, []), undefined); | ||
it('isEmptyOrUndefined', () => { | ||
const isEmptyOrUndefined = StandardMethods['isEmptyOrUndefined']; | ||
it("isEmptyOrUndefined", () => { | ||
const isEmptyOrUndefined = standardMethods["isEmptyOrUndefined"]; | ||
assert.equal(isEmptyOrUndefined(undefined, []), true); | ||
@@ -154,4 +174,18 @@ assert.equal(isEmptyOrUndefined(null, []), true); | ||
it('isUndefined', () => { | ||
const isUndefined = StandardMethods['isUndefined']; | ||
it("isOfType", done => { | ||
const isOfType = standardMethods["isOfType"]; | ||
assert.equal(isOfType(undefined, []), undefined); | ||
assert.equal(isOfType(undefined, [undefined]), undefined); | ||
assert.equal(isOfType("foo", [mxStringTypeLiteral]), undefined); | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
assert.equal(isOfType(entity, ["bar"]), undefined); | ||
assert.equal(isOfType(entity, [entityType]), true); | ||
assert.equal(isOfType(entity.attributes[0], [attributeType]), true); | ||
assert.equal(isOfType(entity, [domainModelType]), false); | ||
done(); | ||
}); | ||
}); | ||
it("isUndefined", () => { | ||
const isUndefined = standardMethods["isUndefined"]; | ||
assert.equal(isUndefined(undefined, []), true); | ||
@@ -162,4 +196,4 @@ assert.equal(isUndefined(null, []), true); | ||
it('length', () => { | ||
const length = StandardMethods['length']; | ||
it("length", () => { | ||
const length = standardMethods["length"]; | ||
assert.equal(length(undefined, []), undefined); | ||
@@ -171,12 +205,23 @@ assert.equal(length([], []), 0); | ||
it('last', () => { | ||
const last = StandardMethods['last']; | ||
it("last", () => { | ||
const last = standardMethods["last"]; | ||
assert.equal(last(undefined, []), undefined); | ||
assert.equal(last([], []), undefined); | ||
const n = 4; | ||
assert.equal(last(range(n), []), n-1); | ||
assert.equal(last(range(n), []), n - 1); | ||
}); | ||
it('notEmpty', () => { | ||
const notEmpty = StandardMethods['notEmpty']; | ||
it("modelUnit", done => { | ||
const modelUnit = standardMethods["modelUnit"]; | ||
assert.equal(modelUnit(undefined, []), undefined); | ||
assert.equal(modelUnit(["foo"], []), undefined); | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
assert.deepEqual(modelUnit(entity, []), domainModel); | ||
assert.deepEqual(modelUnit(domainModel, []), domainModel); | ||
done(); | ||
}); | ||
}); | ||
it("notEmpty", () => { | ||
const notEmpty = standardMethods["notEmpty"]; | ||
assert.equal(notEmpty(undefined, []), undefined); | ||
@@ -189,4 +234,15 @@ assert.equal(notEmpty(null, []), undefined); | ||
it('typeFilter', done => { | ||
const typeFilter = StandardMethods['typeFilter']; | ||
it("qualifiedName", done => { | ||
const qualifiedName = standardMethods["qualifiedName"]; | ||
assert.equal(qualifiedName(undefined, []), undefined); | ||
assert.equal(qualifiedName("foo", []), undefined); | ||
withEntityLoaded("6.1.0", done, (entity, domainModel, model) => { // (ignore warnings issued) | ||
assert.equal(qualifiedName(domainModel, []), "MyAwesomeSimplifiedDomainModel"); | ||
assert.equal(qualifiedName(entity, []), "MyAwesomeSimplifiedDomainModel.ExpenseType"); | ||
done(); | ||
}); | ||
}); | ||
it("typeFilter", done => { | ||
const typeFilter = standardMethods["typeFilter"]; | ||
assert.equal(typeFilter(undefined, []), undefined); | ||
@@ -193,0 +249,0 @@ assert.equal(typeFilter(undefined, [undefined]), undefined); |
@@ -123,3 +123,3 @@ /// <reference path="../test-typings.d.ts"/> | ||
it('deploy a project', (done) => { | ||
createSdkClient().deploy("1", (res: IDeploymentResult) => { | ||
createSdkClient().deploy("1", true, (res: IDeploymentResult) => { | ||
assert.ok(typeof res.url == 'string'); | ||
@@ -126,0 +126,0 @@ done(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4701587
177
87694
13
2