@ttt-productions/query-core 0.14.22 → 0.14.24

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.
Files changed (137) hide show
  1. package/README.md +6 -6
  2. package/dist/defaults.d.ts +0 -15
  3. package/dist/defaults.d.ts.map +1 -1
  4. package/dist/defaults.js +0 -15
  5. package/dist/defaults.js.map +1 -1
  6. package/dist/firestore/types.d.ts +5 -49
  7. package/dist/firestore/types.d.ts.map +1 -1
  8. package/dist/firestore/types.js.map +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +0 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/keys.d.ts +0 -22
  13. package/dist/keys.d.ts.map +1 -1
  14. package/dist/keys.js +0 -4
  15. package/dist/keys.js.map +1 -1
  16. package/dist/react/cache-helpers.d.ts +0 -32
  17. package/dist/react/cache-helpers.d.ts.map +1 -1
  18. package/dist/react/cache-helpers.js +0 -28
  19. package/dist/react/cache-helpers.js.map +1 -1
  20. package/dist/react/callables/create-callables.d.ts +40 -0
  21. package/dist/react/callables/create-callables.d.ts.map +1 -0
  22. package/dist/react/callables/create-callables.js +101 -0
  23. package/dist/react/callables/create-callables.js.map +1 -0
  24. package/dist/react/defaults.d.ts +0 -4
  25. package/dist/react/defaults.d.ts.map +1 -1
  26. package/dist/react/defaults.js +2 -6
  27. package/dist/react/defaults.js.map +1 -1
  28. package/dist/react/domain-events/cache-invalidation.d.ts +0 -37
  29. package/dist/react/domain-events/cache-invalidation.d.ts.map +1 -1
  30. package/dist/react/domain-events/cache-invalidation.js +4 -53
  31. package/dist/react/domain-events/cache-invalidation.js.map +1 -1
  32. package/dist/react/domain-events/create-domain-event-invalidator.d.ts +0 -18
  33. package/dist/react/domain-events/create-domain-event-invalidator.d.ts.map +1 -1
  34. package/dist/react/domain-events/create-domain-event-invalidator.js +0 -5
  35. package/dist/react/domain-events/create-domain-event-invalidator.js.map +1 -1
  36. package/dist/react/firestore/absence-scheduler.d.ts +0 -28
  37. package/dist/react/firestore/absence-scheduler.d.ts.map +1 -1
  38. package/dist/react/firestore/absence-scheduler.js +1 -39
  39. package/dist/react/firestore/absence-scheduler.js.map +1 -1
  40. package/dist/react/firestore/batch-doc-loader.d.ts +0 -30
  41. package/dist/react/firestore/batch-doc-loader.d.ts.map +1 -1
  42. package/dist/react/firestore/batch-doc-loader.js +0 -34
  43. package/dist/react/firestore/batch-doc-loader.js.map +1 -1
  44. package/dist/react/firestore/context.d.ts +0 -19
  45. package/dist/react/firestore/context.d.ts.map +1 -1
  46. package/dist/react/firestore/context.js +0 -19
  47. package/dist/react/firestore/context.js.map +1 -1
  48. package/dist/react/firestore/doc-subscription-registry.d.ts +0 -23
  49. package/dist/react/firestore/doc-subscription-registry.d.ts.map +1 -1
  50. package/dist/react/firestore/doc-subscription-registry.js +5 -26
  51. package/dist/react/firestore/doc-subscription-registry.js.map +1 -1
  52. package/dist/react/firestore/infinite-helpers.d.ts +0 -12
  53. package/dist/react/firestore/infinite-helpers.d.ts.map +1 -1
  54. package/dist/react/firestore/infinite-helpers.js +0 -12
  55. package/dist/react/firestore/infinite-helpers.js.map +1 -1
  56. package/dist/react/firestore/resubscribe.d.ts +0 -20
  57. package/dist/react/firestore/resubscribe.d.ts.map +1 -1
  58. package/dist/react/firestore/resubscribe.js +0 -20
  59. package/dist/react/firestore/resubscribe.js.map +1 -1
  60. package/dist/react/firestore/subscription-status.d.ts +0 -29
  61. package/dist/react/firestore/subscription-status.d.ts.map +1 -1
  62. package/dist/react/firestore/subscription-status.js +1 -34
  63. package/dist/react/firestore/subscription-status.js.map +1 -1
  64. package/dist/react/firestore/types.d.ts +0 -64
  65. package/dist/react/firestore/types.d.ts.map +1 -1
  66. package/dist/react/firestore/types.js +0 -3
  67. package/dist/react/firestore/types.js.map +1 -1
  68. package/dist/react/firestore/use-firestore-collection.d.ts +0 -20
  69. package/dist/react/firestore/use-firestore-collection.d.ts.map +1 -1
  70. package/dist/react/firestore/use-firestore-collection.js +1 -35
  71. package/dist/react/firestore/use-firestore-collection.js.map +1 -1
  72. package/dist/react/firestore/use-firestore-count.d.ts +0 -15
  73. package/dist/react/firestore/use-firestore-count.d.ts.map +1 -1
  74. package/dist/react/firestore/use-firestore-count.js +0 -15
  75. package/dist/react/firestore/use-firestore-count.js.map +1 -1
  76. package/dist/react/firestore/use-firestore-doc.d.ts +0 -23
  77. package/dist/react/firestore/use-firestore-doc.d.ts.map +1 -1
  78. package/dist/react/firestore/use-firestore-doc.js +3 -40
  79. package/dist/react/firestore/use-firestore-doc.js.map +1 -1
  80. package/dist/react/firestore/use-firestore-infinite.d.ts +0 -29
  81. package/dist/react/firestore/use-firestore-infinite.d.ts.map +1 -1
  82. package/dist/react/firestore/use-firestore-infinite.js +0 -32
  83. package/dist/react/firestore/use-firestore-infinite.js.map +1 -1
  84. package/dist/react/firestore/use-firestore-live-infinite.d.ts +0 -34
  85. package/dist/react/firestore/use-firestore-live-infinite.d.ts.map +1 -1
  86. package/dist/react/firestore/use-firestore-live-infinite.js +1 -35
  87. package/dist/react/firestore/use-firestore-live-infinite.js.map +1 -1
  88. package/dist/react/firestore/use-firestore-mutations.d.ts.map +1 -1
  89. package/dist/react/firestore/use-firestore-mutations.js +6 -5
  90. package/dist/react/firestore/use-firestore-mutations.js.map +1 -1
  91. package/dist/react/firestore/use-firestore-paginated.d.ts +0 -30
  92. package/dist/react/firestore/use-firestore-paginated.d.ts.map +1 -1
  93. package/dist/react/firestore/use-firestore-paginated.js +2 -33
  94. package/dist/react/firestore/use-firestore-paginated.js.map +1 -1
  95. package/dist/react/firestore/useBatchFirestoreDocs.d.ts +1 -123
  96. package/dist/react/firestore/useBatchFirestoreDocs.d.ts.map +1 -1
  97. package/dist/react/firestore/useBatchFirestoreDocs.js +23 -64
  98. package/dist/react/firestore/useBatchFirestoreDocs.js.map +1 -1
  99. package/dist/react/index.d.ts +4 -0
  100. package/dist/react/index.d.ts.map +1 -1
  101. package/dist/react/index.js +2 -13
  102. package/dist/react/index.js.map +1 -1
  103. package/dist/react/pending-mutations.d.ts +1 -21
  104. package/dist/react/pending-mutations.d.ts.map +1 -1
  105. package/dist/react/pending-mutations.js +1 -32
  106. package/dist/react/pending-mutations.js.map +1 -1
  107. package/dist/react/provider.d.ts +0 -5
  108. package/dist/react/provider.d.ts.map +1 -1
  109. package/dist/react/provider.js +0 -4
  110. package/dist/react/provider.js.map +1 -1
  111. package/dist/react/query-client.d.ts +0 -4
  112. package/dist/react/query-client.d.ts.map +1 -1
  113. package/dist/react/query-client.js +0 -4
  114. package/dist/react/query-client.js.map +1 -1
  115. package/dist/react/search/types.d.ts +0 -12
  116. package/dist/react/search/types.d.ts.map +1 -1
  117. package/dist/react/search/types.js.map +1 -1
  118. package/dist/react/search/use-firestore-search.d.ts +0 -29
  119. package/dist/react/search/use-firestore-search.d.ts.map +1 -1
  120. package/dist/react/search/use-firestore-search.js +3 -41
  121. package/dist/react/search/use-firestore-search.js.map +1 -1
  122. package/dist/react/session-mutation.d.ts +27 -0
  123. package/dist/react/session-mutation.d.ts.map +1 -0
  124. package/dist/react/session-mutation.js +150 -0
  125. package/dist/react/session-mutation.js.map +1 -0
  126. package/dist/react/use-read-retry-state.d.ts +1 -21
  127. package/dist/react/use-read-retry-state.d.ts.map +1 -1
  128. package/dist/react/use-read-retry-state.js +2 -21
  129. package/dist/react/use-read-retry-state.js.map +1 -1
  130. package/dist/search/rule.d.ts +0 -6
  131. package/dist/search/rule.d.ts.map +1 -1
  132. package/dist/search/rule.js +0 -6
  133. package/dist/search/rule.js.map +1 -1
  134. package/dist/search/types.d.ts +1 -13
  135. package/dist/search/types.d.ts.map +1 -1
  136. package/dist/search/types.js.map +1 -1
  137. package/package.json +4 -4
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # @ttt-productions/query-core
2
2
 
3
- Shared TanStack Query (React Query) setup for TTT Productions apps.
3
+ Shared TanStack Query (React Query) setup and Firestore read hooks for consuming apps.
4
4
 
5
- - `createTTTQueryClient()` factory with safe defaults
6
- - `keys` query key helpers
7
- - invalidation + cache update helpers
8
- - `TTTQueryProvider` for Next.js/React apps
5
+ - `createQueryClient()` factory with safe defaults and `QueryProvider` (`./react`)
6
+ - `STALE_TIMES` presets and the search rule (root)
7
+ - `keys` query key helpers (`./keys`)
8
+ - the Firestore hooks, invalidation, and cache update helpers (`./react`)
9
9
 
10
- No app business logic. No Firebase.
10
+ No app business logic. See `docs/packages/query-core.md`.
@@ -1,18 +1,3 @@
1
- /**
2
- * Named `staleTime` presets (milliseconds) for React Query call sites.
3
- *
4
- * Use a preset instead of a magic number so every query self-documents how
5
- * fresh its data must be:
6
- * - `short` (30s) — frequently-changing counts/lists; matches the client default.
7
- * - `medium` (5m) — semi-dynamic data that tolerates a few minutes of staleness.
8
- * - `long` (30m) — rarely-changing data (public profiles, detail docs).
9
- * - `forever` (∞) — immutable for the session, OR data whose freshness is driven
10
- * entirely by explicit cache invalidation (a domain event), never
11
- * by elapsed time. Do NOT use `forever` for data with no
12
- * invalidation path — it will never refetch.
13
- *
14
- * Generic time buckets, not app-specific presets — safe to live in this package.
15
- */
16
1
  export declare const STALE_TIMES: {
17
2
  readonly short: 30000;
18
3
  readonly medium: number;
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW;;;;;CAKd,CAAC"}
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;CAKd,CAAC"}
package/dist/defaults.js CHANGED
@@ -1,18 +1,3 @@
1
- /**
2
- * Named `staleTime` presets (milliseconds) for React Query call sites.
3
- *
4
- * Use a preset instead of a magic number so every query self-documents how
5
- * fresh its data must be:
6
- * - `short` (30s) — frequently-changing counts/lists; matches the client default.
7
- * - `medium` (5m) — semi-dynamic data that tolerates a few minutes of staleness.
8
- * - `long` (30m) — rarely-changing data (public profiles, detail docs).
9
- * - `forever` (∞) — immutable for the session, OR data whose freshness is driven
10
- * entirely by explicit cache invalidation (a domain event), never
11
- * by elapsed time. Do NOT use `forever` for data with no
12
- * invalidation path — it will never refetch.
13
- *
14
- * Generic time buckets, not app-specific presets — safe to live in this package.
15
- */
16
1
  export const STALE_TIMES = {
17
2
  short: 30_000,
18
3
  medium: 5 * 60_000,
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,CAAC,GAAG,MAAM;IAClB,IAAI,EAAE,EAAE,GAAG,MAAM;IACjB,OAAO,EAAE,MAAM,CAAC,iBAAiB;CACzB,CAAC","sourcesContent":["/**\n * Named `staleTime` presets (milliseconds) for React Query call sites.\n *\n * Use a preset instead of a magic number so every query self-documents how\n * fresh its data must be:\n * - `short` (30s) — frequently-changing counts/lists; matches the client default.\n * - `medium` (5m) — semi-dynamic data that tolerates a few minutes of staleness.\n * - `long` (30m) — rarely-changing data (public profiles, detail docs).\n * - `forever` (∞) — immutable for the session, OR data whose freshness is driven\n * entirely by explicit cache invalidation (a domain event), never\n * by elapsed time. Do NOT use `forever` for data with no\n * invalidation path — it will never refetch.\n *\n * Generic time buckets, not app-specific presets — safe to live in this package.\n */\nexport const STALE_TIMES = {\n short: 30_000,\n medium: 5 * 60_000,\n long: 30 * 60_000,\n forever: Number.POSITIVE_INFINITY,\n} as const;\n"]}
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,CAAC,GAAG,MAAM;IAClB,IAAI,EAAE,EAAE,GAAG,MAAM;IACjB,OAAO,EAAE,MAAM,CAAC,iBAAiB;CACzB,CAAC","sourcesContent":["export const STALE_TIMES = {\n short: 30_000,\n medium: 5 * 60_000,\n long: 30 * 60_000,\n forever: Number.POSITIVE_INFINITY,\n} as const;\n"]}
@@ -1,44 +1,20 @@
1
- /**
2
- * Document with ID included in the data object.
3
- */
4
1
  export type WithId<T> = T & {
5
2
  id: string;
6
3
  };
7
- /**
8
- * Metadata-derived liveness of a realtime subscription. Firestore serves cached
9
- * snapshots offline WITHOUT firing the error callback, so error-only detection
10
- * renders a stale cached empty result as "live". This four-state is derived from
11
- * `snapshot.metadata.fromCache` (server-confirmed vs cache) plus the listener
12
- * error callback:
13
- * - `connecting` — no server-confirmed snapshot yet (initial, or only cache-first data).
14
- * - `live` — at least one server-confirmed snapshot (`fromCache === false`).
15
- * - `offline` — only cached data after having been live (connectivity loss).
16
- * - `error` — the listener error callback fired (e.g. permission loss).
17
- *
18
- * Meaningful only for `subscribe: true`; a non-subscribed hook stays `connecting`.
19
- */
4
+ /** Firestore serves cached snapshots offline without firing the error callback, so liveness is read from `metadata.fromCache`. */
20
5
  export type FirestoreSourceState = 'connecting' | 'live' | 'offline' | 'error';
21
- /** A query-hook result augmented with the metadata-derived subscription source state. */
22
6
  export type WithSourceState<R> = R & {
23
7
  sourceState: FirestoreSourceState;
24
8
  };
25
- /**
26
- * One requested id's answer from `useBatchFirestoreDocs`:
27
- * - `loading` — no answer yet (nothing cached for the id, or the hook is disabled).
28
- * - `present` — the document exists and is readable; `data` is it.
29
- * - `absent` — the read succeeded and the document does not exist.
30
- * - `failed` — the read (or, in subscribe mode, the listener) errored; `error` is the cause.
31
- * A failure is never reported as `absent`, and a document cached before the failure is
32
- * not reported as `present`. What a failure means for a given collection (a rules denial
33
- * that stands for "not there for this reader", say) is the consumer's to decide from `error`.
34
- * - A failed id stays `failed` through a retry of it, with the failure it showed and `retrying`
35
- * true while the retry runs; an answer replaces it, a new failure replaces its `error`.
36
- */
37
9
  export type BatchFirestoreDocOutcome<T> = {
38
10
  status: 'loading';
39
11
  } | {
40
12
  status: 'present';
41
13
  data: T;
14
+ failure?: {
15
+ error: Error;
16
+ retrying: boolean;
17
+ };
42
18
  } | {
43
19
  status: 'absent';
44
20
  } | {
@@ -46,42 +22,22 @@ export type BatchFirestoreDocOutcome<T> = {
46
22
  error: Error;
47
23
  retrying: boolean;
48
24
  };
49
- /**
50
- * Base options shared across all Firestore hooks.
51
- */
52
25
  export interface FirestoreBaseOptions {
53
- /** React Query cache key */
54
26
  queryKey: readonly unknown[];
55
- /** Enable/disable the query */
56
27
  enabled?: boolean;
57
- /** Stale time override (ms) */
58
28
  staleTime?: number;
59
- /** Garbage collection time override (ms) */
60
29
  gcTime?: number;
61
30
  }
62
- /**
63
- * Options for document mutations.
64
- */
65
31
  export interface FirestoreMutationOptions<T> {
66
- /** Document path for single-doc mutations */
67
32
  docPath?: string;
68
- /** Query keys to invalidate on success */
69
33
  invalidateKeys?: readonly unknown[][];
70
- /** Enable optimistic updates */
71
34
  optimistic?: {
72
- /** Query key of the cache to update */
73
35
  queryKey: readonly unknown[];
74
- /** How to update the cached data */
75
36
  updater: (oldData: T | undefined, newData: Partial<T>) => T;
76
37
  };
77
38
  }
78
- /**
79
- * Options for batch mutations.
80
- */
81
39
  export interface FirestoreBatchOptions {
82
- /** Query keys to invalidate on success */
83
40
  invalidateKeys?: readonly unknown[][];
84
- /** Max operations per batch (default: 450) */
85
41
  batchSize?: number;
86
42
  }
87
43
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/firestore/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAE/E,yFAAyF;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C,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;KAC7D,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,EAAE,SAAS,OAAO,EAAE,EAAE,CAAC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/firestore/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Document with ID included in the data object.\n */\nexport type WithId<T> = T & { id: string };\n\n/**\n * Metadata-derived liveness of a realtime subscription. Firestore serves cached\n * snapshots offline WITHOUT firing the error callback, so error-only detection\n * renders a stale cached empty result as \"live\". This four-state is derived from\n * `snapshot.metadata.fromCache` (server-confirmed vs cache) plus the listener\n * error callback:\n * - `connecting` — no server-confirmed snapshot yet (initial, or only cache-first data).\n * - `live` — at least one server-confirmed snapshot (`fromCache === false`).\n * - `offline` — only cached data after having been live (connectivity loss).\n * - `error` — the listener error callback fired (e.g. permission loss).\n *\n * Meaningful only for `subscribe: true`; a non-subscribed hook stays `connecting`.\n */\nexport type FirestoreSourceState = 'connecting' | 'live' | 'offline' | 'error';\n\n/** A query-hook result augmented with the metadata-derived subscription source state. */\nexport type WithSourceState<R> = R & { sourceState: FirestoreSourceState };\n\n/**\n * One requested id's answer from `useBatchFirestoreDocs`:\n * - `loading` — no answer yet (nothing cached for the id, or the hook is disabled).\n * - `present` — the document exists and is readable; `data` is it.\n * - `absent` — the read succeeded and the document does not exist.\n * - `failed` — the read (or, in subscribe mode, the listener) errored; `error` is the cause.\n * A failure is never reported as `absent`, and a document cached before the failure is\n * not reported as `present`. What a failure means for a given collection (a rules denial\n * that stands for \"not there for this reader\", say) is the consumer's to decide from `error`.\n * - A failed id stays `failed` through a retry of it, with the failure it showed and `retrying`\n * true while the retry runs; an answer replaces it, a new failure replaces its `error`.\n */\nexport type BatchFirestoreDocOutcome<T> =\n | { status: 'loading' }\n | { status: 'present'; data: T }\n | { status: 'absent' }\n | { status: 'failed'; error: Error; retrying: boolean };\n\n/**\n * Base options shared across all Firestore hooks.\n */\nexport interface FirestoreBaseOptions {\n /** React Query cache key */\n queryKey: readonly unknown[];\n /** Enable/disable the query */\n enabled?: boolean;\n /** Stale time override (ms) */\n staleTime?: number;\n /** Garbage collection time override (ms) */\n gcTime?: number;\n}\n\n/**\n * Options for document mutations.\n */\nexport interface FirestoreMutationOptions<T> {\n /** Document path for single-doc mutations */\n docPath?: string;\n /** Query keys to invalidate on success */\n invalidateKeys?: readonly unknown[][];\n /** Enable optimistic updates */\n optimistic?: {\n /** Query key of the cache to update */\n queryKey: readonly unknown[];\n /** How to update the cached data */\n updater: (oldData: T | undefined, newData: Partial<T>) => T;\n };\n}\n\n/**\n * Options for batch mutations.\n */\nexport interface FirestoreBatchOptions {\n /** Query keys to invalidate on success */\n invalidateKeys?: readonly unknown[][];\n /** Max operations per batch (default: 450) */\n batchSize?: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/firestore/types.ts"],"names":[],"mappings":"","sourcesContent":["export type WithId<T> = T & { id: string };\n\n/** Firestore serves cached snapshots offline without firing the error callback, so liveness is read from `metadata.fromCache`. */\nexport type FirestoreSourceState = 'connecting' | 'live' | 'offline' | 'error';\n\nexport type WithSourceState<R> = R & { sourceState: FirestoreSourceState };\n\nexport type BatchFirestoreDocOutcome<T> =\n | { status: 'loading' }\n | { status: 'present'; data: T; failure?: { error: Error; retrying: boolean } }\n | { status: 'absent' }\n | { status: 'failed'; error: Error; retrying: boolean };\n\nexport interface FirestoreBaseOptions {\n queryKey: readonly unknown[];\n enabled?: boolean;\n staleTime?: number;\n gcTime?: number;\n}\n\nexport interface FirestoreMutationOptions<T> {\n docPath?: string;\n invalidateKeys?: readonly unknown[][];\n optimistic?: {\n queryKey: readonly unknown[];\n updater: (oldData: T | undefined, newData: Partial<T>) => T;\n };\n}\n\nexport interface FirestoreBatchOptions {\n invalidateKeys?: readonly unknown[][];\n batchSize?: number;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // Query defaults & staleTime presets (server-safe — plain constants, no React runtime)
2
1
  export { STALE_TIMES } from './defaults.js';
3
2
  export { FIRESTORE_SEARCH_MIN_LENGTH, isSearchableText, normalizeSearchText, } from './search/rule.js';
4
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC","sourcesContent":["// Query defaults & staleTime presets (server-safe — plain constants, no React runtime)\nexport { STALE_TIMES } from './defaults.js';\n\n// Search Types\nexport type { FirestoreSearchConfig, SearchEqualityFilter } from './search/types.js';\nexport {\n FIRESTORE_SEARCH_MIN_LENGTH,\n isSearchableText,\n normalizeSearchText,\n} from './search/rule.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC","sourcesContent":["export { STALE_TIMES } from './defaults.js';\n\nexport type { FirestoreSearchConfig, SearchEqualityFilter } from './search/types.js';\nexport {\n FIRESTORE_SEARCH_MIN_LENGTH,\n isSearchableText,\n normalizeSearchText,\n} from './search/rule.js';\n"]}
package/dist/keys.d.ts CHANGED
@@ -1,21 +1,3 @@
1
- /**
2
- * Lightweight, stable, Firestore-safe query key helpers.
3
- *
4
- * All keys are arrays of `string | number | boolean | null` so they can
5
- * be written into Firestore docs (used by the unified upload pipeline's
6
- * `result.invalidate` field) and read back by the frontend hook to call
7
- * `queryClient.invalidateQueries`. Both sides produce structurally
8
- * identical arrays.
9
- *
10
- * Convention:
11
- * - `keys.user.all` => ['user']
12
- * - `keys.user.detail(id)` => ['user', 'detail', id]
13
- * - `keys.user.list(param?)` => ['user', 'list', param?]
14
- * - `keys.user.custom('accountStatus', id)` => ['user', 'accountStatus', id]
15
- *
16
- * For list filters that need multiple discriminators, use `custom`:
17
- * keys.feedback.custom('list', filter, sortBy)
18
- */
19
1
  type SerializedKeyPart = string | number | boolean | null | undefined;
20
2
  export type QueryKey = ReadonlyArray<string | number | boolean | null>;
21
3
  export declare const keys: {
@@ -81,10 +63,6 @@ export declare const keys: {
81
63
  };
82
64
  readonly custom: (...parts: SerializedKeyPart[]) => QueryKey;
83
65
  };
84
- /**
85
- * Utility for apps that want to define their own scoped key sets
86
- * while following the same conventions.
87
- */
88
66
  export declare function createKeyScope(scope: string): {
89
67
  readonly all: QueryKey;
90
68
  readonly detail: (id: string) => QueryKey;
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;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BAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;;;8BAIzB,MAAM;gCACJ,iBAAiB;oCACb,iBAAiB,EAAE;;gCAErB,iBAAiB,EAAE;CAC9B,CAAC;AAEX,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM;;0BAG3B,MAAM;4BACJ,iBAAiB;gCACb,iBAAiB,EAAE;EAEzC"}
package/dist/keys.js CHANGED
@@ -65,10 +65,6 @@ export const keys = {
65
65
  },
66
66
  custom: (...parts) => withScope('custom', ...parts),
67
67
  };
68
- /**
69
- * Utility for apps that want to define their own scoped key sets
70
- * while following the same conventions.
71
- */
72
68
  export function createKeyScope(scope) {
73
69
  return {
74
70
  all: withScope(scope),
package/dist/keys.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAsBA,SAAS,SAAS,CAAC,KAAa,EAAE,GAAG,KAA0B;IAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAA8C,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjG,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAU,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,E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;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC;QACrB,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC;QACtD,IAAI,EAAE,CAAC,KAAyB,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;QACpE,MAAM,EAAE,CAAC,GAAG,KAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC;KAC7D,CAAC;AACb,CAAC","sourcesContent":["/**\n * Lightweight, stable, Firestore-safe query key helpers.\n *\n * All keys are arrays of `string | number | boolean | null` so they can\n * be written into Firestore docs (used by the unified upload pipeline's\n * `result.invalidate` field) and read back by the frontend hook to call\n * `queryClient.invalidateQueries`. Both sides produce structurally\n * identical arrays.\n *\n * Convention:\n * - `keys.user.all` => ['user']\n * - `keys.user.detail(id)` => ['user', 'detail', id]\n * - `keys.user.list(param?)` => ['user', 'list', param?]\n * - `keys.user.custom('accountStatus', id)` => ['user', 'accountStatus', id]\n *\n * For list filters that need multiple discriminators, use `custom`:\n * keys.feedback.custom('list', filter, sortBy)\n */\ntype SerializedKeyPart = string | number | boolean | null | undefined;\n\nexport type QueryKey = ReadonlyArray<string | number | boolean | null>;\n\nfunction withScope(scope: string, ...parts: SerializedKeyPart[]): QueryKey {\n const cleaned = parts.filter((p): p is Exclude<SerializedKeyPart, undefined> => p !== undefined);\n return [scope, ...cleaned] as const;\n}\n\nexport const keys = {\n user: {\n all: withScope('user'),\n detail: (id: string) => withScope('user', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('user', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('user', ...parts),\n },\n follows: {\n all: withScope('follows'),\n detail: (id: string) => withScope('follows', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('follows', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('follows', ...parts),\n },\n entities: {\n all: withScope('entities'),\n detail: (id: string) => withScope('entities', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('entities', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('entities', ...parts),\n },\n messages: {\n all: withScope('messages'),\n detail: (id: string) => withScope('messages', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('messages', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('messages', ...parts),\n },\n admin: {\n all: withScope('admin'),\n detail: (id: string) => withScope('admin', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('admin', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('admin', ...parts),\n },\n chat: {\n all: withScope('chat'),\n detail: (id: string) => withScope('chat', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('chat', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('chat', ...parts),\n },\n notifications: {\n all: withScope('notifications'),\n detail: (id: string) => withScope('notifications', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('notifications', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('notifications', ...parts),\n },\n shortLinks: {\n all: withScope('shortLinks'),\n detail: (id: string) => withScope('shortLinks', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('shortLinks', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('shortLinks', ...parts),\n },\n mentions: {\n all: withScope('mentions'),\n detail: (id: string) => withScope('mentions', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('mentions', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('mentions', ...parts),\n },\n feedback: {\n all: withScope('feedback'),\n detail: (id: string) => withScope('feedback', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('feedback', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('feedback', ...parts),\n },\n custom: (...parts: SerializedKeyPart[]) => withScope('custom', ...parts),\n} as const;\n\n/**\n * Utility for apps that want to define their own scoped key sets\n * while following the same conventions.\n */\nexport function createKeyScope(scope: string) {\n return {\n all: withScope(scope),\n detail: (id: string) => withScope(scope, 'detail', id),\n list: (param?: SerializedKeyPart) => withScope(scope, 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope(scope, ...parts),\n } as const;\n}\n"]}
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAIA,SAAS,SAAS,CAAC,KAAa,EAAE,GAAG,KAA0B;IAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAA8C,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACjG,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAU,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,EAAE;QACJ,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC;QACtB,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC;QACvD,IAAI,EAAE,CAAC,KAAyB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;QACrE,MAAM,EAAE,CAAC,GAAG,KAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC;KACvE;IACD,OAAO,EAAE;QACP,GAAG,EAAE,SAAS,CAAC,SAAS,CAAC;QACzB,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC1D,IAAI,EAAE,CAAC,KAAyB,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC;QACxE,MAAM,EAAE,CAAC,GAAG,KAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,KAAK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AAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC;KAC3E;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC;QAC1B,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC3D,IAAI,EAAE,CAAC,KAAyB,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC;QACzE,MAAM,EAAE,CAAC,GAAG,KAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC;KAC3E;IACD,MAAM,EAAE,CAAC,GAAG,KAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC;CAChE,CAAC;AAEX,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC;QACrB,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC;QACtD,IAAI,EAAE,CAAC,KAAyB,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;QACpE,MAAM,EAAE,CAAC,GAAG,KAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC;KAC7D,CAAC;AACb,CAAC","sourcesContent":["type SerializedKeyPart = string | number | boolean | null | undefined;\n\nexport type QueryKey = ReadonlyArray<string | number | boolean | null>;\n\nfunction withScope(scope: string, ...parts: SerializedKeyPart[]): QueryKey {\n const cleaned = parts.filter((p): p is Exclude<SerializedKeyPart, undefined> => p !== undefined);\n return [scope, ...cleaned] as const;\n}\n\nexport const keys = {\n user: {\n all: withScope('user'),\n detail: (id: string) => withScope('user', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('user', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('user', ...parts),\n },\n follows: {\n all: withScope('follows'),\n detail: (id: string) => withScope('follows', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('follows', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('follows', ...parts),\n },\n entities: {\n all: withScope('entities'),\n detail: (id: string) => withScope('entities', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('entities', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('entities', ...parts),\n },\n messages: {\n all: withScope('messages'),\n detail: (id: string) => withScope('messages', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('messages', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('messages', ...parts),\n },\n admin: {\n all: withScope('admin'),\n detail: (id: string) => withScope('admin', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('admin', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('admin', ...parts),\n },\n chat: {\n all: withScope('chat'),\n detail: (id: string) => withScope('chat', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('chat', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('chat', ...parts),\n },\n notifications: {\n all: withScope('notifications'),\n detail: (id: string) => withScope('notifications', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('notifications', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('notifications', ...parts),\n },\n shortLinks: {\n all: withScope('shortLinks'),\n detail: (id: string) => withScope('shortLinks', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('shortLinks', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('shortLinks', ...parts),\n },\n mentions: {\n all: withScope('mentions'),\n detail: (id: string) => withScope('mentions', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('mentions', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('mentions', ...parts),\n },\n feedback: {\n all: withScope('feedback'),\n detail: (id: string) => withScope('feedback', 'detail', id),\n list: (param?: SerializedKeyPart) => withScope('feedback', 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope('feedback', ...parts),\n },\n custom: (...parts: SerializedKeyPart[]) => withScope('custom', ...parts),\n} as const;\n\nexport function createKeyScope(scope: string) {\n return {\n all: withScope(scope),\n detail: (id: string) => withScope(scope, 'detail', id),\n list: (param?: SerializedKeyPart) => withScope(scope, 'list', param),\n custom: (...parts: SerializedKeyPart[]) => withScope(scope, ...parts),\n } as const;\n}\n"]}
@@ -1,48 +1,16 @@
1
1
  import type { InfiniteData, QueryClient, QueryKey } from '@tanstack/react-query';
2
- /** Invalidate everything that matches a key prefix. */
3
2
  export declare function invalidateByPrefix(client: QueryClient, prefix: QueryKey): Promise<void>;
4
- /** Remove everything that matches a key prefix (drops cached data). */
5
3
  export declare function removeByPrefix(client: QueryClient, prefix: QueryKey): void;
6
- /**
7
- * Generic cache update helper.
8
- * Useful for optimistic updates without baking in business logic.
9
- */
10
4
  export declare function updateQueryData<T>(client: QueryClient, key: QueryKey, updater: (prev: T | undefined) => T): void;
11
- /** The cache key of page `page` of a `useFirestorePaginated` list keyed `queryKey`. */
12
5
  export declare function paginatedPageKey(queryKey: QueryKey, page: number): QueryKey;
13
- /**
14
- * Patch rows in place across every cached page of a `useFirestorePaginated` list
15
- * (`queryKey` is the base key the hook was given). Return the same row to leave it
16
- * unchanged; a page with no changed row keeps its identity. Cursors and has-more are
17
- * untouched, so paging stays aligned with the server.
18
- */
19
6
  export declare function mapPaginatedItems<T>(client: QueryClient, queryKey: QueryKey, mapItem: (item: T) => T): void;
20
- /**
21
- * Put a just-created row at the top of page 1 of a `useFirestorePaginated` list, only
22
- * when page 1 is cached. Use it only for a list ordered newest-first. Page 1 keeps its
23
- * cursor, so it shows one extra row and page 2 keeps its place until page 1 is next read;
24
- * that read moves page 1's cursor, and the hook then re-reads page 2 from the new cursor
25
- * before showing it.
26
- */
27
7
  export declare function prependToFirstPaginatedPage<T>(client: QueryClient, queryKey: QueryKey, item: T): void;
28
- /** How `placeRowInPages` reads and writes one infinite list's pages. */
29
8
  export interface PagedRows<P, T> {
30
9
  rowsOf: (page: P) => readonly T[];
31
10
  withRows: (page: P, rows: T[]) => P;
32
- /** True when `candidate` is the row being placed (its id). */
33
11
  isRow: (candidate: T) => boolean;
34
- /** True when `a` comes before `b` in the list's own order. */
35
12
  sortsBefore: (a: T, b: T) => boolean;
36
- /** True when this page is not the last one the source holds (a next page exists). */
37
13
  hasMoreAfter: (page: P) => boolean;
38
14
  }
39
- /**
40
- * Place, move, or drop ONE row in a cached infinite list's loaded pages, in place: the row leaves
41
- * wherever it sits and, when `belongs`, joins at its position in the list's own order. A row that
42
- * sorts after every loaded row is added only when no further page exists; otherwise the next page
43
- * read returns it, so placing it here would list it twice. Every other row, every page, and every
44
- * cursor stays put; a list the row neither left nor joined is returned as it was. Never a reset to the
45
- * first page.
46
- */
47
15
  export declare function placeRowInPages<P, T, TParam = unknown>(data: InfiniteData<P, TParam> | undefined, row: T, belongs: boolean, how: PagedRows<P, T>): InfiniteData<P, TParam> | undefined;
48
16
  //# sourceMappingURL=cache-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache-helpers.d.ts","sourceRoot":"","sources":["../../src/react/cache-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjF,uDAAuD;AACvD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,iBAE7E;AAED,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,QAEnE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,QAGpC;AAED,u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C,KAAK,OAAO,CAAC;CACpC;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,EACpD,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,SAAS,EACzC,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,SAAS,CA2BrC"}
@@ -1,19 +1,12 @@
1
- /** Invalidate everything that matches a key prefix. */
2
1
  export async function invalidateByPrefix(client, prefix) {
3
2
  return client.invalidateQueries({ queryKey: prefix, exact: false });
4
3
  }
5
- /** Remove everything that matches a key prefix (drops cached data). */
6
4
  export function removeByPrefix(client, prefix) {
7
5
  return client.removeQueries({ queryKey: prefix, exact: false });
8
6
  }
9
- /**
10
- * Generic cache update helper.
11
- * Useful for optimistic updates without baking in business logic.
12
- */
13
7
  export function updateQueryData(client, key, updater) {
14
8
  client.setQueryData(key, (prev) => updater(prev));
15
9
  }
16
- /** The cache key of page `page` of a `useFirestorePaginated` list keyed `queryKey`. */
17
10
  export function paginatedPageKey(queryKey, page) {
18
11
  return [...queryKey, 'page', page];
19
12
  }
@@ -26,12 +19,6 @@ function isPaginatedPage(value) {
26
19
  function isPageKey(baseKey, key) {
27
20
  return key.length === baseKey.length + 2 && key[baseKey.length] === 'page';
28
21
  }
29
- /**
30
- * Patch rows in place across every cached page of a `useFirestorePaginated` list
31
- * (`queryKey` is the base key the hook was given). Return the same row to leave it
32
- * unchanged; a page with no changed row keeps its identity. Cursors and has-more are
33
- * untouched, so paging stays aligned with the server.
34
- */
35
22
  export function mapPaginatedItems(client, queryKey, mapItem) {
36
23
  for (const [key, value] of client.getQueriesData({ queryKey })) {
37
24
  if (!isPageKey(queryKey, key) || !isPaginatedPage(value))
@@ -47,13 +34,6 @@ export function mapPaginatedItems(client, queryKey, mapItem) {
47
34
  client.setQueryData(key, { ...value, items });
48
35
  }
49
36
  }
50
- /**
51
- * Put a just-created row at the top of page 1 of a `useFirestorePaginated` list, only
52
- * when page 1 is cached. Use it only for a list ordered newest-first. Page 1 keeps its
53
- * cursor, so it shows one extra row and page 2 keeps its place until page 1 is next read;
54
- * that read moves page 1's cursor, and the hook then re-reads page 2 from the new cursor
55
- * before showing it.
56
- */
57
37
  export function prependToFirstPaginatedPage(client, queryKey, item) {
58
38
  const key = paginatedPageKey(queryKey, 1);
59
39
  const value = client.getQueryData(key);
@@ -61,14 +41,6 @@ export function prependToFirstPaginatedPage(client, queryKey, item) {
61
41
  return;
62
42
  client.setQueryData(key, { ...value, items: [item, ...value.items] });
63
43
  }
64
- /**
65
- * Place, move, or drop ONE row in a cached infinite list's loaded pages, in place: the row leaves
66
- * wherever it sits and, when `belongs`, joins at its position in the list's own order. A row that
67
- * sorts after every loaded row is added only when no further page exists; otherwise the next page
68
- * read returns it, so placing it here would list it twice. Every other row, every page, and every
69
- * cursor stays put; a list the row neither left nor joined is returned as it was. Never a reset to the
70
- * first page.
71
- */
72
44
  export function placeRowInPages(data, row, belongs, how) {
73
45
  if (!data || data.pages.length === 0)
74
46
  return data;
@@ -1 +1 @@
1
- {"version":3,"file":"cache-helpers.js","sourceRoot":"","sources":["../../src/react/cache-helpers.ts"],"names":[],"mappings":"AAGA,uDAAuD;AACvD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAmB,EAAE,MAAgB;IAC5E,OAAO,MAAM,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,cAAc,CAAC,MAAmB,EAAE,MAAgB;IAClE,OAAO,MAAM,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MA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C5D,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;YACjF,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;gBAC/B,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM;YACR,CAAC;QACH,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,GAAG,OAAO,IAAI,MAAM,CAAC;IAC9B,CAAC;IACD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtF,CAAC","sourcesContent":["import type { InfiniteData, QueryClient, QueryKey } from '@tanstack/react-query';\nimport type { PaginatedPage } from './firestore/types.js';\n\n/** Invalidate everything that matches a key prefix. */\nexport async function invalidateByPrefix(client: QueryClient, prefix: QueryKey) {\n return client.invalidateQueries({ queryKey: prefix, exact: false });\n}\n\n/** Remove everything that matches a key prefix (drops cached data). */\nexport function removeByPrefix(client: QueryClient, prefix: QueryKey) {\n return client.removeQueries({ queryKey: prefix, exact: false });\n}\n\n/**\n * Generic cache update helper.\n * Useful for optimistic updates without baking in business logic.\n */\nexport function updateQueryData<T>(\n client: QueryClient,\n key: QueryKey,\n updater: (prev: T | undefined) => T,\n) {\n client.setQueryData<T>(key, (prev) => updater(prev));\n}\n\n/** The cache key of page `page` of a `useFirestorePaginated` list keyed `queryKey`. */\nexport function paginatedPageKey(queryKey: QueryKey, page: number): QueryKey {\n return [...queryKey, 'page', page];\n}\n\nfunction isPaginatedPage(value: unknown): value is PaginatedPage<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n Array.isArray((value as { items?: unknown }).items) &&\n typeof (value as { hasMore?: unknown }).hasMore === 'boolean'\n );\n}\n\nfunction isPageKey(baseKey: QueryKey, key: QueryKey): boolean {\n return key.length === baseKey.length + 2 && key[baseKey.length] === 'page';\n}\n\n/**\n * Patch rows in place across every cached page of a `useFirestorePaginated` list\n * (`queryKey` is the base key the hook was given). Return the same row to leave it\n * unchanged; a page with no changed row keeps its identity. Cursors and has-more are\n * untouched, so paging stays aligned with the server.\n */\nexport function mapPaginatedItems<T>(\n client: QueryClient,\n queryKey: QueryKey,\n mapItem: (item: T) => T,\n): void {\n for (const [key, value] of client.getQueriesData<PaginatedPage<T>>({ queryKey })) {\n if (!isPageKey(queryKey, key) || !isPaginatedPage(value)) continue;\n let changed = false;\n const items = value.items.map((item) => {\n const next = mapItem(item as T);\n if (next !== item) changed = true;\n return next;\n });\n if (changed) client.setQueryData<PaginatedPage<T>>(key, { ...value, items });\n }\n}\n\n/**\n * Put a just-created row at the top of page 1 of a `useFirestorePaginated` list, only\n * when page 1 is cached. Use it only for a list ordered newest-first. Page 1 keeps its\n * cursor, so it shows one extra row and page 2 keeps its place until page 1 is next read;\n * that read moves page 1's cursor, and the hook then re-reads page 2 from the new cursor\n * before showing it.\n */\nexport function prependToFirstPaginatedPage<T>(\n client: QueryClient,\n queryKey: QueryKey,\n item: T,\n): void {\n const key = paginatedPageKey(queryKey, 1);\n const value = client.getQueryData<PaginatedPage<T>>(key);\n if (!isPaginatedPage(value)) return;\n client.setQueryData<PaginatedPage<T>>(key, { ...value, items: [item, ...value.items] });\n}\n\n/** How `placeRowInPages` reads and writes one infinite list's pages. */\nexport interface PagedRows<P, T> {\n rowsOf: (page: P) => readonly T[];\n withRows: (page: P, rows: T[]) => P;\n /** True when `candidate` is the row being placed (its id). */\n isRow: (candidate: T) => boolean;\n /** True when `a` comes before `b` in the list's own order. */\n sortsBefore: (a: T, b: T) => boolean;\n /** True when this page is not the last one the source holds (a next page exists). */\n hasMoreAfter: (page: P) => boolean;\n}\n\n/**\n * Place, move, or drop ONE row in a cached infinite list's loaded pages, in place: the row leaves\n * wherever it sits and, when `belongs`, joins at its position in the list's own order. A row that\n * sorts after every loaded row is added only when no further page exists; otherwise the next page\n * read returns it, so placing it here would list it twice. Every other row, every page, and every\n * cursor stays put; a list the row neither left nor joined is returned as it was. Never a reset to the\n * first page.\n */\nexport function placeRowInPages<P, T, TParam = unknown>(\n data: InfiniteData<P, TParam> | undefined,\n row: T,\n belongs: boolean,\n how: PagedRows<P, T>,\n): InfiniteData<P, TParam> | undefined {\n if (!data || data.pages.length === 0) return data;\n let changed = false;\n const rows = data.pages.map((page) => {\n const kept = how.rowsOf(page).filter((candidate) => !how.isRow(candidate));\n if (kept.length !== how.rowsOf(page).length) changed = true;\n return kept;\n });\n if (belongs) {\n let placed = false;\n for (const pageRows of rows) {\n const index = pageRows.findIndex((candidate) => how.sortsBefore(row, candidate));\n if (index !== -1) {\n pageRows.splice(index, 0, row);\n placed = true;\n break;\n }\n }\n const lastIndex = data.pages.length - 1;\n if (!placed && !how.hasMoreAfter(data.pages[lastIndex])) {\n rows[lastIndex].push(row);\n placed = true;\n }\n changed = changed || placed;\n }\n if (!changed) return data;\n return { ...data, pages: data.pages.map((page, i) => how.withRows(page, rows[i])) };\n}\n"]}
1
+ {"version":3,"file":"cache-helpers.js","sourceRoot":"","sources":["../../src/react/cache-helpers.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAmB,EAAE,MAAgB;IAC5E,OAAO,MAAM,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAmB,EAAE,MAAgB;IAClE,OAAO,MAAM,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,MAAmB,EACnB,GAAa,EACb,OAAmC;IAEnC,MAAM,CAAC,YAAY,CAAI,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAkB,EAAE,IAAY;IAC/D,OAAO,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,CAAC,OAAO,CAAE,KAA6B,CAAC,KAAK,CAAC;QACnD,OAAQ,KAA+B,CAAC,OAAO,KAAK,SAAS,CAC9D,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,OAAiB,EAAE,GAAa;IACjD,OAAO,GAAG,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,MAAM,CAAC;AAC7E,CAAC;AAED,MAAM,U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QACD,OAAO,GAAG,OAAO,IAAI,MAAM,CAAC;IAC9B,CAAC;IACD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtF,CAAC","sourcesContent":["import type { InfiniteData, QueryClient, QueryKey } from '@tanstack/react-query';\nimport type { PaginatedPage } from './firestore/types.js';\n\nexport async function invalidateByPrefix(client: QueryClient, prefix: QueryKey) {\n return client.invalidateQueries({ queryKey: prefix, exact: false });\n}\n\nexport function removeByPrefix(client: QueryClient, prefix: QueryKey) {\n return client.removeQueries({ queryKey: prefix, exact: false });\n}\n\nexport function updateQueryData<T>(\n client: QueryClient,\n key: QueryKey,\n updater: (prev: T | undefined) => T,\n) {\n client.setQueryData<T>(key, (prev) => updater(prev));\n}\n\nexport function paginatedPageKey(queryKey: QueryKey, page: number): QueryKey {\n return [...queryKey, 'page', page];\n}\n\nfunction isPaginatedPage(value: unknown): value is PaginatedPage<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n Array.isArray((value as { items?: unknown }).items) &&\n typeof (value as { hasMore?: unknown }).hasMore === 'boolean'\n );\n}\n\nfunction isPageKey(baseKey: QueryKey, key: QueryKey): boolean {\n return key.length === baseKey.length + 2 && key[baseKey.length] === 'page';\n}\n\nexport function mapPaginatedItems<T>(\n client: QueryClient,\n queryKey: QueryKey,\n mapItem: (item: T) => T,\n): void {\n for (const [key, value] of client.getQueriesData<PaginatedPage<T>>({ queryKey })) {\n if (!isPageKey(queryKey, key) || !isPaginatedPage(value)) continue;\n let changed = false;\n const items = value.items.map((item) => {\n const next = mapItem(item as T);\n if (next !== item) changed = true;\n return next;\n });\n if (changed) client.setQueryData<PaginatedPage<T>>(key, { ...value, items });\n }\n}\n\nexport function prependToFirstPaginatedPage<T>(\n client: QueryClient,\n queryKey: QueryKey,\n item: T,\n): void {\n const key = paginatedPageKey(queryKey, 1);\n const value = client.getQueryData<PaginatedPage<T>>(key);\n if (!isPaginatedPage(value)) return;\n client.setQueryData<PaginatedPage<T>>(key, { ...value, items: [item, ...value.items] });\n}\n\nexport interface PagedRows<P, T> {\n rowsOf: (page: P) => readonly T[];\n withRows: (page: P, rows: T[]) => P;\n isRow: (candidate: T) => boolean;\n sortsBefore: (a: T, b: T) => boolean;\n hasMoreAfter: (page: P) => boolean;\n}\n\nexport function placeRowInPages<P, T, TParam = unknown>(\n data: InfiniteData<P, TParam> | undefined,\n row: T,\n belongs: boolean,\n how: PagedRows<P, T>,\n): InfiniteData<P, TParam> | undefined {\n if (!data || data.pages.length === 0) return data;\n let changed = false;\n const rows = data.pages.map((page) => {\n const kept = how.rowsOf(page).filter((candidate) => !how.isRow(candidate));\n if (kept.length !== how.rowsOf(page).length) changed = true;\n return kept;\n });\n if (belongs) {\n let placed = false;\n for (const pageRows of rows) {\n const index = pageRows.findIndex((candidate) => how.sortsBefore(row, candidate));\n if (index !== -1) {\n pageRows.splice(index, 0, row);\n placed = true;\n break;\n }\n }\n const lastIndex = data.pages.length - 1;\n if (!placed && !how.hasMoreAfter(data.pages[lastIndex])) {\n rows[lastIndex].push(row);\n placed = true;\n }\n changed = changed || placed;\n }\n if (!changed) return data;\n return { ...data, pages: data.pages.map((page, i) => how.withRows(page, rows[i])) };\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import type { UseMutationResult } from '@tanstack/react-query';
2
+ import type { ExpectedCallableAnswerCode } from '@ttt-productions/firebase-helpers';
3
+ import { type FunctionsProvider } from '@ttt-productions/firebase-helpers/client';
4
+ import { type SessionMutationOptions } from '../session-mutation.js';
5
+ export interface CallableErrorRouting {
6
+ showErrorToast: boolean;
7
+ answeredRefusals: readonly ExpectedCallableAnswerCode[];
8
+ isAnswerSurfacedByCaller?: (error: unknown) => boolean;
9
+ }
10
+ export type CallableCaptureContext = Record<string, unknown>;
11
+ export interface CallablePolicy {
12
+ getFunctions: FunctionsProvider;
13
+ timeoutMs: number;
14
+ resolveLimitedUseAppCheck: (requested: boolean) => boolean;
15
+ captureFault: (error: unknown, context: CallableCaptureContext) => void;
16
+ captureRecoveredFallback: (error: unknown, context: CallableCaptureContext) => void;
17
+ onActionError: (error: unknown, routing: CallableErrorRouting) => void;
18
+ }
19
+ export interface CallableDeclaration {
20
+ limitedUseAppCheck?: true;
21
+ }
22
+ interface CallableTransportOptions extends Partial<CallableErrorRouting> {
23
+ captureFaults?: boolean;
24
+ }
25
+ export type CallableMutationOptions<TInput, TResult, TOnMutateResult = unknown> = Omit<SessionMutationOptions<TResult, Error, TInput, TOnMutateResult>, 'mutationFn' | 'retry'> & Pick<CallableTransportOptions, 'showErrorToast' | 'answeredRefusals' | 'isAnswerSurfacedByCaller' | 'captureFaults'>;
26
+ export declare const MAX_RESUMABLE_CALLS = 12;
27
+ export type ResumableOutcome<TResult> = TResult & {
28
+ interruption: Error | null;
29
+ };
30
+ export interface Callables {
31
+ createCallableHook<TInput, TResult>(functionName: string, declaration?: CallableDeclaration): <TOnMutateResult = unknown>(options?: CallableMutationOptions<TInput, TResult, TOnMutateResult>) => UseMutationResult<TResult, Error, TInput, TOnMutateResult>;
32
+ createResumableCallableHook<TInput, TResult extends {
33
+ complete: boolean;
34
+ }>(functionName: string, merge: (earlier: TResult, later: TResult) => TResult, declaration?: CallableDeclaration): <TOnMutateResult = unknown>(options?: CallableMutationOptions<TInput, ResumableOutcome<TResult>, TOnMutateResult>) => UseMutationResult<ResumableOutcome<TResult>, Error, TInput, TOnMutateResult>;
35
+ createCallableReader<TInput, TResult>(functionName: string, declaration?: CallableDeclaration): () => (input: TInput) => Promise<TResult>;
36
+ createCallableInvoker<TInput, TResult>(functionName: string, declaration?: CallableDeclaration): () => (input: TInput) => Promise<TResult>;
37
+ }
38
+ export declare function createCallables(policy: CallablePolicy): Callables;
39
+ export {};
40
+ //# sourceMappingURL=create-callables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-callables.d.ts","sourceRoot":"","sources":["../../../src/react/callables/create-callables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAIL,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,SAAS,0BAA0B,EAAE,CAAC;IACxD,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACxD;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7D,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC;IAC3D,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACxE,wBAAwB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACpF,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACxE;AAED,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,IAAI,CAAC;CAC3B;AAED,UAAU,wBAAyB,SAAQ,OAAO,CAAC,oBAAoB,CAAC;IACtE,aAAa,CAAC,EAAE,OAAO,CAAC;C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M,EACpB,WAAW,CAAC,EAAE,mBAAmB,GAChC,MAAM,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,qBAAqB,CAAC,MAAM,EAAE,OAAO,EACnC,YAAY,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,mBAAmB,GAChC,MAAM,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAOD,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAuJjE"}
@@ -0,0 +1,101 @@
1
+ 'use client';
2
+ import { useCallback, useMemo, useRef } from 'react';
3
+ import { callCallable, isRecoveredFallbackReport, } from '@ttt-productions/firebase-helpers/client';
4
+ import { useMutationSessionCapture, useSessionMutation, } from '../session-mutation.js';
5
+ export const MAX_RESUMABLE_CALLS = 12;
6
+ export function createCallables(policy) {
7
+ function useCallableTransport(functionName, declaration, options) {
8
+ const optionsRef = useRef(options);
9
+ optionsRef.current = options;
10
+ const limitedUseAppCheck = policy.resolveLimitedUseAppCheck(declaration.limitedUseAppCheck === true);
11
+ return useCallback((input, session) => callCallable(policy.getFunctions, functionName, input, {
12
+ captureException: (error, context) => {
13
+ if (optionsRef.current.captureFaults !== false)
14
+ policy.captureFault(error, context);
15
+ else if (isRecoveredFallbackReport(context))
16
+ policy.captureRecoveredFallback(error, context);
17
+ },
18
+ onError: (error) => {
19
+ if (!session.isCurrent())
20
+ return;
21
+ const { showErrorToast = true, answeredRefusals = [], isAnswerSurfacedByCaller, } = optionsRef.current;
22
+ policy.onActionError(error, {
23
+ showErrorToast,
24
+ answeredRefusals,
25
+ isAnswerSurfacedByCaller,
26
+ });
27
+ },
28
+ }, { timeoutMs: policy.timeoutMs, limitedUseAppCheck }), [functionName, limitedUseAppCheck]);
29
+ }
30
+ function useSessionBoundCall(call) {
31
+ const captureSession = useMutationSessionCapture();
32
+ return useMemo(() => (input) => call(input, captureSession()), [call, captureSession]);
33
+ }
34
+ return {
35
+ createCallableHook(functionName, declaration = {}) {
36
+ return function useNamedCallable(options = {}) {
37
+ const { showErrorToast, answeredRefusals, isAnswerSurfacedByCaller, captureFaults, ...mutationOptions } = options;
38
+ const call = useCallableTransport(functionName, declaration, {
39
+ showErrorToast,
40
+ answeredRefusals,
41
+ isAnswerSurfacedByCaller,
42
+ captureFaults,
43
+ });
44
+ // `retry: false` comes last so nothing overrides it: a deadline expiry is an unknown outcome,
45
+ // and a retry after a committed first attempt writes twice.
46
+ return useSessionMutation({
47
+ ...mutationOptions,
48
+ retry: false,
49
+ mutationFn: (input, { session }) => call(input, session),
50
+ });
51
+ };
52
+ },
53
+ createResumableCallableHook(functionName, merge, declaration = {}) {
54
+ return function useNamedResumableCallable(options = {}) {
55
+ const { showErrorToast, answeredRefusals, isAnswerSurfacedByCaller, captureFaults, ...mutationOptions } = options;
56
+ const call = useCallableTransport(functionName, declaration, {
57
+ showErrorToast,
58
+ answeredRefusals,
59
+ isAnswerSurfacedByCaller,
60
+ captureFaults,
61
+ });
62
+ return useSessionMutation({
63
+ ...mutationOptions,
64
+ retry: false,
65
+ mutationFn: async (input, { session }) => {
66
+ let progress = await call(input, session);
67
+ for (let calls = 1; !progress.complete && calls < MAX_RESUMABLE_CALLS; calls += 1) {
68
+ session.assertCurrent();
69
+ let later;
70
+ try {
71
+ later = await call(input, session);
72
+ }
73
+ catch (error) {
74
+ const interruption = error instanceof Error ? error : new Error(String(error));
75
+ return { ...progress, complete: false, interruption };
76
+ }
77
+ progress = merge(progress, later);
78
+ }
79
+ return { ...progress, interruption: null };
80
+ },
81
+ });
82
+ };
83
+ },
84
+ createCallableReader(functionName, declaration = {}) {
85
+ return function useNamedCallableReader() {
86
+ const call = useCallableTransport(functionName, declaration, {
87
+ showErrorToast: false,
88
+ captureFaults: false,
89
+ });
90
+ return useSessionBoundCall(call);
91
+ };
92
+ },
93
+ createCallableInvoker(functionName, declaration = {}) {
94
+ return function useNamedCallableInvoker() {
95
+ const call = useCallableTransport(functionName, declaration, {});
96
+ return useSessionBoundCall(call);
97
+ };
98
+ },
99
+ };
100
+ }
101
+ //# sourceMappingURL=create-callables.js.map