@promptbook/node 0.89.0-30 → 0.89.0-32

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/esm/index.es.js CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-30';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-32';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1167,6 +1167,9 @@ function isValidFilePath(filename) {
1167
1167
  /**
1168
1168
  * Function isValidJsonString will tell you if the string is valid JSON or not
1169
1169
  *
1170
+ * @param value The string to check
1171
+ * @returns True if the string is a valid JSON string, false otherwise
1172
+ *
1170
1173
  * @public exported from `@promptbook/utils`
1171
1174
  */
1172
1175
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -2479,6 +2482,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
2479
2482
  // encoding: 'utf-8',
2480
2483
  });
2481
2484
 
2485
+ /**
2486
+ * Function to check if a string is valid CSV
2487
+ *
2488
+ * @param value The string to check
2489
+ * @returns True if the string is a valid CSV string, false otherwise
2490
+ *
2491
+ * @public exported from `@promptbook/utils`
2492
+ */
2493
+ function isValidCsvString(value) {
2494
+ try {
2495
+ // A simple check for CSV format: at least one comma and no invalid characters
2496
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
2497
+ return true;
2498
+ }
2499
+ return false;
2500
+ }
2501
+ catch (error) {
2502
+ assertsError(error);
2503
+ return false;
2504
+ }
2505
+ }
2506
+
2482
2507
  /**
2483
2508
  * Definition for CSV spreadsheet
2484
2509
  *
@@ -2489,7 +2514,7 @@ const CsvFormatDefinition = {
2489
2514
  formatName: 'CSV',
2490
2515
  aliases: ['SPREADSHEET', 'TABLE'],
2491
2516
  isValid(value, settings, schema) {
2492
- return true;
2517
+ return isValidCsvString(value);
2493
2518
  },
2494
2519
  canBeValid(partialValue, settings, schema) {
2495
2520
  return true;
@@ -2643,6 +2668,30 @@ const TextFormatDefinition = {
2643
2668
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
2644
2669
  */
2645
2670
 
2671
+ /**
2672
+ * Function to check if a string is valid XML
2673
+ *
2674
+ * @param value
2675
+ * @returns True if the string is a valid XML string, false otherwise
2676
+ *
2677
+ * @public exported from `@promptbook/utils`
2678
+ */
2679
+ function isValidXmlString(value) {
2680
+ try {
2681
+ const parser = new DOMParser();
2682
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
2683
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
2684
+ if (parserError.length > 0) {
2685
+ return false;
2686
+ }
2687
+ return true;
2688
+ }
2689
+ catch (error) {
2690
+ assertsError(error);
2691
+ return false;
2692
+ }
2693
+ }
2694
+
2646
2695
  /**
2647
2696
  * Definition for XML format
2648
2697
  *
@@ -2652,7 +2701,7 @@ const XmlFormatDefinition = {
2652
2701
  formatName: 'XML',
2653
2702
  mimeType: 'application/xml',
2654
2703
  isValid(value, settings, schema) {
2655
- return true;
2704
+ return isValidXmlString(value);
2656
2705
  },
2657
2706
  canBeValid(partialValue, settings, schema) {
2658
2707
  return true;