mobiletto-orm-typedef-gen 2.0.3 → 2.0.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.
package/lib/cjs/generate.js
CHANGED
|
@@ -20,6 +20,7 @@ const _findDecls = (name, fields, decls) => {
|
|
|
20
20
|
}
|
|
21
21
|
return decls;
|
|
22
22
|
};
|
|
23
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
23
24
|
const defaultPrepareContext = (typeDef, ctx) => {
|
|
24
25
|
for (const fieldName of Object.keys(ctx.fields)) {
|
|
25
26
|
const field = ctx.fields[fieldName];
|
|
@@ -60,6 +61,7 @@ const defaultPrepareContext = (typeDef, ctx) => {
|
|
|
60
61
|
field.isEnum = true;
|
|
61
62
|
field.enumValues = JSON.stringify(field.items.map((i) => i.value));
|
|
62
63
|
}
|
|
64
|
+
field.Name = capitalize(field.name);
|
|
63
65
|
}
|
|
64
66
|
ctx.typeName = typeDef.typeName;
|
|
65
67
|
ctx.curlyOpen = "{";
|
|
@@ -82,6 +84,7 @@ export const generate = (typeDef, templatePath, opts) => {
|
|
|
82
84
|
const typeContext = defaultPrepareContext(typeDef, {
|
|
83
85
|
typeDef,
|
|
84
86
|
name: decl.name,
|
|
87
|
+
Name: capitalize(decl.name),
|
|
85
88
|
fields: decl.fields,
|
|
86
89
|
disclaimer: decls.length > 0 ? null : disclaimer,
|
|
87
90
|
first,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}
|
|
2
|
-
{{/if}}export type {{
|
|
2
|
+
{{/if}}export type {{ Name }}Type = {{#if root}}{
|
|
3
3
|
_meta?: {
|
|
4
4
|
id: string;
|
|
5
5
|
version: string;
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
mtime: number;
|
|
9
9
|
};
|
|
10
10
|
{{else}}{
|
|
11
|
-
{{/if}}{{#each fields}} {{
|
|
11
|
+
{{/if}}{{#each fields}} {{name}}{{#if optional}}?{{/if}}: {{#if typeIsObject}}{{ ../Name }}_{{name}}Type{{else if typeIsArray}}{{valueType}}[]{{else}}{{type}}{{/if}};
|
|
12
12
|
{{/each}}
|
|
13
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}
|
|
2
2
|
import * as yup from "yup";{{/if}}
|
|
3
|
-
export const {{
|
|
4
|
-
{{name}}: {{#if typeIsObject}}{{ ../
|
|
3
|
+
export const {{Name}}Schema = yup.object({{{curlyOpen}}}{{#each fields}}
|
|
4
|
+
{{name}}: {{#if typeIsObject}}{{ ../Name }}_{{name}}Schema{{else}}{{#if typeIsArray}}yup.array(yup.{{valueType}}),{{else}}yup.{{type}}(){{/if}}{{#if required}}.required('required'){{/if}}{{#if minValue}}.min({{minValue}}, 'minValue'){{/if}}{{#if maxValue}}.max({{maxValue}}, 'maxValue'){{/if}}{{#if min}}.min({{min}}, 'min'){{/if}}{{#if max}}.max({{max}}, 'max'){{/if}}{{#if regex}}.matches({{{regexValue}}}, 'regex'){{/if}}{{#if default}}.default({{{defaultValue}}}){{/if}}{{#if isEnum}}.oneOf({{{enumValues}}}, 'enum'){{/if}}.typeError('invalid'){{/if}},{{/each}}
|
|
5
5
|
});
|
package/lib/esm/generate.js
CHANGED
|
@@ -20,6 +20,7 @@ const _findDecls = (name, fields, decls) => {
|
|
|
20
20
|
}
|
|
21
21
|
return decls;
|
|
22
22
|
};
|
|
23
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
23
24
|
const defaultPrepareContext = (typeDef, ctx) => {
|
|
24
25
|
for (const fieldName of Object.keys(ctx.fields)) {
|
|
25
26
|
const field = ctx.fields[fieldName];
|
|
@@ -60,6 +61,7 @@ const defaultPrepareContext = (typeDef, ctx) => {
|
|
|
60
61
|
field.isEnum = true;
|
|
61
62
|
field.enumValues = JSON.stringify(field.items.map((i) => i.value));
|
|
62
63
|
}
|
|
64
|
+
field.Name = capitalize(field.name);
|
|
63
65
|
}
|
|
64
66
|
ctx.typeName = typeDef.typeName;
|
|
65
67
|
ctx.curlyOpen = "{";
|
|
@@ -82,6 +84,7 @@ export const generate = (typeDef, templatePath, opts) => {
|
|
|
82
84
|
const typeContext = defaultPrepareContext(typeDef, {
|
|
83
85
|
typeDef,
|
|
84
86
|
name: decl.name,
|
|
87
|
+
Name: capitalize(decl.name),
|
|
85
88
|
fields: decl.fields,
|
|
86
89
|
disclaimer: decls.length > 0 ? null : disclaimer,
|
|
87
90
|
first,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}
|
|
2
|
-
{{/if}}export type {{
|
|
2
|
+
{{/if}}export type {{ Name }}Type = {{#if root}}{
|
|
3
3
|
_meta?: {
|
|
4
4
|
id: string;
|
|
5
5
|
version: string;
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
mtime: number;
|
|
9
9
|
};
|
|
10
10
|
{{else}}{
|
|
11
|
-
{{/if}}{{#each fields}} {{
|
|
11
|
+
{{/if}}{{#each fields}} {{name}}{{#if optional}}?{{/if}}: {{#if typeIsObject}}{{ ../Name }}_{{name}}Type{{else if typeIsArray}}{{valueType}}[]{{else}}{{type}}{{/if}};
|
|
12
12
|
{{/each}}
|
|
13
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}
|
|
2
2
|
import * as yup from "yup";{{/if}}
|
|
3
|
-
export const {{
|
|
4
|
-
{{name}}: {{#if typeIsObject}}{{ ../
|
|
3
|
+
export const {{Name}}Schema = yup.object({{{curlyOpen}}}{{#each fields}}
|
|
4
|
+
{{name}}: {{#if typeIsObject}}{{ ../Name }}_{{name}}Schema{{else}}{{#if typeIsArray}}yup.array(yup.{{valueType}}),{{else}}yup.{{type}}(){{/if}}{{#if required}}.required('required'){{/if}}{{#if minValue}}.min({{minValue}}, 'minValue'){{/if}}{{#if maxValue}}.max({{maxValue}}, 'maxValue'){{/if}}{{#if min}}.min({{min}}, 'min'){{/if}}{{#if max}}.max({{max}}, 'max'){{/if}}{{#if regex}}.matches({{{regexValue}}}, 'regex'){{/if}}{{#if default}}.default({{{defaultValue}}}){{/if}}{{#if isEnum}}.oneOf({{{enumValues}}}, 'enum'){{/if}}.typeError('invalid'){{/if}},{{/each}}
|
|
5
5
|
});
|