@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/README.md CHANGED
@@ -97,8 +97,8 @@ const getUser = client.build(registry.byKey['GET /v1/users/:userId'], {
97
97
 
98
98
  // Infinite/feed GET (cfg.feed === true)
99
99
  const listFeed = client.build(registry.byKey['GET /v1/posts'], {
100
- cursorParam: 'page', // defaults to "pagination_cursor"
101
- getNextPageParam: (last) => last.nextCursor, // React Query option override
100
+ cursorQueryKey: 'page', // defaults to "pagination_cursor"
101
+ getNextPageCursor: (last) => last.nextCursor, // cursor extraction override
102
102
  })
103
103
 
104
104
  // Mutation
package/dist/index.cjs CHANGED
@@ -317,6 +317,7 @@ function assertFileFieldValue(sourceKey, targetField, value) {
317
317
  if (value == null) return;
318
318
  if (isBlobLike(value)) return;
319
319
  if (isReactNativeFile(value)) return;
320
+ if (isImagePickerAsset(value)) return;
320
321
  if (typeof FileList !== "undefined" && value instanceof FileList) {
321
322
  for (const item of Array.from(value)) {
322
323
  if (!isBlobLike(item)) {
@@ -329,16 +330,16 @@ function assertFileFieldValue(sourceKey, targetField, value) {
329
330
  }
330
331
  if (Array.isArray(value)) {
331
332
  for (const item of value) {
332
- if (!isBlobLike(item) && !isReactNativeFile(item)) {
333
+ if (!isBlobLike(item) && !isReactNativeFile(item) && !isImagePickerAsset(item)) {
333
334
  throw new Error(
334
- `Multipart field "${sourceKey}" must contain Blob/File values for "${targetField}".`
335
+ `Multipart field "${sourceKey}" must contain Blob/File, ReactNativeFile or ImagePickerAsset values for "${targetField}".`
335
336
  );
336
337
  }
337
338
  }
338
339
  return;
339
340
  }
340
341
  throw new Error(
341
- `Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, Blob[]/ReactNativeFile[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
342
+ `Multipart field "${sourceKey}" must be Blob/File, ReactNativeFile, ImagePickerAsset, Blob[]/ReactNativeFile[]/ImagePickerAsset[] or FileList. ReactNativeFile = { uri: string, name: string, type: string }.`
342
343
  );
343
344
  }
344
345
  function splitMultipartBody(body, fields) {
@@ -367,6 +368,7 @@ function splitMultipartBody(body, fields) {
367
368
  return { regularBody, multipartFiles };
368
369
  }
369
370
  var isReactNativeFile = (v) => v && typeof v === "object" && typeof v.uri === "string" && typeof v.name === "string" && typeof v.type === "string";
371
+ 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");
370
372
  var isFile = (v) => typeof File !== "undefined" && v instanceof File;
371
373
  var isBlob = (v) => typeof Blob !== "undefined" && v instanceof Blob;
372
374
  function toFormData(body, bodyFiles = []) {
@@ -378,6 +380,14 @@ function toFormData(body, bodyFiles = []) {
378
380
  fd.append(fieldName, value);
379
381
  return;
380
382
  }
383
+ if (isImagePickerAsset(value)) {
384
+ fd.append(fieldName, {
385
+ uri: value.uri,
386
+ name: value.fileName ?? "upload",
387
+ type: value.mimeType ?? "application/octet-stream"
388
+ });
389
+ return;
390
+ }
381
391
  if (isFile(value)) {
382
392
  fd.append(fieldName, value, value.name);
383
393
  return;
@@ -763,16 +773,15 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
763
773
  emit({ type: "build", leaf: leafLabel });
764
774
  const infiniteOptions = rqOpts ?? {};
765
775
  const {
766
- cursorParam,
767
- getNextPageParam,
776
+ cursorQueryKey,
777
+ getNextPageCursor,
768
778
  initialPageParam,
769
779
  splitPageSize,
770
780
  splitPageSizeParam,
771
781
  ...passthroughOptions
772
782
  } = infiniteOptions;
773
- const feedCursorParam = cursorParam ?? "pagination_cursor";
774
- const feedNextPageParam = getNextPageParam ?? ((lastPage) => defaultGetNextCursor(lastPage));
775
- const cursorFromPage = (page) => feedNextPageParam(page);
783
+ const feedCursorQueryKey = cursorQueryKey ?? "pagination_cursor";
784
+ const feedNextPageCursor = getNextPageCursor ?? ((lastPage) => defaultGetNextCursor(lastPage));
776
785
  const feedInitialPageParam = typeof initialPageParam === "undefined" ? void 0 : initialPageParam;
777
786
  const feedQueryOptions = passthroughOptions;
778
787
  const effectiveSplitPageSize = typeof splitPageSize === "number" && splitPageSize > 0 ? splitPageSize : void 0;
@@ -781,7 +790,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
781
790
  const a = extractArgs(tuple);
782
791
  const params = a?.params;
783
792
  const query = a?.query;
784
- const qForKey = stripKey(query, feedCursorParam);
793
+ const qForKey = stripKey(query, feedCursorQueryKey);
785
794
  return (0, import_rrroutes_contract4.buildCacheKey)({
786
795
  leaf,
787
796
  params,
@@ -944,18 +953,32 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
944
953
  const useEndpointOptions = expectsArgs ? useArgs[1] : useArgs[0];
945
954
  const hasCompleteArgs = !expectsArgs || areEndpointArgsComplete(leaf, args);
946
955
  const tuple = toArgsTuple(args);
947
- const queryKeys = getQueryKeys(...tuple);
956
+ const params = args?.params;
957
+ const query = args?.query;
958
+ const buildOptions = feedQueryOptions ?? {};
959
+ const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
960
+ const {
961
+ onReceive: useOnReceive,
962
+ cursorQueryKey: useCursorQueryKey,
963
+ getNextPageCursor: useGetNextPageCursor,
964
+ initialPageParam: useInitialPageParam,
965
+ ...runtimeInfiniteQueryOptions
966
+ } = useEndpointOptions ?? {};
967
+ const effectiveCursorParam = useCursorQueryKey ?? feedCursorQueryKey;
968
+ const effectiveNextPageCursor = useGetNextPageCursor ?? feedNextPageCursor;
969
+ const effectiveInitialPageParam = typeof useInitialPageParam === "undefined" ? feedInitialPageParam : useInitialPageParam;
970
+ const qForKey = stripKey(query, effectiveCursorParam);
971
+ const queryKeys = (0, import_rrroutes_contract4.buildCacheKey)({
972
+ leaf,
973
+ params,
974
+ query: qForKey
975
+ });
948
976
  emit({
949
977
  type: "useEndpoint",
950
978
  leaf: leafLabel,
951
979
  variant: "infiniteGet",
952
980
  keys: queryKeys
953
981
  });
954
- const params = args?.params;
955
- const query = args?.query;
956
- const buildOptions = feedQueryOptions ?? {};
957
- const { onReceive: buildOnReceive2, ...buildInfiniteQueryOptions } = buildOptions;
958
- const { onReceive: useOnReceive, ...runtimeInfiniteQueryOptions } = useEndpointOptions ?? {};
959
982
  const mergedInfiniteQueryOptions = {
960
983
  ...buildInfiniteQueryOptions,
961
984
  ...runtimeInfiniteQueryOptions
@@ -989,8 +1012,8 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
989
1012
  ...mergedInfiniteQueryOptions,
990
1013
  enabled: guardedEnabled,
991
1014
  placeholderData: mergedInfiniteQueryOptions.placeholderData ?? import_react_query3.keepPreviousData,
992
- initialPageParam: feedInitialPageParam,
993
- getNextPageParam: (lastPage) => cursorFromPage(lastPage),
1015
+ initialPageParam: effectiveInitialPageParam,
1016
+ getNextPageParam: (lastPage) => effectiveNextPageCursor(lastPage),
994
1017
  queryKey: queryKeys,
995
1018
  queryFn: ({ pageParam }) => {
996
1019
  if (!hasCompleteArgs) {
@@ -999,7 +1022,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
999
1022
  if (!effectiveSplitPageSize) {
1000
1023
  const pageQuery = {
1001
1024
  ...normalizedQuery,
1002
- ...pageParam ? { [feedCursorParam]: pageParam } : {}
1025
+ ...pageParam ? { [effectiveCursorParam]: pageParam } : {}
1003
1026
  };
1004
1027
  return fetchEndpoint(tuple, {
1005
1028
  queryOverride: pageQuery,
@@ -1011,7 +1034,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
1011
1034
  if (!basePageSize || !Number.isFinite(basePageSize) || basePageSize <= effectiveSplitPageSize) {
1012
1035
  const pageQuery = {
1013
1036
  ...normalizedQuery,
1014
- ...pageParam ? { [feedCursorParam]: pageParam } : {}
1037
+ ...pageParam ? { [effectiveCursorParam]: pageParam } : {}
1015
1038
  };
1016
1039
  return fetchEndpoint(tuple, {
1017
1040
  queryOverride: pageQuery,
@@ -1028,7 +1051,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
1028
1051
  const thisCallSize = Math.min(remaining, effectiveSplitPageSize);
1029
1052
  const splitQuery = {
1030
1053
  ...normalizedQuery,
1031
- ...currentCursor ? { [feedCursorParam]: currentCursor } : {},
1054
+ ...currentCursor ? { [effectiveCursorParam]: currentCursor } : {},
1032
1055
  [effectiveSplitPageSizeParam]: thisCallSize
1033
1056
  };
1034
1057
  const page = await fetchEndpoint(tuple, {
@@ -1037,7 +1060,7 @@ function buildInfiniteGetLeaf(leaf, rqOpts, env) {
1037
1060
  });
1038
1061
  aggregated = aggregated ? mergePageOutputs(aggregated, page) : page;
1039
1062
  remaining -= thisCallSize;
1040
- const nextCursor = cursorFromPage(page);
1063
+ const nextCursor = effectiveNextPageCursor(page);
1041
1064
  currentCursor = nextCursor;
1042
1065
  const k = queryKeys;
1043
1066
  queryClient.setQueryData(k, (prev) => {