@frontic/nuxt 0.8.4 → 1.1.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 +65 -4
- package/dist/module.d.mts +2 -132
- package/dist/module.json +2 -2
- package/dist/module.mjs +130 -15
- 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 +25 -4
- package/dist/runtime/composables/useFronticClient.d.ts +9 -28
- package/dist/runtime/composables/useFronticClient.js +59 -48
- 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 +28 -5
- package/dist/runtime/composables/useFronticPage.d.ts +35 -16
- package/dist/runtime/composables/useFronticPage.js +42 -20
- package/dist/runtime/composables/useFronticSearch.d.ts +4 -96
- package/dist/runtime/composables/useFronticSearch.js +193 -60
- package/dist/runtime/composables/useFronticTree.d.ts +23 -14
- package/dist/runtime/composables/useFronticTree.js +25 -5
- package/dist/runtime/server/api/frontic/[...path].js +48 -10
- package/dist/runtime/server/middleware/sitemap.d.ts +2 -0
- package/dist/runtime/server/middleware/sitemap.js +55 -0
- 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 +36 -0
- package/dist/runtime/types/client.js +0 -0
- package/dist/runtime/types/errors.d.ts +47 -0
- package/dist/runtime/types/errors.js +1 -0
- package/dist/runtime/types/index.d.ts +9 -3
- package/dist/runtime/types/listing.d.ts +113 -251
- package/dist/runtime/types/options.d.ts +169 -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 +90 -38
- package/dist/runtime/utils/describe-error.d.ts +38 -0
- package/dist/runtime/utils/describe-error.js +38 -0
- package/dist/runtime/utils/errors.d.ts +22 -0
- package/dist/runtime/utils/errors.js +3 -0
- package/dist/runtime/utils/filter-helpers.d.ts +13 -0
- package/dist/runtime/utils/filter-helpers.js +14 -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/resolve-context-domain.d.ts +14 -0
- package/dist/runtime/utils/resolve-context-domain.js +9 -1
- 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
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* Type definitions for the useFronticSearch composable.
|
|
5
5
|
* These types provide type-safe filtering, sorting, and pagination for Frontic search listings.
|
|
6
6
|
*/
|
|
7
|
-
import type { Ref, ShallowRef } from 'vue';
|
|
7
|
+
import type { Ref, ShallowRef, MaybeRef } 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,55 @@ 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
|
+
* Search term to start from, committed before the first query runs.
|
|
89
|
+
*
|
|
90
|
+
* The debounced input path cannot carry a term that arrives with the request:
|
|
91
|
+
* on the server the timer never fires before the render finishes, and on the
|
|
92
|
+
* client the hydrated value never changes, so the watcher never sees it. Seed
|
|
93
|
+
* it here instead — a `?name=` restored on the server reaches the first query.
|
|
94
|
+
*
|
|
95
|
+
* An empty or whitespace-only value is treated as no search. Unlike the typed
|
|
96
|
+
* path this is not subject to `searchTermThreshold`: the threshold exists to
|
|
97
|
+
* stop a request per keystroke, and a term that arrived with the request was
|
|
98
|
+
* not typed — dropping it would render results that contradict the URL.
|
|
99
|
+
*/
|
|
100
|
+
initialSearch?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Filters to start from, keyed by field, in the same shape `filterResult`
|
|
103
|
+
* takes. Range values are recognised by shape; every other field is routed
|
|
104
|
+
* through `orFilter` exactly as an interaction would route it.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* initialFilters: { hersteller: ['Atomic'], 'price.amount': { from: 20, to: 100 } }
|
|
108
|
+
*/
|
|
109
|
+
initialFilters?: Partial<Record<keyof TFilters & string, unknown>>;
|
|
110
|
+
/**
|
|
111
|
+
* Sort to start from, in the same `'field:order'` form `sortResult` takes.
|
|
112
|
+
* Ignored when the sorting config disallows it, like any other sort.
|
|
113
|
+
*/
|
|
114
|
+
initialSort?: SortStringOf<TSorts>;
|
|
115
|
+
/**
|
|
116
|
+
* Analytics thresholds, deliberately separate from the UX knobs above.
|
|
117
|
+
* The debounce that keeps a listing responsive and the delay that decides a
|
|
118
|
+
* term became intent are different questions and must not share a value:
|
|
119
|
+
* instrumenting off `searchDebounce` records `s`, `sk`, `ski`, `skis` as four
|
|
120
|
+
* searches.
|
|
121
|
+
*/
|
|
122
|
+
analytics?: {
|
|
123
|
+
/** How long a term must rest before it counts as a search (default: 1000) */
|
|
124
|
+
searchCommitMs?: number;
|
|
125
|
+
/** Shortest term worth recording (default: 3) */
|
|
126
|
+
searchMinChars?: number;
|
|
127
|
+
};
|
|
86
128
|
/**
|
|
87
129
|
* Filter fields that should use OR logic (all others use AND)
|
|
88
130
|
* Type-safe: only allows valid filter field names for this listing
|
|
89
131
|
*/
|
|
90
|
-
orFilter?: Array<keyof TFilters & string
|
|
132
|
+
orFilter?: Array<NoInfer<keyof TFilters & string>>;
|
|
91
133
|
/**
|
|
92
134
|
* Filter configuration using unified structure
|
|
93
|
-
* Type-safe: select and label must
|
|
135
|
+
* Type-safe: select and label must use valid filter field names
|
|
94
136
|
* @example
|
|
95
137
|
* // With select and label
|
|
96
138
|
* filter: {
|
|
@@ -109,10 +151,11 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
109
151
|
* select: ['properties.color', 'properties.size']
|
|
110
152
|
* }
|
|
111
153
|
*/
|
|
112
|
-
filter?: ListingFieldConfig<TFilters
|
|
154
|
+
filter?: ListingFieldConfig<NoInfer<keyof TFilters & string>>;
|
|
113
155
|
/**
|
|
114
156
|
* Sort configuration using unified structure
|
|
115
|
-
* Type-safe:
|
|
157
|
+
* Type-safe: keys are sort strings — valid sort field names with :asc/:desc
|
|
158
|
+
* suffix, or 'default'
|
|
116
159
|
*
|
|
117
160
|
* Special handling for 'default' sort:
|
|
118
161
|
* - The 'default' sort represents Frontic backend's default sorting (no sort applied to query)
|
|
@@ -138,7 +181,7 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
138
181
|
* }
|
|
139
182
|
* }
|
|
140
183
|
*/
|
|
141
|
-
sorting?: ListingFieldConfig<TSorts
|
|
184
|
+
sorting?: ListingFieldConfig<NoInfer<SortStringOf<TSorts>>>;
|
|
142
185
|
/**
|
|
143
186
|
* Disable search functionality (default: false)
|
|
144
187
|
*/
|
|
@@ -154,12 +197,12 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
154
197
|
/**
|
|
155
198
|
* Number of items per page (sent as `limit` to the Frontic API).
|
|
156
199
|
* When omitted, the backend default is used.
|
|
200
|
+
*
|
|
201
|
+
* Accepts a ref: a page size that depends on something resolved after setup
|
|
202
|
+
* enters the query key when it changes, so the listing refetches rather than
|
|
203
|
+
* keeping the size it was created with.
|
|
157
204
|
*/
|
|
158
|
-
limit?: number
|
|
159
|
-
/**
|
|
160
|
-
* Stale time in milliseconds (default: 5 minutes)
|
|
161
|
-
*/
|
|
162
|
-
staleTime?: number;
|
|
205
|
+
limit?: MaybeRef<number | undefined>;
|
|
163
206
|
/**
|
|
164
207
|
* Enable infinite scroll mode.
|
|
165
208
|
* When true, loadNext()/loadPrev() append/prepend items from adjacent pages
|
|
@@ -177,17 +220,28 @@ export interface UseFronticSearchOptions<TSearch extends keyof Listings = keyof
|
|
|
177
220
|
initialPage?: number;
|
|
178
221
|
}
|
|
179
222
|
/**
|
|
180
|
-
* Return type for the search composable
|
|
223
|
+
* Return type for the search composable — the declared contract of
|
|
224
|
+
* useFronticSearch (the composable is annotated with this type).
|
|
181
225
|
*
|
|
182
|
-
* @template TSearch - The listing name key from
|
|
226
|
+
* @template TSearch - The listing name key from the registry
|
|
183
227
|
* @template TFilters - Filter fields for this listing
|
|
184
228
|
* @template TSorts - Sort fields for this listing
|
|
185
229
|
*/
|
|
186
|
-
export interface UseSearchReturn<TSearch extends
|
|
230
|
+
export interface UseSearchReturn<TSearch extends ListingName = ListingName, TFilters = ListingFiltersOf<TSearch>, TSorts = ListingSortsOf<TSearch>> {
|
|
187
231
|
/** The listing response containing items, pagination info, and filter metadata */
|
|
188
|
-
result: ShallowRef<
|
|
189
|
-
/**
|
|
232
|
+
result: ShallowRef<ResponseOf<TSearch> | undefined>;
|
|
233
|
+
/** Data status: 'pending' | 'error' | 'success' */
|
|
190
234
|
status: UseQueryReturn['status'];
|
|
235
|
+
/**
|
|
236
|
+
* Network status: 'idle' | 'loading'. Together with `status` this
|
|
237
|
+
* distinguishes a first load (`pending`) from a background refresh
|
|
238
|
+
* (`success` + 'loading').
|
|
239
|
+
*/
|
|
240
|
+
asyncStatus: UseQueryReturn['asyncStatus'];
|
|
241
|
+
/** Whether a request is in flight (shortcut for `asyncStatus === 'loading'`) */
|
|
242
|
+
isLoading: UseQueryReturn['isLoading'];
|
|
243
|
+
/** Error of the last fetch, null while pending or after success */
|
|
244
|
+
error: UseQueryReturn['error'];
|
|
191
245
|
/** Current state of the search including page, sort, search, and filter settings (fully typed) */
|
|
192
246
|
state: Ref<SearchState<TFilters, TSorts>>;
|
|
193
247
|
/** Current search term */
|
|
@@ -198,14 +252,14 @@ export interface UseSearchReturn<TSearch extends keyof Listings = keyof Listings
|
|
|
198
252
|
* Infinite mode: appends items from the next page.
|
|
199
253
|
* @returns The page response, or undefined if no next page
|
|
200
254
|
*/
|
|
201
|
-
loadNext: () => Promise<
|
|
255
|
+
loadNext: () => Promise<ResponseOf<TSearch> | undefined>;
|
|
202
256
|
/**
|
|
203
257
|
* Load the previous page of results.
|
|
204
258
|
* Standard mode: replaces current page with the previous one.
|
|
205
259
|
* Infinite mode: prepends items from the previous page.
|
|
206
260
|
* @returns The page response, or undefined if no previous page
|
|
207
261
|
*/
|
|
208
|
-
loadPrev: () => Promise<
|
|
262
|
+
loadPrev: () => Promise<ResponseOf<TSearch> | undefined>;
|
|
209
263
|
/**
|
|
210
264
|
* Jump to a specific page number.
|
|
211
265
|
* Standard mode: replaces current page with the requested one.
|
|
@@ -213,7 +267,7 @@ export interface UseSearchReturn<TSearch extends keyof Listings = keyof Listings
|
|
|
213
267
|
* @param page - The page number to load
|
|
214
268
|
* @returns The page response, or undefined if the page doesn't exist
|
|
215
269
|
*/
|
|
216
|
-
loadPage: (page: number) => Promise<
|
|
270
|
+
loadPage: (page: number) => Promise<ResponseOf<TSearch> | undefined>;
|
|
217
271
|
/**
|
|
218
272
|
* Fetches the search with current query parameters (uses cache if valid)
|
|
219
273
|
*/
|
|
@@ -227,35 +281,33 @@ export interface UseSearchReturn<TSearch extends keyof Listings = keyof Listings
|
|
|
227
281
|
* Type-safe: only accepts valid sort strings for this search
|
|
228
282
|
* @param sortBy - Sort field and direction (e.g., 'name:desc' or 'name:asc'), or omit to reset
|
|
229
283
|
*/
|
|
230
|
-
sortResult: (sortBy?:
|
|
284
|
+
sortResult: (sortBy?: SortStringOf<TSorts>) => Promise<void>;
|
|
231
285
|
/**
|
|
232
286
|
* Resets sorting to default (Frontic backend default)
|
|
233
287
|
*/
|
|
234
288
|
resetSorting: () => Promise<void>;
|
|
235
289
|
/**
|
|
236
|
-
* Adds a filter option to the specified filter field
|
|
237
|
-
*
|
|
290
|
+
* Adds a filter option to the specified filter field.
|
|
291
|
+
* For range filters, pass a { from, to } object — replaces the existing range.
|
|
238
292
|
* @param filterField - The field to filter on (autocomplete available)
|
|
239
|
-
* @param filterOption - The option value to add
|
|
293
|
+
* @param filterOption - The option value to add, or { from, to } for range filters
|
|
240
294
|
*/
|
|
241
|
-
addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K]) => Promise<void>;
|
|
295
|
+
addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K] | RangeFilterValue) => Promise<void>;
|
|
242
296
|
/**
|
|
243
297
|
* Removes a filter option from the specified filter field
|
|
244
|
-
* Type-safe: field and value types are validated
|
|
245
298
|
* @param filterField - The field to remove the filter from (autocomplete available)
|
|
246
299
|
* @param filterOption - The option value to remove (optional - omit to remove entire filter)
|
|
247
300
|
*/
|
|
248
301
|
removeFilter: <K extends keyof TFilters & string>(filterField: K, filterOption?: TFilters[K]) => Promise<void>;
|
|
249
302
|
/**
|
|
250
|
-
* Applies filter options to the specified filter field
|
|
251
|
-
*
|
|
303
|
+
* Applies filter options to the specified filter field (replaces existing values).
|
|
304
|
+
* For range filters, pass an array with a single { from, to } object.
|
|
252
305
|
* @param filterField - The field to filter on (autocomplete available)
|
|
253
|
-
* @param filterOptions - Array of filter values to apply
|
|
306
|
+
* @param filterOptions - Array of filter values to apply, or [{ from, to }] for range filters
|
|
254
307
|
*/
|
|
255
|
-
filterResult: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K]>) => Promise<void>;
|
|
308
|
+
filterResult: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K] | RangeFilterValue>) => Promise<void>;
|
|
256
309
|
/**
|
|
257
310
|
* Resets filters either for a specific field or all filters if no field specified
|
|
258
|
-
* Type-safe: field names are validated
|
|
259
311
|
* @param filterField - Optional field to reset. If omitted, all filters are reset
|
|
260
312
|
*/
|
|
261
313
|
resetFilter: (filterField?: keyof TFilters & string) => Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error description for the `frontic:fetch:error` hook.
|
|
3
|
+
*
|
|
4
|
+
* Connection-level failures arrive as a bare "Bad Gateway" or "fetch failed"
|
|
5
|
+
* with the actual reason — ECONNRESET, ETIMEDOUT, DNS, TLS — buried in `cause`.
|
|
6
|
+
* `cause` is non-enumerable, so it is absent from `console.error(err)` and from
|
|
7
|
+
* anything that serialises the error, and has to be walked explicitly.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Flatten an error and its `cause` chain, outermost first.
|
|
11
|
+
*
|
|
12
|
+
* Returned as an array rather than a joined string so a consumer can send the
|
|
13
|
+
* frames to an error tracker individually; {@link toFetchErrorDetail} joins
|
|
14
|
+
* them for logs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function describeErrorChain(error: unknown): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Whether a failure — or anything in its cause chain — is an abort or timeout.
|
|
19
|
+
*
|
|
20
|
+
* The chain matters: h3's `sendProxy` catches every fetch failure and rethrows
|
|
21
|
+
* `createError({ status: 502, cause: error })`, so by the time a handler sees
|
|
22
|
+
* it the outermost error is an H3Error carrying a 502 and the real
|
|
23
|
+
* `TimeoutError` sits two levels down. Testing only the top-level error can
|
|
24
|
+
* never see a timeout.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isTimeoutError(error: unknown): boolean;
|
|
27
|
+
export interface FronticFetchErrorDetail {
|
|
28
|
+
/** The original error, unwrapped, for `captureException` */
|
|
29
|
+
error: unknown;
|
|
30
|
+
/** The cause chain, outermost first */
|
|
31
|
+
chain: string[];
|
|
32
|
+
/** The chain as one line, for logs */
|
|
33
|
+
message: string;
|
|
34
|
+
/** HTTP status, absent when the failure never reached a response */
|
|
35
|
+
status?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Describe a failure once, so every call site reports it the same way. */
|
|
38
|
+
export declare function toFetchErrorDetail(error: unknown): FronticFetchErrorDetail;
|