Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix(sdk): build issue

Ramesh Manec509a95cc905
diff --git a/packages/nocodb-sdk/src/lib/ai/index.ts b/packages/nocodb-sdk/src/lib/ai/index.ts
index aca08b4906..26c22b1243 100644
--- a/packages/nocodb-sdk/src/lib/ai/index.ts
+++ b/packages/nocodb-sdk/src/lib/ai/index.ts
@@ -1,4 +1,5 @@
import { ColumnType } from '../Api';
+import { stringAllMatches } from '../stringHelpers';
export interface SerializedAiTableType {
tables?: {
@@ -69,7 +70,8 @@ export function substituteColumnIdWithAliasInPrompt(
// Keep flexible regex: matches anything inside {}
const regex = /{(.*?)}/g;
- const rawMatches = rawPrompt ? [...rawPrompt.matchAll(regex)] : [];
+ const rawMatches = rawPrompt ? [...stringAllMatches(rawPrompt, regex)] : [];
+
let matchIndex = 0;
const missingIds: { id: string; title: string }[] = [];
diff --git a/packages/nocodb-sdk/src/lib/stringHelpers.ts b/packages/nocodb-sdk/src/lib/stringHelpers.ts
index 9d3b68c4f2..b7e00a5630 100644
--- a/packages/nocodb-sdk/src/lib/stringHelpers.ts
+++ b/packages/nocodb-sdk/src/lib/stringHelpers.ts
@@ -162,3 +162,29 @@ export const trimMatchingQuotes = (str?: string | null): string => {
return str?.trim()?.replace(/^(['"])(.*)\1$/, '$2') ?? '';
};
+
+/**
+ * Get all matches of a regex in a string
+ * @param str - The string to search
+ * @param regex - The regular expression to match against
+ * @returns An array of all matches of the regex in the string
+ *
+ * Note: Since we are using ES2017, `String.prototype.matchAll` is not available.
+ * This function acts as a fallback to achieve the same behavior.
+ */
+export function stringAllMatches(str: string, regex: RegExp): RegExpExecArray[] {
+ // Ensure regex has the global flag, because exec() needs it to iterate
+ const globalRegex = new RegExp(
+ regex.source,
+ regex.flags.includes('g') ? regex.flags : regex.flags + 'g'
+ );
+
+ const matches: RegExpExecArray[] = [];
+ let m: RegExpExecArray | null;
+
+ while ((m = globalRegex.exec(str)) !== null) {
+ matches.push(m);
+ }
+
+ return matches;
+}