proto.io 0.0.213 → 0.0.215
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 +133 -82
- package/dist/adapters/storage/progres.js.map +1 -1
- package/dist/adapters/storage/progres.mjs +95 -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-Cp5le5dC.d.ts} +2 -2
- package/dist/internals/base-Cp5le5dC.d.ts.map +1 -0
- package/dist/internals/{chunk-BsT9SYny.d.ts → chunk--Vo2-p-z.d.ts} +3 -3
- package/dist/internals/chunk--Vo2-p-z.d.ts.map +1 -0
- package/dist/internals/{index-NF-U_3zG.d.ts → index-CZUGnb-y.d.ts} +2 -2
- package/dist/internals/index-CZUGnb-y.d.ts.map +1 -0
- package/dist/internals/{index-Boxwkqe0.d.ts → index-YLrO0f2D.d.ts} +12 -8
- package/dist/internals/index-YLrO0f2D.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-DG9HHO_U.mjs → validator-ChrCrz_C.mjs} +618 -3
- package/dist/internals/validator-ChrCrz_C.mjs.map +1 -0
- package/dist/internals/{index-D8O7SinR.js → validator-m6wY35c6.js} +622 -2
- package/dist/internals/validator-m6wY35c6.js.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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P as ProtoService } from '../../internals/index-
|
|
1
|
+
import { P as ProtoService } from '../../internals/index-YLrO0f2D.js';
|
|
2
2
|
import OSS from 'ali-oss';
|
|
3
|
-
import { a as FileStorageOptions } from '../../internals/base-
|
|
4
|
-
import { F as FileChunkStorageBase } from '../../internals/chunk-
|
|
3
|
+
import { a as FileStorageOptions } from '../../internals/base-Cp5le5dC.js';
|
|
4
|
+
import { F as FileChunkStorageBase } from '../../internals/chunk--Vo2-p-z.js';
|
|
5
5
|
import '@o2ter/utils-js';
|
|
6
6
|
import 'jsonwebtoken';
|
|
7
7
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TSchema, P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-
|
|
1
|
+
import { T as TSchema, P as ProtoService } from '../../internals/index-YLrO0f2D.js';
|
|
2
|
+
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/base-Cp5le5dC.js';
|
|
3
3
|
import '@o2ter/utils-js';
|
|
4
4
|
import 'jsonwebtoken';
|
|
5
5
|
import '@o2ter/server-js';
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _ = require('lodash');
|
|
6
6
|
var base = require('../../internals/base-NsJYo2MG.js');
|
|
7
7
|
var utilsJs = require('@o2ter/utils-js');
|
|
8
|
-
var
|
|
8
|
+
var validator = require('../../internals/validator-m6wY35c6.js');
|
|
9
9
|
require('util');
|
|
10
10
|
require('zlib');
|
|
11
11
|
require('../../internals/private-Ciddhure.js');
|
|
@@ -101,7 +101,7 @@ class DatabaseFileStorage extends base.FileStorageBase {
|
|
|
101
101
|
async destroy(proto, token) {
|
|
102
102
|
proto.storage.delete({
|
|
103
103
|
className: '_FileChunk',
|
|
104
|
-
filter:
|
|
104
|
+
filter: validator.QuerySelector.decode({ token: { $eq: token } }),
|
|
105
105
|
includes: ['_id'],
|
|
106
106
|
matches: {},
|
|
107
107
|
groupMatches: {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sources":["../../../../src/adapters/file/database/index.ts"],"sourcesContent":["//\n// index.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 { ProtoService } from '../../../server/proto';\nimport { TSchema } from '../../../internals/schema';\nimport FileStorageBase, { FileStorageOptions } from '../base';\nimport { QuerySelector } from '../../../server/query/dispatcher/parser';\nimport { base64ToBuffer, bufferToBase64 } from '@o2ter/utils-js';\n\nexport class DatabaseFileStorage extends FileStorageBase {\n\n constructor(options: FileStorageOptions = {}) {\n super(options);\n }\n\n get schema(): Record<string, TSchema> {\n return {\n '_FileChunk': {\n fields: {\n token: 'string',\n start: 'number',\n end: 'number',\n size: 'number',\n base64: 'string',\n },\n classLevelPermissions: {\n get: [],\n find: [],\n count: [],\n create: [],\n update: [],\n delete: [],\n },\n fieldLevelPermissions: {\n _expired_at: { create: [], update: [] },\n },\n indexes: [\n { keys: { token: 1, start: 1, end: 1 } },\n { keys: { token: 1, end: 1 } },\n ]\n },\n }\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n\n const created = await proto.Query('_FileChunk').insert({\n token,\n start: start,\n end: end,\n size: end - start,\n base64: bufferToBase64(compressed),\n }, { master: true });\n\n if (!created) throw Error('Unable to save file');\n\n }\n\n async* readChunks<E>(proto: ProtoService<E>, token: string, start?: number, end?: number) {\n const query = proto.Query('_FileChunk')\n .sort({ start: 1 })\n .filter({\n token: { $eq: token },\n ...start ? { end: { $gt: start } } : {},\n ...end ? { start: { $lt: end } } : {},\n });\n for await (const chunk of query.find({ master: true })) {\n const startBytes = chunk.get('start');\n const base64 = chunk.get('base64');\n if (!_.isNumber(startBytes) || !_.isString(base64)) throw Error('Corrupted data');\n yield {\n start: startBytes,\n data: base64ToBuffer(base64),\n };\n }\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n proto.storage.delete({\n className: '_FileChunk',\n filter: QuerySelector.decode({ token: { $eq: token } }),\n includes: ['_id'],\n matches: {},\n groupMatches: {},\n objectIdSize: 0\n });\n }\n};\n\nexport default DatabaseFileStorage;"],"names":["FileStorageBase","bufferToBase64","base64ToBuffer","QuerySelector"],"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;AASM,MAAO,mBAAoB,SAAQA,oBAAe,CAAA;AAEtD,IAAA,WAAA,CAAY,UAA8B,EAAE,EAAA;QAC1C,KAAK,CAAC,OAAO,CAAC;;AAGhB,IAAA,IAAI,MAAM,GAAA;QACR,OAAO;AACL,YAAA,YAAY,EAAE;AACZ,gBAAA,MAAM,EAAE;AACN,oBAAA,KAAK,EAAE,QAAQ;AACf,oBAAA,KAAK,EAAE,QAAQ;AACf,oBAAA,GAAG,EAAE,QAAQ;AACb,oBAAA,IAAI,EAAE,QAAQ;AACd,oBAAA,MAAM,EAAE,QAAQ;AACjB,iBAAA;AACD,gBAAA,qBAAqB,EAAE;AACrB,oBAAA,GAAG,EAAE,EAAE;AACP,oBAAA,IAAI,EAAE,EAAE;AACR,oBAAA,KAAK,EAAE,EAAE;AACT,oBAAA,MAAM,EAAE,EAAE;AACV,oBAAA,MAAM,EAAE,EAAE;AACV,oBAAA,MAAM,EAAE,EAAE;AACX,iBAAA;AACD,gBAAA,qBAAqB,EAAE;oBACrB,WAAW,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;AACxC,iBAAA;AACD,gBAAA,OAAO,EAAE;AACP,oBAAA,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;oBACxC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE;AAC/B;AACF,aAAA;SACF;;IAGH,MAAM,WAAW,CAAI,KAAsB,EAAE,KAAa,EAAE,KAAa,EAAE,GA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AAC,gBAAgB,CAAC;YACjF,MAAM;AACJ,gBAAA,KAAK,EAAE,UAAU;AACjB,gBAAA,IAAI,EAAEC,sBAAc,CAAC,MAAM,CAAC;aAC7B;;;AAIL,IAAA,MAAM,OAAO,CAAI,KAAsB,EAAE,KAAa,EAAA;AACpD,QAAA,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AACnB,YAAA,SAAS,EAAE,YAAY;AACvB,YAAA,MAAM,EAAEC,
|
|
1
|
+
{"version":3,"file":"database.js","sources":["../../../../src/adapters/file/database/index.ts"],"sourcesContent":["//\n// index.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 { ProtoService } from '../../../server/proto';\nimport { TSchema } from '../../../internals/schema';\nimport FileStorageBase, { FileStorageOptions } from '../base';\nimport { QuerySelector } from '../../../server/query/dispatcher/parser';\nimport { base64ToBuffer, bufferToBase64 } from '@o2ter/utils-js';\n\nexport class DatabaseFileStorage extends FileStorageBase {\n\n constructor(options: FileStorageOptions = {}) {\n super(options);\n }\n\n get schema(): Record<string, TSchema> {\n return {\n '_FileChunk': {\n fields: {\n token: 'string',\n start: 'number',\n end: 'number',\n size: 'number',\n base64: 'string',\n },\n classLevelPermissions: {\n get: [],\n find: [],\n count: [],\n create: [],\n update: [],\n delete: [],\n },\n fieldLevelPermissions: {\n _expired_at: { create: [], update: [] },\n },\n indexes: [\n { keys: { token: 1, start: 1, end: 1 } },\n { keys: { token: 1, end: 1 } },\n ]\n },\n }\n }\n\n async createChunk<E>(proto: ProtoService<E>, token: string, start: number, end: number, compressed: Buffer) {\n\n const created = await proto.Query('_FileChunk').insert({\n token,\n start: start,\n end: end,\n size: end - start,\n base64: bufferToBase64(compressed),\n }, { master: true });\n\n if (!created) throw Error('Unable to save file');\n\n }\n\n async* readChunks<E>(proto: ProtoService<E>, token: string, start?: number, end?: number) {\n const query = proto.Query('_FileChunk')\n .sort({ start: 1 })\n .filter({\n token: { $eq: token },\n ...start ? { end: { $gt: start } } : {},\n ...end ? { start: { $lt: end } } : {},\n });\n for await (const chunk of query.find({ master: true })) {\n const startBytes = chunk.get('start');\n const base64 = chunk.get('base64');\n if (!_.isNumber(startBytes) || !_.isString(base64)) throw Error('Corrupted data');\n yield {\n start: startBytes,\n data: base64ToBuffer(base64),\n };\n }\n }\n\n async destroy<E>(proto: ProtoService<E>, token: string) {\n proto.storage.delete({\n className: '_FileChunk',\n filter: QuerySelector.decode({ token: { $eq: token } }),\n includes: ['_id'],\n matches: {},\n groupMatches: {},\n objectIdSize: 0\n });\n }\n};\n\nexport default DatabaseFileStorage;"],"names":["FileStorageBase","bufferToBase64","base64ToBuffer","QuerySelector"],"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;AASM,MAAO,mBAAoB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ACnB,YAAA,SAAS,EAAE,YAAY;AACvB,YAAA,MAAM,EAAEC,uBAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;YACvD,QAAQ,EAAE,CAAC,KAAK,CAAC;AACjB,YAAA,OAAO,EAAE,EAAE;AACX,YAAA,YAAY,EAAE,EAAE;AAChB,YAAA,YAAY,EAAE;AACf,SAAA,CAAC;;AAEL;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { F as FileStorageBase } from '../../internals/base-DYc1_peK.mjs';
|
|
3
3
|
import { bufferToBase64, base64ToBuffer } from '@o2ter/utils-js';
|
|
4
|
-
import {
|
|
4
|
+
import { b as QuerySelector } from '../../internals/validator-ChrCrz_C.mjs';
|
|
5
5
|
import 'util';
|
|
6
6
|
import 'zlib';
|
|
7
7
|
import '../../internals/private-CNw40LZ7.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { a as FileStorageOptions } from '../../internals/base-
|
|
3
|
-
import { F as FileChunkStorageBase } from '../../internals/chunk-
|
|
1
|
+
import { P as ProtoService } from '../../internals/index-YLrO0f2D.js';
|
|
2
|
+
import { a as FileStorageOptions } from '../../internals/base-Cp5le5dC.js';
|
|
3
|
+
import { F as FileChunkStorageBase } from '../../internals/chunk--Vo2-p-z.js';
|
|
4
4
|
import '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
6
6
|
import '@o2ter/server-js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _google_cloud_storage from '@google-cloud/storage';
|
|
2
2
|
import { File, Storage } from '@google-cloud/storage';
|
|
3
|
-
import { P as ProtoService } from '../../internals/index-
|
|
4
|
-
import { a as FileStorageOptions } from '../../internals/base-
|
|
5
|
-
import { F as FileChunkStorageBase } from '../../internals/chunk-
|
|
3
|
+
import { P as ProtoService } from '../../internals/index-YLrO0f2D.js';
|
|
4
|
+
import { a as FileStorageOptions } from '../../internals/base-Cp5le5dC.js';
|
|
5
|
+
import { F as FileChunkStorageBase } from '../../internals/chunk--Vo2-p-z.js';
|
|
6
6
|
import '@o2ter/utils-js';
|
|
7
7
|
import 'jsonwebtoken';
|
|
8
8
|
import '@o2ter/server-js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
-
import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QueryAccumulator, y as QuerySelector, z as DecodedSortOption, A as DecodedQuery, B as FindOptions, I as InsertOptions, C as TStorage, G as TransactionOptions, j as TObject, H as TQueryRandomOptions, J as TPubSub } from '../../internals/index-
|
|
2
|
+
import { a as TValueWithoutObject, T as TSchema, u as TValueWithUndefined, v as TValue, w as TUpdateOp, F as FieldSelectorExpression, Q as QueryExpression, R as RelationOptions, x as QueryAccumulator, y as QuerySelector, z as DecodedSortOption, A as DecodedQuery, B as FindOptions, I as InsertOptions, C as TStorage, G as TransactionOptions, j as TObject, H as TQueryRandomOptions, J as TPubSub } from '../../internals/index-YLrO0f2D.js';
|
|
3
3
|
import * as _o2ter_utils_js from '@o2ter/utils-js';
|
|
4
4
|
import { asyncStream } from '@o2ter/utils-js';
|
|
5
5
|
import 'jsonwebtoken';
|
|
@@ -9,10 +9,10 @@ var QueryStream = require('pg-query-stream');
|
|
|
9
9
|
var utilsJs = require('@o2ter/utils-js');
|
|
10
10
|
var Decimal = require('decimal.js');
|
|
11
11
|
var utils = require('pg/lib/utils');
|
|
12
|
-
var
|
|
12
|
+
var validator = require('../../internals/validator-m6wY35c6.js');
|
|
13
13
|
require('@o2ter/crypto-js');
|
|
14
|
-
var random$1 = require('../../internals/random-DzvxbWAc.js');
|
|
15
14
|
var _const = require('../../internals/const-C3I6cfav.js');
|
|
15
|
+
var random$1 = require('../../internals/random-nkOQ9U6S.js');
|
|
16
16
|
var _private = require('../../internals/private-Ciddhure.js');
|
|
17
17
|
|
|
18
18
|
//
|
|
@@ -220,7 +220,7 @@ class QueryCompiler {
|
|
|
220
220
|
const populates = {};
|
|
221
221
|
const groupMatches = {};
|
|
222
222
|
for (const include of query.includes) {
|
|
223
|
-
const { paths: [colname, ...subpath], dataType } =
|
|
223
|
+
const { paths: [colname, ...subpath], dataType } = validator.resolveColumn(this.schema, query.className, include);
|
|
224
224
|
names[colname] = dataType;
|
|
225
225
|
if (index.isRelation(dataType) && !_.isNil(query.groupMatches[colname]))
|
|
226
226
|
groupMatches[colname] = query.groupMatches[colname];
|
|
@@ -239,7 +239,7 @@ class QueryCompiler {
|
|
|
239
239
|
colname,
|
|
240
240
|
};
|
|
241
241
|
if (index.isRelation(dataType) && dataType.foreignField) {
|
|
242
|
-
const targetType =
|
|
242
|
+
const targetType = validator.resolveDataType(this.schema, dataType.target, dataType.foreignField);
|
|
243
243
|
if (_.isNil(targetType))
|
|
244
244
|
throw Error(`Invalid path: ${include}`);
|
|
245
245
|
if (!index.isPointer(targetType) && !index.isRelation(targetType))
|
|
@@ -359,7 +359,7 @@ class QueryCompiler {
|
|
|
359
359
|
sql `_updated_at = NOW()`,
|
|
360
360
|
];
|
|
361
361
|
for (const [path, op] of _.toPairs(attrs)) {
|
|
362
|
-
const { paths: [column, ...subpath], dataType } =
|
|
362
|
+
const { paths: [column, ...subpath], dataType } = validator.resolveColumn(this.schema, className, path);
|
|
363
363
|
if (index.isShape(dataType)) {
|
|
364
364
|
const [_op, value] = index.decodeUpdateOp(op);
|
|
365
365
|
if (_op !== '$set')
|
|
@@ -379,7 +379,7 @@ class QueryCompiler {
|
|
|
379
379
|
_encodeObjectAttrs(className, attrs) {
|
|
380
380
|
const result = {};
|
|
381
381
|
for (const [key, value] of _.toPairs(attrs)) {
|
|
382
|
-
const { paths: [column, ...subpath], dataType } =
|
|
382
|
+
const { paths: [column, ...subpath], dataType } = validator.resolveColumn(this.schema, className, key);
|
|
383
383
|
if (!_.isEmpty(subpath))
|
|
384
384
|
throw Error(`Invalid insert key: ${key}`);
|
|
385
385
|
if (index.isShape(dataType)) {
|
|
@@ -406,13 +406,13 @@ class QueryCompiler {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
_encodeFilter(parent, filter) {
|
|
409
|
-
if (filter instanceof
|
|
409
|
+
if (filter instanceof validator.QueryCoditionalSelector) {
|
|
410
410
|
return this._encodeCoditionalSelector(parent, filter);
|
|
411
411
|
}
|
|
412
|
-
if (filter instanceof
|
|
412
|
+
if (filter instanceof validator.QueryFieldSelector) {
|
|
413
413
|
return this.dialect.encodeFieldExpression(this, parent, filter.field, filter.expr);
|
|
414
414
|
}
|
|
415
|
-
if (filter instanceof
|
|
415
|
+
if (filter instanceof validator.QueryExpressionSelector) {
|
|
416
416
|
return this.dialect.encodeQueryExpression(this, parent, filter.expr);
|
|
417
417
|
}
|
|
418
418
|
}
|
|
@@ -672,14 +672,19 @@ class SqlStorage {
|
|
|
672
672
|
const count = parseInt(_count);
|
|
673
673
|
return _.isFinite(count) ? count : 0;
|
|
674
674
|
}
|
|
675
|
-
_matchesType(options) {
|
|
675
|
+
_matchesType(compiler, options) {
|
|
676
676
|
const types = {};
|
|
677
677
|
for (const [key, match] of _.entries(options.matches)) {
|
|
678
|
-
|
|
678
|
+
const type = validator.resolveDataType(compiler.schema, options.className, key);
|
|
679
|
+
if (_.isNil(type))
|
|
680
|
+
continue;
|
|
681
|
+
if (index.isPointer(type) || index.isRelation(type)) {
|
|
682
|
+
types[key] = this._matchesType(compiler, { className: type.target, ...match });
|
|
683
|
+
}
|
|
679
684
|
}
|
|
680
685
|
for (const [key, group] of _.entries(options.groupMatches)) {
|
|
681
686
|
for (const [field, expr] of _.entries(group)) {
|
|
682
|
-
_.set(types, `${key}.${field}`,
|
|
687
|
+
_.set(types, `${key}.${field}`, expr.evalType(compiler.schema, options.className));
|
|
683
688
|
}
|
|
684
689
|
}
|
|
685
690
|
return types;
|
|
@@ -687,24 +692,26 @@ class SqlStorage {
|
|
|
687
692
|
find(query) {
|
|
688
693
|
const self = this;
|
|
689
694
|
const compiler = self._makeCompiler(false, query.extraFilter);
|
|
695
|
+
const _matchesType = self._matchesType(compiler, query);
|
|
690
696
|
const _query = compiler._selectQuery(query);
|
|
691
697
|
return (async function* () {
|
|
692
698
|
const objects = self.query(_query);
|
|
693
699
|
for await (const object of objects) {
|
|
694
|
-
yield self._decodeObject(query.className, object,
|
|
700
|
+
yield self._decodeObject(query.className, object, _matchesType);
|
|
695
701
|
}
|
|
696
702
|
})();
|
|
697
703
|
}
|
|
698
704
|
random(query, opts) {
|
|
699
705
|
const self = this;
|
|
700
706
|
const compiler = self._makeCompiler(false, query.extraFilter);
|
|
707
|
+
const _matchesType = self._matchesType(compiler, query);
|
|
701
708
|
const _query = compiler._selectQuery({ ...query, sort: {} }, {
|
|
702
709
|
sort: sql `ORDER BY ${self.dialect.random(opts ?? {})}`,
|
|
703
710
|
});
|
|
704
711
|
return (async function* () {
|
|
705
712
|
const objects = self.query(_query);
|
|
706
713
|
for await (const object of objects) {
|
|
707
|
-
yield self._decodeObject(query.className, object,
|
|
714
|
+
yield self._decodeObject(query.className, object, _matchesType);
|
|
708
715
|
}
|
|
709
716
|
})();
|
|
710
717
|
}
|
|
@@ -725,6 +732,7 @@ class SqlStorage {
|
|
|
725
732
|
nonrefs(query) {
|
|
726
733
|
const self = this;
|
|
727
734
|
const compiler = self._makeCompiler(false, query.extraFilter);
|
|
735
|
+
const _matchesType = self._matchesType(compiler, query);
|
|
728
736
|
const _query = compiler._selectQuery(query, ({ fetchName }) => ({
|
|
729
737
|
extraFilter: sql `
|
|
730
738
|
NOT EXISTS (${this._refs(this.schema, query.className, ['_id'], sql `(${{ quote: query.className + '$' }} || ${{ identifier: fetchName }}.${{ identifier: '_id' }})`)})
|
|
@@ -733,29 +741,33 @@ class SqlStorage {
|
|
|
733
741
|
return (async function* () {
|
|
734
742
|
const objects = self.query(_query);
|
|
735
743
|
for await (const object of objects) {
|
|
736
|
-
yield self._decodeObject(query.className, object,
|
|
744
|
+
yield self._decodeObject(query.className, object, _matchesType);
|
|
737
745
|
}
|
|
738
746
|
})();
|
|
739
747
|
}
|
|
740
748
|
async insert(options, values) {
|
|
741
749
|
const compiler = this._makeCompiler(true);
|
|
750
|
+
const _matchesType = this._matchesType(compiler, options);
|
|
742
751
|
const result = await this.query(compiler.insert(options, values));
|
|
743
|
-
return _.map(result, x => this._decodeObject(options.className, x,
|
|
752
|
+
return _.map(result, x => this._decodeObject(options.className, x, _matchesType));
|
|
744
753
|
}
|
|
745
754
|
async update(query, update) {
|
|
746
755
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
756
|
+
const _matchesType = this._matchesType(compiler, query);
|
|
747
757
|
const updated = await this.query(compiler.update(query, update));
|
|
748
|
-
return _.map(updated, x => this._decodeObject(query.className, x,
|
|
758
|
+
return _.map(updated, x => this._decodeObject(query.className, x, _matchesType));
|
|
749
759
|
}
|
|
750
760
|
async upsert(query, update, setOnInsert) {
|
|
751
761
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
762
|
+
const _matchesType = this._matchesType(compiler, query);
|
|
752
763
|
const upserted = await this.query(compiler.upsert(query, update, setOnInsert));
|
|
753
|
-
return _.map(upserted, x => this._decodeObject(query.className, x,
|
|
764
|
+
return _.map(upserted, x => this._decodeObject(query.className, x, _matchesType));
|
|
754
765
|
}
|
|
755
766
|
async delete(query) {
|
|
756
767
|
const compiler = this._makeCompiler(true, query.extraFilter);
|
|
768
|
+
const _matchesType = this._matchesType(compiler, query);
|
|
757
769
|
const deleted = await this.query(compiler.delete(query));
|
|
758
|
-
return _.map(deleted, x => this._decodeObject(query.className, x,
|
|
770
|
+
return _.map(deleted, x => this._decodeObject(query.className, x, _matchesType));
|
|
759
771
|
}
|
|
760
772
|
}
|
|
761
773
|
|
|
@@ -783,7 +795,7 @@ class SqlStorage {
|
|
|
783
795
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
784
796
|
// THE SOFTWARE.
|
|
785
797
|
//
|
|
786
|
-
const _fetchElement = (parent, colname, subpath, dataType) => {
|
|
798
|
+
const _fetchElement = (compiler, parent, colname, subpath, dataType) => {
|
|
787
799
|
const element = sql `${{ identifier: parent.name }}.${{ identifier: parent.name.startsWith('_doller_expr_$') ? '$' : colname }}`;
|
|
788
800
|
if (!parent.className) {
|
|
789
801
|
if (colname !== '$') {
|
|
@@ -806,7 +818,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
|
|
|
806
818
|
return {
|
|
807
819
|
element: sql `${{ identifier: parent.name }}.${{ identifier: `${colname}.${subpath[0]}` }}`,
|
|
808
820
|
json: false,
|
|
809
|
-
dataType:
|
|
821
|
+
dataType: match.evalType(compiler.schema, dataType.target),
|
|
810
822
|
};
|
|
811
823
|
}
|
|
812
824
|
else if (dataType && index._isTypeof(dataType, ['array', 'string[]', 'relation'])) {
|
|
@@ -831,7 +843,7 @@ const _fetchElement = (parent, colname, subpath, dataType) => {
|
|
|
831
843
|
return { element, json: false };
|
|
832
844
|
};
|
|
833
845
|
const resolvePaths = (compiler, className, paths) => {
|
|
834
|
-
const { paths: [colname, ...subpath], dataType } =
|
|
846
|
+
const { paths: [colname, ...subpath], dataType } = validator.resolveColumn(compiler.schema, className, paths.join('.'));
|
|
835
847
|
if (!_.isEmpty(subpath) && index.isVector(dataType)) {
|
|
836
848
|
if (subpath.length !== 1)
|
|
837
849
|
throw Error(`Invalid key: ${paths.join('.')}`);
|
|
@@ -848,7 +860,7 @@ const resolvePaths = (compiler, className, paths) => {
|
|
|
848
860
|
return { ...resolved, colname: `${colname}.${resolved.colname}` };
|
|
849
861
|
}
|
|
850
862
|
const digit = _.first(subpath);
|
|
851
|
-
if (!_.isEmpty(subpath) && index.isRelation(dataType) && digit?.match(
|
|
863
|
+
if (!_.isEmpty(subpath) && index.isRelation(dataType) && digit?.match(validator.QueryValidator.patterns.digits)) {
|
|
852
864
|
const resolved = resolvePaths(compiler, dataType.target, _.slice(subpath, 1));
|
|
853
865
|
return { dataType, colname, subpath: [digit, resolved.colname, ...resolved.subpath] };
|
|
854
866
|
}
|
|
@@ -869,7 +881,7 @@ const _resolvePopulate = (path, populates) => {
|
|
|
869
881
|
const fetchElement = (compiler, parent, field) => {
|
|
870
882
|
if (parent.className) {
|
|
871
883
|
const { dataType, colname, subpath } = resolvePaths(compiler, parent.className, _.toPath(field));
|
|
872
|
-
const { element, json, dataType: _dataType } = _fetchElement(parent, colname, subpath, dataType);
|
|
884
|
+
const { element, json, dataType: _dataType } = _fetchElement(compiler, parent, colname, subpath, dataType);
|
|
873
885
|
if (index.isPointer(dataType))
|
|
874
886
|
return { element: sql `${{ identifier: parent.name }}.${{ identifier: `${colname}._id` }}`, dataType };
|
|
875
887
|
const populate = index.isRelation(dataType) && _resolvePopulate(_.toPath(colname), parent.populates);
|
|
@@ -901,7 +913,7 @@ const fetchElement = (compiler, parent, field) => {
|
|
|
901
913
|
}
|
|
902
914
|
}
|
|
903
915
|
const [colname, ...subpath] = _.toPath(field);
|
|
904
|
-
const { element } = _fetchElement(parent, colname, subpath);
|
|
916
|
+
const { element } = _fetchElement(compiler, parent, colname, subpath);
|
|
905
917
|
return { element, dataType: null, relation: null };
|
|
906
918
|
};
|
|
907
919
|
|
|
@@ -1664,36 +1676,48 @@ const updateOperation = (paths, dataType, operation) => {
|
|
|
1664
1676
|
// THE SOFTWARE.
|
|
1665
1677
|
//
|
|
1666
1678
|
const isArrayExpression = (expr) => {
|
|
1667
|
-
if (expr instanceof
|
|
1679
|
+
if (expr instanceof validator.QueryArrayExpression)
|
|
1668
1680
|
return true;
|
|
1669
|
-
if (expr instanceof
|
|
1681
|
+
if (expr instanceof validator.QueryValueExpression)
|
|
1670
1682
|
return _.isArray(expr.value);
|
|
1671
1683
|
return false;
|
|
1672
1684
|
};
|
|
1673
1685
|
const arrayLength = (expr) => {
|
|
1674
|
-
if (expr instanceof
|
|
1686
|
+
if (expr instanceof validator.QueryArrayExpression)
|
|
1675
1687
|
return expr.exprs.length;
|
|
1676
|
-
if (expr instanceof
|
|
1688
|
+
if (expr instanceof validator.QueryValueExpression)
|
|
1677
1689
|
return _.isArray(expr.value) ? expr.value.length : 0;
|
|
1678
1690
|
return 0;
|
|
1679
1691
|
};
|
|
1680
1692
|
const mapExpression = (expr, callback) => {
|
|
1681
|
-
if (expr instanceof
|
|
1693
|
+
if (expr instanceof validator.QueryArrayExpression)
|
|
1682
1694
|
return _.map(expr.exprs, x => callback(x));
|
|
1683
|
-
if (expr instanceof
|
|
1684
|
-
return _.isArray(expr.value) ? _.map(expr.value, x => callback(new
|
|
1695
|
+
if (expr instanceof validator.QueryValueExpression)
|
|
1696
|
+
return _.isArray(expr.value) ? _.map(expr.value, x => callback(new validator.QueryValueExpression(x))) : [];
|
|
1685
1697
|
return [];
|
|
1686
1698
|
};
|
|
1687
1699
|
const _PrimitiveValue = ['boolean', 'number', 'decimal', 'string', 'date'];
|
|
1688
1700
|
const encodeTypedQueryExpression = (compiler, parent, expr) => {
|
|
1689
|
-
if (expr instanceof
|
|
1701
|
+
if (expr instanceof validator.QueryKeyExpression) {
|
|
1690
1702
|
const { element, dataType } = fetchElement(compiler, parent, expr.key);
|
|
1691
1703
|
const _dataType = dataType ? index._typeof(dataType) : null;
|
|
1692
|
-
if (_dataType
|
|
1704
|
+
if (_dataType === 'number') {
|
|
1705
|
+
return [
|
|
1706
|
+
{ type: 'number', sql: element },
|
|
1707
|
+
{ type: 'decimal', sql: sql `CAST((${element}) AS DECIMAL)` },
|
|
1708
|
+
];
|
|
1709
|
+
}
|
|
1710
|
+
else if (_dataType === 'decimal') {
|
|
1711
|
+
return [
|
|
1712
|
+
{ type: 'decimal', sql: element },
|
|
1713
|
+
{ type: 'number', sql: element },
|
|
1714
|
+
];
|
|
1715
|
+
}
|
|
1716
|
+
else if (_dataType && _PrimitiveValue.includes(_dataType)) {
|
|
1693
1717
|
return [{ type: _dataType, sql: element }];
|
|
1694
1718
|
}
|
|
1695
1719
|
}
|
|
1696
|
-
if (expr instanceof
|
|
1720
|
+
if (expr instanceof validator.QueryValueExpression) {
|
|
1697
1721
|
if (_.isBoolean(expr.value))
|
|
1698
1722
|
return [{ type: 'boolean', sql: sql `${{ value: expr.value }}` }];
|
|
1699
1723
|
if (_.isNumber(expr.value))
|
|
@@ -1711,20 +1735,20 @@ const encodeTypedQueryExpression = (compiler, parent, expr) => {
|
|
|
1711
1735
|
if (_.isDate(expr.value))
|
|
1712
1736
|
return [{ type: 'date', sql: sql `${{ value: expr.value }}` }];
|
|
1713
1737
|
}
|
|
1714
|
-
if (expr instanceof
|
|
1715
|
-
expr instanceof
|
|
1716
|
-
expr instanceof
|
|
1738
|
+
if (expr instanceof validator.QueryCoditionalExpression ||
|
|
1739
|
+
expr instanceof validator.QueryComparisonExpression ||
|
|
1740
|
+
expr instanceof validator.QueryNotExpression) {
|
|
1717
1741
|
const value = encodeBooleanExpression(compiler, parent, expr);
|
|
1718
1742
|
if (value)
|
|
1719
1743
|
return [{ type: 'boolean', sql: value }];
|
|
1720
1744
|
}
|
|
1721
|
-
if (expr instanceof
|
|
1745
|
+
if (expr instanceof validator.QueryDistanceExpression) {
|
|
1722
1746
|
const value = encodeDistanceQueryExpression(compiler, parent, expr);
|
|
1723
1747
|
return [{ type: 'number', sql: value }];
|
|
1724
1748
|
}
|
|
1725
1749
|
};
|
|
1726
1750
|
const encodeJsonQueryExpression = (compiler, parent, expr) => {
|
|
1727
|
-
if (expr instanceof
|
|
1751
|
+
if (expr instanceof validator.QueryKeyExpression) {
|
|
1728
1752
|
const { element, dataType } = fetchElement(compiler, parent, expr.key);
|
|
1729
1753
|
if (dataType && index.isPrimitive(dataType)) {
|
|
1730
1754
|
switch (index._typeof(dataType)) {
|
|
@@ -1740,10 +1764,10 @@ const encodeJsonQueryExpression = (compiler, parent, expr) => {
|
|
|
1740
1764
|
}
|
|
1741
1765
|
return sql `${element}`;
|
|
1742
1766
|
}
|
|
1743
|
-
if (expr instanceof
|
|
1767
|
+
if (expr instanceof validator.QueryValueExpression) {
|
|
1744
1768
|
return _encodeJsonValue(index._encodeValue(expr.value));
|
|
1745
1769
|
}
|
|
1746
|
-
if (expr instanceof
|
|
1770
|
+
if (expr instanceof validator.QueryArrayExpression) {
|
|
1747
1771
|
return sql `jsonb_build_array(${_.map(expr.exprs, x => encodeJsonQueryExpression(compiler, parent, x))})`;
|
|
1748
1772
|
}
|
|
1749
1773
|
const value = encodeQueryExpression(compiler, parent, expr);
|
|
@@ -1754,13 +1778,13 @@ const encodeJsonQueryExpression = (compiler, parent, expr) => {
|
|
|
1754
1778
|
const encodeVectorExpression = (compiler, parent, exprs) => {
|
|
1755
1779
|
if (exprs.length === 1) {
|
|
1756
1780
|
const [expr] = exprs;
|
|
1757
|
-
if (expr instanceof
|
|
1781
|
+
if (expr instanceof validator.QueryKeyExpression) {
|
|
1758
1782
|
const { element, dataType } = fetchElement(compiler, parent, expr.key);
|
|
1759
1783
|
if (!dataType || !index.isVector(dataType))
|
|
1760
1784
|
throw Error('Invalid expression');
|
|
1761
1785
|
return { sql: element, dimension: dataType.dimension };
|
|
1762
1786
|
}
|
|
1763
|
-
if (expr instanceof
|
|
1787
|
+
if (expr instanceof validator.QueryValueExpression) {
|
|
1764
1788
|
if (!_.isArray(expr.value) || !_.every(expr.value, x => _.isFinite(x)))
|
|
1765
1789
|
throw Error('Invalid expression');
|
|
1766
1790
|
return { sql: sql `${{ value: expr.value }}::DOUBLE PRECISION[]`, dimension: expr.value.length };
|
|
@@ -1799,7 +1823,7 @@ const matchType = (first, second) => {
|
|
|
1799
1823
|
return found ? [found, _.find(second, r => r.type === found.type)] : undefined;
|
|
1800
1824
|
};
|
|
1801
1825
|
const encodeBooleanExpression = (compiler, parent, expr) => {
|
|
1802
|
-
if (expr instanceof
|
|
1826
|
+
if (expr instanceof validator.QueryCoditionalExpression) {
|
|
1803
1827
|
const queries = _.compact(_.map(expr.exprs, x => encodeBooleanExpression(compiler, parent, x)));
|
|
1804
1828
|
if (_.isEmpty(queries))
|
|
1805
1829
|
return;
|
|
@@ -1809,7 +1833,7 @@ const encodeBooleanExpression = (compiler, parent, expr) => {
|
|
|
1809
1833
|
case '$or': return sql `(${{ literal: _.map(queries, x => sql `(${x})`), separator: ' OR ' }})`;
|
|
1810
1834
|
}
|
|
1811
1835
|
}
|
|
1812
|
-
if (expr instanceof
|
|
1836
|
+
if (expr instanceof validator.QueryComparisonExpression) {
|
|
1813
1837
|
const operatorMap = {
|
|
1814
1838
|
'$eq': nullSafeEqual(),
|
|
1815
1839
|
'$ne': nullSafeNotEqual(),
|
|
@@ -1840,14 +1864,14 @@ const encodeBooleanExpression = (compiler, parent, expr) => {
|
|
|
1840
1864
|
const _right2 = encodeJsonQueryExpression(compiler, parent, expr.right);
|
|
1841
1865
|
return sql `${_left2} ${operatorMap[expr.type]} ${_right2}`;
|
|
1842
1866
|
}
|
|
1843
|
-
if (expr instanceof
|
|
1867
|
+
if (expr instanceof validator.QueryNotExpression) {
|
|
1844
1868
|
const _expr = encodeBooleanExpression(compiler, parent, expr.expr);
|
|
1845
1869
|
return _expr ? sql `NOT (${_expr})` : undefined;
|
|
1846
1870
|
}
|
|
1847
1871
|
throw Error('Invalid expression');
|
|
1848
1872
|
};
|
|
1849
1873
|
const encodeQueryExpression = (compiler, parent, expr) => {
|
|
1850
|
-
if (expr instanceof
|
|
1874
|
+
if (expr instanceof validator.QueryDistanceExpression) {
|
|
1851
1875
|
return encodeDistanceQueryExpression(compiler, parent, expr);
|
|
1852
1876
|
}
|
|
1853
1877
|
return encodeBooleanExpression(compiler, parent, expr);
|
|
@@ -1954,39 +1978,66 @@ const selectPopulate = (compiler, parent, populate, field) => {
|
|
|
1954
1978
|
sql `${{ identifier: parent.name }}.${{ identifier: field }} AS ${{ identifier: `$${field}` }}`,
|
|
1955
1979
|
];
|
|
1956
1980
|
if (!_.isEmpty(groupMatches?.[field])) {
|
|
1957
|
-
for (const [key,
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
(
|
|
1962
|
-
SELECT COUNT(*) FROM (
|
|
1963
|
-
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
1964
|
-
) ${{ identifier: populate.name }}
|
|
1965
|
-
) AS ${{ identifier: `${field}.${key}` }}
|
|
1966
|
-
`);
|
|
1967
|
-
break;
|
|
1968
|
-
case '$avg':
|
|
1969
|
-
case '$sum':
|
|
1970
|
-
{
|
|
1971
|
-
const op = {
|
|
1972
|
-
'$avg': 'AVG',
|
|
1973
|
-
'$sum': 'SUM',
|
|
1974
|
-
}[type];
|
|
1975
|
-
if (!expr)
|
|
1976
|
-
throw Error('Invalid expression');
|
|
1977
|
-
const exprs = encodeTypedQueryExpression(compiler, populate, expr);
|
|
1978
|
-
const { sql: value } = (_.includes(['$avg'], type) ? _.find(exprs, e => e.type === 'number') : _.first(exprs)) ?? {};
|
|
1979
|
-
if (!value)
|
|
1980
|
-
throw Error('Invalid expression');
|
|
1981
|
+
for (const [key, expr] of _.entries(groupMatches[field])) {
|
|
1982
|
+
if (expr instanceof validator.QueryNoParamAccumulator) {
|
|
1983
|
+
switch (expr.type) {
|
|
1984
|
+
case '$count':
|
|
1981
1985
|
columns.push(sql `
|
|
1982
1986
|
(
|
|
1983
|
-
SELECT
|
|
1987
|
+
SELECT COUNT(*) FROM (
|
|
1984
1988
|
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
1985
1989
|
) ${{ identifier: populate.name }}
|
|
1986
1990
|
) AS ${{ identifier: `${field}.${key}` }}
|
|
1987
1991
|
`);
|
|
1988
|
-
|
|
1989
|
-
|
|
1992
|
+
break;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
else if (expr instanceof validator.QueryExprAccumulator) {
|
|
1996
|
+
const op = {
|
|
1997
|
+
'$max': 'MAX',
|
|
1998
|
+
'$min': 'MIN',
|
|
1999
|
+
'$avg': 'AVG',
|
|
2000
|
+
'$sum': 'SUM',
|
|
2001
|
+
'$stdDevPop': 'STDDEV_POP',
|
|
2002
|
+
'$stdDevSamp': 'STDDEV_SAMP',
|
|
2003
|
+
'$varPop': 'VAR_POP',
|
|
2004
|
+
'$varSamp': 'VAR_SAMP',
|
|
2005
|
+
}[expr.type];
|
|
2006
|
+
if (!expr.expr)
|
|
2007
|
+
throw Error('Invalid expression');
|
|
2008
|
+
const exprs = encodeTypedQueryExpression(compiler, populate, expr.expr);
|
|
2009
|
+
const value = _.first(exprs)?.sql;
|
|
2010
|
+
if (!value)
|
|
2011
|
+
throw Error('Invalid expression');
|
|
2012
|
+
columns.push(sql `
|
|
2013
|
+
(
|
|
2014
|
+
SELECT ${{ literal: op }}(${value}) FROM (
|
|
2015
|
+
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
2016
|
+
) ${{ identifier: populate.name }}
|
|
2017
|
+
) AS ${{ identifier: `${field}.${key}` }}
|
|
2018
|
+
`);
|
|
2019
|
+
}
|
|
2020
|
+
else if (expr instanceof validator.QueryPercentileAccumulator) {
|
|
2021
|
+
const op = {
|
|
2022
|
+
'discrete': 'PERCENTILE_DISC',
|
|
2023
|
+
'continuous': 'PERCENTILE_CONT',
|
|
2024
|
+
}[expr.mode];
|
|
2025
|
+
if (!expr.input)
|
|
2026
|
+
throw Error('Invalid expression');
|
|
2027
|
+
const exprs = encodeTypedQueryExpression(compiler, populate, expr.input);
|
|
2028
|
+
const value = _.first(exprs)?.sql;
|
|
2029
|
+
if (!value)
|
|
2030
|
+
throw Error('Invalid expression');
|
|
2031
|
+
columns.push(sql `
|
|
2032
|
+
(
|
|
2033
|
+
SELECT ${{ literal: op }}(${{ value: expr.p }}) WITHIN GROUP (ORDER BY (${value})) FROM (
|
|
2034
|
+
${_selectRelationPopulate(compiler, parent, populate, field, false)}
|
|
2035
|
+
) ${{ identifier: populate.name }}
|
|
2036
|
+
) AS ${{ identifier: `${field}.${key}` }}
|
|
2037
|
+
`);
|
|
2038
|
+
}
|
|
2039
|
+
else {
|
|
2040
|
+
throw Error('Invalid expression');
|
|
1990
2041
|
}
|
|
1991
2042
|
}
|
|
1992
2043
|
}
|
|
@@ -2021,7 +2072,7 @@ const encodeRemix = (parent, remix) => sql `${remix?.className === parent.classN
|
|
|
2021
2072
|
(SELECT * FROM ${{ identifier: remix.name }} UNION SELECT * FROM ${{ identifier: parent.className }})
|
|
2022
2073
|
` : { identifier: parent.className }}`;
|
|
2023
2074
|
const encodeForeignField = (compiler, parent, foreignField, remix) => {
|
|
2024
|
-
const { paths: [colname, ...subpath], dataType } =
|
|
2075
|
+
const { paths: [colname, ...subpath], dataType } = validator.resolveColumn(compiler.schema, parent.className, foreignField);
|
|
2025
2076
|
const tempName = `_populate_$${compiler.nextIdx()}`;
|
|
2026
2077
|
const _local = (field) => sql `${{ identifier: parent.name }}.${{ identifier: field }}`;
|
|
2027
2078
|
const _foreign = (field) => sql `${{ identifier: tempName }}.${{ identifier: field }}`;
|
|
@@ -2152,7 +2203,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2152
2203
|
switch (expr.type) {
|
|
2153
2204
|
case '$eq':
|
|
2154
2205
|
{
|
|
2155
|
-
if (_.isRegExp(expr.value) || expr.value instanceof
|
|
2206
|
+
if (_.isRegExp(expr.value) || expr.value instanceof validator.QuerySelector || expr.value instanceof validator.FieldSelectorExpression)
|
|
2156
2207
|
break;
|
|
2157
2208
|
if (_.isNil(expr.value))
|
|
2158
2209
|
return sql `${element} IS NULL`;
|
|
@@ -2165,7 +2216,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2165
2216
|
}
|
|
2166
2217
|
case '$ne':
|
|
2167
2218
|
{
|
|
2168
|
-
if (_.isRegExp(expr.value) || expr.value instanceof
|
|
2219
|
+
if (_.isRegExp(expr.value) || expr.value instanceof validator.QuerySelector || expr.value instanceof validator.FieldSelectorExpression)
|
|
2169
2220
|
break;
|
|
2170
2221
|
if (_.isNil(expr.value))
|
|
2171
2222
|
return sql `${element} IS NOT NULL`;
|
|
@@ -2187,7 +2238,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2187
2238
|
'$lt': '<',
|
|
2188
2239
|
'$lte': '<=',
|
|
2189
2240
|
}[expr.type];
|
|
2190
|
-
if (_.isRegExp(expr.value) || expr.value instanceof
|
|
2241
|
+
if (_.isRegExp(expr.value) || expr.value instanceof validator.QuerySelector || expr.value instanceof validator.FieldSelectorExpression)
|
|
2191
2242
|
break;
|
|
2192
2243
|
if (dataType && index.isPrimitive(dataType)) {
|
|
2193
2244
|
switch (index._typeof(dataType)) {
|
|
@@ -2348,7 +2399,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2348
2399
|
break;
|
|
2349
2400
|
case '$not':
|
|
2350
2401
|
{
|
|
2351
|
-
if (!(expr.value instanceof
|
|
2402
|
+
if (!(expr.value instanceof validator.FieldSelectorExpression))
|
|
2352
2403
|
break;
|
|
2353
2404
|
return sql `NOT (${encodeFieldExpression(compiler, parent, field, expr.value)})`;
|
|
2354
2405
|
}
|
|
@@ -2454,7 +2505,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2454
2505
|
break;
|
|
2455
2506
|
case '$every':
|
|
2456
2507
|
{
|
|
2457
|
-
if (!(expr.value instanceof
|
|
2508
|
+
if (!(expr.value instanceof validator.QuerySelector))
|
|
2458
2509
|
break;
|
|
2459
2510
|
if (relation && parent.className) {
|
|
2460
2511
|
const tempName = `_populate_expr_$${compiler.nextIdx()}`;
|
|
@@ -2507,7 +2558,7 @@ const encodeFieldExpression = (compiler, parent, field, expr) => {
|
|
|
2507
2558
|
break;
|
|
2508
2559
|
case '$some':
|
|
2509
2560
|
{
|
|
2510
|
-
if (!(expr.value instanceof
|
|
2561
|
+
if (!(expr.value instanceof validator.QuerySelector))
|
|
2511
2562
|
break;
|
|
2512
2563
|
if (relation && parent.className) {
|
|
2513
2564
|
const tempName = `_populate_expr_$${compiler.nextIdx()}`;
|