@sinequa/atomic

Helpers and utilities

The functions that build queries, read results and parse URLs — grouped by what they are for, with the ones to avoid marked as such.

Two barrels, helpers/ and utils/, exporting about sixty functions in no particular order. Grouped here by task, and every one of them either points at the guide that uses it or says why it is not worth using.

Building a query

FunctionWhat it gives youWorth knowing
filter.eq neq gt gte lt lte like contains regexA SimpleFilterThe only way you should ever need to write a filter by hand
filter.in between isNull isNotNullInFilter, BetweenFilter, …in with an empty array collapses to undefined, on purpose
filter.and or notAn ExprFilter, or undefinedFalsy children are dropped; a single survivor comes back unwrapped
filter.distributionA range FilterFor a range facet. Passing a distribution item to filter.eq answers 500
addConcepts removeConcept removeConcepts getConceptsQuery text with +[concept] tokens editedNever build the token by hand — the syntax has escaping rules
parseText rewriteTextFullTextPattern[] ↔ stringThe parser behind the above: quoted phrases, /regex/, concepts
legacyFilterToFilterA modern Filter from a pre-2.0 SelectFor migrating stored queries. Nothing else

Filtering · Query syntax

Reading a result

FunctionWhat it gives youWorth knowing
resultPages(result, pageSize)The numbers a pager rendersrowCount alone is not enough; this does the arithmetic
getMetadata(article, field)string[]Reads a metadata field regardless of how the server shaped it
getMetadataWithValues(article, field){ display, value }[]When you need the raw value to filter on, not only the label
makeColumn · extraColumnsA CCColumnDeclaring a column the server configuration does not
resolveToColumnName(alias, app, queryName?)The real column name, or undefinedQuery aliases first, then the merged index schema
resolveAggregationCount · aggregationHasMoreThe page size, and whether more remainThe server returns count + 1 items when more exist. Never compare for equality
suggestionsToTreeAggregationNodesTreeAggregationNode[]Rendering a tree facet from autocomplete answers
aggregationItemStrictComparebooleanIdentity of two facet items — value and path, not display
flattenLegacyFilterValues(filters)string[]Every leaf value/display in a LegacyFilter tree — restores $selected from a stored or URL filter

Reading a result · Aggregations · Paging

URL state

FunctionWhat it gives youWorth knowing
getQueryParamsFromUrl(url)QueryParamsThe whole search state out of a URL, in one call
getUrlParamsFromQueryParams(params)URLSearchParamsThe other direction. Pair them; do not hand-roll one side
getQueryTextFromUrl · getIdFromUrl · getQueryTabFromUrlOne fieldWhen the whole object is more than you need
getQueryPageFromUrl(url)numberDefaults to 0 while Query.page is 1-based. Read the pitfall first
getFiltersFromUrl(url)LegacyFilter[]Legacy shapes: pass them through legacyFilterToFilter

Search state in the URL

Dates and localisation

FunctionWhat it gives youWorth knowing
sysLang(text, locale)One language out of an all[fr]tous[de]alle stringServer labels are multilingual; this is how you read them
translateAggregationToDateOptions(agg)DateFilter[]Turns a date facet into relative-date choices
getRelativeDate(offset)RelativeDateThe unit is always "day" — the parameter suggesting otherwise is ignored

Localisation

Infrastructure

FunctionWhat it gives youWorth knowing
configureLogger({ level })Log verbosityThe only way to set it. The logLevel config key is inert
notify.info warn errorA dispatched CustomEventNo UI of its own — your application listens
Audit.notify(events)A recorded usage eventCarries noRecovery: a 401 here is never a session to repair
escapeExpr(value)An escaped expression fragmentUse it on anything user-typed that reaches a Sinequa expression
toSqlValue(value)A quoted SQL literalNot reachable from @sinequa/atomic: src/utils/index.ts omits it while listing every sibling. Written, tested, used internally by fetchSuggest, and unimportable
hashString(value, seed?)A short non-cryptographic hash (cyrb53)For cache keys and deduplication
bisect(items, predicate){ true: T[]; false: T[] }Partition in one pass. Generic; nothing Sinequa about it

Logging · Notifications · Audit

Names that mislead

Two exports whose names promise something they do not deliver. Both are still exported, so both are documented here rather than left as a surprise.

guid() is not a UUID

It is built from Math.random(). Uniqueness is not guaranteed, and it is not a v4 UUID whatever the shape suggests. Use crypto.randomUUID() where you need either property.

sha512() throws rather than lying

It used to fall back to a repeated FNV-1a, returning a 128-character string that was the SHA-512 of nothing — a real hazard for anyone who reached for it by name. It now throws when the platform offers no crypto.subtle, and hashString() is the honest non-cryptographic alternative for cache keys.

Renamed

Both names still work; the old one carries the @deprecated tag, so your editor strikes it through.

Old nameWrite instead
getJWTokenrequestWebTokenSession
appInitializerFninitializeAppConfig
fetchSuggestQueryfetchSuggest
isStringtypeof value === "string"

Four more are tagged as implementation details the HTTP helpers already apply on every call, so there is never a reason to call them yourself: createHeaders (pass options.headers), handleResponse, resolveNoAutoAuthentication (pass options.noAutoAuthentication) and withRetry.

What's next

On this page