svelte-reflector 2.1.2 → 2.1.4

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.
@@ -54,6 +54,7 @@ export class Reflector {
54
54
  const runtimeFiles = RuntimeFilesEmitter.build({
55
55
  propertiesNames: this.propertiesNames,
56
56
  context: this.context,
57
+ config: this.config,
57
58
  });
58
59
  await Promise.all([
59
60
  ...moduleSchemaFiles.map((f) => f.save()),
@@ -12,6 +12,8 @@ export interface ReflectorConfig {
12
12
  environmentImport: string;
13
13
  /** Name of the exported environment flag — values other than `DEV` are treated as prod. */
14
14
  environmentFlag: string;
15
+ /** Full import path to the toast module (default export must expose `.error({ title, description })`). */
16
+ toastImport: string;
15
17
  }
16
18
  export declare const DEFAULT_REFLECTOR_CONFIG: ReflectorConfig;
17
19
  export declare function resolveReflectorConfig(partial?: Partial<ReflectorConfig>): ReflectorConfig;
@@ -3,6 +3,7 @@ export const DEFAULT_REFLECTOR_CONFIG = {
3
3
  validatorsImport: "$lib/sanitizers/validateFormats",
4
4
  environmentImport: "$env/static/public",
5
5
  environmentFlag: "PUBLIC_ENVIRONMENT",
6
+ toastImport: "$lib/utils/toast.svelte",
6
7
  };
7
8
  export function resolveReflectorConfig(partial) {
8
9
  return { ...DEFAULT_REFLECTOR_CONFIG, ...(partial ?? {}) };
@@ -1,5 +1,6 @@
1
1
  import { Source } from "../../file.js";
2
2
  import type { CodegenContext } from "../CodegenContext.js";
3
+ import type { ReflectorConfig } from "../config/ReflectorConfig.js";
3
4
  /**
4
5
  * Emits the shared runtime-support files that sit alongside the generated
5
6
  * module files: the reflector runtime template, the FIELD_NAMES list, the
@@ -9,5 +10,6 @@ export declare class RuntimeFilesEmitter {
9
10
  static build(params: {
10
11
  propertiesNames: Set<string>;
11
12
  context: CodegenContext;
13
+ config: ReflectorConfig;
12
14
  }): Source[];
13
15
  }
@@ -4,6 +4,7 @@ import { Source } from "../../file.js";
4
4
  import { loadReflectorTemplate } from "../../loadTemplate.js";
5
5
  import { generatedDir } from "../../vars.global.js";
6
6
  import { dedent } from "../../helpers/codegen.js";
7
+ import { DEFAULT_REFLECTOR_CONFIG } from "../config/ReflectorConfig.js";
7
8
  function generated(relPath) {
8
9
  return path.resolve(process.cwd(), `${generatedDir}/${relPath}`);
9
10
  }
@@ -14,19 +15,23 @@ function generated(relPath) {
14
15
  */
15
16
  export class RuntimeFilesEmitter {
16
17
  static build(params) {
17
- const { propertiesNames, context } = params;
18
+ const { propertiesNames, context, config } = params;
19
+ let templateData = loadReflectorTemplate();
20
+ if (config.toastImport !== DEFAULT_REFLECTOR_CONFIG.toastImport) {
21
+ templateData = templateData.replace(`from "${DEFAULT_REFLECTOR_CONFIG.toastImport}"`, `from "${config.toastImport}"`);
22
+ }
18
23
  const typesSrc = new Source({
19
24
  path: generated("reflector.svelte.ts"),
20
- data: loadReflectorTemplate(),
25
+ data: templateData,
21
26
  });
22
27
  const fieldLiterals = Array.from(propertiesNames).map((p) => `'${p}'`);
23
28
  const fieldsFile = new Source({
24
29
  path: generated("fields.ts"),
25
- data: dedent `
26
- export const FIELD_NAMES = [
27
- ${fieldLiterals}
28
- ] as const;
29
- export type FieldName = (typeof FIELD_NAMES)[number]
30
+ data: dedent `
31
+ export const FIELD_NAMES = [
32
+ ${fieldLiterals}
33
+ ] as const;
34
+ export type FieldName = (typeof FIELD_NAMES)[number]
30
35
  `,
31
36
  });
32
37
  const enumss = Array.from(context.enumTypes)
@@ -41,13 +46,13 @@ export class RuntimeFilesEmitter {
41
46
  .join(";");
42
47
  const mockedFile = new Source({
43
48
  path: generated("mocked-params.svelte.ts"),
44
- data: dedent `
45
- class MockedParams {
46
- ${mockedFields}
47
- }
48
-
49
- const mockedParams = new MockedParams()
50
- export default mockedParams
49
+ data: dedent `
50
+ class MockedParams {
51
+ ${mockedFields}
52
+ }
53
+
54
+ const mockedParams = new MockedParams()
55
+ export default mockedParams
51
56
  `,
52
57
  });
53
58
  return [typesSrc, fieldsFile, enumFile, mockedFile];
@@ -158,10 +158,18 @@ export function genericArrayBundler<T extends { bundle: () => BundleResult<T> }>
158
158
  return (data as T[]).map((item) => item.bundle());
159
159
  }
160
160
 
161
+ /**
162
+ * Atualiza um query param na URL.
163
+ * - `""` (string vazia) → remove o param.
164
+ * - qualquer outro valor → `searchParams.set(key, String(event))`.
165
+ */
161
166
  export function changeParam({ event, key }: QueryContract) {
162
- const newValue = event;
163
167
  const url = new SvelteURL(page.url);
164
- url.searchParams.set(key, String(newValue));
168
+ if (event === "") {
169
+ url.searchParams.delete(key);
170
+ } else {
171
+ url.searchParams.set(key, String(event));
172
+ }
165
173
  goto(url, { replaceState: true, keepFocus: true });
166
174
  }
167
175
 
@@ -190,12 +198,24 @@ export class QueryBuilder {
190
198
  return fromUrl !== null ? fromUrl : this.defaultValue;
191
199
  }
192
200
 
201
+ /**
202
+ * Aplica o valor recebido ao query param.
203
+ * - `null` / `undefined` → no-op (não chama `goto`).
204
+ * - `""` (string vazia) → delega pra `changeParam`, que remove o param.
205
+ * - número / string não-vazia → `set(key, String(event))`.
206
+ */
193
207
  update(event: string | number | null) {
194
208
  if (event === null || event === undefined) return;
195
209
  return changeParam({ key: this.key, event: String(event) });
196
210
  }
197
211
  }
198
212
 
213
+ /**
214
+ * Atualiza vários query params de uma vez.
215
+ * - array → `delete(key)` seguido de `append` para cada item.
216
+ * - `""` → remove o param.
217
+ * - outros valores → `set(key, String(value))`.
218
+ */
199
219
  export function setQueryGroup(group: QueryWithArrayType[]) {
200
220
  if (!browser) return;
201
221
 
@@ -210,6 +230,11 @@ export function setQueryGroup(group: QueryWithArrayType[]) {
210
230
  continue;
211
231
  }
212
232
 
233
+ if (value === "") {
234
+ url.searchParams.delete(key);
235
+ continue;
236
+ }
237
+
213
238
  url.searchParams.set(key, String(value));
214
239
  }
215
240
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-reflector",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Reflects zod types from openAPI schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",