@classytic/arc-next 0.13.0 → 0.14.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/api.js CHANGED
@@ -98,12 +98,14 @@ var BaseApi = class {
98
98
  });
99
99
  return;
100
100
  }
101
- if (value !== void 0 && value !== "") if (["page", "limit"].includes(key)) result[key] = parseInt(String(value), 10) || (key === "page" ? 1 : 10);
102
- else if (Array.isArray(value)) {
103
- if (/\[([^\]]+)\]$/.test(key)) result[key] = value.join(",");
104
- else if (value.length > 1) result[`${key}[in]`] = value.join(",");
105
- else if (value.length === 1) result[key] = value[0];
106
- } else result[key] = value;
101
+ if (value !== void 0 && value !== "") {
102
+ if (["page", "limit"].includes(key)) result[key] = parseInt(String(value), 10) || (key === "page" ? 1 : 10);
103
+ else if (Array.isArray(value)) {
104
+ if (/\[([^\]]+)\]$/.test(key)) result[key] = value.join(",");
105
+ else if (value.length > 1) result[`${key}[in]`] = value.join(",");
106
+ else if (value.length === 1) result[key] = value[0];
107
+ } else result[key] = value;
108
+ }
107
109
  });
108
110
  return result;
109
111
  }
package/dist/cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  //#region src/cache.ts
2
2
  const DEFAULT_QUERY_CONFIG = {
3
- staleTime: 300 * 1e3,
4
- gcTime: 1800 * 1e3,
3
+ staleTime: 3e5,
4
+ gcTime: 18e5,
5
5
  refetchOnWindowFocus: false,
6
6
  retry: 0
7
7
  };
package/dist/client.js CHANGED
@@ -872,8 +872,10 @@ function withTimeoutSignal(signal, timeoutMs) {
872
872
  const controller = new AbortController();
873
873
  let timedOut = false;
874
874
  const onCallerAbort = () => controller.abort();
875
- if (signal) if (signal.aborted) controller.abort();
876
- else signal.addEventListener("abort", onCallerAbort, { once: true });
875
+ if (signal) {
876
+ if (signal.aborted) controller.abort();
877
+ else signal.addEventListener("abort", onCallerAbort, { once: true });
878
+ }
877
879
  const timer = setTimeout(() => {
878
880
  timedOut = true;
879
881
  controller.abort();
package/dist/hooks.js CHANGED
@@ -305,11 +305,12 @@ function createCrudHooks({ api, entityKey, singular, plural, idField, defaults =
305
305
  tempId = resolveItemId(data) ?? `temp-${globalThis.crypto?.randomUUID?.() ?? Date.now()}`;
306
306
  tempIdsRef.current.set(variables, tempId);
307
307
  }
308
- return prependToListCache(oldData, {
308
+ const optimisticItem = {
309
309
  ...data,
310
310
  _optimistic: true,
311
311
  [idField ?? (resolveItemId(data) ? "id" : "_id")]: tempId
312
- });
312
+ };
313
+ return prependToListCache(oldData, optimisticItem);
313
314
  },
314
315
  reconcile: (raw, variables) => {
315
316
  const serverDoc = extractItem(raw);
@@ -462,7 +463,8 @@ function createCrudHooks({ api, entityKey, singular, plural, idField, defaults =
462
463
  create: useCallback(async (params, options) => {
463
464
  silentRef.current = options?.silent ?? false;
464
465
  try {
465
- const entity = extractItem(await createMutation.mutateAsync(resolveActionAuth(params)));
466
+ const raw = await createMutation.mutateAsync(resolveActionAuth(params));
467
+ const entity = extractItem(raw);
466
468
  options?.onSuccess?.(entity);
467
469
  options?.onSettled?.(entity, null);
468
470
  return entity;
@@ -477,7 +479,8 @@ function createCrudHooks({ api, entityKey, singular, plural, idField, defaults =
477
479
  update: useCallback(async (params, options) => {
478
480
  silentRef.current = options?.silent ?? false;
479
481
  try {
480
- const entity = extractItem(await enqueueWrite(params.id, () => updateMutation.mutateAsync(resolveActionAuth(params))));
482
+ const raw = await enqueueWrite(params.id, () => updateMutation.mutateAsync(resolveActionAuth(params)));
483
+ const entity = extractItem(raw);
481
484
  options?.onSuccess?.(entity);
482
485
  options?.onSettled?.(entity, null);
483
486
  return entity;
@@ -507,7 +510,8 @@ function createCrudHooks({ api, entityKey, singular, plural, idField, defaults =
507
510
  restore: useCallback(async (params, options) => {
508
511
  silentRef.current = options?.silent ?? false;
509
512
  try {
510
- const entity = extractItem(await enqueueWrite(params.id, () => restoreMutation.mutateAsync(resolveActionAuth(params))));
513
+ const raw = await enqueueWrite(params.id, () => restoreMutation.mutateAsync(resolveActionAuth(params)));
514
+ const entity = extractItem(raw);
511
515
  options?.onSuccess?.(entity);
512
516
  options?.onSettled?.(entity, null);
513
517
  return entity;
package/dist/mutation.js CHANGED
@@ -82,8 +82,10 @@ function useMutationWithTransition(config) {
82
82
  queryClient.invalidateQueries({ queryKey: key });
83
83
  });
84
84
  };
85
- if (invalidateQueries.length > 0 && (config.shouldInvalidate?.(data) ?? true)) if (withTransition) startTransition(invalidate);
86
- else invalidate();
85
+ if (invalidateQueries.length > 0 && (config.shouldInvalidate?.(data) ?? true)) {
86
+ if (withTransition) startTransition(invalidate);
87
+ else invalidate();
88
+ }
87
89
  if (toast && (config.shouldToast?.() ?? true)) showToast("success", messages, data, variables, void 0, instanceToast);
88
90
  onSuccess?.(data, variables);
89
91
  },
@@ -3,8 +3,8 @@ import { QueryClient, defaultShouldDehydrateQuery, isServer } from "@tanstack/re
3
3
 
4
4
  //#region src/query-client.ts
5
5
  const DEFAULTS = {
6
- staleTime: 300 * 1e3,
7
- gcTime: 1800 * 1e3,
6
+ staleTime: 3e5,
7
+ gcTime: 18e5,
8
8
  retry: 0,
9
9
  refetchOnWindowFocus: false
10
10
  };
package/dist/upload.js CHANGED
@@ -181,7 +181,8 @@ function uploadAttempt(options) {
181
181
  resolve(body);
182
182
  return;
183
183
  }
184
- reject(new ArcApiError(extractErrorMessage(body, statusText), {
184
+ const message = extractErrorMessage(body, statusText);
185
+ reject(new ArcApiError(message, {
185
186
  status,
186
187
  statusText,
187
188
  json: body,
package/dist/ws.js CHANGED
@@ -123,18 +123,19 @@ function connectWs(options = {}) {
123
123
  const isAuthClose = event.code === 1008 || event.code === 3401 || event.code === 4001 || event.code === 4401;
124
124
  if (handler && isAuthClose && wsAuthRetries < maxAuthRetries) {
125
125
  wsAuthRetries += 1;
126
+ const synthError = new ArcApiError(event.reason || `WebSocket closed with auth code ${event.code}`, {
127
+ status: 401,
128
+ statusText: "WebSocket auth failure",
129
+ json: {
130
+ code: "arc.websocket.unauthorized",
131
+ wsCloseCode: event.code,
132
+ reason: event.reason
133
+ },
134
+ endpoint: url ?? path,
135
+ method: "GET"
136
+ });
126
137
  _runAuthRecovery(handler, {
127
- error: new ArcApiError(event.reason || `WebSocket closed with auth code ${event.code}`, {
128
- status: 401,
129
- statusText: "WebSocket auth failure",
130
- json: {
131
- code: "arc.websocket.unauthorized",
132
- wsCloseCode: event.code,
133
- reason: event.reason
134
- },
135
- endpoint: url ?? path,
136
- method: "GET"
137
- }),
138
+ error: synthError,
138
139
  request: {
139
140
  method: "GET",
140
141
  endpoint: url ?? path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/arc-next",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "React + TanStack Query SDK for Arc resources",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -148,7 +148,7 @@
148
148
  "check:dead-code": "knip"
149
149
  },
150
150
  "peerDependencies": {
151
- "@classytic/repo-core": ">=0.14.0",
151
+ "@classytic/repo-core": ">=0.24.0",
152
152
  "@tanstack/react-query": ">=5.62.0",
153
153
  "jose": ">=5.0.0",
154
154
  "react": ">=19.0.0"
@@ -171,7 +171,7 @@
171
171
  "@arethetypeswrong/cli": "^0.18.5",
172
172
  "@biomejs/biome": "^2.5.5",
173
173
  "@classytic/dev-tools": "^0.2.0",
174
- "@classytic/repo-core": "^0.19.0",
174
+ "@classytic/repo-core": ">=0.24.0",
175
175
  "@tanstack/react-query": "^5.97.0",
176
176
  "@testing-library/react": "^16.3.2",
177
177
  "@types/react": "^19.2.14",