@lowdefy/engine 3.23.0-alpha.0 → 4.0.0-alpha.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.
@@ -1,12 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
1
  /*
11
2
  Copyright 2020-2021 Lowdefy, Inc
12
3
 
@@ -21,55 +12,52 @@ var _helpers = require("@lowdefy/helpers");
21
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
13
  See the License for the specific language governing permissions and
23
14
  limitations under the License.
24
- */
25
- var getBlockMatcher = params => {
26
- var testParams = params;
27
- if (_helpers.type.isNone(testParams)) return () => true;
28
-
29
- if (_helpers.type.isString(testParams)) {
30
- testParams = {
31
- blockIds: [testParams]
32
- };
33
- }
34
-
35
- if (_helpers.type.isArray(testParams) || _helpers.type.isBoolean(testParams)) {
36
- testParams = {
37
- blockIds: testParams
38
- };
39
- }
40
-
41
- if (!_helpers.type.isObject(testParams)) {
42
- throw new Error('Invalid validate params.');
43
- }
44
-
45
- if (_helpers.type.isString(testParams.blockIds)) {
46
- testParams.blockIds = [testParams.blockIds];
47
- }
48
-
49
- if (_helpers.type.isString(testParams.regex)) {
50
- testParams.regex = [testParams.regex];
51
- }
52
-
53
- if (_helpers.type.isArray(testParams.regex)) {
54
- testParams.regex = testParams.regex.map(regex => new RegExp(regex));
55
- }
56
-
57
- return id => {
58
- if (testParams.blockIds === true || _helpers.type.isArray(testParams.blockIds) && testParams.blockIds.includes(id)) {
59
- return true;
15
+ */ import { type } from '@lowdefy/helpers';
16
+ const getBlockMatcher = (params)=>{
17
+ let testParams = params;
18
+ if (type.isNone(testParams)) return ()=>true
19
+ ;
20
+ if (type.isString(testParams)) {
21
+ testParams = {
22
+ blockIds: [
23
+ testParams
24
+ ]
25
+ };
60
26
  }
61
-
62
- if (_helpers.type.isArray(testParams.regex)) {
63
- for (var regex of testParams.regex) {
64
- if (regex.test(id)) {
65
- return true;
66
- }
67
- }
27
+ if (type.isArray(testParams) || type.isBoolean(testParams)) {
28
+ testParams = {
29
+ blockIds: testParams
30
+ };
68
31
  }
69
-
70
- return false;
71
- };
32
+ if (!type.isObject(testParams)) {
33
+ throw new Error('Invalid validate params.');
34
+ }
35
+ if (type.isString(testParams.blockIds)) {
36
+ testParams.blockIds = [
37
+ testParams.blockIds
38
+ ];
39
+ }
40
+ if (type.isString(testParams.regex)) {
41
+ testParams.regex = [
42
+ testParams.regex
43
+ ];
44
+ }
45
+ if (type.isArray(testParams.regex)) {
46
+ testParams.regex = testParams.regex.map((regex)=>new RegExp(regex)
47
+ );
48
+ }
49
+ return (id)=>{
50
+ if (testParams.blockIds === true || type.isArray(testParams.blockIds) && testParams.blockIds.includes(id)) {
51
+ return true;
52
+ }
53
+ if (type.isArray(testParams.regex)) {
54
+ for (const regex of testParams.regex){
55
+ if (regex.test(id)) {
56
+ return true;
57
+ }
58
+ }
59
+ }
60
+ return false;
61
+ };
72
62
  };
73
-
74
- var _default = getBlockMatcher;
75
- exports.default = _default;
63
+ export default getBlockMatcher;
@@ -1,151 +1,109 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _operators = require("@lowdefy/operators");
9
-
10
- var _Actions = _interopRequireDefault(require("./Actions"));
11
-
12
- var _Blocks = _interopRequireDefault(require("./Blocks"));
13
-
14
- var _Requests = _interopRequireDefault(require("./Requests"));
15
-
16
- var _State = _interopRequireDefault(require("./State"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
-
22
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
-
24
- var blockData = _ref => {
25
- var {
26
- areas,
27
- blockId,
28
- blocks,
29
- events,
30
- field,
31
- id,
32
- layout,
33
- meta,
34
- operators,
35
- pageId,
36
- properties,
37
- requests,
38
- required,
39
- style,
40
- type,
41
- validate,
42
- visible
43
- } = _ref;
44
- return {
45
- areas,
46
- blockId,
47
- blocks,
48
- events,
49
- field,
50
- id,
51
- layout,
52
- meta,
53
- operators,
54
- pageId,
55
- properties,
56
- requests,
57
- required,
58
- style,
59
- type,
60
- validate,
61
- visible
62
- };
63
- };
64
-
65
- var getContext = /*#__PURE__*/function () {
66
- var _ref3 = _asyncToGenerator(function* (_ref2) {
67
- var {
68
- block,
69
- contextId,
70
- lowdefy
71
- } = _ref2;
72
-
73
- if (lowdefy.contexts[contextId]) {
74
- lowdefy.contexts[contextId].update();
75
- return lowdefy.contexts[contextId];
1
+ /*
2
+ Copyright 2020-2021 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 , meta , operators , pageId , properties , requests , required , style , type , validate , visible , })=>({
21
+ areas,
22
+ blockId,
23
+ blocks,
24
+ events,
25
+ field,
26
+ id,
27
+ layout,
28
+ meta,
29
+ operators,
30
+ pageId,
31
+ properties,
32
+ requests,
33
+ required,
34
+ style,
35
+ type,
36
+ validate,
37
+ visible
38
+ })
39
+ ;
40
+ async function getContext({ config , lowdefy }) {
41
+ if (!config) {
42
+ throw new Error('A page must be provided to get context.');
76
43
  }
77
-
78
- if (!block) {
79
- throw new Error('A block must be provided to get context.');
80
- } // eslint-disable-next-line no-param-reassign
81
-
82
-
83
- if (!lowdefy.inputs[contextId]) {
84
- lowdefy.inputs[contextId] = {};
44
+ const { id } = config;
45
+ if (lowdefy.contexts[id]) {
46
+ lowdefy.contexts[id]._internal.update();
47
+ return lowdefy.contexts[id];
85
48
  }
86
-
87
- var operatorsSet = new Set([...block.operators, '_not', '_type']);
88
- lowdefy.contexts[contextId] = {
89
- id: contextId,
90
- blockId: block.blockId,
91
- eventLog: [],
92
- requests: {},
93
- operators: [...operatorsSet],
94
- lowdefy,
95
- pageId: lowdefy.pageId,
96
- rootBlock: blockData(block),
97
- // filter block to prevent circular structure
98
- state: {},
99
- update: () => {},
100
- // Initialize update since Requests might call it during context creation
101
- updateListeners: new Set()
49
+ if (!lowdefy.inputs[id]) {
50
+ lowdefy.inputs[id] = {
51
+ };
52
+ }
53
+ const operatorsSet = new Set([
54
+ ...config.operators,
55
+ '_not',
56
+ '_type'
57
+ ]);
58
+ const ctx = {
59
+ id: id,
60
+ pageId: config.pageId,
61
+ eventLog: [],
62
+ requests: {
63
+ },
64
+ state: {
65
+ },
66
+ _internal: {
67
+ lowdefy,
68
+ operators: [
69
+ ...operatorsSet
70
+ ],
71
+ rootBlock: blockData(config),
72
+ update: ()=>{
73
+ }
74
+ }
102
75
  };
103
- var ctx = lowdefy.contexts[contextId];
104
- ctx.parser = new _operators.WebParser({
105
- context: ctx,
106
- contexts: lowdefy.contexts
76
+ const _internal = ctx._internal;
77
+ _internal.parser = new WebParser({
78
+ context: ctx
107
79
  });
108
- yield ctx.parser.init();
109
- ctx.State = new _State.default(ctx);
110
- ctx.Actions = new _Actions.default(ctx);
111
- ctx.Requests = new _Requests.default(ctx);
112
- ctx.RootBlocks = new _Blocks.default({
113
- areas: {
114
- root: {
115
- blocks: [ctx.rootBlock]
116
- }
117
- },
118
- context: ctx
80
+ await _internal.parser.init();
81
+ _internal.State = new State(ctx);
82
+ _internal.Actions = new Actions(ctx);
83
+ _internal.Requests = new Requests(ctx);
84
+ _internal.RootBlocks = new Blocks({
85
+ areas: {
86
+ root: {
87
+ blocks: [
88
+ _internal.rootBlock
89
+ ]
90
+ }
91
+ },
92
+ context: ctx
119
93
  });
120
- ctx.RootBlocks.init();
121
-
122
- ctx.update = () => {
123
- ctx.RootBlocks.update();
124
- [...ctx.updateListeners].forEach(listenId => {
125
- // Will loop infinitely if update is called on self
126
- if (!lowdefy.contexts[listenId] || listenId === contextId) {
127
- ctx.updateListeners.delete(listenId);
128
- } else {
129
- lowdefy.contexts[listenId].update();
130
- }
131
- });
94
+ _internal.RootBlocks.init();
95
+ _internal.update = ()=>{
96
+ _internal.RootBlocks.update();
132
97
  };
133
-
134
- yield ctx.RootBlocks.map[ctx.blockId].triggerEvent({
135
- name: 'onInit'
98
+ await _internal.RootBlocks.map[ctx.id].triggerEvent({
99
+ name: 'onInit'
136
100
  });
137
- ctx.update();
138
- ctx.State.freezeState();
139
- ctx.RootBlocks.map[ctx.blockId].triggerEvent({
140
- name: 'onInitAsync'
101
+ _internal.update();
102
+ _internal.State.freezeState();
103
+ _internal.RootBlocks.map[ctx.id].triggerEvent({
104
+ name: 'onInitAsync'
141
105
  });
106
+ lowdefy.contexts[id] = ctx;
142
107
  return ctx;
143
- });
144
-
145
- return function getContext(_x) {
146
- return _ref3.apply(this, arguments);
147
- };
148
- }();
149
-
150
- var _default = getContext;
151
- exports.default = _default;
108
+ }
109
+ export default getContext;
@@ -1,12 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
1
  /*
11
2
  Copyright 2020-2021 Lowdefy, Inc
12
3
 
@@ -21,29 +12,24 @@ var _helpers = require("@lowdefy/helpers");
21
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
13
  See the License for the specific language governing permissions and
23
14
  limitations under the License.
24
- */
25
- function getFieldValues(operatorName) {
26
- var result = new Set();
27
-
28
- function reviver(key, value) {
29
- if (key === operatorName) {
30
- result.add(value);
15
+ */ import { serializer } from '@lowdefy/helpers';
16
+ function getFieldValues(operatorName, ...args) {
17
+ const result = new Set();
18
+ function reviver(key, value) {
19
+ if (key === operatorName) {
20
+ result.add(value);
21
+ }
22
+ return value;
31
23
  }
32
-
33
- return value;
34
- }
35
-
36
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
37
- args[_key - 1] = arguments[_key];
38
- }
39
-
40
- [...args].forEach(element => {
41
- _helpers.serializer.deserializeFromString(_helpers.serializer.serializeToString(element), {
42
- reviver
24
+ [
25
+ ...args
26
+ ].forEach((element)=>{
27
+ serializer.deserializeFromString(serializer.serializeToString(element), {
28
+ reviver
29
+ });
43
30
  });
44
- });
45
- return [...result];
31
+ return [
32
+ ...result
33
+ ];
46
34
  }
47
-
48
- var _default = getFieldValues;
49
- exports.default = _default;
35
+ export default getFieldValues;
package/dist/index.js CHANGED
@@ -1,70 +1,3 @@
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, "Events", {
13
- enumerable: true,
14
- get: function get() {
15
- return _Events.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, "createLink", {
25
- enumerable: true,
26
- get: function get() {
27
- return _createLink.default;
28
- }
29
- });
30
- Object.defineProperty(exports, "makeContextId", {
31
- enumerable: true,
32
- get: function get() {
33
- return _makeContextId.default;
34
- }
35
- });
36
- Object.defineProperty(exports, "Requests", {
37
- enumerable: true,
38
- get: function get() {
39
- return _Requests.default;
40
- }
41
- });
42
- Object.defineProperty(exports, "State", {
43
- enumerable: true,
44
- get: function get() {
45
- return _State.default;
46
- }
47
- });
48
- exports.default = void 0;
49
-
50
- var _Actions = _interopRequireDefault(require("./Actions"));
51
-
52
- var _Events = _interopRequireDefault(require("./Events"));
53
-
54
- var _Blocks = _interopRequireDefault(require("./Blocks"));
55
-
56
- var _createLink = _interopRequireDefault(require("./createLink"));
57
-
58
- var _makeContextId = _interopRequireDefault(require("./makeContextId"));
59
-
60
- var _Requests = _interopRequireDefault(require("./Requests"));
61
-
62
- var _State = _interopRequireDefault(require("./State"));
63
-
64
- var _getContext = _interopRequireDefault(require("./getContext"));
65
-
66
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
67
-
68
1
  /*
69
2
  Copyright 2020-2021 Lowdefy, Inc
70
3
 
@@ -79,6 +12,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
79
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80
13
  See the License for the specific language governing permissions and
81
14
  limitations under the License.
82
- */
83
- var _default = _getContext.default;
84
- exports.default = _default;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/engine",
3
- "version": "3.23.0-alpha.0",
3
+ "version": "4.0.0-alpha.4",
4
4
  "licence": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -24,32 +24,31 @@
24
24
  "type": "git",
25
25
  "url": "https://github.com/lowdefy/lowdefy.git"
26
26
  },
27
- "main": "dist/index.js",
27
+ "type": "module",
28
+ "exports": "./dist/index.js",
28
29
  "files": [
29
30
  "dist/*"
30
31
  ],
31
32
  "scripts": {
32
- "build": "babel src --out-dir dist",
33
+ "build": "yarn swc",
33
34
  "clean": "rm -rf dist",
34
35
  "prepare": "yarn build",
36
+ "swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
35
37
  "test:watch": "jest --coverage --watch",
36
38
  "test": "jest --coverage"
37
39
  },
38
40
  "dependencies": {
39
- "@lowdefy/helpers": "3.23.0-alpha.0",
40
- "@lowdefy/operators": "3.23.0-alpha.0",
41
- "graphql": "15.5.0",
42
- "graphql-tag": "2.12.4"
41
+ "@lowdefy/helpers": "4.0.0-alpha.4",
42
+ "@lowdefy/operators": "4.0.0-alpha.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@babel/cli": "7.14.3",
46
- "@babel/core": "7.14.3",
47
- "@babel/preset-env": "7.14.4",
48
- "babel-jest": "26.6.3",
49
- "jest": "26.6.3"
45
+ "@swc/cli": "0.1.52",
46
+ "@swc/core": "1.2.112",
47
+ "@swc/jest": "0.2.9",
48
+ "jest": "27.3.1"
50
49
  },
51
50
  "publishConfig": {
52
51
  "access": "public"
53
52
  },
54
- "gitHead": "8a2b43f5906ff3fbe50237f706c0daec3a480fca"
53
+ "gitHead": "537d166ba3f6e017b8a61c2a7e5c12fd0a48bf67"
55
54
  }
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
- /*
11
- Copyright 2020-2021 Lowdefy, Inc
12
-
13
- Licensed under the Apache License, Version 2.0 (the "License");
14
- you may not use this file except in compliance with the License.
15
- You may obtain a copy of the License at
16
-
17
- http://www.apache.org/licenses/LICENSE-2.0
18
-
19
- Unless required by applicable law or agreed to in writing, software
20
- distributed under the License is distributed on an "AS IS" BASIS,
21
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- See the License for the specific language governing permissions and
23
- limitations under the License.
24
- */
25
- function makeContextId(_ref) {
26
- var {
27
- blockId,
28
- pageId,
29
- urlQuery = {}
30
- } = _ref;
31
-
32
- if (!_helpers.type.isString(blockId)) {
33
- throw new Error("Expected string for parameter blockId, received ".concat(blockId));
34
- }
35
-
36
- if (!_helpers.type.isString(pageId)) {
37
- throw new Error("Expected string for parameter pageId, received ".concat(pageId));
38
- }
39
-
40
- return "".concat(pageId, ":").concat(blockId, ":").concat(_helpers.serializer.serializeToString(urlQuery));
41
- }
42
-
43
- var _default = makeContextId;
44
- exports.default = _default;