svelte-reflector 2.0.0 → 2.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 CHANGED
@@ -265,6 +265,28 @@ The auto-injected `setQueryGroup([...])` constructor on the generated
265
265
  `setQueryGroup` manually from `$reflector/reflector.svelte` if you still
266
266
  need batch URL writes.
267
267
 
268
+ #### Ephemeral pagination (sidebar / widget)
269
+
270
+ Sometimes a list lives outside the canonical route — a global sidebar, a
271
+ widget, a paginated combobox in a modal — and should NOT mutate the
272
+ current URL. For those cases, every generated `call()` with query params
273
+ accepts an optional `queryOverride`:
274
+
275
+ ```typescript
276
+ const sidebar = new UserService();
277
+
278
+ // Current URL stays put. Request goes out with ?page=2&limit=10.
279
+ await sidebar.listAll({
280
+ queryOverride: { page: "2", limit: "10" },
281
+ });
282
+ ```
283
+
284
+ When `queryOverride` is passed, the method skips `this.querys.bundle()`
285
+ entirely and uses the override as `queryData`. Without it, the method
286
+ reads from `QueryBuilder.value` (the URL) as usual — so you can mix and
287
+ match on a per-call basis. Omit a key to drop it from the request; pass
288
+ `null` to send a literal `null`.
289
+
268
290
  ## Configuration
269
291
 
270
292
  ### Environment Variables
@@ -44,7 +44,7 @@ export class CallMethodGenerator {
44
44
  const { querys, paths, cookies } = method.analyzers.props;
45
45
  const lines = [];
46
46
  if (querys.length > 0) {
47
- lines.push(`const { ${this.joinNames(querys)} } = this.querys.bundle()`);
47
+ lines.push(`const { ${this.joinNames(querys)} } = params?.queryOverride ?? this.querys.bundle()`);
48
48
  }
49
49
  if (paths.length > 0) {
50
50
  lines.push(`const { ${this.joinNames(paths)} } = params?.paths ?? this.paths`);
@@ -6,4 +6,6 @@ export declare class ModuleCallStrategy implements CallStrategy {
6
6
  formStateAccess(method: CallMethodInput): string;
7
7
  private buildParamsType;
8
8
  private buildPathsBlock;
9
+ private buildQueryOverrideBlock;
10
+ private queryOverrideType;
9
11
  }
@@ -17,27 +17,43 @@ export class ModuleCallStrategy {
17
17
  buildParamsType(method) {
18
18
  const behaviorType = `Behavior<${method.responseTypeInterface}, ApiErrorResponse>`;
19
19
  const pathsBlock = this.buildPathsBlock(method);
20
- if (pathsBlock) {
21
- return `{
22
- behavior?: ${behaviorType};${pathsBlock}
23
- }`;
24
- }
20
+ const queryBlock = this.buildQueryOverrideBlock(method);
21
+ const blocks = [`behavior?: ${behaviorType};`, pathsBlock, queryBlock]
22
+ .filter((b) => !!b)
23
+ .join("\n");
25
24
  return `{
26
- behavior?: ${behaviorType};
25
+ ${blocks}
27
26
  }`;
28
27
  }
29
28
  buildPathsBlock(method) {
30
29
  const paths = method.analyzers.props.paths;
31
30
  if (paths.length === 0)
32
31
  return undefined;
33
- return `
34
- paths?: {
32
+ return `paths?: {
35
33
  ${paths
36
34
  .map((p) => {
37
35
  const type = p.rawType ?? p.type;
38
36
  return `${p.name}: ${type}`;
39
37
  })
40
38
  .join("\n")}
41
- }`;
39
+ };`;
40
+ }
41
+ buildQueryOverrideBlock(method) {
42
+ const querys = method.analyzers.props.querys;
43
+ if (querys.length === 0)
44
+ return undefined;
45
+ const fields = querys
46
+ .map((q) => `${q.name}?: ${this.queryOverrideType(q)}`)
47
+ .join("\n");
48
+ return `queryOverride?: {
49
+ ${fields}
50
+ };`;
51
+ }
52
+ queryOverrideType(q) {
53
+ if ("isEnum" in q && q.isEnum)
54
+ return `${q.type}[]`;
55
+ if (!("rawType" in q) && !("enumName" in q))
56
+ return "string[]";
57
+ return "string | null";
42
58
  }
43
59
  }
@@ -9,9 +9,10 @@ type ValidatorResult = string | null;
9
9
  type ValidatorFn<T> = (v: T) => ValidatorResult;
10
10
  type BundleResult<T> = T extends { bundle: () => infer R } ? R : T;
11
11
 
12
- export type ApiCallParams<TResponse, TPaths = void> = TPaths extends void
13
- ? { behavior?: Behavior<TResponse, ApiErrorResponse> }
14
- : { behavior?: Behavior<TResponse, ApiErrorResponse>; paths?: TPaths };
12
+ export type ApiCallParams<TResponse, TPaths = void, TQuery = void> = {
13
+ behavior?: Behavior<TResponse, ApiErrorResponse>;
14
+ } & (TPaths extends void ? object : { paths?: TPaths }) &
15
+ (TQuery extends void ? object : { queryOverride?: TQuery });
15
16
 
16
17
  type PartialBuildedInput<T> = {
17
18
  [K in Exclude<keyof T, "bundle">]?: BuildedInput<T[K]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",