pupt-lib 1.2.0 → 1.2.2

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.js CHANGED
@@ -369,15 +369,12 @@ async function renderChildrenFallback(children, state) {
369
369
  }
370
370
  async function renderComponentWithValidation(type, componentName, props, children, state, renderFn, resolveFn) {
371
371
  const schema = getSchema(type);
372
- if (!schema) {
373
- throw new Error(
374
- `Component "${componentName}" does not have a schema defined. All components must declare a static schema.`
375
- );
376
- }
377
- const validationErrors = validateProps(componentName, { ...props, children }, schema);
378
- if (validationErrors.length > 0) {
379
- state.context.errors.push(...validationErrors);
380
- return renderChildrenFallback(children, state);
372
+ if (schema) {
373
+ const validationErrors = validateProps(componentName, { ...props, children }, schema);
374
+ if (validationErrors.length > 0) {
375
+ state.context.errors.push(...validationErrors);
376
+ return renderChildrenFallback(children, state);
377
+ }
381
378
  }
382
379
  try {
383
380
  let resolvedValue;
@@ -550,6 +547,57 @@ function createInputIterator(element, options = {}) {
550
547
  }
551
548
  return reqs.length;
552
549
  }
550
+ function followPath2(obj, path) {
551
+ return path.reduce((current, key) => {
552
+ if (current == null) return void 0;
553
+ return current[key];
554
+ }, obj);
555
+ }
556
+ function resolveIteratorPropValue(value) {
557
+ if (isPuptElement(value)) {
558
+ const elementProps = value[PROPS];
559
+ const elementName = elementProps.name;
560
+ if (elementName && values2.has(elementName)) {
561
+ return values2.get(elementName);
562
+ }
563
+ if (elementProps.default !== void 0) {
564
+ return elementProps.default;
565
+ }
566
+ return void 0;
567
+ }
568
+ if (isDeferredRef(value)) {
569
+ const elementProps = value.element[PROPS];
570
+ const elementName = elementProps.name;
571
+ let elementValue;
572
+ if (elementName && values2.has(elementName)) {
573
+ elementValue = values2.get(elementName);
574
+ } else if (elementProps.default !== void 0) {
575
+ elementValue = elementProps.default;
576
+ }
577
+ return followPath2(elementValue, value.path);
578
+ }
579
+ if (Array.isArray(value)) {
580
+ return value.map((item) => resolveIteratorPropValue(item));
581
+ }
582
+ if (value !== null && typeof value === "object" && !isPuptElement(value) && !isDeferredRef(value)) {
583
+ const resolved = {};
584
+ for (const [key, val] of Object.entries(value)) {
585
+ resolved[key] = resolveIteratorPropValue(val);
586
+ }
587
+ return resolved;
588
+ }
589
+ return value;
590
+ }
591
+ function resolveIteratorProps(props) {
592
+ if (props == null) {
593
+ return {};
594
+ }
595
+ const resolved = {};
596
+ for (const [key, value] of Object.entries(props)) {
597
+ resolved[key] = resolveIteratorPropValue(value);
598
+ }
599
+ return resolved;
600
+ }
553
601
  async function walkNode(node, context) {
554
602
  if (node === null || node === void 0 || node === false) {
555
603
  return;
@@ -574,8 +622,14 @@ function createInputIterator(element, options = {}) {
574
622
  return;
575
623
  }
576
624
  if (isComponentClass(type)) {
625
+ if (children && children.length > 0) {
626
+ for (const child of children) {
627
+ await walkNode(child, context);
628
+ }
629
+ }
577
630
  const instance = new type();
578
- const renderResult = instance.render({ ...props, children }, void 0, context);
631
+ const resolvedProps = resolveIteratorProps(props);
632
+ const renderResult = instance.render({ ...resolvedProps, children }, void 0, context);
579
633
  const result = renderResult instanceof Promise ? await renderResult : renderResult;
580
634
  if (result !== null && typeof result === "object") {
581
635
  await walkNode(result, context);
@@ -583,8 +637,14 @@ function createInputIterator(element, options = {}) {
583
637
  return;
584
638
  }
585
639
  if (typeof type === "function" && !isComponentClass(type)) {
640
+ if (children && children.length > 0) {
641
+ for (const child of children) {
642
+ await walkNode(child, context);
643
+ }
644
+ }
586
645
  const fn = type;
587
- const renderResult = fn({ ...props, children });
646
+ const resolvedProps = resolveIteratorProps(props);
647
+ const renderResult = fn({ ...resolvedProps, children });
588
648
  const result = renderResult instanceof Promise ? await renderResult : renderResult;
589
649
  if (result !== null && typeof result === "object") {
590
650
  await walkNode(result, context);
@@ -1 +1 @@
1
- {"version":3,"file":"input-iterator.d.ts","sourceRoot":"","sources":["../../src/services/input-iterator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAY,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,GAAG,MAAM,GAAG,SAAS,CAAC;AA6CpD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,MAAM,CAAC;AAExD,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,0DAA0D;IAC1D,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;CAC7C;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,gBAAgB,GAAG,IAAI,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAClD;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,IAAI,OAAO,CAAC;IAClB,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC;;;;;;OAMG;IACH,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAID,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EACpB,OAAO,GAAE,oBAAyB,GACjC,aAAa,CA2sBf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pupt-lib",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "TypeScript library for creating AI prompts using JSX syntax",
5
5
  "license": "MIT",
6
6
  "author": "",