proto.io 0.0.169 → 0.0.171

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.
@@ -2266,16 +2266,24 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2266
2266
  }[expr.type];
2267
2267
  if (!_.isArray(expr.value))
2268
2268
  break;
2269
- if (_.isEmpty(expr.value))
2270
- return sql `true`;
2269
+ if (_.isEmpty(expr.value)) {
2270
+ switch (expr.type) {
2271
+ case '$superset': return sql `true`;
2272
+ case '$intersect': return sql `false`;
2273
+ }
2274
+ }
2271
2275
  if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
2272
2276
  return sql `${element} ${{ literal: op }} ${{ value: index._encodeValue(expr.value) }}`;
2273
2277
  }
2274
2278
  if (relation && parent.className) {
2275
2279
  if (!_.every(expr.value, x => x instanceof index.TObject && x.objectId))
2276
2280
  break;
2281
+ const tempName = `_populate_expr_$${compiler.nextIdx()}`;
2277
2282
  const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
2278
- return sql `ARRAY(SELECT ${{ identifier: '_id' }} FROM (${populate})) ${{ literal: op }} ARRAY[${_.map(expr.value, (x) => sql `${{ value: x.objectId }}`)}]`;
2283
+ return sql `ARRAY(
2284
+ SELECT ${{ identifier: '_id' }}
2285
+ FROM (${populate}) AS ${{ identifier: tempName }}
2286
+ ) ${{ literal: op }} ARRAY[${_.map(expr.value, (x) => sql `${{ value: x.objectId }}`)}]::TEXT[]`;
2279
2287
  }
2280
2288
  if (!dataType) {
2281
2289
  return sql `jsonb_typeof(${element}) ${nullSafeEqual()} 'array' AND ${element} ${{ literal: op }} ${_encodeJsonValue(index._encodeValue(expr.value))}`;