@zauru-sdk/graphql 6.7.0 → 6.9.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/dist/GraphQL.queries.d.ts +12 -1
- package/dist/esm/GraphQL.queries.js +64 -12
- package/package.json +4 -3
|
@@ -5,7 +5,7 @@ export declare const getPurchaseOrderStringQuery: (id: number, config?: {
|
|
|
5
5
|
withPayee: boolean;
|
|
6
6
|
withReceptions: boolean;
|
|
7
7
|
}) => string;
|
|
8
|
-
export declare const getShipmentsStringQuery: ({ agency_to_id, agency_from_id, suffix, voided, delivered, shipped, returned, id_number_not_null, id_number, id_number_not_empty, withMovementLots, withPurchaseOrdersByShipmentReference, limit, id, wheres, memoILike, plannedShippingDateRange, plannedDeliveryDateRange, }: {
|
|
8
|
+
export declare const getShipmentsStringQuery: ({ agency_to_id, agency_from_id, suffix, voided, delivered, shipped, returned, id_number_not_null, id_number, id_number_not_empty, withMovementLots, withMovements, withPurchaseOrdersByShipmentReference, limit, id, wheres, memoILike, plannedShippingDateRange, plannedDeliveryDateRange, }: {
|
|
9
9
|
agency_to_id?: number | number[];
|
|
10
10
|
agency_from_id?: number | number[];
|
|
11
11
|
suffix?: string;
|
|
@@ -17,6 +17,7 @@ export declare const getShipmentsStringQuery: ({ agency_to_id, agency_from_id, s
|
|
|
17
17
|
id_number?: string;
|
|
18
18
|
id_number_not_empty?: boolean;
|
|
19
19
|
withMovementLots?: boolean;
|
|
20
|
+
withMovements?: boolean;
|
|
20
21
|
withPurchaseOrdersByShipmentReference?: boolean;
|
|
21
22
|
limit?: number;
|
|
22
23
|
id?: number | string;
|
|
@@ -87,8 +88,18 @@ export type GetWebAppRowsByTableIdOptions = {
|
|
|
87
88
|
/**
|
|
88
89
|
* JSONB `_contains` filters against `webapp_rows.data`.
|
|
89
90
|
* Multiple keys are AND-ed. An array value becomes an OR of `_contains`.
|
|
91
|
+
* Numeric scalars also match the string form (`1` or `"1"`), because JSONB is typed.
|
|
90
92
|
*/
|
|
91
93
|
data?: Record<string, WebAppRowDataFilterValue>;
|
|
94
|
+
/**
|
|
95
|
+
* Filter the row timestamp (`webapp_rows.created_at`), not `data`.
|
|
96
|
+
* Values are GraphQL string literals (`YYYY-MM-DD` or ISO-8601).
|
|
97
|
+
*/
|
|
98
|
+
createdAt?: {
|
|
99
|
+
gte?: string;
|
|
100
|
+
lte?: string;
|
|
101
|
+
lt?: string;
|
|
102
|
+
};
|
|
92
103
|
};
|
|
93
104
|
export declare const getWebAppRowsByWebAppTableIdStringQuery: (webapp_table_id: number, options?: GetWebAppRowsByTableIdOptions) => string;
|
|
94
105
|
export declare const getPayeeCategoryByIdStringQuery: (id: number) => string;
|
|
@@ -203,7 +203,7 @@ query getPurchaseOrder($id: bigint) @cached {
|
|
|
203
203
|
`;
|
|
204
204
|
};
|
|
205
205
|
exports.getPurchaseOrderStringQuery = getPurchaseOrderStringQuery;
|
|
206
|
-
const getShipmentsStringQuery = ({ agency_to_id, agency_from_id, suffix, voided, delivered, shipped, returned, id_number_not_null = false, id_number, id_number_not_empty = false, withMovementLots = false, withPurchaseOrdersByShipmentReference = false, limit = 1000, id, wheres, memoILike, plannedShippingDateRange, plannedDeliveryDateRange, }) => {
|
|
206
|
+
const getShipmentsStringQuery = ({ agency_to_id, agency_from_id, suffix, voided, delivered, shipped, returned, id_number_not_null = false, id_number, id_number_not_empty = false, withMovementLots = false, withMovements = true, withPurchaseOrdersByShipmentReference = false, limit = 1000, id, wheres, memoILike, plannedShippingDateRange, plannedDeliveryDateRange, }) => {
|
|
207
207
|
let conditions = [];
|
|
208
208
|
if (agency_to_id) {
|
|
209
209
|
if (Array.isArray(agency_to_id)) {
|
|
@@ -286,6 +286,17 @@ const getShipmentsStringQuery = ({ agency_to_id, agency_from_id, suffix, voided,
|
|
|
286
286
|
}
|
|
287
287
|
}`
|
|
288
288
|
: "";
|
|
289
|
+
const movements = withMovements
|
|
290
|
+
? `movements {
|
|
291
|
+
id
|
|
292
|
+
booked_quantity
|
|
293
|
+
delivered_quantity
|
|
294
|
+
reference
|
|
295
|
+
item_id
|
|
296
|
+
lot_id
|
|
297
|
+
${movementLots}
|
|
298
|
+
}`
|
|
299
|
+
: "";
|
|
289
300
|
return `query getShipments {
|
|
290
301
|
shipments(
|
|
291
302
|
limit: ${limit},
|
|
@@ -319,15 +330,7 @@ const getShipmentsStringQuery = ({ agency_to_id, agency_from_id, suffix, voided,
|
|
|
319
330
|
returned_at
|
|
320
331
|
returner_id
|
|
321
332
|
${purchaseOrdersByShipmentReference}
|
|
322
|
-
movements
|
|
323
|
-
id
|
|
324
|
-
booked_quantity
|
|
325
|
-
delivered_quantity
|
|
326
|
-
reference
|
|
327
|
-
item_id
|
|
328
|
-
lot_id
|
|
329
|
-
${movementLots}
|
|
330
|
-
}
|
|
333
|
+
${movements}
|
|
331
334
|
}
|
|
332
335
|
}`;
|
|
333
336
|
};
|
|
@@ -677,6 +680,7 @@ query getWebAppRow {
|
|
|
677
680
|
`;
|
|
678
681
|
exports.getWebAppRowStringQuery = getWebAppRowStringQuery;
|
|
679
682
|
const GRAPHQL_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
683
|
+
const GRAPHQL_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
680
684
|
const serializeGraphQLLiteral = (value) => {
|
|
681
685
|
if (value === null) {
|
|
682
686
|
return "null";
|
|
@@ -698,6 +702,28 @@ const buildDataContainsClause = (key, value) => {
|
|
|
698
702
|
}
|
|
699
703
|
return `{ data: { _contains: { ${key}: ${serializeGraphQLLiteral(value)} } } }`;
|
|
700
704
|
};
|
|
705
|
+
const expandJsonbContainsValue = (value) => {
|
|
706
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
707
|
+
return [value, String(value)];
|
|
708
|
+
}
|
|
709
|
+
if (typeof value === "string" && value !== "" && Number.isFinite(Number(value))) {
|
|
710
|
+
return [Number(value), value];
|
|
711
|
+
}
|
|
712
|
+
return [value];
|
|
713
|
+
};
|
|
714
|
+
const uniqueJsonbContainsValues = (values) => {
|
|
715
|
+
const seen = new Set();
|
|
716
|
+
const unique = [];
|
|
717
|
+
for (const value of values) {
|
|
718
|
+
const identity = `${typeof value}:${String(value)}`;
|
|
719
|
+
if (seen.has(identity)) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
seen.add(identity);
|
|
723
|
+
unique.push(value);
|
|
724
|
+
}
|
|
725
|
+
return unique;
|
|
726
|
+
};
|
|
701
727
|
const buildDataFilterAndClauses = (data) => {
|
|
702
728
|
if (!data) {
|
|
703
729
|
return [];
|
|
@@ -707,7 +733,7 @@ const buildDataFilterAndClauses = (data) => {
|
|
|
707
733
|
if (raw === undefined) {
|
|
708
734
|
continue;
|
|
709
735
|
}
|
|
710
|
-
const values = Array.isArray(raw) ? raw : [raw];
|
|
736
|
+
const values = uniqueJsonbContainsValues((Array.isArray(raw) ? raw : [raw]).flatMap(expandJsonbContainsValue));
|
|
711
737
|
if (values.length === 0) {
|
|
712
738
|
continue;
|
|
713
739
|
}
|
|
@@ -721,13 +747,39 @@ const buildDataFilterAndClauses = (data) => {
|
|
|
721
747
|
}
|
|
722
748
|
return andParts;
|
|
723
749
|
};
|
|
750
|
+
const serializeGraphQLTimestamp = (value, bound) => {
|
|
751
|
+
if (!GRAPHQL_TIMESTAMP_RE.test(value)) {
|
|
752
|
+
throw new Error(`Invalid webapp row created_at ${bound}: ${value}`);
|
|
753
|
+
}
|
|
754
|
+
return JSON.stringify(value);
|
|
755
|
+
};
|
|
756
|
+
const buildCreatedAtClause = (createdAt) => {
|
|
757
|
+
if (!createdAt) {
|
|
758
|
+
return "";
|
|
759
|
+
}
|
|
760
|
+
const bounds = [];
|
|
761
|
+
if (createdAt.gte) {
|
|
762
|
+
bounds.push(`_gte: ${serializeGraphQLTimestamp(createdAt.gte, "gte")}`);
|
|
763
|
+
}
|
|
764
|
+
if (createdAt.lte) {
|
|
765
|
+
bounds.push(`_lte: ${serializeGraphQLTimestamp(createdAt.lte, "lte")}`);
|
|
766
|
+
}
|
|
767
|
+
if (createdAt.lt) {
|
|
768
|
+
bounds.push(`_lt: ${serializeGraphQLTimestamp(createdAt.lt, "lt")}`);
|
|
769
|
+
}
|
|
770
|
+
return bounds.length ? `created_at: { ${bounds.join(", ")} }` : "";
|
|
771
|
+
};
|
|
724
772
|
const getWebAppRowsByWebAppTableIdStringQuery = (webapp_table_id, options) => {
|
|
725
|
-
const { limit, data } = options ?? {};
|
|
773
|
+
const { limit, data, createdAt } = options ?? {};
|
|
726
774
|
const tableId = Number(webapp_table_id);
|
|
727
775
|
const conditions = [];
|
|
728
776
|
if (tableId) {
|
|
729
777
|
conditions.push(`webapp_table_id: {_eq: ${tableId}}`);
|
|
730
778
|
}
|
|
779
|
+
const createdAtClause = buildCreatedAtClause(createdAt);
|
|
780
|
+
if (createdAtClause) {
|
|
781
|
+
conditions.push(createdAtClause);
|
|
782
|
+
}
|
|
731
783
|
const dataAnd = buildDataFilterAndClauses(data);
|
|
732
784
|
if (dataAnd.length > 0) {
|
|
733
785
|
conditions.push(`_and: [${dataAnd.join(", ")}]`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/graphql",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.0",
|
|
4
4
|
"description": "Queries de uso común para las aplicación de Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "npm run build:esm",
|
|
14
14
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
15
|
-
"test": "
|
|
15
|
+
"test": "tsx --test src/GraphQL.queries.test.ts"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"author": "Oscar Cuéllar",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"devDependencies": {
|
|
23
|
+
"tsx": "^4.23.15",
|
|
23
24
|
"typescript": "^5.1.6"
|
|
24
25
|
},
|
|
25
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "2daa677e6cd4948b23bfbf862929b4c74655e4e0"
|
|
26
27
|
}
|