From 01dff745ffbb27c04fd845a673d34b48e27f2c7f Mon Sep 17 00:00:00 2001
From: Noah Overcash <novercash@ebsco.com>
Date: Mon, 8 Jan 2024 15:56:47 -0500
Subject: [PATCH] more deps

---
 package.json                                  |  1 +
 .../lib/SearchAndSort/makeQueryFunction.d.ts  | 52 +++++++++++++++++++
 .../lib/SearchAndSort/nsQueryFunctions.d.ts   | 32 ++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 smart-components/lib/SearchAndSort/makeQueryFunction.d.ts
 create mode 100644 smart-components/lib/SearchAndSort/nsQueryFunctions.d.ts

diff --git a/package.json b/package.json
index 1455bd0..10940f0 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
   },
   "dependencies": {
     "@folio/stripes-react-hotkeys": "^3.0.0",
+    "apollo-client": "^2.6.10",
     "ky": "^0.33.3",
     "moment": "^2.29.4",
     "popper.js": "^1.16.1",
diff --git a/smart-components/lib/SearchAndSort/makeQueryFunction.d.ts b/smart-components/lib/SearchAndSort/makeQueryFunction.d.ts
new file mode 100644
index 0000000..87f296a
--- /dev/null
+++ b/smart-components/lib/SearchAndSort/makeQueryFunction.d.ts
@@ -0,0 +1,52 @@
+import { FilterGroupsConfig } from '../../../components';
+import Logger from '../../../util/logger';
+import { NsParamsType } from './nsQueryFunctions';
+
+/**
+ * Returns a string, or null, which stripes-connect will use to construct a resource query.
+ *
+ * Accepts four params:
+ * @param queryParams An object containing the UI URL's query parameters (as accessed by ?{name}).
+ * @param pathComponents An object containing the UI URL's path components (as accessed by :{name}).
+ * @param resourceData An object containing the component's resources' data (as accessed by %{name}).
+ * @param logger A logger object.
+ */
+export type QueryFunction = (
+  queryParams: Record<string, unknown>,
+  pathComponents: Record<string, unknown>,
+  resourceData: { query: Record<string, unknown> },
+  logger: Logger,
+) => string | null;
+
+/**
+ * Builds a {@link QueryFunction}
+ *
+ * @param findAll CQL query to retrieve all records when there is a sort clause but no CQL query
+ * @param queryTemplate CQL query to interpolate, or function which will return CQL
+ * @param sortMap map from sort keys to CQL fields
+ * @param filterConfig list of filter objects, see {@link FilterGroupsConfig}
+ * @param failOnCondition one of the following:
+ *   - 0 (or false (legacy)): do not fail even if query and filters and empty
+ *   - 1 (or true (legacy)): fail if query is empty, whatever the filter state
+ *   - 2: fail if both query and filters and empty
+ * @param nsParams namespace keys
+ * @param configOrEscape an object containing configuration parameters:
+ *   - escape: whether to escape the query string (default true)
+ *   - rightTrunc: whether to right-truncate the query string (default true)
+ * For backwards compatibility, this parameter may also be a boolean, in which case it is used as the `escape` configuration value.
+ */
+export default function makeQueryFunction(
+  findAll: string,
+  queryTemplate:
+    | string
+    | ((
+        nsQueryParams: Record<string, unknown>,
+        pathComponents: Record<string, unknown>,
+        queryObj: { query: Record<string, unknown> },
+      ) => string),
+  sortMap: Record<string, string>,
+  filterConfig: FilterGroupsConfig,
+  failOnCondition: 0 | 1 | 2 | true | false,
+  nsParams: NsParamsType,
+  configOrEscape: boolean | { escape?: boolean; rightTrunc?: boolean },
+): QueryFunction;
diff --git a/smart-components/lib/SearchAndSort/nsQueryFunctions.d.ts b/smart-components/lib/SearchAndSort/nsQueryFunctions.d.ts
new file mode 100644
index 0000000..28c82c5
--- /dev/null
+++ b/smart-components/lib/SearchAndSort/nsQueryFunctions.d.ts
@@ -0,0 +1,32 @@
+export type NsParamsType = string | Record<string, unknown> | undefined | null;
+
+export function getNsKey(key: string, params?: NsParamsType): string;
+
+/**
+ *
+ * Adds namespace / prefix to keys in whitelist for given values object
+ *
+ * @example
+ * ```
+ * values = mapNsKeys({ query: "test", filters: 'active', userId: 1 }, 'users')
+ * // result: { "users.query" : "test", "users.filters": "active", userId: 1 }
+ * ```
+ */
+export function mapNsKeys(
+  values: Record<string, unknown>,
+  params?: NsParamsType,
+): Record<string, unknown>;
+
+/**
+ * Removes namespace / prefix from keys for given values object
+ *
+ * @example
+ * ```
+ * values = removeNsKeys({ "users.query" : "test", "users.filters": "active" }, 'users')
+ * // result: { query: "test", filters: 'active' }
+ * ```
+ */
+export function removeNsKeys(
+  values: Record<string, unknown>,
+  params?: NsParamsType,
+): Record<string, unknown>;