@emeryld/rrroutes-client 2.7.7 → 2.7.9

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/index.mjs CHANGED
@@ -281,6 +281,7 @@ function assertFileFieldValue(sourceKey, targetField, value) {
281
281
  if (value == null) return;
282
282
  if (isBlobLike(value)) return;
283
283
  if (isReactNativeFile(value)) return;
284
+ if (isImagePickerAsset(value)) return;
284
285
  if (typeof FileList !== "undefined" && value instanceof FileList) {
285
286
  for (const item of Array.from(value)) {
286
287
  if (!isBlobLike(item)) {
@@ -293,16 +294,16 @@ function assertFileFieldValue(sourceKey, targetField, value) {
293
294
  }
294
295
  if (Array.isArray(value)) {
295
296
  for (const item of value) {
296
- if (!isBlobLike(item) && !isReactNativeFile(item)) {
297
+ if (!isBlobLike(item) && !isReactNativeFile(item) && !isImagePickerAsset(item)) {
297
298
  throw new Error(
298
- `Multipart field "${sourceKey}" must contain Blob/File values for "${targetField}".`
299
+ `Multipart field "${sourceKey}" must contain Blob/File, ReactNativeFile or ImagePickerAsset values for "${targetField}".`
299
300
  );
300
301
  }
301
302
  }
302
303
  return;
303
304
  }
304
305
  throw new Error(
305
- `Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, Blob[]/ReactNativeFile[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
306
+ `Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, ImagePickerAsset, Blob[]/ReactNativeFile[]/ImagePickerAsset[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
306
307
  );
307
308
  }
308
309
  function splitMultipartBody(body, fields) {
@@ -331,6 +332,7 @@ function splitMultipartBody(body, fields) {
331
332
  return { regularBody, multipartFiles };
332
333
  }
333
334
  var isReactNativeFile = (v) => v && typeof v === "object" && typeof v.uri === "string" && typeof v.name === "string" && typeof v.type === "string";
335
+ var isImagePickerAsset = (v) => v && typeof v === "object" && typeof v.uri === "string" && (typeof v.fileName === "string" || typeof v.mimeType === "string" || typeof v.width === "number" || typeof v.height === "number");
334
336
  var isFile = (v) => typeof File !== "undefined" && v instanceof File;
335
337
  var isBlob = (v) => typeof Blob !== "undefined" && v instanceof Blob;
336
338
  function toFormData(body, bodyFiles = []) {
@@ -342,6 +344,14 @@ function toFormData(body, bodyFiles = []) {
342
344
  fd.append(fieldName, value);
343
345
  return;
344
346
  }
347
+ if (isImagePickerAsset(value)) {
348
+ fd.append(fieldName, {
349
+ uri: value.uri,
350
+ name: value.fileName ?? "upload",
351
+ type: value.mimeType ?? "application/octet-stream"
352
+ });
353
+ return;
354
+ }
345
355
  if (isFile(value)) {
346
356
  fd.append(fieldName, value, value.name);
347
357
  return;
@@ -730,16 +740,15 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
730
740
  emit({ type: "build", leaf: leafLabel });
731
741
  const infiniteOptions = rqOpts ?? {};
732
742
  const {
733
- cursorParam,
734
- getNextPageParam,
743
+ cursorQueryKey,
744
+ getNextPageCursor,
735
745
  initialPageParam,
736
746
  splitPageSize,
737
747
  splitPageSizeParam,
738
748
  ...passthroughOptions
739
749
  } = infiniteOptions;
740
- const feedCursorParam = cursorParam ?? "pagination_cursor";
741
- const feedNextPageParam = getNextPageParam ?? ((lastPage) => defaultGetNextCursor(lastPage));
742
- const cursorFromPage = (page) => feedNextPageParam(page);
750
+ const feedCursorQueryKey = cursorQueryKey ?? "pagination_cursor";
751
+ const feedNextPageCursor = getNextPageCursor ?? ((lastPage) => defaultGetNextCursor(lastPage));
743
752
  const feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
744
753
  const feedQueryOptions = passthroughOptions;
745
754
  const effectiveSplitPageSize = typeof splitPageSize === "number" && splitPageSize > 0 ? splitPageSize : void 0;
@@ -748,7 +757,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
748
757
  const a = extractArgs(tuple);
749
758
  const params = a?.params;
750
759
  const query = a?.query;
751
- const qForKey = stripKey(query, feedCursorParam);
760
+ const qForKey = stripKey(query, feedCursorQueryKey);
752
761
  return buildCacheKey2({
753
762
  leaf,
754
763
  params,
@@ -911,18 +920,32 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
911
920
  const useEndpointOptions = expectsArgs ? useArgs[1] : useArgs[0];
912
921
  const hasCompleteArgs = !expectsArgs || areEndpointArgsComplete(leaf, args);
913
922
  const tuple = toArgsTuple(args);
914
- const queryKeys = getQueryKeys(...tuple);
923
+ const params = args?.params;
924
+ const query = args?.query;
925
+ const buildOptions = feedQueryOptions ?? {};
926
+ const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
927
+ const {
928
+ onReceive: useOnReceive,
929
+ cursorQueryKey: useCursorQueryKey,
930
+ getNextPageCursor: useGetNextPageCursor,
931
+ initialPageParam: useInitialPageParam,
932
+ ...runtimeInfiniteQueryOptions
933
+ } = useEndpointOptions ?? {};
934
+ const effectiveCursorParam = useCursorQueryKey ?? feedCursorQueryKey;
935
+ const effectiveNextPageCursor = useGetNextPageCursor ?? feedNextPageCursor;
936
+ const effectiveInitialPageParam = typeof useInitialPageParam === "undefined" ? feedInitialPageParam : useInitialPageParam;
937
+ const qForKey = stripKey(query, effectiveCursorParam);
938
+ const queryKeys = buildCacheKey2({
939
+ leaf,
940
+ params,
941
+ query: qForKey
942
+ });
915
943
  emit({
916
944
  type: "useEndpoint",
917
945
  leaf: leafLabel,
918
946
  variant: "infiniteGet",
919
947
  keys: queryKeys
920
948
  });
921
- const params = args?.params;
922
- const query = args?.query;
923
- const buildOptions = feedQueryOptions ?? {};
924
- const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
925
- const { onReceive: useOnReceive, ...runtimeInfiniteQueryOptions } = useEndpointOptions ?? {};
926
949
  const mergedInfiniteQueryOptions = {
927
950
  ...buildInfiniteQueryOptions,
928
951
  ...runtimeInfiniteQueryOptions
@@ -956,8 +979,8 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
956
979
  ...mergedInfiniteQueryOptions,
957
980
  enabled: guardedEnabled,
958
981
  placeholderData: mergedInfiniteQueryOptions.placeholderData ?? keepPreviousData3,
959
- initialPageParam: feedInitialPageParam,
960
- getNextPageParam: (lastPage) => cursorFromPage(lastPage),
982
+ initialPageParam: effectiveInitialPageParam,
983
+ getNextPageParam: (lastPage) => effectiveNextPageCursor(lastPage),
961
984
  queryKey: queryKeys,
962
985
  queryFn: ({ pageParam }) => {
963
986
  if (!hasCompleteArgs) {
@@ -966,7 +989,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
966
989
  if (!effectiveSplitPageSize) {
967
990
  const pageQuery = {
968
991
  ...normalizedQuery,
969
- ...pageParam ? { [feedCursorParam]: pageParam } : {}
992
+ ...pageParam ? { [effectiveCursorParam]: pageParam } : {}
970
993
  };
971
994
  return fetchEndpoint(tuple, {
972
995
  queryOverride: pageQuery,
@@ -978,7 +1001,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
978
1001
  if (!basePageSize || !Number.isFinite(basePageSize) || basePageSize <= effectiveSplitPageSize) {
979
1002
  const pageQuery = {
980
1003
  ...normalizedQuery,
981
- ...pageParam ? { [feedCursorParam]: pageParam } : {}
1004
+ ...pageParam ? { [effectiveCursorParam]: pageParam } : {}
982
1005
  };
983
1006
  return fetchEndpoint(tuple, {
984
1007
  queryOverride: pageQuery,
@@ -995,7 +1018,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
995
1018
  const thisCallSize = Math.min(remaining, effectiveSplitPageSize);
996
1019
  const splitQuery = {
997
1020
  ...normalizedQuery,
998
- ...currentCursor ? { [feedCursorParam]: currentCursor } : {},
1021
+ ...currentCursor ? { [effectiveCursorParam]: currentCursor } : {},
999
1022
  [effectiveSplitPageSizeParam]: thisCallSize
1000
1023
  };
1001
1024
  const page = await fetchEndpoint(tuple, {
@@ -1004,7 +1027,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
1004
1027
  });
1005
1028
  aggregated = aggregated ? mergePageOutputs(aggregated, page) : page;
1006
1029
  remaining -= thisCallSize;
1007
- const nextCursor = cursorFromPage(page);
1030
+ const nextCursor = effectiveNextPageCursor(page);
1008
1031
  currentCursor = nextCursor;
1009
1032
  const k = queryKeys;
1010
1033
  queryClient.setQueryData(k, (prev) => {