@lowdefy/engine 0.0.0-alpha.6 → 0.0.0-experimental-20231123101256
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/LICENSE +201 -0
- package/dist/Actions.js +231 -486
- package/dist/Blocks.js +563 -572
- package/dist/Events.js +126 -0
- package/dist/Requests.js +107 -134
- package/dist/State.js +56 -83
- package/dist/actions/createCallMethod.js +29 -0
- package/dist/actions/createDisplayMessage.js +20 -0
- package/dist/actions/createGetActions.js +27 -0
- package/dist/actions/createGetBlockId.js +20 -0
- package/dist/actions/createGetEvent.js +27 -0
- package/dist/actions/createGetGlobal.js +27 -0
- package/dist/actions/createGetInput.js +27 -0
- package/dist/actions/createGetPageId.js +20 -0
- package/dist/actions/createGetRequestDetails.js +27 -0
- package/dist/actions/createGetState.js +27 -0
- package/dist/actions/createGetUrlQuery.js +32 -0
- package/dist/actions/createGetUser.js +27 -0
- package/dist/actions/createLink.js +20 -0
- package/dist/actions/createLogin.js +20 -0
- package/dist/actions/createLogout.js +20 -0
- package/dist/actions/createRequest.js +26 -0
- package/dist/actions/createReset.js +22 -0
- package/dist/actions/createResetValidation.js +21 -0
- package/dist/actions/createSetGlobal.js +25 -0
- package/dist/actions/createSetState.js +25 -0
- package/dist/actions/createUpdateSession.js +20 -0
- package/dist/actions/createValidate.js +25 -0
- package/dist/actions/getActionMethods.js +63 -0
- package/dist/actions/getFromObject.js +42 -0
- package/dist/createLink.js +71 -0
- package/dist/getBlockMatcher.js +61 -0
- package/dist/getContext.js +106 -153
- package/dist/index.js +10 -63
- package/package.json +27 -26
- package/dist/BlockActions.js +0 -211
- package/dist/Mutations.js +0 -100
- package/dist/getFieldValues.js +0 -49
- package/dist/makeContextId.js +0 -44
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
const getBlockMatcher = (params)=>{
|
|
17
|
+
let testParams = params;
|
|
18
|
+
if (type.isNone(testParams)) return ()=>true;
|
|
19
|
+
if (type.isString(testParams)) {
|
|
20
|
+
testParams = {
|
|
21
|
+
blockIds: [
|
|
22
|
+
testParams
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (type.isArray(testParams) || type.isBoolean(testParams)) {
|
|
27
|
+
testParams = {
|
|
28
|
+
blockIds: testParams
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (!type.isObject(testParams)) {
|
|
32
|
+
throw new Error('Invalid validate params.');
|
|
33
|
+
}
|
|
34
|
+
if (type.isString(testParams.blockIds)) {
|
|
35
|
+
testParams.blockIds = [
|
|
36
|
+
testParams.blockIds
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
if (type.isString(testParams.regex)) {
|
|
40
|
+
testParams.regex = [
|
|
41
|
+
testParams.regex
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
if (type.isArray(testParams.regex)) {
|
|
45
|
+
testParams.regex = testParams.regex.map((regex)=>new RegExp(regex));
|
|
46
|
+
}
|
|
47
|
+
return (id)=>{
|
|
48
|
+
if (testParams.blockIds === true || type.isArray(testParams.blockIds) && testParams.blockIds.includes(id)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (type.isArray(testParams.regex)) {
|
|
52
|
+
for (const regex of testParams.regex){
|
|
53
|
+
if (regex.test(id)) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export default getBlockMatcher;
|
package/dist/getContext.js
CHANGED
|
@@ -1,160 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
actions,
|
|
45
|
-
areas,
|
|
46
|
-
blockId,
|
|
47
|
-
blocks,
|
|
48
|
-
field,
|
|
49
|
-
id,
|
|
50
|
-
layout,
|
|
51
|
-
meta,
|
|
52
|
-
pageId,
|
|
53
|
-
properties,
|
|
54
|
-
requests,
|
|
55
|
-
required,
|
|
56
|
-
style,
|
|
57
|
-
type,
|
|
58
|
-
validate,
|
|
59
|
-
visible
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
var getContext = /*#__PURE__*/function () {
|
|
64
|
-
var _ref3 = _asyncToGenerator(function* (_ref2) {
|
|
65
|
-
var {
|
|
66
|
-
block,
|
|
67
|
-
contextId,
|
|
68
|
-
pageId,
|
|
69
|
-
rootContext
|
|
70
|
-
} = _ref2;
|
|
71
|
-
|
|
72
|
-
if (rootContext.contexts[contextId]) {
|
|
73
|
-
rootContext.contexts[contextId].input = rootContext.input[contextId] || {};
|
|
74
|
-
rootContext.contexts[contextId].urlQuery = rootContext.urlQuery;
|
|
75
|
-
rootContext.contexts[contextId].lowdefyGlobal = rootContext.lowdefyGlobal;
|
|
76
|
-
rootContext.contexts[contextId].menus = rootContext.menus;
|
|
77
|
-
rootContext.contexts[contextId].config = rootContext.config;
|
|
78
|
-
rootContext.contexts[contextId].update();
|
|
79
|
-
return rootContext.contexts[contextId];
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { WebParser } from '@lowdefy/operators';
|
|
16
|
+
import Actions from './Actions.js';
|
|
17
|
+
import Blocks from './Blocks.js';
|
|
18
|
+
import Requests from './Requests.js';
|
|
19
|
+
import State from './State.js';
|
|
20
|
+
const blockData = ({ areas, blockId, blocks, events, field, id, layout, pageId, properties, requests, required, style, type, validate, visible })=>({
|
|
21
|
+
areas,
|
|
22
|
+
blockId,
|
|
23
|
+
blocks,
|
|
24
|
+
events,
|
|
25
|
+
field,
|
|
26
|
+
id,
|
|
27
|
+
layout,
|
|
28
|
+
pageId,
|
|
29
|
+
properties,
|
|
30
|
+
requests,
|
|
31
|
+
required,
|
|
32
|
+
style,
|
|
33
|
+
type,
|
|
34
|
+
validate,
|
|
35
|
+
visible
|
|
36
|
+
});
|
|
37
|
+
function getContext({ config, lowdefy, resetContext = {
|
|
38
|
+
reset: false,
|
|
39
|
+
setReset: ()=>undefined
|
|
40
|
+
} }) {
|
|
41
|
+
if (!config) {
|
|
42
|
+
throw new Error('A page must be provided to get context.');
|
|
80
43
|
}
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// filter block to prevent circular structure
|
|
103
|
-
routeHistory: rootContext.routeHistory,
|
|
104
|
-
showValidationErrors: false,
|
|
105
|
-
state: {},
|
|
106
|
-
update: () => {},
|
|
107
|
-
// Initialize update since Requests might call it during context creation
|
|
108
|
-
updateBlock: rootContext.updateBlock,
|
|
109
|
-
urlQuery: rootContext.urlQuery,
|
|
110
|
-
window: rootContext.window,
|
|
111
|
-
updateListeners: new Set()
|
|
44
|
+
const { id } = config;
|
|
45
|
+
if (lowdefy.contexts[id] && !resetContext.reset) {
|
|
46
|
+
// memoize context if already created, eg between page transitions, unless the reset flag is raised
|
|
47
|
+
lowdefy.contexts[id]._internal.update();
|
|
48
|
+
return lowdefy.contexts[id];
|
|
49
|
+
}
|
|
50
|
+
resetContext.setReset(false); // lower context reset flag.
|
|
51
|
+
if (!lowdefy.inputs[id]) {
|
|
52
|
+
lowdefy.inputs[id] = {};
|
|
53
|
+
}
|
|
54
|
+
const ctx = {
|
|
55
|
+
id,
|
|
56
|
+
pageId: config.pageId,
|
|
57
|
+
eventLog: [],
|
|
58
|
+
requests: {},
|
|
59
|
+
state: {},
|
|
60
|
+
_internal: {
|
|
61
|
+
lowdefy,
|
|
62
|
+
rootBlock: blockData(config),
|
|
63
|
+
update: ()=>{}
|
|
64
|
+
}
|
|
112
65
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
66
|
+
const _internal = ctx._internal;
|
|
67
|
+
_internal.parser = new WebParser({
|
|
68
|
+
context: ctx,
|
|
69
|
+
operators: lowdefy._internal.operators
|
|
117
70
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
71
|
+
_internal.State = new State(ctx);
|
|
72
|
+
_internal.Actions = new Actions(ctx);
|
|
73
|
+
_internal.Requests = new Requests(ctx);
|
|
74
|
+
_internal.RootBlocks = new Blocks({
|
|
75
|
+
areas: {
|
|
76
|
+
root: {
|
|
77
|
+
blocks: [
|
|
78
|
+
_internal.rootBlock
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
context: ctx
|
|
128
83
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (!
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
84
|
+
_internal.RootBlocks.init();
|
|
85
|
+
_internal.update = ()=>{
|
|
86
|
+
_internal.RootBlocks.update();
|
|
87
|
+
};
|
|
88
|
+
_internal.runOnInit = async (progress)=>{
|
|
89
|
+
progress();
|
|
90
|
+
if (!_internal.onInitDone) {
|
|
91
|
+
await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
|
92
|
+
name: 'onInit',
|
|
93
|
+
progress
|
|
94
|
+
});
|
|
95
|
+
_internal.update();
|
|
96
|
+
_internal.State.freezeState();
|
|
97
|
+
_internal.onInitDone = true;
|
|
139
98
|
}
|
|
140
|
-
});
|
|
141
99
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
100
|
+
_internal.runOnInitAsync = async (progress)=>{
|
|
101
|
+
if (_internal.onInitDone && !_internal.onInitAsyncDone) {
|
|
102
|
+
await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
|
103
|
+
name: 'onInitAsync',
|
|
104
|
+
progress
|
|
105
|
+
});
|
|
106
|
+
_internal.onInitAsyncDone = true;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
ctx._internal.update();
|
|
110
|
+
lowdefy.contexts[id] = ctx;
|
|
151
111
|
return ctx;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return function getContext(_x) {
|
|
155
|
-
return _ref3.apply(this, arguments);
|
|
156
|
-
};
|
|
157
|
-
}();
|
|
158
|
-
|
|
159
|
-
var _default = getContext;
|
|
160
|
-
exports.default = _default;
|
|
112
|
+
}
|
|
113
|
+
export default getContext;
|
package/dist/index.js
CHANGED
|
@@ -1,64 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Actions", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _Actions.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "BlockActions", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _BlockActions.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "Blocks", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return _Blocks.default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "makeContextId", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function get() {
|
|
27
|
-
return _makeContextId.default;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "Requests", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function get() {
|
|
33
|
-
return _Requests.default;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "State", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function get() {
|
|
39
|
-
return _State.default;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
exports.default = void 0;
|
|
43
|
-
|
|
44
|
-
var _Actions = _interopRequireDefault(require("./Actions"));
|
|
45
|
-
|
|
46
|
-
var _BlockActions = _interopRequireDefault(require("./BlockActions"));
|
|
47
|
-
|
|
48
|
-
var _Blocks = _interopRequireDefault(require("./Blocks"));
|
|
49
|
-
|
|
50
|
-
var _makeContextId = _interopRequireDefault(require("./makeContextId"));
|
|
51
|
-
|
|
52
|
-
var _Requests = _interopRequireDefault(require("./Requests"));
|
|
53
|
-
|
|
54
|
-
var _State = _interopRequireDefault(require("./State"));
|
|
55
|
-
|
|
56
|
-
var _getContext = _interopRequireDefault(require("./getContext"));
|
|
57
|
-
|
|
58
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
|
-
|
|
60
1
|
/*
|
|
61
|
-
Copyright 2020 Lowdefy, Inc
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
62
3
|
|
|
63
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
5
|
you may not use this file except in compliance with the License.
|
|
@@ -71,6 +12,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
71
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
13
|
See the License for the specific language governing permissions and
|
|
73
14
|
limitations under the License.
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
|
|
15
|
+
*/ import Actions from './Actions.js';
|
|
16
|
+
import Events from './Events.js';
|
|
17
|
+
import Blocks from './Blocks.js';
|
|
18
|
+
import createLink from './createLink.js';
|
|
19
|
+
import Requests from './Requests.js';
|
|
20
|
+
import State from './State.js';
|
|
21
|
+
import getContext from './getContext.js';
|
|
22
|
+
export { Actions, Events, Blocks, createLink, Requests, State };
|
|
23
|
+
export default getContext;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/engine",
|
|
3
|
-
"version": "0.0.0-
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-experimental-20231123101256",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"lowdefy"
|
|
9
|
+
],
|
|
7
10
|
"bugs": {
|
|
8
11
|
"url": "https://github.com/lowdefy/lowdefy/issues"
|
|
9
12
|
},
|
|
@@ -21,34 +24,32 @@
|
|
|
21
24
|
"type": "git",
|
|
22
25
|
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
23
26
|
},
|
|
24
|
-
"
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": "./dist/index.js",
|
|
25
29
|
"files": [
|
|
26
30
|
"dist/*"
|
|
27
31
|
],
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "babel src --out-dir dist",
|
|
30
|
-
"clean": "rm -rf dist",
|
|
31
|
-
"npm-publish": "npm publish --access public",
|
|
32
|
-
"prepare": "yarn build",
|
|
33
|
-
"prepublishOnly": "yarn build",
|
|
34
|
-
"test:watch": "jest --coverage --watch",
|
|
35
|
-
"test": "jest --coverage",
|
|
36
|
-
"version:prerelease": "yarn version prerelease",
|
|
37
|
-
"version:patch": "yarn version patch",
|
|
38
|
-
"version:minor": "yarn version minor",
|
|
39
|
-
"version:major": "yarn version major"
|
|
40
|
-
},
|
|
41
32
|
"dependencies": {
|
|
42
|
-
"@lowdefy/helpers": "
|
|
43
|
-
"@lowdefy/operators": "
|
|
44
|
-
"graphql": "15.4.0",
|
|
45
|
-
"graphql-tag": "2.11.0"
|
|
33
|
+
"@lowdefy/helpers": "0.0.0-experimental-20231123101256",
|
|
34
|
+
"@lowdefy/operators": "0.0.0-experimental-20231123101256"
|
|
46
35
|
},
|
|
47
36
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
37
|
+
"@jest/globals": "28.1.3",
|
|
38
|
+
"@lowdefy/actions-core": "0.0.0-experimental-20231123101256",
|
|
39
|
+
"@lowdefy/build": "0.0.0-experimental-20231123101256",
|
|
40
|
+
"@lowdefy/operators-js": "0.0.0-experimental-20231123101256",
|
|
41
|
+
"@lowdefy/operators-mql": "0.0.0-experimental-20231123101256",
|
|
42
|
+
"@swc/cli": "0.1.63",
|
|
43
|
+
"@swc/core": "1.3.99",
|
|
44
|
+
"@swc/jest": "0.2.29",
|
|
45
|
+
"jest": "28.1.3"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
|
52
|
+
"clean": "rm -rf dist",
|
|
53
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
+
}
|