prostgles-server 2.0.119 → 2.0.123

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/lib/Filtering.ts CHANGED
@@ -40,7 +40,7 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
40
40
  // parseExistsFilter()
41
41
  }
42
42
 
43
- let selItem;
43
+ let selItem: SelectItem | undefined;
44
44
  if(select) selItem = select.find(s => fKey === s.alias);
45
45
  let rightF: FilterDataType = _f[fKey];
46
46
 
@@ -191,6 +191,11 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
191
191
  }
192
192
  // console.log({ fOpType, fVal, sOpType })
193
193
 
194
+ /** JSON cannot be compared so we'll cast it to TEXT */
195
+ if(selItem?.column_udt_type === "json" || ["$ilike", "$like"].includes(fOpType)){
196
+ leftQ += "::TEXT "
197
+ }
198
+
194
199
  /** st_makeenvelope */
195
200
  if(GeomFilterKeys.includes(fOpType) && sOpType && GeomFilter_Funcs.includes(sOpType)){
196
201
  /** If leftQ is geography then this err can happen: 'Antipodal (180 degrees long) edge detected!' */
@@ -218,11 +223,13 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
218
223
  return leftQ + " <= " + parseRightVal(fVal);
219
224
 
220
225
  } else if(["$in"].includes(fOpType)){
226
+ if(!fVal?.length) throw "$in filter array is empty";
221
227
  let res = leftQ + " IN " + parseRightVal(fVal, "csv");
222
228
  if(fVal.includes(null)) res += ` OR ${leftQ} IS NULL `
223
229
  return res;
224
230
 
225
231
  } else if(["$nin"].includes(fOpType)){
232
+ if(!fVal?.length) throw "$nin filter array is empty";
226
233
  let res = leftQ + " NOT IN " + parseRightVal(fVal, "csv");
227
234
  if(fVal.includes(null)) res += ` AND ${leftQ} IS NOT NULL `
228
235
  return res;
@@ -234,10 +241,10 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
234
241
  return leftQ + " BETWEEN " + asValue(fVal[0]) + " AND " + asValue(fVal[1]);
235
242
 
236
243
  } else if(["$ilike"].includes(fOpType)){
237
- return leftQ + "::TEXT ILIKE " + asValue(fVal);
244
+ return leftQ + " ILIKE " + asValue(fVal);
238
245
 
239
246
  } else if(["$like"].includes(fOpType)){
240
- return leftQ + "::TEXT LIKE " + asValue(fVal);
247
+ return leftQ + " LIKE " + asValue(fVal);
241
248
 
242
249
  /* MAYBE TEXT OR MAYBE ARRAY */
243
250
  } else if(["@>", "<@", "$contains", "$containedBy", "&&", "@@"].includes(fOpType)){
@@ -253,7 +260,7 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
253
260
  /* FTSQuery */
254
261
  } else if(["@@"].includes(fOpType) && TextFilter_FullTextSearchFilterKeys.includes(sOpType)) {
255
262
  let lq = `to_tsvector(${leftQ}::text)`;
256
- if(selItem && selItem.columnDataType === "tsvector") lq = leftQ;
263
+ if(selItem && selItem.columnPGDataType === "tsvector") lq = leftQ;
257
264
 
258
265
  let res = `${lq} ${operand} ` + `${sOpType}${parseRightVal(sVal, "csv")}`;
259
266
 
package/lib/Prostgles.ts CHANGED
@@ -544,7 +544,7 @@ export class Prostgles<DBO = DbHandler> {
544
544
  if(watchSchema && this.loaded){
545
545
  console.log("Schema changed");
546
546
  const { query } = event;
547
- if(query && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)){
547
+ if(typeof query === "string" && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)){
548
548
  console.log("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
549
549
  return;
550
550
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { pgp, Filter, LocalParams, isPlainObject, TableHandler, ViewHandler, postgresToTsType } from "./DboBuilder";
8
8
  import { TableRule, flat } from "./Prostgles";
9
- import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, TS_PG_Types, ColumnInfo } from "prostgles-types";
9
+ import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, TS_PG_Types, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE } from "prostgles-types";
10
10
  import { get } from "./utils";
11
11
 
12
12
 
@@ -15,6 +15,7 @@ export type SelectItem = {
15
15
  getFields: (args?: any[]) => string[] | "*";
16
16
  getQuery: (tableAlias?: string) => string;
17
17
  columnPGDataType?: string;
18
+ column_udt_type?: PG_COLUMN_UDT_DATA_TYPE;
18
19
  // columnName?: string; /* Must only exist if type "column" ... dissalow aliased columns? */
19
20
  alias: string;
20
21
  selected: boolean;
@@ -422,6 +423,17 @@ export const FUNCTIONS: FunctionSpec[] = [
422
423
  return pgp.as.format("LEFT(" + asNameAlias(args[0], tableAlias) + ", $1)", [args[1]]);
423
424
  }
424
425
  },
426
+ {
427
+ name: "$unnest_words",
428
+ description: ` :[column_name, number] -> substring`,
429
+ type: "function",
430
+ numArgs: 1,
431
+ singleColArg: true,
432
+ getFields: (args: any[]) => [args[0]],
433
+ getQuery: ({ allowedFields, args, tableAlias }) => {
434
+ return pgp.as.format("unnest(string_to_array(" + asNameAlias(args[0], tableAlias) + "::TEXT , ' '))");//, [args[1]]
435
+ }
436
+ },
425
437
  {
426
438
  name: "$right",
427
439
  description: ` :[column_name, number] -> substring`,
@@ -945,6 +957,7 @@ export class SelectItemBuilder {
945
957
  this.addItem({
946
958
  type: "column",
947
959
  columnPGDataType: colDef?.data_type,
960
+ column_udt_type: colDef?.udt_name,
948
961
  alias,
949
962
  getQuery: () => asName(fieldName),
950
963
  getFields: () => [fieldName],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "2.0.119",
3
+ "version": "2.0.123",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1 +1 @@
1
- 15516
1
+ 4994
@@ -174,6 +174,16 @@ async function isomorphic(db) {
174
174
  }
175
175
  ]);
176
176
  });
177
+ await tryRun("$unnest_words", async () => {
178
+ const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
179
+ console.trace(res);
180
+ assert_1.strict.deepStrictEqual(res, [
181
+ 'abc9',
182
+ 'abc1',
183
+ 'abc81',
184
+ 'here'
185
+ ]);
186
+ });
177
187
  /**
178
188
  * Group by/Distinct
179
189
  */
@@ -172,6 +172,17 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
172
172
  );
173
173
  });
174
174
 
175
+ await tryRun("$unnest_words", async () => {
176
+ const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
177
+ console.trace(res)
178
+ assert.deepStrictEqual( res, [
179
+ 'abc9',
180
+ 'abc1',
181
+ 'abc81',
182
+ 'here'
183
+ ]);
184
+ })
185
+
175
186
  /**
176
187
  * Group by/Distinct
177
188
  */
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "../..": {
25
25
  "name": "prostgles-server",
26
- "version": "2.0.118",
26
+ "version": "2.0.122",
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-s3": "^3.32.0",