@rebasepro/utils 0.12.1-canary.gf5f1d39 → 0.13.0

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/arrays.d.ts CHANGED
@@ -1 +1,8 @@
1
- export declare function toArray<T>(input?: T | T[]): T[];
1
+ /**
2
+ * Normalise a value that may be a single item or a list into a list.
3
+ *
4
+ * Only `null`/`undefined` mean "nothing". A truthiness check here silently
5
+ * swallowed legitimate values — `toArray(0)`, `toArray(false)` and `toArray("")`
6
+ * all came back empty, so a caller normalising a single falsy item lost it.
7
+ */
8
+ export declare function toArray<T>(input?: T | T[] | null): T[];
package/dist/index.es.js CHANGED
@@ -204,16 +204,12 @@ function removeFunctions(o) {
204
204
  if (o === void 0) return void 0;
205
205
  if (o === null) return null;
206
206
  if (typeof o === "object") {
207
- if (Array.isArray(o)) return o.map((v) => removeFunctions(v));
207
+ if (Array.isArray(o)) return o.filter((v) => typeof v !== "function").map((v) => removeFunctions(v));
208
208
  if (!isPlainObject(o)) return o;
209
- return Object.entries(o).filter(([_, value]) => typeof value !== "function").map(([key, value]) => {
210
- if (Array.isArray(value)) return { [key]: value.map((v) => removeFunctions(v)) };
211
- else if (typeof value === "object") return { [key]: removeFunctions(value) };
212
- else return { [key]: value };
213
- }).reduce((a, b) => ({
214
- ...a,
215
- ...b
216
- }), {});
209
+ return Object.entries(o).filter(([_, value]) => typeof value !== "function").reduce((acc, [key, value]) => {
210
+ acc[key] = removeFunctions(value);
211
+ return acc;
212
+ }, {});
217
213
  }
218
214
  return o;
219
215
  }
@@ -281,8 +277,17 @@ function removePropsIfExisting(source, comparison) {
281
277
  }
282
278
  //#endregion
283
279
  //#region src/arrays.ts
280
+ /**
281
+ * Normalise a value that may be a single item or a list into a list.
282
+ *
283
+ * Only `null`/`undefined` mean "nothing". A truthiness check here silently
284
+ * swallowed legitimate values — `toArray(0)`, `toArray(false)` and `toArray("")`
285
+ * all came back empty, so a caller normalising a single falsy item lost it.
286
+ */
284
287
  function toArray(input) {
285
- return Array.isArray(input) ? input : input ? [input] : [];
288
+ if (Array.isArray(input)) return input;
289
+ if (input === void 0 || input === null) return [];
290
+ return [input];
286
291
  }
287
292
  //#endregion
288
293
  //#region src/dates.ts
@@ -457,9 +462,21 @@ function hydrateRegExp(input) {
457
462
  if (fragments) return new RegExp(fragments[1], fragments[2] || "");
458
463
  else return new RegExp(input, "");
459
464
  }
465
+ /**
466
+ * Is `input` something {@link hydrateRegExp} can turn into a working RegExp?
467
+ *
468
+ * This used to pattern-match the *shape* of a regex literal and, failing that,
469
+ * fall back to "does it contain any regex-ish character" — which said yes to
470
+ * malformed input like `/[a-z/g`. The only answer that matters to a caller is
471
+ * whether hydration succeeds, so ask the engine instead of approximating it.
472
+ */
460
473
  function isValidRegExp(input) {
461
- if (input.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/)) return true;
462
- return !!input.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/);
474
+ if (!input) return false;
475
+ try {
476
+ return hydrateRegExp(input) !== void 0;
477
+ } catch {
478
+ return false;
479
+ }
463
480
  }
464
481
  //#endregion
465
482
  //#region src/flatten_object.ts
@@ -660,8 +677,10 @@ function singular(word, amount) {
660
677
  //#region src/names.ts
661
678
  /**
662
679
  * Generates a foreign key column name from a given string, typically a collection slug or name.
663
- * It converts the name to snake_case, attempts to singularize it by removing a trailing 's'
664
- * (a common convention for collection names), and appends '_id'.
680
+ * It singularizes the name, converts it to snake_case and appends '_id'.
681
+ *
682
+ * Singularization runs *before* snake-casing so that acronyms survive: `toSnakeCase`
683
+ * splits on every capital, which turned "URLs" into "ur_ls" and then "ur_l_id".
665
684
  *
666
685
  * @param name The base name to convert to a foreign key.
667
686
  * @returns A foreign key name in the format 'singular_name_id'.
@@ -671,8 +690,8 @@ function singular(word, amount) {
671
690
  * generateForeignKeyName("users")
672
691
  *
673
692
  * @example
674
- * // returns "post_id"
675
- * generateForeignKeyName("posts")
693
+ * // returns "category_id"
694
+ * generateForeignKeyName("categories")
676
695
  *
677
696
  * @example
678
697
  * // returns "product_id"
@@ -680,8 +699,41 @@ function singular(word, amount) {
680
699
  *
681
700
  */
682
701
  function generateForeignKeyName(name) {
683
- const snakeCaseName = toSnakeCase(name);
684
- return `${snakeCaseName.endsWith("s") ? snakeCaseName.slice(0, -1) : snakeCaseName}_id`;
702
+ return `${toSnakeCase(singularizeForKey(name))}_id`;
703
+ }
704
+ /**
705
+ * `singular()` handles real English plurals, but its final catch-all rule strips
706
+ * any trailing "s", which mangles words that only look plural. Guard the two
707
+ * cases that produce a column name nobody would recognise:
708
+ *
709
+ * - a double "s" ending is never a plural marker ("address", "class", "process"),
710
+ * so stripping it yields "addres";
711
+ * - a name that singularizes to nothing (the literal "s") would yield "_id".
712
+ */
713
+ function singularizeForKey(name) {
714
+ if (/ss$/i.test(name)) return name;
715
+ const result = singular(name);
716
+ return result.length > 0 ? result : name;
717
+ }
718
+ /**
719
+ * What `generateForeignKeyName` returned before it learned to singularize:
720
+ * snake-case the name, then chop one trailing "s".
721
+ *
722
+ * This is here to be *detected*, never to be generated. A database provisioned
723
+ * under the old rule carries `categorie_id`, `addresse_id`, `children_id` or
724
+ * `ur_l_id` where the current rule expects `category_id`, `address_id`,
725
+ * `child_id` and `url_id` — and the boot-time schema ensure is additive, so it
726
+ * would create the new column empty beside the populated old one and leave the
727
+ * relation reading nothing. No error, no missing table: the failure is silent,
728
+ * which is the only reason this function still exists.
729
+ *
730
+ * `ensureCollectionSchema` calls it to recognise that shape and say so.
731
+ * Returns the same string as `generateForeignKeyName` for every regular plural,
732
+ * so a caller can compare the two and act only when they differ.
733
+ */
734
+ function legacyForeignKeyName(name) {
735
+ const snake = toSnakeCase(name);
736
+ return `${snake.endsWith("s") ? snake.slice(0, -1) : snake}_id`;
685
737
  }
686
738
  //#endregion
687
739
  //#region src/fields.ts
@@ -712,6 +764,6 @@ function isDefaultFieldConfigId(id) {
712
764
  ].includes(id);
713
765
  }
714
766
  //#endregion
715
- export { camelCase, clone, deepClone, defaultDateFormat, flattenObject, generateForeignKeyName, getArrayValuesCount, getHashValue, getIn, getPolicyNameHash, getPolicyNamesForRule, getPolicyNamesForRules, getPolicyOperations, getValueInPath, hashString, hydrateRegExp, isDefaultFieldConfigId, isEmptyArray, isEmptyObject, isFunction, isInteger, isNaN, isObject, isPlainObject, isValidRegExp, mergeDeep, pick, plural, prettifyIdentifier, randomColor, randomString, removeFunctions, removeInPath, removeNulls, removePropsIfExisting, removeUndefined, serializeRegExp, setIn, sha1Hex, singular, slugify, toArray, toKebabCase, toSnakeCase, unslugify };
767
+ export { camelCase, clone, deepClone, defaultDateFormat, flattenObject, generateForeignKeyName, getArrayValuesCount, getHashValue, getIn, getPolicyNameHash, getPolicyNamesForRule, getPolicyNamesForRules, getPolicyOperations, getValueInPath, hashString, hydrateRegExp, isDefaultFieldConfigId, isEmptyArray, isEmptyObject, isFunction, isInteger, isNaN, isObject, isPlainObject, isValidRegExp, legacyForeignKeyName, mergeDeep, pick, plural, prettifyIdentifier, randomColor, randomString, removeFunctions, removeInPath, removeNulls, removePropsIfExisting, removeUndefined, serializeRegExp, setIn, sha1Hex, singular, slugify, toArray, toKebabCase, toSnakeCase, unslugify };
716
768
 
717
769
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","names":[],"sources":["../src/strings.ts","../src/objects.ts","../src/arrays.ts","../src/dates.ts","../src/hash.ts","../src/sha1.ts","../src/policy-names.ts","../src/regexp.ts","../src/flatten_object.ts","../src/plurals.ts","../src/names.ts","../src/fields.ts"],"sourcesContent":["const tokenizeRegex = /[A-Z]{2,}(?=[A-Z][a-z]|\\b)|[A-Z]?[a-z]+|[0-9]+(?:[a-z](?![a-z]))?|[A-Z]/g;\n\nexport const toKebabCase = (str?: string) => {\n if (!str || typeof str !== \"string\") return \"\";\n const regExpMatchArray = str.match(tokenizeRegex);\n if (!regExpMatchArray) return \"\";\n return regExpMatchArray\n .map(x => x.toLowerCase())\n .join(\"-\");\n};\n\nconst snakeCaseRegex = tokenizeRegex;\n\nexport const toSnakeCase = (str?: string) => {\n if (!str || typeof str !== \"string\") return \"\";\n const regExpMatchArray = str.match(snakeCaseRegex);\n if (!regExpMatchArray) return \"\";\n return regExpMatchArray\n .map(x => x.toLowerCase())\n .join(\"_\");\n};\n\nexport function camelCase(str: string): string {\n if (!str) return \"\";\n if (str.length === 1) return str.toLowerCase();\n\n // Split by hyphens, underscores, or spaces and filter out empty strings\n const parts = str.split(/[-_ ]+/).filter(Boolean);\n\n if (parts.length === 0) return \"\";\n\n // Start with first part in lowercase\n return parts[0].toLowerCase() +\n // Transform remaining parts to have first letter uppercase\n parts.slice(1)\n .map(part => part.charAt(0).toUpperCase() + part.substring(1).toLowerCase())\n .join(\"\");\n}\n\n/**\n * A random base-36 string of exactly `strLength` characters.\n *\n * Not `Math.random().toString(36).slice(2, 2 + strLength)`: that has no\n * guaranteed length. Base-36 of a double drops trailing zeros, so the source\n * string is short about once in 36 calls and the slice quietly returns fewer\n * characters than asked for — `randomString(10)` returning 9. These values\n * prefix uploaded filenames to keep them apart, so a short one is a likelier\n * collision, and it fails at the rate that makes a test look flaky.\n */\nexport function randomString(strLength = 5) {\n const alphabet = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n let result = \"\";\n for (let i = 0; i < strLength; i++) {\n result += alphabet.charAt(Math.floor(Math.random() * alphabet.length));\n }\n return result;\n}\n\nexport function randomColor() {\n return Math.floor(Math.random() * 16777215).toString(16);\n}\n\nexport function slugify(text?: string, separator = \"_\", lowercase = true) {\n if (!text) return \"\";\n const from = \"ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-\"\n const to = `aaaaaeeeeeiiiiooooouuuunc${separator}${separator}${separator}${separator}${separator}${separator}${separator}`;\n\n for (let i = 0, l = from.length; i < l; i++) {\n text = text.replace(new RegExp(from.charAt(i), \"g\"), to.charAt(i));\n }\n\n text = text\n .toString() // Cast to string\n .trim() // Remove whitespace from both sides of a string\n .replace(/^\\s+|\\s+$/g, \"\")\n .replace(/\\s+/g, separator) // Replace spaces with separator\n .replace(/&/g, separator) // Replace & with separator\n .replace(/[^\\w\\\\-]+/g, \"\") // Remove all non-word chars\n .replace(new RegExp(\"\\\\\" + separator + \"\\\\\" + separator + \"+\", \"g\"),\n separator); // Replace multiple separators with single one\n\n return lowercase\n ? text.toLowerCase() // Convert the string to lowercase letters\n : text;\n}\n\nexport function unslugify(slug?: string): string {\n if (!slug) return \"\";\n if (slug.includes(\"-\") || slug.includes(\"_\") || !slug.includes(\" \")) {\n const result = slug.replace(/[-_]/g, \" \");\n return result.replace(/\\w\\S*/g, function (txt) {\n return txt.charAt(0).toUpperCase() + txt.substring(1);\n }).trim();\n } else {\n return slug.trim();\n }\n}\n\nexport function prettifyIdentifier(input: string) {\n if (!input) return \"\";\n\n let text = input;\n\n // 1. Handle camelCase and Acronyms\n // Group 1 ($1 $2): Lowercase followed by Uppercase (e.g., imageURL -> image URL)\n // Group 2 ($3 $4): Uppercase followed by Uppercase+lowercase (e.g., XMLParser -> XML Parser)\n text = text.replace(/([a-z])([A-Z])|([A-Z])([A-Z][a-z])/g, \"$1$3 $2$4\");\n\n // 2. Replace hyphens/underscores with spaces\n text = text.replace(/[_-]+/g, \" \");\n\n // 3. Capitalize first letter of each word (Title Case)\n const s = text\n .trim()\n .replace(/\\b\\w/g, (char) => char.toUpperCase());\n return s;\n}\n","import hash from \"object-hash\";\nimport { GeoPoint } from \"@rebasepro/types\";\n\n/** @private is the value an empty array? */\nexport const isEmptyArray = (value?: unknown) =>\n Array.isArray(value) && value.length === 0;\n\n/** @private is the given object a Function? */\nexport const isFunction = (obj: unknown): obj is (...args: unknown[]) => unknown =>\n typeof obj === \"function\";\n\n/** @private is the given object an integer? */\nexport const isInteger = (obj: unknown): boolean =>\n String(Math.floor(Number(obj))) === String(obj);\n\n/** @private is the given object a NaN? */\n\nexport const isNaN = (obj: unknown): boolean => obj !== obj;\n\n/**\n * Deeply get a value from an object via its path.\n */\nexport function getIn(\n obj: Record<string, unknown> | unknown[] | unknown,\n key: string | string[],\n def?: unknown,\n p = 0\n) {\n const path = toPath(key);\n while (obj && p < path.length) {\n obj = (obj as Record<string, unknown>)[path[p++]];\n }\n\n // check if path is not in the end\n if (p !== path.length && !obj) {\n return def;\n }\n\n return obj === undefined ? def : obj;\n}\n\nexport function setIn<T>(obj: T, path: string, value: unknown): T {\n const res = clone(obj) as Record<string, unknown>;\n let resVal: Record<string, unknown> = res;\n let i = 0;\n const pathArray = toPath(path);\n\n for (; i < pathArray.length - 1; i++) {\n const currentPath: string = pathArray[i];\n const currentObj = getIn(obj as Record<string, unknown>, pathArray.slice(0, i + 1));\n\n if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {\n resVal = resVal[currentPath] = clone(currentObj) as Record<string, unknown>;\n } else {\n const nextPath: string = pathArray[i + 1];\n resVal = resVal[currentPath] =\n (isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {}) as Record<string, unknown>;\n }\n }\n\n // Return original object if new value is the same as current\n if ((i === 0 ? obj as Record<string, unknown> : resVal)[pathArray[i]] === value) {\n return obj;\n }\n\n if (value === undefined) {\n delete resVal[pathArray[i]];\n } else {\n resVal[pathArray[i]] = value;\n }\n\n // If the path array has a single element, the loop did not run.\n // Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.\n if (i === 0 && value === undefined) {\n delete res[pathArray[i]];\n }\n\n return res as T;\n}\n\nexport function clone<T>(value: T): T {\n if (Array.isArray(value)) {\n return [...value] as T;\n } else if (typeof value === \"object\" && value !== null) {\n return { ...value } as T;\n } else {\n return value; // This is for primitive types which do not need cloning.\n }\n}\n\n/**\n * Deep clone a value, preserving function references and class instances.\n * Unlike structuredClone, this handles objects that contain functions\n * (e.g. CollectionConfig with target(), childCollections(), callbacks).\n */\nexport function deepClone<T>(value: T): T {\n if (value === null || value === undefined) return value;\n if (typeof value === \"function\") return value;\n if (typeof value !== \"object\") return value;\n\n if (Array.isArray(value)) {\n return value.map(item => deepClone(item)) as T;\n }\n\n // Preserve class instances (Date, GeoPoint, etc.) — don't recurse\n if (Object.getPrototypeOf(value) !== Object.prototype) {\n return value;\n }\n\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n result[key] = deepClone((value as Record<string, unknown>)[key]);\n }\n return result as T;\n}\n\nfunction toPath(value: string | string[]) {\n if (Array.isArray(value)) return value; // Already in path array form.\n // Replace brackets with dots, remove leading/trailing dots, then split by dot.\n return value.replace(/\\[(\\d+)]/g, \".$1\").replace(/^\\./, \"\").replace(/\\.$/, \"\").split(\".\");\n}\n\n\nexport const pick: <T extends Record<string, unknown>>(obj: T, ...args: (keyof T)[]) => Partial<T> = <T extends Record<string, unknown>>(obj: T, ...args: (keyof T)[]) => ({\n ...args.reduce<Record<string, unknown>>((res, key) => ({\n ...res,\n [key as string]: obj[key as string]\n }), {})\n}) as Partial<T>;\n\nexport function isObject(item: unknown): item is Record<string, unknown> {\n return !!item && typeof item === \"object\" && !Array.isArray(item);\n}\n\nexport function isPlainObject(obj: unknown): obj is Record<string, unknown> {\n // 1. Rule out non-objects, null, and arrays\n if (typeof obj !== \"object\" || obj === null || Array.isArray(obj)) {\n return false;\n }\n\n // 2. Get the object's direct prototype\n const proto = Object.getPrototypeOf(obj);\n\n // 3. A plain object's direct prototype is Object.prototype\n return proto === Object.prototype;\n}\n\nexport function mergeDeep<T extends object, U extends object>(\n target: T,\n source: U,\n ignoreUndefined = false\n): T & U {\n // If target is not a true object (e.g., null, array, primitive), return target itself.\n if (!isObject(target)) {\n return target as T & U;\n }\n\n // Create a shallow copy of the target to avoid modifying the original object.\n const output = { ...target };\n\n // If source is not a true object, there's nothing to merge from it.\n // Return the shallow copy of target.\n if (!isObject(source)) {\n return output as T & U;\n }\n\n // Iterate over keys in the source object.\n for (const key in source) {\n if (key === \"__proto__\" || key === \"constructor\" || key === \"prototype\") {\n continue;\n }\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n const sourceValue = source[key];\n const outputValue = (output as Record<string, unknown>)[key]; // Current value in our merged object (originating from target)\n\n // Skip if source value is undefined and ignoreUndefined is true.\n // This handles both not adding new undefined properties and not overwriting existing properties with undefined.\n if (ignoreUndefined && sourceValue === undefined) {\n continue;\n }\n\n if (sourceValue instanceof Date) {\n // If source value is a Date, create a new Date instance.\n (output as Record<string, unknown>)[key] = new Date(sourceValue.getTime());\n } else if (Array.isArray(sourceValue)) {\n if (Array.isArray(outputValue)) {\n // If the array contains primitives or class instances (non-plain objects),\n // overwrite the array entirely instead of doing element-wise merging.\n const hasPlainObjects = sourceValue.some(isPlainObject) || outputValue.some(isPlainObject);\n if (!hasPlainObjects) {\n (output as Record<string, unknown>)[key] = [...sourceValue];\n } else {\n const newArray = [];\n const maxLength = Math.max(outputValue.length, sourceValue.length);\n for (let i = 0; i < maxLength; i++) {\n const sourceItem = sourceValue[i];\n const targetItem = outputValue[i];\n\n if (i >= sourceValue.length) { // source is shorter\n newArray[i] = targetItem;\n } else if (i >= outputValue.length) { // target is shorter\n newArray[i] = sourceItem;\n } else if (sourceItem === null) {\n newArray[i] = targetItem;\n } else if (isPlainObject(sourceItem) && isPlainObject(targetItem)) {\n // Only recursively merge plain objects, preserve class instances\n newArray[i] = mergeDeep(targetItem, sourceItem, ignoreUndefined);\n } else {\n // For class instances and primitives, use source directly\n newArray[i] = sourceItem;\n }\n }\n (output as Record<string, unknown>)[key] = newArray;\n }\n } else {\n // If output's value (from target) is not an array,\n // overwrite with a shallow copy of the source array.\n (output as Record<string, unknown>)[key] = [...sourceValue];\n }\n } else if (isPlainObject(sourceValue)) {\n // If source value is a plain object (not a class instance like EntityReference, GeoPoint, etc.):\n if (isPlainObject(outputValue)) {\n // If the corresponding value in output (from target) is also a plain object, recurse.\n // Ensure the ignoreUndefined flag is passed down.\n (output as Record<string, unknown>)[key] = mergeDeep(outputValue as Record<string, unknown>, sourceValue, ignoreUndefined);\n } else {\n // If output's value (from target) is not a plain object (e.g., null, primitive, class instance, or key didn't exist in original target),\n // overwrite with the source object.\n (output as Record<string, unknown>)[key] = sourceValue;\n }\n } else if (isObject(sourceValue)) {\n // If source value is a class instance (not a plain object), use it directly to preserve prototype\n (output as Record<string, unknown>)[key] = sourceValue;\n } else {\n // If source value is a primitive, null, or undefined (and not ignored).\n (output as Record<string, unknown>)[key] = sourceValue;\n }\n }\n }\n\n return output as T & U;\n}\n\nexport function getValueInPath(o: object | undefined, path: string): unknown {\n if (!o) return undefined;\n if (typeof o === \"object\") {\n if (path in o) {\n return (o as Record<string, unknown>)[path];\n }\n if (path.includes(\".\") || path.includes(\"[\")) {\n let pathSegments = path.split(/[.[]/);\n if (path.includes(\"[\")) {\n pathSegments = pathSegments.map(segment => segment.replace(\"]\", \"\"));\n }\n const firstSegment = pathSegments[0];\n const isArrayAndIndexExists = Array.isArray((o as Record<string, unknown>)[firstSegment]) && !isNaN(parseInt(pathSegments[1]));\n const nextObject = isArrayAndIndexExists\n ? ((o as Record<string, unknown>)[firstSegment] as unknown[])[parseInt(pathSegments[1])]\n : (o as Record<string, unknown>)[firstSegment];\n\n const nextPath = pathSegments.slice(isArrayAndIndexExists ? 2 : 1).join(\".\");\n if (nextPath === \"\")\n return nextObject;\n return getValueInPath(nextObject as object | undefined, nextPath);\n }\n }\n return undefined;\n}\n\nexport function removeInPath(o: object, path: string): object | undefined {\n const res = clone(o) as Record<string, unknown>;\n let current = res;\n const parts = path.split(\".\");\n const last = parts.pop();\n for (const part of parts) {\n if (part in current && current[part] !== null && typeof current[part] === \"object\") {\n current[part] = clone(current[part]) as Record<string, unknown>;\n current = current[part] as Record<string, unknown>;\n } else {\n return res;\n }\n }\n if (last && current && typeof current === \"object\") {\n delete current[last];\n }\n return res;\n}\n\nexport function removeFunctions(o: unknown): unknown {\n if (o === undefined) return undefined;\n if (o === null) return null;\n if (typeof o === \"object\") {\n // Handle arrays first - map over them recursively\n if (Array.isArray(o)) {\n return o.map(v => removeFunctions(v));\n }\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them\n if (!isPlainObject(o)) {\n return o;\n }\n return Object.entries(o)\n .filter(([_, value]) => typeof value !== \"function\")\n .map(([key, value]) => {\n if (Array.isArray(value)) {\n return { [key]: value.map(v => removeFunctions(v)) };\n } else if (typeof value === \"object\") {\n return { [key]: removeFunctions(value) };\n } else return { [key]: value };\n })\n .reduce((a, b) => ({ ...a,\n...b }), {});\n }\n return o;\n}\n\nexport function getHashValue<T>(v: T): string | null {\n if (!v) return null;\n if (typeof v === \"object\" && v !== null) {\n if (\"id\" in v)\n return String((v as Record<string, unknown>).id);\n else if (v instanceof Date)\n return v.toLocaleString();\n else if (v instanceof GeoPoint)\n return hash(v as Record<string, unknown>);\n }\n return hash(v as object, { ignoreUnknown: true });\n}\n\nexport function removeUndefined(value: unknown, removeEmptyStrings?: boolean): unknown {\n if (typeof value === \"function\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((v: unknown) => removeUndefined(v, removeEmptyStrings));\n }\n if (typeof value === \"object\") {\n if (value === null)\n return value;\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them\n if (!isPlainObject(value)) {\n return value;\n }\n const res: Record<string, unknown> = {};\n Object.keys(value).forEach((key) => {\n if (!isEmptyObject(value as object)) {\n const childRes = removeUndefined((value as Record<string, unknown>)[key], removeEmptyStrings);\n const isString = typeof childRes === \"string\";\n const shouldKeepIfString = !removeEmptyStrings || (removeEmptyStrings && !isString) || (removeEmptyStrings && isString && childRes !== \"\");\n if (childRes !== undefined && !isEmptyObject(childRes as object) && shouldKeepIfString)\n res[key] = childRes;\n }\n });\n return res;\n }\n return value;\n}\n\nexport function removeNulls(value: unknown): unknown {\n if (typeof value === \"function\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((v: unknown) => removeNulls(v));\n }\n if (typeof value === \"object\") {\n if (value === null)\n return value;\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them\n if (!isPlainObject(value)) {\n return value;\n }\n const res: Record<string, unknown> = {};\n const obj = value as Record<string, unknown>;\n Object.keys(obj).forEach((key) => {\n if (obj[key] !== null)\n res[key] = removeNulls(obj[key]);\n });\n return res;\n }\n return value;\n}\n\nexport function isEmptyObject(obj: object) {\n return obj &&\n Object.getPrototypeOf(obj) === Object.prototype &&\n Object.keys(obj).length === 0\n}\n\nexport function removePropsIfExisting(source: Record<string, unknown> | unknown[], comparison: Record<string, unknown> | unknown[]) {\n const isObject = (val: unknown): val is Record<string, unknown> => typeof val === \"object\" && val !== null;\n const isArray = (val: unknown): val is unknown[] => Array.isArray(val);\n\n if (!isObject(source) || !isObject(comparison)) {\n return source;\n }\n\n const res = isArray(source) ? [...source] : { ...source };\n\n if (isArray(res)) {\n for (let i = res.length - 1; i >= 0; i--) {\n if (res[i] === comparison[i]) {\n res.splice(i, 1);\n } else if (isObject(res[i]) && isObject(comparison[i])) {\n res[i] = removePropsIfExisting(res[i] as unknown as Record<string, unknown>, (comparison as unknown as unknown[])[i] as Record<string, unknown>);\n }\n }\n } else {\n Object.keys(comparison).forEach(key => {\n if (key in res) {\n if (isObject(res[key]) && isObject(comparison[key])) {\n res[key] = removePropsIfExisting(res[key], comparison[key]);\n } else if (res[key] === comparison[key]) {\n delete res[key];\n }\n }\n });\n }\n\n return res;\n}\n","export function toArray<T>(input?: T | T[]): T[] {\n return Array.isArray(input) ? input : (input ? [input] : []);\n}\n","export const defaultDateFormat = \"MMMM dd, yyyy, HH:mm:ss\";\n","export function hashString(str: string): number {\n if (!str) return 0;\n let hash = 0;\n let i;\n let chr;\n for (i = 0; i < str.length; i++) {\n chr = str.charCodeAt(i);\n hash = ((hash << 5) - hash) + chr;\n hash |= 0; // Convert to 32bit integer\n }\n return Math.abs(hash);\n}\n","/**\n * Minimal SHA-1 implementation that runs in both Node and the browser.\n *\n * This exists because generated Postgres policy names embed a SHA-1 digest of\n * the security rule. The DDL generator runs on the server (where `node:crypto`\n * is available) but the Studio has to derive the same names in the browser to\n * tell a policy it generated apart from one it did not. `node:crypto` cannot be\n * bundled for the browser, so the shared derivation needs a portable digest.\n *\n * SHA-1 is used purely to name things deterministically — never for security.\n * The output is byte-identical to `createHash(\"sha1\").update(str).digest(\"hex\")`,\n * which `sha1.test.ts` pins against `node:crypto` directly.\n */\n\n/** Rotate a 32-bit word left by `n` bits. */\nfunction rotl(value: number, n: number): number {\n return (value << n) | (value >>> (32 - n));\n}\n\n/**\n * SHA-1 digest of a string, hex-encoded.\n *\n * The input is encoded as UTF-8, matching Node's default handling of strings\n * passed to `hash.update(str)`.\n */\nexport function sha1Hex(input: string): string {\n const bytes: number[] = Array.from(new TextEncoder().encode(input));\n const bitLength = bytes.length * 8;\n\n // Padding: 0x80, then zeroes up to 56 bytes mod 64, then the length as a\n // 64-bit big-endian integer.\n bytes.push(0x80);\n while (bytes.length % 64 !== 56) bytes.push(0);\n\n const hi = Math.floor(bitLength / 0x100000000);\n const lo = bitLength >>> 0;\n bytes.push((hi >>> 24) & 0xff, (hi >>> 16) & 0xff, (hi >>> 8) & 0xff, hi & 0xff);\n bytes.push((lo >>> 24) & 0xff, (lo >>> 16) & 0xff, (lo >>> 8) & 0xff, lo & 0xff);\n\n let h0 = 0x67452301;\n let h1 = 0xefcdab89;\n let h2 = 0x98badcfe;\n let h3 = 0x10325476;\n let h4 = 0xc3d2e1f0;\n\n const w = new Array<number>(80);\n\n for (let offset = 0; offset < bytes.length; offset += 64) {\n for (let i = 0; i < 16; i++) {\n const j = offset + i * 4;\n w[i] = ((bytes[j] << 24) | (bytes[j + 1] << 16) | (bytes[j + 2] << 8) | bytes[j + 3]) | 0;\n }\n for (let i = 16; i < 80; i++) {\n w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);\n }\n\n let a = h0;\n let b = h1;\n let c = h2;\n let d = h3;\n let e = h4;\n\n for (let i = 0; i < 80; i++) {\n let f: number;\n let k: number;\n if (i < 20) {\n f = (b & c) | (~b & d);\n k = 0x5a827999;\n } else if (i < 40) {\n f = b ^ c ^ d;\n k = 0x6ed9eba1;\n } else if (i < 60) {\n f = (b & c) | (b & d) | (c & d);\n k = 0x8f1bbcdc;\n } else {\n f = b ^ c ^ d;\n k = 0xca62c1d6;\n }\n\n const temp = (rotl(a, 5) + f + e + k + w[i]) | 0;\n e = d;\n d = c;\n c = rotl(b, 30);\n b = a;\n a = temp;\n }\n\n h0 = (h0 + a) | 0;\n h1 = (h1 + b) | 0;\n h2 = (h2 + c) | 0;\n h3 = (h3 + d) | 0;\n h4 = (h4 + e) | 0;\n }\n\n return [h0, h1, h2, h3, h4]\n .map(word => (word >>> 0).toString(16).padStart(8, \"0\"))\n .join(\"\");\n}\n","import type { SecurityOperation, SecurityRule } from \"@rebasepro/types\";\nimport { sha1Hex } from \"./sha1\";\n\n/**\n * Naming of the Postgres policies generated from a collection's security rules.\n *\n * A rule without an explicit `name` is compiled to `<table>_<op>_<hash>`, where\n * the hash covers the rule's semantics. The Studio needs the same names to tell\n * \"this policy came from your code\" apart from \"someone wrote this in SQL\" —\n * without them it treats generated policies as foreign and offers to import\n * them back into the codebase they came from.\n *\n * This is the single definition of that naming. The DDL and Drizzle generators\n * both derive names from here, so a change cannot silently rename every policy\n * in every deployed database while the UI keeps matching the old ones.\n */\n\n/** Stable digest of the parts of a rule that determine what the policy does. */\nexport function getPolicyNameHash(rule: SecurityRule): string {\n const data = JSON.stringify({\n a: rule.access,\n m: rule.mode,\n op: rule.operation,\n ops: rule.operations?.slice().sort(),\n own: rule.ownerField,\n rol: rule.roles?.slice().sort(),\n pg: rule.pgRoles?.slice().sort(),\n u: rule.using,\n w: rule.withCheck,\n c: rule.condition,\n ch: rule.check\n });\n return sha1Hex(data).substring(0, 7);\n}\n\n/** The operations a rule expands to — `operations` wins over `operation`. */\nexport function getPolicyOperations(rule: SecurityRule): readonly SecurityOperation[] {\n return rule.operations && rule.operations.length > 0\n ? rule.operations\n : [rule.operation ?? \"all\"];\n}\n\n/**\n * Every Postgres policy name a single rule compiles to — one per operation.\n *\n * @param rule The security rule as written in the collection config.\n * @param tableName The rule's table (see `getTableName` in `@rebasepro/common`).\n */\nexport function getPolicyNamesForRule(rule: SecurityRule, tableName: string): string[] {\n const ops = getPolicyOperations(rule);\n const ruleHash = getPolicyNameHash(rule);\n\n return ops.map((op, opIdx) => rule.name\n ? (ops.length > 1 ? `${rule.name}_${op}` : rule.name)\n : `${tableName}_${op}_${ruleHash}${ops.length > 1 ? `_${opIdx}` : \"\"}`);\n}\n\n/** Every policy name a set of rules compiles to, for membership checks. */\nexport function getPolicyNamesForRules(rules: SecurityRule[], tableName: string): Set<string> {\n const names = new Set<string>();\n for (const rule of rules) {\n for (const name of getPolicyNamesForRule(rule, tableName)) names.add(name);\n }\n return names;\n}\n","export function serializeRegExp(input: RegExp): string {\n if (!input) return \"\";\n // const fragments = input.toString().match(/\\/(.*?)\\/([a-z]*)?$/i);\n // if (fragments) {\n // if (fragments[2])\n // return input.toString();\n // return fragments[1];\n // }\n return input.toString();\n}\n\n/**\n * Get a RegExp out of a serialized string\n * @param input\n */\nexport function hydrateRegExp(input?: string): RegExp | undefined {\n if (!input) return undefined;\n const fragments = input.match(/\\/(.*?)\\/([a-z]*)?$/i);\n if (fragments) {\n return new RegExp(fragments[1], fragments[2] || \"\");\n } else {\n return new RegExp(input, \"\");\n }\n}\n\nexport function isValidRegExp(input: string): boolean {\n const fullRegexp = input.match(/\\/((?![*+?])(?:[^\\r\\n[/\\\\]|\\\\.|\\[(?:[^\\r\\n\\]\\\\]|\\\\.)*])+)\\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/);\n if (fullRegexp)\n return true;\n const simpleRegexp = input.match(/((?![*+?])(?:[^\\r\\n[/\\\\]|\\\\.|\\[(?:[^\\r\\n\\]\\\\]|\\\\.)*])+)/);\n return !!simpleRegexp;\n}\n","export function flattenObject(obj: Record<string, unknown>, parentKey = \"\") {\n if (!obj) return obj;\n return Object.keys(obj).reduce((flatObj, key) => {\n const newKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n if (Array.isArray(obj[key])) {\n obj[key].forEach((item: unknown, index: number) => {\n if (typeof item === \"object\" && item !== null) {\n Object.assign(flatObj, flattenObject(item as Record<string, unknown>, `${newKey}[${index}]`));\n } else {\n flatObj[`${newKey}[${index}]`] = item;\n }\n });\n } else {\n Object.assign(flatObj, flattenObject(obj[key] as Record<string, unknown>, newKey));\n }\n } else {\n flatObj[newKey] = obj[key];\n }\n\n return flatObj;\n }, {} as { [key: string]: unknown });\n}\n\n\n// map from nested property key like \"a.b.c\" to the maximum array count found in a list of objects for that array\nexport type ArrayValuesCount = Record<string, number>;\n\nexport function getArrayValuesCount(array: Record<string, unknown>[]): ArrayValuesCount {\n return array.reduce((acc: ArrayValuesCount, obj: Record<string, unknown>) => {\n Object.entries(obj).forEach(([key, value]) => {\n // proceed only if value is an array\n if (Array.isArray(value)) {\n acc[key] = Math.max(acc[key] || 0, value.length);\n }\n\n // handle nested object\n if (typeof value === \"object\" && value !== null) {\n const nested = getArrayValuesCount([value as Record<string, unknown>]);\n Object.entries(nested).forEach(([nestedKey, nestedCount]) => {\n const compoundKey = `${key}.${nestedKey}`;\n acc[compoundKey] = Math.max(acc[compoundKey] || 0, nestedCount);\n });\n }\n });\n return acc;\n }, {});\n}\n","/**\n * Returns the plural of an English word.\n *\n * @param {string} word\n * @param {number} [amount]\n * @returns {string}\n */\nexport function plural(word: string, amount?: number): string {\n if (amount !== undefined && amount === 1) {\n return word\n }\n const plurals: { [key: string]: string } = {\n \"(quiz)$\": \"$1zes\",\n \"^(ox)$\": \"$1en\",\n \"([m|l])ouse$\": \"$1ice\",\n \"(matr|vert|ind)ix|ex$\": \"$1ices\",\n \"(x|ch|ss|sh)$\": \"$1es\",\n \"([^aeiouy]|qu)y$\": \"$1ies\",\n \"(hive)$\": \"$1s\",\n \"(?:([^f])fe|([lr])f)$\": \"$1$2ves\",\n \"(shea|lea|loa|thie)f$\": \"$1ves\",\n sis$: \"ses\",\n \"([ti])um$\": \"$1a\",\n \"(tomat|potat|ech|her|vet)o$\": \"$1oes\",\n \"(bu)s$\": \"$1ses\",\n \"(alias)$\": \"$1es\",\n \"(octop)us$\": \"$1i\",\n \"(ax|test)is$\": \"$1es\",\n \"(us)$\": \"$1es\",\n \"([^s]+)$\": \"$1s\"\n }\n const irregular: { [key: string]: string } = {\n move: \"moves\",\n foot: \"feet\",\n goose: \"geese\",\n sex: \"sexes\",\n child: \"children\",\n man: \"men\",\n tooth: \"teeth\",\n person: \"people\"\n }\n const uncountable: string[] = [\n \"sheep\",\n \"fish\",\n \"deer\",\n \"moose\",\n \"series\",\n \"species\",\n \"money\",\n \"rice\",\n \"information\",\n \"equipment\",\n \"bison\",\n \"cod\",\n \"offspring\",\n \"pike\",\n \"salmon\",\n \"shrimp\",\n \"swine\",\n \"trout\",\n \"aircraft\",\n \"hovercraft\",\n \"spacecraft\",\n \"sugar\",\n \"tuna\",\n \"you\",\n \"wood\"\n ]\n // save some time in the case that singular and plural are the same\n if (uncountable.indexOf(word.toLowerCase()) >= 0) {\n return word;\n }\n // check for irregular forms\n for (const w in irregular) {\n const pattern = new RegExp(`${w}$`, \"i\")\n const replace = irregular[w]\n if (pattern.test(word)) {\n return word.replace(pattern, replace);\n }\n }\n // check for matches using regular expressions\n for (const reg in plurals) {\n const pattern = new RegExp(reg, \"i\")\n if (pattern.test(word)) {\n return word.replace(pattern, plurals[reg])\n }\n }\n return word;\n}\n\n/**\n * Returns the singular of an English word.\n *\n * @param {string} word\n * @param {number} [amount]\n * @returns {string}\n */\nexport function singular(word: string, amount?: number): string {\n if (amount !== undefined && amount !== 1) {\n return word;\n }\n const singulars: { [key: string]: string } = {\n \"(quiz)zes$\": \"$1\",\n \"(matr)ices$\": \"$1ix\",\n \"(vert|ind)ices$\": \"$1ex\",\n \"^(ox)en$\": \"$1\",\n \"(alias)es$\": \"$1\",\n \"(octop|vir)i$\": \"$1us\",\n \"(cris|ax|test)es$\": \"$1is\",\n \"(shoe)s$\": \"$1\",\n \"(o)es$\": \"$1\",\n \"(bus)es$\": \"$1\",\n \"([m|l])ice$\": \"$1ouse\",\n \"(x|ch|ss|sh)es$\": \"$1\",\n \"(m)ovies$\": \"$1ovie\",\n \"(s)eries$\": \"$1eries\",\n \"([^aeiouy]|qu)ies$\": \"$1y\",\n \"([lr])ves$\": \"$1f\",\n \"(tive)s$\": \"$1\",\n \"(hive)s$\": \"$1\",\n \"(li|wi|kni)ves$\": \"$1fe\",\n \"(shea|loa|lea|thie)ves$\": \"$1f\",\n \"(^analy)ses$\": \"$1sis\",\n \"((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$\": \"$1$2sis\",\n \"([ti])a$\": \"$1um\",\n \"(n)ews$\": \"$1ews\",\n \"(h|bl)ouses$\": \"$1ouse\",\n \"(corpse)s$\": \"$1\",\n \"(us)es$\": \"$1\",\n s$: \"\"\n }\n const irregular: { [key: string]: string } = {\n move: \"moves\",\n foot: \"feet\",\n goose: \"geese\",\n sex: \"sexes\",\n child: \"children\",\n man: \"men\",\n tooth: \"teeth\",\n person: \"people\"\n }\n const uncountable: string[] = [\n \"sheep\",\n \"fish\",\n \"deer\",\n \"moose\",\n \"series\",\n \"species\",\n \"money\",\n \"rice\",\n \"information\",\n \"equipment\",\n \"bison\",\n \"cod\",\n \"offspring\",\n \"pike\",\n \"salmon\",\n \"shrimp\",\n \"swine\",\n \"trout\",\n \"aircraft\",\n \"hovercraft\",\n \"spacecraft\",\n \"sugar\",\n \"tuna\",\n \"you\",\n \"wood\"\n ]\n // save some time in the case that singular and plural are the same\n if (uncountable.indexOf(word.toLowerCase()) >= 0) {\n return word;\n }\n // check for irregular forms\n for (const w in irregular) {\n const pattern = new RegExp(`${irregular[w]}$`, \"i\");\n if (pattern.test(word)) {\n return word.replace(pattern, w);\n }\n }\n // check for matches using regular expressions\n for (const reg in singulars) {\n const pattern = new RegExp(reg, \"i\");\n if (pattern.test(word)) {\n return word.replace(pattern, singulars[reg]);\n }\n }\n return word;\n}\n","import { toSnakeCase } from \"./strings\";\n\n/**\n * Generates a foreign key column name from a given string, typically a collection slug or name.\n * It converts the name to snake_case, attempts to singularize it by removing a trailing 's'\n * (a common convention for collection names), and appends '_id'.\n *\n * @param name The base name to convert to a foreign key.\n * @returns A foreign key name in the format 'singular_name_id'.\n *\n * @example\n * // returns \"user_id\"\n * generateForeignKeyName(\"users\")\n *\n * @example\n * // returns \"post_id\"\n * generateForeignKeyName(\"posts\")\n *\n * @example\n * // returns \"product_id\"\n * generateForeignKeyName(\"Product\")\n *\n */\nexport function generateForeignKeyName(name: string): string {\n const snakeCaseName = toSnakeCase(name);\n // A simple heuristic to singularize a plural name, which is a common convention.\n const singularName = snakeCaseName.endsWith(\"s\") ? snakeCaseName.slice(0, -1) : snakeCaseName;\n return `${singularName}_id`;\n}\n\n","\n\nexport function isDefaultFieldConfigId(id: string): boolean {\n return [\"text_field\",\n \"multiline\",\n \"markdown\",\n \"url\",\n \"email\",\n \"switch\",\n \"select\",\n \"multi_select\",\n \"number_input\",\n \"number_select\",\n \"multi_number_select\",\n \"file_upload\",\n \"multi_file_upload\",\n \"reference\",\n \"multi_references\",\n \"relation\",\n \"date_time\",\n \"group\",\n \"key_value\",\n \"repeat\",\n \"custom_array\",\n \"block\"\n ].includes(id);\n}\n"],"mappings":";;;AAAA,IAAM,gBAAgB;AAEtB,IAAa,eAAe,QAAiB;CACzC,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,mBAAmB,IAAI,MAAM,aAAa;CAChD,IAAI,CAAC,kBAAkB,OAAO;CAC9B,OAAO,iBACF,KAAI,MAAK,EAAE,YAAY,CAAC,EACxB,KAAK,GAAG;AACjB;AAEA,IAAM,iBAAiB;AAEvB,IAAa,eAAe,QAAiB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,OAAO;EACP,KAAK;EACL,OAAO;EACP,KAAK;EACL,OAAO;EACP,QAAQ;CACZ;CA6BA,IAAI;EA3BA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGA,EAAY,QAAQ,KAAK,YAAY,CAAC,KAAK,GAC3C,OAAO;CAGX,KAAK,MAAM,KAAK,WAAW;EACvB,MAAM,UAAU,IAAI,OAAO,GAAG,UAAU,GAAG,IAAI,GAAG;EAClD,IAAI,QAAQ,KAAK,IAAI,GACjB,OAAO,KAAK,QAAQ,SAAS,CAAC;CAEtC;CAEA,KAAK,MAAM,OAAO,WAAW;EACzB,MAAM,UAAU,IAAI,OAAO,KAAK,GAAG;EACnC,IAAI,QAAQ,KAAK,IAAI,GACjB,OAAO,KAAK,QAAQ,SAAS,UAAU,IAAI;CAEnD;CACA,OAAO;AACX;;;;;;;;;;;;;;;;;;;;;;;;ACpKA,SAAgB,uBAAuB,MAAsB;CACzD,MAAM,gBAAgB,YAAY,IAAI;CAGtC,OAAO,GADc,cAAc,SAAS,GAAG,IAAI,cAAc,MAAM,GAAG,EAAE,IAAI,cACzD;AAC3B;;;AC1BA,SAAgB,uBAAuB,IAAqB;CACxD,OAAO;EAAC;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,EAAE,SAAS,EAAE;AACjB"}
1
+ {"version":3,"file":"index.es.js","names":[],"sources":["../src/strings.ts","../src/objects.ts","../src/arrays.ts","../src/dates.ts","../src/hash.ts","../src/sha1.ts","../src/policy-names.ts","../src/regexp.ts","../src/flatten_object.ts","../src/plurals.ts","../src/names.ts","../src/fields.ts"],"sourcesContent":["const tokenizeRegex = /[A-Z]{2,}(?=[A-Z][a-z]|\\b)|[A-Z]?[a-z]+|[0-9]+(?:[a-z](?![a-z]))?|[A-Z]/g;\n\nexport const toKebabCase = (str?: string) => {\n if (!str || typeof str !== \"string\") return \"\";\n const regExpMatchArray = str.match(tokenizeRegex);\n if (!regExpMatchArray) return \"\";\n return regExpMatchArray\n .map(x => x.toLowerCase())\n .join(\"-\");\n};\n\nconst snakeCaseRegex = tokenizeRegex;\n\nexport const toSnakeCase = (str?: string) => {\n if (!str || typeof str !== \"string\") return \"\";\n const regExpMatchArray = str.match(snakeCaseRegex);\n if (!regExpMatchArray) return \"\";\n return regExpMatchArray\n .map(x => x.toLowerCase())\n .join(\"_\");\n};\n\nexport function camelCase(str: string): string {\n if (!str) return \"\";\n if (str.length === 1) return str.toLowerCase();\n\n // Split by hyphens, underscores, or spaces and filter out empty strings\n const parts = str.split(/[-_ ]+/).filter(Boolean);\n\n if (parts.length === 0) return \"\";\n\n // Start with first part in lowercase\n return parts[0].toLowerCase() +\n // Transform remaining parts to have first letter uppercase\n parts.slice(1)\n .map(part => part.charAt(0).toUpperCase() + part.substring(1).toLowerCase())\n .join(\"\");\n}\n\n/**\n * A random base-36 string of exactly `strLength` characters.\n *\n * Not `Math.random().toString(36).slice(2, 2 + strLength)`: that has no\n * guaranteed length. Base-36 of a double drops trailing zeros, so the source\n * string is short about once in 36 calls and the slice quietly returns fewer\n * characters than asked for — `randomString(10)` returning 9. These values\n * prefix uploaded filenames to keep them apart, so a short one is a likelier\n * collision, and it fails at the rate that makes a test look flaky.\n */\nexport function randomString(strLength = 5) {\n const alphabet = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n let result = \"\";\n for (let i = 0; i < strLength; i++) {\n result += alphabet.charAt(Math.floor(Math.random() * alphabet.length));\n }\n return result;\n}\n\nexport function randomColor() {\n return Math.floor(Math.random() * 16777215).toString(16);\n}\n\nexport function slugify(text?: string, separator = \"_\", lowercase = true) {\n if (!text) return \"\";\n const from = \"ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;-\"\n const to = `aaaaaeeeeeiiiiooooouuuunc${separator}${separator}${separator}${separator}${separator}${separator}${separator}`;\n\n for (let i = 0, l = from.length; i < l; i++) {\n text = text.replace(new RegExp(from.charAt(i), \"g\"), to.charAt(i));\n }\n\n text = text\n .toString() // Cast to string\n .trim() // Remove whitespace from both sides of a string\n .replace(/^\\s+|\\s+$/g, \"\")\n .replace(/\\s+/g, separator) // Replace spaces with separator\n .replace(/&/g, separator) // Replace & with separator\n .replace(/[^\\w\\\\-]+/g, \"\") // Remove all non-word chars\n .replace(new RegExp(\"\\\\\" + separator + \"\\\\\" + separator + \"+\", \"g\"),\n separator); // Replace multiple separators with single one\n\n return lowercase\n ? text.toLowerCase() // Convert the string to lowercase letters\n : text;\n}\n\nexport function unslugify(slug?: string): string {\n if (!slug) return \"\";\n if (slug.includes(\"-\") || slug.includes(\"_\") || !slug.includes(\" \")) {\n const result = slug.replace(/[-_]/g, \" \");\n return result.replace(/\\w\\S*/g, function (txt) {\n return txt.charAt(0).toUpperCase() + txt.substring(1);\n }).trim();\n } else {\n return slug.trim();\n }\n}\n\nexport function prettifyIdentifier(input: string) {\n if (!input) return \"\";\n\n let text = input;\n\n // 1. Handle camelCase and Acronyms\n // Group 1 ($1 $2): Lowercase followed by Uppercase (e.g., imageURL -> image URL)\n // Group 2 ($3 $4): Uppercase followed by Uppercase+lowercase (e.g., XMLParser -> XML Parser)\n text = text.replace(/([a-z])([A-Z])|([A-Z])([A-Z][a-z])/g, \"$1$3 $2$4\");\n\n // 2. Replace hyphens/underscores with spaces\n text = text.replace(/[_-]+/g, \" \");\n\n // 3. Capitalize first letter of each word (Title Case)\n const s = text\n .trim()\n .replace(/\\b\\w/g, (char) => char.toUpperCase());\n return s;\n}\n","import hash from \"object-hash\";\nimport { GeoPoint } from \"@rebasepro/types\";\n\n/** @private is the value an empty array? */\nexport const isEmptyArray = (value?: unknown) =>\n Array.isArray(value) && value.length === 0;\n\n/** @private is the given object a Function? */\nexport const isFunction = (obj: unknown): obj is (...args: unknown[]) => unknown =>\n typeof obj === \"function\";\n\n/** @private is the given object an integer? */\nexport const isInteger = (obj: unknown): boolean =>\n String(Math.floor(Number(obj))) === String(obj);\n\n/** @private is the given object a NaN? */\n\nexport const isNaN = (obj: unknown): boolean => obj !== obj;\n\n/**\n * Deeply get a value from an object via its path.\n */\nexport function getIn(\n obj: Record<string, unknown> | unknown[] | unknown,\n key: string | string[],\n def?: unknown,\n p = 0\n) {\n const path = toPath(key);\n while (obj && p < path.length) {\n obj = (obj as Record<string, unknown>)[path[p++]];\n }\n\n // check if path is not in the end\n if (p !== path.length && !obj) {\n return def;\n }\n\n return obj === undefined ? def : obj;\n}\n\nexport function setIn<T>(obj: T, path: string, value: unknown): T {\n const res = clone(obj) as Record<string, unknown>;\n let resVal: Record<string, unknown> = res;\n let i = 0;\n const pathArray = toPath(path);\n\n for (; i < pathArray.length - 1; i++) {\n const currentPath: string = pathArray[i];\n const currentObj = getIn(obj as Record<string, unknown>, pathArray.slice(0, i + 1));\n\n if (currentObj && (isObject(currentObj) || Array.isArray(currentObj))) {\n resVal = resVal[currentPath] = clone(currentObj) as Record<string, unknown>;\n } else {\n const nextPath: string = pathArray[i + 1];\n resVal = resVal[currentPath] =\n (isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {}) as Record<string, unknown>;\n }\n }\n\n // Return original object if new value is the same as current\n if ((i === 0 ? obj as Record<string, unknown> : resVal)[pathArray[i]] === value) {\n return obj;\n }\n\n if (value === undefined) {\n delete resVal[pathArray[i]];\n } else {\n resVal[pathArray[i]] = value;\n }\n\n // If the path array has a single element, the loop did not run.\n // Deleting on `resVal` had no effect in this scenario, so we delete on the result instead.\n if (i === 0 && value === undefined) {\n delete res[pathArray[i]];\n }\n\n return res as T;\n}\n\nexport function clone<T>(value: T): T {\n if (Array.isArray(value)) {\n return [...value] as T;\n } else if (typeof value === \"object\" && value !== null) {\n return { ...value } as T;\n } else {\n return value; // This is for primitive types which do not need cloning.\n }\n}\n\n/**\n * Deep clone a value, preserving function references and class instances.\n * Unlike structuredClone, this handles objects that contain functions\n * (e.g. CollectionConfig with target(), childCollections(), callbacks).\n */\nexport function deepClone<T>(value: T): T {\n if (value === null || value === undefined) return value;\n if (typeof value === \"function\") return value;\n if (typeof value !== \"object\") return value;\n\n if (Array.isArray(value)) {\n return value.map(item => deepClone(item)) as T;\n }\n\n // Preserve class instances (Date, GeoPoint, etc.) — don't recurse\n if (Object.getPrototypeOf(value) !== Object.prototype) {\n return value;\n }\n\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n result[key] = deepClone((value as Record<string, unknown>)[key]);\n }\n return result as T;\n}\n\nfunction toPath(value: string | string[]) {\n if (Array.isArray(value)) return value; // Already in path array form.\n // Replace brackets with dots, remove leading/trailing dots, then split by dot.\n return value.replace(/\\[(\\d+)]/g, \".$1\").replace(/^\\./, \"\").replace(/\\.$/, \"\").split(\".\");\n}\n\n\nexport const pick: <T extends Record<string, unknown>>(obj: T, ...args: (keyof T)[]) => Partial<T> = <T extends Record<string, unknown>>(obj: T, ...args: (keyof T)[]) => ({\n ...args.reduce<Record<string, unknown>>((res, key) => ({\n ...res,\n [key as string]: obj[key as string]\n }), {})\n}) as Partial<T>;\n\nexport function isObject(item: unknown): item is Record<string, unknown> {\n return !!item && typeof item === \"object\" && !Array.isArray(item);\n}\n\nexport function isPlainObject(obj: unknown): obj is Record<string, unknown> {\n // 1. Rule out non-objects, null, and arrays\n if (typeof obj !== \"object\" || obj === null || Array.isArray(obj)) {\n return false;\n }\n\n // 2. Get the object's direct prototype\n const proto = Object.getPrototypeOf(obj);\n\n // 3. A plain object's direct prototype is Object.prototype\n return proto === Object.prototype;\n}\n\nexport function mergeDeep<T extends object, U extends object>(\n target: T,\n source: U,\n ignoreUndefined = false\n): T & U {\n // If target is not a true object (e.g., null, array, primitive), return target itself.\n if (!isObject(target)) {\n return target as T & U;\n }\n\n // Create a shallow copy of the target to avoid modifying the original object.\n const output = { ...target };\n\n // If source is not a true object, there's nothing to merge from it.\n // Return the shallow copy of target.\n if (!isObject(source)) {\n return output as T & U;\n }\n\n // Iterate over keys in the source object.\n for (const key in source) {\n if (key === \"__proto__\" || key === \"constructor\" || key === \"prototype\") {\n continue;\n }\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n const sourceValue = source[key];\n const outputValue = (output as Record<string, unknown>)[key]; // Current value in our merged object (originating from target)\n\n // Skip if source value is undefined and ignoreUndefined is true.\n // This handles both not adding new undefined properties and not overwriting existing properties with undefined.\n if (ignoreUndefined && sourceValue === undefined) {\n continue;\n }\n\n if (sourceValue instanceof Date) {\n // If source value is a Date, create a new Date instance.\n (output as Record<string, unknown>)[key] = new Date(sourceValue.getTime());\n } else if (Array.isArray(sourceValue)) {\n if (Array.isArray(outputValue)) {\n // If the array contains primitives or class instances (non-plain objects),\n // overwrite the array entirely instead of doing element-wise merging.\n const hasPlainObjects = sourceValue.some(isPlainObject) || outputValue.some(isPlainObject);\n if (!hasPlainObjects) {\n (output as Record<string, unknown>)[key] = [...sourceValue];\n } else {\n const newArray = [];\n const maxLength = Math.max(outputValue.length, sourceValue.length);\n for (let i = 0; i < maxLength; i++) {\n const sourceItem = sourceValue[i];\n const targetItem = outputValue[i];\n\n if (i >= sourceValue.length) { // source is shorter\n newArray[i] = targetItem;\n } else if (i >= outputValue.length) { // target is shorter\n newArray[i] = sourceItem;\n } else if (sourceItem === null) {\n newArray[i] = targetItem;\n } else if (isPlainObject(sourceItem) && isPlainObject(targetItem)) {\n // Only recursively merge plain objects, preserve class instances\n newArray[i] = mergeDeep(targetItem, sourceItem, ignoreUndefined);\n } else {\n // For class instances and primitives, use source directly\n newArray[i] = sourceItem;\n }\n }\n (output as Record<string, unknown>)[key] = newArray;\n }\n } else {\n // If output's value (from target) is not an array,\n // overwrite with a shallow copy of the source array.\n (output as Record<string, unknown>)[key] = [...sourceValue];\n }\n } else if (isPlainObject(sourceValue)) {\n // If source value is a plain object (not a class instance like EntityReference, GeoPoint, etc.):\n if (isPlainObject(outputValue)) {\n // If the corresponding value in output (from target) is also a plain object, recurse.\n // Ensure the ignoreUndefined flag is passed down.\n (output as Record<string, unknown>)[key] = mergeDeep(outputValue as Record<string, unknown>, sourceValue, ignoreUndefined);\n } else {\n // If output's value (from target) is not a plain object (e.g., null, primitive, class instance, or key didn't exist in original target),\n // overwrite with the source object.\n (output as Record<string, unknown>)[key] = sourceValue;\n }\n } else if (isObject(sourceValue)) {\n // If source value is a class instance (not a plain object), use it directly to preserve prototype\n (output as Record<string, unknown>)[key] = sourceValue;\n } else {\n // If source value is a primitive, null, or undefined (and not ignored).\n (output as Record<string, unknown>)[key] = sourceValue;\n }\n }\n }\n\n return output as T & U;\n}\n\nexport function getValueInPath(o: object | undefined, path: string): unknown {\n if (!o) return undefined;\n if (typeof o === \"object\") {\n if (path in o) {\n return (o as Record<string, unknown>)[path];\n }\n if (path.includes(\".\") || path.includes(\"[\")) {\n let pathSegments = path.split(/[.[]/);\n if (path.includes(\"[\")) {\n pathSegments = pathSegments.map(segment => segment.replace(\"]\", \"\"));\n }\n const firstSegment = pathSegments[0];\n const isArrayAndIndexExists = Array.isArray((o as Record<string, unknown>)[firstSegment]) && !isNaN(parseInt(pathSegments[1]));\n const nextObject = isArrayAndIndexExists\n ? ((o as Record<string, unknown>)[firstSegment] as unknown[])[parseInt(pathSegments[1])]\n : (o as Record<string, unknown>)[firstSegment];\n\n const nextPath = pathSegments.slice(isArrayAndIndexExists ? 2 : 1).join(\".\");\n if (nextPath === \"\")\n return nextObject;\n return getValueInPath(nextObject as object | undefined, nextPath);\n }\n }\n return undefined;\n}\n\nexport function removeInPath(o: object, path: string): object | undefined {\n const res = clone(o) as Record<string, unknown>;\n let current = res;\n const parts = path.split(\".\");\n const last = parts.pop();\n for (const part of parts) {\n if (part in current && current[part] !== null && typeof current[part] === \"object\") {\n current[part] = clone(current[part]) as Record<string, unknown>;\n current = current[part] as Record<string, unknown>;\n } else {\n return res;\n }\n }\n if (last && current && typeof current === \"object\") {\n delete current[last];\n }\n return res;\n}\n\nexport function removeFunctions(o: unknown): unknown {\n if (o === undefined) return undefined;\n if (o === null) return null;\n if (typeof o === \"object\") {\n // Handle arrays first - drop function elements, then recurse.\n // Only object *properties* used to be filtered, so a function sitting\n // directly in an array survived — and the callers strip functions\n // precisely because a function survives no deep comparison.\n if (Array.isArray(o)) {\n return o\n .filter(v => typeof v !== \"function\")\n .map(v => removeFunctions(v));\n }\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them\n if (!isPlainObject(o)) {\n return o;\n }\n return Object.entries(o)\n .filter(([_, value]) => typeof value !== \"function\")\n .reduce<Record<string, unknown>>((acc, [key, value]) => {\n acc[key] = removeFunctions(value);\n return acc;\n }, {});\n }\n return o;\n}\n\nexport function getHashValue<T>(v: T): string | null {\n if (!v) return null;\n if (typeof v === \"object\" && v !== null) {\n if (\"id\" in v)\n return String((v as Record<string, unknown>).id);\n else if (v instanceof Date)\n return v.toLocaleString();\n else if (v instanceof GeoPoint)\n return hash(v as Record<string, unknown>);\n }\n return hash(v as object, { ignoreUnknown: true });\n}\n\nexport function removeUndefined(value: unknown, removeEmptyStrings?: boolean): unknown {\n if (typeof value === \"function\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((v: unknown) => removeUndefined(v, removeEmptyStrings));\n }\n if (typeof value === \"object\") {\n if (value === null)\n return value;\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them\n if (!isPlainObject(value)) {\n return value;\n }\n const res: Record<string, unknown> = {};\n Object.keys(value).forEach((key) => {\n if (!isEmptyObject(value as object)) {\n const childRes = removeUndefined((value as Record<string, unknown>)[key], removeEmptyStrings);\n const isString = typeof childRes === \"string\";\n const shouldKeepIfString = !removeEmptyStrings || (removeEmptyStrings && !isString) || (removeEmptyStrings && isString && childRes !== \"\");\n if (childRes !== undefined && !isEmptyObject(childRes as object) && shouldKeepIfString)\n res[key] = childRes;\n }\n });\n return res;\n }\n return value;\n}\n\nexport function removeNulls(value: unknown): unknown {\n if (typeof value === \"function\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((v: unknown) => removeNulls(v));\n }\n if (typeof value === \"object\") {\n if (value === null)\n return value;\n // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them\n if (!isPlainObject(value)) {\n return value;\n }\n const res: Record<string, unknown> = {};\n const obj = value as Record<string, unknown>;\n Object.keys(obj).forEach((key) => {\n if (obj[key] !== null)\n res[key] = removeNulls(obj[key]);\n });\n return res;\n }\n return value;\n}\n\nexport function isEmptyObject(obj: object) {\n return obj &&\n Object.getPrototypeOf(obj) === Object.prototype &&\n Object.keys(obj).length === 0\n}\n\nexport function removePropsIfExisting(source: Record<string, unknown> | unknown[], comparison: Record<string, unknown> | unknown[]) {\n const isObject = (val: unknown): val is Record<string, unknown> => typeof val === \"object\" && val !== null;\n const isArray = (val: unknown): val is unknown[] => Array.isArray(val);\n\n if (!isObject(source) || !isObject(comparison)) {\n return source;\n }\n\n const res = isArray(source) ? [...source] : { ...source };\n\n if (isArray(res)) {\n for (let i = res.length - 1; i >= 0; i--) {\n if (res[i] === comparison[i]) {\n res.splice(i, 1);\n } else if (isObject(res[i]) && isObject(comparison[i])) {\n res[i] = removePropsIfExisting(res[i] as unknown as Record<string, unknown>, (comparison as unknown as unknown[])[i] as Record<string, unknown>);\n }\n }\n } else {\n Object.keys(comparison).forEach(key => {\n if (key in res) {\n if (isObject(res[key]) && isObject(comparison[key])) {\n res[key] = removePropsIfExisting(res[key], comparison[key]);\n } else if (res[key] === comparison[key]) {\n delete res[key];\n }\n }\n });\n }\n\n return res;\n}\n","/**\n * Normalise a value that may be a single item or a list into a list.\n *\n * Only `null`/`undefined` mean \"nothing\". A truthiness check here silently\n * swallowed legitimate values — `toArray(0)`, `toArray(false)` and `toArray(\"\")`\n * all came back empty, so a caller normalising a single falsy item lost it.\n */\nexport function toArray<T>(input?: T | T[] | null): T[] {\n if (Array.isArray(input)) return input;\n if (input === undefined || input === null) return [];\n return [input];\n}\n","export const defaultDateFormat = \"MMMM dd, yyyy, HH:mm:ss\";\n","export function hashString(str: string): number {\n if (!str) return 0;\n let hash = 0;\n let i;\n let chr;\n for (i = 0; i < str.length; i++) {\n chr = str.charCodeAt(i);\n hash = ((hash << 5) - hash) + chr;\n hash |= 0; // Convert to 32bit integer\n }\n return Math.abs(hash);\n}\n","/**\n * Minimal SHA-1 implementation that runs in both Node and the browser.\n *\n * This exists because generated Postgres policy names embed a SHA-1 digest of\n * the security rule. The DDL generator runs on the server (where `node:crypto`\n * is available) but the Studio has to derive the same names in the browser to\n * tell a policy it generated apart from one it did not. `node:crypto` cannot be\n * bundled for the browser, so the shared derivation needs a portable digest.\n *\n * SHA-1 is used purely to name things deterministically — never for security.\n * The output is byte-identical to `createHash(\"sha1\").update(str).digest(\"hex\")`,\n * which `sha1.test.ts` pins against `node:crypto` directly.\n */\n\n/** Rotate a 32-bit word left by `n` bits. */\nfunction rotl(value: number, n: number): number {\n return (value << n) | (value >>> (32 - n));\n}\n\n/**\n * SHA-1 digest of a string, hex-encoded.\n *\n * The input is encoded as UTF-8, matching Node's default handling of strings\n * passed to `hash.update(str)`.\n */\nexport function sha1Hex(input: string): string {\n const bytes: number[] = Array.from(new TextEncoder().encode(input));\n const bitLength = bytes.length * 8;\n\n // Padding: 0x80, then zeroes up to 56 bytes mod 64, then the length as a\n // 64-bit big-endian integer.\n bytes.push(0x80);\n while (bytes.length % 64 !== 56) bytes.push(0);\n\n const hi = Math.floor(bitLength / 0x100000000);\n const lo = bitLength >>> 0;\n bytes.push((hi >>> 24) & 0xff, (hi >>> 16) & 0xff, (hi >>> 8) & 0xff, hi & 0xff);\n bytes.push((lo >>> 24) & 0xff, (lo >>> 16) & 0xff, (lo >>> 8) & 0xff, lo & 0xff);\n\n let h0 = 0x67452301;\n let h1 = 0xefcdab89;\n let h2 = 0x98badcfe;\n let h3 = 0x10325476;\n let h4 = 0xc3d2e1f0;\n\n const w = new Array<number>(80);\n\n for (let offset = 0; offset < bytes.length; offset += 64) {\n for (let i = 0; i < 16; i++) {\n const j = offset + i * 4;\n w[i] = ((bytes[j] << 24) | (bytes[j + 1] << 16) | (bytes[j + 2] << 8) | bytes[j + 3]) | 0;\n }\n for (let i = 16; i < 80; i++) {\n w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);\n }\n\n let a = h0;\n let b = h1;\n let c = h2;\n let d = h3;\n let e = h4;\n\n for (let i = 0; i < 80; i++) {\n let f: number;\n let k: number;\n if (i < 20) {\n f = (b & c) | (~b & d);\n k = 0x5a827999;\n } else if (i < 40) {\n f = b ^ c ^ d;\n k = 0x6ed9eba1;\n } else if (i < 60) {\n f = (b & c) | (b & d) | (c & d);\n k = 0x8f1bbcdc;\n } else {\n f = b ^ c ^ d;\n k = 0xca62c1d6;\n }\n\n const temp = (rotl(a, 5) + f + e + k + w[i]) | 0;\n e = d;\n d = c;\n c = rotl(b, 30);\n b = a;\n a = temp;\n }\n\n h0 = (h0 + a) | 0;\n h1 = (h1 + b) | 0;\n h2 = (h2 + c) | 0;\n h3 = (h3 + d) | 0;\n h4 = (h4 + e) | 0;\n }\n\n return [h0, h1, h2, h3, h4]\n .map(word => (word >>> 0).toString(16).padStart(8, \"0\"))\n .join(\"\");\n}\n","import type { SecurityOperation, SecurityRule } from \"@rebasepro/types\";\nimport { sha1Hex } from \"./sha1\";\n\n/**\n * Naming of the Postgres policies generated from a collection's security rules.\n *\n * A rule without an explicit `name` is compiled to `<table>_<op>_<hash>`, where\n * the hash covers the rule's semantics. The Studio needs the same names to tell\n * \"this policy came from your code\" apart from \"someone wrote this in SQL\" —\n * without them it treats generated policies as foreign and offers to import\n * them back into the codebase they came from.\n *\n * This is the single definition of that naming. The DDL and Drizzle generators\n * both derive names from here, so a change cannot silently rename every policy\n * in every deployed database while the UI keeps matching the old ones.\n */\n\n/** Stable digest of the parts of a rule that determine what the policy does. */\nexport function getPolicyNameHash(rule: SecurityRule): string {\n const data = JSON.stringify({\n a: rule.access,\n m: rule.mode,\n op: rule.operation,\n ops: rule.operations?.slice().sort(),\n own: rule.ownerField,\n rol: rule.roles?.slice().sort(),\n pg: rule.pgRoles?.slice().sort(),\n u: rule.using,\n w: rule.withCheck,\n c: rule.condition,\n ch: rule.check\n });\n return sha1Hex(data).substring(0, 7);\n}\n\n/** The operations a rule expands to — `operations` wins over `operation`. */\nexport function getPolicyOperations(rule: SecurityRule): readonly SecurityOperation[] {\n return rule.operations && rule.operations.length > 0\n ? rule.operations\n : [rule.operation ?? \"all\"];\n}\n\n/**\n * Every Postgres policy name a single rule compiles to — one per operation.\n *\n * @param rule The security rule as written in the collection config.\n * @param tableName The rule's table (see `getTableName` in `@rebasepro/common`).\n */\nexport function getPolicyNamesForRule(rule: SecurityRule, tableName: string): string[] {\n const ops = getPolicyOperations(rule);\n const ruleHash = getPolicyNameHash(rule);\n\n return ops.map((op, opIdx) => rule.name\n ? (ops.length > 1 ? `${rule.name}_${op}` : rule.name)\n : `${tableName}_${op}_${ruleHash}${ops.length > 1 ? `_${opIdx}` : \"\"}`);\n}\n\n/** Every policy name a set of rules compiles to, for membership checks. */\nexport function getPolicyNamesForRules(rules: SecurityRule[], tableName: string): Set<string> {\n const names = new Set<string>();\n for (const rule of rules) {\n for (const name of getPolicyNamesForRule(rule, tableName)) names.add(name);\n }\n return names;\n}\n","export function serializeRegExp(input: RegExp): string {\n if (!input) return \"\";\n // const fragments = input.toString().match(/\\/(.*?)\\/([a-z]*)?$/i);\n // if (fragments) {\n // if (fragments[2])\n // return input.toString();\n // return fragments[1];\n // }\n return input.toString();\n}\n\n/**\n * Get a RegExp out of a serialized string\n * @param input\n */\nexport function hydrateRegExp(input?: string): RegExp | undefined {\n if (!input) return undefined;\n const fragments = input.match(/\\/(.*?)\\/([a-z]*)?$/i);\n if (fragments) {\n return new RegExp(fragments[1], fragments[2] || \"\");\n } else {\n return new RegExp(input, \"\");\n }\n}\n\n/**\n * Is `input` something {@link hydrateRegExp} can turn into a working RegExp?\n *\n * This used to pattern-match the *shape* of a regex literal and, failing that,\n * fall back to \"does it contain any regex-ish character\" — which said yes to\n * malformed input like `/[a-z/g`. The only answer that matters to a caller is\n * whether hydration succeeds, so ask the engine instead of approximating it.\n */\nexport function isValidRegExp(input: string): boolean {\n if (!input) return false;\n try {\n return hydrateRegExp(input) !== undefined;\n } catch {\n return false;\n }\n}\n","export function flattenObject(obj: Record<string, unknown>, parentKey = \"\") {\n if (!obj) return obj;\n return Object.keys(obj).reduce((flatObj, key) => {\n const newKey = parentKey ? `${parentKey}.${key}` : key;\n\n if (typeof obj[key] === \"object\" && obj[key] !== null) {\n if (Array.isArray(obj[key])) {\n obj[key].forEach((item: unknown, index: number) => {\n if (typeof item === \"object\" && item !== null) {\n Object.assign(flatObj, flattenObject(item as Record<string, unknown>, `${newKey}[${index}]`));\n } else {\n flatObj[`${newKey}[${index}]`] = item;\n }\n });\n } else {\n Object.assign(flatObj, flattenObject(obj[key] as Record<string, unknown>, newKey));\n }\n } else {\n flatObj[newKey] = obj[key];\n }\n\n return flatObj;\n }, {} as { [key: string]: unknown });\n}\n\n\n// map from nested property key like \"a.b.c\" to the maximum array count found in a list of objects for that array\nexport type ArrayValuesCount = Record<string, number>;\n\nexport function getArrayValuesCount(array: Record<string, unknown>[]): ArrayValuesCount {\n return array.reduce((acc: ArrayValuesCount, obj: Record<string, unknown>) => {\n Object.entries(obj).forEach(([key, value]) => {\n // proceed only if value is an array\n if (Array.isArray(value)) {\n acc[key] = Math.max(acc[key] || 0, value.length);\n }\n\n // handle nested object\n if (typeof value === \"object\" && value !== null) {\n const nested = getArrayValuesCount([value as Record<string, unknown>]);\n Object.entries(nested).forEach(([nestedKey, nestedCount]) => {\n const compoundKey = `${key}.${nestedKey}`;\n acc[compoundKey] = Math.max(acc[compoundKey] || 0, nestedCount);\n });\n }\n });\n return acc;\n }, {});\n}\n","/**\n * Returns the plural of an English word.\n *\n * @param {string} word\n * @param {number} [amount]\n * @returns {string}\n */\nexport function plural(word: string, amount?: number): string {\n if (amount !== undefined && amount === 1) {\n return word\n }\n const plurals: { [key: string]: string } = {\n \"(quiz)$\": \"$1zes\",\n \"^(ox)$\": \"$1en\",\n \"([m|l])ouse$\": \"$1ice\",\n \"(matr|vert|ind)ix|ex$\": \"$1ices\",\n \"(x|ch|ss|sh)$\": \"$1es\",\n \"([^aeiouy]|qu)y$\": \"$1ies\",\n \"(hive)$\": \"$1s\",\n \"(?:([^f])fe|([lr])f)$\": \"$1$2ves\",\n \"(shea|lea|loa|thie)f$\": \"$1ves\",\n sis$: \"ses\",\n \"([ti])um$\": \"$1a\",\n \"(tomat|potat|ech|her|vet)o$\": \"$1oes\",\n \"(bu)s$\": \"$1ses\",\n \"(alias)$\": \"$1es\",\n \"(octop)us$\": \"$1i\",\n \"(ax|test)is$\": \"$1es\",\n \"(us)$\": \"$1es\",\n \"([^s]+)$\": \"$1s\"\n }\n const irregular: { [key: string]: string } = {\n move: \"moves\",\n foot: \"feet\",\n goose: \"geese\",\n sex: \"sexes\",\n child: \"children\",\n man: \"men\",\n tooth: \"teeth\",\n person: \"people\"\n }\n const uncountable: string[] = [\n \"sheep\",\n \"fish\",\n \"deer\",\n \"moose\",\n \"series\",\n \"species\",\n \"money\",\n \"rice\",\n \"information\",\n \"equipment\",\n \"bison\",\n \"cod\",\n \"offspring\",\n \"pike\",\n \"salmon\",\n \"shrimp\",\n \"swine\",\n \"trout\",\n \"aircraft\",\n \"hovercraft\",\n \"spacecraft\",\n \"sugar\",\n \"tuna\",\n \"you\",\n \"wood\"\n ]\n // save some time in the case that singular and plural are the same\n if (uncountable.indexOf(word.toLowerCase()) >= 0) {\n return word;\n }\n // check for irregular forms\n for (const w in irregular) {\n const pattern = new RegExp(`${w}$`, \"i\")\n const replace = irregular[w]\n if (pattern.test(word)) {\n return word.replace(pattern, replace);\n }\n }\n // check for matches using regular expressions\n for (const reg in plurals) {\n const pattern = new RegExp(reg, \"i\")\n if (pattern.test(word)) {\n return word.replace(pattern, plurals[reg])\n }\n }\n return word;\n}\n\n/**\n * Returns the singular of an English word.\n *\n * @param {string} word\n * @param {number} [amount]\n * @returns {string}\n */\nexport function singular(word: string, amount?: number): string {\n if (amount !== undefined && amount !== 1) {\n return word;\n }\n const singulars: { [key: string]: string } = {\n \"(quiz)zes$\": \"$1\",\n \"(matr)ices$\": \"$1ix\",\n \"(vert|ind)ices$\": \"$1ex\",\n \"^(ox)en$\": \"$1\",\n \"(alias)es$\": \"$1\",\n \"(octop|vir)i$\": \"$1us\",\n \"(cris|ax|test)es$\": \"$1is\",\n \"(shoe)s$\": \"$1\",\n \"(o)es$\": \"$1\",\n \"(bus)es$\": \"$1\",\n \"([m|l])ice$\": \"$1ouse\",\n \"(x|ch|ss|sh)es$\": \"$1\",\n \"(m)ovies$\": \"$1ovie\",\n \"(s)eries$\": \"$1eries\",\n \"([^aeiouy]|qu)ies$\": \"$1y\",\n \"([lr])ves$\": \"$1f\",\n \"(tive)s$\": \"$1\",\n \"(hive)s$\": \"$1\",\n \"(li|wi|kni)ves$\": \"$1fe\",\n \"(shea|loa|lea|thie)ves$\": \"$1f\",\n \"(^analy)ses$\": \"$1sis\",\n \"((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$\": \"$1$2sis\",\n \"([ti])a$\": \"$1um\",\n \"(n)ews$\": \"$1ews\",\n \"(h|bl)ouses$\": \"$1ouse\",\n \"(corpse)s$\": \"$1\",\n \"(us)es$\": \"$1\",\n s$: \"\"\n }\n const irregular: { [key: string]: string } = {\n move: \"moves\",\n foot: \"feet\",\n goose: \"geese\",\n sex: \"sexes\",\n child: \"children\",\n man: \"men\",\n tooth: \"teeth\",\n person: \"people\"\n }\n const uncountable: string[] = [\n \"sheep\",\n \"fish\",\n \"deer\",\n \"moose\",\n \"series\",\n \"species\",\n \"money\",\n \"rice\",\n \"information\",\n \"equipment\",\n \"bison\",\n \"cod\",\n \"offspring\",\n \"pike\",\n \"salmon\",\n \"shrimp\",\n \"swine\",\n \"trout\",\n \"aircraft\",\n \"hovercraft\",\n \"spacecraft\",\n \"sugar\",\n \"tuna\",\n \"you\",\n \"wood\"\n ]\n // save some time in the case that singular and plural are the same\n if (uncountable.indexOf(word.toLowerCase()) >= 0) {\n return word;\n }\n // check for irregular forms\n for (const w in irregular) {\n const pattern = new RegExp(`${irregular[w]}$`, \"i\");\n if (pattern.test(word)) {\n return word.replace(pattern, w);\n }\n }\n // check for matches using regular expressions\n for (const reg in singulars) {\n const pattern = new RegExp(reg, \"i\");\n if (pattern.test(word)) {\n return word.replace(pattern, singulars[reg]);\n }\n }\n return word;\n}\n","import { singular } from \"./plurals\";\nimport { toSnakeCase } from \"./strings\";\n\n/**\n * Generates a foreign key column name from a given string, typically a collection slug or name.\n * It singularizes the name, converts it to snake_case and appends '_id'.\n *\n * Singularization runs *before* snake-casing so that acronyms survive: `toSnakeCase`\n * splits on every capital, which turned \"URLs\" into \"ur_ls\" and then \"ur_l_id\".\n *\n * @param name The base name to convert to a foreign key.\n * @returns A foreign key name in the format 'singular_name_id'.\n *\n * @example\n * // returns \"user_id\"\n * generateForeignKeyName(\"users\")\n *\n * @example\n * // returns \"category_id\"\n * generateForeignKeyName(\"categories\")\n *\n * @example\n * // returns \"product_id\"\n * generateForeignKeyName(\"Product\")\n *\n */\nexport function generateForeignKeyName(name: string): string {\n return `${toSnakeCase(singularizeForKey(name))}_id`;\n}\n\n/**\n * `singular()` handles real English plurals, but its final catch-all rule strips\n * any trailing \"s\", which mangles words that only look plural. Guard the two\n * cases that produce a column name nobody would recognise:\n *\n * - a double \"s\" ending is never a plural marker (\"address\", \"class\", \"process\"),\n * so stripping it yields \"addres\";\n * - a name that singularizes to nothing (the literal \"s\") would yield \"_id\".\n */\nfunction singularizeForKey(name: string): string {\n if (/ss$/i.test(name)) return name;\n const result = singular(name);\n return result.length > 0 ? result : name;\n}\n\n/**\n * What `generateForeignKeyName` returned before it learned to singularize:\n * snake-case the name, then chop one trailing \"s\".\n *\n * This is here to be *detected*, never to be generated. A database provisioned\n * under the old rule carries `categorie_id`, `addresse_id`, `children_id` or\n * `ur_l_id` where the current rule expects `category_id`, `address_id`,\n * `child_id` and `url_id` — and the boot-time schema ensure is additive, so it\n * would create the new column empty beside the populated old one and leave the\n * relation reading nothing. No error, no missing table: the failure is silent,\n * which is the only reason this function still exists.\n *\n * `ensureCollectionSchema` calls it to recognise that shape and say so.\n * Returns the same string as `generateForeignKeyName` for every regular plural,\n * so a caller can compare the two and act only when they differ.\n */\nexport function legacyForeignKeyName(name: string): string {\n const snake = toSnakeCase(name);\n return `${snake.endsWith(\"s\") ? snake.slice(0, -1) : snake}_id`;\n}\n","\n\nexport function isDefaultFieldConfigId(id: string): boolean {\n return [\"text_field\",\n \"multiline\",\n \"markdown\",\n \"url\",\n \"email\",\n \"switch\",\n \"select\",\n \"multi_select\",\n \"number_input\",\n \"number_select\",\n \"multi_number_select\",\n \"file_upload\",\n \"multi_file_upload\",\n \"reference\",\n \"multi_references\",\n \"relation\",\n \"date_time\",\n \"group\",\n \"key_value\",\n \"repeat\",\n \"custom_array\",\n \"block\"\n ].includes(id);\n}\n"],"mappings":";;;AAAA,IAAM,gBAAgB;AAEtB,IAAa,eAAe,QAAiB;CACzC,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,mBAAmB,IAAI,MAAM,aAAa;CAChD,IAAI,CAAC,kBAAkB,OAAO;CAC9B,OAAO,iBACF,KAAI,MAAK,EAAE,YAAY,CAAC,CAAC,CACzB,KAAK,GAAG;AACjB;AAEA,IAAM,iBAAiB;AAEvB,IAAa,eAAe,QAAiB;CACzC,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,mBAAmB,IAAI,MAAM,cAAc;CACjD,IAAI,CAAC,kBAAkB,OAAO;CAC9B,OAAO,iBACF,KAAI,MAAK,EAAE,YAAY,CAAC,CAAC,CACzB,KAAK,GAAG;AACjB;AAEA,SAAgB,UAAU,KAAqB;CAC3C,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,IAAI,WAAW,GAAG,OAAO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A;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CAGA,CAAA,CAAY,QAAQ,KAAK,YAAY,CAAC,KAAK,GAC3C,OAAO;CAGX,KAAK,MAAM,KAAK,WAAW;EACvB,MAAM,UAAU,IAAI,OAAO,GAAG,UAAU,GAAG,IAAI,GAAG;EAClD,IAAI,QAAQ,KAAK,IAAI,GACjB,OAAO,KAAK,QAAQ,SAAS,CAAC;CAEtC;CAEA,KAAK,MAAM,OAAO,WAAW;EACzB,MAAM,UAAU,IAAI,OAAO,KAAK,GAAG;EACnC,IAAI,QAAQ,KAAK,IAAI,GACjB,OAAO,KAAK,QAAQ,SAAS,UAAU,IAAI;CAEnD;CACA,OAAO;AACX;;;;;;;;;;;;;;;;;;;;;;;;;;ACjKA,SAAgB,uBAAuB,MAAsB;CACzD,OAAO,GAAG,YAAY,kBAAkB,IAAI,CAAC,EAAE;AACnD;;;;;;;;;;AAWA,SAAS,kBAAkB,MAAsB;CAC7C,IAAI,OAAO,KAAK,IAAI,GAAG,OAAO;CAC9B,MAAM,SAAS,SAAS,IAAI;CAC5B,OAAO,OAAO,SAAS,IAAI,SAAS;AACxC;;;;;;;;;;;;;;;;;AAkBA,SAAgB,qBAAqB,MAAsB;CACvD,MAAM,QAAQ,YAAY,IAAI;CAC9B,OAAO,GAAG,MAAM,SAAS,GAAG,IAAI,MAAM,MAAM,GAAG,EAAE,IAAI,MAAM;AAC/D;;;AC9DA,SAAgB,uBAAuB,IAAqB;CACxD,OAAO;EAAC;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC,CAAC,SAAS,EAAE;AACjB"}
package/dist/names.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Generates a foreign key column name from a given string, typically a collection slug or name.
3
- * It converts the name to snake_case, attempts to singularize it by removing a trailing 's'
4
- * (a common convention for collection names), and appends '_id'.
3
+ * It singularizes the name, converts it to snake_case and appends '_id'.
4
+ *
5
+ * Singularization runs *before* snake-casing so that acronyms survive: `toSnakeCase`
6
+ * splits on every capital, which turned "URLs" into "ur_ls" and then "ur_l_id".
5
7
  *
6
8
  * @param name The base name to convert to a foreign key.
7
9
  * @returns A foreign key name in the format 'singular_name_id'.
@@ -11,8 +13,8 @@
11
13
  * generateForeignKeyName("users")
12
14
  *
13
15
  * @example
14
- * // returns "post_id"
15
- * generateForeignKeyName("posts")
16
+ * // returns "category_id"
17
+ * generateForeignKeyName("categories")
16
18
  *
17
19
  * @example
18
20
  * // returns "product_id"
@@ -20,3 +22,20 @@
20
22
  *
21
23
  */
22
24
  export declare function generateForeignKeyName(name: string): string;
25
+ /**
26
+ * What `generateForeignKeyName` returned before it learned to singularize:
27
+ * snake-case the name, then chop one trailing "s".
28
+ *
29
+ * This is here to be *detected*, never to be generated. A database provisioned
30
+ * under the old rule carries `categorie_id`, `addresse_id`, `children_id` or
31
+ * `ur_l_id` where the current rule expects `category_id`, `address_id`,
32
+ * `child_id` and `url_id` — and the boot-time schema ensure is additive, so it
33
+ * would create the new column empty beside the populated old one and leave the
34
+ * relation reading nothing. No error, no missing table: the failure is silent,
35
+ * which is the only reason this function still exists.
36
+ *
37
+ * `ensureCollectionSchema` calls it to recognise that shape and say so.
38
+ * Returns the same string as `generateForeignKeyName` for every regular plural,
39
+ * so a caller can compare the two and act only when they differ.
40
+ */
41
+ export declare function legacyForeignKeyName(name: string): string;
package/dist/regexp.d.ts CHANGED
@@ -4,4 +4,12 @@ export declare function serializeRegExp(input: RegExp): string;
4
4
  * @param input
5
5
  */
6
6
  export declare function hydrateRegExp(input?: string): RegExp | undefined;
7
+ /**
8
+ * Is `input` something {@link hydrateRegExp} can turn into a working RegExp?
9
+ *
10
+ * This used to pattern-match the *shape* of a regex literal and, failing that,
11
+ * fall back to "does it contain any regex-ish character" — which said yes to
12
+ * malformed input like `/[a-z/g`. The only answer that matters to a caller is
13
+ * whether hydration succeeds, so ask the engine instead of approximating it.
14
+ */
7
15
  export declare function isValidRegExp(input: string): boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/utils",
3
3
  "type": "module",
4
- "version": "0.12.1-canary.gf5f1d39",
4
+ "version": "0.13.0",
5
5
  "description": "Utility functions for Rebase",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "object-hash": "^3.0.0",
42
- "@rebasepro/types": "0.12.1-canary.gf5f1d39"
42
+ "@rebasepro/types": "0.13.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@jest/globals": "^30.4.1",
@@ -47,16 +47,16 @@
47
47
  "@testing-library/user-event": "^14.6.1",
48
48
  "@types/jest": "^30.0.0",
49
49
  "@types/lodash": "4.17.24",
50
- "@types/node": "^25.9.3",
50
+ "@types/node": "^26.1.2",
51
51
  "@types/object-hash": "^3.0.6",
52
52
  "@types/react-measure": "^2.0.12",
53
53
  "babel-plugin-react-compiler": "beta",
54
54
  "cross-env": "^10.1.0",
55
55
  "jest": "^30.4.2",
56
- "ts-jest": "^29.4.11",
56
+ "ts-jest": "^29.4.12",
57
57
  "tsd": "^0.33.0",
58
58
  "typescript": "^6.0.3",
59
- "vite": "^8.0.16"
59
+ "vite": "^8.1.5"
60
60
  },
61
61
  "files": [
62
62
  "dist",
package/src/arrays.ts CHANGED
@@ -1,3 +1,12 @@
1
- export function toArray<T>(input?: T | T[]): T[] {
2
- return Array.isArray(input) ? input : (input ? [input] : []);
1
+ /**
2
+ * Normalise a value that may be a single item or a list into a list.
3
+ *
4
+ * Only `null`/`undefined` mean "nothing". A truthiness check here silently
5
+ * swallowed legitimate values — `toArray(0)`, `toArray(false)` and `toArray("")`
6
+ * all came back empty, so a caller normalising a single falsy item lost it.
7
+ */
8
+ export function toArray<T>(input?: T | T[] | null): T[] {
9
+ if (Array.isArray(input)) return input;
10
+ if (input === undefined || input === null) return [];
11
+ return [input];
3
12
  }
package/src/names.ts CHANGED
@@ -1,9 +1,12 @@
1
+ import { singular } from "./plurals";
1
2
  import { toSnakeCase } from "./strings";
2
3
 
3
4
  /**
4
5
  * Generates a foreign key column name from a given string, typically a collection slug or name.
5
- * It converts the name to snake_case, attempts to singularize it by removing a trailing 's'
6
- * (a common convention for collection names), and appends '_id'.
6
+ * It singularizes the name, converts it to snake_case and appends '_id'.
7
+ *
8
+ * Singularization runs *before* snake-casing so that acronyms survive: `toSnakeCase`
9
+ * splits on every capital, which turned "URLs" into "ur_ls" and then "ur_l_id".
7
10
  *
8
11
  * @param name The base name to convert to a foreign key.
9
12
  * @returns A foreign key name in the format 'singular_name_id'.
@@ -13,8 +16,8 @@ import { toSnakeCase } from "./strings";
13
16
  * generateForeignKeyName("users")
14
17
  *
15
18
  * @example
16
- * // returns "post_id"
17
- * generateForeignKeyName("posts")
19
+ * // returns "category_id"
20
+ * generateForeignKeyName("categories")
18
21
  *
19
22
  * @example
20
23
  * // returns "product_id"
@@ -22,9 +25,41 @@ import { toSnakeCase } from "./strings";
22
25
  *
23
26
  */
24
27
  export function generateForeignKeyName(name: string): string {
25
- const snakeCaseName = toSnakeCase(name);
26
- // A simple heuristic to singularize a plural name, which is a common convention.
27
- const singularName = snakeCaseName.endsWith("s") ? snakeCaseName.slice(0, -1) : snakeCaseName;
28
- return `${singularName}_id`;
28
+ return `${toSnakeCase(singularizeForKey(name))}_id`;
29
+ }
30
+
31
+ /**
32
+ * `singular()` handles real English plurals, but its final catch-all rule strips
33
+ * any trailing "s", which mangles words that only look plural. Guard the two
34
+ * cases that produce a column name nobody would recognise:
35
+ *
36
+ * - a double "s" ending is never a plural marker ("address", "class", "process"),
37
+ * so stripping it yields "addres";
38
+ * - a name that singularizes to nothing (the literal "s") would yield "_id".
39
+ */
40
+ function singularizeForKey(name: string): string {
41
+ if (/ss$/i.test(name)) return name;
42
+ const result = singular(name);
43
+ return result.length > 0 ? result : name;
29
44
  }
30
45
 
46
+ /**
47
+ * What `generateForeignKeyName` returned before it learned to singularize:
48
+ * snake-case the name, then chop one trailing "s".
49
+ *
50
+ * This is here to be *detected*, never to be generated. A database provisioned
51
+ * under the old rule carries `categorie_id`, `addresse_id`, `children_id` or
52
+ * `ur_l_id` where the current rule expects `category_id`, `address_id`,
53
+ * `child_id` and `url_id` — and the boot-time schema ensure is additive, so it
54
+ * would create the new column empty beside the populated old one and leave the
55
+ * relation reading nothing. No error, no missing table: the failure is silent,
56
+ * which is the only reason this function still exists.
57
+ *
58
+ * `ensureCollectionSchema` calls it to recognise that shape and say so.
59
+ * Returns the same string as `generateForeignKeyName` for every regular plural,
60
+ * so a caller can compare the two and act only when they differ.
61
+ */
62
+ export function legacyForeignKeyName(name: string): string {
63
+ const snake = toSnakeCase(name);
64
+ return `${snake.endsWith("s") ? snake.slice(0, -1) : snake}_id`;
65
+ }
package/src/objects.ts CHANGED
@@ -290,9 +290,14 @@ export function removeFunctions(o: unknown): unknown {
290
290
  if (o === undefined) return undefined;
291
291
  if (o === null) return null;
292
292
  if (typeof o === "object") {
293
- // Handle arrays first - map over them recursively
293
+ // Handle arrays first - drop function elements, then recurse.
294
+ // Only object *properties* used to be filtered, so a function sitting
295
+ // directly in an array survived — and the callers strip functions
296
+ // precisely because a function survives no deep comparison.
294
297
  if (Array.isArray(o)) {
295
- return o.map(v => removeFunctions(v));
298
+ return o
299
+ .filter(v => typeof v !== "function")
300
+ .map(v => removeFunctions(v));
296
301
  }
297
302
  // Preserve class instances (EntityReference, GeoPoint, etc.) - don't recurse into them
298
303
  if (!isPlainObject(o)) {
@@ -300,15 +305,10 @@ export function removeFunctions(o: unknown): unknown {
300
305
  }
301
306
  return Object.entries(o)
302
307
  .filter(([_, value]) => typeof value !== "function")
303
- .map(([key, value]) => {
304
- if (Array.isArray(value)) {
305
- return { [key]: value.map(v => removeFunctions(v)) };
306
- } else if (typeof value === "object") {
307
- return { [key]: removeFunctions(value) };
308
- } else return { [key]: value };
309
- })
310
- .reduce((a, b) => ({ ...a,
311
- ...b }), {});
308
+ .reduce<Record<string, unknown>>((acc, [key, value]) => {
309
+ acc[key] = removeFunctions(value);
310
+ return acc;
311
+ }, {});
312
312
  }
313
313
  return o;
314
314
  }
package/src/regexp.ts CHANGED
@@ -23,10 +23,19 @@ export function hydrateRegExp(input?: string): RegExp | undefined {
23
23
  }
24
24
  }
25
25
 
26
+ /**
27
+ * Is `input` something {@link hydrateRegExp} can turn into a working RegExp?
28
+ *
29
+ * This used to pattern-match the *shape* of a regex literal and, failing that,
30
+ * fall back to "does it contain any regex-ish character" — which said yes to
31
+ * malformed input like `/[a-z/g`. The only answer that matters to a caller is
32
+ * whether hydration succeeds, so ask the engine instead of approximating it.
33
+ */
26
34
  export function isValidRegExp(input: string): boolean {
27
- const fullRegexp = input.match(/\/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/);
28
- if (fullRegexp)
29
- return true;
30
- const simpleRegexp = input.match(/((?![*+?])(?:[^\r\n[/\\]|\\.|\[(?:[^\r\n\]\\]|\\.)*])+)/);
31
- return !!simpleRegexp;
35
+ if (!input) return false;
36
+ try {
37
+ return hydrateRegExp(input) !== undefined;
38
+ } catch {
39
+ return false;
40
+ }
32
41
  }