proto.io 0.0.170 → 0.0.172

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.
@@ -2104,7 +2104,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2104
2104
  break;
2105
2105
  if (_.isNil(expr.value))
2106
2106
  return sql `${element} IS NULL`;
2107
- if (!_.isString(dataType) && dataType?.type === 'pointer' && expr.value instanceof TObject && expr.value.objectId) {
2107
+ if (!_.isString(dataType) && dataType?.type === 'pointer') {
2108
+ if (!(expr.value instanceof TObject) || dataType.target !== expr.value.className || !expr.value.objectId)
2109
+ break;
2108
2110
  return sql `${element} ${nullSafeEqual()} ${{ value: expr.value.objectId }}`;
2109
2111
  }
2110
2112
  return sql `${element} ${nullSafeEqual()} ${encodeValue(expr.value)}`;
@@ -2115,7 +2117,9 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2115
2117
  break;
2116
2118
  if (_.isNil(expr.value))
2117
2119
  return sql `${element} IS NOT NULL`;
2118
- if (!_.isString(dataType) && dataType?.type === 'pointer' && expr.value instanceof TObject && expr.value.objectId) {
2120
+ if (!_.isString(dataType) && dataType?.type === 'pointer') {
2121
+ if (!(expr.value instanceof TObject) || dataType.target !== expr.value.className || !expr.value.objectId)
2122
+ break;
2119
2123
  return sql `${element} ${nullSafeNotEqual()} ${{ value: expr.value.objectId }}`;
2120
2124
  }
2121
2125
  return sql `${element} ${nullSafeNotEqual()} ${encodeValue(expr.value)}`;
@@ -2191,7 +2195,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2191
2195
  if (!_.isString(dataType) && dataType?.type === 'pointer') {
2192
2196
  if (_.isNil(value))
2193
2197
  return sql `${element} IS NULL`;
2194
- if (!(value instanceof TObject) || !value.objectId)
2198
+ if (!(value instanceof TObject) || dataType.target !== value.className || !value.objectId)
2195
2199
  break;
2196
2200
  return sql `${element} ${nullSafeEqual()} ${{ value: value.objectId }}`;
2197
2201
  }
@@ -2201,7 +2205,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2201
2205
  const containsNil = _.some(expr.value, x => _.isNil(x));
2202
2206
  const values = _.filter(expr.value, x => !_.isNil(x));
2203
2207
  if (!_.isString(dataType) && dataType?.type === 'pointer') {
2204
- if (!_.every(values, x => x instanceof TObject && x.objectId))
2208
+ if (!_.every(values, x => x instanceof TObject && dataType.target === x.className && x.objectId))
2205
2209
  break;
2206
2210
  if (containsNil) {
2207
2211
  return sql `${element} IS NULL OR ${element} IN (${_.map(values, (x) => sql `${{ value: x.objectId }}`)})`;
@@ -2227,7 +2231,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2227
2231
  if (!_.isString(dataType) && dataType?.type === 'pointer') {
2228
2232
  if (_.isNil(value))
2229
2233
  return sql `${element} IS NOT NULL`;
2230
- if (!(value instanceof TObject) || !value.objectId)
2234
+ if (!(value instanceof TObject) || dataType.target !== value.className || !value.objectId)
2231
2235
  break;
2232
2236
  return sql `${element} ${nullSafeNotEqual()} ${{ value: value.objectId }}`;
2233
2237
  }
@@ -2237,7 +2241,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2237
2241
  const containsNil = _.some(expr.value, x => _.isNil(x));
2238
2242
  const values = _.filter(expr.value, x => !_.isNil(x));
2239
2243
  if (!_.isString(dataType) && dataType?.type === 'pointer') {
2240
- if (!_.every(values, x => x instanceof TObject && x.objectId))
2244
+ if (!_.every(values, x => x instanceof TObject && dataType.target === x.className && x.objectId))
2241
2245
  break;
2242
2246
  if (containsNil) {
2243
2247
  return sql `${element} IS NOT NULL AND ${element} NOT IN (${_.map(values, (x) => sql `${{ value: x.objectId }}`)})`;
@@ -2262,20 +2266,24 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
2262
2266
  }[expr.type];
2263
2267
  if (!_.isArray(expr.value))
2264
2268
  break;
2265
- if (_.isEmpty(expr.value))
2266
- 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
+ }
2267
2275
  if (dataType === 'array' || (!_.isString(dataType) && dataType?.type === 'array')) {
2268
2276
  return sql `${element} ${{ literal: op }} ${{ value: _encodeValue(expr.value) }}`;
2269
2277
  }
2270
2278
  if (relation && parent.className) {
2271
- if (!_.every(expr.value, x => x instanceof TObject && x.objectId))
2279
+ if (!_.every(expr.value, x => x instanceof TObject && relation.target === x.className && x.objectId))
2272
2280
  break;
2273
2281
  const tempName = `_populate_expr_$${compiler.nextIdx()}`;
2274
2282
  const populate = _selectRelationPopulate(compiler, { className: parent.className, name: parent.name }, relation.populate, `$${field}`, false);
2275
2283
  return sql `ARRAY(
2276
2284
  SELECT ${{ identifier: '_id' }}
2277
2285
  FROM (${populate}) AS ${{ identifier: tempName }}
2278
- ) ${{ literal: op }} ARRAY[${_.map(expr.value, (x) => sql `${{ value: x.objectId }}`)}]`;
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(_encodeValue(expr.value))}`;