@lowdefy/engine 4.0.0-alpha.9 → 4.0.0-rc.0

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/Actions.js CHANGED
@@ -165,6 +165,7 @@ let Actions = class Actions {
165
165
  });
166
166
  try {
167
167
  response = await this.actions[action.type]({
168
+ globals: this.context._internal.lowdefy._internal.globals,
168
169
  methods: getActionMethods({
169
170
  actions: responses,
170
171
  arrayIndices,
@@ -172,9 +173,7 @@ let Actions = class Actions {
172
173
  context: this.context,
173
174
  event
174
175
  }),
175
- document: this.context._internal.lowdefy._internal.document,
176
- params: parsedAction.params,
177
- window: this.context._internal.lowdefy._internal.window
176
+ params: parsedAction.params
178
177
  });
179
178
  if (progress) {
180
179
  progress();
@@ -227,8 +226,7 @@ let Actions = class Actions {
227
226
  };
228
227
  }
229
228
  displayMessage({ defaultMessage , duration , hideExplicitly , message , status }) {
230
- let close = ()=>undefined
231
- ;
229
+ let close = ()=>undefined;
232
230
  if (hideExplicitly && message !== false || !hideExplicitly && !type.isNone(message)) {
233
231
  close = this.context._internal.lowdefy._internal.displayMessage({
234
232
  content: type.isString(message) ? message : defaultMessage,
package/dist/Blocks.js CHANGED
@@ -28,11 +28,13 @@ let Blocks = class Blocks {
28
28
  this.loopBlocks((block)=>{
29
29
  block.idPattern = block.id;
30
30
  block.blockIdPattern = block.blockId;
31
- block.fieldPattern = block.field;
32
31
  block.id = applyArrayIndices(this.arrayIndices, block.idPattern);
33
32
  block.blockId = applyArrayIndices(this.arrayIndices, block.blockIdPattern);
34
- block.field = !type.isNone(block.fieldPattern) ? applyArrayIndices(this.arrayIndices, block.fieldPattern) : block.blockId;
35
- this.context._internal.RootBlocks.map[block.id] = block;
33
+ // CAUTION:
34
+ // map is not a direct reference to all blocks, blocks with duplicate ids will be overwritten in map
35
+ // which can cause issues with ambiguous config during call method since it will call only the method
36
+ // of the last initialized block for the referenced id.
37
+ this.context._internal.RootBlocks.map[block.blockId] = block;
36
38
  block.events = type.isNone(block.events) ? {} : block.events;
37
39
  block.layout = type.isNone(block.layout) ? {} : block.layout;
38
40
  block.loading = type.isNone(block.loading) ? false : block.loading;
@@ -56,6 +58,9 @@ let Blocks = class Blocks {
56
58
  } catch (error) {
57
59
  throw new Error(`Block type ${block.type} not found at ${block.blockId}. Check your plugins to make sure the block is installed. For more info, see https://docs.lowdefy.com/plugins.`);
58
60
  }
61
+ if (block.meta?.category !== 'container' && block.meta?.category !== 'display' && block.meta?.category !== 'input' && block.meta?.category !== 'list') {
62
+ throw new Error(`Block type ${block.type}.meta.category must be either "container", "display", "input" or "list".`);
63
+ }
59
64
  if (!type.isNone(block.areas)) {
60
65
  block.areasLayout = {};
61
66
  Object.keys(block.areas).forEach((key)=>{
@@ -72,8 +77,7 @@ let Blocks = class Blocks {
72
77
  block.registerMethod = (methodName, method)=>{
73
78
  block.methods[methodName] = method;
74
79
  };
75
- // TODO: add callMethod on block to be used by actions and accessible in blocks
76
- if (get(block, 'meta.category') === 'list') {
80
+ if (block.meta.category === 'list') {
77
81
  // TODO: to initialize new object in array, the new value should be passed by method to unshiftItem and pushItem
78
82
  block.unshiftItem = ()=>{
79
83
  this.subBlocks[block.id].forEach((bl, i)=>{
@@ -90,7 +94,7 @@ let Blocks = class Blocks {
90
94
  block,
91
95
  initState: {}
92
96
  }));
93
- this.context._internal.State.set(block.field, undefined);
97
+ this.context._internal.State.set(block.blockId, undefined);
94
98
  // set block and subBlock values undefined, so as not to pass values to new blocks
95
99
  this.subBlocks[block.id][0].recSetUndefined();
96
100
  block.update = true;
@@ -158,10 +162,10 @@ let Blocks = class Blocks {
158
162
  this.context._internal.update();
159
163
  };
160
164
  }
161
- if (get(block, 'meta.category') === 'input') {
165
+ if (block.meta.category === 'input') {
162
166
  block.setValue = (value)=>{
163
167
  block.value = type.enforceType(block.meta.valueType, value);
164
- this.context._internal.State.set(block.field, block.value);
168
+ this.context._internal.State.set(block.blockId, block.value);
165
169
  block.update = true;
166
170
  this.context._internal.update();
167
171
  };
@@ -181,14 +185,14 @@ let Blocks = class Blocks {
181
185
  this.loopBlocks((block)=>{
182
186
  block.update = true;
183
187
  block.showValidation = false;
184
- if (get(block, 'meta.category') === 'input' || get(block, 'meta.category') === 'list') {
185
- let blockValue = get(initState, block.field);
188
+ if (block.meta.category === 'input' || block.meta.category === 'list') {
189
+ let blockValue = get(initState, block.blockId);
186
190
  if (type.isUndefined(blockValue)) {
187
191
  // default null value for block type
188
192
  blockValue = type.isUndefined(block.meta.initValue) ? type.enforceType(block.meta.valueType, null) : block.meta.initValue;
189
- this.context._internal.State.set(block.field, block.value);
193
+ this.context._internal.State.set(block.blockId, block.value);
190
194
  }
191
- if (get(block, 'meta.category') === 'list') {
195
+ if (block.meta.category === 'list') {
192
196
  // load list value into list blocks
193
197
  if (!type.isArray(this.subBlocks[block.id])) {
194
198
  this.subBlocks[block.id] = [];
@@ -212,7 +216,7 @@ let Blocks = class Blocks {
212
216
  } else {
213
217
  block.value = blockValue;
214
218
  }
215
- } else if (get(block, 'meta.category') === 'container') {
219
+ } else if (block.meta.category === 'container') {
216
220
  if (!type.isArray(this.subBlocks[block.id])) {
217
221
  this.subBlocks[block.id] = [];
218
222
  }
@@ -256,7 +260,7 @@ let Blocks = class Blocks {
256
260
  let repeat = false;
257
261
  this.loopBlocks((block)=>{
258
262
  if (block.meta.category === 'input') {
259
- const stateValue = get(this.context.state, block.field);
263
+ const stateValue = get(this.context.state, block.blockId);
260
264
  // TODO: related to #345
261
265
  // enforce type here? should we reassign value here??
262
266
  block.value = type.isUndefined(stateValue) ? block.value : stateValue;
@@ -370,7 +374,7 @@ let Blocks = class Blocks {
370
374
  arrayIndices: this.arrayIndices
371
375
  });
372
376
  }
373
- if (get(block, 'meta.category') === 'container' || get(block, 'meta.category') === 'list') {
377
+ if (block.meta.category === 'container' || block.meta.category === 'list') {
374
378
  if (this.subBlocks[block.id] && this.subBlocks[block.id].length > 0) {
375
379
  this.subBlocks[block.id].forEach((blockClass)=>{
376
380
  repeat = blockClass.recEval(block.visibleEval.output) || repeat;
@@ -390,25 +394,25 @@ let Blocks = class Blocks {
390
394
  const toDelete = new Set();
391
395
  this.loopBlocks((block)=>{
392
396
  if (block.visibleEval.output !== false) {
393
- if (get(block, 'meta.category') === 'container' || get(block, 'meta.category') === 'list') {
397
+ if (block.meta.category === 'container' || block.meta.category === 'list') {
394
398
  if (this.subBlocks[block.id] && this.subBlocks[block.id].length > 0) {
395
399
  this.subBlocks[block.id].forEach((blockClass)=>{
396
400
  blockClass.updateState();
397
401
  });
398
402
  } else {
399
- toSet.add(block.field);
400
- this.context._internal.State.set(block.field, type.enforceType(block.meta.valueType, null));
403
+ toSet.add(block.blockId);
404
+ this.context._internal.State.set(block.blockId, type.enforceType(block.meta.valueType, null));
401
405
  }
402
- } else if (get(block, 'meta.category') === 'input') {
403
- toSet.add(block.field);
404
- this.context._internal.State.set(block.field, block.value);
406
+ } else if (block.meta.category === 'input') {
407
+ toSet.add(block.blockId);
408
+ this.context._internal.State.set(block.blockId, block.value);
405
409
  }
406
- } else if (get(block, 'meta.category') === 'container') {
410
+ } else if (block.meta.category === 'container') {
407
411
  this.subBlocks[block.id].forEach((blockClass)=>{
408
412
  blockClass.recContainerDelState(toDelete);
409
413
  });
410
414
  } else {
411
- toDelete.add(block.field);
415
+ toDelete.add(block.blockId);
412
416
  }
413
417
  });
414
418
  toDelete.forEach((field)=>{
@@ -419,12 +423,12 @@ let Blocks = class Blocks {
419
423
  }
420
424
  recContainerDelState(toDelete) {
421
425
  this.loopBlocks((block)=>{
422
- if (get(block, 'meta.category') === 'container') {
426
+ if (block.meta.category === 'container') {
423
427
  this.subBlocks[block.id].forEach((blockClass)=>{
424
428
  blockClass.recContainerDelState(toDelete);
425
429
  });
426
430
  } else {
427
- toDelete.add(block.field);
431
+ toDelete.add(block.blockId);
428
432
  }
429
433
  });
430
434
  }
@@ -444,7 +448,6 @@ let Blocks = class Blocks {
444
448
  this.loopBlocks((block)=>{
445
449
  block.blockId = applyArrayIndices(this.arrayIndices, block.blockIdPattern);
446
450
  this.context._internal.RootBlocks.map[block.blockId] = block;
447
- block.field = !type.isNone(block.fieldPattern) ? applyArrayIndices(this.arrayIndices, block.fieldPattern) : block.blockId;
448
451
  });
449
452
  Object.keys(this.subBlocks).forEach((subKey)=>{
450
453
  this.subBlocks[subKey].forEach((subBlock)=>{
@@ -474,7 +477,7 @@ let Blocks = class Blocks {
474
477
  }
475
478
  recSetUndefined() {
476
479
  this.loopBlocks((block)=>{
477
- this.context._internal.State.set(block.field, undefined);
480
+ this.context._internal.State.set(block.blockId, undefined);
478
481
  });
479
482
  Object.keys(this.subBlocks).forEach((subKey)=>{
480
483
  this.subBlocks[subKey].forEach((subBlock)=>{
@@ -548,10 +551,10 @@ let Blocks = class Blocks {
548
551
  });
549
552
  });
550
553
  }
551
- constructor({ arrayIndices , areas , context }){
554
+ constructor({ arrayIndices =[] , areas , context }){
552
555
  this.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
553
556
  this.areas = serializer.copy(areas || []);
554
- this.arrayIndices = type.isArray(arrayIndices) ? arrayIndices : [];
557
+ this.arrayIndices = arrayIndices;
555
558
  this.context = context;
556
559
  this.map = {};
557
560
  this.recCount = 0;
package/dist/Requests.js CHANGED
@@ -14,82 +14,85 @@
14
14
  limitations under the License.
15
15
  */ import { get, serializer, type } from '@lowdefy/helpers';
16
16
  let Requests = class Requests {
17
- callRequests({ actions , arrayIndices , event , params } = {}) {
17
+ callRequests({ actions , arrayIndices , blockId , event , params } = {}) {
18
18
  if (type.isObject(params) && params.all === true) {
19
19
  return Promise.all(Object.keys(this.requestConfig).map((requestId)=>this.callRequest({
20
- requestId,
20
+ arrayIndices,
21
+ blockId,
21
22
  event,
22
- arrayIndices
23
- })
24
- ));
23
+ requestId
24
+ })));
25
25
  }
26
26
  let requestIds = [];
27
27
  if (type.isString(params)) requestIds = [
28
28
  params
29
29
  ];
30
30
  if (type.isArray(params)) requestIds = params;
31
- return Promise.all(requestIds.map((requestId)=>this.callRequest({
31
+ const requests = requestIds.map((requestId)=>this.callRequest({
32
32
  actions,
33
33
  requestId,
34
+ blockId,
34
35
  event,
35
36
  arrayIndices
36
- })
37
- ));
37
+ }));
38
+ this.context._internal.update(); // update to render request reset
39
+ return Promise.all(requests);
38
40
  }
39
- callRequest({ actions , arrayIndices , event , requestId }) {
40
- const request = this.requestConfig[requestId];
41
- if (!request) {
41
+ async callRequest({ actions , arrayIndices , blockId , event , requestId }) {
42
+ const requestConfig = this.requestConfig[requestId];
43
+ if (!this.context.requests[requestId]) {
44
+ this.context.requests[requestId] = [];
45
+ }
46
+ if (!requestConfig) {
42
47
  const error = new Error(`Configuration Error: Request ${requestId} not defined on page.`);
43
- this.context.requests[requestId] = {
48
+ this.context.requests[requestId].unshift({
49
+ blockId: 'block_id',
50
+ error,
44
51
  loading: false,
45
- response: null,
46
- error: [
47
- error
48
- ]
49
- };
50
- return Promise.reject(error);
51
- }
52
- if (!this.context.requests[requestId]) {
53
- this.context.requests[requestId] = {
54
- loading: true,
55
- response: null,
56
- error: []
57
- };
52
+ requestId,
53
+ response: null
54
+ });
55
+ throw error;
58
56
  }
59
57
  const { output: payload , errors: parserErrors } = this.context._internal.parser.parse({
60
58
  actions,
61
59
  event,
62
60
  arrayIndices,
63
- input: request.payload,
61
+ input: requestConfig.payload,
64
62
  location: requestId
65
63
  });
66
- // TODO: We are throwing this error differently to the request does not exist error
67
64
  if (parserErrors.length > 0) {
68
65
  throw parserErrors[0];
69
66
  }
70
- return this.fetch({
67
+ const request = {
68
+ blockId,
69
+ loading: true,
70
+ payload,
71
71
  requestId,
72
- payload
73
- });
72
+ response: null
73
+ };
74
+ this.context.requests[requestId].unshift(request);
75
+ return this.fetch(request);
74
76
  }
75
- async fetch({ requestId , payload }) {
76
- this.context.requests[requestId].loading = true;
77
+ async fetch(request) {
78
+ request.loading = true;
77
79
  try {
78
80
  const response = await this.context._internal.lowdefy._internal.callRequest({
81
+ blockId: request.blockId,
79
82
  pageId: this.context.pageId,
80
- payload: serializer.serialize(payload),
81
- requestId
83
+ payload: serializer.serialize(request.payload),
84
+ requestId: request.requestId
82
85
  });
83
86
  const deserializedResponse = serializer.deserialize(get(response, 'response', {
84
87
  default: null
85
88
  }));
86
- this.context.requests[requestId].response = deserializedResponse;
87
- this.context.requests[requestId].loading = false;
89
+ request.response = deserializedResponse;
90
+ request.loading = false;
88
91
  this.context._internal.update();
89
92
  return deserializedResponse;
90
93
  } catch (error) {
91
- this.context.requests[requestId].error.unshift(error);
92
- this.context.requests[requestId].loading = false;
94
+ request.error = error;
95
+ request.loading = false;
93
96
  this.context._internal.update();
94
97
  throw error;
95
98
  }
@@ -13,12 +13,17 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import getFromObject from './getFromObject.js';
16
+ import { urlQuery } from '@lowdefy/helpers';
16
17
  function createGetUrlQuery({ arrayIndices , blockId , context }) {
17
18
  return function getUrlQuery(params) {
19
+ const { window } = context._internal.lowdefy._internal.globals;
20
+ if (!window?.location) {
21
+ throw new Error(`Browser window.location not available for getUrlQuery. Received: ${JSON.stringify(params)} on blockId: ${blockId}.`);
22
+ }
18
23
  return getFromObject({
19
24
  arrayIndices,
20
25
  location: blockId,
21
- object: context._internal.lowdefy.urlQuery,
26
+ object: urlQuery.parse(window.location.search.slice(1)),
22
27
  method: 'getUrlQuery',
23
28
  params
24
29
  });
@@ -13,8 +13,8 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ function createLogout({ context }) {
16
- return function logout() {
17
- return context._internal.lowdefy._internal.auth.logout();
16
+ return function logout(params) {
17
+ return context._internal.lowdefy._internal.auth.logout(params);
18
18
  };
19
19
  }
20
20
  export default createLogout;
@@ -12,11 +12,12 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function createRequest({ actions , arrayIndices , context , event }) {
15
+ */ function createRequest({ actions , arrayIndices , blockId , context , event }) {
16
16
  return async function request(params) {
17
17
  return await context._internal.Requests.callRequests({
18
18
  actions,
19
19
  arrayIndices,
20
+ blockId,
20
21
  event,
21
22
  params
22
23
  });
@@ -17,7 +17,6 @@ function createReset({ context }) {
17
17
  return function reset() {
18
18
  context._internal.State.resetState();
19
19
  context._internal.RootBlocks.reset(serializer.deserializeFromString(context._internal.State.frozenState));
20
- context._internal.update();
21
20
  };
22
21
  }
23
22
  export default createReset;
@@ -16,7 +16,7 @@
16
16
  const createSetGlobal = ({ arrayIndices , context })=>{
17
17
  return function setGlobal(params) {
18
18
  Object.keys(params).forEach((key)=>{
19
- set(context._internal.lowdefy._internal.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
19
+ set(context._internal.lowdefy.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
20
20
  });
21
21
  context._internal.RootBlocks.reset();
22
22
  context._internal.update();
@@ -23,8 +23,7 @@ function createLink({ backLink , disabledLink , lowdefy , newOriginLink , noLink
23
23
  !props.back,
24
24
  !props.home,
25
25
  !props.url
26
- ].filter((v)=>!v
27
- ).length > 1) {
26
+ ].filter((v)=>!v).length > 1) {
28
27
  throw Error(`Invalid Link: To avoid ambiguity, only one of 'back', 'home', 'pageId' or 'url' can be defined.`);
29
28
  }
30
29
  if (props.back === true) {
@@ -39,7 +38,7 @@ function createLink({ backLink , disabledLink , lowdefy , newOriginLink , noLink
39
38
  pathname,
40
39
  query,
41
40
  setInput: ()=>{
42
- lowdefy.inputs[`page:${lowdefy.home.pageId}`] = props.input || {};
41
+ lowdefy.inputs[`page:${lowdefy.home.pageId}`] = props.input ?? {};
43
42
  }
44
43
  });
45
44
  }
@@ -49,7 +48,7 @@ function createLink({ backLink , disabledLink , lowdefy , newOriginLink , noLink
49
48
  pathname: `/${props.pageId}`,
50
49
  query,
51
50
  setInput: ()=>{
52
- lowdefy.inputs[`page:${props.pageId}`] = props.input || {};
51
+ lowdefy.inputs[`page:${props.pageId}`] = props.input ?? {};
53
52
  }
54
53
  });
55
54
  }
@@ -15,8 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  const getBlockMatcher = (params)=>{
17
17
  let testParams = params;
18
- if (type.isNone(testParams)) return ()=>true
19
- ;
18
+ if (type.isNone(testParams)) return ()=>true;
20
19
  if (type.isString(testParams)) {
21
20
  testParams = {
22
21
  blockIds: [
@@ -43,8 +42,7 @@ const getBlockMatcher = (params)=>{
43
42
  ];
44
43
  }
45
44
  if (type.isArray(testParams.regex)) {
46
- testParams.regex = testParams.regex.map((regex)=>new RegExp(regex)
47
- );
45
+ testParams.regex = testParams.regex.map((regex)=>new RegExp(regex));
48
46
  }
49
47
  return (id)=>{
50
48
  if (testParams.blockIds === true || type.isArray(testParams.blockIds) && testParams.blockIds.includes(id)) {
@@ -33,8 +33,7 @@ const blockData = ({ areas , blockId , blocks , events , field , id , layout , p
33
33
  type,
34
34
  validate,
35
35
  visible
36
- })
37
- ;
36
+ });
38
37
  function getContext({ config , lowdefy , resetContext ={
39
38
  reset: false,
40
39
  setReset: ()=>undefined
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lowdefy/engine",
3
- "version": "4.0.0-alpha.9",
4
- "licence": "Apache-2.0",
3
+ "version": "4.0.0-rc.0",
4
+ "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
7
7
  "keywords": [
@@ -30,26 +30,28 @@
30
30
  "dist/*"
31
31
  ],
32
32
  "scripts": {
33
- "build": "yarn swc",
33
+ "build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
34
34
  "clean": "rm -rf dist",
35
- "prepare": "yarn build",
36
- "swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
37
- "test:watch": "jest --coverage --watch",
38
- "test": "jest --coverage"
35
+ "prepublishOnly": "pnpm build",
36
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
39
37
  },
40
38
  "dependencies": {
41
- "@lowdefy/helpers": "4.0.0-alpha.9",
42
- "@lowdefy/operators": "4.0.0-alpha.9"
39
+ "@lowdefy/helpers": "4.0.0-rc.0",
40
+ "@lowdefy/operators": "4.0.0-rc.0"
43
41
  },
44
42
  "devDependencies": {
45
- "@lowdefy/operators-js": "4.0.0-alpha.9",
46
- "@swc/cli": "0.1.55",
47
- "@swc/core": "1.2.135",
48
- "@swc/jest": "0.2.17",
49
- "jest": "27.5.1"
43
+ "@jest/globals": "28.1.0",
44
+ "@lowdefy/actions-core": "4.0.0-rc.0",
45
+ "@lowdefy/build": "4.0.0-rc.0",
46
+ "@lowdefy/operators-js": "4.0.0-rc.0",
47
+ "@lowdefy/operators-mql": "4.0.0-rc.0",
48
+ "@swc/cli": "0.1.57",
49
+ "@swc/core": "1.2.194",
50
+ "@swc/jest": "0.2.21",
51
+ "jest": "28.1.0"
50
52
  },
51
53
  "publishConfig": {
52
54
  "access": "public"
53
55
  },
54
- "gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
56
+ "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
55
57
  }