proto.io 0.0.213 → 0.0.214
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.
- package/dist/adapters/file/aliyun-oss.d.ts +3 -3
- package/dist/adapters/file/database.d.ts +2 -2
- package/dist/adapters/file/database.js +2 -2
- package/dist/adapters/file/database.js.map +1 -1
- package/dist/adapters/file/database.mjs +1 -1
- package/dist/adapters/file/filesystem.d.ts +3 -3
- package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
- package/dist/adapters/storage/progres.d.ts +1 -1
- package/dist/adapters/storage/progres.js +111 -82
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +73 -44
- package/dist/adapters/storage/progres.mjs.map +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +42 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/internals/{base-CZGalGrd.d.ts → base-E1b8J-Fs.d.ts} +2 -2
- package/dist/internals/base-E1b8J-Fs.d.ts.map +1 -0
- package/dist/internals/{chunk-BsT9SYny.d.ts → chunk-D1bD7otk.d.ts} +3 -3
- package/dist/internals/chunk-D1bD7otk.d.ts.map +1 -0
- package/dist/internals/{index-Boxwkqe0.d.ts → index-CbjY-gJ7.d.ts} +6 -8
- package/dist/internals/index-CbjY-gJ7.d.ts.map +1 -0
- package/dist/internals/{index-NF-U_3zG.d.ts → index-SSEdPyhp.d.ts} +2 -2
- package/dist/internals/index-SSEdPyhp.d.ts.map +1 -0
- package/dist/internals/random-CYjWDvex.mjs +37 -0
- package/dist/internals/random-CYjWDvex.mjs.map +1 -0
- package/dist/internals/random-nkOQ9U6S.js +39 -0
- package/dist/internals/random-nkOQ9U6S.js.map +1 -0
- package/dist/internals/{index-D8O7SinR.js → validator-DoRPoIs2.js} +586 -2
- package/dist/internals/validator-DoRPoIs2.js.map +1 -0
- package/dist/internals/{index-DG9HHO_U.mjs → validator-Dxmbwa3P.mjs} +583 -3
- package/dist/internals/validator-Dxmbwa3P.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/internals/base-CZGalGrd.d.ts.map +0 -1
- package/dist/internals/chunk-BsT9SYny.d.ts.map +0 -1
- package/dist/internals/index-Boxwkqe0.d.ts.map +0 -1
- package/dist/internals/index-D8O7SinR.js.map +0 -1
- package/dist/internals/index-DG9HHO_U.mjs.map +0 -1
- package/dist/internals/index-NF-U_3zG.d.ts.map +0 -1
- package/dist/internals/random-CufRbivU.mjs +0 -526
- package/dist/internals/random-CufRbivU.mjs.map +0 -1
- package/dist/internals/random-DzvxbWAc.js +0 -532
- package/dist/internals/random-DzvxbWAc.js.map +0 -1
|
@@ -5,10 +5,10 @@ import QueryStream from 'pg-query-stream';
|
|
|
5
5
|
import { asyncStream, IteratorPool } from '@o2ter/utils-js';
|
|
6
6
|
import Decimal from 'decimal.js';
|
|
7
7
|
import { escapeLiteral, escapeIdentifier } from 'pg/lib/utils';
|
|
8
|
-
import { a as QueryCoditionalSelector,
|
|
8
|
+
import { r as resolveColumn, a as resolveDataType$1, c as QueryCoditionalSelector, d as QueryFieldSelector, e as QueryExpressionSelector, Q as QueryValidator, f as QueryDistanceExpression, g as QueryKeyExpression, h as QueryValueExpression, i as QueryCoditionalExpression, j as QueryComparisonExpression, k as QueryNotExpression, l as QueryArrayExpression, m as QueryNoParamAccumulator, n as QueryExprAccumulator, b as QuerySelector, F as FieldSelectorExpression } from '../../internals/validator-Dxmbwa3P.mjs';
|
|
9
9
|
import '@o2ter/crypto-js';
|
|
10
|
-
import { r as resolveColumn, a as resolveDataType$1, g as generateId, b as accumulatorKeyTypes, Q as QueryValidator } from '../../internals/random-CufRbivU.mjs';
|
|
11
10
|
import { c as PROTO_EVENT } from '../../internals/const-Dkp7Nsv5.mjs';
|
|
11
|
+
import { g as generateId } from '../../internals/random-CYjWDvex.mjs';
|
|
12
12
|
import { P as PVK } from '../../internals/private-CNw40LZ7.mjs';
|
|
13
13
|
|
|
14
14
|
//
|
|
@@ -668,14 +668,19 @@ class SqlStorage {
|
|
|
668
668
|
const count = parseInt(_count);
|
|
669
669
|
return _.isFinite(count) ? count : 0;
|
|
670
670
|
}
|
|
671
|
-
_matchesType(options) {
|
|
671
|
+
_matchesType(compiler, options) {
|
|
672
672
|
const types = {};
|
|
673
673
|
for (const [key, match] of _.entries(options.matches)) {
|
|
674
|
-
|
|
674
|
+
const type = resolveDataType$1(compiler.schema, options.className, key);
|
|
675
|
+
if (_.isNil(type))
|
|
676
|
+
continue;
|
|
677
|
+
if (isPointer(type) || isRelation(type)) {
|
|
678
|
+
types[key] = this._matchesType(compiler, { className: type.target, ...match });
|
|
679
|
+
}
|
|
675
680
|
}
|
|
676
681
|
for (const [key, group] of _.entries(options.groupMatches)) {
|
|
677
682
|
for (const [field, expr] of _.entries(group)) {
|
|
678
|
-
_.set(types, `${key}.${field}`,
|
|
683
|
+
_.set(types, `${key}.${field}`, expr.evalType(compiler.schema, options.className));
|
|
679
684
|
}
|
|
680
685
|
}
|
|
681
686
|
return types;
|
|
@@ -683,24 +688,26 @@ class SqlStorage {
|
|
|
683
688
|
find(query) {
|
|
684
689
|
const self = this;
|
|
685
690
|
const compiler = self._makeCompiler(false, query.extraFilter);
|
|
691
|
+
const _matchesType = self._matchesType(compiler, query);
|
|
686
692
|
const _query = compiler._selectQuery(query);
|
|
687
693
|
return (async function* () {
|
|
688
694
|
const objects = self.query(_query);
|
|
689
695
|
for await (const object of objects) {
|
|
690
|
-
yield self._decodeObject(query.className, object,
|
|
696
|
+
yield self._decodeObject(query.className, object, _matchesType);
|
|
691
697
|
}
|
|
692
698
|
})();
|
|
693
699
|
}
|
|
694
700
|
random(query, opts) {
|
|
695
701
|
const self = this;
|
|
696
702
|
const compiler = self._makeCompiler(false, query.extraFilter);
|
|
703
|
+
const _matchesType = self._matchesType(compiler, query);
|
|
697
704
|
const _query = compiler._selectQuery({ ...query, sort: {} }, {
|
|
698
705
|
sort: sql `ORDER BY ${self.dialect.random(opts ?? {})}`,
|
|
699
706
|
});
|
|
700
707
|
return (async function* () {
|
|
701
708
|
const objects = self.query(_query);
|
|
702
709
|
for await (const object of objects) {
|
|
703
|
-
yield self._decodeObject(query.className, object,
|
|
710
|
+
yield self._decodeObject(query.className, object, _matchesType);
|
|
704
711
|
}
|
|
705
712
|
})();
|
|
706
713
|
}
|
|
@@ -721,6 +728,7 @@ class SqlStorage {
|
|
|
721
728
|
nonrefs(query) {
|
|
722
729
|
const self = this;
|
|
723
730
|
const compiler = self._makeCompiler(false, query.extraFilter);
|
|
731
|
+
const _matchesType = self._matchesType(compiler, query);
|
|
724
732
|
const _query = compiler._selectQuery(query, ({ fetchName }) => ({
|
|
725
733
|
extraFilter: sql `
|
|
726
734
|
NOT EXISTS (${this._refs(this.schema, query.className, ['_id'], sql `(${{ quote: query.className + '$' }} || ${{ identifier: fetchName }}.${{ identifier: '_id' }})`)})
|
|
@@ -729,29 +737,33 @@ class SqlStorage {
|
|
|
729
737
|
return (async function* () {
|
|
730
738
|
const objects = self.query(_query);
|
|
731
739
|
for await (const object of objects) {
|
|
732
|
-
yield self._decodeObject(query.className, object,
|
|
740
|
+
yield self._decodeObject(query.className, object, _matchesType);
|
|
733
741
|
}
|
|
734
742
|
})();
|
|
735
743
|
}
|
|
736
744
|
async insert(options, values) {
|
|
737
745
|
const compiler = this._makeCompiler(true);
|
|
746
|
+
const _matchesType = this._matchesType(compiler, options);
|
|
738
747
|
const result = await this.query(compiler.insert(options, values));
|
|
739
|
-
return _.map(result, x => this._decodeObject(options.className, x,
|
|
748
|
+
return _.map(result, x => this._decodeObject(options.className, x, _matchesType));
|
|
740
749
|
}
|
|
741
750
|
async update(query, update) {
|
|
742
751
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
752
|
+
const _matchesType = this._matchesType(compiler, query);
|
|
743
753
|
const updated = await this.query(compiler.update(query, update));
|
|
744
|
-
return _.map(updated, x => this._decodeObject(query.className, x,
|
|
754
|
+
return _.map(updated, x => this._decodeObject(query.className, x, _matchesType));
|
|
745
755
|
}
|
|
746
756
|
async upsert(query, update, setOnInsert) {
|
|
747
757
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
758
|
+
const _matchesType = this._matchesType(compiler, query);
|
|
748
759
|
const upserted = await this.query(compiler.upsert(query, update, setOnInsert));
|
|
749
|
-
return _.map(upserted, x => this._decodeObject(query.className, x,
|
|
760
|
+
return _.map(upserted, x => this._decodeObject(query.className, x, _matchesType));
|
|
750
761
|
}
|
|
751
762
|
async delete(query) {
|
|
752
763
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
764
|
+
const _matchesType = this._matchesType(compiler, query);
|
|
753
765
|
const deleted = await this.query(compiler.delete(query));
|
|
754
|
-
return _.map(deleted, x => this._decodeObject(query.className, x,
|
|
766
|
+
return _.map(deleted, x => this._decodeObject(query.className, x, _matchesType));
|
|
755
767
|
}
|
|
756
768
|
}
|
|
757
769
|
|
|
@@ -779,7 +791,7 @@ class SqlStorage {
|
|
|
779
791
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
780
792
|
// THE SOFTWARE.
|
|
781
793
|
//
|
|
782
|
-
const _fetchElement = (parent, colname, subpath, dataType) => {
|
|
794
|
+
const _fetchElement = (compiler, parent, colname, subpath, dataType) => {
|
|
783
795
|
const element = sql `${{ identifier: parent.name }}.${{ identifier: parent.name.startsWith('_doller_expr_$') ? '$' : colname }}`;
|
|
784
796
|
if (!parent.className) {
|
|
785
797
|
if (colname !== '$') {
|
|
@@ -802,7 +814,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
|
|
|
802
814
|
return {
|
|
803
815
|
element: sql `${{ identifier: parent.name }}.${{ identifier: `${colname}.${subpath[0]}` }}`,
|
|
804
816
|
json: false,
|
|
805
|
-
dataType:
|
|
817
|
+
dataType: match.evalType(compiler.schema, dataType.target),
|
|
806
818
|
};
|
|
807
819
|
}
|
|
808
820
|
else if (dataType && _isTypeof(dataType, ['array', 'string[]', 'relation'])) {
|
|
@@ -865,7 +877,7 @@ const _resolvePopulate = (path, populates) => {
|
|
|
865
877
|
const fetchElement = (compiler, parent, field) => {
|
|
866
878
|
if (parent.className) {
|
|
867
879
|
const { dataType, colname, subpath } = resolvePaths(compiler, parent.className, _.toPath(field));
|
|
868
|
-
const { element, json, dataType: _dataType } = _fetchElement(parent, colname, subpath, dataType);
|
|
880
|
+
const { element, json, dataType: _dataType } = _fetchElement(compiler, parent, colname, subpath, dataType);
|
|
869
881
|
if (isPointer(dataType))
|
|
870
882
|
return { element: sql `${{ identifier: parent.name }}.${{ identifier: `${colname}._id` }}`, dataType };
|
|
871
883
|
const populate = isRelation(dataType) && _resolvePopulate(_.toPath(colname), parent.populates);
|
|
@@ -897,7 +909,7 @@ const fetchElement = (compiler, parent, field) => {
|
|
|
897
909
|
}
|
|
898
910
|
}
|
|
899
911
|
const [colname, ...subpath] = _.toPath(field);
|
|
900
|
-
const { element } = _fetchElement(parent, colname, subpath);
|
|
912
|
+
const { element } = _fetchElement(compiler, parent, colname, subpath);
|
|
901
913
|
return { element, dataType: null, relation: null };
|
|
902
914
|
};
|
|
903
915
|
|
|
@@ -1685,7 +1697,19 @@ const encodeTypedQueryExpression = (compiler, parent, expr) => {
|
|
|
1685
1697
|
if (expr instanceof QueryKeyExpression) {
|
|
1686
1698
|
const { element, dataType } = fetchElement(compiler, parent, expr.key);
|
|
1687
1699
|
const _dataType = dataType ? _typeof(dataType) : null;
|
|
1688
|
-
if (_dataType
|
|
1700
|
+
if (_dataType === 'number') {
|
|
1701
|
+
return [
|
|
1702
|
+
{ type: 'number', sql: element },
|
|
1703
|
+
{ type: 'decimal', sql: sql `CAST((${element}) AS DECIMAL)` },
|
|
1704
|
+
];
|
|
1705
|
+
}
|
|
1706
|
+
else if (_dataType === 'decimal') {
|
|
1707
|
+
return [
|
|
1708
|
+
{ type: 'decimal', sql: element },
|
|
1709
|
+
{ type: 'number', sql: element },
|
|
1710
|
+
];
|
|
1711
|
+
}
|
|
1712
|
+
else if (_dataType && _PrimitiveValue.includes(_dataType)) {
|
|
1689
1713
|
return [{ type: _dataType, sql: element }];
|
|
1690
1714
|
}
|
|
1691
1715
|
}
|
|
@@ -1950,39 +1974,44 @@ const selectPopulate = (compiler, parent, populate, field) => {
|
|
|
1950
1974
|
sql `${{ identifier: parent.name }}.${{ identifier: field }} AS ${{ identifier: `$${field}` }}`,
|
|
1951
1975
|
];
|
|
1952
1976
|
if (!_.isEmpty(groupMatches?.[field])) {
|
|
1953
|
-
for (const [key,
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
(
|
|
1958
|
-
SELECT COUNT(*) FROM (
|
|
1959
|
-
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
1960
|
-
) ${{ identifier: populate.name }}
|
|
1961
|
-
) AS ${{ identifier: `${field}.${key}` }}
|
|
1962
|
-
`);
|
|
1963
|
-
break;
|
|
1964
|
-
case '$avg':
|
|
1965
|
-
case '$sum':
|
|
1966
|
-
{
|
|
1967
|
-
const op = {
|
|
1968
|
-
'$avg': 'AVG',
|
|
1969
|
-
'$sum': 'SUM',
|
|
1970
|
-
}[type];
|
|
1971
|
-
if (!expr)
|
|
1972
|
-
throw Error('Invalid expression');
|
|
1973
|
-
const exprs = encodeTypedQueryExpression(compiler, populate, expr);
|
|
1974
|
-
const { sql: value } = (_.includes(['$avg'], type) ? _.find(exprs, e => e.type === 'number') : _.first(exprs)) ?? {};
|
|
1975
|
-
if (!value)
|
|
1976
|
-
throw Error('Invalid expression');
|
|
1977
|
+
for (const [key, expr] of _.entries(groupMatches[field])) {
|
|
1978
|
+
if (expr instanceof QueryNoParamAccumulator) {
|
|
1979
|
+
switch (expr.type) {
|
|
1980
|
+
case '$count':
|
|
1977
1981
|
columns.push(sql `
|
|
1978
1982
|
(
|
|
1979
|
-
SELECT
|
|
1983
|
+
SELECT COUNT(*) FROM (
|
|
1980
1984
|
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
1981
1985
|
) ${{ identifier: populate.name }}
|
|
1982
1986
|
) AS ${{ identifier: `${field}.${key}` }}
|
|
1983
1987
|
`);
|
|
1984
|
-
|
|
1985
|
-
|
|
1988
|
+
break;
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
else if (expr instanceof QueryExprAccumulator) {
|
|
1992
|
+
const op = {
|
|
1993
|
+
'$max': 'MAX',
|
|
1994
|
+
'$min': 'MIN',
|
|
1995
|
+
'$avg': 'AVG',
|
|
1996
|
+
'$sum': 'SUM',
|
|
1997
|
+
'$stdDevPop': 'STDDEV_POP',
|
|
1998
|
+
'$stdDevSamp': 'STDDEV_SAMP',
|
|
1999
|
+
'$varPop': 'VAR_POP',
|
|
2000
|
+
'$varSamp': 'VAR_SAMP',
|
|
2001
|
+
}[expr.type];
|
|
2002
|
+
if (!expr.expr)
|
|
2003
|
+
throw Error('Invalid expression');
|
|
2004
|
+
const exprs = encodeTypedQueryExpression(compiler, populate, expr.expr);
|
|
2005
|
+
const value = _.first(exprs)?.sql;
|
|
2006
|
+
if (!value)
|
|
2007
|
+
throw Error('Invalid expression');
|
|
2008
|
+
columns.push(sql `
|
|
2009
|
+
(
|
|
2010
|
+
SELECT ${{ literal: op }}(${value}) FROM (
|
|
2011
|
+
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
2012
|
+
) ${{ identifier: populate.name }}
|
|
2013
|
+
) AS ${{ identifier: `${field}.${key}` }}
|
|
2014
|
+
`);
|
|
1986
2015
|
}
|
|
1987
2016
|
}
|
|
1988
2017
|
}
|