proto.io 0.0.192 → 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))
@@ -1023,15 +1023,17 @@ class PostgresClientDriver {
1023
1023
  return asyncStream(async function* () {
1024
1024
  const client = db instanceof Pool ? await db.connect() : db;
1025
1025
  const stream = new QueryStream(text, values, { batchSize });
1026
- client.query(stream);
1027
- try {
1028
- yield* IteratorPool(Number.MAX_SAFE_INTEGER, stream);
1029
- }
1030
- finally {
1031
- stream.destroy();
1032
- if (db instanceof Pool)
1033
- client.release();
1034
- }
1026
+ yield* IteratorPool(Number.MAX_SAFE_INTEGER, async function* () {
1027
+ client.query(stream);
1028
+ try {
1029
+ yield* stream;
1030
+ }
1031
+ finally {
1032
+ stream.destroy();
1033
+ if (db instanceof Pool)
1034
+ client.release();
1035
+ }
1036
+ });
1035
1037
  });
1036
1038
  }
1037
1039
  async version() {
@@ -2899,6 +2901,21 @@ class PostgresStorageTransaction extends PostgresStorageClient {
2899
2901
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2900
2902
  // THE SOFTWARE.
2901
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
+ };
2902
2919
  class PostgresStorage extends PostgresStorageClient {
2903
2920
  constructor(config) {
2904
2921
  super(new PostgresDriver(config));
@@ -3004,7 +3021,9 @@ class PostgresStorage extends PostgresStorageClient {
3004
3021
  ],
3005
3022
  };
3006
3023
  }
3007
- _indexBasicName(className, keys) {
3024
+ _indexBasicName(className, keys, unique) {
3025
+ if (unique)
3026
+ return `${className}$u$${_.map(keys, (v, k) => `${k}:${v}`).join('$')}`;
3008
3027
  return `${className}$b$${_.map(keys, (v, k) => `${k}:${v}`).join('$')}`;
3009
3028
  }
3010
3029
  _indexVectorName(className, keys) {
@@ -3026,7 +3045,7 @@ class PostgresStorage extends PostgresStorageClient {
3026
3045
  names.push(..._.values(this._indexVectorName(className, _.castArray(index.keys))));
3027
3046
  break;
3028
3047
  default:
3029
- names.push(this._indexBasicName(className, index.keys));
3048
+ names.push(this._indexBasicName(className, index.keys, !!index.unique));
3030
3049
  break;
3031
3050
  }
3032
3051
  }
@@ -3122,16 +3141,20 @@ class PostgresStorage extends PostgresStorageClient {
3122
3141
  break;
3123
3142
  default:
3124
3143
  {
3125
- const name = this._indexBasicName(className, index.keys);
3126
- const isAcl = _.isEqual(index.keys, { _rperm: 1 }) || _.isEqual(index.keys, { _wperm: 1 });
3127
- 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
+ });
3128
3151
  await this.query(sql `
3129
3152
  CREATE ${{ literal: index.unique ? 'UNIQUE' : '' }} INDEX CONCURRENTLY
3130
3153
  IF NOT EXISTS ${{ identifier: name }}
3131
3154
  ON ${{ identifier: className }}
3132
- ${{ literal: isAcl || isRelation ? 'USING GIN' : '' }}
3155
+ ${{ literal: useGin ? 'USING GIN' : '' }}
3133
3156
  (${_.map(index.keys, (v, k) => sql `
3134
- ${{ identifier: k }} ${{ literal: isAcl || isRelation ? '' : v === 1 ? 'ASC' : 'DESC' }}
3157
+ ${{ identifier: k }} ${{ literal: useGin ? '' : v === 1 ? 'ASC' : 'DESC' }}
3135
3158
  `)})
3136
3159
  `);
3137
3160
  }