@frontic/nuxt 0.8.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/dist/module.d.mts +2 -132
- package/dist/module.json +2 -2
- package/dist/module.mjs +63 -7
- package/dist/runtime/composables/analytics.d.ts +82 -0
- package/dist/runtime/composables/analytics.js +38 -0
- package/dist/runtime/composables/blocks.d.ts +24 -22
- package/dist/runtime/composables/blocks.js +16 -16
- package/dist/runtime/composables/index.d.ts +1 -1
- package/dist/runtime/composables/listings.d.ts +22 -13
- package/dist/runtime/composables/listings.js +24 -25
- package/dist/runtime/composables/pages.d.ts +21 -18
- package/dist/runtime/composables/pages.js +15 -16
- package/dist/runtime/composables/trees.d.ts +24 -22
- package/dist/runtime/composables/trees.js +15 -25
- package/dist/runtime/composables/useFronticBlock.d.ts +22 -13
- package/dist/runtime/composables/useFronticBlock.js +19 -2
- package/dist/runtime/composables/useFronticClient.d.ts +6 -3
- package/dist/runtime/composables/useFronticContext.d.ts +12 -0
- package/dist/runtime/composables/useFronticContext.js +71 -9
- package/dist/runtime/composables/useFronticListing.d.ts +23 -19
- package/dist/runtime/composables/useFronticListing.js +22 -3
- package/dist/runtime/composables/useFronticPage.d.ts +35 -16
- package/dist/runtime/composables/useFronticPage.js +36 -7
- package/dist/runtime/composables/useFronticSearch.d.ts +4 -96
- package/dist/runtime/composables/useFronticSearch.js +179 -51
- package/dist/runtime/composables/useFronticTree.d.ts +23 -14
- package/dist/runtime/composables/useFronticTree.js +19 -2
- package/dist/runtime/server/plugins/fetch-secret.d.ts +2 -0
- package/dist/runtime/server/plugins/fetch-secret.js +20 -0
- package/dist/runtime/types/client.d.ts +34 -0
- package/dist/runtime/types/client.js +0 -0
- package/dist/runtime/types/index.d.ts +8 -3
- package/dist/runtime/types/listing.d.ts +113 -251
- package/dist/runtime/types/options.d.ts +139 -0
- package/dist/runtime/types/options.js +0 -0
- package/dist/runtime/types/query.d.ts +88 -0
- package/dist/runtime/types/query.js +0 -0
- package/dist/runtime/types/registry.d.ts +272 -0
- package/dist/runtime/types/registry.js +0 -0
- package/dist/runtime/types/search.d.ts +56 -36
- package/dist/runtime/utils/errors.d.ts +22 -0
- package/dist/runtime/utils/errors.js +3 -0
- package/dist/runtime/utils/index.d.ts +2 -0
- package/dist/runtime/utils/index.js +2 -0
- package/dist/runtime/utils/query-keys.d.ts +27 -0
- package/dist/runtime/utils/query-keys.js +18 -0
- package/dist/runtime/utils/state-helpers.d.ts +3 -6
- package/dist/runtime/utils/state-helpers.js +7 -8
- package/dist/types.d.mts +2 -2
- package/package.json +15 -15
- package/dist/runtime/frontic-stack.d.ts +0 -168
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frontic Query Types
|
|
3
|
+
*
|
|
4
|
+
* Module-owned mirror of the generated client's query surface
|
|
5
|
+
* (`.frontic/query-types.ts`): same shapes, typed against the registry so the
|
|
6
|
+
* composables and query factories accept exactly what the client accepts.
|
|
7
|
+
*/
|
|
8
|
+
/** Field keys of `T` whose values are numeric (range-filterable) */
|
|
9
|
+
type NumericKeys<T> = {
|
|
10
|
+
[K in keyof T]: T[K] extends number ? K : never;
|
|
11
|
+
}[keyof T];
|
|
12
|
+
/** Field keys of `T` whose values are string literal unions (enums) */
|
|
13
|
+
type EnumKeys<T> = {
|
|
14
|
+
[K in keyof T]: T[K] extends string ? (string extends T[K] ? never : K) : never;
|
|
15
|
+
}[keyof T];
|
|
16
|
+
/** Field keys of `T` whose values are plain strings (word-match filterable) */
|
|
17
|
+
type StringKeys<T> = {
|
|
18
|
+
[K in keyof T]: T[K] extends string ? K : never;
|
|
19
|
+
}[keyof T] & Exclude<keyof T, EnumKeys<T>>;
|
|
20
|
+
/**
|
|
21
|
+
* Filter a field by equality. Use an array of values to filter by multiple values.
|
|
22
|
+
*/
|
|
23
|
+
export type EqualsFilter<T = Record<string, unknown>> = {
|
|
24
|
+
[K in keyof T]: {
|
|
25
|
+
type: 'equals';
|
|
26
|
+
field: K;
|
|
27
|
+
value: T[K] | T[K][];
|
|
28
|
+
};
|
|
29
|
+
}[keyof T];
|
|
30
|
+
type RangeFilterShapes<K> = {
|
|
31
|
+
from: K;
|
|
32
|
+
} | {
|
|
33
|
+
to: K;
|
|
34
|
+
} | {
|
|
35
|
+
from: K;
|
|
36
|
+
to: K;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Filter a numeric field by a range. Use either `from`, `to` or both.
|
|
40
|
+
*/
|
|
41
|
+
export type RangeFilter<T = Record<string, unknown>> = {
|
|
42
|
+
[K in NumericKeys<T>]: {
|
|
43
|
+
type: 'range';
|
|
44
|
+
field: K;
|
|
45
|
+
} & RangeFilterShapes<T[K]>;
|
|
46
|
+
}[NumericKeys<T>];
|
|
47
|
+
/**
|
|
48
|
+
* Filter a string field by a word match (e.g. 'Dress' matches 'Yellow Dress').
|
|
49
|
+
*/
|
|
50
|
+
export type ContainsFilter<T = Record<string, unknown>> = {
|
|
51
|
+
[K in StringKeys<T>]: {
|
|
52
|
+
type: 'contains';
|
|
53
|
+
field: K;
|
|
54
|
+
value: string;
|
|
55
|
+
};
|
|
56
|
+
}[StringKeys<T>];
|
|
57
|
+
/**
|
|
58
|
+
* Combine multiple filters with a logical operator.
|
|
59
|
+
*/
|
|
60
|
+
export interface LogicalFilter<T = Record<string, unknown>> {
|
|
61
|
+
type: 'and' | 'or' | 'not';
|
|
62
|
+
filter: Filter<T>[];
|
|
63
|
+
}
|
|
64
|
+
export type Filter<T = Record<string, unknown>> = EqualsFilter<T> | RangeFilter<T> | ContainsFilter<T> | LogicalFilter<T>;
|
|
65
|
+
export type SortField<T = Record<string, unknown>> = keyof T;
|
|
66
|
+
/**
|
|
67
|
+
* Sort results by a field and ordering direction.
|
|
68
|
+
*/
|
|
69
|
+
export interface Sort<T = Record<string, unknown>> {
|
|
70
|
+
field: SortField<T>;
|
|
71
|
+
order: 'asc' | 'desc';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Query options for listing requests — filters, sorting, search and pagination.
|
|
75
|
+
*/
|
|
76
|
+
export interface Query<TFilter = Record<string, unknown>, TSort = Record<string, unknown>> {
|
|
77
|
+
/** Filter results by a set of conditions */
|
|
78
|
+
filter?: Filter<TFilter>[];
|
|
79
|
+
/** Search fields that are marked as searchable */
|
|
80
|
+
search?: string;
|
|
81
|
+
/** Sort by a single sort object, an array of sort objects, or a bare field name */
|
|
82
|
+
sort?: Sort<TSort> | Sort<TSort>[] | SortField<TSort>;
|
|
83
|
+
/** Limit the number of results returned */
|
|
84
|
+
limit?: number;
|
|
85
|
+
/** Paginate results */
|
|
86
|
+
page?: number;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frontic Type Registry
|
|
3
|
+
*
|
|
4
|
+
* The module declares these global interfaces empty; the generated client
|
|
5
|
+
* (`npx @frontic/cli generate`, schemaVersion >= 2) augments them with the
|
|
6
|
+
* project's blocks, listings and trees via `declare global`. Interface merging
|
|
7
|
+
* makes the generated members visible to every composable without the module
|
|
8
|
+
* ever importing types from generated files.
|
|
9
|
+
*
|
|
10
|
+
* Without a generated client the interfaces stay empty, so every name union
|
|
11
|
+
* (`keyof FronticBlocks`, ...) is `never` and composable calls fail loudly at
|
|
12
|
+
* compile time instead of degrading to `any`.
|
|
13
|
+
*/
|
|
14
|
+
declare global {
|
|
15
|
+
/** Block name -> `never` (names only; responses live in {@link FronticResponses}) */
|
|
16
|
+
interface FronticBlocks {
|
|
17
|
+
}
|
|
18
|
+
/** Listing name -> parameters type */
|
|
19
|
+
interface FronticListings {
|
|
20
|
+
}
|
|
21
|
+
/** Listing name -> parameters type */
|
|
22
|
+
interface FronticListingParameters {
|
|
23
|
+
}
|
|
24
|
+
/** Listing name -> filterable fields map (field -> value type) */
|
|
25
|
+
interface FronticListingQueryFilters {
|
|
26
|
+
}
|
|
27
|
+
/** Listing name -> sortable fields map (field -> value type) */
|
|
28
|
+
interface FronticListingQuerySorts {
|
|
29
|
+
}
|
|
30
|
+
/** Tree name -> `never` (names only; responses live in {@link FronticResponses}) */
|
|
31
|
+
interface FronticTrees {
|
|
32
|
+
}
|
|
33
|
+
/** Block/listing/tree name -> response type */
|
|
34
|
+
interface FronticResponses {
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The Page feature's type graph: page, pageRoute, routeMeta, alternateRoute
|
|
38
|
+
* (lowerCamel of the component schema names). Every member is optional for
|
|
39
|
+
* the generator: the module falls back to its Default* shapes per member.
|
|
40
|
+
*/
|
|
41
|
+
interface FronticPages {
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The listing response envelope: the `_page`, `_filter` and `_aggregation`
|
|
45
|
+
* shapes every listing response carries, keyed as `pagination`, `filter` and
|
|
46
|
+
* `aggregation`. Every member is optional for the generator: the module
|
|
47
|
+
* falls back to its Default* shapes per member.
|
|
48
|
+
*/
|
|
49
|
+
interface FronticEnvelopes {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The error bodies the Fetch API returns: `apiError` for deliberately raised
|
|
53
|
+
* failures, `internalError` for 500s. Empty until a generation describes
|
|
54
|
+
* them; the module falls back per member.
|
|
55
|
+
*/
|
|
56
|
+
interface FronticErrors {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export type Blocks = FronticBlocks;
|
|
60
|
+
export type Listings = FronticListings;
|
|
61
|
+
export type ListingParameters = FronticListingParameters;
|
|
62
|
+
export type ListingQueryFilters = FronticListingQueryFilters;
|
|
63
|
+
export type ListingQuerySorts = FronticListingQuerySorts;
|
|
64
|
+
export type Trees = FronticTrees;
|
|
65
|
+
export type Responses = FronticResponses;
|
|
66
|
+
/**
|
|
67
|
+
* Stand-in for the name unions while the registry is empty.
|
|
68
|
+
*
|
|
69
|
+
* An empty registry makes every `keyof` union `never`, and TypeScript reports
|
|
70
|
+
* that as "not assignable to parameter of type 'never'" — accurate, and
|
|
71
|
+
* useless to someone who has simply not run the generator yet. Naming the
|
|
72
|
+
* command in the type puts the fix in the error itself, where the reader is.
|
|
73
|
+
*/
|
|
74
|
+
type NotGeneratedHint = 'Run `npx @frontic/cli generate` — no Frontic client types found';
|
|
75
|
+
/**
|
|
76
|
+
* The name union for a registry map, or the hint when nothing is generated.
|
|
77
|
+
* The tuple wrapper stops `never` from short-circuiting the conditional.
|
|
78
|
+
*/
|
|
79
|
+
type NameOf<TMap> = [keyof TMap] extends [never] ? NotGeneratedHint : keyof TMap;
|
|
80
|
+
/** Valid block names — constrains every block-taking API */
|
|
81
|
+
export type BlockName = NameOf<FronticBlocks>;
|
|
82
|
+
/** Valid listing names — constrains every listing-taking API */
|
|
83
|
+
export type ListingName = NameOf<FronticListings>;
|
|
84
|
+
/** Valid tree names — constrains every tree-taking API */
|
|
85
|
+
export type TreeName = NameOf<FronticTrees>;
|
|
86
|
+
/** Response type for a block/listing/tree name, `unknown` when not generated */
|
|
87
|
+
export type ResponseOf<TName> = TName extends keyof FronticResponses ? FronticResponses[TName] : unknown;
|
|
88
|
+
/** Parameters type for a listing name */
|
|
89
|
+
export type ListingParamsOf<TName> = TName extends keyof FronticListingParameters ? FronticListingParameters[TName] : Record<string, unknown>;
|
|
90
|
+
/** Filterable fields map for a listing name */
|
|
91
|
+
export type ListingFiltersOf<TName> = TName extends keyof FronticListingQueryFilters ? FronticListingQueryFilters[TName] : Record<string, unknown>;
|
|
92
|
+
/** Sortable fields map for a listing name */
|
|
93
|
+
export type ListingSortsOf<TName> = TName extends keyof FronticListingQuerySorts ? FronticListingQuerySorts[TName] : Record<string, unknown>;
|
|
94
|
+
/**
|
|
95
|
+
* Per-request options accepted by every client method.
|
|
96
|
+
*
|
|
97
|
+
* `secret` reaches the wire only on generated clients that map it to the
|
|
98
|
+
* `fs-secret` header; older clients ignore it.
|
|
99
|
+
*/
|
|
100
|
+
export interface RequestOptions {
|
|
101
|
+
requestUrl?: string;
|
|
102
|
+
contextKey?: string;
|
|
103
|
+
contextDomain?: string;
|
|
104
|
+
proxyUrl?: string;
|
|
105
|
+
secret?: string;
|
|
106
|
+
}
|
|
107
|
+
/** Query options for tree requests */
|
|
108
|
+
export interface TreeQuery {
|
|
109
|
+
key?: string;
|
|
110
|
+
depth?: number;
|
|
111
|
+
}
|
|
112
|
+
export interface DefaultPageRoute {
|
|
113
|
+
href: string;
|
|
114
|
+
path: string;
|
|
115
|
+
slug: string;
|
|
116
|
+
url: string;
|
|
117
|
+
}
|
|
118
|
+
export interface DefaultAlternateRoute extends DefaultPageRoute {
|
|
119
|
+
locale: string;
|
|
120
|
+
region: string;
|
|
121
|
+
lang?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface DefaultRouteMeta {
|
|
124
|
+
code: 200 | 301 | 404;
|
|
125
|
+
redirect?: PageRoute;
|
|
126
|
+
alternates?: AlternateRoute[];
|
|
127
|
+
context?: {
|
|
128
|
+
region: string;
|
|
129
|
+
locale: string;
|
|
130
|
+
suggested?: AlternateRoute;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export interface DefaultPage {
|
|
134
|
+
id?: string;
|
|
135
|
+
slug?: string;
|
|
136
|
+
title?: string;
|
|
137
|
+
type?: string;
|
|
138
|
+
block?: string;
|
|
139
|
+
meta?: Record<string, unknown>;
|
|
140
|
+
data?: Record<string, unknown>;
|
|
141
|
+
route?: RouteMeta;
|
|
142
|
+
}
|
|
143
|
+
export type Page = FronticPages extends {
|
|
144
|
+
page: infer T;
|
|
145
|
+
} ? T : DefaultPage;
|
|
146
|
+
export type PageRoute = FronticPages extends {
|
|
147
|
+
pageRoute: infer T;
|
|
148
|
+
} ? T : DefaultPageRoute;
|
|
149
|
+
export type RouteMeta = FronticPages extends {
|
|
150
|
+
routeMeta: infer T;
|
|
151
|
+
} ? T : DefaultRouteMeta;
|
|
152
|
+
export type AlternateRoute = FronticPages extends {
|
|
153
|
+
alternateRoute: infer T;
|
|
154
|
+
} ? T : DefaultAlternateRoute;
|
|
155
|
+
/** The `data` payload of a page, distributed over the page union */
|
|
156
|
+
export type PageData = Page extends {
|
|
157
|
+
data?: infer D;
|
|
158
|
+
} ? D : unknown;
|
|
159
|
+
export interface Context {
|
|
160
|
+
region: string;
|
|
161
|
+
locale: string;
|
|
162
|
+
scope: string;
|
|
163
|
+
token: string;
|
|
164
|
+
}
|
|
165
|
+
export interface ContextOption {
|
|
166
|
+
region: string;
|
|
167
|
+
currency: string;
|
|
168
|
+
locales: Array<{
|
|
169
|
+
key: string;
|
|
170
|
+
url: string;
|
|
171
|
+
}>;
|
|
172
|
+
}
|
|
173
|
+
/** Pagination block of a listing response (`_page`) */
|
|
174
|
+
export interface DefaultPagination {
|
|
175
|
+
/** Items per page */
|
|
176
|
+
limit: number;
|
|
177
|
+
/** Current page number */
|
|
178
|
+
current: number;
|
|
179
|
+
/** Next page number */
|
|
180
|
+
next: number;
|
|
181
|
+
/** Previous page number */
|
|
182
|
+
prev: number;
|
|
183
|
+
/** Last page number */
|
|
184
|
+
last: number;
|
|
185
|
+
}
|
|
186
|
+
/** One facet option within a filter group (`_filter[field][n]`) */
|
|
187
|
+
export interface DefaultFilterOption {
|
|
188
|
+
/** The facet option name */
|
|
189
|
+
option: string;
|
|
190
|
+
/** The facet option value */
|
|
191
|
+
value: string;
|
|
192
|
+
/** Number of items carrying this option */
|
|
193
|
+
count: number;
|
|
194
|
+
/** Whether the option is currently selected */
|
|
195
|
+
selected?: boolean;
|
|
196
|
+
/** Whether the option is currently unavailable */
|
|
197
|
+
disabled?: boolean;
|
|
198
|
+
}
|
|
199
|
+
/** Statistics for one aggregated field */
|
|
200
|
+
export interface DefaultAggregationStats {
|
|
201
|
+
/** Highest value present */
|
|
202
|
+
max?: number;
|
|
203
|
+
/** Lowest value present */
|
|
204
|
+
min?: number;
|
|
205
|
+
/** Mean across items */
|
|
206
|
+
avg?: number;
|
|
207
|
+
/** Sum across items */
|
|
208
|
+
sum?: number;
|
|
209
|
+
/** Number of possible values for this field */
|
|
210
|
+
total: number;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Aggregation for one field, over the whole set (`total`) and over the
|
|
214
|
+
* currently filtered result (`result`).
|
|
215
|
+
*/
|
|
216
|
+
export interface DefaultAggregation {
|
|
217
|
+
total: DefaultAggregationStats;
|
|
218
|
+
result: DefaultAggregationStats;
|
|
219
|
+
}
|
|
220
|
+
/** Pagination block of a listing response */
|
|
221
|
+
export type Pagination = FronticEnvelopes extends {
|
|
222
|
+
pagination: infer T;
|
|
223
|
+
} ? T : DefaultPagination;
|
|
224
|
+
/** Filter facets of a listing response, keyed by field */
|
|
225
|
+
export type FilterData = FronticEnvelopes extends {
|
|
226
|
+
filter: infer T;
|
|
227
|
+
} ? T : Record<string, DefaultFilterOption[]>;
|
|
228
|
+
/** Aggregations of a listing response, keyed by field */
|
|
229
|
+
export type AggregationData = FronticEnvelopes extends {
|
|
230
|
+
aggregation: infer T;
|
|
231
|
+
} ? T : Record<string, DefaultAggregation>;
|
|
232
|
+
/** Facet options for a single filter field */
|
|
233
|
+
export type FilterGroup = FilterData extends Record<string, infer G> ? G : DefaultFilterOption[];
|
|
234
|
+
/** Aggregation for a single field */
|
|
235
|
+
export type AggregationGroup = AggregationData extends Record<string, infer A> ? A : DefaultAggregation;
|
|
236
|
+
/** Body of a deliberately raised failure (301/307/401/404/405/422) */
|
|
237
|
+
export interface DefaultApiError {
|
|
238
|
+
error: string;
|
|
239
|
+
code: string;
|
|
240
|
+
/** Untyped by design: the payload has no per-code shape to promise */
|
|
241
|
+
details: unknown;
|
|
242
|
+
correlationId: string;
|
|
243
|
+
}
|
|
244
|
+
/** Body of an unhandled server failure (500) */
|
|
245
|
+
export interface DefaultInternalError {
|
|
246
|
+
error: string;
|
|
247
|
+
correlationId: string;
|
|
248
|
+
}
|
|
249
|
+
/** Error body of a deliberately raised failure */
|
|
250
|
+
export type ApiError = FronticErrors extends {
|
|
251
|
+
apiError: infer T;
|
|
252
|
+
} ? T : DefaultApiError;
|
|
253
|
+
/** Error body of an unhandled server failure */
|
|
254
|
+
export type InternalError = FronticErrors extends {
|
|
255
|
+
internalError: infer T;
|
|
256
|
+
} ? T : DefaultInternalError;
|
|
257
|
+
/**
|
|
258
|
+
* Either error body the Fetch API can return.
|
|
259
|
+
*
|
|
260
|
+
* The matching `FronticFetchError` — the ofetch error carrying one of these on
|
|
261
|
+
* `data` — is declared by the generated client, not here, and cannot move:
|
|
262
|
+
* `ofetch` is a direct dependency of that client and is not declared by this
|
|
263
|
+
* module, so importing `IFetchError` here would be a phantom dependency under
|
|
264
|
+
* strict resolution.
|
|
265
|
+
*
|
|
266
|
+
* The two also disagree on an empty registry, by design. This union falls back
|
|
267
|
+
* to the `Default*` shapes, so `code` stays readable before the API describes
|
|
268
|
+
* its error responses; the generated type widens to `unknown` there, because
|
|
269
|
+
* nothing generated can honestly claim a shape the spec has not stated.
|
|
270
|
+
*/
|
|
271
|
+
export type FronticApiError = ApiError | InternalError;
|
|
272
|
+
export {};
|
|
File without changes
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Ref, ShallowRef } from 'vue';
|
|
8
8
|
import type { UseQueryReturn } from '@pinia/colada';
|
|
9
|
-
import type {
|
|
10
|
-
import type { FronticRequestOptions, ListingFieldConfig, UiFilter, UiSort } from './listing.js';
|
|
11
|
-
|
|
12
|
-
export type {
|
|
9
|
+
import type { ListingName, ListingFiltersOf, ListingSortsOf, ResponseOf } from './registry.js';
|
|
10
|
+
import type { FronticRequestOptions, FronticQueryOptions, ListingFieldConfig, SortStringOf, UiFilter, UiSort } from './listing.js';
|
|
11
|
+
import type { RangeFilterValue } from '../utils/filter-helpers.js';
|
|
12
|
+
export type { FronticRequestOptions, ListingFieldConfig, FilterOption, UiFilter, UiSort, AggregationStats, InclusionMode, SortString, SortStringOf } from './listing.js';
|
|
13
|
+
export type { Listings, ListingQueryFilters, ListingQuerySorts, Responses, ResponseOf } from './registry.js';
|
|
13
14
|
/**
|
|
14
15
|
* Search state exposed to consumers
|
|
15
16
|
* Contains both the current query state and processed data ready for UI consumption
|
|
@@ -65,11 +66,11 @@ export interface SearchState<TFilters = Record<string, unknown>, TSorts = Record
|
|
|
65
66
|
/**
|
|
66
67
|
* Options for the useFronticSearch composable
|
|
67
68
|
*
|
|
68
|
-
* @template TSearch - The listing name key from
|
|
69
|
-
* @template TFilters - Filter fields for this listing (defaults to
|
|
70
|
-
* @template TSorts - Sort fields for this listing (defaults to
|
|
69
|
+
* @template TSearch - The listing name key from the registry
|
|
70
|
+
* @template TFilters - Filter fields for this listing (defaults to the registry's filter map)
|
|
71
|
+
* @template TSorts - Sort fields for this listing (defaults to the registry's sort map)
|
|
71
72
|
*/
|
|
72
|
-
export interface UseFronticSearchOptions<TSearch extends
|
|
73
|
+
export interface UseFronticSearchOptions<TSearch extends ListingName = ListingName, TFilters = ListingFiltersOf<TSearch>, TSorts = ListingSortsOf<TSearch>> extends FronticRequestOptions, FronticQueryOptions {
|
|
73
74
|
/**
|
|
74
75
|
* Cache key for the query (defaults to name)
|
|
75
76
|
*/
|
|
@@ -83,14 +84,27 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
83
84
|
* Controls how long to wait after the user stops typing before triggering a search request.
|
|
84
85
|
*/
|
|
85
86
|
searchDebounce?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Analytics thresholds, deliberately separate from the UX knobs above.
|
|
89
|
+
* The debounce that keeps a listing responsive and the delay that decides a
|
|
90
|
+
* term became intent are different questions and must not share a value:
|
|
91
|
+
* instrumenting off `searchDebounce` records `s`, `sk`, `ski`, `skis` as four
|
|
92
|
+
* searches.
|
|
93
|
+
*/
|
|
94
|
+
analytics?: {
|
|
95
|
+
/** How long a term must rest before it counts as a search (default: 1000) */
|
|
96
|
+
searchCommitMs?: number;
|
|
97
|
+
/** Shortest term worth recording (default: 3) */
|
|
98
|
+
searchMinChars?: number;
|
|
99
|
+
};
|
|
86
100
|
/**
|
|
87
101
|
* Filter fields that should use OR logic (all others use AND)
|
|
88
102
|
* Type-safe: only allows valid filter field names for this listing
|
|
89
103
|
*/
|
|
90
|
-
orFilter?: Array<keyof TFilters & string
|
|
104
|
+
orFilter?: Array<NoInfer<keyof TFilters & string>>;
|
|
91
105
|
/**
|
|
92
106
|
* Filter configuration using unified structure
|
|
93
|
-
* Type-safe: select and label must
|
|
107
|
+
* Type-safe: select and label must use valid filter field names
|
|
94
108
|
* @example
|
|
95
109
|
* // With select and label
|
|
96
110
|
* filter: {
|
|
@@ -109,10 +123,11 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
109
123
|
* select: ['properties.color', 'properties.size']
|
|
110
124
|
* }
|
|
111
125
|
*/
|
|
112
|
-
filter?: ListingFieldConfig<TFilters
|
|
126
|
+
filter?: ListingFieldConfig<NoInfer<keyof TFilters & string>>;
|
|
113
127
|
/**
|
|
114
128
|
* Sort configuration using unified structure
|
|
115
|
-
* Type-safe:
|
|
129
|
+
* Type-safe: keys are sort strings — valid sort field names with :asc/:desc
|
|
130
|
+
* suffix, or 'default'
|
|
116
131
|
*
|
|
117
132
|
* Special handling for 'default' sort:
|
|
118
133
|
* - The 'default' sort represents Frontic backend's default sorting (no sort applied to query)
|
|
@@ -138,7 +153,7 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
138
153
|
* }
|
|
139
154
|
* }
|
|
140
155
|
*/
|
|
141
|
-
sorting?: ListingFieldConfig<TSorts
|
|
156
|
+
sorting?: ListingFieldConfig<NoInfer<SortStringOf<TSorts>>>;
|
|
142
157
|
/**
|
|
143
158
|
* Disable search functionality (default: false)
|
|
144
159
|
*/
|
|
@@ -156,10 +171,6 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
156
171
|
* When omitted, the backend default is used.
|
|
157
172
|
*/
|
|
158
173
|
limit?: number;
|
|
159
|
-
/**
|
|
160
|
-
* Stale time in milliseconds (default: 5 minutes)
|
|
161
|
-
*/
|
|
162
|
-
staleTime?: number;
|
|
163
174
|
/**
|
|
164
175
|
* Enable infinite scroll mode.
|
|
165
176
|
* When true, loadNext()/loadPrev() append/prepend items from adjacent pages
|
|
@@ -177,17 +188,28 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
177
188
|
initialPage?: number;
|
|
178
189
|
}
|
|
179
190
|
/**
|
|
180
|
-
* Return type for the search composable
|
|
191
|
+
* Return type for the search composable — the declared contract of
|
|
192
|
+
* useFronticSearch (the composable is annotated with this type).
|
|
181
193
|
*
|
|
182
|
-
* @template TSearch - The listing name key from
|
|
194
|
+
* @template TSearch - The listing name key from the registry
|
|
183
195
|
* @template TFilters - Filter fields for this listing
|
|
184
196
|
* @template TSorts - Sort fields for this listing
|
|
185
197
|
*/
|
|
186
|
-
export interface UseSearchReturn<TSearch extends
|
|
198
|
+
export interface UseSearchReturn<TSearch extends ListingName = ListingName, TFilters = ListingFiltersOf<TSearch>, TSorts = ListingSortsOf<TSearch>> {
|
|
187
199
|
/** The listing response containing items, pagination info, and filter metadata */
|
|
188
|
-
result: ShallowRef<
|
|
189
|
-
/**
|
|
200
|
+
result: ShallowRef<ResponseOf<TSearch> | undefined>;
|
|
201
|
+
/** Data status: 'pending' | 'error' | 'success' */
|
|
190
202
|
status: UseQueryReturn['status'];
|
|
203
|
+
/**
|
|
204
|
+
* Network status: 'idle' | 'loading'. Together with `status` this
|
|
205
|
+
* distinguishes a first load (`pending`) from a background refresh
|
|
206
|
+
* (`success` + 'loading').
|
|
207
|
+
*/
|
|
208
|
+
asyncStatus: UseQueryReturn['asyncStatus'];
|
|
209
|
+
/** Whether a request is in flight (shortcut for `asyncStatus === 'loading'`) */
|
|
210
|
+
isLoading: UseQueryReturn['isLoading'];
|
|
211
|
+
/** Error of the last fetch, null while pending or after success */
|
|
212
|
+
error: UseQueryReturn['error'];
|
|
191
213
|
/** Current state of the search including page, sort, search, and filter settings (fully typed) */
|
|
192
214
|
state: Ref<SearchState<TFilters, TSorts>>;
|
|
193
215
|
/** Current search term */
|
|
@@ -198,14 +220,14 @@ export interface UseSearchReturn<TSearch extends keyof Listings = keyof Listings
|
|
|
198
220
|
* Infinite mode: appends items from the next page.
|
|
199
221
|
* @returns The page response, or undefined if no next page
|
|
200
222
|
*/
|
|
201
|
-
loadNext: () => Promise<
|
|
223
|
+
loadNext: () => Promise<ResponseOf<TSearch> | undefined>;
|
|
202
224
|
/**
|
|
203
225
|
* Load the previous page of results.
|
|
204
226
|
* Standard mode: replaces current page with the previous one.
|
|
205
227
|
* Infinite mode: prepends items from the previous page.
|
|
206
228
|
* @returns The page response, or undefined if no previous page
|
|
207
229
|
*/
|
|
208
|
-
loadPrev: () => Promise<
|
|
230
|
+
loadPrev: () => Promise<ResponseOf<TSearch> | undefined>;
|
|
209
231
|
/**
|
|
210
232
|
* Jump to a specific page number.
|
|
211
233
|
* Standard mode: replaces current page with the requested one.
|
|
@@ -213,7 +235,7 @@ export interface UseSearchReturn<TSearch extends keyof Listings = keyof Listings
|
|
|
213
235
|
* @param page - The page number to load
|
|
214
236
|
* @returns The page response, or undefined if the page doesn't exist
|
|
215
237
|
*/
|
|
216
|
-
loadPage: (page: number) => Promise<
|
|
238
|
+
loadPage: (page: number) => Promise<ResponseOf<TSearch> | undefined>;
|
|
217
239
|
/**
|
|
218
240
|
* Fetches the search with current query parameters (uses cache if valid)
|
|
219
241
|
*/
|
|
@@ -227,35 +249,33 @@ export interface UseSearchReturn<TSearch extends keyof Listings = keyof Listings
|
|
|
227
249
|
* Type-safe: only accepts valid sort strings for this search
|
|
228
250
|
* @param sortBy - Sort field and direction (e.g., 'name:desc' or 'name:asc'), or omit to reset
|
|
229
251
|
*/
|
|
230
|
-
sortResult: (sortBy?:
|
|
252
|
+
sortResult: (sortBy?: SortStringOf<TSorts>) => Promise<void>;
|
|
231
253
|
/**
|
|
232
254
|
* Resets sorting to default (Frontic backend default)
|
|
233
255
|
*/
|
|
234
256
|
resetSorting: () => Promise<void>;
|
|
235
257
|
/**
|
|
236
|
-
* Adds a filter option to the specified filter field
|
|
237
|
-
*
|
|
258
|
+
* Adds a filter option to the specified filter field.
|
|
259
|
+
* For range filters, pass a { from, to } object — replaces the existing range.
|
|
238
260
|
* @param filterField - The field to filter on (autocomplete available)
|
|
239
|
-
* @param filterOption - The option value to add
|
|
261
|
+
* @param filterOption - The option value to add, or { from, to } for range filters
|
|
240
262
|
*/
|
|
241
|
-
addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K]) => Promise<void>;
|
|
263
|
+
addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K] | RangeFilterValue) => Promise<void>;
|
|
242
264
|
/**
|
|
243
265
|
* Removes a filter option from the specified filter field
|
|
244
|
-
* Type-safe: field and value types are validated
|
|
245
266
|
* @param filterField - The field to remove the filter from (autocomplete available)
|
|
246
267
|
* @param filterOption - The option value to remove (optional - omit to remove entire filter)
|
|
247
268
|
*/
|
|
248
269
|
removeFilter: <K extends keyof TFilters & string>(filterField: K, filterOption?: TFilters[K]) => Promise<void>;
|
|
249
270
|
/**
|
|
250
|
-
* Applies filter options to the specified filter field
|
|
251
|
-
*
|
|
271
|
+
* Applies filter options to the specified filter field (replaces existing values).
|
|
272
|
+
* For range filters, pass an array with a single { from, to } object.
|
|
252
273
|
* @param filterField - The field to filter on (autocomplete available)
|
|
253
|
-
* @param filterOptions - Array of filter values to apply
|
|
274
|
+
* @param filterOptions - Array of filter values to apply, or [{ from, to }] for range filters
|
|
254
275
|
*/
|
|
255
|
-
filterResult: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K]>) => Promise<void>;
|
|
276
|
+
filterResult: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K] | RangeFilterValue>) => Promise<void>;
|
|
256
277
|
/**
|
|
257
278
|
* Resets filters either for a specific field or all filters if no field specified
|
|
258
|
-
* Type-safe: field names are validated
|
|
259
279
|
* @param filterField - Optional field to reset. If omitted, all filters are reset
|
|
260
280
|
*/
|
|
261
281
|
resetFilter: (filterField?: keyof TFilters & string) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Helper Utilities
|
|
3
|
+
*
|
|
4
|
+
* The Fetch API returns two error bodies, told apart by `code`: it is present
|
|
5
|
+
* exactly when the failure was raised deliberately, so a 500 never carries
|
|
6
|
+
* one. The body arrives on the thrown fetch error's `data`, not as a resolved
|
|
7
|
+
* response.
|
|
8
|
+
*/
|
|
9
|
+
import type { ApiError } from '../types/registry.js';
|
|
10
|
+
/**
|
|
11
|
+
* Narrow an unknown error body to the deliberately-raised shape.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const { error } = useFronticBlock('ProductCard', key)
|
|
16
|
+
* const body = (error.value as { data?: unknown } | null)?.data
|
|
17
|
+
* if (isApiError(body) && body.code === 'KEY_NOT_FOUND') {
|
|
18
|
+
* // `code` and `correlationId` are typed here
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function isApiError(value: unknown): value is ApiError;
|
|
@@ -5,3 +5,5 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { makeEqualsFilter, makeLogicalFilter, manageFilter, removeFilter, hasFilter, getFilterValues, type EqualsFilter, type LogicalFilter } from './filter-helpers.js';
|
|
7
7
|
export { makeFilterState, processAvailableFilters, processAvailableSorts, applyFilterConfig, countActiveFilters, parseSortString, isSortAllowed } from './state-helpers.js';
|
|
8
|
+
export { DEFAULT_STALE_TIME, requestContextSlot, toKeyPart } from './query-keys.js';
|
|
9
|
+
export { isApiError } from './errors.js';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { makeEqualsFilter, makeLogicalFilter, manageFilter, removeFilter, hasFilter, getFilterValues } from "./filter-helpers.js";
|
|
2
2
|
export { makeFilterState, processAvailableFilters, processAvailableSorts, applyFilterConfig, countActiveFilters, parseSortString, isSortAllowed } from "./state-helpers.js";
|
|
3
|
+
export { DEFAULT_STALE_TIME, requestContextSlot, toKeyPart } from "./query-keys.js";
|
|
4
|
+
export { isApiError } from "./errors.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Key Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared building blocks for the per-entity query key factories.
|
|
5
|
+
*/
|
|
6
|
+
/** Default stale time for all Frontic queries (5 minutes) */
|
|
7
|
+
export declare const DEFAULT_STALE_TIME: number;
|
|
8
|
+
/**
|
|
9
|
+
* Request context slot appended to every detail key, so responses fetched
|
|
10
|
+
* under different contexts (personalization token) or context domains
|
|
11
|
+
* (locale/region domain) never share a cache entry. `null` marks "not set" —
|
|
12
|
+
* Pinia Colada forbids `undefined` inside keys.
|
|
13
|
+
*
|
|
14
|
+
* `requestUrl` is deliberately absent: it is per-route request metadata
|
|
15
|
+
* (attribution/tracking), not content identity — keying on it would fragment
|
|
16
|
+
* the cache into one entry per visited URL.
|
|
17
|
+
*/
|
|
18
|
+
export declare function requestContextSlot(contextKey?: string, contextDomain?: string): {
|
|
19
|
+
readonly context: string | null;
|
|
20
|
+
readonly domain: string | null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Makes an object usable inside a query key: Pinia Colada keys must be JSON
|
|
24
|
+
* values, so `undefined` entries are dropped recursively. Property order does
|
|
25
|
+
* not matter — the cache normalises objects order-insensitively.
|
|
26
|
+
*/
|
|
27
|
+
export declare function toKeyPart(value: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const DEFAULT_STALE_TIME = 1e3 * 60 * 5;
|
|
2
|
+
export function requestContextSlot(contextKey, contextDomain) {
|
|
3
|
+
return { context: contextKey ?? null, domain: contextDomain ?? null };
|
|
4
|
+
}
|
|
5
|
+
export function toKeyPart(value) {
|
|
6
|
+
return stripUndefined(value);
|
|
7
|
+
}
|
|
8
|
+
function stripUndefined(value) {
|
|
9
|
+
if (Array.isArray(value)) return value.map(stripUndefined);
|
|
10
|
+
if (value && typeof value === "object") {
|
|
11
|
+
const result = {};
|
|
12
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
13
|
+
if (entry !== void 0) result[key] = stripUndefined(entry);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|