@singularsystems/neo-core 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Model/ModelGraphTraverser.d.ts +3 -0
- package/dist/Model/ModelGraphTraverser.js +30 -19
- package/dist/Model/NeoTypeInfo.js +2 -2
- package/dist/Settings.d.ts +5 -0
- package/dist/Settings.js +6 -1
- package/dist/Validation/Rules.d.ts +1 -1
- package/dist/Validation/Rules.js +4 -4
- package/dist/Validation/ValidationRules.d.ts +1 -1
- package/dist/Validation/ValidationRules.js +1 -1
- package/package.json +1 -1
|
@@ -4,12 +4,15 @@ import PropertyInfo from './PropertyInfo';
|
|
|
4
4
|
export declare class RecursionState {
|
|
5
5
|
stop: boolean;
|
|
6
6
|
canRecurse: (model: IModelBase, property: PropertyInfo) => boolean;
|
|
7
|
+
canRecurseType(item: any): boolean;
|
|
7
8
|
pushState(): void;
|
|
8
9
|
popState(): void;
|
|
9
10
|
/**
|
|
10
11
|
* Overwrites the canRecurse callback to always return true.
|
|
11
12
|
*/
|
|
12
13
|
includeNonTrackedProperties(): this;
|
|
14
|
+
/** Child objects / lists of any type will be included. By default only types extending ModelBase are included. */
|
|
15
|
+
includeNonModelBaseTypes(): this;
|
|
13
16
|
}
|
|
14
17
|
export declare class BooleanRecursionState extends RecursionState {
|
|
15
18
|
flag: boolean;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
2
|
import { RelationType } from './Misc';
|
|
3
|
+
import ModelBase from "./ModelBase";
|
|
3
4
|
var RecursionState = /** @class */ (function () {
|
|
4
5
|
function RecursionState() {
|
|
5
6
|
this.stop = false;
|
|
6
7
|
this.canRecurse = function (model, property) { return !property.noTrack; };
|
|
7
8
|
}
|
|
9
|
+
RecursionState.prototype.canRecurseType = function (item) {
|
|
10
|
+
return item instanceof ModelBase;
|
|
11
|
+
};
|
|
8
12
|
RecursionState.prototype.pushState = function () {
|
|
9
13
|
};
|
|
10
14
|
RecursionState.prototype.popState = function () {
|
|
@@ -16,6 +20,11 @@ var RecursionState = /** @class */ (function () {
|
|
|
16
20
|
this.canRecurse = function (model, property) { return true; };
|
|
17
21
|
return this;
|
|
18
22
|
};
|
|
23
|
+
/** Child objects / lists of any type will be included. By default only types extending ModelBase are included. */
|
|
24
|
+
RecursionState.prototype.includeNonModelBaseTypes = function () {
|
|
25
|
+
this.canRecurseType = function () { return true; };
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
19
28
|
return RecursionState;
|
|
20
29
|
}());
|
|
21
30
|
export { RecursionState };
|
|
@@ -67,32 +76,34 @@ function invokeOnSelfAndChildren(model, state, callback, listCallback, relationT
|
|
|
67
76
|
for (var i = 0; i < ctor.neo.children.length; i++) {
|
|
68
77
|
var cpi = ctor.neo.children[i];
|
|
69
78
|
if (state.canRecurse(model, cpi)) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
listCallback
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
try {
|
|
80
|
+
if (cpi.relationType == RelationType.ChildList) {
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
var childList = model[cpi.propertyName];
|
|
83
|
+
if (listCallback)
|
|
84
|
+
listCallback(childList, state);
|
|
85
|
+
if (state.stop)
|
|
86
|
+
return state;
|
|
87
|
+
if (childList.length && state.canRecurseType(childList[0])) {
|
|
88
|
+
state.pushState();
|
|
89
|
+
invokeOnItemsAndChildren(childList, state, callback, listCallback, RelationType.ChildList);
|
|
90
|
+
state.popState();
|
|
91
|
+
if (state.stop)
|
|
92
|
+
return state;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
85
96
|
// @ts-ignore
|
|
86
97
|
var child = model[cpi.propertyName];
|
|
87
|
-
if (child) {
|
|
98
|
+
if (child && state.canRecurseType(child)) {
|
|
88
99
|
state.pushState();
|
|
89
100
|
invokeOnSelfAndChildren(child, state, callback, listCallback, cpi.relationType);
|
|
90
101
|
state.popState();
|
|
91
102
|
}
|
|
92
103
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
throw "Error on property '".concat(cpi.propertyName, "' on type '").concat(model.constructor.name, "': ").concat(error, ".");
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
109
|
}
|
|
@@ -128,8 +128,8 @@ var NeoTypeInfo = /** @class */ (function () {
|
|
|
128
128
|
if (instance.addBusinessRules !== undefined) {
|
|
129
129
|
var validationRules = new ValidationRules();
|
|
130
130
|
instance.addBusinessRules(validationRules);
|
|
131
|
-
if (validationRules.rules.some(function (c) { return c instanceof CallbackRule && c.
|
|
132
|
-
console.error("Warning: ".concat(this.objectConstructor.name, " has rules which have been added using
|
|
131
|
+
if (validationRules.rules.some(function (c) { return c instanceof CallbackRule && c.hasArrowFunction; })) {
|
|
132
|
+
console.error("Warning: ".concat(this.objectConstructor.name, " has rules which have been added using an arrow function."));
|
|
133
133
|
}
|
|
134
134
|
var modelProxy = new ModelProxy(instance);
|
|
135
135
|
for (var _i = 0, _a = validationRules.rules; _i < _a.length; _i++) {
|
package/dist/Settings.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare const Settings: {
|
|
|
75
75
|
/** Global allowed extensions. Can be changed on each file upload manager. Must be lower case. */
|
|
76
76
|
allowedExtensions: string[];
|
|
77
77
|
fileEditorButton: IButtonOptions;
|
|
78
|
+
browseButton: IButtonOptions;
|
|
78
79
|
};
|
|
79
80
|
progressBar: {
|
|
80
81
|
/** True if you want the animation to be reversed globally. */
|
|
@@ -86,4 +87,8 @@ export declare const Settings: {
|
|
|
86
87
|
/** The standard notification duration in seconds. */
|
|
87
88
|
standardDuration: number;
|
|
88
89
|
};
|
|
90
|
+
alerts: {
|
|
91
|
+
isOutline: boolean;
|
|
92
|
+
iconPosition: "left" | "body";
|
|
93
|
+
};
|
|
89
94
|
};
|
package/dist/Settings.js
CHANGED
|
@@ -106,7 +106,8 @@ export var Settings = {
|
|
|
106
106
|
disallowedFileExtensions: [".exe", ".bat", ".cmd", ".sh", ".com", ".ps", ".ps1", ".dll"],
|
|
107
107
|
/** Global allowed extensions. Can be changed on each file upload manager. Must be lower case. */
|
|
108
108
|
allowedExtensions: [],
|
|
109
|
-
fileEditorButton: { variant: "dark" }
|
|
109
|
+
fileEditorButton: { variant: "dark" },
|
|
110
|
+
browseButton: { variant: "light" },
|
|
110
111
|
},
|
|
111
112
|
progressBar: {
|
|
112
113
|
/** True if you want the animation to be reversed globally. */
|
|
@@ -117,5 +118,9 @@ export var Settings = {
|
|
|
117
118
|
notifications: {
|
|
118
119
|
/** The standard notification duration in seconds. */
|
|
119
120
|
standardDuration: 4
|
|
121
|
+
},
|
|
122
|
+
alerts: {
|
|
123
|
+
isOutline: false,
|
|
124
|
+
iconPosition: "body",
|
|
120
125
|
}
|
|
121
126
|
};
|
|
@@ -57,7 +57,7 @@ export declare abstract class CustomRule<T extends IModelBase> extends Rule impl
|
|
|
57
57
|
}
|
|
58
58
|
export declare class CallbackRule<T extends IModelBase> extends CustomRule<T> {
|
|
59
59
|
private validateFn;
|
|
60
|
-
|
|
60
|
+
hasArrowFunction: boolean;
|
|
61
61
|
constructor(validateFn: (context: RuleContext) => void);
|
|
62
62
|
checkRule(propertyInstance: IPropertyInstance, context: RuleContext): void;
|
|
63
63
|
}
|
package/dist/Validation/Rules.js
CHANGED
|
@@ -125,14 +125,14 @@ var CallbackRule = /** @class */ (function (_super) {
|
|
|
125
125
|
function CallbackRule(validateFn) {
|
|
126
126
|
var _this = _super.call(this) || this;
|
|
127
127
|
_this.validateFn = validateFn;
|
|
128
|
-
_this.
|
|
129
|
-
if (!validateFn.hasOwnProperty("prototype")) {
|
|
130
|
-
_this.
|
|
128
|
+
_this.hasArrowFunction = false;
|
|
129
|
+
if (!validateFn.hasOwnProperty("prototype") && !validateFn.name) {
|
|
130
|
+
_this.hasArrowFunction = true;
|
|
131
131
|
}
|
|
132
132
|
return _this;
|
|
133
133
|
}
|
|
134
134
|
CallbackRule.prototype.checkRule = function (propertyInstance, context) {
|
|
135
|
-
if (this.
|
|
135
|
+
if (this.hasArrowFunction) {
|
|
136
136
|
var reboundFn = this.validateFn.bind(propertyInstance.attachedTo);
|
|
137
137
|
reboundFn(context);
|
|
138
138
|
}
|
|
@@ -5,7 +5,7 @@ export declare class ValidationRules<T extends IModelBase> {
|
|
|
5
5
|
rules: CustomRule<T>[];
|
|
6
6
|
/**
|
|
7
7
|
* Registers a custom rule.
|
|
8
|
-
* NOTE: Do not use an arrow function
|
|
8
|
+
* **NOTE: Do not use `.bind(this)`, and do not use an arrow function:**, either pass in the address of a function: add(this.myRule), or pass an anonymous function: add(function(context) {}).
|
|
9
9
|
* @param ruleFunction
|
|
10
10
|
*/
|
|
11
11
|
add(ruleFunction: (context: IRuleContext) => void): ICustomRule<T>;
|
|
@@ -6,7 +6,7 @@ var ValidationRules = /** @class */ (function () {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Registers a custom rule.
|
|
9
|
-
* NOTE: Do not use an arrow function
|
|
9
|
+
* **NOTE: Do not use `.bind(this)`, and do not use an arrow function:**, either pass in the address of a function: add(this.myRule), or pass an anonymous function: add(function(context) {}).
|
|
10
10
|
* @param ruleFunction
|
|
11
11
|
*/
|
|
12
12
|
ValidationRules.prototype.add = function (ruleFunction) {
|