svelte-reflector 2.1.2 → 2.1.3
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/dist/core/Reflector.js
CHANGED
|
@@ -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:
|
|
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];
|