@zauru-sdk/graphql 6.5.0 → 6.7.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.
@@ -80,7 +80,17 @@ export declare const getPayeesStringQuery: (filters?: {
80
80
  export declare const getProvidersStringQuery = "\nquery getProviders {\n payees (where: {vendor: {_eq: true}}) {\n id\n id_number\n name\n tin\n address_line_1\n }\n}\n";
81
81
  export declare const getAgenciesStringQuery = "\nquery getAgencies {\n agencies {\n id\n name\n address_line_2\n }\n}\n";
82
82
  export declare const getWebAppRowStringQuery: (id: number) => string;
83
- export declare const getWebAppRowsByWebAppTableIdStringQuery: (webapp_table_id: number, limit?: number) => string;
83
+ export type WebAppRowDataFilterScalar = string | number | boolean | null;
84
+ export type WebAppRowDataFilterValue = WebAppRowDataFilterScalar | WebAppRowDataFilterScalar[];
85
+ export type GetWebAppRowsByTableIdOptions = {
86
+ limit?: number;
87
+ /**
88
+ * JSONB `_contains` filters against `webapp_rows.data`.
89
+ * Multiple keys are AND-ed. An array value becomes an OR of `_contains`.
90
+ */
91
+ data?: Record<string, WebAppRowDataFilterValue>;
92
+ };
93
+ export declare const getWebAppRowsByWebAppTableIdStringQuery: (webapp_table_id: number, options?: GetWebAppRowsByTableIdOptions) => string;
84
94
  export declare const getPayeeCategoryByIdStringQuery: (id: number) => string;
85
95
  export declare const getPayeeCategoriesByNotesMatchStringQuery: (match: string) => string;
86
96
  export declare const getPayeeCategoriesStringQuery = "\nquery getPayeeCategories {\n payee_categories {\n id\n name\n notes\n payees_count\n price_list_id\n }\n}\n";
@@ -676,15 +676,66 @@ query getWebAppRow {
676
676
  }
677
677
  `;
678
678
  exports.getWebAppRowStringQuery = getWebAppRowStringQuery;
679
- const getWebAppRowsByWebAppTableIdStringQuery = (webapp_table_id, limit) => {
679
+ const GRAPHQL_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
680
+ const serializeGraphQLLiteral = (value) => {
681
+ if (value === null) {
682
+ return "null";
683
+ }
684
+ if (typeof value === "boolean") {
685
+ return value ? "true" : "false";
686
+ }
687
+ if (typeof value === "number") {
688
+ if (!Number.isFinite(value)) {
689
+ throw new Error("Invalid numeric GraphQL literal");
690
+ }
691
+ return String(value);
692
+ }
693
+ return JSON.stringify(value);
694
+ };
695
+ const buildDataContainsClause = (key, value) => {
696
+ if (!GRAPHQL_NAME_RE.test(key)) {
697
+ throw new Error(`Invalid webapp row data filter key: ${key}`);
698
+ }
699
+ return `{ data: { _contains: { ${key}: ${serializeGraphQLLiteral(value)} } } }`;
700
+ };
701
+ const buildDataFilterAndClauses = (data) => {
702
+ if (!data) {
703
+ return [];
704
+ }
705
+ const andParts = [];
706
+ for (const [key, raw] of Object.entries(data)) {
707
+ if (raw === undefined) {
708
+ continue;
709
+ }
710
+ const values = Array.isArray(raw) ? raw : [raw];
711
+ if (values.length === 0) {
712
+ continue;
713
+ }
714
+ const orParts = values.map((value) => buildDataContainsClause(key, value));
715
+ if (orParts.length === 1) {
716
+ andParts.push(orParts[0]);
717
+ }
718
+ else {
719
+ andParts.push(`{ _or: [${orParts.join(", ")}] }`);
720
+ }
721
+ }
722
+ return andParts;
723
+ };
724
+ const getWebAppRowsByWebAppTableIdStringQuery = (webapp_table_id, options) => {
725
+ const { limit, data } = options ?? {};
726
+ const tableId = Number(webapp_table_id);
680
727
  const conditions = [];
681
- if (webapp_table_id) {
682
- conditions.push(`webapp_table_id: {_eq: ${webapp_table_id}}`);
728
+ if (tableId) {
729
+ conditions.push(`webapp_table_id: {_eq: ${tableId}}`);
730
+ }
731
+ const dataAnd = buildDataFilterAndClauses(data);
732
+ if (dataAnd.length > 0) {
733
+ conditions.push(`_and: [${dataAnd.join(", ")}]`);
683
734
  }
684
735
  const whereClause = conditions.length
685
736
  ? `where: { ${conditions.join(", ")} }`
686
737
  : "";
687
- const limitClause = limit ? `limit: ${limit}` : "";
738
+ const limitClause = limit ? `limit: ${Number(limit)}` : "";
688
739
  const orderByClause = `order_by: { id: desc }`;
689
740
  return `
690
741
  query getWebAppRowsByWebAppTableId {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/graphql",
3
- "version": "6.5.0",
3
+ "version": "6.7.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": "4df5f4a0b8160018e6047ed2afdd284c2ea0c8a6"
25
+ "gitHead": "add1b36bf68bad8debe05c25fd826d68acce2810"
26
26
  }