@pylo/react 0.9.0 → 0.10.1

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.
@@ -38,6 +38,7 @@ import {
38
38
  uploadToUrl,
39
39
  toUploadPart
40
40
  } from "@pylo/core";
41
+ var INFINITE_PAGINATION_SELECT = { current_page: true, has_more_pages: true };
41
42
  function createPyloHooks(options) {
42
43
  var _a;
43
44
  const useTransport = (_a = options == null ? void 0 : options.useTransport) != null ? _a : usePyloTransport;
@@ -71,7 +72,7 @@ function createPyloHooks(options) {
71
72
  });
72
73
  return {
73
74
  data: (_b = (_a2 = result.data) == null ? void 0 : _a2.data) != null ? _b : void 0,
74
- pagination: (_c = result.data) == null ? void 0 : _c.pagination,
75
+ ..."_pagination" in queryOptions.select && { pagination: (_c = result.data) == null ? void 0 : _c.pagination },
75
76
  isLoading: result.isLoading,
76
77
  error: result.error,
77
78
  refetch: result.refetch
@@ -95,8 +96,12 @@ function createPyloHooks(options) {
95
96
  }
96
97
  ],
97
98
  queryFn: async ({ pageParam }) => {
99
+ const select = infiniteOptions.select;
98
100
  const runtimeOptions = {
99
- select: infiniteOptions == null ? void 0 : infiniteOptions.select,
101
+ select: {
102
+ ...select,
103
+ _pagination: { ...select._pagination, ...INFINITE_PAGINATION_SELECT }
104
+ },
100
105
  filter: infiniteOptions == null ? void 0 : infiniteOptions.filter,
101
106
  pagination: { page: pageParam, per_page: perPage }
102
107
  };
package/dist/hooks.d.ts CHANGED
@@ -1,24 +1,30 @@
1
1
  import { T as Transport } from './transport-55cSrvQo.js';
2
2
  import { UseQueryResult, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
3
- import { EntityNameWith, EntitySelect, FilterInput, RequestOptions, PaginationData, EntityRelationPath, UploadAttachTarget, UploadProgress, PyloUploadedFile, UploadSource, SelectConstraint, ListOptions, EntityResult, ByIdOptions, EntityName, AggregateMetricInput, AggregateGroupByInput, AggregateOptions, AggregateResult, EventMetricInput, EventGroupByInput, EventAggregateOptions, UpsertInput, MutationRequestOptions, PyloEvent, PyloEventInput, EventListOptions, PyloEventListResult, PyloEventPropertyKeysOptions, PyloEventProperty, PyloEventFieldValuesOptions, PyloEventFieldValue } from '@pylo/core';
3
+ import { EntityNameWith, ListSelect, FilterInput, RequestOptions, WithPagination, EntityRelationPath, UploadAttachTarget, UploadProgress, PyloUploadedFile, UploadSource, ListSelectConstraint, ListOptions, EntityResult, PaginationData, SelectConstraint, ByIdOptions, EntityName, AggregateMetricInput, AggregateGroupByInput, AggregateOptions, AggregateResult, EventMetricInput, EventGroupByInput, EventAggregateOptions, UpsertInput, MutationRequestOptions, PyloEvent, PyloEventInput, PaginationSelect, EventListOptions, PyloEventListResult, PyloEventPropertyKeysOptions, PyloEventProperty, PyloEventFieldValuesOptions, PyloEventFieldValue } from '@pylo/core';
4
4
 
5
5
  interface HooksOptions {
6
6
  /** Defaults to reading the transport `PyloProvider` supplies. */
7
7
  useTransport?: () => Transport;
8
8
  headers?: Record<string, string>;
9
9
  }
10
- interface ListHookResult<T> {
10
+ type ListHookResult<T, Sel = unknown> = {
11
11
  data: T[] | undefined;
12
- pagination: PaginationData | undefined;
13
12
  isLoading: boolean;
14
13
  error: Error | null;
15
14
  refetch: UseQueryResult["refetch"];
16
- }
17
- type InfiniteListOptions<S, E extends EntityNameWith<S, "list">, Sel extends EntitySelect<S, E>> = {
15
+ } & (WithPagination<Sel> extends {
16
+ pagination: infer D;
17
+ } ? {
18
+ pagination: D | undefined;
19
+ } : unknown);
20
+ type InfiniteListOptions<S, E extends EntityNameWith<S, "list">, Sel extends ListSelect<S, E>> = {
18
21
  perPage?: number;
19
22
  select: Sel;
20
23
  filter?: FilterInput;
21
24
  } & RequestOptions;
25
+ type InfinitePagination<Sel> = Pick<PaginationData, "current_page" | "has_more_pages" | (Sel extends {
26
+ _pagination: infer PS;
27
+ } ? keyof PS & keyof PaginationData : never)>;
22
28
  interface UploadHookOptions<S> {
23
29
  /**
24
30
  * The pyloMedia relation the files are destined for, e.g. `"contact.avatar"`.
@@ -57,12 +63,12 @@ interface UploadHookResult<S> {
57
63
  reset: () => void;
58
64
  }
59
65
  declare function createPyloHooks<S>(options?: HooksOptions): {
60
- usePyloList: <E extends EntityNameWith<S, "list">, const Sel extends SelectConstraint<S, E, Sel>>(entity: E, queryOptions: ListOptions<S, E, Sel> & RequestOptions) => ListHookResult<EntityResult<S, E, Sel>>;
61
- usePyloInfiniteList: <E extends EntityNameWith<S, "list">, const Sel extends SelectConstraint<S, E, Sel>>(entity: E, infiniteOptions: InfiniteListOptions<S, E, Sel>) => UseInfiniteQueryResult<{
66
+ usePyloList: <E extends EntityNameWith<S, "list">, const Sel extends ListSelectConstraint<S, E, Sel>>(entity: E, queryOptions: ListOptions<S, E, Sel> & RequestOptions) => ListHookResult<EntityResult<S, E, Sel>, Sel>;
67
+ usePyloInfiniteList: <E extends EntityNameWith<S, "list">, const Sel extends ListSelectConstraint<S, E, Sel>>(entity: E, infiniteOptions: InfiniteListOptions<S, E, Sel>) => UseInfiniteQueryResult<{
62
68
  data: Array<EntityResult<S, E, Sel>>;
63
69
  pages: Array<{
64
70
  data: Array<EntityResult<S, E, Sel>>;
65
- pagination: PaginationData;
71
+ pagination: InfinitePagination<Sel>;
66
72
  }>;
67
73
  }>;
68
74
  usePyloById: <E extends EntityNameWith<S, "byId">, const Sel extends SelectConstraint<S, E, Sel>>(entity: E, id: string | null | undefined, queryOptions: ByIdOptions<S, E, Sel> & RequestOptions) => UseQueryResult<EntityResult<S, E, Sel> | null>;
@@ -85,7 +91,7 @@ declare function createPyloHooks<S>(options?: HooksOptions): {
85
91
  success: boolean;
86
92
  }, Error, string[]>;
87
93
  usePyloIngestEvents: (mutationOptions?: Omit<UseMutationOptions<PyloEvent[], Error, PyloEventInput[]>, "mutationFn"> & MutationRequestOptions) => UseMutationResult<PyloEvent[], Error, PyloEventInput[]>;
88
- usePyloEventList: (queryOptions?: EventListOptions & RequestOptions) => UseQueryResult<PyloEventListResult>;
94
+ usePyloEventList: <PS extends PaginationSelect = Record<never, never>>(queryOptions?: EventListOptions<PS> & RequestOptions) => UseQueryResult<PyloEventListResult<PS>>;
89
95
  usePyloEventPropertyKeys: (queryOptions?: PyloEventPropertyKeysOptions & RequestOptions) => UseQueryResult<PyloEventProperty[]>;
90
96
  usePyloEventFieldValues: (field: string | null | undefined, queryOptions?: PyloEventFieldValuesOptions & RequestOptions) => UseQueryResult<PyloEventFieldValue[]>;
91
97
  usePyloUpload: (hookOptions?: UploadHookOptions<S>) => UploadHookResult<S>;
package/dist/hooks.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  createPyloHooks
4
- } from "./chunk-O456XBDT.js";
4
+ } from "./chunk-FKUNSR3E.js";
5
5
  import "./chunk-BPRHGSZF.js";
6
6
  export {
7
7
  createPyloHooks
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPyloHooks
3
- } from "./chunk-O456XBDT.js";
3
+ } from "./chunk-FKUNSR3E.js";
4
4
  import {
5
5
  PyloProvider,
6
6
  createDirectTransport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylo/react",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Type-safe React SDK for Pylo — hooks, session provider, client",
5
5
  "type": "module",
6
6
  "bin": {
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@pylo/auth": "0.2.0",
40
- "@pylo/core": "0.8.1"
40
+ "@pylo/core": "0.11.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@tanstack/react-query": ">=5.0.0",
@@ -1,50 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
- import { PyloClient } from '@pylo/core';
4
- import { PyloUser, AuthResult } from '@pylo/auth';
5
- import { T as Transport } from './transport-55cSrvQo.js';
6
-
7
- /**
8
- * The three operations a session needs from a key-value store. Async because
9
- * the native implementations are: Expo's SecureStore has no synchronous API.
10
- */
11
- interface PyloStorage {
12
- getItem(key: string): Promise<string | null>;
13
- setItem(key: string, value: string): Promise<void>;
14
- removeItem(key: string): Promise<void>;
15
- }
16
- declare function createMemoryStorage(): PyloStorage;
17
- /**
18
- * Persists to `localStorage`, falling back to memory where it is missing or
19
- * blocked — server rendering, and Safari's private mode, which throws on write.
20
- * Falling back means the session lasts the page's lifetime rather than failing
21
- * outright, so a read consults memory whenever the web store comes up empty.
22
- */
23
- declare function createLocalStorageAdapter(): PyloStorage;
24
-
25
- interface PyloProviderProps {
26
- children: ReactNode;
27
- endpoint?: string;
28
- appId?: string;
29
- storage?: PyloStorage;
30
- keyPrefix?: string;
31
- /**
32
- * Escape hatch for apps whose auth lives elsewhere. Supplying it disables the
33
- * session entirely: no login, no logout, no refresh.
34
- */
35
- getToken?: () => Promise<string | null>;
36
- }
37
- declare function PyloProvider(props: PyloProviderProps): react_jsx_runtime.JSX.Element;
38
- declare function usePyloTransport(): Transport;
39
- declare function usePyloClient<S>(): PyloClient<S>;
40
- interface PyloAuth {
41
- isLoading: boolean;
42
- isSignedIn: boolean;
43
- user: PyloUser | undefined;
44
- login: (email: string, password: string) => Promise<AuthResult>;
45
- logout: () => Promise<void>;
46
- getToken: () => Promise<string | null>;
47
- }
48
- declare function usePyloAuth(): PyloAuth;
49
-
50
- export { type PyloStorage as P, type PyloAuth as a, PyloProvider as b, type PyloProviderProps as c, createLocalStorageAdapter as d, createMemoryStorage as e, usePyloClient as f, usePyloTransport as g, usePyloAuth as u };