@player-tools/dsl 0.4.0-next.2 → 0.4.0-next.3

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/index.esm.js CHANGED
@@ -4,9 +4,8 @@ import mergeRefs from 'react-merge-refs';
4
4
  import { flattenNodes, ProxyNode, createPortal, PropertyNode, ValueNode, ArrayNode, toJSON, render } from 'react-json-reconciler';
5
5
  export * from 'react-json-reconciler';
6
6
  import { parseExpression } from '@player-ui/player';
7
- import signale from 'signale';
8
7
  import { dequal } from 'dequal';
9
- import { SyncWaterfallHook, SyncHook } from 'tapable-ts';
8
+ import { SyncWaterfallHook, SyncHook, AsyncSeriesWaterfallHook, AsyncSeriesHook } from 'tapable-ts';
10
9
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
11
10
 
12
11
  const IDSuffixContext = React.createContext("root");
@@ -73,25 +72,25 @@ const OptionalIDSuffixProvider = (props) => {
73
72
  return /* @__PURE__ */ React.createElement(React.Fragment, null, props.children);
74
73
  };
75
74
 
76
- var __defProp$4 = Object.defineProperty;
77
- var __defProps$3 = Object.defineProperties;
78
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
79
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
80
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
81
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
82
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
83
- var __spreadValues$4 = (a, b) => {
75
+ var __defProp$5 = Object.defineProperty;
76
+ var __defProps$4 = Object.defineProperties;
77
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
78
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
79
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
80
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
81
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
82
+ var __spreadValues$5 = (a, b) => {
84
83
  for (var prop in b || (b = {}))
85
- if (__hasOwnProp$4.call(b, prop))
86
- __defNormalProp$4(a, prop, b[prop]);
87
- if (__getOwnPropSymbols$4)
88
- for (var prop of __getOwnPropSymbols$4(b)) {
89
- if (__propIsEnum$4.call(b, prop))
90
- __defNormalProp$4(a, prop, b[prop]);
84
+ if (__hasOwnProp$5.call(b, prop))
85
+ __defNormalProp$5(a, prop, b[prop]);
86
+ if (__getOwnPropSymbols$5)
87
+ for (var prop of __getOwnPropSymbols$5(b)) {
88
+ if (__propIsEnum$5.call(b, prop))
89
+ __defNormalProp$5(a, prop, b[prop]);
91
90
  }
92
91
  return a;
93
92
  };
94
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
93
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
95
94
  const OpaqueIdentifier = Symbol("TemplateStringType");
96
95
  const TemplateStringComponent = (props) => {
97
96
  return React.createElement("value", {
@@ -122,7 +121,7 @@ const createTemplateInstance = (options) => {
122
121
  const element = React.createElement(TemplateStringComponent, {
123
122
  value: toString()
124
123
  }, null);
125
- return __spreadProps$3(__spreadValues$4({}, element), {
124
+ return __spreadProps$4(__spreadValues$5({}, element), {
126
125
  [OpaqueIdentifier]: true,
127
126
  toString,
128
127
  toValue,
@@ -132,7 +131,7 @@ const createTemplateInstance = (options) => {
132
131
  });
133
132
  };
134
133
  const createBindingTemplateInstance = (options) => {
135
- const templateInstance = createTemplateInstance(__spreadProps$3(__spreadValues$4({}, options), {
134
+ const templateInstance = createTemplateInstance(__spreadProps$4(__spreadValues$5({}, options), {
136
135
  toRefString: (context, value) => {
137
136
  return `{{${value}}}`;
138
137
  }
@@ -141,7 +140,7 @@ const createBindingTemplateInstance = (options) => {
141
140
  return templateInstance;
142
141
  };
143
142
  const createExpressionTemplateInstance = (options) => {
144
- const templateInstance = createTemplateInstance(__spreadProps$3(__spreadValues$4({}, options), {
143
+ const templateInstance = createTemplateInstance(__spreadProps$4(__spreadValues$5({}, options), {
145
144
  toRefString: (contextOptions, value) => {
146
145
  if ((contextOptions == null ? void 0 : contextOptions.nestedContext) === "expression") {
147
146
  return value;
@@ -168,54 +167,60 @@ const expression = (strings, ...nested) => {
168
167
  });
169
168
  };
170
169
  const isTemplateStringInstance = (val) => {
171
- return typeof val === "object" && val[OpaqueIdentifier] === true;
170
+ return val !== null && typeof val === "object" && val[OpaqueIdentifier] === true;
172
171
  };
173
172
 
174
- var __defProp$3 = Object.defineProperty;
175
- var __defProps$2 = Object.defineProperties;
176
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
177
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
178
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
179
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
180
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
181
- var __spreadValues$3 = (a, b) => {
173
+ var __defProp$4 = Object.defineProperty;
174
+ var __defProps$3 = Object.defineProperties;
175
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
176
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
177
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
178
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
179
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
180
+ var __spreadValues$4 = (a, b) => {
182
181
  for (var prop in b || (b = {}))
183
- if (__hasOwnProp$3.call(b, prop))
184
- __defNormalProp$3(a, prop, b[prop]);
185
- if (__getOwnPropSymbols$3)
186
- for (var prop of __getOwnPropSymbols$3(b)) {
187
- if (__propIsEnum$3.call(b, prop))
188
- __defNormalProp$3(a, prop, b[prop]);
182
+ if (__hasOwnProp$4.call(b, prop))
183
+ __defNormalProp$4(a, prop, b[prop]);
184
+ if (__getOwnPropSymbols$4)
185
+ for (var prop of __getOwnPropSymbols$4(b)) {
186
+ if (__propIsEnum$4.call(b, prop))
187
+ __defNormalProp$4(a, prop, b[prop]);
189
188
  }
190
189
  return a;
191
190
  };
192
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
191
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
193
192
  function toArray(val) {
194
193
  return Array.isArray(val) ? val : [val];
195
194
  }
196
- function toJsonElement(value, index) {
197
- const keyProp = index === void 0 ? null : { key: index };
195
+ function toJsonElement(value, indexOrKey, options) {
196
+ var _a;
197
+ const indexProp = typeof indexOrKey === "number" ? { key: indexOrKey } : null;
198
198
  if (Array.isArray(value)) {
199
- return /* @__PURE__ */ React.createElement("array", __spreadValues$3({}, keyProp), value.map((item, idx) => toJsonElement(item, idx)));
199
+ return /* @__PURE__ */ React.createElement("array", __spreadValues$4({}, indexProp), value.map((item, idx) => toJsonElement(item, idx, options)));
200
200
  }
201
201
  if (isTemplateStringInstance(value)) {
202
- return /* @__PURE__ */ React.createElement("value", __spreadValues$3({}, keyProp), value.toRefString());
202
+ if (typeof indexOrKey === "string" && ((_a = options == null ? void 0 : options.propertiesToSkip) == null ? void 0 : _a.includes(indexOrKey))) {
203
+ return /* @__PURE__ */ React.createElement("value", __spreadValues$4({}, indexProp), value.toValue());
204
+ }
205
+ return /* @__PURE__ */ React.createElement("value", __spreadValues$4({}, indexProp), value.toRefString());
203
206
  }
204
207
  if (typeof value === "object" && value !== null) {
205
- return /* @__PURE__ */ React.createElement("obj", __spreadValues$3({}, keyProp), Object.keys(value).map((key) => /* @__PURE__ */ React.createElement("property", {
208
+ return /* @__PURE__ */ React.createElement("obj", __spreadValues$4({}, indexProp), Object.keys(value).map((key) => /* @__PURE__ */ React.createElement("property", {
206
209
  key,
207
210
  name: key
208
- }, toJsonElement(value[key]))));
211
+ }, toJsonElement(value[key], key, options))));
209
212
  }
210
- return /* @__PURE__ */ React.createElement("value", __spreadProps$2(__spreadValues$3({}, keyProp), {
213
+ return /* @__PURE__ */ React.createElement("value", __spreadProps$3(__spreadValues$4({}, indexProp), {
211
214
  value
212
215
  }));
213
216
  }
214
- function toJsonProperties(value) {
215
- return Object.keys(value).map((key) => /* @__PURE__ */ React.createElement("property", {
216
- key,
217
- name: key
218
- }, toJsonElement(value[key])));
217
+ function toJsonProperties(value, options = { propertiesToSkip: ["applicability"] }) {
218
+ return Object.keys(value).map((key) => {
219
+ return /* @__PURE__ */ React.createElement("property", {
220
+ key,
221
+ name: key
222
+ }, toJsonElement(value[key], key, options));
223
+ });
219
224
  }
220
225
  function normalizeText(options) {
221
226
  const { node, TextComp } = options;
@@ -236,36 +241,36 @@ function normalizeToCollection(options) {
236
241
  }
237
242
  return /* @__PURE__ */ React.createElement(CollectionComp, null, node);
238
243
  }
239
- return normalizeText(__spreadProps$2(__spreadValues$3({}, options), { node }));
244
+ return normalizeText(__spreadProps$3(__spreadValues$4({}, options), { node }));
240
245
  }
241
246
 
242
- var __defProp$2 = Object.defineProperty;
243
- var __defProps$1 = Object.defineProperties;
244
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
245
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
246
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
247
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
248
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
249
- var __spreadValues$2 = (a, b) => {
247
+ var __defProp$3 = Object.defineProperty;
248
+ var __defProps$2 = Object.defineProperties;
249
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
250
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
251
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
252
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
253
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
254
+ var __spreadValues$3 = (a, b) => {
250
255
  for (var prop in b || (b = {}))
251
- if (__hasOwnProp$2.call(b, prop))
252
- __defNormalProp$2(a, prop, b[prop]);
253
- if (__getOwnPropSymbols$2)
254
- for (var prop of __getOwnPropSymbols$2(b)) {
255
- if (__propIsEnum$2.call(b, prop))
256
- __defNormalProp$2(a, prop, b[prop]);
256
+ if (__hasOwnProp$3.call(b, prop))
257
+ __defNormalProp$3(a, prop, b[prop]);
258
+ if (__getOwnPropSymbols$3)
259
+ for (var prop of __getOwnPropSymbols$3(b)) {
260
+ if (__propIsEnum$3.call(b, prop))
261
+ __defNormalProp$3(a, prop, b[prop]);
257
262
  }
258
263
  return a;
259
264
  };
260
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
265
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
261
266
  var __objRest = (source, exclude) => {
262
267
  var target = {};
263
268
  for (var prop in source)
264
- if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
269
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
265
270
  target[prop] = source[prop];
266
- if (source != null && __getOwnPropSymbols$2)
267
- for (var prop of __getOwnPropSymbols$2(source)) {
268
- if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
271
+ if (source != null && __getOwnPropSymbols$3)
272
+ for (var prop of __getOwnPropSymbols$3(source)) {
273
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
269
274
  target[prop] = source[prop];
270
275
  }
271
276
  return target;
@@ -291,7 +296,7 @@ const Asset = React.forwardRef((props, ref) => {
291
296
  const slotContext = React.useContext(SlotContext);
292
297
  const localRef = React.useRef(null);
293
298
  const Wrapper = (slotContext == null ? void 0 : slotContext.wrapInAsset) ? AssetWrapper : React.Fragment;
294
- return /* @__PURE__ */ React.createElement(Wrapper, __spreadValues$2({
299
+ return /* @__PURE__ */ React.createElement(Wrapper, __spreadValues$3({
295
300
  ref: (slotContext == null ? void 0 : slotContext.wrapInAsset) ? mergeRefs([ref, localRef]) : void 0
296
301
  }, (slotContext == null ? void 0 : slotContext.wrapInAsset) && (slotContext == null ? void 0 : slotContext.additionalProperties) ? slotContext == null ? void 0 : slotContext.additionalProperties : {}), /* @__PURE__ */ React.createElement(OptionalIDSuffixProvider, {
297
302
  wrapperRef: localRef
@@ -308,13 +313,28 @@ const Asset = React.forwardRef((props, ref) => {
308
313
  }, type), applicability !== void 0 && /* @__PURE__ */ React.createElement("property", {
309
314
  name: "applicability"
310
315
  }, /* @__PURE__ */ React.createElement("value", {
311
- value: typeof applicability === "boolean" ? applicability : applicability.toRefString()
316
+ value: typeof applicability === "boolean" ? applicability : applicability.toValue()
312
317
  })), toJsonProperties(rest), children)))));
313
318
  });
314
319
  Asset.defaultProps = {
315
320
  id: void 0,
316
321
  children: void 0
317
322
  };
323
+ const View = React.forwardRef((props, ref) => {
324
+ const _a = props, { validation, children } = _a, rest = __objRest(_a, ["validation", "children"]);
325
+ return /* @__PURE__ */ React.createElement(Asset, __spreadValues$3({
326
+ ref
327
+ }, rest), validation && /* @__PURE__ */ React.createElement("property", {
328
+ key: "validation",
329
+ name: "validation"
330
+ }, toJsonElement(validation, "validation", {
331
+ propertiesToSkip: ["ref"]
332
+ })), children);
333
+ });
334
+ View.defaultProps = {
335
+ id: void 0,
336
+ children: void 0
337
+ };
318
338
  const Slot = (props) => {
319
339
  var _a, _b;
320
340
  const { TextComp, CollectionComp } = props;
@@ -350,31 +370,31 @@ const Slot = (props) => {
350
370
  function createSlot(options) {
351
371
  return (props) => {
352
372
  const _a = props, { children } = _a, other = __objRest(_a, ["children"]);
353
- return /* @__PURE__ */ React.createElement(Slot, __spreadProps$1(__spreadValues$2({}, options), {
373
+ return /* @__PURE__ */ React.createElement(Slot, __spreadProps$2(__spreadValues$3({}, options), {
354
374
  additionalProperties: other
355
375
  }), children);
356
376
  };
357
377
  }
358
378
 
359
- var __defProp$1 = Object.defineProperty;
360
- var __defProps = Object.defineProperties;
361
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
362
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
363
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
364
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
365
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
366
- var __spreadValues$1 = (a, b) => {
379
+ var __defProp$2 = Object.defineProperty;
380
+ var __defProps$1 = Object.defineProperties;
381
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
382
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
383
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
384
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
385
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
386
+ var __spreadValues$2 = (a, b) => {
367
387
  for (var prop in b || (b = {}))
368
- if (__hasOwnProp$1.call(b, prop))
369
- __defNormalProp$1(a, prop, b[prop]);
370
- if (__getOwnPropSymbols$1)
371
- for (var prop of __getOwnPropSymbols$1(b)) {
372
- if (__propIsEnum$1.call(b, prop))
373
- __defNormalProp$1(a, prop, b[prop]);
388
+ if (__hasOwnProp$2.call(b, prop))
389
+ __defNormalProp$2(a, prop, b[prop]);
390
+ if (__getOwnPropSymbols$2)
391
+ for (var prop of __getOwnPropSymbols$2(b)) {
392
+ if (__propIsEnum$2.call(b, prop))
393
+ __defNormalProp$2(a, prop, b[prop]);
374
394
  }
375
395
  return a;
376
396
  };
377
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
397
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
378
398
  const SwitchContext = React.createContext({});
379
399
  const Switch = (props) => {
380
400
  const slotContext = React.useContext(SlotContext);
@@ -382,7 +402,7 @@ const Switch = (props) => {
382
402
  return /* @__PURE__ */ React.createElement("obj", {
383
403
  ref: propertyNode
384
404
  }, /* @__PURE__ */ React.createElement(SwitchContext.Provider, {
385
- value: __spreadProps(__spreadValues$1({}, props), {
405
+ value: __spreadProps$1(__spreadValues$2({}, props), {
386
406
  TextComp: slotContext == null ? void 0 : slotContext.TextComp,
387
407
  CollectionComp: slotContext == null ? void 0 : slotContext.CollectionComp
388
408
  })
@@ -434,7 +454,7 @@ const Case = (props) => {
434
454
  })), /* @__PURE__ */ React.createElement(IDSuffixProvider, {
435
455
  suffix: `${switchContext.isDynamic ? "dynamicSwitch" : "staticSwitch"}-${caseIndex}`
436
456
  }, /* @__PURE__ */ React.createElement(SlotContext.Provider, {
437
- value: slotContext ? __spreadProps(__spreadValues$1({}, slotContext), { wrapInAsset: false }) : void 0
457
+ value: slotContext ? __spreadProps$1(__spreadValues$2({}, slotContext), { wrapInAsset: false }) : void 0
438
458
  }, /* @__PURE__ */ React.createElement("property", {
439
459
  name: "asset"
440
460
  }, normalizeToCollection({
@@ -506,7 +526,9 @@ const getParentProperty = (node) => {
506
526
  }
507
527
  };
508
528
  const Template = (props) => {
529
+ var _a;
509
530
  const baseContext = React.useContext(TemplateContext);
531
+ const dynamicProp = (_a = props.dynamic) != null ? _a : false;
510
532
  const [outputProp, setOutputProp] = React.useState(props.output);
511
533
  const proxyRef = React.useRef(null);
512
534
  const valueRef = React.useRef(null);
@@ -541,19 +563,40 @@ const Template = (props) => {
541
563
  name: "output"
542
564
  }, outputProp), /* @__PURE__ */ React.createElement("property", {
543
565
  name: "value"
544
- }, props.children)))), outputElement), /* @__PURE__ */ React.createElement("value", {
566
+ }, props.children), dynamicProp && /* @__PURE__ */ React.createElement("property", {
567
+ name: "dynamic"
568
+ }, toJsonElement(dynamicProp))))), outputElement), /* @__PURE__ */ React.createElement("value", {
545
569
  ref: valueRef,
546
570
  value: void 0
547
571
  }));
548
572
  };
549
573
 
574
+ var __defProp$1 = Object.defineProperty;
575
+ var __defProps = Object.defineProperties;
576
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
577
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
578
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
579
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
580
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
581
+ var __spreadValues$1 = (a, b2) => {
582
+ for (var prop in b2 || (b2 = {}))
583
+ if (__hasOwnProp$1.call(b2, prop))
584
+ __defNormalProp$1(a, prop, b2[prop]);
585
+ if (__getOwnPropSymbols$1)
586
+ for (var prop of __getOwnPropSymbols$1(b2)) {
587
+ if (__propIsEnum$1.call(b2, prop))
588
+ __defNormalProp$1(a, prop, b2[prop]);
589
+ }
590
+ return a;
591
+ };
592
+ var __spreadProps = (a, b2) => __defProps(a, __getOwnPropDescs(b2));
550
593
  const bindingSymbol = Symbol("binding");
551
594
  const SchemaTypeName = Symbol("Schema Rename");
552
595
  const isTypeDef = (property) => {
553
596
  return property.type !== void 0;
554
597
  };
555
598
  class SchemaGenerator {
556
- constructor() {
599
+ constructor(logger) {
557
600
  this.hooks = {
558
601
  createSchemaNode: new SyncWaterfallHook()
559
602
  };
@@ -562,10 +605,10 @@ class SchemaGenerator {
562
605
  ROOT: {}
563
606
  };
564
607
  this.children = [];
565
- this.generatedDataTypeNames.clear();
608
+ this.generatedDataTypes.clear();
566
609
  Object.keys(schema).forEach((property) => {
567
610
  const subType = schema[property];
568
- newSchema.ROOT[property] = this.hooks.createSchemaNode.call(this.processChildren(property, subType), subType);
611
+ newSchema.ROOT[property] = this.hooks.createSchemaNode.call(this.processChild(property, subType), subType);
569
612
  });
570
613
  while (this.children.length > 0) {
571
614
  const c = this.children.pop();
@@ -576,7 +619,7 @@ class SchemaGenerator {
576
619
  const typeDef = {};
577
620
  Object.keys(child).forEach((property) => {
578
621
  const subType = child[property];
579
- typeDef[property] = this.hooks.createSchemaNode.call(this.processChildren(property, subType), subType);
622
+ typeDef[property] = this.hooks.createSchemaNode.call(this.processChild(property, subType), subType);
580
623
  });
581
624
  newSchema[name] = typeDef;
582
625
  }
@@ -588,17 +631,18 @@ class SchemaGenerator {
588
631
  };
589
632
  };
590
633
  this.children = [];
591
- this.generatedDataTypeNames = new Map();
634
+ this.generatedDataTypes = new Map();
635
+ this.logger = logger != null ? logger : console;
592
636
  }
593
- processChildren(property, subType) {
594
- var _a, _b;
637
+ processChild(property, subType) {
638
+ var _a, _b, _c;
595
639
  if (isTypeDef(subType)) {
596
640
  return subType;
597
641
  }
598
642
  let intermediateType;
599
643
  if (Array.isArray(subType)) {
600
644
  if (subType.length > 1) {
601
- signale.warn(`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`);
645
+ this.logger.warn(`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`);
602
646
  }
603
647
  const subTypeName = (_a = subType[0][SchemaTypeName]) != null ? _a : property;
604
648
  intermediateType = this.makePlaceholderArrayType(subTypeName);
@@ -608,13 +652,23 @@ class SchemaGenerator {
608
652
  intermediateType = this.makePlaceholderType(subTypeName);
609
653
  this.children.push({ name: intermediateType.type, child: subType });
610
654
  }
611
- if (this.generatedDataTypeNames.has(intermediateType.type)) {
612
- if (!dequal(subType, this.generatedDataTypeNames.get(intermediateType.type))) {
613
- throw new Error(`Error: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes`);
655
+ if (this.generatedDataTypes.has(intermediateType.type)) {
656
+ const generatedType = this.generatedDataTypes.get(intermediateType.type);
657
+ if (!dequal(subType, (_c = this.generatedDataTypes.get(intermediateType.type)) == null ? void 0 : _c.node)) {
658
+ generatedType.count += 1;
659
+ const newIntermediateType = __spreadProps(__spreadValues$1({}, intermediateType), {
660
+ type: `${intermediateType.type}${generatedType.count}`
661
+ });
662
+ this.logger.warn(`WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`);
663
+ intermediateType = newIntermediateType;
664
+ this.children.pop();
665
+ this.children.push({ name: intermediateType.type, child: subType });
614
666
  }
615
- this.children.pop();
616
667
  }
617
- this.generatedDataTypeNames.set(intermediateType.type, subType);
668
+ this.generatedDataTypes.set(intermediateType.type, {
669
+ node: subType,
670
+ count: 1
671
+ });
618
672
  return intermediateType;
619
673
  }
620
674
  makePlaceholderArrayType(typeName) {
@@ -746,10 +800,14 @@ const mergeSourceMaps = (sourceMaps, generated) => {
746
800
  return generator.toString();
747
801
  };
748
802
  class DSLCompiler {
749
- constructor() {
803
+ constructor(logger) {
750
804
  this.hooks = {
751
- schemaGenerator: new SyncHook()
805
+ schemaGenerator: new SyncHook(),
806
+ preProcessFlow: new AsyncSeriesWaterfallHook(),
807
+ postProcessFlow: new AsyncSeriesWaterfallHook(),
808
+ onEnd: new AsyncSeriesHook()
752
809
  };
810
+ this.logger = logger != null ? logger : console;
753
811
  }
754
812
  serialize(value) {
755
813
  return __async(this, null, function* () {
@@ -757,6 +815,8 @@ class DSLCompiler {
757
815
  if (typeof value !== "object" || value === null) {
758
816
  throw new Error("Unable to serialize non-object");
759
817
  }
818
+ const schemaGenerator = new SchemaGenerator(this.logger);
819
+ this.hooks.schemaGenerator.call(schemaGenerator);
760
820
  if (React.isValidElement(value)) {
761
821
  const { jsonValue, sourceMap } = yield render(value, {
762
822
  collectSourceMap: true
@@ -767,9 +827,10 @@ class DSLCompiler {
767
827
  contentType: "view"
768
828
  };
769
829
  }
770
- if ("navigation" in value) {
830
+ const preProcessedValue = yield this.hooks.preProcessFlow.call(value);
831
+ if ("navigation" in preProcessedValue) {
771
832
  const allSourceMaps = [];
772
- const copiedValue = __spreadValues({}, value);
833
+ const copiedValue = __spreadValues({}, preProcessedValue);
773
834
  copiedValue.views = yield Promise.all((_b = (_a = copiedValue == null ? void 0 : copiedValue.views) == null ? void 0 : _a.map((node) => __async(this, null, function* () {
774
835
  const { jsonValue, sourceMap, stringValue } = yield render(node, {
775
836
  collectSourceMap: true
@@ -786,13 +847,13 @@ class DSLCompiler {
786
847
  }
787
848
  return jsonValue;
788
849
  }))) != null ? _b : []);
789
- if ("navigation" in value) {
790
- Object.entries(value.navigation).forEach(([navKey, node]) => {
850
+ if ("navigation" in preProcessedValue) {
851
+ Object.entries(preProcessedValue.navigation).forEach(([navKey, node]) => {
791
852
  if (typeof node === "object") {
792
853
  Object.entries(node).forEach(([nodeKey, flowNode]) => {
793
854
  var _a2, _b2, _c, _d;
794
855
  if (flowNode && typeof flowNode === "object" && "state_type" in flowNode && flowNode.state_type === "VIEW" && React.isValidElement(flowNode.ref)) {
795
- const actualViewIndex = (_b2 = (_a2 = value.views) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b2.call(_a2, flowNode.ref);
856
+ const actualViewIndex = (_b2 = (_a2 = preProcessedValue.views) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b2.call(_a2, flowNode.ref);
796
857
  if (actualViewIndex !== void 0 && actualViewIndex > -1) {
797
858
  const actualId = (_d = (_c = copiedValue.views) == null ? void 0 : _c[actualViewIndex]) == null ? void 0 : _d.id;
798
859
  copiedValue.navigation[navKey][nodeKey].ref = actualId;
@@ -801,25 +862,27 @@ class DSLCompiler {
801
862
  });
802
863
  }
803
864
  });
865
+ if ("schema" in preProcessedValue) {
866
+ copiedValue.schema = schemaGenerator.toSchema(copiedValue.schema);
867
+ }
804
868
  copiedValue.navigation = parseNavigationExpressions(copiedValue.navigation);
805
869
  }
806
870
  if (value) {
871
+ const postProcessFlow = yield this.hooks.postProcessFlow.call(copiedValue);
807
872
  return {
808
- value: copiedValue,
873
+ value: postProcessFlow,
809
874
  contentType: "flow",
810
875
  sourceMap: mergeSourceMaps(allSourceMaps, JSON.stringify(copiedValue, null, 2))
811
876
  };
812
877
  }
813
878
  }
814
- const schemaGenerator = new SchemaGenerator();
815
- this.hooks.schemaGenerator.call(schemaGenerator);
816
879
  return {
817
- value: schemaGenerator.toSchema(value),
880
+ value: schemaGenerator.toSchema(preProcessedValue),
818
881
  contentType: "schema"
819
882
  };
820
883
  });
821
884
  }
822
885
  }
823
886
 
824
- export { Asset, AssetWrapper, DSLCompiler, GeneratedIDProperty, IDProvider, IDSuffixIndexProvider, IDSuffixProvider, IndexSuffixStopContext, OptionalIDSuffixProvider, SchemaGenerator, SchemaTypeName, Slot, SlotContext, Switch, Template, TemplateContext, TemplateStringComponent, binding, createSlot, expression, getBindingFromObject, getBindingStringFromObject, getRefStringFromObject, isTemplateStringInstance, makeBindingsForObject, normalizeText, normalizeToCollection, toArray, toJsonElement, toJsonProperties, useGetIdPrefix, useIndexInSlot };
887
+ export { Asset, AssetWrapper, DSLCompiler, GeneratedIDProperty, IDProvider, IDSuffixIndexProvider, IDSuffixProvider, IndexSuffixStopContext, OptionalIDSuffixProvider, SchemaGenerator, SchemaTypeName, Slot, SlotContext, Switch, Template, TemplateContext, TemplateStringComponent, View, binding, createSlot, expression, getBindingFromObject, getBindingStringFromObject, getRefStringFromObject, isTemplateStringInstance, makeBindingsForObject, normalizeText, normalizeToCollection, toArray, toJsonElement, toJsonProperties, useGetIdPrefix, useIndexInSlot };
825
888
  //# sourceMappingURL=index.esm.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-tools/dsl",
3
- "version": "0.4.0-next.2",
3
+ "version": "0.4.0-next.3",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
@@ -12,7 +12,6 @@
12
12
  "@player-ui/types": "0.4.0-next.7",
13
13
  "@player-ui/player": "0.4.0-next.7",
14
14
  "@types/mkdirp": "^1.0.2",
15
- "@types/signale": "^1.4.2",
16
15
  "chalk": "^4.0.1",
17
16
  "command-line-application": "^0.10.1",
18
17
  "fs-extra": "^10.0.0",
@@ -23,7 +22,6 @@
23
22
  "react-json-reconciler": "^2.0.0",
24
23
  "react-merge-refs": "^1.1.0",
25
24
  "source-map-js": "^1.0.2",
26
- "signale": "^1.4.0",
27
25
  "ts-node": "^10.4.0",
28
26
  "typescript": "4.8.4",
29
27
  "tapable-ts": "^0.1.0",