@navservice/core 1.37.0 → 1.40.0
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/build/es/helpers/_data.d.ts +5 -0
- package/build/es/helpers/_set_response.d.ts +3 -8
- package/build/es/helpers/index.d.ts +12 -17
- package/build/es/helpers.js +60 -26
- package/build/es/index.node.js +54 -21
- package/build/lib/helpers/_data.d.ts +5 -0
- package/build/lib/helpers/_set_response.d.ts +3 -8
- package/build/lib/helpers/index.d.ts +12 -17
- package/build/lib/helpers.cjs +59 -21
- package/build/lib/index.node.cjs +59 -21
- package/package.json +2 -2
|
@@ -29,13 +29,6 @@ declare const set_response: {
|
|
|
29
29
|
}, 201, "json">);
|
|
30
30
|
WARNING<T>({ message, results, c }: ResponseCOmmit): void;
|
|
31
31
|
AUTHORIZATION_ERROR<T>({ message, results, c }: ResponseCOmmit): void;
|
|
32
|
-
DATABASE_ERROR<T>({ message, results, c }: ResponseCOmmit): ResponseCPayload<T> | (Response & import("hono").TypedResponse<{
|
|
33
|
-
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
34
|
-
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
35
|
-
type: "success" | "warning" | "error";
|
|
36
|
-
message?: string | undefined;
|
|
37
|
-
results: any;
|
|
38
|
-
}, 500, "json">);
|
|
39
32
|
SERVER_ERROR<T>({ error, c }: {
|
|
40
33
|
error: any;
|
|
41
34
|
c: t.Context;
|
|
@@ -74,7 +67,9 @@ declare const set_response: {
|
|
|
74
67
|
ACTION_REQUIRED({ message, results }: ResponseErrorOmmit): void;
|
|
75
68
|
WARNING({ message, results }: ResponseErrorOmmit): void;
|
|
76
69
|
AUTHORIZATION_ERROR({ message, results }: ResponseErrorOmmit): void;
|
|
77
|
-
DATABASE_ERROR({ message, results }: ResponseErrorOmmit
|
|
70
|
+
DATABASE_ERROR({ message, results, erro }: ResponseErrorOmmit & {
|
|
71
|
+
erro: any;
|
|
72
|
+
}): void;
|
|
78
73
|
SCHEMA_VALIDATION({ results }: ResponseErrorOmmit): void;
|
|
79
74
|
UNAUTHORIZED({ message }: ResponseErrorOmmit): void;
|
|
80
75
|
INVALID_TOKEN({ message }: ResponseErrorOmmit): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _secret from "./_secret";
|
|
2
|
-
declare
|
|
3
|
-
|
|
2
|
+
declare const helpers: {
|
|
3
|
+
set_response: {
|
|
4
4
|
new (): {};
|
|
5
5
|
c: {
|
|
6
6
|
new (): {};
|
|
@@ -47,17 +47,6 @@ declare class helpers {
|
|
|
47
47
|
results: any;
|
|
48
48
|
c: import("../types").default.Context;
|
|
49
49
|
}): void;
|
|
50
|
-
DATABASE_ERROR<T>({ message, results, c }: {
|
|
51
|
-
message?: string | undefined;
|
|
52
|
-
results: any;
|
|
53
|
-
c: import("../types").default.Context;
|
|
54
|
-
}): import("./_set_response").ResponseCPayload<T> | (Response & import("hono").TypedResponse<{
|
|
55
|
-
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
56
|
-
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
57
|
-
type: "success" | "warning" | "error";
|
|
58
|
-
message?: string | undefined;
|
|
59
|
-
results: any;
|
|
60
|
-
}, 500, "json">);
|
|
61
50
|
SERVER_ERROR<T>({ error, c }: {
|
|
62
51
|
error: any;
|
|
63
52
|
c: import("../types").default.Context;
|
|
@@ -117,9 +106,11 @@ declare class helpers {
|
|
|
117
106
|
message?: string | undefined;
|
|
118
107
|
results?: unknown;
|
|
119
108
|
}): void;
|
|
120
|
-
DATABASE_ERROR({ message, results }: {
|
|
109
|
+
DATABASE_ERROR({ message, results, erro }: {
|
|
121
110
|
message?: string | undefined;
|
|
122
111
|
results?: unknown;
|
|
112
|
+
} & {
|
|
113
|
+
erro: any;
|
|
123
114
|
}): void;
|
|
124
115
|
SCHEMA_VALIDATION({ results }: {
|
|
125
116
|
message?: string | undefined;
|
|
@@ -139,7 +130,7 @@ declare class helpers {
|
|
|
139
130
|
}): void;
|
|
140
131
|
};
|
|
141
132
|
};
|
|
142
|
-
|
|
133
|
+
token: {
|
|
143
134
|
new (): {};
|
|
144
135
|
verificar_token(c: import("../types").default.Context, next: import("hono").Next): Promise<void | import("./_set_response").ResponseCPayload<unknown> | (Response & import("hono").TypedResponse<{
|
|
145
136
|
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
@@ -152,6 +143,10 @@ declare class helpers {
|
|
|
152
143
|
c: import("../types").default.Context;
|
|
153
144
|
}): Promise<string>;
|
|
154
145
|
};
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
secret: typeof _secret;
|
|
147
|
+
data: {
|
|
148
|
+
get_now_format_number: number;
|
|
149
|
+
verificar_data: (value: number) => number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
157
152
|
export default helpers;
|
package/build/es/helpers.js
CHANGED
|
@@ -68,18 +68,6 @@ const set_response = class {
|
|
|
68
68
|
});
|
|
69
69
|
throw payload;
|
|
70
70
|
}
|
|
71
|
-
static DATABASE_ERROR({ message, results, c }) {
|
|
72
|
-
const payload = {
|
|
73
|
-
status: 500,
|
|
74
|
-
code: "DATABASE_ERROR",
|
|
75
|
-
type: "error",
|
|
76
|
-
message: message || "Erro no banco de dados!",
|
|
77
|
-
results: results || []
|
|
78
|
-
};
|
|
79
|
-
return c ? c.json(payload, {
|
|
80
|
-
status: 500
|
|
81
|
-
}) : payload;
|
|
82
|
-
}
|
|
83
71
|
static SERVER_ERROR({ error, c }) {
|
|
84
72
|
if (error instanceof v4.ZodError) {
|
|
85
73
|
const payload = {
|
|
@@ -194,13 +182,48 @@ const set_response = class {
|
|
|
194
182
|
};
|
|
195
183
|
throw payload;
|
|
196
184
|
}
|
|
197
|
-
static DATABASE_ERROR({ message, results }) {
|
|
185
|
+
static DATABASE_ERROR({ message, results, erro }) {
|
|
186
|
+
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
187
|
+
const map = {
|
|
188
|
+
SQLITE_CONSTRAINT_UNIQUE: {
|
|
189
|
+
status: 409,
|
|
190
|
+
message: "Registro duplicado. Violação de UNIQUE."
|
|
191
|
+
},
|
|
192
|
+
SQLITE_CONSTRAINT_FOREIGNKEY: {
|
|
193
|
+
status: 409,
|
|
194
|
+
message: "Registro relacionado não encontrado (FOREIGN KEY)."
|
|
195
|
+
},
|
|
196
|
+
SQLITE_CONSTRAINT_NOTNULL: {
|
|
197
|
+
status: 400,
|
|
198
|
+
message: "Campo obrigatório ausente."
|
|
199
|
+
},
|
|
200
|
+
SQLITE_CONSTRAINT_CHECK: {
|
|
201
|
+
status: 400,
|
|
202
|
+
message: "Regra de validação violada."
|
|
203
|
+
},
|
|
204
|
+
SQLITE_CONSTRAINT_PRIMARYKEY: {
|
|
205
|
+
status: 409,
|
|
206
|
+
message: "Chave primária duplicada."
|
|
207
|
+
},
|
|
208
|
+
SQLITE_BUSY: {
|
|
209
|
+
status: 503,
|
|
210
|
+
message: "Banco ocupado. Tente novamente."
|
|
211
|
+
},
|
|
212
|
+
SQLITE_READONLY: {
|
|
213
|
+
status: 500,
|
|
214
|
+
message: "Banco de dados em modo somente leitura."
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const causeMessage = erro?.cause?.message;
|
|
218
|
+
const isUniqueMessage = causeMessage?.includes("UNIQUE constraint failed");
|
|
219
|
+
const isForeignMessage = causeMessage?.includes("FOREIGN KEY constraint failed");
|
|
220
|
+
const mapped = map[errorCode] || (isUniqueMessage ? map["SQLITE_CONSTRAINT_UNIQUE"] : null) || (isForeignMessage ? map["SQLITE_CONSTRAINT_FOREIGNKEY"] : null);
|
|
198
221
|
const payload = {
|
|
199
|
-
status:
|
|
222
|
+
status: mapped?.status || 500,
|
|
200
223
|
code: "DATABASE_ERROR",
|
|
201
224
|
type: "error",
|
|
202
|
-
message: message || "Erro no banco de dados!",
|
|
203
|
-
results:
|
|
225
|
+
message: mapped?.message || message || "Erro no banco de dados!",
|
|
226
|
+
results: []
|
|
204
227
|
};
|
|
205
228
|
throw payload;
|
|
206
229
|
}
|
|
@@ -268,11 +291,21 @@ class _secret {
|
|
|
268
291
|
}
|
|
269
292
|
}
|
|
270
293
|
const helpers_secret = _secret;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
294
|
+
const _data = {
|
|
295
|
+
get_now_format_number: Math.floor(Date.now() / 1000),
|
|
296
|
+
verificar_data: (value)=>{
|
|
297
|
+
const data = new Date(1000 * value);
|
|
298
|
+
if (isNaN(data.getTime())) throw new Error("Timestamp está inválido.");
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const helpers_data = _data;
|
|
303
|
+
const helpers = {
|
|
304
|
+
set_response: _set_response,
|
|
305
|
+
token: helpers_token,
|
|
306
|
+
secret: helpers_secret,
|
|
307
|
+
data: helpers_data
|
|
308
|
+
};
|
|
276
309
|
const src_helpers = helpers;
|
|
277
310
|
const _token = class {
|
|
278
311
|
static async verificar_token(c, next) {
|
|
@@ -338,10 +371,11 @@ const _token = class {
|
|
|
338
371
|
}
|
|
339
372
|
};
|
|
340
373
|
const helpers_token = _token;
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
374
|
+
const helpers_helpers = {
|
|
375
|
+
set_response: _set_response,
|
|
376
|
+
token: helpers_token,
|
|
377
|
+
secret: helpers_secret,
|
|
378
|
+
data: helpers_data
|
|
379
|
+
};
|
|
346
380
|
const src_helpers_0 = helpers_helpers;
|
|
347
381
|
export { src_helpers_0 as default };
|
package/build/es/index.node.js
CHANGED
|
@@ -68,18 +68,6 @@ const set_response = class {
|
|
|
68
68
|
});
|
|
69
69
|
throw payload;
|
|
70
70
|
}
|
|
71
|
-
static DATABASE_ERROR({ message, results, c }) {
|
|
72
|
-
const payload = {
|
|
73
|
-
status: 500,
|
|
74
|
-
code: "DATABASE_ERROR",
|
|
75
|
-
type: "error",
|
|
76
|
-
message: message || "Erro no banco de dados!",
|
|
77
|
-
results: results || []
|
|
78
|
-
};
|
|
79
|
-
return c ? c.json(payload, {
|
|
80
|
-
status: 500
|
|
81
|
-
}) : payload;
|
|
82
|
-
}
|
|
83
71
|
static SERVER_ERROR({ error, c }) {
|
|
84
72
|
if (error instanceof v4.ZodError) {
|
|
85
73
|
const payload = {
|
|
@@ -194,13 +182,48 @@ const set_response = class {
|
|
|
194
182
|
};
|
|
195
183
|
throw payload;
|
|
196
184
|
}
|
|
197
|
-
static DATABASE_ERROR({ message, results }) {
|
|
185
|
+
static DATABASE_ERROR({ message, results, erro }) {
|
|
186
|
+
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
187
|
+
const map = {
|
|
188
|
+
SQLITE_CONSTRAINT_UNIQUE: {
|
|
189
|
+
status: 409,
|
|
190
|
+
message: "Registro duplicado. Violação de UNIQUE."
|
|
191
|
+
},
|
|
192
|
+
SQLITE_CONSTRAINT_FOREIGNKEY: {
|
|
193
|
+
status: 409,
|
|
194
|
+
message: "Registro relacionado não encontrado (FOREIGN KEY)."
|
|
195
|
+
},
|
|
196
|
+
SQLITE_CONSTRAINT_NOTNULL: {
|
|
197
|
+
status: 400,
|
|
198
|
+
message: "Campo obrigatório ausente."
|
|
199
|
+
},
|
|
200
|
+
SQLITE_CONSTRAINT_CHECK: {
|
|
201
|
+
status: 400,
|
|
202
|
+
message: "Regra de validação violada."
|
|
203
|
+
},
|
|
204
|
+
SQLITE_CONSTRAINT_PRIMARYKEY: {
|
|
205
|
+
status: 409,
|
|
206
|
+
message: "Chave primária duplicada."
|
|
207
|
+
},
|
|
208
|
+
SQLITE_BUSY: {
|
|
209
|
+
status: 503,
|
|
210
|
+
message: "Banco ocupado. Tente novamente."
|
|
211
|
+
},
|
|
212
|
+
SQLITE_READONLY: {
|
|
213
|
+
status: 500,
|
|
214
|
+
message: "Banco de dados em modo somente leitura."
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const causeMessage = erro?.cause?.message;
|
|
218
|
+
const isUniqueMessage = causeMessage?.includes("UNIQUE constraint failed");
|
|
219
|
+
const isForeignMessage = causeMessage?.includes("FOREIGN KEY constraint failed");
|
|
220
|
+
const mapped = map[errorCode] || (isUniqueMessage ? map["SQLITE_CONSTRAINT_UNIQUE"] : null) || (isForeignMessage ? map["SQLITE_CONSTRAINT_FOREIGNKEY"] : null);
|
|
198
221
|
const payload = {
|
|
199
|
-
status:
|
|
222
|
+
status: mapped?.status || 500,
|
|
200
223
|
code: "DATABASE_ERROR",
|
|
201
224
|
type: "error",
|
|
202
|
-
message: message || "Erro no banco de dados!",
|
|
203
|
-
results:
|
|
225
|
+
message: mapped?.message || message || "Erro no banco de dados!",
|
|
226
|
+
results: []
|
|
204
227
|
};
|
|
205
228
|
throw payload;
|
|
206
229
|
}
|
|
@@ -332,10 +355,20 @@ class _secret {
|
|
|
332
355
|
}
|
|
333
356
|
}
|
|
334
357
|
const helpers_secret = _secret;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
358
|
+
const _data = {
|
|
359
|
+
get_now_format_number: Math.floor(Date.now() / 1000),
|
|
360
|
+
verificar_data: (value)=>{
|
|
361
|
+
const data = new Date(1000 * value);
|
|
362
|
+
if (isNaN(data.getTime())) throw new Error("Timestamp está inválido.");
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const helpers_data = _data;
|
|
367
|
+
const helpers = {
|
|
368
|
+
set_response: _set_response,
|
|
369
|
+
token: helpers_token,
|
|
370
|
+
secret: helpers_secret,
|
|
371
|
+
data: helpers_data
|
|
372
|
+
};
|
|
340
373
|
const src_helpers = helpers;
|
|
341
374
|
export { src_helpers as helpers };
|
|
@@ -29,13 +29,6 @@ declare const set_response: {
|
|
|
29
29
|
}, 201, "json">);
|
|
30
30
|
WARNING<T>({ message, results, c }: ResponseCOmmit): void;
|
|
31
31
|
AUTHORIZATION_ERROR<T>({ message, results, c }: ResponseCOmmit): void;
|
|
32
|
-
DATABASE_ERROR<T>({ message, results, c }: ResponseCOmmit): ResponseCPayload<T> | (Response & import("hono").TypedResponse<{
|
|
33
|
-
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
34
|
-
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
35
|
-
type: "success" | "warning" | "error";
|
|
36
|
-
message?: string | undefined;
|
|
37
|
-
results: any;
|
|
38
|
-
}, 500, "json">);
|
|
39
32
|
SERVER_ERROR<T>({ error, c }: {
|
|
40
33
|
error: any;
|
|
41
34
|
c: t.Context;
|
|
@@ -74,7 +67,9 @@ declare const set_response: {
|
|
|
74
67
|
ACTION_REQUIRED({ message, results }: ResponseErrorOmmit): void;
|
|
75
68
|
WARNING({ message, results }: ResponseErrorOmmit): void;
|
|
76
69
|
AUTHORIZATION_ERROR({ message, results }: ResponseErrorOmmit): void;
|
|
77
|
-
DATABASE_ERROR({ message, results }: ResponseErrorOmmit
|
|
70
|
+
DATABASE_ERROR({ message, results, erro }: ResponseErrorOmmit & {
|
|
71
|
+
erro: any;
|
|
72
|
+
}): void;
|
|
78
73
|
SCHEMA_VALIDATION({ results }: ResponseErrorOmmit): void;
|
|
79
74
|
UNAUTHORIZED({ message }: ResponseErrorOmmit): void;
|
|
80
75
|
INVALID_TOKEN({ message }: ResponseErrorOmmit): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _secret from "./_secret";
|
|
2
|
-
declare
|
|
3
|
-
|
|
2
|
+
declare const helpers: {
|
|
3
|
+
set_response: {
|
|
4
4
|
new (): {};
|
|
5
5
|
c: {
|
|
6
6
|
new (): {};
|
|
@@ -47,17 +47,6 @@ declare class helpers {
|
|
|
47
47
|
results: any;
|
|
48
48
|
c: import("../types").default.Context;
|
|
49
49
|
}): void;
|
|
50
|
-
DATABASE_ERROR<T>({ message, results, c }: {
|
|
51
|
-
message?: string | undefined;
|
|
52
|
-
results: any;
|
|
53
|
-
c: import("../types").default.Context;
|
|
54
|
-
}): import("./_set_response").ResponseCPayload<T> | (Response & import("hono").TypedResponse<{
|
|
55
|
-
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
56
|
-
code: "SUCCESS" | "ACTION_REQUIRED" | "CREATED" | "WARNING" | "AUTHORIZATION_ERROR" | "SCHEMA_VALIDATION" | "SERVER_ERROR" | "UNAUTHORIZED" | "INVALID_TOKEN" | "NOT_FOUND" | "SUCCESS_FILE" | "DATABASE_ERROR";
|
|
57
|
-
type: "success" | "warning" | "error";
|
|
58
|
-
message?: string | undefined;
|
|
59
|
-
results: any;
|
|
60
|
-
}, 500, "json">);
|
|
61
50
|
SERVER_ERROR<T>({ error, c }: {
|
|
62
51
|
error: any;
|
|
63
52
|
c: import("../types").default.Context;
|
|
@@ -117,9 +106,11 @@ declare class helpers {
|
|
|
117
106
|
message?: string | undefined;
|
|
118
107
|
results?: unknown;
|
|
119
108
|
}): void;
|
|
120
|
-
DATABASE_ERROR({ message, results }: {
|
|
109
|
+
DATABASE_ERROR({ message, results, erro }: {
|
|
121
110
|
message?: string | undefined;
|
|
122
111
|
results?: unknown;
|
|
112
|
+
} & {
|
|
113
|
+
erro: any;
|
|
123
114
|
}): void;
|
|
124
115
|
SCHEMA_VALIDATION({ results }: {
|
|
125
116
|
message?: string | undefined;
|
|
@@ -139,7 +130,7 @@ declare class helpers {
|
|
|
139
130
|
}): void;
|
|
140
131
|
};
|
|
141
132
|
};
|
|
142
|
-
|
|
133
|
+
token: {
|
|
143
134
|
new (): {};
|
|
144
135
|
verificar_token(c: import("../types").default.Context, next: import("hono").Next): Promise<void | import("./_set_response").ResponseCPayload<unknown> | (Response & import("hono").TypedResponse<{
|
|
145
136
|
status: 200 | 201 | 202 | 204 | 400 | 401 | 403 | 404 | 409 | 422 | 500 | 428 | 405;
|
|
@@ -152,6 +143,10 @@ declare class helpers {
|
|
|
152
143
|
c: import("../types").default.Context;
|
|
153
144
|
}): Promise<string>;
|
|
154
145
|
};
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
secret: typeof _secret;
|
|
147
|
+
data: {
|
|
148
|
+
get_now_format_number: number;
|
|
149
|
+
verificar_data: (value: number) => number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
157
152
|
export default helpers;
|
package/build/lib/helpers.cjs
CHANGED
|
@@ -130,18 +130,6 @@ const set_response = class set_response {
|
|
|
130
130
|
});
|
|
131
131
|
throw payload;
|
|
132
132
|
}
|
|
133
|
-
static DATABASE_ERROR({ message, results, c }) {
|
|
134
|
-
const payload = {
|
|
135
|
-
status: 500,
|
|
136
|
-
code: "DATABASE_ERROR",
|
|
137
|
-
type: "error",
|
|
138
|
-
message: message || "Erro no banco de dados!",
|
|
139
|
-
results: results || []
|
|
140
|
-
};
|
|
141
|
-
return c ? c.json(payload, {
|
|
142
|
-
status: 500
|
|
143
|
-
}) : payload;
|
|
144
|
-
}
|
|
145
133
|
static SERVER_ERROR({ error, c }) {
|
|
146
134
|
if (error instanceof (v4_default()).ZodError) {
|
|
147
135
|
const payload = {
|
|
@@ -256,13 +244,48 @@ const set_response = class set_response {
|
|
|
256
244
|
};
|
|
257
245
|
throw payload;
|
|
258
246
|
}
|
|
259
|
-
static DATABASE_ERROR({ message, results }) {
|
|
247
|
+
static DATABASE_ERROR({ message, results, erro }) {
|
|
248
|
+
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
249
|
+
const map = {
|
|
250
|
+
"SQLITE_CONSTRAINT_UNIQUE": {
|
|
251
|
+
status: 409,
|
|
252
|
+
message: "Registro duplicado. Violação de UNIQUE."
|
|
253
|
+
},
|
|
254
|
+
"SQLITE_CONSTRAINT_FOREIGNKEY": {
|
|
255
|
+
status: 409,
|
|
256
|
+
message: "Registro relacionado não encontrado (FOREIGN KEY)."
|
|
257
|
+
},
|
|
258
|
+
"SQLITE_CONSTRAINT_NOTNULL": {
|
|
259
|
+
status: 400,
|
|
260
|
+
message: "Campo obrigatório ausente."
|
|
261
|
+
},
|
|
262
|
+
"SQLITE_CONSTRAINT_CHECK": {
|
|
263
|
+
status: 400,
|
|
264
|
+
message: "Regra de validação violada."
|
|
265
|
+
},
|
|
266
|
+
"SQLITE_CONSTRAINT_PRIMARYKEY": {
|
|
267
|
+
status: 409,
|
|
268
|
+
message: "Chave primária duplicada."
|
|
269
|
+
},
|
|
270
|
+
"SQLITE_BUSY": {
|
|
271
|
+
status: 503,
|
|
272
|
+
message: "Banco ocupado. Tente novamente."
|
|
273
|
+
},
|
|
274
|
+
"SQLITE_READONLY": {
|
|
275
|
+
status: 500,
|
|
276
|
+
message: "Banco de dados em modo somente leitura."
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const causeMessage = erro?.cause?.message;
|
|
280
|
+
const isUniqueMessage = causeMessage?.includes("UNIQUE constraint failed");
|
|
281
|
+
const isForeignMessage = causeMessage?.includes("FOREIGN KEY constraint failed");
|
|
282
|
+
const mapped = map[errorCode] || (isUniqueMessage ? map["SQLITE_CONSTRAINT_UNIQUE"] : null) || (isForeignMessage ? map["SQLITE_CONSTRAINT_FOREIGNKEY"] : null);
|
|
260
283
|
const payload = {
|
|
261
|
-
status:
|
|
284
|
+
status: mapped?.status || 500,
|
|
262
285
|
code: "DATABASE_ERROR",
|
|
263
286
|
type: "error",
|
|
264
|
-
message: message || "Erro no banco de dados!",
|
|
265
|
-
results:
|
|
287
|
+
message: mapped?.message || message || "Erro no banco de dados!",
|
|
288
|
+
results: []
|
|
266
289
|
};
|
|
267
290
|
throw payload;
|
|
268
291
|
}
|
|
@@ -416,16 +439,31 @@ class _secret {
|
|
|
416
439
|
}
|
|
417
440
|
/* export default */ const helpers_secret = (_secret);
|
|
418
441
|
|
|
442
|
+
;// CONCATENATED MODULE: ./src/helpers/_data.ts
|
|
443
|
+
const _data = {
|
|
444
|
+
get_now_format_number: Math.floor(Date.now() / 1000),
|
|
445
|
+
verificar_data: (value)=>{
|
|
446
|
+
const data = new Date(value * 1000);
|
|
447
|
+
if (isNaN(data.getTime())) {
|
|
448
|
+
throw new Error("Timestamp está inválido.");
|
|
449
|
+
}
|
|
450
|
+
return value; // válido
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
/* export default */ const helpers_data = (_data);
|
|
454
|
+
|
|
419
455
|
;// CONCATENATED MODULE: ./src/helpers/index.ts
|
|
420
456
|
//_HELPERS
|
|
421
457
|
|
|
422
458
|
|
|
423
459
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
460
|
+
|
|
461
|
+
const helpers = {
|
|
462
|
+
set_response: _set_response,
|
|
463
|
+
token: helpers_token,
|
|
464
|
+
secret: helpers_secret,
|
|
465
|
+
data: helpers_data
|
|
466
|
+
};
|
|
429
467
|
/* export default */ const src_helpers = (helpers);
|
|
430
468
|
|
|
431
469
|
exports["default"] = __webpack_exports__["default"];
|
package/build/lib/index.node.cjs
CHANGED
|
@@ -90,18 +90,6 @@ const set_response = class set_response {
|
|
|
90
90
|
});
|
|
91
91
|
throw payload;
|
|
92
92
|
}
|
|
93
|
-
static DATABASE_ERROR({ message, results, c }) {
|
|
94
|
-
const payload = {
|
|
95
|
-
status: 500,
|
|
96
|
-
code: "DATABASE_ERROR",
|
|
97
|
-
type: "error",
|
|
98
|
-
message: message || "Erro no banco de dados!",
|
|
99
|
-
results: results || []
|
|
100
|
-
};
|
|
101
|
-
return c ? c.json(payload, {
|
|
102
|
-
status: 500
|
|
103
|
-
}) : payload;
|
|
104
|
-
}
|
|
105
93
|
static SERVER_ERROR({ error, c }) {
|
|
106
94
|
if (error instanceof (v4_default()).ZodError) {
|
|
107
95
|
const payload = {
|
|
@@ -216,13 +204,48 @@ const set_response = class set_response {
|
|
|
216
204
|
};
|
|
217
205
|
throw payload;
|
|
218
206
|
}
|
|
219
|
-
static DATABASE_ERROR({ message, results }) {
|
|
207
|
+
static DATABASE_ERROR({ message, results, erro }) {
|
|
208
|
+
const errorCode = erro?.cause?.code || erro?.cause?.cause?.code || erro?.code || "";
|
|
209
|
+
const map = {
|
|
210
|
+
"SQLITE_CONSTRAINT_UNIQUE": {
|
|
211
|
+
status: 409,
|
|
212
|
+
message: "Registro duplicado. Violação de UNIQUE."
|
|
213
|
+
},
|
|
214
|
+
"SQLITE_CONSTRAINT_FOREIGNKEY": {
|
|
215
|
+
status: 409,
|
|
216
|
+
message: "Registro relacionado não encontrado (FOREIGN KEY)."
|
|
217
|
+
},
|
|
218
|
+
"SQLITE_CONSTRAINT_NOTNULL": {
|
|
219
|
+
status: 400,
|
|
220
|
+
message: "Campo obrigatório ausente."
|
|
221
|
+
},
|
|
222
|
+
"SQLITE_CONSTRAINT_CHECK": {
|
|
223
|
+
status: 400,
|
|
224
|
+
message: "Regra de validação violada."
|
|
225
|
+
},
|
|
226
|
+
"SQLITE_CONSTRAINT_PRIMARYKEY": {
|
|
227
|
+
status: 409,
|
|
228
|
+
message: "Chave primária duplicada."
|
|
229
|
+
},
|
|
230
|
+
"SQLITE_BUSY": {
|
|
231
|
+
status: 503,
|
|
232
|
+
message: "Banco ocupado. Tente novamente."
|
|
233
|
+
},
|
|
234
|
+
"SQLITE_READONLY": {
|
|
235
|
+
status: 500,
|
|
236
|
+
message: "Banco de dados em modo somente leitura."
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const causeMessage = erro?.cause?.message;
|
|
240
|
+
const isUniqueMessage = causeMessage?.includes("UNIQUE constraint failed");
|
|
241
|
+
const isForeignMessage = causeMessage?.includes("FOREIGN KEY constraint failed");
|
|
242
|
+
const mapped = map[errorCode] || (isUniqueMessage ? map["SQLITE_CONSTRAINT_UNIQUE"] : null) || (isForeignMessage ? map["SQLITE_CONSTRAINT_FOREIGNKEY"] : null);
|
|
220
243
|
const payload = {
|
|
221
|
-
status:
|
|
244
|
+
status: mapped?.status || 500,
|
|
222
245
|
code: "DATABASE_ERROR",
|
|
223
246
|
type: "error",
|
|
224
|
-
message: message || "Erro no banco de dados!",
|
|
225
|
-
results:
|
|
247
|
+
message: mapped?.message || message || "Erro no banco de dados!",
|
|
248
|
+
results: []
|
|
226
249
|
};
|
|
227
250
|
throw payload;
|
|
228
251
|
}
|
|
@@ -376,16 +399,31 @@ class _secret {
|
|
|
376
399
|
}
|
|
377
400
|
/* export default */ const helpers_secret = (_secret);
|
|
378
401
|
|
|
402
|
+
;// CONCATENATED MODULE: ./src/helpers/_data.ts
|
|
403
|
+
const _data = {
|
|
404
|
+
get_now_format_number: Math.floor(Date.now() / 1000),
|
|
405
|
+
verificar_data: (value)=>{
|
|
406
|
+
const data = new Date(value * 1000);
|
|
407
|
+
if (isNaN(data.getTime())) {
|
|
408
|
+
throw new Error("Timestamp está inválido.");
|
|
409
|
+
}
|
|
410
|
+
return value; // válido
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
/* export default */ const helpers_data = (_data);
|
|
414
|
+
|
|
379
415
|
;// CONCATENATED MODULE: ./src/helpers/index.ts
|
|
380
416
|
//_HELPERS
|
|
381
417
|
|
|
382
418
|
|
|
383
419
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
420
|
+
|
|
421
|
+
const helpers = {
|
|
422
|
+
set_response: _set_response,
|
|
423
|
+
token: helpers_token,
|
|
424
|
+
secret: helpers_secret,
|
|
425
|
+
data: helpers_data
|
|
426
|
+
};
|
|
389
427
|
/* export default */ const src_helpers = (helpers);
|
|
390
428
|
|
|
391
429
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navservice/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0",
|
|
4
4
|
"description": "Service core de todos os micro serviços",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rslib build",
|
|
27
|
-
"lib": "npm
|
|
27
|
+
"lib": "npm run build && npm publish --access public"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public",
|