speedly 2.0.34 → 2.0.36

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.
@@ -116,7 +116,7 @@ function routeAnalyzer(route, routerName) {
116
116
  doc.parameters = pathParams.map((name) => ({
117
117
  name,
118
118
  in: "path",
119
- required: validation?.params?.fields?.[name]?.required ||
119
+ required: validation?.params?.fields?.[name]?.spec?.optional == false ||
120
120
  !new RegExp(`\\{[^\\}]*${name}[^\\}]*\\}`).test(route.path),
121
121
  schema: { type: "string" },
122
122
  }));
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
7
  const translation_1 = __importDefault(require("./../model/translation"));
8
8
  const getConfig_1 = __importDefault(require("./getConfig"));
9
- const configs = { ...(0, getConfig_1.default)('translate') };
9
+ const configs = { ...(0, getConfig_1.default)("translate") };
10
10
  async function firstSuccessful(promises) {
11
11
  return new Promise((resolve, reject) => {
12
12
  let rejections = 0;
@@ -27,7 +27,10 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
27
27
  const formattedText = text
28
28
  .replaceAll(/[\-\_]/g, " ")
29
29
  .replaceAll(/[A-Z]/g, " $&");
30
- const translationDoc = await translation_1.default.findOne({ text: formattedText, lang });
30
+ const translationDoc = await translation_1.default.findOne({
31
+ text: formattedText,
32
+ lang,
33
+ });
31
34
  if (translationDoc)
32
35
  return translationDoc.translatedText;
33
36
  const translationPromises = [];
@@ -37,27 +40,30 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
37
40
  throw new Error("Translation failed");
38
41
  return res.data.response.translated_text;
39
42
  })());
40
- if (configs.one_api_token)
41
- translationPromises.push((async () => {
42
- const res = await axios_1.default.post("https://api.one-api.ir/translate/v1/microsoft", {
43
- text: formattedText,
44
- target: lang,
45
- }, {
46
- timeout: 2000,
47
- headers: {
48
- "one-api-token": configs.one_api_token
49
- },
50
- });
51
- if (res.data.status === 200) {
52
- return res.data.result;
53
- }
54
- else {
55
- throw new Error(res.data.message);
56
- }
57
- })());
43
+ translationPromises.push((async () => {
44
+ const res = await axios_1.default.post("https://api.one-api.ir/translate/v1/microsoft", {
45
+ text: formattedText,
46
+ target: lang,
47
+ }, {
48
+ timeout: 2000,
49
+ headers: {
50
+ "one-api-token": "783122:68a02b5c4dcee",
51
+ },
52
+ });
53
+ if (res.data.status === 200) {
54
+ return res.data.result;
55
+ }
56
+ else {
57
+ throw new Error(res.data.message);
58
+ }
59
+ })());
58
60
  try {
59
61
  const result = await firstSuccessful(translationPromises);
60
- await translation_1.default.create({ text: formattedText, lang, translatedText: result });
62
+ await translation_1.default.create({
63
+ text: formattedText,
64
+ lang,
65
+ translatedText: result,
66
+ });
61
67
  return result;
62
68
  }
63
69
  catch (err) {
@@ -116,7 +116,7 @@ function routeAnalyzer(route, routerName) {
116
116
  doc.parameters = pathParams.map((name) => ({
117
117
  name,
118
118
  in: "path",
119
- required: validation?.params?.fields?.[name]?.required ||
119
+ required: validation?.params?.fields?.[name]?.spec?.optional == false ||
120
120
  !new RegExp(`\\{[^\\}]*${name}[^\\}]*\\}`).test(route.path),
121
121
  schema: { type: "string" },
122
122
  }));
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
7
  const translation_1 = __importDefault(require("./../model/translation"));
8
8
  const getConfig_1 = __importDefault(require("./getConfig"));
9
- const configs = { ...(0, getConfig_1.default)('translate') };
9
+ const configs = { ...(0, getConfig_1.default)("translate") };
10
10
  async function firstSuccessful(promises) {
11
11
  return new Promise((resolve, reject) => {
12
12
  let rejections = 0;
@@ -27,7 +27,10 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
27
27
  const formattedText = text
28
28
  .replaceAll(/[\-\_]/g, " ")
29
29
  .replaceAll(/[A-Z]/g, " $&");
30
- const translationDoc = await translation_1.default.findOne({ text: formattedText, lang });
30
+ const translationDoc = await translation_1.default.findOne({
31
+ text: formattedText,
32
+ lang,
33
+ });
31
34
  if (translationDoc)
32
35
  return translationDoc.translatedText;
33
36
  const translationPromises = [];
@@ -37,27 +40,30 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
37
40
  throw new Error("Translation failed");
38
41
  return res.data.response.translated_text;
39
42
  })());
40
- if (configs.one_api_token)
41
- translationPromises.push((async () => {
42
- const res = await axios_1.default.post("https://api.one-api.ir/translate/v1/microsoft", {
43
- text: formattedText,
44
- target: lang,
45
- }, {
46
- timeout: 2000,
47
- headers: {
48
- "one-api-token": configs.one_api_token
49
- },
50
- });
51
- if (res.data.status === 200) {
52
- return res.data.result;
53
- }
54
- else {
55
- throw new Error(res.data.message);
56
- }
57
- })());
43
+ translationPromises.push((async () => {
44
+ const res = await axios_1.default.post("https://api.one-api.ir/translate/v1/microsoft", {
45
+ text: formattedText,
46
+ target: lang,
47
+ }, {
48
+ timeout: 2000,
49
+ headers: {
50
+ "one-api-token": "783122:68a02b5c4dcee",
51
+ },
52
+ });
53
+ if (res.data.status === 200) {
54
+ return res.data.result;
55
+ }
56
+ else {
57
+ throw new Error(res.data.message);
58
+ }
59
+ })());
58
60
  try {
59
61
  const result = await firstSuccessful(translationPromises);
60
- await translation_1.default.create({ text: formattedText, lang, translatedText: result });
62
+ await translation_1.default.create({
63
+ text: formattedText,
64
+ lang,
65
+ translatedText: result,
66
+ });
61
67
  return result;
62
68
  }
63
69
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "2.0.34",
3
+ "version": "2.0.36",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",