proto.io 0.0.193 → 0.0.194

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.
@@ -7,7 +7,7 @@ import Decimal from 'decimal.js';
7
7
  import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
8
8
  import { a as QueryCoditionalSelector, b as QueryFieldSelector, c as QueryExpressionSelector, d as QueryDistanceExpression, e as QueryCoditionalExpression, f as QueryComparisonExpression, g as QueryNotExpression, h as QueryArrayExpression, i as QueryValueExpression, j as QueryKeyExpression, Q as QuerySelector, F as FieldSelectorExpression } from '../../internals/index-ikHjpb6F.mjs';
9
9
  import '@o2ter/crypto-js';
10
- import { r as resolveColumn, a as resolveDataType, g as generateId, Q as QueryValidator } from '../../internals/random-uHM4KXoV.mjs';
10
+ import { r as resolveColumn, a as resolveDataType$1, g as generateId, Q as QueryValidator } from '../../internals/random-uHM4KXoV.mjs';
11
11
  import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
12
12
 
13
13
  //
@@ -230,7 +230,7 @@ class QueryCompiler {
230
230
  colname,
231
231
  };
232
232
  if (isRelation(dataType) && dataType.foreignField) {
233
- const targetType = resolveDataType(this.schema, dataType.target, dataType.foreignField);
233
+ const targetType = resolveDataType$1(this.schema, dataType.target, dataType.foreignField);
234
234
  if (_.isNil(targetType))
235
235
  throw Error(`Invalid path: ${include}`);
236
236
  if (!isPointer(targetType) && !isRelation(targetType))
@@ -2901,6 +2901,21 @@ class PostgresStorageTransaction extends PostgresStorageClient {
2901
2901
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2902
2902
  // THE SOFTWARE.
2903
2903
  //
2904
+ const resolveDataType = (schema, path) => {
2905
+ let fields = schema.fields;
2906
+ let last;
2907
+ for (const key of _.toPath(path)) {
2908
+ const dataType = fields[key];
2909
+ if (_.isNil(dataType))
2910
+ throw Error(`Invalid path: ${path}`);
2911
+ if (isPrimitive(dataType) || isVector(dataType))
2912
+ return dataType;
2913
+ if (!isShape(dataType))
2914
+ return dataType;
2915
+ fields = dataType.shape;
2916
+ }
2917
+ return last;
2918
+ };
2904
2919
  class PostgresStorage extends PostgresStorageClient {
2905
2920
  constructor(config) {
2906
2921
  super(new PostgresDriver(config));
@@ -3006,7 +3021,9 @@ class PostgresStorage extends PostgresStorageClient {
3006
3021
  ],
3007
3022
  };
3008
3023
  }
3009
- _indexBasicName(className, keys) {
3024
+ _indexBasicName(className, keys, unique) {
3025
+ if (unique)
3026
+ return `${className}$u$${_.map(keys, (v, k) => `${k}:${v}`).join('$')}`;
3010
3027
  return `${className}$b$${_.map(keys, (v, k) => `${k}:${v}`).join('$')}`;
3011
3028
  }
3012
3029
  _indexVectorName(className, keys) {
@@ -3028,7 +3045,7 @@ class PostgresStorage extends PostgresStorageClient {
3028
3045
  names.push(..._.values(this._indexVectorName(className, _.castArray(index.keys))));
3029
3046
  break;
3030
3047
  default:
3031
- names.push(this._indexBasicName(className, index.keys));
3048
+ names.push(this._indexBasicName(className, index.keys, !!index.unique));
3032
3049
  break;
3033
3050
  }
3034
3051
  }
@@ -3124,16 +3141,20 @@ class PostgresStorage extends PostgresStorageClient {
3124
3141
  break;
3125
3142
  default:
3126
3143
  {
3127
- const name = this._indexBasicName(className, index.keys);
3128
- const isAcl = _.isEqual(index.keys, { _rperm: 1 }) || _.isEqual(index.keys, { _wperm: 1 });
3129
- const isRelation = _.has(relations, _.last(_.keys(index.keys)));
3144
+ const name = this._indexBasicName(className, index.keys, !!index.unique);
3145
+ const useGin = _.some(_.keys(index.keys), column => {
3146
+ const dataType = resolveDataType(schema, column);
3147
+ if (!dataType || isShape(dataType))
3148
+ throw Error('Invalid index type');
3149
+ return _isTypeof(dataType, 'string[]') || _.has(relations, column);
3150
+ });
3130
3151
  await this.query(sql `
3131
3152
  CREATE ${{ literal: index.unique ? 'UNIQUE' : '' }} INDEX CONCURRENTLY
3132
3153
  IF NOT EXISTS ${{ identifier: name }}
3133
3154
  ON ${{ identifier: className }}
3134
- ${{ literal: isAcl || isRelation ? 'USING GIN' : '' }}
3155
+ ${{ literal: useGin ? 'USING GIN' : '' }}
3135
3156
  (${_.map(index.keys, (v, k) => sql `
3136
- ${{ identifier: k }} ${{ literal: isAcl || isRelation ? '' : v === 1 ? 'ASC' : 'DESC' }}
3157
+ ${{ identifier: k }} ${{ literal: useGin ? '' : v === 1 ? 'ASC' : 'DESC' }}
3137
3158
  `)})
3138
3159
  `);
3139
3160
  }