svelte-reflector 1.3.1 → 1.3.2
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.
|
@@ -15,6 +15,8 @@ export declare class PrimitiveProp {
|
|
|
15
15
|
private readonly example;
|
|
16
16
|
private readonly fallbackExample;
|
|
17
17
|
private get effectiveType();
|
|
18
|
+
/** Non-required fields become nullable (| null) instead of optional (?) */
|
|
19
|
+
private get isEffectivelyNullable();
|
|
18
20
|
constructor(params: {
|
|
19
21
|
name: string;
|
|
20
22
|
schemaObject: SchemaObject;
|
|
@@ -14,6 +14,10 @@ export class PrimitiveProp {
|
|
|
14
14
|
get effectiveType() {
|
|
15
15
|
return this.customType ?? this.rawType;
|
|
16
16
|
}
|
|
17
|
+
/** Non-required fields become nullable (| null) instead of optional (?) */
|
|
18
|
+
get isEffectivelyNullable() {
|
|
19
|
+
return this.isNullable || !this.required;
|
|
20
|
+
}
|
|
17
21
|
constructor(params) {
|
|
18
22
|
const { name, schemaObject, required, validator, customType, isParam, isNullable } = params;
|
|
19
23
|
const { type: rawType } = schemaObject;
|
|
@@ -94,8 +98,15 @@ export class PrimitiveProp {
|
|
|
94
98
|
return "";
|
|
95
99
|
};
|
|
96
100
|
const buildedExample = `params?.empty || isEmpty ? ${this.fallbackExample} : ${this.example}`;
|
|
97
|
-
const
|
|
98
|
-
const
|
|
101
|
+
const effectivelyNullable = this.isEffectivelyNullable;
|
|
102
|
+
const keyExpr = effectivelyNullable ? `params?.data?.${name} ?? null` : `params?.data?.${name}`;
|
|
103
|
+
let typeParam = "";
|
|
104
|
+
if (effectivelyNullable) {
|
|
105
|
+
typeParam = `<${this.effectiveType} | null>`;
|
|
106
|
+
}
|
|
107
|
+
else if (this.customType) {
|
|
108
|
+
typeParam = `<${this.effectiveType}>`;
|
|
109
|
+
}
|
|
99
110
|
return `
|
|
100
111
|
build${typeParam}({ key: ${keyExpr}, placeholder: ${this.example}, example: ${buildedExample}, required: ${required}, ${buildedValidator()}})
|
|
101
112
|
`;
|
|
@@ -107,13 +118,13 @@ export class PrimitiveProp {
|
|
|
107
118
|
return `${this.thisDot()}${this.name} = ${this.buildedConst}`;
|
|
108
119
|
}
|
|
109
120
|
classBuild() {
|
|
110
|
-
const req = (this.required || this.
|
|
111
|
-
const nullable = this.
|
|
121
|
+
const req = (this.required || this.isEffectivelyNullable) ? "" : "?";
|
|
122
|
+
const nullable = this.isEffectivelyNullable ? " | null" : "";
|
|
112
123
|
return `${this.name}${req}: BuildedInput<${this.effectiveType}${nullable}>`;
|
|
113
124
|
}
|
|
114
125
|
interfaceBuild() {
|
|
115
|
-
const req = this.required ? "" : "?";
|
|
116
|
-
const nullable = this.
|
|
126
|
+
const req = (this.required || this.isEffectivelyNullable) ? "" : "?";
|
|
127
|
+
const nullable = this.isEffectivelyNullable ? " | null" : "";
|
|
117
128
|
return `${this.name}${req}: ${this.effectiveType}${nullable}`;
|
|
118
129
|
}
|
|
119
130
|
patchBuild() {
|