ixc-orm 1.0.0 → 1.1.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/README.md +6 -3
- package/dist/IXCClient.d.ts +2 -2
- package/dist/IXCClient.js +12 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +6 -3
- package/dist/request.d.ts +3 -3
- package/dist/request.js +4 -4
- package/package.json +1 -1
- package/src/IXCClient.ts +20 -6
- package/src/index.ts +20 -6
- package/src/request.ts +5 -7
package/README.md
CHANGED
|
@@ -34,8 +34,8 @@ class Contrato extends IXCClient {
|
|
|
34
34
|
```typescript
|
|
35
35
|
const contrato = new Contrato();
|
|
36
36
|
|
|
37
|
-
contrato
|
|
38
|
-
.where('
|
|
37
|
+
const contratos = await contrato
|
|
38
|
+
.where(['id_cliente', 240])
|
|
39
39
|
.where(['data_ativacao', '>=', '2024-09-24 00:45:00'])
|
|
40
40
|
.orderBy('data_ativacao', 'desc')
|
|
41
41
|
.get();
|
|
@@ -48,4 +48,7 @@ Para configurar a comunicação da biblioteca com seu servidor IXC, é necessár
|
|
|
48
48
|
|
|
49
49
|
`IXC_HOST`
|
|
50
50
|
|
|
51
|
-
`IXC_TOKEN`
|
|
51
|
+
`IXC_TOKEN`
|
|
52
|
+
|
|
53
|
+
> **IXC_HOST** deve conter a url do seu servidor IXC, no formato: `https://seudominio.com.br/webservice/v1`
|
|
54
|
+
> **IXC_TOKEN** deve conter um token de API gerado dentro do seu sistema IXCsoft.
|
package/dist/IXCClient.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export default abstract class IXCClient {
|
|
|
6
6
|
protected options: IXCOptions;
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
|
-
* @param table O nome da tabela
|
|
9
|
+
* @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
|
|
10
10
|
* @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
|
|
11
11
|
*/
|
|
12
12
|
constructor(table: string);
|
|
@@ -15,7 +15,7 @@ export default abstract class IXCClient {
|
|
|
15
15
|
* @param whereClauses Um array de strings, no formato [coluna, operador, valor]
|
|
16
16
|
* Obs: se você passar um array no formato [coluna, valor] o operador será considerado como '='
|
|
17
17
|
*
|
|
18
|
-
* Operadores: =, !=, >, <, >=, <=,
|
|
18
|
+
* Operadores: =, !=, >, <, >=, <=, L
|
|
19
19
|
*
|
|
20
20
|
* @returns
|
|
21
21
|
*/
|
package/dist/IXCClient.js
CHANGED
|
@@ -22,10 +22,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
const axios_1 = require("axios");
|
|
24
24
|
const request_1 = require("./request");
|
|
25
|
+
const types_1 = require("./types");
|
|
25
26
|
class IXCClient {
|
|
26
27
|
/**
|
|
27
28
|
*
|
|
28
|
-
* @param table O nome da tabela
|
|
29
|
+
* @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
|
|
29
30
|
* @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
|
|
30
31
|
*/
|
|
31
32
|
constructor(table) {
|
|
@@ -43,14 +44,21 @@ class IXCClient {
|
|
|
43
44
|
* @param whereClauses Um array de strings, no formato [coluna, operador, valor]
|
|
44
45
|
* Obs: se você passar um array no formato [coluna, valor] o operador será considerado como '='
|
|
45
46
|
*
|
|
46
|
-
* Operadores: =, !=, >, <, >=, <=,
|
|
47
|
+
* Operadores: =, !=, >, <, >=, <=, L
|
|
47
48
|
*
|
|
48
49
|
* @returns
|
|
49
50
|
*/
|
|
50
51
|
where(whereClauses) {
|
|
51
|
-
|
|
52
|
+
if (whereClauses.length > 3) {
|
|
53
|
+
throw new Error(`O array de cláusulas não pode conter mais de 3 elementos!`);
|
|
54
|
+
}
|
|
55
|
+
const [alwaysColumn, operatorOrValue, valueOrUndefined] = whereClauses;
|
|
56
|
+
const availableOperators = Object.keys(types_1.IXCOperator);
|
|
57
|
+
if (whereClauses.length > 2 && !availableOperators.includes(operatorOrValue)) {
|
|
58
|
+
throw new Error(`O operador ${operatorOrValue}, não faz parte da lista de operadores válidos: ${availableOperators}`);
|
|
59
|
+
}
|
|
52
60
|
this.params.push({
|
|
53
|
-
TB:
|
|
61
|
+
TB: alwaysColumn,
|
|
54
62
|
OP: valueOrUndefined ? operatorOrValue : '=',
|
|
55
63
|
P: valueOrUndefined ? valueOrUndefined : operatorOrValue
|
|
56
64
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import IXCClient from './IXCClient';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
export default _default;
|
|
2
|
+
import { IXCOperator, IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods, IXCResponse, IXCSortOrder } from './types';
|
|
3
|
+
export { IXCClient, IXCOperator, IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods, IXCResponse, IXCSortOrder };
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IXCSortOrder = exports.IXCRequestMethods = exports.IXCOperator = exports.IXCClient = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
9
|
const IXCClient_1 = __importDefault(require("./IXCClient"));
|
|
10
|
+
exports.IXCClient = IXCClient_1.default;
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
Object.defineProperty(exports, "IXCOperator", { enumerable: true, get: function () { return types_1.IXCOperator; } });
|
|
13
|
+
Object.defineProperty(exports, "IXCRequestMethods", { enumerable: true, get: function () { return types_1.IXCRequestMethods; } });
|
|
14
|
+
Object.defineProperty(exports, "IXCSortOrder", { enumerable: true, get: function () { return types_1.IXCSortOrder; } });
|
|
9
15
|
const env = dotenv_1.default.config({
|
|
10
16
|
path: path_1.default.join(__dirname, `../.env`)
|
|
11
17
|
});
|
|
@@ -13,6 +19,3 @@ if (env.error) {
|
|
|
13
19
|
console.error(env.error);
|
|
14
20
|
process.exit(-1);
|
|
15
21
|
}
|
|
16
|
-
exports.default = {
|
|
17
|
-
IXCClient: IXCClient_1.default
|
|
18
|
-
};
|
package/dist/request.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods } from './types';
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
5
|
* @param method GET | POST | PUT
|
|
6
|
-
* @returns A
|
|
6
|
+
* @returns A instância de um objeto do tipo AxiosInstance, pré-configurado com os cabeçalhos necessários
|
|
7
7
|
*/
|
|
8
8
|
export declare function createAxiosInstance(method?: keyof typeof IXCRequestMethods): AxiosInstance;
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
|
-
* @param table Nome da
|
|
12
|
-
* @param params Parâmetros da busca (desconciderado
|
|
11
|
+
* @param table Nome da tabela do IXC onde será feita a busca, atualização, inserção ou remoção
|
|
12
|
+
* @param params Parâmetros da busca (desconciderado quando a ação é a de inserir novos registros)
|
|
13
13
|
* @param options Parâmetros de formatação dos dados da responsta (página, ítens por página e ordenação)
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
package/dist/request.js
CHANGED
|
@@ -9,14 +9,14 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
* @param method GET | POST | PUT
|
|
12
|
-
* @returns A
|
|
12
|
+
* @returns A instância de um objeto do tipo AxiosInstance, pré-configurado com os cabeçalhos necessários
|
|
13
13
|
*/
|
|
14
14
|
function createAxiosInstance(method = 'GET') {
|
|
15
15
|
const host = process.env.IXC_HOST;
|
|
16
16
|
const token = process.env.IXC_TOKEN;
|
|
17
17
|
return axios_1.default.create({
|
|
18
18
|
method: method,
|
|
19
|
-
baseURL: host !== null && host !== void 0 ? host : 'http://127.0.0.1
|
|
19
|
+
baseURL: host !== null && host !== void 0 ? host : 'http://127.0.0.1/webservice/v1',
|
|
20
20
|
headers: {
|
|
21
21
|
'ixcsoft': (method === 'GET') ? 'listar' : '',
|
|
22
22
|
'Content-Type': 'application/json',
|
|
@@ -26,8 +26,8 @@ function createAxiosInstance(method = 'GET') {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
|
-
* @param table Nome da
|
|
30
|
-
* @param params Parâmetros da busca (desconciderado
|
|
29
|
+
* @param table Nome da tabela do IXC onde será feita a busca, atualização, inserção ou remoção
|
|
30
|
+
* @param params Parâmetros da busca (desconciderado quando a ação é a de inserir novos registros)
|
|
31
31
|
* @param options Parâmetros de formatação dos dados da responsta (página, ítens por página e ordenação)
|
|
32
32
|
* @returns
|
|
33
33
|
*/
|
package/package.json
CHANGED
package/src/IXCClient.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosError } from 'axios';
|
|
2
2
|
import { createAxiosInstance, createRequestPayload } from './request';
|
|
3
|
-
import { IXCOptions, IXCQuery, IXCResponse, IXCSortOrder } from './types';
|
|
3
|
+
import { IXCOperator, IXCOptions, IXCQuery, IXCResponse, IXCSortOrder } from './types';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ export default abstract class IXCClient {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
17
|
-
* @param table O nome da tabela
|
|
17
|
+
* @param table O nome da tabela correspondente ao banco de dados do seu servidor IXC
|
|
18
18
|
* @see {@link https://wikiapiprovedor.ixcsoft.com.br/index.php}
|
|
19
19
|
*/
|
|
20
20
|
constructor(table: string) {
|
|
@@ -36,25 +36,39 @@ export default abstract class IXCClient {
|
|
|
36
36
|
* @param whereClauses Um array de strings, no formato [coluna, operador, valor]
|
|
37
37
|
* Obs: se você passar um array no formato [coluna, valor] o operador será considerado como '='
|
|
38
38
|
*
|
|
39
|
-
* Operadores: =, !=, >, <, >=, <=,
|
|
39
|
+
* Operadores: =, !=, >, <, >=, <=, L
|
|
40
40
|
*
|
|
41
41
|
* @returns
|
|
42
42
|
*/
|
|
43
43
|
where(whereClauses: string[]) : IXCClient {
|
|
44
|
+
|
|
45
|
+
if (whereClauses.length > 3) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`O array de cláusulas não pode conter mais de 3 elementos!`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
44
50
|
|
|
45
51
|
const [
|
|
46
|
-
|
|
52
|
+
alwaysColumn,
|
|
47
53
|
operatorOrValue,
|
|
48
54
|
valueOrUndefined
|
|
49
55
|
] = whereClauses;
|
|
50
56
|
|
|
57
|
+
const availableOperators = Object.keys(IXCOperator);
|
|
58
|
+
|
|
59
|
+
if (whereClauses.length > 2 && !availableOperators.includes(operatorOrValue)) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`O operador ${ operatorOrValue }, não faz parte da lista de operadores válidos: ${ availableOperators }`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
51
65
|
this.params.push({
|
|
52
|
-
TB:
|
|
66
|
+
TB: alwaysColumn,
|
|
53
67
|
OP: valueOrUndefined ? operatorOrValue : '=',
|
|
54
68
|
P: valueOrUndefined ? valueOrUndefined : operatorOrValue
|
|
55
69
|
});
|
|
56
70
|
|
|
57
|
-
return this
|
|
71
|
+
return this;
|
|
58
72
|
}
|
|
59
73
|
|
|
60
74
|
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,16 @@ import dotenv from 'dotenv';
|
|
|
3
3
|
|
|
4
4
|
import IXCClient from './IXCClient';
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
IXCOperator,
|
|
8
|
+
IXCOptions,
|
|
9
|
+
IXCQuery,
|
|
10
|
+
IXCRequest,
|
|
11
|
+
IXCRequestMethods,
|
|
12
|
+
IXCResponse,
|
|
13
|
+
IXCSortOrder
|
|
14
|
+
} from './types';
|
|
15
|
+
|
|
6
16
|
|
|
7
17
|
|
|
8
18
|
const env = dotenv.config({
|
|
@@ -15,9 +25,13 @@ if (env.error) {
|
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
export {
|
|
29
|
+
IXCClient,
|
|
30
|
+
IXCOperator,
|
|
31
|
+
IXCOptions,
|
|
32
|
+
IXCQuery,
|
|
33
|
+
IXCRequest,
|
|
34
|
+
IXCRequestMethods,
|
|
35
|
+
IXCResponse,
|
|
36
|
+
IXCSortOrder
|
|
37
|
+
};
|
package/src/request.ts
CHANGED
|
@@ -5,18 +5,16 @@ import { IXCOptions, IXCQuery, IXCRequest, IXCRequestMethods } from './types';
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
7
|
* @param method GET | POST | PUT
|
|
8
|
-
* @returns A
|
|
8
|
+
* @returns A instância de um objeto do tipo AxiosInstance, pré-configurado com os cabeçalhos necessários
|
|
9
9
|
*/
|
|
10
|
-
export function createAxiosInstance(
|
|
11
|
-
method: keyof typeof IXCRequestMethods = 'GET'
|
|
12
|
-
) : AxiosInstance {
|
|
10
|
+
export function createAxiosInstance(method: keyof typeof IXCRequestMethods = 'GET') : AxiosInstance {
|
|
13
11
|
|
|
14
12
|
const host = process.env.IXC_HOST;
|
|
15
13
|
const token = process.env.IXC_TOKEN;
|
|
16
14
|
|
|
17
15
|
return axios.create({
|
|
18
16
|
method: method,
|
|
19
|
-
baseURL: host ?? 'http://127.0.0.1
|
|
17
|
+
baseURL: host ?? 'http://127.0.0.1/webservice/v1',
|
|
20
18
|
headers: {
|
|
21
19
|
'ixcsoft': (method === 'GET') ? 'listar' : '',
|
|
22
20
|
'Content-Type': 'application/json',
|
|
@@ -28,8 +26,8 @@ export function createAxiosInstance(
|
|
|
28
26
|
|
|
29
27
|
/**
|
|
30
28
|
*
|
|
31
|
-
* @param table Nome da
|
|
32
|
-
* @param params Parâmetros da busca (desconciderado
|
|
29
|
+
* @param table Nome da tabela do IXC onde será feita a busca, atualização, inserção ou remoção
|
|
30
|
+
* @param params Parâmetros da busca (desconciderado quando a ação é a de inserir novos registros)
|
|
33
31
|
* @param options Parâmetros de formatação dos dados da responsta (página, ítens por página e ordenação)
|
|
34
32
|
* @returns
|
|
35
33
|
*/
|