@webority/web-core 0.161.0 → 0.163.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/README.md +25 -3
- package/dist/api/contractCaller.js +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api-contract/dist/call.js +1 -1
- package/dist/index.js +1 -1
- package/dist/query/index.js +1 -1
- package/dist/query/listQuery.js +1 -1
- package/dist/query/useListQuery.js +1 -1
- package/dist/types/api/contractCaller.d.ts +19 -5
- package/dist/types/api/index.d.ts +2 -0
- package/dist/types/query/apiBaseQuery.d.ts +1 -1
- package/dist/types/query/index.d.ts +3 -3
- package/dist/types/query/listQuery.d.ts +10 -7
- package/dist/types/query/useListQuery.d.ts +7 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -233,19 +233,19 @@ constant for a person to delete.
|
|
|
233
233
|
|
|
234
234
|
```tsx
|
|
235
235
|
import { AppDataTable } from "@webority/ui-react";
|
|
236
|
-
import {
|
|
236
|
+
import { listQuery, useListQuery, userClient } from "@webority/web-core";
|
|
237
237
|
|
|
238
238
|
function LeaveList() {
|
|
239
239
|
const list = useListQuery<Leave>({
|
|
240
240
|
defaults: { sortBy: "start", sortOrder: "desc" },
|
|
241
241
|
fetchPage: (query, { signal }) =>
|
|
242
|
-
userClient.get(
|
|
242
|
+
userClient.get("/api/leave", { params: listQuery(query), signal }).then((r) => r.data),
|
|
243
243
|
});
|
|
244
244
|
return <AppDataTable columns={columns} {...list.tableProps} pagination={list.paginationProps} />;
|
|
245
245
|
}
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
`tableProps` feeds `AppDataTable` and `paginationProps` feeds its pager. The server answers `{ items, page, pageSize, totalCount, totalPages }`, and the hook takes the page size from that answer when the URL names none.
|
|
248
|
+
`tableProps` feeds `AppDataTable` and `paginationProps` feeds its pager. The server answers `{ items, page, pageSize, totalCount, totalPages }`, and the hook takes the page size from that answer when the URL names none. With a generated contract, pass the operation's query type, `useListQuery<Leave, LeaveListQuery>`, and `fetchPage` hands `call("Leave_List", { query: listQuery(query) })` a typed query with no cast; a facet key the query does not declare is a type error, and an enum facet ignores a URL value outside its options.
|
|
249
249
|
|
|
250
250
|
## Versioned saves
|
|
251
251
|
|
|
@@ -489,6 +489,28 @@ The caller adds no catch: a failure reaches the caller as the client's curated e
|
|
|
489
489
|
`{ query: { ids: [1, 2] } }` sends `ids=1&ids=2`. The third argument takes `signal`, `timeout` and `retry`
|
|
490
490
|
(`false`, or a policy such as `{ retries: 1 }`). `client` may be any object with axios's `request` method.
|
|
491
491
|
|
|
492
|
+
`{ reply: "full" }` resolves to `{ status, notModified, headers, body }`, header names in lower case, for a
|
|
493
|
+
call that reads a header or a 304. A 304 resolves as `notModified: true` with no body instead of rejecting.
|
|
494
|
+
`{ replacesSession: true }` marks a call that ends the session and answers with a new one (a workspace switch,
|
|
495
|
+
a two-factor change). `{ keepalive: true }` sends the call so it outlives the page, for the last save on page hide.
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
const file = await call("Workspace_Export", {}, { reply: "full", timeout: 0 });
|
|
499
|
+
const name = contentDispositionFileName(file.headers["content-disposition"] ?? "");
|
|
500
|
+
|
|
501
|
+
const steps = await call("Reference_Steps", { path: { id } }, { reply: "full", headers: { "If-None-Match": etag } });
|
|
502
|
+
if (steps.notModified) return cached;
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
`listQuery<TQuery>(input)` builds a list call's `query`, typed as the operation declares it, so it needs no cast:
|
|
506
|
+
paging, sort, `search` and each filter the query names. A `{ from, to }` range is written as `<name>From` and
|
|
507
|
+
`<name>To`, blank values are left out, and a filter named like a list param throws.
|
|
508
|
+
|
|
509
|
+
```ts
|
|
510
|
+
type Query = Operations["Team_Removed"]["request"]["query"];
|
|
511
|
+
const removed = await call("Team_Removed", { query: listQuery<Query>({ page, sortBy, search, filters: { status } }) });
|
|
512
|
+
```
|
|
513
|
+
|
|
492
514
|
### RTK Query endpoints from a contract
|
|
493
515
|
|
|
494
516
|
`createContractQuery` builds the request for an RTK Query endpoint from the same contract, by operation id.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ContractCallError as e,buildContractRequest as t,contractFullReply as n,contractReply as r,isFullReplyStatus as i}from"../api-contract/dist/call.js";var a=(a,o)=>{async function s(s,c,l){let u=o[s],d=t(u,c,l);if(l?.keepalive!==void 0&&typeof l.keepalive!=`boolean`)throw new e(`${u.method} ${u.path} needs keepalive as true or false`);let f=await a.request({method:d.method,url:d.url,...d.headers!==void 0&&{headers:d.headers},data:d.data,responseType:d.responseType,...d.skipErrorLog!==void 0&&{skipErrorLog:d.skipErrorLog},...d.expectedStatuses!==void 0&&{expectedStatuses:d.expectedStatuses},...d.replacesSession!==void 0&&{replacesSession:d.replacesSession},...l?.keepalive===!0&&{adapter:`fetch`,fetchOptions:{keepalive:!0}},...d.reply===`full`&&{validateStatus:i},...l?.signal!==void 0&&{signal:l.signal},...l?.timeout!==void 0&&{timeout:l.timeout},...l?.retry!==void 0&&{retry:l.retry}});return d.reply===`full`?n(u,f.status,f.headers,f.data):r(u,f.status,f.data)}return s};export{a as createContractCaller};
|
package/dist/api/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{listQuery as e}from"../api-contract/dist/call.js";import{initUserAuth as t}from"../initUserAuth.js";import{readBlobErrorBody as n}from"./blobErrorBody.js";import{ACCOUNT_ID_HEADER as r,CLIENT_BUILD_HEADER as i,CLIENT_KIND as a,CLIENT_KIND_HEADER as o,getClientBuild as s}from"./clientHeaders.js";import{createContractCaller as c}from"./contractCaller.js";import{REFRESH_LOCK_NAME as l,withCrossTabRefreshLock as u}from"./crossTabRefreshLock.js";import{DESIGN_SAMPLE_HEADER as d,DESIGN_SAMPLE_QUERY_KEY as f,DESIGN_SAMPLE_STORAGE_KEY as p,applyDesignSample as m,readDesignSampleTicket as h}from"./designSample.js";import{contentDispositionFileName as g,downloadFile as _}from"./downloadFile.js";import{newIdempotencyKey as v}from"./idempotencyKey.js";import{MIN_APP_VERSION_HEADER as y,addMinAppVersionListener as b,getMinAppVersion as x}from"./minAppVersion.js";import S from"./publicClient.js";import{TRACEPARENT_HEADER as C,applyRequestDefaults as w,newTraceparent as T}from"./requestDefaults.js";import{IDEMPOTENCY_KEY_HEADER as E,attachRetry as D,isNeverSentError as O,isRetryableFailure as k,isRetryableStatus as A,retryAfterMs as j}from"./retry.js";import{SESSION_EXPIRED_CODE as M,SESSION_REVOKED_CODE as N,injectStore as P,injectUserAuth as F,refreshAccessToken as I,resetRefreshState as L}from"./tokenRefresh.js";import R,{RequestOfflineError as z}from"./userClient.js";import{WORKSPACE_CHANGED_CODE as B,WorkspaceChangedError as V,isWorkspaceChangedError as H}from"./workspaceChanged.js";export{r as ACCOUNT_ID_HEADER,i as CLIENT_BUILD_HEADER,a as CLIENT_KIND,o as CLIENT_KIND_HEADER,d as DESIGN_SAMPLE_HEADER,f as DESIGN_SAMPLE_QUERY_KEY,p as DESIGN_SAMPLE_STORAGE_KEY,E as IDEMPOTENCY_KEY_HEADER,y as MIN_APP_VERSION_HEADER,l as REFRESH_LOCK_NAME,z as RequestOfflineError,M as SESSION_EXPIRED_CODE,N as SESSION_REVOKED_CODE,C as TRACEPARENT_HEADER,B as WORKSPACE_CHANGED_CODE,V as WorkspaceChangedError,b as addMinAppVersionListener,m as applyDesignSample,w as applyRequestDefaults,D as attachRetry,g as contentDispositionFileName,c as createContractCaller,_ as downloadFile,s as getClientBuild,x as getMinAppVersion,t as initUserAuth,P as injectStore,F as injectUserAuth,O as isNeverSentError,k as isRetryableFailure,A as isRetryableStatus,H as isWorkspaceChangedError,e as listQuery,v as newIdempotencyKey,T as newTraceparent,S as publicClient,n as readBlobErrorBody,h as readDesignSampleTicket,I as refreshAccessToken,L as resetRefreshState,j as retryAfterMs,R as userClient,u as withCrossTabRefreshLock};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=class extends Error{constructor(e){super(e),this.name=`ContractCallError`}},t=/\{([^{}]+)\}/g,n=e=>e instanceof Date?encodeURIComponent(e.toISOString()):encodeURIComponent(typeof e==`object`?JSON.stringify(e):String(e));function r(e){let t=[];for(let[r,i]of Object.entries(e??{})){if(i==null)continue;let e=encodeURIComponent(r);for(let r of Array.isArray(i)?i:[i])r!=null&&t.push(`${e}=${n(r)}`)}return t.join(`&`)}var i=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,a=[`content-type`,`content-length`],o=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function s(t,n,r){if(r===void 0)return n;if(!o(r))throw new e(`${t} needs call headers as an object of header names to string values`);let s=new Set(Object.keys(n??{}).map(e=>e.toLowerCase())),c={...n};for(let[n,o]of Object.entries(r)){if(!i.test(n))throw new e(`${t} has a call header named "${n}", which is not a valid header name`);let r=n.toLowerCase();if(a.includes(r))throw new e(`${t} sets "${n}" as a call header; the body decides it`);if(s.has(r))throw new e(`${t} sets "${n}" twice; set a header the contract declares on the request's headers only`);if(typeof o!=`string`||/[\r\n\0]/.test(o))throw new e(`${t} needs call header "${n}" as a string with no line break`);s.add(r),c[n]=o}return c}function c(t,n){let r=n?.skipErrorLog,i=n?.expectedStatuses;if(r!==void 0&&typeof r!=`boolean`)throw new e(`${t} needs skipErrorLog as true or false`);if(i===void 0)return{skipErrorLog:r,expectedStatuses:void 0};if(!Array.isArray(i)||i.length===0)throw new e(`${t} needs expectedStatuses as a non-empty list of failure statuses`);for(let n of i)if(!Number.isInteger(n)||n<400||n>599)throw new e(`${t} lists ${String(n)} in expectedStatuses; only a failure status from 400 to 599 is expected`);if(new Set(i).size!==i.length)throw new e(`${t} lists a status twice in expectedStatuses`);if(r===!0)throw new e(`${t} sets skipErrorLog and expectedStatuses; skipErrorLog already keeps every failure out of the log`);return{skipErrorLog:r,expectedStatuses:i}}function l(e,t,n){return e.replyKind===`none`||t===204||t===205?void 0:n}function
|
|
1
|
+
var e=class extends Error{constructor(e){super(e),this.name=`ContractCallError`}},t=/\{([^{}]+)\}/g,n=e=>e instanceof Date?encodeURIComponent(e.toISOString()):encodeURIComponent(typeof e==`object`?JSON.stringify(e):String(e));function r(e){let t=[];for(let[r,i]of Object.entries(e??{})){if(i==null)continue;let e=encodeURIComponent(r);for(let r of Array.isArray(i)?i:[i])r!=null&&t.push(`${e}=${n(r)}`)}return t.join(`&`)}var i=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,a=[`content-type`,`content-length`],o=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function s(t,n,r){if(r===void 0)return n;if(!o(r))throw new e(`${t} needs call headers as an object of header names to string values`);let s=new Set(Object.keys(n??{}).map(e=>e.toLowerCase())),c={...n};for(let[n,o]of Object.entries(r)){if(!i.test(n))throw new e(`${t} has a call header named "${n}", which is not a valid header name`);let r=n.toLowerCase();if(a.includes(r))throw new e(`${t} sets "${n}" as a call header; the body decides it`);if(s.has(r))throw new e(`${t} sets "${n}" twice; set a header the contract declares on the request's headers only`);if(typeof o!=`string`||/[\r\n\0]/.test(o))throw new e(`${t} needs call header "${n}" as a string with no line break`);s.add(r),c[n]=o}return c}function c(t,n){let r=n?.skipErrorLog,i=n?.expectedStatuses;if(r!==void 0&&typeof r!=`boolean`)throw new e(`${t} needs skipErrorLog as true or false`);if(i===void 0)return{skipErrorLog:r,expectedStatuses:void 0};if(!Array.isArray(i)||i.length===0)throw new e(`${t} needs expectedStatuses as a non-empty list of failure statuses`);for(let n of i)if(!Number.isInteger(n)||n<400||n>599)throw new e(`${t} lists ${String(n)} in expectedStatuses; only a failure status from 400 to 599 is expected`);if(new Set(i).size!==i.length)throw new e(`${t} lists a status twice in expectedStatuses`);if(r===!0)throw new e(`${t} sets skipErrorLog and expectedStatuses; skipErrorLog already keeps every failure out of the log`);return{skipErrorLog:r,expectedStatuses:i}}function l(t,n){let r=n?.reply,i=n?.replacesSession;if(r!==void 0&&r!==`body`&&r!==`full`)throw new e(`${t} needs reply as "body" or "full"`);if(i!==void 0&&typeof i!=`boolean`)throw new e(`${t} needs replacesSession as true or false`);return{reply:r??`body`,replacesSession:i}}var u=e=>e>=200&&e<300||e===304;function d(e,t,n,r){let i={};for(let[e,t]of Object.entries(n))t!=null&&(i[e.toLowerCase()]=Array.isArray(t)?t.map(String).join(`, `):String(t));return t===304?{status:304,notModified:!0,headers:i,body:void 0}:{status:t,notModified:!1,headers:i,body:f(e,t,r)}}function f(e,t,n){return e.replyKind===`none`||t===204||t===205?void 0:n}function p(n,i,a){let o=`${n.method} ${n.path}`,u=n.path.replace(t,(t,n)=>{let r=i.path?.[n],a=r===void 0?``:String(r);if(a===``)throw new e(`${o} needs a non-empty path value for "${n}"`);if(a===`.`||a===`..`)throw new e(`${o} needs a path value for "${n}" other than "." or ".."`);return encodeURIComponent(a)}),d=r(i.query);return{method:n.method,url:d===``?u:`${u}?${d}`,headers:s(o,i.headers,a?.headers),data:i.body,responseType:n.replyKind===`blob`?`blob`:`json`,...c(o,a),...l(o,a)}}var m=[`page`,`pageSize`,`sortBy`,`sortOrder`,`search`],h=e=>String(e).padStart(2,`0`),g=e=>e instanceof Date?`${e.getFullYear()}-${h(e.getMonth()+1)}-${h(e.getDate())}`:e,_=e=>e==null||typeof e==`string`&&e.trim()===``,v=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Date),y=m;function b(t,n,r){if(!_(r)){if(typeof r==`string`||r instanceof Date)return g(r);throw new e(`listQuery needs "${t}.${n}" as a yyyy-MM-dd string or a Date`)}}function x(t){let n={},{filters:r,...i}=t;for(let e of m){let t=i[e];_(t)||(n[e]=typeof t==`string`?t.trim():t)}n.sortBy===void 0&&delete n.sortOrder;for(let[t,i]of Object.entries(r??{})){if(y.includes(t))throw new e(`listQuery has a filter named "${t}", which the list query reserves (${m.join(`, `)})`);if(Array.isArray(i)){let e=i.filter(e=>!_(e));e.length>0&&(n[t]=e)}else if(v(i)){let e=b(t,`from`,i.from),r=b(t,`to`,i.to);e!==void 0&&(n[`${t}From`]=e),r!==void 0&&(n[`${t}To`]=r)}else i instanceof Date?n[t]=g(i):_(i)||(n[t]=i)}return n}export{e as ContractCallError,p as buildContractRequest,d as contractFullReply,f as contractReply,u as isFullReplyStatus,x as listQuery};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DEFAULT_BUILD_CHECK_INTERVAL_MS as
|
|
1
|
+
import{listQuery as e}from"./api-contract/dist/call.js";import{DEFAULT_BUILD_CHECK_INTERVAL_MS as t,DEFAULT_LOG_LEVEL as n,DEFAULT_RETRIES as r,DEFAULT_TIMEOUT_MS as i,DEFAULT_VERSION_URL as a,getConfig as o,getConfigValue as s,resetConfig as c,setConfig as l}from"./config/index.js";import{TRACEPARENT_HEADER as u,applyRequestDefaults as d,newTraceparent as f}from"./api/requestDefaults.js";import{Logger as p,configureLogger as m,getDeviceContext as h,setDeviceContext as g,setRemoteLogger as _}from"./logger/logger.js";import{decodeJWT as v,getJWTExpiry as y,isJWTExpired as b}from"./auth/jwt.js";import{ACCESS_TOKEN_KEY as x,LEGACY_REFRESH_TOKEN_LIFETIME_MS as S,REFRESH_TOKEN_KEY as C,SESSION_USER_KEY as w,addSessionEndedListener as T,clearSession as E,getKeepSignedIn as D,getSessionUser as O,getToken as k,hasSession as A,hasSessionEndedInTab as j,removeSessionUser as M,removeToken as N,setKeepSignedIn as P,setLegacyTokenKeys as F,storeSessionUser as I,storeToken as L}from"./auth/authStore.js";import{addNetworkStatusListener as R,getNetworkStatus as z,setNetworkStatusImplementation as B,useNetworkStatus as V}from"./network/networkStatus.js";import{ACCOUNT_ID_HEADER as H,CLIENT_BUILD_HEADER as U,CLIENT_KIND as W,CLIENT_KIND_HEADER as G,getClientBuild as K}from"./api/clientHeaders.js";import{initWebority as q}from"./initSDK.js";import{DESIGN_SAMPLE_HEADER as J,DESIGN_SAMPLE_QUERY_KEY as Y,DESIGN_SAMPLE_STORAGE_KEY as X,applyDesignSample as Z,readDesignSampleTicket as Q}from"./api/designSample.js";import{MIN_APP_VERSION_HEADER as $,addMinAppVersionListener as ee,getMinAppVersion as te}from"./api/minAppVersion.js";import{WORKSPACE_CHANGED_CODE as ne,WorkspaceChangedError as re,isWorkspaceChangedError as ie}from"./api/workspaceChanged.js";import{IDEMPOTENCY_KEY_HEADER as ae,attachRetry as oe,isNeverSentError as se,isRetryableFailure as ce,isRetryableStatus as le,retryAfterMs as ue}from"./api/retry.js";import{REFRESH_LOCK_NAME as de,withCrossTabRefreshLock as fe}from"./api/crossTabRefreshLock.js";import pe from"./api/publicClient.js";import{SESSION_EXPIRED_CODE as me,SESSION_REVOKED_CODE as he,injectStore as ge,injectUserAuth as _e,refreshAccessToken as ve,resetRefreshState as ye}from"./api/tokenRefresh.js";import be,{RequestOfflineError as xe}from"./api/userClient.js";import{initUserAuth as Se}from"./initUserAuth.js";import{readBlobErrorBody as Ce}from"./api/blobErrorBody.js";import{createContractCaller as we}from"./api/contractCaller.js";import{CONTRACT_ERROR_CODE as Te,NETWORK_CODE as Ee,OFFLINE_CODE as De,OFFLINE_MESSAGE as Oe,REQUEST_CANCELED_CODE as ke,SERVER_FAILURE_MESSAGE as Ae,TIMEOUT_CODE as je,TIMEOUT_MESSAGE as Me,UNEXPECTED_MESSAGE as Ne,UNREACHABLE_MESSAGE as Pe,apiErrorMessage as Fe,extractApiError as Ie,isApiError as Le,isNoResponse as Re,toFieldPath as ze}from"./errors/extractApiError.js";import{parseResponse as Be}from"./errors/parseResponse.js";import{contentDispositionFileName as Ve,downloadFile as He}from"./api/downloadFile.js";import{newIdempotencyKey as Ue}from"./api/idempotencyKey.js";import{configureFormatters as We,getFormatterConfig as Ge}from"./formatters/formatConfig.js";import{formatCurrency as Ke}from"./formatters/currency.js";import{addDays as qe}from"./formatters/dateMath.js";import{formatDate as Je,formatDateTime as Ye,formatMinor as Xe,formatNumber as Ze,formatPercent as Qe,formatRelative as $e,formatTime as et}from"./formatters/house.js";import{staticUrl as tt}from"./static/index.js";import{createApiBaseQuery as nt}from"./query/apiBaseQuery.js";import{createContractQuery as rt}from"./query/contractQuery.js";import{APP_API_DEFAULTS as it,createAppApi as at}from"./query/createAppApi.js";import{useDataState as ot,useInfiniteDataState as st}from"./query/dataState.js";import{entityTagOf as ct,saveWithVersion as lt,versionOf as ut,withIfMatch as dt}from"./query/entityVersion.js";import{setupApiListeners as ft}from"./query/listeners.js";import{LIST_QUERY_RESERVED as pt,SEARCH_PARAM as mt,emptyFacetValue as ht,isFacetActive as gt,listQueryParamNames as _t,parseListQuery as vt}from"./query/listQuery.js";import{getNextPageParam as yt,getPreviousPageParam as bt,hasNextPage as xt,hasPreviousPage as St}from"./query/paging.js";import{LIST_TAG_ID as Ct,itemTag as wt,listTag as Tt,providesList as Et,providesPagedList as Dt}from"./query/tags.js";import{useListQuery as Ot}from"./query/useListQuery.js";import{errorToastMiddleware as kt,isSilentRejection as At}from"./redux/errorToastMiddleware.js";import{createRootReducer as jt,resetState as Mt}from"./redux/rootReducer.js";import{SERIALIZABLE_IGNORED_ACTION_PATHS as Nt}from"./redux/serializableCheck.js";import{hasRecentlyReloaded as Pt,importWithReload as Ft,isChunkLoadError as It,lazyWithReload as Lt,markReloaded as Rt}from"./router/chunkReload.js";import{classifyRouteError as zt,useRouteErrorReport as Bt}from"./router/routeError.js";import{ErrorBoundary as Vt}from"./router/ErrorBoundary.js";import{hasPermission as Ht}from"./router/permissions.js";import{RETURN_TO_PARAM as Ut,buildLoginPath as Wt,getReturnTo as Gt,toSafeReturnTo as Kt}from"./router/returnTo.js";import{PublicOnly as qt,RequireAuth as Jt,RequirePermission as Yt}from"./router/guards.js";import{publicOnly as Xt,requireAuth as Zt,requirePermission as Qt,withGuards as $t}from"./router/loaders.js";import{defineRouteTable as en}from"./router/routeTable.js";import{Storage as tn,isStorageAvailable as nn,setStorageImplementation as rn,syncSessionStorage as an,syncStorage as on}from"./storage/index.js";import{isBuildBelowMinimum as sn,parseBuildNumber as cn}from"./versionCheck/buildNumber.js";import{addDeployedBuildListener as ln,getNewerDeployedBuild as un,startDeployedBuildCheck as dn}from"./versionCheck/deployedBuild.js";import{installReloadOnNavigate as fn,isUpdateAvailable as pn,useVersionCheck as mn}from"./versionCheck/index.js";export{x as ACCESS_TOKEN_KEY,H as ACCOUNT_ID_HEADER,it as APP_API_DEFAULTS,U as CLIENT_BUILD_HEADER,W as CLIENT_KIND,G as CLIENT_KIND_HEADER,Te as CONTRACT_ERROR_CODE,t as DEFAULT_BUILD_CHECK_INTERVAL_MS,n as DEFAULT_LOG_LEVEL,r as DEFAULT_RETRIES,i as DEFAULT_TIMEOUT_MS,a as DEFAULT_VERSION_URL,J as DESIGN_SAMPLE_HEADER,Y as DESIGN_SAMPLE_QUERY_KEY,X as DESIGN_SAMPLE_STORAGE_KEY,Vt as ErrorBoundary,ae as IDEMPOTENCY_KEY_HEADER,S as LEGACY_REFRESH_TOKEN_LIFETIME_MS,pt as LIST_QUERY_RESERVED,Ct as LIST_TAG_ID,p as Logger,$ as MIN_APP_VERSION_HEADER,Ee as NETWORK_CODE,De as OFFLINE_CODE,Oe as OFFLINE_MESSAGE,qt as PublicOnly,de as REFRESH_LOCK_NAME,C as REFRESH_TOKEN_KEY,ke as REQUEST_CANCELED_CODE,Ut as RETURN_TO_PARAM,xe as RequestOfflineError,Jt as RequireAuth,Yt as RequirePermission,mt as SEARCH_PARAM,Nt as SERIALIZABLE_IGNORED_ACTION_PATHS,Ae as SERVER_FAILURE_MESSAGE,me as SESSION_EXPIRED_CODE,he as SESSION_REVOKED_CODE,w as SESSION_USER_KEY,tn as Storage,je as TIMEOUT_CODE,Me as TIMEOUT_MESSAGE,u as TRACEPARENT_HEADER,Ne as UNEXPECTED_MESSAGE,Pe as UNREACHABLE_MESSAGE,ne as WORKSPACE_CHANGED_CODE,re as WorkspaceChangedError,qe as addDays,ln as addDeployedBuildListener,ee as addMinAppVersionListener,R as addNetworkStatusListener,T as addSessionEndedListener,Fe as apiErrorMessage,Z as applyDesignSample,d as applyRequestDefaults,oe as attachRetry,Wt as buildLoginPath,zt as classifyRouteError,E as clearSession,We as configureFormatters,m as configureLogger,Ve as contentDispositionFileName,nt as createApiBaseQuery,at as createAppApi,we as createContractCaller,rt as createContractQuery,jt as createRootReducer,v as decodeJWT,en as defineRouteTable,He as downloadFile,ht as emptyFacetValue,ct as entityTagOf,kt as errorToastMiddleware,Ie as extractApiError,Ke as formatCurrency,Je as formatDate,Ye as formatDateTime,Xe as formatMinor,Ze as formatNumber,Qe as formatPercent,$e as formatRelative,et as formatTime,K as getClientBuild,o as getConfig,s as getConfigValue,h as getDeviceContext,Ge as getFormatterConfig,y as getJWTExpiry,D as getKeepSignedIn,te as getMinAppVersion,z as getNetworkStatus,un as getNewerDeployedBuild,yt as getNextPageParam,bt as getPreviousPageParam,Gt as getReturnTo,O as getSessionUser,k as getToken,xt as hasNextPage,Ht as hasPermission,St as hasPreviousPage,Pt as hasRecentlyReloaded,A as hasSession,j as hasSessionEndedInTab,Ft as importWithReload,Se as initUserAuth,q as initWebority,ge as injectStore,_e as injectUserAuth,fn as installReloadOnNavigate,Le as isApiError,sn as isBuildBelowMinimum,It as isChunkLoadError,gt as isFacetActive,b as isJWTExpired,se as isNeverSentError,Re as isNoResponse,ce as isRetryableFailure,le as isRetryableStatus,At as isSilentRejection,nn as isStorageAvailable,pn as isUpdateAvailable,ie as isWorkspaceChangedError,wt as itemTag,Lt as lazyWithReload,e as listQuery,_t as listQueryParamNames,Tt as listTag,Rt as markReloaded,Ue as newIdempotencyKey,f as newTraceparent,cn as parseBuildNumber,vt as parseListQuery,Be as parseResponse,Et as providesList,Dt as providesPagedList,pe as publicClient,Xt as publicOnly,Ce as readBlobErrorBody,Q as readDesignSampleTicket,ve as refreshAccessToken,M as removeSessionUser,N as removeToken,Zt as requireAuth,Qt as requirePermission,c as resetConfig,ye as resetRefreshState,Mt as resetState,ue as retryAfterMs,lt as saveWithVersion,l as setConfig,g as setDeviceContext,P as setKeepSignedIn,F as setLegacyTokenKeys,B as setNetworkStatusImplementation,_ as setRemoteLogger,rn as setStorageImplementation,ft as setupApiListeners,dn as startDeployedBuildCheck,tt as staticUrl,I as storeSessionUser,L as storeToken,an as syncSessionStorage,on as syncStorage,ze as toFieldPath,Kt as toSafeReturnTo,ot as useDataState,st as useInfiniteDataState,Ot as useListQuery,V as useNetworkStatus,Bt as useRouteErrorReport,mn as useVersionCheck,be as userClient,ut as versionOf,fe as withCrossTabRefreshLock,$t as withGuards,dt as withIfMatch};
|
package/dist/query/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createApiBaseQuery as e}from"./apiBaseQuery.js";import{createContractQuery as t}from"./contractQuery.js";import{APP_API_DEFAULTS as n,createAppApi as r}from"./createAppApi.js";import{useDataState as i,useInfiniteDataState as a}from"./dataState.js";import{entityTagOf as o,saveWithVersion as s,versionOf as c,withIfMatch as l}from"./entityVersion.js";import{setupApiListeners as u}from"./listeners.js";import{LIST_QUERY_RESERVED as d,SEARCH_PARAM as f,
|
|
1
|
+
import{createApiBaseQuery as e}from"./apiBaseQuery.js";import{createContractQuery as t}from"./contractQuery.js";import{APP_API_DEFAULTS as n,createAppApi as r}from"./createAppApi.js";import{useDataState as i,useInfiniteDataState as a}from"./dataState.js";import{entityTagOf as o,saveWithVersion as s,versionOf as c,withIfMatch as l}from"./entityVersion.js";import{setupApiListeners as u}from"./listeners.js";import{LIST_QUERY_RESERVED as d,SEARCH_PARAM as f,emptyFacetValue as p,isFacetActive as m,listQueryParamNames as h,parseListQuery as g}from"./listQuery.js";import{getNextPageParam as _,getPreviousPageParam as v,hasNextPage as y,hasPreviousPage as b}from"./paging.js";import{LIST_TAG_ID as x,itemTag as S,listTag as C,providesList as w,providesPagedList as T}from"./tags.js";import{useListQuery as E}from"./useListQuery.js";export{n as APP_API_DEFAULTS,d as LIST_QUERY_RESERVED,x as LIST_TAG_ID,f as SEARCH_PARAM,e as createApiBaseQuery,r as createAppApi,t as createContractQuery,p as emptyFacetValue,o as entityTagOf,_ as getNextPageParam,v as getPreviousPageParam,y as hasNextPage,b as hasPreviousPage,m as isFacetActive,S as itemTag,h as listQueryParamNames,C as listTag,g as parseListQuery,w as providesList,T as providesPagedList,s as saveWithVersion,u as setupApiListeners,i as useDataState,a as useInfiniteDataState,E as useListQuery,c as versionOf,l as withIfMatch};
|
package/dist/query/listQuery.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.freeze([`page`,`pageSize`,`sortBy`,`sortOrder`,`search`]),t=`search`,n=[`asc`,`desc`],r=e=>n.some(t=>t===e),i=e=>e==null||e===``,a=e=>String(e).padStart(2,`0`),o=e=>e instanceof Date?`${e.getFullYear()}-${a(e.getMonth()+1)}-${a(e.getDate())}`:String(e);function s(t){if(e.includes(t))throw Error(`"${t}" is reserved by the list query (${e.join(`, `)}) and cannot name a filter.`)}var c=e=>typeof e==`object`&&!!e&&!(e instanceof Date);function l(e={}){let{page:n,pageSize:a,sortBy:l,sortOrder:u,search:d,filters:f}=e;if(!i(u)&&!r(u))throw Error(`sortOrder must be "asc" or "desc", got "${u}".`);let p=new URLSearchParams;i(n)||p.set(`page`,String(n)),i(a)||p.set(`pageSize`,String(a)),i(l)||(p.set(`sortBy`,l),p.set(`sortOrder`,u||`asc`));let m=i(d)?``:String(d).trim();m&&p.set(t,m);for(let[e,t]of Object.entries(f??{}))if(s(e),Array.isArray(t))for(let n of t)i(n)||p.append(e,o(n));else c(t)?(i(t.from)||p.set(`${e}From`,o(t.from)),i(t.to)||p.set(`${e}To`,o(t.to))):i(t)||p.set(e,o(t));return p}function u(e){return e.type===`multiEnum`?[]:e.type===`dateRange`?{from:``,to:``}:``}function d(e,t){return t==null?!1:e.type===`multiEnum`?Array.isArray(t)&&t.length>0:e.type===`dateRange`?c(t)?!!(t.from||t.to):!1:t!==``}function f(t=[]){let n=new Set(e);for(let{key:e,type:r}of t)r===`dateRange`?(n.add(`${e}From`),n.add(`${e}To`)):n.add(e);return n}var p=e=>{let t=Number(e);return Number.isInteger(t)&&t>=1?t:void 0};function m(e,t={}){let{facets:n=[],defaults:i={}}=t,a=typeof e==`string`?new URLSearchParams(e):e;for(let e of n)s(e.key);let o=f(n),c=[...a.keys()].some(e=>o.has(e)),l=a.get(`sortOrder`),d={};for(let e of n){let{key:t,type:n}=e,r;
|
|
1
|
+
var e=Object.freeze([`page`,`pageSize`,`sortBy`,`sortOrder`,`search`]),t=`search`,n=[`asc`,`desc`],r=e=>n.some(t=>t===e),i=e=>e==null||e===``,a=e=>String(e).padStart(2,`0`),o=e=>e instanceof Date?`${e.getFullYear()}-${a(e.getMonth()+1)}-${a(e.getDate())}`:String(e);function s(t){if(e.includes(t))throw Error(`"${t}" is reserved by the list query (${e.join(`, `)}) and cannot name a filter.`)}var c=e=>typeof e==`object`&&!!e&&!(e instanceof Date);function l(e={}){let{page:n,pageSize:a,sortBy:l,sortOrder:u,search:d,filters:f}=e;if(!i(u)&&!r(u))throw Error(`sortOrder must be "asc" or "desc", got "${u}".`);let p=new URLSearchParams;i(n)||p.set(`page`,String(n)),i(a)||p.set(`pageSize`,String(a)),i(l)||(p.set(`sortBy`,l),p.set(`sortOrder`,u||`asc`));let m=i(d)?``:String(d).trim();m&&p.set(t,m);for(let[e,t]of Object.entries(f??{}))if(s(e),Array.isArray(t))for(let n of t)i(n)||p.append(e,o(n));else c(t)?(i(t.from)||p.set(`${e}From`,o(t.from)),i(t.to)||p.set(`${e}To`,o(t.to))):i(t)||p.set(e,o(t));return p}function u(e){return e.type===`multiEnum`?[]:e.type===`dateRange`?{from:``,to:``}:``}function d(e,t){return t==null?!1:e.type===`multiEnum`?Array.isArray(t)&&t.length>0:e.type===`dateRange`?c(t)?!!(t.from||t.to):!1:t!==``}function f(t=[]){let n=new Set(e);for(let{key:e,type:r}of t)r===`dateRange`?(n.add(`${e}From`),n.add(`${e}To`)):n.add(e);return n}var p=e=>{let t=Number(e);return Number.isInteger(t)&&t>=1?t:void 0};function m(e,t={}){let{facets:n=[],defaults:i={}}=t,a=typeof e==`string`?new URLSearchParams(e):e;for(let e of n)s(e.key);let o=f(n),c=[...a.keys()].some(e=>o.has(e)),l=a.get(`sortOrder`),d={};for(let e of n){let{key:t,type:n,options:r}=e,o=r===void 0?void 0:new Set(r.map(e=>e.value)),s;if(!c)s=i.filters?.[t]??u(e);else if(n===`multiEnum`)s=a.getAll(t).filter(e=>!!e&&(o?.has(e)??!0));else if(n===`dateRange`)s={from:a.get(`${t}From`)??``,to:a.get(`${t}To`)??``};else{let e=a.get(t)??``;s=n===`enum`&&o!==void 0&&!o.has(e)?``:e}d[t]=s}return{page:p(a.get(`page`))??i.page??1,pageSize:p(a.get(`pageSize`))??i.pageSize,sortBy:a.get(`sortBy`)||i.sortBy,sortOrder:r(l)?l:i.sortOrder??`asc`,search:(a.get(`search`)??``).trim(),filters:d}}export{e as LIST_QUERY_RESERVED,t as SEARCH_PARAM,u as emptyFacetValue,d as isFacetActive,f as listQueryParamNames,l as listQueryParams,m as parseListQuery};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extractApiError as e}from"../errors/extractApiError.js";import{
|
|
1
|
+
import{extractApiError as e}from"../errors/extractApiError.js";import{isFacetActive as t,listQueryParamNames as n,listQueryParams as r,parseListQuery as i}from"./listQuery.js";import{useCallback as a,useEffect as o,useMemo as s,useRef as c,useState as l}from"react";import{useSearchParams as u}from"react-router";var d=300,f=20,p=`No results match these filters.`,m=[];function h(e,t,r){let a=n(t),o=[...e.keys()].some(e=>a.has(e)),s=i(e,{facets:t,defaults:r});return{page:s.page,...s.pageSize!==void 0&&{pageSize:s.pageSize},...s.sortBy!==void 0&&{sortBy:s.sortBy},sortOrder:s.sortOrder,search:o?s.search:r.search??``,filters:s.filters}}function g(e){return r({page:e.page,...e.pageSize!==void 0&&{pageSize:e.pageSize},...e.sortBy!==void 0&&{sortBy:e.sortBy},sortOrder:e.sortOrder,search:e.search,filters:e.filters})}function _(e){return{page:e.page,...e.pageSize!==void 0&&{pageSize:e.pageSize},...e.sortBy!==void 0&&{sortBy:e.sortBy},sortOrder:e.sortOrder,search:e.search,filters:e.filters}}function v(n){let{fetchPage:r,facets:i=[],defaults:v={},debounceMs:y=d,onRefreshError:b}=n,[x,S]=u(),C=h(x,i,v),[w,T]=l(C.search),[E,D]=l(),O=c(E);O.current=E;let[k,A]=l(),[j,M]=l(!0),[N,P]=l(0),F={...C,search:w},I=c(F);I.current=F;let L=c(r);L.current=r;let R=c(b);R.current=b;let z=`${g(F)}#${N}`,B=c(z);B.current=z,o(()=>{if(C.search===w)return;let e=setTimeout(()=>T(C.search),y);return()=>clearTimeout(e)},[C.search,w,y]),o(()=>{let t=new AbortController,n=()=>t.signal.aborted||B.current!==z;return M(!0),new Promise(e=>{e(L.current(_(I.current),{signal:t.signal}))}).then(e=>{n()||(D(e),A(void 0),M(!1))},t=>{n()||(O.current!==void 0&&R.current?.(e(t)),A({reason:t}),M(!1))}),()=>t.abort()},[z]);let V=(e,t)=>{S(g(e),{replace:!0}),t&&T(e.search)},H=e=>V({...C,page:e},!0),U=e=>V({...C,pageSize:e},!0),W=e=>V({...C,page:1,search:e},!1),G=(e,t)=>V({...C,page:1,filters:{...C.filters,[e]:t}},!0),K=(e,t=`asc`)=>V({...C,page:1,sortBy:e,sortOrder:t},!0),q=e=>K(e,e===C.sortBy&&C.sortOrder===`asc`?`desc`:`asc`),J=()=>{let e=h(new URLSearchParams,i,v);S(new URLSearchParams,{replace:!0}),T(e.search)},Y=a(()=>P(e=>e+1),[]),X=C.search!==``||i.some(e=>t(e,C.filters[e.key])),Z=E?.totalCount??0,Q=E?.totalPages??0,$=E?.totalCountCapped===!0,ee=s(()=>E===void 0?k===void 0||j?{status:`loading`,refetch:Y}:{status:`error`,error:e(k.reason),retry:Y,refetch:Y}:E.items.length===0?{status:`empty`,refreshing:j,refresh:Y,refetch:Y}:{status:`data`,data:E,refreshing:j,refresh:Y,refetch:Y},[E,k,j,Y]);return{query:C,rows:E?.items??m,state:ee,totalCount:Z,totalPages:Q,totalCountCapped:$,setFilter:G,setSearch:W,setSort:K,setPage:H,setPageSize:U,reset:J,tableProps:{rows:E?.items??m,...C.sortBy?{sort:{key:C.sortBy,dir:C.sortOrder}}:{},onSort:q,loading:j,...X?{emptyFiltered:p}:{},sourceCount:X?Math.max(Z,1):Z},paginationProps:{page:C.page,totalPages:Q,pageSize:C.pageSize??E?.pageSize??f,onPageChange:H,onPageSizeChange:U}}}export{v as useListQuery};
|
|
@@ -1,15 +1,29 @@
|
|
|
1
|
-
import { type ContractCallOptions, type OperationEntry, type OperationShape } from "@webority/api-contract/call";
|
|
1
|
+
import { type ContractCallOptions, type ContractFullReply, type OperationEntry, type OperationShape } from "@webority/api-contract/call";
|
|
2
2
|
import type { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
3
3
|
/**
|
|
4
4
|
* Per-call options: an abort signal, a timeout, the client's retry override (`false`, or a policy such as `{ retries: 1 }`),
|
|
5
5
|
* call headers the contract does not declare, `skipErrorLog` and `expectedStatuses`. buildContractRequest validates the
|
|
6
6
|
* headers and the two error options, and throws ContractCallError on an invalid value before anything is sent.
|
|
7
|
+
* `keepalive: true` sends the call so it survives the page closing (a save on page hide), through the browser fetch with
|
|
8
|
+
* keepalive; it must be a boolean when given.
|
|
7
9
|
*/
|
|
8
|
-
export type ContractCallConfig = Pick<AxiosRequestConfig, "signal" | "timeout" | "retry"> & ContractCallOptions
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export type ContractCallConfig = Pick<AxiosRequestConfig, "signal" | "timeout" | "retry"> & ContractCallOptions & {
|
|
11
|
+
readonly keepalive?: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Calls one operation of a generated contract by its id. `reply: "full"` resolves to the status, the headers and the body;
|
|
15
|
+
* otherwise the call resolves to the body the contract types for the operation.
|
|
16
|
+
*/
|
|
17
|
+
export interface ContractCaller<TOperations extends {
|
|
11
18
|
readonly [K in keyof TOperations]: OperationShape;
|
|
12
|
-
}>
|
|
19
|
+
}> {
|
|
20
|
+
<TId extends keyof TOperations & string>(id: TId, request: TOperations[TId]["request"], config: ContractCallConfig & {
|
|
21
|
+
readonly reply: "full";
|
|
22
|
+
}): Promise<ContractFullReply<TOperations[TId]["response"]>>;
|
|
23
|
+
<TId extends keyof TOperations & string>(id: TId, request: TOperations[TId]["request"], config?: ContractCallConfig & {
|
|
24
|
+
readonly reply?: "body" | undefined;
|
|
25
|
+
}): Promise<TOperations[TId]["response"]>;
|
|
26
|
+
}
|
|
13
27
|
/**
|
|
14
28
|
* Builds the typed caller for one generated contract. Errors are the client's own: an interceptor
|
|
15
29
|
* on `client` turns a failure into the curated error, so the caller adds no catch.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type { ContractFullReply, ContractListQueryInput } from "@webority/api-contract/call";
|
|
2
|
+
export { listQuery } from "@webority/api-contract/call";
|
|
1
3
|
export type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
4
|
export type { TokenRefreshConfig, TokenRefreshResult, UserAuthOptions } from "../initUserAuth";
|
|
3
5
|
export { initUserAuth } from "../initUserAuth";
|
|
@@ -19,7 +19,7 @@ export interface ApiRequest {
|
|
|
19
19
|
method?: Method;
|
|
20
20
|
/** The request body. FormData is sent as multipart by the client. */
|
|
21
21
|
data?: unknown;
|
|
22
|
-
/** Query string values; build list queries with `
|
|
22
|
+
/** Query string values; build list queries with `listQuery`. */
|
|
23
23
|
params?: Record<string, unknown>;
|
|
24
24
|
headers?: Record<string, string>;
|
|
25
25
|
/** Only JSON-safe types belong in the store; a file download is a service call through `downloadFile`. */
|
|
@@ -8,11 +8,11 @@ export { useDataState, useInfiniteDataState } from "./dataState";
|
|
|
8
8
|
export type { SaveWithVersionOptions, SaveWithVersionResult, VersionedRead } from "./entityVersion";
|
|
9
9
|
export { entityTagOf, saveWithVersion, versionOf, withIfMatch } from "./entityVersion";
|
|
10
10
|
export { setupApiListeners } from "./listeners";
|
|
11
|
-
export type { Facet, FacetKey, FacetType,
|
|
12
|
-
export {
|
|
11
|
+
export type { Facet, FacetKey, FacetType, ParsedListQuery, ParseListQueryOptions } from "./listQuery";
|
|
12
|
+
export { emptyFacetValue, isFacetActive, LIST_QUERY_RESERVED, listQueryParamNames, parseListQuery, SEARCH_PARAM, } from "./listQuery";
|
|
13
13
|
export type { ListFilterValue, ListQuery, PagedDataObject, PagedListRequest, SortOrder, } from "./paging";
|
|
14
14
|
export { getNextPageParam, getPreviousPageParam, hasNextPage, hasPreviousPage } from "./paging";
|
|
15
15
|
export type { ApiTag, TagId } from "./tags";
|
|
16
16
|
export { itemTag, LIST_TAG_ID, listTag, providesList, providesPagedList } from "./tags";
|
|
17
|
-
export type { ListQueryState, UseListQueryOptions, UseListQueryResult } from "./useListQuery";
|
|
17
|
+
export type { ListFilterKey, ListQueryState, UseListQueryOptions, UseListQueryResult } from "./useListQuery";
|
|
18
18
|
export { useListQuery } from "./useListQuery";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ListFilterValue, SortOrder } from "./paging";
|
|
2
2
|
export type FacetType = "enum" | "multiEnum" | "dateRange" | "text";
|
|
3
|
-
export interface Facet {
|
|
4
|
-
key:
|
|
3
|
+
export interface Facet<TKey extends string = string> {
|
|
4
|
+
key: TKey;
|
|
5
5
|
label: string;
|
|
6
6
|
type: FacetType;
|
|
7
7
|
options?: {
|
|
@@ -10,8 +10,8 @@ export interface Facet {
|
|
|
10
10
|
}[] | undefined;
|
|
11
11
|
}
|
|
12
12
|
/** The part of a facet the URL needs; a full Facet is assignable. */
|
|
13
|
-
export type FacetKey = Pick<Facet, "key" | "type">;
|
|
14
|
-
export interface
|
|
13
|
+
export type FacetKey = Pick<Facet, "key" | "type" | "options">;
|
|
14
|
+
export interface ListUrlState {
|
|
15
15
|
page?: number;
|
|
16
16
|
pageSize?: number;
|
|
17
17
|
sortBy?: string;
|
|
@@ -42,7 +42,7 @@ export declare const LIST_QUERY_RESERVED: readonly string[];
|
|
|
42
42
|
/** The filter param a search box writes (Webority.Ui.Razor ListQuery.SearchKey). */
|
|
43
43
|
export declare const SEARCH_PARAM = "search";
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Writes a list's state into the address bar's search params: the inverse of `parseListQuery`.
|
|
46
46
|
*
|
|
47
47
|
* A filter value is a scalar, an array (one param per item) or a date range `{ from, to }`
|
|
48
48
|
* (written as `<name>From` / `<name>To`). Empty values are left out. A `Date` is written as
|
|
@@ -57,7 +57,7 @@ export declare const SEARCH_PARAM = "search";
|
|
|
57
57
|
* @returns The query params for the list request.
|
|
58
58
|
* @throws When a filter is named page, pageSize, sortBy, sortOrder or search, or `sortOrder` is not asc or desc.
|
|
59
59
|
*/
|
|
60
|
-
export declare function
|
|
60
|
+
export declare function listQueryParams(query?: ListUrlState): URLSearchParams;
|
|
61
61
|
/** The empty value of a facet: "" (enum, text), [] (multiEnum) or { from: "", to: "" } (dateRange). */
|
|
62
62
|
export declare function emptyFacetValue(facet: FacetKey): string | string[] | {
|
|
63
63
|
from: string;
|
|
@@ -68,10 +68,13 @@ export declare function isFacetActive(facet: FacetKey, value: unknown): boolean;
|
|
|
68
68
|
/** Every query param name a list owns: the reserved five plus each facet's own (`<key>From`/`<key>To` for a date range). */
|
|
69
69
|
export declare function listQueryParamNames(facets?: readonly FacetKey[]): ReadonlySet<string>;
|
|
70
70
|
/**
|
|
71
|
-
* Reads a list query back out of the URL's search params: the inverse of `
|
|
71
|
+
* Reads a list query back out of the URL's search params: the inverse of `listQueryParams`.
|
|
72
72
|
* Anything missing or invalid falls back to `defaults`. Every facet gets a value, empty when the
|
|
73
73
|
* URL has none, so the result is always safe to render.
|
|
74
74
|
*
|
|
75
|
+
* A facet with `options` keeps only the option values: an enum value outside them reads as empty,
|
|
76
|
+
* and a multiEnum drops the items outside them. `defaults` are not checked.
|
|
77
|
+
*
|
|
75
78
|
* `defaults.filters` apply only when the URL carries no list param at all (the first landing on
|
|
76
79
|
* the page). After that the URL is the truth, so clearing a filter that has a default stays cleared.
|
|
77
80
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ContractListQueryInput } from "@webority/api-contract/call";
|
|
1
2
|
import { type ApiError } from "../errors";
|
|
2
3
|
import type { DataState } from "./dataState";
|
|
3
4
|
import { type Facet } from "./listQuery";
|
|
@@ -10,11 +11,13 @@ export interface ListQueryState {
|
|
|
10
11
|
search: string;
|
|
11
12
|
filters: Record<string, ListFilterValue>;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/** The filter keys a list query declares, a date range under its base name (`due` for `dueFrom` and `dueTo`). */
|
|
15
|
+
export type ListFilterKey<TQuery> = keyof NonNullable<ContractListQueryInput<TQuery>["filters"]> & string;
|
|
16
|
+
export interface UseListQueryOptions<TRow, TQuery = Record<string, unknown>> {
|
|
17
|
+
fetchPage: (query: ContractListQueryInput<TQuery>, options: {
|
|
15
18
|
signal: AbortSignal;
|
|
16
19
|
}) => Promise<PagedDataObject<TRow>>;
|
|
17
|
-
facets?: Facet[];
|
|
20
|
+
facets?: Facet<ListFilterKey<TQuery>>[];
|
|
18
21
|
defaults?: Partial<ListQueryState>;
|
|
19
22
|
/** Milliseconds a typed search or text filter waits before the list refetches. */
|
|
20
23
|
debounceMs?: number;
|
|
@@ -59,4 +62,4 @@ export interface UseListQueryResult<TRow> {
|
|
|
59
62
|
* rather than push. A filter, search or sort change returns to page 1, and a new
|
|
60
63
|
* request aborts the one in flight.
|
|
61
64
|
*/
|
|
62
|
-
export declare function useListQuery<TRow
|
|
65
|
+
export declare function useListQuery<TRow, TQuery = Record<string, unknown>>(options: UseListQueryOptions<TRow, TQuery>): UseListQueryResult<TRow>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.163.0",
|
|
4
4
|
"description": "Platform layer for Webority React web portals: HTTP clients with single-flight token refresh, auth store, API error extraction, RTK Query base query, logger, formatters, storage, version check and route guards. No UI.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
},
|
|
99
99
|
"sideEffects": false,
|
|
100
100
|
"dependencies": {
|
|
101
|
-
"@webority/api-contract": "0.
|
|
101
|
+
"@webority/api-contract": "0.163.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@microsoft/applicationinsights-web": "^3.4.5",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"@types/node": "25.6.0",
|
|
121
121
|
"@types/react": "^19.3.0",
|
|
122
122
|
"@vitest/coverage-v8": "5.1.0",
|
|
123
|
-
"@webority/biome-config": "0.
|
|
123
|
+
"@webority/biome-config": "0.163.0",
|
|
124
124
|
"axios": "^1.18.0",
|
|
125
125
|
"jsdom": "30.1.1",
|
|
126
126
|
"react": "^19.3.1",
|