proto.io 0.0.211 → 0.0.212

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.
Files changed (48) hide show
  1. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  2. package/dist/adapters/file/database.d.ts +2 -2
  3. package/dist/adapters/file/database.js +1 -1
  4. package/dist/adapters/file/database.js.map +1 -1
  5. package/dist/adapters/file/database.mjs +2 -2
  6. package/dist/adapters/file/database.mjs.map +1 -1
  7. package/dist/adapters/file/filesystem.d.ts +3 -3
  8. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  9. package/dist/adapters/storage/progres.d.ts +8 -6
  10. package/dist/adapters/storage/progres.js +142 -78
  11. package/dist/adapters/storage/progres.js.map +1 -1
  12. package/dist/adapters/storage/progres.mjs +143 -79
  13. package/dist/adapters/storage/progres.mjs.map +1 -1
  14. package/dist/client.d.ts +3 -3
  15. package/dist/client.js +1 -1
  16. package/dist/client.mjs +2 -2
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +8 -8
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +10 -10
  21. package/dist/index.mjs.map +1 -1
  22. package/dist/internals/{base-BCWOHUaQ.d.ts → base-CZGalGrd.d.ts} +2 -2
  23. package/dist/internals/base-CZGalGrd.d.ts.map +1 -0
  24. package/dist/internals/{chunk-2pKgkO5-.d.ts → chunk-BsT9SYny.d.ts} +3 -3
  25. package/dist/internals/chunk-BsT9SYny.d.ts.map +1 -0
  26. package/dist/internals/{index-lTzbCO8S.d.ts → index-Boxwkqe0.d.ts} +32 -15
  27. package/dist/internals/index-Boxwkqe0.d.ts.map +1 -0
  28. package/dist/internals/{index-DPPLcZx8.mjs → index-DG9HHO_U.mjs} +2 -2
  29. package/dist/internals/{index-DPPLcZx8.mjs.map → index-DG9HHO_U.mjs.map} +1 -1
  30. package/dist/internals/{index-Btxxs0KS.js → index-DfnPpl1I.js} +16 -10
  31. package/dist/internals/index-DfnPpl1I.js.map +1 -0
  32. package/dist/internals/{index-8AdKlZUU.d.ts → index-NF-U_3zG.d.ts} +2 -2
  33. package/dist/internals/index-NF-U_3zG.d.ts.map +1 -0
  34. package/dist/internals/{index-CoeDMG5V.mjs → index-ZPbBr9Db.mjs} +16 -10
  35. package/dist/internals/index-ZPbBr9Db.mjs.map +1 -0
  36. package/dist/internals/{random-ycCeBd0S.mjs → random-CufRbivU.mjs} +121 -19
  37. package/dist/internals/random-CufRbivU.mjs.map +1 -0
  38. package/dist/internals/{random-CyU_Y2Ay.js → random-DzvxbWAc.js} +161 -58
  39. package/dist/internals/random-DzvxbWAc.js.map +1 -0
  40. package/package.json +1 -1
  41. package/dist/internals/base-BCWOHUaQ.d.ts.map +0 -1
  42. package/dist/internals/chunk-2pKgkO5-.d.ts.map +0 -1
  43. package/dist/internals/index-8AdKlZUU.d.ts.map +0 -1
  44. package/dist/internals/index-Btxxs0KS.js.map +0 -1
  45. package/dist/internals/index-CoeDMG5V.mjs.map +0 -1
  46. package/dist/internals/index-lTzbCO8S.d.ts.map +0 -1
  47. package/dist/internals/random-CyU_Y2Ay.js.map +0 -1
  48. package/dist/internals/random-ycCeBd0S.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random-CufRbivU.mjs","sources":["../../../src/internals/query/types/accumulators.ts","../../../src/server/query/dispatcher/parser/accumulators.ts","../../../src/server/query/dispatcher/validator.ts","../../../src/server/crypto/random.ts"],"sourcesContent":["//\n// accumulators.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { TExpression } from './expressions';\n\nexport const accumulatorExprKeys = ['$sum', '$avg'] as const;\nexport const accumulatorNoExprKeys = ['$count'] as const;\n\nexport type TQueryAccumulator = {\n [x in (typeof accumulatorNoExprKeys)[number]]?: true | {};\n} & {\n [x in (typeof accumulatorExprKeys)[number]]?: TExpression;\n};\n\nexport const accumulatorKeyTypes = {\n '$count': 'number',\n '$sum': 'number',\n '$avg': 'number',\n} as const;\n","//\n// accumulators.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { accumulatorExprKeys, accumulatorNoExprKeys, TQueryAccumulator } from '../../../../internals/query/types/accumulators';\nimport { QueryExpression } from './expressions';\n\ntype AccumulatorKeys = typeof accumulatorExprKeys[number] | typeof accumulatorNoExprKeys[number];\n\nexport class QueryAccumulator {\n\n type: AccumulatorKeys;\n expr?: QueryExpression;\n\n static decode(query: TQueryAccumulator): QueryAccumulator {\n for (const [key, expr] of _.toPairs(query)) {\n if (_.includes(accumulatorExprKeys, key)) {\n return new QueryAccumulator(key as AccumulatorKeys, QueryExpression.decode(expr as any ?? [], false));\n } else if (_.includes(accumulatorNoExprKeys, key)) {\n return new QueryAccumulator(key as AccumulatorKeys);\n } else {\n throw Error('Invalid expression');\n }\n }\n throw Error('Invalid expression');\n }\n\n constructor(type: AccumulatorKeys, expr?: QueryExpression) {\n this.type = type;\n this.expr = expr;\n }\n\n simplify() {\n return new QueryAccumulator(this.type, this.expr?.simplify());\n }\n\n keyPaths() {\n return this.expr?.keyPaths() ?? [];\n }\n\n mapKey(callback: (key: string) => string) {\n return new QueryAccumulator(this.type, this.expr?.mapKey(callback));\n }\n\n}\n","//\n// validator.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport _ from 'lodash';\nimport { DecodedBaseQuery, DecodedQuery, FindOptions, DecodedSortOption, RelationOptions } from '../../storage';\nimport { QueryCoditionalSelector, QueryFieldSelector, QuerySelector } from './parser';\nimport { TSchema, _typeof, isPointer, isPrimitive, isRelation, isShape, isVector, shapePaths } from '../../../internals/schema';\nimport { ProtoService } from '../../proto';\nimport { TQueryBaseOptions, TSortOption } from '../../../internals/query/base';\nimport { isPrimitiveValue } from '../../../internals/object';\nimport { TObject } from '../../../internals/object';\nimport { PVK } from '../../../internals/private';\nimport { TQuerySelector } from '../../../internals/query/types/selectors';\nimport { QueryExpression } from './parser/expressions';\nimport { TQueryAccumulator } from '../../../internals/query/types/accumulators';\nimport { QueryAccumulator } from './parser/accumulators';\n\nexport const recursiveCheck = (x: any, stack: any[]) => {\n if (_.indexOf(stack, x) !== -1) throw Error('Recursive data detected');\n if (_.isRegExp(x) || isPrimitiveValue(x) || x instanceof TObject) return;\n const children = _.isArray(x) ? x : _.values(x);\n children.forEach(v => recursiveCheck(v, [...stack, x]));\n}\n\nexport const resolveDataType = (\n schema: Record<string, TSchema>,\n classname: string,\n path: string,\n) => {\n let fields = schema[classname].fields;\n let last;\n for (const key of _.toPath(path)) {\n const dataType = fields[key];\n if (_.isNil(dataType)) throw Error(`Invalid path: ${path}`);\n if (isPrimitive(dataType) || isVector(dataType)) return dataType;\n if (isShape(dataType)) {\n fields = dataType.shape;\n continue;\n }\n if (_.isNil(schema[dataType.target])) throw Error(`Invalid path: ${path}`);\n fields = schema[dataType.target].fields;\n last = dataType;\n }\n return last;\n}\n\nexport const resolveColumn = (\n schema: Record<string, TSchema>,\n className: string,\n path: string,\n) => {\n const _schema = schema[className] ?? {};\n let [colname, ...subpath] = path.split('.');\n let dataType = _schema.fields[colname];\n while (dataType && !_.isEmpty(subpath) && isShape(dataType)) {\n const [key, ...remain] = subpath;\n if (!dataType.shape[key]) break;\n dataType = dataType.shape[key];\n colname = `${colname}.${key}`;\n subpath = remain;\n }\n return {\n paths: [colname, ...subpath],\n dataType,\n };\n}\n\ntype QueryValidatorOption = {\n master: boolean;\n disableSecurity: boolean;\n};\n\nexport class QueryValidator<E> {\n\n proto: ProtoService<E>\n acls: string[];\n options: QueryValidatorOption;\n\n static patterns = {\n path: /^[a-z_][\\w-]*(\\[\\d+\\]|\\.\\d*|\\.[a-z_][\\w-]*)*$/gi,\n className: /^[a-z_][\\w]*$/gi,\n fieldName: /^[a-z_][\\w-]*$/gi,\n digits: /^\\d+$/g,\n }\n\n _rperm(className: string) {\n if (this.options.master) return [];\n const check = _.intersection(this.schema[className]?.additionalObjectPermissions?.read, this.acls);\n if (!_.isEmpty(check)) return [];\n return [{ _rperm: { $intersect: this.acls } }];\n }\n _wperm(className: string) {\n if (this.options.master) return [];\n const check = _.intersection(this.schema[className]?.additionalObjectPermissions?.update, this.acls);\n if (!_.isEmpty(check)) return [];\n return [{ _wperm: { $intersect: this.acls } }];\n }\n _expiredAt = { $or: [{ _expired_at: { $eq: null } }, { _expired_at: { $gt: new Date() } }] };\n\n constructor(\n proto: ProtoService<E>,\n acls: string[],\n options: QueryValidatorOption,\n ) {\n this.proto = proto;\n this.acls = _.uniq(['*', ...acls]);\n this.options = options;\n }\n\n get schema() {\n return this.proto.schema;\n }\n\n get objectIdSize() {\n return this.proto[PVK].options.objectIdSize;\n }\n\n static recursiveCheck(...x: any[]) {\n recursiveCheck(x, []);\n }\n\n validateKeyPerm(\n key: string,\n type: keyof TSchema.FLPs,\n schema: TSchema,\n ) {\n key = _.first(key?.split('.')) ?? key;\n if (_.isEmpty(key) || (!_.has(schema.fields, key) && !TObject.defaultKeys.includes(key))) throw Error(`Invalid key: ${key}`);\n if (type === 'read' && TObject.defaultKeys.includes(key)) return true;\n if (type !== 'read' && TObject.defaultReadonlyKeys.includes(key)) return false;\n if (!this.options.disableSecurity && _.includes(schema.secureFields, key)) return false;\n return this.options.master || !_.every(schema.fieldLevelPermissions?.[key]?.[type] ?? ['*'], x => !_.includes(this.acls, x));\n }\n\n validateCLPs(\n className: string,\n ...keys: (keyof TSchema.CLPs)[]\n ) {\n if (!_.has(this.schema, className)) throw Error('No permission');\n return this.options.master || this.proto[PVK].validateCLPs(className, this.acls, keys);\n }\n\n validateForeignField(dataType: TSchema.RelationType, type: keyof TSchema.FLPs, errorMeg: string) {\n if (_.isNil(dataType.foreignField)) return;\n const foreignField = resolveDataType(this.schema, dataType.target, dataType.foreignField);\n if (_.isNil(foreignField) || _.isString(foreignField)) throw Error(errorMeg);\n if (isPrimitive(foreignField)) throw Error(errorMeg);\n if (foreignField.type === 'relation' && !_.isNil(foreignField.foreignField)) throw Error(errorMeg);\n if (!this.validateKeyPerm(dataType.foreignField, type, this.schema[dataType.target])) throw Error('No permission');\n }\n\n validateKey(\n className: string,\n key: string | string[],\n type: keyof TSchema.FLPs,\n validator: RegExp,\n ): boolean {\n\n const schema = this.schema[className] ?? {};\n const _key = _.isArray(key) ? key.join('.') : key;\n if (!_key.match(validator)) throw Error(`Invalid key: ${_key}`);\n\n const [colname, ..._subpath] = _.toPath(_key);\n if (!this.validateKeyPerm(colname, type, schema)) return false;\n if (_.isEmpty(_subpath) && TObject.defaultKeys.includes(colname)) return true;\n if (_.isEmpty(_subpath)) return true;\n\n const { paths: [_colname, ...subpath], dataType } = resolveColumn(this.schema, className, _key);\n const isElem = _.first(subpath)?.match(QueryValidator.patterns.digits);\n if (isElem) {\n if (dataType === 'array' || dataType === 'string[]') return true;\n if (!_.isString(dataType) && dataType.type !== 'relation') return false;\n }\n\n if (isPrimitive(dataType)) return true;\n if (isVector(dataType)) return true;\n\n const relations: (TSchema.PointerType | TSchema.RelationType)[] = [];\n\n if (isShape(dataType)) {\n for (const { type } of shapePaths(dataType)) {\n if (!isPrimitive(type) && !isVector(type)) relations.push(type);\n }\n } else {\n relations.push(dataType);\n }\n\n for (const relation of relations) {\n if (_.isNil(this.schema[relation.target])) return false;\n if (type === 'read' && !this.validateCLPs(relation.target, 'get')) return false;\n if (relation.type === 'relation') this.validateForeignField(relation, type, `Invalid key: ${_key}`);\n }\n\n if (isShape(dataType)) {\n if (!_.isEmpty(subpath)) throw Error(`Invalid key: ${_key}`);\n return true;\n }\n\n const _sub = isElem ? subpath.slice(1) : subpath;\n return _.isEmpty(_sub) || this.validateKey(dataType.target, _sub, type, validator);\n }\n\n validateFields<T extends Record<string, any>>(\n className: string,\n values: T,\n type: keyof TSchema.FLPs,\n validator: RegExp,\n ) {\n const _values = { ...values };\n for (const key of _.keys(_values)) {\n if (!this.validateKey(className, key, type, validator)) throw Error('No permission');\n }\n return _values;\n }\n\n decodeGroupMatches(className: string, groupMatches: Record<string, Record<string, TQueryAccumulator>>): Record<string, Record<string, QueryAccumulator>> {\n const result = _.mapValues(groupMatches, m => _.mapValues(m, x => QueryAccumulator.decode(x).simplify()));\n for (const [colname, group] of _.entries(result)) {\n const dataType = resolveDataType(this.schema, className, colname);\n if (!dataType || !isRelation(dataType)) throw Error(`Invalid relation key: ${colname}`);\n for (const key of _.keys(group)) {\n if (!key.match(QueryValidator.patterns.fieldName)) throw Error(`Invalid field name: ${key}`);\n }\n }\n return result;\n }\n\n decodeIncludes(className: string, includes: string[], groupMatches: Record<string, Record<string, QueryAccumulator>>): string[] {\n\n const schema = this.schema[className] ?? {};\n\n const _includes: string[] = [];\n const populates: Record<string, {\n className: string;\n subpaths: string[];\n groupMatches: Record<string, Record<string, QueryAccumulator>>;\n }> = {};\n\n for (const include of includes) {\n if (include === '*') {\n const primitive = _.pickBy(schema.fields, (v, k) => isPrimitive(v) && this.validateKeyPerm(k, 'read', schema));\n const shapedObject = _.pickBy(schema.fields, (v, k) => isShape(v) && this.validateKeyPerm(k, 'read', schema));\n _includes.push(\n ..._.keys(primitive),\n ..._.flatMap(shapedObject, (v, k) => _.flatMap(shapePaths(v as any), x => isPrimitive(x.type) ? [`${k}.${x.path}`] : [])),\n );\n } else {\n const { paths: [colname, ...subpath], dataType } = resolveColumn(this.schema, className, include);\n if (!this.validateKeyPerm(colname, 'read', schema)) throw Error('No permission');\n\n if (isPointer(dataType) || isRelation(dataType)) {\n if (!this.validateCLPs(dataType.target, 'get')) throw Error('No permission');\n if (dataType.type === 'relation') this.validateForeignField(dataType, 'read', `Invalid include: ${include}`);\n\n const isDigit = _.first(subpath)?.match(QueryValidator.patterns.digits);\n const _subpath = isRelation(dataType) && isDigit ? _.slice(subpath, 1) : subpath;\n\n populates[colname] = populates[colname] ?? { className: dataType.target, subpaths: [], groupMatches: {} };\n const s = _.first(_subpath);\n if (!s || !groupMatches[colname]?.[s]) {\n populates[colname].subpaths.push(_.isEmpty(_subpath) ? '*' : _subpath.join('.'));\n populates[colname].groupMatches = _.mapKeys(_.pickBy(groupMatches, (x, k) => _.startsWith(k, `${colname}.`)), (x, k) => k.slice(colname.length + 1));\n }\n\n } else if (_.isEmpty(subpath) && isShape(dataType)) {\n\n for (const { path, type } of shapePaths(dataType)) {\n if (isPrimitive(type) || isVector(type)) {\n _includes.push(`${colname}.${path}`);\n } else {\n\n if (!this.validateCLPs(type.target, 'get')) throw Error('No permission');\n if (type.type === 'relation') this.validateForeignField(type, 'read', `Invalid include: ${include}`);\n\n populates[`${colname}.${path}`] = populates[`${colname}.${path}`] ?? { className: type.target, subpaths: [], groupMatches: {} };\n populates[`${colname}.${path}`].subpaths.push('*');\n populates[`${colname}.${path}`].groupMatches = _.mapKeys(_.pickBy(groupMatches, (x, k) => _.startsWith(k, `${colname}.${path}.`)), (x, k) => k.slice(`${colname}.${path}`.length + 1));\n }\n }\n\n } else if (_.isEmpty(subpath) || _.includes(['object', 'array'], _typeof(dataType))) {\n _includes.push(colname);\n } else {\n throw Error(`Invalid include: ${include}`);\n }\n }\n }\n\n for (const [key, populate] of _.toPairs(populates)) {\n const subpaths = this.decodeIncludes(populate.className, populate.subpaths, populate.groupMatches);\n _includes.push(..._.map(subpaths, x => `${key}.${x}`));\n }\n\n _includes.push(...TObject.defaultKeys);\n return _.uniq(_includes);\n }\n\n decodeSort(sort: Record<string, 1 | -1> | TSortOption[]): Record<string, 1 | -1> | DecodedSortOption[] {\n if (_.isArray(sort)) {\n return _.map(sort, s => ({\n order: s.order,\n expr: QueryExpression.decode(s.expr, false).simplify(),\n }))\n }\n return sort;\n }\n\n decodeMatches(className: string, matches: Record<string, TQueryBaseOptions>, includes: string[]): Record<string, DecodedBaseQuery> {\n\n const schema = this.schema[className] ?? {};\n const _matches: Record<string, DecodedBaseQuery> = {};\n\n const _includes = _.groupBy(_.map(includes, x => resolveColumn(this.schema, className, x)), ({ paths: [colname] }) => colname);\n\n for (const [colname, [{ dataType }]] of _.entries(_includes)) {\n if (!this.validateKeyPerm(colname, 'read', schema)) continue;\n if (isPrimitive(dataType) || isVector(dataType) || isShape(dataType)) continue;\n _matches[colname] = {\n matches: this.decodeMatches(\n dataType.target, {},\n includes.filter(x => x.startsWith(`${colname}.`)).map(x => x.slice(colname.length + 1)),\n ),\n };\n }\n\n for (const [colname, match] of _.toPairs(matches)) {\n if (!this.validateKeyPerm(colname, 'read', schema)) throw Error('No permission');\n\n const { paths: [_colname, ...subpath], dataType } = resolveColumn(this.schema, className, colname);\n\n if (isPointer(dataType) && !_.isEmpty(subpath)) {\n _matches[_colname] = {\n matches: this.decodeMatches(\n dataType.target, { [subpath.join('.')]: match },\n includes.filter(x => x.startsWith(`${_colname}.`)).map(x => x.slice(_colname.length + 1)),\n ),\n };\n } else if (isRelation(dataType)) {\n if (!this.validateCLPs(dataType.target, 'get')) throw Error('No permission');\n this.validateForeignField(dataType, 'read', `Invalid match: ${colname}`);\n const groupMatches = this.decodeGroupMatches(dataType.target, match.groupMatches ?? {});\n _matches[_colname] = {\n ...match,\n groupMatches,\n filter: QuerySelector.decode(_.castArray<TQuerySelector>(match.filter)).simplify(),\n matches: this.decodeMatches(\n dataType.target, match.matches ?? {},\n includes.filter(x => x.startsWith(`${_colname}.`)).map(x => x.slice(_colname.length + 1)),\n ),\n sort: match.sort && this.decodeSort(match.sort),\n };\n } else {\n throw Error(`Invalid match: ${colname}`);\n }\n }\n\n return _matches;\n }\n\n validateRelatedBy(className: string | null, relation: { className: string; key: string; }) {\n\n if (!this.validateCLPs(relation.className, 'get')) throw Error('No permission');\n if (!this.validateKey(relation.className, relation.key, 'read', QueryValidator.patterns.path)) throw Error('No permission');\n\n const { dataType } = resolveColumn(this.schema, relation.className, relation.key);\n if (!isPointer(dataType) && !isRelation(dataType)) throw Error(`Invalid relation key: ${relation.key}`);\n if (className && dataType.target !== className) throw Error(`Invalid relation key: ${relation.key}`);\n\n if (isRelation(dataType) && dataType.foreignField) {\n this.validateForeignField(dataType, 'read', `Invalid relation key: ${relation.key}`);\n this.validateRelatedBy(null, { className: dataType.target, key: dataType.foreignField });\n }\n }\n\n decodeQuery<Q extends FindOptions & RelationOptions>(query: Q, action: keyof TSchema.ACLs): DecodedQuery<Q> {\n\n if ('relatedBy' in query && query.relatedBy) this.validateRelatedBy(query.className, query.relatedBy);\n\n const filter = QuerySelector.decode([\n ...action === 'read' ? this._rperm(query.className) : this._wperm(query.className),\n ..._.castArray<TQuerySelector>(query.filter),\n this._expiredAt,\n ]).simplify();\n\n const groupMatches = this.decodeGroupMatches(query.className, query.groupMatches ?? {});\n\n const matchKeyPaths = (\n matches: Record<string, TQueryBaseOptions>\n ): string[] => _.flatMap(matches, (match, key) => [\n ..._.keys(match.sort),\n ...QuerySelector.decode(match.filter ?? []).keyPaths(),\n ...matchKeyPaths(match.matches ?? {}),\n ..._.keys(match.groupMatches),\n ..._.flatMap(_.values(match.groupMatches), x => QueryAccumulator.decode(x).keyPaths()),\n ].map(x => `${key}.${x}`));\n\n const sort = query.sort && this.decodeSort(query.sort);\n\n const keyPaths = _.uniq([\n ...query.includes ?? ['*'],\n ..._.isArray(sort) ? _.flatMap(sort, s => s.expr.keyPaths()) : _.keys(sort),\n ...filter.keyPaths(),\n ...matchKeyPaths(query.matches ?? {}),\n ..._.keys(groupMatches),\n ..._.flatMap(_.values(groupMatches), m => _.flatMap(_.values(m), x => x.keyPaths())),\n ]);\n\n const includes = this.decodeIncludes(query.className, keyPaths, groupMatches);\n const matches = this.decodeMatches(query.className, query.matches ?? {}, includes);\n\n return {\n ...query,\n groupMatches,\n filter,\n matches,\n includes,\n sort,\n objectIdSize: this.objectIdSize,\n extraFilter: (className) => QuerySelector.decode([...this._rperm(className), this._expiredAt]).simplify(),\n };\n }\n\n isGetMethod(query: QuerySelector) {\n\n const objectIds = [];\n\n if (query instanceof QueryCoditionalSelector && query.type === '$and') {\n for (const expr of query.exprs) {\n if (\n expr instanceof QueryFieldSelector &&\n expr.field === '_id' &&\n expr.expr.type === '$eq'\n ) {\n if (!_.isString(expr.expr.value)) return false;\n objectIds.push(expr.expr.value);\n }\n }\n } else if (\n query instanceof QueryFieldSelector &&\n query.field === '_id' &&\n query.expr.type === '$eq'\n ) {\n if (!_.isString(query.expr.value)) return false;\n objectIds.push(query.expr.value);\n }\n\n return _.uniq(objectIds).length === 1;\n }\n\n}\n","//\n// random.ts\n//\n// The MIT License\n// Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n//\n\nimport { randomBytes } from '@o2ter/crypto-js';\n\nconst chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n\nexport const generateId = (size: number): string => {\n let id = '';\n for (const x of randomBytes(size)) {\n id += chars[x % chars.length];\n }\n return id;\n}\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIO,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAU;AACrD,MAAM,qBAAqB,GAAG,CAAC,QAAQ,CAAU;AAQ3C,MAAA,mBAAmB,GAAG;AACjC,IAAA,QAAQ,EAAE,QAAQ;AAClB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,MAAM,EAAE,QAAQ;;;ACvClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAQa,gBAAgB,CAAA;AAE3B,IAAA,IAAI;AACJ,IAAA,IAAI;IAEJ,OAAO,MAAM,CAAC,KAAwB,EAAA;AACpC,QAAA,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC1C,IAAI,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EAAE,IAAI,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;;AAE/B,IAAA,OAAO,EAAE;AACX;;;;"}
@@ -1,11 +1,99 @@
1
1
  'use strict';
2
2
 
3
3
  var _ = require('lodash');
4
- var index$1 = require('./index-D8O7SinR.js');
5
- var index = require('./index-B8TESzd9.js');
4
+ var index = require('./index-D8O7SinR.js');
5
+ var index$1 = require('./index-B8TESzd9.js');
6
6
  var _private = require('./private-Ciddhure.js');
7
7
  var cryptoJs = require('@o2ter/crypto-js');
8
8
 
9
+ //
10
+ // accumulators.ts
11
+ //
12
+ // The MIT License
13
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
14
+ //
15
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ // of this software and associated documentation files (the "Software"), to deal
17
+ // in the Software without restriction, including without limitation the rights
18
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ // copies of the Software, and to permit persons to whom the Software is
20
+ // furnished to do so, subject to the following conditions:
21
+ //
22
+ // The above copyright notice and this permission notice shall be included in
23
+ // all copies or substantial portions of the Software.
24
+ //
25
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31
+ // THE SOFTWARE.
32
+ //
33
+ const accumulatorExprKeys = ['$sum', '$avg'];
34
+ const accumulatorNoExprKeys = ['$count'];
35
+ const accumulatorKeyTypes = {
36
+ '$count': 'number',
37
+ '$sum': 'number',
38
+ '$avg': 'number',
39
+ };
40
+
41
+ //
42
+ // accumulators.ts
43
+ //
44
+ // The MIT License
45
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
46
+ //
47
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
48
+ // of this software and associated documentation files (the "Software"), to deal
49
+ // in the Software without restriction, including without limitation the rights
50
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51
+ // copies of the Software, and to permit persons to whom the Software is
52
+ // furnished to do so, subject to the following conditions:
53
+ //
54
+ // The above copyright notice and this permission notice shall be included in
55
+ // all copies or substantial portions of the Software.
56
+ //
57
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
63
+ // THE SOFTWARE.
64
+ //
65
+ class QueryAccumulator {
66
+ type;
67
+ expr;
68
+ static decode(query) {
69
+ for (const [key, expr] of _.toPairs(query)) {
70
+ if (_.includes(accumulatorExprKeys, key)) {
71
+ return new QueryAccumulator(key, index.QueryExpression.decode(expr ?? [], false));
72
+ }
73
+ else if (_.includes(accumulatorNoExprKeys, key)) {
74
+ return new QueryAccumulator(key);
75
+ }
76
+ else {
77
+ throw Error('Invalid expression');
78
+ }
79
+ }
80
+ throw Error('Invalid expression');
81
+ }
82
+ constructor(type, expr) {
83
+ this.type = type;
84
+ this.expr = expr;
85
+ }
86
+ simplify() {
87
+ return new QueryAccumulator(this.type, this.expr?.simplify());
88
+ }
89
+ keyPaths() {
90
+ return this.expr?.keyPaths() ?? [];
91
+ }
92
+ mapKey(callback) {
93
+ return new QueryAccumulator(this.type, this.expr?.mapKey(callback));
94
+ }
95
+ }
96
+
9
97
  //
10
98
  // validator.ts
11
99
  //
@@ -33,7 +121,7 @@ var cryptoJs = require('@o2ter/crypto-js');
33
121
  const recursiveCheck = (x, stack) => {
34
122
  if (_.indexOf(stack, x) !== -1)
35
123
  throw Error('Recursive data detected');
36
- if (_.isRegExp(x) || index.isPrimitiveValue(x) || x instanceof index.TObject)
124
+ if (_.isRegExp(x) || index$1.isPrimitiveValue(x) || x instanceof index$1.TObject)
37
125
  return;
38
126
  const children = _.isArray(x) ? x : _.values(x);
39
127
  children.forEach(v => recursiveCheck(v, [...stack, x]));
@@ -45,9 +133,9 @@ const resolveDataType = (schema, classname, path) => {
45
133
  const dataType = fields[key];
46
134
  if (_.isNil(dataType))
47
135
  throw Error(`Invalid path: ${path}`);
48
- if (index.isPrimitive(dataType) || index.isVector(dataType))
136
+ if (index$1.isPrimitive(dataType) || index$1.isVector(dataType))
49
137
  return dataType;
50
- if (index.isShape(dataType)) {
138
+ if (index$1.isShape(dataType)) {
51
139
  fields = dataType.shape;
52
140
  continue;
53
141
  }
@@ -62,7 +150,7 @@ const resolveColumn = (schema, className, path) => {
62
150
  const _schema = schema[className] ?? {};
63
151
  let [colname, ...subpath] = path.split('.');
64
152
  let dataType = _schema.fields[colname];
65
- while (dataType && !_.isEmpty(subpath) && index.isShape(dataType)) {
153
+ while (dataType && !_.isEmpty(subpath) && index$1.isShape(dataType)) {
66
154
  const [key, ...remain] = subpath;
67
155
  if (!dataType.shape[key])
68
156
  break;
@@ -118,11 +206,11 @@ class QueryValidator {
118
206
  }
119
207
  validateKeyPerm(key, type, schema) {
120
208
  key = _.first(key?.split('.')) ?? key;
121
- if (_.isEmpty(key) || (!_.has(schema.fields, key) && !index.TObject.defaultKeys.includes(key)))
209
+ if (_.isEmpty(key) || (!_.has(schema.fields, key) && !index$1.TObject.defaultKeys.includes(key)))
122
210
  throw Error(`Invalid key: ${key}`);
123
- if (type === 'read' && index.TObject.defaultKeys.includes(key))
211
+ if (type === 'read' && index$1.TObject.defaultKeys.includes(key))
124
212
  return true;
125
- if (type !== 'read' && index.TObject.defaultReadonlyKeys.includes(key))
213
+ if (type !== 'read' && index$1.TObject.defaultReadonlyKeys.includes(key))
126
214
  return false;
127
215
  if (!this.options.disableSecurity && _.includes(schema.secureFields, key))
128
216
  return false;
@@ -139,7 +227,7 @@ class QueryValidator {
139
227
  const foreignField = resolveDataType(this.schema, dataType.target, dataType.foreignField);
140
228
  if (_.isNil(foreignField) || _.isString(foreignField))
141
229
  throw Error(errorMeg);
142
- if (index.isPrimitive(foreignField))
230
+ if (index$1.isPrimitive(foreignField))
143
231
  throw Error(errorMeg);
144
232
  if (foreignField.type === 'relation' && !_.isNil(foreignField.foreignField))
145
233
  throw Error(errorMeg);
@@ -154,7 +242,7 @@ class QueryValidator {
154
242
  const [colname, ..._subpath] = _.toPath(_key);
155
243
  if (!this.validateKeyPerm(colname, type, schema))
156
244
  return false;
157
- if (_.isEmpty(_subpath) && index.TObject.defaultKeys.includes(colname))
245
+ if (_.isEmpty(_subpath) && index$1.TObject.defaultKeys.includes(colname))
158
246
  return true;
159
247
  if (_.isEmpty(_subpath))
160
248
  return true;
@@ -166,14 +254,14 @@ class QueryValidator {
166
254
  if (!_.isString(dataType) && dataType.type !== 'relation')
167
255
  return false;
168
256
  }
169
- if (index.isPrimitive(dataType))
257
+ if (index$1.isPrimitive(dataType))
170
258
  return true;
171
- if (index.isVector(dataType))
259
+ if (index$1.isVector(dataType))
172
260
  return true;
173
261
  const relations = [];
174
- if (index.isShape(dataType)) {
175
- for (const { type } of index.shapePaths(dataType)) {
176
- if (!index.isPrimitive(type) && !index.isVector(type))
262
+ if (index$1.isShape(dataType)) {
263
+ for (const { type } of index$1.shapePaths(dataType)) {
264
+ if (!index$1.isPrimitive(type) && !index$1.isVector(type))
177
265
  relations.push(type);
178
266
  }
179
267
  }
@@ -188,7 +276,7 @@ class QueryValidator {
188
276
  if (relation.type === 'relation')
189
277
  this.validateForeignField(relation, type, `Invalid key: ${_key}`);
190
278
  }
191
- if (index.isShape(dataType)) {
279
+ if (index$1.isShape(dataType)) {
192
280
  if (!_.isEmpty(subpath))
193
281
  throw Error(`Invalid key: ${_key}`);
194
282
  return true;
@@ -204,40 +292,50 @@ class QueryValidator {
204
292
  }
205
293
  return _values;
206
294
  }
207
- validateCountMatches(className, countMatches) {
208
- for (const colname of countMatches) {
295
+ decodeGroupMatches(className, groupMatches) {
296
+ const result = _.mapValues(groupMatches, m => _.mapValues(m, x => QueryAccumulator.decode(x).simplify()));
297
+ for (const [colname, group] of _.entries(result)) {
209
298
  const dataType = resolveDataType(this.schema, className, colname);
210
- if (!dataType || !index.isRelation(dataType))
299
+ if (!dataType || !index$1.isRelation(dataType))
211
300
  throw Error(`Invalid relation key: ${colname}`);
301
+ for (const key of _.keys(group)) {
302
+ if (!key.match(QueryValidator.patterns.fieldName))
303
+ throw Error(`Invalid field name: ${key}`);
304
+ }
212
305
  }
306
+ return result;
213
307
  }
214
- decodeIncludes(className, includes) {
308
+ decodeIncludes(className, includes, groupMatches) {
215
309
  const schema = this.schema[className] ?? {};
216
310
  const _includes = [];
217
311
  const populates = {};
218
312
  for (const include of includes) {
219
313
  if (include === '*') {
220
- const primitive = _.pickBy(schema.fields, (v, k) => index.isPrimitive(v) && this.validateKeyPerm(k, 'read', schema));
221
- const shapedObject = _.pickBy(schema.fields, (v, k) => index.isShape(v) && this.validateKeyPerm(k, 'read', schema));
222
- _includes.push(..._.keys(primitive), ..._.flatMap(shapedObject, (v, k) => _.flatMap(index.shapePaths(v), x => index.isPrimitive(x.type) ? [`${k}.${x.path}`] : [])));
314
+ const primitive = _.pickBy(schema.fields, (v, k) => index$1.isPrimitive(v) && this.validateKeyPerm(k, 'read', schema));
315
+ const shapedObject = _.pickBy(schema.fields, (v, k) => index$1.isShape(v) && this.validateKeyPerm(k, 'read', schema));
316
+ _includes.push(..._.keys(primitive), ..._.flatMap(shapedObject, (v, k) => _.flatMap(index$1.shapePaths(v), x => index$1.isPrimitive(x.type) ? [`${k}.${x.path}`] : [])));
223
317
  }
224
318
  else {
225
319
  const { paths: [colname, ...subpath], dataType } = resolveColumn(this.schema, className, include);
226
320
  if (!this.validateKeyPerm(colname, 'read', schema))
227
321
  throw Error('No permission');
228
- if (index.isPointer(dataType) || index.isRelation(dataType)) {
322
+ if (index$1.isPointer(dataType) || index$1.isRelation(dataType)) {
229
323
  if (!this.validateCLPs(dataType.target, 'get'))
230
324
  throw Error('No permission');
231
325
  if (dataType.type === 'relation')
232
326
  this.validateForeignField(dataType, 'read', `Invalid include: ${include}`);
233
327
  const isDigit = _.first(subpath)?.match(QueryValidator.patterns.digits);
234
- const _subpath = index.isRelation(dataType) && isDigit ? _.slice(subpath, 1) : subpath;
235
- populates[colname] = populates[colname] ?? { className: dataType.target, subpaths: [] };
236
- populates[colname].subpaths.push(_.isEmpty(_subpath) ? '*' : _subpath.join('.'));
328
+ const _subpath = index$1.isRelation(dataType) && isDigit ? _.slice(subpath, 1) : subpath;
329
+ populates[colname] = populates[colname] ?? { className: dataType.target, subpaths: [], groupMatches: {} };
330
+ const s = _.first(_subpath);
331
+ if (!s || !groupMatches[colname]?.[s]) {
332
+ populates[colname].subpaths.push(_.isEmpty(_subpath) ? '*' : _subpath.join('.'));
333
+ populates[colname].groupMatches = _.mapKeys(_.pickBy(groupMatches, (x, k) => _.startsWith(k, `${colname}.`)), (x, k) => k.slice(colname.length + 1));
334
+ }
237
335
  }
238
- else if (_.isEmpty(subpath) && index.isShape(dataType)) {
239
- for (const { path, type } of index.shapePaths(dataType)) {
240
- if (index.isPrimitive(type) || index.isVector(type)) {
336
+ else if (_.isEmpty(subpath) && index$1.isShape(dataType)) {
337
+ for (const { path, type } of index$1.shapePaths(dataType)) {
338
+ if (index$1.isPrimitive(type) || index$1.isVector(type)) {
241
339
  _includes.push(`${colname}.${path}`);
242
340
  }
243
341
  else {
@@ -245,12 +343,13 @@ class QueryValidator {
245
343
  throw Error('No permission');
246
344
  if (type.type === 'relation')
247
345
  this.validateForeignField(type, 'read', `Invalid include: ${include}`);
248
- populates[`${colname}.${path}`] = populates[`${colname}.${path}`] ?? { className: type.target, subpaths: [] };
346
+ populates[`${colname}.${path}`] = populates[`${colname}.${path}`] ?? { className: type.target, subpaths: [], groupMatches: {} };
249
347
  populates[`${colname}.${path}`].subpaths.push('*');
348
+ populates[`${colname}.${path}`].groupMatches = _.mapKeys(_.pickBy(groupMatches, (x, k) => _.startsWith(k, `${colname}.${path}.`)), (x, k) => k.slice(`${colname}.${path}`.length + 1));
250
349
  }
251
350
  }
252
351
  }
253
- else if (_.isEmpty(subpath) || _.includes(['object', 'array'], index._typeof(dataType))) {
352
+ else if (_.isEmpty(subpath) || _.includes(['object', 'array'], index$1._typeof(dataType))) {
254
353
  _includes.push(colname);
255
354
  }
256
355
  else {
@@ -259,17 +358,17 @@ class QueryValidator {
259
358
  }
260
359
  }
261
360
  for (const [key, populate] of _.toPairs(populates)) {
262
- const subpaths = this.decodeIncludes(populate.className, populate.subpaths);
361
+ const subpaths = this.decodeIncludes(populate.className, populate.subpaths, populate.groupMatches);
263
362
  _includes.push(..._.map(subpaths, x => `${key}.${x}`));
264
363
  }
265
- _includes.push(...index.TObject.defaultKeys);
364
+ _includes.push(...index$1.TObject.defaultKeys);
266
365
  return _.uniq(_includes);
267
366
  }
268
367
  decodeSort(sort) {
269
368
  if (_.isArray(sort)) {
270
369
  return _.map(sort, s => ({
271
370
  order: s.order,
272
- expr: index$1.QueryExpression.decode(s.expr, false).simplify(),
371
+ expr: index.QueryExpression.decode(s.expr, false).simplify(),
273
372
  }));
274
373
  }
275
374
  return sort;
@@ -281,7 +380,7 @@ class QueryValidator {
281
380
  for (const [colname, [{ dataType }]] of _.entries(_includes)) {
282
381
  if (!this.validateKeyPerm(colname, 'read', schema))
283
382
  continue;
284
- if (index.isPrimitive(dataType) || index.isVector(dataType) || index.isShape(dataType))
383
+ if (index$1.isPrimitive(dataType) || index$1.isVector(dataType) || index$1.isShape(dataType))
285
384
  continue;
286
385
  _matches[colname] = {
287
386
  matches: this.decodeMatches(dataType.target, {}, includes.filter(x => x.startsWith(`${colname}.`)).map(x => x.slice(colname.length + 1))),
@@ -291,19 +390,20 @@ class QueryValidator {
291
390
  if (!this.validateKeyPerm(colname, 'read', schema))
292
391
  throw Error('No permission');
293
392
  const { paths: [_colname, ...subpath], dataType } = resolveColumn(this.schema, className, colname);
294
- if (index.isPointer(dataType) && !_.isEmpty(subpath)) {
393
+ if (index$1.isPointer(dataType) && !_.isEmpty(subpath)) {
295
394
  _matches[_colname] = {
296
395
  matches: this.decodeMatches(dataType.target, { [subpath.join('.')]: match }, includes.filter(x => x.startsWith(`${_colname}.`)).map(x => x.slice(_colname.length + 1))),
297
396
  };
298
397
  }
299
- else if (index.isRelation(dataType)) {
398
+ else if (index$1.isRelation(dataType)) {
300
399
  if (!this.validateCLPs(dataType.target, 'get'))
301
400
  throw Error('No permission');
302
401
  this.validateForeignField(dataType, 'read', `Invalid match: ${colname}`);
402
+ const groupMatches = this.decodeGroupMatches(dataType.target, match.groupMatches ?? {});
303
403
  _matches[_colname] = {
304
404
  ...match,
305
- countMatches: match.countMatches ?? [],
306
- filter: index$1.QuerySelector.decode(_.castArray(match.filter)).simplify(),
405
+ groupMatches,
406
+ filter: index.QuerySelector.decode(_.castArray(match.filter)).simplify(),
307
407
  matches: this.decodeMatches(dataType.target, match.matches ?? {}, includes.filter(x => x.startsWith(`${_colname}.`)).map(x => x.slice(_colname.length + 1))),
308
408
  sort: match.sort && this.decodeSort(match.sort),
309
409
  };
@@ -320,11 +420,11 @@ class QueryValidator {
320
420
  if (!this.validateKey(relation.className, relation.key, 'read', QueryValidator.patterns.path))
321
421
  throw Error('No permission');
322
422
  const { dataType } = resolveColumn(this.schema, relation.className, relation.key);
323
- if (!index.isPointer(dataType) && !index.isRelation(dataType))
423
+ if (!index$1.isPointer(dataType) && !index$1.isRelation(dataType))
324
424
  throw Error(`Invalid relation key: ${relation.key}`);
325
425
  if (className && dataType.target !== className)
326
426
  throw Error(`Invalid relation key: ${relation.key}`);
327
- if (index.isRelation(dataType) && dataType.foreignField) {
427
+ if (index$1.isRelation(dataType) && dataType.foreignField) {
328
428
  this.validateForeignField(dataType, 'read', `Invalid relation key: ${relation.key}`);
329
429
  this.validateRelatedBy(null, { className: dataType.target, key: dataType.foreignField });
330
430
  }
@@ -332,44 +432,46 @@ class QueryValidator {
332
432
  decodeQuery(query, action) {
333
433
  if ('relatedBy' in query && query.relatedBy)
334
434
  this.validateRelatedBy(query.className, query.relatedBy);
335
- this.validateCountMatches(query.className, query.countMatches ?? []);
336
- const filter = index$1.QuerySelector.decode([
435
+ const filter = index.QuerySelector.decode([
337
436
  ...action === 'read' ? this._rperm(query.className) : this._wperm(query.className),
338
437
  ..._.castArray(query.filter),
339
438
  this._expiredAt,
340
439
  ]).simplify();
341
- const matcheKeyPaths = (matches) => _.flatMap(matches, (match, key) => [
440
+ const groupMatches = this.decodeGroupMatches(query.className, query.groupMatches ?? {});
441
+ const matchKeyPaths = (matches) => _.flatMap(matches, (match, key) => [
342
442
  ..._.keys(match.sort),
343
- ...index$1.QuerySelector.decode(match.filter ?? []).keyPaths(),
344
- ...matcheKeyPaths(match.matches ?? {}),
345
- ...match.countMatches ?? [],
443
+ ...index.QuerySelector.decode(match.filter ?? []).keyPaths(),
444
+ ...matchKeyPaths(match.matches ?? {}),
445
+ ..._.keys(match.groupMatches),
446
+ ..._.flatMap(_.values(match.groupMatches), x => QueryAccumulator.decode(x).keyPaths()),
346
447
  ].map(x => `${key}.${x}`));
347
448
  const sort = query.sort && this.decodeSort(query.sort);
348
449
  const keyPaths = _.uniq([
349
450
  ...query.includes ?? ['*'],
350
451
  ..._.isArray(sort) ? _.flatMap(sort, s => s.expr.keyPaths()) : _.keys(sort),
351
452
  ...filter.keyPaths(),
352
- ...matcheKeyPaths(query.matches ?? {}),
353
- ...query.countMatches ?? [],
453
+ ...matchKeyPaths(query.matches ?? {}),
454
+ ..._.keys(groupMatches),
455
+ ..._.flatMap(_.values(groupMatches), m => _.flatMap(_.values(m), x => x.keyPaths())),
354
456
  ]);
355
- const includes = this.decodeIncludes(query.className, keyPaths);
457
+ const includes = this.decodeIncludes(query.className, keyPaths, groupMatches);
356
458
  const matches = this.decodeMatches(query.className, query.matches ?? {}, includes);
357
459
  return {
358
460
  ...query,
359
- countMatches: query.countMatches ?? [],
461
+ groupMatches,
360
462
  filter,
361
463
  matches,
362
464
  includes,
363
465
  sort,
364
466
  objectIdSize: this.objectIdSize,
365
- extraFilter: (className) => index$1.QuerySelector.decode([...this._rperm(className), this._expiredAt]).simplify(),
467
+ extraFilter: (className) => index.QuerySelector.decode([...this._rperm(className), this._expiredAt]).simplify(),
366
468
  };
367
469
  }
368
470
  isGetMethod(query) {
369
471
  const objectIds = [];
370
- if (query instanceof index$1.QueryCoditionalSelector && query.type === '$and') {
472
+ if (query instanceof index.QueryCoditionalSelector && query.type === '$and') {
371
473
  for (const expr of query.exprs) {
372
- if (expr instanceof index$1.QueryFieldSelector &&
474
+ if (expr instanceof index.QueryFieldSelector &&
373
475
  expr.field === '_id' &&
374
476
  expr.expr.type === '$eq') {
375
477
  if (!_.isString(expr.expr.value))
@@ -378,7 +480,7 @@ class QueryValidator {
378
480
  }
379
481
  }
380
482
  }
381
- else if (query instanceof index$1.QueryFieldSelector &&
483
+ else if (query instanceof index.QueryFieldSelector &&
382
484
  query.field === '_id' &&
383
485
  query.expr.type === '$eq') {
384
486
  if (!_.isString(query.expr.value))
@@ -423,7 +525,8 @@ const generateId = (size) => {
423
525
  };
424
526
 
425
527
  exports.QueryValidator = QueryValidator;
528
+ exports.accumulatorKeyTypes = accumulatorKeyTypes;
426
529
  exports.generateId = generateId;
427
530
  exports.resolveColumn = resolveColumn;
428
531
  exports.resolveDataType = resolveDataType;
429
- //# sourceMappingURL=random-CyU_Y2Ay.js.map
532
+ //# sourceMappingURL=random-DzvxbWAc.js.map