vovk 3.0.0-draft.375 → 3.0.0-draft.376

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.
@@ -32,33 +32,51 @@ function isTextFormat(mimeType) {
32
32
  }
33
33
  function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValidation, bodyValidation, paramsValidation, outputValidation, iterationValidation, hasArg, }) {
34
34
  const getTsSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: true, indent: indent ?? 4 });
35
- const getTsFormSample = (schema, indent, nesting = 0) => {
35
+ const getTsFormSample = (schema) => {
36
36
  let formSample = 'const formData = new FormData();';
37
37
  for (const [key, prop] of Object.entries(schema.properties || {})) {
38
38
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
39
- let sampleValue;
40
- if (target.type === 'string' && target.format === 'binary') {
41
- sampleValue = `new Blob(${isTextFormat(target.contentMediaType) ? '["text_content"]' : '[binary_data]'}${target.contentMediaType ? `, { type: "${target.contentMediaType}" }` : ''})`;
42
- }
43
- else if (target.type === 'array') {
44
- if (nesting === 0 && target.items) {
45
- sampleValue +=
46
- getTsFormSample(target.items, indent, nesting + 1) + getTsFormSample(target.items, indent, nesting + 1);
47
- }
48
- else {
49
- sampleValue += '"array_unknown"';
50
- }
51
- }
52
- else if (target.type === 'object') {
53
- sampleValue += '"object_unknown"';
39
+ if (target.type === 'array') {
40
+ formSample += getTsFormAppend(target, key);
41
+ formSample += getTsFormAppend(target, key);
54
42
  }
55
43
  else {
56
- sampleValue += `"${(0, getJSONSchemaExample_1.getSampleValue)(target)}"`;
44
+ formSample += getTsFormAppend(target, key);
45
+ }
46
+ /* if (target.type === 'string' && target.format === 'binary') {
47
+ sampleValue = `new Blob(${isTextFormat(target.contentMediaType) ? '["text_content"]' : '[binary_data]'}${
48
+ target.contentMediaType ? `, { type: "${target.contentMediaType}" }` : ''
49
+ })`;
50
+ } else if (target.type === 'array') {
51
+ if (nesting === 0 && target.items) {
52
+ sampleValue +=
53
+ getTsFormSample(target.items, indent, nesting + 1) + getTsFormSample(target.items, indent, nesting + 1);
54
+ } else {
55
+ sampleValue += '"array_unknown"';
56
+ }
57
+ } else if (target.type === 'object') {
58
+ sampleValue += '"object_unknown"';
59
+ } else {
60
+ sampleValue += `"${getSampleValue(target)}"`;
57
61
  }
58
- formSample += `\nform.append("${key}", ${sampleValue});`;
62
+
63
+ formSample += `\n${getIndentSpaces(4)}form.append("${key}", ${sampleValue});`; */
59
64
  }
60
65
  return formSample;
61
66
  };
67
+ const getTsFormAppend = (schema, key) => {
68
+ let sampleValue;
69
+ if (schema.type === 'string' && schema.format === 'binary') {
70
+ sampleValue = `new Blob(${isTextFormat(schema.contentMediaType) ? '["text_content"]' : '[binary_data]'}${schema.contentMediaType ? `, { type: "${schema.contentMediaType}" }` : ''})`;
71
+ }
72
+ else if (schema.type === 'object') {
73
+ sampleValue = '"object_unknown"';
74
+ }
75
+ else {
76
+ sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
77
+ }
78
+ return `\n${getIndentSpaces(4)}formData.append("${key}", ${sampleValue});`;
79
+ };
62
80
  const tsArgs = hasArg
63
81
  ? `{
64
82
  ${[
@@ -32,33 +32,51 @@ function isTextFormat(mimeType) {
32
32
  }
33
33
  function generateTypeScriptCode({ handlerName, rpcName, packageName, queryValidation, bodyValidation, paramsValidation, outputValidation, iterationValidation, hasArg, }) {
34
34
  const getTsSample = (schema, indent) => (0, getJSONSchemaExample_1.getJSONSchemaExample)(schema, { stripQuotes: true, indent: indent ?? 4 });
35
- const getTsFormSample = (schema, indent, nesting = 0) => {
35
+ const getTsFormSample = (schema) => {
36
36
  let formSample = 'const formData = new FormData();';
37
37
  for (const [key, prop] of Object.entries(schema.properties || {})) {
38
38
  const target = prop.oneOf?.[0] || prop.anyOf?.[0] || prop.allOf?.[0] || prop;
39
- let sampleValue;
40
- if (target.type === 'string' && target.format === 'binary') {
41
- sampleValue = `new Blob(${isTextFormat(target.contentMediaType) ? '["text_content"]' : '[binary_data]'}${target.contentMediaType ? `, { type: "${target.contentMediaType}" }` : ''})`;
42
- }
43
- else if (target.type === 'array') {
44
- if (nesting === 0 && target.items) {
45
- sampleValue +=
46
- getTsFormSample(target.items, indent, nesting + 1) + getTsFormSample(target.items, indent, nesting + 1);
47
- }
48
- else {
49
- sampleValue += '"array_unknown"';
50
- }
51
- }
52
- else if (target.type === 'object') {
53
- sampleValue += '"object_unknown"';
39
+ if (target.type === 'array') {
40
+ formSample += getTsFormAppend(target, key);
41
+ formSample += getTsFormAppend(target, key);
54
42
  }
55
43
  else {
56
- sampleValue += `"${(0, getJSONSchemaExample_1.getSampleValue)(target)}"`;
44
+ formSample += getTsFormAppend(target, key);
45
+ }
46
+ /* if (target.type === 'string' && target.format === 'binary') {
47
+ sampleValue = `new Blob(${isTextFormat(target.contentMediaType) ? '["text_content"]' : '[binary_data]'}${
48
+ target.contentMediaType ? `, { type: "${target.contentMediaType}" }` : ''
49
+ })`;
50
+ } else if (target.type === 'array') {
51
+ if (nesting === 0 && target.items) {
52
+ sampleValue +=
53
+ getTsFormSample(target.items, indent, nesting + 1) + getTsFormSample(target.items, indent, nesting + 1);
54
+ } else {
55
+ sampleValue += '"array_unknown"';
56
+ }
57
+ } else if (target.type === 'object') {
58
+ sampleValue += '"object_unknown"';
59
+ } else {
60
+ sampleValue += `"${getSampleValue(target)}"`;
57
61
  }
58
- formSample += `\nform.append("${key}", ${sampleValue});`;
62
+
63
+ formSample += `\n${getIndentSpaces(4)}form.append("${key}", ${sampleValue});`; */
59
64
  }
60
65
  return formSample;
61
66
  };
67
+ const getTsFormAppend = (schema, key) => {
68
+ let sampleValue;
69
+ if (schema.type === 'string' && schema.format === 'binary') {
70
+ sampleValue = `new Blob(${isTextFormat(schema.contentMediaType) ? '["text_content"]' : '[binary_data]'}${schema.contentMediaType ? `, { type: "${schema.contentMediaType}" }` : ''})`;
71
+ }
72
+ else if (schema.type === 'object') {
73
+ sampleValue = '"object_unknown"';
74
+ }
75
+ else {
76
+ sampleValue = `"${(0, getJSONSchemaExample_1.getSampleValue)(schema)}"`;
77
+ }
78
+ return `\n${getIndentSpaces(4)}formData.append("${key}", ${sampleValue});`;
79
+ };
62
80
  const tsArgs = hasArg
63
81
  ? `{
64
82
  ${[
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.375",
3
+ "version": "3.0.0-draft.376",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",