mobiletto-orm-typedef-gen 2.1.13 → 2.1.14
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.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type TypeDeclaration = {
|
|
|
8
8
|
export type GenerateOptions = {
|
|
9
9
|
outfile?: string;
|
|
10
10
|
header?: string;
|
|
11
|
+
typescript?: boolean;
|
|
11
12
|
name?: string;
|
|
12
13
|
disclaimer?: string;
|
|
13
14
|
prepareContext?: (typeDef: MobilettoOrmTypeDef, ctx: Record<string, unknown>) => Record<string, unknown>;
|
package/lib/cjs/generate.js
CHANGED
|
@@ -80,6 +80,12 @@ const defaultPrepareContext = (typeDef, ctx) => {
|
|
|
80
80
|
field.whenFieldNamesQuoted = field.whenFieldNames
|
|
81
81
|
.filter((f) => f !== fieldName)
|
|
82
82
|
.map((f) => JSON.stringify(f));
|
|
83
|
+
field.whenFieldSignature = field.whenFieldNames
|
|
84
|
+
.map((f) => {
|
|
85
|
+
const fld = ctx.fields[f];
|
|
86
|
+
return f + (fld.required ? "" : "?") + ": " + fld.type;
|
|
87
|
+
})
|
|
88
|
+
.join(", ");
|
|
83
89
|
}
|
|
84
90
|
if (field.test && field.test.message && field.test.valid) {
|
|
85
91
|
field.testCode = field.test.valid.toString();
|
|
@@ -98,6 +104,7 @@ export const generate = (typeDef, templatePath, opts) => {
|
|
|
98
104
|
if (!(typeDef instanceof MobilettoOrmTypeDef)) {
|
|
99
105
|
typeDef = new MobilettoOrmTypeDef(typeDef);
|
|
100
106
|
}
|
|
107
|
+
const typescript = !opts || opts.typescript !== false;
|
|
101
108
|
const disclaimer = (opts === null || opts === void 0 ? void 0 : opts.disclaimer) ? opts.disclaimer : STANDARD_AUTOGEN_FILE_DISCLAIMER;
|
|
102
109
|
const name = (opts === null || opts === void 0 ? void 0 : opts.name) ? opts.name : typeDef.typeName;
|
|
103
110
|
const decls = [...findDecls(name, typeDef.fields), { name, fields: typeDef.fields, root: true }];
|
|
@@ -117,6 +124,7 @@ export const generate = (typeDef, templatePath, opts) => {
|
|
|
117
124
|
header: decls.length > 0 ? null : opts === null || opts === void 0 ? void 0 : opts.header,
|
|
118
125
|
first,
|
|
119
126
|
root: decl.root || false,
|
|
127
|
+
typescript,
|
|
120
128
|
});
|
|
121
129
|
const preparedContext = (opts === null || opts === void 0 ? void 0 : opts.prepareContext) ? opts.prepareContext(typeDef, typeContext) : typeContext;
|
|
122
130
|
first = false;
|
|
@@ -18,15 +18,15 @@ export const {{Name}}Schema = yup.object({{{curlyOpen}}}{{#each fields}}
|
|
|
18
18
|
name: "{{test.message}}",
|
|
19
19
|
message: '{{fullName}}_{{test.message}}',
|
|
20
20
|
skipAbsent: true,
|
|
21
|
-
test(value, ctx) {
|
|
21
|
+
test(value{{#if typescript}}: string | number | boolean | null | undefined{{/if}}, ctx) {
|
|
22
22
|
const t = {{{testCode}}};
|
|
23
23
|
return typeof value === "undefined" || value == null || t({ ...ctx.parent });
|
|
24
24
|
}
|
|
25
25
|
}){{/if}}{{#if hasWhen}}
|
|
26
26
|
.when([{{{whenFieldNamesQuoted}}}], {
|
|
27
|
-
is: ({{whenFieldNames}}) => {
|
|
27
|
+
is: ({{#if typescript}}{{whenFieldSignature}}{{else}}{{whenFieldNames}}{{/if}}) => {
|
|
28
28
|
const w = {{{whenCode}}};
|
|
29
|
-
const v = { {{whenFieldNames}} };
|
|
29
|
+
const v{{#if typescript}}: Record<string, unknown>{{/if}} = { {{whenFieldNames}} };
|
|
30
30
|
return w(v);
|
|
31
31
|
},
|
|
32
32
|
then: (schema) => schema.required('{{fullName}}_required'),
|
package/lib/esm/generate.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type TypeDeclaration = {
|
|
|
8
8
|
export type GenerateOptions = {
|
|
9
9
|
outfile?: string;
|
|
10
10
|
header?: string;
|
|
11
|
+
typescript?: boolean;
|
|
11
12
|
name?: string;
|
|
12
13
|
disclaimer?: string;
|
|
13
14
|
prepareContext?: (typeDef: MobilettoOrmTypeDef, ctx: Record<string, unknown>) => Record<string, unknown>;
|
package/lib/esm/generate.js
CHANGED
|
@@ -80,6 +80,12 @@ const defaultPrepareContext = (typeDef, ctx) => {
|
|
|
80
80
|
field.whenFieldNamesQuoted = field.whenFieldNames
|
|
81
81
|
.filter((f) => f !== fieldName)
|
|
82
82
|
.map((f) => JSON.stringify(f));
|
|
83
|
+
field.whenFieldSignature = field.whenFieldNames
|
|
84
|
+
.map((f) => {
|
|
85
|
+
const fld = ctx.fields[f];
|
|
86
|
+
return f + (fld.required ? "" : "?") + ": " + fld.type;
|
|
87
|
+
})
|
|
88
|
+
.join(", ");
|
|
83
89
|
}
|
|
84
90
|
if (field.test && field.test.message && field.test.valid) {
|
|
85
91
|
field.testCode = field.test.valid.toString();
|
|
@@ -98,6 +104,7 @@ export const generate = (typeDef, templatePath, opts) => {
|
|
|
98
104
|
if (!(typeDef instanceof MobilettoOrmTypeDef)) {
|
|
99
105
|
typeDef = new MobilettoOrmTypeDef(typeDef);
|
|
100
106
|
}
|
|
107
|
+
const typescript = !opts || opts.typescript !== false;
|
|
101
108
|
const disclaimer = (opts === null || opts === void 0 ? void 0 : opts.disclaimer) ? opts.disclaimer : STANDARD_AUTOGEN_FILE_DISCLAIMER;
|
|
102
109
|
const name = (opts === null || opts === void 0 ? void 0 : opts.name) ? opts.name : typeDef.typeName;
|
|
103
110
|
const decls = [...findDecls(name, typeDef.fields), { name, fields: typeDef.fields, root: true }];
|
|
@@ -117,6 +124,7 @@ export const generate = (typeDef, templatePath, opts) => {
|
|
|
117
124
|
header: decls.length > 0 ? null : opts === null || opts === void 0 ? void 0 : opts.header,
|
|
118
125
|
first,
|
|
119
126
|
root: decl.root || false,
|
|
127
|
+
typescript,
|
|
120
128
|
});
|
|
121
129
|
const preparedContext = (opts === null || opts === void 0 ? void 0 : opts.prepareContext) ? opts.prepareContext(typeDef, typeContext) : typeContext;
|
|
122
130
|
first = false;
|
|
@@ -18,15 +18,15 @@ export const {{Name}}Schema = yup.object({{{curlyOpen}}}{{#each fields}}
|
|
|
18
18
|
name: "{{test.message}}",
|
|
19
19
|
message: '{{fullName}}_{{test.message}}',
|
|
20
20
|
skipAbsent: true,
|
|
21
|
-
test(value, ctx) {
|
|
21
|
+
test(value{{#if typescript}}: string | number | boolean | null | undefined{{/if}}, ctx) {
|
|
22
22
|
const t = {{{testCode}}};
|
|
23
23
|
return typeof value === "undefined" || value == null || t({ ...ctx.parent });
|
|
24
24
|
}
|
|
25
25
|
}){{/if}}{{#if hasWhen}}
|
|
26
26
|
.when([{{{whenFieldNamesQuoted}}}], {
|
|
27
|
-
is: ({{whenFieldNames}}) => {
|
|
27
|
+
is: ({{#if typescript}}{{whenFieldSignature}}{{else}}{{whenFieldNames}}{{/if}}) => {
|
|
28
28
|
const w = {{{whenCode}}};
|
|
29
|
-
const v = { {{whenFieldNames}} };
|
|
29
|
+
const v{{#if typescript}}: Record<string, unknown>{{/if}} = { {{whenFieldNames}} };
|
|
30
30
|
return w(v);
|
|
31
31
|
},
|
|
32
32
|
then: (schema) => schema.required('{{fullName}}_required'),
|