pqb 0.43.3 → 0.43.5

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/index.d.ts CHANGED
@@ -1667,8 +1667,18 @@ interface OperatorsJson extends Base<unknown> {
1667
1667
  }
1668
1668
  type OperatorsAny = Base<any>;
1669
1669
  type OperatorsDate = Ord<Date | string>;
1670
- type OperatorsArray = Base<any>;
1671
1670
  type OperatorsTime = Ord<string>;
1671
+ interface OperatorsArray<T> extends Base<T[]> {
1672
+ has: Operator<T | IsQuery | Expression, BooleanQueryColumn>;
1673
+ hasEvery: Operator<T[] | IsQuery | Expression, BooleanQueryColumn>;
1674
+ hasSome: Operator<T[] | IsQuery | Expression, BooleanQueryColumn>;
1675
+ containedIn: Operator<T[] | IsQuery | Expression, BooleanQueryColumn>;
1676
+ length: {
1677
+ _opType: number | {
1678
+ [K in keyof OperatorsNumber]?: OperatorsNumber[K]['_opType'];
1679
+ };
1680
+ };
1681
+ }
1672
1682
  declare const Operators: {
1673
1683
  any: OperatorsAny;
1674
1684
  boolean: OperatorsBoolean;
@@ -1677,7 +1687,7 @@ declare const Operators: {
1677
1687
  time: OperatorsTime;
1678
1688
  text: OperatorsText;
1679
1689
  json: OperatorsJson;
1680
- array: OperatorsArray;
1690
+ array: OperatorsArray<unknown>;
1681
1691
  };
1682
1692
 
1683
1693
  declare class ColumnRefExpression<T extends QueryColumn> extends Expression<T> {
@@ -2675,9 +2685,9 @@ interface ArrayData<Item extends ArrayColumnValue> extends ColumnData, ArrayMeth
2675
2685
  item: Item;
2676
2686
  arrayDims: number;
2677
2687
  }
2678
- declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends ArrayColumnValue, InputType, OutputType, QueryType> extends ColumnType<Schema, Item['type'][], InputType, OperatorsArray, Item['inputType'][], Item['outputType'][], OutputType, Item['queryType'][], QueryType> {
2688
+ declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends ArrayColumnValue, InputType, OutputType, QueryType> extends ColumnType<Schema, Item['type'][], InputType, OperatorsArray<Item['queryType']>, Item['inputType'][], Item['outputType'][], OutputType, Item['queryType'][], QueryType> {
2679
2689
  dataType: "array";
2680
- operators: OperatorsArray;
2690
+ operators: OperatorsArray<Item["queryType"]>;
2681
2691
  data: ArrayData<Item>;
2682
2692
  constructor(schema: Schema, item: Item, inputType: InputType, outputType?: OutputType, queryType?: QueryType);
2683
2693
  toSQL(): string;
@@ -3748,8 +3758,8 @@ type NullableJSONAggReturn<T extends PickQueryMeta, Arg extends SelectableOrExpr
3748
3758
  type: (ExpressionOutput<T, Arg>['type'] | null)[] | null;
3749
3759
  outputType: (ExpressionOutput<T, Arg>['outputType'] | null)[] | null;
3750
3760
  queryType: (ExpressionOutput<T, Arg>['queryType'] | null)[] | null;
3751
- operators: OperatorsArray;
3752
- }> & OperatorsArray;
3761
+ operators: OperatorsArray<never>;
3762
+ }> & OperatorsArray<never>;
3753
3763
  interface RecordSelectableOrExpression<T extends PickQueryMeta> {
3754
3764
  [K: string]: SelectableOrExpression<T>;
3755
3765
  }
package/dist/index.js CHANGED
@@ -1003,9 +1003,9 @@ const makeVarArg = (_op) => {
1003
1003
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1004
1004
  );
1005
1005
  };
1006
- const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
1006
+ const quoteValue = (arg, ctx, quotedAs, IN) => {
1007
1007
  if (arg && typeof arg === "object") {
1008
- if (!jsonArray && Array.isArray(arg)) {
1008
+ if (IN && Array.isArray(arg)) {
1009
1009
  return `(${arg.map((value) => orchidCore.addValue(ctx.values, value)).join(", ")})`;
1010
1010
  }
1011
1011
  if (orchidCore.isExpression(arg)) {
@@ -1041,10 +1041,10 @@ const base = {
1041
1041
  (key, value, ctx, quotedAs) => value === null ? `${key} IS NOT NULL` : `${key} <> ${quoteValue(value, ctx, quotedAs)}`
1042
1042
  ),
1043
1043
  in: make(
1044
- (key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs)}`
1044
+ (key, value, ctx, quotedAs) => `${key} IN ${quoteValue(value, ctx, quotedAs, true)}`
1045
1045
  ),
1046
1046
  notIn: make(
1047
- (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
1047
+ (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs, true)}`
1048
1048
  )
1049
1049
  };
1050
1050
  const boolean = {
@@ -1126,10 +1126,10 @@ const json = {
1126
1126
  { _op: jsonPathQueryOp }
1127
1127
  ),
1128
1128
  jsonSupersetOf: make(
1129
- (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs, true)}`
1129
+ (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs)}`
1130
1130
  ),
1131
1131
  jsonSubsetOf: make(
1132
- (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs, true)}`
1132
+ (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs)}`
1133
1133
  ),
1134
1134
  jsonSet: makeVarArg(
1135
1135
  (key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${orchidCore.addValue(
@@ -1153,6 +1153,30 @@ const json = {
1153
1153
  (key, [path], ctx) => `(${key} #- ${encodeJsonPath(ctx, path)})`
1154
1154
  )
1155
1155
  };
1156
+ const array = {
1157
+ ...base,
1158
+ has: make(
1159
+ (key, value, ctx, quotedAs) => `${quoteValue(value, ctx, quotedAs)} = ANY(${key})`
1160
+ ),
1161
+ hasEvery: make(
1162
+ (key, value, ctx, quotedAs) => `${key} @> ${quoteValue(value, ctx, quotedAs)}`
1163
+ ),
1164
+ hasSome: make(
1165
+ (key, value, ctx, quotedAs) => `${key} && ${quoteValue(value, ctx, quotedAs)}`
1166
+ ),
1167
+ containedIn: make(
1168
+ (key, value, ctx, quotedAs) => `${key} <@ ${quoteValue(value, ctx, quotedAs)}`
1169
+ ),
1170
+ length: make((key, value, ctx, quotedAs) => {
1171
+ const expr = `COALESCE(array_length(${key}, 1), 0)`;
1172
+ return typeof value === "number" ? `${expr} = ${quoteValue(value, ctx, quotedAs)}` : Object.keys(value).map(
1173
+ (key2) => (
1174
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1175
+ numeric[key2]._op(expr, value[key2], ctx, quotedAs)
1176
+ )
1177
+ ).join(" AND ");
1178
+ })
1179
+ };
1156
1180
  const Operators = {
1157
1181
  any: base,
1158
1182
  boolean,
@@ -1161,7 +1185,7 @@ const Operators = {
1161
1185
  time: numeric,
1162
1186
  text,
1163
1187
  json,
1164
- array: base
1188
+ array
1165
1189
  };
1166
1190
 
1167
1191
  class TextBaseColumn extends ColumnType {
@@ -2138,7 +2162,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2138
2162
  } else if (key === "SEARCH") {
2139
2163
  const search = value;
2140
2164
  ands.push(`${search.vectorSQL} @@ "${search.as}"`);
2141
- } else if (typeof value === "object" && value && !(value instanceof Date)) {
2165
+ } else if (typeof value === "object" && value && !(value instanceof Date) && !Array.isArray(value)) {
2142
2166
  if (orchidCore.isExpression(value)) {
2143
2167
  ands.push(
2144
2168
  `${columnToSql(
@@ -3685,6 +3709,7 @@ class ArrayColumn extends ColumnType {
3685
3709
  }
3686
3710
  }
3687
3711
  const parse = function(source) {
3712
+ if (typeof source !== "string") return source;
3688
3713
  const entries = [];
3689
3714
  parsePostgresArray(source, entries, this.data.item.data.parseItem);
3690
3715
  return entries;
@@ -6634,7 +6659,14 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6634
6659
 
6635
6660
  const toSQLCacheKey = Symbol("toSQLCache");
6636
6661
  const toSQL = (table, options) => {
6637
- return !options?.clearCache && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6662
+ if (table.q[toSQLCacheKey] && !options?.clearCache) {
6663
+ const cached = table.q[toSQLCacheKey];
6664
+ if (options?.values && "values" in cached && cached.values && options.values !== cached.values) {
6665
+ options.values.push(...cached.values);
6666
+ }
6667
+ return cached;
6668
+ }
6669
+ return table.q[toSQLCacheKey] = makeSQL(table, options);
6638
6670
  };
6639
6671
  const makeSQL = (table, options) => {
6640
6672
  const query = table.q;
@@ -7491,6 +7523,7 @@ function makeFnExpression(self, type, fn, args, options) {
7491
7523
  options,
7492
7524
  type
7493
7525
  );
7526
+ q.q.transform = void 0;
7494
7527
  return q;
7495
7528
  }
7496
7529