@promptbook/core 0.89.0-31 → 0.89.0-33

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
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-31';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-33';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -595,6 +595,9 @@ function assertsError(whatWasThrown) {
595
595
  /**
596
596
  * Function isValidJsonString will tell you if the string is valid JSON or not
597
597
  *
598
+ * @param value The string to check
599
+ * @returns True if the string is a valid JSON string, false otherwise
600
+ *
598
601
  * @public exported from `@promptbook/utils`
599
602
  */
600
603
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -2708,6 +2711,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
2708
2711
  // encoding: 'utf-8',
2709
2712
  });
2710
2713
 
2714
+ /**
2715
+ * Function to check if a string is valid CSV
2716
+ *
2717
+ * @param value The string to check
2718
+ * @returns True if the string is a valid CSV string, false otherwise
2719
+ *
2720
+ * @public exported from `@promptbook/utils`
2721
+ */
2722
+ function isValidCsvString(value) {
2723
+ try {
2724
+ // A simple check for CSV format: at least one comma and no invalid characters
2725
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
2726
+ return true;
2727
+ }
2728
+ return false;
2729
+ }
2730
+ catch (error) {
2731
+ assertsError(error);
2732
+ return false;
2733
+ }
2734
+ }
2735
+
2711
2736
  /**
2712
2737
  * Definition for CSV spreadsheet
2713
2738
  *
@@ -2718,7 +2743,7 @@ const CsvFormatDefinition = {
2718
2743
  formatName: 'CSV',
2719
2744
  aliases: ['SPREADSHEET', 'TABLE'],
2720
2745
  isValid(value, settings, schema) {
2721
- return true;
2746
+ return isValidCsvString(value);
2722
2747
  },
2723
2748
  canBeValid(partialValue, settings, schema) {
2724
2749
  return true;
@@ -2872,6 +2897,30 @@ const TextFormatDefinition = {
2872
2897
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
2873
2898
  */
2874
2899
 
2900
+ /**
2901
+ * Function to check if a string is valid XML
2902
+ *
2903
+ * @param value
2904
+ * @returns True if the string is a valid XML string, false otherwise
2905
+ *
2906
+ * @public exported from `@promptbook/utils`
2907
+ */
2908
+ function isValidXmlString(value) {
2909
+ try {
2910
+ const parser = new DOMParser();
2911
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
2912
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
2913
+ if (parserError.length > 0) {
2914
+ return false;
2915
+ }
2916
+ return true;
2917
+ }
2918
+ catch (error) {
2919
+ assertsError(error);
2920
+ return false;
2921
+ }
2922
+ }
2923
+
2875
2924
  /**
2876
2925
  * Definition for XML format
2877
2926
  *
@@ -2881,7 +2930,7 @@ const XmlFormatDefinition = {
2881
2930
  formatName: 'XML',
2882
2931
  mimeType: 'application/xml',
2883
2932
  isValid(value, settings, schema) {
2884
- return true;
2933
+ return isValidXmlString(value);
2885
2934
  },
2886
2935
  canBeValid(partialValue, settings, schema) {
2887
2936
  return true;