@lowdefy/engine 0.0.0-alpha.7 → 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.
Files changed (40) hide show
  1. package/LICENSE +201 -0
  2. package/dist/Actions.js +231 -486
  3. package/dist/Blocks.js +563 -572
  4. package/dist/Events.js +126 -0
  5. package/dist/Requests.js +107 -134
  6. package/dist/State.js +56 -83
  7. package/dist/actions/createCallMethod.js +29 -0
  8. package/dist/actions/createDisplayMessage.js +20 -0
  9. package/dist/actions/createGetActions.js +27 -0
  10. package/dist/actions/createGetBlockId.js +20 -0
  11. package/dist/actions/createGetEvent.js +27 -0
  12. package/dist/actions/createGetGlobal.js +27 -0
  13. package/dist/actions/createGetInput.js +27 -0
  14. package/dist/actions/createGetPageId.js +20 -0
  15. package/dist/actions/createGetRequestDetails.js +27 -0
  16. package/dist/actions/createGetState.js +27 -0
  17. package/dist/actions/createGetUrlQuery.js +32 -0
  18. package/dist/actions/createGetUser.js +27 -0
  19. package/dist/actions/createLink.js +20 -0
  20. package/dist/actions/createLogin.js +20 -0
  21. package/dist/actions/createLogout.js +20 -0
  22. package/dist/actions/createRequest.js +26 -0
  23. package/dist/actions/createReset.js +22 -0
  24. package/dist/actions/createResetValidation.js +21 -0
  25. package/dist/actions/createSetGlobal.js +25 -0
  26. package/dist/actions/createSetState.js +25 -0
  27. package/dist/actions/createUpdateSession.js +20 -0
  28. package/dist/actions/createValidate.js +25 -0
  29. package/dist/actions/getActionMethods.js +63 -0
  30. package/dist/actions/getFromObject.js +42 -0
  31. package/dist/createLink.js +71 -0
  32. package/dist/getBlockMatcher.js +61 -0
  33. package/dist/getContext.js +106 -153
  34. package/dist/index.js +10 -63
  35. package/package.json +27 -26
  36. package/CHANGELOG.md +0 -38
  37. package/dist/BlockActions.js +0 -211
  38. package/dist/Mutations.js +0 -100
  39. package/dist/getFieldValues.js +0 -49
  40. 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;
@@ -1,160 +1,113 @@
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
- actions,
27
- areas,
28
- blockId,
29
- blocks,
30
- field,
31
- id,
32
- layout,
33
- meta,
34
- pageId,
35
- properties,
36
- requests,
37
- required,
38
- style,
39
- type,
40
- validate,
41
- visible
42
- } = _ref;
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 (!block) {
83
- throw new Error('A block must be provided to get context.');
84
- } // eslint-disable-next-line no-param-reassign
85
-
86
-
87
- rootContext.contexts[contextId] = {
88
- id: contextId,
89
- pageId,
90
- actionLog: [],
91
- blockId: block.blockId,
92
- client: rootContext.client,
93
- config: rootContext.config,
94
- displayMessage: rootContext.displayMessage,
95
- document: rootContext.document,
96
- input: rootContext.input[contextId] || {},
97
- allInputs: rootContext.input,
98
- lowdefyGlobal: rootContext.lowdefyGlobal,
99
- menus: rootContext.menus,
100
- requests: {},
101
- rootBlock: blockData(block),
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
- var ctx = rootContext.contexts[contextId];
114
- ctx.parser = new _operators.WebParser({
115
- context: ctx,
116
- contexts: rootContext.contexts
66
+ const _internal = ctx._internal;
67
+ _internal.parser = new WebParser({
68
+ context: ctx,
69
+ operators: lowdefy._internal.operators
117
70
  });
118
- ctx.State = new _State.default(ctx);
119
- ctx.Actions = new _Actions.default(ctx);
120
- ctx.Requests = new _Requests.default(ctx);
121
- ctx.RootBlocks = new _Blocks.default({
122
- areas: {
123
- root: {
124
- blocks: [ctx.rootBlock]
125
- }
126
- },
127
- context: ctx
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
- ctx.RootBlocks.init();
130
-
131
- ctx.update = () => {
132
- ctx.RootBlocks.update();
133
- [...ctx.updateListeners].forEach(listenId => {
134
- // Will loop infinitely if update is called on self
135
- if (!rootContext.contexts[listenId] || listenId === contextId) {
136
- ctx.updateListeners.delete(listenId);
137
- } else {
138
- rootContext.contexts[listenId].update();
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
- ctx.update();
144
- yield ctx.RootBlocks.map[ctx.blockId].callAction({
145
- action: 'onInit'
146
- });
147
- ctx.State.freezeState();
148
- ctx.RootBlocks.map[ctx.blockId].callAction({
149
- action: 'onInitAsync'
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
- var _default = _getContext.default;
76
- 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,9 +1,12 @@
1
1
  {
2
2
  "name": "@lowdefy/engine",
3
- "version": "0.0.0-alpha.7",
4
- "licence": "Apache-2.0",
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
- "main": "dist/index.js",
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": "1.2.0",
43
- "@lowdefy/operators": "1.1.0",
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
- "@babel/cli": "7.12.10",
49
- "@babel/core": "7.12.10",
50
- "@babel/preset-env": "7.12.10",
51
- "babel-jest": "26.6.3",
52
- "jest": "26.6.3"
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
+ }
package/CHANGELOG.md DELETED
@@ -1,38 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # 0.0.0-alpha.7 (2020-12-10)
7
-
8
-
9
- ### Bug Fixes
10
-
11
- * **blockTools:** remove registeredMethods ([b984e6f](https://github.com/lowdefy/lowdefy/commit/b984e6f5554a617d4d8d7e077e91619330d0eb4d))
12
- * **deps:** update dependency graphql to v15.4.0 ([24803a3](https://github.com/lowdefy/lowdefy/commit/24803a30d4fe6fb140c28891691fc1fab6537d5f))
13
- * **engine:** do not recreate actions on call ([58f6e8e](https://github.com/lowdefy/lowdefy/commit/58f6e8ed5698df4bb7f1853c75266d7264b7156a))
14
- * **engine:** minor bug fixes ([8937087](https://github.com/lowdefy/lowdefy/commit/8937087274bfba78d0433cada9a3d28c288fa0b7))
15
- * **engine:** remove defaultValue field ([a380aef](https://github.com/lowdefy/lowdefy/commit/a380aefea5b30077ab662d3abefd412e5b0695b8))
16
- * **engine:** replace graphql-tag dependency in engine ([370f69b](https://github.com/lowdefy/lowdefy/commit/370f69be4e91d0bbbb4a72f50abadbdfe8319e50))
17
- * **engine:** structured params for newBlocks ([1c5bd0c](https://github.com/lowdefy/lowdefy/commit/1c5bd0c4734d11767065a2bb605c59b947db4750))
18
- * **engine:** update tests ([4de3325](https://github.com/lowdefy/lowdefy/commit/4de332549a690c41b31944876dbf15d7f4a76a24))
19
- * **engine:** visible should evaluate only when not equal to false ([76e7f2a](https://github.com/lowdefy/lowdefy/commit/76e7f2a6589593bf0eaa3cecbf01214df9edf727))
20
- * **renderer:** fix useContext, split onEnter and get context ([6af60c6](https://github.com/lowdefy/lowdefy/commit/6af60c6703f0fc119d0b44b6328a2ad1e8278ba6))
21
- * build and test errors ([909b2bf](https://github.com/lowdefy/lowdefy/commit/909b2bf1250d26b1fd944811117770a35f187a09))
22
- * move engine related files from helpers to engine ([3b96ab7](https://github.com/lowdefy/lowdefy/commit/3b96ab7e0e651ca54a4861d90a9fe732a3d1fe21))
23
- * requests fixes ([0e7af60](https://github.com/lowdefy/lowdefy/commit/0e7af6093210a030129200c7abfe330c30cf1574))
24
- * use helpers from helpers ([ebe3738](https://github.com/lowdefy/lowdefy/commit/ebe373827d54f4009f5f246fef8be630e20ba4a7))
25
- * **renderer, engine:** move displayMessage to rootContext, update engine tests ([0f6339f](https://github.com/lowdefy/lowdefy/commit/0f6339f07d0b00aa86cce8c501ebae7fd6157ea7))
26
-
27
-
28
- ### Features
29
-
30
- * **engine:** init @lowdefy/engine package ([1604212](https://github.com/lowdefy/lowdefy/commit/160421241933611936321cdc64255a462384646a))
31
- * **engine:** refactor validation messages and only eval visible ([a507cc3](https://github.com/lowdefy/lowdefy/commit/a507cc3ccb3506013bf66a3f14cebeabb374d742))
32
- * **engine:** remove all empty objects from state as an effect of deleted values ([7cb2f2e](https://github.com/lowdefy/lowdefy/commit/7cb2f2e6fa6df1ed1ea4709c8567412602cce33e))
33
- * **engine:** remove mutations ([68f8578](https://github.com/lowdefy/lowdefy/commit/68f85789eba4979d6ee77332250e649482d5127c))
34
- * **engine:** validate action can be null = all, string = one or array = list of field names ([5a64c8b](https://github.com/lowdefy/lowdefy/commit/5a64c8b7b1dbf5594ec9865dd4a183cff8b8f018))
35
- * add Apache-2.0 license ([3e2064e](https://github.com/lowdefy/lowdefy/commit/3e2064eef02dd71bb8987f8e126f9bef6cb7d01b))
36
- * add type package ([d0c60c4](https://github.com/lowdefy/lowdefy/commit/d0c60c4bfab8ec9038f6cab67a87d658f6732dc9))
37
- * remove fetch requests on page load, add async load actions ([1f396d6](https://github.com/lowdefy/lowdefy/commit/1f396d62ef204de1cde5ddeea0abe0bcf0c898c0))
38
- * **engine, renderer:** move apollo cache block update to renderer ([778ff4a](https://github.com/lowdefy/lowdefy/commit/778ff4aa99ce986b4ad43629cec9e3b82bde714f))