ag-common 0.0.767 → 0.0.769

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.
@@ -2,9 +2,9 @@ import type { Container } from '@azure/cosmos';
2
2
  export declare function getItemCosmos<T>(container: Container, partitionValue: string): Promise<T | null>;
3
3
  export declare function getItemsByCosmos<T>(container: Container, partitionValues: string[]): Promise<T[]>;
4
4
  export declare function queryItemsByText<T>(container: Container, searchFields: {
5
- fieldName: string;
5
+ fieldName: keyof T & string;
6
6
  fieldValue: string;
7
- type: 'contains' | 'equals';
7
+ type: 'contains' | 'equals' | 'not_equals';
8
8
  }[], operator?: 'AND' | 'OR'): Promise<T[] | {
9
9
  error: string;
10
10
  }>;
@@ -114,9 +114,18 @@ function queryItemsCosmos(container, query, parameters) {
114
114
  function queryItemsByText(container_1, searchFields_1) {
115
115
  return __awaiter(this, arguments, void 0, function* (container, searchFields, operator = 'AND') {
116
116
  try {
117
- const conditions = searchFields.map((field, index) => field.type === 'contains' //true to ignore case
118
- ? `CONTAINS(c.${field.fieldName}, @value${index}, true)`
119
- : `c.${field.fieldName} = @value${index}`);
117
+ const conditions = searchFields.map((field, index) => {
118
+ switch (field.type) {
119
+ case 'contains':
120
+ return `CONTAINS(c.${field.fieldName}, @value${index}, true)`; //true to ignore case
121
+ case 'equals':
122
+ return `c.${field.fieldName} = @value${index}`;
123
+ case 'not_equals':
124
+ return `c.${field.fieldName} != @value${index}`;
125
+ default:
126
+ throw new Error(`Unsupported field type: ${field.type}`);
127
+ }
128
+ });
120
129
  const query = `SELECT * FROM c WHERE ${conditions.join(` ${operator} `)}`;
121
130
  const parameters = searchFields.reduce((acc, field, index) => {
122
131
  acc[`value${index}`] = escapeSqlString(field.fieldValue);
@@ -5,9 +5,9 @@ export declare class Cosmos {
5
5
  getItem<T>(partitionValue: string): Promise<T | null>;
6
6
  getItemsBy<T>(partitionValues: string[]): Promise<T[]>;
7
7
  queryItemsByText<T>(searchFields: {
8
- fieldName: string;
8
+ fieldName: keyof T & string;
9
9
  fieldValue: string;
10
- type: 'contains' | 'equals';
10
+ type: 'contains' | 'equals' | 'not_equals';
11
11
  }[], operator?: 'AND' | 'OR'): Promise<T[] | {
12
12
  error: string;
13
13
  }>;
@@ -1,6 +1,7 @@
1
1
  export * from './api';
2
2
  export * from './apigw';
3
3
  export * from './aws';
4
+ export * from './cosmos';
4
5
  export * from './dynamo';
5
6
  export * from './enforceDynamoProvisionCap';
6
7
  export * from './s3';
@@ -10,4 +11,3 @@ export * from './ssm';
10
11
  export * from './ssmInfra';
11
12
  export * from './sts';
12
13
  export * from './validations';
13
- export * from './cosmos';
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
18
  __exportStar(require("./apigw"), exports);
19
19
  __exportStar(require("./aws"), exports);
20
+ __exportStar(require("./cosmos"), exports);
20
21
  __exportStar(require("./dynamo"), exports);
21
22
  __exportStar(require("./enforceDynamoProvisionCap"), exports);
22
23
  __exportStar(require("./s3"), exports);
@@ -26,4 +27,3 @@ __exportStar(require("./ssm"), exports);
26
27
  __exportStar(require("./ssmInfra"), exports);
27
28
  __exportStar(require("./sts"), exports);
28
29
  __exportStar(require("./validations"), exports);
29
- __exportStar(require("./cosmos"), exports);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.767",
2
+ "version": "0.0.769",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",