@zauru-sdk/graphql 6.7.0 → 6.8.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 +10 -0
- package/dist/esm/GraphQL.queries.js +51 -2
- package/package.json +2 -2
|
@@ -87,8 +87,18 @@ export type GetWebAppRowsByTableIdOptions = {
|
|
|
87
87
|
/**
|
|
88
88
|
* JSONB `_contains` filters against `webapp_rows.data`.
|
|
89
89
|
* Multiple keys are AND-ed. An array value becomes an OR of `_contains`.
|
|
90
|
+
* Numeric scalars also match the string form (`1` or `"1"`), because JSONB is typed.
|
|
90
91
|
*/
|
|
91
92
|
data?: Record<string, WebAppRowDataFilterValue>;
|
|
93
|
+
/**
|
|
94
|
+
* Filter the row timestamp (`webapp_rows.created_at`), not `data`.
|
|
95
|
+
* Values are GraphQL string literals (`YYYY-MM-DD` or ISO-8601).
|
|
96
|
+
*/
|
|
97
|
+
createdAt?: {
|
|
98
|
+
gte?: string;
|
|
99
|
+
lte?: string;
|
|
100
|
+
lt?: string;
|
|
101
|
+
};
|
|
92
102
|
};
|
|
93
103
|
export declare const getWebAppRowsByWebAppTableIdStringQuery: (webapp_table_id: number, options?: GetWebAppRowsByTableIdOptions) => string;
|
|
94
104
|
export declare const getPayeeCategoryByIdStringQuery: (id: number) => string;
|
|
@@ -677,6 +677,7 @@ query getWebAppRow {
|
|
|
677
677
|
`;
|
|
678
678
|
exports.getWebAppRowStringQuery = getWebAppRowStringQuery;
|
|
679
679
|
const GRAPHQL_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
680
|
+
const GRAPHQL_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
680
681
|
const serializeGraphQLLiteral = (value) => {
|
|
681
682
|
if (value === null) {
|
|
682
683
|
return "null";
|
|
@@ -698,6 +699,28 @@ const buildDataContainsClause = (key, value) => {
|
|
|
698
699
|
}
|
|
699
700
|
return `{ data: { _contains: { ${key}: ${serializeGraphQLLiteral(value)} } } }`;
|
|
700
701
|
};
|
|
702
|
+
const expandJsonbContainsValue = (value) => {
|
|
703
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
704
|
+
return [value, String(value)];
|
|
705
|
+
}
|
|
706
|
+
if (typeof value === "string" && value !== "" && Number.isFinite(Number(value))) {
|
|
707
|
+
return [Number(value), value];
|
|
708
|
+
}
|
|
709
|
+
return [value];
|
|
710
|
+
};
|
|
711
|
+
const uniqueJsonbContainsValues = (values) => {
|
|
712
|
+
const seen = new Set();
|
|
713
|
+
const unique = [];
|
|
714
|
+
for (const value of values) {
|
|
715
|
+
const identity = `${typeof value}:${String(value)}`;
|
|
716
|
+
if (seen.has(identity)) {
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
seen.add(identity);
|
|
720
|
+
unique.push(value);
|
|
721
|
+
}
|
|
722
|
+
return unique;
|
|
723
|
+
};
|
|
701
724
|
const buildDataFilterAndClauses = (data) => {
|
|
702
725
|
if (!data) {
|
|
703
726
|
return [];
|
|
@@ -707,7 +730,7 @@ const buildDataFilterAndClauses = (data) => {
|
|
|
707
730
|
if (raw === undefined) {
|
|
708
731
|
continue;
|
|
709
732
|
}
|
|
710
|
-
const values = Array.isArray(raw) ? raw : [raw];
|
|
733
|
+
const values = uniqueJsonbContainsValues((Array.isArray(raw) ? raw : [raw]).flatMap(expandJsonbContainsValue));
|
|
711
734
|
if (values.length === 0) {
|
|
712
735
|
continue;
|
|
713
736
|
}
|
|
@@ -721,13 +744,39 @@ const buildDataFilterAndClauses = (data) => {
|
|
|
721
744
|
}
|
|
722
745
|
return andParts;
|
|
723
746
|
};
|
|
747
|
+
const serializeGraphQLTimestamp = (value, bound) => {
|
|
748
|
+
if (!GRAPHQL_TIMESTAMP_RE.test(value)) {
|
|
749
|
+
throw new Error(`Invalid webapp row created_at ${bound}: ${value}`);
|
|
750
|
+
}
|
|
751
|
+
return JSON.stringify(value);
|
|
752
|
+
};
|
|
753
|
+
const buildCreatedAtClause = (createdAt) => {
|
|
754
|
+
if (!createdAt) {
|
|
755
|
+
return "";
|
|
756
|
+
}
|
|
757
|
+
const bounds = [];
|
|
758
|
+
if (createdAt.gte) {
|
|
759
|
+
bounds.push(`_gte: ${serializeGraphQLTimestamp(createdAt.gte, "gte")}`);
|
|
760
|
+
}
|
|
761
|
+
if (createdAt.lte) {
|
|
762
|
+
bounds.push(`_lte: ${serializeGraphQLTimestamp(createdAt.lte, "lte")}`);
|
|
763
|
+
}
|
|
764
|
+
if (createdAt.lt) {
|
|
765
|
+
bounds.push(`_lt: ${serializeGraphQLTimestamp(createdAt.lt, "lt")}`);
|
|
766
|
+
}
|
|
767
|
+
return bounds.length ? `created_at: { ${bounds.join(", ")} }` : "";
|
|
768
|
+
};
|
|
724
769
|
const getWebAppRowsByWebAppTableIdStringQuery = (webapp_table_id, options) => {
|
|
725
|
-
const { limit, data } = options ?? {};
|
|
770
|
+
const { limit, data, createdAt } = options ?? {};
|
|
726
771
|
const tableId = Number(webapp_table_id);
|
|
727
772
|
const conditions = [];
|
|
728
773
|
if (tableId) {
|
|
729
774
|
conditions.push(`webapp_table_id: {_eq: ${tableId}}`);
|
|
730
775
|
}
|
|
776
|
+
const createdAtClause = buildCreatedAtClause(createdAt);
|
|
777
|
+
if (createdAtClause) {
|
|
778
|
+
conditions.push(createdAtClause);
|
|
779
|
+
}
|
|
731
780
|
const dataAnd = buildDataFilterAndClauses(data);
|
|
732
781
|
if (dataAnd.length > 0) {
|
|
733
782
|
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.8.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",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.1.6"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "a5b35540efd2b3395e05ea0182c97d78f059c3c4"
|
|
26
26
|
}
|